2015-06-11 Paul Thomas <pault@gcc.gnu.org>
[official-gcc.git] / gcc / print-tree.c
blob19a0aa56218e2f8df22111c2297f8bdf26a9d9c1
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 "input.h"
26 #include "alias.h"
27 #include "symtab.h"
28 #include "tree.h"
29 #include "varasm.h"
30 #include "print-rtl.h"
31 #include "stor-layout.h"
32 #include "langhooks.h"
33 #include "tree-iterator.h"
34 #include "diagnostic.h"
35 #include "gimple-pretty-print.h" /* FIXME */
36 #include "is-a.h"
37 #include "plugin-api.h"
38 #include "hard-reg-set.h"
39 #include "input.h"
40 #include "function.h"
41 #include "ipa-ref.h"
42 #include "cgraph.h"
43 #include "tree-cfg.h"
44 #include "tree-dump.h"
45 #include "dumpfile.h"
46 #include "wide-int-print.h"
48 /* Define the hash table of nodes already seen.
49 Such nodes are not repeated; brief cross-references are used. */
51 #define HASH_SIZE 37
53 struct bucket
55 tree node;
56 struct bucket *next;
59 static struct bucket **table;
61 /* Print PREFIX and ADDR to FILE. */
62 void
63 dump_addr (FILE *file, const char *prefix, const void *addr)
65 if (flag_dump_noaddr || flag_dump_unnumbered)
66 fprintf (file, "%s#", prefix);
67 else
68 fprintf (file, "%s" HOST_PTR_PRINTF, prefix, addr);
71 /* Print a node in brief fashion, with just the code, address and name. */
73 void
74 print_node_brief (FILE *file, const char *prefix, const_tree node, int indent)
76 enum tree_code_class tclass;
78 if (node == 0)
79 return;
81 tclass = TREE_CODE_CLASS (TREE_CODE (node));
83 /* Always print the slot this node is in, and its code, address and
84 name if any. */
85 if (indent > 0)
86 fprintf (file, " ");
87 fprintf (file, "%s <%s", prefix, get_tree_code_name (TREE_CODE (node)));
88 dump_addr (file, " ", node);
90 if (tclass == tcc_declaration)
92 if (DECL_NAME (node))
93 fprintf (file, " %s", IDENTIFIER_POINTER (DECL_NAME (node)));
94 else if (TREE_CODE (node) == LABEL_DECL
95 && LABEL_DECL_UID (node) != -1)
97 if (dump_flags & TDF_NOUID)
98 fprintf (file, " L.xxxx");
99 else
100 fprintf (file, " L.%d", (int) LABEL_DECL_UID (node));
102 else
104 if (dump_flags & TDF_NOUID)
105 fprintf (file, " %c.xxxx",
106 TREE_CODE (node) == CONST_DECL ? 'C' : 'D');
107 else
108 fprintf (file, " %c.%u",
109 TREE_CODE (node) == CONST_DECL ? 'C' : 'D',
110 DECL_UID (node));
113 else if (tclass == tcc_type)
115 if (TYPE_NAME (node))
117 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
118 fprintf (file, " %s", IDENTIFIER_POINTER (TYPE_NAME (node)));
119 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
120 && DECL_NAME (TYPE_NAME (node)))
121 fprintf (file, " %s",
122 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node))));
124 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (node)))
125 fprintf (file, " address-space-%d", TYPE_ADDR_SPACE (node));
127 if (TREE_CODE (node) == IDENTIFIER_NODE)
128 fprintf (file, " %s", IDENTIFIER_POINTER (node));
130 /* We might as well always print the value of an integer or real. */
131 if (TREE_CODE (node) == INTEGER_CST)
133 if (TREE_OVERFLOW (node))
134 fprintf (file, " overflow");
136 fprintf (file, " ");
137 print_dec (node, file, TYPE_SIGN (TREE_TYPE (node)));
139 if (TREE_CODE (node) == REAL_CST)
141 REAL_VALUE_TYPE d;
143 if (TREE_OVERFLOW (node))
144 fprintf (file, " overflow");
146 d = TREE_REAL_CST (node);
147 if (REAL_VALUE_ISINF (d))
148 fprintf (file, REAL_VALUE_NEGATIVE (d) ? " -Inf" : " Inf");
149 else if (REAL_VALUE_ISNAN (d))
150 fprintf (file, " Nan");
151 else
153 char string[60];
154 real_to_decimal (string, &d, sizeof (string), 0, 1);
155 fprintf (file, " %s", string);
158 if (TREE_CODE (node) == FIXED_CST)
160 FIXED_VALUE_TYPE f;
161 char string[60];
163 if (TREE_OVERFLOW (node))
164 fprintf (file, " overflow");
166 f = TREE_FIXED_CST (node);
167 fixed_to_decimal (string, &f, sizeof (string));
168 fprintf (file, " %s", string);
171 fprintf (file, ">");
174 void
175 indent_to (FILE *file, int column)
177 int i;
179 /* Since this is the long way, indent to desired column. */
180 if (column > 0)
181 fprintf (file, "\n");
182 for (i = 0; i < column; i++)
183 fprintf (file, " ");
186 /* Print the node NODE in full on file FILE, preceded by PREFIX,
187 starting in column INDENT. */
189 void
190 print_node (FILE *file, const char *prefix, tree node, int indent)
192 int hash;
193 struct bucket *b;
194 machine_mode mode;
195 enum tree_code_class tclass;
196 int len;
197 int i;
198 expanded_location xloc;
199 enum tree_code code;
201 if (node == 0)
202 return;
204 code = TREE_CODE (node);
205 tclass = TREE_CODE_CLASS (code);
207 /* Don't get too deep in nesting. If the user wants to see deeper,
208 it is easy to use the address of a lowest-level node
209 as an argument in another call to debug_tree. */
211 if (indent > 24)
213 print_node_brief (file, prefix, node, indent);
214 return;
217 if (indent > 8 && (tclass == tcc_type || tclass == tcc_declaration))
219 print_node_brief (file, prefix, node, indent);
220 return;
223 /* It is unsafe to look at any other fields of an ERROR_MARK node. */
224 if (code == ERROR_MARK)
226 print_node_brief (file, prefix, node, indent);
227 return;
230 /* Allow this function to be called if the table is not there. */
231 if (table)
233 hash = ((uintptr_t) node) % HASH_SIZE;
235 /* If node is in the table, just mention its address. */
236 for (b = table[hash]; b; b = b->next)
237 if (b->node == node)
239 print_node_brief (file, prefix, node, indent);
240 return;
243 /* Add this node to the table. */
244 b = XNEW (struct bucket);
245 b->node = node;
246 b->next = table[hash];
247 table[hash] = b;
250 /* Indent to the specified column, since this is the long form. */
251 indent_to (file, indent);
253 /* Print the slot this node is in, and its code, and address. */
254 fprintf (file, "%s <%s", prefix, get_tree_code_name (code));
255 dump_addr (file, " ", node);
257 /* Print the name, if any. */
258 if (tclass == tcc_declaration)
260 if (DECL_NAME (node))
261 fprintf (file, " %s", IDENTIFIER_POINTER (DECL_NAME (node)));
262 else if (code == LABEL_DECL
263 && LABEL_DECL_UID (node) != -1)
265 if (dump_flags & TDF_NOUID)
266 fprintf (file, " L.xxxx");
267 else
268 fprintf (file, " L.%d", (int) LABEL_DECL_UID (node));
270 else
272 if (dump_flags & TDF_NOUID)
273 fprintf (file, " %c.xxxx", code == CONST_DECL ? 'C' : 'D');
274 else
275 fprintf (file, " %c.%u", code == CONST_DECL ? 'C' : 'D',
276 DECL_UID (node));
279 else if (tclass == tcc_type)
281 if (TYPE_NAME (node))
283 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
284 fprintf (file, " %s", IDENTIFIER_POINTER (TYPE_NAME (node)));
285 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
286 && DECL_NAME (TYPE_NAME (node)))
287 fprintf (file, " %s",
288 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node))));
291 if (code == IDENTIFIER_NODE)
292 fprintf (file, " %s", IDENTIFIER_POINTER (node));
294 if (code == INTEGER_CST)
296 if (indent <= 4)
297 print_node_brief (file, "type", TREE_TYPE (node), indent + 4);
299 else if (CODE_CONTAINS_STRUCT (code, TS_TYPED))
301 print_node (file, "type", TREE_TYPE (node), indent + 4);
302 if (TREE_TYPE (node))
303 indent_to (file, indent + 3);
306 if (!TYPE_P (node) && TREE_SIDE_EFFECTS (node))
307 fputs (" side-effects", file);
309 if (TYPE_P (node) ? TYPE_READONLY (node) : TREE_READONLY (node))
310 fputs (" readonly", file);
311 if (TYPE_P (node) && TYPE_ATOMIC (node))
312 fputs (" atomic", file);
313 if (!TYPE_P (node) && TREE_CONSTANT (node))
314 fputs (" constant", file);
315 else if (TYPE_P (node) && TYPE_SIZES_GIMPLIFIED (node))
316 fputs (" sizes-gimplified", file);
318 if (TYPE_P (node) && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (node)))
319 fprintf (file, " address-space-%d", TYPE_ADDR_SPACE (node));
321 if (TREE_ADDRESSABLE (node))
322 fputs (" addressable", file);
323 if (TREE_THIS_VOLATILE (node))
324 fputs (" volatile", file);
325 if (TREE_ASM_WRITTEN (node))
326 fputs (" asm_written", file);
327 if (TREE_USED (node))
328 fputs (" used", file);
329 if (TREE_NOTHROW (node))
330 fputs (TYPE_P (node) ? " align-ok" : " nothrow", file);
331 if (TREE_PUBLIC (node))
332 fputs (" public", file);
333 if (TREE_PRIVATE (node))
334 fputs (" private", file);
335 if (TREE_PROTECTED (node))
336 fputs (" protected", file);
337 if (TREE_STATIC (node))
338 fputs (" static", file);
339 if (TREE_DEPRECATED (node))
340 fputs (" deprecated", file);
341 if (TREE_VISITED (node))
342 fputs (" visited", file);
344 if (code != TREE_VEC && code != INTEGER_CST && code != SSA_NAME)
346 if (TREE_LANG_FLAG_0 (node))
347 fputs (" tree_0", file);
348 if (TREE_LANG_FLAG_1 (node))
349 fputs (" tree_1", file);
350 if (TREE_LANG_FLAG_2 (node))
351 fputs (" tree_2", file);
352 if (TREE_LANG_FLAG_3 (node))
353 fputs (" tree_3", file);
354 if (TREE_LANG_FLAG_4 (node))
355 fputs (" tree_4", file);
356 if (TREE_LANG_FLAG_5 (node))
357 fputs (" tree_5", file);
358 if (TREE_LANG_FLAG_6 (node))
359 fputs (" tree_6", file);
362 /* DECL_ nodes have additional attributes. */
364 switch (TREE_CODE_CLASS (code))
366 case tcc_declaration:
367 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
369 if (DECL_UNSIGNED (node))
370 fputs (" unsigned", file);
371 if (DECL_IGNORED_P (node))
372 fputs (" ignored", file);
373 if (DECL_ABSTRACT_P (node))
374 fputs (" abstract", file);
375 if (DECL_EXTERNAL (node))
376 fputs (" external", file);
377 if (DECL_NONLOCAL (node))
378 fputs (" nonlocal", file);
380 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
382 if (DECL_WEAK (node))
383 fputs (" weak", file);
384 if (DECL_IN_SYSTEM_HEADER (node))
385 fputs (" in_system_header", file);
387 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WRTL)
388 && code != LABEL_DECL
389 && code != FUNCTION_DECL
390 && DECL_REGISTER (node))
391 fputs (" regdecl", file);
393 if (code == TYPE_DECL && TYPE_DECL_SUPPRESS_DEBUG (node))
394 fputs (" suppress-debug", file);
396 if (code == FUNCTION_DECL
397 && DECL_FUNCTION_SPECIFIC_TARGET (node))
398 fputs (" function-specific-target", file);
399 if (code == FUNCTION_DECL
400 && DECL_FUNCTION_SPECIFIC_OPTIMIZATION (node))
401 fputs (" function-specific-opt", file);
402 if (code == FUNCTION_DECL && DECL_DECLARED_INLINE_P (node))
403 fputs (" autoinline", file);
404 if (code == FUNCTION_DECL && DECL_BUILT_IN (node))
405 fputs (" built-in", file);
406 if (code == FUNCTION_DECL && DECL_STATIC_CHAIN (node))
407 fputs (" static-chain", file);
408 if (TREE_CODE (node) == FUNCTION_DECL && decl_is_tm_clone (node))
409 fputs (" tm-clone", file);
411 if (code == FIELD_DECL && DECL_PACKED (node))
412 fputs (" packed", file);
413 if (code == FIELD_DECL && DECL_BIT_FIELD (node))
414 fputs (" bit-field", file);
415 if (code == FIELD_DECL && DECL_NONADDRESSABLE_P (node))
416 fputs (" nonaddressable", file);
418 if (code == LABEL_DECL && EH_LANDING_PAD_NR (node))
419 fprintf (file, " landing-pad:%d", EH_LANDING_PAD_NR (node));
421 if (code == VAR_DECL && DECL_IN_TEXT_SECTION (node))
422 fputs (" in-text-section", file);
423 if (code == VAR_DECL && DECL_IN_CONSTANT_POOL (node))
424 fputs (" in-constant-pool", file);
425 if (code == VAR_DECL && DECL_COMMON (node))
426 fputs (" common", file);
427 if (code == VAR_DECL && DECL_THREAD_LOCAL_P (node))
429 fputs (" ", file);
430 fputs (tls_model_names[DECL_TLS_MODEL (node)], file);
433 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
435 if (DECL_VIRTUAL_P (node))
436 fputs (" virtual", file);
437 if (DECL_PRESERVE_P (node))
438 fputs (" preserve", file);
439 if (DECL_LANG_FLAG_0 (node))
440 fputs (" decl_0", file);
441 if (DECL_LANG_FLAG_1 (node))
442 fputs (" decl_1", file);
443 if (DECL_LANG_FLAG_2 (node))
444 fputs (" decl_2", file);
445 if (DECL_LANG_FLAG_3 (node))
446 fputs (" decl_3", file);
447 if (DECL_LANG_FLAG_4 (node))
448 fputs (" decl_4", file);
449 if (DECL_LANG_FLAG_5 (node))
450 fputs (" decl_5", file);
451 if (DECL_LANG_FLAG_6 (node))
452 fputs (" decl_6", file);
453 if (DECL_LANG_FLAG_7 (node))
454 fputs (" decl_7", file);
456 mode = DECL_MODE (node);
457 fprintf (file, " %s", GET_MODE_NAME (mode));
460 if ((code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
461 && DECL_BY_REFERENCE (node))
462 fputs (" passed-by-reference", file);
464 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS) && DECL_DEFER_OUTPUT (node))
465 fputs (" defer-output", file);
468 xloc = expand_location (DECL_SOURCE_LOCATION (node));
469 fprintf (file, " file %s line %d col %d", xloc.file, xloc.line,
470 xloc.column);
472 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
474 print_node (file, "size", DECL_SIZE (node), indent + 4);
475 print_node (file, "unit size", DECL_SIZE_UNIT (node), indent + 4);
477 if (code != FUNCTION_DECL || DECL_BUILT_IN (node))
478 indent_to (file, indent + 3);
480 if (DECL_USER_ALIGN (node))
481 fprintf (file, " user");
483 fprintf (file, " align %d", DECL_ALIGN (node));
484 if (code == FIELD_DECL)
485 fprintf (file, " offset_align " HOST_WIDE_INT_PRINT_UNSIGNED,
486 DECL_OFFSET_ALIGN (node));
488 if (code == FUNCTION_DECL && DECL_BUILT_IN (node))
490 if (DECL_BUILT_IN_CLASS (node) == BUILT_IN_MD)
491 fprintf (file, " built-in BUILT_IN_MD %d", DECL_FUNCTION_CODE (node));
492 else
493 fprintf (file, " built-in %s:%s",
494 built_in_class_names[(int) DECL_BUILT_IN_CLASS (node)],
495 built_in_names[(int) DECL_FUNCTION_CODE (node)]);
498 if (code == FIELD_DECL)
500 print_node (file, "offset", DECL_FIELD_OFFSET (node), indent + 4);
501 print_node (file, "bit offset", DECL_FIELD_BIT_OFFSET (node),
502 indent + 4);
503 if (DECL_BIT_FIELD_TYPE (node))
504 print_node (file, "bit_field_type", DECL_BIT_FIELD_TYPE (node),
505 indent + 4);
508 print_node_brief (file, "context", DECL_CONTEXT (node), indent + 4);
510 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
512 print_node_brief (file, "attributes",
513 DECL_ATTRIBUTES (node), indent + 4);
514 if (code != PARM_DECL)
515 print_node_brief (file, "initial", DECL_INITIAL (node),
516 indent + 4);
518 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WRTL))
520 print_node_brief (file, "abstract_origin",
521 DECL_ABSTRACT_ORIGIN (node), indent + 4);
523 if (CODE_CONTAINS_STRUCT (code, TS_DECL_NON_COMMON))
525 print_node (file, "result", DECL_RESULT_FLD (node), indent + 4);
528 lang_hooks.print_decl (file, node, indent);
530 if (DECL_RTL_SET_P (node))
532 indent_to (file, indent + 4);
533 print_rtl (file, DECL_RTL (node));
536 if (code == PARM_DECL)
538 print_node (file, "arg-type", DECL_ARG_TYPE (node), indent + 4);
540 if (DECL_INCOMING_RTL (node) != 0)
542 indent_to (file, indent + 4);
543 fprintf (file, "incoming-rtl ");
544 print_rtl (file, DECL_INCOMING_RTL (node));
547 else if (code == FUNCTION_DECL
548 && DECL_STRUCT_FUNCTION (node) != 0)
550 print_node (file, "arguments", DECL_ARGUMENTS (node), indent + 4);
551 indent_to (file, indent + 4);
552 dump_addr (file, "struct-function ", DECL_STRUCT_FUNCTION (node));
555 if ((code == VAR_DECL || code == PARM_DECL)
556 && DECL_HAS_VALUE_EXPR_P (node))
557 print_node (file, "value-expr", DECL_VALUE_EXPR (node), indent + 4);
559 /* Print the decl chain only if decl is at second level. */
560 if (indent == 4)
561 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
562 else
563 print_node_brief (file, "chain", TREE_CHAIN (node), indent + 4);
564 break;
566 case tcc_type:
567 if (TYPE_UNSIGNED (node))
568 fputs (" unsigned", file);
570 if (TYPE_NO_FORCE_BLK (node))
571 fputs (" no-force-blk", file);
573 if (TYPE_STRING_FLAG (node))
574 fputs (" string-flag", file);
576 if (TYPE_NEEDS_CONSTRUCTING (node))
577 fputs (" needs-constructing", file);
579 /* The transparent-union flag is used for different things in
580 different nodes. */
581 if ((code == UNION_TYPE || code == RECORD_TYPE)
582 && TYPE_TRANSPARENT_AGGR (node))
583 fputs (" transparent-aggr", file);
584 else if (code == ARRAY_TYPE
585 && TYPE_NONALIASED_COMPONENT (node))
586 fputs (" nonaliased-component", file);
588 if (TYPE_PACKED (node))
589 fputs (" packed", file);
591 if (TYPE_RESTRICT (node))
592 fputs (" restrict", file);
594 if (TYPE_LANG_FLAG_0 (node))
595 fputs (" type_0", file);
596 if (TYPE_LANG_FLAG_1 (node))
597 fputs (" type_1", file);
598 if (TYPE_LANG_FLAG_2 (node))
599 fputs (" type_2", file);
600 if (TYPE_LANG_FLAG_3 (node))
601 fputs (" type_3", file);
602 if (TYPE_LANG_FLAG_4 (node))
603 fputs (" type_4", file);
604 if (TYPE_LANG_FLAG_5 (node))
605 fputs (" type_5", file);
606 if (TYPE_LANG_FLAG_6 (node))
607 fputs (" type_6", file);
609 mode = TYPE_MODE (node);
610 fprintf (file, " %s", GET_MODE_NAME (mode));
612 print_node (file, "size", TYPE_SIZE (node), indent + 4);
613 print_node (file, "unit size", TYPE_SIZE_UNIT (node), indent + 4);
614 indent_to (file, indent + 3);
616 if (TYPE_USER_ALIGN (node))
617 fprintf (file, " user");
619 fprintf (file, " align %d symtab %d alias set " HOST_WIDE_INT_PRINT_DEC,
620 TYPE_ALIGN (node), TYPE_SYMTAB_ADDRESS (node),
621 (HOST_WIDE_INT) TYPE_ALIAS_SET (node));
623 if (TYPE_STRUCTURAL_EQUALITY_P (node))
624 fprintf (file, " structural equality");
625 else
626 dump_addr (file, " canonical type ", TYPE_CANONICAL (node));
628 print_node (file, "attributes", TYPE_ATTRIBUTES (node), indent + 4);
630 if (INTEGRAL_TYPE_P (node) || code == REAL_TYPE
631 || code == FIXED_POINT_TYPE)
633 fprintf (file, " precision %d", TYPE_PRECISION (node));
634 print_node_brief (file, "min", TYPE_MIN_VALUE (node), indent + 4);
635 print_node_brief (file, "max", TYPE_MAX_VALUE (node), indent + 4);
638 if (code == ENUMERAL_TYPE)
639 print_node (file, "values", TYPE_VALUES (node), indent + 4);
640 else if (code == ARRAY_TYPE)
641 print_node (file, "domain", TYPE_DOMAIN (node), indent + 4);
642 else if (code == VECTOR_TYPE)
643 fprintf (file, " nunits %d", (int) TYPE_VECTOR_SUBPARTS (node));
644 else if (code == RECORD_TYPE
645 || code == UNION_TYPE
646 || code == QUAL_UNION_TYPE)
647 print_node (file, "fields", TYPE_FIELDS (node), indent + 4);
648 else if (code == FUNCTION_TYPE
649 || code == METHOD_TYPE)
651 if (TYPE_METHOD_BASETYPE (node))
652 print_node_brief (file, "method basetype",
653 TYPE_METHOD_BASETYPE (node), indent + 4);
654 print_node (file, "arg-types", TYPE_ARG_TYPES (node), indent + 4);
656 else if (code == OFFSET_TYPE)
657 print_node_brief (file, "basetype", TYPE_OFFSET_BASETYPE (node),
658 indent + 4);
660 if (TYPE_CONTEXT (node))
661 print_node_brief (file, "context", TYPE_CONTEXT (node), indent + 4);
663 lang_hooks.print_type (file, node, indent);
665 if (TYPE_POINTER_TO (node) || TREE_CHAIN (node))
666 indent_to (file, indent + 3);
668 print_node_brief (file, "pointer_to_this", TYPE_POINTER_TO (node),
669 indent + 4);
670 print_node_brief (file, "reference_to_this", TYPE_REFERENCE_TO (node),
671 indent + 4);
672 print_node_brief (file, "chain", TREE_CHAIN (node), indent + 4);
673 break;
675 case tcc_expression:
676 case tcc_comparison:
677 case tcc_unary:
678 case tcc_binary:
679 case tcc_reference:
680 case tcc_statement:
681 case tcc_vl_exp:
682 if (code == BIND_EXPR)
684 print_node (file, "vars", TREE_OPERAND (node, 0), indent + 4);
685 print_node (file, "body", TREE_OPERAND (node, 1), indent + 4);
686 print_node (file, "block", TREE_OPERAND (node, 2), indent + 4);
687 break;
689 if (code == CALL_EXPR)
691 call_expr_arg_iterator iter;
692 tree arg;
693 print_node (file, "fn", CALL_EXPR_FN (node), indent + 4);
694 print_node (file, "static_chain", CALL_EXPR_STATIC_CHAIN (node),
695 indent + 4);
696 i = 0;
697 FOR_EACH_CALL_EXPR_ARG (arg, iter, node)
699 char temp[10];
700 sprintf (temp, "arg %d", i);
701 print_node (file, temp, arg, indent + 4);
702 i++;
705 else
707 len = TREE_OPERAND_LENGTH (node);
709 for (i = 0; i < len; i++)
711 char temp[10];
713 sprintf (temp, "arg %d", i);
714 print_node (file, temp, TREE_OPERAND (node, i), indent + 4);
717 if (CODE_CONTAINS_STRUCT (code, TS_COMMON))
718 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
719 break;
721 case tcc_constant:
722 case tcc_exceptional:
723 switch (code)
725 case INTEGER_CST:
726 if (TREE_OVERFLOW (node))
727 fprintf (file, " overflow");
729 fprintf (file, " ");
730 print_dec (node, file, TYPE_SIGN (TREE_TYPE (node)));
731 break;
733 case REAL_CST:
735 REAL_VALUE_TYPE d;
737 if (TREE_OVERFLOW (node))
738 fprintf (file, " overflow");
740 d = TREE_REAL_CST (node);
741 if (REAL_VALUE_ISINF (d))
742 fprintf (file, REAL_VALUE_NEGATIVE (d) ? " -Inf" : " Inf");
743 else if (REAL_VALUE_ISNAN (d))
744 fprintf (file, " Nan");
745 else
747 char string[64];
748 real_to_decimal (string, &d, sizeof (string), 0, 1);
749 fprintf (file, " %s", string);
752 break;
754 case FIXED_CST:
756 FIXED_VALUE_TYPE f;
757 char string[64];
759 if (TREE_OVERFLOW (node))
760 fprintf (file, " overflow");
762 f = TREE_FIXED_CST (node);
763 fixed_to_decimal (string, &f, sizeof (string));
764 fprintf (file, " %s", string);
766 break;
768 case VECTOR_CST:
770 char buf[10];
771 unsigned i;
773 for (i = 0; i < VECTOR_CST_NELTS (node); ++i)
775 sprintf (buf, "elt%u: ", i);
776 print_node (file, buf, VECTOR_CST_ELT (node, i), indent + 4);
779 break;
781 case COMPLEX_CST:
782 print_node (file, "real", TREE_REALPART (node), indent + 4);
783 print_node (file, "imag", TREE_IMAGPART (node), indent + 4);
784 break;
786 case STRING_CST:
788 const char *p = TREE_STRING_POINTER (node);
789 int i = TREE_STRING_LENGTH (node);
790 fputs (" \"", file);
791 while (--i >= 0)
793 char ch = *p++;
794 if (ch >= ' ' && ch < 127)
795 putc (ch, file);
796 else
797 fprintf (file, "\\%03o", ch & 0xFF);
799 fputc ('\"', file);
801 break;
803 case IDENTIFIER_NODE:
804 lang_hooks.print_identifier (file, node, indent);
805 break;
807 case TREE_LIST:
808 print_node (file, "purpose", TREE_PURPOSE (node), indent + 4);
809 print_node (file, "value", TREE_VALUE (node), indent + 4);
810 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
811 break;
813 case TREE_VEC:
814 len = TREE_VEC_LENGTH (node);
815 for (i = 0; i < len; i++)
816 if (TREE_VEC_ELT (node, i))
818 char temp[10];
819 sprintf (temp, "elt %d", i);
820 print_node (file, temp, TREE_VEC_ELT (node, i), indent + 4);
822 break;
824 case CONSTRUCTOR:
826 unsigned HOST_WIDE_INT cnt;
827 tree index, value;
828 len = vec_safe_length (CONSTRUCTOR_ELTS (node));
829 fprintf (file, " lngt %d", len);
830 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (node),
831 cnt, index, value)
833 print_node (file, "idx", index, indent + 4);
834 print_node (file, "val", value, indent + 4);
837 break;
839 case STATEMENT_LIST:
840 dump_addr (file, " head ", node->stmt_list.head);
841 dump_addr (file, " tail ", node->stmt_list.tail);
842 fprintf (file, " stmts");
844 tree_stmt_iterator i;
845 for (i = tsi_start (node); !tsi_end_p (i); tsi_next (&i))
847 /* Not printing the addresses of the (not-a-tree)
848 'struct tree_stmt_list_node's. */
849 dump_addr (file, " ", tsi_stmt (i));
851 fprintf (file, "\n");
852 for (i = tsi_start (node); !tsi_end_p (i); tsi_next (&i))
854 /* Not printing the addresses of the (not-a-tree)
855 'struct tree_stmt_list_node's. */
856 print_node (file, "stmt", tsi_stmt (i), indent + 4);
859 break;
861 case BLOCK:
862 print_node (file, "vars", BLOCK_VARS (node), indent + 4);
863 print_node (file, "supercontext", BLOCK_SUPERCONTEXT (node),
864 indent + 4);
865 print_node (file, "subblocks", BLOCK_SUBBLOCKS (node), indent + 4);
866 print_node (file, "chain", BLOCK_CHAIN (node), indent + 4);
867 print_node (file, "abstract_origin",
868 BLOCK_ABSTRACT_ORIGIN (node), indent + 4);
869 break;
871 case SSA_NAME:
872 print_node_brief (file, "var", SSA_NAME_VAR (node), indent + 4);
873 fprintf (file, "def_stmt ");
874 print_gimple_stmt (file, SSA_NAME_DEF_STMT (node), indent + 4, 0);
876 indent_to (file, indent + 4);
877 fprintf (file, "version %u", SSA_NAME_VERSION (node));
878 if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (node))
879 fprintf (file, " in-abnormal-phi");
880 if (SSA_NAME_IN_FREE_LIST (node))
881 fprintf (file, " in-free-list");
883 if (SSA_NAME_PTR_INFO (node))
885 indent_to (file, indent + 3);
886 if (SSA_NAME_PTR_INFO (node))
887 dump_addr (file, " ptr-info ", SSA_NAME_PTR_INFO (node));
889 break;
891 case OMP_CLAUSE:
893 int i;
894 fprintf (file, " %s",
895 omp_clause_code_name[OMP_CLAUSE_CODE (node)]);
896 for (i = 0; i < omp_clause_num_ops[OMP_CLAUSE_CODE (node)]; i++)
898 indent_to (file, indent + 4);
899 fprintf (file, "op %d:", i);
900 print_node_brief (file, "", OMP_CLAUSE_OPERAND (node, i), 0);
903 break;
905 case OPTIMIZATION_NODE:
906 cl_optimization_print (file, indent + 4, TREE_OPTIMIZATION (node));
907 break;
909 case TARGET_OPTION_NODE:
910 cl_target_option_print (file, indent + 4, TREE_TARGET_OPTION (node));
911 break;
912 case IMPORTED_DECL:
913 fprintf (file, " imported declaration");
914 print_node_brief (file, "associated declaration",
915 IMPORTED_DECL_ASSOCIATED_DECL (node),
916 indent + 4);
917 break;
919 default:
920 if (EXCEPTIONAL_CLASS_P (node))
921 lang_hooks.print_xnode (file, node, indent);
922 break;
925 break;
928 if (EXPR_HAS_LOCATION (node))
930 expanded_location xloc = expand_location (EXPR_LOCATION (node));
931 indent_to (file, indent+4);
932 fprintf (file, "%s:%d:%d", xloc.file, xloc.line, xloc.column);
935 fprintf (file, ">");
939 /* Print the node NODE on standard error, for debugging.
940 Most nodes referred to by this one are printed recursively
941 down to a depth of six. */
943 DEBUG_FUNCTION void
944 debug_tree (tree node)
946 table = XCNEWVEC (struct bucket *, HASH_SIZE);
947 print_node (stderr, "", node, 0);
948 free (table);
949 table = 0;
950 putc ('\n', stderr);
953 DEBUG_FUNCTION void
954 debug_raw (const tree_node &ref)
956 debug_tree (const_cast <tree> (&ref));
959 DEBUG_FUNCTION void
960 debug_raw (const tree_node *ptr)
962 if (ptr)
963 debug_raw (*ptr);
964 else
965 fprintf (stderr, "<nil>\n");
968 static void
969 dump_tree_via_hooks (const tree_node *ptr, int options)
971 if (DECL_P (ptr))
972 lang_hooks.print_decl (stderr, const_cast <tree_node*> (ptr), 0);
973 else if (TYPE_P (ptr))
974 lang_hooks.print_type (stderr, const_cast <tree_node*> (ptr), 0);
975 else if (TREE_CODE (ptr) == IDENTIFIER_NODE)
976 lang_hooks.print_identifier (stderr, const_cast <tree_node*> (ptr), 0);
977 else
978 print_generic_expr (stderr, const_cast <tree_node*> (ptr), options);
979 fprintf (stderr, "\n");
982 DEBUG_FUNCTION void
983 debug (const tree_node &ref)
985 dump_tree_via_hooks (&ref, 0);
988 DEBUG_FUNCTION void
989 debug (const tree_node *ptr)
991 if (ptr)
992 debug (*ptr);
993 else
994 fprintf (stderr, "<nil>\n");
997 DEBUG_FUNCTION void
998 debug_verbose (const tree_node &ref)
1000 dump_tree_via_hooks (&ref, TDF_VERBOSE);
1003 DEBUG_FUNCTION void
1004 debug_verbose (const tree_node *ptr)
1006 if (ptr)
1007 debug_verbose (*ptr);
1008 else
1009 fprintf (stderr, "<nil>\n");
1012 DEBUG_FUNCTION void
1013 debug_head (const tree_node &ref)
1015 debug (ref);
1018 DEBUG_FUNCTION void
1019 debug_head (const tree_node *ptr)
1021 if (ptr)
1022 debug_head (*ptr);
1023 else
1024 fprintf (stderr, "<nil>\n");
1027 DEBUG_FUNCTION void
1028 debug_body (const tree_node &ref)
1030 if (TREE_CODE (&ref) == FUNCTION_DECL)
1031 dump_function_to_file (const_cast <tree_node*> (&ref), stderr, 0);
1032 else
1033 debug (ref);
1036 DEBUG_FUNCTION void
1037 debug_body (const tree_node *ptr)
1039 if (ptr)
1040 debug_body (*ptr);
1041 else
1042 fprintf (stderr, "<nil>\n");
1045 /* Print the vector of trees VEC on standard error, for debugging.
1046 Most nodes referred to by this one are printed recursively
1047 down to a depth of six. */
1049 DEBUG_FUNCTION void
1050 debug_raw (vec<tree, va_gc> &ref)
1052 tree elt;
1053 unsigned ix;
1055 /* Print the slot this node is in, and its code, and address. */
1056 fprintf (stderr, "<VEC");
1057 dump_addr (stderr, " ", ref.address ());
1059 FOR_EACH_VEC_ELT (ref, ix, elt)
1061 fprintf (stderr, "elt %d ", ix);
1062 debug_raw (elt);
1066 DEBUG_FUNCTION void
1067 debug (vec<tree, va_gc> &ref)
1069 tree elt;
1070 unsigned ix;
1072 /* Print the slot this node is in, and its code, and address. */
1073 fprintf (stderr, "<VEC");
1074 dump_addr (stderr, " ", ref.address ());
1076 FOR_EACH_VEC_ELT (ref, ix, elt)
1078 fprintf (stderr, "elt %d ", ix);
1079 debug (elt);
1083 DEBUG_FUNCTION void
1084 debug (vec<tree, va_gc> *ptr)
1086 if (ptr)
1087 debug (*ptr);
1088 else
1089 fprintf (stderr, "<nil>\n");
1092 DEBUG_FUNCTION void
1093 debug_raw (vec<tree, va_gc> *ptr)
1095 if (ptr)
1096 debug_raw (*ptr);
1097 else
1098 fprintf (stderr, "<nil>\n");
1101 DEBUG_FUNCTION void
1102 debug_vec_tree (vec<tree, va_gc> *vec)
1104 debug_raw (vec);