* xvasprintf.c: New file.
[official-gcc.git] / gcc / java / java-gimplify.c
blobfe7a6e3288b0ef62f453ba7f8ccfd0a34b6ab6e8
1 /* Java(TM) language-specific gimplification routines.
2 Copyright (C) 2003-2014 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC 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 3, or (at your option)
9 any later version.
11 GCC 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 GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>.
20 Java and all Java-based marks are trademarks or registered trademarks
21 of Sun Microsystems, Inc. in the United States and other countries.
22 The Free Software Foundation is independent of Sun Microsystems, Inc. */
24 #include "config.h"
25 #include "system.h"
26 #include "coretypes.h"
27 #include "tree.h"
28 #include "java-tree.h"
29 #include "dumpfile.h"
30 #include "predict.h"
31 #include "vec.h"
32 #include "hashtab.h"
33 #include "hash-set.h"
34 #include "machmode.h"
35 #include "tm.h"
36 #include "hard-reg-set.h"
37 #include "input.h"
38 #include "function.h"
39 #include "basic-block.h"
40 #include "tree-ssa-alias.h"
41 #include "internal-fn.h"
42 #include "gimple-expr.h"
43 #include "is-a.h"
44 #include "gimple.h"
45 #include "gimplify.h"
47 static tree java_gimplify_block (tree);
48 static enum gimplify_status java_gimplify_modify_expr (tree *);
49 static enum gimplify_status java_gimplify_self_mod_expr (tree *, gimple_seq *,
50 gimple_seq *);
52 static void dump_java_tree (enum tree_dump_index, tree);
54 /* Convert a Java tree to GENERIC. */
56 void
57 java_genericize (tree fndecl)
59 walk_tree (&DECL_SAVED_TREE (fndecl), java_replace_references, NULL, NULL);
60 dump_java_tree (TDI_original, fndecl);
63 /* Gimplify a Java tree. */
65 int
66 java_gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p)
68 enum tree_code code = TREE_CODE (*expr_p);
70 switch (code)
72 case BLOCK:
73 *expr_p = java_gimplify_block (*expr_p);
74 break;
76 case MODIFY_EXPR:
77 return java_gimplify_modify_expr (expr_p);
79 case POSTINCREMENT_EXPR:
80 case POSTDECREMENT_EXPR:
81 case PREINCREMENT_EXPR:
82 case PREDECREMENT_EXPR:
83 return java_gimplify_self_mod_expr (expr_p, pre_p, post_p);
85 /* These should already be lowered before we get here. */
86 case URSHIFT_EXPR:
87 case COMPARE_EXPR:
88 case COMPARE_L_EXPR:
89 case COMPARE_G_EXPR:
90 gcc_unreachable ();
92 default:
93 return GS_UNHANDLED;
96 return GS_OK;
99 static enum gimplify_status
100 java_gimplify_modify_expr (tree *modify_expr_p)
102 tree modify_expr = *modify_expr_p;
103 tree lhs = TREE_OPERAND (modify_expr, 0);
104 tree rhs = TREE_OPERAND (modify_expr, 1);
105 tree lhs_type = TREE_TYPE (lhs);
107 if (lhs_type != TREE_TYPE (rhs))
108 /* Fix up type mismatches to make legal GIMPLE. These are
109 generated in several places, in particular null pointer
110 assignment and subclass assignment. */
111 TREE_OPERAND (modify_expr, 1) = convert (lhs_type, rhs);
113 return GS_UNHANDLED;
116 /* Special case handling for volatiles: we need to generate a barrier
117 between the reading and the writing. */
119 static enum gimplify_status
120 java_gimplify_self_mod_expr (tree *expr_p, gimple_seq *pre_p ATTRIBUTE_UNUSED,
121 gimple_seq *post_p ATTRIBUTE_UNUSED)
123 tree lhs = TREE_OPERAND (*expr_p, 0);
125 if (TREE_CODE (lhs) == COMPONENT_REF
126 && TREE_THIS_VOLATILE (TREE_OPERAND (lhs, 1)))
127 TREE_THIS_VOLATILE (lhs) = 1;
129 return GS_UNHANDLED;
133 /* Gimplify BLOCK into a BIND_EXPR. */
135 static tree
136 java_gimplify_block (tree java_block)
138 tree decls = BLOCK_VARS (java_block);
139 tree body = BLOCK_EXPR_BODY (java_block);
140 gbind *outer = gimple_current_bind_expr ();
141 tree block;
143 /* Don't bother with empty blocks. */
144 if (! body)
145 return build_empty_stmt (input_location);
147 if (IS_EMPTY_STMT (body))
148 return body;
150 /* Make a proper block. Java blocks are unsuitable for BIND_EXPR
151 because they use BLOCK_SUBBLOCKS for another purpose. */
152 block = make_node (BLOCK);
153 BLOCK_VARS (block) = decls;
155 /* The TREE_USED flag on a block determines whether the debug output
156 routines generate info for the variables in that block. */
157 TREE_USED (block) = 1;
159 if (outer != NULL)
161 tree b = gimple_bind_block (outer);
162 BLOCK_SUBBLOCKS (b) = chainon (BLOCK_SUBBLOCKS (b), block);
164 BLOCK_EXPR_BODY (java_block) = NULL_TREE;
166 return build3 (BIND_EXPR, TREE_TYPE (java_block), decls, body, block);
169 /* Dump a tree of some kind. This is a convenience wrapper for the
170 dump_* functions in tree-dump.c. */
171 static void
172 dump_java_tree (enum tree_dump_index phase, tree t)
174 FILE *stream;
175 int flags;
177 stream = dump_begin (phase, &flags);
178 flags |= TDF_SLIM;
179 if (stream)
181 dump_node (t, flags, stream);
182 dump_end (phase, stream);