Suppress -fstack-protector warning on hppa.
[official-gcc.git] / gcc / print-tree.cc
blob58a98250cc4f74d1aaa0541ba4d5c0269c8c3192
1 /* Prints out tree in human readable form - GCC
2 Copyright (C) 1990-2022 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 to FILE a NODE representing a REAL_CST constant, including
56 Infinity and NaN. Be verbose when BFRIEF is false. */
58 static void
59 print_real_cst (FILE *file, const_tree node, bool brief)
61 if (TREE_OVERFLOW (node))
62 fprintf (file, " overflow");
64 REAL_VALUE_TYPE d = TREE_REAL_CST (node);
65 if (REAL_VALUE_ISINF (d))
66 fprintf (file, REAL_VALUE_NEGATIVE (d) ? " -Inf" : " Inf");
67 else if (REAL_VALUE_ISNAN (d))
69 /* Print a NaN in the format [-][Q]NaN[(significand[exponent])]
70 where significand is a hexadecimal string that starts with
71 the 0x prefix followed by 0 if the number is not canonical
72 and a non-zero digit if it is, and exponent is decimal. */
73 unsigned start = 0;
74 const char *psig = (const char *) d.sig;
75 for (unsigned i = 0; i != sizeof d.sig; ++i)
76 if (psig[i])
78 start = i;
79 break;
82 fprintf (file, " %s%sNaN", d.sign ? "-" : "",
83 d.signalling ? "S" : "Q");
85 if (brief)
86 return;
88 if (start)
89 fprintf (file, "(0x%s", d.canonical ? "" : "0");
90 else if (d.uexp)
91 fprintf (file, "(%s", d.canonical ? "" : "0");
92 else if (!d.canonical)
94 fprintf (file, "(0)");
95 return;
98 if (psig[start])
100 for (unsigned i = start; i != sizeof d.sig; ++i)
101 if (i == start)
102 fprintf (file, "%x", psig[i]);
103 else
104 fprintf (file, "%02x", psig[i]);
107 if (d.uexp)
108 fprintf (file, "%se%u)", psig[start] ? "," : "", d.uexp);
109 else if (psig[start])
110 fputc (')', file);
112 else
114 char string[64];
115 real_to_decimal (string, &d, sizeof (string), 0, 1);
116 fprintf (file, " %s", string);
120 /* Print a node in brief fashion, with just the code, address and name. */
122 void
123 print_node_brief (FILE *file, const char *prefix, const_tree node, int indent)
125 enum tree_code_class tclass;
127 if (node == 0)
128 return;
130 tclass = TREE_CODE_CLASS (TREE_CODE (node));
132 /* Always print the slot this node is in, and its code, address and
133 name if any. */
134 if (indent > 0)
135 fprintf (file, " ");
136 fprintf (file, "%s <%s", prefix, get_tree_code_name (TREE_CODE (node)));
137 dump_addr (file, " ", node);
139 if (tclass == tcc_declaration)
141 if (DECL_NAME (node))
142 fprintf (file, " %s", IDENTIFIER_POINTER (DECL_NAME (node)));
143 else if (TREE_CODE (node) == LABEL_DECL
144 && LABEL_DECL_UID (node) != -1)
146 if (dump_flags & TDF_NOUID)
147 fprintf (file, " L.xxxx");
148 else
149 fprintf (file, " L.%d", (int) LABEL_DECL_UID (node));
151 else
153 if (dump_flags & TDF_NOUID)
154 fprintf (file, " %c.xxxx",
155 TREE_CODE (node) == CONST_DECL ? 'C' : 'D');
156 else
157 fprintf (file, " %c.%u",
158 TREE_CODE (node) == CONST_DECL ? 'C' : 'D',
159 DECL_UID (node));
162 else if (tclass == tcc_type)
164 if (TYPE_NAME (node))
166 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
167 fprintf (file, " %s", IDENTIFIER_POINTER (TYPE_NAME (node)));
168 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
169 && DECL_NAME (TYPE_NAME (node)))
170 fprintf (file, " %s",
171 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node))));
173 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (node)))
174 fprintf (file, " address-space-%d", TYPE_ADDR_SPACE (node));
176 if (TREE_CODE (node) == IDENTIFIER_NODE)
177 fprintf (file, " %s", IDENTIFIER_POINTER (node));
179 /* We might as well always print the value of an integer or real. */
180 if (TREE_CODE (node) == INTEGER_CST)
182 if (TREE_OVERFLOW (node))
183 fprintf (file, " overflow");
185 fprintf (file, " ");
186 print_dec (wi::to_wide (node), file, TYPE_SIGN (TREE_TYPE (node)));
188 if (TREE_CODE (node) == REAL_CST)
189 print_real_cst (file, node, true);
190 if (TREE_CODE (node) == FIXED_CST)
192 FIXED_VALUE_TYPE f;
193 char string[60];
195 if (TREE_OVERFLOW (node))
196 fprintf (file, " overflow");
198 f = TREE_FIXED_CST (node);
199 fixed_to_decimal (string, &f, sizeof (string));
200 fprintf (file, " %s", string);
203 fprintf (file, ">");
206 void
207 indent_to (FILE *file, int column)
209 int i;
211 /* Since this is the long way, indent to desired column. */
212 if (column > 0)
213 fprintf (file, "\n");
214 for (i = 0; i < column; i++)
215 fprintf (file, " ");
218 /* Print the node NODE in full on file FILE, preceded by PREFIX,
219 starting in column INDENT. */
221 void
222 print_node (FILE *file, const char *prefix, tree node, int indent,
223 bool brief_for_visited)
225 machine_mode mode;
226 enum tree_code_class tclass;
227 int len;
228 int i;
229 expanded_location xloc;
230 enum tree_code code;
232 if (node == 0)
233 return;
235 code = TREE_CODE (node);
237 /* It is unsafe to look at any other fields of a node with ERROR_MARK or
238 invalid code. */
239 if (code == ERROR_MARK || code >= MAX_TREE_CODES)
241 print_node_brief (file, prefix, node, indent);
242 return;
245 tclass = TREE_CODE_CLASS (code);
247 /* Don't get too deep in nesting. If the user wants to see deeper,
248 it is easy to use the address of a lowest-level node
249 as an argument in another call to debug_tree. */
251 if (indent > 24)
253 print_node_brief (file, prefix, node, indent);
254 return;
257 if (indent > 8 && (tclass == tcc_type || tclass == tcc_declaration))
259 print_node_brief (file, prefix, node, indent);
260 return;
263 /* Allow this function to be called if the table is not there. */
264 if (table)
266 /* If node is in the table, just mention its address. */
267 if (table->contains (node) && brief_for_visited)
269 print_node_brief (file, prefix, node, indent);
270 return;
273 table->add (node);
276 /* Indent to the specified column, since this is the long form. */
277 indent_to (file, indent);
279 /* Print the slot this node is in, and its code, and address. */
280 fprintf (file, "%s <%s", prefix, get_tree_code_name (code));
281 dump_addr (file, " ", node);
283 /* Print the name, if any. */
284 if (tclass == tcc_declaration)
286 if (DECL_NAME (node))
287 fprintf (file, " %s", IDENTIFIER_POINTER (DECL_NAME (node)));
288 else if (code == LABEL_DECL
289 && LABEL_DECL_UID (node) != -1)
291 if (dump_flags & TDF_NOUID)
292 fprintf (file, " L.xxxx");
293 else
294 fprintf (file, " L.%d", (int) LABEL_DECL_UID (node));
296 else
298 if (dump_flags & TDF_NOUID)
299 fprintf (file, " %c.xxxx", code == CONST_DECL ? 'C' : 'D');
300 else
301 fprintf (file, " %c.%u", code == CONST_DECL ? 'C' : 'D',
302 DECL_UID (node));
305 else if (tclass == tcc_type)
307 if (TYPE_NAME (node))
309 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
310 fprintf (file, " %s", IDENTIFIER_POINTER (TYPE_NAME (node)));
311 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
312 && DECL_NAME (TYPE_NAME (node)))
313 fprintf (file, " %s",
314 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node))));
317 if (code == IDENTIFIER_NODE)
318 fprintf (file, " %s", IDENTIFIER_POINTER (node));
320 if (code == INTEGER_CST)
322 if (indent <= 4)
323 print_node_brief (file, "type", TREE_TYPE (node), indent + 4);
325 else if (CODE_CONTAINS_STRUCT (code, TS_TYPED))
327 print_node (file, "type", TREE_TYPE (node), indent + 4);
328 if (TREE_TYPE (node))
329 indent_to (file, indent + 3);
332 if (!TYPE_P (node) && TREE_SIDE_EFFECTS (node))
333 fputs (" side-effects", file);
335 if (TYPE_P (node) ? TYPE_READONLY (node) : TREE_READONLY (node))
336 fputs (" readonly", file);
337 if (TYPE_P (node) && TYPE_ATOMIC (node))
338 fputs (" atomic", file);
339 if (!TYPE_P (node) && TREE_CONSTANT (node))
340 fputs (" constant", file);
341 else if (TYPE_P (node) && TYPE_SIZES_GIMPLIFIED (node))
342 fputs (" sizes-gimplified", file);
344 if (TYPE_P (node) && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (node)))
345 fprintf (file, " address-space-%d", TYPE_ADDR_SPACE (node));
347 if (TREE_ADDRESSABLE (node))
348 fputs (" addressable", file);
349 if (TREE_THIS_VOLATILE (node))
350 fputs (" volatile", file);
351 if (TREE_ASM_WRITTEN (node))
352 fputs (" asm_written", file);
353 if (TREE_USED (node))
354 fputs (" used", file);
355 if (TREE_NOTHROW (node))
356 fputs (" nothrow", file);
357 if (TREE_PUBLIC (node))
358 fputs (" public", file);
359 if (TREE_PRIVATE (node))
360 fputs (" private", file);
361 if (TREE_PROTECTED (node))
362 fputs (" protected", file);
363 if (TREE_STATIC (node))
364 fputs (code == CALL_EXPR ? " must-tail-call" : " static", file);
365 if (TREE_DEPRECATED (node))
366 fputs (" deprecated", file);
367 if (TREE_UNAVAILABLE (node))
368 fputs (" unavailable", file);
369 if (TREE_VISITED (node))
370 fputs (" visited", file);
372 if (code != TREE_VEC && code != INTEGER_CST && code != SSA_NAME)
374 if (TREE_LANG_FLAG_0 (node))
375 fputs (" tree_0", file);
376 if (TREE_LANG_FLAG_1 (node))
377 fputs (" tree_1", file);
378 if (TREE_LANG_FLAG_2 (node))
379 fputs (" tree_2", file);
380 if (TREE_LANG_FLAG_3 (node))
381 fputs (" tree_3", file);
382 if (TREE_LANG_FLAG_4 (node))
383 fputs (" tree_4", file);
384 if (TREE_LANG_FLAG_5 (node))
385 fputs (" tree_5", file);
386 if (TREE_LANG_FLAG_6 (node))
387 fputs (" tree_6", file);
390 /* DECL_ nodes have additional attributes. */
392 switch (TREE_CODE_CLASS (code))
394 case tcc_declaration:
395 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
397 if (DECL_UNSIGNED (node))
398 fputs (" unsigned", file);
399 if (DECL_IGNORED_P (node))
400 fputs (" ignored", file);
401 if (DECL_ABSTRACT_P (node))
402 fputs (" abstract", file);
403 if (DECL_EXTERNAL (node))
404 fputs (" external", file);
405 if (DECL_NONLOCAL (node))
406 fputs (" nonlocal", file);
408 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
410 if (DECL_WEAK (node))
411 fputs (" weak", file);
412 if (DECL_IN_SYSTEM_HEADER (node))
413 fputs (" in_system_header", file);
415 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WRTL)
416 && code != LABEL_DECL
417 && code != FUNCTION_DECL
418 && DECL_REGISTER (node))
419 fputs (" regdecl", file);
421 if (code == TYPE_DECL && TYPE_DECL_SUPPRESS_DEBUG (node))
422 fputs (" suppress-debug", file);
424 if (code == FUNCTION_DECL
425 && DECL_FUNCTION_SPECIFIC_TARGET (node))
426 fputs (" function-specific-target", file);
427 if (code == FUNCTION_DECL
428 && DECL_FUNCTION_SPECIFIC_OPTIMIZATION (node))
429 fputs (" function-specific-opt", file);
430 if (code == FUNCTION_DECL && DECL_DECLARED_INLINE_P (node))
431 fputs (" autoinline", file);
432 if (code == FUNCTION_DECL && DECL_UNINLINABLE (node))
433 fputs (" uninlinable", file);
434 if (code == FUNCTION_DECL && fndecl_built_in_p (node))
435 fputs (" built-in", file);
436 if (code == FUNCTION_DECL && DECL_STATIC_CHAIN (node))
437 fputs (" static-chain", file);
438 if (TREE_CODE (node) == FUNCTION_DECL && decl_is_tm_clone (node))
439 fputs (" tm-clone", file);
441 if (code == FIELD_DECL && DECL_PACKED (node))
442 fputs (" packed", file);
443 if (code == FIELD_DECL && DECL_BIT_FIELD (node))
444 fputs (" bit-field", file);
445 if (code == FIELD_DECL && DECL_NONADDRESSABLE_P (node))
446 fputs (" nonaddressable", file);
448 if (code == LABEL_DECL && EH_LANDING_PAD_NR (node))
449 fprintf (file, " landing-pad:%d", EH_LANDING_PAD_NR (node));
451 if (code == VAR_DECL && DECL_IN_TEXT_SECTION (node))
452 fputs (" in-text-section", file);
453 if (code == VAR_DECL && DECL_IN_CONSTANT_POOL (node))
454 fputs (" in-constant-pool", file);
455 if (code == VAR_DECL && DECL_COMMON (node))
456 fputs (" common", file);
457 if ((code == VAR_DECL || code == PARM_DECL) && DECL_READ_P (node))
458 fputs (" read", file);
459 if (code == VAR_DECL && DECL_THREAD_LOCAL_P (node))
461 fputs (" ", file);
462 fputs (tls_model_names[DECL_TLS_MODEL (node)], file);
465 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
467 if (DECL_VIRTUAL_P (node))
468 fputs (" virtual", file);
469 if (DECL_PRESERVE_P (node))
470 fputs (" preserve", file);
471 if (DECL_LANG_FLAG_0 (node))
472 fputs (" decl_0", file);
473 if (DECL_LANG_FLAG_1 (node))
474 fputs (" decl_1", file);
475 if (DECL_LANG_FLAG_2 (node))
476 fputs (" decl_2", file);
477 if (DECL_LANG_FLAG_3 (node))
478 fputs (" decl_3", file);
479 if (DECL_LANG_FLAG_4 (node))
480 fputs (" decl_4", file);
481 if (DECL_LANG_FLAG_5 (node))
482 fputs (" decl_5", file);
483 if (DECL_LANG_FLAG_6 (node))
484 fputs (" decl_6", file);
485 if (DECL_LANG_FLAG_7 (node))
486 fputs (" decl_7", file);
487 if (DECL_LANG_FLAG_8 (node))
488 fputs (" decl_8", file);
490 mode = DECL_MODE (node);
491 fprintf (file, " %s", GET_MODE_NAME (mode));
494 if ((code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
495 && DECL_BY_REFERENCE (node))
496 fputs (" passed-by-reference", file);
498 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS) && DECL_DEFER_OUTPUT (node))
499 fputs (" defer-output", file);
502 xloc = expand_location (DECL_SOURCE_LOCATION (node));
503 fprintf (file, " %s:%d:%d", xloc.file, xloc.line,
504 xloc.column);
506 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
508 print_node (file, "size", DECL_SIZE (node), indent + 4);
509 print_node (file, "unit-size", DECL_SIZE_UNIT (node), indent + 4);
511 if (code != FUNCTION_DECL || fndecl_built_in_p (node))
512 indent_to (file, indent + 3);
514 if (DECL_USER_ALIGN (node))
515 fprintf (file, " user");
517 fprintf (file, " align:%d warn_if_not_align:%d",
518 DECL_ALIGN (node), DECL_WARN_IF_NOT_ALIGN (node));
519 if (code == FIELD_DECL)
521 fprintf (file, " offset_align " HOST_WIDE_INT_PRINT_UNSIGNED,
522 DECL_OFFSET_ALIGN (node));
523 fprintf (file, " decl_not_flexarray: %d",
524 DECL_NOT_FLEXARRAY (node));
527 if (code == FUNCTION_DECL && fndecl_built_in_p (node))
529 if (DECL_BUILT_IN_CLASS (node) == BUILT_IN_MD)
530 fprintf (file, " built-in: BUILT_IN_MD:%d",
531 DECL_MD_FUNCTION_CODE (node));
532 else if (DECL_BUILT_IN_CLASS (node) == BUILT_IN_FRONTEND)
533 fprintf (file, " built-in: BUILT_IN_FRONTEND:%d",
534 DECL_FE_FUNCTION_CODE (node));
535 else
536 fprintf (file, " built-in: %s:%s",
537 built_in_class_names[(int) DECL_BUILT_IN_CLASS (node)],
538 built_in_names[(int) DECL_FUNCTION_CODE (node)]);
541 if (code == FIELD_DECL)
543 print_node (file, "offset", DECL_FIELD_OFFSET (node), indent + 4);
544 print_node (file, "bit-offset", DECL_FIELD_BIT_OFFSET (node),
545 indent + 4);
546 if (DECL_BIT_FIELD_TYPE (node))
547 print_node (file, "bit_field_type", DECL_BIT_FIELD_TYPE (node),
548 indent + 4);
551 print_node_brief (file, "context", DECL_CONTEXT (node), indent + 4);
553 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
555 print_node (file, "attributes",
556 DECL_ATTRIBUTES (node), indent + 4);
557 if (code != PARM_DECL)
558 print_node_brief (file, "initial", DECL_INITIAL (node),
559 indent + 4);
561 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WRTL))
563 print_node_brief (file, "abstract_origin",
564 DECL_ABSTRACT_ORIGIN (node), indent + 4);
566 if (CODE_CONTAINS_STRUCT (code, TS_DECL_NON_COMMON))
568 print_node (file, "result", DECL_RESULT_FLD (node), indent + 4);
571 lang_hooks.print_decl (file, node, indent);
573 if (DECL_RTL_SET_P (node))
575 indent_to (file, indent + 4);
576 print_rtl (file, DECL_RTL (node));
579 if (code == PARM_DECL)
581 print_node (file, "arg-type", DECL_ARG_TYPE (node), indent + 4);
583 if (DECL_INCOMING_RTL (node) != 0)
585 indent_to (file, indent + 4);
586 fprintf (file, "incoming-rtl ");
587 print_rtl (file, DECL_INCOMING_RTL (node));
590 else if (code == FUNCTION_DECL
591 && DECL_STRUCT_FUNCTION (node) != 0)
593 print_node (file, "arguments", DECL_ARGUMENTS (node), indent + 4);
594 indent_to (file, indent + 4);
595 dump_addr (file, "struct-function ", DECL_STRUCT_FUNCTION (node));
598 if ((code == VAR_DECL || code == PARM_DECL)
599 && DECL_HAS_VALUE_EXPR_P (node))
600 print_node (file, "value-expr", DECL_VALUE_EXPR (node), indent + 4);
602 /* Print the decl chain only if decl is at second level. */
603 if (indent == 4)
604 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
605 else
606 print_node_brief (file, "chain", TREE_CHAIN (node), indent + 4);
607 break;
609 case tcc_type:
610 if (TYPE_UNSIGNED (node))
611 fputs (" unsigned", file);
613 if (TYPE_NO_FORCE_BLK (node))
614 fputs (" no-force-blk", file);
616 if (code == ARRAY_TYPE && TYPE_STRING_FLAG (node))
617 fputs (" string-flag", file);
619 if (TYPE_NEEDS_CONSTRUCTING (node))
620 fputs (" needs-constructing", file);
622 if ((code == RECORD_TYPE
623 || code == UNION_TYPE
624 || code == QUAL_UNION_TYPE
625 || code == ARRAY_TYPE)
626 && TYPE_REVERSE_STORAGE_ORDER (node))
627 fputs (" reverse-storage-order", file);
629 if ((code == RECORD_TYPE
630 || code == UNION_TYPE)
631 && TYPE_CXX_ODR_P (node))
632 fputs (" cxx-odr-p", file);
634 /* The transparent-union flag is used for different things in
635 different nodes. */
636 if ((code == UNION_TYPE || code == RECORD_TYPE)
637 && TYPE_TRANSPARENT_AGGR (node))
638 fputs (" transparent-aggr", file);
639 else if (code == ARRAY_TYPE
640 && TYPE_NONALIASED_COMPONENT (node))
641 fputs (" nonaliased-component", file);
643 if (TYPE_PACKED (node))
644 fputs (" packed", file);
646 if (TYPE_RESTRICT (node))
647 fputs (" restrict", file);
649 if (TYPE_LANG_FLAG_0 (node))
650 fputs (" type_0", file);
651 if (TYPE_LANG_FLAG_1 (node))
652 fputs (" type_1", file);
653 if (TYPE_LANG_FLAG_2 (node))
654 fputs (" type_2", file);
655 if (TYPE_LANG_FLAG_3 (node))
656 fputs (" type_3", file);
657 if (TYPE_LANG_FLAG_4 (node))
658 fputs (" type_4", file);
659 if (TYPE_LANG_FLAG_5 (node))
660 fputs (" type_5", file);
661 if (TYPE_LANG_FLAG_6 (node))
662 fputs (" type_6", file);
663 if (TYPE_LANG_FLAG_7 (node))
664 fputs (" type_7", file);
666 mode = TYPE_MODE (node);
667 fprintf (file, " %s", GET_MODE_NAME (mode));
669 print_node (file, "size", TYPE_SIZE (node), indent + 4);
670 print_node (file, "unit-size", TYPE_SIZE_UNIT (node), indent + 4);
671 indent_to (file, indent + 3);
673 if (TYPE_USER_ALIGN (node))
674 fprintf (file, " user");
676 fprintf (file, " align:%d warn_if_not_align:%d symtab:%d alias-set "
677 HOST_WIDE_INT_PRINT_DEC,
678 TYPE_ALIGN (node), TYPE_WARN_IF_NOT_ALIGN (node),
679 TYPE_SYMTAB_ADDRESS (node),
680 (HOST_WIDE_INT) TYPE_ALIAS_SET (node));
682 if (TYPE_STRUCTURAL_EQUALITY_P (node))
683 fprintf (file, " structural-equality");
684 else
685 dump_addr (file, " canonical-type ", TYPE_CANONICAL (node));
687 print_node (file, "attributes", TYPE_ATTRIBUTES (node), indent + 4);
689 if (INTEGRAL_TYPE_P (node) || code == REAL_TYPE
690 || code == FIXED_POINT_TYPE)
692 fprintf (file, " precision:%d", TYPE_PRECISION (node));
693 print_node_brief (file, "min", TYPE_MIN_VALUE (node), indent + 4);
694 print_node_brief (file, "max", TYPE_MAX_VALUE (node), indent + 4);
697 if (code == ENUMERAL_TYPE)
698 print_node (file, "values", TYPE_VALUES (node), indent + 4);
699 else if (code == ARRAY_TYPE)
700 print_node (file, "domain", TYPE_DOMAIN (node), indent + 4);
701 else if (code == VECTOR_TYPE)
703 fprintf (file, " nunits:");
704 print_dec (TYPE_VECTOR_SUBPARTS (node), file);
706 else if (code == RECORD_TYPE
707 || code == UNION_TYPE
708 || code == QUAL_UNION_TYPE)
709 print_node (file, "fields", TYPE_FIELDS (node), indent + 4);
710 else if (code == FUNCTION_TYPE
711 || code == METHOD_TYPE)
713 if (TYPE_METHOD_BASETYPE (node))
714 print_node_brief (file, "method basetype",
715 TYPE_METHOD_BASETYPE (node), indent + 4);
716 print_node (file, "arg-types", TYPE_ARG_TYPES (node), indent + 4);
718 else if (code == OFFSET_TYPE)
719 print_node_brief (file, "basetype", TYPE_OFFSET_BASETYPE (node),
720 indent + 4);
722 if (TYPE_CONTEXT (node))
723 print_node_brief (file, "context", TYPE_CONTEXT (node), indent + 4);
725 lang_hooks.print_type (file, node, indent);
727 if (TYPE_POINTER_TO (node) || TREE_CHAIN (node))
728 indent_to (file, indent + 3);
730 print_node_brief (file, "pointer_to_this", TYPE_POINTER_TO (node),
731 indent + 4);
732 print_node_brief (file, "reference_to_this", TYPE_REFERENCE_TO (node),
733 indent + 4);
734 print_node_brief (file, "chain", TREE_CHAIN (node), indent + 4);
735 break;
737 case tcc_expression:
738 case tcc_comparison:
739 case tcc_unary:
740 case tcc_binary:
741 case tcc_reference:
742 case tcc_statement:
743 case tcc_vl_exp:
744 if (code == BIND_EXPR)
746 print_node (file, "vars", TREE_OPERAND (node, 0), indent + 4);
747 print_node (file, "body", TREE_OPERAND (node, 1), indent + 4);
748 print_node (file, "block", TREE_OPERAND (node, 2), indent + 4);
749 break;
751 if (code == CALL_EXPR)
753 print_node (file, "fn", CALL_EXPR_FN (node), indent + 4);
754 print_node (file, "static_chain", CALL_EXPR_STATIC_CHAIN (node),
755 indent + 4);
757 call_expr_arg_iterator iter;
758 init_call_expr_arg_iterator (node, &iter);
759 while (more_call_expr_args_p (&iter))
761 /* Buffer big enough to format a 32-bit UINT_MAX into, plus
762 the text. */
763 char temp[15];
764 sprintf (temp, "arg:%u", iter.i);
765 tree arg = next_call_expr_arg (&iter);
766 if (arg)
767 print_node (file, temp, arg, indent + 4);
768 else
770 indent_to (file, indent + 4);
771 fprintf (file, "%s NULL", temp);
775 else
777 len = TREE_OPERAND_LENGTH (node);
779 for (i = 0; i < len; i++)
781 /* Buffer big enough to format a 32-bit UINT_MAX into, plus
782 the text. */
783 char temp[16];
785 sprintf (temp, "arg:%d", i);
786 print_node (file, temp, TREE_OPERAND (node, i), indent + 4);
789 if (CODE_CONTAINS_STRUCT (code, TS_COMMON))
790 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
791 break;
793 case tcc_constant:
794 case tcc_exceptional:
795 switch (code)
797 case INTEGER_CST:
798 if (TREE_OVERFLOW (node))
799 fprintf (file, " overflow");
801 fprintf (file, " ");
802 print_dec (wi::to_wide (node), file, TYPE_SIGN (TREE_TYPE (node)));
803 break;
805 case REAL_CST:
806 print_real_cst (file, node, false);
807 break;
809 case FIXED_CST:
811 FIXED_VALUE_TYPE f;
812 char string[64];
814 if (TREE_OVERFLOW (node))
815 fprintf (file, " overflow");
817 f = TREE_FIXED_CST (node);
818 fixed_to_decimal (string, &f, sizeof (string));
819 fprintf (file, " %s", string);
821 break;
823 case VECTOR_CST:
825 /* Big enough for UINT_MAX plus the string below. */
826 char buf[32];
828 fprintf (file, " npatterns:%u nelts-per-pattern:%u",
829 VECTOR_CST_NPATTERNS (node),
830 VECTOR_CST_NELTS_PER_PATTERN (node));
831 unsigned int count = vector_cst_encoded_nelts (node);
832 for (unsigned int i = 0; i < count; ++i)
834 sprintf (buf, "elt:%u: ", i);
835 print_node (file, buf, VECTOR_CST_ENCODED_ELT (node, i),
836 indent + 4);
839 break;
841 case COMPLEX_CST:
842 print_node (file, "real", TREE_REALPART (node), indent + 4);
843 print_node (file, "imag", TREE_IMAGPART (node), indent + 4);
844 break;
846 case STRING_CST:
848 const char *p = TREE_STRING_POINTER (node);
849 int i = TREE_STRING_LENGTH (node);
850 fputs (" \"", file);
851 while (--i >= 0)
853 char ch = *p++;
854 if (ch >= ' ' && ch < 127)
855 putc (ch, file);
856 else
857 fprintf (file, "\\%03o", ch & 0xFF);
859 fputc ('\"', file);
861 break;
863 case POLY_INT_CST:
865 char buf[10];
866 for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
868 snprintf (buf, sizeof (buf), "elt%u:", i);
869 print_node (file, buf, POLY_INT_CST_COEFF (node, i),
870 indent + 4);
873 break;
875 case IDENTIFIER_NODE:
876 lang_hooks.print_identifier (file, node, indent);
877 break;
879 case TREE_LIST:
880 print_node (file, "purpose", TREE_PURPOSE (node), indent + 4);
881 print_node (file, "value", TREE_VALUE (node), indent + 4);
882 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
883 break;
885 case TREE_VEC:
886 len = TREE_VEC_LENGTH (node);
887 fprintf (file, " length:%d", len);
888 for (i = 0; i < len; i++)
889 if (TREE_VEC_ELT (node, i))
891 /* Buffer big enough to format a 32-bit UINT_MAX into, plus
892 the text. */
893 char temp[16];
894 sprintf (temp, "elt:%d", i);
895 print_node (file, temp, TREE_VEC_ELT (node, i), indent + 4);
897 break;
899 case CONSTRUCTOR:
901 unsigned HOST_WIDE_INT cnt;
902 tree index, value;
903 len = CONSTRUCTOR_NELTS (node);
904 fprintf (file, " length:%d", len);
905 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (node),
906 cnt, index, value)
908 print_node (file, "idx", index, indent + 4, false);
909 print_node (file, "val", value, indent + 4, false);
912 break;
914 case STATEMENT_LIST:
915 dump_addr (file, " head ", node->stmt_list.head);
916 dump_addr (file, " tail ", node->stmt_list.tail);
917 fprintf (file, " stmts");
919 tree_stmt_iterator i;
920 for (i = tsi_start (node); !tsi_end_p (i); tsi_next (&i))
922 /* Not printing the addresses of the (not-a-tree)
923 'struct tree_stmt_list_node's. */
924 dump_addr (file, " ", tsi_stmt (i));
926 fprintf (file, "\n");
927 for (i = tsi_start (node); !tsi_end_p (i); tsi_next (&i))
929 /* Not printing the addresses of the (not-a-tree)
930 'struct tree_stmt_list_node's. */
931 print_node (file, "stmt", tsi_stmt (i), indent + 4);
934 break;
936 case BLOCK:
937 print_node (file, "vars", BLOCK_VARS (node), indent + 4);
938 print_node (file, "supercontext", BLOCK_SUPERCONTEXT (node),
939 indent + 4);
940 print_node (file, "subblocks", BLOCK_SUBBLOCKS (node), indent + 4);
941 print_node (file, "chain", BLOCK_CHAIN (node), indent + 4);
942 print_node (file, "abstract_origin",
943 BLOCK_ABSTRACT_ORIGIN (node), indent + 4);
944 break;
946 case SSA_NAME:
947 print_node_brief (file, "var", SSA_NAME_VAR (node), indent + 4);
948 indent_to (file, indent + 4);
949 fprintf (file, "def_stmt ");
951 pretty_printer buffer;
952 buffer.buffer->stream = file;
953 pp_gimple_stmt_1 (&buffer, SSA_NAME_DEF_STMT (node), indent + 4,
954 TDF_NONE);
955 pp_flush (&buffer);
958 indent_to (file, indent + 4);
959 fprintf (file, "version:%u", SSA_NAME_VERSION (node));
960 if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (node))
961 fprintf (file, " in-abnormal-phi");
962 if (SSA_NAME_IN_FREE_LIST (node))
963 fprintf (file, " in-free-list");
965 if (SSA_NAME_PTR_INFO (node))
967 indent_to (file, indent + 3);
968 if (SSA_NAME_PTR_INFO (node))
969 dump_addr (file, " ptr-info ", SSA_NAME_PTR_INFO (node));
971 break;
973 case OMP_CLAUSE:
975 int i;
976 fprintf (file, " %s",
977 omp_clause_code_name[OMP_CLAUSE_CODE (node)]);
978 for (i = 0; i < omp_clause_num_ops[OMP_CLAUSE_CODE (node)]; i++)
980 indent_to (file, indent + 4);
981 fprintf (file, "op-%d:", i);
982 print_node_brief (file, "", OMP_CLAUSE_OPERAND (node, i), 0);
985 break;
987 case OPTIMIZATION_NODE:
988 cl_optimization_print (file, indent + 4, TREE_OPTIMIZATION (node));
989 break;
991 case TARGET_OPTION_NODE:
992 cl_target_option_print (file, indent + 4, TREE_TARGET_OPTION (node));
993 break;
994 case IMPORTED_DECL:
995 fprintf (file, " imported-declaration");
996 print_node_brief (file, "associated-declaration",
997 IMPORTED_DECL_ASSOCIATED_DECL (node),
998 indent + 4);
999 break;
1001 case TREE_BINFO:
1002 fprintf (file, " bases:%d",
1003 vec_safe_length (BINFO_BASE_BINFOS (node)));
1004 print_node_brief (file, "offset", BINFO_OFFSET (node), indent + 4);
1005 print_node_brief (file, "virtuals", BINFO_VIRTUALS (node),
1006 indent + 4);
1007 print_node_brief (file, "inheritance-chain",
1008 BINFO_INHERITANCE_CHAIN (node),
1009 indent + 4);
1010 break;
1012 default:
1013 lang_hooks.print_xnode (file, node, indent);
1014 break;
1017 break;
1020 if (EXPR_HAS_LOCATION (node))
1022 expanded_location xloc = expand_location (EXPR_LOCATION (node));
1023 indent_to (file, indent+4);
1024 fprintf (file, "%s:%d:%d", xloc.file, xloc.line, xloc.column);
1026 /* Print the range, if any */
1027 source_range r = EXPR_LOCATION_RANGE (node);
1028 if (r.m_start)
1030 xloc = expand_location (r.m_start);
1031 fprintf (file, " start: %s:%d:%d", xloc.file, xloc.line, xloc.column);
1033 else
1035 fprintf (file, " start: unknown");
1037 if (r.m_finish)
1039 xloc = expand_location (r.m_finish);
1040 fprintf (file, " finish: %s:%d:%d", xloc.file, xloc.line, xloc.column);
1042 else
1044 fprintf (file, " finish: unknown");
1048 fprintf (file, ">");
1051 /* Print the identifier for DECL according to FLAGS. */
1053 void
1054 print_decl_identifier (FILE *file, tree decl, int flags)
1056 bool needs_colon = false;
1057 const char *name;
1058 char c;
1060 if (flags & PRINT_DECL_ORIGIN)
1062 if (DECL_IS_UNDECLARED_BUILTIN (decl))
1063 fputs ("<built-in>", file);
1064 else
1066 expanded_location loc
1067 = expand_location (DECL_SOURCE_LOCATION (decl));
1068 fprintf (file, "%s:%d:%d", loc.file, loc.line, loc.column);
1070 needs_colon = true;
1073 if (flags & PRINT_DECL_UNIQUE_NAME)
1075 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
1076 if (!TREE_PUBLIC (decl)
1077 || (DECL_WEAK (decl) && !DECL_EXTERNAL (decl)))
1078 /* The symbol has internal or weak linkage so its assembler name
1079 is not necessarily unique among the compilation units of the
1080 program. We therefore have to further mangle it. But we can't
1081 simply use DECL_SOURCE_FILE because it contains the name of the
1082 file the symbol originates from so, e.g. for function templates
1083 in C++ where the templates are defined in a header file, we can
1084 have symbols with the same assembler name and DECL_SOURCE_FILE.
1085 That's why we use the name of the top-level source file of the
1086 compilation unit. ??? Unnecessary for Ada. */
1087 name = ACONCAT ((main_input_filename, ":", name, NULL));
1089 else if (flags & PRINT_DECL_NAME)
1091 /* We don't want to print the full qualified name because it can be long,
1092 so we strip the scope prefix, but we may need to deal with the suffix
1093 created by the compiler. */
1094 const char *suffix = strchr (IDENTIFIER_POINTER (DECL_NAME (decl)), '.');
1095 name = lang_hooks.decl_printable_name (decl, 2);
1096 if (suffix)
1098 const char *dot = strchr (name, '.');
1099 while (dot && strcasecmp (dot, suffix) != 0)
1101 name = dot + 1;
1102 dot = strchr (name, '.');
1105 else
1107 const char *dot = strrchr (name, '.');
1108 if (dot)
1109 name = dot + 1;
1112 else
1113 return;
1115 if (needs_colon)
1116 fputc (':', file);
1118 while ((c = *name++) != '\0')
1120 /* Strip double-quotes because of VCG. */
1121 if (c == '"')
1122 continue;
1123 fputc (c, file);
1128 /* Print the node NODE on standard error, for debugging.
1129 Most nodes referred to by this one are printed recursively
1130 down to a depth of six. */
1132 DEBUG_FUNCTION void
1133 debug_tree (tree node)
1135 table = new hash_set<tree> (HASH_SIZE);
1136 print_node (stderr, "", node, 0);
1137 delete table;
1138 table = NULL;
1139 putc ('\n', stderr);
1142 DEBUG_FUNCTION void
1143 debug_raw (const tree_node &ref)
1145 debug_tree (const_cast <tree> (&ref));
1148 DEBUG_FUNCTION void
1149 debug_raw (const tree_node *ptr)
1151 if (ptr)
1152 debug_raw (*ptr);
1153 else
1154 fprintf (stderr, "<nil>\n");
1157 static void
1158 dump_tree_via_hooks (const tree_node *ptr, dump_flags_t options)
1160 if (DECL_P (ptr))
1161 lang_hooks.print_decl (stderr, const_cast <tree_node*> (ptr), 0);
1162 else if (TYPE_P (ptr))
1163 lang_hooks.print_type (stderr, const_cast <tree_node*> (ptr), 0);
1164 else if (TREE_CODE (ptr) == IDENTIFIER_NODE)
1165 lang_hooks.print_identifier (stderr, const_cast <tree_node*> (ptr), 0);
1166 else
1167 print_generic_expr (stderr, const_cast <tree_node*> (ptr), options);
1168 fprintf (stderr, "\n");
1171 DEBUG_FUNCTION void
1172 debug (const tree_node &ref)
1174 dump_tree_via_hooks (&ref, TDF_NONE);
1177 DEBUG_FUNCTION void
1178 debug (const tree_node *ptr)
1180 if (ptr)
1181 debug (*ptr);
1182 else
1183 fprintf (stderr, "<nil>\n");
1186 DEBUG_FUNCTION void
1187 debug_head (const tree_node &ref)
1189 debug (ref);
1192 DEBUG_FUNCTION void
1193 debug_head (const tree_node *ptr)
1195 if (ptr)
1196 debug_head (*ptr);
1197 else
1198 fprintf (stderr, "<nil>\n");
1201 DEBUG_FUNCTION void
1202 debug_body (const tree_node &ref)
1204 if (TREE_CODE (&ref) == FUNCTION_DECL)
1205 dump_function_to_file (const_cast <tree_node*> (&ref), stderr, TDF_NONE);
1206 else
1207 debug (ref);
1210 DEBUG_FUNCTION void
1211 debug_body (const tree_node *ptr)
1213 if (ptr)
1214 debug_body (*ptr);
1215 else
1216 fprintf (stderr, "<nil>\n");
1219 /* Print the vector of trees VEC on standard error, for debugging.
1220 Most nodes referred to by this one are printed recursively
1221 down to a depth of six. */
1223 DEBUG_FUNCTION void
1224 debug_raw (vec<tree, va_gc> &ref)
1226 tree elt;
1227 unsigned ix;
1229 /* Print the slot this node is in, and its code, and address. */
1230 fprintf (stderr, "<VEC");
1231 dump_addr (stderr, " ", ref.address ());
1233 FOR_EACH_VEC_ELT (ref, ix, elt)
1235 fprintf (stderr, "elt:%d ", ix);
1236 debug_raw (elt);
1240 DEBUG_FUNCTION void
1241 debug_raw (vec<tree, va_gc> *ptr)
1243 if (ptr)
1244 debug_raw (*ptr);
1245 else
1246 fprintf (stderr, "<nil>\n");
1249 static void
1250 debug_slim (tree t)
1252 print_node_brief (stderr, "", t, 0);
1255 DEFINE_DEBUG_VEC (tree)
1256 DEFINE_DEBUG_HASH_SET (tree)