]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/print-tree.c
tree-core.h (tree_code_name): Remove.
[thirdparty/gcc.git] / gcc / print-tree.c
1 /* Prints out tree in human readable form - GCC
2 Copyright (C) 1990-2013 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
10
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
15
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/>. */
19
20
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tm.h"
25 #include "tree.h"
26 #include "ggc.h"
27 #include "langhooks.h"
28 #include "tree-iterator.h"
29 #include "diagnostic.h"
30 #include "gimple-pretty-print.h" /* FIXME */
31 #include "tree-ssa.h"
32 #include "tree-dump.h"
33 #include "dumpfile.h"
34
35 /* Define the hash table of nodes already seen.
36 Such nodes are not repeated; brief cross-references are used. */
37
38 #define HASH_SIZE 37
39
40 struct bucket
41 {
42 tree node;
43 struct bucket *next;
44 };
45
46 static struct bucket **table;
47
48 /* Print PREFIX and ADDR to FILE. */
49 void
50 dump_addr (FILE *file, const char *prefix, const void *addr)
51 {
52 if (flag_dump_noaddr || flag_dump_unnumbered)
53 fprintf (file, "%s#", prefix);
54 else
55 fprintf (file, "%s" HOST_PTR_PRINTF, prefix, addr);
56 }
57
58 /* Print a node in brief fashion, with just the code, address and name. */
59
60 void
61 print_node_brief (FILE *file, const char *prefix, const_tree node, int indent)
62 {
63 enum tree_code_class tclass;
64
65 if (node == 0)
66 return;
67
68 tclass = TREE_CODE_CLASS (TREE_CODE (node));
69
70 /* Always print the slot this node is in, and its code, address and
71 name if any. */
72 if (indent > 0)
73 fprintf (file, " ");
74 fprintf (file, "%s <%s", prefix, get_tree_code_name (TREE_CODE (node)));
75 dump_addr (file, " ", node);
76
77 if (tclass == tcc_declaration)
78 {
79 if (DECL_NAME (node))
80 fprintf (file, " %s", IDENTIFIER_POINTER (DECL_NAME (node)));
81 else if (TREE_CODE (node) == LABEL_DECL
82 && LABEL_DECL_UID (node) != -1)
83 {
84 if (dump_flags & TDF_NOUID)
85 fprintf (file, " L.xxxx");
86 else
87 fprintf (file, " L.%d", (int) LABEL_DECL_UID (node));
88 }
89 else
90 {
91 if (dump_flags & TDF_NOUID)
92 fprintf (file, " %c.xxxx",
93 TREE_CODE (node) == CONST_DECL ? 'C' : 'D');
94 else
95 fprintf (file, " %c.%u",
96 TREE_CODE (node) == CONST_DECL ? 'C' : 'D',
97 DECL_UID (node));
98 }
99 }
100 else if (tclass == tcc_type)
101 {
102 if (TYPE_NAME (node))
103 {
104 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
105 fprintf (file, " %s", IDENTIFIER_POINTER (TYPE_NAME (node)));
106 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
107 && DECL_NAME (TYPE_NAME (node)))
108 fprintf (file, " %s",
109 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node))));
110 }
111 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (node)))
112 fprintf (file, " address-space-%d", TYPE_ADDR_SPACE (node));
113 }
114 if (TREE_CODE (node) == IDENTIFIER_NODE)
115 fprintf (file, " %s", IDENTIFIER_POINTER (node));
116
117 /* We might as well always print the value of an integer or real. */
118 if (TREE_CODE (node) == INTEGER_CST)
119 {
120 if (TREE_OVERFLOW (node))
121 fprintf (file, " overflow");
122
123 fprintf (file, " ");
124 if (TREE_INT_CST_HIGH (node) == 0)
125 fprintf (file, HOST_WIDE_INT_PRINT_UNSIGNED, TREE_INT_CST_LOW (node));
126 else if (TREE_INT_CST_HIGH (node) == -1
127 && TREE_INT_CST_LOW (node) != 0)
128 fprintf (file, "-" HOST_WIDE_INT_PRINT_UNSIGNED,
129 -TREE_INT_CST_LOW (node));
130 else
131 fprintf (file, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
132 (unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (node),
133 (unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (node));
134 }
135 if (TREE_CODE (node) == REAL_CST)
136 {
137 REAL_VALUE_TYPE d;
138
139 if (TREE_OVERFLOW (node))
140 fprintf (file, " overflow");
141
142 d = TREE_REAL_CST (node);
143 if (REAL_VALUE_ISINF (d))
144 fprintf (file, REAL_VALUE_NEGATIVE (d) ? " -Inf" : " Inf");
145 else if (REAL_VALUE_ISNAN (d))
146 fprintf (file, " Nan");
147 else
148 {
149 char string[60];
150 real_to_decimal (string, &d, sizeof (string), 0, 1);
151 fprintf (file, " %s", string);
152 }
153 }
154 if (TREE_CODE (node) == FIXED_CST)
155 {
156 FIXED_VALUE_TYPE f;
157 char string[60];
158
159 if (TREE_OVERFLOW (node))
160 fprintf (file, " overflow");
161
162 f = TREE_FIXED_CST (node);
163 fixed_to_decimal (string, &f, sizeof (string));
164 fprintf (file, " %s", string);
165 }
166
167 fprintf (file, ">");
168 }
169
170 void
171 indent_to (FILE *file, int column)
172 {
173 int i;
174
175 /* Since this is the long way, indent to desired column. */
176 if (column > 0)
177 fprintf (file, "\n");
178 for (i = 0; i < column; i++)
179 fprintf (file, " ");
180 }
181 \f
182 /* Print the node NODE in full on file FILE, preceded by PREFIX,
183 starting in column INDENT. */
184
185 void
186 print_node (FILE *file, const char *prefix, tree node, int indent)
187 {
188 int hash;
189 struct bucket *b;
190 enum machine_mode mode;
191 enum tree_code_class tclass;
192 int len;
193 int i;
194 expanded_location xloc;
195 enum tree_code code;
196
197 if (node == 0)
198 return;
199
200 code = TREE_CODE (node);
201 tclass = TREE_CODE_CLASS (code);
202
203 /* Don't get too deep in nesting. If the user wants to see deeper,
204 it is easy to use the address of a lowest-level node
205 as an argument in another call to debug_tree. */
206
207 if (indent > 24)
208 {
209 print_node_brief (file, prefix, node, indent);
210 return;
211 }
212
213 if (indent > 8 && (tclass == tcc_type || tclass == tcc_declaration))
214 {
215 print_node_brief (file, prefix, node, indent);
216 return;
217 }
218
219 /* It is unsafe to look at any other fields of an ERROR_MARK node. */
220 if (code == ERROR_MARK)
221 {
222 print_node_brief (file, prefix, node, indent);
223 return;
224 }
225
226 /* Allow this function to be called if the table is not there. */
227 if (table)
228 {
229 hash = ((uintptr_t) node) % HASH_SIZE;
230
231 /* If node is in the table, just mention its address. */
232 for (b = table[hash]; b; b = b->next)
233 if (b->node == node)
234 {
235 print_node_brief (file, prefix, node, indent);
236 return;
237 }
238
239 /* Add this node to the table. */
240 b = XNEW (struct bucket);
241 b->node = node;
242 b->next = table[hash];
243 table[hash] = b;
244 }
245
246 /* Indent to the specified column, since this is the long form. */
247 indent_to (file, indent);
248
249 /* Print the slot this node is in, and its code, and address. */
250 fprintf (file, "%s <%s", prefix, get_tree_code_name (code));
251 dump_addr (file, " ", node);
252
253 /* Print the name, if any. */
254 if (tclass == tcc_declaration)
255 {
256 if (DECL_NAME (node))
257 fprintf (file, " %s", IDENTIFIER_POINTER (DECL_NAME (node)));
258 else if (code == LABEL_DECL
259 && LABEL_DECL_UID (node) != -1)
260 {
261 if (dump_flags & TDF_NOUID)
262 fprintf (file, " L.xxxx");
263 else
264 fprintf (file, " L.%d", (int) LABEL_DECL_UID (node));
265 }
266 else
267 {
268 if (dump_flags & TDF_NOUID)
269 fprintf (file, " %c.xxxx", code == CONST_DECL ? 'C' : 'D');
270 else
271 fprintf (file, " %c.%u", code == CONST_DECL ? 'C' : 'D',
272 DECL_UID (node));
273 }
274 }
275 else if (tclass == tcc_type)
276 {
277 if (TYPE_NAME (node))
278 {
279 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
280 fprintf (file, " %s", IDENTIFIER_POINTER (TYPE_NAME (node)));
281 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
282 && DECL_NAME (TYPE_NAME (node)))
283 fprintf (file, " %s",
284 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node))));
285 }
286 }
287 if (code == IDENTIFIER_NODE)
288 fprintf (file, " %s", IDENTIFIER_POINTER (node));
289
290 if (code == INTEGER_CST)
291 {
292 if (indent <= 4)
293 print_node_brief (file, "type", TREE_TYPE (node), indent + 4);
294 }
295 else if (CODE_CONTAINS_STRUCT (code, TS_TYPED))
296 {
297 print_node (file, "type", TREE_TYPE (node), indent + 4);
298 if (TREE_TYPE (node))
299 indent_to (file, indent + 3);
300 }
301
302 if (!TYPE_P (node) && TREE_SIDE_EFFECTS (node))
303 fputs (" side-effects", file);
304
305 if (TYPE_P (node) ? TYPE_READONLY (node) : TREE_READONLY (node))
306 fputs (" readonly", file);
307 if (!TYPE_P (node) && TREE_CONSTANT (node))
308 fputs (" constant", file);
309 else if (TYPE_P (node) && TYPE_SIZES_GIMPLIFIED (node))
310 fputs (" sizes-gimplified", file);
311
312 if (TYPE_P (node) && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (node)))
313 fprintf (file, " address-space-%d", TYPE_ADDR_SPACE (node));
314
315 if (TREE_ADDRESSABLE (node))
316 fputs (" addressable", file);
317 if (TREE_THIS_VOLATILE (node))
318 fputs (" volatile", file);
319 if (TREE_ASM_WRITTEN (node))
320 fputs (" asm_written", file);
321 if (TREE_USED (node))
322 fputs (" used", file);
323 if (TREE_NOTHROW (node))
324 fputs (TYPE_P (node) ? " align-ok" : " nothrow", file);
325 if (TREE_PUBLIC (node))
326 fputs (" public", file);
327 if (TREE_PRIVATE (node))
328 fputs (" private", file);
329 if (TREE_PROTECTED (node))
330 fputs (" protected", file);
331 if (TREE_STATIC (node))
332 fputs (" static", file);
333 if (TREE_DEPRECATED (node))
334 fputs (" deprecated", file);
335 if (TREE_VISITED (node))
336 fputs (" visited", file);
337
338 if (code != TREE_VEC && code != SSA_NAME)
339 {
340 if (TREE_LANG_FLAG_0 (node))
341 fputs (" tree_0", file);
342 if (TREE_LANG_FLAG_1 (node))
343 fputs (" tree_1", file);
344 if (TREE_LANG_FLAG_2 (node))
345 fputs (" tree_2", file);
346 if (TREE_LANG_FLAG_3 (node))
347 fputs (" tree_3", file);
348 if (TREE_LANG_FLAG_4 (node))
349 fputs (" tree_4", file);
350 if (TREE_LANG_FLAG_5 (node))
351 fputs (" tree_5", file);
352 if (TREE_LANG_FLAG_6 (node))
353 fputs (" tree_6", file);
354 }
355
356 /* DECL_ nodes have additional attributes. */
357
358 switch (TREE_CODE_CLASS (code))
359 {
360 case tcc_declaration:
361 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
362 {
363 if (DECL_UNSIGNED (node))
364 fputs (" unsigned", file);
365 if (DECL_IGNORED_P (node))
366 fputs (" ignored", file);
367 if (DECL_ABSTRACT (node))
368 fputs (" abstract", file);
369 if (DECL_EXTERNAL (node))
370 fputs (" external", file);
371 if (DECL_NONLOCAL (node))
372 fputs (" nonlocal", file);
373 }
374 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
375 {
376 if (DECL_WEAK (node))
377 fputs (" weak", file);
378 if (DECL_IN_SYSTEM_HEADER (node))
379 fputs (" in_system_header", file);
380 }
381 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WRTL)
382 && code != LABEL_DECL
383 && code != FUNCTION_DECL
384 && DECL_REGISTER (node))
385 fputs (" regdecl", file);
386
387 if (code == TYPE_DECL && TYPE_DECL_SUPPRESS_DEBUG (node))
388 fputs (" suppress-debug", file);
389
390 if (code == FUNCTION_DECL
391 && DECL_FUNCTION_SPECIFIC_TARGET (node))
392 fputs (" function-specific-target", file);
393 if (code == FUNCTION_DECL
394 && DECL_FUNCTION_SPECIFIC_OPTIMIZATION (node))
395 fputs (" function-specific-opt", file);
396 if (code == FUNCTION_DECL && DECL_DECLARED_INLINE_P (node))
397 fputs (" autoinline", file);
398 if (code == FUNCTION_DECL && DECL_BUILT_IN (node))
399 fputs (" built-in", file);
400 if (code == FUNCTION_DECL && DECL_STATIC_CHAIN (node))
401 fputs (" static-chain", file);
402 if (TREE_CODE (node) == FUNCTION_DECL && decl_is_tm_clone (node))
403 fputs (" tm-clone", file);
404
405 if (code == FIELD_DECL && DECL_PACKED (node))
406 fputs (" packed", file);
407 if (code == FIELD_DECL && DECL_BIT_FIELD (node))
408 fputs (" bit-field", file);
409 if (code == FIELD_DECL && DECL_NONADDRESSABLE_P (node))
410 fputs (" nonaddressable", file);
411
412 if (code == LABEL_DECL && EH_LANDING_PAD_NR (node))
413 fprintf (file, " landing-pad:%d", EH_LANDING_PAD_NR (node));
414
415 if (code == VAR_DECL && DECL_IN_TEXT_SECTION (node))
416 fputs (" in-text-section", file);
417 if (code == VAR_DECL && DECL_IN_CONSTANT_POOL (node))
418 fputs (" in-constant-pool", file);
419 if (code == VAR_DECL && DECL_COMMON (node))
420 fputs (" common", file);
421 if (code == VAR_DECL && DECL_THREAD_LOCAL_P (node))
422 {
423 enum tls_model kind = DECL_TLS_MODEL (node);
424 switch (kind)
425 {
426 case TLS_MODEL_GLOBAL_DYNAMIC:
427 fputs (" tls-global-dynamic", file);
428 break;
429 case TLS_MODEL_LOCAL_DYNAMIC:
430 fputs (" tls-local-dynamic", file);
431 break;
432 case TLS_MODEL_INITIAL_EXEC:
433 fputs (" tls-initial-exec", file);
434 break;
435 case TLS_MODEL_LOCAL_EXEC:
436 fputs (" tls-local-exec", file);
437 break;
438 default:
439 gcc_unreachable ();
440 }
441 }
442
443 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
444 {
445 if (DECL_VIRTUAL_P (node))
446 fputs (" virtual", file);
447 if (DECL_PRESERVE_P (node))
448 fputs (" preserve", file);
449 if (DECL_LANG_FLAG_0 (node))
450 fputs (" decl_0", file);
451 if (DECL_LANG_FLAG_1 (node))
452 fputs (" decl_1", file);
453 if (DECL_LANG_FLAG_2 (node))
454 fputs (" decl_2", file);
455 if (DECL_LANG_FLAG_3 (node))
456 fputs (" decl_3", file);
457 if (DECL_LANG_FLAG_4 (node))
458 fputs (" decl_4", file);
459 if (DECL_LANG_FLAG_5 (node))
460 fputs (" decl_5", file);
461 if (DECL_LANG_FLAG_6 (node))
462 fputs (" decl_6", file);
463 if (DECL_LANG_FLAG_7 (node))
464 fputs (" decl_7", file);
465
466 mode = DECL_MODE (node);
467 fprintf (file, " %s", GET_MODE_NAME (mode));
468 }
469
470 if ((code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
471 && DECL_BY_REFERENCE (node))
472 fputs (" passed-by-reference", file);
473
474 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS) && DECL_DEFER_OUTPUT (node))
475 fputs (" defer-output", file);
476
477
478 xloc = expand_location (DECL_SOURCE_LOCATION (node));
479 fprintf (file, " file %s line %d col %d", xloc.file, xloc.line,
480 xloc.column);
481
482 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
483 {
484 print_node (file, "size", DECL_SIZE (node), indent + 4);
485 print_node (file, "unit size", DECL_SIZE_UNIT (node), indent + 4);
486
487 if (code != FUNCTION_DECL || DECL_BUILT_IN (node))
488 indent_to (file, indent + 3);
489
490 if (DECL_USER_ALIGN (node))
491 fprintf (file, " user");
492
493 fprintf (file, " align %d", DECL_ALIGN (node));
494 if (code == FIELD_DECL)
495 fprintf (file, " offset_align " HOST_WIDE_INT_PRINT_UNSIGNED,
496 DECL_OFFSET_ALIGN (node));
497
498 if (code == FUNCTION_DECL && DECL_BUILT_IN (node))
499 {
500 if (DECL_BUILT_IN_CLASS (node) == BUILT_IN_MD)
501 fprintf (file, " built-in BUILT_IN_MD %d", DECL_FUNCTION_CODE (node));
502 else
503 fprintf (file, " built-in %s:%s",
504 built_in_class_names[(int) DECL_BUILT_IN_CLASS (node)],
505 built_in_names[(int) DECL_FUNCTION_CODE (node)]);
506 }
507 }
508 if (code == FIELD_DECL)
509 {
510 print_node (file, "offset", DECL_FIELD_OFFSET (node), indent + 4);
511 print_node (file, "bit offset", DECL_FIELD_BIT_OFFSET (node),
512 indent + 4);
513 if (DECL_BIT_FIELD_TYPE (node))
514 print_node (file, "bit_field_type", DECL_BIT_FIELD_TYPE (node),
515 indent + 4);
516 }
517
518 print_node_brief (file, "context", DECL_CONTEXT (node), indent + 4);
519
520 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
521 {
522 print_node_brief (file, "attributes",
523 DECL_ATTRIBUTES (node), indent + 4);
524 if (code != PARM_DECL)
525 print_node_brief (file, "initial", DECL_INITIAL (node),
526 indent + 4);
527 }
528 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WRTL))
529 {
530 print_node_brief (file, "abstract_origin",
531 DECL_ABSTRACT_ORIGIN (node), indent + 4);
532 }
533 if (CODE_CONTAINS_STRUCT (code, TS_DECL_NON_COMMON))
534 {
535 print_node (file, "arguments", DECL_ARGUMENT_FLD (node), indent + 4);
536 print_node (file, "result", DECL_RESULT_FLD (node), indent + 4);
537 }
538
539 lang_hooks.print_decl (file, node, indent);
540
541 if (DECL_RTL_SET_P (node))
542 {
543 indent_to (file, indent + 4);
544 print_rtl (file, DECL_RTL (node));
545 }
546
547 if (code == PARM_DECL)
548 {
549 print_node (file, "arg-type", DECL_ARG_TYPE (node), indent + 4);
550
551 if (DECL_INCOMING_RTL (node) != 0)
552 {
553 indent_to (file, indent + 4);
554 fprintf (file, "incoming-rtl ");
555 print_rtl (file, DECL_INCOMING_RTL (node));
556 }
557 }
558 else if (code == FUNCTION_DECL
559 && DECL_STRUCT_FUNCTION (node) != 0)
560 {
561 indent_to (file, indent + 4);
562 dump_addr (file, "struct-function ", DECL_STRUCT_FUNCTION (node));
563 }
564
565 if ((code == VAR_DECL || code == PARM_DECL)
566 && DECL_HAS_VALUE_EXPR_P (node))
567 print_node (file, "value-expr", DECL_VALUE_EXPR (node), indent + 4);
568
569 /* Print the decl chain only if decl is at second level. */
570 if (indent == 4)
571 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
572 else
573 print_node_brief (file, "chain", TREE_CHAIN (node), indent + 4);
574 break;
575
576 case tcc_type:
577 if (TYPE_UNSIGNED (node))
578 fputs (" unsigned", file);
579
580 /* The no-force-blk flag is used for different things in
581 different types. */
582 if ((code == RECORD_TYPE
583 || code == UNION_TYPE
584 || code == QUAL_UNION_TYPE)
585 && TYPE_NO_FORCE_BLK (node))
586 fputs (" no-force-blk", file);
587
588 if (TYPE_STRING_FLAG (node))
589 fputs (" string-flag", file);
590 if (TYPE_NEEDS_CONSTRUCTING (node))
591 fputs (" needs-constructing", file);
592
593 /* The transparent-union flag is used for different things in
594 different nodes. */
595 if ((code == UNION_TYPE || code == RECORD_TYPE)
596 && TYPE_TRANSPARENT_AGGR (node))
597 fputs (" transparent-aggr", file);
598 else if (code == ARRAY_TYPE
599 && TYPE_NONALIASED_COMPONENT (node))
600 fputs (" nonaliased-component", file);
601
602 if (TYPE_PACKED (node))
603 fputs (" packed", file);
604
605 if (TYPE_RESTRICT (node))
606 fputs (" restrict", file);
607
608 if (TYPE_LANG_FLAG_0 (node))
609 fputs (" type_0", file);
610 if (TYPE_LANG_FLAG_1 (node))
611 fputs (" type_1", file);
612 if (TYPE_LANG_FLAG_2 (node))
613 fputs (" type_2", file);
614 if (TYPE_LANG_FLAG_3 (node))
615 fputs (" type_3", file);
616 if (TYPE_LANG_FLAG_4 (node))
617 fputs (" type_4", file);
618 if (TYPE_LANG_FLAG_5 (node))
619 fputs (" type_5", file);
620 if (TYPE_LANG_FLAG_6 (node))
621 fputs (" type_6", file);
622
623 mode = TYPE_MODE (node);
624 fprintf (file, " %s", GET_MODE_NAME (mode));
625
626 print_node (file, "size", TYPE_SIZE (node), indent + 4);
627 print_node (file, "unit size", TYPE_SIZE_UNIT (node), indent + 4);
628 indent_to (file, indent + 3);
629
630 if (TYPE_USER_ALIGN (node))
631 fprintf (file, " user");
632
633 fprintf (file, " align %d symtab %d alias set " HOST_WIDE_INT_PRINT_DEC,
634 TYPE_ALIGN (node), TYPE_SYMTAB_ADDRESS (node),
635 (HOST_WIDE_INT) TYPE_ALIAS_SET (node));
636
637 if (TYPE_STRUCTURAL_EQUALITY_P (node))
638 fprintf (file, " structural equality");
639 else
640 dump_addr (file, " canonical type ", TYPE_CANONICAL (node));
641
642 print_node (file, "attributes", TYPE_ATTRIBUTES (node), indent + 4);
643
644 if (INTEGRAL_TYPE_P (node) || code == REAL_TYPE
645 || code == FIXED_POINT_TYPE)
646 {
647 fprintf (file, " precision %d", TYPE_PRECISION (node));
648 print_node_brief (file, "min", TYPE_MIN_VALUE (node), indent + 4);
649 print_node_brief (file, "max", TYPE_MAX_VALUE (node), indent + 4);
650 }
651
652 if (code == ENUMERAL_TYPE)
653 print_node (file, "values", TYPE_VALUES (node), indent + 4);
654 else if (code == ARRAY_TYPE)
655 print_node (file, "domain", TYPE_DOMAIN (node), indent + 4);
656 else if (code == VECTOR_TYPE)
657 fprintf (file, " nunits %d", (int) TYPE_VECTOR_SUBPARTS (node));
658 else if (code == RECORD_TYPE
659 || code == UNION_TYPE
660 || code == QUAL_UNION_TYPE)
661 print_node (file, "fields", TYPE_FIELDS (node), indent + 4);
662 else if (code == FUNCTION_TYPE
663 || code == METHOD_TYPE)
664 {
665 if (TYPE_METHOD_BASETYPE (node))
666 print_node_brief (file, "method basetype",
667 TYPE_METHOD_BASETYPE (node), indent + 4);
668 print_node (file, "arg-types", TYPE_ARG_TYPES (node), indent + 4);
669 }
670 else if (code == OFFSET_TYPE)
671 print_node_brief (file, "basetype", TYPE_OFFSET_BASETYPE (node),
672 indent + 4);
673
674 if (TYPE_CONTEXT (node))
675 print_node_brief (file, "context", TYPE_CONTEXT (node), indent + 4);
676
677 lang_hooks.print_type (file, node, indent);
678
679 if (TYPE_POINTER_TO (node) || TREE_CHAIN (node))
680 indent_to (file, indent + 3);
681
682 print_node_brief (file, "pointer_to_this", TYPE_POINTER_TO (node),
683 indent + 4);
684 print_node_brief (file, "reference_to_this", TYPE_REFERENCE_TO (node),
685 indent + 4);
686 print_node_brief (file, "chain", TREE_CHAIN (node), indent + 4);
687 break;
688
689 case tcc_expression:
690 case tcc_comparison:
691 case tcc_unary:
692 case tcc_binary:
693 case tcc_reference:
694 case tcc_statement:
695 case tcc_vl_exp:
696 if (code == BIND_EXPR)
697 {
698 print_node (file, "vars", TREE_OPERAND (node, 0), indent + 4);
699 print_node (file, "body", TREE_OPERAND (node, 1), indent + 4);
700 print_node (file, "block", TREE_OPERAND (node, 2), indent + 4);
701 break;
702 }
703 if (code == CALL_EXPR)
704 {
705 call_expr_arg_iterator iter;
706 tree arg;
707 print_node (file, "fn", CALL_EXPR_FN (node), indent + 4);
708 print_node (file, "static_chain", CALL_EXPR_STATIC_CHAIN (node),
709 indent + 4);
710 i = 0;
711 FOR_EACH_CALL_EXPR_ARG (arg, iter, node)
712 {
713 char temp[10];
714 sprintf (temp, "arg %d", i);
715 print_node (file, temp, arg, indent + 4);
716 i++;
717 }
718 }
719 else
720 {
721 len = TREE_OPERAND_LENGTH (node);
722
723 for (i = 0; i < len; i++)
724 {
725 char temp[10];
726
727 sprintf (temp, "arg %d", i);
728 print_node (file, temp, TREE_OPERAND (node, i), indent + 4);
729 }
730 }
731 if (CODE_CONTAINS_STRUCT (code, TS_COMMON))
732 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
733 break;
734
735 case tcc_constant:
736 case tcc_exceptional:
737 switch (code)
738 {
739 case INTEGER_CST:
740 if (TREE_OVERFLOW (node))
741 fprintf (file, " overflow");
742
743 fprintf (file, " ");
744 if (TREE_INT_CST_HIGH (node) == 0)
745 fprintf (file, HOST_WIDE_INT_PRINT_UNSIGNED,
746 TREE_INT_CST_LOW (node));
747 else if (TREE_INT_CST_HIGH (node) == -1
748 && TREE_INT_CST_LOW (node) != 0)
749 fprintf (file, "-" HOST_WIDE_INT_PRINT_UNSIGNED,
750 -TREE_INT_CST_LOW (node));
751 else
752 fprintf (file, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
753 (unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (node),
754 (unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (node));
755 break;
756
757 case REAL_CST:
758 {
759 REAL_VALUE_TYPE d;
760
761 if (TREE_OVERFLOW (node))
762 fprintf (file, " overflow");
763
764 d = TREE_REAL_CST (node);
765 if (REAL_VALUE_ISINF (d))
766 fprintf (file, REAL_VALUE_NEGATIVE (d) ? " -Inf" : " Inf");
767 else if (REAL_VALUE_ISNAN (d))
768 fprintf (file, " Nan");
769 else
770 {
771 char string[64];
772 real_to_decimal (string, &d, sizeof (string), 0, 1);
773 fprintf (file, " %s", string);
774 }
775 }
776 break;
777
778 case FIXED_CST:
779 {
780 FIXED_VALUE_TYPE f;
781 char string[64];
782
783 if (TREE_OVERFLOW (node))
784 fprintf (file, " overflow");
785
786 f = TREE_FIXED_CST (node);
787 fixed_to_decimal (string, &f, sizeof (string));
788 fprintf (file, " %s", string);
789 }
790 break;
791
792 case VECTOR_CST:
793 {
794 char buf[10];
795 unsigned i;
796
797 for (i = 0; i < VECTOR_CST_NELTS (node); ++i)
798 {
799 sprintf (buf, "elt%u: ", i);
800 print_node (file, buf, VECTOR_CST_ELT (node, i), indent + 4);
801 }
802 }
803 break;
804
805 case COMPLEX_CST:
806 print_node (file, "real", TREE_REALPART (node), indent + 4);
807 print_node (file, "imag", TREE_IMAGPART (node), indent + 4);
808 break;
809
810 case STRING_CST:
811 {
812 const char *p = TREE_STRING_POINTER (node);
813 int i = TREE_STRING_LENGTH (node);
814 fputs (" \"", file);
815 while (--i >= 0)
816 {
817 char ch = *p++;
818 if (ch >= ' ' && ch < 127)
819 putc (ch, file);
820 else
821 fprintf (file, "\\%03o", ch & 0xFF);
822 }
823 fputc ('\"', file);
824 }
825 break;
826
827 case IDENTIFIER_NODE:
828 lang_hooks.print_identifier (file, node, indent);
829 break;
830
831 case TREE_LIST:
832 print_node (file, "purpose", TREE_PURPOSE (node), indent + 4);
833 print_node (file, "value", TREE_VALUE (node), indent + 4);
834 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
835 break;
836
837 case TREE_VEC:
838 len = TREE_VEC_LENGTH (node);
839 for (i = 0; i < len; i++)
840 if (TREE_VEC_ELT (node, i))
841 {
842 char temp[10];
843 sprintf (temp, "elt %d", i);
844 print_node (file, temp, TREE_VEC_ELT (node, i), indent + 4);
845 }
846 break;
847
848 case CONSTRUCTOR:
849 {
850 unsigned HOST_WIDE_INT cnt;
851 tree index, value;
852 len = vec_safe_length (CONSTRUCTOR_ELTS (node));
853 fprintf (file, " lngt %d", len);
854 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (node),
855 cnt, index, value)
856 {
857 print_node (file, "idx", index, indent + 4);
858 print_node (file, "val", value, indent + 4);
859 }
860 }
861 break;
862
863 case STATEMENT_LIST:
864 dump_addr (file, " head ", node->stmt_list.head);
865 dump_addr (file, " tail ", node->stmt_list.tail);
866 fprintf (file, " stmts");
867 {
868 tree_stmt_iterator i;
869 for (i = tsi_start (node); !tsi_end_p (i); tsi_next (&i))
870 {
871 /* Not printing the addresses of the (not-a-tree)
872 'struct tree_stmt_list_node's. */
873 dump_addr (file, " ", tsi_stmt (i));
874 }
875 fprintf (file, "\n");
876 for (i = tsi_start (node); !tsi_end_p (i); tsi_next (&i))
877 {
878 /* Not printing the addresses of the (not-a-tree)
879 'struct tree_stmt_list_node's. */
880 print_node (file, "stmt", tsi_stmt (i), indent + 4);
881 }
882 }
883 break;
884
885 case BLOCK:
886 print_node (file, "vars", BLOCK_VARS (node), indent + 4);
887 print_node (file, "supercontext", BLOCK_SUPERCONTEXT (node),
888 indent + 4);
889 print_node (file, "subblocks", BLOCK_SUBBLOCKS (node), indent + 4);
890 print_node (file, "chain", BLOCK_CHAIN (node), indent + 4);
891 print_node (file, "abstract_origin",
892 BLOCK_ABSTRACT_ORIGIN (node), indent + 4);
893 break;
894
895 case SSA_NAME:
896 print_node_brief (file, "var", SSA_NAME_VAR (node), indent + 4);
897 fprintf (file, "def_stmt ");
898 print_gimple_stmt (file, SSA_NAME_DEF_STMT (node), indent + 4, 0);
899
900 indent_to (file, indent + 4);
901 fprintf (file, "version %u", SSA_NAME_VERSION (node));
902 if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (node))
903 fprintf (file, " in-abnormal-phi");
904 if (SSA_NAME_IN_FREE_LIST (node))
905 fprintf (file, " in-free-list");
906
907 if (SSA_NAME_PTR_INFO (node))
908 {
909 indent_to (file, indent + 3);
910 if (SSA_NAME_PTR_INFO (node))
911 dump_addr (file, " ptr-info ", SSA_NAME_PTR_INFO (node));
912 }
913 break;
914
915 case OMP_CLAUSE:
916 {
917 int i;
918 fprintf (file, " %s",
919 omp_clause_code_name[OMP_CLAUSE_CODE (node)]);
920 for (i = 0; i < omp_clause_num_ops[OMP_CLAUSE_CODE (node)]; i++)
921 {
922 indent_to (file, indent + 4);
923 fprintf (file, "op %d:", i);
924 print_node_brief (file, "", OMP_CLAUSE_OPERAND (node, i), 0);
925 }
926 }
927 break;
928
929 case OPTIMIZATION_NODE:
930 cl_optimization_print (file, indent + 4, TREE_OPTIMIZATION (node));
931 break;
932
933 case TARGET_OPTION_NODE:
934 cl_target_option_print (file, indent + 4, TREE_TARGET_OPTION (node));
935 break;
936 case IMPORTED_DECL:
937 fprintf (file, " imported declaration");
938 print_node_brief (file, "associated declaration",
939 IMPORTED_DECL_ASSOCIATED_DECL (node),
940 indent + 4);
941 break;
942
943 default:
944 if (EXCEPTIONAL_CLASS_P (node))
945 lang_hooks.print_xnode (file, node, indent);
946 break;
947 }
948
949 break;
950 }
951
952 if (EXPR_HAS_LOCATION (node))
953 {
954 expanded_location xloc = expand_location (EXPR_LOCATION (node));
955 indent_to (file, indent+4);
956 fprintf (file, "%s:%d:%d", xloc.file, xloc.line, xloc.column);
957 }
958
959 fprintf (file, ">");
960 }
961
962 /* Print the tree vector VEC in full on file FILE, preceded by PREFIX,
963 starting in column INDENT. */
964
965 void
966 print_vec_tree (FILE *file, const char *prefix, vec<tree, va_gc> *vec, int indent)
967 {
968 tree elt;
969 unsigned ix;
970
971 /* Indent to the specified column, since this is the long form. */
972 indent_to (file, indent);
973
974 /* Print the slot this node is in, and its code, and address. */
975 fprintf (file, "%s <VEC", prefix);
976 dump_addr (file, " ", vec->address ());
977
978 FOR_EACH_VEC_ELT (*vec, ix, elt)
979 {
980 char temp[10];
981 sprintf (temp, "elt %d", ix);
982 print_node (file, temp, elt, indent + 4);
983 }
984 }
985
986
987 /* Print the node NODE on standard error, for debugging.
988 Most nodes referred to by this one are printed recursively
989 down to a depth of six. */
990
991 DEBUG_FUNCTION void
992 debug_tree (tree node)
993 {
994 table = XCNEWVEC (struct bucket *, HASH_SIZE);
995 print_node (stderr, "", node, 0);
996 free (table);
997 table = 0;
998 putc ('\n', stderr);
999 }
1000
1001 DEBUG_FUNCTION void
1002 debug_raw (const tree_node &ref)
1003 {
1004 debug_tree (const_cast <tree> (&ref));
1005 }
1006
1007 DEBUG_FUNCTION void
1008 debug_raw (const tree_node *ptr)
1009 {
1010 if (ptr)
1011 debug_raw (*ptr);
1012 else
1013 fprintf (stderr, "<nil>\n");
1014 }
1015
1016 static void
1017 dump_tree_via_hooks (const tree_node *ptr, int options)
1018 {
1019 if (DECL_P (ptr))
1020 lang_hooks.print_decl (stderr, const_cast <tree_node*> (ptr), 0);
1021 else if (TYPE_P (ptr))
1022 lang_hooks.print_type (stderr, const_cast <tree_node*> (ptr), 0);
1023 else if (TREE_CODE (ptr) == IDENTIFIER_NODE)
1024 lang_hooks.print_identifier (stderr, const_cast <tree_node*> (ptr), 0);
1025 else
1026 print_generic_expr (stderr, const_cast <tree_node*> (ptr), options);
1027 fprintf (stderr, "\n");
1028 }
1029
1030 DEBUG_FUNCTION void
1031 debug (const tree_node &ref)
1032 {
1033 dump_tree_via_hooks (&ref, 0);
1034 }
1035
1036 DEBUG_FUNCTION void
1037 debug (const tree_node *ptr)
1038 {
1039 if (ptr)
1040 debug (*ptr);
1041 else
1042 fprintf (stderr, "<nil>\n");
1043 }
1044
1045 DEBUG_FUNCTION void
1046 debug_verbose (const tree_node &ref)
1047 {
1048 dump_tree_via_hooks (&ref, TDF_VERBOSE);
1049 }
1050
1051 DEBUG_FUNCTION void
1052 debug_verbose (const tree_node *ptr)
1053 {
1054 if (ptr)
1055 debug_verbose (*ptr);
1056 else
1057 fprintf (stderr, "<nil>\n");
1058 }
1059
1060 DEBUG_FUNCTION void
1061 debug_head (const tree_node &ref)
1062 {
1063 debug (ref);
1064 }
1065
1066 DEBUG_FUNCTION void
1067 debug_head (const tree_node *ptr)
1068 {
1069 if (ptr)
1070 debug_head (*ptr);
1071 else
1072 fprintf (stderr, "<nil>\n");
1073 }
1074
1075 DEBUG_FUNCTION void
1076 debug_body (const tree_node &ref)
1077 {
1078 if (TREE_CODE (&ref) == FUNCTION_DECL)
1079 dump_function_to_file (const_cast <tree_node*> (&ref), stderr, 0);
1080 else
1081 debug (ref);
1082 }
1083
1084 DEBUG_FUNCTION void
1085 debug_body (const tree_node *ptr)
1086 {
1087 if (ptr)
1088 debug_body (*ptr);
1089 else
1090 fprintf (stderr, "<nil>\n");
1091 }
1092
1093 /* Print the vector of trees VEC on standard error, for debugging.
1094 Most nodes referred to by this one are printed recursively
1095 down to a depth of six. */
1096
1097 DEBUG_FUNCTION void
1098 debug_raw (vec<tree, va_gc> &ref)
1099 {
1100 tree elt;
1101 unsigned ix;
1102
1103 /* Print the slot this node is in, and its code, and address. */
1104 fprintf (stderr, "<VEC");
1105 dump_addr (stderr, " ", ref.address ());
1106
1107 FOR_EACH_VEC_ELT (ref, ix, elt)
1108 {
1109 fprintf (stderr, "elt %d ", ix);
1110 debug_raw (elt);
1111 }
1112 }
1113
1114 DEBUG_FUNCTION void
1115 debug (vec<tree, va_gc> &ref)
1116 {
1117 tree elt;
1118 unsigned ix;
1119
1120 /* Print the slot this node is in, and its code, and address. */
1121 fprintf (stderr, "<VEC");
1122 dump_addr (stderr, " ", ref.address ());
1123
1124 FOR_EACH_VEC_ELT (ref, ix, elt)
1125 {
1126 fprintf (stderr, "elt %d ", ix);
1127 debug (elt);
1128 }
1129 }
1130
1131 DEBUG_FUNCTION void
1132 debug (vec<tree, va_gc> *ptr)
1133 {
1134 if (ptr)
1135 debug (*ptr);
1136 else
1137 fprintf (stderr, "<nil>\n");
1138 }
1139
1140 DEBUG_FUNCTION void
1141 debug_raw (vec<tree, va_gc> *ptr)
1142 {
1143 if (ptr)
1144 debug_raw (*ptr);
1145 else
1146 fprintf (stderr, "<nil>\n");
1147 }
1148
1149 DEBUG_FUNCTION void
1150 debug_vec_tree (vec<tree, va_gc> *vec)
1151 {
1152 debug_raw (vec);
1153 }