Merge trunk version 198815 into gupc branch.
[official-gcc.git] / gcc / print-tree.c
blob04ebce2f46bb59023e3216d76ebbecdb1b48983a
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 "tree-flow.h"
32 #include "tree-dump.h"
33 #include "dumpfile.h"
35 /* Define the hash table of nodes already seen.
36 Such nodes are not repeated; brief cross-references are used. */
38 #define HASH_SIZE 37
40 struct bucket
42 tree node;
43 struct bucket *next;
46 static struct bucket **table;
48 /* Print PREFIX and ADDR to FILE. */
49 void
50 dump_addr (FILE *file, const char *prefix, const void *addr)
52 if (flag_dump_noaddr || flag_dump_unnumbered)
53 fprintf (file, "%s#", prefix);
54 else
55 fprintf (file, "%s" HOST_PTR_PRINTF, prefix, addr);
58 /* Print a node in brief fashion, with just the code, address and name. */
60 void
61 print_node_brief (FILE *file, const char *prefix, const_tree node, int indent)
63 enum tree_code_class tclass;
65 if (node == 0)
66 return;
68 tclass = TREE_CODE_CLASS (TREE_CODE (node));
70 /* Always print the slot this node is in, and its code, address and
71 name if any. */
72 if (indent > 0)
73 fprintf (file, " ");
74 fprintf (file, "%s <%s", prefix, tree_code_name[(int) TREE_CODE (node)]);
75 dump_addr (file, " ", node);
77 if (tclass == tcc_declaration)
79 if (DECL_NAME (node))
80 fprintf (file, " %s", IDENTIFIER_POINTER (DECL_NAME (node)));
81 else if (TREE_CODE (node) == LABEL_DECL
82 && LABEL_DECL_UID (node) != -1)
84 if (dump_flags & TDF_NOUID)
85 fprintf (file, " L.xxxx");
86 else
87 fprintf (file, " L.%d", (int) LABEL_DECL_UID (node));
89 else
91 if (dump_flags & TDF_NOUID)
92 fprintf (file, " %c.xxxx",
93 TREE_CODE (node) == CONST_DECL ? 'C' : 'D');
94 else
95 fprintf (file, " %c.%u",
96 TREE_CODE (node) == CONST_DECL ? 'C' : 'D',
97 DECL_UID (node));
100 else if (tclass == tcc_type)
102 if (TYPE_NAME (node))
104 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
105 fprintf (file, " %s", IDENTIFIER_POINTER (TYPE_NAME (node)));
106 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
107 && DECL_NAME (TYPE_NAME (node)))
108 fprintf (file, " %s",
109 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node))));
111 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (node)))
112 fprintf (file, " address-space-%d", TYPE_ADDR_SPACE (node));
114 if (TREE_CODE (node) == IDENTIFIER_NODE)
115 fprintf (file, " %s", IDENTIFIER_POINTER (node));
117 /* We might as well always print the value of an integer or real. */
118 if (TREE_CODE (node) == INTEGER_CST)
120 if (TREE_OVERFLOW (node))
121 fprintf (file, " overflow");
123 fprintf (file, " ");
124 if (TREE_INT_CST_HIGH (node) == 0)
125 fprintf (file, HOST_WIDE_INT_PRINT_UNSIGNED, TREE_INT_CST_LOW (node));
126 else if (TREE_INT_CST_HIGH (node) == -1
127 && TREE_INT_CST_LOW (node) != 0)
128 fprintf (file, "-" HOST_WIDE_INT_PRINT_UNSIGNED,
129 -TREE_INT_CST_LOW (node));
130 else
131 fprintf (file, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
132 (unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (node),
133 (unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (node));
135 if (TREE_CODE (node) == REAL_CST)
137 REAL_VALUE_TYPE d;
139 if (TREE_OVERFLOW (node))
140 fprintf (file, " overflow");
142 d = TREE_REAL_CST (node);
143 if (REAL_VALUE_ISINF (d))
144 fprintf (file, REAL_VALUE_NEGATIVE (d) ? " -Inf" : " Inf");
145 else if (REAL_VALUE_ISNAN (d))
146 fprintf (file, " Nan");
147 else
149 char string[60];
150 real_to_decimal (string, &d, sizeof (string), 0, 1);
151 fprintf (file, " %s", string);
154 if (TREE_CODE (node) == FIXED_CST)
156 FIXED_VALUE_TYPE f;
157 char string[60];
159 if (TREE_OVERFLOW (node))
160 fprintf (file, " overflow");
162 f = TREE_FIXED_CST (node);
163 fixed_to_decimal (string, &f, sizeof (string));
164 fprintf (file, " %s", string);
167 fprintf (file, ">");
170 void
171 indent_to (FILE *file, int column)
173 int i;
175 /* Since this is the long way, indent to desired column. */
176 if (column > 0)
177 fprintf (file, "\n");
178 for (i = 0; i < column; i++)
179 fprintf (file, " ");
182 /* Print the node NODE in full on file FILE, preceded by PREFIX,
183 starting in column INDENT. */
185 void
186 print_node (FILE *file, const char *prefix, tree node, int indent)
188 int hash;
189 struct bucket *b;
190 enum machine_mode mode;
191 enum tree_code_class tclass;
192 int len;
193 int i;
194 expanded_location xloc;
195 enum tree_code code;
197 if (node == 0)
198 return;
200 code = TREE_CODE (node);
201 tclass = TREE_CODE_CLASS (code);
203 /* Don't get too deep in nesting. If the user wants to see deeper,
204 it is easy to use the address of a lowest-level node
205 as an argument in another call to debug_tree. */
207 if (indent > 24)
209 print_node_brief (file, prefix, node, indent);
210 return;
213 if (indent > 8 && (tclass == tcc_type || tclass == tcc_declaration))
215 print_node_brief (file, prefix, node, indent);
216 return;
219 /* It is unsafe to look at any other fields of an ERROR_MARK node. */
220 if (code == ERROR_MARK)
222 print_node_brief (file, prefix, node, indent);
223 return;
226 /* Allow this function to be called if the table is not there. */
227 if (table)
229 hash = ((uintptr_t) node) % HASH_SIZE;
231 /* If node is in the table, just mention its address. */
232 for (b = table[hash]; b; b = b->next)
233 if (b->node == node)
235 print_node_brief (file, prefix, node, indent);
236 return;
239 /* Add this node to the table. */
240 b = XNEW (struct bucket);
241 b->node = node;
242 b->next = table[hash];
243 table[hash] = b;
246 /* Indent to the specified column, since this is the long form. */
247 indent_to (file, indent);
249 /* Print the slot this node is in, and its code, and address. */
250 fprintf (file, "%s <%s", prefix, tree_code_name[(int) code]);
251 dump_addr (file, " ", node);
253 /* Print the name, if any. */
254 if (tclass == tcc_declaration)
256 if (DECL_NAME (node))
257 fprintf (file, " %s", IDENTIFIER_POINTER (DECL_NAME (node)));
258 else if (code == LABEL_DECL
259 && LABEL_DECL_UID (node) != -1)
261 if (dump_flags & TDF_NOUID)
262 fprintf (file, " L.xxxx");
263 else
264 fprintf (file, " L.%d", (int) LABEL_DECL_UID (node));
266 else
268 if (dump_flags & TDF_NOUID)
269 fprintf (file, " %c.xxxx", code == CONST_DECL ? 'C' : 'D');
270 else
271 fprintf (file, " %c.%u", code == CONST_DECL ? 'C' : 'D',
272 DECL_UID (node));
275 else if (tclass == tcc_type)
277 if (TYPE_NAME (node))
279 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
280 fprintf (file, " %s", IDENTIFIER_POINTER (TYPE_NAME (node)));
281 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
282 && DECL_NAME (TYPE_NAME (node)))
283 fprintf (file, " %s",
284 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node))));
287 if (code == IDENTIFIER_NODE)
288 fprintf (file, " %s", IDENTIFIER_POINTER (node));
290 if (code == INTEGER_CST)
292 if (indent <= 4)
293 print_node_brief (file, "type", TREE_TYPE (node), indent + 4);
295 else if (CODE_CONTAINS_STRUCT (code, TS_TYPED))
297 print_node (file, "type", TREE_TYPE (node), indent + 4);
298 if (TREE_TYPE (node))
299 indent_to (file, indent + 3);
302 if (!TYPE_P (node) && TREE_SIDE_EFFECTS (node))
303 fputs (" side-effects", file);
305 if (TYPE_P (node) ? TYPE_READONLY (node) : TREE_READONLY (node))
306 fputs (" readonly", file);
307 if (TREE_SHARED (node))
308 fputs (" shared", file);
309 if (!TYPE_P (node) && TREE_CONSTANT (node))
310 fputs (" constant", file);
311 else if (TYPE_P (node) && TYPE_SIZES_GIMPLIFIED (node))
312 fputs (" sizes-gimplified", file);
314 if (TYPE_P (node) && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (node)))
315 fprintf (file, " address-space-%d", TYPE_ADDR_SPACE (node));
317 if (TREE_ADDRESSABLE (node))
318 fputs (" addressable", file);
319 if (TREE_THIS_VOLATILE (node))
320 fputs (" volatile", file);
321 if (TREE_ASM_WRITTEN (node))
322 fputs (" asm_written", file);
323 if (TREE_USED (node))
324 fputs (" used", file);
325 if (TREE_NOTHROW (node))
326 fputs (TYPE_P (node) ? " align-ok" : " nothrow", file);
327 if (TREE_PUBLIC (node))
328 fputs (" public", file);
329 if (TREE_PRIVATE (node))
330 fputs (" private", file);
331 if (TREE_PROTECTED (node))
332 fputs (" protected", file);
333 if (TREE_STATIC (node))
334 fputs (" static", file);
335 if (TREE_CODE (node) == FUNCTION_DECL && DECL_STATIC_CONSTRUCTOR (node))
336 fputs (" constructor", file);
337 if (TREE_CODE (node) == FUNCTION_DECL && DECL_STATIC_DESTRUCTOR (node))
338 fputs (" destructor", 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 != 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 (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 && DECL_ERROR_ISSUED (node))
419 fputs (" error-issued", file);
420 if (code == LABEL_DECL && EH_LANDING_PAD_NR (node))
421 fprintf (file, " landing-pad:%d", EH_LANDING_PAD_NR (node));
423 if (code == VAR_DECL && DECL_IN_TEXT_SECTION (node))
424 fputs (" in-text-section", file);
425 if (code == VAR_DECL && DECL_IN_CONSTANT_POOL (node))
426 fputs (" in-constant-pool", file);
427 if (code == VAR_DECL && DECL_COMMON (node))
428 fputs (" common", file);
429 if (code == VAR_DECL && DECL_THREAD_LOCAL_P (node))
431 enum tls_model kind = DECL_TLS_MODEL (node);
432 switch (kind)
434 case TLS_MODEL_GLOBAL_DYNAMIC:
435 fputs (" tls-global-dynamic", file);
436 break;
437 case TLS_MODEL_LOCAL_DYNAMIC:
438 fputs (" tls-local-dynamic", file);
439 break;
440 case TLS_MODEL_INITIAL_EXEC:
441 fputs (" tls-initial-exec", file);
442 break;
443 case TLS_MODEL_LOCAL_EXEC:
444 fputs (" tls-local-exec", file);
445 break;
446 default:
447 gcc_unreachable ();
451 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
453 if (DECL_VIRTUAL_P (node))
454 fputs (" virtual", file);
455 if (DECL_PRESERVE_P (node))
456 fputs (" preserve", file);
457 if (DECL_LANG_FLAG_0 (node))
458 fputs (" decl_0", file);
459 if (DECL_LANG_FLAG_1 (node))
460 fputs (" decl_1", file);
461 if (DECL_LANG_FLAG_2 (node))
462 fputs (" decl_2", file);
463 if (DECL_LANG_FLAG_3 (node))
464 fputs (" decl_3", file);
465 if (DECL_LANG_FLAG_4 (node))
466 fputs (" decl_4", file);
467 if (DECL_LANG_FLAG_5 (node))
468 fputs (" decl_5", file);
469 if (DECL_LANG_FLAG_6 (node))
470 fputs (" decl_6", file);
471 if (DECL_LANG_FLAG_7 (node))
472 fputs (" decl_7", file);
474 mode = DECL_MODE (node);
475 fprintf (file, " %s", GET_MODE_NAME (mode));
478 if ((code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
479 && DECL_BY_REFERENCE (node))
480 fputs (" passed-by-reference", file);
482 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS) && DECL_DEFER_OUTPUT (node))
483 fputs (" defer-output", file);
486 xloc = expand_location (DECL_SOURCE_LOCATION (node));
487 fprintf (file, " file %s line %d col %d", xloc.file, xloc.line,
488 xloc.column);
490 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
492 print_node (file, "size", DECL_SIZE (node), indent + 4);
493 print_node (file, "unit size", DECL_SIZE_UNIT (node), indent + 4);
495 if (code != FUNCTION_DECL || DECL_BUILT_IN (node))
496 indent_to (file, indent + 3);
498 if (DECL_USER_ALIGN (node))
499 fprintf (file, " user");
501 fprintf (file, " align %d", DECL_ALIGN (node));
502 if (code == FIELD_DECL)
503 fprintf (file, " offset_align " HOST_WIDE_INT_PRINT_UNSIGNED,
504 DECL_OFFSET_ALIGN (node));
506 if (code == FUNCTION_DECL && DECL_BUILT_IN (node))
508 if (DECL_BUILT_IN_CLASS (node) == BUILT_IN_MD)
509 fprintf (file, " built-in BUILT_IN_MD %d", DECL_FUNCTION_CODE (node));
510 else
511 fprintf (file, " built-in %s:%s",
512 built_in_class_names[(int) DECL_BUILT_IN_CLASS (node)],
513 built_in_names[(int) DECL_FUNCTION_CODE (node)]);
516 if (code == FIELD_DECL)
518 print_node (file, "offset", DECL_FIELD_OFFSET (node), indent + 4);
519 print_node (file, "bit offset", DECL_FIELD_BIT_OFFSET (node),
520 indent + 4);
521 if (DECL_BIT_FIELD_TYPE (node))
522 print_node (file, "bit_field_type", DECL_BIT_FIELD_TYPE (node),
523 indent + 4);
526 print_node_brief (file, "context", DECL_CONTEXT (node), indent + 4);
528 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
530 print_node_brief (file, "attributes",
531 DECL_ATTRIBUTES (node), indent + 4);
532 if (code != PARM_DECL)
533 print_node_brief (file, "initial", DECL_INITIAL (node),
534 indent + 4);
536 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WRTL))
538 print_node_brief (file, "abstract_origin",
539 DECL_ABSTRACT_ORIGIN (node), indent + 4);
541 if (CODE_CONTAINS_STRUCT (code, TS_DECL_NON_COMMON))
543 print_node (file, "arguments", DECL_ARGUMENT_FLD (node), indent + 4);
544 print_node (file, "result", DECL_RESULT_FLD (node), indent + 4);
547 lang_hooks.print_decl (file, node, indent);
549 if (DECL_RTL_SET_P (node))
551 indent_to (file, indent + 4);
552 print_rtl (file, DECL_RTL (node));
555 if (code == PARM_DECL)
557 print_node (file, "arg-type", DECL_ARG_TYPE (node), indent + 4);
559 if (DECL_INCOMING_RTL (node) != 0)
561 indent_to (file, indent + 4);
562 fprintf (file, "incoming-rtl ");
563 print_rtl (file, DECL_INCOMING_RTL (node));
566 else if (code == FUNCTION_DECL
567 && DECL_STRUCT_FUNCTION (node) != 0)
569 indent_to (file, indent + 4);
570 dump_addr (file, "struct-function ", DECL_STRUCT_FUNCTION (node));
573 if ((code == VAR_DECL || code == PARM_DECL)
574 && DECL_HAS_VALUE_EXPR_P (node))
575 print_node (file, "value-expr", DECL_VALUE_EXPR (node), indent + 4);
577 /* Print the decl chain only if decl is at second level. */
578 if (indent == 4)
579 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
580 else
581 print_node_brief (file, "chain", TREE_CHAIN (node), indent + 4);
582 break;
584 case tcc_type:
585 if (TYPE_UNSIGNED (node))
586 fputs (" unsigned", file);
588 /* The no-force-blk flag is used for different things in
589 different types. */
590 if ((code == RECORD_TYPE
591 || code == UNION_TYPE
592 || code == QUAL_UNION_TYPE)
593 && TYPE_NO_FORCE_BLK (node))
594 fputs (" no-force-blk", file);
596 if (TYPE_STRING_FLAG (node))
597 fputs (" string-flag", file);
598 if (TYPE_NEEDS_CONSTRUCTING (node))
599 fputs (" needs-constructing", file);
601 /* The transparent-union flag is used for different things in
602 different nodes. */
603 if ((code == UNION_TYPE || code == RECORD_TYPE)
604 && TYPE_TRANSPARENT_AGGR (node))
605 fputs (" transparent-aggr", file);
606 else if (code == ARRAY_TYPE
607 && TYPE_NONALIASED_COMPONENT (node))
608 fputs (" nonaliased-component", file);
610 if (TYPE_PACKED (node))
611 fputs (" packed", file);
613 if (TYPE_RESTRICT (node))
614 fputs (" restrict", file);
616 if (TYPE_LANG_FLAG_0 (node))
617 fputs (" type_0", file);
618 if (TYPE_LANG_FLAG_1 (node))
619 fputs (" type_1", file);
620 if (TYPE_LANG_FLAG_2 (node))
621 fputs (" type_2", file);
622 if (!TYPE_SHARED (node))
624 if (TYPE_LANG_FLAG_3 (node))
625 fputs (" type_3", file);
626 if (TYPE_LANG_FLAG_4 (node))
627 fputs (" type_4", file);
628 if (TYPE_LANG_FLAG_5 (node))
629 fputs (" type_5", file);
631 if (TYPE_LANG_FLAG_6 (node))
632 fputs (" type_6", file);
634 mode = TYPE_MODE (node);
635 fprintf (file, " %s", GET_MODE_NAME (mode));
637 print_node (file, "size", TYPE_SIZE (node), indent + 4);
638 print_node (file, "unit size", TYPE_SIZE_UNIT (node), indent + 4);
639 if (TYPE_SHARED (node))
641 if (TYPE_HAS_THREADS_FACTOR(node))
642 fputs (" THREADS factor", file);
643 if (TYPE_HAS_BLOCK_FACTOR (node))
644 print_node (file, "block factor",
645 TYPE_BLOCK_FACTOR (node), indent + 4);
647 indent_to (file, indent + 3);
649 if (TYPE_USER_ALIGN (node))
650 fprintf (file, " user");
652 fprintf (file, " align %d symtab %d alias set " HOST_WIDE_INT_PRINT_DEC,
653 TYPE_ALIGN (node), TYPE_SYMTAB_ADDRESS (node),
654 (HOST_WIDE_INT) TYPE_ALIAS_SET (node));
656 if (TYPE_STRUCTURAL_EQUALITY_P (node))
657 fprintf (file, " structural equality");
658 else
659 dump_addr (file, " canonical type ", TYPE_CANONICAL (node));
661 print_node (file, "attributes", TYPE_ATTRIBUTES (node), indent + 4);
663 if (INTEGRAL_TYPE_P (node) || code == REAL_TYPE
664 || code == FIXED_POINT_TYPE)
666 fprintf (file, " precision %d", TYPE_PRECISION (node));
667 print_node_brief (file, "min", TYPE_MIN_VALUE (node), indent + 4);
668 print_node_brief (file, "max", TYPE_MAX_VALUE (node), indent + 4);
671 if (code == ENUMERAL_TYPE)
672 print_node (file, "values", TYPE_VALUES (node), indent + 4);
673 else if (code == ARRAY_TYPE)
674 print_node (file, "domain", TYPE_DOMAIN (node), indent + 4);
675 else if (code == VECTOR_TYPE)
676 fprintf (file, " nunits %d", (int) TYPE_VECTOR_SUBPARTS (node));
677 else if (code == RECORD_TYPE
678 || code == UNION_TYPE
679 || code == QUAL_UNION_TYPE)
680 print_node (file, "fields", TYPE_FIELDS (node), indent + 4);
681 else if (code == FUNCTION_TYPE
682 || code == METHOD_TYPE)
684 if (TYPE_METHOD_BASETYPE (node))
685 print_node_brief (file, "method basetype",
686 TYPE_METHOD_BASETYPE (node), indent + 4);
687 print_node (file, "arg-types", TYPE_ARG_TYPES (node), indent + 4);
689 else if (code == OFFSET_TYPE)
690 print_node_brief (file, "basetype", TYPE_OFFSET_BASETYPE (node),
691 indent + 4);
693 if (TYPE_CONTEXT (node))
694 print_node_brief (file, "context", TYPE_CONTEXT (node), indent + 4);
696 lang_hooks.print_type (file, node, indent);
698 if (TYPE_POINTER_TO (node) || TREE_CHAIN (node))
699 indent_to (file, indent + 3);
701 print_node_brief (file, "pointer_to_this", TYPE_POINTER_TO (node),
702 indent + 4);
703 print_node_brief (file, "reference_to_this", TYPE_REFERENCE_TO (node),
704 indent + 4);
705 print_node_brief (file, "chain", TREE_CHAIN (node), indent + 4);
706 break;
708 case tcc_expression:
709 case tcc_comparison:
710 case tcc_unary:
711 case tcc_binary:
712 case tcc_reference:
713 case tcc_statement:
714 case tcc_vl_exp:
715 if (code == BIND_EXPR)
717 print_node (file, "vars", TREE_OPERAND (node, 0), indent + 4);
718 print_node (file, "body", TREE_OPERAND (node, 1), indent + 4);
719 print_node (file, "block", TREE_OPERAND (node, 2), indent + 4);
720 break;
722 if (code == CALL_EXPR)
724 call_expr_arg_iterator iter;
725 tree arg;
726 print_node (file, "fn", CALL_EXPR_FN (node), indent + 4);
727 print_node (file, "static_chain", CALL_EXPR_STATIC_CHAIN (node),
728 indent + 4);
729 i = 0;
730 FOR_EACH_CALL_EXPR_ARG (arg, iter, node)
732 char temp[10];
733 sprintf (temp, "arg %d", i);
734 print_node (file, temp, arg, indent + 4);
735 i++;
738 else
740 len = TREE_OPERAND_LENGTH (node);
742 for (i = 0; i < len; i++)
744 char temp[10];
746 sprintf (temp, "arg %d", i);
747 print_node (file, temp, TREE_OPERAND (node, i), indent + 4);
750 if (CODE_CONTAINS_STRUCT (code, TS_COMMON))
751 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
752 break;
754 case tcc_constant:
755 case tcc_exceptional:
756 switch (code)
758 case INTEGER_CST:
759 if (TREE_OVERFLOW (node))
760 fprintf (file, " overflow");
762 fprintf (file, " ");
763 if (TREE_INT_CST_HIGH (node) == 0)
764 fprintf (file, HOST_WIDE_INT_PRINT_UNSIGNED,
765 TREE_INT_CST_LOW (node));
766 else if (TREE_INT_CST_HIGH (node) == -1
767 && TREE_INT_CST_LOW (node) != 0)
768 fprintf (file, "-" HOST_WIDE_INT_PRINT_UNSIGNED,
769 -TREE_INT_CST_LOW (node));
770 else
771 fprintf (file, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
772 (unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (node),
773 (unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (node));
774 break;
776 case REAL_CST:
778 REAL_VALUE_TYPE d;
780 if (TREE_OVERFLOW (node))
781 fprintf (file, " overflow");
783 d = TREE_REAL_CST (node);
784 if (REAL_VALUE_ISINF (d))
785 fprintf (file, REAL_VALUE_NEGATIVE (d) ? " -Inf" : " Inf");
786 else if (REAL_VALUE_ISNAN (d))
787 fprintf (file, " Nan");
788 else
790 char string[64];
791 real_to_decimal (string, &d, sizeof (string), 0, 1);
792 fprintf (file, " %s", string);
795 break;
797 case FIXED_CST:
799 FIXED_VALUE_TYPE f;
800 char string[64];
802 if (TREE_OVERFLOW (node))
803 fprintf (file, " overflow");
805 f = TREE_FIXED_CST (node);
806 fixed_to_decimal (string, &f, sizeof (string));
807 fprintf (file, " %s", string);
809 break;
811 case VECTOR_CST:
813 char buf[10];
814 unsigned i;
816 for (i = 0; i < VECTOR_CST_NELTS (node); ++i)
818 sprintf (buf, "elt%u: ", i);
819 print_node (file, buf, VECTOR_CST_ELT (node, i), indent + 4);
822 break;
824 case COMPLEX_CST:
825 print_node (file, "real", TREE_REALPART (node), indent + 4);
826 print_node (file, "imag", TREE_IMAGPART (node), indent + 4);
827 break;
829 case STRING_CST:
831 const char *p = TREE_STRING_POINTER (node);
832 int i = TREE_STRING_LENGTH (node);
833 fputs (" \"", file);
834 while (--i >= 0)
836 char ch = *p++;
837 if (ch >= ' ' && ch < 127)
838 putc (ch, file);
839 else
840 fprintf(file, "\\%03o", ch & 0xFF);
842 fputc ('\"', file);
844 break;
846 case IDENTIFIER_NODE:
847 lang_hooks.print_identifier (file, node, indent);
848 break;
850 case TREE_LIST:
851 print_node (file, "purpose", TREE_PURPOSE (node), indent + 4);
852 print_node (file, "value", TREE_VALUE (node), indent + 4);
853 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
854 break;
856 case TREE_VEC:
857 len = TREE_VEC_LENGTH (node);
858 for (i = 0; i < len; i++)
859 if (TREE_VEC_ELT (node, i))
861 char temp[10];
862 sprintf (temp, "elt %d", i);
863 print_node (file, temp, TREE_VEC_ELT (node, i), indent + 4);
865 break;
867 case CONSTRUCTOR:
869 unsigned HOST_WIDE_INT cnt;
870 tree index, value;
871 len = vec_safe_length (CONSTRUCTOR_ELTS (node));
872 fprintf (file, " lngt %d", len);
873 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (node),
874 cnt, index, value)
876 print_node (file, "idx", index, indent + 4);
877 print_node (file, "val", value, indent + 4);
880 break;
882 case STATEMENT_LIST:
883 dump_addr (file, " head ", node->stmt_list.head);
884 dump_addr (file, " tail ", node->stmt_list.tail);
885 fprintf (file, " stmts");
887 tree_stmt_iterator i;
888 for (i = tsi_start (node); !tsi_end_p (i); tsi_next (&i))
890 /* Not printing the addresses of the (not-a-tree)
891 'struct tree_stmt_list_node's. */
892 dump_addr (file, " ", tsi_stmt (i));
894 fprintf (file, "\n");
895 for (i = tsi_start (node); !tsi_end_p (i); tsi_next (&i))
897 /* Not printing the addresses of the (not-a-tree)
898 'struct tree_stmt_list_node's. */
899 print_node (file, "stmt", tsi_stmt (i), indent + 4);
902 break;
904 case BLOCK:
905 print_node (file, "vars", BLOCK_VARS (node), indent + 4);
906 print_node (file, "supercontext", BLOCK_SUPERCONTEXT (node),
907 indent + 4);
908 print_node (file, "subblocks", BLOCK_SUBBLOCKS (node), indent + 4);
909 print_node (file, "chain", BLOCK_CHAIN (node), indent + 4);
910 print_node (file, "abstract_origin",
911 BLOCK_ABSTRACT_ORIGIN (node), indent + 4);
912 break;
914 case SSA_NAME:
915 print_node_brief (file, "var", SSA_NAME_VAR (node), indent + 4);
916 fprintf (file, "def_stmt ");
917 print_gimple_stmt (file, SSA_NAME_DEF_STMT (node), indent + 4, 0);
919 indent_to (file, indent + 4);
920 fprintf (file, "version %u", SSA_NAME_VERSION (node));
921 if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (node))
922 fprintf (file, " in-abnormal-phi");
923 if (SSA_NAME_IN_FREE_LIST (node))
924 fprintf (file, " in-free-list");
926 if (SSA_NAME_PTR_INFO (node))
928 indent_to (file, indent + 3);
929 if (SSA_NAME_PTR_INFO (node))
930 dump_addr (file, " ptr-info ", SSA_NAME_PTR_INFO (node));
932 break;
934 case OMP_CLAUSE:
936 int i;
937 fprintf (file, " %s",
938 omp_clause_code_name[OMP_CLAUSE_CODE (node)]);
939 for (i = 0; i < omp_clause_num_ops[OMP_CLAUSE_CODE (node)]; i++)
941 indent_to (file, indent + 4);
942 fprintf (file, "op %d:", i);
943 print_node_brief (file, "", OMP_CLAUSE_OPERAND (node, i), 0);
946 break;
948 case OPTIMIZATION_NODE:
949 cl_optimization_print (file, indent + 4, TREE_OPTIMIZATION (node));
950 break;
952 case TARGET_OPTION_NODE:
953 cl_target_option_print (file, indent + 4, TREE_TARGET_OPTION (node));
954 break;
955 case IMPORTED_DECL:
956 fprintf (file, " imported declaration");
957 print_node_brief (file, "associated declaration",
958 IMPORTED_DECL_ASSOCIATED_DECL (node),
959 indent + 4);
960 break;
962 default:
963 if (EXCEPTIONAL_CLASS_P (node))
964 lang_hooks.print_xnode (file, node, indent);
965 break;
968 break;
971 if (EXPR_HAS_LOCATION (node))
973 expanded_location xloc = expand_location (EXPR_LOCATION (node));
974 indent_to (file, indent+4);
975 fprintf (file, "%s:%d:%d", xloc.file, xloc.line, xloc.column);
978 fprintf (file, ">");
981 /* Print the tree vector VEC in full on file FILE, preceded by PREFIX,
982 starting in column INDENT. */
984 void
985 print_vec_tree (FILE *file, const char *prefix, vec<tree, va_gc> *vec, int indent)
987 tree elt;
988 unsigned ix;
990 /* Indent to the specified column, since this is the long form. */
991 indent_to (file, indent);
993 /* Print the slot this node is in, and its code, and address. */
994 fprintf (file, "%s <VEC", prefix);
995 dump_addr (file, " ", vec->address ());
997 FOR_EACH_VEC_ELT (*vec, ix, elt)
999 char temp[10];
1000 sprintf (temp, "elt %d", ix);
1001 print_node (file, temp, elt, indent + 4);
1006 /* Print the node NODE on standard error, for debugging.
1007 Most nodes referred to by this one are printed recursively
1008 down to a depth of six. */
1010 DEBUG_FUNCTION void
1011 debug_tree (tree node)
1013 table = XCNEWVEC (struct bucket *, HASH_SIZE);
1014 print_node (stderr, "", node, 0);
1015 free (table);
1016 table = 0;
1017 putc ('\n', stderr);
1020 DEBUG_FUNCTION void
1021 debug_raw (const tree_node &ref)
1023 debug_tree (const_cast <tree> (&ref));
1026 DEBUG_FUNCTION void
1027 debug_raw (const tree_node *ptr)
1029 if (ptr)
1030 debug_raw (*ptr);
1031 else
1032 fprintf (stderr, "<nil>\n");
1035 static void
1036 dump_tree_via_hooks (const tree_node *ptr, int options)
1038 if (DECL_P (ptr))
1039 lang_hooks.print_decl (stderr, const_cast <tree_node*> (ptr), 0);
1040 else if (TYPE_P (ptr))
1041 lang_hooks.print_type (stderr, const_cast <tree_node*> (ptr), 0);
1042 else if (TREE_CODE (ptr) == IDENTIFIER_NODE)
1043 lang_hooks.print_identifier (stderr, const_cast <tree_node*> (ptr), 0);
1044 else
1045 print_generic_expr (stderr, const_cast <tree_node*> (ptr), options);
1046 fprintf (stderr, "\n");
1049 DEBUG_FUNCTION void
1050 debug (const tree_node &ref)
1052 dump_tree_via_hooks (&ref, 0);
1055 DEBUG_FUNCTION void
1056 debug (const tree_node *ptr)
1058 if (ptr)
1059 debug (*ptr);
1060 else
1061 fprintf (stderr, "<nil>\n");
1064 DEBUG_FUNCTION void
1065 debug_verbose (const tree_node &ref)
1067 dump_tree_via_hooks (&ref, TDF_VERBOSE);
1070 DEBUG_FUNCTION void
1071 debug_verbose (const tree_node *ptr)
1073 if (ptr)
1074 debug_verbose (*ptr);
1075 else
1076 fprintf (stderr, "<nil>\n");
1079 DEBUG_FUNCTION void
1080 debug_head (const tree_node &ref)
1082 debug (ref);
1085 DEBUG_FUNCTION void
1086 debug_head (const tree_node *ptr)
1088 if (ptr)
1089 debug_head (*ptr);
1090 else
1091 fprintf (stderr, "<nil>\n");
1094 DEBUG_FUNCTION void
1095 debug_body (const tree_node &ref)
1097 if (TREE_CODE (&ref) == FUNCTION_DECL)
1098 dump_function_to_file (const_cast <tree_node*> (&ref), stderr, 0);
1099 else
1100 debug (ref);
1103 DEBUG_FUNCTION void
1104 debug_body (const tree_node *ptr)
1106 if (ptr)
1107 debug_body (*ptr);
1108 else
1109 fprintf (stderr, "<nil>\n");
1112 /* Print the vector of trees VEC on standard error, for debugging.
1113 Most nodes referred to by this one are printed recursively
1114 down to a depth of six. */
1116 DEBUG_FUNCTION void
1117 debug_vec_tree (vec<tree, va_gc> *vec)
1119 tree elt;
1120 unsigned ix;
1122 /* Print the slot this node is in, and its code, and address. */
1123 fprintf (stderr, "<VEC");
1124 dump_addr (stderr, " ", vec->address ());
1126 FOR_EACH_VEC_ELT (*vec, ix, elt)
1128 fprintf (stderr, "elt %d ", ix);
1129 debug (elt);
1133 DEBUG_FUNCTION void
1134 debug (vec<tree, va_gc> &ref)
1136 debug_vec_tree (&ref);
1139 DEBUG_FUNCTION void
1140 debug (vec<tree, va_gc> *ptr)
1142 if (ptr)
1143 debug (*ptr);
1144 else
1145 fprintf (stderr, "<nil>\n");