tree-ssa-threadupdate.c: Include tree-cfg.h and tree-pass.h
[official-gcc.git] / gcc / print-tree.c
blob1f4bf222aa122072bded163fbe959689a949cd15
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 "varasm.h"
27 #include "print-rtl.h"
28 #include "stor-layout.h"
29 #include "ggc.h"
30 #include "langhooks.h"
31 #include "tree-iterator.h"
32 #include "diagnostic.h"
33 #include "gimple-pretty-print.h" /* FIXME */
34 #include "cgraph.h"
35 #include "tree-cfg.h"
36 #include "tree-dump.h"
37 #include "dumpfile.h"
39 /* Define the hash table of nodes already seen.
40 Such nodes are not repeated; brief cross-references are used. */
42 #define HASH_SIZE 37
44 struct bucket
46 tree node;
47 struct bucket *next;
50 static struct bucket **table;
52 /* Print PREFIX and ADDR to FILE. */
53 void
54 dump_addr (FILE *file, const char *prefix, const void *addr)
56 if (flag_dump_noaddr || flag_dump_unnumbered)
57 fprintf (file, "%s#", prefix);
58 else
59 fprintf (file, "%s" HOST_PTR_PRINTF, prefix, addr);
62 /* Print a node in brief fashion, with just the code, address and name. */
64 void
65 print_node_brief (FILE *file, const char *prefix, const_tree node, int indent)
67 enum tree_code_class tclass;
69 if (node == 0)
70 return;
72 tclass = TREE_CODE_CLASS (TREE_CODE (node));
74 /* Always print the slot this node is in, and its code, address and
75 name if any. */
76 if (indent > 0)
77 fprintf (file, " ");
78 fprintf (file, "%s <%s", prefix, get_tree_code_name (TREE_CODE (node)));
79 dump_addr (file, " ", node);
81 if (tclass == tcc_declaration)
83 if (DECL_NAME (node))
84 fprintf (file, " %s", IDENTIFIER_POINTER (DECL_NAME (node)));
85 else if (TREE_CODE (node) == LABEL_DECL
86 && LABEL_DECL_UID (node) != -1)
88 if (dump_flags & TDF_NOUID)
89 fprintf (file, " L.xxxx");
90 else
91 fprintf (file, " L.%d", (int) LABEL_DECL_UID (node));
93 else
95 if (dump_flags & TDF_NOUID)
96 fprintf (file, " %c.xxxx",
97 TREE_CODE (node) == CONST_DECL ? 'C' : 'D');
98 else
99 fprintf (file, " %c.%u",
100 TREE_CODE (node) == CONST_DECL ? 'C' : 'D',
101 DECL_UID (node));
104 else if (tclass == tcc_type)
106 if (TYPE_NAME (node))
108 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
109 fprintf (file, " %s", IDENTIFIER_POINTER (TYPE_NAME (node)));
110 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
111 && DECL_NAME (TYPE_NAME (node)))
112 fprintf (file, " %s",
113 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node))));
115 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (node)))
116 fprintf (file, " address-space-%d", TYPE_ADDR_SPACE (node));
118 if (TREE_CODE (node) == IDENTIFIER_NODE)
119 fprintf (file, " %s", IDENTIFIER_POINTER (node));
121 /* We might as well always print the value of an integer or real. */
122 if (TREE_CODE (node) == INTEGER_CST)
124 if (TREE_OVERFLOW (node))
125 fprintf (file, " overflow");
127 fprintf (file, " ");
128 if (TREE_INT_CST_HIGH (node) == 0)
129 fprintf (file, HOST_WIDE_INT_PRINT_UNSIGNED, TREE_INT_CST_LOW (node));
130 else if (TREE_INT_CST_HIGH (node) == -1
131 && TREE_INT_CST_LOW (node) != 0)
132 fprintf (file, "-" HOST_WIDE_INT_PRINT_UNSIGNED,
133 -TREE_INT_CST_LOW (node));
134 else
135 fprintf (file, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
136 (unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (node),
137 (unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (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 enum 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 != 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 && 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 enum tls_model kind = DECL_TLS_MODEL (node);
430 switch (kind)
432 case TLS_MODEL_GLOBAL_DYNAMIC:
433 fputs (" tls-global-dynamic", file);
434 break;
435 case TLS_MODEL_LOCAL_DYNAMIC:
436 fputs (" tls-local-dynamic", file);
437 break;
438 case TLS_MODEL_INITIAL_EXEC:
439 fputs (" tls-initial-exec", file);
440 break;
441 case TLS_MODEL_LOCAL_EXEC:
442 fputs (" tls-local-exec", file);
443 break;
444 default:
445 gcc_unreachable ();
449 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
451 if (DECL_VIRTUAL_P (node))
452 fputs (" virtual", file);
453 if (DECL_PRESERVE_P (node))
454 fputs (" preserve", file);
455 if (DECL_LANG_FLAG_0 (node))
456 fputs (" decl_0", file);
457 if (DECL_LANG_FLAG_1 (node))
458 fputs (" decl_1", file);
459 if (DECL_LANG_FLAG_2 (node))
460 fputs (" decl_2", file);
461 if (DECL_LANG_FLAG_3 (node))
462 fputs (" decl_3", file);
463 if (DECL_LANG_FLAG_4 (node))
464 fputs (" decl_4", file);
465 if (DECL_LANG_FLAG_5 (node))
466 fputs (" decl_5", file);
467 if (DECL_LANG_FLAG_6 (node))
468 fputs (" decl_6", file);
469 if (DECL_LANG_FLAG_7 (node))
470 fputs (" decl_7", file);
472 mode = DECL_MODE (node);
473 fprintf (file, " %s", GET_MODE_NAME (mode));
476 if ((code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
477 && DECL_BY_REFERENCE (node))
478 fputs (" passed-by-reference", file);
480 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS) && DECL_DEFER_OUTPUT (node))
481 fputs (" defer-output", file);
484 xloc = expand_location (DECL_SOURCE_LOCATION (node));
485 fprintf (file, " file %s line %d col %d", xloc.file, xloc.line,
486 xloc.column);
488 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
490 print_node (file, "size", DECL_SIZE (node), indent + 4);
491 print_node (file, "unit size", DECL_SIZE_UNIT (node), indent + 4);
493 if (code != FUNCTION_DECL || DECL_BUILT_IN (node))
494 indent_to (file, indent + 3);
496 if (DECL_USER_ALIGN (node))
497 fprintf (file, " user");
499 fprintf (file, " align %d", DECL_ALIGN (node));
500 if (code == FIELD_DECL)
501 fprintf (file, " offset_align " HOST_WIDE_INT_PRINT_UNSIGNED,
502 DECL_OFFSET_ALIGN (node));
504 if (code == FUNCTION_DECL && DECL_BUILT_IN (node))
506 if (DECL_BUILT_IN_CLASS (node) == BUILT_IN_MD)
507 fprintf (file, " built-in BUILT_IN_MD %d", DECL_FUNCTION_CODE (node));
508 else
509 fprintf (file, " built-in %s:%s",
510 built_in_class_names[(int) DECL_BUILT_IN_CLASS (node)],
511 built_in_names[(int) DECL_FUNCTION_CODE (node)]);
514 if (code == FIELD_DECL)
516 print_node (file, "offset", DECL_FIELD_OFFSET (node), indent + 4);
517 print_node (file, "bit offset", DECL_FIELD_BIT_OFFSET (node),
518 indent + 4);
519 if (DECL_BIT_FIELD_TYPE (node))
520 print_node (file, "bit_field_type", DECL_BIT_FIELD_TYPE (node),
521 indent + 4);
524 print_node_brief (file, "context", DECL_CONTEXT (node), indent + 4);
526 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
528 print_node_brief (file, "attributes",
529 DECL_ATTRIBUTES (node), indent + 4);
530 if (code != PARM_DECL)
531 print_node_brief (file, "initial", DECL_INITIAL (node),
532 indent + 4);
534 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WRTL))
536 print_node_brief (file, "abstract_origin",
537 DECL_ABSTRACT_ORIGIN (node), indent + 4);
539 if (CODE_CONTAINS_STRUCT (code, TS_DECL_NON_COMMON))
541 print_node (file, "arguments", DECL_ARGUMENT_FLD (node), indent + 4);
542 print_node (file, "result", DECL_RESULT_FLD (node), indent + 4);
545 lang_hooks.print_decl (file, node, indent);
547 if (DECL_RTL_SET_P (node))
549 indent_to (file, indent + 4);
550 print_rtl (file, DECL_RTL (node));
553 if (code == PARM_DECL)
555 print_node (file, "arg-type", DECL_ARG_TYPE (node), indent + 4);
557 if (DECL_INCOMING_RTL (node) != 0)
559 indent_to (file, indent + 4);
560 fprintf (file, "incoming-rtl ");
561 print_rtl (file, DECL_INCOMING_RTL (node));
564 else if (code == FUNCTION_DECL
565 && DECL_STRUCT_FUNCTION (node) != 0)
567 indent_to (file, indent + 4);
568 dump_addr (file, "struct-function ", DECL_STRUCT_FUNCTION (node));
571 if ((code == VAR_DECL || code == PARM_DECL)
572 && DECL_HAS_VALUE_EXPR_P (node))
573 print_node (file, "value-expr", DECL_VALUE_EXPR (node), indent + 4);
575 /* Print the decl chain only if decl is at second level. */
576 if (indent == 4)
577 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
578 else
579 print_node_brief (file, "chain", TREE_CHAIN (node), indent + 4);
580 break;
582 case tcc_type:
583 if (TYPE_UNSIGNED (node))
584 fputs (" unsigned", file);
586 /* The no-force-blk flag is used for different things in
587 different types. */
588 if ((code == RECORD_TYPE
589 || code == UNION_TYPE
590 || code == QUAL_UNION_TYPE)
591 && TYPE_NO_FORCE_BLK (node))
592 fputs (" no-force-blk", file);
594 if (TYPE_STRING_FLAG (node))
595 fputs (" string-flag", file);
596 if (TYPE_NEEDS_CONSTRUCTING (node))
597 fputs (" needs-constructing", file);
599 /* The transparent-union flag is used for different things in
600 different nodes. */
601 if ((code == UNION_TYPE || code == RECORD_TYPE)
602 && TYPE_TRANSPARENT_AGGR (node))
603 fputs (" transparent-aggr", file);
604 else if (code == ARRAY_TYPE
605 && TYPE_NONALIASED_COMPONENT (node))
606 fputs (" nonaliased-component", file);
608 if (TYPE_PACKED (node))
609 fputs (" packed", file);
611 if (TYPE_RESTRICT (node))
612 fputs (" restrict", file);
614 if (TYPE_LANG_FLAG_0 (node))
615 fputs (" type_0", file);
616 if (TYPE_LANG_FLAG_1 (node))
617 fputs (" type_1", file);
618 if (TYPE_LANG_FLAG_2 (node))
619 fputs (" type_2", file);
620 if (TYPE_LANG_FLAG_3 (node))
621 fputs (" type_3", file);
622 if (TYPE_LANG_FLAG_4 (node))
623 fputs (" type_4", file);
624 if (TYPE_LANG_FLAG_5 (node))
625 fputs (" type_5", file);
626 if (TYPE_LANG_FLAG_6 (node))
627 fputs (" type_6", file);
629 mode = TYPE_MODE (node);
630 fprintf (file, " %s", GET_MODE_NAME (mode));
632 print_node (file, "size", TYPE_SIZE (node), indent + 4);
633 print_node (file, "unit size", TYPE_SIZE_UNIT (node), indent + 4);
634 indent_to (file, indent + 3);
636 if (TYPE_USER_ALIGN (node))
637 fprintf (file, " user");
639 fprintf (file, " align %d symtab %d alias set " HOST_WIDE_INT_PRINT_DEC,
640 TYPE_ALIGN (node), TYPE_SYMTAB_ADDRESS (node),
641 (HOST_WIDE_INT) TYPE_ALIAS_SET (node));
643 if (TYPE_STRUCTURAL_EQUALITY_P (node))
644 fprintf (file, " structural equality");
645 else
646 dump_addr (file, " canonical type ", TYPE_CANONICAL (node));
648 print_node (file, "attributes", TYPE_ATTRIBUTES (node), indent + 4);
650 if (INTEGRAL_TYPE_P (node) || code == REAL_TYPE
651 || code == FIXED_POINT_TYPE)
653 fprintf (file, " precision %d", TYPE_PRECISION (node));
654 print_node_brief (file, "min", TYPE_MIN_VALUE (node), indent + 4);
655 print_node_brief (file, "max", TYPE_MAX_VALUE (node), indent + 4);
658 if (code == ENUMERAL_TYPE)
659 print_node (file, "values", TYPE_VALUES (node), indent + 4);
660 else if (code == ARRAY_TYPE)
661 print_node (file, "domain", TYPE_DOMAIN (node), indent + 4);
662 else if (code == VECTOR_TYPE)
663 fprintf (file, " nunits %d", (int) TYPE_VECTOR_SUBPARTS (node));
664 else if (code == RECORD_TYPE
665 || code == UNION_TYPE
666 || code == QUAL_UNION_TYPE)
667 print_node (file, "fields", TYPE_FIELDS (node), indent + 4);
668 else if (code == FUNCTION_TYPE
669 || code == METHOD_TYPE)
671 if (TYPE_METHOD_BASETYPE (node))
672 print_node_brief (file, "method basetype",
673 TYPE_METHOD_BASETYPE (node), indent + 4);
674 print_node (file, "arg-types", TYPE_ARG_TYPES (node), indent + 4);
676 else if (code == OFFSET_TYPE)
677 print_node_brief (file, "basetype", TYPE_OFFSET_BASETYPE (node),
678 indent + 4);
680 if (TYPE_CONTEXT (node))
681 print_node_brief (file, "context", TYPE_CONTEXT (node), indent + 4);
683 lang_hooks.print_type (file, node, indent);
685 if (TYPE_POINTER_TO (node) || TREE_CHAIN (node))
686 indent_to (file, indent + 3);
688 print_node_brief (file, "pointer_to_this", TYPE_POINTER_TO (node),
689 indent + 4);
690 print_node_brief (file, "reference_to_this", TYPE_REFERENCE_TO (node),
691 indent + 4);
692 print_node_brief (file, "chain", TREE_CHAIN (node), indent + 4);
693 break;
695 case tcc_expression:
696 case tcc_comparison:
697 case tcc_unary:
698 case tcc_binary:
699 case tcc_reference:
700 case tcc_statement:
701 case tcc_vl_exp:
702 if (code == BIND_EXPR)
704 print_node (file, "vars", TREE_OPERAND (node, 0), indent + 4);
705 print_node (file, "body", TREE_OPERAND (node, 1), indent + 4);
706 print_node (file, "block", TREE_OPERAND (node, 2), indent + 4);
707 break;
709 if (code == CALL_EXPR)
711 call_expr_arg_iterator iter;
712 tree arg;
713 print_node (file, "fn", CALL_EXPR_FN (node), indent + 4);
714 print_node (file, "static_chain", CALL_EXPR_STATIC_CHAIN (node),
715 indent + 4);
716 i = 0;
717 FOR_EACH_CALL_EXPR_ARG (arg, iter, node)
719 char temp[10];
720 sprintf (temp, "arg %d", i);
721 print_node (file, temp, arg, indent + 4);
722 i++;
725 else
727 len = TREE_OPERAND_LENGTH (node);
729 for (i = 0; i < len; i++)
731 char temp[10];
733 sprintf (temp, "arg %d", i);
734 print_node (file, temp, TREE_OPERAND (node, i), indent + 4);
737 if (CODE_CONTAINS_STRUCT (code, TS_COMMON))
738 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
739 break;
741 case tcc_constant:
742 case tcc_exceptional:
743 switch (code)
745 case INTEGER_CST:
746 if (TREE_OVERFLOW (node))
747 fprintf (file, " overflow");
749 fprintf (file, " ");
750 if (TREE_INT_CST_HIGH (node) == 0)
751 fprintf (file, HOST_WIDE_INT_PRINT_UNSIGNED,
752 TREE_INT_CST_LOW (node));
753 else if (TREE_INT_CST_HIGH (node) == -1
754 && TREE_INT_CST_LOW (node) != 0)
755 fprintf (file, "-" HOST_WIDE_INT_PRINT_UNSIGNED,
756 -TREE_INT_CST_LOW (node));
757 else
758 fprintf (file, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
759 (unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (node),
760 (unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (node));
761 break;
763 case REAL_CST:
765 REAL_VALUE_TYPE d;
767 if (TREE_OVERFLOW (node))
768 fprintf (file, " overflow");
770 d = TREE_REAL_CST (node);
771 if (REAL_VALUE_ISINF (d))
772 fprintf (file, REAL_VALUE_NEGATIVE (d) ? " -Inf" : " Inf");
773 else if (REAL_VALUE_ISNAN (d))
774 fprintf (file, " Nan");
775 else
777 char string[64];
778 real_to_decimal (string, &d, sizeof (string), 0, 1);
779 fprintf (file, " %s", string);
782 break;
784 case FIXED_CST:
786 FIXED_VALUE_TYPE f;
787 char string[64];
789 if (TREE_OVERFLOW (node))
790 fprintf (file, " overflow");
792 f = TREE_FIXED_CST (node);
793 fixed_to_decimal (string, &f, sizeof (string));
794 fprintf (file, " %s", string);
796 break;
798 case VECTOR_CST:
800 char buf[10];
801 unsigned i;
803 for (i = 0; i < VECTOR_CST_NELTS (node); ++i)
805 sprintf (buf, "elt%u: ", i);
806 print_node (file, buf, VECTOR_CST_ELT (node, i), indent + 4);
809 break;
811 case COMPLEX_CST:
812 print_node (file, "real", TREE_REALPART (node), indent + 4);
813 print_node (file, "imag", TREE_IMAGPART (node), indent + 4);
814 break;
816 case STRING_CST:
818 const char *p = TREE_STRING_POINTER (node);
819 int i = TREE_STRING_LENGTH (node);
820 fputs (" \"", file);
821 while (--i >= 0)
823 char ch = *p++;
824 if (ch >= ' ' && ch < 127)
825 putc (ch, file);
826 else
827 fprintf (file, "\\%03o", ch & 0xFF);
829 fputc ('\"', file);
831 break;
833 case IDENTIFIER_NODE:
834 lang_hooks.print_identifier (file, node, indent);
835 break;
837 case TREE_LIST:
838 print_node (file, "purpose", TREE_PURPOSE (node), indent + 4);
839 print_node (file, "value", TREE_VALUE (node), indent + 4);
840 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
841 break;
843 case TREE_VEC:
844 len = TREE_VEC_LENGTH (node);
845 for (i = 0; i < len; i++)
846 if (TREE_VEC_ELT (node, i))
848 char temp[10];
849 sprintf (temp, "elt %d", i);
850 print_node (file, temp, TREE_VEC_ELT (node, i), indent + 4);
852 break;
854 case CONSTRUCTOR:
856 unsigned HOST_WIDE_INT cnt;
857 tree index, value;
858 len = vec_safe_length (CONSTRUCTOR_ELTS (node));
859 fprintf (file, " lngt %d", len);
860 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (node),
861 cnt, index, value)
863 print_node (file, "idx", index, indent + 4);
864 print_node (file, "val", value, indent + 4);
867 break;
869 case STATEMENT_LIST:
870 dump_addr (file, " head ", node->stmt_list.head);
871 dump_addr (file, " tail ", node->stmt_list.tail);
872 fprintf (file, " stmts");
874 tree_stmt_iterator i;
875 for (i = tsi_start (node); !tsi_end_p (i); tsi_next (&i))
877 /* Not printing the addresses of the (not-a-tree)
878 'struct tree_stmt_list_node's. */
879 dump_addr (file, " ", tsi_stmt (i));
881 fprintf (file, "\n");
882 for (i = tsi_start (node); !tsi_end_p (i); tsi_next (&i))
884 /* Not printing the addresses of the (not-a-tree)
885 'struct tree_stmt_list_node's. */
886 print_node (file, "stmt", tsi_stmt (i), indent + 4);
889 break;
891 case BLOCK:
892 print_node (file, "vars", BLOCK_VARS (node), indent + 4);
893 print_node (file, "supercontext", BLOCK_SUPERCONTEXT (node),
894 indent + 4);
895 print_node (file, "subblocks", BLOCK_SUBBLOCKS (node), indent + 4);
896 print_node (file, "chain", BLOCK_CHAIN (node), indent + 4);
897 print_node (file, "abstract_origin",
898 BLOCK_ABSTRACT_ORIGIN (node), indent + 4);
899 break;
901 case SSA_NAME:
902 print_node_brief (file, "var", SSA_NAME_VAR (node), indent + 4);
903 fprintf (file, "def_stmt ");
904 print_gimple_stmt (file, SSA_NAME_DEF_STMT (node), indent + 4, 0);
906 indent_to (file, indent + 4);
907 fprintf (file, "version %u", SSA_NAME_VERSION (node));
908 if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (node))
909 fprintf (file, " in-abnormal-phi");
910 if (SSA_NAME_IN_FREE_LIST (node))
911 fprintf (file, " in-free-list");
913 if (SSA_NAME_PTR_INFO (node))
915 indent_to (file, indent + 3);
916 if (SSA_NAME_PTR_INFO (node))
917 dump_addr (file, " ptr-info ", SSA_NAME_PTR_INFO (node));
919 break;
921 case OMP_CLAUSE:
923 int i;
924 fprintf (file, " %s",
925 omp_clause_code_name[OMP_CLAUSE_CODE (node)]);
926 for (i = 0; i < omp_clause_num_ops[OMP_CLAUSE_CODE (node)]; i++)
928 indent_to (file, indent + 4);
929 fprintf (file, "op %d:", i);
930 print_node_brief (file, "", OMP_CLAUSE_OPERAND (node, i), 0);
933 break;
935 case OPTIMIZATION_NODE:
936 cl_optimization_print (file, indent + 4, TREE_OPTIMIZATION (node));
937 break;
939 case TARGET_OPTION_NODE:
940 cl_target_option_print (file, indent + 4, TREE_TARGET_OPTION (node));
941 break;
942 case IMPORTED_DECL:
943 fprintf (file, " imported declaration");
944 print_node_brief (file, "associated declaration",
945 IMPORTED_DECL_ASSOCIATED_DECL (node),
946 indent + 4);
947 break;
949 default:
950 if (EXCEPTIONAL_CLASS_P (node))
951 lang_hooks.print_xnode (file, node, indent);
952 break;
955 break;
958 if (EXPR_HAS_LOCATION (node))
960 expanded_location xloc = expand_location (EXPR_LOCATION (node));
961 indent_to (file, indent+4);
962 fprintf (file, "%s:%d:%d", xloc.file, xloc.line, xloc.column);
965 fprintf (file, ">");
969 /* Print the node NODE on standard error, for debugging.
970 Most nodes referred to by this one are printed recursively
971 down to a depth of six. */
973 DEBUG_FUNCTION void
974 debug_tree (tree node)
976 table = XCNEWVEC (struct bucket *, HASH_SIZE);
977 print_node (stderr, "", node, 0);
978 free (table);
979 table = 0;
980 putc ('\n', stderr);
983 DEBUG_FUNCTION void
984 debug_raw (const tree_node &ref)
986 debug_tree (const_cast <tree> (&ref));
989 DEBUG_FUNCTION void
990 debug_raw (const tree_node *ptr)
992 if (ptr)
993 debug_raw (*ptr);
994 else
995 fprintf (stderr, "<nil>\n");
998 static void
999 dump_tree_via_hooks (const tree_node *ptr, int options)
1001 if (DECL_P (ptr))
1002 lang_hooks.print_decl (stderr, const_cast <tree_node*> (ptr), 0);
1003 else if (TYPE_P (ptr))
1004 lang_hooks.print_type (stderr, const_cast <tree_node*> (ptr), 0);
1005 else if (TREE_CODE (ptr) == IDENTIFIER_NODE)
1006 lang_hooks.print_identifier (stderr, const_cast <tree_node*> (ptr), 0);
1007 else
1008 print_generic_expr (stderr, const_cast <tree_node*> (ptr), options);
1009 fprintf (stderr, "\n");
1012 DEBUG_FUNCTION void
1013 debug (const tree_node &ref)
1015 dump_tree_via_hooks (&ref, 0);
1018 DEBUG_FUNCTION void
1019 debug (const tree_node *ptr)
1021 if (ptr)
1022 debug (*ptr);
1023 else
1024 fprintf (stderr, "<nil>\n");
1027 DEBUG_FUNCTION void
1028 debug_verbose (const tree_node &ref)
1030 dump_tree_via_hooks (&ref, TDF_VERBOSE);
1033 DEBUG_FUNCTION void
1034 debug_verbose (const tree_node *ptr)
1036 if (ptr)
1037 debug_verbose (*ptr);
1038 else
1039 fprintf (stderr, "<nil>\n");
1042 DEBUG_FUNCTION void
1043 debug_head (const tree_node &ref)
1045 debug (ref);
1048 DEBUG_FUNCTION void
1049 debug_head (const tree_node *ptr)
1051 if (ptr)
1052 debug_head (*ptr);
1053 else
1054 fprintf (stderr, "<nil>\n");
1057 DEBUG_FUNCTION void
1058 debug_body (const tree_node &ref)
1060 if (TREE_CODE (&ref) == FUNCTION_DECL)
1061 dump_function_to_file (const_cast <tree_node*> (&ref), stderr, 0);
1062 else
1063 debug (ref);
1066 DEBUG_FUNCTION void
1067 debug_body (const tree_node *ptr)
1069 if (ptr)
1070 debug_body (*ptr);
1071 else
1072 fprintf (stderr, "<nil>\n");
1075 /* Print the vector of trees VEC on standard error, for debugging.
1076 Most nodes referred to by this one are printed recursively
1077 down to a depth of six. */
1079 DEBUG_FUNCTION void
1080 debug_raw (vec<tree, va_gc> &ref)
1082 tree elt;
1083 unsigned ix;
1085 /* Print the slot this node is in, and its code, and address. */
1086 fprintf (stderr, "<VEC");
1087 dump_addr (stderr, " ", ref.address ());
1089 FOR_EACH_VEC_ELT (ref, ix, elt)
1091 fprintf (stderr, "elt %d ", ix);
1092 debug_raw (elt);
1096 DEBUG_FUNCTION void
1097 debug (vec<tree, va_gc> &ref)
1099 tree elt;
1100 unsigned ix;
1102 /* Print the slot this node is in, and its code, and address. */
1103 fprintf (stderr, "<VEC");
1104 dump_addr (stderr, " ", ref.address ());
1106 FOR_EACH_VEC_ELT (ref, ix, elt)
1108 fprintf (stderr, "elt %d ", ix);
1109 debug (elt);
1113 DEBUG_FUNCTION void
1114 debug (vec<tree, va_gc> *ptr)
1116 if (ptr)
1117 debug (*ptr);
1118 else
1119 fprintf (stderr, "<nil>\n");
1122 DEBUG_FUNCTION void
1123 debug_raw (vec<tree, va_gc> *ptr)
1125 if (ptr)
1126 debug_raw (*ptr);
1127 else
1128 fprintf (stderr, "<nil>\n");
1131 DEBUG_FUNCTION void
1132 debug_vec_tree (vec<tree, va_gc> *vec)
1134 debug_raw (vec);