2007-03-01 Paul Brook <paul@codesourcery.com>
[official-gcc.git] / gcc / print-tree.c
blob7eef3a386d2a2fdd0cf3e4ffb9462ac2019cc3d1
1 /* Prints out tree in human readable form - GCC
2 Copyright (C) 1990, 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
20 02110-1301, USA. */
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "tm.h"
27 #include "tree.h"
28 #include "real.h"
29 #include "ggc.h"
30 #include "langhooks.h"
31 #include "tree-iterator.h"
33 /* Define the hash table of nodes already seen.
34 Such nodes are not repeated; brief cross-references are used. */
36 #define HASH_SIZE 37
38 struct bucket
40 tree node;
41 struct bucket *next;
44 static struct bucket **table;
46 /* Print the node NODE on standard error, for debugging.
47 Most nodes referred to by this one are printed recursively
48 down to a depth of six. */
50 void
51 debug_tree (tree node)
53 table = XCNEWVEC (struct bucket *, HASH_SIZE);
54 print_node (stderr, "", node, 0);
55 free (table);
56 table = 0;
57 putc ('\n', stderr);
60 /* Print PREFIX and ADDR to FILE. */
61 void
62 dump_addr (FILE *file, const char *prefix, void *addr)
64 if (flag_dump_noaddr || flag_dump_unnumbered)
65 fprintf (file, "%s#", prefix);
66 else
67 fprintf (file, "%s%p", prefix, addr);
70 /* Print a node in brief fashion, with just the code, address and name. */
72 void
73 print_node_brief (FILE *file, const char *prefix, tree node, int indent)
75 enum tree_code_class class;
77 if (node == 0)
78 return;
80 class = TREE_CODE_CLASS (TREE_CODE (node));
82 /* Always print the slot this node is in, and its code, address and
83 name if any. */
84 if (indent > 0)
85 fprintf (file, " ");
86 fprintf (file, "%s <%s", prefix, tree_code_name[(int) TREE_CODE (node)]);
87 dump_addr (file, " ", node);
89 if (class == tcc_declaration)
91 if (DECL_NAME (node))
92 fprintf (file, " %s", IDENTIFIER_POINTER (DECL_NAME (node)));
93 else if (TREE_CODE (node) == LABEL_DECL
94 && LABEL_DECL_UID (node) != -1)
95 fprintf (file, " L." HOST_WIDE_INT_PRINT_DEC, LABEL_DECL_UID (node));
96 else
97 fprintf (file, " %c.%u", TREE_CODE (node) == CONST_DECL ? 'C' : 'D',
98 DECL_UID (node));
100 else if (class == 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))));
112 if (TREE_CODE (node) == IDENTIFIER_NODE)
113 fprintf (file, " %s", IDENTIFIER_POINTER (node));
115 /* We might as well always print the value of an integer or real. */
116 if (TREE_CODE (node) == INTEGER_CST)
118 if (TREE_OVERFLOW (node))
119 fprintf (file, " overflow");
121 fprintf (file, " ");
122 if (TREE_INT_CST_HIGH (node) == 0)
123 fprintf (file, HOST_WIDE_INT_PRINT_UNSIGNED, TREE_INT_CST_LOW (node));
124 else if (TREE_INT_CST_HIGH (node) == -1
125 && TREE_INT_CST_LOW (node) != 0)
126 fprintf (file, "-" HOST_WIDE_INT_PRINT_UNSIGNED,
127 -TREE_INT_CST_LOW (node));
128 else
129 fprintf (file, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
130 TREE_INT_CST_HIGH (node), TREE_INT_CST_LOW (node));
132 if (TREE_CODE (node) == REAL_CST)
134 REAL_VALUE_TYPE d;
136 if (TREE_OVERFLOW (node))
137 fprintf (file, " overflow");
139 d = TREE_REAL_CST (node);
140 if (REAL_VALUE_ISINF (d))
141 fprintf (file, REAL_VALUE_NEGATIVE (d) ? " -Inf" : " Inf");
142 else if (REAL_VALUE_ISNAN (d))
143 fprintf (file, " Nan");
144 else
146 char string[60];
147 real_to_decimal (string, &d, sizeof (string), 0, 1);
148 fprintf (file, " %s", string);
152 fprintf (file, ">");
155 void
156 indent_to (FILE *file, int column)
158 int i;
160 /* Since this is the long way, indent to desired column. */
161 if (column > 0)
162 fprintf (file, "\n");
163 for (i = 0; i < column; i++)
164 fprintf (file, " ");
167 /* Print the node NODE in full on file FILE, preceded by PREFIX,
168 starting in column INDENT. */
170 void
171 print_node (FILE *file, const char *prefix, tree node, int indent)
173 int hash;
174 struct bucket *b;
175 enum machine_mode mode;
176 enum tree_code_class class;
177 int len;
178 int i;
179 expanded_location xloc;
180 enum tree_code code;
182 if (node == 0)
183 return;
185 code = TREE_CODE (node);
186 class = TREE_CODE_CLASS (code);
188 /* Don't get too deep in nesting. If the user wants to see deeper,
189 it is easy to use the address of a lowest-level node
190 as an argument in another call to debug_tree. */
192 if (indent > 24)
194 print_node_brief (file, prefix, node, indent);
195 return;
198 if (indent > 8 && (class == tcc_type || class == tcc_declaration))
200 print_node_brief (file, prefix, node, indent);
201 return;
204 /* It is unsafe to look at any other fields of an ERROR_MARK node. */
205 if (TREE_CODE (node) == ERROR_MARK)
207 print_node_brief (file, prefix, node, indent);
208 return;
211 hash = ((unsigned long) node) % HASH_SIZE;
213 /* If node is in the table, just mention its address. */
214 for (b = table[hash]; b; b = b->next)
215 if (b->node == node)
217 print_node_brief (file, prefix, node, indent);
218 return;
221 /* Add this node to the table. */
222 b = XNEW (struct bucket);
223 b->node = node;
224 b->next = table[hash];
225 table[hash] = b;
227 /* Indent to the specified column, since this is the long form. */
228 indent_to (file, indent);
230 /* Print the slot this node is in, and its code, and address. */
231 fprintf (file, "%s <%s", prefix, tree_code_name[(int) TREE_CODE (node)]);
232 dump_addr (file, " ", node);
234 /* Print the name, if any. */
235 if (class == tcc_declaration)
237 if (DECL_NAME (node))
238 fprintf (file, " %s", IDENTIFIER_POINTER (DECL_NAME (node)));
239 else if (TREE_CODE (node) == LABEL_DECL
240 && LABEL_DECL_UID (node) != -1)
241 fprintf (file, " L." HOST_WIDE_INT_PRINT_DEC, LABEL_DECL_UID (node));
242 else
243 fprintf (file, " %c.%u", TREE_CODE (node) == CONST_DECL ? 'C' : 'D',
244 DECL_UID (node));
246 else if (class == tcc_type)
248 if (TYPE_NAME (node))
250 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
251 fprintf (file, " %s", IDENTIFIER_POINTER (TYPE_NAME (node)));
252 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
253 && DECL_NAME (TYPE_NAME (node)))
254 fprintf (file, " %s",
255 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node))));
258 if (TREE_CODE (node) == IDENTIFIER_NODE)
259 fprintf (file, " %s", IDENTIFIER_POINTER (node));
261 if (TREE_CODE (node) == INTEGER_CST)
263 if (indent <= 4)
264 print_node_brief (file, "type", TREE_TYPE (node), indent + 4);
266 else if (!GIMPLE_TUPLE_P (node))
268 print_node (file, "type", TREE_TYPE (node), indent + 4);
269 if (TREE_TYPE (node))
270 indent_to (file, indent + 3);
273 if (!TYPE_P (node) && TREE_SIDE_EFFECTS (node))
274 fputs (" side-effects", file);
276 if (TYPE_P (node) ? TYPE_READONLY (node) : TREE_READONLY (node))
277 fputs (" readonly", file);
278 if (!TYPE_P (node) && TREE_CONSTANT (node))
279 fputs (" constant", file);
280 else if (TYPE_P (node) && TYPE_SIZES_GIMPLIFIED (node))
281 fputs (" sizes-gimplified", file);
283 if (TREE_INVARIANT (node))
284 fputs (" invariant", file);
285 if (TREE_ADDRESSABLE (node))
286 fputs (" addressable", file);
287 if (TREE_THIS_VOLATILE (node))
288 fputs (" volatile", file);
289 if (TREE_ASM_WRITTEN (node))
290 fputs (" asm_written", file);
291 if (TREE_USED (node))
292 fputs (" used", file);
293 if (TREE_NOTHROW (node))
294 fputs (TYPE_P (node) ? " align-ok" : " nothrow", file);
295 if (TREE_PUBLIC (node))
296 fputs (" public", file);
297 if (TREE_PRIVATE (node))
298 fputs (" private", file);
299 if (TREE_PROTECTED (node))
300 fputs (" protected", file);
301 if (TREE_STATIC (node))
302 fputs (" static", file);
303 if (TREE_DEPRECATED (node))
304 fputs (" deprecated", file);
305 if (TREE_VISITED (node))
306 fputs (" visited", file);
307 if (TREE_LANG_FLAG_0 (node))
308 fputs (" tree_0", file);
309 if (TREE_LANG_FLAG_1 (node))
310 fputs (" tree_1", file);
311 if (TREE_LANG_FLAG_2 (node))
312 fputs (" tree_2", file);
313 if (TREE_LANG_FLAG_3 (node))
314 fputs (" tree_3", file);
315 if (TREE_LANG_FLAG_4 (node))
316 fputs (" tree_4", file);
317 if (TREE_LANG_FLAG_5 (node))
318 fputs (" tree_5", file);
319 if (TREE_LANG_FLAG_6 (node))
320 fputs (" tree_6", file);
322 /* DECL_ nodes have additional attributes. */
324 switch (TREE_CODE_CLASS (TREE_CODE (node)))
326 case tcc_declaration:
327 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
329 if (DECL_UNSIGNED (node))
330 fputs (" unsigned", file);
331 if (DECL_IGNORED_P (node))
332 fputs (" ignored", file);
333 if (DECL_ABSTRACT (node))
334 fputs (" abstract", file);
335 if (DECL_EXTERNAL (node))
336 fputs (" external", file);
337 if (DECL_NONLOCAL (node))
338 fputs (" nonlocal", file);
340 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
342 if (DECL_WEAK (node))
343 fputs (" weak", file);
344 if (DECL_IN_SYSTEM_HEADER (node))
345 fputs (" in_system_header", file);
347 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WRTL)
348 && TREE_CODE (node) != LABEL_DECL
349 && TREE_CODE (node) != FUNCTION_DECL
350 && DECL_REGISTER (node))
351 fputs (" regdecl", file);
353 if (TREE_CODE (node) == TYPE_DECL && TYPE_DECL_SUPPRESS_DEBUG (node))
354 fputs (" suppress-debug", file);
356 if (TREE_CODE (node) == FUNCTION_DECL && DECL_INLINE (node))
357 fputs (DECL_DECLARED_INLINE_P (node) ? " inline" : " autoinline", file);
358 if (TREE_CODE (node) == FUNCTION_DECL && DECL_BUILT_IN (node))
359 fputs (" built-in", file);
360 if (TREE_CODE (node) == FUNCTION_DECL && DECL_NO_STATIC_CHAIN (node))
361 fputs (" no-static-chain", file);
363 if (TREE_CODE (node) == FIELD_DECL && DECL_PACKED (node))
364 fputs (" packed", file);
365 if (TREE_CODE (node) == FIELD_DECL && DECL_BIT_FIELD (node))
366 fputs (" bit-field", file);
367 if (TREE_CODE (node) == FIELD_DECL && DECL_NONADDRESSABLE_P (node))
368 fputs (" nonaddressable", file);
370 if (TREE_CODE (node) == LABEL_DECL && DECL_ERROR_ISSUED (node))
371 fputs (" error-issued", file);
373 if (TREE_CODE (node) == VAR_DECL && DECL_IN_TEXT_SECTION (node))
374 fputs (" in-text-section", file);
375 if (TREE_CODE (node) == VAR_DECL && DECL_COMMON (node))
376 fputs (" common", file);
377 if (TREE_CODE (node) == VAR_DECL && DECL_THREAD_LOCAL_P (node))
379 enum tls_model kind = DECL_TLS_MODEL (node);
380 switch (kind)
382 case TLS_MODEL_GLOBAL_DYNAMIC:
383 fputs (" tls-global-dynamic", file);
384 break;
385 case TLS_MODEL_LOCAL_DYNAMIC:
386 fputs (" tls-local-dynamic", file);
387 break;
388 case TLS_MODEL_INITIAL_EXEC:
389 fputs (" tls-initial-exec", file);
390 break;
391 case TLS_MODEL_LOCAL_EXEC:
392 fputs (" tls-local-exec", file);
393 break;
394 default:
395 gcc_unreachable ();
399 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
401 if (DECL_VIRTUAL_P (node))
402 fputs (" virtual", file);
403 if (DECL_PRESERVE_P (node))
404 fputs (" preserve", file);
405 if (DECL_LANG_FLAG_0 (node))
406 fputs (" decl_0", file);
407 if (DECL_LANG_FLAG_1 (node))
408 fputs (" decl_1", file);
409 if (DECL_LANG_FLAG_2 (node))
410 fputs (" decl_2", file);
411 if (DECL_LANG_FLAG_3 (node))
412 fputs (" decl_3", file);
413 if (DECL_LANG_FLAG_4 (node))
414 fputs (" decl_4", file);
415 if (DECL_LANG_FLAG_5 (node))
416 fputs (" decl_5", file);
417 if (DECL_LANG_FLAG_6 (node))
418 fputs (" decl_6", file);
419 if (DECL_LANG_FLAG_7 (node))
420 fputs (" decl_7", file);
422 mode = DECL_MODE (node);
423 fprintf (file, " %s", GET_MODE_NAME (mode));
426 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS) && DECL_DEFER_OUTPUT (node))
427 fputs (" defer-output", file);
430 xloc = expand_location (DECL_SOURCE_LOCATION (node));
431 fprintf (file, " file %s line %d", xloc.file, xloc.line);
433 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
435 print_node (file, "size", DECL_SIZE (node), indent + 4);
436 print_node (file, "unit size", DECL_SIZE_UNIT (node), indent + 4);
438 if (TREE_CODE (node) != FUNCTION_DECL
439 || DECL_INLINE (node) || DECL_BUILT_IN (node))
440 indent_to (file, indent + 3);
442 if (TREE_CODE (node) != FUNCTION_DECL)
444 if (DECL_USER_ALIGN (node))
445 fprintf (file, " user");
447 fprintf (file, " align %d", DECL_ALIGN (node));
448 if (TREE_CODE (node) == FIELD_DECL)
449 fprintf (file, " offset_align " HOST_WIDE_INT_PRINT_UNSIGNED,
450 DECL_OFFSET_ALIGN (node));
452 else if (DECL_BUILT_IN (node))
454 if (DECL_BUILT_IN_CLASS (node) == BUILT_IN_MD)
455 fprintf (file, " built-in BUILT_IN_MD %d", DECL_FUNCTION_CODE (node));
456 else
457 fprintf (file, " built-in %s:%s",
458 built_in_class_names[(int) DECL_BUILT_IN_CLASS (node)],
459 built_in_names[(int) DECL_FUNCTION_CODE (node)]);
462 if (DECL_POINTER_ALIAS_SET_KNOWN_P (node))
463 fprintf (file, " alias set " HOST_WIDE_INT_PRINT_DEC,
464 DECL_POINTER_ALIAS_SET (node));
466 if (TREE_CODE (node) == FIELD_DECL)
468 print_node (file, "offset", DECL_FIELD_OFFSET (node), indent + 4);
469 print_node (file, "bit offset", DECL_FIELD_BIT_OFFSET (node),
470 indent + 4);
471 if (DECL_BIT_FIELD_TYPE (node))
472 print_node (file, "bit_field_type", DECL_BIT_FIELD_TYPE (node),
473 indent + 4);
476 print_node_brief (file, "context", DECL_CONTEXT (node), indent + 4);
478 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
480 print_node_brief (file, "attributes",
481 DECL_ATTRIBUTES (node), indent + 4);
482 print_node_brief (file, "initial", DECL_INITIAL (node), indent + 4);
484 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WRTL))
486 print_node_brief (file, "abstract_origin",
487 DECL_ABSTRACT_ORIGIN (node), indent + 4);
489 if (CODE_CONTAINS_STRUCT (code, TS_DECL_NON_COMMON))
491 print_node (file, "arguments", DECL_ARGUMENT_FLD (node), indent + 4);
492 print_node (file, "result", DECL_RESULT_FLD (node), indent + 4);
495 lang_hooks.print_decl (file, node, indent);
497 if (DECL_RTL_SET_P (node))
499 indent_to (file, indent + 4);
500 print_rtl (file, DECL_RTL (node));
503 if (TREE_CODE (node) == PARM_DECL)
505 print_node (file, "arg-type", DECL_ARG_TYPE (node), indent + 4);
507 if (DECL_INCOMING_RTL (node) != 0)
509 indent_to (file, indent + 4);
510 fprintf (file, "incoming-rtl ");
511 print_rtl (file, DECL_INCOMING_RTL (node));
514 else if (TREE_CODE (node) == FUNCTION_DECL
515 && DECL_STRUCT_FUNCTION (node) != 0)
517 indent_to (file, indent + 4);
518 dump_addr (file, "saved-insns ", DECL_STRUCT_FUNCTION (node));
521 if ((TREE_CODE (node) == VAR_DECL || TREE_CODE (node) == PARM_DECL)
522 && DECL_HAS_VALUE_EXPR_P (node))
523 print_node (file, "value-expr", DECL_VALUE_EXPR (node), indent + 4);
525 if (TREE_CODE (node) == STRUCT_FIELD_TAG)
527 fprintf (file, " sft size " HOST_WIDE_INT_PRINT_DEC,
528 SFT_SIZE (node));
529 fprintf (file, " sft offset " HOST_WIDE_INT_PRINT_DEC,
530 SFT_OFFSET (node));
531 print_node_brief (file, "parent var", SFT_PARENT_VAR (node),
532 indent + 4);
534 /* Print the decl chain only if decl is at second level. */
535 if (indent == 4)
536 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
537 else
538 print_node_brief (file, "chain", TREE_CHAIN (node), indent + 4);
539 break;
541 case tcc_type:
542 if (TYPE_UNSIGNED (node))
543 fputs (" unsigned", file);
545 /* The no-force-blk flag is used for different things in
546 different types. */
547 if ((TREE_CODE (node) == RECORD_TYPE
548 || TREE_CODE (node) == UNION_TYPE
549 || TREE_CODE (node) == QUAL_UNION_TYPE)
550 && TYPE_NO_FORCE_BLK (node))
551 fputs (" no-force-blk", file);
552 else if (TREE_CODE (node) == INTEGER_TYPE
553 && TYPE_IS_SIZETYPE (node))
554 fputs (" sizetype", file);
555 else if (TREE_CODE (node) == FUNCTION_TYPE
556 && TYPE_RETURNS_STACK_DEPRESSED (node))
557 fputs (" returns-stack-depressed", file);
559 if (TYPE_STRING_FLAG (node))
560 fputs (" string-flag", file);
561 if (TYPE_NEEDS_CONSTRUCTING (node))
562 fputs (" needs-constructing", file);
564 /* The transparent-union flag is used for different things in
565 different nodes. */
566 if (TREE_CODE (node) == UNION_TYPE && TYPE_TRANSPARENT_UNION (node))
567 fputs (" transparent-union", file);
568 else if (TREE_CODE (node) == ARRAY_TYPE
569 && TYPE_NONALIASED_COMPONENT (node))
570 fputs (" nonaliased-component", file);
572 if (TYPE_PACKED (node))
573 fputs (" packed", file);
575 if (TYPE_RESTRICT (node))
576 fputs (" restrict", file);
578 if (TYPE_LANG_FLAG_0 (node))
579 fputs (" type_0", file);
580 if (TYPE_LANG_FLAG_1 (node))
581 fputs (" type_1", file);
582 if (TYPE_LANG_FLAG_2 (node))
583 fputs (" type_2", file);
584 if (TYPE_LANG_FLAG_3 (node))
585 fputs (" type_3", file);
586 if (TYPE_LANG_FLAG_4 (node))
587 fputs (" type_4", file);
588 if (TYPE_LANG_FLAG_5 (node))
589 fputs (" type_5", file);
590 if (TYPE_LANG_FLAG_6 (node))
591 fputs (" type_6", file);
593 mode = TYPE_MODE (node);
594 fprintf (file, " %s", GET_MODE_NAME (mode));
596 print_node (file, "size", TYPE_SIZE (node), indent + 4);
597 print_node (file, "unit size", TYPE_SIZE_UNIT (node), indent + 4);
598 indent_to (file, indent + 3);
600 if (TYPE_USER_ALIGN (node))
601 fprintf (file, " user");
603 fprintf (file, " align %d symtab %d alias set " HOST_WIDE_INT_PRINT_DEC,
604 TYPE_ALIGN (node), TYPE_SYMTAB_ADDRESS (node),
605 TYPE_ALIAS_SET (node));
607 if (TYPE_STRUCTURAL_EQUALITY_P (node))
608 fprintf (file, " structural equality");
609 else
610 dump_addr (file, " canonical type ", TYPE_CANONICAL (node));
612 print_node (file, "attributes", TYPE_ATTRIBUTES (node), indent + 4);
614 if (INTEGRAL_TYPE_P (node) || TREE_CODE (node) == REAL_TYPE)
616 fprintf (file, " precision %d", TYPE_PRECISION (node));
617 print_node_brief (file, "min", TYPE_MIN_VALUE (node), indent + 4);
618 print_node_brief (file, "max", TYPE_MAX_VALUE (node), indent + 4);
621 if (TREE_CODE (node) == ENUMERAL_TYPE)
622 print_node (file, "values", TYPE_VALUES (node), indent + 4);
623 else if (TREE_CODE (node) == ARRAY_TYPE)
624 print_node (file, "domain", TYPE_DOMAIN (node), indent + 4);
625 else if (TREE_CODE (node) == VECTOR_TYPE)
626 fprintf (file, " nunits %d", (int) TYPE_VECTOR_SUBPARTS (node));
627 else if (TREE_CODE (node) == RECORD_TYPE
628 || TREE_CODE (node) == UNION_TYPE
629 || TREE_CODE (node) == QUAL_UNION_TYPE)
630 print_node (file, "fields", TYPE_FIELDS (node), indent + 4);
631 else if (TREE_CODE (node) == FUNCTION_TYPE
632 || TREE_CODE (node) == METHOD_TYPE)
634 if (TYPE_METHOD_BASETYPE (node))
635 print_node_brief (file, "method basetype",
636 TYPE_METHOD_BASETYPE (node), indent + 4);
637 print_node (file, "arg-types", TYPE_ARG_TYPES (node), indent + 4);
639 else if (TREE_CODE (node) == OFFSET_TYPE)
640 print_node_brief (file, "basetype", TYPE_OFFSET_BASETYPE (node),
641 indent + 4);
643 if (TYPE_CONTEXT (node))
644 print_node_brief (file, "context", TYPE_CONTEXT (node), indent + 4);
646 lang_hooks.print_type (file, node, indent);
648 if (TYPE_POINTER_TO (node) || TREE_CHAIN (node))
649 indent_to (file, indent + 3);
651 print_node_brief (file, "pointer_to_this", TYPE_POINTER_TO (node),
652 indent + 4);
653 print_node_brief (file, "reference_to_this", TYPE_REFERENCE_TO (node),
654 indent + 4);
655 print_node_brief (file, "chain", TREE_CHAIN (node), indent + 4);
656 break;
658 case tcc_expression:
659 case tcc_comparison:
660 case tcc_unary:
661 case tcc_binary:
662 case tcc_reference:
663 case tcc_statement:
664 case tcc_vl_exp:
665 if (TREE_CODE (node) == BIT_FIELD_REF && BIT_FIELD_REF_UNSIGNED (node))
666 fputs (" unsigned", file);
667 if (TREE_CODE (node) == BIND_EXPR)
669 print_node (file, "vars", TREE_OPERAND (node, 0), indent + 4);
670 print_node (file, "body", TREE_OPERAND (node, 1), indent + 4);
671 print_node (file, "block", TREE_OPERAND (node, 2), indent + 4);
672 break;
674 if (TREE_CODE (node) == CALL_EXPR)
676 call_expr_arg_iterator iter;
677 tree arg;
678 print_node (file, "fn", CALL_EXPR_FN (node), indent + 4);
679 print_node (file, "static_chain", CALL_EXPR_STATIC_CHAIN (node),
680 indent + 4);
681 i = 0;
682 FOR_EACH_CALL_EXPR_ARG (arg, iter, node)
684 char temp[10];
685 sprintf (temp, "arg %d", i);
686 print_node (file, temp, arg, indent + 4);
687 i++;
690 else
692 len = TREE_OPERAND_LENGTH (node);
694 for (i = 0; i < len; i++)
696 char temp[10];
698 sprintf (temp, "arg %d", i);
699 print_node (file, temp, TREE_OPERAND (node, i), indent + 4);
702 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
703 break;
705 case tcc_gimple_stmt:
706 len = TREE_CODE_LENGTH (TREE_CODE (node));
708 for (i = 0; i < len; i++)
710 char temp[10];
712 sprintf (temp, "arg %d", i);
713 print_node (file, temp, GIMPLE_STMT_OPERAND (node, i), indent + 4);
715 break;
717 case tcc_constant:
718 case tcc_exceptional:
719 switch (TREE_CODE (node))
721 case INTEGER_CST:
722 if (TREE_OVERFLOW (node))
723 fprintf (file, " overflow");
725 fprintf (file, " ");
726 if (TREE_INT_CST_HIGH (node) == 0)
727 fprintf (file, HOST_WIDE_INT_PRINT_UNSIGNED,
728 TREE_INT_CST_LOW (node));
729 else if (TREE_INT_CST_HIGH (node) == -1
730 && TREE_INT_CST_LOW (node) != 0)
731 fprintf (file, "-" HOST_WIDE_INT_PRINT_UNSIGNED,
732 -TREE_INT_CST_LOW (node));
733 else
734 fprintf (file, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
735 TREE_INT_CST_HIGH (node), TREE_INT_CST_LOW (node));
736 break;
738 case REAL_CST:
740 REAL_VALUE_TYPE d;
742 if (TREE_OVERFLOW (node))
743 fprintf (file, " overflow");
745 d = TREE_REAL_CST (node);
746 if (REAL_VALUE_ISINF (d))
747 fprintf (file, REAL_VALUE_NEGATIVE (d) ? " -Inf" : " Inf");
748 else if (REAL_VALUE_ISNAN (d))
749 fprintf (file, " Nan");
750 else
752 char string[64];
753 real_to_decimal (string, &d, sizeof (string), 0, 1);
754 fprintf (file, " %s", string);
757 break;
759 case VECTOR_CST:
761 tree vals = TREE_VECTOR_CST_ELTS (node);
762 char buf[10];
763 tree link;
764 int i;
766 i = 0;
767 for (link = vals; link; link = TREE_CHAIN (link), ++i)
769 sprintf (buf, "elt%d: ", i);
770 print_node (file, buf, TREE_VALUE (link), 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 /* Print the chain at second level. */
796 if (indent == 4)
797 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
798 else
799 print_node_brief (file, "chain", TREE_CHAIN (node), indent + 4);
800 break;
802 case IDENTIFIER_NODE:
803 lang_hooks.print_identifier (file, node, indent);
804 break;
806 case TREE_LIST:
807 print_node (file, "purpose", TREE_PURPOSE (node), indent + 4);
808 print_node (file, "value", TREE_VALUE (node), indent + 4);
809 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
810 break;
812 case TREE_VEC:
813 len = TREE_VEC_LENGTH (node);
814 for (i = 0; i < len; i++)
815 if (TREE_VEC_ELT (node, i))
817 char temp[10];
818 sprintf (temp, "elt %d", i);
819 indent_to (file, indent + 4);
820 print_node_brief (file, temp, TREE_VEC_ELT (node, i), 0);
822 break;
824 case STATEMENT_LIST:
825 dump_addr (file, " head ", node->stmt_list.head);
826 dump_addr (file, " tail ", node->stmt_list.tail);
827 fprintf (file, " stmts");
829 tree_stmt_iterator i;
830 for (i = tsi_start (node); !tsi_end_p (i); tsi_next (&i))
832 /* Not printing the addresses of the (not-a-tree)
833 'struct tree_stmt_list_node's. */
834 dump_addr (file, " ", tsi_stmt (i));
836 fprintf (file, "\n");
837 for (i = tsi_start (node); !tsi_end_p (i); tsi_next (&i))
839 /* Not printing the addresses of the (not-a-tree)
840 'struct tree_stmt_list_node's. */
841 print_node (file, "stmt", tsi_stmt (i), indent + 4);
844 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
845 break;
847 case BLOCK:
848 print_node (file, "vars", BLOCK_VARS (node), indent + 4);
849 print_node (file, "supercontext", BLOCK_SUPERCONTEXT (node),
850 indent + 4);
851 print_node (file, "subblocks", BLOCK_SUBBLOCKS (node), indent + 4);
852 print_node (file, "chain", BLOCK_CHAIN (node), indent + 4);
853 print_node (file, "abstract_origin",
854 BLOCK_ABSTRACT_ORIGIN (node), indent + 4);
855 break;
857 case SSA_NAME:
858 print_node_brief (file, "var", SSA_NAME_VAR (node), indent + 4);
859 print_node_brief (file, "def_stmt",
860 SSA_NAME_DEF_STMT (node), indent + 4);
862 indent_to (file, indent + 4);
863 fprintf (file, "version %u", SSA_NAME_VERSION (node));
864 if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (node))
865 fprintf (file, " in-abnormal-phi");
866 if (SSA_NAME_IN_FREE_LIST (node))
867 fprintf (file, " in-free-list");
869 if (SSA_NAME_PTR_INFO (node)
870 || SSA_NAME_VALUE (node))
872 indent_to (file, indent + 3);
873 if (SSA_NAME_PTR_INFO (node))
874 dump_addr (file, " ptr-info ", SSA_NAME_PTR_INFO (node));
875 if (SSA_NAME_VALUE (node))
876 dump_addr (file, " value ", SSA_NAME_VALUE (node));
878 break;
880 case OMP_CLAUSE:
882 int i;
883 fprintf (file, " %s",
884 omp_clause_code_name[OMP_CLAUSE_CODE (node)]);
885 for (i = 0; i < omp_clause_num_ops[OMP_CLAUSE_CODE (node)]; i++)
887 indent_to (file, indent + 4);
888 fprintf (file, "op %d:", i);
889 print_node_brief (file, "", OMP_CLAUSE_OPERAND (node, i), 0);
892 break;
894 default:
895 if (EXCEPTIONAL_CLASS_P (node))
896 lang_hooks.print_xnode (file, node, indent);
897 break;
900 break;
903 if (EXPR_HAS_LOCATION (node))
905 expanded_location xloc = expand_location (EXPR_LOCATION (node));
906 indent_to (file, indent+4);
907 fprintf (file, "%s:%d", xloc.file, xloc.line);
910 fprintf (file, ">");