Merge trunk version 204659 into gupc branch.
[official-gcc.git] / gcc / print-tree.c
blob913dcbfd32b07e0bcf10e39e009131b0cca2b429
1 /* Prints out tree in human readable form - GCC
2 Copyright (C) 1990-2013 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 "ggc.h"
27 #include "langhooks.h"
28 #include "tree-iterator.h"
29 #include "diagnostic.h"
30 #include "gimple-pretty-print.h" /* FIXME */
31 #include "cgraph.h"
32 #include "tree-cfg.h"
33 #include "tree-dump.h"
34 #include "dumpfile.h"
36 /* Define the hash table of nodes already seen.
37 Such nodes are not repeated; brief cross-references are used. */
39 #define HASH_SIZE 37
41 struct bucket
43 tree node;
44 struct bucket *next;
47 static struct bucket **table;
49 /* Print PREFIX and ADDR to FILE. */
50 void
51 dump_addr (FILE *file, const char *prefix, const void *addr)
53 if (flag_dump_noaddr || flag_dump_unnumbered)
54 fprintf (file, "%s#", prefix);
55 else
56 fprintf (file, "%s" HOST_PTR_PRINTF, prefix, addr);
59 /* Print a node in brief fashion, with just the code, address and name. */
61 void
62 print_node_brief (FILE *file, const char *prefix, const_tree node, int indent)
64 enum tree_code_class tclass;
66 if (node == 0)
67 return;
69 tclass = TREE_CODE_CLASS (TREE_CODE (node));
71 /* Always print the slot this node is in, and its code, address and
72 name if any. */
73 if (indent > 0)
74 fprintf (file, " ");
75 fprintf (file, "%s <%s", prefix, get_tree_code_name (TREE_CODE (node)));
76 dump_addr (file, " ", node);
78 if (tclass == tcc_declaration)
80 if (DECL_NAME (node))
81 fprintf (file, " %s", IDENTIFIER_POINTER (DECL_NAME (node)));
82 else if (TREE_CODE (node) == LABEL_DECL
83 && LABEL_DECL_UID (node) != -1)
85 if (dump_flags & TDF_NOUID)
86 fprintf (file, " L.xxxx");
87 else
88 fprintf (file, " L.%d", (int) LABEL_DECL_UID (node));
90 else
92 if (dump_flags & TDF_NOUID)
93 fprintf (file, " %c.xxxx",
94 TREE_CODE (node) == CONST_DECL ? 'C' : 'D');
95 else
96 fprintf (file, " %c.%u",
97 TREE_CODE (node) == CONST_DECL ? 'C' : 'D',
98 DECL_UID (node));
101 else if (tclass == tcc_type)
103 if (TYPE_NAME (node))
105 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
106 fprintf (file, " %s", IDENTIFIER_POINTER (TYPE_NAME (node)));
107 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
108 && DECL_NAME (TYPE_NAME (node)))
109 fprintf (file, " %s",
110 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node))));
112 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (node)))
113 fprintf (file, " address-space-%d", TYPE_ADDR_SPACE (node));
115 if (TREE_CODE (node) == IDENTIFIER_NODE)
116 fprintf (file, " %s", IDENTIFIER_POINTER (node));
118 /* We might as well always print the value of an integer or real. */
119 if (TREE_CODE (node) == INTEGER_CST)
121 if (TREE_OVERFLOW (node))
122 fprintf (file, " overflow");
124 fprintf (file, " ");
125 if (TREE_INT_CST_HIGH (node) == 0)
126 fprintf (file, HOST_WIDE_INT_PRINT_UNSIGNED, TREE_INT_CST_LOW (node));
127 else if (TREE_INT_CST_HIGH (node) == -1
128 && TREE_INT_CST_LOW (node) != 0)
129 fprintf (file, "-" HOST_WIDE_INT_PRINT_UNSIGNED,
130 -TREE_INT_CST_LOW (node));
131 else
132 fprintf (file, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
133 (unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (node),
134 (unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (node));
136 if (TREE_CODE (node) == REAL_CST)
138 REAL_VALUE_TYPE d;
140 if (TREE_OVERFLOW (node))
141 fprintf (file, " overflow");
143 d = TREE_REAL_CST (node);
144 if (REAL_VALUE_ISINF (d))
145 fprintf (file, REAL_VALUE_NEGATIVE (d) ? " -Inf" : " Inf");
146 else if (REAL_VALUE_ISNAN (d))
147 fprintf (file, " Nan");
148 else
150 char string[60];
151 real_to_decimal (string, &d, sizeof (string), 0, 1);
152 fprintf (file, " %s", string);
155 if (TREE_CODE (node) == FIXED_CST)
157 FIXED_VALUE_TYPE f;
158 char string[60];
160 if (TREE_OVERFLOW (node))
161 fprintf (file, " overflow");
163 f = TREE_FIXED_CST (node);
164 fixed_to_decimal (string, &f, sizeof (string));
165 fprintf (file, " %s", string);
168 fprintf (file, ">");
171 void
172 indent_to (FILE *file, int column)
174 int i;
176 /* Since this is the long way, indent to desired column. */
177 if (column > 0)
178 fprintf (file, "\n");
179 for (i = 0; i < column; i++)
180 fprintf (file, " ");
183 /* Print the node NODE in full on file FILE, preceded by PREFIX,
184 starting in column INDENT. */
186 void
187 print_node (FILE *file, const char *prefix, tree node, int indent)
189 int hash;
190 struct bucket *b;
191 enum machine_mode mode;
192 enum tree_code_class tclass;
193 int len;
194 int i;
195 expanded_location xloc;
196 enum tree_code code;
198 if (node == 0)
199 return;
201 code = TREE_CODE (node);
202 tclass = TREE_CODE_CLASS (code);
204 /* Don't get too deep in nesting. If the user wants to see deeper,
205 it is easy to use the address of a lowest-level node
206 as an argument in another call to debug_tree. */
208 if (indent > 24)
210 print_node_brief (file, prefix, node, indent);
211 return;
214 if (indent > 8 && (tclass == tcc_type || tclass == tcc_declaration))
216 print_node_brief (file, prefix, node, indent);
217 return;
220 /* It is unsafe to look at any other fields of an ERROR_MARK node. */
221 if (code == ERROR_MARK)
223 print_node_brief (file, prefix, node, indent);
224 return;
227 /* Allow this function to be called if the table is not there. */
228 if (table)
230 hash = ((uintptr_t) node) % HASH_SIZE;
232 /* If node is in the table, just mention its address. */
233 for (b = table[hash]; b; b = b->next)
234 if (b->node == node)
236 print_node_brief (file, prefix, node, indent);
237 return;
240 /* Add this node to the table. */
241 b = XNEW (struct bucket);
242 b->node = node;
243 b->next = table[hash];
244 table[hash] = b;
247 /* Indent to the specified column, since this is the long form. */
248 indent_to (file, indent);
250 /* Print the slot this node is in, and its code, and address. */
251 fprintf (file, "%s <%s", prefix, get_tree_code_name (code));
252 dump_addr (file, " ", node);
254 /* Print the name, if any. */
255 if (tclass == tcc_declaration)
257 if (DECL_NAME (node))
258 fprintf (file, " %s", IDENTIFIER_POINTER (DECL_NAME (node)));
259 else if (code == LABEL_DECL
260 && LABEL_DECL_UID (node) != -1)
262 if (dump_flags & TDF_NOUID)
263 fprintf (file, " L.xxxx");
264 else
265 fprintf (file, " L.%d", (int) LABEL_DECL_UID (node));
267 else
269 if (dump_flags & TDF_NOUID)
270 fprintf (file, " %c.xxxx", code == CONST_DECL ? 'C' : 'D');
271 else
272 fprintf (file, " %c.%u", code == CONST_DECL ? 'C' : 'D',
273 DECL_UID (node));
276 else if (tclass == tcc_type)
278 if (TYPE_NAME (node))
280 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
281 fprintf (file, " %s", IDENTIFIER_POINTER (TYPE_NAME (node)));
282 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
283 && DECL_NAME (TYPE_NAME (node)))
284 fprintf (file, " %s",
285 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node))));
288 if (code == IDENTIFIER_NODE)
289 fprintf (file, " %s", IDENTIFIER_POINTER (node));
291 if (code == INTEGER_CST)
293 if (indent <= 4)
294 print_node_brief (file, "type", TREE_TYPE (node), indent + 4);
296 else if (CODE_CONTAINS_STRUCT (code, TS_TYPED))
298 print_node (file, "type", TREE_TYPE (node), indent + 4);
299 if (TREE_TYPE (node))
300 indent_to (file, indent + 3);
303 if (!TYPE_P (node) && TREE_SIDE_EFFECTS (node))
304 fputs (" side-effects", file);
306 if (TYPE_P (node) ? TYPE_READONLY (node) : TREE_READONLY (node))
307 fputs (" readonly", file);
308 if (TYPE_P (node) && TYPE_ATOMIC (node))
309 fputs (" atomic", file);
310 if (TREE_SHARED (node))
311 fputs (" shared", file);
312 if (!TYPE_P (node) && TREE_CONSTANT (node))
313 fputs (" constant", file);
314 else if (TYPE_P (node) && TYPE_SIZES_GIMPLIFIED (node))
315 fputs (" sizes-gimplified", file);
317 if (TYPE_P (node) && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (node)))
318 fprintf (file, " address-space-%d", TYPE_ADDR_SPACE (node));
320 if (TREE_ADDRESSABLE (node))
321 fputs (" addressable", file);
322 if (TREE_THIS_VOLATILE (node))
323 fputs (" volatile", file);
324 if (TREE_ASM_WRITTEN (node))
325 fputs (" asm_written", file);
326 if (TREE_USED (node))
327 fputs (" used", file);
328 if (TREE_NOTHROW (node))
329 fputs (TYPE_P (node) ? " align-ok" : " nothrow", file);
330 if (TREE_PUBLIC (node))
331 fputs (" public", file);
332 if (TREE_PRIVATE (node))
333 fputs (" private", file);
334 if (TREE_PROTECTED (node))
335 fputs (" protected", file);
336 if (TREE_STATIC (node))
337 fputs (" static", file);
338 if (TREE_CODE (node) == FUNCTION_DECL && DECL_STATIC_CONSTRUCTOR (node))
339 fputs (" constructor", file);
340 if (TREE_CODE (node) == FUNCTION_DECL && DECL_STATIC_DESTRUCTOR (node))
341 fputs (" destructor", file);
342 if (TREE_DEPRECATED (node))
343 fputs (" deprecated", file);
344 if (TREE_VISITED (node))
345 fputs (" visited", file);
347 if (code != TREE_VEC && code != SSA_NAME)
349 if (TREE_LANG_FLAG_0 (node))
350 fputs (" tree_0", file);
351 if (TREE_LANG_FLAG_1 (node))
352 fputs (" tree_1", file);
353 if (TREE_LANG_FLAG_2 (node))
354 fputs (" tree_2", file);
355 if (TREE_LANG_FLAG_3 (node))
356 fputs (" tree_3", file);
357 if (TREE_LANG_FLAG_4 (node))
358 fputs (" tree_4", file);
359 if (TREE_LANG_FLAG_5 (node))
360 fputs (" tree_5", file);
361 if (TREE_LANG_FLAG_6 (node))
362 fputs (" tree_6", file);
365 /* DECL_ nodes have additional attributes. */
367 switch (TREE_CODE_CLASS (code))
369 case tcc_declaration:
370 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
372 if (DECL_UNSIGNED (node))
373 fputs (" unsigned", file);
374 if (DECL_IGNORED_P (node))
375 fputs (" ignored", file);
376 if (DECL_ABSTRACT (node))
377 fputs (" abstract", file);
378 if (DECL_EXTERNAL (node))
379 fputs (" external", file);
380 if (DECL_NONLOCAL (node))
381 fputs (" nonlocal", file);
383 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
385 if (DECL_WEAK (node))
386 fputs (" weak", file);
387 if (DECL_IN_SYSTEM_HEADER (node))
388 fputs (" in_system_header", file);
390 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WRTL)
391 && code != LABEL_DECL
392 && code != FUNCTION_DECL
393 && DECL_REGISTER (node))
394 fputs (" regdecl", file);
396 if (code == TYPE_DECL && TYPE_DECL_SUPPRESS_DEBUG (node))
397 fputs (" suppress-debug", file);
399 if (code == FUNCTION_DECL
400 && DECL_FUNCTION_SPECIFIC_TARGET (node))
401 fputs (" function-specific-target", file);
402 if (code == FUNCTION_DECL
403 && DECL_FUNCTION_SPECIFIC_OPTIMIZATION (node))
404 fputs (" function-specific-opt", file);
405 if (code == FUNCTION_DECL && DECL_DECLARED_INLINE_P (node))
406 fputs (" autoinline", file);
407 if (code == FUNCTION_DECL && DECL_BUILT_IN (node))
408 fputs (" built-in", file);
409 if (code == FUNCTION_DECL && DECL_STATIC_CHAIN (node))
410 fputs (" static-chain", file);
411 if (TREE_CODE (node) == FUNCTION_DECL && decl_is_tm_clone (node))
412 fputs (" tm-clone", file);
414 if (code == FIELD_DECL && DECL_PACKED (node))
415 fputs (" packed", file);
416 if (code == FIELD_DECL && DECL_BIT_FIELD (node))
417 fputs (" bit-field", file);
418 if (code == FIELD_DECL && DECL_NONADDRESSABLE_P (node))
419 fputs (" nonaddressable", file);
421 if (code == LABEL_DECL && EH_LANDING_PAD_NR (node))
422 fprintf (file, " landing-pad:%d", EH_LANDING_PAD_NR (node));
424 if (code == VAR_DECL && DECL_IN_TEXT_SECTION (node))
425 fputs (" in-text-section", file);
426 if (code == VAR_DECL && DECL_IN_CONSTANT_POOL (node))
427 fputs (" in-constant-pool", file);
428 if (code == VAR_DECL && DECL_COMMON (node))
429 fputs (" common", file);
430 if (code == VAR_DECL && DECL_THREAD_LOCAL_P (node))
432 enum tls_model kind = DECL_TLS_MODEL (node);
433 switch (kind)
435 case TLS_MODEL_GLOBAL_DYNAMIC:
436 fputs (" tls-global-dynamic", file);
437 break;
438 case TLS_MODEL_LOCAL_DYNAMIC:
439 fputs (" tls-local-dynamic", file);
440 break;
441 case TLS_MODEL_INITIAL_EXEC:
442 fputs (" tls-initial-exec", file);
443 break;
444 case TLS_MODEL_LOCAL_EXEC:
445 fputs (" tls-local-exec", file);
446 break;
447 default:
448 gcc_unreachable ();
452 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
454 if (DECL_VIRTUAL_P (node))
455 fputs (" virtual", file);
456 if (DECL_PRESERVE_P (node))
457 fputs (" preserve", file);
458 if (DECL_LANG_FLAG_0 (node))
459 fputs (" decl_0", file);
460 if (DECL_LANG_FLAG_1 (node))
461 fputs (" decl_1", file);
462 if (DECL_LANG_FLAG_2 (node))
463 fputs (" decl_2", file);
464 if (DECL_LANG_FLAG_3 (node))
465 fputs (" decl_3", file);
466 if (DECL_LANG_FLAG_4 (node))
467 fputs (" decl_4", file);
468 if (DECL_LANG_FLAG_5 (node))
469 fputs (" decl_5", file);
470 if (DECL_LANG_FLAG_6 (node))
471 fputs (" decl_6", file);
472 if (DECL_LANG_FLAG_7 (node))
473 fputs (" decl_7", file);
475 mode = DECL_MODE (node);
476 fprintf (file, " %s", GET_MODE_NAME (mode));
479 if ((code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
480 && DECL_BY_REFERENCE (node))
481 fputs (" passed-by-reference", file);
483 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS) && DECL_DEFER_OUTPUT (node))
484 fputs (" defer-output", file);
487 xloc = expand_location (DECL_SOURCE_LOCATION (node));
488 fprintf (file, " file %s line %d col %d", xloc.file, xloc.line,
489 xloc.column);
491 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
493 print_node (file, "size", DECL_SIZE (node), indent + 4);
494 print_node (file, "unit size", DECL_SIZE_UNIT (node), indent + 4);
496 if (code != FUNCTION_DECL || DECL_BUILT_IN (node))
497 indent_to (file, indent + 3);
499 if (DECL_USER_ALIGN (node))
500 fprintf (file, " user");
502 fprintf (file, " align %d", DECL_ALIGN (node));
503 if (code == FIELD_DECL)
504 fprintf (file, " offset_align " HOST_WIDE_INT_PRINT_UNSIGNED,
505 DECL_OFFSET_ALIGN (node));
507 if (code == FUNCTION_DECL && DECL_BUILT_IN (node))
509 if (DECL_BUILT_IN_CLASS (node) == BUILT_IN_MD)
510 fprintf (file, " built-in BUILT_IN_MD %d", DECL_FUNCTION_CODE (node));
511 else
512 fprintf (file, " built-in %s:%s",
513 built_in_class_names[(int) DECL_BUILT_IN_CLASS (node)],
514 built_in_names[(int) DECL_FUNCTION_CODE (node)]);
517 if (code == FIELD_DECL)
519 print_node (file, "offset", DECL_FIELD_OFFSET (node), indent + 4);
520 print_node (file, "bit offset", DECL_FIELD_BIT_OFFSET (node),
521 indent + 4);
522 if (DECL_BIT_FIELD_TYPE (node))
523 print_node (file, "bit_field_type", DECL_BIT_FIELD_TYPE (node),
524 indent + 4);
527 print_node_brief (file, "context", DECL_CONTEXT (node), indent + 4);
529 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
531 print_node_brief (file, "attributes",
532 DECL_ATTRIBUTES (node), indent + 4);
533 if (code != PARM_DECL)
534 print_node_brief (file, "initial", DECL_INITIAL (node),
535 indent + 4);
537 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WRTL))
539 print_node_brief (file, "abstract_origin",
540 DECL_ABSTRACT_ORIGIN (node), indent + 4);
542 if (CODE_CONTAINS_STRUCT (code, TS_DECL_NON_COMMON))
544 print_node (file, "arguments", DECL_ARGUMENT_FLD (node), indent + 4);
545 print_node (file, "result", DECL_RESULT_FLD (node), indent + 4);
548 lang_hooks.print_decl (file, node, indent);
550 if (DECL_RTL_SET_P (node))
552 indent_to (file, indent + 4);
553 print_rtl (file, DECL_RTL (node));
556 if (code == PARM_DECL)
558 print_node (file, "arg-type", DECL_ARG_TYPE (node), indent + 4);
560 if (DECL_INCOMING_RTL (node) != 0)
562 indent_to (file, indent + 4);
563 fprintf (file, "incoming-rtl ");
564 print_rtl (file, DECL_INCOMING_RTL (node));
567 else if (code == FUNCTION_DECL
568 && DECL_STRUCT_FUNCTION (node) != 0)
570 indent_to (file, indent + 4);
571 dump_addr (file, "struct-function ", DECL_STRUCT_FUNCTION (node));
574 if ((code == VAR_DECL || code == PARM_DECL)
575 && DECL_HAS_VALUE_EXPR_P (node))
576 print_node (file, "value-expr", DECL_VALUE_EXPR (node), indent + 4);
578 /* Print the decl chain only if decl is at second level. */
579 if (indent == 4)
580 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
581 else
582 print_node_brief (file, "chain", TREE_CHAIN (node), indent + 4);
583 break;
585 case tcc_type:
586 if (TYPE_UNSIGNED (node))
587 fputs (" unsigned", file);
589 /* The no-force-blk flag is used for different things in
590 different types. */
591 if ((code == RECORD_TYPE
592 || code == UNION_TYPE
593 || code == QUAL_UNION_TYPE)
594 && TYPE_NO_FORCE_BLK (node))
595 fputs (" no-force-blk", file);
597 if (TYPE_STRING_FLAG (node))
598 fputs (" string-flag", file);
599 if (TYPE_NEEDS_CONSTRUCTING (node))
600 fputs (" needs-constructing", file);
602 /* The transparent-union flag is used for different things in
603 different nodes. */
604 if ((code == UNION_TYPE || code == RECORD_TYPE)
605 && TYPE_TRANSPARENT_AGGR (node))
606 fputs (" transparent-aggr", file);
607 else if (code == ARRAY_TYPE
608 && TYPE_NONALIASED_COMPONENT (node))
609 fputs (" nonaliased-component", file);
611 if (TYPE_PACKED (node))
612 fputs (" packed", file);
614 if (TYPE_RESTRICT (node))
615 fputs (" restrict", file);
617 if (TYPE_LANG_FLAG_0 (node))
618 fputs (" type_0", file);
619 if (TYPE_LANG_FLAG_1 (node))
620 fputs (" type_1", file);
621 if (TYPE_LANG_FLAG_2 (node))
622 fputs (" type_2", file);
623 if (!TYPE_SHARED (node))
625 if (TYPE_LANG_FLAG_3 (node))
626 fputs (" type_3", file);
627 if (TYPE_LANG_FLAG_4 (node))
628 fputs (" type_4", file);
629 if (TYPE_LANG_FLAG_5 (node))
630 fputs (" type_5", file);
632 if (TYPE_LANG_FLAG_6 (node))
633 fputs (" type_6", file);
635 mode = TYPE_MODE (node);
636 fprintf (file, " %s", GET_MODE_NAME (mode));
638 print_node (file, "size", TYPE_SIZE (node), indent + 4);
639 print_node (file, "unit size", TYPE_SIZE_UNIT (node), indent + 4);
640 if (TYPE_SHARED (node))
642 if (TYPE_HAS_THREADS_FACTOR(node))
643 fputs (" THREADS factor", file);
644 if (TYPE_HAS_BLOCK_FACTOR (node))
645 print_node (file, "block factor",
646 TYPE_BLOCK_FACTOR (node), indent + 4);
648 indent_to (file, indent + 3);
650 if (TYPE_USER_ALIGN (node))
651 fprintf (file, " user");
653 fprintf (file, " align %d symtab %d alias set " HOST_WIDE_INT_PRINT_DEC,
654 TYPE_ALIGN (node), TYPE_SYMTAB_ADDRESS (node),
655 (HOST_WIDE_INT) TYPE_ALIAS_SET (node));
657 if (TYPE_STRUCTURAL_EQUALITY_P (node))
658 fprintf (file, " structural equality");
659 else
660 dump_addr (file, " canonical type ", TYPE_CANONICAL (node));
662 print_node (file, "attributes", TYPE_ATTRIBUTES (node), indent + 4);
664 if (INTEGRAL_TYPE_P (node) || code == REAL_TYPE
665 || code == FIXED_POINT_TYPE)
667 fprintf (file, " precision %d", TYPE_PRECISION (node));
668 print_node_brief (file, "min", TYPE_MIN_VALUE (node), indent + 4);
669 print_node_brief (file, "max", TYPE_MAX_VALUE (node), indent + 4);
672 if (code == ENUMERAL_TYPE)
673 print_node (file, "values", TYPE_VALUES (node), indent + 4);
674 else if (code == ARRAY_TYPE)
675 print_node (file, "domain", TYPE_DOMAIN (node), indent + 4);
676 else if (code == VECTOR_TYPE)
677 fprintf (file, " nunits %d", (int) TYPE_VECTOR_SUBPARTS (node));
678 else if (code == RECORD_TYPE
679 || code == UNION_TYPE
680 || code == QUAL_UNION_TYPE)
681 print_node (file, "fields", TYPE_FIELDS (node), indent + 4);
682 else if (code == FUNCTION_TYPE
683 || code == METHOD_TYPE)
685 if (TYPE_METHOD_BASETYPE (node))
686 print_node_brief (file, "method basetype",
687 TYPE_METHOD_BASETYPE (node), indent + 4);
688 print_node (file, "arg-types", TYPE_ARG_TYPES (node), indent + 4);
690 else if (code == OFFSET_TYPE)
691 print_node_brief (file, "basetype", TYPE_OFFSET_BASETYPE (node),
692 indent + 4);
694 if (TYPE_CONTEXT (node))
695 print_node_brief (file, "context", TYPE_CONTEXT (node), indent + 4);
697 lang_hooks.print_type (file, node, indent);
699 if (TYPE_POINTER_TO (node) || TREE_CHAIN (node))
700 indent_to (file, indent + 3);
702 print_node_brief (file, "pointer_to_this", TYPE_POINTER_TO (node),
703 indent + 4);
704 print_node_brief (file, "reference_to_this", TYPE_REFERENCE_TO (node),
705 indent + 4);
706 print_node_brief (file, "chain", TREE_CHAIN (node), indent + 4);
707 break;
709 case tcc_expression:
710 case tcc_comparison:
711 case tcc_unary:
712 case tcc_binary:
713 case tcc_reference:
714 case tcc_statement:
715 case tcc_vl_exp:
716 if (code == BIND_EXPR)
718 print_node (file, "vars", TREE_OPERAND (node, 0), indent + 4);
719 print_node (file, "body", TREE_OPERAND (node, 1), indent + 4);
720 print_node (file, "block", TREE_OPERAND (node, 2), indent + 4);
721 break;
723 if (code == CALL_EXPR)
725 call_expr_arg_iterator iter;
726 tree arg;
727 print_node (file, "fn", CALL_EXPR_FN (node), indent + 4);
728 print_node (file, "static_chain", CALL_EXPR_STATIC_CHAIN (node),
729 indent + 4);
730 i = 0;
731 FOR_EACH_CALL_EXPR_ARG (arg, iter, node)
733 char temp[10];
734 sprintf (temp, "arg %d", i);
735 print_node (file, temp, arg, indent + 4);
736 i++;
739 else
741 len = TREE_OPERAND_LENGTH (node);
743 for (i = 0; i < len; i++)
745 char temp[10];
747 sprintf (temp, "arg %d", i);
748 print_node (file, temp, TREE_OPERAND (node, i), indent + 4);
751 if (CODE_CONTAINS_STRUCT (code, TS_COMMON))
752 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
753 break;
755 case tcc_constant:
756 case tcc_exceptional:
757 switch (code)
759 case INTEGER_CST:
760 if (TREE_OVERFLOW (node))
761 fprintf (file, " overflow");
763 fprintf (file, " ");
764 if (TREE_INT_CST_HIGH (node) == 0)
765 fprintf (file, HOST_WIDE_INT_PRINT_UNSIGNED,
766 TREE_INT_CST_LOW (node));
767 else if (TREE_INT_CST_HIGH (node) == -1
768 && TREE_INT_CST_LOW (node) != 0)
769 fprintf (file, "-" HOST_WIDE_INT_PRINT_UNSIGNED,
770 -TREE_INT_CST_LOW (node));
771 else
772 fprintf (file, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
773 (unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (node),
774 (unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (node));
775 break;
777 case REAL_CST:
779 REAL_VALUE_TYPE d;
781 if (TREE_OVERFLOW (node))
782 fprintf (file, " overflow");
784 d = TREE_REAL_CST (node);
785 if (REAL_VALUE_ISINF (d))
786 fprintf (file, REAL_VALUE_NEGATIVE (d) ? " -Inf" : " Inf");
787 else if (REAL_VALUE_ISNAN (d))
788 fprintf (file, " Nan");
789 else
791 char string[64];
792 real_to_decimal (string, &d, sizeof (string), 0, 1);
793 fprintf (file, " %s", string);
796 break;
798 case FIXED_CST:
800 FIXED_VALUE_TYPE f;
801 char string[64];
803 if (TREE_OVERFLOW (node))
804 fprintf (file, " overflow");
806 f = TREE_FIXED_CST (node);
807 fixed_to_decimal (string, &f, sizeof (string));
808 fprintf (file, " %s", string);
810 break;
812 case VECTOR_CST:
814 char buf[10];
815 unsigned i;
817 for (i = 0; i < VECTOR_CST_NELTS (node); ++i)
819 sprintf (buf, "elt%u: ", i);
820 print_node (file, buf, VECTOR_CST_ELT (node, i), indent + 4);
823 break;
825 case COMPLEX_CST:
826 print_node (file, "real", TREE_REALPART (node), indent + 4);
827 print_node (file, "imag", TREE_IMAGPART (node), indent + 4);
828 break;
830 case STRING_CST:
832 const char *p = TREE_STRING_POINTER (node);
833 int i = TREE_STRING_LENGTH (node);
834 fputs (" \"", file);
835 while (--i >= 0)
837 char ch = *p++;
838 if (ch >= ' ' && ch < 127)
839 putc (ch, file);
840 else
841 fprintf (file, "\\%03o", ch & 0xFF);
843 fputc ('\"', file);
845 break;
847 case IDENTIFIER_NODE:
848 lang_hooks.print_identifier (file, node, indent);
849 break;
851 case TREE_LIST:
852 print_node (file, "purpose", TREE_PURPOSE (node), indent + 4);
853 print_node (file, "value", TREE_VALUE (node), indent + 4);
854 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
855 break;
857 case TREE_VEC:
858 len = TREE_VEC_LENGTH (node);
859 for (i = 0; i < len; i++)
860 if (TREE_VEC_ELT (node, i))
862 char temp[10];
863 sprintf (temp, "elt %d", i);
864 print_node (file, temp, TREE_VEC_ELT (node, i), indent + 4);
866 break;
868 case CONSTRUCTOR:
870 unsigned HOST_WIDE_INT cnt;
871 tree index, value;
872 len = vec_safe_length (CONSTRUCTOR_ELTS (node));
873 fprintf (file, " lngt %d", len);
874 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (node),
875 cnt, index, value)
877 print_node (file, "idx", index, indent + 4);
878 print_node (file, "val", value, indent + 4);
881 break;
883 case STATEMENT_LIST:
884 dump_addr (file, " head ", node->stmt_list.head);
885 dump_addr (file, " tail ", node->stmt_list.tail);
886 fprintf (file, " stmts");
888 tree_stmt_iterator i;
889 for (i = tsi_start (node); !tsi_end_p (i); tsi_next (&i))
891 /* Not printing the addresses of the (not-a-tree)
892 'struct tree_stmt_list_node's. */
893 dump_addr (file, " ", tsi_stmt (i));
895 fprintf (file, "\n");
896 for (i = tsi_start (node); !tsi_end_p (i); tsi_next (&i))
898 /* Not printing the addresses of the (not-a-tree)
899 'struct tree_stmt_list_node's. */
900 print_node (file, "stmt", tsi_stmt (i), indent + 4);
903 break;
905 case BLOCK:
906 print_node (file, "vars", BLOCK_VARS (node), indent + 4);
907 print_node (file, "supercontext", BLOCK_SUPERCONTEXT (node),
908 indent + 4);
909 print_node (file, "subblocks", BLOCK_SUBBLOCKS (node), indent + 4);
910 print_node (file, "chain", BLOCK_CHAIN (node), indent + 4);
911 print_node (file, "abstract_origin",
912 BLOCK_ABSTRACT_ORIGIN (node), indent + 4);
913 break;
915 case SSA_NAME:
916 print_node_brief (file, "var", SSA_NAME_VAR (node), indent + 4);
917 fprintf (file, "def_stmt ");
918 print_gimple_stmt (file, SSA_NAME_DEF_STMT (node), indent + 4, 0);
920 indent_to (file, indent + 4);
921 fprintf (file, "version %u", SSA_NAME_VERSION (node));
922 if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (node))
923 fprintf (file, " in-abnormal-phi");
924 if (SSA_NAME_IN_FREE_LIST (node))
925 fprintf (file, " in-free-list");
927 if (SSA_NAME_PTR_INFO (node))
929 indent_to (file, indent + 3);
930 if (SSA_NAME_PTR_INFO (node))
931 dump_addr (file, " ptr-info ", SSA_NAME_PTR_INFO (node));
933 break;
935 case OMP_CLAUSE:
937 int i;
938 fprintf (file, " %s",
939 omp_clause_code_name[OMP_CLAUSE_CODE (node)]);
940 for (i = 0; i < omp_clause_num_ops[OMP_CLAUSE_CODE (node)]; i++)
942 indent_to (file, indent + 4);
943 fprintf (file, "op %d:", i);
944 print_node_brief (file, "", OMP_CLAUSE_OPERAND (node, i), 0);
947 break;
949 case OPTIMIZATION_NODE:
950 cl_optimization_print (file, indent + 4, TREE_OPTIMIZATION (node));
951 break;
953 case TARGET_OPTION_NODE:
954 cl_target_option_print (file, indent + 4, TREE_TARGET_OPTION (node));
955 break;
956 case IMPORTED_DECL:
957 fprintf (file, " imported declaration");
958 print_node_brief (file, "associated declaration",
959 IMPORTED_DECL_ASSOCIATED_DECL (node),
960 indent + 4);
961 break;
963 default:
964 if (EXCEPTIONAL_CLASS_P (node))
965 lang_hooks.print_xnode (file, node, indent);
966 break;
969 break;
972 if (EXPR_HAS_LOCATION (node))
974 expanded_location xloc = expand_location (EXPR_LOCATION (node));
975 indent_to (file, indent+4);
976 fprintf (file, "%s:%d:%d", xloc.file, xloc.line, xloc.column);
979 fprintf (file, ">");
983 /* Print the node NODE on standard error, for debugging.
984 Most nodes referred to by this one are printed recursively
985 down to a depth of six. */
987 DEBUG_FUNCTION void
988 debug_tree (tree node)
990 table = XCNEWVEC (struct bucket *, HASH_SIZE);
991 print_node (stderr, "", node, 0);
992 free (table);
993 table = 0;
994 putc ('\n', stderr);
997 DEBUG_FUNCTION void
998 debug_raw (const tree_node &ref)
1000 debug_tree (const_cast <tree> (&ref));
1003 DEBUG_FUNCTION void
1004 debug_raw (const tree_node *ptr)
1006 if (ptr)
1007 debug_raw (*ptr);
1008 else
1009 fprintf (stderr, "<nil>\n");
1012 static void
1013 dump_tree_via_hooks (const tree_node *ptr, int options)
1015 if (DECL_P (ptr))
1016 lang_hooks.print_decl (stderr, const_cast <tree_node*> (ptr), 0);
1017 else if (TYPE_P (ptr))
1018 lang_hooks.print_type (stderr, const_cast <tree_node*> (ptr), 0);
1019 else if (TREE_CODE (ptr) == IDENTIFIER_NODE)
1020 lang_hooks.print_identifier (stderr, const_cast <tree_node*> (ptr), 0);
1021 else
1022 print_generic_expr (stderr, const_cast <tree_node*> (ptr), options);
1023 fprintf (stderr, "\n");
1026 DEBUG_FUNCTION void
1027 debug (const tree_node &ref)
1029 dump_tree_via_hooks (&ref, 0);
1032 DEBUG_FUNCTION void
1033 debug (const tree_node *ptr)
1035 if (ptr)
1036 debug (*ptr);
1037 else
1038 fprintf (stderr, "<nil>\n");
1041 DEBUG_FUNCTION void
1042 debug_verbose (const tree_node &ref)
1044 dump_tree_via_hooks (&ref, TDF_VERBOSE);
1047 DEBUG_FUNCTION void
1048 debug_verbose (const tree_node *ptr)
1050 if (ptr)
1051 debug_verbose (*ptr);
1052 else
1053 fprintf (stderr, "<nil>\n");
1056 DEBUG_FUNCTION void
1057 debug_head (const tree_node &ref)
1059 debug (ref);
1062 DEBUG_FUNCTION void
1063 debug_head (const tree_node *ptr)
1065 if (ptr)
1066 debug_head (*ptr);
1067 else
1068 fprintf (stderr, "<nil>\n");
1071 DEBUG_FUNCTION void
1072 debug_body (const tree_node &ref)
1074 if (TREE_CODE (&ref) == FUNCTION_DECL)
1075 dump_function_to_file (const_cast <tree_node*> (&ref), stderr, 0);
1076 else
1077 debug (ref);
1080 DEBUG_FUNCTION void
1081 debug_body (const tree_node *ptr)
1083 if (ptr)
1084 debug_body (*ptr);
1085 else
1086 fprintf (stderr, "<nil>\n");
1089 /* Print the vector of trees VEC on standard error, for debugging.
1090 Most nodes referred to by this one are printed recursively
1091 down to a depth of six. */
1093 DEBUG_FUNCTION void
1094 debug_raw (vec<tree, va_gc> &ref)
1096 tree elt;
1097 unsigned ix;
1099 /* Print the slot this node is in, and its code, and address. */
1100 fprintf (stderr, "<VEC");
1101 dump_addr (stderr, " ", ref.address ());
1103 FOR_EACH_VEC_ELT (ref, ix, elt)
1105 fprintf (stderr, "elt %d ", ix);
1106 debug_raw (elt);
1110 DEBUG_FUNCTION void
1111 debug (vec<tree, va_gc> &ref)
1113 tree elt;
1114 unsigned ix;
1116 /* Print the slot this node is in, and its code, and address. */
1117 fprintf (stderr, "<VEC");
1118 dump_addr (stderr, " ", ref.address ());
1120 FOR_EACH_VEC_ELT (ref, ix, elt)
1122 fprintf (stderr, "elt %d ", ix);
1123 debug (elt);
1127 DEBUG_FUNCTION void
1128 debug (vec<tree, va_gc> *ptr)
1130 if (ptr)
1131 debug (*ptr);
1132 else
1133 fprintf (stderr, "<nil>\n");
1136 DEBUG_FUNCTION void
1137 debug_raw (vec<tree, va_gc> *ptr)
1139 if (ptr)
1140 debug_raw (*ptr);
1141 else
1142 fprintf (stderr, "<nil>\n");
1145 DEBUG_FUNCTION void
1146 debug_vec_tree (vec<tree, va_gc> *vec)
1148 debug_raw (vec);