]>
Commit | Line | Data |
---|---|---|
f2c5f623 BC |
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). | |
4f78b9a8 RH |
4 | Copyright (C) 2000, 2001 Free Software Foundation, Inc. |
5 | Written by Benjamin Chelf (chelf@codesourcery.com). | |
f2c5f623 BC |
6 | |
7 | This file is part of GNU CC. | |
8 | ||
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) | |
12 | any later version. | |
13 | ||
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. | |
18 | ||
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. */ | |
23 | ||
24 | #include "config.h" | |
25 | #include "system.h" | |
26 | #include "tree.h" | |
27 | #include "function.h" | |
28 | #include "splay-tree.h" | |
29 | #include "varray.h" | |
30 | #include "c-common.h" | |
31 | #include "except.h" | |
32 | #include "toplev.h" | |
33 | #include "flags.h" | |
34 | #include "ggc.h" | |
35 | #include "rtl.h" | |
d6684bc8 | 36 | #include "expr.h" |
f2c5f623 BC |
37 | #include "output.h" |
38 | #include "timevar.h" | |
39 | ||
54f7877c MM |
40 | /* If non-NULL, the address of a language-specific function for |
41 | expanding statements. */ | |
42 | void (*lang_expand_stmt) PARAMS ((tree)); | |
43 | ||
8f17b5c5 MM |
44 | /* If non-NULL, the address of a language-specific function for |
45 | expanding a DECL_STMT. After the language-independent cases are | |
46 | handled, this function will be called. If this function is not | |
47 | defined, it is assumed that declarations other than those for | |
48 | variables and labels do not require any RTL generation. */ | |
49 | void (*lang_expand_decl_stmt) PARAMS ((tree)); | |
50 | ||
ae499cce MM |
51 | /* Create an empty statement tree rooted at T. */ |
52 | ||
53 | void | |
54 | begin_stmt_tree (t) | |
55 | tree *t; | |
56 | { | |
57 | /* We create a trivial EXPR_STMT so that last_tree is never NULL in | |
58 | what follows. We remove the extraneous statement in | |
59 | finish_stmt_tree. */ | |
60 | *t = build_nt (EXPR_STMT, void_zero_node); | |
61 | last_tree = *t; | |
62 | last_expr_type = NULL_TREE; | |
63 | } | |
64 | ||
65 | /* T is a statement. Add it to the statement-tree. */ | |
66 | ||
56cb9733 | 67 | tree |
ae499cce MM |
68 | add_stmt (t) |
69 | tree t; | |
70 | { | |
71 | /* Add T to the statement-tree. */ | |
72 | TREE_CHAIN (last_tree) = t; | |
73 | last_tree = t; | |
0ba8a114 | 74 | |
ae499cce | 75 | /* When we expand a statement-tree, we must know whether or not the |
0ba8a114 | 76 | statements are full-expressions. We record that fact here. */ |
ae499cce | 77 | STMT_IS_FULL_EXPR_P (last_tree) = stmts_are_full_exprs_p (); |
b850de4f MM |
78 | |
79 | /* Keep track of the number of statements in this function. */ | |
80 | if (current_function_decl) | |
81 | ++DECL_NUM_STMTS (current_function_decl); | |
82 | ||
56cb9733 | 83 | return t; |
ae499cce MM |
84 | } |
85 | ||
8f17b5c5 MM |
86 | /* Create a declaration statement for the declaration given by the |
87 | DECL. */ | |
88 | ||
89 | void | |
90 | add_decl_stmt (decl) | |
91 | tree decl; | |
92 | { | |
93 | tree decl_stmt; | |
94 | ||
95 | /* We need the type to last until instantiation time. */ | |
96 | decl_stmt = build_stmt (DECL_STMT, decl); | |
97 | add_stmt (decl_stmt); | |
98 | } | |
99 | ||
100 | /* Add a scope-statement to the statement-tree. BEGIN_P indicates | |
101 | whether this statements opens or closes a scope. PARTIAL_P is true | |
102 | for a partial scope, i.e, the scope that begins after a label when | |
103 | an object that needs a cleanup is created. If BEGIN_P is nonzero, | |
104 | returns a new TREE_LIST representing the top of the SCOPE_STMT | |
105 | stack. The TREE_PURPOSE is the new SCOPE_STMT. If BEGIN_P is | |
106 | zero, returns a TREE_LIST whose TREE_VALUE is the new SCOPE_STMT, | |
0ba8a114 | 107 | and whose TREE_PURPOSE is the matching SCOPE_STMT with |
8f17b5c5 MM |
108 | SCOPE_BEGIN_P set. */ |
109 | ||
110 | tree | |
111 | add_scope_stmt (begin_p, partial_p) | |
112 | int begin_p; | |
113 | int partial_p; | |
114 | { | |
115 | tree ss; | |
116 | tree top; | |
117 | ||
118 | /* Build the statement. */ | |
119 | ss = build_stmt (SCOPE_STMT, NULL_TREE); | |
120 | SCOPE_BEGIN_P (ss) = begin_p; | |
121 | SCOPE_PARTIAL_P (ss) = partial_p; | |
122 | ||
123 | /* Keep the scope stack up to date. */ | |
124 | if (begin_p) | |
125 | { | |
126 | *current_scope_stmt_stack () | |
127 | = tree_cons (ss, NULL_TREE, *current_scope_stmt_stack ()); | |
128 | top = *current_scope_stmt_stack (); | |
129 | } | |
130 | else | |
131 | { | |
132 | top = *current_scope_stmt_stack (); | |
133 | TREE_VALUE (top) = ss; | |
134 | *current_scope_stmt_stack () = TREE_CHAIN (top); | |
135 | } | |
136 | ||
137 | /* Add the new statement to the statement-tree. */ | |
138 | add_stmt (ss); | |
139 | ||
140 | return top; | |
141 | } | |
142 | ||
ae499cce MM |
143 | /* Finish the statement tree rooted at T. */ |
144 | ||
145 | void | |
146 | finish_stmt_tree (t) | |
147 | tree *t; | |
148 | { | |
149 | tree stmt; | |
150 | ||
151 | /* Remove the fake extra statement added in begin_stmt_tree. */ | |
152 | stmt = TREE_CHAIN (*t); | |
153 | *t = stmt; | |
154 | last_tree = NULL_TREE; | |
155 | ||
8f17b5c5 | 156 | if (cfun && stmt) |
ae499cce MM |
157 | { |
158 | /* The line-number recorded in the outermost statement in a function | |
159 | is the line number of the end of the function. */ | |
160 | STMT_LINENO (stmt) = lineno; | |
161 | STMT_LINENO_FOR_FN_P (stmt) = 1; | |
162 | } | |
163 | } | |
164 | ||
0dfdeca6 BC |
165 | /* Build a generic statement based on the given type of node and |
166 | arguments. Similar to `build_nt', except that we set | |
64094f6a RH |
167 | STMT_LINENO to be the current line number. */ |
168 | /* ??? This should be obsolete with the lineno_stmt productions | |
169 | in the grammar. */ | |
0dfdeca6 BC |
170 | |
171 | tree | |
172 | build_stmt VPARAMS ((enum tree_code code, ...)) | |
173 | { | |
174 | #ifndef ANSI_PROTOTYPES | |
175 | enum tree_code code; | |
176 | #endif | |
177 | va_list p; | |
178 | register tree t; | |
179 | register int length; | |
180 | register int i; | |
181 | ||
182 | VA_START (p, code); | |
183 | ||
184 | #ifndef ANSI_PROTOTYPES | |
185 | code = va_arg (p, enum tree_code); | |
186 | #endif | |
187 | ||
188 | t = make_node (code); | |
189 | length = TREE_CODE_LENGTH (code); | |
64094f6a | 190 | STMT_LINENO (t) = lineno; |
0dfdeca6 BC |
191 | |
192 | for (i = 0; i < length; i++) | |
193 | TREE_OPERAND (t, i) = va_arg (p, tree); | |
194 | ||
195 | va_end (p); | |
196 | return t; | |
197 | } | |
198 | ||
f2c5f623 BC |
199 | /* Some statements, like for-statements or if-statements, require a |
200 | condition. This condition can be a declaration. If T is such a | |
201 | declaration it is processed, and an expression appropriate to use | |
202 | as the condition is returned. Otherwise, T itself is returned. */ | |
203 | ||
204 | tree | |
205 | expand_cond (t) | |
206 | tree t; | |
207 | { | |
208 | if (t && TREE_CODE (t) == TREE_LIST) | |
209 | { | |
210 | expand_stmt (TREE_PURPOSE (t)); | |
211 | return TREE_VALUE (t); | |
212 | } | |
213 | else | |
214 | return t; | |
215 | } | |
216 | ||
217 | /* Create RTL for the local static variable DECL. */ | |
218 | ||
219 | void | |
220 | make_rtl_for_local_static (decl) | |
221 | tree decl; | |
222 | { | |
223 | const char *asmspec = NULL; | |
224 | ||
225 | /* If we inlined this variable, we could see it's declaration | |
226 | again. */ | |
95ee998c | 227 | if (TREE_ASM_WRITTEN (decl)) |
f2c5f623 BC |
228 | return; |
229 | ||
2c21b247 MM |
230 | /* If the DECL_ASSEMBLER_NAME is not the same as the DECL_NAME, then |
231 | either we already created RTL for this DECL (and since it was a | |
0a7394bc | 232 | local variable, its DECL_ASSEMBLER_NAME got hacked up to prevent |
2c21b247 MM |
233 | clashes with other local statics with the same name by a previous |
234 | call to make_decl_rtl), or the user explicitly requested a | |
235 | particular assembly name for this variable, using the GNU | |
236 | extension for this purpose: | |
237 | ||
238 | int i asm ("j"); | |
239 | ||
240 | There's no way to know which case we're in, here. But, it turns | |
241 | out we're safe. If there's already RTL, then | |
242 | rest_of_decl_compilation ignores the ASMSPEC parameter, so we | |
243 | may as well not pass it in. If there isn't RTL, then we didn't | |
244 | already create RTL, which means that the modification to | |
245 | DECL_ASSEMBLER_NAME came only via the explicit extension. */ | |
246 | if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl) | |
247 | && !DECL_RTL (decl)) | |
248 | asmspec = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); | |
f2c5f623 BC |
249 | |
250 | rest_of_decl_compilation (decl, asmspec, /*top_level=*/0, /*at_end=*/0); | |
251 | } | |
252 | ||
253 | /* Let the back-end know about DECL. */ | |
254 | ||
255 | void | |
256 | emit_local_var (decl) | |
257 | tree decl; | |
258 | { | |
259 | /* Create RTL for this variable. */ | |
19e7881c | 260 | if (!DECL_RTL_SET_P (decl)) |
f2c5f623 | 261 | { |
3645c4dc RH |
262 | if (DECL_C_HARD_REGISTER (decl)) |
263 | /* The user specified an assembler name for this variable. | |
264 | Set that up now. */ | |
f2c5f623 BC |
265 | rest_of_decl_compilation |
266 | (decl, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), | |
267 | /*top_level=*/0, /*at_end=*/0); | |
268 | else | |
269 | expand_decl (decl); | |
270 | } | |
271 | ||
272 | /* Actually do the initialization. */ | |
273 | if (stmts_are_full_exprs_p ()) | |
274 | expand_start_target_temps (); | |
275 | ||
276 | expand_decl_init (decl); | |
277 | ||
278 | if (stmts_are_full_exprs_p ()) | |
279 | expand_end_target_temps (); | |
280 | } | |
281 | ||
282 | /* Helper for generating the RTL at the beginning of a scope. */ | |
283 | ||
284 | void | |
285 | genrtl_do_pushlevel () | |
286 | { | |
287 | emit_line_note (input_filename, lineno); | |
288 | clear_last_expr (); | |
289 | } | |
290 | ||
f2c5f623 BC |
291 | /* Generate the RTL for DESTINATION, which is a GOTO_STMT. */ |
292 | ||
293 | void | |
294 | genrtl_goto_stmt (destination) | |
295 | tree destination; | |
296 | { | |
297 | if (TREE_CODE (destination) == IDENTIFIER_NODE) | |
298 | abort (); | |
299 | ||
300 | /* We warn about unused labels with -Wunused. That means we have to | |
301 | mark the used labels as used. */ | |
302 | if (TREE_CODE (destination) == LABEL_DECL) | |
303 | TREE_USED (destination) = 1; | |
304 | ||
305 | emit_line_note (input_filename, lineno); | |
306 | ||
307 | if (TREE_CODE (destination) == LABEL_DECL) | |
308 | { | |
309 | label_rtx (destination); | |
310 | expand_goto (destination); | |
311 | } | |
312 | else | |
313 | expand_computed_goto (destination); | |
314 | } | |
315 | ||
316 | /* Generate the RTL for EXPR, which is an EXPR_STMT. */ | |
317 | ||
318 | void | |
319 | genrtl_expr_stmt (expr) | |
320 | tree expr; | |
321 | { | |
322 | if (expr != NULL_TREE) | |
323 | { | |
324 | emit_line_note (input_filename, lineno); | |
325 | ||
326 | if (stmts_are_full_exprs_p ()) | |
327 | expand_start_target_temps (); | |
328 | ||
8f17b5c5 MM |
329 | if (expr != error_mark_node) |
330 | expand_expr_stmt (expr); | |
f2c5f623 BC |
331 | |
332 | if (stmts_are_full_exprs_p ()) | |
333 | expand_end_target_temps (); | |
334 | } | |
335 | } | |
336 | ||
337 | /* Generate the RTL for T, which is a DECL_STMT. */ | |
338 | ||
339 | void | |
340 | genrtl_decl_stmt (t) | |
341 | tree t; | |
342 | { | |
343 | tree decl; | |
344 | emit_line_note (input_filename, lineno); | |
345 | decl = DECL_STMT_DECL (t); | |
346 | /* If this is a declaration for an automatic local | |
347 | variable, initialize it. Note that we might also see a | |
348 | declaration for a namespace-scope object (declared with | |
349 | `extern'). We don't have to handle the initialization | |
350 | of those objects here; they can only be declarations, | |
351 | rather than definitions. */ | |
352 | if (TREE_CODE (decl) == VAR_DECL | |
353 | && !TREE_STATIC (decl) | |
354 | && !DECL_EXTERNAL (decl)) | |
355 | { | |
356 | /* Let the back-end know about this variable. */ | |
357 | if (!anon_aggr_type_p (TREE_TYPE (decl))) | |
358 | emit_local_var (decl); | |
359 | else | |
360 | expand_anon_union_decl (decl, NULL_TREE, | |
361 | DECL_ANON_UNION_ELEMS (decl)); | |
362 | } | |
363 | else if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)) | |
0ba8a114 | 364 | make_rtl_for_local_static (decl); |
8f17b5c5 MM |
365 | else if (TREE_CODE (decl) == LABEL_DECL |
366 | && C_DECLARED_LABEL_FLAG (decl)) | |
367 | declare_nonlocal_label (decl); | |
368 | else if (lang_expand_decl_stmt) | |
369 | (*lang_expand_decl_stmt) (t); | |
f2c5f623 BC |
370 | } |
371 | ||
372 | /* Generate the RTL for T, which is an IF_STMT. */ | |
373 | ||
374 | void | |
375 | genrtl_if_stmt (t) | |
376 | tree t; | |
377 | { | |
378 | tree cond; | |
379 | genrtl_do_pushlevel (); | |
380 | cond = expand_cond (IF_COND (t)); | |
381 | emit_line_note (input_filename, lineno); | |
382 | expand_start_cond (cond, 0); | |
383 | if (THEN_CLAUSE (t)) | |
384 | expand_stmt (THEN_CLAUSE (t)); | |
385 | if (ELSE_CLAUSE (t)) | |
386 | { | |
387 | expand_start_else (); | |
388 | expand_stmt (ELSE_CLAUSE (t)); | |
389 | } | |
390 | expand_end_cond (); | |
391 | } | |
392 | ||
393 | /* Generate the RTL for T, which is a WHILE_STMT. */ | |
394 | ||
395 | void | |
396 | genrtl_while_stmt (t) | |
397 | tree t; | |
398 | { | |
399 | tree cond; | |
400 | emit_nop (); | |
401 | emit_line_note (input_filename, lineno); | |
402 | expand_start_loop (1); | |
403 | genrtl_do_pushlevel (); | |
404 | ||
405 | cond = expand_cond (WHILE_COND (t)); | |
406 | emit_line_note (input_filename, lineno); | |
407 | expand_exit_loop_if_false (0, cond); | |
57939159 | 408 | genrtl_do_pushlevel (); |
f2c5f623 BC |
409 | |
410 | expand_stmt (WHILE_BODY (t)); | |
411 | ||
412 | expand_end_loop (); | |
413 | } | |
414 | ||
415 | /* Generate the RTL for T, which is a DO_STMT. */ | |
416 | ||
417 | void | |
418 | genrtl_do_stmt (t) | |
419 | tree t; | |
420 | { | |
d599b81f RH |
421 | tree cond = DO_COND (t); |
422 | ||
423 | /* Recognize the common special-case of do { ... } while (0) and do | |
424 | not emit the loop widgetry in this case. In particular this | |
425 | avoids cluttering the rtl with dummy loop notes, which can affect | |
426 | alignment of adjacent labels. */ | |
5f10ef5b | 427 | if (integer_zerop (cond)) |
f0de0c5d RH |
428 | { |
429 | expand_start_null_loop (); | |
430 | expand_stmt (DO_BODY (t)); | |
431 | expand_end_null_loop (); | |
432 | } | |
d599b81f RH |
433 | else |
434 | { | |
435 | emit_nop (); | |
436 | emit_line_note (input_filename, lineno); | |
437 | expand_start_loop_continue_elsewhere (1); | |
f2c5f623 | 438 | |
d599b81f | 439 | expand_stmt (DO_BODY (t)); |
f2c5f623 | 440 | |
d599b81f RH |
441 | expand_loop_continue_here (); |
442 | cond = expand_cond (cond); | |
443 | emit_line_note (input_filename, lineno); | |
444 | expand_exit_loop_if_false (0, cond); | |
445 | expand_end_loop (); | |
446 | } | |
f2c5f623 BC |
447 | } |
448 | ||
0dfdeca6 BC |
449 | /* Build the node for a return statement and return it. */ |
450 | ||
451 | tree | |
452 | build_return_stmt (expr) | |
453 | tree expr; | |
454 | { | |
455 | return (build_stmt (RETURN_STMT, expr)); | |
456 | } | |
457 | ||
56cb9733 | 458 | /* Generate the RTL for STMT, which is a RETURN_STMT. */ |
f2c5f623 BC |
459 | |
460 | void | |
56cb9733 MM |
461 | genrtl_return_stmt (stmt) |
462 | tree stmt; | |
f2c5f623 | 463 | { |
56cb9733 MM |
464 | tree expr = RETURN_EXPR (stmt); |
465 | ||
f2c5f623 | 466 | emit_line_note (input_filename, lineno); |
56cb9733 MM |
467 | if (!expr) |
468 | expand_null_return (); | |
469 | else | |
470 | { | |
471 | expand_start_target_temps (); | |
472 | expand_return (expr); | |
473 | expand_end_target_temps (); | |
474 | } | |
f2c5f623 BC |
475 | } |
476 | ||
477 | /* Generate the RTL for T, which is a FOR_STMT. */ | |
478 | ||
479 | void | |
480 | genrtl_for_stmt (t) | |
481 | tree t; | |
482 | { | |
f2c5f623 | 483 | tree cond; |
8f17b5c5 MM |
484 | const char *saved_filename; |
485 | int saved_lineno; | |
486 | ||
f2c5f623 BC |
487 | if (NEW_FOR_SCOPE_P (t)) |
488 | genrtl_do_pushlevel (); | |
489 | ||
490 | expand_stmt (FOR_INIT_STMT (t)); | |
491 | ||
8f17b5c5 | 492 | /* Expand the initialization. */ |
f2c5f623 BC |
493 | emit_nop (); |
494 | emit_line_note (input_filename, lineno); | |
495 | expand_start_loop_continue_elsewhere (1); | |
496 | genrtl_do_pushlevel (); | |
497 | cond = expand_cond (FOR_COND (t)); | |
8f17b5c5 MM |
498 | |
499 | /* Save the filename and line number so that we expand the FOR_EXPR | |
500 | we can reset them back to the saved values. */ | |
501 | saved_filename = input_filename; | |
502 | saved_lineno = lineno; | |
503 | ||
504 | /* Expand the condition. */ | |
f2c5f623 BC |
505 | emit_line_note (input_filename, lineno); |
506 | if (cond) | |
507 | expand_exit_loop_if_false (0, cond); | |
f2c5f623 | 508 | |
8f17b5c5 MM |
509 | /* Expand the body. */ |
510 | genrtl_do_pushlevel (); | |
f2c5f623 BC |
511 | expand_stmt (FOR_BODY (t)); |
512 | ||
8f17b5c5 MM |
513 | /* Expand the increment expression. */ |
514 | input_filename = saved_filename; | |
515 | lineno = saved_lineno; | |
f2c5f623 BC |
516 | emit_line_note (input_filename, lineno); |
517 | expand_loop_continue_here (); | |
8f17b5c5 MM |
518 | if (FOR_EXPR (t)) |
519 | genrtl_expr_stmt (FOR_EXPR (t)); | |
f2c5f623 BC |
520 | expand_end_loop (); |
521 | } | |
522 | ||
0dfdeca6 BC |
523 | /* Build a break statement node and return it. */ |
524 | ||
525 | tree | |
526 | build_break_stmt () | |
527 | { | |
528 | return (build_stmt (BREAK_STMT)); | |
529 | } | |
530 | ||
f2c5f623 BC |
531 | /* Generate the RTL for a BREAK_STMT. */ |
532 | ||
533 | void | |
534 | genrtl_break_stmt () | |
535 | { | |
536 | emit_line_note (input_filename, lineno); | |
537 | if ( ! expand_exit_something ()) | |
538 | error ("break statement not within loop or switch"); | |
539 | } | |
540 | ||
0dfdeca6 BC |
541 | /* Build a continue statement node and return it. */ |
542 | ||
543 | tree | |
544 | build_continue_stmt () | |
545 | { | |
546 | return (build_stmt (CONTINUE_STMT)); | |
547 | } | |
548 | ||
f2c5f623 BC |
549 | /* Generate the RTL for a CONTINUE_STMT. */ |
550 | ||
551 | void | |
552 | genrtl_continue_stmt () | |
553 | { | |
554 | emit_line_note (input_filename, lineno); | |
555 | if (! expand_continue_loop (0)) | |
556 | error ("continue statement not within a loop"); | |
557 | } | |
558 | ||
559 | /* Generate the RTL for T, which is a SCOPE_STMT. */ | |
560 | ||
561 | void | |
562 | genrtl_scope_stmt (t) | |
563 | tree t; | |
564 | { | |
565 | if (!SCOPE_NO_CLEANUPS_P (t)) | |
566 | { | |
567 | if (SCOPE_BEGIN_P (t)) | |
568 | expand_start_bindings_and_block (2 * SCOPE_NULLIFIED_P (t), | |
569 | SCOPE_STMT_BLOCK (t)); | |
570 | else if (SCOPE_END_P (t)) | |
571 | expand_end_bindings (NULL_TREE, !SCOPE_NULLIFIED_P (t), 0); | |
572 | } | |
573 | else if (!SCOPE_NULLIFIED_P (t)) | |
574 | { | |
575 | rtx note = emit_note (NULL, | |
576 | (SCOPE_BEGIN_P (t) | |
577 | ? NOTE_INSN_BLOCK_BEG | |
578 | : NOTE_INSN_BLOCK_END)); | |
579 | NOTE_BLOCK (note) = SCOPE_STMT_BLOCK (t); | |
580 | } | |
581 | } | |
582 | ||
583 | /* Generate the RTL for T, which is a SWITCH_STMT. */ | |
584 | ||
585 | void | |
586 | genrtl_switch_stmt (t) | |
587 | tree t; | |
588 | { | |
589 | tree cond; | |
590 | genrtl_do_pushlevel (); | |
591 | ||
592 | cond = expand_cond (SWITCH_COND (t)); | |
56cb9733 | 593 | if (cond == error_mark_node) |
f2c5f623 BC |
594 | /* The code is in error, but we don't want expand_end_case to |
595 | crash. */ | |
56cb9733 | 596 | cond = boolean_false_node; |
f2c5f623 | 597 | |
56cb9733 MM |
598 | emit_line_note (input_filename, lineno); |
599 | expand_start_case (1, cond, TREE_TYPE (cond), "switch statement"); | |
f2c5f623 | 600 | expand_stmt (SWITCH_BODY (t)); |
f2c5f623 BC |
601 | expand_end_case (cond); |
602 | } | |
603 | ||
0dfdeca6 BC |
604 | /* Create a CASE_LABEL tree node and return it. */ |
605 | ||
606 | tree | |
56cb9733 | 607 | build_case_label (low_value, high_value, label_decl) |
0dfdeca6 BC |
608 | tree low_value; |
609 | tree high_value; | |
56cb9733 | 610 | tree label_decl; |
0dfdeca6 | 611 | { |
56cb9733 | 612 | return build_stmt (CASE_LABEL, low_value, high_value, label_decl); |
0dfdeca6 BC |
613 | } |
614 | ||
615 | ||
f2c5f623 BC |
616 | /* Generate the RTL for a CASE_LABEL. */ |
617 | ||
618 | void | |
56cb9733 MM |
619 | genrtl_case_label (case_label) |
620 | tree case_label; | |
f2c5f623 | 621 | { |
56cb9733 | 622 | tree duplicate; |
8f17b5c5 MM |
623 | tree cleanup; |
624 | ||
625 | cleanup = last_cleanup_this_contour (); | |
626 | if (cleanup) | |
627 | { | |
628 | static int explained = 0; | |
629 | warning_with_decl (TREE_PURPOSE (cleanup), | |
630 | "destructor needed for `%#D'"); | |
631 | warning ("where case label appears here"); | |
632 | if (!explained) | |
633 | { | |
634 | warning ("(enclose actions of previous case statements requiring destructors in their own scope.)"); | |
635 | explained = 1; | |
636 | } | |
637 | } | |
638 | ||
56cb9733 MM |
639 | add_case_node (CASE_LOW (case_label), CASE_HIGH (case_label), |
640 | CASE_LABEL_DECL (case_label), &duplicate); | |
f2c5f623 BC |
641 | } |
642 | ||
4cf88f57 | 643 | /* Generate the RTL for T, which is a COMPOUND_STMT. */ |
f2c5f623 | 644 | |
4cf88f57 BC |
645 | void |
646 | genrtl_compound_stmt (t) | |
647 | tree t; | |
f2c5f623 | 648 | { |
f2c5f623 | 649 | expand_stmt (COMPOUND_BODY (t)); |
f2c5f623 BC |
650 | } |
651 | ||
652 | /* Generate the RTL for an ASM_STMT. */ | |
653 | ||
654 | void | |
655 | genrtl_asm_stmt (cv_qualifier, string, output_operands, | |
4f78b9a8 | 656 | input_operands, clobbers, asm_input_p) |
f2c5f623 BC |
657 | tree cv_qualifier; |
658 | tree string; | |
659 | tree output_operands; | |
660 | tree input_operands; | |
661 | tree clobbers; | |
4f78b9a8 | 662 | int asm_input_p; |
f2c5f623 | 663 | { |
f2c5f623 BC |
664 | if (cv_qualifier != NULL_TREE |
665 | && cv_qualifier != ridpointers[(int) RID_VOLATILE]) | |
666 | { | |
667 | warning ("%s qualifier ignored on asm", | |
668 | IDENTIFIER_POINTER (cv_qualifier)); | |
669 | cv_qualifier = NULL_TREE; | |
670 | } | |
671 | ||
672 | emit_line_note (input_filename, lineno); | |
4f78b9a8 | 673 | if (asm_input_p) |
f2c5f623 | 674 | expand_asm (string); |
4f78b9a8 RH |
675 | else |
676 | c_expand_asm_operands (string, output_operands, input_operands, | |
677 | clobbers, cv_qualifier != NULL_TREE, | |
678 | input_filename, lineno); | |
f2c5f623 BC |
679 | } |
680 | ||
681 | /* Generate the RTL for a DECL_CLEANUP. */ | |
682 | ||
683 | void | |
684 | genrtl_decl_cleanup (decl, cleanup) | |
685 | tree decl; | |
686 | tree cleanup; | |
687 | { | |
688 | if (!decl || (DECL_SIZE (decl) && TREE_TYPE (decl) != error_mark_node)) | |
689 | expand_decl_cleanup (decl, cleanup); | |
690 | } | |
691 | ||
54f7877c MM |
692 | /* We're about to expand T, a statement. Set up appropriate context |
693 | for the substitution. */ | |
694 | ||
695 | void | |
696 | prep_stmt (t) | |
697 | tree t; | |
698 | { | |
699 | if (!STMT_LINENO_FOR_FN_P (t)) | |
700 | lineno = STMT_LINENO (t); | |
701 | current_stmt_tree ()->stmts_are_full_exprs_p = STMT_IS_FULL_EXPR_P (t); | |
702 | } | |
703 | ||
4cf88f57 BC |
704 | /* Generate the RTL for the statement T, its substatements, and any |
705 | other statements at its nesting level. */ | |
706 | ||
54f7877c | 707 | void |
f2c5f623 BC |
708 | expand_stmt (t) |
709 | tree t; | |
710 | { | |
54f7877c MM |
711 | while (t && t != error_mark_node) |
712 | { | |
713 | int saved_stmts_are_full_exprs_p; | |
714 | ||
715 | /* Set up context appropriately for handling this statement. */ | |
716 | saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p (); | |
717 | prep_stmt (t); | |
718 | ||
719 | switch (TREE_CODE (t)) | |
720 | { | |
721 | case RETURN_STMT: | |
56cb9733 | 722 | genrtl_return_stmt (t); |
54f7877c MM |
723 | break; |
724 | ||
725 | case EXPR_STMT: | |
726 | genrtl_expr_stmt (EXPR_STMT_EXPR (t)); | |
727 | break; | |
728 | ||
729 | case DECL_STMT: | |
730 | genrtl_decl_stmt (t); | |
731 | break; | |
732 | ||
733 | case FOR_STMT: | |
734 | genrtl_for_stmt (t); | |
735 | break; | |
736 | ||
737 | case WHILE_STMT: | |
738 | genrtl_while_stmt (t); | |
739 | break; | |
740 | ||
741 | case DO_STMT: | |
742 | genrtl_do_stmt (t); | |
743 | break; | |
744 | ||
745 | case IF_STMT: | |
746 | genrtl_if_stmt (t); | |
747 | break; | |
748 | ||
749 | case COMPOUND_STMT: | |
750 | genrtl_compound_stmt (t); | |
751 | break; | |
752 | ||
753 | case BREAK_STMT: | |
754 | genrtl_break_stmt (); | |
755 | break; | |
756 | ||
757 | case CONTINUE_STMT: | |
758 | genrtl_continue_stmt (); | |
759 | break; | |
760 | ||
761 | case SWITCH_STMT: | |
762 | genrtl_switch_stmt (t); | |
763 | break; | |
764 | ||
765 | case CASE_LABEL: | |
56cb9733 | 766 | genrtl_case_label (t); |
54f7877c MM |
767 | break; |
768 | ||
769 | case LABEL_STMT: | |
770 | expand_label (LABEL_STMT_LABEL (t)); | |
771 | break; | |
772 | ||
773 | case GOTO_STMT: | |
774 | genrtl_goto_stmt (GOTO_DESTINATION (t)); | |
775 | break; | |
776 | ||
777 | case ASM_STMT: | |
778 | genrtl_asm_stmt (ASM_CV_QUAL (t), ASM_STRING (t), | |
4f78b9a8 RH |
779 | ASM_OUTPUTS (t), ASM_INPUTS (t), |
780 | ASM_CLOBBERS (t), ASM_INPUT_P (t)); | |
54f7877c MM |
781 | break; |
782 | ||
8f17b5c5 MM |
783 | case SCOPE_STMT: |
784 | genrtl_scope_stmt (t); | |
785 | break; | |
786 | ||
54f7877c MM |
787 | default: |
788 | if (lang_expand_stmt) | |
789 | (*lang_expand_stmt) (t); | |
790 | else | |
791 | abort (); | |
792 | break; | |
793 | } | |
794 | ||
795 | /* Restore saved state. */ | |
e92044c3 RK |
796 | current_stmt_tree ()->stmts_are_full_exprs_p |
797 | = saved_stmts_are_full_exprs_p; | |
54f7877c MM |
798 | |
799 | /* Go on to the next statement in this scope. */ | |
800 | t = TREE_CHAIN (t); | |
801 | } | |
f2c5f623 | 802 | } |
4cf88f57 | 803 |