Remove nfs bogon
[official-gcc.git] / gcc / print-tree.c
blob5347e0647043485277a63d95ce29c626a928c4c7
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 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);
236 tclass = TREE_CODE_CLASS (code);
238 /* Don't get too deep in nesting. If the user wants to see deeper,
239 it is easy to use the address of a lowest-level node
240 as an argument in another call to debug_tree. */
242 if (indent > 24)
244 print_node_brief (file, prefix, node, indent);
245 return;
248 if (indent > 8 && (tclass == tcc_type || tclass == tcc_declaration))
250 print_node_brief (file, prefix, node, indent);
251 return;
254 /* It is unsafe to look at any other fields of an ERROR_MARK node. */
255 if (code == ERROR_MARK)
257 print_node_brief (file, prefix, node, indent);
258 return;
261 /* Allow this function to be called if the table is not there. */
262 if (table)
264 /* If node is in the table, just mention its address. */
265 if (table->contains (node) && brief_for_visited)
267 print_node_brief (file, prefix, node, indent);
268 return;
271 table->add (node);
274 /* Indent to the specified column, since this is the long form. */
275 indent_to (file, indent);
277 /* Print the slot this node is in, and its code, and address. */
278 fprintf (file, "%s <%s", prefix, get_tree_code_name (code));
279 dump_addr (file, " ", node);
281 /* Print the name, if any. */
282 if (tclass == tcc_declaration)
284 if (DECL_NAME (node))
285 fprintf (file, " %s", IDENTIFIER_POINTER (DECL_NAME (node)));
286 else if (code == LABEL_DECL
287 && LABEL_DECL_UID (node) != -1)
289 if (dump_flags & TDF_NOUID)
290 fprintf (file, " L.xxxx");
291 else
292 fprintf (file, " L.%d", (int) LABEL_DECL_UID (node));
294 else
296 if (dump_flags & TDF_NOUID)
297 fprintf (file, " %c.xxxx", code == CONST_DECL ? 'C' : 'D');
298 else
299 fprintf (file, " %c.%u", code == CONST_DECL ? 'C' : 'D',
300 DECL_UID (node));
303 else if (tclass == tcc_type)
305 if (TYPE_NAME (node))
307 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
308 fprintf (file, " %s", IDENTIFIER_POINTER (TYPE_NAME (node)));
309 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
310 && DECL_NAME (TYPE_NAME (node)))
311 fprintf (file, " %s",
312 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node))));
315 if (code == IDENTIFIER_NODE)
316 fprintf (file, " %s", IDENTIFIER_POINTER (node));
318 if (code == INTEGER_CST)
320 if (indent <= 4)
321 print_node_brief (file, "type", TREE_TYPE (node), indent + 4);
323 else if (CODE_CONTAINS_STRUCT (code, TS_TYPED))
325 print_node (file, "type", TREE_TYPE (node), indent + 4);
326 if (TREE_TYPE (node))
327 indent_to (file, indent + 3);
330 if (!TYPE_P (node) && TREE_SIDE_EFFECTS (node))
331 fputs (" side-effects", file);
333 if (TYPE_P (node) ? TYPE_READONLY (node) : TREE_READONLY (node))
334 fputs (" readonly", file);
335 if (TYPE_P (node) && TYPE_ATOMIC (node))
336 fputs (" atomic", file);
337 if (!TYPE_P (node) && TREE_CONSTANT (node))
338 fputs (" constant", file);
339 else if (TYPE_P (node) && TYPE_SIZES_GIMPLIFIED (node))
340 fputs (" sizes-gimplified", file);
342 if (TYPE_P (node) && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (node)))
343 fprintf (file, " address-space-%d", TYPE_ADDR_SPACE (node));
345 if (TREE_ADDRESSABLE (node))
346 fputs (" addressable", file);
347 if (TREE_THIS_VOLATILE (node))
348 fputs (" volatile", file);
349 if (TREE_ASM_WRITTEN (node))
350 fputs (" asm_written", file);
351 if (TREE_USED (node))
352 fputs (" used", file);
353 if (TREE_NOTHROW (node))
354 fputs (" nothrow", file);
355 if (TREE_PUBLIC (node))
356 fputs (" public", file);
357 if (TREE_PRIVATE (node))
358 fputs (" private", file);
359 if (TREE_PROTECTED (node))
360 fputs (" protected", file);
361 if (TREE_STATIC (node))
362 fputs (code == CALL_EXPR ? " must-tail-call" : " static", file);
363 if (TREE_DEPRECATED (node))
364 fputs (" deprecated", file);
365 if (TREE_VISITED (node))
366 fputs (" visited", file);
368 if (code != TREE_VEC && code != INTEGER_CST && code != SSA_NAME)
370 if (TREE_LANG_FLAG_0 (node))
371 fputs (" tree_0", file);
372 if (TREE_LANG_FLAG_1 (node))
373 fputs (" tree_1", file);
374 if (TREE_LANG_FLAG_2 (node))
375 fputs (" tree_2", file);
376 if (TREE_LANG_FLAG_3 (node))
377 fputs (" tree_3", file);
378 if (TREE_LANG_FLAG_4 (node))
379 fputs (" tree_4", file);
380 if (TREE_LANG_FLAG_5 (node))
381 fputs (" tree_5", file);
382 if (TREE_LANG_FLAG_6 (node))
383 fputs (" tree_6", file);
386 /* DECL_ nodes have additional attributes. */
388 switch (TREE_CODE_CLASS (code))
390 case tcc_declaration:
391 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
393 if (DECL_UNSIGNED (node))
394 fputs (" unsigned", file);
395 if (DECL_IGNORED_P (node))
396 fputs (" ignored", file);
397 if (DECL_ABSTRACT_P (node))
398 fputs (" abstract", file);
399 if (DECL_EXTERNAL (node))
400 fputs (" external", file);
401 if (DECL_NONLOCAL (node))
402 fputs (" nonlocal", file);
404 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
406 if (DECL_WEAK (node))
407 fputs (" weak", file);
408 if (DECL_IN_SYSTEM_HEADER (node))
409 fputs (" in_system_header", file);
411 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WRTL)
412 && code != LABEL_DECL
413 && code != FUNCTION_DECL
414 && DECL_REGISTER (node))
415 fputs (" regdecl", file);
417 if (code == TYPE_DECL && TYPE_DECL_SUPPRESS_DEBUG (node))
418 fputs (" suppress-debug", file);
420 if (code == FUNCTION_DECL
421 && DECL_FUNCTION_SPECIFIC_TARGET (node))
422 fputs (" function-specific-target", file);
423 if (code == FUNCTION_DECL
424 && DECL_FUNCTION_SPECIFIC_OPTIMIZATION (node))
425 fputs (" function-specific-opt", file);
426 if (code == FUNCTION_DECL && DECL_DECLARED_INLINE_P (node))
427 fputs (" autoinline", file);
428 if (code == FUNCTION_DECL && DECL_UNINLINABLE (node))
429 fputs (" uninlinable", file);
430 if (code == FUNCTION_DECL && DECL_BUILT_IN (node))
431 fputs (" built-in", file);
432 if (code == FUNCTION_DECL && DECL_STATIC_CHAIN (node))
433 fputs (" static-chain", file);
434 if (TREE_CODE (node) == FUNCTION_DECL && decl_is_tm_clone (node))
435 fputs (" tm-clone", file);
437 if (code == FIELD_DECL && DECL_PACKED (node))
438 fputs (" packed", file);
439 if (code == FIELD_DECL && DECL_BIT_FIELD (node))
440 fputs (" bit-field", file);
441 if (code == FIELD_DECL && DECL_NONADDRESSABLE_P (node))
442 fputs (" nonaddressable", file);
444 if (code == LABEL_DECL && EH_LANDING_PAD_NR (node))
445 fprintf (file, " landing-pad:%d", EH_LANDING_PAD_NR (node));
447 if (code == VAR_DECL && DECL_IN_TEXT_SECTION (node))
448 fputs (" in-text-section", file);
449 if (code == VAR_DECL && DECL_IN_CONSTANT_POOL (node))
450 fputs (" in-constant-pool", file);
451 if (code == VAR_DECL && DECL_COMMON (node))
452 fputs (" common", file);
453 if ((code == VAR_DECL || code == PARM_DECL) && DECL_READ_P (node))
454 fputs (" read", file);
455 if (code == VAR_DECL && DECL_THREAD_LOCAL_P (node))
457 fputs (" ", file);
458 fputs (tls_model_names[DECL_TLS_MODEL (node)], file);
461 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
463 if (DECL_VIRTUAL_P (node))
464 fputs (" virtual", file);
465 if (DECL_PRESERVE_P (node))
466 fputs (" preserve", file);
467 if (DECL_LANG_FLAG_0 (node))
468 fputs (" decl_0", file);
469 if (DECL_LANG_FLAG_1 (node))
470 fputs (" decl_1", file);
471 if (DECL_LANG_FLAG_2 (node))
472 fputs (" decl_2", file);
473 if (DECL_LANG_FLAG_3 (node))
474 fputs (" decl_3", file);
475 if (DECL_LANG_FLAG_4 (node))
476 fputs (" decl_4", file);
477 if (DECL_LANG_FLAG_5 (node))
478 fputs (" decl_5", file);
479 if (DECL_LANG_FLAG_6 (node))
480 fputs (" decl_6", file);
481 if (DECL_LANG_FLAG_7 (node))
482 fputs (" decl_7", file);
484 mode = DECL_MODE (node);
485 fprintf (file, " %s", GET_MODE_NAME (mode));
488 if ((code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
489 && DECL_BY_REFERENCE (node))
490 fputs (" passed-by-reference", file);
492 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS) && DECL_DEFER_OUTPUT (node))
493 fputs (" defer-output", file);
496 xloc = expand_location (DECL_SOURCE_LOCATION (node));
497 fprintf (file, " %s:%d:%d", xloc.file, xloc.line,
498 xloc.column);
500 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
502 print_node (file, "size", DECL_SIZE (node), indent + 4);
503 print_node (file, "unit-size", DECL_SIZE_UNIT (node), indent + 4);
505 if (code != FUNCTION_DECL || DECL_BUILT_IN (node))
506 indent_to (file, indent + 3);
508 if (DECL_USER_ALIGN (node))
509 fprintf (file, " user");
511 fprintf (file, " align:%d warn_if_not_align:%d",
512 DECL_ALIGN (node), DECL_WARN_IF_NOT_ALIGN (node));
513 if (code == FIELD_DECL)
514 fprintf (file, " offset_align " HOST_WIDE_INT_PRINT_UNSIGNED,
515 DECL_OFFSET_ALIGN (node));
517 if (code == FUNCTION_DECL && DECL_BUILT_IN (node))
519 if (DECL_BUILT_IN_CLASS (node) == BUILT_IN_MD)
520 fprintf (file, " built-in: BUILT_IN_MD:%d", DECL_FUNCTION_CODE (node));
521 else
522 fprintf (file, " built-in: %s:%s",
523 built_in_class_names[(int) DECL_BUILT_IN_CLASS (node)],
524 built_in_names[(int) DECL_FUNCTION_CODE (node)]);
527 if (code == FIELD_DECL)
529 print_node (file, "offset", DECL_FIELD_OFFSET (node), indent + 4);
530 print_node (file, "bit-offset", DECL_FIELD_BIT_OFFSET (node),
531 indent + 4);
532 if (DECL_BIT_FIELD_TYPE (node))
533 print_node (file, "bit_field_type", DECL_BIT_FIELD_TYPE (node),
534 indent + 4);
537 print_node_brief (file, "context", DECL_CONTEXT (node), indent + 4);
539 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
541 print_node (file, "attributes",
542 DECL_ATTRIBUTES (node), indent + 4);
543 if (code != PARM_DECL)
544 print_node_brief (file, "initial", DECL_INITIAL (node),
545 indent + 4);
547 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WRTL))
549 print_node_brief (file, "abstract_origin",
550 DECL_ABSTRACT_ORIGIN (node), indent + 4);
552 if (CODE_CONTAINS_STRUCT (code, TS_DECL_NON_COMMON))
554 print_node (file, "result", DECL_RESULT_FLD (node), indent + 4);
557 lang_hooks.print_decl (file, node, indent);
559 if (DECL_RTL_SET_P (node))
561 indent_to (file, indent + 4);
562 print_rtl (file, DECL_RTL (node));
565 if (code == PARM_DECL)
567 print_node (file, "arg-type", DECL_ARG_TYPE (node), indent + 4);
569 if (DECL_INCOMING_RTL (node) != 0)
571 indent_to (file, indent + 4);
572 fprintf (file, "incoming-rtl ");
573 print_rtl (file, DECL_INCOMING_RTL (node));
576 else if (code == FUNCTION_DECL
577 && DECL_STRUCT_FUNCTION (node) != 0)
579 print_node (file, "arguments", DECL_ARGUMENTS (node), indent + 4);
580 indent_to (file, indent + 4);
581 dump_addr (file, "struct-function ", DECL_STRUCT_FUNCTION (node));
584 if ((code == VAR_DECL || code == PARM_DECL)
585 && DECL_HAS_VALUE_EXPR_P (node))
586 print_node (file, "value-expr", DECL_VALUE_EXPR (node), indent + 4);
588 /* Print the decl chain only if decl is at second level. */
589 if (indent == 4)
590 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
591 else
592 print_node_brief (file, "chain", TREE_CHAIN (node), indent + 4);
593 break;
595 case tcc_type:
596 if (TYPE_UNSIGNED (node))
597 fputs (" unsigned", file);
599 if (TYPE_NO_FORCE_BLK (node))
600 fputs (" no-force-blk", file);
602 if (TYPE_STRING_FLAG (node))
603 fputs (" string-flag", file);
605 if (TYPE_NEEDS_CONSTRUCTING (node))
606 fputs (" needs-constructing", file);
608 if ((code == RECORD_TYPE
609 || code == UNION_TYPE
610 || code == QUAL_UNION_TYPE
611 || code == ARRAY_TYPE)
612 && TYPE_REVERSE_STORAGE_ORDER (node))
613 fputs (" reverse-storage-order", file);
615 /* The transparent-union flag is used for different things in
616 different nodes. */
617 if ((code == UNION_TYPE || code == RECORD_TYPE)
618 && TYPE_TRANSPARENT_AGGR (node))
619 fputs (" transparent-aggr", file);
620 else if (code == ARRAY_TYPE
621 && TYPE_NONALIASED_COMPONENT (node))
622 fputs (" nonaliased-component", file);
624 if (TYPE_PACKED (node))
625 fputs (" packed", file);
627 if (TYPE_RESTRICT (node))
628 fputs (" restrict", file);
630 if (TYPE_LANG_FLAG_0 (node))
631 fputs (" type_0", file);
632 if (TYPE_LANG_FLAG_1 (node))
633 fputs (" type_1", file);
634 if (TYPE_LANG_FLAG_2 (node))
635 fputs (" type_2", file);
636 if (TYPE_LANG_FLAG_3 (node))
637 fputs (" type_3", file);
638 if (TYPE_LANG_FLAG_4 (node))
639 fputs (" type_4", file);
640 if (TYPE_LANG_FLAG_5 (node))
641 fputs (" type_5", file);
642 if (TYPE_LANG_FLAG_6 (node))
643 fputs (" type_6", file);
644 if (TYPE_LANG_FLAG_7 (node))
645 fputs (" type_7", file);
647 mode = TYPE_MODE (node);
648 fprintf (file, " %s", GET_MODE_NAME (mode));
650 print_node (file, "size", TYPE_SIZE (node), indent + 4);
651 print_node (file, "unit-size", TYPE_SIZE_UNIT (node), indent + 4);
652 indent_to (file, indent + 3);
654 if (TYPE_USER_ALIGN (node))
655 fprintf (file, " user");
657 fprintf (file, " align:%d warn_if_not_align:%d symtab:%d alias-set "
658 HOST_WIDE_INT_PRINT_DEC,
659 TYPE_ALIGN (node), TYPE_WARN_IF_NOT_ALIGN (node),
660 TYPE_SYMTAB_ADDRESS (node),
661 (HOST_WIDE_INT) TYPE_ALIAS_SET (node));
663 if (TYPE_STRUCTURAL_EQUALITY_P (node))
664 fprintf (file, " structural-equality");
665 else
666 dump_addr (file, " canonical-type ", TYPE_CANONICAL (node));
668 print_node (file, "attributes", TYPE_ATTRIBUTES (node), indent + 4);
670 if (INTEGRAL_TYPE_P (node) || code == REAL_TYPE
671 || code == FIXED_POINT_TYPE)
673 fprintf (file, " precision:%d", TYPE_PRECISION (node));
674 print_node_brief (file, "min", TYPE_MIN_VALUE (node), indent + 4);
675 print_node_brief (file, "max", TYPE_MAX_VALUE (node), indent + 4);
678 if (code == ENUMERAL_TYPE)
679 print_node (file, "values", TYPE_VALUES (node), indent + 4);
680 else if (code == ARRAY_TYPE)
681 print_node (file, "domain", TYPE_DOMAIN (node), indent + 4);
682 else if (code == VECTOR_TYPE)
684 fprintf (file, " nunits:");
685 print_dec (TYPE_VECTOR_SUBPARTS (node), file);
687 else if (code == RECORD_TYPE
688 || code == UNION_TYPE
689 || code == QUAL_UNION_TYPE)
690 print_node (file, "fields", TYPE_FIELDS (node), indent + 4);
691 else if (code == FUNCTION_TYPE
692 || code == METHOD_TYPE)
694 if (TYPE_METHOD_BASETYPE (node))
695 print_node_brief (file, "method basetype",
696 TYPE_METHOD_BASETYPE (node), indent + 4);
697 print_node (file, "arg-types", TYPE_ARG_TYPES (node), indent + 4);
699 else if (code == OFFSET_TYPE)
700 print_node_brief (file, "basetype", TYPE_OFFSET_BASETYPE (node),
701 indent + 4);
703 if (TYPE_CONTEXT (node))
704 print_node_brief (file, "context", TYPE_CONTEXT (node), indent + 4);
706 lang_hooks.print_type (file, node, indent);
708 if (TYPE_POINTER_TO (node) || TREE_CHAIN (node))
709 indent_to (file, indent + 3);
711 print_node_brief (file, "pointer_to_this", TYPE_POINTER_TO (node),
712 indent + 4);
713 print_node_brief (file, "reference_to_this", TYPE_REFERENCE_TO (node),
714 indent + 4);
715 print_node_brief (file, "chain", TREE_CHAIN (node), indent + 4);
716 break;
718 case tcc_expression:
719 case tcc_comparison:
720 case tcc_unary:
721 case tcc_binary:
722 case tcc_reference:
723 case tcc_statement:
724 case tcc_vl_exp:
725 if (code == BIND_EXPR)
727 print_node (file, "vars", TREE_OPERAND (node, 0), indent + 4);
728 print_node (file, "body", TREE_OPERAND (node, 1), indent + 4);
729 print_node (file, "block", TREE_OPERAND (node, 2), indent + 4);
730 break;
732 if (code == CALL_EXPR)
734 call_expr_arg_iterator iter;
735 tree arg;
736 print_node (file, "fn", CALL_EXPR_FN (node), indent + 4);
737 print_node (file, "static_chain", CALL_EXPR_STATIC_CHAIN (node),
738 indent + 4);
739 i = 0;
740 FOR_EACH_CALL_EXPR_ARG (arg, iter, node)
742 /* Buffer big enough to format a 32-bit UINT_MAX into, plus
743 the text. */
744 char temp[15];
745 sprintf (temp, "arg:%u", i);
746 print_node (file, temp, arg, indent + 4);
747 i++;
750 else
752 len = TREE_OPERAND_LENGTH (node);
754 for (i = 0; i < len; i++)
756 /* Buffer big enough to format a 32-bit UINT_MAX into, plus
757 the text. */
758 char temp[15];
760 sprintf (temp, "arg:%d", i);
761 print_node (file, temp, TREE_OPERAND (node, i), indent + 4);
764 if (CODE_CONTAINS_STRUCT (code, TS_COMMON))
765 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
766 break;
768 case tcc_constant:
769 case tcc_exceptional:
770 switch (code)
772 case INTEGER_CST:
773 if (TREE_OVERFLOW (node))
774 fprintf (file, " overflow");
776 fprintf (file, " ");
777 print_dec (wi::to_wide (node), file, TYPE_SIGN (TREE_TYPE (node)));
778 break;
780 case REAL_CST:
781 print_real_cst (file, node, false);
782 break;
784 case FIXED_CST:
786 FIXED_VALUE_TYPE f;
787 char string[64];
789 if (TREE_OVERFLOW (node))
790 fprintf (file, " overflow");
792 f = TREE_FIXED_CST (node);
793 fixed_to_decimal (string, &f, sizeof (string));
794 fprintf (file, " %s", string);
796 break;
798 case VECTOR_CST:
800 /* Big enough for UINT_MAX plus the string below. */
801 char buf[32];
803 fprintf (file, " npatterns:%u nelts-per-pattern:%u",
804 VECTOR_CST_NPATTERNS (node),
805 VECTOR_CST_NELTS_PER_PATTERN (node));
806 unsigned int count = vector_cst_encoded_nelts (node);
807 for (unsigned int i = 0; i < count; ++i)
809 sprintf (buf, "elt:%u: ", i);
810 print_node (file, buf, VECTOR_CST_ENCODED_ELT (node, i),
811 indent + 4);
814 break;
816 case COMPLEX_CST:
817 print_node (file, "real", TREE_REALPART (node), indent + 4);
818 print_node (file, "imag", TREE_IMAGPART (node), indent + 4);
819 break;
821 case STRING_CST:
823 const char *p = TREE_STRING_POINTER (node);
824 int i = TREE_STRING_LENGTH (node);
825 fputs (" \"", file);
826 while (--i >= 0)
828 char ch = *p++;
829 if (ch >= ' ' && ch < 127)
830 putc (ch, file);
831 else
832 fprintf (file, "\\%03o", ch & 0xFF);
834 fputc ('\"', file);
836 break;
838 case POLY_INT_CST:
840 char buf[10];
841 for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
843 snprintf (buf, sizeof (buf), "elt%u: ", i);
844 print_node (file, buf, POLY_INT_CST_COEFF (node, i),
845 indent + 4);
848 break;
850 case IDENTIFIER_NODE:
851 lang_hooks.print_identifier (file, node, indent);
852 break;
854 case TREE_LIST:
855 print_node (file, "purpose", TREE_PURPOSE (node), indent + 4);
856 print_node (file, "value", TREE_VALUE (node), indent + 4);
857 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
858 break;
860 case TREE_VEC:
861 len = TREE_VEC_LENGTH (node);
862 fprintf (file, " length:%d", len);
863 for (i = 0; i < len; i++)
864 if (TREE_VEC_ELT (node, i))
866 /* Buffer big enough to format a 32-bit UINT_MAX into, plus
867 the text. */
868 char temp[15];
869 sprintf (temp, "elt:%d", i);
870 print_node (file, temp, TREE_VEC_ELT (node, i), indent + 4);
872 break;
874 case CONSTRUCTOR:
876 unsigned HOST_WIDE_INT cnt;
877 tree index, value;
878 len = CONSTRUCTOR_NELTS (node);
879 fprintf (file, " length:%d", len);
880 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (node),
881 cnt, index, value)
883 print_node (file, "idx", index, indent + 4, false);
884 print_node (file, "val", value, indent + 4, false);
887 break;
889 case STATEMENT_LIST:
890 dump_addr (file, " head ", node->stmt_list.head);
891 dump_addr (file, " tail ", node->stmt_list.tail);
892 fprintf (file, " stmts");
894 tree_stmt_iterator i;
895 for (i = tsi_start (node); !tsi_end_p (i); tsi_next (&i))
897 /* Not printing the addresses of the (not-a-tree)
898 'struct tree_stmt_list_node's. */
899 dump_addr (file, " ", tsi_stmt (i));
901 fprintf (file, "\n");
902 for (i = tsi_start (node); !tsi_end_p (i); tsi_next (&i))
904 /* Not printing the addresses of the (not-a-tree)
905 'struct tree_stmt_list_node's. */
906 print_node (file, "stmt", tsi_stmt (i), indent + 4);
909 break;
911 case BLOCK:
912 print_node (file, "vars", BLOCK_VARS (node), indent + 4);
913 print_node (file, "supercontext", BLOCK_SUPERCONTEXT (node),
914 indent + 4);
915 print_node (file, "subblocks", BLOCK_SUBBLOCKS (node), indent + 4);
916 print_node (file, "chain", BLOCK_CHAIN (node), indent + 4);
917 print_node (file, "abstract_origin",
918 BLOCK_ABSTRACT_ORIGIN (node), indent + 4);
919 break;
921 case SSA_NAME:
922 print_node_brief (file, "var", SSA_NAME_VAR (node), indent + 4);
923 indent_to (file, indent + 4);
924 fprintf (file, "def_stmt ");
926 pretty_printer buffer;
927 buffer.buffer->stream = file;
928 pp_gimple_stmt_1 (&buffer, SSA_NAME_DEF_STMT (node), indent + 4,
929 TDF_NONE);
930 pp_flush (&buffer);
933 indent_to (file, indent + 4);
934 fprintf (file, "version:%u", SSA_NAME_VERSION (node));
935 if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (node))
936 fprintf (file, " in-abnormal-phi");
937 if (SSA_NAME_IN_FREE_LIST (node))
938 fprintf (file, " in-free-list");
940 if (SSA_NAME_PTR_INFO (node))
942 indent_to (file, indent + 3);
943 if (SSA_NAME_PTR_INFO (node))
944 dump_addr (file, " ptr-info ", SSA_NAME_PTR_INFO (node));
946 break;
948 case OMP_CLAUSE:
950 int i;
951 fprintf (file, " %s",
952 omp_clause_code_name[OMP_CLAUSE_CODE (node)]);
953 for (i = 0; i < omp_clause_num_ops[OMP_CLAUSE_CODE (node)]; i++)
955 indent_to (file, indent + 4);
956 fprintf (file, "op-%d:", i);
957 print_node_brief (file, "", OMP_CLAUSE_OPERAND (node, i), 0);
960 break;
962 case OPTIMIZATION_NODE:
963 cl_optimization_print (file, indent + 4, TREE_OPTIMIZATION (node));
964 break;
966 case TARGET_OPTION_NODE:
967 cl_target_option_print (file, indent + 4, TREE_TARGET_OPTION (node));
968 break;
969 case IMPORTED_DECL:
970 fprintf (file, " imported-declaration");
971 print_node_brief (file, "associated-declaration",
972 IMPORTED_DECL_ASSOCIATED_DECL (node),
973 indent + 4);
974 break;
976 case TREE_BINFO:
977 fprintf (file, " bases:%d",
978 vec_safe_length (BINFO_BASE_BINFOS (node)));
979 print_node_brief (file, "offset", BINFO_OFFSET (node), indent + 4);
980 print_node_brief (file, "virtuals", BINFO_VIRTUALS (node),
981 indent + 4);
982 print_node_brief (file, "inheritance-chain",
983 BINFO_INHERITANCE_CHAIN (node),
984 indent + 4);
985 break;
987 default:
988 if (EXCEPTIONAL_CLASS_P (node))
989 lang_hooks.print_xnode (file, node, indent);
990 break;
993 break;
996 if (EXPR_HAS_LOCATION (node))
998 expanded_location xloc = expand_location (EXPR_LOCATION (node));
999 indent_to (file, indent+4);
1000 fprintf (file, "%s:%d:%d", xloc.file, xloc.line, xloc.column);
1002 /* Print the range, if any */
1003 source_range r = EXPR_LOCATION_RANGE (node);
1004 if (r.m_start)
1006 xloc = expand_location (r.m_start);
1007 fprintf (file, " start: %s:%d:%d", xloc.file, xloc.line, xloc.column);
1009 else
1011 fprintf (file, " start: unknown");
1013 if (r.m_finish)
1015 xloc = expand_location (r.m_finish);
1016 fprintf (file, " finish: %s:%d:%d", xloc.file, xloc.line, xloc.column);
1018 else
1020 fprintf (file, " finish: unknown");
1024 fprintf (file, ">");
1028 /* Print the node NODE on standard error, for debugging.
1029 Most nodes referred to by this one are printed recursively
1030 down to a depth of six. */
1032 DEBUG_FUNCTION void
1033 debug_tree (tree node)
1035 table = new hash_set<tree> (HASH_SIZE);
1036 print_node (stderr, "", node, 0);
1037 delete table;
1038 table = NULL;
1039 putc ('\n', stderr);
1042 DEBUG_FUNCTION void
1043 debug_raw (const tree_node &ref)
1045 debug_tree (const_cast <tree> (&ref));
1048 DEBUG_FUNCTION void
1049 debug_raw (const tree_node *ptr)
1051 if (ptr)
1052 debug_raw (*ptr);
1053 else
1054 fprintf (stderr, "<nil>\n");
1057 static void
1058 dump_tree_via_hooks (const tree_node *ptr, dump_flags_t options)
1060 if (DECL_P (ptr))
1061 lang_hooks.print_decl (stderr, const_cast <tree_node*> (ptr), 0);
1062 else if (TYPE_P (ptr))
1063 lang_hooks.print_type (stderr, const_cast <tree_node*> (ptr), 0);
1064 else if (TREE_CODE (ptr) == IDENTIFIER_NODE)
1065 lang_hooks.print_identifier (stderr, const_cast <tree_node*> (ptr), 0);
1066 else
1067 print_generic_expr (stderr, const_cast <tree_node*> (ptr), options);
1068 fprintf (stderr, "\n");
1071 DEBUG_FUNCTION void
1072 debug (const tree_node &ref)
1074 dump_tree_via_hooks (&ref, TDF_NONE);
1077 DEBUG_FUNCTION void
1078 debug (const tree_node *ptr)
1080 if (ptr)
1081 debug (*ptr);
1082 else
1083 fprintf (stderr, "<nil>\n");
1086 DEBUG_FUNCTION void
1087 debug_head (const tree_node &ref)
1089 debug (ref);
1092 DEBUG_FUNCTION void
1093 debug_head (const tree_node *ptr)
1095 if (ptr)
1096 debug_head (*ptr);
1097 else
1098 fprintf (stderr, "<nil>\n");
1101 DEBUG_FUNCTION void
1102 debug_body (const tree_node &ref)
1104 if (TREE_CODE (&ref) == FUNCTION_DECL)
1105 dump_function_to_file (const_cast <tree_node*> (&ref), stderr, TDF_NONE);
1106 else
1107 debug (ref);
1110 DEBUG_FUNCTION void
1111 debug_body (const tree_node *ptr)
1113 if (ptr)
1114 debug_body (*ptr);
1115 else
1116 fprintf (stderr, "<nil>\n");
1119 /* Print the vector of trees VEC on standard error, for debugging.
1120 Most nodes referred to by this one are printed recursively
1121 down to a depth of six. */
1123 DEBUG_FUNCTION void
1124 debug_raw (vec<tree, va_gc> &ref)
1126 tree elt;
1127 unsigned ix;
1129 /* Print the slot this node is in, and its code, and address. */
1130 fprintf (stderr, "<VEC");
1131 dump_addr (stderr, " ", ref.address ());
1133 FOR_EACH_VEC_ELT (ref, ix, elt)
1135 fprintf (stderr, "elt:%d ", ix);
1136 debug_raw (elt);
1140 DEBUG_FUNCTION void
1141 debug_raw (vec<tree, va_gc> *ptr)
1143 if (ptr)
1144 debug_raw (*ptr);
1145 else
1146 fprintf (stderr, "<nil>\n");
1149 static void
1150 debug_slim (tree t)
1152 print_node_brief (stderr, "", t, 0);
1155 DEFINE_DEBUG_VEC (tree)
1156 DEFINE_DEBUG_HASH_SET (tree)