]>
Commit | Line | Data |
---|---|---|
74338ff6 | 1 | /* Tree-dumping functionality for intermediate representation. |
aad93da1 | 2 | Copyright (C) 1999-2017 Free Software Foundation, Inc. |
74338ff6 | 3 | Written by Mark Mitchell <mark@codesourcery.com> |
4 | ||
5 | This file is part of GCC. | |
6 | ||
7 | GCC is free software; you can redistribute it and/or modify it under | |
8 | the terms of the GNU General Public License as published by the Free | |
8c4c00c1 | 9 | Software Foundation; either version 3, or (at your option) any later |
74338ff6 | 10 | version. |
11 | ||
12 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
13 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 | for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
8c4c00c1 | 18 | along with GCC; see the file COPYING3. If not see |
19 | <http://www.gnu.org/licenses/>. */ | |
74338ff6 | 20 | |
21 | #include "config.h" | |
22 | #include "system.h" | |
805e22b2 | 23 | #include "coretypes.h" |
74338ff6 | 24 | #include "tree.h" |
7c29e30e | 25 | #include "tree-pretty-print.h" |
3119c950 | 26 | #include "tree-dump.h" |
74338ff6 | 27 | #include "langhooks.h" |
e8c5dd3c | 28 | #include "tree-iterator.h" |
74338ff6 | 29 | |
9f627b1a | 30 | static unsigned int queue (dump_info_p, const_tree, int); |
d598ad0d | 31 | static void dump_index (dump_info_p, unsigned int); |
32 | static void dequeue_and_dump (dump_info_p); | |
33 | static void dump_new_line (dump_info_p); | |
34 | static void dump_maybe_newline (dump_info_p); | |
74338ff6 | 35 | |
36 | /* Add T to the end of the queue of nodes to dump. Returns the index | |
37 | assigned to T. */ | |
38 | ||
39 | static unsigned int | |
9f627b1a | 40 | queue (dump_info_p di, const_tree t, int flags) |
74338ff6 | 41 | { |
42 | dump_queue_p dq; | |
43 | dump_node_info_p dni; | |
44 | unsigned int index; | |
45 | ||
46 | /* Assign the next available index to T. */ | |
47 | index = ++di->index; | |
48 | ||
49 | /* Obtain a new queue node. */ | |
50 | if (di->free_list) | |
51 | { | |
52 | dq = di->free_list; | |
53 | di->free_list = dq->next; | |
54 | } | |
55 | else | |
4c36ffe6 | 56 | dq = XNEW (struct dump_queue); |
74338ff6 | 57 | |
58 | /* Create a new entry in the splay-tree. */ | |
4c36ffe6 | 59 | dni = XNEW (struct dump_node_info); |
74338ff6 | 60 | dni->index = index; |
61 | dni->binfo_p = ((flags & DUMP_BINFO) != 0); | |
40570cc2 | 62 | dq->node = splay_tree_insert (di->nodes, (splay_tree_key) t, |
74338ff6 | 63 | (splay_tree_value) dni); |
64 | ||
65 | /* Add it to the end of the queue. */ | |
66 | dq->next = 0; | |
67 | if (!di->queue_end) | |
68 | di->queue = dq; | |
69 | else | |
70 | di->queue_end->next = dq; | |
71 | di->queue_end = dq; | |
72 | ||
73 | /* Return the index. */ | |
74 | return index; | |
75 | } | |
76 | ||
77 | static void | |
d598ad0d | 78 | dump_index (dump_info_p di, unsigned int index) |
74338ff6 | 79 | { |
80 | fprintf (di->stream, "@%-6u ", index); | |
81 | di->column += 8; | |
82 | } | |
83 | ||
84 | /* If T has not already been output, queue it for subsequent output. | |
85 | FIELD is a string to print before printing the index. Then, the | |
86 | index of T is printed. */ | |
87 | ||
88 | void | |
9f627b1a | 89 | queue_and_dump_index (dump_info_p di, const char *field, const_tree t, int flags) |
74338ff6 | 90 | { |
91 | unsigned int index; | |
92 | splay_tree_node n; | |
93 | ||
94 | /* If there's no node, just return. This makes for fewer checks in | |
95 | our callers. */ | |
96 | if (!t) | |
97 | return; | |
98 | ||
99 | /* See if we've already queued or dumped this node. */ | |
100 | n = splay_tree_lookup (di->nodes, (splay_tree_key) t); | |
101 | if (n) | |
102 | index = ((dump_node_info_p) n->value)->index; | |
103 | else | |
104 | /* If we haven't, add it to the queue. */ | |
105 | index = queue (di, t, flags); | |
106 | ||
107 | /* Print the index of the node. */ | |
108 | dump_maybe_newline (di); | |
109 | fprintf (di->stream, "%-4s: ", field); | |
110 | di->column += 6; | |
111 | dump_index (di, index); | |
112 | } | |
113 | ||
114 | /* Dump the type of T. */ | |
115 | ||
116 | void | |
9f627b1a | 117 | queue_and_dump_type (dump_info_p di, const_tree t) |
74338ff6 | 118 | { |
119 | queue_and_dump_index (di, "type", TREE_TYPE (t), DUMP_NONE); | |
120 | } | |
121 | ||
122 | /* Dump column control */ | |
123 | #define SOL_COLUMN 25 /* Start of line column. */ | |
124 | #define EOL_COLUMN 55 /* End of line column. */ | |
125 | #define COLUMN_ALIGNMENT 15 /* Alignment. */ | |
126 | ||
127 | /* Insert a new line in the dump output, and indent to an appropriate | |
128 | place to start printing more fields. */ | |
129 | ||
130 | static void | |
d598ad0d | 131 | dump_new_line (dump_info_p di) |
74338ff6 | 132 | { |
133 | fprintf (di->stream, "\n%*s", SOL_COLUMN, ""); | |
134 | di->column = SOL_COLUMN; | |
135 | } | |
136 | ||
137 | /* If necessary, insert a new line. */ | |
138 | ||
139 | static void | |
d598ad0d | 140 | dump_maybe_newline (dump_info_p di) |
74338ff6 | 141 | { |
142 | int extra; | |
40570cc2 | 143 | |
74338ff6 | 144 | /* See if we need a new line. */ |
145 | if (di->column > EOL_COLUMN) | |
146 | dump_new_line (di); | |
147 | /* See if we need any padding. */ | |
148 | else if ((extra = (di->column - SOL_COLUMN) % COLUMN_ALIGNMENT) != 0) | |
149 | { | |
150 | fprintf (di->stream, "%*s", COLUMN_ALIGNMENT - extra, ""); | |
151 | di->column += COLUMN_ALIGNMENT - extra; | |
152 | } | |
153 | } | |
154 | ||
155 | /* Dump pointer PTR using FIELD to identify it. */ | |
156 | ||
157 | void | |
d598ad0d | 158 | dump_pointer (dump_info_p di, const char *field, void *ptr) |
74338ff6 | 159 | { |
160 | dump_maybe_newline (di); | |
fb2893a7 | 161 | fprintf (di->stream, "%-4s: %-8" HOST_WIDE_INT_PRINT "x ", field, |
162 | (unsigned HOST_WIDE_INT) (uintptr_t) ptr); | |
74338ff6 | 163 | di->column += 15; |
164 | } | |
165 | ||
166 | /* Dump integer I using FIELD to identify it. */ | |
167 | ||
168 | void | |
d598ad0d | 169 | dump_int (dump_info_p di, const char *field, int i) |
74338ff6 | 170 | { |
171 | dump_maybe_newline (di); | |
172 | fprintf (di->stream, "%-4s: %-7d ", field, i); | |
173 | di->column += 14; | |
174 | } | |
175 | ||
905582c1 | 176 | /* Dump the floating point value R, using FIELD to identify it. */ |
177 | ||
178 | static void | |
179 | dump_real (dump_info_p di, const char *field, const REAL_VALUE_TYPE *r) | |
180 | { | |
181 | char buf[32]; | |
182 | real_to_decimal (buf, r, sizeof (buf), 0, true); | |
183 | dump_maybe_newline (di); | |
184 | fprintf (di->stream, "%-4s: %s ", field, buf); | |
185 | di->column += strlen (buf) + 7; | |
186 | } | |
187 | ||
06f0b99c | 188 | /* Dump the fixed-point value F, using FIELD to identify it. */ |
189 | ||
190 | static void | |
191 | dump_fixed (dump_info_p di, const char *field, const FIXED_VALUE_TYPE *f) | |
192 | { | |
193 | char buf[32]; | |
194 | fixed_to_decimal (buf, f, sizeof (buf)); | |
195 | dump_maybe_newline (di); | |
196 | fprintf (di->stream, "%-4s: %s ", field, buf); | |
197 | di->column += strlen (buf) + 7; | |
198 | } | |
199 | ||
905582c1 | 200 | |
74338ff6 | 201 | /* Dump the string S. */ |
202 | ||
203 | void | |
d598ad0d | 204 | dump_string (dump_info_p di, const char *string) |
74338ff6 | 205 | { |
206 | dump_maybe_newline (di); | |
207 | fprintf (di->stream, "%-13s ", string); | |
208 | if (strlen (string) > 13) | |
209 | di->column += strlen (string) + 1; | |
210 | else | |
211 | di->column += 14; | |
212 | } | |
213 | ||
214 | /* Dump the string field S. */ | |
215 | ||
5a471c32 | 216 | void |
d598ad0d | 217 | dump_string_field (dump_info_p di, const char *field, const char *string) |
74338ff6 | 218 | { |
219 | dump_maybe_newline (di); | |
220 | fprintf (di->stream, "%-4s: %-7s ", field, string); | |
221 | if (strlen (string) > 7) | |
222 | di->column += 6 + strlen (string) + 1; | |
223 | else | |
224 | di->column += 14; | |
225 | } | |
226 | ||
74338ff6 | 227 | /* Dump the next node in the queue. */ |
228 | ||
40570cc2 | 229 | static void |
d598ad0d | 230 | dequeue_and_dump (dump_info_p di) |
74338ff6 | 231 | { |
232 | dump_queue_p dq; | |
233 | splay_tree_node stn; | |
234 | dump_node_info_p dni; | |
235 | tree t; | |
236 | unsigned int index; | |
237 | enum tree_code code; | |
ce45a448 | 238 | enum tree_code_class code_class; |
74338ff6 | 239 | const char* code_name; |
240 | ||
241 | /* Get the next node from the queue. */ | |
242 | dq = di->queue; | |
243 | stn = dq->node; | |
244 | t = (tree) stn->key; | |
245 | dni = (dump_node_info_p) stn->value; | |
246 | index = dni->index; | |
247 | ||
248 | /* Remove the node from the queue, and put it on the free list. */ | |
249 | di->queue = dq->next; | |
250 | if (!di->queue) | |
251 | di->queue_end = 0; | |
252 | dq->next = di->free_list; | |
253 | di->free_list = dq; | |
254 | ||
255 | /* Print the node index. */ | |
256 | dump_index (di, index); | |
257 | /* And the type of node this is. */ | |
258 | if (dni->binfo_p) | |
259 | code_name = "binfo"; | |
260 | else | |
f3d35d4d | 261 | code_name = get_tree_code_name (TREE_CODE (t)); |
74338ff6 | 262 | fprintf (di->stream, "%-16s ", code_name); |
263 | di->column = 25; | |
264 | ||
265 | /* Figure out what kind of node this is. */ | |
266 | code = TREE_CODE (t); | |
267 | code_class = TREE_CODE_CLASS (code); | |
268 | ||
269 | /* Although BINFOs are TREE_VECs, we dump them specially so as to be | |
270 | more informative. */ | |
271 | if (dni->binfo_p) | |
272 | { | |
95f3173a | 273 | unsigned ix; |
f6cc6a08 | 274 | tree base; |
f1f41a6c | 275 | vec<tree, va_gc> *accesses = BINFO_BASE_ACCESSES (t); |
d598ad0d | 276 | |
95f3173a | 277 | dump_child ("type", BINFO_TYPE (t)); |
278 | ||
57c28194 | 279 | if (BINFO_VIRTUAL_P (t)) |
5a471c32 | 280 | dump_string_field (di, "spec", "virt"); |
40570cc2 | 281 | |
f6cc6a08 | 282 | dump_int (di, "bases", BINFO_N_BASE_BINFOS (t)); |
283 | for (ix = 0; BINFO_BASE_ITERATE (t, ix, base); ix++) | |
95f3173a | 284 | { |
f1f41a6c | 285 | tree access = (accesses ? (*accesses)[ix] : access_public_node); |
95f3173a | 286 | const char *string = NULL; |
287 | ||
288 | if (access == access_public_node) | |
289 | string = "pub"; | |
290 | else if (access == access_protected_node) | |
291 | string = "prot"; | |
292 | else if (access == access_private_node) | |
293 | string = "priv"; | |
294 | else | |
8c0963c4 | 295 | gcc_unreachable (); |
d598ad0d | 296 | |
5a471c32 | 297 | dump_string_field (di, "accs", string); |
95f3173a | 298 | queue_and_dump_index (di, "binf", base, DUMP_BINFO); |
299 | } | |
d598ad0d | 300 | |
74338ff6 | 301 | goto done; |
302 | } | |
303 | ||
304 | /* We can knock off a bunch of expression nodes in exactly the same | |
305 | way. */ | |
306 | if (IS_EXPR_CODE_CLASS (code_class)) | |
307 | { | |
308 | /* If we're dumping children, dump them now. */ | |
309 | queue_and_dump_type (di, t); | |
310 | ||
311 | switch (code_class) | |
312 | { | |
ce45a448 | 313 | case tcc_unary: |
74338ff6 | 314 | dump_child ("op 0", TREE_OPERAND (t, 0)); |
315 | break; | |
40570cc2 | 316 | |
ce45a448 | 317 | case tcc_binary: |
318 | case tcc_comparison: | |
74338ff6 | 319 | dump_child ("op 0", TREE_OPERAND (t, 0)); |
320 | dump_child ("op 1", TREE_OPERAND (t, 1)); | |
321 | break; | |
40570cc2 | 322 | |
ce45a448 | 323 | case tcc_expression: |
324 | case tcc_reference: | |
325 | case tcc_statement: | |
f43a1a60 | 326 | case tcc_vl_exp: |
74338ff6 | 327 | /* These nodes are handled explicitly below. */ |
328 | break; | |
40570cc2 | 329 | |
74338ff6 | 330 | default: |
8c0963c4 | 331 | gcc_unreachable (); |
74338ff6 | 332 | } |
333 | } | |
334 | else if (DECL_P (t)) | |
335 | { | |
2ed8b5d0 | 336 | expanded_location xloc; |
74338ff6 | 337 | /* All declarations have names. */ |
338 | if (DECL_NAME (t)) | |
339 | dump_child ("name", DECL_NAME (t)); | |
40570cc2 | 340 | if (DECL_ASSEMBLER_NAME_SET_P (t) |
74338ff6 | 341 | && DECL_ASSEMBLER_NAME (t) != DECL_NAME (t)) |
342 | dump_child ("mngl", DECL_ASSEMBLER_NAME (t)); | |
9021d2da | 343 | if (DECL_ABSTRACT_ORIGIN (t)) |
344 | dump_child ("orig", DECL_ABSTRACT_ORIGIN (t)); | |
74338ff6 | 345 | /* And types. */ |
346 | queue_and_dump_type (di, t); | |
347 | dump_child ("scpe", DECL_CONTEXT (t)); | |
348 | /* And a source position. */ | |
2ed8b5d0 | 349 | xloc = expand_location (DECL_SOURCE_LOCATION (t)); |
350 | if (xloc.file) | |
74338ff6 | 351 | { |
82715bcd | 352 | const char *filename = lbasename (xloc.file); |
74338ff6 | 353 | |
354 | dump_maybe_newline (di); | |
40570cc2 | 355 | fprintf (di->stream, "srcp: %s:%-6d ", filename, |
2ed8b5d0 | 356 | xloc.line); |
74338ff6 | 357 | di->column += 6 + strlen (filename) + 8; |
358 | } | |
359 | /* And any declaration can be compiler-generated. */ | |
437f5d6b | 360 | if (CODE_CONTAINS_STRUCT (TREE_CODE (t), TS_DECL_COMMON) |
361 | && DECL_ARTIFICIAL (t)) | |
5a471c32 | 362 | dump_string_field (di, "note", "artificial"); |
1767a056 | 363 | if (DECL_CHAIN (t) && !dump_flag (di, TDF_SLIM, NULL)) |
364 | dump_child ("chain", DECL_CHAIN (t)); | |
74338ff6 | 365 | } |
ce45a448 | 366 | else if (code_class == tcc_type) |
74338ff6 | 367 | { |
368 | /* All types have qualifiers. */ | |
dc24ddbd | 369 | int quals = lang_hooks.tree_dump.type_quals (t); |
40570cc2 | 370 | |
74338ff6 | 371 | if (quals != TYPE_UNQUALIFIED) |
372 | { | |
373 | fprintf (di->stream, "qual: %c%c%c ", | |
374 | (quals & TYPE_QUAL_CONST) ? 'c' : ' ', | |
375 | (quals & TYPE_QUAL_VOLATILE) ? 'v' : ' ', | |
376 | (quals & TYPE_QUAL_RESTRICT) ? 'r' : ' '); | |
377 | di->column += 14; | |
378 | } | |
379 | ||
380 | /* All types have associated declarations. */ | |
381 | dump_child ("name", TYPE_NAME (t)); | |
382 | ||
383 | /* All types have a main variant. */ | |
384 | if (TYPE_MAIN_VARIANT (t) != t) | |
385 | dump_child ("unql", TYPE_MAIN_VARIANT (t)); | |
40570cc2 | 386 | |
74338ff6 | 387 | /* And sizes. */ |
388 | dump_child ("size", TYPE_SIZE (t)); | |
389 | ||
390 | /* All types have alignments. */ | |
391 | dump_int (di, "algn", TYPE_ALIGN (t)); | |
392 | } | |
ce45a448 | 393 | else if (code_class == tcc_constant) |
74338ff6 | 394 | /* All constants can have types. */ |
395 | queue_and_dump_type (di, t); | |
396 | ||
397 | /* Give the language-specific code a chance to print something. If | |
398 | it's completely taken care of things, don't bother printing | |
399 | anything more ourselves. */ | |
dc24ddbd | 400 | if (lang_hooks.tree_dump.dump_tree (di, t)) |
74338ff6 | 401 | goto done; |
402 | ||
403 | /* Now handle the various kinds of nodes. */ | |
404 | switch (code) | |
405 | { | |
406 | int i; | |
407 | ||
408 | case IDENTIFIER_NODE: | |
409 | dump_string_field (di, "strg", IDENTIFIER_POINTER (t)); | |
410 | dump_int (di, "lngt", IDENTIFIER_LENGTH (t)); | |
411 | break; | |
412 | ||
413 | case TREE_LIST: | |
414 | dump_child ("purp", TREE_PURPOSE (t)); | |
415 | dump_child ("valu", TREE_VALUE (t)); | |
416 | dump_child ("chan", TREE_CHAIN (t)); | |
417 | break; | |
418 | ||
e8c5dd3c | 419 | case STATEMENT_LIST: |
420 | { | |
421 | tree_stmt_iterator it; | |
422 | for (i = 0, it = tsi_start (t); !tsi_end_p (it); tsi_next (&it), i++) | |
423 | { | |
424 | char buffer[32]; | |
425 | sprintf (buffer, "%u", i); | |
426 | dump_child (buffer, tsi_stmt (it)); | |
427 | } | |
428 | } | |
429 | break; | |
430 | ||
74338ff6 | 431 | case TREE_VEC: |
432 | dump_int (di, "lngt", TREE_VEC_LENGTH (t)); | |
433 | for (i = 0; i < TREE_VEC_LENGTH (t); ++i) | |
434 | { | |
435 | char buffer[32]; | |
436 | sprintf (buffer, "%u", i); | |
437 | dump_child (buffer, TREE_VEC_ELT (t, i)); | |
438 | } | |
439 | break; | |
440 | ||
441 | case INTEGER_TYPE: | |
442 | case ENUMERAL_TYPE: | |
443 | dump_int (di, "prec", TYPE_PRECISION (t)); | |
5a471c32 | 444 | dump_string_field (di, "sign", TYPE_UNSIGNED (t) ? "unsigned": "signed"); |
74338ff6 | 445 | dump_child ("min", TYPE_MIN_VALUE (t)); |
446 | dump_child ("max", TYPE_MAX_VALUE (t)); | |
447 | ||
448 | if (code == ENUMERAL_TYPE) | |
449 | dump_child ("csts", TYPE_VALUES (t)); | |
450 | break; | |
451 | ||
452 | case REAL_TYPE: | |
453 | dump_int (di, "prec", TYPE_PRECISION (t)); | |
454 | break; | |
455 | ||
06f0b99c | 456 | case FIXED_POINT_TYPE: |
457 | dump_int (di, "prec", TYPE_PRECISION (t)); | |
458 | dump_string_field (di, "sign", TYPE_UNSIGNED (t) ? "unsigned": "signed"); | |
459 | dump_string_field (di, "saturating", | |
460 | TYPE_SATURATING (t) ? "saturating": "non-saturating"); | |
461 | break; | |
462 | ||
74338ff6 | 463 | case POINTER_TYPE: |
464 | dump_child ("ptd", TREE_TYPE (t)); | |
465 | break; | |
466 | ||
467 | case REFERENCE_TYPE: | |
468 | dump_child ("refd", TREE_TYPE (t)); | |
469 | break; | |
470 | ||
471 | case METHOD_TYPE: | |
472 | dump_child ("clas", TYPE_METHOD_BASETYPE (t)); | |
473 | /* Fall through. */ | |
474 | ||
475 | case FUNCTION_TYPE: | |
476 | dump_child ("retn", TREE_TYPE (t)); | |
477 | dump_child ("prms", TYPE_ARG_TYPES (t)); | |
478 | break; | |
479 | ||
480 | case ARRAY_TYPE: | |
481 | dump_child ("elts", TREE_TYPE (t)); | |
482 | dump_child ("domn", TYPE_DOMAIN (t)); | |
483 | break; | |
484 | ||
485 | case RECORD_TYPE: | |
486 | case UNION_TYPE: | |
487 | if (TREE_CODE (t) == RECORD_TYPE) | |
5a471c32 | 488 | dump_string_field (di, "tag", "struct"); |
74338ff6 | 489 | else |
5a471c32 | 490 | dump_string_field (di, "tag", "union"); |
40570cc2 | 491 | |
74338ff6 | 492 | dump_child ("flds", TYPE_FIELDS (t)); |
40570cc2 | 493 | queue_and_dump_index (di, "binf", TYPE_BINFO (t), |
74338ff6 | 494 | DUMP_BINFO); |
495 | break; | |
496 | ||
497 | case CONST_DECL: | |
498 | dump_child ("cnst", DECL_INITIAL (t)); | |
499 | break; | |
500 | ||
688ff29b | 501 | case DEBUG_EXPR_DECL: |
502 | dump_int (di, "-uid", DEBUG_TEMP_UID (t)); | |
503 | /* Fall through. */ | |
504 | ||
74338ff6 | 505 | case VAR_DECL: |
506 | case PARM_DECL: | |
507 | case FIELD_DECL: | |
508 | case RESULT_DECL: | |
509 | if (TREE_CODE (t) == PARM_DECL) | |
510 | dump_child ("argt", DECL_ARG_TYPE (t)); | |
511 | else | |
512 | dump_child ("init", DECL_INITIAL (t)); | |
513 | dump_child ("size", DECL_SIZE (t)); | |
514 | dump_int (di, "algn", DECL_ALIGN (t)); | |
515 | ||
516 | if (TREE_CODE (t) == FIELD_DECL) | |
517 | { | |
74338ff6 | 518 | if (DECL_FIELD_OFFSET (t)) |
519 | dump_child ("bpos", bit_position (t)); | |
520 | } | |
53e9c5c4 | 521 | else if (VAR_P (t) || TREE_CODE (t) == PARM_DECL) |
74338ff6 | 522 | { |
523 | dump_int (di, "used", TREE_USED (t)); | |
524 | if (DECL_REGISTER (t)) | |
5a471c32 | 525 | dump_string_field (di, "spec", "register"); |
74338ff6 | 526 | } |
527 | break; | |
528 | ||
529 | case FUNCTION_DECL: | |
530 | dump_child ("args", DECL_ARGUMENTS (t)); | |
531 | if (DECL_EXTERNAL (t)) | |
5a471c32 | 532 | dump_string_field (di, "body", "undefined"); |
74338ff6 | 533 | if (TREE_PUBLIC (t)) |
5a471c32 | 534 | dump_string_field (di, "link", "extern"); |
74338ff6 | 535 | else |
5a471c32 | 536 | dump_string_field (di, "link", "static"); |
de9ebaea | 537 | if (DECL_SAVED_TREE (t) && !dump_flag (di, TDF_SLIM, t)) |
74338ff6 | 538 | dump_child ("body", DECL_SAVED_TREE (t)); |
539 | break; | |
540 | ||
74338ff6 | 541 | case INTEGER_CST: |
e913b5cd | 542 | fprintf (di->stream, "int: "); |
6da74b21 | 543 | print_decs (t, di->stream); |
74338ff6 | 544 | break; |
545 | ||
546 | case STRING_CST: | |
547 | fprintf (di->stream, "strg: %-7s ", TREE_STRING_POINTER (t)); | |
548 | dump_int (di, "lngt", TREE_STRING_LENGTH (t)); | |
549 | break; | |
550 | ||
905582c1 | 551 | case REAL_CST: |
552 | dump_real (di, "valu", TREE_REAL_CST_PTR (t)); | |
553 | break; | |
554 | ||
06f0b99c | 555 | case FIXED_CST: |
556 | dump_fixed (di, "valu", TREE_FIXED_CST_PTR (t)); | |
557 | break; | |
558 | ||
74338ff6 | 559 | case TRUTH_NOT_EXPR: |
560 | case ADDR_EXPR: | |
561 | case INDIRECT_REF: | |
562 | case CLEANUP_POINT_EXPR: | |
563 | case SAVE_EXPR: | |
b25de375 | 564 | case REALPART_EXPR: |
565 | case IMAGPART_EXPR: | |
74338ff6 | 566 | /* These nodes are unary, but do not have code class `1'. */ |
567 | dump_child ("op 0", TREE_OPERAND (t, 0)); | |
568 | break; | |
569 | ||
570 | case TRUTH_ANDIF_EXPR: | |
571 | case TRUTH_ORIF_EXPR: | |
572 | case INIT_EXPR: | |
573 | case MODIFY_EXPR: | |
74338ff6 | 574 | case COMPOUND_EXPR: |
74338ff6 | 575 | case PREDECREMENT_EXPR: |
576 | case PREINCREMENT_EXPR: | |
577 | case POSTDECREMENT_EXPR: | |
578 | case POSTINCREMENT_EXPR: | |
579 | /* These nodes are binary, but do not have code class `2'. */ | |
580 | dump_child ("op 0", TREE_OPERAND (t, 0)); | |
581 | dump_child ("op 1", TREE_OPERAND (t, 1)); | |
582 | break; | |
583 | ||
6374121b | 584 | case COMPONENT_REF: |
7f85203b | 585 | case BIT_FIELD_REF: |
6374121b | 586 | dump_child ("op 0", TREE_OPERAND (t, 0)); |
587 | dump_child ("op 1", TREE_OPERAND (t, 1)); | |
588 | dump_child ("op 2", TREE_OPERAND (t, 2)); | |
589 | break; | |
590 | ||
591 | case ARRAY_REF: | |
592 | case ARRAY_RANGE_REF: | |
593 | dump_child ("op 0", TREE_OPERAND (t, 0)); | |
594 | dump_child ("op 1", TREE_OPERAND (t, 1)); | |
595 | dump_child ("op 2", TREE_OPERAND (t, 2)); | |
596 | dump_child ("op 3", TREE_OPERAND (t, 3)); | |
597 | break; | |
598 | ||
74338ff6 | 599 | case COND_EXPR: |
600 | dump_child ("op 0", TREE_OPERAND (t, 0)); | |
601 | dump_child ("op 1", TREE_OPERAND (t, 1)); | |
602 | dump_child ("op 2", TREE_OPERAND (t, 2)); | |
603 | break; | |
604 | ||
9021d2da | 605 | case TRY_FINALLY_EXPR: |
606 | dump_child ("op 0", TREE_OPERAND (t, 0)); | |
607 | dump_child ("op 1", TREE_OPERAND (t, 1)); | |
608 | break; | |
609 | ||
74338ff6 | 610 | case CALL_EXPR: |
c2f47e15 | 611 | { |
612 | int i = 0; | |
613 | tree arg; | |
614 | call_expr_arg_iterator iter; | |
615 | dump_child ("fn", CALL_EXPR_FN (t)); | |
616 | FOR_EACH_CALL_EXPR_ARG (arg, iter, t) | |
617 | { | |
618 | char buffer[32]; | |
619 | sprintf (buffer, "%u", i); | |
620 | dump_child (buffer, arg); | |
621 | i++; | |
622 | } | |
623 | } | |
74338ff6 | 624 | break; |
625 | ||
626 | case CONSTRUCTOR: | |
c75b4594 | 627 | { |
628 | unsigned HOST_WIDE_INT cnt; | |
629 | tree index, value; | |
8698843f | 630 | dump_int (di, "lngt", CONSTRUCTOR_NELTS (t)); |
c75b4594 | 631 | FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t), cnt, index, value) |
632 | { | |
633 | dump_child ("idx", index); | |
634 | dump_child ("val", value); | |
635 | } | |
636 | } | |
74338ff6 | 637 | break; |
638 | ||
74338ff6 | 639 | case BIND_EXPR: |
640 | dump_child ("vars", TREE_OPERAND (t, 0)); | |
641 | dump_child ("body", TREE_OPERAND (t, 1)); | |
642 | break; | |
643 | ||
644 | case LOOP_EXPR: | |
645 | dump_child ("body", TREE_OPERAND (t, 0)); | |
646 | break; | |
647 | ||
648 | case EXIT_EXPR: | |
649 | dump_child ("cond", TREE_OPERAND (t, 0)); | |
650 | break; | |
651 | ||
9021d2da | 652 | case RETURN_EXPR: |
653 | dump_child ("expr", TREE_OPERAND (t, 0)); | |
654 | break; | |
655 | ||
74338ff6 | 656 | case TARGET_EXPR: |
657 | dump_child ("decl", TREE_OPERAND (t, 0)); | |
658 | dump_child ("init", TREE_OPERAND (t, 1)); | |
659 | dump_child ("clnp", TREE_OPERAND (t, 2)); | |
660 | /* There really are two possible places the initializer can be. | |
661 | After RTL expansion, the second operand is moved to the | |
662 | position of the fourth operand, and the second operand | |
663 | becomes NULL. */ | |
664 | dump_child ("init", TREE_OPERAND (t, 3)); | |
665 | break; | |
40570cc2 | 666 | |
9021d2da | 667 | case CASE_LABEL_EXPR: |
668 | dump_child ("name", CASE_LABEL (t)); | |
7d4c98bc | 669 | if (CASE_LOW (t)) |
670 | { | |
671 | dump_child ("low ", CASE_LOW (t)); | |
672 | if (CASE_HIGH (t)) | |
673 | dump_child ("high", CASE_HIGH (t)); | |
9021d2da | 674 | } |
9021d2da | 675 | break; |
676 | case LABEL_EXPR: | |
677 | dump_child ("name", TREE_OPERAND (t,0)); | |
678 | break; | |
679 | case GOTO_EXPR: | |
680 | dump_child ("labl", TREE_OPERAND (t, 0)); | |
681 | break; | |
682 | case SWITCH_EXPR: | |
683 | dump_child ("cond", TREE_OPERAND (t, 0)); | |
684 | dump_child ("body", TREE_OPERAND (t, 1)); | |
685 | if (TREE_OPERAND (t, 2)) | |
686 | { | |
687 | dump_child ("labl", TREE_OPERAND (t,2)); | |
688 | } | |
689 | break; | |
55d6e7cd | 690 | case OMP_CLAUSE: |
691 | { | |
692 | int i; | |
693 | fprintf (di->stream, "%s\n", omp_clause_code_name[OMP_CLAUSE_CODE (t)]); | |
694 | for (i = 0; i < omp_clause_num_ops[OMP_CLAUSE_CODE (t)]; i++) | |
695 | dump_child ("op: ", OMP_CLAUSE_OPERAND (t, i)); | |
696 | } | |
697 | break; | |
74338ff6 | 698 | default: |
699 | /* There are no additional fields to print. */ | |
700 | break; | |
701 | } | |
702 | ||
703 | done: | |
704 | if (dump_flag (di, TDF_ADDRESS, NULL)) | |
705 | dump_pointer (di, "addr", (void *)t); | |
40570cc2 | 706 | |
74338ff6 | 707 | /* Terminate the line. */ |
708 | fprintf (di->stream, "\n"); | |
709 | } | |
710 | ||
f712a0dc | 711 | /* Return nonzero if FLAG has been specified for the dump, and NODE |
74338ff6 | 712 | is not the root node of the dump. */ |
713 | ||
3f6e5ced | 714 | int dump_flag (dump_info_p di, dump_flags_t flag, const_tree node) |
74338ff6 | 715 | { |
716 | return (di->flags & flag) && (node != di->node); | |
717 | } | |
718 | ||
719 | /* Dump T, and all its children, on STREAM. */ | |
720 | ||
721 | void | |
3f6e5ced | 722 | dump_node (const_tree t, dump_flags_t flags, FILE *stream) |
74338ff6 | 723 | { |
724 | struct dump_info di; | |
725 | dump_queue_p dq; | |
726 | dump_queue_p next_dq; | |
727 | ||
728 | /* Initialize the dump-information structure. */ | |
729 | di.stream = stream; | |
730 | di.index = 0; | |
731 | di.column = 0; | |
732 | di.queue = 0; | |
733 | di.queue_end = 0; | |
734 | di.free_list = 0; | |
735 | di.flags = flags; | |
736 | di.node = t; | |
40570cc2 | 737 | di.nodes = splay_tree_new (splay_tree_compare_pointers, 0, |
74338ff6 | 738 | (splay_tree_delete_value_fn) &free); |
739 | ||
740 | /* Queue up the first node. */ | |
741 | queue (&di, t, DUMP_NONE); | |
742 | ||
743 | /* Until the queue is empty, keep dumping nodes. */ | |
744 | while (di.queue) | |
745 | dequeue_and_dump (&di); | |
746 | ||
747 | /* Now, clean up. */ | |
748 | for (dq = di.free_list; dq; dq = next_dq) | |
749 | { | |
750 | next_dq = dq->next; | |
751 | free (dq); | |
752 | } | |
753 | splay_tree_delete (di.nodes); | |
754 | } |