gcc/
[official-gcc.git] / gcc / print-tree.c
bloba3a64bb390f2ceb7b845a127a63e8339c4409492
1 /* Prints out tree in human readable form - GCC
2 Copyright (C) 1990-2014 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 "tree.h"
26 #include "varasm.h"
27 #include "print-rtl.h"
28 #include "stor-layout.h"
29 #include "ggc.h"
30 #include "langhooks.h"
31 #include "tree-iterator.h"
32 #include "diagnostic.h"
33 #include "gimple-pretty-print.h" /* FIXME */
34 #include "hash-map.h"
35 #include "is-a.h"
36 #include "plugin-api.h"
37 #include "vec.h"
38 #include "hashtab.h"
39 #include "hash-set.h"
40 #include "machmode.h"
41 #include "hard-reg-set.h"
42 #include "input.h"
43 #include "function.h"
44 #include "ipa-ref.h"
45 #include "cgraph.h"
46 #include "tree-cfg.h"
47 #include "tree-dump.h"
48 #include "dumpfile.h"
49 #include "wide-int-print.h"
51 /* Define the hash table of nodes already seen.
52 Such nodes are not repeated; brief cross-references are used. */
54 #define HASH_SIZE 37
56 struct bucket
58 tree node;
59 struct bucket *next;
62 static struct bucket **table;
64 /* Print PREFIX and ADDR to FILE. */
65 void
66 dump_addr (FILE *file, const char *prefix, const void *addr)
68 if (flag_dump_noaddr || flag_dump_unnumbered)
69 fprintf (file, "%s#", prefix);
70 else
71 fprintf (file, "%s" HOST_PTR_PRINTF, prefix, addr);
74 /* Print a node in brief fashion, with just the code, address and name. */
76 void
77 print_node_brief (FILE *file, const char *prefix, const_tree node, int indent)
79 enum tree_code_class tclass;
81 if (node == 0)
82 return;
84 tclass = TREE_CODE_CLASS (TREE_CODE (node));
86 /* Always print the slot this node is in, and its code, address and
87 name if any. */
88 if (indent > 0)
89 fprintf (file, " ");
90 fprintf (file, "%s <%s", prefix, get_tree_code_name (TREE_CODE (node)));
91 dump_addr (file, " ", node);
93 if (tclass == tcc_declaration)
95 if (DECL_NAME (node))
96 fprintf (file, " %s", IDENTIFIER_POINTER (DECL_NAME (node)));
97 else if (TREE_CODE (node) == LABEL_DECL
98 && LABEL_DECL_UID (node) != -1)
100 if (dump_flags & TDF_NOUID)
101 fprintf (file, " L.xxxx");
102 else
103 fprintf (file, " L.%d", (int) LABEL_DECL_UID (node));
105 else
107 if (dump_flags & TDF_NOUID)
108 fprintf (file, " %c.xxxx",
109 TREE_CODE (node) == CONST_DECL ? 'C' : 'D');
110 else
111 fprintf (file, " %c.%u",
112 TREE_CODE (node) == CONST_DECL ? 'C' : 'D',
113 DECL_UID (node));
116 else if (tclass == tcc_type)
118 if (TYPE_NAME (node))
120 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
121 fprintf (file, " %s", IDENTIFIER_POINTER (TYPE_NAME (node)));
122 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
123 && DECL_NAME (TYPE_NAME (node)))
124 fprintf (file, " %s",
125 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node))));
127 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (node)))
128 fprintf (file, " address-space-%d", TYPE_ADDR_SPACE (node));
130 if (TREE_CODE (node) == IDENTIFIER_NODE)
131 fprintf (file, " %s", IDENTIFIER_POINTER (node));
133 /* We might as well always print the value of an integer or real. */
134 if (TREE_CODE (node) == INTEGER_CST)
136 if (TREE_OVERFLOW (node))
137 fprintf (file, " overflow");
139 fprintf (file, " ");
140 print_dec (node, file, TYPE_SIGN (TREE_TYPE (node)));
142 if (TREE_CODE (node) == REAL_CST)
144 REAL_VALUE_TYPE d;
146 if (TREE_OVERFLOW (node))
147 fprintf (file, " overflow");
149 d = TREE_REAL_CST (node);
150 if (REAL_VALUE_ISINF (d))
151 fprintf (file, REAL_VALUE_NEGATIVE (d) ? " -Inf" : " Inf");
152 else if (REAL_VALUE_ISNAN (d))
153 fprintf (file, " Nan");
154 else
156 char string[60];
157 real_to_decimal (string, &d, sizeof (string), 0, 1);
158 fprintf (file, " %s", string);
161 if (TREE_CODE (node) == FIXED_CST)
163 FIXED_VALUE_TYPE f;
164 char string[60];
166 if (TREE_OVERFLOW (node))
167 fprintf (file, " overflow");
169 f = TREE_FIXED_CST (node);
170 fixed_to_decimal (string, &f, sizeof (string));
171 fprintf (file, " %s", string);
174 fprintf (file, ">");
177 void
178 indent_to (FILE *file, int column)
180 int i;
182 /* Since this is the long way, indent to desired column. */
183 if (column > 0)
184 fprintf (file, "\n");
185 for (i = 0; i < column; i++)
186 fprintf (file, " ");
189 /* Print the node NODE in full on file FILE, preceded by PREFIX,
190 starting in column INDENT. */
192 void
193 print_node (FILE *file, const char *prefix, tree node, int indent)
195 int hash;
196 struct bucket *b;
197 machine_mode mode;
198 enum tree_code_class tclass;
199 int len;
200 int i;
201 expanded_location xloc;
202 enum tree_code code;
204 if (node == 0)
205 return;
207 code = TREE_CODE (node);
208 tclass = TREE_CODE_CLASS (code);
210 /* Don't get too deep in nesting. If the user wants to see deeper,
211 it is easy to use the address of a lowest-level node
212 as an argument in another call to debug_tree. */
214 if (indent > 24)
216 print_node_brief (file, prefix, node, indent);
217 return;
220 if (indent > 8 && (tclass == tcc_type || tclass == tcc_declaration))
222 print_node_brief (file, prefix, node, indent);
223 return;
226 /* It is unsafe to look at any other fields of an ERROR_MARK node. */
227 if (code == ERROR_MARK)
229 print_node_brief (file, prefix, node, indent);
230 return;
233 /* Allow this function to be called if the table is not there. */
234 if (table)
236 hash = ((uintptr_t) node) % HASH_SIZE;
238 /* If node is in the table, just mention its address. */
239 for (b = table[hash]; b; b = b->next)
240 if (b->node == node)
242 print_node_brief (file, prefix, node, indent);
243 return;
246 /* Add this node to the table. */
247 b = XNEW (struct bucket);
248 b->node = node;
249 b->next = table[hash];
250 table[hash] = b;
253 /* Indent to the specified column, since this is the long form. */
254 indent_to (file, indent);
256 /* Print the slot this node is in, and its code, and address. */
257 fprintf (file, "%s <%s", prefix, get_tree_code_name (code));
258 dump_addr (file, " ", node);
260 /* Print the name, if any. */
261 if (tclass == tcc_declaration)
263 if (DECL_NAME (node))
264 fprintf (file, " %s", IDENTIFIER_POINTER (DECL_NAME (node)));
265 else if (code == LABEL_DECL
266 && LABEL_DECL_UID (node) != -1)
268 if (dump_flags & TDF_NOUID)
269 fprintf (file, " L.xxxx");
270 else
271 fprintf (file, " L.%d", (int) LABEL_DECL_UID (node));
273 else
275 if (dump_flags & TDF_NOUID)
276 fprintf (file, " %c.xxxx", code == CONST_DECL ? 'C' : 'D');
277 else
278 fprintf (file, " %c.%u", code == CONST_DECL ? 'C' : 'D',
279 DECL_UID (node));
282 else if (tclass == tcc_type)
284 if (TYPE_NAME (node))
286 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
287 fprintf (file, " %s", IDENTIFIER_POINTER (TYPE_NAME (node)));
288 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
289 && DECL_NAME (TYPE_NAME (node)))
290 fprintf (file, " %s",
291 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node))));
294 if (code == IDENTIFIER_NODE)
295 fprintf (file, " %s", IDENTIFIER_POINTER (node));
297 if (code == INTEGER_CST)
299 if (indent <= 4)
300 print_node_brief (file, "type", TREE_TYPE (node), indent + 4);
302 else if (CODE_CONTAINS_STRUCT (code, TS_TYPED))
304 print_node (file, "type", TREE_TYPE (node), indent + 4);
305 if (TREE_TYPE (node))
306 indent_to (file, indent + 3);
309 if (!TYPE_P (node) && TREE_SIDE_EFFECTS (node))
310 fputs (" side-effects", file);
312 if (TYPE_P (node) ? TYPE_READONLY (node) : TREE_READONLY (node))
313 fputs (" readonly", file);
314 if (TYPE_P (node) && TYPE_ATOMIC (node))
315 fputs (" atomic", file);
316 if (!TYPE_P (node) && TREE_CONSTANT (node))
317 fputs (" constant", file);
318 else if (TYPE_P (node) && TYPE_SIZES_GIMPLIFIED (node))
319 fputs (" sizes-gimplified", file);
321 if (TYPE_P (node) && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (node)))
322 fprintf (file, " address-space-%d", TYPE_ADDR_SPACE (node));
324 if (TREE_ADDRESSABLE (node))
325 fputs (" addressable", file);
326 if (TREE_THIS_VOLATILE (node))
327 fputs (" volatile", file);
328 if (TREE_ASM_WRITTEN (node))
329 fputs (" asm_written", file);
330 if (TREE_USED (node))
331 fputs (" used", file);
332 if (TREE_NOTHROW (node))
333 fputs (TYPE_P (node) ? " align-ok" : " nothrow", file);
334 if (TREE_PUBLIC (node))
335 fputs (" public", file);
336 if (TREE_PRIVATE (node))
337 fputs (" private", file);
338 if (TREE_PROTECTED (node))
339 fputs (" protected", file);
340 if (TREE_STATIC (node))
341 fputs (" static", file);
342 if (TREE_DEPRECATED (node))
343 fputs (" deprecated", file);
344 if (TREE_VISITED (node))
345 fputs (" visited", file);
347 if (code != TREE_VEC && code != INTEGER_CST && code != SSA_NAME)
349 if (TREE_LANG_FLAG_0 (node))
350 fputs (" tree_0", file);
351 if (TREE_LANG_FLAG_1 (node))
352 fputs (" tree_1", file);
353 if (TREE_LANG_FLAG_2 (node))
354 fputs (" tree_2", file);
355 if (TREE_LANG_FLAG_3 (node))
356 fputs (" tree_3", file);
357 if (TREE_LANG_FLAG_4 (node))
358 fputs (" tree_4", file);
359 if (TREE_LANG_FLAG_5 (node))
360 fputs (" tree_5", file);
361 if (TREE_LANG_FLAG_6 (node))
362 fputs (" tree_6", file);
365 /* DECL_ nodes have additional attributes. */
367 switch (TREE_CODE_CLASS (code))
369 case tcc_declaration:
370 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
372 if (DECL_UNSIGNED (node))
373 fputs (" unsigned", file);
374 if (DECL_IGNORED_P (node))
375 fputs (" ignored", file);
376 if (DECL_ABSTRACT_P (node))
377 fputs (" abstract", file);
378 if (DECL_EXTERNAL (node))
379 fputs (" external", file);
380 if (DECL_NONLOCAL (node))
381 fputs (" nonlocal", file);
383 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
385 if (DECL_WEAK (node))
386 fputs (" weak", file);
387 if (DECL_IN_SYSTEM_HEADER (node))
388 fputs (" in_system_header", file);
390 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WRTL)
391 && code != LABEL_DECL
392 && code != FUNCTION_DECL
393 && DECL_REGISTER (node))
394 fputs (" regdecl", file);
396 if (code == TYPE_DECL && TYPE_DECL_SUPPRESS_DEBUG (node))
397 fputs (" suppress-debug", file);
399 if (code == FUNCTION_DECL
400 && DECL_FUNCTION_SPECIFIC_TARGET (node))
401 fputs (" function-specific-target", file);
402 if (code == FUNCTION_DECL
403 && DECL_FUNCTION_SPECIFIC_OPTIMIZATION (node))
404 fputs (" function-specific-opt", file);
405 if (code == FUNCTION_DECL && DECL_DECLARED_INLINE_P (node))
406 fputs (" autoinline", file);
407 if (code == FUNCTION_DECL && DECL_BUILT_IN (node))
408 fputs (" built-in", file);
409 if (code == FUNCTION_DECL && DECL_STATIC_CHAIN (node))
410 fputs (" static-chain", file);
411 if (TREE_CODE (node) == FUNCTION_DECL && decl_is_tm_clone (node))
412 fputs (" tm-clone", file);
414 if (code == FIELD_DECL && DECL_PACKED (node))
415 fputs (" packed", file);
416 if (code == FIELD_DECL && DECL_BIT_FIELD (node))
417 fputs (" bit-field", file);
418 if (code == FIELD_DECL && DECL_NONADDRESSABLE_P (node))
419 fputs (" nonaddressable", file);
421 if (code == LABEL_DECL && EH_LANDING_PAD_NR (node))
422 fprintf (file, " landing-pad:%d", EH_LANDING_PAD_NR (node));
424 if (code == VAR_DECL && DECL_IN_TEXT_SECTION (node))
425 fputs (" in-text-section", file);
426 if (code == VAR_DECL && DECL_IN_CONSTANT_POOL (node))
427 fputs (" in-constant-pool", file);
428 if (code == VAR_DECL && DECL_COMMON (node))
429 fputs (" common", file);
430 if (code == VAR_DECL && DECL_THREAD_LOCAL_P (node))
432 fputs (" ", file);
433 fputs (tls_model_names[DECL_TLS_MODEL (node)], file);
436 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
438 if (DECL_VIRTUAL_P (node))
439 fputs (" virtual", file);
440 if (DECL_PRESERVE_P (node))
441 fputs (" preserve", file);
442 if (DECL_LANG_FLAG_0 (node))
443 fputs (" decl_0", file);
444 if (DECL_LANG_FLAG_1 (node))
445 fputs (" decl_1", file);
446 if (DECL_LANG_FLAG_2 (node))
447 fputs (" decl_2", file);
448 if (DECL_LANG_FLAG_3 (node))
449 fputs (" decl_3", file);
450 if (DECL_LANG_FLAG_4 (node))
451 fputs (" decl_4", file);
452 if (DECL_LANG_FLAG_5 (node))
453 fputs (" decl_5", file);
454 if (DECL_LANG_FLAG_6 (node))
455 fputs (" decl_6", file);
456 if (DECL_LANG_FLAG_7 (node))
457 fputs (" decl_7", file);
459 mode = DECL_MODE (node);
460 fprintf (file, " %s", GET_MODE_NAME (mode));
463 if ((code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
464 && DECL_BY_REFERENCE (node))
465 fputs (" passed-by-reference", file);
467 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS) && DECL_DEFER_OUTPUT (node))
468 fputs (" defer-output", file);
471 xloc = expand_location (DECL_SOURCE_LOCATION (node));
472 fprintf (file, " file %s line %d col %d", xloc.file, xloc.line,
473 xloc.column);
475 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
477 print_node (file, "size", DECL_SIZE (node), indent + 4);
478 print_node (file, "unit size", DECL_SIZE_UNIT (node), indent + 4);
480 if (code != FUNCTION_DECL || DECL_BUILT_IN (node))
481 indent_to (file, indent + 3);
483 if (DECL_USER_ALIGN (node))
484 fprintf (file, " user");
486 fprintf (file, " align %d", DECL_ALIGN (node));
487 if (code == FIELD_DECL)
488 fprintf (file, " offset_align " HOST_WIDE_INT_PRINT_UNSIGNED,
489 DECL_OFFSET_ALIGN (node));
491 if (code == FUNCTION_DECL && DECL_BUILT_IN (node))
493 if (DECL_BUILT_IN_CLASS (node) == BUILT_IN_MD)
494 fprintf (file, " built-in BUILT_IN_MD %d", DECL_FUNCTION_CODE (node));
495 else
496 fprintf (file, " built-in %s:%s",
497 built_in_class_names[(int) DECL_BUILT_IN_CLASS (node)],
498 built_in_names[(int) DECL_FUNCTION_CODE (node)]);
501 if (code == FIELD_DECL)
503 print_node (file, "offset", DECL_FIELD_OFFSET (node), indent + 4);
504 print_node (file, "bit offset", DECL_FIELD_BIT_OFFSET (node),
505 indent + 4);
506 if (DECL_BIT_FIELD_TYPE (node))
507 print_node (file, "bit_field_type", DECL_BIT_FIELD_TYPE (node),
508 indent + 4);
511 print_node_brief (file, "context", DECL_CONTEXT (node), indent + 4);
513 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
515 print_node_brief (file, "attributes",
516 DECL_ATTRIBUTES (node), indent + 4);
517 if (code != PARM_DECL)
518 print_node_brief (file, "initial", DECL_INITIAL (node),
519 indent + 4);
521 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WRTL))
523 print_node_brief (file, "abstract_origin",
524 DECL_ABSTRACT_ORIGIN (node), indent + 4);
526 if (CODE_CONTAINS_STRUCT (code, TS_DECL_NON_COMMON))
528 print_node (file, "result", DECL_RESULT_FLD (node), indent + 4);
531 lang_hooks.print_decl (file, node, indent);
533 if (DECL_RTL_SET_P (node))
535 indent_to (file, indent + 4);
536 print_rtl (file, DECL_RTL (node));
539 if (code == PARM_DECL)
541 print_node (file, "arg-type", DECL_ARG_TYPE (node), indent + 4);
543 if (DECL_INCOMING_RTL (node) != 0)
545 indent_to (file, indent + 4);
546 fprintf (file, "incoming-rtl ");
547 print_rtl (file, DECL_INCOMING_RTL (node));
550 else if (code == FUNCTION_DECL
551 && DECL_STRUCT_FUNCTION (node) != 0)
553 print_node (file, "arguments", DECL_ARGUMENTS (node), indent + 4);
554 indent_to (file, indent + 4);
555 dump_addr (file, "struct-function ", DECL_STRUCT_FUNCTION (node));
558 if ((code == VAR_DECL || code == PARM_DECL)
559 && DECL_HAS_VALUE_EXPR_P (node))
560 print_node (file, "value-expr", DECL_VALUE_EXPR (node), indent + 4);
562 /* Print the decl chain only if decl is at second level. */
563 if (indent == 4)
564 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
565 else
566 print_node_brief (file, "chain", TREE_CHAIN (node), indent + 4);
567 break;
569 case tcc_type:
570 if (TYPE_UNSIGNED (node))
571 fputs (" unsigned", file);
573 if (TYPE_NO_FORCE_BLK (node))
574 fputs (" no-force-blk", file);
576 if (TYPE_STRING_FLAG (node))
577 fputs (" string-flag", file);
579 if (TYPE_NEEDS_CONSTRUCTING (node))
580 fputs (" needs-constructing", file);
582 /* The transparent-union flag is used for different things in
583 different nodes. */
584 if ((code == UNION_TYPE || code == RECORD_TYPE)
585 && TYPE_TRANSPARENT_AGGR (node))
586 fputs (" transparent-aggr", file);
587 else if (code == ARRAY_TYPE
588 && TYPE_NONALIASED_COMPONENT (node))
589 fputs (" nonaliased-component", file);
591 if (TYPE_PACKED (node))
592 fputs (" packed", file);
594 if (TYPE_RESTRICT (node))
595 fputs (" restrict", file);
597 if (TYPE_LANG_FLAG_0 (node))
598 fputs (" type_0", file);
599 if (TYPE_LANG_FLAG_1 (node))
600 fputs (" type_1", file);
601 if (TYPE_LANG_FLAG_2 (node))
602 fputs (" type_2", file);
603 if (TYPE_LANG_FLAG_3 (node))
604 fputs (" type_3", file);
605 if (TYPE_LANG_FLAG_4 (node))
606 fputs (" type_4", file);
607 if (TYPE_LANG_FLAG_5 (node))
608 fputs (" type_5", file);
609 if (TYPE_LANG_FLAG_6 (node))
610 fputs (" type_6", file);
612 mode = TYPE_MODE (node);
613 fprintf (file, " %s", GET_MODE_NAME (mode));
615 print_node (file, "size", TYPE_SIZE (node), indent + 4);
616 print_node (file, "unit size", TYPE_SIZE_UNIT (node), indent + 4);
617 indent_to (file, indent + 3);
619 if (TYPE_USER_ALIGN (node))
620 fprintf (file, " user");
622 fprintf (file, " align %d symtab %d alias set " HOST_WIDE_INT_PRINT_DEC,
623 TYPE_ALIGN (node), TYPE_SYMTAB_ADDRESS (node),
624 (HOST_WIDE_INT) TYPE_ALIAS_SET (node));
626 if (TYPE_STRUCTURAL_EQUALITY_P (node))
627 fprintf (file, " structural equality");
628 else
629 dump_addr (file, " canonical type ", TYPE_CANONICAL (node));
631 print_node (file, "attributes", TYPE_ATTRIBUTES (node), indent + 4);
633 if (INTEGRAL_TYPE_P (node) || code == REAL_TYPE
634 || code == FIXED_POINT_TYPE)
636 fprintf (file, " precision %d", TYPE_PRECISION (node));
637 print_node_brief (file, "min", TYPE_MIN_VALUE (node), indent + 4);
638 print_node_brief (file, "max", TYPE_MAX_VALUE (node), indent + 4);
641 if (code == ENUMERAL_TYPE)
642 print_node (file, "values", TYPE_VALUES (node), indent + 4);
643 else if (code == ARRAY_TYPE)
644 print_node (file, "domain", TYPE_DOMAIN (node), indent + 4);
645 else if (code == VECTOR_TYPE)
646 fprintf (file, " nunits %d", (int) TYPE_VECTOR_SUBPARTS (node));
647 else if (code == RECORD_TYPE
648 || code == UNION_TYPE
649 || code == QUAL_UNION_TYPE)
650 print_node (file, "fields", TYPE_FIELDS (node), indent + 4);
651 else if (code == FUNCTION_TYPE
652 || code == METHOD_TYPE)
654 if (TYPE_METHOD_BASETYPE (node))
655 print_node_brief (file, "method basetype",
656 TYPE_METHOD_BASETYPE (node), indent + 4);
657 print_node (file, "arg-types", TYPE_ARG_TYPES (node), indent + 4);
659 else if (code == OFFSET_TYPE)
660 print_node_brief (file, "basetype", TYPE_OFFSET_BASETYPE (node),
661 indent + 4);
663 if (TYPE_CONTEXT (node))
664 print_node_brief (file, "context", TYPE_CONTEXT (node), indent + 4);
666 lang_hooks.print_type (file, node, indent);
668 if (TYPE_POINTER_TO (node) || TREE_CHAIN (node))
669 indent_to (file, indent + 3);
671 print_node_brief (file, "pointer_to_this", TYPE_POINTER_TO (node),
672 indent + 4);
673 print_node_brief (file, "reference_to_this", TYPE_REFERENCE_TO (node),
674 indent + 4);
675 print_node_brief (file, "chain", TREE_CHAIN (node), indent + 4);
676 break;
678 case tcc_expression:
679 case tcc_comparison:
680 case tcc_unary:
681 case tcc_binary:
682 case tcc_reference:
683 case tcc_statement:
684 case tcc_vl_exp:
685 if (code == BIND_EXPR)
687 print_node (file, "vars", TREE_OPERAND (node, 0), indent + 4);
688 print_node (file, "body", TREE_OPERAND (node, 1), indent + 4);
689 print_node (file, "block", TREE_OPERAND (node, 2), indent + 4);
690 break;
692 if (code == CALL_EXPR)
694 call_expr_arg_iterator iter;
695 tree arg;
696 print_node (file, "fn", CALL_EXPR_FN (node), indent + 4);
697 print_node (file, "static_chain", CALL_EXPR_STATIC_CHAIN (node),
698 indent + 4);
699 i = 0;
700 FOR_EACH_CALL_EXPR_ARG (arg, iter, node)
702 char temp[10];
703 sprintf (temp, "arg %d", i);
704 print_node (file, temp, arg, indent + 4);
705 i++;
708 else
710 len = TREE_OPERAND_LENGTH (node);
712 for (i = 0; i < len; i++)
714 char temp[10];
716 sprintf (temp, "arg %d", i);
717 print_node (file, temp, TREE_OPERAND (node, i), indent + 4);
720 if (CODE_CONTAINS_STRUCT (code, TS_COMMON))
721 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
722 break;
724 case tcc_constant:
725 case tcc_exceptional:
726 switch (code)
728 case INTEGER_CST:
729 if (TREE_OVERFLOW (node))
730 fprintf (file, " overflow");
732 fprintf (file, " ");
733 print_dec (node, file, TYPE_SIGN (TREE_TYPE (node)));
734 break;
736 case REAL_CST:
738 REAL_VALUE_TYPE d;
740 if (TREE_OVERFLOW (node))
741 fprintf (file, " overflow");
743 d = TREE_REAL_CST (node);
744 if (REAL_VALUE_ISINF (d))
745 fprintf (file, REAL_VALUE_NEGATIVE (d) ? " -Inf" : " Inf");
746 else if (REAL_VALUE_ISNAN (d))
747 fprintf (file, " Nan");
748 else
750 char string[64];
751 real_to_decimal (string, &d, sizeof (string), 0, 1);
752 fprintf (file, " %s", string);
755 break;
757 case FIXED_CST:
759 FIXED_VALUE_TYPE f;
760 char string[64];
762 if (TREE_OVERFLOW (node))
763 fprintf (file, " overflow");
765 f = TREE_FIXED_CST (node);
766 fixed_to_decimal (string, &f, sizeof (string));
767 fprintf (file, " %s", string);
769 break;
771 case VECTOR_CST:
773 char buf[10];
774 unsigned i;
776 for (i = 0; i < VECTOR_CST_NELTS (node); ++i)
778 sprintf (buf, "elt%u: ", i);
779 print_node (file, buf, VECTOR_CST_ELT (node, i), indent + 4);
782 break;
784 case COMPLEX_CST:
785 print_node (file, "real", TREE_REALPART (node), indent + 4);
786 print_node (file, "imag", TREE_IMAGPART (node), indent + 4);
787 break;
789 case STRING_CST:
791 const char *p = TREE_STRING_POINTER (node);
792 int i = TREE_STRING_LENGTH (node);
793 fputs (" \"", file);
794 while (--i >= 0)
796 char ch = *p++;
797 if (ch >= ' ' && ch < 127)
798 putc (ch, file);
799 else
800 fprintf (file, "\\%03o", ch & 0xFF);
802 fputc ('\"', file);
804 break;
806 case IDENTIFIER_NODE:
807 lang_hooks.print_identifier (file, node, indent);
808 break;
810 case TREE_LIST:
811 print_node (file, "purpose", TREE_PURPOSE (node), indent + 4);
812 print_node (file, "value", TREE_VALUE (node), indent + 4);
813 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
814 break;
816 case TREE_VEC:
817 len = TREE_VEC_LENGTH (node);
818 for (i = 0; i < len; i++)
819 if (TREE_VEC_ELT (node, i))
821 char temp[10];
822 sprintf (temp, "elt %d", i);
823 print_node (file, temp, TREE_VEC_ELT (node, i), indent + 4);
825 break;
827 case CONSTRUCTOR:
829 unsigned HOST_WIDE_INT cnt;
830 tree index, value;
831 len = vec_safe_length (CONSTRUCTOR_ELTS (node));
832 fprintf (file, " lngt %d", len);
833 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (node),
834 cnt, index, value)
836 print_node (file, "idx", index, indent + 4);
837 print_node (file, "val", value, indent + 4);
840 break;
842 case STATEMENT_LIST:
843 dump_addr (file, " head ", node->stmt_list.head);
844 dump_addr (file, " tail ", node->stmt_list.tail);
845 fprintf (file, " stmts");
847 tree_stmt_iterator i;
848 for (i = tsi_start (node); !tsi_end_p (i); tsi_next (&i))
850 /* Not printing the addresses of the (not-a-tree)
851 'struct tree_stmt_list_node's. */
852 dump_addr (file, " ", tsi_stmt (i));
854 fprintf (file, "\n");
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 print_node (file, "stmt", tsi_stmt (i), indent + 4);
862 break;
864 case BLOCK:
865 print_node (file, "vars", BLOCK_VARS (node), indent + 4);
866 print_node (file, "supercontext", BLOCK_SUPERCONTEXT (node),
867 indent + 4);
868 print_node (file, "subblocks", BLOCK_SUBBLOCKS (node), indent + 4);
869 print_node (file, "chain", BLOCK_CHAIN (node), indent + 4);
870 print_node (file, "abstract_origin",
871 BLOCK_ABSTRACT_ORIGIN (node), indent + 4);
872 break;
874 case SSA_NAME:
875 print_node_brief (file, "var", SSA_NAME_VAR (node), indent + 4);
876 fprintf (file, "def_stmt ");
877 print_gimple_stmt (file, SSA_NAME_DEF_STMT (node), indent + 4, 0);
879 indent_to (file, indent + 4);
880 fprintf (file, "version %u", SSA_NAME_VERSION (node));
881 if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (node))
882 fprintf (file, " in-abnormal-phi");
883 if (SSA_NAME_IN_FREE_LIST (node))
884 fprintf (file, " in-free-list");
886 if (SSA_NAME_PTR_INFO (node))
888 indent_to (file, indent + 3);
889 if (SSA_NAME_PTR_INFO (node))
890 dump_addr (file, " ptr-info ", SSA_NAME_PTR_INFO (node));
892 break;
894 case OMP_CLAUSE:
896 int i;
897 fprintf (file, " %s",
898 omp_clause_code_name[OMP_CLAUSE_CODE (node)]);
899 for (i = 0; i < omp_clause_num_ops[OMP_CLAUSE_CODE (node)]; i++)
901 indent_to (file, indent + 4);
902 fprintf (file, "op %d:", i);
903 print_node_brief (file, "", OMP_CLAUSE_OPERAND (node, i), 0);
906 break;
908 case OPTIMIZATION_NODE:
909 cl_optimization_print (file, indent + 4, TREE_OPTIMIZATION (node));
910 break;
912 case TARGET_OPTION_NODE:
913 cl_target_option_print (file, indent + 4, TREE_TARGET_OPTION (node));
914 break;
915 case IMPORTED_DECL:
916 fprintf (file, " imported declaration");
917 print_node_brief (file, "associated declaration",
918 IMPORTED_DECL_ASSOCIATED_DECL (node),
919 indent + 4);
920 break;
922 default:
923 if (EXCEPTIONAL_CLASS_P (node))
924 lang_hooks.print_xnode (file, node, indent);
925 break;
928 break;
931 if (EXPR_HAS_LOCATION (node))
933 expanded_location xloc = expand_location (EXPR_LOCATION (node));
934 indent_to (file, indent+4);
935 fprintf (file, "%s:%d:%d", xloc.file, xloc.line, xloc.column);
938 fprintf (file, ">");
942 /* Print the node NODE on standard error, for debugging.
943 Most nodes referred to by this one are printed recursively
944 down to a depth of six. */
946 DEBUG_FUNCTION void
947 debug_tree (tree node)
949 table = XCNEWVEC (struct bucket *, HASH_SIZE);
950 print_node (stderr, "", node, 0);
951 free (table);
952 table = 0;
953 putc ('\n', stderr);
956 DEBUG_FUNCTION void
957 debug_raw (const tree_node &ref)
959 debug_tree (const_cast <tree> (&ref));
962 DEBUG_FUNCTION void
963 debug_raw (const tree_node *ptr)
965 if (ptr)
966 debug_raw (*ptr);
967 else
968 fprintf (stderr, "<nil>\n");
971 static void
972 dump_tree_via_hooks (const tree_node *ptr, int options)
974 if (DECL_P (ptr))
975 lang_hooks.print_decl (stderr, const_cast <tree_node*> (ptr), 0);
976 else if (TYPE_P (ptr))
977 lang_hooks.print_type (stderr, const_cast <tree_node*> (ptr), 0);
978 else if (TREE_CODE (ptr) == IDENTIFIER_NODE)
979 lang_hooks.print_identifier (stderr, const_cast <tree_node*> (ptr), 0);
980 else
981 print_generic_expr (stderr, const_cast <tree_node*> (ptr), options);
982 fprintf (stderr, "\n");
985 DEBUG_FUNCTION void
986 debug (const tree_node &ref)
988 dump_tree_via_hooks (&ref, 0);
991 DEBUG_FUNCTION void
992 debug (const tree_node *ptr)
994 if (ptr)
995 debug (*ptr);
996 else
997 fprintf (stderr, "<nil>\n");
1000 DEBUG_FUNCTION void
1001 debug_verbose (const tree_node &ref)
1003 dump_tree_via_hooks (&ref, TDF_VERBOSE);
1006 DEBUG_FUNCTION void
1007 debug_verbose (const tree_node *ptr)
1009 if (ptr)
1010 debug_verbose (*ptr);
1011 else
1012 fprintf (stderr, "<nil>\n");
1015 DEBUG_FUNCTION void
1016 debug_head (const tree_node &ref)
1018 debug (ref);
1021 DEBUG_FUNCTION void
1022 debug_head (const tree_node *ptr)
1024 if (ptr)
1025 debug_head (*ptr);
1026 else
1027 fprintf (stderr, "<nil>\n");
1030 DEBUG_FUNCTION void
1031 debug_body (const tree_node &ref)
1033 if (TREE_CODE (&ref) == FUNCTION_DECL)
1034 dump_function_to_file (const_cast <tree_node*> (&ref), stderr, 0);
1035 else
1036 debug (ref);
1039 DEBUG_FUNCTION void
1040 debug_body (const tree_node *ptr)
1042 if (ptr)
1043 debug_body (*ptr);
1044 else
1045 fprintf (stderr, "<nil>\n");
1048 /* Print the vector of trees VEC on standard error, for debugging.
1049 Most nodes referred to by this one are printed recursively
1050 down to a depth of six. */
1052 DEBUG_FUNCTION void
1053 debug_raw (vec<tree, va_gc> &ref)
1055 tree elt;
1056 unsigned ix;
1058 /* Print the slot this node is in, and its code, and address. */
1059 fprintf (stderr, "<VEC");
1060 dump_addr (stderr, " ", ref.address ());
1062 FOR_EACH_VEC_ELT (ref, ix, elt)
1064 fprintf (stderr, "elt %d ", ix);
1065 debug_raw (elt);
1069 DEBUG_FUNCTION void
1070 debug (vec<tree, va_gc> &ref)
1072 tree elt;
1073 unsigned ix;
1075 /* Print the slot this node is in, and its code, and address. */
1076 fprintf (stderr, "<VEC");
1077 dump_addr (stderr, " ", ref.address ());
1079 FOR_EACH_VEC_ELT (ref, ix, elt)
1081 fprintf (stderr, "elt %d ", ix);
1082 debug (elt);
1086 DEBUG_FUNCTION void
1087 debug (vec<tree, va_gc> *ptr)
1089 if (ptr)
1090 debug (*ptr);
1091 else
1092 fprintf (stderr, "<nil>\n");
1095 DEBUG_FUNCTION void
1096 debug_raw (vec<tree, va_gc> *ptr)
1098 if (ptr)
1099 debug_raw (*ptr);
1100 else
1101 fprintf (stderr, "<nil>\n");
1104 DEBUG_FUNCTION void
1105 debug_vec_tree (vec<tree, va_gc> *vec)
1107 debug_raw (vec);