PR tree-optimization/66718
[official-gcc.git] / gcc / print-tree.c
blob6e0d4a9f02ce8de301ed22856ae97037e08093dd
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 "tree.h"
27 #include "varasm.h"
28 #include "print-rtl.h"
29 #include "stor-layout.h"
30 #include "langhooks.h"
31 #include "tree-iterator.h"
32 #include "diagnostic.h"
33 #include "gimple-pretty-print.h" /* FIXME */
34 #include "hard-reg-set.h"
35 #include "function.h"
36 #include "cgraph.h"
37 #include "tree-cfg.h"
38 #include "tree-dump.h"
39 #include "dumpfile.h"
40 #include "wide-int-print.h"
42 /* Define the hash table of nodes already seen.
43 Such nodes are not repeated; brief cross-references are used. */
45 #define HASH_SIZE 37
47 struct bucket
49 tree node;
50 struct bucket *next;
53 static struct bucket **table;
55 /* Print PREFIX and ADDR to FILE. */
56 void
57 dump_addr (FILE *file, const char *prefix, const void *addr)
59 if (flag_dump_noaddr || flag_dump_unnumbered)
60 fprintf (file, "%s#", prefix);
61 else
62 fprintf (file, "%s" HOST_PTR_PRINTF, prefix, addr);
65 /* Print a node in brief fashion, with just the code, address and name. */
67 void
68 print_node_brief (FILE *file, const char *prefix, const_tree node, int indent)
70 enum tree_code_class tclass;
72 if (node == 0)
73 return;
75 tclass = TREE_CODE_CLASS (TREE_CODE (node));
77 /* Always print the slot this node is in, and its code, address and
78 name if any. */
79 if (indent > 0)
80 fprintf (file, " ");
81 fprintf (file, "%s <%s", prefix, get_tree_code_name (TREE_CODE (node)));
82 dump_addr (file, " ", node);
84 if (tclass == tcc_declaration)
86 if (DECL_NAME (node))
87 fprintf (file, " %s", IDENTIFIER_POINTER (DECL_NAME (node)));
88 else if (TREE_CODE (node) == LABEL_DECL
89 && LABEL_DECL_UID (node) != -1)
91 if (dump_flags & TDF_NOUID)
92 fprintf (file, " L.xxxx");
93 else
94 fprintf (file, " L.%d", (int) LABEL_DECL_UID (node));
96 else
98 if (dump_flags & TDF_NOUID)
99 fprintf (file, " %c.xxxx",
100 TREE_CODE (node) == CONST_DECL ? 'C' : 'D');
101 else
102 fprintf (file, " %c.%u",
103 TREE_CODE (node) == CONST_DECL ? 'C' : 'D',
104 DECL_UID (node));
107 else if (tclass == tcc_type)
109 if (TYPE_NAME (node))
111 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
112 fprintf (file, " %s", IDENTIFIER_POINTER (TYPE_NAME (node)));
113 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
114 && DECL_NAME (TYPE_NAME (node)))
115 fprintf (file, " %s",
116 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node))));
118 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (node)))
119 fprintf (file, " address-space-%d", TYPE_ADDR_SPACE (node));
121 if (TREE_CODE (node) == IDENTIFIER_NODE)
122 fprintf (file, " %s", IDENTIFIER_POINTER (node));
124 /* We might as well always print the value of an integer or real. */
125 if (TREE_CODE (node) == INTEGER_CST)
127 if (TREE_OVERFLOW (node))
128 fprintf (file, " overflow");
130 fprintf (file, " ");
131 print_dec (node, file, TYPE_SIGN (TREE_TYPE (node)));
133 if (TREE_CODE (node) == REAL_CST)
135 REAL_VALUE_TYPE d;
137 if (TREE_OVERFLOW (node))
138 fprintf (file, " overflow");
140 d = TREE_REAL_CST (node);
141 if (REAL_VALUE_ISINF (d))
142 fprintf (file, REAL_VALUE_NEGATIVE (d) ? " -Inf" : " Inf");
143 else if (REAL_VALUE_ISNAN (d))
144 fprintf (file, " Nan");
145 else
147 char string[60];
148 real_to_decimal (string, &d, sizeof (string), 0, 1);
149 fprintf (file, " %s", string);
152 if (TREE_CODE (node) == FIXED_CST)
154 FIXED_VALUE_TYPE f;
155 char string[60];
157 if (TREE_OVERFLOW (node))
158 fprintf (file, " overflow");
160 f = TREE_FIXED_CST (node);
161 fixed_to_decimal (string, &f, sizeof (string));
162 fprintf (file, " %s", string);
165 fprintf (file, ">");
168 void
169 indent_to (FILE *file, int column)
171 int i;
173 /* Since this is the long way, indent to desired column. */
174 if (column > 0)
175 fprintf (file, "\n");
176 for (i = 0; i < column; i++)
177 fprintf (file, " ");
180 /* Print the node NODE in full on file FILE, preceded by PREFIX,
181 starting in column INDENT. */
183 void
184 print_node (FILE *file, const char *prefix, tree node, int indent)
186 int hash;
187 struct bucket *b;
188 machine_mode mode;
189 enum tree_code_class tclass;
190 int len;
191 int i;
192 expanded_location xloc;
193 enum tree_code code;
195 if (node == 0)
196 return;
198 code = TREE_CODE (node);
199 tclass = TREE_CODE_CLASS (code);
201 /* Don't get too deep in nesting. If the user wants to see deeper,
202 it is easy to use the address of a lowest-level node
203 as an argument in another call to debug_tree. */
205 if (indent > 24)
207 print_node_brief (file, prefix, node, indent);
208 return;
211 if (indent > 8 && (tclass == tcc_type || tclass == tcc_declaration))
213 print_node_brief (file, prefix, node, indent);
214 return;
217 /* It is unsafe to look at any other fields of an ERROR_MARK node. */
218 if (code == ERROR_MARK)
220 print_node_brief (file, prefix, node, indent);
221 return;
224 /* Allow this function to be called if the table is not there. */
225 if (table)
227 hash = ((uintptr_t) node) % HASH_SIZE;
229 /* If node is in the table, just mention its address. */
230 for (b = table[hash]; b; b = b->next)
231 if (b->node == node)
233 print_node_brief (file, prefix, node, indent);
234 return;
237 /* Add this node to the table. */
238 b = XNEW (struct bucket);
239 b->node = node;
240 b->next = table[hash];
241 table[hash] = b;
244 /* Indent to the specified column, since this is the long form. */
245 indent_to (file, indent);
247 /* Print the slot this node is in, and its code, and address. */
248 fprintf (file, "%s <%s", prefix, get_tree_code_name (code));
249 dump_addr (file, " ", node);
251 /* Print the name, if any. */
252 if (tclass == tcc_declaration)
254 if (DECL_NAME (node))
255 fprintf (file, " %s", IDENTIFIER_POINTER (DECL_NAME (node)));
256 else if (code == LABEL_DECL
257 && LABEL_DECL_UID (node) != -1)
259 if (dump_flags & TDF_NOUID)
260 fprintf (file, " L.xxxx");
261 else
262 fprintf (file, " L.%d", (int) LABEL_DECL_UID (node));
264 else
266 if (dump_flags & TDF_NOUID)
267 fprintf (file, " %c.xxxx", code == CONST_DECL ? 'C' : 'D');
268 else
269 fprintf (file, " %c.%u", code == CONST_DECL ? 'C' : 'D',
270 DECL_UID (node));
273 else if (tclass == tcc_type)
275 if (TYPE_NAME (node))
277 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
278 fprintf (file, " %s", IDENTIFIER_POINTER (TYPE_NAME (node)));
279 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
280 && DECL_NAME (TYPE_NAME (node)))
281 fprintf (file, " %s",
282 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node))));
285 if (code == IDENTIFIER_NODE)
286 fprintf (file, " %s", IDENTIFIER_POINTER (node));
288 if (code == INTEGER_CST)
290 if (indent <= 4)
291 print_node_brief (file, "type", TREE_TYPE (node), indent + 4);
293 else if (CODE_CONTAINS_STRUCT (code, TS_TYPED))
295 print_node (file, "type", TREE_TYPE (node), indent + 4);
296 if (TREE_TYPE (node))
297 indent_to (file, indent + 3);
300 if (!TYPE_P (node) && TREE_SIDE_EFFECTS (node))
301 fputs (" side-effects", file);
303 if (TYPE_P (node) ? TYPE_READONLY (node) : TREE_READONLY (node))
304 fputs (" readonly", file);
305 if (TYPE_P (node) && TYPE_ATOMIC (node))
306 fputs (" atomic", file);
307 if (!TYPE_P (node) && TREE_CONSTANT (node))
308 fputs (" constant", file);
309 else if (TYPE_P (node) && TYPE_SIZES_GIMPLIFIED (node))
310 fputs (" sizes-gimplified", file);
312 if (TYPE_P (node) && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (node)))
313 fprintf (file, " address-space-%d", TYPE_ADDR_SPACE (node));
315 if (TREE_ADDRESSABLE (node))
316 fputs (" addressable", file);
317 if (TREE_THIS_VOLATILE (node))
318 fputs (" volatile", file);
319 if (TREE_ASM_WRITTEN (node))
320 fputs (" asm_written", file);
321 if (TREE_USED (node))
322 fputs (" used", file);
323 if (TREE_NOTHROW (node))
324 fputs (TYPE_P (node) ? " align-ok" : " nothrow", file);
325 if (TREE_PUBLIC (node))
326 fputs (" public", file);
327 if (TREE_PRIVATE (node))
328 fputs (" private", file);
329 if (TREE_PROTECTED (node))
330 fputs (" protected", file);
331 if (TREE_STATIC (node))
332 fputs (" static", file);
333 if (TREE_DEPRECATED (node))
334 fputs (" deprecated", file);
335 if (TREE_VISITED (node))
336 fputs (" visited", file);
338 if (code != TREE_VEC && code != INTEGER_CST && code != SSA_NAME)
340 if (TREE_LANG_FLAG_0 (node))
341 fputs (" tree_0", file);
342 if (TREE_LANG_FLAG_1 (node))
343 fputs (" tree_1", file);
344 if (TREE_LANG_FLAG_2 (node))
345 fputs (" tree_2", file);
346 if (TREE_LANG_FLAG_3 (node))
347 fputs (" tree_3", file);
348 if (TREE_LANG_FLAG_4 (node))
349 fputs (" tree_4", file);
350 if (TREE_LANG_FLAG_5 (node))
351 fputs (" tree_5", file);
352 if (TREE_LANG_FLAG_6 (node))
353 fputs (" tree_6", file);
356 /* DECL_ nodes have additional attributes. */
358 switch (TREE_CODE_CLASS (code))
360 case tcc_declaration:
361 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
363 if (DECL_UNSIGNED (node))
364 fputs (" unsigned", file);
365 if (DECL_IGNORED_P (node))
366 fputs (" ignored", file);
367 if (DECL_ABSTRACT_P (node))
368 fputs (" abstract", file);
369 if (DECL_EXTERNAL (node))
370 fputs (" external", file);
371 if (DECL_NONLOCAL (node))
372 fputs (" nonlocal", file);
374 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
376 if (DECL_WEAK (node))
377 fputs (" weak", file);
378 if (DECL_IN_SYSTEM_HEADER (node))
379 fputs (" in_system_header", file);
381 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WRTL)
382 && code != LABEL_DECL
383 && code != FUNCTION_DECL
384 && DECL_REGISTER (node))
385 fputs (" regdecl", file);
387 if (code == TYPE_DECL && TYPE_DECL_SUPPRESS_DEBUG (node))
388 fputs (" suppress-debug", file);
390 if (code == FUNCTION_DECL
391 && DECL_FUNCTION_SPECIFIC_TARGET (node))
392 fputs (" function-specific-target", file);
393 if (code == FUNCTION_DECL
394 && DECL_FUNCTION_SPECIFIC_OPTIMIZATION (node))
395 fputs (" function-specific-opt", file);
396 if (code == FUNCTION_DECL && DECL_DECLARED_INLINE_P (node))
397 fputs (" autoinline", file);
398 if (code == FUNCTION_DECL && DECL_BUILT_IN (node))
399 fputs (" built-in", file);
400 if (code == FUNCTION_DECL && DECL_STATIC_CHAIN (node))
401 fputs (" static-chain", file);
402 if (TREE_CODE (node) == FUNCTION_DECL && decl_is_tm_clone (node))
403 fputs (" tm-clone", file);
405 if (code == FIELD_DECL && DECL_PACKED (node))
406 fputs (" packed", file);
407 if (code == FIELD_DECL && DECL_BIT_FIELD (node))
408 fputs (" bit-field", file);
409 if (code == FIELD_DECL && DECL_NONADDRESSABLE_P (node))
410 fputs (" nonaddressable", file);
412 if (code == LABEL_DECL && EH_LANDING_PAD_NR (node))
413 fprintf (file, " landing-pad:%d", EH_LANDING_PAD_NR (node));
415 if (code == VAR_DECL && DECL_IN_TEXT_SECTION (node))
416 fputs (" in-text-section", file);
417 if (code == VAR_DECL && DECL_IN_CONSTANT_POOL (node))
418 fputs (" in-constant-pool", file);
419 if (code == VAR_DECL && DECL_COMMON (node))
420 fputs (" common", file);
421 if (code == VAR_DECL && DECL_THREAD_LOCAL_P (node))
423 fputs (" ", file);
424 fputs (tls_model_names[DECL_TLS_MODEL (node)], file);
427 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
429 if (DECL_VIRTUAL_P (node))
430 fputs (" virtual", file);
431 if (DECL_PRESERVE_P (node))
432 fputs (" preserve", file);
433 if (DECL_LANG_FLAG_0 (node))
434 fputs (" decl_0", file);
435 if (DECL_LANG_FLAG_1 (node))
436 fputs (" decl_1", file);
437 if (DECL_LANG_FLAG_2 (node))
438 fputs (" decl_2", file);
439 if (DECL_LANG_FLAG_3 (node))
440 fputs (" decl_3", file);
441 if (DECL_LANG_FLAG_4 (node))
442 fputs (" decl_4", file);
443 if (DECL_LANG_FLAG_5 (node))
444 fputs (" decl_5", file);
445 if (DECL_LANG_FLAG_6 (node))
446 fputs (" decl_6", file);
447 if (DECL_LANG_FLAG_7 (node))
448 fputs (" decl_7", file);
450 mode = DECL_MODE (node);
451 fprintf (file, " %s", GET_MODE_NAME (mode));
454 if ((code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
455 && DECL_BY_REFERENCE (node))
456 fputs (" passed-by-reference", file);
458 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS) && DECL_DEFER_OUTPUT (node))
459 fputs (" defer-output", file);
462 xloc = expand_location (DECL_SOURCE_LOCATION (node));
463 fprintf (file, " file %s line %d col %d", xloc.file, xloc.line,
464 xloc.column);
466 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
468 print_node (file, "size", DECL_SIZE (node), indent + 4);
469 print_node (file, "unit size", DECL_SIZE_UNIT (node), indent + 4);
471 if (code != FUNCTION_DECL || DECL_BUILT_IN (node))
472 indent_to (file, indent + 3);
474 if (DECL_USER_ALIGN (node))
475 fprintf (file, " user");
477 fprintf (file, " align %d", DECL_ALIGN (node));
478 if (code == FIELD_DECL)
479 fprintf (file, " offset_align " HOST_WIDE_INT_PRINT_UNSIGNED,
480 DECL_OFFSET_ALIGN (node));
482 if (code == FUNCTION_DECL && DECL_BUILT_IN (node))
484 if (DECL_BUILT_IN_CLASS (node) == BUILT_IN_MD)
485 fprintf (file, " built-in BUILT_IN_MD %d", DECL_FUNCTION_CODE (node));
486 else
487 fprintf (file, " built-in %s:%s",
488 built_in_class_names[(int) DECL_BUILT_IN_CLASS (node)],
489 built_in_names[(int) DECL_FUNCTION_CODE (node)]);
492 if (code == FIELD_DECL)
494 print_node (file, "offset", DECL_FIELD_OFFSET (node), indent + 4);
495 print_node (file, "bit offset", DECL_FIELD_BIT_OFFSET (node),
496 indent + 4);
497 if (DECL_BIT_FIELD_TYPE (node))
498 print_node (file, "bit_field_type", DECL_BIT_FIELD_TYPE (node),
499 indent + 4);
502 print_node_brief (file, "context", DECL_CONTEXT (node), indent + 4);
504 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
506 print_node_brief (file, "attributes",
507 DECL_ATTRIBUTES (node), indent + 4);
508 if (code != PARM_DECL)
509 print_node_brief (file, "initial", DECL_INITIAL (node),
510 indent + 4);
512 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WRTL))
514 print_node_brief (file, "abstract_origin",
515 DECL_ABSTRACT_ORIGIN (node), indent + 4);
517 if (CODE_CONTAINS_STRUCT (code, TS_DECL_NON_COMMON))
519 print_node (file, "result", DECL_RESULT_FLD (node), indent + 4);
522 lang_hooks.print_decl (file, node, indent);
524 if (DECL_RTL_SET_P (node))
526 indent_to (file, indent + 4);
527 print_rtl (file, DECL_RTL (node));
530 if (code == PARM_DECL)
532 print_node (file, "arg-type", DECL_ARG_TYPE (node), indent + 4);
534 if (DECL_INCOMING_RTL (node) != 0)
536 indent_to (file, indent + 4);
537 fprintf (file, "incoming-rtl ");
538 print_rtl (file, DECL_INCOMING_RTL (node));
541 else if (code == FUNCTION_DECL
542 && DECL_STRUCT_FUNCTION (node) != 0)
544 print_node (file, "arguments", DECL_ARGUMENTS (node), indent + 4);
545 indent_to (file, indent + 4);
546 dump_addr (file, "struct-function ", DECL_STRUCT_FUNCTION (node));
549 if ((code == VAR_DECL || code == PARM_DECL)
550 && DECL_HAS_VALUE_EXPR_P (node))
551 print_node (file, "value-expr", DECL_VALUE_EXPR (node), indent + 4);
553 /* Print the decl chain only if decl is at second level. */
554 if (indent == 4)
555 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
556 else
557 print_node_brief (file, "chain", TREE_CHAIN (node), indent + 4);
558 break;
560 case tcc_type:
561 if (TYPE_UNSIGNED (node))
562 fputs (" unsigned", file);
564 if (TYPE_NO_FORCE_BLK (node))
565 fputs (" no-force-blk", file);
567 if (TYPE_STRING_FLAG (node))
568 fputs (" string-flag", file);
570 if (TYPE_NEEDS_CONSTRUCTING (node))
571 fputs (" needs-constructing", file);
573 /* The transparent-union flag is used for different things in
574 different nodes. */
575 if ((code == UNION_TYPE || code == RECORD_TYPE)
576 && TYPE_TRANSPARENT_AGGR (node))
577 fputs (" transparent-aggr", file);
578 else if (code == ARRAY_TYPE
579 && TYPE_NONALIASED_COMPONENT (node))
580 fputs (" nonaliased-component", file);
582 if (TYPE_PACKED (node))
583 fputs (" packed", file);
585 if (TYPE_RESTRICT (node))
586 fputs (" restrict", file);
588 if (TYPE_LANG_FLAG_0 (node))
589 fputs (" type_0", file);
590 if (TYPE_LANG_FLAG_1 (node))
591 fputs (" type_1", file);
592 if (TYPE_LANG_FLAG_2 (node))
593 fputs (" type_2", file);
594 if (TYPE_LANG_FLAG_3 (node))
595 fputs (" type_3", file);
596 if (TYPE_LANG_FLAG_4 (node))
597 fputs (" type_4", file);
598 if (TYPE_LANG_FLAG_5 (node))
599 fputs (" type_5", file);
600 if (TYPE_LANG_FLAG_6 (node))
601 fputs (" type_6", file);
603 mode = TYPE_MODE (node);
604 fprintf (file, " %s", GET_MODE_NAME (mode));
606 print_node (file, "size", TYPE_SIZE (node), indent + 4);
607 print_node (file, "unit size", TYPE_SIZE_UNIT (node), indent + 4);
608 indent_to (file, indent + 3);
610 if (TYPE_USER_ALIGN (node))
611 fprintf (file, " user");
613 fprintf (file, " align %d symtab %d alias set " HOST_WIDE_INT_PRINT_DEC,
614 TYPE_ALIGN (node), TYPE_SYMTAB_ADDRESS (node),
615 (HOST_WIDE_INT) TYPE_ALIAS_SET (node));
617 if (TYPE_STRUCTURAL_EQUALITY_P (node))
618 fprintf (file, " structural equality");
619 else
620 dump_addr (file, " canonical type ", TYPE_CANONICAL (node));
622 print_node (file, "attributes", TYPE_ATTRIBUTES (node), indent + 4);
624 if (INTEGRAL_TYPE_P (node) || code == REAL_TYPE
625 || code == FIXED_POINT_TYPE)
627 fprintf (file, " precision %d", TYPE_PRECISION (node));
628 print_node_brief (file, "min", TYPE_MIN_VALUE (node), indent + 4);
629 print_node_brief (file, "max", TYPE_MAX_VALUE (node), indent + 4);
632 if (code == ENUMERAL_TYPE)
633 print_node (file, "values", TYPE_VALUES (node), indent + 4);
634 else if (code == ARRAY_TYPE)
635 print_node (file, "domain", TYPE_DOMAIN (node), indent + 4);
636 else if (code == VECTOR_TYPE)
637 fprintf (file, " nunits %d", (int) TYPE_VECTOR_SUBPARTS (node));
638 else if (code == RECORD_TYPE
639 || code == UNION_TYPE
640 || code == QUAL_UNION_TYPE)
641 print_node (file, "fields", TYPE_FIELDS (node), indent + 4);
642 else if (code == FUNCTION_TYPE
643 || code == METHOD_TYPE)
645 if (TYPE_METHOD_BASETYPE (node))
646 print_node_brief (file, "method basetype",
647 TYPE_METHOD_BASETYPE (node), indent + 4);
648 print_node (file, "arg-types", TYPE_ARG_TYPES (node), indent + 4);
650 else if (code == OFFSET_TYPE)
651 print_node_brief (file, "basetype", TYPE_OFFSET_BASETYPE (node),
652 indent + 4);
654 if (TYPE_CONTEXT (node))
655 print_node_brief (file, "context", TYPE_CONTEXT (node), indent + 4);
657 lang_hooks.print_type (file, node, indent);
659 if (TYPE_POINTER_TO (node) || TREE_CHAIN (node))
660 indent_to (file, indent + 3);
662 print_node_brief (file, "pointer_to_this", TYPE_POINTER_TO (node),
663 indent + 4);
664 print_node_brief (file, "reference_to_this", TYPE_REFERENCE_TO (node),
665 indent + 4);
666 print_node_brief (file, "chain", TREE_CHAIN (node), indent + 4);
667 break;
669 case tcc_expression:
670 case tcc_comparison:
671 case tcc_unary:
672 case tcc_binary:
673 case tcc_reference:
674 case tcc_statement:
675 case tcc_vl_exp:
676 if (code == BIND_EXPR)
678 print_node (file, "vars", TREE_OPERAND (node, 0), indent + 4);
679 print_node (file, "body", TREE_OPERAND (node, 1), indent + 4);
680 print_node (file, "block", TREE_OPERAND (node, 2), indent + 4);
681 break;
683 if (code == CALL_EXPR)
685 call_expr_arg_iterator iter;
686 tree arg;
687 print_node (file, "fn", CALL_EXPR_FN (node), indent + 4);
688 print_node (file, "static_chain", CALL_EXPR_STATIC_CHAIN (node),
689 indent + 4);
690 i = 0;
691 FOR_EACH_CALL_EXPR_ARG (arg, iter, node)
693 char temp[10];
694 sprintf (temp, "arg %d", i);
695 print_node (file, temp, arg, indent + 4);
696 i++;
699 else
701 len = TREE_OPERAND_LENGTH (node);
703 for (i = 0; i < len; i++)
705 char temp[10];
707 sprintf (temp, "arg %d", i);
708 print_node (file, temp, TREE_OPERAND (node, i), indent + 4);
711 if (CODE_CONTAINS_STRUCT (code, TS_COMMON))
712 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
713 break;
715 case tcc_constant:
716 case tcc_exceptional:
717 switch (code)
719 case INTEGER_CST:
720 if (TREE_OVERFLOW (node))
721 fprintf (file, " overflow");
723 fprintf (file, " ");
724 print_dec (node, file, TYPE_SIGN (TREE_TYPE (node)));
725 break;
727 case REAL_CST:
729 REAL_VALUE_TYPE d;
731 if (TREE_OVERFLOW (node))
732 fprintf (file, " overflow");
734 d = TREE_REAL_CST (node);
735 if (REAL_VALUE_ISINF (d))
736 fprintf (file, REAL_VALUE_NEGATIVE (d) ? " -Inf" : " Inf");
737 else if (REAL_VALUE_ISNAN (d))
738 fprintf (file, " Nan");
739 else
741 char string[64];
742 real_to_decimal (string, &d, sizeof (string), 0, 1);
743 fprintf (file, " %s", string);
746 break;
748 case FIXED_CST:
750 FIXED_VALUE_TYPE f;
751 char string[64];
753 if (TREE_OVERFLOW (node))
754 fprintf (file, " overflow");
756 f = TREE_FIXED_CST (node);
757 fixed_to_decimal (string, &f, sizeof (string));
758 fprintf (file, " %s", string);
760 break;
762 case VECTOR_CST:
764 char buf[10];
765 unsigned i;
767 for (i = 0; i < VECTOR_CST_NELTS (node); ++i)
769 sprintf (buf, "elt%u: ", i);
770 print_node (file, buf, VECTOR_CST_ELT (node, i), indent + 4);
773 break;
775 case COMPLEX_CST:
776 print_node (file, "real", TREE_REALPART (node), indent + 4);
777 print_node (file, "imag", TREE_IMAGPART (node), indent + 4);
778 break;
780 case STRING_CST:
782 const char *p = TREE_STRING_POINTER (node);
783 int i = TREE_STRING_LENGTH (node);
784 fputs (" \"", file);
785 while (--i >= 0)
787 char ch = *p++;
788 if (ch >= ' ' && ch < 127)
789 putc (ch, file);
790 else
791 fprintf (file, "\\%03o", ch & 0xFF);
793 fputc ('\"', file);
795 break;
797 case IDENTIFIER_NODE:
798 lang_hooks.print_identifier (file, node, indent);
799 break;
801 case TREE_LIST:
802 print_node (file, "purpose", TREE_PURPOSE (node), indent + 4);
803 print_node (file, "value", TREE_VALUE (node), indent + 4);
804 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
805 break;
807 case TREE_VEC:
808 len = TREE_VEC_LENGTH (node);
809 fprintf (file, " length %d", len);
810 for (i = 0; i < len; i++)
811 if (TREE_VEC_ELT (node, i))
813 char temp[10];
814 sprintf (temp, "elt %d", i);
815 print_node (file, temp, TREE_VEC_ELT (node, i), indent + 4);
817 break;
819 case CONSTRUCTOR:
821 unsigned HOST_WIDE_INT cnt;
822 tree index, value;
823 len = vec_safe_length (CONSTRUCTOR_ELTS (node));
824 fprintf (file, " lngt %d", len);
825 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (node),
826 cnt, index, value)
828 print_node (file, "idx", index, indent + 4);
829 print_node (file, "val", value, indent + 4);
832 break;
834 case STATEMENT_LIST:
835 dump_addr (file, " head ", node->stmt_list.head);
836 dump_addr (file, " tail ", node->stmt_list.tail);
837 fprintf (file, " stmts");
839 tree_stmt_iterator i;
840 for (i = tsi_start (node); !tsi_end_p (i); tsi_next (&i))
842 /* Not printing the addresses of the (not-a-tree)
843 'struct tree_stmt_list_node's. */
844 dump_addr (file, " ", tsi_stmt (i));
846 fprintf (file, "\n");
847 for (i = tsi_start (node); !tsi_end_p (i); tsi_next (&i))
849 /* Not printing the addresses of the (not-a-tree)
850 'struct tree_stmt_list_node's. */
851 print_node (file, "stmt", tsi_stmt (i), indent + 4);
854 break;
856 case BLOCK:
857 print_node (file, "vars", BLOCK_VARS (node), indent + 4);
858 print_node (file, "supercontext", BLOCK_SUPERCONTEXT (node),
859 indent + 4);
860 print_node (file, "subblocks", BLOCK_SUBBLOCKS (node), indent + 4);
861 print_node (file, "chain", BLOCK_CHAIN (node), indent + 4);
862 print_node (file, "abstract_origin",
863 BLOCK_ABSTRACT_ORIGIN (node), indent + 4);
864 break;
866 case SSA_NAME:
867 print_node_brief (file, "var", SSA_NAME_VAR (node), indent + 4);
868 fprintf (file, "def_stmt ");
869 print_gimple_stmt (file, SSA_NAME_DEF_STMT (node), indent + 4, 0);
871 indent_to (file, indent + 4);
872 fprintf (file, "version %u", SSA_NAME_VERSION (node));
873 if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (node))
874 fprintf (file, " in-abnormal-phi");
875 if (SSA_NAME_IN_FREE_LIST (node))
876 fprintf (file, " in-free-list");
878 if (SSA_NAME_PTR_INFO (node))
880 indent_to (file, indent + 3);
881 if (SSA_NAME_PTR_INFO (node))
882 dump_addr (file, " ptr-info ", SSA_NAME_PTR_INFO (node));
884 break;
886 case OMP_CLAUSE:
888 int i;
889 fprintf (file, " %s",
890 omp_clause_code_name[OMP_CLAUSE_CODE (node)]);
891 for (i = 0; i < omp_clause_num_ops[OMP_CLAUSE_CODE (node)]; i++)
893 indent_to (file, indent + 4);
894 fprintf (file, "op %d:", i);
895 print_node_brief (file, "", OMP_CLAUSE_OPERAND (node, i), 0);
898 break;
900 case OPTIMIZATION_NODE:
901 cl_optimization_print (file, indent + 4, TREE_OPTIMIZATION (node));
902 break;
904 case TARGET_OPTION_NODE:
905 cl_target_option_print (file, indent + 4, TREE_TARGET_OPTION (node));
906 break;
907 case IMPORTED_DECL:
908 fprintf (file, " imported declaration");
909 print_node_brief (file, "associated declaration",
910 IMPORTED_DECL_ASSOCIATED_DECL (node),
911 indent + 4);
912 break;
914 default:
915 if (EXCEPTIONAL_CLASS_P (node))
916 lang_hooks.print_xnode (file, node, indent);
917 break;
920 break;
923 if (EXPR_HAS_LOCATION (node))
925 expanded_location xloc = expand_location (EXPR_LOCATION (node));
926 indent_to (file, indent+4);
927 fprintf (file, "%s:%d:%d", xloc.file, xloc.line, xloc.column);
930 fprintf (file, ">");
934 /* Print the node NODE on standard error, for debugging.
935 Most nodes referred to by this one are printed recursively
936 down to a depth of six. */
938 DEBUG_FUNCTION void
939 debug_tree (tree node)
941 table = XCNEWVEC (struct bucket *, HASH_SIZE);
942 print_node (stderr, "", node, 0);
943 free (table);
944 table = 0;
945 putc ('\n', stderr);
948 DEBUG_FUNCTION void
949 debug_raw (const tree_node &ref)
951 debug_tree (const_cast <tree> (&ref));
954 DEBUG_FUNCTION void
955 debug_raw (const tree_node *ptr)
957 if (ptr)
958 debug_raw (*ptr);
959 else
960 fprintf (stderr, "<nil>\n");
963 static void
964 dump_tree_via_hooks (const tree_node *ptr, int options)
966 if (DECL_P (ptr))
967 lang_hooks.print_decl (stderr, const_cast <tree_node*> (ptr), 0);
968 else if (TYPE_P (ptr))
969 lang_hooks.print_type (stderr, const_cast <tree_node*> (ptr), 0);
970 else if (TREE_CODE (ptr) == IDENTIFIER_NODE)
971 lang_hooks.print_identifier (stderr, const_cast <tree_node*> (ptr), 0);
972 else
973 print_generic_expr (stderr, const_cast <tree_node*> (ptr), options);
974 fprintf (stderr, "\n");
977 DEBUG_FUNCTION void
978 debug (const tree_node &ref)
980 dump_tree_via_hooks (&ref, 0);
983 DEBUG_FUNCTION void
984 debug (const tree_node *ptr)
986 if (ptr)
987 debug (*ptr);
988 else
989 fprintf (stderr, "<nil>\n");
992 DEBUG_FUNCTION void
993 debug_verbose (const tree_node &ref)
995 dump_tree_via_hooks (&ref, TDF_VERBOSE);
998 DEBUG_FUNCTION void
999 debug_verbose (const tree_node *ptr)
1001 if (ptr)
1002 debug_verbose (*ptr);
1003 else
1004 fprintf (stderr, "<nil>\n");
1007 DEBUG_FUNCTION void
1008 debug_head (const tree_node &ref)
1010 debug (ref);
1013 DEBUG_FUNCTION void
1014 debug_head (const tree_node *ptr)
1016 if (ptr)
1017 debug_head (*ptr);
1018 else
1019 fprintf (stderr, "<nil>\n");
1022 DEBUG_FUNCTION void
1023 debug_body (const tree_node &ref)
1025 if (TREE_CODE (&ref) == FUNCTION_DECL)
1026 dump_function_to_file (const_cast <tree_node*> (&ref), stderr, 0);
1027 else
1028 debug (ref);
1031 DEBUG_FUNCTION void
1032 debug_body (const tree_node *ptr)
1034 if (ptr)
1035 debug_body (*ptr);
1036 else
1037 fprintf (stderr, "<nil>\n");
1040 /* Print the vector of trees VEC on standard error, for debugging.
1041 Most nodes referred to by this one are printed recursively
1042 down to a depth of six. */
1044 DEBUG_FUNCTION void
1045 debug_raw (vec<tree, va_gc> &ref)
1047 tree elt;
1048 unsigned ix;
1050 /* Print the slot this node is in, and its code, and address. */
1051 fprintf (stderr, "<VEC");
1052 dump_addr (stderr, " ", ref.address ());
1054 FOR_EACH_VEC_ELT (ref, ix, elt)
1056 fprintf (stderr, "elt %d ", ix);
1057 debug_raw (elt);
1061 DEBUG_FUNCTION void
1062 debug (vec<tree, va_gc> &ref)
1064 tree elt;
1065 unsigned ix;
1067 /* Print the slot this node is in, and its code, and address. */
1068 fprintf (stderr, "<VEC");
1069 dump_addr (stderr, " ", ref.address ());
1071 FOR_EACH_VEC_ELT (ref, ix, elt)
1073 fprintf (stderr, "elt %d ", ix);
1074 debug (elt);
1078 DEBUG_FUNCTION void
1079 debug (vec<tree, va_gc> *ptr)
1081 if (ptr)
1082 debug (*ptr);
1083 else
1084 fprintf (stderr, "<nil>\n");
1087 DEBUG_FUNCTION void
1088 debug_raw (vec<tree, va_gc> *ptr)
1090 if (ptr)
1091 debug_raw (*ptr);
1092 else
1093 fprintf (stderr, "<nil>\n");
1096 DEBUG_FUNCTION void
1097 debug_vec_tree (vec<tree, va_gc> *vec)
1099 debug_raw (vec);