1 /* This file contains the definitions and documentation for the common
2 tree codes used in the GNU C and C++ compilers (see c-common.def
3 for the standard codes).
4 Copyright (C) 2000 Free Software Foundation, Inc. Written by
5 Benjamin Chelf (chelf@codesourcery.com).
7 This file is part of GNU CC.
9 GNU CC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
14 GNU CC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GNU CC; see the file COPYING. If not, write to
21 the Free Software Foundation, 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
28 #include "splay-tree.h"
39 /* Some statements, like for-statements or if-statements, require a
40 condition. This condition can be a declaration. If T is such a
41 declaration it is processed, and an expression appropriate to use
42 as the condition is returned. Otherwise, T itself is returned. */
48 if (t && TREE_CODE (t) == TREE_LIST)
50 expand_stmt (TREE_PURPOSE (t));
51 return TREE_VALUE (t);
57 /* Create RTL for the local static variable DECL. */
60 make_rtl_for_local_static (decl)
63 const char *asmspec = NULL;
65 /* If we inlined this variable, we could see it's declaration
70 if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
72 /* The only way this situaton can occur is if the
73 user specified a name for this DECL using the
74 `attribute' syntax. */
75 asmspec = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
76 DECL_ASSEMBLER_NAME (decl) = DECL_NAME (decl);
79 rest_of_decl_compilation (decl, asmspec, /*top_level=*/0, /*at_end=*/0);
82 /* Let the back-end know about DECL. */
88 /* Create RTL for this variable. */
91 if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
92 /* The user must have specified an assembler name for this
93 variable. Set that up now. */
94 rest_of_decl_compilation
95 (decl, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
96 /*top_level=*/0, /*at_end=*/0);
101 /* Actually do the initialization. */
102 if (stmts_are_full_exprs_p ())
103 expand_start_target_temps ();
105 expand_decl_init (decl);
107 if (stmts_are_full_exprs_p ())
108 expand_end_target_temps ();
111 /* Helper for generating the RTL at the beginning of a scope. */
114 genrtl_do_pushlevel ()
116 emit_line_note (input_filename, lineno);
120 /* Helper for generating the RTL. */
123 genrtl_clear_out_block ()
125 /* If COND wasn't a declaration, clear out the
126 block we made for it and start a new one here so the
127 optimization in expand_end_loop will work. */
128 if (getdecls () == NULL_TREE)
129 genrtl_do_pushlevel ();
132 /* Generate the RTL for DESTINATION, which is a GOTO_STMT. */
135 genrtl_goto_stmt (destination)
138 if (TREE_CODE (destination) == IDENTIFIER_NODE)
141 /* We warn about unused labels with -Wunused. That means we have to
142 mark the used labels as used. */
143 if (TREE_CODE (destination) == LABEL_DECL)
144 TREE_USED (destination) = 1;
146 emit_line_note (input_filename, lineno);
148 if (TREE_CODE (destination) == LABEL_DECL)
150 label_rtx (destination);
151 expand_goto (destination);
154 expand_computed_goto (destination);
157 /* Generate the RTL for EXPR, which is an EXPR_STMT. */
160 genrtl_expr_stmt (expr)
163 if (expr != NULL_TREE)
165 emit_line_note (input_filename, lineno);
167 if (stmts_are_full_exprs_p ())
168 expand_start_target_temps ();
170 lang_expand_expr_stmt (expr);
172 if (stmts_are_full_exprs_p ())
173 expand_end_target_temps ();
177 /* Generate the RTL for T, which is a DECL_STMT. */
184 emit_line_note (input_filename, lineno);
185 decl = DECL_STMT_DECL (t);
186 /* If this is a declaration for an automatic local
187 variable, initialize it. Note that we might also see a
188 declaration for a namespace-scope object (declared with
189 `extern'). We don't have to handle the initialization
190 of those objects here; they can only be declarations,
191 rather than definitions. */
192 if (TREE_CODE (decl) == VAR_DECL
193 && !TREE_STATIC (decl)
194 && !DECL_EXTERNAL (decl))
196 /* Let the back-end know about this variable. */
197 if (!anon_aggr_type_p (TREE_TYPE (decl)))
198 emit_local_var (decl);
200 expand_anon_union_decl (decl, NULL_TREE,
201 DECL_ANON_UNION_ELEMS (decl));
203 else if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
205 if (DECL_ARTIFICIAL (decl) && ! TREE_USED (decl))
206 /* Do not emit unused decls. This is not just an
207 optimization. We really do not want to emit
208 __PRETTY_FUNCTION__ etc, if they're never used. */
209 DECL_IGNORED_P (decl) = 1;
211 make_rtl_for_local_static (decl);
215 /* Generate the RTL for T, which is an IF_STMT. */
222 genrtl_do_pushlevel ();
223 cond = expand_cond (IF_COND (t));
224 emit_line_note (input_filename, lineno);
225 expand_start_cond (cond, 0);
227 expand_stmt (THEN_CLAUSE (t));
230 expand_start_else ();
231 expand_stmt (ELSE_CLAUSE (t));
236 /* Generate the RTL for T, which is a WHILE_STMT. */
239 genrtl_while_stmt (t)
244 emit_line_note (input_filename, lineno);
245 expand_start_loop (1);
246 genrtl_do_pushlevel ();
248 cond = expand_cond (WHILE_COND (t));
249 emit_line_note (input_filename, lineno);
250 expand_exit_loop_if_false (0, cond);
251 genrtl_clear_out_block ();
253 expand_stmt (WHILE_BODY (t));
258 /* Generate the RTL for T, which is a DO_STMT. */
266 emit_line_note (input_filename, lineno);
267 expand_start_loop_continue_elsewhere (1);
269 expand_stmt (DO_BODY (t));
271 expand_loop_continue_here ();
273 cond = expand_cond (DO_COND (t));
274 emit_line_note (input_filename, lineno);
275 expand_exit_loop_if_false (0, cond);
279 /* Generate the RTL for EXPR, which is a RETURN_STMT. */
282 genrtl_return_stmt (expr)
285 emit_line_note (input_filename, lineno);
286 c_expand_return (expr);
289 /* Generate the RTL for T, which is a FOR_STMT. */
297 if (NEW_FOR_SCOPE_P (t))
298 genrtl_do_pushlevel ();
300 expand_stmt (FOR_INIT_STMT (t));
303 emit_line_note (input_filename, lineno);
304 expand_start_loop_continue_elsewhere (1);
305 genrtl_do_pushlevel ();
306 cond = expand_cond (FOR_COND (t));
307 emit_line_note (input_filename, lineno);
309 expand_exit_loop_if_false (0, cond);
310 genrtl_clear_out_block ();
313 expand_stmt (FOR_BODY (t));
315 emit_line_note (input_filename, lineno);
316 expand_loop_continue_here ();
318 genrtl_expr_stmt (tmp);
322 /* Generate the RTL for a BREAK_STMT. */
327 emit_line_note (input_filename, lineno);
328 if ( ! expand_exit_something ())
329 error ("break statement not within loop or switch");
332 /* Generate the RTL for a CONTINUE_STMT. */
335 genrtl_continue_stmt ()
337 emit_line_note (input_filename, lineno);
338 if (! expand_continue_loop (0))
339 error ("continue statement not within a loop");
342 /* Generate the RTL for T, which is a SCOPE_STMT. */
345 genrtl_scope_stmt (t)
348 if (!SCOPE_NO_CLEANUPS_P (t))
350 if (SCOPE_BEGIN_P (t))
351 expand_start_bindings_and_block (2 * SCOPE_NULLIFIED_P (t),
352 SCOPE_STMT_BLOCK (t));
353 else if (SCOPE_END_P (t))
354 expand_end_bindings (NULL_TREE, !SCOPE_NULLIFIED_P (t), 0);
356 else if (!SCOPE_NULLIFIED_P (t))
358 rtx note = emit_note (NULL,
360 ? NOTE_INSN_BLOCK_BEG
361 : NOTE_INSN_BLOCK_END));
362 NOTE_BLOCK (note) = SCOPE_STMT_BLOCK (t);
366 /* Generate the RTL for T, which is a SWITCH_STMT. */
369 genrtl_switch_stmt (t)
373 genrtl_do_pushlevel ();
375 cond = expand_cond (SWITCH_COND (t));
376 if (cond != error_mark_node)
378 emit_line_note (input_filename, lineno);
379 c_expand_start_case (cond);
382 /* The code is in error, but we don't want expand_end_case to
384 c_expand_start_case (boolean_false_node);
386 expand_stmt (SWITCH_BODY (t));
388 expand_end_case (cond);
391 /* Generate the RTL for a CASE_LABEL. */
394 genrtl_case_label (low_value, high_value)
398 do_case (low_value, high_value);
401 /* Generate the RTL for the start of a COMPOUND_STMT. */
404 genrtl_begin_compound_stmt (has_no_scope)
407 /* If this is the outermost block of the function, declare the
408 variables __FUNCTION__, __PRETTY_FUNCTION__, and so forth. */
410 && !current_function_name_declared ()
413 set_current_function_name_declared (1);
414 declare_function_name ();
420 /* Generate the RTL for the end of a COMPOUND_STMT. */
422 tree genrtl_finish_compound_stmt (has_no_scope)
428 /* Generate the RTL for T, which is a COMPOUND_STMT. */
431 genrtl_compound_stmt (t)
434 genrtl_begin_compound_stmt (COMPOUND_STMT_NO_SCOPE (t));
435 expand_stmt (COMPOUND_BODY (t));
436 return (genrtl_finish_compound_stmt (COMPOUND_STMT_NO_SCOPE (t)));
439 /* Generate the RTL for an ASM_STMT. */
442 genrtl_asm_stmt (cv_qualifier, string, output_operands,
443 input_operands, clobbers)
446 tree output_operands;
450 if (TREE_CHAIN (string))
451 string = combine_strings (string);
453 if (cv_qualifier != NULL_TREE
454 && cv_qualifier != ridpointers[(int) RID_VOLATILE])
456 warning ("%s qualifier ignored on asm",
457 IDENTIFIER_POINTER (cv_qualifier));
458 cv_qualifier = NULL_TREE;
461 emit_line_note (input_filename, lineno);
462 if (output_operands != NULL_TREE || input_operands != NULL_TREE
463 || clobbers != NULL_TREE)
464 c_expand_asm_operands (string, output_operands,
467 cv_qualifier != NULL_TREE,
468 input_filename, lineno);
473 /* Generate the RTL for a DECL_CLEANUP. */
476 genrtl_decl_cleanup (decl, cleanup)
480 if (!decl || (DECL_SIZE (decl) && TREE_TYPE (decl) != error_mark_node))
481 expand_decl_cleanup (decl, cleanup);
489 rval = lang_expand_stmt (t);