PR middle-end/81657
[official-gcc.git] / gcc / print-tree.c
blobcaf5f2601475cdbf653fa2f129a9fec8c5e1c0e5
1 /* Prints out tree in human readable form - GCC
2 Copyright (C) 1990-2018 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 "cgraph.h"
27 #include "diagnostic.h"
28 #include "varasm.h"
29 #include "print-rtl.h"
30 #include "stor-layout.h"
31 #include "langhooks.h"
32 #include "tree-iterator.h"
33 #include "gimple-pretty-print.h" /* FIXME */
34 #include "tree-cfg.h"
35 #include "dumpfile.h"
36 #include "print-tree.h"
38 /* Define the hash table of nodes already seen.
39 Such nodes are not repeated; brief cross-references are used. */
41 #define HASH_SIZE 37
43 static hash_set<tree> *table = NULL;
45 /* Print PREFIX and ADDR to FILE. */
46 void
47 dump_addr (FILE *file, const char *prefix, const void *addr)
49 if (flag_dump_noaddr || flag_dump_unnumbered)
50 fprintf (file, "%s#", prefix);
51 else
52 fprintf (file, "%s" HOST_PTR_PRINTF, prefix, addr);
55 /* Print a node in brief fashion, with just the code, address and name. */
57 void
58 print_node_brief (FILE *file, const char *prefix, const_tree node, int indent)
60 enum tree_code_class tclass;
62 if (node == 0)
63 return;
65 tclass = TREE_CODE_CLASS (TREE_CODE (node));
67 /* Always print the slot this node is in, and its code, address and
68 name if any. */
69 if (indent > 0)
70 fprintf (file, " ");
71 fprintf (file, "%s <%s", prefix, get_tree_code_name (TREE_CODE (node)));
72 dump_addr (file, " ", node);
74 if (tclass == tcc_declaration)
76 if (DECL_NAME (node))
77 fprintf (file, " %s", IDENTIFIER_POINTER (DECL_NAME (node)));
78 else if (TREE_CODE (node) == LABEL_DECL
79 && LABEL_DECL_UID (node) != -1)
81 if (dump_flags & TDF_NOUID)
82 fprintf (file, " L.xxxx");
83 else
84 fprintf (file, " L.%d", (int) LABEL_DECL_UID (node));
86 else
88 if (dump_flags & TDF_NOUID)
89 fprintf (file, " %c.xxxx",
90 TREE_CODE (node) == CONST_DECL ? 'C' : 'D');
91 else
92 fprintf (file, " %c.%u",
93 TREE_CODE (node) == CONST_DECL ? 'C' : 'D',
94 DECL_UID (node));
97 else if (tclass == tcc_type)
99 if (TYPE_NAME (node))
101 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
102 fprintf (file, " %s", IDENTIFIER_POINTER (TYPE_NAME (node)));
103 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
104 && DECL_NAME (TYPE_NAME (node)))
105 fprintf (file, " %s",
106 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node))));
108 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (node)))
109 fprintf (file, " address-space-%d", TYPE_ADDR_SPACE (node));
111 if (TREE_CODE (node) == IDENTIFIER_NODE)
112 fprintf (file, " %s", IDENTIFIER_POINTER (node));
114 /* We might as well always print the value of an integer or real. */
115 if (TREE_CODE (node) == INTEGER_CST)
117 if (TREE_OVERFLOW (node))
118 fprintf (file, " overflow");
120 fprintf (file, " ");
121 print_dec (wi::to_wide (node), file, TYPE_SIGN (TREE_TYPE (node)));
123 if (TREE_CODE (node) == REAL_CST)
125 REAL_VALUE_TYPE d;
127 if (TREE_OVERFLOW (node))
128 fprintf (file, " overflow");
130 d = TREE_REAL_CST (node);
131 if (REAL_VALUE_ISINF (d))
132 fprintf (file, REAL_VALUE_NEGATIVE (d) ? " -Inf" : " Inf");
133 else if (REAL_VALUE_ISNAN (d))
134 fprintf (file, " Nan");
135 else
137 char string[60];
138 real_to_decimal (string, &d, sizeof (string), 0, 1);
139 fprintf (file, " %s", string);
142 if (TREE_CODE (node) == FIXED_CST)
144 FIXED_VALUE_TYPE f;
145 char string[60];
147 if (TREE_OVERFLOW (node))
148 fprintf (file, " overflow");
150 f = TREE_FIXED_CST (node);
151 fixed_to_decimal (string, &f, sizeof (string));
152 fprintf (file, " %s", string);
155 fprintf (file, ">");
158 void
159 indent_to (FILE *file, int column)
161 int i;
163 /* Since this is the long way, indent to desired column. */
164 if (column > 0)
165 fprintf (file, "\n");
166 for (i = 0; i < column; i++)
167 fprintf (file, " ");
170 /* Print the node NODE in full on file FILE, preceded by PREFIX,
171 starting in column INDENT. */
173 void
174 print_node (FILE *file, const char *prefix, tree node, int indent,
175 bool brief_for_visited)
177 machine_mode mode;
178 enum tree_code_class tclass;
179 int len;
180 int i;
181 expanded_location xloc;
182 enum tree_code code;
184 if (node == 0)
185 return;
187 code = TREE_CODE (node);
188 tclass = TREE_CODE_CLASS (code);
190 /* Don't get too deep in nesting. If the user wants to see deeper,
191 it is easy to use the address of a lowest-level node
192 as an argument in another call to debug_tree. */
194 if (indent > 24)
196 print_node_brief (file, prefix, node, indent);
197 return;
200 if (indent > 8 && (tclass == tcc_type || tclass == tcc_declaration))
202 print_node_brief (file, prefix, node, indent);
203 return;
206 /* It is unsafe to look at any other fields of an ERROR_MARK node. */
207 if (code == ERROR_MARK)
209 print_node_brief (file, prefix, node, indent);
210 return;
213 /* Allow this function to be called if the table is not there. */
214 if (table)
216 /* If node is in the table, just mention its address. */
217 if (table->contains (node) && brief_for_visited)
219 print_node_brief (file, prefix, node, indent);
220 return;
223 table->add (node);
226 /* Indent to the specified column, since this is the long form. */
227 indent_to (file, indent);
229 /* Print the slot this node is in, and its code, and address. */
230 fprintf (file, "%s <%s", prefix, get_tree_code_name (code));
231 dump_addr (file, " ", node);
233 /* Print the name, if any. */
234 if (tclass == tcc_declaration)
236 if (DECL_NAME (node))
237 fprintf (file, " %s", IDENTIFIER_POINTER (DECL_NAME (node)));
238 else if (code == LABEL_DECL
239 && LABEL_DECL_UID (node) != -1)
241 if (dump_flags & TDF_NOUID)
242 fprintf (file, " L.xxxx");
243 else
244 fprintf (file, " L.%d", (int) LABEL_DECL_UID (node));
246 else
248 if (dump_flags & TDF_NOUID)
249 fprintf (file, " %c.xxxx", code == CONST_DECL ? 'C' : 'D');
250 else
251 fprintf (file, " %c.%u", code == CONST_DECL ? 'C' : 'D',
252 DECL_UID (node));
255 else if (tclass == tcc_type)
257 if (TYPE_NAME (node))
259 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
260 fprintf (file, " %s", IDENTIFIER_POINTER (TYPE_NAME (node)));
261 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
262 && DECL_NAME (TYPE_NAME (node)))
263 fprintf (file, " %s",
264 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node))));
267 if (code == IDENTIFIER_NODE)
268 fprintf (file, " %s", IDENTIFIER_POINTER (node));
270 if (code == INTEGER_CST)
272 if (indent <= 4)
273 print_node_brief (file, "type", TREE_TYPE (node), indent + 4);
275 else if (CODE_CONTAINS_STRUCT (code, TS_TYPED))
277 print_node (file, "type", TREE_TYPE (node), indent + 4);
278 if (TREE_TYPE (node))
279 indent_to (file, indent + 3);
282 if (!TYPE_P (node) && TREE_SIDE_EFFECTS (node))
283 fputs (" side-effects", file);
285 if (TYPE_P (node) ? TYPE_READONLY (node) : TREE_READONLY (node))
286 fputs (" readonly", file);
287 if (TYPE_P (node) && TYPE_ATOMIC (node))
288 fputs (" atomic", file);
289 if (!TYPE_P (node) && TREE_CONSTANT (node))
290 fputs (" constant", file);
291 else if (TYPE_P (node) && TYPE_SIZES_GIMPLIFIED (node))
292 fputs (" sizes-gimplified", file);
294 if (TYPE_P (node) && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (node)))
295 fprintf (file, " address-space-%d", TYPE_ADDR_SPACE (node));
297 if (TREE_ADDRESSABLE (node))
298 fputs (" addressable", file);
299 if (TREE_THIS_VOLATILE (node))
300 fputs (" volatile", file);
301 if (TREE_ASM_WRITTEN (node))
302 fputs (" asm_written", file);
303 if (TREE_USED (node))
304 fputs (" used", file);
305 if (TREE_NOTHROW (node))
306 fputs (" nothrow", file);
307 if (TREE_PUBLIC (node))
308 fputs (" public", file);
309 if (TREE_PRIVATE (node))
310 fputs (" private", file);
311 if (TREE_PROTECTED (node))
312 fputs (" protected", file);
313 if (TREE_STATIC (node))
314 fputs (code == CALL_EXPR ? " must-tail-call" : " static", file);
315 if (TREE_DEPRECATED (node))
316 fputs (" deprecated", file);
317 if (TREE_VISITED (node))
318 fputs (" visited", file);
320 if (code != TREE_VEC && code != INTEGER_CST && code != SSA_NAME)
322 if (TREE_LANG_FLAG_0 (node))
323 fputs (" tree_0", file);
324 if (TREE_LANG_FLAG_1 (node))
325 fputs (" tree_1", file);
326 if (TREE_LANG_FLAG_2 (node))
327 fputs (" tree_2", file);
328 if (TREE_LANG_FLAG_3 (node))
329 fputs (" tree_3", file);
330 if (TREE_LANG_FLAG_4 (node))
331 fputs (" tree_4", file);
332 if (TREE_LANG_FLAG_5 (node))
333 fputs (" tree_5", file);
334 if (TREE_LANG_FLAG_6 (node))
335 fputs (" tree_6", file);
338 /* DECL_ nodes have additional attributes. */
340 switch (TREE_CODE_CLASS (code))
342 case tcc_declaration:
343 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
345 if (DECL_UNSIGNED (node))
346 fputs (" unsigned", file);
347 if (DECL_IGNORED_P (node))
348 fputs (" ignored", file);
349 if (DECL_ABSTRACT_P (node))
350 fputs (" abstract", file);
351 if (DECL_EXTERNAL (node))
352 fputs (" external", file);
353 if (DECL_NONLOCAL (node))
354 fputs (" nonlocal", file);
356 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
358 if (DECL_WEAK (node))
359 fputs (" weak", file);
360 if (DECL_IN_SYSTEM_HEADER (node))
361 fputs (" in_system_header", file);
363 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WRTL)
364 && code != LABEL_DECL
365 && code != FUNCTION_DECL
366 && DECL_REGISTER (node))
367 fputs (" regdecl", file);
369 if (code == TYPE_DECL && TYPE_DECL_SUPPRESS_DEBUG (node))
370 fputs (" suppress-debug", file);
372 if (code == FUNCTION_DECL
373 && DECL_FUNCTION_SPECIFIC_TARGET (node))
374 fputs (" function-specific-target", file);
375 if (code == FUNCTION_DECL
376 && DECL_FUNCTION_SPECIFIC_OPTIMIZATION (node))
377 fputs (" function-specific-opt", file);
378 if (code == FUNCTION_DECL && DECL_DECLARED_INLINE_P (node))
379 fputs (" autoinline", file);
380 if (code == FUNCTION_DECL && DECL_UNINLINABLE (node))
381 fputs (" uninlinable", file);
382 if (code == FUNCTION_DECL && DECL_BUILT_IN (node))
383 fputs (" built-in", file);
384 if (code == FUNCTION_DECL && DECL_STATIC_CHAIN (node))
385 fputs (" static-chain", file);
386 if (TREE_CODE (node) == FUNCTION_DECL && decl_is_tm_clone (node))
387 fputs (" tm-clone", file);
389 if (code == FIELD_DECL && DECL_PACKED (node))
390 fputs (" packed", file);
391 if (code == FIELD_DECL && DECL_BIT_FIELD (node))
392 fputs (" bit-field", file);
393 if (code == FIELD_DECL && DECL_NONADDRESSABLE_P (node))
394 fputs (" nonaddressable", file);
396 if (code == LABEL_DECL && EH_LANDING_PAD_NR (node))
397 fprintf (file, " landing-pad:%d", EH_LANDING_PAD_NR (node));
399 if (code == VAR_DECL && DECL_IN_TEXT_SECTION (node))
400 fputs (" in-text-section", file);
401 if (code == VAR_DECL && DECL_IN_CONSTANT_POOL (node))
402 fputs (" in-constant-pool", file);
403 if (code == VAR_DECL && DECL_COMMON (node))
404 fputs (" common", file);
405 if ((code == VAR_DECL || code == PARM_DECL) && DECL_READ_P (node))
406 fputs (" read", file);
407 if (code == VAR_DECL && DECL_THREAD_LOCAL_P (node))
409 fputs (" ", file);
410 fputs (tls_model_names[DECL_TLS_MODEL (node)], file);
413 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
415 if (DECL_VIRTUAL_P (node))
416 fputs (" virtual", file);
417 if (DECL_PRESERVE_P (node))
418 fputs (" preserve", file);
419 if (DECL_LANG_FLAG_0 (node))
420 fputs (" decl_0", file);
421 if (DECL_LANG_FLAG_1 (node))
422 fputs (" decl_1", file);
423 if (DECL_LANG_FLAG_2 (node))
424 fputs (" decl_2", file);
425 if (DECL_LANG_FLAG_3 (node))
426 fputs (" decl_3", file);
427 if (DECL_LANG_FLAG_4 (node))
428 fputs (" decl_4", file);
429 if (DECL_LANG_FLAG_5 (node))
430 fputs (" decl_5", file);
431 if (DECL_LANG_FLAG_6 (node))
432 fputs (" decl_6", file);
433 if (DECL_LANG_FLAG_7 (node))
434 fputs (" decl_7", file);
436 mode = DECL_MODE (node);
437 fprintf (file, " %s", GET_MODE_NAME (mode));
440 if ((code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
441 && DECL_BY_REFERENCE (node))
442 fputs (" passed-by-reference", file);
444 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS) && DECL_DEFER_OUTPUT (node))
445 fputs (" defer-output", file);
448 xloc = expand_location (DECL_SOURCE_LOCATION (node));
449 fprintf (file, " %s:%d:%d", xloc.file, xloc.line,
450 xloc.column);
452 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
454 print_node (file, "size", DECL_SIZE (node), indent + 4);
455 print_node (file, "unit-size", DECL_SIZE_UNIT (node), indent + 4);
457 if (code != FUNCTION_DECL || DECL_BUILT_IN (node))
458 indent_to (file, indent + 3);
460 if (DECL_USER_ALIGN (node))
461 fprintf (file, " user");
463 fprintf (file, " align:%d warn_if_not_align:%d",
464 DECL_ALIGN (node), DECL_WARN_IF_NOT_ALIGN (node));
465 if (code == FIELD_DECL)
466 fprintf (file, " offset_align " HOST_WIDE_INT_PRINT_UNSIGNED,
467 DECL_OFFSET_ALIGN (node));
469 if (code == FUNCTION_DECL && DECL_BUILT_IN (node))
471 if (DECL_BUILT_IN_CLASS (node) == BUILT_IN_MD)
472 fprintf (file, " built-in: BUILT_IN_MD:%d", DECL_FUNCTION_CODE (node));
473 else
474 fprintf (file, " built-in: %s:%s",
475 built_in_class_names[(int) DECL_BUILT_IN_CLASS (node)],
476 built_in_names[(int) DECL_FUNCTION_CODE (node)]);
479 if (code == FIELD_DECL)
481 print_node (file, "offset", DECL_FIELD_OFFSET (node), indent + 4);
482 print_node (file, "bit-offset", DECL_FIELD_BIT_OFFSET (node),
483 indent + 4);
484 if (DECL_BIT_FIELD_TYPE (node))
485 print_node (file, "bit_field_type", DECL_BIT_FIELD_TYPE (node),
486 indent + 4);
489 print_node_brief (file, "context", DECL_CONTEXT (node), indent + 4);
491 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
493 print_node (file, "attributes",
494 DECL_ATTRIBUTES (node), indent + 4);
495 if (code != PARM_DECL)
496 print_node_brief (file, "initial", DECL_INITIAL (node),
497 indent + 4);
499 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WRTL))
501 print_node_brief (file, "abstract_origin",
502 DECL_ABSTRACT_ORIGIN (node), indent + 4);
504 if (CODE_CONTAINS_STRUCT (code, TS_DECL_NON_COMMON))
506 print_node (file, "result", DECL_RESULT_FLD (node), indent + 4);
509 lang_hooks.print_decl (file, node, indent);
511 if (DECL_RTL_SET_P (node))
513 indent_to (file, indent + 4);
514 print_rtl (file, DECL_RTL (node));
517 if (code == PARM_DECL)
519 print_node (file, "arg-type", DECL_ARG_TYPE (node), indent + 4);
521 if (DECL_INCOMING_RTL (node) != 0)
523 indent_to (file, indent + 4);
524 fprintf (file, "incoming-rtl ");
525 print_rtl (file, DECL_INCOMING_RTL (node));
528 else if (code == FUNCTION_DECL
529 && DECL_STRUCT_FUNCTION (node) != 0)
531 print_node (file, "arguments", DECL_ARGUMENTS (node), indent + 4);
532 indent_to (file, indent + 4);
533 dump_addr (file, "struct-function ", DECL_STRUCT_FUNCTION (node));
536 if ((code == VAR_DECL || code == PARM_DECL)
537 && DECL_HAS_VALUE_EXPR_P (node))
538 print_node (file, "value-expr", DECL_VALUE_EXPR (node), indent + 4);
540 /* Print the decl chain only if decl is at second level. */
541 if (indent == 4)
542 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
543 else
544 print_node_brief (file, "chain", TREE_CHAIN (node), indent + 4);
545 break;
547 case tcc_type:
548 if (TYPE_UNSIGNED (node))
549 fputs (" unsigned", file);
551 if (TYPE_NO_FORCE_BLK (node))
552 fputs (" no-force-blk", file);
554 if (TYPE_STRING_FLAG (node))
555 fputs (" string-flag", file);
557 if (TYPE_NEEDS_CONSTRUCTING (node))
558 fputs (" needs-constructing", file);
560 if ((code == RECORD_TYPE
561 || code == UNION_TYPE
562 || code == QUAL_UNION_TYPE
563 || code == ARRAY_TYPE)
564 && TYPE_REVERSE_STORAGE_ORDER (node))
565 fputs (" reverse-storage-order", file);
567 /* The transparent-union flag is used for different things in
568 different nodes. */
569 if ((code == UNION_TYPE || code == RECORD_TYPE)
570 && TYPE_TRANSPARENT_AGGR (node))
571 fputs (" transparent-aggr", file);
572 else if (code == ARRAY_TYPE
573 && TYPE_NONALIASED_COMPONENT (node))
574 fputs (" nonaliased-component", file);
576 if (TYPE_PACKED (node))
577 fputs (" packed", file);
579 if (TYPE_RESTRICT (node))
580 fputs (" restrict", file);
582 if (TYPE_LANG_FLAG_0 (node))
583 fputs (" type_0", file);
584 if (TYPE_LANG_FLAG_1 (node))
585 fputs (" type_1", file);
586 if (TYPE_LANG_FLAG_2 (node))
587 fputs (" type_2", file);
588 if (TYPE_LANG_FLAG_3 (node))
589 fputs (" type_3", file);
590 if (TYPE_LANG_FLAG_4 (node))
591 fputs (" type_4", file);
592 if (TYPE_LANG_FLAG_5 (node))
593 fputs (" type_5", file);
594 if (TYPE_LANG_FLAG_6 (node))
595 fputs (" type_6", file);
596 if (TYPE_LANG_FLAG_7 (node))
597 fputs (" type_7", file);
599 mode = TYPE_MODE (node);
600 fprintf (file, " %s", GET_MODE_NAME (mode));
602 print_node (file, "size", TYPE_SIZE (node), indent + 4);
603 print_node (file, "unit-size", TYPE_SIZE_UNIT (node), indent + 4);
604 indent_to (file, indent + 3);
606 if (TYPE_USER_ALIGN (node))
607 fprintf (file, " user");
609 fprintf (file, " align:%d warn_if_not_align:%d symtab:%d alias-set "
610 HOST_WIDE_INT_PRINT_DEC,
611 TYPE_ALIGN (node), TYPE_WARN_IF_NOT_ALIGN (node),
612 TYPE_SYMTAB_ADDRESS (node),
613 (HOST_WIDE_INT) TYPE_ALIAS_SET (node));
615 if (TYPE_STRUCTURAL_EQUALITY_P (node))
616 fprintf (file, " structural-equality");
617 else
618 dump_addr (file, " canonical-type ", TYPE_CANONICAL (node));
620 print_node (file, "attributes", TYPE_ATTRIBUTES (node), indent + 4);
622 if (INTEGRAL_TYPE_P (node) || code == REAL_TYPE
623 || code == FIXED_POINT_TYPE)
625 fprintf (file, " precision:%d", TYPE_PRECISION (node));
626 print_node_brief (file, "min", TYPE_MIN_VALUE (node), indent + 4);
627 print_node_brief (file, "max", TYPE_MAX_VALUE (node), indent + 4);
630 if (code == ENUMERAL_TYPE)
631 print_node (file, "values", TYPE_VALUES (node), indent + 4);
632 else if (code == ARRAY_TYPE)
633 print_node (file, "domain", TYPE_DOMAIN (node), indent + 4);
634 else if (code == VECTOR_TYPE)
636 fprintf (file, " nunits:");
637 print_dec (TYPE_VECTOR_SUBPARTS (node), file);
639 else if (code == RECORD_TYPE
640 || code == UNION_TYPE
641 || code == QUAL_UNION_TYPE)
642 print_node (file, "fields", TYPE_FIELDS (node), indent + 4);
643 else if (code == FUNCTION_TYPE
644 || code == METHOD_TYPE)
646 if (TYPE_METHOD_BASETYPE (node))
647 print_node_brief (file, "method basetype",
648 TYPE_METHOD_BASETYPE (node), indent + 4);
649 print_node (file, "arg-types", TYPE_ARG_TYPES (node), indent + 4);
651 else if (code == OFFSET_TYPE)
652 print_node_brief (file, "basetype", TYPE_OFFSET_BASETYPE (node),
653 indent + 4);
655 if (TYPE_CONTEXT (node))
656 print_node_brief (file, "context", TYPE_CONTEXT (node), indent + 4);
658 lang_hooks.print_type (file, node, indent);
660 if (TYPE_POINTER_TO (node) || TREE_CHAIN (node))
661 indent_to (file, indent + 3);
663 print_node_brief (file, "pointer_to_this", TYPE_POINTER_TO (node),
664 indent + 4);
665 print_node_brief (file, "reference_to_this", TYPE_REFERENCE_TO (node),
666 indent + 4);
667 print_node_brief (file, "chain", TREE_CHAIN (node), indent + 4);
668 break;
670 case tcc_expression:
671 case tcc_comparison:
672 case tcc_unary:
673 case tcc_binary:
674 case tcc_reference:
675 case tcc_statement:
676 case tcc_vl_exp:
677 if (code == BIND_EXPR)
679 print_node (file, "vars", TREE_OPERAND (node, 0), indent + 4);
680 print_node (file, "body", TREE_OPERAND (node, 1), indent + 4);
681 print_node (file, "block", TREE_OPERAND (node, 2), indent + 4);
682 break;
684 if (code == CALL_EXPR)
686 call_expr_arg_iterator iter;
687 tree arg;
688 print_node (file, "fn", CALL_EXPR_FN (node), indent + 4);
689 print_node (file, "static_chain", CALL_EXPR_STATIC_CHAIN (node),
690 indent + 4);
691 i = 0;
692 FOR_EACH_CALL_EXPR_ARG (arg, iter, node)
694 /* Buffer big enough to format a 32-bit UINT_MAX into, plus
695 the text. */
696 char temp[15];
697 sprintf (temp, "arg:%u", i);
698 print_node (file, temp, arg, indent + 4);
699 i++;
702 else
704 len = TREE_OPERAND_LENGTH (node);
706 for (i = 0; i < len; i++)
708 /* Buffer big enough to format a 32-bit UINT_MAX into, plus
709 the text. */
710 char temp[15];
712 sprintf (temp, "arg:%d", i);
713 print_node (file, temp, TREE_OPERAND (node, i), indent + 4);
716 if (CODE_CONTAINS_STRUCT (code, TS_COMMON))
717 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
718 break;
720 case tcc_constant:
721 case tcc_exceptional:
722 switch (code)
724 case INTEGER_CST:
725 if (TREE_OVERFLOW (node))
726 fprintf (file, " overflow");
728 fprintf (file, " ");
729 print_dec (wi::to_wide (node), file, TYPE_SIGN (TREE_TYPE (node)));
730 break;
732 case REAL_CST:
734 REAL_VALUE_TYPE d;
736 if (TREE_OVERFLOW (node))
737 fprintf (file, " overflow");
739 d = TREE_REAL_CST (node);
740 if (REAL_VALUE_ISINF (d))
741 fprintf (file, REAL_VALUE_NEGATIVE (d) ? " -Inf" : " Inf");
742 else if (REAL_VALUE_ISNAN (d))
743 fprintf (file, " Nan");
744 else
746 char string[64];
747 real_to_decimal (string, &d, sizeof (string), 0, 1);
748 fprintf (file, " %s", string);
751 break;
753 case FIXED_CST:
755 FIXED_VALUE_TYPE f;
756 char string[64];
758 if (TREE_OVERFLOW (node))
759 fprintf (file, " overflow");
761 f = TREE_FIXED_CST (node);
762 fixed_to_decimal (string, &f, sizeof (string));
763 fprintf (file, " %s", string);
765 break;
767 case VECTOR_CST:
769 /* Big enough for UINT_MAX plus the string below. */
770 char buf[32];
772 fprintf (file, " npatterns:%u nelts-per-pattern:%u",
773 VECTOR_CST_NPATTERNS (node),
774 VECTOR_CST_NELTS_PER_PATTERN (node));
775 unsigned int count = vector_cst_encoded_nelts (node);
776 for (unsigned int i = 0; i < count; ++i)
778 sprintf (buf, "elt:%u: ", i);
779 print_node (file, buf, VECTOR_CST_ENCODED_ELT (node, i),
780 indent + 4);
783 break;
785 case COMPLEX_CST:
786 print_node (file, "real", TREE_REALPART (node), indent + 4);
787 print_node (file, "imag", TREE_IMAGPART (node), indent + 4);
788 break;
790 case STRING_CST:
792 const char *p = TREE_STRING_POINTER (node);
793 int i = TREE_STRING_LENGTH (node);
794 fputs (" \"", file);
795 while (--i >= 0)
797 char ch = *p++;
798 if (ch >= ' ' && ch < 127)
799 putc (ch, file);
800 else
801 fprintf (file, "\\%03o", ch & 0xFF);
803 fputc ('\"', file);
805 break;
807 case POLY_INT_CST:
809 char buf[10];
810 for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
812 snprintf (buf, sizeof (buf), "elt%u: ", i);
813 print_node (file, buf, POLY_INT_CST_COEFF (node, i),
814 indent + 4);
817 break;
819 case IDENTIFIER_NODE:
820 lang_hooks.print_identifier (file, node, indent);
821 break;
823 case TREE_LIST:
824 print_node (file, "purpose", TREE_PURPOSE (node), indent + 4);
825 print_node (file, "value", TREE_VALUE (node), indent + 4);
826 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
827 break;
829 case TREE_VEC:
830 len = TREE_VEC_LENGTH (node);
831 fprintf (file, " length:%d", len);
832 for (i = 0; i < len; i++)
833 if (TREE_VEC_ELT (node, i))
835 /* Buffer big enough to format a 32-bit UINT_MAX into, plus
836 the text. */
837 char temp[15];
838 sprintf (temp, "elt:%d", i);
839 print_node (file, temp, TREE_VEC_ELT (node, i), indent + 4);
841 break;
843 case CONSTRUCTOR:
845 unsigned HOST_WIDE_INT cnt;
846 tree index, value;
847 len = CONSTRUCTOR_NELTS (node);
848 fprintf (file, " length:%d", len);
849 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (node),
850 cnt, index, value)
852 print_node (file, "idx", index, indent + 4, false);
853 print_node (file, "val", value, indent + 4, false);
856 break;
858 case STATEMENT_LIST:
859 dump_addr (file, " head ", node->stmt_list.head);
860 dump_addr (file, " tail ", node->stmt_list.tail);
861 fprintf (file, " stmts");
863 tree_stmt_iterator i;
864 for (i = tsi_start (node); !tsi_end_p (i); tsi_next (&i))
866 /* Not printing the addresses of the (not-a-tree)
867 'struct tree_stmt_list_node's. */
868 dump_addr (file, " ", tsi_stmt (i));
870 fprintf (file, "\n");
871 for (i = tsi_start (node); !tsi_end_p (i); tsi_next (&i))
873 /* Not printing the addresses of the (not-a-tree)
874 'struct tree_stmt_list_node's. */
875 print_node (file, "stmt", tsi_stmt (i), indent + 4);
878 break;
880 case BLOCK:
881 print_node (file, "vars", BLOCK_VARS (node), indent + 4);
882 print_node (file, "supercontext", BLOCK_SUPERCONTEXT (node),
883 indent + 4);
884 print_node (file, "subblocks", BLOCK_SUBBLOCKS (node), indent + 4);
885 print_node (file, "chain", BLOCK_CHAIN (node), indent + 4);
886 print_node (file, "abstract_origin",
887 BLOCK_ABSTRACT_ORIGIN (node), indent + 4);
888 break;
890 case SSA_NAME:
891 print_node_brief (file, "var", SSA_NAME_VAR (node), indent + 4);
892 indent_to (file, indent + 4);
893 fprintf (file, "def_stmt ");
895 pretty_printer buffer;
896 buffer.buffer->stream = file;
897 pp_gimple_stmt_1 (&buffer, SSA_NAME_DEF_STMT (node), indent + 4, 0);
898 pp_flush (&buffer);
901 indent_to (file, indent + 4);
902 fprintf (file, "version:%u", SSA_NAME_VERSION (node));
903 if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (node))
904 fprintf (file, " in-abnormal-phi");
905 if (SSA_NAME_IN_FREE_LIST (node))
906 fprintf (file, " in-free-list");
908 if (SSA_NAME_PTR_INFO (node))
910 indent_to (file, indent + 3);
911 if (SSA_NAME_PTR_INFO (node))
912 dump_addr (file, " ptr-info ", SSA_NAME_PTR_INFO (node));
914 break;
916 case OMP_CLAUSE:
918 int i;
919 fprintf (file, " %s",
920 omp_clause_code_name[OMP_CLAUSE_CODE (node)]);
921 for (i = 0; i < omp_clause_num_ops[OMP_CLAUSE_CODE (node)]; i++)
923 indent_to (file, indent + 4);
924 fprintf (file, "op-%d:", i);
925 print_node_brief (file, "", OMP_CLAUSE_OPERAND (node, i), 0);
928 break;
930 case OPTIMIZATION_NODE:
931 cl_optimization_print (file, indent + 4, TREE_OPTIMIZATION (node));
932 break;
934 case TARGET_OPTION_NODE:
935 cl_target_option_print (file, indent + 4, TREE_TARGET_OPTION (node));
936 break;
937 case IMPORTED_DECL:
938 fprintf (file, " imported-declaration");
939 print_node_brief (file, "associated-declaration",
940 IMPORTED_DECL_ASSOCIATED_DECL (node),
941 indent + 4);
942 break;
944 case TREE_BINFO:
945 fprintf (file, " bases:%d",
946 vec_safe_length (BINFO_BASE_BINFOS (node)));
947 print_node_brief (file, "offset", BINFO_OFFSET (node), indent + 4);
948 print_node_brief (file, "virtuals", BINFO_VIRTUALS (node),
949 indent + 4);
950 print_node_brief (file, "inheritance-chain",
951 BINFO_INHERITANCE_CHAIN (node),
952 indent + 4);
953 break;
955 default:
956 if (EXCEPTIONAL_CLASS_P (node))
957 lang_hooks.print_xnode (file, node, indent);
958 break;
961 break;
964 if (EXPR_HAS_LOCATION (node))
966 expanded_location xloc = expand_location (EXPR_LOCATION (node));
967 indent_to (file, indent+4);
968 fprintf (file, "%s:%d:%d", xloc.file, xloc.line, xloc.column);
970 /* Print the range, if any */
971 source_range r = EXPR_LOCATION_RANGE (node);
972 if (r.m_start)
974 xloc = expand_location (r.m_start);
975 fprintf (file, " start: %s:%d:%d", xloc.file, xloc.line, xloc.column);
977 else
979 fprintf (file, " start: unknown");
981 if (r.m_finish)
983 xloc = expand_location (r.m_finish);
984 fprintf (file, " finish: %s:%d:%d", xloc.file, xloc.line, xloc.column);
986 else
988 fprintf (file, " finish: unknown");
992 fprintf (file, ">");
996 /* Print the node NODE on standard error, for debugging.
997 Most nodes referred to by this one are printed recursively
998 down to a depth of six. */
1000 DEBUG_FUNCTION void
1001 debug_tree (tree node)
1003 table = new hash_set<tree> (HASH_SIZE);
1004 print_node (stderr, "", node, 0);
1005 delete table;
1006 table = NULL;
1007 putc ('\n', stderr);
1010 DEBUG_FUNCTION void
1011 debug_raw (const tree_node &ref)
1013 debug_tree (const_cast <tree> (&ref));
1016 DEBUG_FUNCTION void
1017 debug_raw (const tree_node *ptr)
1019 if (ptr)
1020 debug_raw (*ptr);
1021 else
1022 fprintf (stderr, "<nil>\n");
1025 static void
1026 dump_tree_via_hooks (const tree_node *ptr, dump_flags_t options)
1028 if (DECL_P (ptr))
1029 lang_hooks.print_decl (stderr, const_cast <tree_node*> (ptr), 0);
1030 else if (TYPE_P (ptr))
1031 lang_hooks.print_type (stderr, const_cast <tree_node*> (ptr), 0);
1032 else if (TREE_CODE (ptr) == IDENTIFIER_NODE)
1033 lang_hooks.print_identifier (stderr, const_cast <tree_node*> (ptr), 0);
1034 else
1035 print_generic_expr (stderr, const_cast <tree_node*> (ptr), options);
1036 fprintf (stderr, "\n");
1039 DEBUG_FUNCTION void
1040 debug (const tree_node &ref)
1042 dump_tree_via_hooks (&ref, 0);
1045 DEBUG_FUNCTION void
1046 debug (const tree_node *ptr)
1048 if (ptr)
1049 debug (*ptr);
1050 else
1051 fprintf (stderr, "<nil>\n");
1054 DEBUG_FUNCTION void
1055 debug_head (const tree_node &ref)
1057 debug (ref);
1060 DEBUG_FUNCTION void
1061 debug_head (const tree_node *ptr)
1063 if (ptr)
1064 debug_head (*ptr);
1065 else
1066 fprintf (stderr, "<nil>\n");
1069 DEBUG_FUNCTION void
1070 debug_body (const tree_node &ref)
1072 if (TREE_CODE (&ref) == FUNCTION_DECL)
1073 dump_function_to_file (const_cast <tree_node*> (&ref), stderr, 0);
1074 else
1075 debug (ref);
1078 DEBUG_FUNCTION void
1079 debug_body (const tree_node *ptr)
1081 if (ptr)
1082 debug_body (*ptr);
1083 else
1084 fprintf (stderr, "<nil>\n");
1087 /* Print the vector of trees VEC on standard error, for debugging.
1088 Most nodes referred to by this one are printed recursively
1089 down to a depth of six. */
1091 DEBUG_FUNCTION void
1092 debug_raw (vec<tree, va_gc> &ref)
1094 tree elt;
1095 unsigned ix;
1097 /* Print the slot this node is in, and its code, and address. */
1098 fprintf (stderr, "<VEC");
1099 dump_addr (stderr, " ", ref.address ());
1101 FOR_EACH_VEC_ELT (ref, ix, elt)
1103 fprintf (stderr, "elt:%d ", ix);
1104 debug_raw (elt);
1108 DEBUG_FUNCTION void
1109 debug_raw (vec<tree, va_gc> *ptr)
1111 if (ptr)
1112 debug_raw (*ptr);
1113 else
1114 fprintf (stderr, "<nil>\n");
1117 static void
1118 debug_slim (tree t)
1120 print_node_brief (stderr, "", t, 0);
1123 DEFINE_DEBUG_VEC (tree)
1124 DEFINE_DEBUG_HASH_SET (tree)