* include/bits/alloc_traits.h (__alloctr_rebind): Remove.
[official-gcc.git] / gcc / print-tree.c
blob1841d77f8930b4f111f134f13cce0785ebb688a2
1 /* Prints out tree in human readable form - GCC
2 Copyright (C) 1990-2015 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 "alias.h"
26 #include "symtab.h"
27 #include "tree.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 "diagnostic.h"
34 #include "gimple-pretty-print.h" /* FIXME */
35 #include "hard-reg-set.h"
36 #include "function.h"
37 #include "cgraph.h"
38 #include "tree-cfg.h"
39 #include "tree-dump.h"
40 #include "dumpfile.h"
41 #include "wide-int-print.h"
43 /* Define the hash table of nodes already seen.
44 Such nodes are not repeated; brief cross-references are used. */
46 #define HASH_SIZE 37
48 struct bucket
50 tree node;
51 struct bucket *next;
54 static struct bucket **table;
56 /* Print PREFIX and ADDR to FILE. */
57 void
58 dump_addr (FILE *file, const char *prefix, const void *addr)
60 if (flag_dump_noaddr || flag_dump_unnumbered)
61 fprintf (file, "%s#", prefix);
62 else
63 fprintf (file, "%s" HOST_PTR_PRINTF, prefix, addr);
66 /* Print a node in brief fashion, with just the code, address and name. */
68 void
69 print_node_brief (FILE *file, const char *prefix, const_tree node, int indent)
71 enum tree_code_class tclass;
73 if (node == 0)
74 return;
76 tclass = TREE_CODE_CLASS (TREE_CODE (node));
78 /* Always print the slot this node is in, and its code, address and
79 name if any. */
80 if (indent > 0)
81 fprintf (file, " ");
82 fprintf (file, "%s <%s", prefix, get_tree_code_name (TREE_CODE (node)));
83 dump_addr (file, " ", node);
85 if (tclass == tcc_declaration)
87 if (DECL_NAME (node))
88 fprintf (file, " %s", IDENTIFIER_POINTER (DECL_NAME (node)));
89 else if (TREE_CODE (node) == LABEL_DECL
90 && LABEL_DECL_UID (node) != -1)
92 if (dump_flags & TDF_NOUID)
93 fprintf (file, " L.xxxx");
94 else
95 fprintf (file, " L.%d", (int) LABEL_DECL_UID (node));
97 else
99 if (dump_flags & TDF_NOUID)
100 fprintf (file, " %c.xxxx",
101 TREE_CODE (node) == CONST_DECL ? 'C' : 'D');
102 else
103 fprintf (file, " %c.%u",
104 TREE_CODE (node) == CONST_DECL ? 'C' : 'D',
105 DECL_UID (node));
108 else if (tclass == tcc_type)
110 if (TYPE_NAME (node))
112 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
113 fprintf (file, " %s", IDENTIFIER_POINTER (TYPE_NAME (node)));
114 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
115 && DECL_NAME (TYPE_NAME (node)))
116 fprintf (file, " %s",
117 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node))));
119 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (node)))
120 fprintf (file, " address-space-%d", TYPE_ADDR_SPACE (node));
122 if (TREE_CODE (node) == IDENTIFIER_NODE)
123 fprintf (file, " %s", IDENTIFIER_POINTER (node));
125 /* We might as well always print the value of an integer or real. */
126 if (TREE_CODE (node) == INTEGER_CST)
128 if (TREE_OVERFLOW (node))
129 fprintf (file, " overflow");
131 fprintf (file, " ");
132 print_dec (node, file, TYPE_SIGN (TREE_TYPE (node)));
134 if (TREE_CODE (node) == REAL_CST)
136 REAL_VALUE_TYPE d;
138 if (TREE_OVERFLOW (node))
139 fprintf (file, " overflow");
141 d = TREE_REAL_CST (node);
142 if (REAL_VALUE_ISINF (d))
143 fprintf (file, REAL_VALUE_NEGATIVE (d) ? " -Inf" : " Inf");
144 else if (REAL_VALUE_ISNAN (d))
145 fprintf (file, " Nan");
146 else
148 char string[60];
149 real_to_decimal (string, &d, sizeof (string), 0, 1);
150 fprintf (file, " %s", string);
153 if (TREE_CODE (node) == FIXED_CST)
155 FIXED_VALUE_TYPE f;
156 char string[60];
158 if (TREE_OVERFLOW (node))
159 fprintf (file, " overflow");
161 f = TREE_FIXED_CST (node);
162 fixed_to_decimal (string, &f, sizeof (string));
163 fprintf (file, " %s", string);
166 fprintf (file, ">");
169 void
170 indent_to (FILE *file, int column)
172 int i;
174 /* Since this is the long way, indent to desired column. */
175 if (column > 0)
176 fprintf (file, "\n");
177 for (i = 0; i < column; i++)
178 fprintf (file, " ");
181 /* Print the node NODE in full on file FILE, preceded by PREFIX,
182 starting in column INDENT. */
184 void
185 print_node (FILE *file, const char *prefix, tree node, int indent)
187 int hash;
188 struct bucket *b;
189 machine_mode mode;
190 enum tree_code_class tclass;
191 int len;
192 int i;
193 expanded_location xloc;
194 enum tree_code code;
196 if (node == 0)
197 return;
199 code = TREE_CODE (node);
200 tclass = TREE_CODE_CLASS (code);
202 /* Don't get too deep in nesting. If the user wants to see deeper,
203 it is easy to use the address of a lowest-level node
204 as an argument in another call to debug_tree. */
206 if (indent > 24)
208 print_node_brief (file, prefix, node, indent);
209 return;
212 if (indent > 8 && (tclass == tcc_type || tclass == tcc_declaration))
214 print_node_brief (file, prefix, node, indent);
215 return;
218 /* It is unsafe to look at any other fields of an ERROR_MARK node. */
219 if (code == ERROR_MARK)
221 print_node_brief (file, prefix, node, indent);
222 return;
225 /* Allow this function to be called if the table is not there. */
226 if (table)
228 hash = ((uintptr_t) node) % HASH_SIZE;
230 /* If node is in the table, just mention its address. */
231 for (b = table[hash]; b; b = b->next)
232 if (b->node == node)
234 print_node_brief (file, prefix, node, indent);
235 return;
238 /* Add this node to the table. */
239 b = XNEW (struct bucket);
240 b->node = node;
241 b->next = table[hash];
242 table[hash] = b;
245 /* Indent to the specified column, since this is the long form. */
246 indent_to (file, indent);
248 /* Print the slot this node is in, and its code, and address. */
249 fprintf (file, "%s <%s", prefix, get_tree_code_name (code));
250 dump_addr (file, " ", node);
252 /* Print the name, if any. */
253 if (tclass == tcc_declaration)
255 if (DECL_NAME (node))
256 fprintf (file, " %s", IDENTIFIER_POINTER (DECL_NAME (node)));
257 else if (code == LABEL_DECL
258 && LABEL_DECL_UID (node) != -1)
260 if (dump_flags & TDF_NOUID)
261 fprintf (file, " L.xxxx");
262 else
263 fprintf (file, " L.%d", (int) LABEL_DECL_UID (node));
265 else
267 if (dump_flags & TDF_NOUID)
268 fprintf (file, " %c.xxxx", code == CONST_DECL ? 'C' : 'D');
269 else
270 fprintf (file, " %c.%u", code == CONST_DECL ? 'C' : 'D',
271 DECL_UID (node));
274 else if (tclass == tcc_type)
276 if (TYPE_NAME (node))
278 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
279 fprintf (file, " %s", IDENTIFIER_POINTER (TYPE_NAME (node)));
280 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
281 && DECL_NAME (TYPE_NAME (node)))
282 fprintf (file, " %s",
283 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node))));
286 if (code == IDENTIFIER_NODE)
287 fprintf (file, " %s", IDENTIFIER_POINTER (node));
289 if (code == INTEGER_CST)
291 if (indent <= 4)
292 print_node_brief (file, "type", TREE_TYPE (node), indent + 4);
294 else if (CODE_CONTAINS_STRUCT (code, TS_TYPED))
296 print_node (file, "type", TREE_TYPE (node), indent + 4);
297 if (TREE_TYPE (node))
298 indent_to (file, indent + 3);
301 if (!TYPE_P (node) && TREE_SIDE_EFFECTS (node))
302 fputs (" side-effects", file);
304 if (TYPE_P (node) ? TYPE_READONLY (node) : TREE_READONLY (node))
305 fputs (" readonly", file);
306 if (TYPE_P (node) && TYPE_ATOMIC (node))
307 fputs (" atomic", file);
308 if (!TYPE_P (node) && TREE_CONSTANT (node))
309 fputs (" constant", file);
310 else if (TYPE_P (node) && TYPE_SIZES_GIMPLIFIED (node))
311 fputs (" sizes-gimplified", file);
313 if (TYPE_P (node) && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (node)))
314 fprintf (file, " address-space-%d", TYPE_ADDR_SPACE (node));
316 if (TREE_ADDRESSABLE (node))
317 fputs (" addressable", file);
318 if (TREE_THIS_VOLATILE (node))
319 fputs (" volatile", file);
320 if (TREE_ASM_WRITTEN (node))
321 fputs (" asm_written", file);
322 if (TREE_USED (node))
323 fputs (" used", file);
324 if (TREE_NOTHROW (node))
325 fputs (TYPE_P (node) ? " align-ok" : " nothrow", file);
326 if (TREE_PUBLIC (node))
327 fputs (" public", file);
328 if (TREE_PRIVATE (node))
329 fputs (" private", file);
330 if (TREE_PROTECTED (node))
331 fputs (" protected", file);
332 if (TREE_STATIC (node))
333 fputs (" static", file);
334 if (TREE_DEPRECATED (node))
335 fputs (" deprecated", file);
336 if (TREE_VISITED (node))
337 fputs (" visited", file);
339 if (code != TREE_VEC && code != INTEGER_CST && code != SSA_NAME)
341 if (TREE_LANG_FLAG_0 (node))
342 fputs (" tree_0", file);
343 if (TREE_LANG_FLAG_1 (node))
344 fputs (" tree_1", file);
345 if (TREE_LANG_FLAG_2 (node))
346 fputs (" tree_2", file);
347 if (TREE_LANG_FLAG_3 (node))
348 fputs (" tree_3", file);
349 if (TREE_LANG_FLAG_4 (node))
350 fputs (" tree_4", file);
351 if (TREE_LANG_FLAG_5 (node))
352 fputs (" tree_5", file);
353 if (TREE_LANG_FLAG_6 (node))
354 fputs (" tree_6", file);
357 /* DECL_ nodes have additional attributes. */
359 switch (TREE_CODE_CLASS (code))
361 case tcc_declaration:
362 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
364 if (DECL_UNSIGNED (node))
365 fputs (" unsigned", file);
366 if (DECL_IGNORED_P (node))
367 fputs (" ignored", file);
368 if (DECL_ABSTRACT_P (node))
369 fputs (" abstract", file);
370 if (DECL_EXTERNAL (node))
371 fputs (" external", file);
372 if (DECL_NONLOCAL (node))
373 fputs (" nonlocal", file);
375 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
377 if (DECL_WEAK (node))
378 fputs (" weak", file);
379 if (DECL_IN_SYSTEM_HEADER (node))
380 fputs (" in_system_header", file);
382 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WRTL)
383 && code != LABEL_DECL
384 && code != FUNCTION_DECL
385 && DECL_REGISTER (node))
386 fputs (" regdecl", file);
388 if (code == TYPE_DECL && TYPE_DECL_SUPPRESS_DEBUG (node))
389 fputs (" suppress-debug", file);
391 if (code == FUNCTION_DECL
392 && DECL_FUNCTION_SPECIFIC_TARGET (node))
393 fputs (" function-specific-target", file);
394 if (code == FUNCTION_DECL
395 && DECL_FUNCTION_SPECIFIC_OPTIMIZATION (node))
396 fputs (" function-specific-opt", file);
397 if (code == FUNCTION_DECL && DECL_DECLARED_INLINE_P (node))
398 fputs (" autoinline", file);
399 if (code == FUNCTION_DECL && DECL_BUILT_IN (node))
400 fputs (" built-in", file);
401 if (code == FUNCTION_DECL && DECL_STATIC_CHAIN (node))
402 fputs (" static-chain", file);
403 if (TREE_CODE (node) == FUNCTION_DECL && decl_is_tm_clone (node))
404 fputs (" tm-clone", file);
406 if (code == FIELD_DECL && DECL_PACKED (node))
407 fputs (" packed", file);
408 if (code == FIELD_DECL && DECL_BIT_FIELD (node))
409 fputs (" bit-field", file);
410 if (code == FIELD_DECL && DECL_NONADDRESSABLE_P (node))
411 fputs (" nonaddressable", file);
413 if (code == LABEL_DECL && EH_LANDING_PAD_NR (node))
414 fprintf (file, " landing-pad:%d", EH_LANDING_PAD_NR (node));
416 if (code == VAR_DECL && DECL_IN_TEXT_SECTION (node))
417 fputs (" in-text-section", file);
418 if (code == VAR_DECL && DECL_IN_CONSTANT_POOL (node))
419 fputs (" in-constant-pool", file);
420 if (code == VAR_DECL && DECL_COMMON (node))
421 fputs (" common", file);
422 if (code == VAR_DECL && DECL_THREAD_LOCAL_P (node))
424 fputs (" ", file);
425 fputs (tls_model_names[DECL_TLS_MODEL (node)], file);
428 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
430 if (DECL_VIRTUAL_P (node))
431 fputs (" virtual", file);
432 if (DECL_PRESERVE_P (node))
433 fputs (" preserve", file);
434 if (DECL_LANG_FLAG_0 (node))
435 fputs (" decl_0", file);
436 if (DECL_LANG_FLAG_1 (node))
437 fputs (" decl_1", file);
438 if (DECL_LANG_FLAG_2 (node))
439 fputs (" decl_2", file);
440 if (DECL_LANG_FLAG_3 (node))
441 fputs (" decl_3", file);
442 if (DECL_LANG_FLAG_4 (node))
443 fputs (" decl_4", file);
444 if (DECL_LANG_FLAG_5 (node))
445 fputs (" decl_5", file);
446 if (DECL_LANG_FLAG_6 (node))
447 fputs (" decl_6", file);
448 if (DECL_LANG_FLAG_7 (node))
449 fputs (" decl_7", file);
451 mode = DECL_MODE (node);
452 fprintf (file, " %s", GET_MODE_NAME (mode));
455 if ((code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
456 && DECL_BY_REFERENCE (node))
457 fputs (" passed-by-reference", file);
459 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS) && DECL_DEFER_OUTPUT (node))
460 fputs (" defer-output", file);
463 xloc = expand_location (DECL_SOURCE_LOCATION (node));
464 fprintf (file, " file %s line %d col %d", xloc.file, xloc.line,
465 xloc.column);
467 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
469 print_node (file, "size", DECL_SIZE (node), indent + 4);
470 print_node (file, "unit size", DECL_SIZE_UNIT (node), indent + 4);
472 if (code != FUNCTION_DECL || DECL_BUILT_IN (node))
473 indent_to (file, indent + 3);
475 if (DECL_USER_ALIGN (node))
476 fprintf (file, " user");
478 fprintf (file, " align %d", DECL_ALIGN (node));
479 if (code == FIELD_DECL)
480 fprintf (file, " offset_align " HOST_WIDE_INT_PRINT_UNSIGNED,
481 DECL_OFFSET_ALIGN (node));
483 if (code == FUNCTION_DECL && DECL_BUILT_IN (node))
485 if (DECL_BUILT_IN_CLASS (node) == BUILT_IN_MD)
486 fprintf (file, " built-in BUILT_IN_MD %d", DECL_FUNCTION_CODE (node));
487 else
488 fprintf (file, " built-in %s:%s",
489 built_in_class_names[(int) DECL_BUILT_IN_CLASS (node)],
490 built_in_names[(int) DECL_FUNCTION_CODE (node)]);
493 if (code == FIELD_DECL)
495 print_node (file, "offset", DECL_FIELD_OFFSET (node), indent + 4);
496 print_node (file, "bit offset", DECL_FIELD_BIT_OFFSET (node),
497 indent + 4);
498 if (DECL_BIT_FIELD_TYPE (node))
499 print_node (file, "bit_field_type", DECL_BIT_FIELD_TYPE (node),
500 indent + 4);
503 print_node_brief (file, "context", DECL_CONTEXT (node), indent + 4);
505 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
507 print_node_brief (file, "attributes",
508 DECL_ATTRIBUTES (node), indent + 4);
509 if (code != PARM_DECL)
510 print_node_brief (file, "initial", DECL_INITIAL (node),
511 indent + 4);
513 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WRTL))
515 print_node_brief (file, "abstract_origin",
516 DECL_ABSTRACT_ORIGIN (node), indent + 4);
518 if (CODE_CONTAINS_STRUCT (code, TS_DECL_NON_COMMON))
520 print_node (file, "result", DECL_RESULT_FLD (node), indent + 4);
523 lang_hooks.print_decl (file, node, indent);
525 if (DECL_RTL_SET_P (node))
527 indent_to (file, indent + 4);
528 print_rtl (file, DECL_RTL (node));
531 if (code == PARM_DECL)
533 print_node (file, "arg-type", DECL_ARG_TYPE (node), indent + 4);
535 if (DECL_INCOMING_RTL (node) != 0)
537 indent_to (file, indent + 4);
538 fprintf (file, "incoming-rtl ");
539 print_rtl (file, DECL_INCOMING_RTL (node));
542 else if (code == FUNCTION_DECL
543 && DECL_STRUCT_FUNCTION (node) != 0)
545 print_node (file, "arguments", DECL_ARGUMENTS (node), indent + 4);
546 indent_to (file, indent + 4);
547 dump_addr (file, "struct-function ", DECL_STRUCT_FUNCTION (node));
550 if ((code == VAR_DECL || code == PARM_DECL)
551 && DECL_HAS_VALUE_EXPR_P (node))
552 print_node (file, "value-expr", DECL_VALUE_EXPR (node), indent + 4);
554 /* Print the decl chain only if decl is at second level. */
555 if (indent == 4)
556 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
557 else
558 print_node_brief (file, "chain", TREE_CHAIN (node), indent + 4);
559 break;
561 case tcc_type:
562 if (TYPE_UNSIGNED (node))
563 fputs (" unsigned", file);
565 if (TYPE_NO_FORCE_BLK (node))
566 fputs (" no-force-blk", file);
568 if (TYPE_STRING_FLAG (node))
569 fputs (" string-flag", file);
571 if (TYPE_NEEDS_CONSTRUCTING (node))
572 fputs (" needs-constructing", file);
574 /* The transparent-union flag is used for different things in
575 different nodes. */
576 if ((code == UNION_TYPE || code == RECORD_TYPE)
577 && TYPE_TRANSPARENT_AGGR (node))
578 fputs (" transparent-aggr", file);
579 else if (code == ARRAY_TYPE
580 && TYPE_NONALIASED_COMPONENT (node))
581 fputs (" nonaliased-component", file);
583 if (TYPE_PACKED (node))
584 fputs (" packed", file);
586 if (TYPE_RESTRICT (node))
587 fputs (" restrict", file);
589 if (TYPE_LANG_FLAG_0 (node))
590 fputs (" type_0", file);
591 if (TYPE_LANG_FLAG_1 (node))
592 fputs (" type_1", file);
593 if (TYPE_LANG_FLAG_2 (node))
594 fputs (" type_2", file);
595 if (TYPE_LANG_FLAG_3 (node))
596 fputs (" type_3", file);
597 if (TYPE_LANG_FLAG_4 (node))
598 fputs (" type_4", file);
599 if (TYPE_LANG_FLAG_5 (node))
600 fputs (" type_5", file);
601 if (TYPE_LANG_FLAG_6 (node))
602 fputs (" type_6", file);
604 mode = TYPE_MODE (node);
605 fprintf (file, " %s", GET_MODE_NAME (mode));
607 print_node (file, "size", TYPE_SIZE (node), indent + 4);
608 print_node (file, "unit size", TYPE_SIZE_UNIT (node), indent + 4);
609 indent_to (file, indent + 3);
611 if (TYPE_USER_ALIGN (node))
612 fprintf (file, " user");
614 fprintf (file, " align %d symtab %d alias set " HOST_WIDE_INT_PRINT_DEC,
615 TYPE_ALIGN (node), TYPE_SYMTAB_ADDRESS (node),
616 (HOST_WIDE_INT) TYPE_ALIAS_SET (node));
618 if (TYPE_STRUCTURAL_EQUALITY_P (node))
619 fprintf (file, " structural equality");
620 else
621 dump_addr (file, " canonical type ", TYPE_CANONICAL (node));
623 print_node (file, "attributes", TYPE_ATTRIBUTES (node), indent + 4);
625 if (INTEGRAL_TYPE_P (node) || code == REAL_TYPE
626 || code == FIXED_POINT_TYPE)
628 fprintf (file, " precision %d", TYPE_PRECISION (node));
629 print_node_brief (file, "min", TYPE_MIN_VALUE (node), indent + 4);
630 print_node_brief (file, "max", TYPE_MAX_VALUE (node), indent + 4);
633 if (code == ENUMERAL_TYPE)
634 print_node (file, "values", TYPE_VALUES (node), indent + 4);
635 else if (code == ARRAY_TYPE)
636 print_node (file, "domain", TYPE_DOMAIN (node), indent + 4);
637 else if (code == VECTOR_TYPE)
638 fprintf (file, " nunits %d", (int) TYPE_VECTOR_SUBPARTS (node));
639 else if (code == RECORD_TYPE
640 || code == UNION_TYPE
641 || code == QUAL_UNION_TYPE)
642 print_node (file, "fields", TYPE_FIELDS (node), indent + 4);
643 else if (code == FUNCTION_TYPE
644 || code == METHOD_TYPE)
646 if (TYPE_METHOD_BASETYPE (node))
647 print_node_brief (file, "method basetype",
648 TYPE_METHOD_BASETYPE (node), indent + 4);
649 print_node (file, "arg-types", TYPE_ARG_TYPES (node), indent + 4);
651 else if (code == OFFSET_TYPE)
652 print_node_brief (file, "basetype", TYPE_OFFSET_BASETYPE (node),
653 indent + 4);
655 if (TYPE_CONTEXT (node))
656 print_node_brief (file, "context", TYPE_CONTEXT (node), indent + 4);
658 lang_hooks.print_type (file, node, indent);
660 if (TYPE_POINTER_TO (node) || TREE_CHAIN (node))
661 indent_to (file, indent + 3);
663 print_node_brief (file, "pointer_to_this", TYPE_POINTER_TO (node),
664 indent + 4);
665 print_node_brief (file, "reference_to_this", TYPE_REFERENCE_TO (node),
666 indent + 4);
667 print_node_brief (file, "chain", TREE_CHAIN (node), indent + 4);
668 break;
670 case tcc_expression:
671 case tcc_comparison:
672 case tcc_unary:
673 case tcc_binary:
674 case tcc_reference:
675 case tcc_statement:
676 case tcc_vl_exp:
677 if (code == BIND_EXPR)
679 print_node (file, "vars", TREE_OPERAND (node, 0), indent + 4);
680 print_node (file, "body", TREE_OPERAND (node, 1), indent + 4);
681 print_node (file, "block", TREE_OPERAND (node, 2), indent + 4);
682 break;
684 if (code == CALL_EXPR)
686 call_expr_arg_iterator iter;
687 tree arg;
688 print_node (file, "fn", CALL_EXPR_FN (node), indent + 4);
689 print_node (file, "static_chain", CALL_EXPR_STATIC_CHAIN (node),
690 indent + 4);
691 i = 0;
692 FOR_EACH_CALL_EXPR_ARG (arg, iter, node)
694 char temp[10];
695 sprintf (temp, "arg %d", i);
696 print_node (file, temp, arg, indent + 4);
697 i++;
700 else
702 len = TREE_OPERAND_LENGTH (node);
704 for (i = 0; i < len; i++)
706 char temp[10];
708 sprintf (temp, "arg %d", i);
709 print_node (file, temp, TREE_OPERAND (node, i), indent + 4);
712 if (CODE_CONTAINS_STRUCT (code, TS_COMMON))
713 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
714 break;
716 case tcc_constant:
717 case tcc_exceptional:
718 switch (code)
720 case INTEGER_CST:
721 if (TREE_OVERFLOW (node))
722 fprintf (file, " overflow");
724 fprintf (file, " ");
725 print_dec (node, file, TYPE_SIGN (TREE_TYPE (node)));
726 break;
728 case REAL_CST:
730 REAL_VALUE_TYPE d;
732 if (TREE_OVERFLOW (node))
733 fprintf (file, " overflow");
735 d = TREE_REAL_CST (node);
736 if (REAL_VALUE_ISINF (d))
737 fprintf (file, REAL_VALUE_NEGATIVE (d) ? " -Inf" : " Inf");
738 else if (REAL_VALUE_ISNAN (d))
739 fprintf (file, " Nan");
740 else
742 char string[64];
743 real_to_decimal (string, &d, sizeof (string), 0, 1);
744 fprintf (file, " %s", string);
747 break;
749 case FIXED_CST:
751 FIXED_VALUE_TYPE f;
752 char string[64];
754 if (TREE_OVERFLOW (node))
755 fprintf (file, " overflow");
757 f = TREE_FIXED_CST (node);
758 fixed_to_decimal (string, &f, sizeof (string));
759 fprintf (file, " %s", string);
761 break;
763 case VECTOR_CST:
765 char buf[10];
766 unsigned i;
768 for (i = 0; i < VECTOR_CST_NELTS (node); ++i)
770 sprintf (buf, "elt%u: ", i);
771 print_node (file, buf, VECTOR_CST_ELT (node, i), indent + 4);
774 break;
776 case COMPLEX_CST:
777 print_node (file, "real", TREE_REALPART (node), indent + 4);
778 print_node (file, "imag", TREE_IMAGPART (node), indent + 4);
779 break;
781 case STRING_CST:
783 const char *p = TREE_STRING_POINTER (node);
784 int i = TREE_STRING_LENGTH (node);
785 fputs (" \"", file);
786 while (--i >= 0)
788 char ch = *p++;
789 if (ch >= ' ' && ch < 127)
790 putc (ch, file);
791 else
792 fprintf (file, "\\%03o", ch & 0xFF);
794 fputc ('\"', file);
796 break;
798 case IDENTIFIER_NODE:
799 lang_hooks.print_identifier (file, node, indent);
800 break;
802 case TREE_LIST:
803 print_node (file, "purpose", TREE_PURPOSE (node), indent + 4);
804 print_node (file, "value", TREE_VALUE (node), indent + 4);
805 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
806 break;
808 case TREE_VEC:
809 len = TREE_VEC_LENGTH (node);
810 fprintf (file, " length %d", len);
811 for (i = 0; i < len; i++)
812 if (TREE_VEC_ELT (node, i))
814 char temp[10];
815 sprintf (temp, "elt %d", i);
816 print_node (file, temp, TREE_VEC_ELT (node, i), indent + 4);
818 break;
820 case CONSTRUCTOR:
822 unsigned HOST_WIDE_INT cnt;
823 tree index, value;
824 len = vec_safe_length (CONSTRUCTOR_ELTS (node));
825 fprintf (file, " lngt %d", len);
826 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (node),
827 cnt, index, value)
829 print_node (file, "idx", index, indent + 4);
830 print_node (file, "val", value, indent + 4);
833 break;
835 case STATEMENT_LIST:
836 dump_addr (file, " head ", node->stmt_list.head);
837 dump_addr (file, " tail ", node->stmt_list.tail);
838 fprintf (file, " stmts");
840 tree_stmt_iterator i;
841 for (i = tsi_start (node); !tsi_end_p (i); tsi_next (&i))
843 /* Not printing the addresses of the (not-a-tree)
844 'struct tree_stmt_list_node's. */
845 dump_addr (file, " ", tsi_stmt (i));
847 fprintf (file, "\n");
848 for (i = tsi_start (node); !tsi_end_p (i); tsi_next (&i))
850 /* Not printing the addresses of the (not-a-tree)
851 'struct tree_stmt_list_node's. */
852 print_node (file, "stmt", tsi_stmt (i), indent + 4);
855 break;
857 case BLOCK:
858 print_node (file, "vars", BLOCK_VARS (node), indent + 4);
859 print_node (file, "supercontext", BLOCK_SUPERCONTEXT (node),
860 indent + 4);
861 print_node (file, "subblocks", BLOCK_SUBBLOCKS (node), indent + 4);
862 print_node (file, "chain", BLOCK_CHAIN (node), indent + 4);
863 print_node (file, "abstract_origin",
864 BLOCK_ABSTRACT_ORIGIN (node), indent + 4);
865 break;
867 case SSA_NAME:
868 print_node_brief (file, "var", SSA_NAME_VAR (node), indent + 4);
869 fprintf (file, "def_stmt ");
870 print_gimple_stmt (file, SSA_NAME_DEF_STMT (node), indent + 4, 0);
872 indent_to (file, indent + 4);
873 fprintf (file, "version %u", SSA_NAME_VERSION (node));
874 if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (node))
875 fprintf (file, " in-abnormal-phi");
876 if (SSA_NAME_IN_FREE_LIST (node))
877 fprintf (file, " in-free-list");
879 if (SSA_NAME_PTR_INFO (node))
881 indent_to (file, indent + 3);
882 if (SSA_NAME_PTR_INFO (node))
883 dump_addr (file, " ptr-info ", SSA_NAME_PTR_INFO (node));
885 break;
887 case OMP_CLAUSE:
889 int i;
890 fprintf (file, " %s",
891 omp_clause_code_name[OMP_CLAUSE_CODE (node)]);
892 for (i = 0; i < omp_clause_num_ops[OMP_CLAUSE_CODE (node)]; i++)
894 indent_to (file, indent + 4);
895 fprintf (file, "op %d:", i);
896 print_node_brief (file, "", OMP_CLAUSE_OPERAND (node, i), 0);
899 break;
901 case OPTIMIZATION_NODE:
902 cl_optimization_print (file, indent + 4, TREE_OPTIMIZATION (node));
903 break;
905 case TARGET_OPTION_NODE:
906 cl_target_option_print (file, indent + 4, TREE_TARGET_OPTION (node));
907 break;
908 case IMPORTED_DECL:
909 fprintf (file, " imported declaration");
910 print_node_brief (file, "associated declaration",
911 IMPORTED_DECL_ASSOCIATED_DECL (node),
912 indent + 4);
913 break;
915 default:
916 if (EXCEPTIONAL_CLASS_P (node))
917 lang_hooks.print_xnode (file, node, indent);
918 break;
921 break;
924 if (EXPR_HAS_LOCATION (node))
926 expanded_location xloc = expand_location (EXPR_LOCATION (node));
927 indent_to (file, indent+4);
928 fprintf (file, "%s:%d:%d", xloc.file, xloc.line, xloc.column);
931 fprintf (file, ">");
935 /* Print the node NODE on standard error, for debugging.
936 Most nodes referred to by this one are printed recursively
937 down to a depth of six. */
939 DEBUG_FUNCTION void
940 debug_tree (tree node)
942 table = XCNEWVEC (struct bucket *, HASH_SIZE);
943 print_node (stderr, "", node, 0);
944 free (table);
945 table = 0;
946 putc ('\n', stderr);
949 DEBUG_FUNCTION void
950 debug_raw (const tree_node &ref)
952 debug_tree (const_cast <tree> (&ref));
955 DEBUG_FUNCTION void
956 debug_raw (const tree_node *ptr)
958 if (ptr)
959 debug_raw (*ptr);
960 else
961 fprintf (stderr, "<nil>\n");
964 static void
965 dump_tree_via_hooks (const tree_node *ptr, int options)
967 if (DECL_P (ptr))
968 lang_hooks.print_decl (stderr, const_cast <tree_node*> (ptr), 0);
969 else if (TYPE_P (ptr))
970 lang_hooks.print_type (stderr, const_cast <tree_node*> (ptr), 0);
971 else if (TREE_CODE (ptr) == IDENTIFIER_NODE)
972 lang_hooks.print_identifier (stderr, const_cast <tree_node*> (ptr), 0);
973 else
974 print_generic_expr (stderr, const_cast <tree_node*> (ptr), options);
975 fprintf (stderr, "\n");
978 DEBUG_FUNCTION void
979 debug (const tree_node &ref)
981 dump_tree_via_hooks (&ref, 0);
984 DEBUG_FUNCTION void
985 debug (const tree_node *ptr)
987 if (ptr)
988 debug (*ptr);
989 else
990 fprintf (stderr, "<nil>\n");
993 DEBUG_FUNCTION void
994 debug_verbose (const tree_node &ref)
996 dump_tree_via_hooks (&ref, TDF_VERBOSE);
999 DEBUG_FUNCTION void
1000 debug_verbose (const tree_node *ptr)
1002 if (ptr)
1003 debug_verbose (*ptr);
1004 else
1005 fprintf (stderr, "<nil>\n");
1008 DEBUG_FUNCTION void
1009 debug_head (const tree_node &ref)
1011 debug (ref);
1014 DEBUG_FUNCTION void
1015 debug_head (const tree_node *ptr)
1017 if (ptr)
1018 debug_head (*ptr);
1019 else
1020 fprintf (stderr, "<nil>\n");
1023 DEBUG_FUNCTION void
1024 debug_body (const tree_node &ref)
1026 if (TREE_CODE (&ref) == FUNCTION_DECL)
1027 dump_function_to_file (const_cast <tree_node*> (&ref), stderr, 0);
1028 else
1029 debug (ref);
1032 DEBUG_FUNCTION void
1033 debug_body (const tree_node *ptr)
1035 if (ptr)
1036 debug_body (*ptr);
1037 else
1038 fprintf (stderr, "<nil>\n");
1041 /* Print the vector of trees VEC on standard error, for debugging.
1042 Most nodes referred to by this one are printed recursively
1043 down to a depth of six. */
1045 DEBUG_FUNCTION void
1046 debug_raw (vec<tree, va_gc> &ref)
1048 tree elt;
1049 unsigned ix;
1051 /* Print the slot this node is in, and its code, and address. */
1052 fprintf (stderr, "<VEC");
1053 dump_addr (stderr, " ", ref.address ());
1055 FOR_EACH_VEC_ELT (ref, ix, elt)
1057 fprintf (stderr, "elt %d ", ix);
1058 debug_raw (elt);
1062 DEBUG_FUNCTION void
1063 debug (vec<tree, va_gc> &ref)
1065 tree elt;
1066 unsigned ix;
1068 /* Print the slot this node is in, and its code, and address. */
1069 fprintf (stderr, "<VEC");
1070 dump_addr (stderr, " ", ref.address ());
1072 FOR_EACH_VEC_ELT (ref, ix, elt)
1074 fprintf (stderr, "elt %d ", ix);
1075 debug (elt);
1079 DEBUG_FUNCTION void
1080 debug (vec<tree, va_gc> *ptr)
1082 if (ptr)
1083 debug (*ptr);
1084 else
1085 fprintf (stderr, "<nil>\n");
1088 DEBUG_FUNCTION void
1089 debug_raw (vec<tree, va_gc> *ptr)
1091 if (ptr)
1092 debug_raw (*ptr);
1093 else
1094 fprintf (stderr, "<nil>\n");
1097 DEBUG_FUNCTION void
1098 debug_vec_tree (vec<tree, va_gc> *vec)
1100 debug_raw (vec);