* doc/contrib.texi (Contributors): Add Ira Rosen.
[official-gcc.git] / gcc / print-tree.c
blob6b36d0294bb8ed3107a0484b74a55c8c06c13ebf
1 /* Prints out tree in human readable form - GCC
2 Copyright (C) 1990-2015 Free Software Foundation, Inc.
4 This file is part of GCC.
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.
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.
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/>. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tm.h"
25 #include "hash-set.h"
26 #include "machmode.h"
27 #include "vec.h"
28 #include "double-int.h"
29 #include "input.h"
30 #include "alias.h"
31 #include "symtab.h"
32 #include "wide-int.h"
33 #include "inchash.h"
34 #include "real.h"
35 #include "fixed-value.h"
36 #include "tree.h"
37 #include "varasm.h"
38 #include "print-rtl.h"
39 #include "stor-layout.h"
40 #include "ggc.h"
41 #include "langhooks.h"
42 #include "tree-iterator.h"
43 #include "diagnostic.h"
44 #include "gimple-pretty-print.h" /* FIXME */
45 #include "hash-map.h"
46 #include "is-a.h"
47 #include "plugin-api.h"
48 #include "hard-reg-set.h"
49 #include "input.h"
50 #include "function.h"
51 #include "ipa-ref.h"
52 #include "cgraph.h"
53 #include "tree-cfg.h"
54 #include "tree-dump.h"
55 #include "dumpfile.h"
56 #include "wide-int-print.h"
58 /* Define the hash table of nodes already seen.
59 Such nodes are not repeated; brief cross-references are used. */
61 #define HASH_SIZE 37
63 struct bucket
65 tree node;
66 struct bucket *next;
69 static struct bucket **table;
71 /* Print PREFIX and ADDR to FILE. */
72 void
73 dump_addr (FILE *file, const char *prefix, const void *addr)
75 if (flag_dump_noaddr || flag_dump_unnumbered)
76 fprintf (file, "%s#", prefix);
77 else
78 fprintf (file, "%s" HOST_PTR_PRINTF, prefix, addr);
81 /* Print a node in brief fashion, with just the code, address and name. */
83 void
84 print_node_brief (FILE *file, const char *prefix, const_tree node, int indent)
86 enum tree_code_class tclass;
88 if (node == 0)
89 return;
91 tclass = TREE_CODE_CLASS (TREE_CODE (node));
93 /* Always print the slot this node is in, and its code, address and
94 name if any. */
95 if (indent > 0)
96 fprintf (file, " ");
97 fprintf (file, "%s <%s", prefix, get_tree_code_name (TREE_CODE (node)));
98 dump_addr (file, " ", node);
100 if (tclass == tcc_declaration)
102 if (DECL_NAME (node))
103 fprintf (file, " %s", IDENTIFIER_POINTER (DECL_NAME (node)));
104 else if (TREE_CODE (node) == LABEL_DECL
105 && LABEL_DECL_UID (node) != -1)
107 if (dump_flags & TDF_NOUID)
108 fprintf (file, " L.xxxx");
109 else
110 fprintf (file, " L.%d", (int) LABEL_DECL_UID (node));
112 else
114 if (dump_flags & TDF_NOUID)
115 fprintf (file, " %c.xxxx",
116 TREE_CODE (node) == CONST_DECL ? 'C' : 'D');
117 else
118 fprintf (file, " %c.%u",
119 TREE_CODE (node) == CONST_DECL ? 'C' : 'D',
120 DECL_UID (node));
123 else if (tclass == tcc_type)
125 if (TYPE_NAME (node))
127 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
128 fprintf (file, " %s", IDENTIFIER_POINTER (TYPE_NAME (node)));
129 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
130 && DECL_NAME (TYPE_NAME (node)))
131 fprintf (file, " %s",
132 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node))));
134 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (node)))
135 fprintf (file, " address-space-%d", TYPE_ADDR_SPACE (node));
137 if (TREE_CODE (node) == IDENTIFIER_NODE)
138 fprintf (file, " %s", IDENTIFIER_POINTER (node));
140 /* We might as well always print the value of an integer or real. */
141 if (TREE_CODE (node) == INTEGER_CST)
143 if (TREE_OVERFLOW (node))
144 fprintf (file, " overflow");
146 fprintf (file, " ");
147 print_dec (node, file, TYPE_SIGN (TREE_TYPE (node)));
149 if (TREE_CODE (node) == REAL_CST)
151 REAL_VALUE_TYPE d;
153 if (TREE_OVERFLOW (node))
154 fprintf (file, " overflow");
156 d = TREE_REAL_CST (node);
157 if (REAL_VALUE_ISINF (d))
158 fprintf (file, REAL_VALUE_NEGATIVE (d) ? " -Inf" : " Inf");
159 else if (REAL_VALUE_ISNAN (d))
160 fprintf (file, " Nan");
161 else
163 char string[60];
164 real_to_decimal (string, &d, sizeof (string), 0, 1);
165 fprintf (file, " %s", string);
168 if (TREE_CODE (node) == FIXED_CST)
170 FIXED_VALUE_TYPE f;
171 char string[60];
173 if (TREE_OVERFLOW (node))
174 fprintf (file, " overflow");
176 f = TREE_FIXED_CST (node);
177 fixed_to_decimal (string, &f, sizeof (string));
178 fprintf (file, " %s", string);
181 fprintf (file, ">");
184 void
185 indent_to (FILE *file, int column)
187 int i;
189 /* Since this is the long way, indent to desired column. */
190 if (column > 0)
191 fprintf (file, "\n");
192 for (i = 0; i < column; i++)
193 fprintf (file, " ");
196 /* Print the node NODE in full on file FILE, preceded by PREFIX,
197 starting in column INDENT. */
199 void
200 print_node (FILE *file, const char *prefix, tree node, int indent)
202 int hash;
203 struct bucket *b;
204 machine_mode mode;
205 enum tree_code_class tclass;
206 int len;
207 int i;
208 expanded_location xloc;
209 enum tree_code code;
211 if (node == 0)
212 return;
214 code = TREE_CODE (node);
215 tclass = TREE_CODE_CLASS (code);
217 /* Don't get too deep in nesting. If the user wants to see deeper,
218 it is easy to use the address of a lowest-level node
219 as an argument in another call to debug_tree. */
221 if (indent > 24)
223 print_node_brief (file, prefix, node, indent);
224 return;
227 if (indent > 8 && (tclass == tcc_type || tclass == tcc_declaration))
229 print_node_brief (file, prefix, node, indent);
230 return;
233 /* It is unsafe to look at any other fields of an ERROR_MARK node. */
234 if (code == ERROR_MARK)
236 print_node_brief (file, prefix, node, indent);
237 return;
240 /* Allow this function to be called if the table is not there. */
241 if (table)
243 hash = ((uintptr_t) node) % HASH_SIZE;
245 /* If node is in the table, just mention its address. */
246 for (b = table[hash]; b; b = b->next)
247 if (b->node == node)
249 print_node_brief (file, prefix, node, indent);
250 return;
253 /* Add this node to the table. */
254 b = XNEW (struct bucket);
255 b->node = node;
256 b->next = table[hash];
257 table[hash] = b;
260 /* Indent to the specified column, since this is the long form. */
261 indent_to (file, indent);
263 /* Print the slot this node is in, and its code, and address. */
264 fprintf (file, "%s <%s", prefix, get_tree_code_name (code));
265 dump_addr (file, " ", node);
267 /* Print the name, if any. */
268 if (tclass == tcc_declaration)
270 if (DECL_NAME (node))
271 fprintf (file, " %s", IDENTIFIER_POINTER (DECL_NAME (node)));
272 else if (code == LABEL_DECL
273 && LABEL_DECL_UID (node) != -1)
275 if (dump_flags & TDF_NOUID)
276 fprintf (file, " L.xxxx");
277 else
278 fprintf (file, " L.%d", (int) LABEL_DECL_UID (node));
280 else
282 if (dump_flags & TDF_NOUID)
283 fprintf (file, " %c.xxxx", code == CONST_DECL ? 'C' : 'D');
284 else
285 fprintf (file, " %c.%u", code == CONST_DECL ? 'C' : 'D',
286 DECL_UID (node));
289 else if (tclass == tcc_type)
291 if (TYPE_NAME (node))
293 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
294 fprintf (file, " %s", IDENTIFIER_POINTER (TYPE_NAME (node)));
295 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
296 && DECL_NAME (TYPE_NAME (node)))
297 fprintf (file, " %s",
298 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node))));
301 if (code == IDENTIFIER_NODE)
302 fprintf (file, " %s", IDENTIFIER_POINTER (node));
304 if (code == INTEGER_CST)
306 if (indent <= 4)
307 print_node_brief (file, "type", TREE_TYPE (node), indent + 4);
309 else if (CODE_CONTAINS_STRUCT (code, TS_TYPED))
311 print_node (file, "type", TREE_TYPE (node), indent + 4);
312 if (TREE_TYPE (node))
313 indent_to (file, indent + 3);
316 if (!TYPE_P (node) && TREE_SIDE_EFFECTS (node))
317 fputs (" side-effects", file);
319 if (TYPE_P (node) ? TYPE_READONLY (node) : TREE_READONLY (node))
320 fputs (" readonly", file);
321 if (TYPE_P (node) && TYPE_ATOMIC (node))
322 fputs (" atomic", file);
323 if (!TYPE_P (node) && TREE_CONSTANT (node))
324 fputs (" constant", file);
325 else if (TYPE_P (node) && TYPE_SIZES_GIMPLIFIED (node))
326 fputs (" sizes-gimplified", file);
328 if (TYPE_P (node) && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (node)))
329 fprintf (file, " address-space-%d", TYPE_ADDR_SPACE (node));
331 if (TREE_ADDRESSABLE (node))
332 fputs (" addressable", file);
333 if (TREE_THIS_VOLATILE (node))
334 fputs (" volatile", file);
335 if (TREE_ASM_WRITTEN (node))
336 fputs (" asm_written", file);
337 if (TREE_USED (node))
338 fputs (" used", file);
339 if (TREE_NOTHROW (node))
340 fputs (TYPE_P (node) ? " align-ok" : " nothrow", file);
341 if (TREE_PUBLIC (node))
342 fputs (" public", file);
343 if (TREE_PRIVATE (node))
344 fputs (" private", file);
345 if (TREE_PROTECTED (node))
346 fputs (" protected", file);
347 if (TREE_STATIC (node))
348 fputs (" static", file);
349 if (TREE_DEPRECATED (node))
350 fputs (" deprecated", file);
351 if (TREE_VISITED (node))
352 fputs (" visited", file);
354 if (code != TREE_VEC && code != INTEGER_CST && code != SSA_NAME)
356 if (TREE_LANG_FLAG_0 (node))
357 fputs (" tree_0", file);
358 if (TREE_LANG_FLAG_1 (node))
359 fputs (" tree_1", file);
360 if (TREE_LANG_FLAG_2 (node))
361 fputs (" tree_2", file);
362 if (TREE_LANG_FLAG_3 (node))
363 fputs (" tree_3", file);
364 if (TREE_LANG_FLAG_4 (node))
365 fputs (" tree_4", file);
366 if (TREE_LANG_FLAG_5 (node))
367 fputs (" tree_5", file);
368 if (TREE_LANG_FLAG_6 (node))
369 fputs (" tree_6", file);
372 /* DECL_ nodes have additional attributes. */
374 switch (TREE_CODE_CLASS (code))
376 case tcc_declaration:
377 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
379 if (DECL_UNSIGNED (node))
380 fputs (" unsigned", file);
381 if (DECL_IGNORED_P (node))
382 fputs (" ignored", file);
383 if (DECL_ABSTRACT_P (node))
384 fputs (" abstract", file);
385 if (DECL_EXTERNAL (node))
386 fputs (" external", file);
387 if (DECL_NONLOCAL (node))
388 fputs (" nonlocal", file);
390 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
392 if (DECL_WEAK (node))
393 fputs (" weak", file);
394 if (DECL_IN_SYSTEM_HEADER (node))
395 fputs (" in_system_header", file);
397 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WRTL)
398 && code != LABEL_DECL
399 && code != FUNCTION_DECL
400 && DECL_REGISTER (node))
401 fputs (" regdecl", file);
403 if (code == TYPE_DECL && TYPE_DECL_SUPPRESS_DEBUG (node))
404 fputs (" suppress-debug", file);
406 if (code == FUNCTION_DECL
407 && DECL_FUNCTION_SPECIFIC_TARGET (node))
408 fputs (" function-specific-target", file);
409 if (code == FUNCTION_DECL
410 && DECL_FUNCTION_SPECIFIC_OPTIMIZATION (node))
411 fputs (" function-specific-opt", file);
412 if (code == FUNCTION_DECL && DECL_DECLARED_INLINE_P (node))
413 fputs (" autoinline", file);
414 if (code == FUNCTION_DECL && DECL_BUILT_IN (node))
415 fputs (" built-in", file);
416 if (code == FUNCTION_DECL && DECL_STATIC_CHAIN (node))
417 fputs (" static-chain", file);
418 if (TREE_CODE (node) == FUNCTION_DECL && decl_is_tm_clone (node))
419 fputs (" tm-clone", file);
421 if (code == FIELD_DECL && DECL_PACKED (node))
422 fputs (" packed", file);
423 if (code == FIELD_DECL && DECL_BIT_FIELD (node))
424 fputs (" bit-field", file);
425 if (code == FIELD_DECL && DECL_NONADDRESSABLE_P (node))
426 fputs (" nonaddressable", file);
428 if (code == LABEL_DECL && EH_LANDING_PAD_NR (node))
429 fprintf (file, " landing-pad:%d", EH_LANDING_PAD_NR (node));
431 if (code == VAR_DECL && DECL_IN_TEXT_SECTION (node))
432 fputs (" in-text-section", file);
433 if (code == VAR_DECL && DECL_IN_CONSTANT_POOL (node))
434 fputs (" in-constant-pool", file);
435 if (code == VAR_DECL && DECL_COMMON (node))
436 fputs (" common", file);
437 if (code == VAR_DECL && DECL_THREAD_LOCAL_P (node))
439 fputs (" ", file);
440 fputs (tls_model_names[DECL_TLS_MODEL (node)], file);
443 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
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);
466 mode = DECL_MODE (node);
467 fprintf (file, " %s", GET_MODE_NAME (mode));
470 if ((code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
471 && DECL_BY_REFERENCE (node))
472 fputs (" passed-by-reference", file);
474 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS) && DECL_DEFER_OUTPUT (node))
475 fputs (" defer-output", file);
478 xloc = expand_location (DECL_SOURCE_LOCATION (node));
479 fprintf (file, " file %s line %d col %d", xloc.file, xloc.line,
480 xloc.column);
482 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
484 print_node (file, "size", DECL_SIZE (node), indent + 4);
485 print_node (file, "unit size", DECL_SIZE_UNIT (node), indent + 4);
487 if (code != FUNCTION_DECL || DECL_BUILT_IN (node))
488 indent_to (file, indent + 3);
490 if (DECL_USER_ALIGN (node))
491 fprintf (file, " user");
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));
498 if (code == FUNCTION_DECL && DECL_BUILT_IN (node))
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)]);
508 if (code == FIELD_DECL)
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);
518 print_node_brief (file, "context", DECL_CONTEXT (node), indent + 4);
520 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
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);
528 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WRTL))
530 print_node_brief (file, "abstract_origin",
531 DECL_ABSTRACT_ORIGIN (node), indent + 4);
533 if (CODE_CONTAINS_STRUCT (code, TS_DECL_NON_COMMON))
535 print_node (file, "result", DECL_RESULT_FLD (node), indent + 4);
538 lang_hooks.print_decl (file, node, indent);
540 if (DECL_RTL_SET_P (node))
542 indent_to (file, indent + 4);
543 print_rtl (file, DECL_RTL (node));
546 if (code == PARM_DECL)
548 print_node (file, "arg-type", DECL_ARG_TYPE (node), indent + 4);
550 if (DECL_INCOMING_RTL (node) != 0)
552 indent_to (file, indent + 4);
553 fprintf (file, "incoming-rtl ");
554 print_rtl (file, DECL_INCOMING_RTL (node));
557 else if (code == FUNCTION_DECL
558 && DECL_STRUCT_FUNCTION (node) != 0)
560 print_node (file, "arguments", DECL_ARGUMENTS (node), indent + 4);
561 indent_to (file, indent + 4);
562 dump_addr (file, "struct-function ", DECL_STRUCT_FUNCTION (node));
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);
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;
576 case tcc_type:
577 if (TYPE_UNSIGNED (node))
578 fputs (" unsigned", file);
580 if (TYPE_NO_FORCE_BLK (node))
581 fputs (" no-force-blk", file);
583 if (TYPE_STRING_FLAG (node))
584 fputs (" string-flag", file);
586 if (TYPE_NEEDS_CONSTRUCTING (node))
587 fputs (" needs-constructing", file);
589 /* The transparent-union flag is used for different things in
590 different nodes. */
591 if ((code == UNION_TYPE || code == RECORD_TYPE)
592 && TYPE_TRANSPARENT_AGGR (node))
593 fputs (" transparent-aggr", file);
594 else if (code == ARRAY_TYPE
595 && TYPE_NONALIASED_COMPONENT (node))
596 fputs (" nonaliased-component", file);
598 if (TYPE_PACKED (node))
599 fputs (" packed", file);
601 if (TYPE_RESTRICT (node))
602 fputs (" restrict", file);
604 if (TYPE_LANG_FLAG_0 (node))
605 fputs (" type_0", file);
606 if (TYPE_LANG_FLAG_1 (node))
607 fputs (" type_1", file);
608 if (TYPE_LANG_FLAG_2 (node))
609 fputs (" type_2", file);
610 if (TYPE_LANG_FLAG_3 (node))
611 fputs (" type_3", file);
612 if (TYPE_LANG_FLAG_4 (node))
613 fputs (" type_4", file);
614 if (TYPE_LANG_FLAG_5 (node))
615 fputs (" type_5", file);
616 if (TYPE_LANG_FLAG_6 (node))
617 fputs (" type_6", file);
619 mode = TYPE_MODE (node);
620 fprintf (file, " %s", GET_MODE_NAME (mode));
622 print_node (file, "size", TYPE_SIZE (node), indent + 4);
623 print_node (file, "unit size", TYPE_SIZE_UNIT (node), indent + 4);
624 indent_to (file, indent + 3);
626 if (TYPE_USER_ALIGN (node))
627 fprintf (file, " user");
629 fprintf (file, " align %d symtab %d alias set " HOST_WIDE_INT_PRINT_DEC,
630 TYPE_ALIGN (node), TYPE_SYMTAB_ADDRESS (node),
631 (HOST_WIDE_INT) TYPE_ALIAS_SET (node));
633 if (TYPE_STRUCTURAL_EQUALITY_P (node))
634 fprintf (file, " structural equality");
635 else
636 dump_addr (file, " canonical type ", TYPE_CANONICAL (node));
638 print_node (file, "attributes", TYPE_ATTRIBUTES (node), indent + 4);
640 if (INTEGRAL_TYPE_P (node) || code == REAL_TYPE
641 || code == FIXED_POINT_TYPE)
643 fprintf (file, " precision %d", TYPE_PRECISION (node));
644 print_node_brief (file, "min", TYPE_MIN_VALUE (node), indent + 4);
645 print_node_brief (file, "max", TYPE_MAX_VALUE (node), indent + 4);
648 if (code == ENUMERAL_TYPE)
649 print_node (file, "values", TYPE_VALUES (node), indent + 4);
650 else if (code == ARRAY_TYPE)
651 print_node (file, "domain", TYPE_DOMAIN (node), indent + 4);
652 else if (code == VECTOR_TYPE)
653 fprintf (file, " nunits %d", (int) TYPE_VECTOR_SUBPARTS (node));
654 else if (code == RECORD_TYPE
655 || code == UNION_TYPE
656 || code == QUAL_UNION_TYPE)
657 print_node (file, "fields", TYPE_FIELDS (node), indent + 4);
658 else if (code == FUNCTION_TYPE
659 || code == METHOD_TYPE)
661 if (TYPE_METHOD_BASETYPE (node))
662 print_node_brief (file, "method basetype",
663 TYPE_METHOD_BASETYPE (node), indent + 4);
664 print_node (file, "arg-types", TYPE_ARG_TYPES (node), indent + 4);
666 else if (code == OFFSET_TYPE)
667 print_node_brief (file, "basetype", TYPE_OFFSET_BASETYPE (node),
668 indent + 4);
670 if (TYPE_CONTEXT (node))
671 print_node_brief (file, "context", TYPE_CONTEXT (node), indent + 4);
673 lang_hooks.print_type (file, node, indent);
675 if (TYPE_POINTER_TO (node) || TREE_CHAIN (node))
676 indent_to (file, indent + 3);
678 print_node_brief (file, "pointer_to_this", TYPE_POINTER_TO (node),
679 indent + 4);
680 print_node_brief (file, "reference_to_this", TYPE_REFERENCE_TO (node),
681 indent + 4);
682 print_node_brief (file, "chain", TREE_CHAIN (node), indent + 4);
683 break;
685 case tcc_expression:
686 case tcc_comparison:
687 case tcc_unary:
688 case tcc_binary:
689 case tcc_reference:
690 case tcc_statement:
691 case tcc_vl_exp:
692 if (code == BIND_EXPR)
694 print_node (file, "vars", TREE_OPERAND (node, 0), indent + 4);
695 print_node (file, "body", TREE_OPERAND (node, 1), indent + 4);
696 print_node (file, "block", TREE_OPERAND (node, 2), indent + 4);
697 break;
699 if (code == CALL_EXPR)
701 call_expr_arg_iterator iter;
702 tree arg;
703 print_node (file, "fn", CALL_EXPR_FN (node), indent + 4);
704 print_node (file, "static_chain", CALL_EXPR_STATIC_CHAIN (node),
705 indent + 4);
706 i = 0;
707 FOR_EACH_CALL_EXPR_ARG (arg, iter, node)
709 char temp[10];
710 sprintf (temp, "arg %d", i);
711 print_node (file, temp, arg, indent + 4);
712 i++;
715 else
717 len = TREE_OPERAND_LENGTH (node);
719 for (i = 0; i < len; i++)
721 char temp[10];
723 sprintf (temp, "arg %d", i);
724 print_node (file, temp, TREE_OPERAND (node, i), indent + 4);
727 if (CODE_CONTAINS_STRUCT (code, TS_COMMON))
728 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
729 break;
731 case tcc_constant:
732 case tcc_exceptional:
733 switch (code)
735 case INTEGER_CST:
736 if (TREE_OVERFLOW (node))
737 fprintf (file, " overflow");
739 fprintf (file, " ");
740 print_dec (node, file, TYPE_SIGN (TREE_TYPE (node)));
741 break;
743 case REAL_CST:
745 REAL_VALUE_TYPE d;
747 if (TREE_OVERFLOW (node))
748 fprintf (file, " overflow");
750 d = TREE_REAL_CST (node);
751 if (REAL_VALUE_ISINF (d))
752 fprintf (file, REAL_VALUE_NEGATIVE (d) ? " -Inf" : " Inf");
753 else if (REAL_VALUE_ISNAN (d))
754 fprintf (file, " Nan");
755 else
757 char string[64];
758 real_to_decimal (string, &d, sizeof (string), 0, 1);
759 fprintf (file, " %s", string);
762 break;
764 case FIXED_CST:
766 FIXED_VALUE_TYPE f;
767 char string[64];
769 if (TREE_OVERFLOW (node))
770 fprintf (file, " overflow");
772 f = TREE_FIXED_CST (node);
773 fixed_to_decimal (string, &f, sizeof (string));
774 fprintf (file, " %s", string);
776 break;
778 case VECTOR_CST:
780 char buf[10];
781 unsigned i;
783 for (i = 0; i < VECTOR_CST_NELTS (node); ++i)
785 sprintf (buf, "elt%u: ", i);
786 print_node (file, buf, VECTOR_CST_ELT (node, i), indent + 4);
789 break;
791 case COMPLEX_CST:
792 print_node (file, "real", TREE_REALPART (node), indent + 4);
793 print_node (file, "imag", TREE_IMAGPART (node), indent + 4);
794 break;
796 case STRING_CST:
798 const char *p = TREE_STRING_POINTER (node);
799 int i = TREE_STRING_LENGTH (node);
800 fputs (" \"", file);
801 while (--i >= 0)
803 char ch = *p++;
804 if (ch >= ' ' && ch < 127)
805 putc (ch, file);
806 else
807 fprintf (file, "\\%03o", ch & 0xFF);
809 fputc ('\"', file);
811 break;
813 case IDENTIFIER_NODE:
814 lang_hooks.print_identifier (file, node, indent);
815 break;
817 case TREE_LIST:
818 print_node (file, "purpose", TREE_PURPOSE (node), indent + 4);
819 print_node (file, "value", TREE_VALUE (node), indent + 4);
820 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
821 break;
823 case TREE_VEC:
824 len = TREE_VEC_LENGTH (node);
825 for (i = 0; i < len; i++)
826 if (TREE_VEC_ELT (node, i))
828 char temp[10];
829 sprintf (temp, "elt %d", i);
830 print_node (file, temp, TREE_VEC_ELT (node, i), indent + 4);
832 break;
834 case CONSTRUCTOR:
836 unsigned HOST_WIDE_INT cnt;
837 tree index, value;
838 len = vec_safe_length (CONSTRUCTOR_ELTS (node));
839 fprintf (file, " lngt %d", len);
840 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (node),
841 cnt, index, value)
843 print_node (file, "idx", index, indent + 4);
844 print_node (file, "val", value, indent + 4);
847 break;
849 case STATEMENT_LIST:
850 dump_addr (file, " head ", node->stmt_list.head);
851 dump_addr (file, " tail ", node->stmt_list.tail);
852 fprintf (file, " stmts");
854 tree_stmt_iterator i;
855 for (i = tsi_start (node); !tsi_end_p (i); tsi_next (&i))
857 /* Not printing the addresses of the (not-a-tree)
858 'struct tree_stmt_list_node's. */
859 dump_addr (file, " ", tsi_stmt (i));
861 fprintf (file, "\n");
862 for (i = tsi_start (node); !tsi_end_p (i); tsi_next (&i))
864 /* Not printing the addresses of the (not-a-tree)
865 'struct tree_stmt_list_node's. */
866 print_node (file, "stmt", tsi_stmt (i), indent + 4);
869 break;
871 case BLOCK:
872 print_node (file, "vars", BLOCK_VARS (node), indent + 4);
873 print_node (file, "supercontext", BLOCK_SUPERCONTEXT (node),
874 indent + 4);
875 print_node (file, "subblocks", BLOCK_SUBBLOCKS (node), indent + 4);
876 print_node (file, "chain", BLOCK_CHAIN (node), indent + 4);
877 print_node (file, "abstract_origin",
878 BLOCK_ABSTRACT_ORIGIN (node), indent + 4);
879 break;
881 case SSA_NAME:
882 print_node_brief (file, "var", SSA_NAME_VAR (node), indent + 4);
883 fprintf (file, "def_stmt ");
884 print_gimple_stmt (file, SSA_NAME_DEF_STMT (node), indent + 4, 0);
886 indent_to (file, indent + 4);
887 fprintf (file, "version %u", SSA_NAME_VERSION (node));
888 if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (node))
889 fprintf (file, " in-abnormal-phi");
890 if (SSA_NAME_IN_FREE_LIST (node))
891 fprintf (file, " in-free-list");
893 if (SSA_NAME_PTR_INFO (node))
895 indent_to (file, indent + 3);
896 if (SSA_NAME_PTR_INFO (node))
897 dump_addr (file, " ptr-info ", SSA_NAME_PTR_INFO (node));
899 break;
901 case OMP_CLAUSE:
903 int i;
904 fprintf (file, " %s",
905 omp_clause_code_name[OMP_CLAUSE_CODE (node)]);
906 for (i = 0; i < omp_clause_num_ops[OMP_CLAUSE_CODE (node)]; i++)
908 indent_to (file, indent + 4);
909 fprintf (file, "op %d:", i);
910 print_node_brief (file, "", OMP_CLAUSE_OPERAND (node, i), 0);
913 break;
915 case OPTIMIZATION_NODE:
916 cl_optimization_print (file, indent + 4, TREE_OPTIMIZATION (node));
917 break;
919 case TARGET_OPTION_NODE:
920 cl_target_option_print (file, indent + 4, TREE_TARGET_OPTION (node));
921 break;
922 case IMPORTED_DECL:
923 fprintf (file, " imported declaration");
924 print_node_brief (file, "associated declaration",
925 IMPORTED_DECL_ASSOCIATED_DECL (node),
926 indent + 4);
927 break;
929 default:
930 if (EXCEPTIONAL_CLASS_P (node))
931 lang_hooks.print_xnode (file, node, indent);
932 break;
935 break;
938 if (EXPR_HAS_LOCATION (node))
940 expanded_location xloc = expand_location (EXPR_LOCATION (node));
941 indent_to (file, indent+4);
942 fprintf (file, "%s:%d:%d", xloc.file, xloc.line, xloc.column);
945 fprintf (file, ">");
949 /* Print the node NODE on standard error, for debugging.
950 Most nodes referred to by this one are printed recursively
951 down to a depth of six. */
953 DEBUG_FUNCTION void
954 debug_tree (tree node)
956 table = XCNEWVEC (struct bucket *, HASH_SIZE);
957 print_node (stderr, "", node, 0);
958 free (table);
959 table = 0;
960 putc ('\n', stderr);
963 DEBUG_FUNCTION void
964 debug_raw (const tree_node &ref)
966 debug_tree (const_cast <tree> (&ref));
969 DEBUG_FUNCTION void
970 debug_raw (const tree_node *ptr)
972 if (ptr)
973 debug_raw (*ptr);
974 else
975 fprintf (stderr, "<nil>\n");
978 static void
979 dump_tree_via_hooks (const tree_node *ptr, int options)
981 if (DECL_P (ptr))
982 lang_hooks.print_decl (stderr, const_cast <tree_node*> (ptr), 0);
983 else if (TYPE_P (ptr))
984 lang_hooks.print_type (stderr, const_cast <tree_node*> (ptr), 0);
985 else if (TREE_CODE (ptr) == IDENTIFIER_NODE)
986 lang_hooks.print_identifier (stderr, const_cast <tree_node*> (ptr), 0);
987 else
988 print_generic_expr (stderr, const_cast <tree_node*> (ptr), options);
989 fprintf (stderr, "\n");
992 DEBUG_FUNCTION void
993 debug (const tree_node &ref)
995 dump_tree_via_hooks (&ref, 0);
998 DEBUG_FUNCTION void
999 debug (const tree_node *ptr)
1001 if (ptr)
1002 debug (*ptr);
1003 else
1004 fprintf (stderr, "<nil>\n");
1007 DEBUG_FUNCTION void
1008 debug_verbose (const tree_node &ref)
1010 dump_tree_via_hooks (&ref, TDF_VERBOSE);
1013 DEBUG_FUNCTION void
1014 debug_verbose (const tree_node *ptr)
1016 if (ptr)
1017 debug_verbose (*ptr);
1018 else
1019 fprintf (stderr, "<nil>\n");
1022 DEBUG_FUNCTION void
1023 debug_head (const tree_node &ref)
1025 debug (ref);
1028 DEBUG_FUNCTION void
1029 debug_head (const tree_node *ptr)
1031 if (ptr)
1032 debug_head (*ptr);
1033 else
1034 fprintf (stderr, "<nil>\n");
1037 DEBUG_FUNCTION void
1038 debug_body (const tree_node &ref)
1040 if (TREE_CODE (&ref) == FUNCTION_DECL)
1041 dump_function_to_file (const_cast <tree_node*> (&ref), stderr, 0);
1042 else
1043 debug (ref);
1046 DEBUG_FUNCTION void
1047 debug_body (const tree_node *ptr)
1049 if (ptr)
1050 debug_body (*ptr);
1051 else
1052 fprintf (stderr, "<nil>\n");
1055 /* Print the vector of trees VEC on standard error, for debugging.
1056 Most nodes referred to by this one are printed recursively
1057 down to a depth of six. */
1059 DEBUG_FUNCTION void
1060 debug_raw (vec<tree, va_gc> &ref)
1062 tree elt;
1063 unsigned ix;
1065 /* Print the slot this node is in, and its code, and address. */
1066 fprintf (stderr, "<VEC");
1067 dump_addr (stderr, " ", ref.address ());
1069 FOR_EACH_VEC_ELT (ref, ix, elt)
1071 fprintf (stderr, "elt %d ", ix);
1072 debug_raw (elt);
1076 DEBUG_FUNCTION void
1077 debug (vec<tree, va_gc> &ref)
1079 tree elt;
1080 unsigned ix;
1082 /* Print the slot this node is in, and its code, and address. */
1083 fprintf (stderr, "<VEC");
1084 dump_addr (stderr, " ", ref.address ());
1086 FOR_EACH_VEC_ELT (ref, ix, elt)
1088 fprintf (stderr, "elt %d ", ix);
1089 debug (elt);
1093 DEBUG_FUNCTION void
1094 debug (vec<tree, va_gc> *ptr)
1096 if (ptr)
1097 debug (*ptr);
1098 else
1099 fprintf (stderr, "<nil>\n");
1102 DEBUG_FUNCTION void
1103 debug_raw (vec<tree, va_gc> *ptr)
1105 if (ptr)
1106 debug_raw (*ptr);
1107 else
1108 fprintf (stderr, "<nil>\n");
1111 DEBUG_FUNCTION void
1112 debug_vec_tree (vec<tree, va_gc> *vec)
1114 debug_raw (vec);