1 /* Process expressions for the GNU compiler for the Java(TM) language.
2 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
3 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to
19 the Free Software Foundation, 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
22 Java and all Java-based marks are trademarks or registered trademarks
23 of Sun Microsystems, Inc. in the United States and other countries.
24 The Free Software Foundation is independent of Sun Microsystems, Inc. */
26 /* Hacked by Per Bothner <bothner@cygnus.com> February 1996. */
30 #include "coretypes.h"
37 #include "java-tree.h"
39 #include "java-opcodes.h"
41 #include "java-except.h"
46 #include "tree-gimple.h"
49 static void flush_quick_stack (void);
50 static void push_value (tree
);
51 static tree
pop_value (tree
);
52 static void java_stack_swap (void);
53 static void java_stack_dup (int, int);
54 static void build_java_athrow (tree
);
55 static void build_java_jsr (int, int);
56 static void build_java_ret (tree
);
57 static void expand_java_multianewarray (tree
, int);
58 static void expand_java_arraystore (tree
);
59 static void expand_java_arrayload (tree
);
60 static void expand_java_array_length (void);
61 static tree
build_java_monitor (tree
, tree
);
62 static void expand_java_pushc (int, tree
);
63 static void expand_java_return (tree
);
64 static void expand_load_internal (int, tree
, int);
65 static void expand_java_NEW (tree
);
66 static void expand_java_INSTANCEOF (tree
);
67 static void expand_java_CHECKCAST (tree
);
68 static void expand_iinc (unsigned int, int, int);
69 static void expand_java_binop (tree
, enum tree_code
);
70 static void note_label (int, int);
71 static void expand_compare (enum tree_code
, tree
, tree
, int);
72 static void expand_test (enum tree_code
, tree
, int);
73 static void expand_cond (enum tree_code
, tree
, int);
74 static void expand_java_goto (int);
75 static tree
expand_java_switch (tree
, int);
76 static void expand_java_add_case (tree
, int, int);
78 static void expand_java_call (int, int);
79 static void expand_java_ret (tree
);
81 static tree
pop_arguments (tree
);
82 static void expand_invoke (int, int, int);
83 static void expand_java_field_op (int, int, int);
84 static void java_push_constant_from_pool (struct JCF
*, int);
85 static void java_stack_pop (int);
86 static tree
build_java_throw_out_of_bounds_exception (tree
);
87 static tree
build_java_check_indexed_type (tree
, tree
);
88 static unsigned char peek_opcode_at_pc (struct JCF
*, int, int);
89 static void promote_arguments (void);
91 static GTY(()) tree operand_type
[59];
93 static GTY(()) tree methods_ident
;
94 static GTY(()) tree ncode_ident
;
95 tree dtable_ident
= NULL_TREE
;
97 /* Set to nonzero value in order to emit class initialization code
98 before static field references. */
99 int always_initialize_class_p
= 0;
101 /* We store the stack state in two places:
102 Within a basic block, we use the quick_stack, which is a
103 pushdown list (TREE_LISTs) of expression nodes.
104 This is the top part of the stack; below that we use find_stack_slot.
105 At the end of a basic block, the quick_stack must be flushed
106 to the stack slot array (as handled by find_stack_slot).
107 Using quick_stack generates better code (especially when
108 compiled without optimization), because we do not have to
109 explicitly store and load trees to temporary variables.
111 If a variable is on the quick stack, it means the value of variable
112 when the quick stack was last flushed. Conceptually, flush_quick_stack
113 saves all the quick_stack elements in parallel. However, that is
114 complicated, so it actually saves them (i.e. copies each stack value
115 to is home virtual register) from low indexes. This allows a quick_stack
116 element at index i (counting from the bottom of stack the) to references
117 slot virtuals for register that are >= i, but not those that are deeper.
118 This convention makes most operations easier. For example iadd works
119 even when the stack contains (reg[0], reg[1]): It results in the
120 stack containing (reg[0]+reg[1]), which is OK. However, some stack
121 operations are more complicated. For example dup given a stack
122 containing (reg[0]) would yield (reg[0], reg[0]), which would violate
123 the convention, since stack value 1 would refer to a register with
124 lower index (reg[0]), which flush_quick_stack does not safely handle.
125 So dup cannot just add an extra element to the quick_stack, but iadd can.
128 static GTY(()) tree quick_stack
;
130 /* A free-list of unused permanent TREE_LIST nodes. */
131 static GTY((deletable
)) tree tree_list_free_list
;
133 /* The stack pointer of the Java virtual machine.
134 This does include the size of the quick_stack. */
138 const unsigned char *linenumber_table
;
139 int linenumber_count
;
141 /* Largest pc so far in this method that has been passed to lookup_label. */
142 int highest_label_pc_this_method
= -1;
144 /* Base value for this method to add to pc to get generated label. */
145 int start_label_pc_this_method
= 0;
148 init_expr_processing (void)
150 operand_type
[21] = operand_type
[54] = int_type_node
;
151 operand_type
[22] = operand_type
[55] = long_type_node
;
152 operand_type
[23] = operand_type
[56] = float_type_node
;
153 operand_type
[24] = operand_type
[57] = double_type_node
;
154 operand_type
[25] = operand_type
[58] = ptr_type_node
;
158 java_truthvalue_conversion (tree expr
)
160 /* It is simpler and generates better code to have only TRUTH_*_EXPR
161 or comparison expressions as truth values at this level.
163 This function should normally be identity for Java. */
165 switch (TREE_CODE (expr
))
167 case EQ_EXPR
: case NE_EXPR
: case UNEQ_EXPR
: case LTGT_EXPR
:
168 case LE_EXPR
: case GE_EXPR
: case LT_EXPR
: case GT_EXPR
:
169 case UNLE_EXPR
: case UNGE_EXPR
: case UNLT_EXPR
: case UNGT_EXPR
:
170 case ORDERED_EXPR
: case UNORDERED_EXPR
:
171 case TRUTH_ANDIF_EXPR
:
172 case TRUTH_ORIF_EXPR
:
181 return integer_zerop (expr
) ? boolean_false_node
: boolean_true_node
;
184 return real_zerop (expr
) ? boolean_false_node
: boolean_true_node
;
186 /* are these legal? XXX JH */
190 /* These don't change whether an object is nonzero or zero. */
191 return java_truthvalue_conversion (TREE_OPERAND (expr
, 0));
194 /* Distribute the conversion into the arms of a COND_EXPR. */
195 return fold_build3 (COND_EXPR
, boolean_type_node
, TREE_OPERAND (expr
, 0),
196 java_truthvalue_conversion (TREE_OPERAND (expr
, 1)),
197 java_truthvalue_conversion (TREE_OPERAND (expr
, 2)));
200 /* If this is widening the argument, we can ignore it. */
201 if (TYPE_PRECISION (TREE_TYPE (expr
))
202 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr
, 0))))
203 return java_truthvalue_conversion (TREE_OPERAND (expr
, 0));
204 /* fall through to default */
207 return fold_build2 (NE_EXPR
, boolean_type_node
,
208 expr
, boolean_false_node
);
212 /* Save any stack slots that happen to be in the quick_stack into their
213 home virtual register slots.
215 The copy order is from low stack index to high, to support the invariant
216 that the expression for a slot may contain decls for stack slots with
217 higher (or the same) index, but not lower. */
220 flush_quick_stack (void)
222 int stack_index
= stack_pointer
;
223 tree prev
, cur
, next
;
225 /* First reverse the quick_stack, and count the number of slots it has. */
226 for (cur
= quick_stack
, prev
= NULL_TREE
; cur
!= NULL_TREE
; cur
= next
)
228 next
= TREE_CHAIN (cur
);
229 TREE_CHAIN (cur
) = prev
;
231 stack_index
-= 1 + TYPE_IS_WIDE (TREE_TYPE (TREE_VALUE (cur
)));
235 while (quick_stack
!= NULL_TREE
)
238 tree node
= quick_stack
, type
;
239 quick_stack
= TREE_CHAIN (node
);
240 TREE_CHAIN (node
) = tree_list_free_list
;
241 tree_list_free_list
= node
;
242 node
= TREE_VALUE (node
);
243 type
= TREE_TYPE (node
);
245 decl
= find_stack_slot (stack_index
, type
);
247 java_add_stmt (build2 (MODIFY_EXPR
, TREE_TYPE (node
), decl
, node
));
248 stack_index
+= 1 + TYPE_IS_WIDE (type
);
252 /* Push TYPE on the type stack.
253 Return true on success, 0 on overflow. */
256 push_type_0 (tree type
)
259 type
= promote_type (type
);
260 n_words
= 1 + TYPE_IS_WIDE (type
);
261 if (stack_pointer
+ n_words
> DECL_MAX_STACK (current_function_decl
))
263 /* Allocate decl for this variable now, so we get a temporary that
264 survives the whole method. */
265 find_stack_slot (stack_pointer
, type
);
266 stack_type_map
[stack_pointer
++] = type
;
268 while (--n_words
>= 0)
269 stack_type_map
[stack_pointer
++] = TYPE_SECOND
;
274 push_type (tree type
)
276 if (! push_type_0 (type
))
281 push_value (tree value
)
283 tree type
= TREE_TYPE (value
);
284 if (TYPE_PRECISION (type
) < 32 && INTEGRAL_TYPE_P (type
))
286 type
= promote_type (type
);
287 value
= convert (type
, value
);
290 if (tree_list_free_list
== NULL_TREE
)
291 quick_stack
= tree_cons (NULL_TREE
, value
, quick_stack
);
294 tree node
= tree_list_free_list
;
295 tree_list_free_list
= TREE_CHAIN (tree_list_free_list
);
296 TREE_VALUE (node
) = value
;
297 TREE_CHAIN (node
) = quick_stack
;
302 /* Pop a type from the type stack.
303 TYPE is the expected type. Return the actual type, which must be
305 On an error, *MESSAGEP is set to a freshly malloc'd error message. */
308 pop_type_0 (tree type
, char **messagep
)
313 if (TREE_CODE (type
) == RECORD_TYPE
)
314 type
= promote_type (type
);
315 n_words
= 1 + TYPE_IS_WIDE (type
);
316 if (stack_pointer
< n_words
)
318 *messagep
= xstrdup ("stack underflow");
321 while (--n_words
> 0)
323 if (stack_type_map
[--stack_pointer
] != void_type_node
)
325 *messagep
= xstrdup ("Invalid multi-word value on type stack");
329 t
= stack_type_map
[--stack_pointer
];
330 if (type
== NULL_TREE
|| t
== type
)
332 if (TREE_CODE (t
) == TREE_LIST
)
336 tree tt
= TREE_PURPOSE (t
);
337 if (! can_widen_reference_to (tt
, type
))
347 if (INTEGRAL_TYPE_P (type
) && INTEGRAL_TYPE_P (t
)
348 && TYPE_PRECISION (type
) <= 32 && TYPE_PRECISION (t
) <= 32)
350 if (TREE_CODE (type
) == POINTER_TYPE
&& TREE_CODE (t
) == POINTER_TYPE
)
352 /* If the expected type we've been passed is object or ptr
353 (i.e. void*), the caller needs to know the real type. */
354 if (type
== ptr_type_node
|| type
== object_ptr_type_node
)
357 /* Since the verifier has already run, we know that any
358 types we see will be compatible. In BC mode, this fact
359 may be checked at runtime, but if that is so then we can
360 assume its truth here as well. So, we always succeed
361 here, with the expected type. */
365 if (! flag_verify_invocations
&& flag_indirect_dispatch
366 && t
== object_ptr_type_node
)
368 if (type
!= ptr_type_node
)
369 warning (0, "need to insert runtime check for %s",
370 xstrdup (lang_printable_name (type
, 0)));
374 /* lang_printable_name uses a static buffer, so we must save the result
375 from calling it the first time. */
378 char *temp
= xstrdup (lang_printable_name (type
, 0));
379 /* If the stack contains a multi-word type, keep popping the stack until
380 the real type is found. */
381 while (t
== void_type_node
)
382 t
= stack_type_map
[--stack_pointer
];
383 *messagep
= concat ("expected type '", temp
,
384 "' but stack contains '", lang_printable_name (t
, 0),
391 /* Pop a type from the type stack.
392 TYPE is the expected type. Return the actual type, which must be
393 convertible to TYPE, otherwise call error. */
398 char *message
= NULL
;
399 type
= pop_type_0 (type
, &message
);
402 error ("%s", message
);
409 /* Return true if two type assertions are equal. */
412 type_assertion_eq (const void * k1_p
, const void * k2_p
)
414 type_assertion k1
= *(type_assertion
*)k1_p
;
415 type_assertion k2
= *(type_assertion
*)k2_p
;
416 return (k1
.assertion_code
== k2
.assertion_code
418 && k1
.op2
== k2
.op2
);
421 /* Hash a type assertion. */
424 type_assertion_hash (const void *p
)
426 const type_assertion
*k_p
= p
;
427 hashval_t hash
= iterative_hash (&k_p
->assertion_code
, sizeof
428 k_p
->assertion_code
, 0);
429 hash
= iterative_hash (&k_p
->op1
, sizeof k_p
->op1
, hash
);
430 return iterative_hash (&k_p
->op2
, sizeof k_p
->op2
, hash
);
433 /* Add an entry to the type assertion table for the given class.
434 CLASS is the class for which this assertion will be evaluated by the
435 runtime during loading/initialization.
436 ASSERTION_CODE is the 'opcode' or type of this assertion: see java-tree.h.
437 OP1 and OP2 are the operands. The tree type of these arguments may be
438 specific to each assertion_code. */
441 add_type_assertion (tree
class, int assertion_code
, tree op1
, tree op2
)
443 htab_t assertions_htab
;
447 assertions_htab
= TYPE_ASSERTIONS (class);
448 if (assertions_htab
== NULL
)
450 assertions_htab
= htab_create_ggc (7, type_assertion_hash
,
451 type_assertion_eq
, NULL
);
452 TYPE_ASSERTIONS (current_class
) = assertions_htab
;
455 as
.assertion_code
= assertion_code
;
459 as_pp
= htab_find_slot (assertions_htab
, &as
, INSERT
);
461 /* Don't add the same assertion twice. */
465 *as_pp
= ggc_alloc (sizeof (type_assertion
));
466 **(type_assertion
**)as_pp
= as
;
470 /* Return 1 if SOURCE_TYPE can be safely widened to TARGET_TYPE.
471 Handles array types and interfaces. */
474 can_widen_reference_to (tree source_type
, tree target_type
)
476 if (source_type
== ptr_type_node
|| target_type
== object_ptr_type_node
)
479 /* Get rid of pointers */
480 if (TREE_CODE (source_type
) == POINTER_TYPE
)
481 source_type
= TREE_TYPE (source_type
);
482 if (TREE_CODE (target_type
) == POINTER_TYPE
)
483 target_type
= TREE_TYPE (target_type
);
485 if (source_type
== target_type
)
488 /* FIXME: This is very pessimistic, in that it checks everything,
489 even if we already know that the types are compatible. If we're
490 to support full Java class loader semantics, we need this.
491 However, we could do something more optimal. */
492 if (! flag_verify_invocations
)
494 add_type_assertion (current_class
, JV_ASSERT_TYPES_COMPATIBLE
,
495 source_type
, target_type
);
498 warning (0, "assert: %s is assign compatible with %s",
499 xstrdup (lang_printable_name (target_type
, 0)),
500 xstrdup (lang_printable_name (source_type
, 0)));
501 /* Punt everything to runtime. */
505 if (TYPE_DUMMY (source_type
) || TYPE_DUMMY (target_type
))
511 if (TYPE_ARRAY_P (source_type
) || TYPE_ARRAY_P (target_type
))
513 HOST_WIDE_INT source_length
, target_length
;
514 if (TYPE_ARRAY_P (source_type
) != TYPE_ARRAY_P (target_type
))
516 /* An array implements Cloneable and Serializable. */
517 tree name
= DECL_NAME (TYPE_NAME (target_type
));
518 return (name
== java_lang_cloneable_identifier_node
519 || name
== java_io_serializable_identifier_node
);
521 target_length
= java_array_type_length (target_type
);
522 if (target_length
>= 0)
524 source_length
= java_array_type_length (source_type
);
525 if (source_length
!= target_length
)
528 source_type
= TYPE_ARRAY_ELEMENT (source_type
);
529 target_type
= TYPE_ARRAY_ELEMENT (target_type
);
530 if (source_type
== target_type
)
532 if (TREE_CODE (source_type
) != POINTER_TYPE
533 || TREE_CODE (target_type
) != POINTER_TYPE
)
535 return can_widen_reference_to (source_type
, target_type
);
539 int source_depth
= class_depth (source_type
);
540 int target_depth
= class_depth (target_type
);
542 if (TYPE_DUMMY (source_type
) || TYPE_DUMMY (target_type
))
545 warning (0, "assert: %s is assign compatible with %s",
546 xstrdup (lang_printable_name (target_type
, 0)),
547 xstrdup (lang_printable_name (source_type
, 0)));
551 /* class_depth can return a negative depth if an error occurred */
552 if (source_depth
< 0 || target_depth
< 0)
555 if (CLASS_INTERFACE (TYPE_NAME (target_type
)))
557 /* target_type is OK if source_type or source_type ancestors
558 implement target_type. We handle multiple sub-interfaces */
559 tree binfo
, base_binfo
;
562 for (binfo
= TYPE_BINFO (source_type
), i
= 0;
563 BINFO_BASE_ITERATE (binfo
, i
, base_binfo
); i
++)
564 if (can_widen_reference_to
565 (BINFO_TYPE (base_binfo
), target_type
))
572 for ( ; source_depth
> target_depth
; source_depth
--)
575 = BINFO_TYPE (BINFO_BASE_BINFO (TYPE_BINFO (source_type
), 0));
577 return source_type
== target_type
;
583 pop_value (tree type
)
585 type
= pop_type (type
);
588 tree node
= quick_stack
;
589 quick_stack
= TREE_CHAIN (quick_stack
);
590 TREE_CHAIN (node
) = tree_list_free_list
;
591 tree_list_free_list
= node
;
592 node
= TREE_VALUE (node
);
596 return find_stack_slot (stack_pointer
, promote_type (type
));
600 /* Pop and discard the top COUNT stack slots. */
603 java_stack_pop (int count
)
609 if (stack_pointer
== 0)
612 type
= stack_type_map
[stack_pointer
- 1];
613 if (type
== TYPE_SECOND
)
616 if (stack_pointer
== 1 || count
<= 0)
619 type
= stack_type_map
[stack_pointer
- 2];
621 val
= pop_value (type
);
626 /* Implement the 'swap' operator (to swap two top stack slots). */
629 java_stack_swap (void)
635 if (stack_pointer
< 2
636 || (type1
= stack_type_map
[stack_pointer
- 1]) == TYPE_UNKNOWN
637 || (type2
= stack_type_map
[stack_pointer
- 2]) == TYPE_UNKNOWN
638 || type1
== TYPE_SECOND
|| type2
== TYPE_SECOND
639 || TYPE_IS_WIDE (type1
) || TYPE_IS_WIDE (type2
))
640 /* Bad stack swap. */
643 flush_quick_stack ();
644 decl1
= find_stack_slot (stack_pointer
- 1, type1
);
645 decl2
= find_stack_slot (stack_pointer
- 2, type2
);
646 temp
= build_decl (VAR_DECL
, NULL_TREE
, type1
);
647 java_add_local_var (temp
);
648 java_add_stmt (build2 (MODIFY_EXPR
, type1
, temp
, decl1
));
649 java_add_stmt (build2 (MODIFY_EXPR
, type2
,
650 find_stack_slot (stack_pointer
- 1, type2
),
652 java_add_stmt (build2 (MODIFY_EXPR
, type1
,
653 find_stack_slot (stack_pointer
- 2, type1
),
655 stack_type_map
[stack_pointer
- 1] = type2
;
656 stack_type_map
[stack_pointer
- 2] = type1
;
660 java_stack_dup (int size
, int offset
)
662 int low_index
= stack_pointer
- size
- offset
;
665 error ("stack underflow - dup* operation");
667 flush_quick_stack ();
669 stack_pointer
+= size
;
670 dst_index
= stack_pointer
;
672 for (dst_index
= stack_pointer
; --dst_index
>= low_index
; )
675 int src_index
= dst_index
- size
;
676 if (src_index
< low_index
)
677 src_index
= dst_index
+ size
+ offset
;
678 type
= stack_type_map
[src_index
];
679 if (type
== TYPE_SECOND
)
681 if (src_index
<= low_index
)
682 /* Dup operation splits 64-bit number. */
685 stack_type_map
[dst_index
] = type
;
686 src_index
--; dst_index
--;
687 type
= stack_type_map
[src_index
];
688 if (! TYPE_IS_WIDE (type
))
691 else if (TYPE_IS_WIDE (type
))
694 if (src_index
!= dst_index
)
696 tree src_decl
= find_stack_slot (src_index
, type
);
697 tree dst_decl
= find_stack_slot (dst_index
, type
);
700 (build2 (MODIFY_EXPR
, TREE_TYPE (dst_decl
), dst_decl
, src_decl
));
701 stack_type_map
[dst_index
] = type
;
706 /* Calls _Jv_Throw or _Jv_Sjlj_Throw. Discard the contents of the
710 build_java_athrow (tree node
)
714 call
= build3 (CALL_EXPR
,
716 build_address_of (throw_node
),
717 build_tree_list (NULL_TREE
, node
),
719 TREE_SIDE_EFFECTS (call
) = 1;
720 java_add_stmt (call
);
721 java_stack_pop (stack_pointer
);
724 /* Implementation for jsr/ret */
727 build_java_jsr (int target_pc
, int return_pc
)
729 tree where
= lookup_label (target_pc
);
730 tree ret
= lookup_label (return_pc
);
731 tree ret_label
= fold_build1 (ADDR_EXPR
, return_address_type_node
, ret
);
732 push_value (ret_label
);
733 flush_quick_stack ();
734 java_add_stmt (build1 (GOTO_EXPR
, void_type_node
, where
));
736 /* Do not need to emit the label here. We noted the existence of the
737 label as a jump target in note_instructions; we'll emit the label
738 for real at the beginning of the expand_byte_code loop. */
742 build_java_ret (tree location
)
744 java_add_stmt (build1 (GOTO_EXPR
, void_type_node
, location
));
747 /* Implementation of operations on array: new, load, store, length */
750 decode_newarray_type (int atype
)
754 case 4: return boolean_type_node
;
755 case 5: return char_type_node
;
756 case 6: return float_type_node
;
757 case 7: return double_type_node
;
758 case 8: return byte_type_node
;
759 case 9: return short_type_node
;
760 case 10: return int_type_node
;
761 case 11: return long_type_node
;
762 default: return NULL_TREE
;
766 /* Map primitive type to the code used by OPCODE_newarray. */
769 encode_newarray_type (tree type
)
771 if (type
== boolean_type_node
)
773 else if (type
== char_type_node
)
775 else if (type
== float_type_node
)
777 else if (type
== double_type_node
)
779 else if (type
== byte_type_node
)
781 else if (type
== short_type_node
)
783 else if (type
== int_type_node
)
785 else if (type
== long_type_node
)
791 /* Build a call to _Jv_ThrowBadArrayIndex(), the
792 ArrayIndexOfBoundsException exception handler. */
795 build_java_throw_out_of_bounds_exception (tree index
)
797 tree node
= build3 (CALL_EXPR
, int_type_node
,
798 build_address_of (soft_badarrayindex_node
),
799 build_tree_list (NULL_TREE
, index
), NULL_TREE
);
800 TREE_SIDE_EFFECTS (node
) = 1; /* Allows expansion within ANDIF */
804 /* Return the length of an array. Doesn't perform any checking on the nature
805 or value of the array NODE. May be used to implement some bytecodes. */
808 build_java_array_length_access (tree node
)
810 tree type
= TREE_TYPE (node
);
811 tree array_type
= TREE_TYPE (type
);
812 HOST_WIDE_INT length
;
814 if (!is_array_type_p (type
))
816 /* With the new verifier, we will see an ordinary pointer type
817 here. In this case, we just use an arbitrary array type. */
818 array_type
= build_java_array_type (object_ptr_type_node
, -1);
819 type
= promote_type (array_type
);
822 length
= java_array_type_length (type
);
824 return build_int_cst (NULL_TREE
, length
);
826 node
= build3 (COMPONENT_REF
, int_type_node
,
827 build_java_indirect_ref (array_type
, node
,
828 flag_check_references
),
829 lookup_field (&array_type
, get_identifier ("length")),
831 IS_ARRAY_LENGTH_ACCESS (node
) = 1;
835 /* Optionally checks a reference against the NULL pointer. ARG1: the
836 expr, ARG2: we should check the reference. Don't generate extra
837 checks if we're not generating code. */
840 java_check_reference (tree expr
, int check
)
842 if (!flag_syntax_only
&& check
)
844 expr
= save_expr (expr
);
845 expr
= build3 (COND_EXPR
, TREE_TYPE (expr
),
846 build2 (EQ_EXPR
, boolean_type_node
,
847 expr
, null_pointer_node
),
848 build3 (CALL_EXPR
, void_type_node
,
849 build_address_of (soft_nullpointer_node
),
850 NULL_TREE
, NULL_TREE
),
857 /* Reference an object: just like an INDIRECT_REF, but with checking. */
860 build_java_indirect_ref (tree type
, tree expr
, int check
)
863 t
= java_check_reference (expr
, check
);
864 t
= convert (build_pointer_type (type
), t
);
865 return build1 (INDIRECT_REF
, type
, t
);
868 /* Implement array indexing (either as l-value or r-value).
869 Returns a tree for ARRAY[INDEX], assume TYPE is the element type.
870 Optionally performs bounds checking and/or test to NULL.
871 At this point, ARRAY should have been verified as an array. */
874 build_java_arrayaccess (tree array
, tree type
, tree index
)
876 tree node
, throw = NULL_TREE
;
879 tree array_type
= TREE_TYPE (TREE_TYPE (array
));
881 if (!is_array_type_p (TREE_TYPE (array
)))
883 /* With the new verifier, we will see an ordinary pointer type
884 here. In this case, we just use the correct array type. */
885 array_type
= build_java_array_type (type
, -1);
888 if (flag_bounds_check
)
891 * (unsigned jint) INDEX >= (unsigned jint) LEN
892 * && throw ArrayIndexOutOfBoundsException.
893 * Note this is equivalent to and more efficient than:
894 * INDEX < 0 || INDEX >= LEN && throw ... */
896 tree len
= convert (unsigned_int_type_node
,
897 build_java_array_length_access (array
));
898 test
= fold_build2 (GE_EXPR
, boolean_type_node
,
899 convert (unsigned_int_type_node
, index
),
901 if (! integer_zerop (test
))
903 throw = build2 (TRUTH_ANDIF_EXPR
, int_type_node
, test
,
904 build_java_throw_out_of_bounds_exception (index
));
905 /* allows expansion within COMPOUND */
906 TREE_SIDE_EFFECTS( throw ) = 1;
910 /* If checking bounds, wrap the index expr with a COMPOUND_EXPR in order
911 to have the bounds check evaluated first. */
912 if (throw != NULL_TREE
)
913 index
= build2 (COMPOUND_EXPR
, int_type_node
, throw, index
);
915 data_field
= lookup_field (&array_type
, get_identifier ("data"));
917 ref
= build3 (COMPONENT_REF
, TREE_TYPE (data_field
),
918 build_java_indirect_ref (array_type
, array
,
919 flag_check_references
),
920 data_field
, NULL_TREE
);
922 node
= build4 (ARRAY_REF
, type
, ref
, index
, NULL_TREE
, NULL_TREE
);
926 /* Generate code to throw an ArrayStoreException if OBJECT is not assignable
927 (at runtime) to an element of ARRAY. A NOP_EXPR is returned if it can
928 determine that no check is required. */
931 build_java_arraystore_check (tree array
, tree object
)
933 tree check
, element_type
, source
;
934 tree array_type_p
= TREE_TYPE (array
);
935 tree object_type
= TYPE_NAME (TREE_TYPE (TREE_TYPE (object
)));
937 if (! flag_verify_invocations
)
939 /* With the new verifier, we don't track precise types. FIXME:
940 performance regression here. */
941 element_type
= TYPE_NAME (object_type_node
);
945 if (! is_array_type_p (array_type_p
))
948 /* Get the TYPE_DECL for ARRAY's element type. */
950 = TYPE_NAME (TREE_TYPE (TREE_TYPE (TREE_TYPE (array_type_p
))));
953 if (TREE_CODE (element_type
) != TYPE_DECL
954 || TREE_CODE (object_type
) != TYPE_DECL
)
957 if (!flag_store_check
)
958 return build1 (NOP_EXPR
, array_type_p
, array
);
960 /* No check is needed if the element type is final. Also check that
961 element_type matches object_type, since in the bytecode
962 compilation case element_type may be the actual element type of
963 the array rather than its declared type. However, if we're doing
964 indirect dispatch, we can't do the `final' optimization. */
965 if (element_type
== object_type
966 && ! flag_indirect_dispatch
967 && CLASS_FINAL (element_type
))
968 return build1 (NOP_EXPR
, array_type_p
, array
);
970 /* OBJECT might be wrapped by a SAVE_EXPR. */
971 if (TREE_CODE (object
) == SAVE_EXPR
)
972 source
= TREE_OPERAND (object
, 0);
976 /* Avoid the check if OBJECT was just loaded from the same array. */
977 if (TREE_CODE (source
) == ARRAY_REF
)
980 source
= TREE_OPERAND (source
, 0); /* COMPONENT_REF. */
981 source
= TREE_OPERAND (source
, 0); /* INDIRECT_REF. */
982 source
= TREE_OPERAND (source
, 0); /* Source array's DECL or SAVE_EXPR. */
983 if (TREE_CODE (source
) == SAVE_EXPR
)
984 source
= TREE_OPERAND (source
, 0);
987 if (TREE_CODE (target
) == SAVE_EXPR
)
988 target
= TREE_OPERAND (target
, 0);
990 if (source
== target
)
991 return build1 (NOP_EXPR
, array_type_p
, array
);
994 /* Build an invocation of _Jv_CheckArrayStore */
995 check
= build3 (CALL_EXPR
, void_type_node
,
996 build_address_of (soft_checkarraystore_node
),
997 tree_cons (NULL_TREE
, array
,
998 build_tree_list (NULL_TREE
, object
)),
1000 TREE_SIDE_EFFECTS (check
) = 1;
1005 /* Makes sure that INDEXED_TYPE is appropriate. If not, make it from
1006 ARRAY_NODE. This function is used to retrieve something less vague than
1007 a pointer type when indexing the first dimension of something like [[<t>.
1008 May return a corrected type, if necessary, otherwise INDEXED_TYPE is
1009 return unchanged. */
1012 build_java_check_indexed_type (tree array_node ATTRIBUTE_UNUSED
,
1015 /* We used to check to see if ARRAY_NODE really had array type.
1016 However, with the new verifier, this is not necessary, as we know
1017 that the object will be an array of the appropriate type. */
1019 return indexed_type
;
1022 /* newarray triggers a call to _Jv_NewPrimArray. This function should be
1023 called with an integer code (the type of array to create), and the length
1024 of the array to create. */
1027 build_newarray (int atype_value
, tree length
)
1031 tree prim_type
= decode_newarray_type (atype_value
);
1033 = build_java_array_type (prim_type
,
1034 host_integerp (length
, 0) == INTEGER_CST
1035 ? tree_low_cst (length
, 0) : -1);
1037 /* If compiling to native, pass a reference to the primitive type class
1038 and save the runtime some work. However, the bytecode generator
1039 expects to find the type_code int here. */
1040 if (flag_emit_class_files
)
1041 type_arg
= build_int_cst (NULL_TREE
, atype_value
);
1043 type_arg
= build_class_ref (prim_type
);
1045 return build3 (CALL_EXPR
, promote_type (type
),
1046 build_address_of (soft_newarray_node
),
1047 tree_cons (NULL_TREE
,
1049 build_tree_list (NULL_TREE
, length
)),
1053 /* Generates anewarray from a given CLASS_TYPE. Gets from the stack the size
1054 of the dimension. */
1057 build_anewarray (tree class_type
, tree length
)
1060 = build_java_array_type (class_type
,
1061 host_integerp (length
, 0)
1062 ? tree_low_cst (length
, 0) : -1);
1064 return build3 (CALL_EXPR
, promote_type (type
),
1065 build_address_of (soft_anewarray_node
),
1066 tree_cons (NULL_TREE
, length
,
1067 tree_cons (NULL_TREE
, build_class_ref (class_type
),
1068 build_tree_list (NULL_TREE
,
1069 null_pointer_node
))),
1073 /* Return a node the evaluates 'new TYPE[LENGTH]'. */
1076 build_new_array (tree type
, tree length
)
1078 if (JPRIMITIVE_TYPE_P (type
))
1079 return build_newarray (encode_newarray_type (type
), length
);
1081 return build_anewarray (TREE_TYPE (type
), length
);
1084 /* Generates a call to _Jv_NewMultiArray. multianewarray expects a
1085 class pointer, a number of dimensions and the matching number of
1086 dimensions. The argument list is NULL terminated. */
1089 expand_java_multianewarray (tree class_type
, int ndim
)
1092 tree args
= build_tree_list( NULL_TREE
, null_pointer_node
);
1094 for( i
= 0; i
< ndim
; i
++ )
1095 args
= tree_cons (NULL_TREE
, pop_value (int_type_node
), args
);
1097 push_value (build3 (CALL_EXPR
,
1098 promote_type (class_type
),
1099 build_address_of (soft_multianewarray_node
),
1100 tree_cons (NULL_TREE
, build_class_ref (class_type
),
1101 tree_cons (NULL_TREE
,
1102 build_int_cst (NULL_TREE
, ndim
),
1107 /* ARRAY[INDEX] <- RHS. build_java_check_indexed_type makes sure that
1108 ARRAY is an array type. May expand some bound checking and NULL
1109 pointer checking. RHS_TYPE_NODE we are going to store. In the case
1110 of the CHAR/BYTE/BOOLEAN SHORT, the type popped of the stack is an
1111 INT. In those cases, we make the conversion.
1113 if ARRAy is a reference type, the assignment is checked at run-time
1114 to make sure that the RHS can be assigned to the array element
1115 type. It is not necessary to generate this code if ARRAY is final. */
1118 expand_java_arraystore (tree rhs_type_node
)
1120 tree rhs_node
= pop_value ((INTEGRAL_TYPE_P (rhs_type_node
)
1121 && TYPE_PRECISION (rhs_type_node
) <= 32) ?
1122 int_type_node
: rhs_type_node
);
1123 tree index
= pop_value (int_type_node
);
1124 tree array_type
, array
;
1126 /* If we're processing an `aaload' we might as well just pick
1128 if (TREE_CODE (rhs_type_node
) == POINTER_TYPE
)
1130 array_type
= build_java_array_type (object_ptr_type_node
, -1);
1131 rhs_type_node
= object_ptr_type_node
;
1134 array_type
= build_java_array_type (rhs_type_node
, -1);
1136 array
= pop_value (array_type
);
1137 array
= build1 (NOP_EXPR
, promote_type (array_type
), array
);
1139 rhs_type_node
= build_java_check_indexed_type (array
, rhs_type_node
);
1141 flush_quick_stack ();
1143 index
= save_expr (index
);
1144 array
= save_expr (array
);
1146 if (TREE_CODE (rhs_type_node
) == POINTER_TYPE
)
1148 tree check
= build_java_arraystore_check (array
, rhs_node
);
1149 java_add_stmt (check
);
1152 array
= build_java_arrayaccess (array
, rhs_type_node
, index
);
1153 java_add_stmt (build2 (MODIFY_EXPR
, TREE_TYPE (array
), array
, rhs_node
));
1156 /* Expand the evaluation of ARRAY[INDEX]. build_java_check_indexed_type makes
1157 sure that LHS is an array type. May expand some bound checking and NULL
1159 LHS_TYPE_NODE is the type of ARRAY[INDEX]. But in the case of CHAR/BYTE/
1160 BOOLEAN/SHORT, we push a promoted type back to the stack.
1164 expand_java_arrayload (tree lhs_type_node
)
1167 tree index_node
= pop_value (int_type_node
);
1171 /* If we're processing an `aaload' we might as well just pick
1173 if (TREE_CODE (lhs_type_node
) == POINTER_TYPE
)
1175 array_type
= build_java_array_type (object_ptr_type_node
, -1);
1176 lhs_type_node
= object_ptr_type_node
;
1179 array_type
= build_java_array_type (lhs_type_node
, -1);
1180 array_node
= pop_value (array_type
);
1181 array_node
= build1 (NOP_EXPR
, promote_type (array_type
), array_node
);
1183 index_node
= save_expr (index_node
);
1184 array_node
= save_expr (array_node
);
1186 lhs_type_node
= build_java_check_indexed_type (array_node
,
1188 load_node
= build_java_arrayaccess (array_node
,
1191 if (INTEGRAL_TYPE_P (lhs_type_node
) && TYPE_PRECISION (lhs_type_node
) <= 32)
1192 load_node
= fold_build1 (NOP_EXPR
, int_type_node
, load_node
);
1193 push_value (load_node
);
1196 /* Expands .length. Makes sure that we deal with and array and may expand
1197 a NULL check on the array object. */
1200 expand_java_array_length (void)
1202 tree array
= pop_value (ptr_type_node
);
1203 tree length
= build_java_array_length_access (array
);
1205 push_value (length
);
1208 /* Emit code for the call to _Jv_Monitor{Enter,Exit}. CALL can be
1209 either soft_monitorenter_node or soft_monitorexit_node. */
1212 build_java_monitor (tree call
, tree object
)
1214 return build3 (CALL_EXPR
,
1216 build_address_of (call
),
1217 build_tree_list (NULL_TREE
, object
),
1221 /* Emit code for one of the PUSHC instructions. */
1224 expand_java_pushc (int ival
, tree type
)
1227 if (type
== ptr_type_node
&& ival
== 0)
1228 value
= null_pointer_node
;
1229 else if (type
== int_type_node
|| type
== long_type_node
)
1230 value
= build_int_cst (type
, ival
);
1231 else if (type
== float_type_node
|| type
== double_type_node
)
1234 REAL_VALUE_FROM_INT (x
, ival
, 0, TYPE_MODE (type
));
1235 value
= build_real (type
, x
);
1244 expand_java_return (tree type
)
1246 if (type
== void_type_node
)
1247 java_add_stmt (build1 (RETURN_EXPR
, void_type_node
, NULL
));
1250 tree retval
= pop_value (type
);
1251 tree res
= DECL_RESULT (current_function_decl
);
1252 retval
= build2 (MODIFY_EXPR
, TREE_TYPE (res
), res
, retval
);
1254 /* Handle the situation where the native integer type is smaller
1255 than the JVM integer. It can happen for many cross compilers.
1256 The whole if expression just goes away if INT_TYPE_SIZE < 32
1258 if (INT_TYPE_SIZE
< 32
1259 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (res
)))
1260 < GET_MODE_SIZE (TYPE_MODE (type
))))
1261 retval
= build1(NOP_EXPR
, TREE_TYPE(res
), retval
);
1263 TREE_SIDE_EFFECTS (retval
) = 1;
1264 java_add_stmt (build1 (RETURN_EXPR
, TREE_TYPE (retval
), retval
));
1269 expand_load_internal (int index
, tree type
, int pc
)
1272 tree var
= find_local_variable (index
, type
, pc
);
1274 /* Now VAR is the VAR_DECL (or PARM_DECL) that we are going to push
1275 on the stack. If there is an assignment to this VAR_DECL between
1276 the stack push and the use, then the wrong code could be
1277 generated. To avoid this we create a new local and copy our
1278 value into it. Then we push this new local on the stack.
1279 Hopefully this all gets optimized out. */
1280 copy
= build_decl (VAR_DECL
, NULL_TREE
, type
);
1281 if ((INTEGRAL_TYPE_P (type
) || POINTER_TYPE_P (type
))
1282 && TREE_TYPE (copy
) != TREE_TYPE (var
))
1283 var
= convert (type
, var
);
1284 java_add_local_var (copy
);
1285 java_add_stmt (build2 (MODIFY_EXPR
, TREE_TYPE (var
), copy
, var
));
1291 build_address_of (tree value
)
1293 return build1 (ADDR_EXPR
, build_pointer_type (TREE_TYPE (value
)), value
);
1297 class_has_finalize_method (tree type
)
1299 tree super
= CLASSTYPE_SUPER (type
);
1301 if (super
== NULL_TREE
)
1302 return false; /* Every class with a real finalizer inherits */
1303 /* from java.lang.Object. */
1305 return HAS_FINALIZER_P (type
) || class_has_finalize_method (super
);
1309 java_create_object (tree type
)
1311 tree alloc_node
= (class_has_finalize_method (type
)
1313 : alloc_no_finalizer_node
);
1315 return build3 (CALL_EXPR
, promote_type (type
),
1316 build_address_of (alloc_node
),
1317 build_tree_list (NULL_TREE
, build_class_ref (type
)),
1322 expand_java_NEW (tree type
)
1326 alloc_node
= (class_has_finalize_method (type
) ? alloc_object_node
1327 : alloc_no_finalizer_node
);
1328 if (! CLASS_LOADED_P (type
))
1329 load_class (type
, 1);
1330 safe_layout_class (type
);
1331 push_value (build3 (CALL_EXPR
, promote_type (type
),
1332 build_address_of (alloc_node
),
1333 build_tree_list (NULL_TREE
, build_class_ref (type
)),
1337 /* This returns an expression which will extract the class of an
1341 build_get_class (tree value
)
1343 tree class_field
= lookup_field (&dtable_type
, get_identifier ("class"));
1344 tree vtable_field
= lookup_field (&object_type_node
,
1345 get_identifier ("vtable"));
1346 tree tmp
= build3 (COMPONENT_REF
, dtable_ptr_type
,
1347 build_java_indirect_ref (object_type_node
, value
,
1348 flag_check_references
),
1349 vtable_field
, NULL_TREE
);
1350 return build3 (COMPONENT_REF
, class_ptr_type
,
1351 build1 (INDIRECT_REF
, dtable_type
, tmp
),
1352 class_field
, NULL_TREE
);
1355 /* This builds the tree representation of the `instanceof' operator.
1356 It tries various tricks to optimize this in cases where types are
1360 build_instanceof (tree value
, tree type
)
1363 tree itype
= TREE_TYPE (TREE_TYPE (soft_instanceof_node
));
1364 tree valtype
= TREE_TYPE (TREE_TYPE (value
));
1365 tree valclass
= TYPE_NAME (valtype
);
1368 /* When compiling from bytecode, we need to ensure that TYPE has
1370 if (CLASS_P (type
) && ! CLASS_LOADED_P (type
))
1372 load_class (type
, 1);
1373 safe_layout_class (type
);
1374 if (! TYPE_SIZE (type
) || TREE_CODE (TYPE_SIZE (type
)) == ERROR_MARK
)
1375 return error_mark_node
;
1377 klass
= TYPE_NAME (type
);
1379 if (type
== object_type_node
|| inherits_from_p (valtype
, type
))
1381 /* Anything except `null' is an instance of Object. Likewise,
1382 if the object is known to be an instance of the class, then
1383 we only need to check for `null'. */
1384 expr
= build2 (NE_EXPR
, itype
, value
, null_pointer_node
);
1386 else if (flag_verify_invocations
1387 && ! TYPE_ARRAY_P (type
)
1388 && ! TYPE_ARRAY_P (valtype
)
1389 && DECL_P (klass
) && DECL_P (valclass
)
1390 && ! CLASS_INTERFACE (valclass
)
1391 && ! CLASS_INTERFACE (klass
)
1392 && ! inherits_from_p (type
, valtype
)
1393 && (CLASS_FINAL (klass
)
1394 || ! inherits_from_p (valtype
, type
)))
1396 /* The classes are from different branches of the derivation
1397 tree, so we immediately know the answer. */
1398 expr
= boolean_false_node
;
1400 else if (DECL_P (klass
) && CLASS_FINAL (klass
))
1402 tree save
= save_expr (value
);
1403 expr
= build3 (COND_EXPR
, itype
,
1404 build2 (NE_EXPR
, boolean_type_node
,
1405 save
, null_pointer_node
),
1406 build2 (EQ_EXPR
, itype
,
1407 build_get_class (save
),
1408 build_class_ref (type
)),
1409 boolean_false_node
);
1413 expr
= build3 (CALL_EXPR
, itype
,
1414 build_address_of (soft_instanceof_node
),
1415 tree_cons (NULL_TREE
, value
,
1416 build_tree_list (NULL_TREE
,
1417 build_class_ref (type
))),
1420 TREE_SIDE_EFFECTS (expr
) = TREE_SIDE_EFFECTS (value
);
1425 expand_java_INSTANCEOF (tree type
)
1427 tree value
= pop_value (object_ptr_type_node
);
1428 value
= build_instanceof (value
, type
);
1433 expand_java_CHECKCAST (tree type
)
1435 tree value
= pop_value (ptr_type_node
);
1436 value
= build3 (CALL_EXPR
, promote_type (type
),
1437 build_address_of (soft_checkcast_node
),
1438 tree_cons (NULL_TREE
, build_class_ref (type
),
1439 build_tree_list (NULL_TREE
, value
)),
1445 expand_iinc (unsigned int local_var_index
, int ival
, int pc
)
1447 tree local_var
, res
;
1448 tree constant_value
;
1450 flush_quick_stack ();
1451 local_var
= find_local_variable (local_var_index
, int_type_node
, pc
);
1452 constant_value
= build_int_cst (NULL_TREE
, ival
);
1453 res
= fold_build2 (PLUS_EXPR
, int_type_node
, local_var
, constant_value
);
1454 java_add_stmt (build2 (MODIFY_EXPR
, TREE_TYPE (local_var
), local_var
, res
));
1455 update_aliases (local_var
, local_var_index
, pc
);
1460 build_java_soft_divmod (enum tree_code op
, tree type
, tree op1
, tree op2
)
1463 tree arg1
= convert (type
, op1
);
1464 tree arg2
= convert (type
, op2
);
1466 if (type
== int_type_node
)
1470 case TRUNC_DIV_EXPR
:
1471 call
= soft_idiv_node
;
1473 case TRUNC_MOD_EXPR
:
1474 call
= soft_irem_node
;
1480 else if (type
== long_type_node
)
1484 case TRUNC_DIV_EXPR
:
1485 call
= soft_ldiv_node
;
1487 case TRUNC_MOD_EXPR
:
1488 call
= soft_lrem_node
;
1498 call
= build3 (CALL_EXPR
, type
,
1499 build_address_of (call
),
1500 tree_cons (NULL_TREE
, arg1
,
1501 build_tree_list (NULL_TREE
, arg2
)),
1508 build_java_binop (enum tree_code op
, tree type
, tree arg1
, tree arg2
)
1515 tree u_type
= java_unsigned_type (type
);
1516 arg1
= convert (u_type
, arg1
);
1517 arg1
= build_java_binop (RSHIFT_EXPR
, u_type
, arg1
, arg2
);
1518 return convert (type
, arg1
);
1522 mask
= build_int_cst (NULL_TREE
,
1523 TYPE_PRECISION (TREE_TYPE (arg1
)) - 1);
1524 arg2
= fold_build2 (BIT_AND_EXPR
, int_type_node
, arg2
, mask
);
1527 case COMPARE_L_EXPR
: /* arg1 > arg2 ? 1 : arg1 == arg2 ? 0 : -1 */
1528 case COMPARE_G_EXPR
: /* arg1 < arg2 ? -1 : arg1 == arg2 ? 0 : 1 */
1529 arg1
= save_expr (arg1
); arg2
= save_expr (arg2
);
1531 tree ifexp1
= fold_build2 (op
== COMPARE_L_EXPR
? GT_EXPR
: LT_EXPR
,
1532 boolean_type_node
, arg1
, arg2
);
1533 tree ifexp2
= fold_build2 (EQ_EXPR
, boolean_type_node
, arg1
, arg2
);
1534 tree second_compare
= fold_build3 (COND_EXPR
, int_type_node
,
1535 ifexp2
, integer_zero_node
,
1536 op
== COMPARE_L_EXPR
1537 ? integer_minus_one_node
1538 : integer_one_node
);
1539 return fold_build3 (COND_EXPR
, int_type_node
, ifexp1
,
1540 op
== COMPARE_L_EXPR
? integer_one_node
1541 : integer_minus_one_node
,
1545 arg1
= save_expr (arg1
); arg2
= save_expr (arg2
);
1547 tree ifexp1
= fold_build2 (LT_EXPR
, boolean_type_node
, arg1
, arg2
);
1548 tree ifexp2
= fold_build2 (GT_EXPR
, boolean_type_node
, arg1
, arg2
);
1549 tree second_compare
= fold_build3 (COND_EXPR
, int_type_node
,
1550 ifexp2
, integer_one_node
,
1552 return fold_build3 (COND_EXPR
, int_type_node
,
1553 ifexp1
, integer_minus_one_node
, second_compare
);
1555 case TRUNC_DIV_EXPR
:
1556 case TRUNC_MOD_EXPR
:
1557 if (TREE_CODE (type
) == REAL_TYPE
1558 && op
== TRUNC_MOD_EXPR
)
1561 if (type
!= double_type_node
)
1563 arg1
= convert (double_type_node
, arg1
);
1564 arg2
= convert (double_type_node
, arg2
);
1566 call
= build3 (CALL_EXPR
, double_type_node
,
1567 build_address_of (soft_fmod_node
),
1568 tree_cons (NULL_TREE
, arg1
,
1569 build_tree_list (NULL_TREE
, arg2
)),
1571 if (type
!= double_type_node
)
1572 call
= convert (type
, call
);
1576 if (TREE_CODE (type
) == INTEGER_TYPE
1577 && flag_use_divide_subroutine
1578 && ! flag_syntax_only
)
1579 return build_java_soft_divmod (op
, type
, arg1
, arg2
);
1584 return fold_build2 (op
, type
, arg1
, arg2
);
1588 expand_java_binop (tree type
, enum tree_code op
)
1598 rtype
= int_type_node
;
1599 rarg
= pop_value (rtype
);
1602 rarg
= pop_value (rtype
);
1604 larg
= pop_value (ltype
);
1605 push_value (build_java_binop (op
, type
, larg
, rarg
));
1608 /* Lookup the field named NAME in *TYPEP or its super classes.
1609 If not found, return NULL_TREE.
1610 (If the *TYPEP is not found, or if the field reference is
1611 ambiguous, return error_mark_node.)
1612 If found, return the FIELD_DECL, and set *TYPEP to the
1613 class containing the field. */
1616 lookup_field (tree
*typep
, tree name
)
1618 if (CLASS_P (*typep
) && !CLASS_LOADED_P (*typep
))
1620 load_class (*typep
, 1);
1621 safe_layout_class (*typep
);
1622 if (!TYPE_SIZE (*typep
) || TREE_CODE (TYPE_SIZE (*typep
)) == ERROR_MARK
)
1623 return error_mark_node
;
1627 tree field
, binfo
, base_binfo
;
1631 for (field
= TYPE_FIELDS (*typep
); field
; field
= TREE_CHAIN (field
))
1632 if (DECL_NAME (field
) == name
)
1635 /* Process implemented interfaces. */
1636 save_field
= NULL_TREE
;
1637 for (binfo
= TYPE_BINFO (*typep
), i
= 0;
1638 BINFO_BASE_ITERATE (binfo
, i
, base_binfo
); i
++)
1640 tree t
= BINFO_TYPE (base_binfo
);
1641 if ((field
= lookup_field (&t
, name
)))
1643 if (save_field
== field
)
1645 if (save_field
== NULL_TREE
)
1649 tree i1
= DECL_CONTEXT (save_field
);
1650 tree i2
= DECL_CONTEXT (field
);
1651 error ("reference %qs is ambiguous: appears in interface %qs and interface %qs",
1652 IDENTIFIER_POINTER (name
),
1653 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (i1
))),
1654 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (i2
))));
1655 return error_mark_node
;
1660 if (save_field
!= NULL_TREE
)
1663 *typep
= CLASSTYPE_SUPER (*typep
);
1668 /* Look up the field named NAME in object SELF_VALUE,
1669 which has class SELF_CLASS (a non-handle RECORD_TYPE).
1670 SELF_VALUE is NULL_TREE if looking for a static field. */
1673 build_field_ref (tree self_value
, tree self_class
, tree name
)
1675 tree base_class
= self_class
;
1676 tree field_decl
= lookup_field (&base_class
, name
);
1677 if (field_decl
== NULL_TREE
)
1679 error ("field %qs not found", IDENTIFIER_POINTER (name
));
1680 return error_mark_node
;
1682 if (self_value
== NULL_TREE
)
1684 return build_static_field_ref (field_decl
);
1688 int check
= (flag_check_references
1689 && ! (DECL_P (self_value
)
1690 && DECL_NAME (self_value
) == this_identifier_node
));
1692 tree base_type
= promote_type (base_class
);
1693 if (base_type
!= TREE_TYPE (self_value
))
1694 self_value
= fold_build1 (NOP_EXPR
, base_type
, self_value
);
1695 if (! flag_syntax_only
&& flag_indirect_dispatch
)
1698 = build_int_cst (NULL_TREE
, get_symbol_table_index
1699 (field_decl
, &TYPE_OTABLE_METHODS (output_class
)));
1701 = build4 (ARRAY_REF
, integer_type_node
,
1702 TYPE_OTABLE_DECL (output_class
), otable_index
,
1703 NULL_TREE
, NULL_TREE
);
1706 field_offset
= fold (convert (sizetype
, field_offset
));
1708 = fold_build2 (PLUS_EXPR
,
1709 build_pointer_type (TREE_TYPE (field_decl
)),
1710 self_value
, field_offset
);
1711 return fold_build1 (INDIRECT_REF
, TREE_TYPE (field_decl
), address
);
1714 self_value
= build_java_indirect_ref (TREE_TYPE (TREE_TYPE (self_value
)),
1716 return fold_build3 (COMPONENT_REF
, TREE_TYPE (field_decl
),
1717 self_value
, field_decl
, NULL_TREE
);
1722 lookup_label (int pc
)
1726 if (pc
> highest_label_pc_this_method
)
1727 highest_label_pc_this_method
= pc
;
1728 ASM_GENERATE_INTERNAL_LABEL(buf
, "LJpc=", start_label_pc_this_method
+ pc
);
1729 name
= get_identifier (buf
);
1730 if (IDENTIFIER_LOCAL_VALUE (name
))
1731 return IDENTIFIER_LOCAL_VALUE (name
);
1734 /* The type of the address of a label is return_address_type_node. */
1735 tree decl
= create_label_decl (name
);
1736 LABEL_PC (decl
) = pc
;
1737 return pushdecl (decl
);
1741 /* Generate a unique name for the purpose of loops and switches
1742 labels, and try-catch-finally blocks label or temporary variables. */
1745 generate_name (void)
1747 static int l_number
= 0;
1749 ASM_GENERATE_INTERNAL_LABEL(buff
, "LJv", l_number
);
1751 return get_identifier (buff
);
1755 create_label_decl (tree name
)
1758 decl
= build_decl (LABEL_DECL
, name
,
1759 TREE_TYPE (return_address_type_node
));
1760 DECL_CONTEXT (decl
) = current_function_decl
;
1761 DECL_IGNORED_P (decl
) = 1;
1765 /* This maps a bytecode offset (PC) to various flags. */
1766 char *instruction_bits
;
1769 note_label (int current_pc ATTRIBUTE_UNUSED
, int target_pc
)
1771 lookup_label (target_pc
);
1772 instruction_bits
[target_pc
] |= BCODE_JUMP_TARGET
;
1775 /* Emit code to jump to TARGET_PC if VALUE1 CONDITION VALUE2,
1776 where CONDITION is one of one the compare operators. */
1779 expand_compare (enum tree_code condition
, tree value1
, tree value2
,
1782 tree target
= lookup_label (target_pc
);
1783 tree cond
= fold_build2 (condition
, boolean_type_node
, value1
, value2
);
1785 (build3 (COND_EXPR
, void_type_node
, java_truthvalue_conversion (cond
),
1786 build1 (GOTO_EXPR
, void_type_node
, target
),
1787 build_java_empty_stmt ()));
1790 /* Emit code for a TEST-type opcode. */
1793 expand_test (enum tree_code condition
, tree type
, int target_pc
)
1795 tree value1
, value2
;
1796 flush_quick_stack ();
1797 value1
= pop_value (type
);
1798 value2
= (type
== ptr_type_node
) ? null_pointer_node
: integer_zero_node
;
1799 expand_compare (condition
, value1
, value2
, target_pc
);
1802 /* Emit code for a COND-type opcode. */
1805 expand_cond (enum tree_code condition
, tree type
, int target_pc
)
1807 tree value1
, value2
;
1808 flush_quick_stack ();
1809 /* note: pop values in opposite order */
1810 value2
= pop_value (type
);
1811 value1
= pop_value (type
);
1812 /* Maybe should check value1 and value2 for type compatibility ??? */
1813 expand_compare (condition
, value1
, value2
, target_pc
);
1817 expand_java_goto (int target_pc
)
1819 tree target_label
= lookup_label (target_pc
);
1820 flush_quick_stack ();
1821 java_add_stmt (build1 (GOTO_EXPR
, void_type_node
, target_label
));
1825 expand_java_switch (tree selector
, int default_pc
)
1827 tree switch_expr
, x
;
1829 flush_quick_stack ();
1830 switch_expr
= build3 (SWITCH_EXPR
, TREE_TYPE (selector
), selector
,
1831 NULL_TREE
, NULL_TREE
);
1832 java_add_stmt (switch_expr
);
1834 x
= build3 (CASE_LABEL_EXPR
, void_type_node
, NULL_TREE
, NULL_TREE
,
1835 create_artificial_label ());
1836 append_to_statement_list (x
, &SWITCH_BODY (switch_expr
));
1838 x
= build1 (GOTO_EXPR
, void_type_node
, lookup_label (default_pc
));
1839 append_to_statement_list (x
, &SWITCH_BODY (switch_expr
));
1845 expand_java_add_case (tree switch_expr
, int match
, int target_pc
)
1849 value
= build_int_cst (TREE_TYPE (switch_expr
), match
);
1851 x
= build3 (CASE_LABEL_EXPR
, void_type_node
, value
, NULL_TREE
,
1852 create_artificial_label ());
1853 append_to_statement_list (x
, &SWITCH_BODY (switch_expr
));
1855 x
= build1 (GOTO_EXPR
, void_type_node
, lookup_label (target_pc
));
1856 append_to_statement_list (x
, &SWITCH_BODY (switch_expr
));
1860 pop_arguments (tree arg_types
)
1862 if (arg_types
== end_params_node
)
1864 if (TREE_CODE (arg_types
) == TREE_LIST
)
1866 tree tail
= pop_arguments (TREE_CHAIN (arg_types
));
1867 tree type
= TREE_VALUE (arg_types
);
1868 tree arg
= pop_value (type
);
1870 /* We simply cast each argument to its proper type. This is
1871 needed since we lose type information coming out of the
1872 verifier. We also have to do this when we pop an integer
1873 type that must be promoted for the function call. */
1874 if (TREE_CODE (type
) == POINTER_TYPE
)
1875 arg
= build1 (NOP_EXPR
, type
, arg
);
1876 else if (targetm
.calls
.promote_prototypes (type
)
1877 && TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
)
1878 && INTEGRAL_TYPE_P (type
))
1879 arg
= convert (integer_type_node
, arg
);
1880 return tree_cons (NULL_TREE
, arg
, tail
);
1885 /* Attach to PTR (a block) the declaration found in ENTRY. */
1888 attach_init_test_initialization_flags (void **entry
, void *ptr
)
1890 tree block
= (tree
)ptr
;
1891 struct treetreehash_entry
*ite
= (struct treetreehash_entry
*) *entry
;
1893 if (block
!= error_mark_node
)
1895 if (TREE_CODE (block
) == BIND_EXPR
)
1897 tree body
= BIND_EXPR_BODY (block
);
1898 TREE_CHAIN (ite
->value
) = BIND_EXPR_VARS (block
);
1899 BIND_EXPR_VARS (block
) = ite
->value
;
1900 body
= build2 (COMPOUND_EXPR
, void_type_node
,
1901 build1 (DECL_EXPR
, void_type_node
, ite
->value
), body
);
1902 BIND_EXPR_BODY (block
) = body
;
1906 tree body
= BLOCK_SUBBLOCKS (block
);
1907 TREE_CHAIN (ite
->value
) = BLOCK_EXPR_DECLS (block
);
1908 BLOCK_EXPR_DECLS (block
) = ite
->value
;
1909 body
= build2 (COMPOUND_EXPR
, void_type_node
,
1910 build1 (DECL_EXPR
, void_type_node
, ite
->value
), body
);
1911 BLOCK_SUBBLOCKS (block
) = body
;
1918 /* Build an expression to initialize the class CLAS.
1919 if EXPR is non-NULL, returns an expression to first call the initializer
1920 (if it is needed) and then calls EXPR. */
1923 build_class_init (tree clas
, tree expr
)
1927 /* An optimization: if CLAS is a superclass of the class we're
1928 compiling, we don't need to initialize it. However, if CLAS is
1929 an interface, it won't necessarily be initialized, even if we
1931 if ((! CLASS_INTERFACE (TYPE_NAME (clas
))
1932 && inherits_from_p (current_class
, clas
))
1933 || current_class
== clas
)
1936 if (always_initialize_class_p
)
1938 init
= build3 (CALL_EXPR
, void_type_node
,
1939 build_address_of (soft_initclass_node
),
1940 build_tree_list (NULL_TREE
, build_class_ref (clas
)),
1942 TREE_SIDE_EFFECTS (init
) = 1;
1946 tree
*init_test_decl
;
1948 init_test_decl
= java_treetreehash_new
1949 (DECL_FUNCTION_INIT_TEST_TABLE (current_function_decl
), clas
);
1951 if (*init_test_decl
== NULL
)
1953 /* Build a declaration and mark it as a flag used to track
1954 static class initializations. */
1955 decl
= build_decl (VAR_DECL
, NULL_TREE
,
1957 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl
);
1958 LOCAL_CLASS_INITIALIZATION_FLAG (decl
) = 1;
1959 DECL_CONTEXT (decl
) = current_function_decl
;
1960 DECL_FUNCTION_INIT_TEST_CLASS (decl
) = clas
;
1961 /* Tell the check-init code to ignore this decl when not
1962 optimizing class initialization. */
1963 if (!STATIC_CLASS_INIT_OPT_P ())
1964 DECL_BIT_INDEX (decl
) = -1;
1965 DECL_INITIAL (decl
) = boolean_false_node
;
1966 /* Don't emit any symbolic debugging info for this decl. */
1967 DECL_IGNORED_P (decl
) = 1;
1968 *init_test_decl
= decl
;
1971 init
= build3 (CALL_EXPR
, void_type_node
,
1972 build_address_of (soft_initclass_node
),
1973 build_tree_list (NULL_TREE
, build_class_ref (clas
)),
1975 TREE_SIDE_EFFECTS (init
) = 1;
1976 init
= build3 (COND_EXPR
, void_type_node
,
1977 build2 (EQ_EXPR
, boolean_type_node
,
1978 *init_test_decl
, boolean_false_node
),
1979 init
, integer_zero_node
);
1980 TREE_SIDE_EFFECTS (init
) = 1;
1981 init
= build2 (COMPOUND_EXPR
, TREE_TYPE (expr
), init
,
1982 build2 (MODIFY_EXPR
, boolean_type_node
,
1983 *init_test_decl
, boolean_true_node
));
1984 TREE_SIDE_EFFECTS (init
) = 1;
1987 if (expr
!= NULL_TREE
)
1989 expr
= build2 (COMPOUND_EXPR
, TREE_TYPE (expr
), init
, expr
);
1990 TREE_SIDE_EFFECTS (expr
) = 1;
1997 build_known_method_ref (tree method
, tree method_type ATTRIBUTE_UNUSED
,
1998 tree self_type
, tree method_signature ATTRIBUTE_UNUSED
,
1999 tree arg_list ATTRIBUTE_UNUSED
)
2002 if (is_compiled_class (self_type
))
2004 /* With indirect dispatch we have to use indirect calls for all
2005 publicly visible methods or gcc will use PLT indirections
2006 to reach them. We also have to use indirect dispatch for all
2007 external methods. */
2008 if (! flag_indirect_dispatch
2009 || (! DECL_EXTERNAL (method
) && ! TREE_PUBLIC (method
)))
2011 func
= build1 (ADDR_EXPR
, build_pointer_type (TREE_TYPE (method
)),
2017 = build_int_cst (NULL_TREE
, get_symbol_table_index
2018 (method
, &TYPE_ATABLE_METHODS (output_class
)));
2020 = build4 (ARRAY_REF
,
2021 TREE_TYPE (TREE_TYPE (TYPE_ATABLE_DECL (output_class
))),
2022 TYPE_ATABLE_DECL (output_class
), table_index
,
2023 NULL_TREE
, NULL_TREE
);
2025 func
= convert (method_ptr_type_node
, func
);
2029 /* We don't know whether the method has been (statically) compiled.
2030 Compile this code to get a reference to the method's code:
2032 SELF_TYPE->methods[METHOD_INDEX].ncode
2036 int method_index
= 0;
2039 /* The method might actually be declared in some superclass, so
2040 we have to use its class context, not the caller's notion of
2041 where the method is. */
2042 self_type
= DECL_CONTEXT (method
);
2043 ref
= build_class_ref (self_type
);
2044 ref
= build1 (INDIRECT_REF
, class_type_node
, ref
);
2045 if (ncode_ident
== NULL_TREE
)
2046 ncode_ident
= get_identifier ("ncode");
2047 if (methods_ident
== NULL_TREE
)
2048 methods_ident
= get_identifier ("methods");
2049 ref
= build3 (COMPONENT_REF
, method_ptr_type_node
, ref
,
2050 lookup_field (&class_type_node
, methods_ident
),
2052 for (meth
= TYPE_METHODS (self_type
);
2053 ; meth
= TREE_CHAIN (meth
))
2057 if (meth
== NULL_TREE
)
2058 fatal_error ("method '%s' not found in class",
2059 IDENTIFIER_POINTER (DECL_NAME (method
)));
2062 method_index
*= int_size_in_bytes (method_type_node
);
2063 ref
= fold_build2 (PLUS_EXPR
, method_ptr_type_node
,
2064 ref
, build_int_cst (NULL_TREE
, method_index
));
2065 ref
= build1 (INDIRECT_REF
, method_type_node
, ref
);
2066 func
= build3 (COMPONENT_REF
, nativecode_ptr_type_node
,
2067 ref
, lookup_field (&method_type_node
, ncode_ident
),
2074 invoke_build_dtable (int is_invoke_interface
, tree arg_list
)
2076 tree dtable
, objectref
;
2078 TREE_VALUE (arg_list
) = save_expr (TREE_VALUE (arg_list
));
2080 /* If we're dealing with interfaces and if the objectref
2081 argument is an array then get the dispatch table of the class
2082 Object rather than the one from the objectref. */
2083 objectref
= (is_invoke_interface
2084 && is_array_type_p (TREE_TYPE (TREE_VALUE (arg_list
)))
2085 ? build_class_ref (object_type_node
) : TREE_VALUE (arg_list
));
2087 if (dtable_ident
== NULL_TREE
)
2088 dtable_ident
= get_identifier ("vtable");
2089 dtable
= build_java_indirect_ref (object_type_node
, objectref
,
2090 flag_check_references
);
2091 dtable
= build3 (COMPONENT_REF
, dtable_ptr_type
, dtable
,
2092 lookup_field (&object_type_node
, dtable_ident
), NULL_TREE
);
2097 /* Determine the index in SYMBOL_TABLE for a reference to the decl
2098 T. If this decl has not been seen before, it will be added to the
2099 [oa]table_methods. If it has, the existing table slot will be
2103 get_symbol_table_index (tree t
, tree
*symbol_table
)
2108 if (*symbol_table
== NULL_TREE
)
2110 *symbol_table
= build_tree_list (t
, t
);
2114 method_list
= *symbol_table
;
2118 tree value
= TREE_VALUE (method_list
);
2122 if (TREE_CHAIN (method_list
) == NULL_TREE
)
2125 method_list
= TREE_CHAIN (method_list
);
2128 TREE_CHAIN (method_list
) = build_tree_list (t
, t
);
2133 build_invokevirtual (tree dtable
, tree method
)
2136 tree nativecode_ptr_ptr_type_node
2137 = build_pointer_type (nativecode_ptr_type_node
);
2141 if (flag_indirect_dispatch
)
2143 if (CLASS_INTERFACE (TYPE_NAME (DECL_CONTEXT (method
))))
2147 = build_int_cst (NULL_TREE
, get_symbol_table_index
2148 (method
, &TYPE_OTABLE_METHODS (output_class
)));
2149 method_index
= build4 (ARRAY_REF
, integer_type_node
,
2150 TYPE_OTABLE_DECL (output_class
),
2151 otable_index
, NULL_TREE
, NULL_TREE
);
2155 /* We fetch the DECL_VINDEX field directly here, rather than
2156 using get_method_index(). DECL_VINDEX is the true offset
2157 from the vtable base to a method, regrdless of any extra
2158 words inserted at the start of the vtable. */
2159 method_index
= DECL_VINDEX (method
);
2160 method_index
= size_binop (MULT_EXPR
, method_index
,
2161 TYPE_SIZE_UNIT (nativecode_ptr_ptr_type_node
));
2162 if (TARGET_VTABLE_USES_DESCRIPTORS
)
2163 method_index
= size_binop (MULT_EXPR
, method_index
,
2164 size_int (TARGET_VTABLE_USES_DESCRIPTORS
));
2167 func
= fold_build2 (PLUS_EXPR
, nativecode_ptr_ptr_type_node
, dtable
,
2168 convert (nativecode_ptr_ptr_type_node
, method_index
));
2170 if (TARGET_VTABLE_USES_DESCRIPTORS
)
2171 func
= build1 (NOP_EXPR
, nativecode_ptr_type_node
, func
);
2173 func
= build1 (INDIRECT_REF
, nativecode_ptr_type_node
, func
);
2178 static GTY(()) tree class_ident
;
2180 build_invokeinterface (tree dtable
, tree method
)
2186 /* We expand invokeinterface here. */
2188 if (class_ident
== NULL_TREE
)
2189 class_ident
= get_identifier ("class");
2191 dtable
= build_java_indirect_ref (dtable_type
, dtable
,
2192 flag_check_references
);
2193 dtable
= build3 (COMPONENT_REF
, class_ptr_type
, dtable
,
2194 lookup_field (&dtable_type
, class_ident
), NULL_TREE
);
2196 interface
= DECL_CONTEXT (method
);
2197 if (! CLASS_INTERFACE (TYPE_NAME (interface
)))
2199 layout_class_methods (interface
);
2201 if (flag_indirect_dispatch
)
2204 = 2 * (get_symbol_table_index
2205 (method
, &TYPE_ITABLE_METHODS (output_class
)));
2207 = build4 (ARRAY_REF
,
2208 TREE_TYPE (TREE_TYPE (TYPE_ITABLE_DECL (output_class
))),
2209 TYPE_ITABLE_DECL (output_class
),
2210 build_int_cst (NULL_TREE
, itable_index
-1),
2211 NULL_TREE
, NULL_TREE
);
2213 = build4 (ARRAY_REF
,
2214 TREE_TYPE (TREE_TYPE (TYPE_ITABLE_DECL (output_class
))),
2215 TYPE_ITABLE_DECL (output_class
),
2216 build_int_cst (NULL_TREE
, itable_index
),
2217 NULL_TREE
, NULL_TREE
);
2218 interface
= convert (class_ptr_type
, interface
);
2219 idx
= convert (integer_type_node
, idx
);
2223 idx
= build_int_cst (NULL_TREE
,
2224 get_interface_method_index (method
, interface
));
2225 interface
= build_class_ref (interface
);
2228 lookup_arg
= tree_cons (NULL_TREE
, dtable
,
2229 tree_cons (NULL_TREE
, interface
,
2230 build_tree_list (NULL_TREE
, idx
)));
2232 return build3 (CALL_EXPR
, ptr_type_node
,
2233 build_address_of (soft_lookupinterfacemethod_node
),
2234 lookup_arg
, NULL_TREE
);
2237 /* Expand one of the invoke_* opcodes.
2238 OPCODE is the specific opcode.
2239 METHOD_REF_INDEX is an index into the constant pool.
2240 NARGS is the number of arguments, or -1 if not specified. */
2243 expand_invoke (int opcode
, int method_ref_index
, int nargs ATTRIBUTE_UNUSED
)
2245 tree method_signature
2246 = COMPONENT_REF_SIGNATURE(¤t_jcf
->cpool
, method_ref_index
);
2247 tree method_name
= COMPONENT_REF_NAME (¤t_jcf
->cpool
,
2250 = get_class_constant (current_jcf
,
2251 COMPONENT_REF_CLASS_INDEX(¤t_jcf
->cpool
,
2253 const char *const self_name
2254 = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (self_type
)));
2255 tree call
, func
, method
, arg_list
, method_type
;
2256 tree check
= NULL_TREE
;
2258 if (! CLASS_LOADED_P (self_type
))
2260 load_class (self_type
, 1);
2261 safe_layout_class (self_type
);
2262 if (TREE_CODE (TYPE_SIZE (self_type
)) == ERROR_MARK
)
2263 fatal_error ("failed to find class '%s'", self_name
);
2265 layout_class_methods (self_type
);
2267 if (ID_INIT_P (method_name
))
2268 method
= lookup_java_constructor (self_type
, method_signature
);
2270 method
= lookup_java_method (self_type
, method_name
, method_signature
);
2272 /* We've found a method in an interface, but this isn't an interface
2274 if (opcode
!= OPCODE_invokeinterface
2276 && (CLASS_INTERFACE (TYPE_NAME (DECL_CONTEXT (method
)))))
2279 /* We've found a non-interface method but we are making an
2280 interface call. This can happen if the interface overrides a
2281 method in Object. */
2282 if (! flag_verify_invocations
2283 && opcode
== OPCODE_invokeinterface
2285 && ! CLASS_INTERFACE (TYPE_NAME (DECL_CONTEXT (method
))))
2288 if (method
== NULL_TREE
)
2290 if (flag_verify_invocations
|| ! flag_indirect_dispatch
)
2292 error ("class '%s' has no method named '%s' matching signature '%s'",
2294 IDENTIFIER_POINTER (method_name
),
2295 IDENTIFIER_POINTER (method_signature
));
2299 int flags
= ACC_PUBLIC
;
2300 if (opcode
== OPCODE_invokestatic
)
2301 flags
|= ACC_STATIC
;
2302 if (opcode
== OPCODE_invokeinterface
)
2304 flags
|= ACC_INTERFACE
| ACC_ABSTRACT
;
2305 CLASS_INTERFACE (TYPE_NAME (self_type
)) = 1;
2307 method
= add_method (self_type
, flags
, method_name
,
2309 DECL_ARTIFICIAL (method
) = 1;
2310 METHOD_DUMMY (method
) = 1;
2311 layout_class_method (self_type
, NULL
,
2316 /* Invoke static can't invoke static/abstract method */
2317 if (method
!= NULL_TREE
)
2319 if (opcode
== OPCODE_invokestatic
)
2321 if (!METHOD_STATIC (method
))
2323 error ("invokestatic on non static method");
2326 else if (METHOD_ABSTRACT (method
))
2328 error ("invokestatic on abstract method");
2334 if (METHOD_STATIC (method
))
2336 error ("invoke[non-static] on static method");
2342 if (method
== NULL_TREE
)
2344 /* If we got here, we emitted an error message above. So we
2345 just pop the arguments, push a properly-typed zero, and
2347 method_type
= get_type_from_signature (method_signature
);
2348 pop_arguments (TYPE_ARG_TYPES (method_type
));
2349 if (opcode
!= OPCODE_invokestatic
)
2350 pop_type (self_type
);
2351 method_type
= promote_type (TREE_TYPE (method_type
));
2352 push_value (convert (method_type
, integer_zero_node
));
2356 method_type
= TREE_TYPE (method
);
2357 arg_list
= pop_arguments (TYPE_ARG_TYPES (method_type
));
2358 flush_quick_stack ();
2361 if (opcode
== OPCODE_invokestatic
)
2362 func
= build_known_method_ref (method
, method_type
, self_type
,
2363 method_signature
, arg_list
);
2364 else if (opcode
== OPCODE_invokespecial
2365 || (opcode
== OPCODE_invokevirtual
2366 && (METHOD_PRIVATE (method
)
2367 || METHOD_FINAL (method
)
2368 || CLASS_FINAL (TYPE_NAME (self_type
)))))
2370 /* If the object for the method call is null, we throw an
2371 exception. We don't do this if the object is the current
2372 method's `this'. In other cases we just rely on an
2373 optimization pass to eliminate redundant checks. FIXME:
2374 Unfortunately there doesn't seem to be a way to determine
2375 what the current method is right now.
2376 We do omit the check if we're calling <init>. */
2377 /* We use a SAVE_EXPR here to make sure we only evaluate
2378 the new `self' expression once. */
2379 tree save_arg
= save_expr (TREE_VALUE (arg_list
));
2380 TREE_VALUE (arg_list
) = save_arg
;
2381 check
= java_check_reference (save_arg
, ! DECL_INIT_P (method
));
2382 func
= build_known_method_ref (method
, method_type
, self_type
,
2383 method_signature
, arg_list
);
2387 tree dtable
= invoke_build_dtable (opcode
== OPCODE_invokeinterface
,
2389 if (opcode
== OPCODE_invokevirtual
)
2390 func
= build_invokevirtual (dtable
, method
);
2392 func
= build_invokeinterface (dtable
, method
);
2395 if (TREE_CODE (func
) == ADDR_EXPR
)
2396 TREE_TYPE (func
) = build_pointer_type (method_type
);
2398 func
= build1 (NOP_EXPR
, build_pointer_type (method_type
), func
);
2400 call
= build3 (CALL_EXPR
, TREE_TYPE (method_type
),
2401 func
, arg_list
, NULL_TREE
);
2402 TREE_SIDE_EFFECTS (call
) = 1;
2403 call
= check_for_builtin (method
, call
);
2405 if (check
!= NULL_TREE
)
2407 call
= build2 (COMPOUND_EXPR
, TREE_TYPE (call
), check
, call
);
2408 TREE_SIDE_EFFECTS (call
) = 1;
2411 if (TREE_CODE (TREE_TYPE (method_type
)) == VOID_TYPE
)
2412 java_add_stmt (call
);
2416 flush_quick_stack ();
2420 /* Create a stub which will be put into the vtable but which will call
2424 build_jni_stub (tree method
)
2426 tree jnifunc
, call
, args
, body
, lookup_arg
, method_sig
, arg_types
;
2427 tree jni_func_type
, tem
;
2428 tree env_var
, res_var
= NULL_TREE
, block
;
2429 tree method_args
, res_type
;
2435 tree klass
= DECL_CONTEXT (method
);
2436 int from_class
= ! CLASS_FROM_SOURCE_P (klass
);
2437 klass
= build_class_ref (klass
);
2439 if (! METHOD_NATIVE (method
) || ! flag_jni
)
2442 DECL_ARTIFICIAL (method
) = 1;
2443 DECL_EXTERNAL (method
) = 0;
2445 env_var
= build_decl (VAR_DECL
, get_identifier ("env"), ptr_type_node
);
2446 DECL_CONTEXT (env_var
) = method
;
2448 if (TREE_TYPE (TREE_TYPE (method
)) != void_type_node
)
2450 res_var
= build_decl (VAR_DECL
, get_identifier ("res"),
2451 TREE_TYPE (TREE_TYPE (method
)));
2452 DECL_CONTEXT (res_var
) = method
;
2453 TREE_CHAIN (env_var
) = res_var
;
2456 meth_var
= build_decl (VAR_DECL
, get_identifier ("meth"), ptr_type_node
);
2457 TREE_STATIC (meth_var
) = 1;
2458 TREE_PUBLIC (meth_var
) = 0;
2459 DECL_EXTERNAL (meth_var
) = 0;
2460 DECL_CONTEXT (meth_var
) = method
;
2461 DECL_ARTIFICIAL (meth_var
) = 1;
2462 DECL_INITIAL (meth_var
) = null_pointer_node
;
2463 TREE_USED (meth_var
) = 1;
2464 chainon (env_var
, meth_var
);
2465 build_result_decl (method
);
2467 /* One strange way that the front ends are different is that they
2468 store arguments differently. */
2470 method_args
= DECL_ARGUMENTS (method
);
2472 method_args
= BLOCK_EXPR_DECLS (DECL_FUNCTION_BODY (method
));
2473 block
= build_block (env_var
, NULL_TREE
, method_args
, NULL_TREE
);
2474 TREE_SIDE_EFFECTS (block
) = 1;
2475 /* When compiling from source we don't set the type of the block,
2476 because that will prevent patch_return from ever being run. */
2478 TREE_TYPE (block
) = TREE_TYPE (TREE_TYPE (method
));
2480 /* Compute the local `env' by calling _Jv_GetJNIEnvNewFrame. */
2481 body
= build2 (MODIFY_EXPR
, ptr_type_node
, env_var
,
2482 build3 (CALL_EXPR
, ptr_type_node
,
2483 build_address_of (soft_getjnienvnewframe_node
),
2484 build_tree_list (NULL_TREE
, klass
),
2486 CAN_COMPLETE_NORMALLY (body
) = 1;
2488 /* All the arguments to this method become arguments to the
2489 underlying JNI function. If we had to wrap object arguments in a
2490 special way, we would do that here. */
2492 for (tem
= method_args
; tem
!= NULL_TREE
; tem
= TREE_CHAIN (tem
))
2494 int arg_bits
= TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (tem
)));
2495 #ifdef PARM_BOUNDARY
2496 arg_bits
= (((arg_bits
+ PARM_BOUNDARY
- 1) / PARM_BOUNDARY
)
2499 args_size
+= (arg_bits
/ BITS_PER_UNIT
);
2501 args
= tree_cons (NULL_TREE
, tem
, args
);
2503 args
= nreverse (args
);
2504 arg_types
= TYPE_ARG_TYPES (TREE_TYPE (method
));
2506 /* For a static method the second argument is the class. For a
2507 non-static method the second argument is `this'; that is already
2508 available in the argument list. */
2509 if (METHOD_STATIC (method
))
2511 args_size
+= int_size_in_bytes (TREE_TYPE (klass
));
2512 args
= tree_cons (NULL_TREE
, klass
, args
);
2513 arg_types
= tree_cons (NULL_TREE
, object_ptr_type_node
, arg_types
);
2516 /* The JNIEnv structure is the first argument to the JNI function. */
2517 args_size
+= int_size_in_bytes (TREE_TYPE (env_var
));
2518 args
= tree_cons (NULL_TREE
, env_var
, args
);
2519 arg_types
= tree_cons (NULL_TREE
, ptr_type_node
, arg_types
);
2521 /* We call _Jv_LookupJNIMethod to find the actual underlying
2522 function pointer. _Jv_LookupJNIMethod will throw the appropriate
2523 exception if this function is not found at runtime. */
2524 tem
= build_tree_list (NULL_TREE
, build_int_cst (NULL_TREE
, args_size
));
2525 method_sig
= build_java_signature (TREE_TYPE (method
));
2526 lookup_arg
= tree_cons (NULL_TREE
,
2527 build_utf8_ref (unmangle_classname
2528 (IDENTIFIER_POINTER (method_sig
),
2529 IDENTIFIER_LENGTH (method_sig
))),
2531 tem
= DECL_NAME (method
);
2533 = tree_cons (NULL_TREE
, klass
,
2534 tree_cons (NULL_TREE
, build_utf8_ref (tem
), lookup_arg
));
2536 tem
= build_function_type (TREE_TYPE (TREE_TYPE (method
)), arg_types
);
2538 #ifdef MODIFY_JNI_METHOD_CALL
2539 tem
= MODIFY_JNI_METHOD_CALL (tem
);
2542 jni_func_type
= build_pointer_type (tem
);
2544 jnifunc
= build3 (COND_EXPR
, ptr_type_node
,
2546 build2 (MODIFY_EXPR
, ptr_type_node
, meth_var
,
2547 build3 (CALL_EXPR
, ptr_type_node
,
2549 (soft_lookupjnimethod_node
),
2550 lookup_arg
, NULL_TREE
)));
2552 /* Now we make the actual JNI call via the resulting function
2554 call
= build3 (CALL_EXPR
, TREE_TYPE (TREE_TYPE (method
)),
2555 build1 (NOP_EXPR
, jni_func_type
, jnifunc
),
2558 /* If the JNI call returned a result, capture it here. If we had to
2559 unwrap JNI object results, we would do that here. */
2560 if (res_var
!= NULL_TREE
)
2562 /* If the call returns an object, it may return a JNI weak
2563 reference, in which case we must unwrap it. */
2564 if (! JPRIMITIVE_TYPE_P (TREE_TYPE (TREE_TYPE (method
))))
2565 call
= build3 (CALL_EXPR
, TREE_TYPE (TREE_TYPE (method
)),
2566 build_address_of (soft_unwrapjni_node
),
2567 build_tree_list (NULL_TREE
, call
),
2569 call
= build2 (MODIFY_EXPR
, TREE_TYPE (TREE_TYPE (method
)),
2573 TREE_SIDE_EFFECTS (call
) = 1;
2574 CAN_COMPLETE_NORMALLY (call
) = 1;
2576 body
= build2 (COMPOUND_EXPR
, void_type_node
, body
, call
);
2577 TREE_SIDE_EFFECTS (body
) = 1;
2579 /* Now free the environment we allocated. */
2580 call
= build3 (CALL_EXPR
, ptr_type_node
,
2581 build_address_of (soft_jnipopsystemframe_node
),
2582 build_tree_list (NULL_TREE
, env_var
),
2584 TREE_SIDE_EFFECTS (call
) = 1;
2585 CAN_COMPLETE_NORMALLY (call
) = 1;
2586 body
= build2 (COMPOUND_EXPR
, void_type_node
, body
, call
);
2587 TREE_SIDE_EFFECTS (body
) = 1;
2589 /* Finally, do the return. */
2590 res_type
= void_type_node
;
2591 if (res_var
!= NULL_TREE
)
2594 if (! DECL_RESULT (method
))
2596 /* Make sure we copy the result variable to the actual
2597 result. We use the type of the DECL_RESULT because it
2598 might be different from the return type of the function:
2599 it might be promoted. */
2600 drt
= TREE_TYPE (DECL_RESULT (method
));
2601 if (drt
!= TREE_TYPE (res_var
))
2602 res_var
= build1 (CONVERT_EXPR
, drt
, res_var
);
2603 res_var
= build2 (MODIFY_EXPR
, drt
, DECL_RESULT (method
), res_var
);
2604 TREE_SIDE_EFFECTS (res_var
) = 1;
2607 body
= build2 (COMPOUND_EXPR
, void_type_node
, body
,
2608 build1 (RETURN_EXPR
, res_type
, res_var
));
2609 TREE_SIDE_EFFECTS (body
) = 1;
2611 bind
= build3 (BIND_EXPR
, void_type_node
, BLOCK_VARS (block
),
2616 /* Expand an operation to extract from or store into a field.
2617 IS_STATIC is 1 iff the field is static.
2618 IS_PUTTING is 1 for putting into a field; 0 for getting from the field.
2619 FIELD_REF_INDEX is an index into the constant pool. */
2622 expand_java_field_op (int is_static
, int is_putting
, int field_ref_index
)
2625 = get_class_constant (current_jcf
,
2626 COMPONENT_REF_CLASS_INDEX (¤t_jcf
->cpool
,
2628 const char *self_name
2629 = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (self_type
)));
2630 tree field_name
= COMPONENT_REF_NAME (¤t_jcf
->cpool
, field_ref_index
);
2631 tree field_signature
= COMPONENT_REF_SIGNATURE (¤t_jcf
->cpool
,
2633 tree field_type
= get_type_from_signature (field_signature
);
2634 tree new_value
= is_putting
? pop_value (field_type
) : NULL_TREE
;
2637 tree original_self_type
= self_type
;
2640 if (! CLASS_LOADED_P (self_type
))
2641 load_class (self_type
, 1);
2642 field_decl
= lookup_field (&self_type
, field_name
);
2643 if (field_decl
== error_mark_node
)
2647 else if (field_decl
== NULL_TREE
)
2649 if (! flag_verify_invocations
)
2651 int flags
= ACC_PUBLIC
;
2653 flags
|= ACC_STATIC
;
2654 self_type
= original_self_type
;
2655 field_decl
= add_field (original_self_type
, field_name
,
2657 DECL_ARTIFICIAL (field_decl
) = 1;
2658 DECL_IGNORED_P (field_decl
) = 1;
2662 error ("missing field '%s' in '%s'",
2663 IDENTIFIER_POINTER (field_name
), self_name
);
2667 else if (build_java_signature (TREE_TYPE (field_decl
)) != field_signature
)
2669 error ("mismatching signature for field '%s' in '%s'",
2670 IDENTIFIER_POINTER (field_name
), self_name
);
2673 field_ref
= is_static
? NULL_TREE
: pop_value (self_type
);
2677 push_value (convert (field_type
, integer_zero_node
));
2678 flush_quick_stack ();
2682 field_ref
= build_field_ref (field_ref
, self_type
, field_name
);
2684 && ! flag_indirect_dispatch
)
2685 field_ref
= build_class_init (self_type
, field_ref
);
2688 flush_quick_stack ();
2689 if (FIELD_FINAL (field_decl
))
2691 if (DECL_CONTEXT (field_decl
) != current_class
)
2692 error ("assignment to final field %q+D not in field's class",
2694 else if (FIELD_STATIC (field_decl
))
2696 if (!DECL_CLINIT_P (current_function_decl
))
2697 warning (0, "assignment to final static field %q+D not in "
2698 "class initializer",
2703 tree cfndecl_name
= DECL_NAME (current_function_decl
);
2704 if (! DECL_CONSTRUCTOR_P (current_function_decl
)
2705 && !ID_FINIT_P (cfndecl_name
))
2706 warning (0, "assignment to final field %q+D not in constructor",
2710 java_add_stmt (build2 (MODIFY_EXPR
, TREE_TYPE (field_ref
),
2711 field_ref
, new_value
));
2714 push_value (field_ref
);
2718 load_type_state (tree label
)
2721 tree vec
= LABEL_TYPE_STATE (label
);
2722 int cur_length
= TREE_VEC_LENGTH (vec
);
2723 stack_pointer
= cur_length
- DECL_MAX_LOCALS(current_function_decl
);
2724 for (i
= 0; i
< cur_length
; i
++)
2725 type_map
[i
] = TREE_VEC_ELT (vec
, i
);
2728 /* Go over METHOD's bytecode and note instruction starts in
2729 instruction_bits[]. */
2732 note_instructions (JCF
*jcf
, tree method
)
2735 unsigned char* byte_ops
;
2736 long length
= DECL_CODE_LENGTH (method
);
2741 #undef RET /* Defined by config/i386/i386.h */
2743 #define BCODE byte_ops
2744 #define BYTE_type_node byte_type_node
2745 #define SHORT_type_node short_type_node
2746 #define INT_type_node int_type_node
2747 #define LONG_type_node long_type_node
2748 #define CHAR_type_node char_type_node
2749 #define PTR_type_node ptr_type_node
2750 #define FLOAT_type_node float_type_node
2751 #define DOUBLE_type_node double_type_node
2752 #define VOID_type_node void_type_node
2753 #define CONST_INDEX_1 (saw_index = 1, IMMEDIATE_u1)
2754 #define CONST_INDEX_2 (saw_index = 1, IMMEDIATE_u2)
2755 #define VAR_INDEX_1 (saw_index = 1, IMMEDIATE_u1)
2756 #define VAR_INDEX_2 (saw_index = 1, IMMEDIATE_u2)
2758 #define CHECK_PC_IN_RANGE(PC) ((void)1) /* Already handled by verifier. */
2760 JCF_SEEK (jcf
, DECL_CODE_OFFSET (method
));
2761 byte_ops
= jcf
->read_ptr
;
2762 instruction_bits
= xrealloc (instruction_bits
, length
+ 1);
2763 memset (instruction_bits
, 0, length
+ 1);
2765 /* This pass figures out which PC can be the targets of jumps. */
2766 for (PC
= 0; PC
< length
;)
2768 int oldpc
= PC
; /* PC at instruction start. */
2769 instruction_bits
[PC
] |= BCODE_INSTRUCTION_START
;
2770 switch (byte_ops
[PC
++])
2772 #define JAVAOP(OPNAME, OPCODE, OPKIND, OPERAND_TYPE, OPERAND_VALUE) \
2774 PRE_##OPKIND(OPERAND_TYPE, OPERAND_VALUE); \
2777 #define NOTE_LABEL(PC) note_label(oldpc, PC)
2779 #define PRE_PUSHC(OPERAND_TYPE, OPERAND_VALUE) (void)(OPERAND_VALUE);
2780 #define PRE_LOAD(OPERAND_TYPE, OPERAND_VALUE) (void)(OPERAND_VALUE);
2781 #define PRE_STORE(OPERAND_TYPE, OPERAND_VALUE) (void)(OPERAND_VALUE);
2782 #define PRE_STACK(OPERAND_TYPE, OPERAND_VALUE) /* nothing */
2783 #define PRE_UNOP(OPERAND_TYPE, OPERAND_VALUE) /* nothing */
2784 #define PRE_BINOP(OPERAND_TYPE, OPERAND_VALUE) /* nothing */
2785 #define PRE_CONVERT(OPERAND_TYPE, OPERAND_VALUE) /* nothing */
2786 #define PRE_CONVERT2(OPERAND_TYPE, OPERAND_VALUE) /* nothing */
2788 #define PRE_SPECIAL(OPERAND_TYPE, INSTRUCTION) \
2789 PRE_SPECIAL_##INSTRUCTION(OPERAND_TYPE)
2790 #define PRE_SPECIAL_IINC(OPERAND_TYPE) \
2791 ((void) IMMEDIATE_u1, (void) IMMEDIATE_s1)
2792 #define PRE_SPECIAL_ENTER(IGNORE) /* nothing */
2793 #define PRE_SPECIAL_EXIT(IGNORE) /* nothing */
2794 #define PRE_SPECIAL_THROW(IGNORE) /* nothing */
2795 #define PRE_SPECIAL_BREAK(IGNORE) /* nothing */
2797 /* two forms of wide instructions */
2798 #define PRE_SPECIAL_WIDE(IGNORE) \
2800 int modified_opcode = IMMEDIATE_u1; \
2801 if (modified_opcode == OPCODE_iinc) \
2803 (void) IMMEDIATE_u2; /* indexbyte1 and indexbyte2 */ \
2804 (void) IMMEDIATE_s2; /* constbyte1 and constbyte2 */ \
2808 (void) IMMEDIATE_u2; /* indexbyte1 and indexbyte2 */ \
2812 #define PRE_IMPL(IGNORE1, IGNORE2) /* nothing */
2814 #define PRE_MONITOR(OPERAND_TYPE, OPERAND_VALUE) /* nothing */
2816 #define PRE_RETURN(OPERAND_TYPE, OPERAND_VALUE) /* nothing */
2817 #define PRE_ARRAY(OPERAND_TYPE, SUBOP) \
2818 PRE_ARRAY_##SUBOP(OPERAND_TYPE)
2819 #define PRE_ARRAY_LOAD(TYPE) /* nothing */
2820 #define PRE_ARRAY_STORE(TYPE) /* nothing */
2821 #define PRE_ARRAY_LENGTH(TYPE) /* nothing */
2822 #define PRE_ARRAY_NEW(TYPE) PRE_ARRAY_NEW_##TYPE
2823 #define PRE_ARRAY_NEW_NUM ((void) IMMEDIATE_u1)
2824 #define PRE_ARRAY_NEW_PTR ((void) IMMEDIATE_u2)
2825 #define PRE_ARRAY_NEW_MULTI ((void) IMMEDIATE_u2, (void) IMMEDIATE_u1)
2827 #define PRE_TEST(OPERAND_TYPE, OPERAND_VALUE) NOTE_LABEL (oldpc+IMMEDIATE_s2)
2828 #define PRE_COND(OPERAND_TYPE, OPERAND_VALUE) NOTE_LABEL (oldpc+IMMEDIATE_s2)
2829 #define PRE_BRANCH(OPERAND_TYPE, OPERAND_VALUE) \
2830 saw_index = 0; INT_temp = (OPERAND_VALUE); \
2831 if (!saw_index) NOTE_LABEL(oldpc + INT_temp);
2832 #define PRE_JSR(OPERAND_TYPE, OPERAND_VALUE) \
2833 saw_index = 0; INT_temp = (OPERAND_VALUE); \
2835 if (!saw_index) NOTE_LABEL(oldpc + INT_temp);
2837 #define PRE_RET(OPERAND_TYPE, OPERAND_VALUE) (void)(OPERAND_VALUE)
2839 #define PRE_SWITCH(OPERAND_TYPE, TABLE_OR_LOOKUP) \
2840 PC = (PC + 3) / 4 * 4; PRE_##TABLE_OR_LOOKUP##_SWITCH
2842 #define PRE_LOOKUP_SWITCH \
2843 { jint default_offset = IMMEDIATE_s4; jint npairs = IMMEDIATE_s4; \
2844 NOTE_LABEL (default_offset+oldpc); \
2846 while (--npairs >= 0) { \
2847 jint match ATTRIBUTE_UNUSED = IMMEDIATE_s4; \
2848 jint offset = IMMEDIATE_s4; \
2849 NOTE_LABEL (offset+oldpc); } \
2852 #define PRE_TABLE_SWITCH \
2853 { jint default_offset = IMMEDIATE_s4; \
2854 jint low = IMMEDIATE_s4; jint high = IMMEDIATE_s4; \
2855 NOTE_LABEL (default_offset+oldpc); \
2857 while (low++ <= high) { \
2858 jint offset = IMMEDIATE_s4; \
2859 NOTE_LABEL (offset+oldpc); } \
2862 #define PRE_FIELD(MAYBE_STATIC, PUT_OR_GET) (void)(IMMEDIATE_u2);
2863 #define PRE_OBJECT(MAYBE_STATIC, PUT_OR_GET) (void)(IMMEDIATE_u2);
2864 #define PRE_INVOKE(MAYBE_STATIC, IS_INTERFACE) \
2865 (void)(IMMEDIATE_u2); \
2866 PC += 2 * IS_INTERFACE /* for invokeinterface */;
2868 #include "javaop.def"
2875 expand_byte_code (JCF
*jcf
, tree method
)
2879 const unsigned char *linenumber_pointer
;
2880 int dead_code_index
= -1;
2881 unsigned char* byte_ops
;
2882 long length
= DECL_CODE_LENGTH (method
);
2885 JCF_SEEK (jcf
, DECL_CODE_OFFSET (method
));
2886 byte_ops
= jcf
->read_ptr
;
2888 /* We make an initial pass of the line number table, to note
2889 which instructions have associated line number entries. */
2890 linenumber_pointer
= linenumber_table
;
2891 for (i
= 0; i
< linenumber_count
; i
++)
2893 int pc
= GET_u2 (linenumber_pointer
);
2894 linenumber_pointer
+= 4;
2896 warning (0, "invalid PC in line number table");
2899 if ((instruction_bits
[pc
] & BCODE_HAS_LINENUMBER
) != 0)
2900 instruction_bits
[pc
] |= BCODE_HAS_MULTI_LINENUMBERS
;
2901 instruction_bits
[pc
] |= BCODE_HAS_LINENUMBER
;
2905 if (! verify_jvm_instructions_new (jcf
, byte_ops
, length
))
2908 promote_arguments ();
2910 /* Translate bytecodes. */
2911 linenumber_pointer
= linenumber_table
;
2912 for (PC
= 0; PC
< length
;)
2914 if ((instruction_bits
[PC
] & BCODE_TARGET
) != 0 || PC
== 0)
2916 tree label
= lookup_label (PC
);
2917 flush_quick_stack ();
2918 if ((instruction_bits
[PC
] & BCODE_TARGET
) != 0)
2919 java_add_stmt (build1 (LABEL_EXPR
, void_type_node
, label
));
2920 if (LABEL_VERIFIED (label
) || PC
== 0)
2921 load_type_state (label
);
2924 if (! (instruction_bits
[PC
] & BCODE_VERIFIED
))
2926 if (dead_code_index
== -1)
2928 /* This is the start of a region of unreachable bytecodes.
2929 They still need to be processed in order for EH ranges
2930 to get handled correctly. However, we can simply
2931 replace these bytecodes with nops. */
2932 dead_code_index
= PC
;
2935 /* Turn this bytecode into a nop. */
2940 if (dead_code_index
!= -1)
2942 /* We've just reached the end of a region of dead code. */
2944 warning (0, "unreachable bytecode from %d to before %d",
2945 dead_code_index
, PC
);
2946 dead_code_index
= -1;
2950 /* Handle possible line number entry for this PC.
2952 This code handles out-of-order and multiple linenumbers per PC,
2953 but is optimized for the case of line numbers increasing
2954 monotonically with PC. */
2955 if ((instruction_bits
[PC
] & BCODE_HAS_LINENUMBER
) != 0)
2957 if ((instruction_bits
[PC
] & BCODE_HAS_MULTI_LINENUMBERS
) != 0
2958 || GET_u2 (linenumber_pointer
) != PC
)
2959 linenumber_pointer
= linenumber_table
;
2960 while (linenumber_pointer
< linenumber_table
+ linenumber_count
* 4)
2962 int pc
= GET_u2 (linenumber_pointer
);
2963 linenumber_pointer
+= 4;
2966 int line
= GET_u2 (linenumber_pointer
- 2);
2967 #ifdef USE_MAPPED_LOCATION
2968 input_location
= linemap_line_start (&line_table
, line
, 1);
2970 input_location
.line
= line
;
2972 if (!(instruction_bits
[PC
] & BCODE_HAS_MULTI_LINENUMBERS
))
2977 maybe_pushlevels (PC
);
2978 PC
= process_jvm_instruction (PC
, byte_ops
, length
);
2979 maybe_poplevels (PC
);
2982 if (dead_code_index
!= -1)
2984 /* We've just reached the end of a region of dead code. */
2986 warning (0, "unreachable bytecode from %d to the end of the method",
2992 java_push_constant_from_pool (JCF
*jcf
, int index
)
2995 if (JPOOL_TAG (jcf
, index
) == CONSTANT_String
)
2998 name
= get_name_constant (jcf
, JPOOL_USHORT1 (jcf
, index
));
2999 index
= alloc_name_constant (CONSTANT_String
, name
);
3000 c
= build_ref_from_constant_pool (index
);
3001 c
= convert (promote_type (string_type_node
), c
);
3004 c
= get_constant (jcf
, index
);
3009 process_jvm_instruction (int PC
, const unsigned char* byte_ops
,
3010 long length ATTRIBUTE_UNUSED
)
3012 const char *opname
; /* Temporary ??? */
3013 int oldpc
= PC
; /* PC at instruction start. */
3015 /* If the instruction is at the beginning of an exception handler,
3016 replace the top of the stack with the thrown object reference. */
3017 if (instruction_bits
[PC
] & BCODE_EXCEPTION_TARGET
)
3019 /* Note that the verifier will not emit a type map at all for
3020 dead exception handlers. In this case we just ignore the
3022 if ((instruction_bits
[PC
] & BCODE_VERIFIED
) != 0)
3024 tree type
= pop_type (promote_type (throwable_type_node
));
3025 push_value (build_exception_object_ref (type
));
3029 switch (byte_ops
[PC
++])
3031 #define JAVAOP(OPNAME, OPCODE, OPKIND, OPERAND_TYPE, OPERAND_VALUE) \
3034 OPKIND(OPERAND_TYPE, OPERAND_VALUE); \
3037 #define RET(OPERAND_TYPE, OPERAND_VALUE) \
3039 int saw_index = 0; \
3040 int index = OPERAND_VALUE; \
3042 (find_local_variable (index, return_address_type_node, oldpc)); \
3045 #define JSR(OPERAND_TYPE, OPERAND_VALUE) \
3047 /* OPERAND_VALUE may have side-effects on PC */ \
3048 int opvalue = OPERAND_VALUE; \
3049 build_java_jsr (oldpc + opvalue, PC); \
3052 /* Push a constant onto the stack. */
3053 #define PUSHC(OPERAND_TYPE, OPERAND_VALUE) \
3054 { int saw_index = 0; int ival = (OPERAND_VALUE); \
3055 if (saw_index) java_push_constant_from_pool (current_jcf, ival); \
3056 else expand_java_pushc (ival, OPERAND_TYPE##_type_node); }
3058 /* internal macro added for use by the WIDE case */
3059 #define LOAD_INTERNAL(OPTYPE, OPVALUE) \
3060 expand_load_internal (OPVALUE, type_map[OPVALUE], oldpc);
3062 /* Push local variable onto the opcode stack. */
3063 #define LOAD(OPERAND_TYPE, OPERAND_VALUE) \
3065 /* have to do this since OPERAND_VALUE may have side-effects */ \
3066 int opvalue = OPERAND_VALUE; \
3067 LOAD_INTERNAL(OPERAND_TYPE##_type_node, opvalue); \
3070 #define RETURN(OPERAND_TYPE, OPERAND_VALUE) \
3071 expand_java_return (OPERAND_TYPE##_type_node)
3073 #define REM_EXPR TRUNC_MOD_EXPR
3074 #define BINOP(OPERAND_TYPE, OPERAND_VALUE) \
3075 expand_java_binop (OPERAND_TYPE##_type_node, OPERAND_VALUE##_EXPR)
3077 #define FIELD(IS_STATIC, IS_PUT) \
3078 expand_java_field_op (IS_STATIC, IS_PUT, IMMEDIATE_u2)
3080 #define TEST(OPERAND_TYPE, CONDITION) \
3081 expand_test (CONDITION##_EXPR, OPERAND_TYPE##_type_node, oldpc+IMMEDIATE_s2)
3083 #define COND(OPERAND_TYPE, CONDITION) \
3084 expand_cond (CONDITION##_EXPR, OPERAND_TYPE##_type_node, oldpc+IMMEDIATE_s2)
3086 #define BRANCH(OPERAND_TYPE, OPERAND_VALUE) \
3087 BRANCH_##OPERAND_TYPE (OPERAND_VALUE)
3089 #define BRANCH_GOTO(OPERAND_VALUE) \
3090 expand_java_goto (oldpc + OPERAND_VALUE)
3092 #define BRANCH_CALL(OPERAND_VALUE) \
3093 expand_java_call (oldpc + OPERAND_VALUE, oldpc)
3096 #define BRANCH_RETURN(OPERAND_VALUE) \
3098 tree type = OPERAND_TYPE##_type_node; \
3099 tree value = find_local_variable (OPERAND_VALUE, type, oldpc); \
3100 expand_java_ret (value); \
3104 #define NOT_IMPL(OPERAND_TYPE, OPERAND_VALUE) \
3105 fprintf (stderr, "%3d: %s ", oldpc, opname); \
3106 fprintf (stderr, "(not implemented)\n")
3107 #define NOT_IMPL1(OPERAND_VALUE) \
3108 fprintf (stderr, "%3d: %s ", oldpc, opname); \
3109 fprintf (stderr, "(not implemented)\n")
3111 #define BRANCH_RETURN(OPERAND_VALUE) NOT_IMPL1(OPERAND_VALUE)
3113 #define STACK(SUBOP, COUNT) STACK_##SUBOP (COUNT)
3115 #define STACK_POP(COUNT) java_stack_pop (COUNT)
3117 #define STACK_SWAP(COUNT) java_stack_swap()
3119 #define STACK_DUP(COUNT) java_stack_dup (COUNT, 0)
3120 #define STACK_DUPx1(COUNT) java_stack_dup (COUNT, 1)
3121 #define STACK_DUPx2(COUNT) java_stack_dup (COUNT, 2)
3123 #define SWITCH(OPERAND_TYPE, TABLE_OR_LOOKUP) \
3124 PC = (PC + 3) / 4 * 4; TABLE_OR_LOOKUP##_SWITCH
3126 #define LOOKUP_SWITCH \
3127 { jint default_offset = IMMEDIATE_s4; jint npairs = IMMEDIATE_s4; \
3128 tree selector = pop_value (INT_type_node); \
3129 tree switch_expr = expand_java_switch (selector, oldpc + default_offset); \
3130 while (--npairs >= 0) \
3132 jint match = IMMEDIATE_s4; jint offset = IMMEDIATE_s4; \
3133 expand_java_add_case (switch_expr, match, oldpc + offset); \
3137 #define TABLE_SWITCH \
3138 { jint default_offset = IMMEDIATE_s4; \
3139 jint low = IMMEDIATE_s4; jint high = IMMEDIATE_s4; \
3140 tree selector = pop_value (INT_type_node); \
3141 tree switch_expr = expand_java_switch (selector, oldpc + default_offset); \
3142 for (; low <= high; low++) \
3144 jint offset = IMMEDIATE_s4; \
3145 expand_java_add_case (switch_expr, low, oldpc + offset); \
3149 #define INVOKE(MAYBE_STATIC, IS_INTERFACE) \
3150 { int opcode = byte_ops[PC-1]; \
3151 int method_ref_index = IMMEDIATE_u2; \
3153 if (IS_INTERFACE) { nargs = IMMEDIATE_u1; (void) IMMEDIATE_u1; } \
3155 expand_invoke (opcode, method_ref_index, nargs); \
3158 /* Handle new, checkcast, instanceof */
3159 #define OBJECT(TYPE, OP) \
3160 expand_java_##OP (get_class_constant (current_jcf, IMMEDIATE_u2))
3162 #define ARRAY(OPERAND_TYPE, SUBOP) ARRAY_##SUBOP(OPERAND_TYPE)
3164 #define ARRAY_LOAD(OPERAND_TYPE) \
3166 expand_java_arrayload( OPERAND_TYPE##_type_node ); \
3169 #define ARRAY_STORE(OPERAND_TYPE) \
3171 expand_java_arraystore( OPERAND_TYPE##_type_node ); \
3174 #define ARRAY_LENGTH(OPERAND_TYPE) expand_java_array_length();
3175 #define ARRAY_NEW(OPERAND_TYPE) ARRAY_NEW_##OPERAND_TYPE()
3176 #define ARRAY_NEW_PTR() \
3177 push_value (build_anewarray (get_class_constant (current_jcf, \
3179 pop_value (int_type_node)));
3180 #define ARRAY_NEW_NUM() \
3182 int atype = IMMEDIATE_u1; \
3183 push_value (build_newarray (atype, pop_value (int_type_node)));\
3185 #define ARRAY_NEW_MULTI() \
3187 tree class = get_class_constant (current_jcf, IMMEDIATE_u2 ); \
3188 int ndims = IMMEDIATE_u1; \
3189 expand_java_multianewarray( class, ndims ); \
3192 #define UNOP(OPERAND_TYPE, OPERAND_VALUE) \
3193 push_value (fold_build1 (NEGATE_EXPR, OPERAND_TYPE##_type_node, \
3194 pop_value (OPERAND_TYPE##_type_node)));
3196 #define CONVERT2(FROM_TYPE, TO_TYPE) \
3198 push_value (build1 (NOP_EXPR, int_type_node, \
3199 (convert (TO_TYPE##_type_node, \
3200 pop_value (FROM_TYPE##_type_node))))); \
3203 #define CONVERT(FROM_TYPE, TO_TYPE) \
3205 push_value (convert (TO_TYPE##_type_node, \
3206 pop_value (FROM_TYPE##_type_node))); \
3209 /* internal macro added for use by the WIDE case
3210 Added TREE_TYPE (decl) assignment, apbianco */
3211 #define STORE_INTERNAL(OPTYPE, OPVALUE) \
3214 int index = OPVALUE; \
3215 tree type = OPTYPE; \
3216 value = pop_value (type); \
3217 type = TREE_TYPE (value); \
3218 decl = find_local_variable (index, type, oldpc); \
3219 set_local_type (index, type); \
3220 java_add_stmt (build2 (MODIFY_EXPR, type, decl, value)); \
3221 update_aliases (decl, index, PC); \
3224 #define STORE(OPERAND_TYPE, OPERAND_VALUE) \
3226 /* have to do this since OPERAND_VALUE may have side-effects */ \
3227 int opvalue = OPERAND_VALUE; \
3228 STORE_INTERNAL(OPERAND_TYPE##_type_node, opvalue); \
3231 #define SPECIAL(OPERAND_TYPE, INSTRUCTION) \
3232 SPECIAL_##INSTRUCTION(OPERAND_TYPE)
3234 #define SPECIAL_ENTER(IGNORED) MONITOR_OPERATION (soft_monitorenter_node)
3235 #define SPECIAL_EXIT(IGNORED) MONITOR_OPERATION (soft_monitorexit_node)
3237 #define MONITOR_OPERATION(call) \
3239 tree o = pop_value (ptr_type_node); \
3241 flush_quick_stack (); \
3242 c = build_java_monitor (call, o); \
3243 TREE_SIDE_EFFECTS (c) = 1; \
3244 java_add_stmt (c); \
3247 #define SPECIAL_IINC(IGNORED) \
3249 unsigned int local_var_index = IMMEDIATE_u1; \
3250 int ival = IMMEDIATE_s1; \
3251 expand_iinc(local_var_index, ival, oldpc); \
3254 #define SPECIAL_WIDE(IGNORED) \
3256 int modified_opcode = IMMEDIATE_u1; \
3257 unsigned int local_var_index = IMMEDIATE_u2; \
3258 switch (modified_opcode) \
3262 int ival = IMMEDIATE_s2; \
3263 expand_iinc (local_var_index, ival, oldpc); \
3266 case OPCODE_iload: \
3267 case OPCODE_lload: \
3268 case OPCODE_fload: \
3269 case OPCODE_dload: \
3270 case OPCODE_aload: \
3272 /* duplicate code from LOAD macro */ \
3273 LOAD_INTERNAL(operand_type[modified_opcode], local_var_index); \
3276 case OPCODE_istore: \
3277 case OPCODE_lstore: \
3278 case OPCODE_fstore: \
3279 case OPCODE_dstore: \
3280 case OPCODE_astore: \
3282 STORE_INTERNAL(operand_type[modified_opcode], local_var_index); \
3286 error ("unrecogized wide sub-instruction"); \
3290 #define SPECIAL_THROW(IGNORED) \
3291 build_java_athrow (pop_value (throwable_type_node))
3293 #define SPECIAL_BREAK NOT_IMPL1
3294 #define IMPL NOT_IMPL
3296 #include "javaop.def"
3299 fprintf (stderr
, "%3d: unknown(%3d)\n", oldpc
, byte_ops
[PC
]);
3304 /* Return the opcode at PC in the code section pointed to by
3307 static unsigned char
3308 peek_opcode_at_pc (JCF
*jcf
, int code_offset
, int pc
)
3310 unsigned char opcode
;
3311 long absolute_offset
= (long)JCF_TELL (jcf
);
3313 JCF_SEEK (jcf
, code_offset
);
3314 opcode
= jcf
->read_ptr
[pc
];
3315 JCF_SEEK (jcf
, absolute_offset
);
3319 /* Some bytecode compilers are emitting accurate LocalVariableTable
3320 attributes. Here's an example:
3325 Attribute "LocalVariableTable"
3326 slot #<n>: ... (PC: PC+1 length: L)
3328 This is accurate because the local in slot <n> really exists after
3329 the opcode at PC is executed, hence from PC+1 to PC+1+L.
3331 This procedure recognizes this situation and extends the live range
3332 of the local in SLOT to START_PC-1 or START_PC-2 (depending on the
3333 length of the store instruction.)
3335 This function is used by `give_name_to_locals' so that a local's
3336 DECL features a DECL_LOCAL_START_PC such that the first related
3337 store operation will use DECL as a destination, not an unrelated
3338 temporary created for the occasion.
3340 This function uses a global (instruction_bits) `note_instructions' should
3341 have allocated and filled properly. */
3344 maybe_adjust_start_pc (struct JCF
*jcf
, int code_offset
,
3345 int start_pc
, int slot
)
3347 int first
, index
, opcode
;
3356 /* Find last previous instruction and remember it */
3357 for (pc
= start_pc
-1; pc
; pc
--)
3358 if (instruction_bits
[pc
] & BCODE_INSTRUCTION_START
)
3362 /* Retrieve the instruction, handle `wide'. */
3363 opcode
= (int) peek_opcode_at_pc (jcf
, code_offset
, pc
++);
3364 if (opcode
== OPCODE_wide
)
3367 opcode
= (int) peek_opcode_at_pc (jcf
, code_offset
, pc
++);
3372 case OPCODE_astore_0
:
3373 case OPCODE_astore_1
:
3374 case OPCODE_astore_2
:
3375 case OPCODE_astore_3
:
3376 first
= OPCODE_astore_0
;
3379 case OPCODE_istore_0
:
3380 case OPCODE_istore_1
:
3381 case OPCODE_istore_2
:
3382 case OPCODE_istore_3
:
3383 first
= OPCODE_istore_0
;
3386 case OPCODE_lstore_0
:
3387 case OPCODE_lstore_1
:
3388 case OPCODE_lstore_2
:
3389 case OPCODE_lstore_3
:
3390 first
= OPCODE_lstore_0
;
3393 case OPCODE_fstore_0
:
3394 case OPCODE_fstore_1
:
3395 case OPCODE_fstore_2
:
3396 case OPCODE_fstore_3
:
3397 first
= OPCODE_fstore_0
;
3400 case OPCODE_dstore_0
:
3401 case OPCODE_dstore_1
:
3402 case OPCODE_dstore_2
:
3403 case OPCODE_dstore_3
:
3404 first
= OPCODE_dstore_0
;
3412 index
= peek_opcode_at_pc (jcf
, code_offset
, pc
);
3415 int other
= peek_opcode_at_pc (jcf
, code_offset
, ++pc
);
3416 index
= (other
<< 8) + index
;
3421 /* Now we decide: first >0 means we have a <t>store_<n>, index >0
3422 means we have a <t>store. */
3423 if ((first
> 0 && opcode
- first
== slot
) || (index
> 0 && index
== slot
))
3429 /* Force the (direct) sub-operands of NODE to be evaluated in left-to-right
3430 order, as specified by Java Language Specification.
3432 The problem is that while expand_expr will evaluate its sub-operands in
3433 left-to-right order, for variables it will just return an rtx (i.e.
3434 an lvalue) for the variable (rather than an rvalue). So it is possible
3435 that a later sub-operand will change the register, and when the
3436 actual operation is done, it will use the new value, when it should
3437 have used the original value.
3439 We fix this by using save_expr. This forces the sub-operand to be
3440 copied into a fresh virtual register,
3442 For method invocation, we modify the arguments so that a
3443 left-to-right order evaluation is performed. Saved expressions
3444 will, in CALL_EXPR order, be reused when the call will be expanded.
3446 We also promote outgoing args if needed. */
3449 force_evaluation_order (tree node
)
3451 if (flag_syntax_only
)
3453 if (TREE_CODE (node
) == CALL_EXPR
3454 || TREE_CODE (node
) == NEW_CLASS_EXPR
3455 || (TREE_CODE (node
) == COMPOUND_EXPR
3456 && TREE_CODE (TREE_OPERAND (node
, 0)) == CALL_EXPR
3457 && TREE_CODE (TREE_OPERAND (node
, 1)) == SAVE_EXPR
))
3463 /* Position arg properly, account for wrapped around ctors. */
3464 if (TREE_CODE (node
) == COMPOUND_EXPR
)
3465 arg
= TREE_OPERAND (node
, 0);
3467 arg
= TREE_OPERAND (arg
, 1);
3469 /* An empty argument list is ok, just ignore it. */
3473 /* Not having a list of arguments here is an error. */
3474 if (TREE_CODE (arg
) != TREE_LIST
)
3477 /* This reverses the evaluation order. This is a desired effect. */
3478 for (cmp
= NULL_TREE
; arg
; arg
= TREE_CHAIN (arg
))
3480 /* Promote types smaller than integer. This is required by
3482 tree type
= TREE_TYPE (TREE_VALUE (arg
));
3484 if (targetm
.calls
.promote_prototypes (type
)
3485 && INTEGRAL_TYPE_P (type
)
3486 && INT_CST_LT_UNSIGNED (TYPE_SIZE (type
),
3487 TYPE_SIZE (integer_type_node
)))
3488 TREE_VALUE (arg
) = fold_convert (integer_type_node
, TREE_VALUE (arg
));
3490 saved
= save_expr (force_evaluation_order (TREE_VALUE (arg
)));
3491 cmp
= (cmp
== NULL_TREE
? saved
:
3492 build2 (COMPOUND_EXPR
, void_type_node
, cmp
, saved
));
3493 TREE_VALUE (arg
) = saved
;
3496 if (cmp
&& TREE_CODE (cmp
) == COMPOUND_EXPR
)
3497 TREE_SIDE_EFFECTS (cmp
) = 1;
3501 cmp
= build2 (COMPOUND_EXPR
, TREE_TYPE (node
), cmp
, node
);
3502 if (TREE_TYPE (cmp
) != void_type_node
)
3503 cmp
= save_expr (cmp
);
3504 CAN_COMPLETE_NORMALLY (cmp
) = CAN_COMPLETE_NORMALLY (node
);
3505 TREE_SIDE_EFFECTS (cmp
) = 1;
3512 /* EXPR_WITH_FILE_LOCATION are used to keep track of the exact
3513 location where an expression or an identifier were encountered. It
3514 is necessary for languages where the frontend parser will handle
3515 recursively more than one file (Java is one of them). */
3518 build_expr_wfl (tree node
,
3519 #ifdef USE_MAPPED_LOCATION
3520 source_location location
3522 const char *file
, int line
, int col
3528 #ifdef USE_MAPPED_LOCATION
3529 wfl
= make_node (EXPR_WITH_FILE_LOCATION
);
3530 SET_EXPR_LOCATION (wfl
, location
);
3532 static const char *last_file
= 0;
3533 static tree last_filenode
= NULL_TREE
;
3535 wfl
= make_node (EXPR_WITH_FILE_LOCATION
);
3537 EXPR_WFL_SET_LINECOL (wfl
, line
, col
);
3538 if (file
!= last_file
)
3541 last_filenode
= file
? get_identifier (file
) : NULL_TREE
;
3543 EXPR_WFL_FILENAME_NODE (wfl
) = last_filenode
;
3545 EXPR_WFL_NODE (wfl
) = node
;
3549 TREE_SIDE_EFFECTS (wfl
) = TREE_SIDE_EFFECTS (node
);
3550 TREE_TYPE (wfl
) = TREE_TYPE (node
);
3556 #ifdef USE_MAPPED_LOCATION
3558 expr_add_location (tree node
, source_location location
, bool statement
)
3562 /* FIXME. This optimization causes failures in code that expects an
3563 EXPR_WITH_FILE_LOCATION. E.g. in resolve_qualified_expression_name. */
3564 if (node
&& ! (statement
&& flag_emit_class_files
))
3566 source_location node_loc
= EXPR_LOCATION (node
);
3567 if (node_loc
== location
|| location
== UNKNOWN_LOCATION
)
3569 if (node_loc
== UNKNOWN_LOCATION
3570 && IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (node
))))
3572 SET_EXPR_LOCATION (node
, location
);
3577 wfl
= make_node (EXPR_WITH_FILE_LOCATION
);
3578 SET_EXPR_LOCATION (wfl
, location
);
3579 EXPR_WFL_NODE (wfl
) = node
;
3580 if (statement
&& debug_info_level
!= DINFO_LEVEL_NONE
)
3581 EXPR_WFL_EMIT_LINE_NOTE (wfl
) = 1;
3585 TREE_SIDE_EFFECTS (wfl
) = TREE_SIDE_EFFECTS (node
);
3586 TREE_TYPE (wfl
) = TREE_TYPE (node
);
3593 /* Build a node to represent empty statements and blocks. */
3596 build_java_empty_stmt (void)
3598 tree t
= build_empty_stmt ();
3599 CAN_COMPLETE_NORMALLY (t
) = 1;
3603 /* Promote all args of integral type before generating any code. */
3606 promote_arguments (void)
3610 for (arg
= DECL_ARGUMENTS (current_function_decl
), i
= 0;
3611 arg
!= NULL_TREE
; arg
= TREE_CHAIN (arg
), i
++)
3613 tree arg_type
= TREE_TYPE (arg
);
3614 if (INTEGRAL_TYPE_P (arg_type
)
3615 && TYPE_PRECISION (arg_type
) < 32)
3617 tree copy
= find_local_variable (i
, integer_type_node
, -1);
3618 java_add_stmt (build2 (MODIFY_EXPR
, integer_type_node
,
3620 fold_convert (integer_type_node
, arg
)));
3622 if (TYPE_IS_WIDE (arg_type
))
3627 #include "gt-java-expr.h"