c++: fix throwing cleanup with label
[official-gcc.git] / gcc / print-tree.cc
blobccecd3dc6a7d7157a5df7eb58ff6f5994e18e02b
1 /* Prints out tree in human readable form - GCC
2 Copyright (C) 1990-2023 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"
37 #include "file-prefix-map.h"
39 /* Define the hash table of nodes already seen.
40 Such nodes are not repeated; brief cross-references are used. */
42 #define HASH_SIZE 37
44 static hash_set<tree> *table = NULL;
46 /* Print PREFIX and ADDR to FILE. */
47 void
48 dump_addr (FILE *file, const char *prefix, const void *addr)
50 if (flag_dump_noaddr || flag_dump_unnumbered)
51 fprintf (file, "%s#", prefix);
52 else
53 fprintf (file, "%s" HOST_PTR_PRINTF, prefix, addr);
56 /* Print to FILE a NODE representing a REAL_CST constant, including
57 Infinity and NaN. Be verbose when BFRIEF is false. */
59 static void
60 print_real_cst (FILE *file, const_tree node, bool brief)
62 if (TREE_OVERFLOW (node))
63 fprintf (file, " overflow");
65 REAL_VALUE_TYPE d = TREE_REAL_CST (node);
66 if (REAL_VALUE_ISINF (d))
67 fprintf (file, REAL_VALUE_NEGATIVE (d) ? " -Inf" : " Inf");
68 else if (REAL_VALUE_ISNAN (d))
70 /* Print a NaN in the format [-][Q]NaN[(significand[exponent])]
71 where significand is a hexadecimal string that starts with
72 the 0x prefix followed by 0 if the number is not canonical
73 and a non-zero digit if it is, and exponent is decimal. */
74 unsigned start = 0;
75 const char *psig = (const char *) d.sig;
76 for (unsigned i = 0; i != sizeof d.sig; ++i)
77 if (psig[i])
79 start = i;
80 break;
83 fprintf (file, " %s%sNaN", d.sign ? "-" : "",
84 d.signalling ? "S" : "Q");
86 if (brief)
87 return;
89 if (start)
90 fprintf (file, "(0x%s", d.canonical ? "" : "0");
91 else if (d.uexp)
92 fprintf (file, "(%s", d.canonical ? "" : "0");
93 else if (!d.canonical)
95 fprintf (file, "(0)");
96 return;
99 if (psig[start])
101 for (unsigned i = start; i != sizeof d.sig; ++i)
102 if (i == start)
103 fprintf (file, "%x", psig[i]);
104 else
105 fprintf (file, "%02x", psig[i]);
108 if (d.uexp)
109 fprintf (file, "%se%u)", psig[start] ? "," : "", d.uexp);
110 else if (psig[start])
111 fputc (')', file);
113 else
115 char string[64];
116 real_to_decimal (string, &d, sizeof (string), 0, 1);
117 fprintf (file, " %s", string);
121 /* Print a node in brief fashion, with just the code, address and name. */
123 void
124 print_node_brief (FILE *file, const char *prefix, const_tree node, int indent)
126 enum tree_code_class tclass;
128 if (node == 0)
129 return;
131 tclass = TREE_CODE_CLASS (TREE_CODE (node));
133 /* Always print the slot this node is in, and its code, address and
134 name if any. */
135 if (indent > 0)
136 fprintf (file, " ");
137 fprintf (file, "%s <%s", prefix, get_tree_code_name (TREE_CODE (node)));
138 dump_addr (file, " ", node);
140 if (tclass == tcc_declaration)
142 if (DECL_NAME (node))
143 fprintf (file, " %s", IDENTIFIER_POINTER (DECL_NAME (node)));
144 else if (TREE_CODE (node) == LABEL_DECL
145 && LABEL_DECL_UID (node) != -1)
147 if (dump_flags & TDF_NOUID)
148 fprintf (file, " L.xxxx");
149 else
150 fprintf (file, " L.%d", (int) LABEL_DECL_UID (node));
152 else
154 if (dump_flags & TDF_NOUID)
155 fprintf (file, " %c.xxxx",
156 TREE_CODE (node) == CONST_DECL ? 'C' : 'D');
157 else
158 fprintf (file, " %c.%u",
159 TREE_CODE (node) == CONST_DECL ? 'C' : 'D',
160 DECL_UID (node));
163 else if (tclass == tcc_type)
165 if (TYPE_NAME (node))
167 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
168 fprintf (file, " %s", IDENTIFIER_POINTER (TYPE_NAME (node)));
169 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
170 && DECL_NAME (TYPE_NAME (node)))
171 fprintf (file, " %s",
172 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node))));
174 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (node)))
175 fprintf (file, " address-space-%d", TYPE_ADDR_SPACE (node));
177 if (TREE_CODE (node) == IDENTIFIER_NODE)
178 fprintf (file, " %s", IDENTIFIER_POINTER (node));
180 /* We might as well always print the value of an integer or real. */
181 if (TREE_CODE (node) == INTEGER_CST)
183 if (TREE_OVERFLOW (node))
184 fprintf (file, " overflow");
186 fprintf (file, " ");
187 print_dec (wi::to_wide (node), file, TYPE_SIGN (TREE_TYPE (node)));
189 if (TREE_CODE (node) == REAL_CST)
190 print_real_cst (file, node, true);
191 if (TREE_CODE (node) == FIXED_CST)
193 FIXED_VALUE_TYPE f;
194 char string[60];
196 if (TREE_OVERFLOW (node))
197 fprintf (file, " overflow");
199 f = TREE_FIXED_CST (node);
200 fixed_to_decimal (string, &f, sizeof (string));
201 fprintf (file, " %s", string);
204 fprintf (file, ">");
207 void
208 indent_to (FILE *file, int column)
210 int i;
212 /* Since this is the long way, indent to desired column. */
213 if (column > 0)
214 fprintf (file, "\n");
215 for (i = 0; i < column; i++)
216 fprintf (file, " ");
219 /* Print the node NODE in full on file FILE, preceded by PREFIX,
220 starting in column INDENT. */
222 void
223 print_node (FILE *file, const char *prefix, tree node, int indent,
224 bool brief_for_visited)
226 machine_mode mode;
227 enum tree_code_class tclass;
228 int len;
229 int i;
230 expanded_location xloc;
231 enum tree_code code;
233 if (node == 0)
234 return;
236 code = TREE_CODE (node);
238 /* It is unsafe to look at any other fields of a node with ERROR_MARK or
239 invalid code. */
240 if (code == ERROR_MARK || code >= MAX_TREE_CODES)
242 print_node_brief (file, prefix, node, indent);
243 return;
246 tclass = TREE_CODE_CLASS (code);
248 /* Don't get too deep in nesting. If the user wants to see deeper,
249 it is easy to use the address of a lowest-level node
250 as an argument in another call to debug_tree. */
252 if (indent > 24)
254 print_node_brief (file, prefix, node, indent);
255 return;
258 if (indent > 8 && (tclass == tcc_type || tclass == tcc_declaration))
260 print_node_brief (file, prefix, node, indent);
261 return;
264 /* Allow this function to be called if the table is not there. */
265 if (table)
267 /* If node is in the table, just mention its address. */
268 if (table->contains (node) && brief_for_visited)
270 print_node_brief (file, prefix, node, indent);
271 return;
274 table->add (node);
277 /* Indent to the specified column, since this is the long form. */
278 indent_to (file, indent);
280 /* Print the slot this node is in, and its code, and address. */
281 fprintf (file, "%s <%s", prefix, get_tree_code_name (code));
282 dump_addr (file, " ", node);
284 /* Print the name, if any. */
285 if (tclass == tcc_declaration)
287 if (DECL_NAME (node))
288 fprintf (file, " %s", IDENTIFIER_POINTER (DECL_NAME (node)));
289 else if (code == LABEL_DECL
290 && LABEL_DECL_UID (node) != -1)
292 if (dump_flags & TDF_NOUID)
293 fprintf (file, " L.xxxx");
294 else
295 fprintf (file, " L.%d", (int) LABEL_DECL_UID (node));
297 else
299 if (dump_flags & TDF_NOUID)
300 fprintf (file, " %c.xxxx", code == CONST_DECL ? 'C' : 'D');
301 else
302 fprintf (file, " %c.%u", code == CONST_DECL ? 'C' : 'D',
303 DECL_UID (node));
306 else if (tclass == tcc_type)
308 if (TYPE_NAME (node))
310 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
311 fprintf (file, " %s", IDENTIFIER_POINTER (TYPE_NAME (node)));
312 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
313 && DECL_NAME (TYPE_NAME (node)))
314 fprintf (file, " %s",
315 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node))));
318 if (code == IDENTIFIER_NODE)
319 fprintf (file, " %s", IDENTIFIER_POINTER (node));
321 if (code == INTEGER_CST)
323 if (indent <= 4)
324 print_node_brief (file, "type", TREE_TYPE (node), indent + 4);
326 else if (CODE_CONTAINS_STRUCT (code, TS_TYPED))
328 print_node (file, "type", TREE_TYPE (node), indent + 4);
329 if (TREE_TYPE (node))
330 indent_to (file, indent + 3);
333 if (!TYPE_P (node) && TREE_SIDE_EFFECTS (node))
334 fputs (" side-effects", file);
336 if (TYPE_P (node) ? TYPE_READONLY (node) : TREE_READONLY (node))
337 fputs (" readonly", file);
338 if (TYPE_P (node) && TYPE_ATOMIC (node))
339 fputs (" atomic", file);
340 if (!TYPE_P (node) && TREE_CONSTANT (node))
341 fputs (" constant", file);
342 else if (TYPE_P (node) && TYPE_SIZES_GIMPLIFIED (node))
343 fputs (" sizes-gimplified", file);
345 if (TYPE_P (node) && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (node)))
346 fprintf (file, " address-space-%d", TYPE_ADDR_SPACE (node));
348 if (TREE_ADDRESSABLE (node))
349 fputs (" addressable", file);
350 if (TREE_THIS_VOLATILE (node))
351 fputs (" volatile", file);
352 if (TREE_ASM_WRITTEN (node))
353 fputs (" asm_written", file);
354 if (TREE_USED (node))
355 fputs (" used", file);
356 if (TREE_NOTHROW (node))
357 fputs (" nothrow", file);
358 if (TREE_PUBLIC (node))
359 fputs (" public", file);
360 if (TREE_PRIVATE (node))
361 fputs (" private", file);
362 if (TREE_PROTECTED (node))
363 fputs (" protected", file);
364 if (TREE_STATIC (node))
365 fputs (code == CALL_EXPR ? " must-tail-call" : " static", file);
366 if (TREE_DEPRECATED (node))
367 fputs (" deprecated", file);
368 if (TREE_UNAVAILABLE (node))
369 fputs (" unavailable", file);
370 if (TREE_VISITED (node))
371 fputs (" visited", file);
373 if (code != TREE_VEC && code != INTEGER_CST && code != SSA_NAME)
375 if (TREE_LANG_FLAG_0 (node))
376 fputs (" tree_0", file);
377 if (TREE_LANG_FLAG_1 (node))
378 fputs (" tree_1", file);
379 if (TREE_LANG_FLAG_2 (node))
380 fputs (" tree_2", file);
381 if (TREE_LANG_FLAG_3 (node))
382 fputs (" tree_3", file);
383 if (TREE_LANG_FLAG_4 (node))
384 fputs (" tree_4", file);
385 if (TREE_LANG_FLAG_5 (node))
386 fputs (" tree_5", file);
387 if (TREE_LANG_FLAG_6 (node))
388 fputs (" tree_6", file);
391 /* DECL_ nodes have additional attributes. */
393 switch (TREE_CODE_CLASS (code))
395 case tcc_declaration:
396 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
398 if (DECL_UNSIGNED (node))
399 fputs (" unsigned", file);
400 if (DECL_IGNORED_P (node))
401 fputs (" ignored", file);
402 if (DECL_ABSTRACT_P (node))
403 fputs (" abstract", file);
404 if (DECL_EXTERNAL (node))
405 fputs (" external", file);
406 if (DECL_NONLOCAL (node))
407 fputs (" nonlocal", file);
409 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
411 if (DECL_WEAK (node))
412 fputs (" weak", file);
413 if (DECL_IN_SYSTEM_HEADER (node))
414 fputs (" in_system_header", file);
416 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WRTL)
417 && code != LABEL_DECL
418 && code != FUNCTION_DECL
419 && DECL_REGISTER (node))
420 fputs (" regdecl", file);
422 if (code == TYPE_DECL && TYPE_DECL_SUPPRESS_DEBUG (node))
423 fputs (" suppress-debug", file);
425 if (code == FUNCTION_DECL
426 && DECL_FUNCTION_SPECIFIC_TARGET (node))
427 fputs (" function-specific-target", file);
428 if (code == FUNCTION_DECL
429 && DECL_FUNCTION_SPECIFIC_OPTIMIZATION (node))
430 fputs (" function-specific-opt", file);
431 if (code == FUNCTION_DECL && DECL_DECLARED_INLINE_P (node))
432 fputs (" autoinline", file);
433 if (code == FUNCTION_DECL && DECL_UNINLINABLE (node))
434 fputs (" uninlinable", file);
435 if (code == FUNCTION_DECL && fndecl_built_in_p (node))
436 fputs (" built-in", file);
437 if (code == FUNCTION_DECL && DECL_STATIC_CHAIN (node))
438 fputs (" static-chain", file);
439 if (TREE_CODE (node) == FUNCTION_DECL && decl_is_tm_clone (node))
440 fputs (" tm-clone", file);
442 if (code == FIELD_DECL && DECL_PACKED (node))
443 fputs (" packed", file);
444 if (code == FIELD_DECL && DECL_BIT_FIELD (node))
445 fputs (" bit-field", file);
446 if (code == FIELD_DECL && DECL_NONADDRESSABLE_P (node))
447 fputs (" nonaddressable", file);
449 if (code == LABEL_DECL && EH_LANDING_PAD_NR (node))
450 fprintf (file, " landing-pad:%d", EH_LANDING_PAD_NR (node));
452 if (code == VAR_DECL && DECL_IN_TEXT_SECTION (node))
453 fputs (" in-text-section", file);
454 if (code == VAR_DECL && DECL_IN_CONSTANT_POOL (node))
455 fputs (" in-constant-pool", file);
456 if (code == VAR_DECL && DECL_COMMON (node))
457 fputs (" common", file);
458 if ((code == VAR_DECL || code == PARM_DECL) && DECL_READ_P (node))
459 fputs (" read", file);
460 if (code == VAR_DECL && DECL_THREAD_LOCAL_P (node))
462 fputs (" ", file);
463 fputs (tls_model_names[DECL_TLS_MODEL (node)], file);
466 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
468 if (DECL_VIRTUAL_P (node))
469 fputs (" virtual", file);
470 if (DECL_PRESERVE_P (node))
471 fputs (" preserve", file);
472 if (DECL_LANG_FLAG_0 (node))
473 fputs (" decl_0", file);
474 if (DECL_LANG_FLAG_1 (node))
475 fputs (" decl_1", file);
476 if (DECL_LANG_FLAG_2 (node))
477 fputs (" decl_2", file);
478 if (DECL_LANG_FLAG_3 (node))
479 fputs (" decl_3", file);
480 if (DECL_LANG_FLAG_4 (node))
481 fputs (" decl_4", file);
482 if (DECL_LANG_FLAG_5 (node))
483 fputs (" decl_5", file);
484 if (DECL_LANG_FLAG_6 (node))
485 fputs (" decl_6", file);
486 if (DECL_LANG_FLAG_7 (node))
487 fputs (" decl_7", file);
488 if (DECL_LANG_FLAG_8 (node))
489 fputs (" decl_8", file);
491 mode = DECL_MODE (node);
492 fprintf (file, " %s", GET_MODE_NAME (mode));
495 if ((code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
496 && DECL_BY_REFERENCE (node))
497 fputs (" passed-by-reference", file);
499 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS) && DECL_DEFER_OUTPUT (node))
500 fputs (" defer-output", file);
503 xloc = expand_location (DECL_SOURCE_LOCATION (node));
504 fprintf (file, " %s:%d:%d", xloc.file, xloc.line,
505 xloc.column);
507 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
509 print_node (file, "size", DECL_SIZE (node), indent + 4);
510 print_node (file, "unit-size", DECL_SIZE_UNIT (node), indent + 4);
512 if (code != FUNCTION_DECL || fndecl_built_in_p (node))
513 indent_to (file, indent + 3);
515 if (DECL_USER_ALIGN (node))
516 fprintf (file, " user");
518 fprintf (file, " align:%d warn_if_not_align:%d",
519 DECL_ALIGN (node), DECL_WARN_IF_NOT_ALIGN (node));
520 if (code == FIELD_DECL)
522 fprintf (file, " offset_align " HOST_WIDE_INT_PRINT_UNSIGNED,
523 DECL_OFFSET_ALIGN (node));
524 fprintf (file, " decl_not_flexarray: %d",
525 DECL_NOT_FLEXARRAY (node));
528 if (code == FUNCTION_DECL && fndecl_built_in_p (node))
530 if (DECL_BUILT_IN_CLASS (node) == BUILT_IN_MD)
531 fprintf (file, " built-in: BUILT_IN_MD:%d",
532 DECL_MD_FUNCTION_CODE (node));
533 else if (DECL_BUILT_IN_CLASS (node) == BUILT_IN_FRONTEND)
534 fprintf (file, " built-in: BUILT_IN_FRONTEND:%d",
535 DECL_FE_FUNCTION_CODE (node));
536 else
537 fprintf (file, " built-in: %s:%s",
538 built_in_class_names[(int) DECL_BUILT_IN_CLASS (node)],
539 built_in_names[(int) DECL_FUNCTION_CODE (node)]);
542 if (code == FIELD_DECL)
544 print_node (file, "offset", DECL_FIELD_OFFSET (node), indent + 4);
545 print_node (file, "bit-offset", DECL_FIELD_BIT_OFFSET (node),
546 indent + 4);
547 if (DECL_BIT_FIELD_TYPE (node))
548 print_node (file, "bit_field_type", DECL_BIT_FIELD_TYPE (node),
549 indent + 4);
552 print_node_brief (file, "context", DECL_CONTEXT (node), indent + 4);
554 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
556 print_node (file, "attributes",
557 DECL_ATTRIBUTES (node), indent + 4);
558 if (code != PARM_DECL)
559 print_node_brief (file, "initial", DECL_INITIAL (node),
560 indent + 4);
562 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WRTL))
564 print_node_brief (file, "abstract_origin",
565 DECL_ABSTRACT_ORIGIN (node), indent + 4);
567 if (CODE_CONTAINS_STRUCT (code, TS_DECL_NON_COMMON))
569 print_node (file, "result", DECL_RESULT_FLD (node), indent + 4);
572 lang_hooks.print_decl (file, node, indent);
574 if (DECL_RTL_SET_P (node))
576 indent_to (file, indent + 4);
577 print_rtl (file, DECL_RTL (node));
580 if (code == PARM_DECL)
582 print_node (file, "arg-type", DECL_ARG_TYPE (node), indent + 4);
584 if (DECL_INCOMING_RTL (node) != 0)
586 indent_to (file, indent + 4);
587 fprintf (file, "incoming-rtl ");
588 print_rtl (file, DECL_INCOMING_RTL (node));
591 else if (code == FUNCTION_DECL
592 && DECL_STRUCT_FUNCTION (node) != 0)
594 print_node (file, "arguments", DECL_ARGUMENTS (node), indent + 4);
595 indent_to (file, indent + 4);
596 dump_addr (file, "struct-function ", DECL_STRUCT_FUNCTION (node));
599 if ((code == VAR_DECL || code == PARM_DECL)
600 && DECL_HAS_VALUE_EXPR_P (node))
601 print_node (file, "value-expr", DECL_VALUE_EXPR (node), indent + 4);
603 /* Print the decl chain only if decl is at second level. */
604 if (indent == 4)
605 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
606 else
607 print_node_brief (file, "chain", TREE_CHAIN (node), indent + 4);
608 break;
610 case tcc_type:
611 if (TYPE_UNSIGNED (node))
612 fputs (" unsigned", file);
614 if (TYPE_NO_FORCE_BLK (node))
615 fputs (" no-force-blk", file);
617 if (code == ARRAY_TYPE && TYPE_STRING_FLAG (node))
618 fputs (" string-flag", file);
620 if (TYPE_NEEDS_CONSTRUCTING (node))
621 fputs (" needs-constructing", file);
623 if ((code == RECORD_TYPE
624 || code == UNION_TYPE
625 || code == QUAL_UNION_TYPE
626 || code == ARRAY_TYPE)
627 && TYPE_REVERSE_STORAGE_ORDER (node))
628 fputs (" reverse-storage-order", file);
630 if ((code == RECORD_TYPE
631 || code == UNION_TYPE)
632 && TYPE_CXX_ODR_P (node))
633 fputs (" cxx-odr-p", file);
635 /* The transparent-union flag is used for different things in
636 different nodes. */
637 if ((code == UNION_TYPE || code == RECORD_TYPE)
638 && TYPE_TRANSPARENT_AGGR (node))
639 fputs (" transparent-aggr", file);
640 else if (code == ARRAY_TYPE
641 && TYPE_NONALIASED_COMPONENT (node))
642 fputs (" nonaliased-component", file);
644 if (TYPE_PACKED (node))
645 fputs (" packed", file);
647 if (TYPE_RESTRICT (node))
648 fputs (" restrict", file);
650 if (TYPE_LANG_FLAG_0 (node))
651 fputs (" type_0", file);
652 if (TYPE_LANG_FLAG_1 (node))
653 fputs (" type_1", file);
654 if (TYPE_LANG_FLAG_2 (node))
655 fputs (" type_2", file);
656 if (TYPE_LANG_FLAG_3 (node))
657 fputs (" type_3", file);
658 if (TYPE_LANG_FLAG_4 (node))
659 fputs (" type_4", file);
660 if (TYPE_LANG_FLAG_5 (node))
661 fputs (" type_5", file);
662 if (TYPE_LANG_FLAG_6 (node))
663 fputs (" type_6", file);
664 if (TYPE_LANG_FLAG_7 (node))
665 fputs (" type_7", file);
667 mode = TYPE_MODE (node);
668 fprintf (file, " %s", GET_MODE_NAME (mode));
670 print_node (file, "size", TYPE_SIZE (node), indent + 4);
671 print_node (file, "unit-size", TYPE_SIZE_UNIT (node), indent + 4);
672 indent_to (file, indent + 3);
674 if (TYPE_USER_ALIGN (node))
675 fprintf (file, " user");
677 fprintf (file, " align:%d warn_if_not_align:%d symtab:%d alias-set "
678 HOST_WIDE_INT_PRINT_DEC,
679 TYPE_ALIGN (node), TYPE_WARN_IF_NOT_ALIGN (node),
680 TYPE_SYMTAB_ADDRESS (node),
681 (HOST_WIDE_INT) TYPE_ALIAS_SET (node));
683 if (TYPE_STRUCTURAL_EQUALITY_P (node))
684 fprintf (file, " structural-equality");
685 else
686 dump_addr (file, " canonical-type ", TYPE_CANONICAL (node));
688 print_node (file, "attributes", TYPE_ATTRIBUTES (node), indent + 4);
690 if (INTEGRAL_TYPE_P (node) || code == REAL_TYPE
691 || code == FIXED_POINT_TYPE)
693 fprintf (file, " precision:%d", TYPE_PRECISION (node));
694 print_node_brief (file, "min", TYPE_MIN_VALUE (node), indent + 4);
695 print_node_brief (file, "max", TYPE_MAX_VALUE (node), indent + 4);
698 if (code == ENUMERAL_TYPE)
699 print_node (file, "values", TYPE_VALUES (node), indent + 4);
700 else if (code == ARRAY_TYPE)
701 print_node (file, "domain", TYPE_DOMAIN (node), indent + 4);
702 else if (code == VECTOR_TYPE)
704 fprintf (file, " nunits:");
705 print_dec (TYPE_VECTOR_SUBPARTS (node), file);
707 else if (code == RECORD_TYPE
708 || code == UNION_TYPE
709 || code == QUAL_UNION_TYPE)
710 print_node (file, "fields", TYPE_FIELDS (node), indent + 4);
711 else if (code == FUNCTION_TYPE
712 || code == METHOD_TYPE)
714 if (TYPE_METHOD_BASETYPE (node))
715 print_node_brief (file, "method basetype",
716 TYPE_METHOD_BASETYPE (node), indent + 4);
717 print_node (file, "arg-types", TYPE_ARG_TYPES (node), indent + 4);
719 else if (code == OFFSET_TYPE)
720 print_node_brief (file, "basetype", TYPE_OFFSET_BASETYPE (node),
721 indent + 4);
723 if (TYPE_CONTEXT (node))
724 print_node_brief (file, "context", TYPE_CONTEXT (node), indent + 4);
726 lang_hooks.print_type (file, node, indent);
728 if (TYPE_POINTER_TO (node) || TREE_CHAIN (node))
729 indent_to (file, indent + 3);
731 print_node_brief (file, "pointer_to_this", TYPE_POINTER_TO (node),
732 indent + 4);
733 print_node_brief (file, "reference_to_this", TYPE_REFERENCE_TO (node),
734 indent + 4);
735 print_node_brief (file, "chain", TREE_CHAIN (node), indent + 4);
736 break;
738 case tcc_expression:
739 case tcc_comparison:
740 case tcc_unary:
741 case tcc_binary:
742 case tcc_reference:
743 case tcc_statement:
744 case tcc_vl_exp:
745 if (code == BIND_EXPR)
747 print_node (file, "vars", TREE_OPERAND (node, 0), indent + 4);
748 print_node (file, "body", TREE_OPERAND (node, 1), indent + 4);
749 print_node (file, "block", TREE_OPERAND (node, 2), indent + 4);
750 break;
752 if (code == CALL_EXPR)
754 print_node (file, "fn", CALL_EXPR_FN (node), indent + 4);
755 print_node (file, "static_chain", CALL_EXPR_STATIC_CHAIN (node),
756 indent + 4);
758 call_expr_arg_iterator iter;
759 init_call_expr_arg_iterator (node, &iter);
760 while (more_call_expr_args_p (&iter))
762 /* Buffer big enough to format a 32-bit UINT_MAX into, plus
763 the text. */
764 char temp[15];
765 sprintf (temp, "arg:%u", iter.i);
766 tree arg = next_call_expr_arg (&iter);
767 if (arg)
768 print_node (file, temp, arg, indent + 4);
769 else
771 indent_to (file, indent + 4);
772 fprintf (file, "%s NULL", temp);
776 else
778 len = TREE_OPERAND_LENGTH (node);
780 for (i = 0; i < len; i++)
782 /* Buffer big enough to format a 32-bit UINT_MAX into, plus
783 the text. */
784 char temp[16];
786 sprintf (temp, "arg:%d", i);
787 print_node (file, temp, TREE_OPERAND (node, i), indent + 4);
790 if (CODE_CONTAINS_STRUCT (code, TS_COMMON))
791 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
792 break;
794 case tcc_constant:
795 case tcc_exceptional:
796 switch (code)
798 case INTEGER_CST:
799 if (TREE_OVERFLOW (node))
800 fprintf (file, " overflow");
802 fprintf (file, " ");
803 print_dec (wi::to_wide (node), file, TYPE_SIGN (TREE_TYPE (node)));
804 break;
806 case REAL_CST:
807 print_real_cst (file, node, false);
808 break;
810 case FIXED_CST:
812 FIXED_VALUE_TYPE f;
813 char string[64];
815 if (TREE_OVERFLOW (node))
816 fprintf (file, " overflow");
818 f = TREE_FIXED_CST (node);
819 fixed_to_decimal (string, &f, sizeof (string));
820 fprintf (file, " %s", string);
822 break;
824 case VECTOR_CST:
826 /* Big enough for UINT_MAX plus the string below. */
827 char buf[32];
829 fprintf (file, " npatterns:%u nelts-per-pattern:%u",
830 VECTOR_CST_NPATTERNS (node),
831 VECTOR_CST_NELTS_PER_PATTERN (node));
832 unsigned int count = vector_cst_encoded_nelts (node);
833 for (unsigned int i = 0; i < count; ++i)
835 sprintf (buf, "elt:%u: ", i);
836 print_node (file, buf, VECTOR_CST_ENCODED_ELT (node, i),
837 indent + 4);
840 break;
842 case COMPLEX_CST:
843 print_node (file, "real", TREE_REALPART (node), indent + 4);
844 print_node (file, "imag", TREE_IMAGPART (node), indent + 4);
845 break;
847 case STRING_CST:
849 const char *p = TREE_STRING_POINTER (node);
850 int i = TREE_STRING_LENGTH (node);
851 fputs (" \"", file);
852 while (--i >= 0)
854 char ch = *p++;
855 if (ch >= ' ' && ch < 127)
856 putc (ch, file);
857 else
858 fprintf (file, "\\%03o", ch & 0xFF);
860 fputc ('\"', file);
862 break;
864 case POLY_INT_CST:
866 char buf[10];
867 for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
869 snprintf (buf, sizeof (buf), "elt%u:", i);
870 print_node (file, buf, POLY_INT_CST_COEFF (node, i),
871 indent + 4);
874 break;
876 case IDENTIFIER_NODE:
877 lang_hooks.print_identifier (file, node, indent);
878 break;
880 case TREE_LIST:
881 print_node (file, "purpose", TREE_PURPOSE (node), indent + 4);
882 print_node (file, "value", TREE_VALUE (node), indent + 4);
883 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
884 break;
886 case TREE_VEC:
887 len = TREE_VEC_LENGTH (node);
888 fprintf (file, " length:%d", len);
889 for (i = 0; i < len; i++)
890 if (TREE_VEC_ELT (node, i))
892 /* Buffer big enough to format a 32-bit UINT_MAX into, plus
893 the text. */
894 char temp[16];
895 sprintf (temp, "elt:%d", i);
896 print_node (file, temp, TREE_VEC_ELT (node, i), indent + 4);
898 break;
900 case CONSTRUCTOR:
902 unsigned HOST_WIDE_INT cnt;
903 tree index, value;
904 len = CONSTRUCTOR_NELTS (node);
905 fprintf (file, " length:%d", len);
906 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (node),
907 cnt, index, value)
909 print_node (file, "idx", index, indent + 4, false);
910 print_node (file, "val", value, indent + 4, false);
913 break;
915 case STATEMENT_LIST:
916 dump_addr (file, " head ", node->stmt_list.head);
917 dump_addr (file, " tail ", node->stmt_list.tail);
918 fprintf (file, " stmts");
920 tree_stmt_iterator i;
921 for (i = tsi_start (node); !tsi_end_p (i); tsi_next (&i))
923 /* Not printing the addresses of the (not-a-tree)
924 'struct tree_stmt_list_node's. */
925 dump_addr (file, " ", tsi_stmt (i));
927 fprintf (file, "\n");
928 for (i = tsi_start (node); !tsi_end_p (i); tsi_next (&i))
930 /* Not printing the addresses of the (not-a-tree)
931 'struct tree_stmt_list_node's. */
932 print_node (file, "stmt", tsi_stmt (i), indent + 4);
935 break;
937 case BLOCK:
938 print_node (file, "vars", BLOCK_VARS (node), indent + 4);
939 print_node (file, "supercontext", BLOCK_SUPERCONTEXT (node),
940 indent + 4);
941 print_node (file, "subblocks", BLOCK_SUBBLOCKS (node), indent + 4);
942 print_node (file, "chain", BLOCK_CHAIN (node), indent + 4);
943 print_node (file, "abstract_origin",
944 BLOCK_ABSTRACT_ORIGIN (node), indent + 4);
945 break;
947 case SSA_NAME:
948 print_node_brief (file, "var", SSA_NAME_VAR (node), indent + 4);
949 indent_to (file, indent + 4);
950 fprintf (file, "def_stmt ");
952 pretty_printer buffer;
953 buffer.buffer->stream = file;
954 pp_gimple_stmt_1 (&buffer, SSA_NAME_DEF_STMT (node), indent + 4,
955 TDF_NONE);
956 pp_flush (&buffer);
959 indent_to (file, indent + 4);
960 fprintf (file, "version:%u", SSA_NAME_VERSION (node));
961 if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (node))
962 fprintf (file, " in-abnormal-phi");
963 if (SSA_NAME_IN_FREE_LIST (node))
964 fprintf (file, " in-free-list");
966 if (SSA_NAME_PTR_INFO (node))
968 indent_to (file, indent + 3);
969 if (SSA_NAME_PTR_INFO (node))
970 dump_addr (file, " ptr-info ", SSA_NAME_PTR_INFO (node));
972 break;
974 case OMP_CLAUSE:
976 int i;
977 fprintf (file, " %s",
978 omp_clause_code_name[OMP_CLAUSE_CODE (node)]);
979 for (i = 0; i < omp_clause_num_ops[OMP_CLAUSE_CODE (node)]; i++)
981 indent_to (file, indent + 4);
982 fprintf (file, "op-%d:", i);
983 print_node_brief (file, "", OMP_CLAUSE_OPERAND (node, i), 0);
986 break;
988 case OPTIMIZATION_NODE:
989 cl_optimization_print (file, indent + 4, TREE_OPTIMIZATION (node));
990 break;
992 case TARGET_OPTION_NODE:
993 cl_target_option_print (file, indent + 4, TREE_TARGET_OPTION (node));
994 break;
995 case IMPORTED_DECL:
996 fprintf (file, " imported-declaration");
997 print_node_brief (file, "associated-declaration",
998 IMPORTED_DECL_ASSOCIATED_DECL (node),
999 indent + 4);
1000 break;
1002 case TREE_BINFO:
1003 fprintf (file, " bases:%d",
1004 vec_safe_length (BINFO_BASE_BINFOS (node)));
1005 print_node_brief (file, "offset", BINFO_OFFSET (node), indent + 4);
1006 print_node_brief (file, "virtuals", BINFO_VIRTUALS (node),
1007 indent + 4);
1008 print_node_brief (file, "inheritance-chain",
1009 BINFO_INHERITANCE_CHAIN (node),
1010 indent + 4);
1011 break;
1013 default:
1014 lang_hooks.print_xnode (file, node, indent);
1015 break;
1018 break;
1021 if (EXPR_HAS_LOCATION (node))
1023 expanded_location xloc = expand_location (EXPR_LOCATION (node));
1024 indent_to (file, indent+4);
1025 fprintf (file, "%s:%d:%d", xloc.file, xloc.line, xloc.column);
1027 /* Print the range, if any */
1028 source_range r = EXPR_LOCATION_RANGE (node);
1029 if (r.m_start)
1031 xloc = expand_location (r.m_start);
1032 fprintf (file, " start: %s:%d:%d", xloc.file, xloc.line, xloc.column);
1034 else
1036 fprintf (file, " start: unknown");
1038 if (r.m_finish)
1040 xloc = expand_location (r.m_finish);
1041 fprintf (file, " finish: %s:%d:%d", xloc.file, xloc.line, xloc.column);
1043 else
1045 fprintf (file, " finish: unknown");
1049 fprintf (file, ">");
1052 /* Print the identifier for DECL according to FLAGS. */
1054 void
1055 print_decl_identifier (FILE *file, tree decl, int flags)
1057 bool needs_colon = false;
1058 const char *name;
1059 char c;
1061 if (flags & PRINT_DECL_ORIGIN)
1063 if (DECL_IS_UNDECLARED_BUILTIN (decl))
1064 fputs ("<built-in>", file);
1065 else
1067 expanded_location loc
1068 = expand_location (DECL_SOURCE_LOCATION (decl));
1069 const char *f = flags & PRINT_DECL_REMAP_DEBUG
1070 ? remap_debug_filename (loc.file)
1071 : loc.file;
1072 fprintf (file, "%s:%d:%d", f, loc.line, loc.column);
1074 needs_colon = true;
1077 if (flags & PRINT_DECL_UNIQUE_NAME)
1079 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
1080 if (!TREE_PUBLIC (decl)
1081 || (DECL_WEAK (decl) && !DECL_EXTERNAL (decl)))
1082 /* The symbol has internal or weak linkage so its assembler name
1083 is not necessarily unique among the compilation units of the
1084 program. We therefore have to further mangle it. But we can't
1085 simply use DECL_SOURCE_FILE because it contains the name of the
1086 file the symbol originates from so, e.g. for function templates
1087 in C++ where the templates are defined in a header file, we can
1088 have symbols with the same assembler name and DECL_SOURCE_FILE.
1089 That's why we use the name of the top-level source file of the
1090 compilation unit. ??? Unnecessary for Ada. */
1091 name = ACONCAT ((main_input_filename, ":", name, NULL));
1093 else if (flags & PRINT_DECL_NAME)
1095 /* We don't want to print the full qualified name because it can be long,
1096 so we strip the scope prefix, but we may need to deal with the suffix
1097 created by the compiler. */
1098 const char *suffix = strchr (IDENTIFIER_POINTER (DECL_NAME (decl)), '.');
1099 name = lang_hooks.decl_printable_name (decl, 2);
1100 if (suffix)
1102 const char *dot = strchr (name, '.');
1103 while (dot && strcasecmp (dot, suffix) != 0)
1105 name = dot + 1;
1106 dot = strchr (name, '.');
1109 else
1111 const char *dot = strrchr (name, '.');
1112 if (dot)
1113 name = dot + 1;
1116 else
1117 return;
1119 if (needs_colon)
1120 fputc (':', file);
1122 while ((c = *name++) != '\0')
1124 /* Strip double-quotes because of VCG. */
1125 if (c == '"')
1126 continue;
1127 fputc (c, file);
1132 /* Print the node NODE on standard error, for debugging.
1133 Most nodes referred to by this one are printed recursively
1134 down to a depth of six. */
1136 DEBUG_FUNCTION void
1137 debug_tree (tree node)
1139 table = new hash_set<tree> (HASH_SIZE);
1140 print_node (stderr, "", node, 0);
1141 delete table;
1142 table = NULL;
1143 putc ('\n', stderr);
1146 DEBUG_FUNCTION void
1147 debug_raw (const tree_node &ref)
1149 debug_tree (const_cast <tree> (&ref));
1152 DEBUG_FUNCTION void
1153 debug_raw (const tree_node *ptr)
1155 if (ptr)
1156 debug_raw (*ptr);
1157 else
1158 fprintf (stderr, "<nil>\n");
1161 static void
1162 dump_tree_via_hooks (const tree_node *ptr, dump_flags_t options)
1164 if (DECL_P (ptr))
1165 lang_hooks.print_decl (stderr, const_cast <tree_node*> (ptr), 0);
1166 else if (TYPE_P (ptr))
1167 lang_hooks.print_type (stderr, const_cast <tree_node*> (ptr), 0);
1168 else if (TREE_CODE (ptr) == IDENTIFIER_NODE)
1169 lang_hooks.print_identifier (stderr, const_cast <tree_node*> (ptr), 0);
1170 else
1171 print_generic_expr (stderr, const_cast <tree_node*> (ptr), options);
1172 fprintf (stderr, "\n");
1175 DEBUG_FUNCTION void
1176 debug (const tree_node &ref)
1178 dump_tree_via_hooks (&ref, TDF_NONE);
1181 DEBUG_FUNCTION void
1182 debug (const tree_node *ptr)
1184 if (ptr)
1185 debug (*ptr);
1186 else
1187 fprintf (stderr, "<nil>\n");
1190 DEBUG_FUNCTION void
1191 debug_head (const tree_node &ref)
1193 debug (ref);
1196 DEBUG_FUNCTION void
1197 debug_head (const tree_node *ptr)
1199 if (ptr)
1200 debug_head (*ptr);
1201 else
1202 fprintf (stderr, "<nil>\n");
1205 DEBUG_FUNCTION void
1206 debug_body (const tree_node &ref)
1208 if (TREE_CODE (&ref) == FUNCTION_DECL)
1209 dump_function_to_file (const_cast <tree_node*> (&ref), stderr, TDF_NONE);
1210 else
1211 debug (ref);
1214 DEBUG_FUNCTION void
1215 debug_body (const tree_node *ptr)
1217 if (ptr)
1218 debug_body (*ptr);
1219 else
1220 fprintf (stderr, "<nil>\n");
1223 /* Print the vector of trees VEC on standard error, for debugging.
1224 Most nodes referred to by this one are printed recursively
1225 down to a depth of six. */
1227 DEBUG_FUNCTION void
1228 debug_raw (vec<tree, va_gc> &ref)
1230 tree elt;
1231 unsigned ix;
1233 /* Print the slot this node is in, and its code, and address. */
1234 fprintf (stderr, "<VEC");
1235 dump_addr (stderr, " ", ref.address ());
1237 FOR_EACH_VEC_ELT (ref, ix, elt)
1239 fprintf (stderr, "elt:%d ", ix);
1240 debug_raw (elt);
1244 DEBUG_FUNCTION void
1245 debug_raw (vec<tree, va_gc> *ptr)
1247 if (ptr)
1248 debug_raw (*ptr);
1249 else
1250 fprintf (stderr, "<nil>\n");
1253 static void
1254 debug_slim (tree t)
1256 print_node_brief (stderr, "", t, 0);
1259 DEFINE_DEBUG_VEC (tree)
1260 DEFINE_DEBUG_HASH_SET (tree)