1 /* Process expressions for the GNU compiler for the Java(TM) language.
2 Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
21 Java and all Java-based marks are trademarks or registered trademarks
22 of Sun Microsystems, Inc. in the United States and other countries.
23 The Free Software Foundation is independent of Sun Microsystems, Inc. */
25 /* Hacked by Per Bothner <bothner@cygnus.com> February 1996. */
33 #include "java-tree.h"
35 #include "java-opcodes.h"
37 #include "java-except.h"
41 static tree operand_type[59];
42 extern struct obstack permanent_obstack;
45 init_expr_processing()
47 operand_type[21] = operand_type[54] = int_type_node;
48 operand_type[22] = operand_type[55] = long_type_node;
49 operand_type[23] = operand_type[56] = float_type_node;
50 operand_type[24] = operand_type[57] = double_type_node;
51 operand_type[25] = operand_type[58] = ptr_type_node;
54 /* We store the stack state in two places:
55 Within a basic block, we use the quick_stack, which is a
56 pushdown list (TREE_LISTs) of expression nodes.
57 This is the top part of the stack; below that we use find_stack_slot.
58 At the end of a basic block, the quick_stack must be flushed
59 to the stack slot array (as handled by find_stack_slot).
60 Using quick_stack generates better code (especially when
61 compiled without optimization), because we do not have to
62 explicitly store and load trees to temporary variables.
64 If a variable is on the quick stack, it means the value of variable
65 when the quick stack was last flushed. Conceptually, flush_quick_stack
66 saves all the the quick_stack elements in parellel. However, that is
67 complicated, so it actually saves them (i.e. copies each stack value
68 to is home virtual register) from low indexes. This allows a quick_stack
69 element at index i (counting from the bottom of stack the) to references
70 slot virtuals for register that are >= i, but not those that are deeper.
71 This convention makes most operations easier. For example iadd works
72 even when the stack contains (reg[0], reg[1]): It results in the
73 stack containing (reg[0]+reg[1]), which is OK. However, some stack
74 operations are more complicated. For example dup given a stack
75 containing (reg[0]) would yield (reg[0], reg[0]), which would violate
76 the convention, since stack value 1 would refer to a register with
77 lower index (reg[0]), which flush_quick_stack does not safely handle.
78 So dup cannot just add an extra element to the quick_stack, but iadd can.
81 tree quick_stack = NULL_TREE;
83 /* A free-list of unused permamnet TREE_LIST nodes. */
84 tree tree_list_free_list = NULL_TREE;
86 /* The stack pointer of the Java virtual machine.
87 This does include the size of the quick_stack. */
91 unsigned char *linenumber_table;
95 truthvalue_conversion (expr)
98 /* It is simpler and generates better code to have only TRUTH_*_EXPR
99 or comparison expressions as truth values at this level.
101 This function should normally be identity for Java. */
103 switch (TREE_CODE (expr))
106 case NE_EXPR: case LE_EXPR: case GE_EXPR: case LT_EXPR: case GT_EXPR:
107 case TRUTH_ANDIF_EXPR:
108 case TRUTH_ORIF_EXPR:
115 return integer_zerop (expr) ? boolean_false_node : boolean_true_node;
118 return real_zerop (expr) ? boolean_false_node : boolean_true_node;
120 /* are these legal? XXX JH */
125 /* These don't change whether an object is non-zero or zero. */
126 return truthvalue_conversion (TREE_OPERAND (expr, 0));
129 /* Distribute the conversion into the arms of a COND_EXPR. */
130 return fold (build (COND_EXPR, boolean_type_node, TREE_OPERAND (expr, 0),
131 truthvalue_conversion (TREE_OPERAND (expr, 1)),
132 truthvalue_conversion (TREE_OPERAND (expr, 2))));
135 /* If this is widening the argument, we can ignore it. */
136 if (TYPE_PRECISION (TREE_TYPE (expr))
137 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr, 0))))
138 return truthvalue_conversion (TREE_OPERAND (expr, 0));
139 /* fall through to default */
142 return fold (build (NE_EXPR, boolean_type_node, expr, boolean_false_node));
146 #ifdef JAVA_USE_HANDLES
147 /* Given a pointer to a handle, get a pointer to an object. */
153 tree field, handle_type;
154 expr = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (expr)), expr);
155 handle_type = TREE_TYPE (expr);
156 field = TYPE_FIELDS (handle_type);
157 expr = build (COMPONENT_REF, TREE_TYPE (field), expr, field);
162 /* Save any stack slots that happen to be in the quick_stack into their
163 home virtual register slots.
165 The copy order is from low stack index to high, to support the invariant
166 that the expression for a slot may contain decls for stack slots with
167 higher (or the same) index, but not lower. */
172 int stack_index = stack_pointer;
173 register tree prev, cur, next;
175 /* First reverse the quick_stack, and count the number of slots it has. */
176 for (cur = quick_stack, prev = NULL_TREE; cur != NULL_TREE; cur = next)
178 next = TREE_CHAIN (cur);
179 TREE_CHAIN (cur) = prev;
181 stack_index -= 1 + TYPE_IS_WIDE (TREE_TYPE (TREE_VALUE (cur)));
185 while (quick_stack != NULL_TREE)
188 tree node = quick_stack, type;
189 quick_stack = TREE_CHAIN (node);
190 TREE_CHAIN (node) = tree_list_free_list;
191 tree_list_free_list = node;
192 node = TREE_VALUE (node);
193 type = TREE_TYPE (node);
195 decl = find_stack_slot (stack_index, type);
197 expand_assignment (decl, node, 0, 0);
198 stack_index += 1 + TYPE_IS_WIDE (type);
207 type = promote_type (type);
208 n_words = 1 + TYPE_IS_WIDE (type);
209 if (stack_pointer + n_words > DECL_MAX_STACK (current_function_decl))
210 fatal ("stack overflow");
211 stack_type_map[stack_pointer++] = type;
213 while (--n_words >= 0)
214 stack_type_map[stack_pointer++] = TYPE_SECOND;
221 tree type = TREE_TYPE (value);
222 if (TYPE_PRECISION (type) < 32 && INTEGRAL_TYPE_P (type))
224 type = promote_type (type);
225 value = convert (type, value);
228 if (tree_list_free_list == NULL_TREE)
229 quick_stack = perm_tree_cons (NULL_TREE, value, quick_stack);
232 tree node = tree_list_free_list;
233 tree_list_free_list = TREE_CHAIN (tree_list_free_list);
234 TREE_VALUE (node) = value;
235 TREE_CHAIN (node) = quick_stack;
247 if (TREE_CODE (type) == RECORD_TYPE)
248 type = promote_type (type);
249 n_words = 1 + TYPE_IS_WIDE (type);
250 if (stack_pointer < n_words)
251 fatal ("stack underflow");
252 while (--n_words > 0)
254 if (stack_type_map[--stack_pointer] != void_type_node)
255 fatal ("Invalid multi-word value on type stack");
257 t = stack_type_map[--stack_pointer];
258 if (type == NULL_TREE || t == type)
260 if (INTEGRAL_TYPE_P (type) && INTEGRAL_TYPE_P (t)
261 && TYPE_PRECISION (type) <= 32 && TYPE_PRECISION (t) <= 32)
263 if (TREE_CODE (type) == POINTER_TYPE && TREE_CODE (t) == POINTER_TYPE)
265 if (type == ptr_type_node || type == object_ptr_type_node)
267 else if (t == ptr_type_node) /* Special case for null reference. */
269 else if (can_widen_reference_to (t, type))
272 error ("unexpected type on stack");
276 /* Return 1f if SOURCE_TYPE can be safely widened to TARGET_TYPE.
277 Handles array types and interfaces. */
280 can_widen_reference_to (source_type, target_type)
281 tree source_type, target_type;
283 if (source_type == ptr_type_node || target_type == object_ptr_type_node)
286 /* Get rid of pointers */
287 if (TREE_CODE (source_type) == POINTER_TYPE)
288 source_type = TREE_TYPE (source_type);
289 if (TREE_CODE (target_type) == POINTER_TYPE)
290 target_type = TREE_TYPE (target_type);
292 if (source_type == target_type)
296 source_type = HANDLE_TO_CLASS_TYPE (source_type);
297 target_type = HANDLE_TO_CLASS_TYPE (target_type);
298 if (TYPE_ARRAY_P (source_type) || TYPE_ARRAY_P (target_type))
300 HOST_WIDE_INT source_length, target_length;
301 if (TYPE_ARRAY_P (source_type) != TYPE_ARRAY_P (target_type))
303 target_length = java_array_type_length (target_type);
304 if (target_length >= 0)
306 source_length = java_array_type_length (source_type);
307 if (source_length != target_length)
310 source_type = TYPE_ARRAY_ELEMENT (source_type);
311 target_type = TYPE_ARRAY_ELEMENT (target_type);
312 if (source_type == target_type)
314 if (TREE_CODE (source_type) != POINTER_TYPE
315 || TREE_CODE (target_type) != POINTER_TYPE)
317 return can_widen_reference_to (source_type, target_type);
321 int source_depth = class_depth (source_type);
322 int target_depth = class_depth (target_type);
324 if (CLASS_INTERFACE (TYPE_NAME (target_type)))
326 /* target_type is OK if source_type or source_type ancestors
327 implement target_type. We handle multiple sub-interfaces */
329 tree basetype_vec = TYPE_BINFO_BASETYPES (source_type);
330 int n = TREE_VEC_LENGTH (basetype_vec), i;
331 for (i=0 ; i < n; i++)
332 if (can_widen_reference_to
333 (TREE_TYPE (TREE_VEC_ELT (basetype_vec, i)),
340 for ( ; source_depth > target_depth; source_depth--)
342 source_type = TYPE_BINFO_BASETYPE (source_type, 0);
344 return source_type == target_type;
353 int n_words = 1 + TYPE_IS_WIDE (type);
355 type = pop_type (type);
358 tree node = quick_stack;
359 quick_stack = TREE_CHAIN (quick_stack);
360 TREE_CHAIN (node) = tree_list_free_list;
361 tree_list_free_list = node;
362 node = TREE_VALUE (node);
366 return find_stack_slot (stack_pointer, promote_type (type));
370 /* Pop and discrad the top COUNT stack slots. */
373 java_stack_pop (count)
379 if (stack_pointer == 0)
380 fatal ("stack underflow");
381 type = stack_type_map[stack_pointer - 1];
382 if (type == TYPE_SECOND)
385 if (stack_pointer == 1 || count <= 0)
386 fatal ("stack underflow");
387 type = stack_type_map[stack_pointer - 2];
389 val = pop_value (type);
394 /* Implement the 'swap' operator (to swap two top stack slots). */
403 if (stack_pointer < 2
404 || (type1 = stack_type_map[stack_pointer - 1]) == TYPE_UNKNOWN
405 || (type2 = stack_type_map[stack_pointer - 2]) == TYPE_UNKNOWN
406 || type1 == TYPE_SECOND || type2 == TYPE_SECOND
407 || TYPE_IS_WIDE (type1) || TYPE_IS_WIDE (type2))
408 fatal ("bad stack swap");
410 flush_quick_stack ();
411 decl1 = find_stack_slot (stack_pointer - 1, type1);
412 decl2 = find_stack_slot (stack_pointer - 2, type2);
413 temp = copy_to_reg (DECL_RTL (decl1));
414 emit_move_insn (DECL_RTL (decl1), DECL_RTL (decl2));
415 emit_move_insn (DECL_RTL (decl2), temp);
416 stack_type_map[stack_pointer - 1] = type2;
417 stack_type_map[stack_pointer - 2] = type1;
421 java_stack_dup (size, offset)
424 int low_index = stack_pointer - size - offset;
427 error ("stack underflow - dup* operation");
429 flush_quick_stack ();
431 stack_pointer += size;
432 dst_index = stack_pointer;
434 for (dst_index = stack_pointer; --dst_index >= low_index; )
437 int src_index = dst_index - size;
438 if (src_index < low_index)
439 src_index = dst_index + size + offset;
440 type = stack_type_map [src_index];
441 if (type == TYPE_SECOND)
443 if (src_index <= low_index)
444 fatal ("dup operation splits 64-bit number");
445 stack_type_map[dst_index] = type;
446 src_index--; dst_index--;
447 type = stack_type_map[src_index];
448 if (! TYPE_IS_WIDE (type))
449 fatal ("internal error - dup operation");
451 else if (TYPE_IS_WIDE (type))
452 fatal ("internal error - dup operation");
453 if (src_index != dst_index)
455 tree src_decl = find_stack_slot (src_index, type);
456 tree dst_decl = find_stack_slot (dst_index, type);
457 emit_move_insn (DECL_RTL (dst_decl), DECL_RTL (src_decl));
458 stack_type_map[dst_index] = type;
463 /* Calls _Jv_Throw. Discard the contents of the value stack. */
466 build_java_athrow (node)
471 call = build (CALL_EXPR,
473 build_address_of (throw_node),
474 build_tree_list (NULL_TREE, node),
476 TREE_SIDE_EFFECTS (call) = 1;
477 expand_expr_stmt (call);
478 java_stack_pop (stack_pointer);
481 /* Implementation for jsr/ret */
484 build_java_jsr (where, ret)
488 tree ret_label = fold (build1 (ADDR_EXPR, return_address_type_node, ret));
489 push_value (ret_label);
490 flush_quick_stack ();
496 build_java_ret (location)
499 expand_computed_goto (location);
502 /* Implementation of operations on array: new, load, store, length */
504 /* Array core info access macros */
506 #define JAVA_ARRAY_LENGTH_OFFSET(A) \
507 size_binop (CEIL_DIV_EXPR, \
509 (TREE_CHAIN (TYPE_FIELDS (TREE_TYPE (TREE_TYPE (A)))))), \
510 size_int (BITS_PER_UNIT))
513 decode_newarray_type (int atype)
517 case 4: return boolean_type_node;
518 case 5: return char_type_node;
519 case 6: return float_type_node;
520 case 7: return double_type_node;
521 case 8: return byte_type_node;
522 case 9: return short_type_node;
523 case 10: return int_type_node;
524 case 11: return long_type_node;
525 default: return NULL_TREE;
529 /* Build a call to _Jv_ThrowBadArrayIndex(), the
530 ArrayIndexOfBoundsException exception handler. */
533 build_java_throw_out_of_bounds_exception (index)
536 tree node = build (CALL_EXPR, int_type_node,
537 build_address_of (soft_badarrayindex_node),
538 build_tree_list (NULL_TREE, index), NULL_TREE);
539 TREE_SIDE_EFFECTS (node) = 1; /* Allows expansion within ANDIF */
543 /* Return the length of an array. Doesn't perform any checking on the nature
544 or value of the array NODE. May be used to implement some bytecodes. */
547 build_java_array_length_access (node)
550 tree type = TREE_TYPE (node);
551 HOST_WIDE_INT length;
552 if (!is_array_type_p (type))
553 fatal ("array length on a non-array reference");
554 length = java_array_type_length (type);
556 return build_int_2 (length, 0);
557 return fold (build1 (INDIRECT_REF,
559 fold (build (PLUS_EXPR, ptr_type_node,
561 JAVA_ARRAY_LENGTH_OFFSET(node)))));
564 /* Optionally checks an array against the NULL pointer, eventually throwing a
565 NullPointerException. It could replace signal handling, but tied to NULL.
566 ARG1: the pointer to check, ARG2: the expression to use if
567 the pointer is non-null and ARG3 the type that should be returned. */
570 build_java_arraynull_check (node, expr, type)
576 static int java_array_access_throws_null_exception = 0;
578 if (java_array_access_throws_null_exception)
579 return (build (COND_EXPR,
581 build (EQ_EXPR, int_type_node, node, null_pointer_node),
582 build_java_athrow (node), expr ));
589 java_array_data_offset (array)
592 tree array_type = TREE_TYPE (TREE_TYPE (array));
593 tree data_fld = TREE_CHAIN (TREE_CHAIN (TYPE_FIELDS (array_type)));
594 if (data_fld == NULL_TREE)
595 return size_in_bytes (array_type);
597 return build_int_2 (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (data_fld))
601 /* Implement array indexing (either as l-value or r-value).
602 Returns a tree for ARRAY[INDEX], assume TYPE is the element type.
603 Optionally performs bounds checking and/or test to NULL.
604 At this point, ARRAY should have been verified as an array. */
607 build_java_arrayaccess (array, type, index)
608 tree array, type, index;
610 tree arith, node, throw = NULL_TREE;
612 arith = fold (build (PLUS_EXPR, int_type_node,
613 java_array_data_offset (array),
614 fold (build (MULT_EXPR, int_type_node,
615 index, size_in_bytes(type)))));
617 if (flag_bounds_check)
620 * (unsigned jint) INDEX >= (unsigned jint) LEN
621 * && throw ArrayIndexOutOfBoundsException.
622 * Note this is equivalent to and more efficient than:
623 * INDEX < 0 || INDEX >= LEN && throw ... */
625 tree len = build_java_array_length_access (array);
626 TREE_TYPE (len) = unsigned_int_type_node;
627 test = fold (build (GE_EXPR, boolean_type_node,
628 convert (unsigned_int_type_node, index),
630 if (! integer_zerop (test))
632 throw = build (TRUTH_ANDIF_EXPR, int_type_node, test,
633 build_java_throw_out_of_bounds_exception (index));
634 /* allows expansion within COMPOUND */
635 TREE_SIDE_EFFECTS( throw ) = 1;
639 node = build1 (INDIRECT_REF, type,
640 fold (build (PLUS_EXPR, ptr_type_node,
642 (throw ? build (COMPOUND_EXPR, int_type_node,
646 return (fold (build_java_arraynull_check (array, node, type)));
649 /* Makes sure that INDEXED_TYPE is appropriate. If not, make it from
650 ARRAY_NODE. This function is used to retrieve something less vague than
651 a pointer type when indexing the first dimension of something like [[<t>.
652 May return a corrected type, if necessary, otherwise INDEXED_TYPE is
654 As a side effect, it also makes sure that ARRAY_NODE is an array. */
657 build_java_check_indexed_type (array_node, indexed_type)
663 if (!is_array_type_p (TREE_TYPE (array_node)))
664 fatal ("array indexing on a non-array reference");
666 elt_type = (TYPE_ARRAY_ELEMENT (TREE_TYPE (TREE_TYPE (array_node))));
668 if (indexed_type == ptr_type_node )
669 return promote_type (elt_type);
671 /* BYTE/BOOLEAN store and load are used for both type */
672 if (indexed_type == byte_type_node && elt_type == boolean_type_node )
673 return boolean_type_node;
675 if (indexed_type != elt_type )
676 fatal ("type array element mismatch");
681 /* newarray triggers a call to _Jv_NewArray. This function should be called
682 with an integer code (the type of array to create) and get from the stack
683 the size of the dimmension. */
686 build_newarray (atype_value, length)
690 tree type = build_java_array_type (decode_newarray_type (atype_value),
691 TREE_CODE (length) == INTEGER_CST
692 ? TREE_INT_CST_LOW (length)
694 return build (CALL_EXPR, promote_type (type),
695 build_address_of (soft_newarray_node),
696 tree_cons (NULL_TREE,
697 build_int_2 (atype_value, 0),
698 build_tree_list (NULL_TREE, length)),
702 /* Generates anewarray from a given CLASS_TYPE. Gets from the stack the size
704 /* Merge with build_newarray. FIXME. */
706 build_anewarray (class_type, length)
710 tree type = build_java_array_type (class_type,
711 TREE_CODE (length) == INTEGER_CST
712 ? TREE_INT_CST_LOW (length)
714 return build (CALL_EXPR, promote_type (type),
715 build_address_of (soft_anewarray_node),
716 tree_cons (NULL_TREE, length,
717 tree_cons (NULL_TREE, build_class_ref (class_type),
718 build_tree_list (NULL_TREE,
719 null_pointer_node))),
723 /* Generates a call to _Jv_NewMultiArray. multianewarray expects a
724 class pointer, a number of dimensions and the matching number of
725 dimensions. The argument list is NULL terminated. */
728 expand_java_multianewarray (class_type, ndim)
733 tree args = build_tree_list( NULL_TREE, null_pointer_node );
735 for( i = 0; i < ndim; i++ )
736 args = tree_cons (NULL_TREE, pop_value (int_type_node), args);
738 push_value (build (CALL_EXPR,
739 promote_type (class_type),
740 build_address_of (soft_multianewarray_node),
741 tree_cons (NULL_TREE, build_class_ref (class_type),
742 tree_cons (NULL_TREE,
743 build_int_2 (ndim, 0), args )),
747 /* ARRAY[INDEX] <- RHS. build_java_check_indexed_type makes sure that
748 ARRAY is an array type. May expand some bound checking and NULL
749 pointer checking. RHS_TYPE_NODE we are going to store. In the case
750 of the CHAR/BYTE/BOOLEAN SHORT, the type popped of the stack is an
751 INT. In those cases, we make the convertion.
753 if ARRAy is a reference type, the assignment is checked at run-time
754 to make sure that the RHS can be assigned to the array element
755 type. It is not necessary to generate this code if ARRAY is final. */
758 expand_java_arraystore (rhs_type_node)
761 tree rhs_node = pop_value ((INTEGRAL_TYPE_P (rhs_type_node)
762 && TYPE_PRECISION (rhs_type_node) <= 32) ?
763 int_type_node : rhs_type_node);
764 tree index = pop_value (int_type_node);
765 tree array = pop_value (ptr_type_node);
767 rhs_type_node = build_java_check_indexed_type (array, rhs_type_node);
769 flush_quick_stack ();
771 index = save_expr (index);
772 array = save_expr (array);
774 if (TREE_CODE (rhs_type_node) == POINTER_TYPE
775 && !CLASS_FINAL (TYPE_NAME (TREE_TYPE (rhs_type_node))))
777 tree check = build (CALL_EXPR, void_type_node,
778 build_address_of (soft_checkarraystore_node),
779 tree_cons (NULL_TREE, array,
780 build_tree_list (NULL_TREE, rhs_node)),
782 TREE_SIDE_EFFECTS (check) = 1;
783 expand_expr_stmt (check);
786 expand_assignment (build_java_arrayaccess (array,
792 /* Expand the evaluation of ARRAY[INDEX]. build_java_check_indexed_type makes
793 sure that LHS is an array type. May expand some bound checking and NULL
795 LHS_TYPE_NODE is the type of ARRAY[INDEX]. But in the case of CHAR/BYTE/
796 BOOLEAN/SHORT, we push a promoted type back to the stack.
800 expand_java_arrayload (lhs_type_node )
805 tree index_node = pop_value (int_type_node);
806 tree array_node = pop_value (ptr_type_node);
808 index_node = save_expr (index_node);
809 array_node = save_expr (array_node);
810 lhs_type_node = build_java_check_indexed_type (array_node, lhs_type_node);
812 load_node = build_java_arrayaccess (array_node,
816 if (INTEGRAL_TYPE_P (lhs_type_node) && TYPE_PRECISION (lhs_type_node) <= 32)
817 load_node = fold (build1 (NOP_EXPR, int_type_node, load_node));
818 push_value (load_node);
821 /* Expands .length. Makes sure that we deal with and array and may expand
822 a NULL check on the array object. */
825 expand_java_array_length ()
827 tree array = pop_value (ptr_type_node);
828 tree length = build_java_array_length_access (array);
830 push_value (build_java_arraynull_check (array, length, int_type_node));
833 /* Emit code for the call to _Jv_Monitor{Enter,Exit}. CALL can be
834 either soft_monitorenter_node or soft_monitorexit_node. */
837 build_java_monitor (call, object)
841 return (build (CALL_EXPR,
843 build_address_of (call),
844 build_tree_list (NULL_TREE, object),
848 /* Emit code for one of the PUSHC instructions. */
851 expand_java_pushc (ival, type)
856 if (type == ptr_type_node && ival == 0)
857 value = null_pointer_node;
858 else if (type == int_type_node || type == long_type_node)
860 value = build_int_2 (ival, ival < 0 ? -1 : 0);
861 TREE_TYPE (value) = type;
863 else if (type == float_type_node || type == double_type_node)
866 #ifdef REAL_ARITHMETIC
867 REAL_VALUE_FROM_INT (x, ival, 0, TYPE_MODE (type));
871 value = build_real (type, x);
874 fatal ("internal error in expand_java_pushc");
879 expand_java_return (type)
882 if (type == void_type_node)
883 expand_null_return ();
886 tree retval = pop_value (type);
887 tree res = DECL_RESULT (current_function_decl);
888 retval = build (MODIFY_EXPR, TREE_TYPE (res), res, retval);
889 TREE_SIDE_EFFECTS (retval) = 1;
890 expand_return (retval);
895 build_address_of (value)
898 return build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (value)), value);
902 expand_java_NEW (type)
905 if (! CLASS_LOADED_P (type))
906 load_class (type, 1);
907 push_value (build (CALL_EXPR, promote_type (type),
908 build_address_of (alloc_object_node),
909 tree_cons (NULL_TREE, build_class_ref (type),
910 build_tree_list (NULL_TREE,
911 size_in_bytes (type))),
916 expand_java_INSTANCEOF (type)
919 tree value = pop_value (object_ptr_type_node);
920 value = build (CALL_EXPR, TREE_TYPE (TREE_TYPE (soft_instanceof_node)),
921 build_address_of (soft_instanceof_node),
922 tree_cons (NULL_TREE, value,
923 build_tree_list (NULL_TREE,
924 build_class_ref (type))),
930 expand_java_CHECKCAST (type)
933 tree value = pop_value (ptr_type_node);
934 value = build (CALL_EXPR, promote_type (type),
935 build_address_of (soft_checkcast_node),
936 tree_cons (NULL_TREE, build_class_ref (type),
937 build_tree_list (NULL_TREE, value)),
943 expand_iinc (unsigned int local_var_index, int ival, int pc)
948 flush_quick_stack ();
949 local_var = find_local_variable (local_var_index, int_type_node, pc);
950 constant_value = build_int_2 (ival, ival < 0 ? -1 : 0);
951 res = fold (build (PLUS_EXPR, int_type_node, local_var, constant_value));
952 expand_assignment (local_var, res, 0, 0);
956 build_java_binop (op, type, arg1, arg2)
958 tree type, arg1, arg2;
965 tree u_type = unsigned_type (type);
966 arg1 = convert (u_type, arg1);
967 arg1 = build_java_binop (RSHIFT_EXPR, u_type, arg1, arg2);
968 return convert (type, arg1);
972 mask = build_int_2 (TYPE_PRECISION (TREE_TYPE (arg1)) - 1, 0);
973 arg2 = fold (build (BIT_AND_EXPR, int_type_node, arg2, mask));
976 case COMPARE_L_EXPR: /* arg1 > arg2 ? 1 : arg1 == arg2 ? 0 : -1 */
977 case COMPARE_G_EXPR: /* arg1 < arg2 ? -1 : arg1 == arg2 ? 0 : 1 */
978 arg1 = save_expr (arg1); arg2 = save_expr (arg2);
980 tree ifexp1 = fold ( build (op == COMPARE_L_EXPR ? GT_EXPR : LT_EXPR,
981 boolean_type_node, arg1, arg2));
982 tree ifexp2 = fold ( build (EQ_EXPR, boolean_type_node, arg1, arg2));
983 tree second_compare = fold (build (COND_EXPR, int_type_node,
984 ifexp2, integer_zero_node,
986 ? integer_negative_one_node
987 : integer_one_node));
988 return fold (build (COND_EXPR, int_type_node, ifexp1,
989 op == COMPARE_L_EXPR ? integer_one_node
990 : integer_negative_one_node,
994 arg1 = save_expr (arg1); arg2 = save_expr (arg2);
996 tree ifexp1 = fold ( build (LT_EXPR, boolean_type_node, arg1, arg2));
997 tree ifexp2 = fold ( build (GT_EXPR, boolean_type_node, arg1, arg2));
998 tree second_compare = fold ( build (COND_EXPR, int_type_node,
999 ifexp2, integer_one_node,
1000 integer_zero_node));
1001 return fold (build (COND_EXPR, int_type_node,
1002 ifexp1, integer_negative_one_node, second_compare));
1005 case TRUNC_MOD_EXPR:
1006 if (TREE_CODE (type) == REAL_TYPE)
1009 if (type != double_type_node)
1011 arg1 = convert (double_type_node, arg1);
1012 arg2 = convert (double_type_node, arg2);
1014 call = build (CALL_EXPR, double_type_node,
1015 build_address_of (soft_fmod_node),
1016 tree_cons (NULL_TREE, arg1,
1017 build_tree_list (NULL_TREE, arg2)),
1019 if (type != double_type_node)
1020 call = convert (type, call);
1025 #if 0 /* not required */
1029 case TRUNC_DIV_EXPR:
1031 /* case REM_EXPR: */
1037 error ("unknown opcode");
1038 return error_mark_node;
1042 return fold (build (op, type, arg1, arg2));
1046 expand_java_binop (type, op)
1047 tree type; enum tree_code op;
1057 rtype = int_type_node;
1058 rarg = pop_value (rtype);
1061 rarg = pop_value (rtype);
1063 larg = pop_value (ltype);
1064 push_value (build_java_binop (op, type, larg, rarg));
1067 /* Lookup the field named NAME in *TYPEP or its super classes.
1068 If not found, return NULL_TREE.
1069 (If the *TYPEP is not found, return error_mark_node.)
1070 If found, return the FIELD_DECL, and set *TYPEP to the
1071 class containing the field. */
1074 lookup_field (typep, name)
1078 if (CLASS_P (*typep) && !CLASS_LOADED_P (*typep))
1080 load_class (*typep, 1);
1081 if (TREE_CODE (TYPE_SIZE (*typep)) == ERROR_MARK)
1082 return error_mark_node;
1087 for (field = TYPE_FIELDS (*typep); field; field = TREE_CHAIN (field))
1089 if (DECL_NAME (field) == name)
1092 *typep = CLASSTYPE_SUPER (*typep);
1097 /* Look up the field named NAME in object SELF_VALUE,
1098 which has class SELF_CLASS (a non-handle RECORD_TYPE).
1099 SELF_VALUE is NULL_TREE if looking for a static field. */
1102 build_field_ref (self_value, self_class, name)
1103 tree self_value, self_class, name;
1105 tree base_class = self_class;
1106 tree field_decl = lookup_field (&base_class, name);
1107 if (field_decl == NULL_TREE)
1109 error ("field `%s' not found", IDENTIFIER_POINTER (name));
1110 return error_mark_node;
1112 if (self_value == NULL_TREE)
1114 return build_static_field_ref (field_decl);
1118 tree base_handle_type = promote_type (base_class);
1119 if (base_handle_type != TREE_TYPE (self_value))
1120 self_value = fold (build1 (NOP_EXPR, base_handle_type, self_value));
1121 #ifdef JAVA_USE_HANDLES
1122 self_value = unhand_expr (self_value);
1124 self_value = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (self_value)),
1126 return fold (build (COMPONENT_REF, TREE_TYPE (field_decl),
1127 self_value, field_decl));
1137 sprintf (buf, "LJpc=%d", pc);
1138 name = get_identifier (buf);
1139 if (IDENTIFIER_LOCAL_VALUE (name))
1140 return IDENTIFIER_LOCAL_VALUE (name);
1143 /* The type of the address of a label is return_address_type_node. */
1144 tree decl = create_label_decl (name);
1145 LABEL_PC (decl) = pc;
1147 return pushdecl (decl);
1151 /* Generate a unique name for the purpose of loops and switches
1152 labels, and try-catch-finally blocks label or temporary variables. */
1157 static int l_number = 0;
1159 sprintf (buff, "$L%d", l_number++);
1160 return get_identifier (buff);
1164 create_label_decl (name)
1168 push_obstacks (&permanent_obstack, &permanent_obstack);
1169 decl = build_decl (LABEL_DECL, name,
1170 TREE_TYPE (return_address_type_node));
1172 DECL_CONTEXT (decl) = current_function_decl;
1173 DECL_IGNORED_P (decl) = 1;
1177 /* This maps a bytecode offset (PC) to various flags. */
1178 char *instruction_bits;
1181 note_label (current_pc, target_pc)
1182 int current_pc, target_pc;
1184 lookup_label (target_pc);
1185 instruction_bits [target_pc] |= BCODE_JUMP_TARGET;
1188 /* Emit code to jump to TARGET_PC if VALUE1 CONDITION VALUE2,
1189 where CONDITION is one of one the compare operators. */
1192 expand_compare (condition, value1, value2, target_pc)
1193 enum tree_code condition;
1194 tree value1, value2;
1197 tree target = lookup_label (target_pc);
1198 tree cond = fold (build (condition, boolean_type_node, value1, value2));
1199 expand_start_cond (truthvalue_conversion (cond), 0);
1200 expand_goto (target);
1204 /* Emit code for a TEST-type opcode. */
1207 expand_test (condition, type, target_pc)
1208 enum tree_code condition;
1212 tree value1, value2;
1213 flush_quick_stack ();
1214 value1 = pop_value (type);
1215 value2 = (type == ptr_type_node) ? null_pointer_node : integer_zero_node;
1216 expand_compare (condition, value1, value2, target_pc);
1219 /* Emit code for a COND-type opcode. */
1222 expand_cond (condition, type, target_pc)
1223 enum tree_code condition;
1227 tree value1, value2;
1228 flush_quick_stack ();
1229 /* note: pop values in opposite order */
1230 value2 = pop_value (type);
1231 value1 = pop_value (type);
1232 /* Maybe should check value1 and value2 for type compatibility ??? */
1233 expand_compare (condition, value1, value2, target_pc);
1237 expand_java_goto (target_pc)
1240 tree target_label = lookup_label (target_pc);
1241 flush_quick_stack ();
1242 expand_goto (target_label);
1246 expand_java_call (target_pc, return_address)
1247 int target_pc, return_address;
1249 tree target_label = lookup_label (target_pc);
1250 tree value = build_int_2 (return_address, return_address < 0 ? -1 : 0);
1252 flush_quick_stack ();
1253 expand_goto (target_label);
1257 expand_java_ret (return_address)
1258 tree return_address;
1260 warning ("ret instruction not implemented");
1262 tree target_label = lookup_label (target_pc);
1263 flush_quick_stack ();
1264 expand_goto (target_label);
1268 /* Recursive helper function to pop argument types during verifiation. */
1271 pop_argument_types (arg_types)
1274 if (arg_types == NULL_TREE)
1276 if (TREE_CODE (arg_types) == TREE_LIST)
1278 pop_argument_types (TREE_CHAIN (arg_types));
1279 pop_type (TREE_VALUE (arg_types));
1286 pop_arguments (arg_types)
1289 if (arg_types == NULL_TREE)
1291 if (TREE_CODE (arg_types) == TREE_LIST)
1293 tree tail = pop_arguments (TREE_CHAIN (arg_types));
1294 tree type = TREE_VALUE (arg_types);
1295 tree arg = pop_value (type);
1296 #ifdef PROMOTE_PROTOTYPES
1297 if (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)
1298 && INTEGRAL_TYPE_P (type))
1299 arg = convert (integer_type_node, arg);
1301 return tree_cons (NULL_TREE, arg, tail);
1306 /* Build an expression to initialize the class CLAS.
1307 if EXPR is non-NULL, returns an expression to first call the initializer
1308 (if it is needed) and then calls EXPR. */
1311 build_class_init (clas, expr)
1315 if (inherits_from_p (current_class, clas))
1317 init = build (CALL_EXPR, void_type_node,
1318 build_address_of (soft_initclass_node),
1319 build_tree_list (NULL_TREE, build_class_ref (clas)),
1321 TREE_SIDE_EFFECTS (init) = 1;
1322 if (expr != NULL_TREE)
1324 expr = build (COMPOUND_EXPR, TREE_TYPE (expr), init, expr);
1325 TREE_SIDE_EFFECTS (expr) = 1;
1331 static tree methods_ident = NULL_TREE;
1332 static tree ncode_ident = NULL_TREE;
1333 tree dtable_ident = NULL_TREE;
1336 build_known_method_ref (method, method_type, self_type, method_signature, arg_list)
1337 tree method, method_type, self_type, method_signature, arg_list;
1340 if (is_compiled_class (self_type))
1342 make_decl_rtl (method, NULL, 1);
1343 func = build1 (ADDR_EXPR, method_ptr_type_node, method);
1347 /* We don't know whether the method has been (statically) compiled.
1348 Compile this code to get a reference to the method's code:
1350 SELF_TYPE->methods[METHOD_INDEX].ncode
1352 This is guaranteed to work (assuming SELF_TYPE has
1353 been initialized), since if the method is not compiled yet,
1354 its ncode points to a trampoline that forces compilation. */
1356 int method_index = 0;
1358 tree ref = build_class_ref (self_type);
1359 ref = build1 (INDIRECT_REF, class_type_node, ref);
1360 if (ncode_ident == NULL_TREE)
1361 ncode_ident = get_identifier ("ncode");
1362 if (methods_ident == NULL_TREE)
1363 methods_ident = get_identifier ("methods");
1364 ref = build (COMPONENT_REF, method_ptr_type_node, ref,
1365 lookup_field (&class_type_node, methods_ident));
1366 for (meth = TYPE_METHODS (CLASS_TO_HANDLE_TYPE (self_type));
1367 ; meth = TREE_CHAIN (meth))
1371 if (meth == NULL_TREE)
1372 fatal ("method '%s' not found in class",
1373 IDENTIFIER_POINTER (DECL_NAME (method)));
1376 method_index *= int_size_in_bytes (method_type_node);
1377 ref = fold (build (PLUS_EXPR, method_ptr_type_node,
1378 ref, build_int_2 (method_index, 0)));
1379 ref = build1 (INDIRECT_REF, method_type_node, ref);
1380 func = build (COMPONENT_REF, nativecode_ptr_type_node,
1382 lookup_field (&method_type_node, ncode_ident));
1388 invoke_build_dtable (is_invoke_interface, arg_list)
1389 int is_invoke_interface;
1392 tree dtable, objectref;
1394 TREE_VALUE (arg_list) = save_expr (TREE_VALUE (arg_list));
1396 /* If we're dealing with interfaces and if the objectref
1397 argument is an array then get the dispatch table of the class
1398 Object rather than the one from the objectref. */
1399 objectref = (is_invoke_interface
1400 && is_array_type_p (TREE_TYPE (TREE_VALUE (arg_list))) ?
1401 object_type_node : TREE_VALUE (arg_list));
1403 if (dtable_ident == NULL_TREE)
1404 dtable_ident = get_identifier ("dtable");
1405 dtable = build1 (INDIRECT_REF, object_type_node, objectref );
1406 dtable = build (COMPONENT_REF, dtable_ptr_type, dtable,
1407 lookup_field (&object_type_node, dtable_ident));
1413 build_invokevirtual (dtable, method)
1414 tree dtable, method;
1417 tree nativecode_ptr_ptr_type_node
1418 = build_pointer_type (nativecode_ptr_type_node);
1419 int method_index = TREE_INT_CST_LOW (DECL_VINDEX (method));
1420 /* Add one to skip "class" field of dtable, and one to skip unused
1421 vtable entry (for C++ compatibility). */
1424 *= int_size_in_bytes (nativecode_ptr_ptr_type_node);
1425 func = fold (build (PLUS_EXPR, nativecode_ptr_ptr_type_node,
1426 dtable, build_int_2 (method_index, 0)));
1427 func = build1 (INDIRECT_REF, nativecode_ptr_type_node, func);
1433 build_invokeinterface (dtable, method_name, method_signature)
1434 tree dtable, method_name, method_signature;
1436 static tree class_ident = NULL_TREE;
1439 /* We expand invokeinterface here. _Jv_LookupInterfaceMethod() will
1440 ensure that the selected method exists, is public and not
1441 abstract nor static. */
1443 if (class_ident == NULL_TREE)
1444 class_ident = get_identifier ("class");
1446 dtable = build1 (INDIRECT_REF, dtable_type, dtable);
1447 dtable = build (COMPONENT_REF, class_ptr_type, dtable,
1448 lookup_field (&dtable_type, class_ident));
1449 lookup_arg = build_tree_list (NULL_TREE, build_utf8_ref (method_signature));
1450 lookup_arg = tree_cons (NULL_TREE, dtable,
1451 tree_cons (NULL_TREE, build_utf8_ref (method_name),
1453 return build (CALL_EXPR, ptr_type_node,
1454 build_address_of (soft_lookupinterfacemethod_node),
1455 lookup_arg, NULL_TREE);
1458 /* Expand one of the invoke_* opcodes.
1459 OCPODE is the specific opcode.
1460 METHOD_REF_INDEX is an index into the constant pool.
1461 NARGS is the number of arguments, or -1 if not specified. */
1464 expand_invoke (opcode, method_ref_index, nargs)
1466 int method_ref_index;
1469 tree method_signature = COMPONENT_REF_SIGNATURE(¤t_jcf->cpool, method_ref_index);
1470 tree method_name = COMPONENT_REF_NAME (¤t_jcf->cpool, method_ref_index);
1471 tree self_type = get_class_constant
1472 (current_jcf, COMPONENT_REF_CLASS_INDEX(¤t_jcf->cpool, method_ref_index));
1473 char *self_name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (self_type)));
1474 tree call, func, method, arg_list, method_type;
1476 if (! CLASS_LOADED_P (self_type))
1478 load_class (self_type, 1);
1479 if (TREE_CODE (TYPE_SIZE (self_type)) == ERROR_MARK)
1480 fatal ("failed to find class '%s'", self_name);
1483 if (method_name == init_identifier_node)
1484 method = lookup_java_constructor (CLASS_TO_HANDLE_TYPE (self_type),
1487 method = lookup_java_method (CLASS_TO_HANDLE_TYPE (self_type),
1488 method_name, method_signature);
1489 if (method == NULL_TREE)
1491 error ("Class '%s' has no method named '%s' matching signature '%s'",
1493 IDENTIFIER_POINTER (method_name),
1494 IDENTIFIER_POINTER (method_signature));
1496 /* Invoke static can't invoke static/abstract method */
1497 else if (opcode == OPCODE_invokestatic)
1499 if (!METHOD_STATIC (method))
1501 error ("invokestatic on non static method");
1504 else if (METHOD_ABSTRACT (method))
1506 error ("invokestatic on abstract method");
1512 if (METHOD_STATIC (method))
1514 error ("invoke[non-static] on static method");
1519 if (method == NULL_TREE)
1521 method_type = get_type_from_signature (method_signature);
1522 pop_arguments (TYPE_ARG_TYPES (method_type));
1523 if (opcode != OPCODE_invokestatic)
1524 pop_type (self_type);
1525 method_type = promote_type (TREE_TYPE (method_type));
1526 push_value (convert (method_type, integer_zero_node));
1530 method_type = TREE_TYPE (method);
1531 arg_list = pop_arguments (TYPE_ARG_TYPES (method_type));
1532 flush_quick_stack ();
1535 if (opcode == OPCODE_invokestatic || opcode == OPCODE_invokespecial
1536 || (opcode == OPCODE_invokevirtual
1537 && (METHOD_FINAL (method) || CLASS_FINAL (TYPE_NAME (self_type)))))
1538 func = build_known_method_ref (method, method_type, self_type,
1539 method_signature, arg_list);
1542 tree dtable = invoke_build_dtable (opcode == OPCODE_invokeinterface,
1544 if (opcode == OPCODE_invokevirtual)
1545 func = build_invokevirtual (dtable, method);
1547 func = build_invokeinterface (dtable, method_name, method_signature);
1549 func = build1 (NOP_EXPR, build_pointer_type (method_type), func);
1550 call = build (CALL_EXPR, TREE_TYPE (method_type), func, arg_list, NULL_TREE);
1551 TREE_SIDE_EFFECTS (call) = 1;
1553 if (TREE_CODE (TREE_TYPE (method_type)) == VOID_TYPE)
1554 expand_expr_stmt (call);
1558 flush_quick_stack ();
1563 /* Expand an operation to extract from or store into a field.
1564 IS_STATIC is 1 iff the field is static.
1565 IS_PUTTING is 1 for putting into a field; 0 for getting from the field.
1566 FIELD_REF_INDEX is an index into the constant pool. */
1569 expand_java_field_op (is_static, is_putting, field_ref_index)
1572 int field_ref_index;
1574 tree self_type = get_class_constant
1575 (current_jcf, COMPONENT_REF_CLASS_INDEX (¤t_jcf->cpool, field_ref_index));
1576 char *self_name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (self_type)));
1577 tree field_name = COMPONENT_REF_NAME (¤t_jcf->cpool, field_ref_index);
1578 tree field_signature = COMPONENT_REF_SIGNATURE (¤t_jcf->cpool, field_ref_index);
1579 tree field_type = get_type_from_signature (field_signature);
1580 tree new_value = is_putting ? pop_value (field_type) : NULL_TREE;
1583 tree field_decl = lookup_field (&self_type, field_name);
1584 if (field_decl == error_mark_node)
1588 else if (field_decl == NULL_TREE)
1590 error ("Missing field '%s' in '%s'",
1591 IDENTIFIER_POINTER (field_name), self_name);
1594 else if (build_java_signature (TREE_TYPE (field_decl)) != field_signature)
1596 error ("Mismatching signature for field '%s' in '%s'",
1597 IDENTIFIER_POINTER (field_name), self_name);
1600 field_ref = is_static ? NULL_TREE : pop_value (self_type);
1604 push_value (convert (field_type, integer_zero_node));
1605 flush_quick_stack ();
1609 /* Inline references to java.lang.PRIMTYPE.TYPE.
1610 In addition to being a useful (minor) optimization,
1611 this is also needed to avoid circularities in the implementation
1612 of these fields in libjava. */
1613 if (field_name == TYPE_identifier_node && ! is_putting
1614 && field_type == class_ptr_type
1615 && strncmp (self_name, "java.lang.", 10) == 0)
1617 tree typ = build_primtype_type_ref (self_name);
1625 field_ref = build_field_ref (field_ref, self_type, field_name);
1627 field_ref = build_class_init (self_type, field_ref);
1630 flush_quick_stack ();
1631 if (FIELD_FINAL (field_decl))
1633 if (DECL_CONTEXT (field_decl) != current_class)
1634 error_with_decl (field_decl,
1635 "assignment to final field `%s' not in field's class");
1636 else if (FIELD_STATIC (field_decl))
1638 if (DECL_NAME (current_function_decl) != clinit_identifier_node)
1639 error_with_decl (field_decl,
1640 "assignment to final static field `%s' not in class initializer");
1644 if (! DECL_CONSTRUCTOR_P (current_function_decl))
1645 error_with_decl (field_decl,
1646 "assignment to final field `%s' not in constructor");
1649 expand_assignment (field_ref, new_value, 0, 0);
1652 push_value (field_ref);
1656 build_primtype_type_ref (self_name)
1659 char *class_name = self_name+10;
1661 if (strncmp(class_name, "Byte", 4) == 0)
1662 typ = byte_type_node;
1663 else if (strncmp(class_name, "Short", 5) == 0)
1664 typ = short_type_node;
1665 else if (strncmp(class_name, "Integer", 7) == 0)
1666 typ = int_type_node;
1667 else if (strncmp(class_name, "Long", 4) == 0)
1668 typ = long_type_node;
1669 else if (strncmp(class_name, "Float", 5) == 0)
1670 typ = float_type_node;
1671 else if (strncmp(class_name, "Boolean", 7) == 0)
1672 typ = boolean_type_node;
1673 else if (strncmp(class_name, "Char", 4) == 0)
1674 typ = char_type_node;
1675 else if (strncmp(class_name, "Void", 4) == 0)
1676 typ = void_type_node;
1679 if (typ != NULL_TREE)
1680 return build_class_ref (typ);
1686 load_type_state (label)
1690 tree vec = LABEL_TYPE_STATE (label);
1691 int cur_length = TREE_VEC_LENGTH (vec);
1692 stack_pointer = cur_length - DECL_MAX_LOCALS(current_function_decl);
1693 for (i = 0; i < cur_length; i++)
1694 type_map [i] = TREE_VEC_ELT (vec, i);
1697 /* Do the expansion of a Java switch. With Gcc, switches are front-end
1698 dependant things, but they rely on gcc routines. This function is
1699 placed here because it uses things defined locally in parse.y. */
1702 case_identity (t, v)
1703 tree t __attribute__ ((__unused__));
1710 java_lang_expand_expr (exp, target, tmode, modifier)
1713 enum machine_mode tmode;
1714 enum expand_modifier modifier;
1717 tree type = TREE_TYPE (exp);
1718 register enum machine_mode mode = TYPE_MODE (type);
1719 int unsignedp = TREE_UNSIGNED (type);
1723 switch (TREE_CODE (exp))
1726 if (BLOCK_EXPR_BODY (exp))
1729 tree body = BLOCK_EXPR_BODY (exp);
1730 struct rtx_def *to_return;
1731 pushlevel (2); /* 2 and above */
1732 expand_start_bindings (0);
1733 local = BLOCK_EXPR_DECLS (exp);
1736 tree next = TREE_CHAIN (local);
1737 layout_decl (local, 0);
1738 expand_decl (pushdecl (local));
1741 /* Avoid deep recursion for long block. */
1742 while (TREE_CODE (body) == COMPOUND_EXPR)
1744 expand_expr (TREE_OPERAND (body, 0), const0_rtx, VOIDmode, 0);
1745 body = TREE_OPERAND (body, 1);
1747 to_return = expand_expr (body, target, tmode, modifier);
1749 expand_end_bindings (getdecls (), 1, 0);
1757 if (pushcase (TREE_OPERAND (exp, 0), case_identity,
1758 build_decl (LABEL_DECL, NULL_TREE, NULL_TREE), &duplicate) == 2)
1760 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (exp);
1762 (wfl_operator, "Duplicate case label: `%s'",
1763 print_int_node (TREE_OPERAND (exp, 0)));
1769 pushcase (NULL_TREE, 0, build_decl (LABEL_DECL, NULL_TREE, NULL_TREE), NULL);
1773 expand_start_case (0, TREE_OPERAND (exp, 0), int_type_node, "switch");
1774 expand_expr_stmt (TREE_OPERAND (exp, 1));
1775 expand_end_case (TREE_OPERAND (exp, 0));
1779 /* We expand a try[-catch][-finally] block */
1781 /* Expand the try block */
1782 expand_eh_region_start ();
1783 expand_expr_stmt (TREE_OPERAND (exp, 0));
1784 expand_start_all_catch ();
1785 has_finally_p = (TREE_OPERAND (exp, 2) ? 1 : 0);
1787 /* Expand all catch clauses (EH handlers) */
1788 for (current = TREE_OPERAND (exp, 1); current;
1789 current = TREE_CHAIN (current))
1791 extern rtx return_label;
1793 /* If we have a finally, the last exception handler is the
1794 one that is supposed to catch everything. */
1795 if (has_finally_p && !TREE_CHAIN (current))
1799 tree catch = java_get_catch_block (current, has_finally_p);
1800 tree decl = BLOCK_EXPR_DECLS (catch);
1801 type = (decl ? TREE_TYPE (TREE_TYPE (decl)) : NULL_TREE);
1803 start_catch_handler (prepare_eh_table_type (type));
1804 expand_expr_stmt (TREE_OPERAND (current, 0));
1806 /* Need to expand a goto to the end of the function here,
1807 but not for the catch everything handler. */
1811 emit_jump (return_label);
1813 fatal ("No return_label for this function - "
1814 "java_lang_expand_expr");
1816 end_catch_handler ();
1819 /* Expand the finally block, if any */
1822 tree finally = TREE_OPERAND (exp, 2);
1823 if (FINALLY_EXPR_LABEL (finally))
1824 emit_label (label_rtx (FINALLY_EXPR_LABEL (finally)));
1825 expand_expr_stmt (FINALLY_EXPR_BLOCK (finally));
1827 expand_end_all_catch ();
1831 fatal ("Can't expand '%s' tree - java_lang_expand_expr",
1832 tree_code_name [TREE_CODE (exp)]);
1837 expand_byte_code (jcf, method)
1844 unsigned char *linenumber_pointer;
1845 struct eh_range *prev_eh_ranges = NULL_EH_RANGE;
1846 struct eh_range *eh_ranges;
1848 #undef RET /* Defined by config/i386/i386.h */
1849 #undef AND /* Causes problems with opcodes for iand and land. */
1851 #define BCODE byte_ops
1852 #define BYTE_type_node byte_type_node
1853 #define SHORT_type_node short_type_node
1854 #define INT_type_node int_type_node
1855 #define LONG_type_node long_type_node
1856 #define CHAR_type_node char_type_node
1857 #define PTR_type_node ptr_type_node
1858 #define FLOAT_type_node float_type_node
1859 #define DOUBLE_type_node double_type_node
1860 #define VOID_type_node void_type_node
1862 unsigned char* byte_ops;
1863 long length = DECL_CODE_LENGTH (method);
1866 JCF_SEEK (jcf, DECL_CODE_OFFSET (method));
1867 byte_ops = jcf->read_ptr;
1869 #define CONST_INDEX_1 (saw_index = 1, IMMEDIATE_u1)
1870 #define CONST_INDEX_2 (saw_index = 1, IMMEDIATE_u2)
1871 #define VAR_INDEX_1 (saw_index = 1, IMMEDIATE_u1)
1872 #define VAR_INDEX_2 (saw_index = 1, IMMEDIATE_u2)
1874 #define CHECK_PC_IN_RANGE(PC) 1 /* Already handled by verifier. */
1876 instruction_bits = oballoc (length + 1);
1877 bzero (instruction_bits, length + 1);
1879 /* We make an initial pass of the line number table, to note
1880 which instructions have associated line number entries. */
1881 linenumber_pointer = linenumber_table;
1882 for (i = 0; i < linenumber_count; i++)
1884 int pc = GET_u2 (linenumber_pointer);
1885 linenumber_pointer += 4;
1887 warning ("invalid PC in line number table");
1890 if ((instruction_bits[pc] & BCODE_HAS_LINENUMBER) != 0)
1891 instruction_bits[pc] |= BCODE_HAS_MULTI_LINENUMBERS;
1892 instruction_bits[pc] |= BCODE_HAS_LINENUMBER;
1896 /* Do a preliminary pass.
1897 * This figures out which PC can be the targets of jumps. */
1898 for (PC = 0; PC < length;)
1900 int oldpc = PC; /* PC at instruction start. */
1901 instruction_bits [PC] |= BCODE_INSTRUCTION_START;
1902 switch (byte_ops[PC++])
1904 #define JAVAOP(OPNAME, OPCODE, OPKIND, OPERAND_TYPE, OPERAND_VALUE) \
1906 PRE_##OPKIND(OPERAND_TYPE, OPERAND_VALUE); \
1909 #define NOTE_LABEL(PC) note_label(oldpc, PC)
1911 #define PRE_PUSHC(OPERAND_TYPE, OPERAND_VALUE) (void)(OPERAND_VALUE);
1912 #define PRE_LOAD(OPERAND_TYPE, OPERAND_VALUE) (void)(OPERAND_VALUE);
1913 #define PRE_STORE(OPERAND_TYPE, OPERAND_VALUE) (void)(OPERAND_VALUE);
1914 #define PRE_STACK(OPERAND_TYPE, OPERAND_VALUE) /* nothing */
1915 #define PRE_UNOP(OPERAND_TYPE, OPERAND_VALUE) /* nothing */
1916 #define PRE_BINOP(OPERAND_TYPE, OPERAND_VALUE) /* nothing */
1917 #define PRE_CONVERT(OPERAND_TYPE, OPERAND_VALUE) /* nothing */
1918 #define PRE_CONVERT2(OPERAND_TYPE, OPERAND_VALUE) /* nothing */
1920 #define PRE_SPECIAL(OPERAND_TYPE, INSTRUCTION) \
1921 PRE_SPECIAL_##INSTRUCTION(OPERAND_TYPE)
1922 #define PRE_SPECIAL_IINC(OPERAND_TYPE) \
1923 ((void) IMMEDIATE_u1, (void) IMMEDIATE_s1)
1924 #define PRE_SPECIAL_ENTER(IGNORE) /* nothing */
1925 #define PRE_SPECIAL_EXIT(IGNORE) /* nothing */
1926 #define PRE_SPECIAL_THROW(IGNORE) /* nothing */
1927 #define PRE_SPECIAL_BREAK(IGNORE) /* nothing */
1929 /* two forms of wide instructions */
1930 #define PRE_SPECIAL_WIDE(IGNORE) \
1932 int modified_opcode = IMMEDIATE_u1; \
1933 if (modified_opcode == OPCODE_iinc) \
1935 (void) IMMEDIATE_u2; /* indexbyte1 and indexbyte2 */ \
1936 (void) IMMEDIATE_s2; /* constbyte1 and constbyte2 */ \
1940 (void) IMMEDIATE_u2; /* indexbyte1 and indexbyte2 */ \
1944 /* nothing */ /* XXX JH */
1946 #define PRE_IMPL(IGNORE1, IGNORE2) /* nothing */
1948 #define PRE_MONITOR(OPERAND_TYPE, OPERAND_VALUE) /* nothing */
1950 #define PRE_RETURN(OPERAND_TYPE, OPERAND_VALUE) /* nothing */
1951 #define PRE_ARRAY(OPERAND_TYPE, SUBOP) \
1952 PRE_ARRAY_##SUBOP(OPERAND_TYPE)
1953 #define PRE_ARRAY_LOAD(TYPE) /* nothing */
1954 #define PRE_ARRAY_STORE(TYPE) /* nothing */
1955 #define PRE_ARRAY_LENGTH(TYPE) /* nothing */
1956 #define PRE_ARRAY_NEW(TYPE) PRE_ARRAY_NEW_##TYPE
1957 #define PRE_ARRAY_NEW_NUM ((void) IMMEDIATE_u1)
1958 #define PRE_ARRAY_NEW_PTR ((void) IMMEDIATE_u2)
1959 #define PRE_ARRAY_NEW_MULTI ((void) IMMEDIATE_u2, (void) IMMEDIATE_u1)
1961 #define PRE_TEST(OPERAND_TYPE, OPERAND_VALUE) NOTE_LABEL (oldpc+IMMEDIATE_s2)
1962 #define PRE_COND(OPERAND_TYPE, OPERAND_VALUE) NOTE_LABEL (oldpc+IMMEDIATE_s2)
1963 #define PRE_BRANCH(OPERAND_TYPE, OPERAND_VALUE) \
1964 saw_index = 0; INT_temp = (OPERAND_VALUE); \
1965 if (!saw_index) NOTE_LABEL(oldpc + INT_temp);
1966 #define PRE_JSR(OPERAND_TYPE, OPERAND_VALUE) \
1967 saw_index = 0; INT_temp = (OPERAND_VALUE); \
1968 if (!saw_index) NOTE_LABEL(oldpc + INT_temp);
1970 #define PRE_RET(OPERAND_TYPE, OPERAND_VALUE) (void)(OPERAND_VALUE)
1972 #define PRE_SWITCH(OPERAND_TYPE, TABLE_OR_LOOKUP) \
1973 PC = (PC + 3) / 4 * 4; PRE_##TABLE_OR_LOOKUP##_SWITCH
1975 #define PRE_LOOKUP_SWITCH \
1976 { jint default_offset = IMMEDIATE_s4; jint npairs = IMMEDIATE_s4; \
1977 NOTE_LABEL (default_offset+oldpc); \
1979 while (--npairs >= 0) { \
1980 jint match = IMMEDIATE_s4; jint offset = IMMEDIATE_s4; \
1981 NOTE_LABEL (offset+oldpc); } \
1984 #define PRE_TABLE_SWITCH \
1985 { jint default_offset = IMMEDIATE_s4; \
1986 jint low = IMMEDIATE_s4; jint high = IMMEDIATE_s4; \
1987 NOTE_LABEL (default_offset+oldpc); \
1989 while (low++ <= high) { \
1990 jint offset = IMMEDIATE_s4; \
1991 NOTE_LABEL (offset+oldpc); } \
1994 #define PRE_FIELD(MAYBE_STATIC, PUT_OR_GET) (void)(IMMEDIATE_u2);
1995 #define PRE_OBJECT(MAYBE_STATIC, PUT_OR_GET) (void)(IMMEDIATE_u2);
1996 #define PRE_INVOKE(MAYBE_STATIC, IS_INTERFACE) \
1997 (void)(IMMEDIATE_u2); \
1998 PC += 2 * IS_INTERFACE /* for invokeinterface */;
2000 #include "javaop.def"
2005 if (! verify_jvm_instructions (jcf, byte_ops, length))
2008 /* Translate bytecodes to rtl instructions. */
2009 linenumber_pointer = linenumber_table;
2010 for (PC = 0; PC < length;)
2012 if ((instruction_bits [PC] & BCODE_TARGET) != 0 || PC == 0)
2014 tree label = lookup_label (PC);
2015 flush_quick_stack ();
2016 if ((instruction_bits [PC] & BCODE_TARGET) != 0)
2017 expand_label (label);
2018 if (LABEL_VERIFIED (label) || PC == 0)
2019 load_type_state (label);
2022 if (! (instruction_bits [PC] & BCODE_VERIFIED))
2024 /* never executed - skip */
2025 warning ("Some bytecode operations (starting at pc %d) can never be executed", PC);
2027 && ! (instruction_bits [PC] & BCODE_VERIFIED))
2033 /* Handle possible line number entry for this PC.
2035 This code handles out-of-order and multiple linenumbers per PC,
2036 but is optimized for the case of line numbers increasing
2037 monotonically with PC. */
2038 if ((instruction_bits[PC] & BCODE_HAS_LINENUMBER) != 0)
2040 if ((instruction_bits[PC] & BCODE_HAS_MULTI_LINENUMBERS) != 0
2041 || GET_u2 (linenumber_pointer) != PC)
2042 linenumber_pointer = linenumber_table;
2043 while (linenumber_pointer < linenumber_table + linenumber_count * 4)
2045 int pc = GET_u2 (linenumber_pointer);
2046 linenumber_pointer += 4;
2049 lineno = GET_u2 (linenumber_pointer - 2);
2050 emit_line_note (input_filename, lineno);
2051 if (!(instruction_bits[PC] & BCODE_HAS_MULTI_LINENUMBERS))
2056 maybe_start_try (PC);
2057 maybe_pushlevels (PC);
2059 PC = process_jvm_instruction (PC, byte_ops, length);
2061 maybe_poplevels (PC);
2067 java_push_constant_from_pool (jcf, index)
2072 if (JPOOL_TAG (jcf, index) == CONSTANT_String)
2075 push_obstacks (&permanent_obstack, &permanent_obstack);
2076 name = get_name_constant (jcf, JPOOL_USHORT1 (jcf, index));
2077 index = alloc_name_constant (CONSTANT_String, name);
2078 c = build_ref_from_constant_pool (index);
2079 TREE_TYPE (c) = promote_type (string_type_node);
2083 c = get_constant (jcf, index);
2088 process_jvm_instruction (PC, byte_ops, length)
2090 unsigned char* byte_ops;
2093 char *opname; /* Temporary ??? */
2094 int oldpc = PC; /* PC at instruction start. */
2096 /* If the instruction is at the beginning of a exception handler,
2097 replace the top of the stack with the thrown object reference */
2098 if (instruction_bits [PC] & BCODE_EXCEPTION_TARGET)
2100 pop_value (ptr_type_node);
2101 push_value (soft_exceptioninfo_call_node);
2104 switch (byte_ops[PC++])
2106 #define JAVAOP(OPNAME, OPCODE, OPKIND, OPERAND_TYPE, OPERAND_VALUE) \
2109 OPKIND(OPERAND_TYPE, OPERAND_VALUE); \
2112 #define RET(OPERAND_TYPE, OPERAND_VALUE) \
2114 int saw_index = 0; \
2115 int index = OPERAND_VALUE; \
2116 build_java_ret (find_local_variable (index, ptr_type_node, oldpc)); \
2119 #define JSR(OPERAND_TYPE, OPERAND_VALUE) \
2121 tree where = lookup_label (oldpc+OPERAND_VALUE); \
2122 tree ret = lookup_label (PC); \
2123 build_java_jsr (where, ret); \
2126 /* Push a constant onto the stack. */
2127 #define PUSHC(OPERAND_TYPE, OPERAND_VALUE) \
2128 { int saw_index = 0; int ival = (OPERAND_VALUE); \
2129 if (saw_index) java_push_constant_from_pool (current_jcf, ival); \
2130 else expand_java_pushc (ival, OPERAND_TYPE##_type_node); }
2132 /* internal macro added for use by the WIDE case */
2133 #define LOAD_INTERNAL(OPTYPE, OPVALUE) \
2134 push_value (find_local_variable (OPVALUE, type_map[OPVALUE], oldpc));
2136 /* Push local variable onto the opcode stack. */
2137 #define LOAD(OPERAND_TYPE, OPERAND_VALUE) \
2139 /* have to do this since OPERAND_VALUE may have side-effects */ \
2140 int opvalue = OPERAND_VALUE; \
2141 LOAD_INTERNAL(OPERAND_TYPE##_type_node, opvalue); \
2144 #define RETURN(OPERAND_TYPE, OPERAND_VALUE) \
2145 expand_java_return (OPERAND_TYPE##_type_node)
2147 #define REM_EXPR TRUNC_MOD_EXPR
2148 #define BINOP(OPERAND_TYPE, OPERAND_VALUE) \
2149 expand_java_binop (OPERAND_TYPE##_type_node, OPERAND_VALUE##_EXPR)
2151 #define FIELD(IS_STATIC, IS_PUT) \
2152 expand_java_field_op (IS_STATIC, IS_PUT, IMMEDIATE_u2)
2154 #define TEST(OPERAND_TYPE, CONDITION) \
2155 expand_test (CONDITION##_EXPR, OPERAND_TYPE##_type_node, oldpc+IMMEDIATE_s2)
2157 #define COND(OPERAND_TYPE, CONDITION) \
2158 expand_cond (CONDITION##_EXPR, OPERAND_TYPE##_type_node, oldpc+IMMEDIATE_s2)
2160 #define BRANCH(OPERAND_TYPE, OPERAND_VALUE) \
2161 BRANCH_##OPERAND_TYPE (OPERAND_VALUE)
2163 #define BRANCH_GOTO(OPERAND_VALUE) \
2164 expand_java_goto (oldpc + OPERAND_VALUE)
2166 #define BRANCH_CALL(OPERAND_VALUE) \
2167 expand_java_call (oldpc + OPERAND_VALUE, oldpc)
2170 #define BRANCH_RETURN(OPERAND_VALUE) \
2172 tree type = OPERAND_TYPE##_type_node; \
2173 tree value = find_local_variable (OPERAND_VALUE, type, oldpc); \
2174 expand_java_ret (value); \
2178 #define NOT_IMPL(OPERAND_TYPE, OPERAND_VALUE) \
2179 fprintf (stderr, "%3d: %s ", oldpc, opname); \
2180 fprintf (stderr, "(not implemented)\n")
2181 #define NOT_IMPL1(OPERAND_VALUE) \
2182 fprintf (stderr, "%3d: %s ", oldpc, opname); \
2183 fprintf (stderr, "(not implemented)\n")
2185 #define BRANCH_RETURN(OPERAND_VALUE) NOT_IMPL1(OPERAND_VALUE)
2187 #define STACK(SUBOP, COUNT) STACK_##SUBOP (COUNT)
2189 #define STACK_POP(COUNT) java_stack_pop (COUNT)
2191 #define STACK_SWAP(COUNT) java_stack_swap()
2193 #define STACK_DUP(COUNT) java_stack_dup (COUNT, 0)
2194 #define STACK_DUPx1(COUNT) java_stack_dup (COUNT, 1)
2195 #define STACK_DUPx2(COUNT) java_stack_dup (COUNT, 2)
2197 #define SWITCH(OPERAND_TYPE, TABLE_OR_LOOKUP) \
2198 PC = (PC + 3) / 4 * 4; TABLE_OR_LOOKUP##_SWITCH
2200 #define LOOKUP_SWITCH \
2201 { jint default_offset = IMMEDIATE_s4; jint npairs = IMMEDIATE_s4; \
2202 tree selector = pop_value (INT_type_node); \
2203 tree duplicate, label; \
2204 tree type = TREE_TYPE (selector); \
2205 flush_quick_stack (); \
2206 expand_start_case (0, selector, type, "switch statement");\
2207 push_momentary (); \
2208 while (--npairs >= 0) \
2210 jint match = IMMEDIATE_s4; jint offset = IMMEDIATE_s4; \
2211 tree value = build_int_2 (match, match < 0 ? -1 : 0); \
2212 TREE_TYPE (value) = type; \
2213 label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); \
2214 pushcase (value, convert, label, &duplicate); \
2215 expand_java_goto (oldpc + offset); \
2217 label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); \
2218 pushcase (NULL_TREE, 0, label, &duplicate); \
2219 expand_java_goto (oldpc + default_offset); \
2221 expand_end_case (selector); \
2224 #define TABLE_SWITCH \
2225 { jint default_offset = IMMEDIATE_s4; \
2226 jint low = IMMEDIATE_s4; jint high = IMMEDIATE_s4; \
2227 tree selector = pop_value (INT_type_node); \
2228 tree duplicate, label; \
2229 tree type = TREE_TYPE (selector); \
2230 flush_quick_stack (); \
2231 expand_start_case (0, selector, type, "switch statement");\
2232 push_momentary (); \
2233 for (; low <= high; low++) \
2235 jint offset = IMMEDIATE_s4; \
2236 tree value = build_int_2 (low, low < 0 ? -1 : 0); \
2237 TREE_TYPE (value) = type; \
2238 label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); \
2239 pushcase (value, convert, label, &duplicate); \
2240 expand_java_goto (oldpc + offset); \
2242 label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); \
2243 pushcase (NULL_TREE, 0, label, &duplicate); \
2244 expand_java_goto (oldpc + default_offset); \
2246 expand_end_case (selector); \
2249 #define INVOKE(MAYBE_STATIC, IS_INTERFACE) \
2250 { int opcode = byte_ops[PC-1]; \
2251 int method_ref_index = IMMEDIATE_u2; \
2253 if (IS_INTERFACE) { nargs = IMMEDIATE_u1; (void) IMMEDIATE_u1; } \
2255 expand_invoke (opcode, method_ref_index, nargs); \
2258 /* Handle new, checkcast, instanceof */
2259 #define OBJECT(TYPE, OP) \
2260 expand_java_##OP (get_class_constant (current_jcf, IMMEDIATE_u2))
2262 #define ARRAY(OPERAND_TYPE, SUBOP) ARRAY_##SUBOP(OPERAND_TYPE)
2264 #define ARRAY_LOAD(OPERAND_TYPE) \
2266 expand_java_arrayload( OPERAND_TYPE##_type_node ); \
2269 #define ARRAY_STORE(OPERAND_TYPE) \
2271 expand_java_arraystore( OPERAND_TYPE##_type_node ); \
2274 #define ARRAY_LENGTH(OPERAND_TYPE) expand_java_array_length();
2275 #define ARRAY_NEW(OPERAND_TYPE) ARRAY_NEW_##OPERAND_TYPE()
2276 #define ARRAY_NEW_PTR() \
2277 push_value (build_anewarray (get_class_constant (current_jcf, \
2279 pop_value (int_type_node)));
2280 #define ARRAY_NEW_NUM() \
2282 int atype = IMMEDIATE_u1; \
2283 push_value (build_newarray (atype, pop_value (int_type_node)));\
2285 #define ARRAY_NEW_MULTI() \
2287 tree class = get_class_constant (current_jcf, IMMEDIATE_u2 ); \
2288 int ndims = IMMEDIATE_u1; \
2289 expand_java_multianewarray( class, ndims ); \
2292 #define UNOP(OPERAND_TYPE, OPERAND_VALUE) \
2293 push_value (fold (build1 (NEGATE_EXPR, OPERAND_TYPE##_type_node, \
2294 pop_value (OPERAND_TYPE##_type_node))));
2296 #define CONVERT2(FROM_TYPE, TO_TYPE) \
2298 push_value (build1 (NOP_EXPR, int_type_node, \
2299 (convert (TO_TYPE##_type_node, \
2300 pop_value (FROM_TYPE##_type_node))))); \
2303 #define CONVERT(FROM_TYPE, TO_TYPE) \
2305 push_value (convert (TO_TYPE##_type_node, \
2306 pop_value (FROM_TYPE##_type_node))); \
2309 /* internal macro added for use by the WIDE case
2310 Added TREE_TYPE (decl) assignment, apbianco */
2311 #define STORE_INTERNAL(OPTYPE, OPVALUE) \
2314 int var = OPVALUE; \
2315 tree type = OPTYPE; \
2316 value = pop_value (type); \
2317 type = TREE_TYPE (value); \
2318 decl = find_local_variable (var, type, oldpc); \
2319 set_local_type (var, type ); \
2320 expand_assignment (decl, value, 0, 0); \
2323 #define STORE(OPERAND_TYPE, OPERAND_VALUE) \
2325 /* have to do this since OPERAND_VALUE may have side-effects */ \
2326 int opvalue = OPERAND_VALUE; \
2327 STORE_INTERNAL(OPERAND_TYPE##_type_node, opvalue); \
2330 #define SPECIAL(OPERAND_TYPE, INSTRUCTION) \
2331 SPECIAL_##INSTRUCTION(OPERAND_TYPE)
2333 #define SPECIAL_ENTER(IGNORED) MONITOR_OPERATION (soft_monitorenter_node)
2334 #define SPECIAL_EXIT(IGNORED) MONITOR_OPERATION (soft_monitorexit_node)
2336 #define MONITOR_OPERATION(call) \
2338 tree o = pop_value (ptr_type_node); \
2340 flush_quick_stack (); \
2341 c = build_java_monitor (call, o); \
2342 TREE_SIDE_EFFECTS (c) = 1; \
2343 expand_expr_stmt (c); \
2346 #define SPECIAL_IINC(IGNORED) \
2348 unsigned int local_var_index = IMMEDIATE_u1; \
2349 int ival = IMMEDIATE_s1; \
2350 expand_iinc(local_var_index, ival, oldpc); \
2353 #define SPECIAL_WIDE(IGNORED) \
2355 int modified_opcode = IMMEDIATE_u1; \
2356 unsigned int local_var_index = IMMEDIATE_u2; \
2357 switch (modified_opcode) \
2361 int ival = IMMEDIATE_s2; \
2362 expand_iinc (local_var_index, ival, oldpc); \
2365 case OPCODE_iload: \
2366 case OPCODE_lload: \
2367 case OPCODE_fload: \
2368 case OPCODE_dload: \
2369 case OPCODE_aload: \
2371 /* duplicate code from LOAD macro */ \
2372 LOAD_INTERNAL(operand_type[modified_opcode], local_var_index); \
2375 case OPCODE_istore: \
2376 case OPCODE_lstore: \
2377 case OPCODE_fstore: \
2378 case OPCODE_dstore: \
2379 case OPCODE_astore: \
2381 STORE_INTERNAL(operand_type[modified_opcode], local_var_index); \
2385 error ("unrecogized wide sub-instruction"); \
2389 #define SPECIAL_THROW(IGNORED) \
2390 build_java_athrow (pop_value (throwable_type_node))
2392 #define SPECIAL_BREAK NOT_IMPL1
2393 #define IMPL NOT_IMPL
2395 #include "javaop.def"
2398 fprintf (stderr, "%3d: unknown(%3d)\n", oldpc, byte_ops[PC]);