1 /* Prints out tree in human readable form - GNU C-compiler
2 Copyright (C) 1987 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 1, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
25 extern char **tree_code_name
;
27 extern char *mode_name
[];
31 #define MIN(x,y) ((x < y) ? x : y)
35 extern int tree_node_counter
;
37 /* markvec[i] is 1 if node number i has been seen already. */
45 debug_dump_tree (root
)
48 dump_tree (stderr
, root
);
52 dump_tree (outf
, root
)
56 markvec
= (char *) alloca (tree_node_counter
+ 1);
57 bzero (markvec
, tree_node_counter
+ 1);
70 fputs ("<>", outfile
);
72 fprintf (outfile
, "%1d", TREE_UID (node
));
82 fprintf (outfile
, " %s = ", title
);
87 /* Similar to `part' but prefix with @ if value is not constant
88 and print the constant value if it is constant. */
91 cpart (title
, ct
, punct
)
96 fprintf (outfile
, " %s = ", title
);
98 fputs ("<>", outfile
);
101 if (!TREE_LITERAL (ct
))
107 fprintf (outfile
, "%ld", TREE_INT_CST_LOW (ct
));
109 putc (punct
, outfile
);
113 walk (node
, leaf
, indent
)
119 /* Don't walk any global nodes reached from local nodes!
120 The global nodes will be dumped at the end, all together.
121 Also don't mention a FUNCTION_DECL node that is marked local
122 since it was fully described when it was dumped locally. */
123 && (TREE_CODE (node
) != FUNCTION_DECL
124 || TREE_PERMANENT (node
))
125 && (TREE_PERMANENT (leaf
) == TREE_PERMANENT (node
)))
126 dump (node
, indent
+1);
130 cwalk (s
, leaf
, indent
)
136 if (!TREE_LITERAL (s
))
137 walk (s
, leaf
, indent
);
146 part ("type", TREE_TYPE (node
));
148 fputs (" [", outfile
);
149 if (TREE_EXTERNAL (node
))
151 if (!first
) putc (' ', outfile
);
152 fputs ("external", outfile
);
155 if (TREE_PUBLIC (node
))
157 if (!first
) putc (' ', outfile
);
158 fputs ("public", outfile
);
161 if (TREE_STATIC (node
))
163 if (!first
) putc (' ', outfile
);
164 fputs ("static", outfile
);
167 if (TREE_VOLATILE (node
))
169 if (!first
) putc (' ', outfile
);
170 fputs ("volatile", outfile
);
173 if (TREE_PACKED (node
))
175 if (!first
) putc (' ', outfile
);
176 fputs ("packed", outfile
);
179 if (TREE_READONLY (node
))
181 if (!first
) putc (' ', outfile
);
182 fputs ("readonly", outfile
);
185 if (TREE_LITERAL (node
))
187 if (!first
) putc (' ', outfile
);
188 fputs ("literal", outfile
);
191 if (TREE_NONLOCAL (node
))
193 if (!first
) putc (' ', outfile
);
194 fputs ("nonlocal", outfile
);
197 if (TREE_ADDRESSABLE (node
))
199 if (!first
) putc (' ', outfile
);
200 fputs ("addressable", outfile
);
203 if (TREE_REGDECL (node
))
205 if (!first
) putc (' ', outfile
);
206 fputs ("regdecl", outfile
);
209 if (TREE_THIS_VOLATILE (node
))
211 if (!first
) putc (' ', outfile
);
212 fputs ("this_vol", outfile
);
215 if (TREE_UNSIGNED (node
))
217 if (!first
) putc (' ', outfile
);
218 fputs ("unsigned", outfile
);
221 if (TREE_ASM_WRITTEN (node
))
223 if (!first
) putc (' ', outfile
);
224 fputs ("asm_written", outfile
);
227 if (TREE_INLINE (node
))
229 if (!first
) putc (' ', outfile
);
230 fputs ("inline", outfile
);
233 if (TREE_USED (node
))
235 if (!first
) putc (' ', outfile
);
236 fputs ("used", outfile
);
239 if (TREE_PERMANENT (node
))
241 if (!first
) putc (' ', outfile
);
242 fputs ("permanent", outfile
);
245 if (TREE_LANG_FLAG_1 (node
))
247 if (!first
) putc (' ', outfile
);
248 fputs ("lang_flag_1", outfile
);
251 if (TREE_LANG_FLAG_2 (node
))
253 if (!first
) putc (' ', outfile
);
254 fputs ("lang_flag_2", outfile
);
257 if (TREE_LANG_FLAG_3 (node
))
259 if (!first
) putc (' ', outfile
);
260 fputs ("lang_flag_3", outfile
);
263 if (TREE_LANG_FLAG_4 (node
))
265 if (!first
) putc (' ', outfile
);
266 fputs ("lang_flag_4", outfile
);
269 fputs ("] ", outfile
);
273 prdeclmodeinfo (node
)
276 register enum machine_mode mode
= DECL_MODE (node
);
277 fprintf (outfile
, " %s;", mode_name
[(int) mode
]);
279 cpart ("size", DECL_SIZE (node
), '*');
280 fprintf (outfile
, "%d;", DECL_SIZE_UNIT (node
));
282 fprintf (outfile
, " alignment = %1d;", DECL_ALIGN (node
));
286 prtypemodeinfo (node
)
289 register enum machine_mode mode
= TYPE_MODE (node
);
290 fprintf (outfile
, " %s;", mode_name
[(int) mode
]);
292 cpart ("size", TYPE_SIZE (node
), '*');
293 fprintf (outfile
, "%d;", TYPE_SIZE_UNIT (node
));
295 fprintf (outfile
, " alignment = %1d;", TYPE_ALIGN (node
));
303 fputs (spaces
+ (strlen (spaces
) - (12 + MIN (40,(indent
+1)*2))), outfile
);
306 /* Output a description of the tree node NODE
307 if its description has not been output already. */
315 register enum tree_code code
= TREE_CODE (node
);
317 register int len
, first_rtl
;
320 if (markvec
[TREE_UID (node
)])
322 markvec
[TREE_UID (node
)] = 1;
324 fputs (" ", outfile
);
325 fprintf (outfile
, "%5d", TREE_UID (node
));
326 fputs (spaces
+ (strlen (spaces
) - MIN (40, (indent
+1)*2)), outfile
);
327 fputs (tree_code_name
[(int) code
], outfile
);
329 switch (*tree_code_type
[(int) code
])
332 fputs (" name = ", outfile
);
333 if (DECL_NAME (node
) == NULL
)
334 fputs ("<>;", outfile
);
336 fprintf (outfile
, "%s;",
337 IDENTIFIER_POINTER (DECL_NAME (node
)));
338 if (code
!= PARM_DECL
)
339 fprintf (outfile
, " at %s line %d;",
340 DECL_SOURCE_FILE (node
), DECL_SOURCE_LINE (node
));
342 prdeclmodeinfo (node
);
344 #ifdef PRINT_LANG_DECL
345 print_lang_decl (node
);
348 fprintf (outfile
, " offset = %1d;", DECL_OFFSET (node
));
349 if (DECL_VOFFSET (node
) != NULL
)
351 fputs ("voffset = ", outfile
);
352 wruid (DECL_VOFFSET (node
));
353 fprintf (outfile
, "*%1d;", DECL_VOFFSET_UNIT (node
));
355 part ("context", DECL_CONTEXT (node
));
356 if (code
== FUNCTION_DECL
)
358 if (DECL_ARGUMENTS (node
) || DECL_RESULT (node
)
359 || DECL_INITIAL (node
))
362 part ("arguments", DECL_ARGUMENTS (node
));
363 part ("result", DECL_RESULT (node
));
364 if ((int) (DECL_INITIAL (node
)) == 1)
365 fprintf (outfile
, " initial = const 1;");
367 part ("initial", DECL_INITIAL (node
));
370 else if (DECL_INITIAL (node
))
372 if ((int) (DECL_INITIAL (node
)) == 1)
373 fprintf (outfile
, " initial = const 1;");
375 part ("initial", DECL_INITIAL (node
));
377 #ifdef PRINT_LANG_DECL
378 walk_lang_decl (node
);
380 part ("chain", TREE_CHAIN (node
));
381 /* A Decl's chain contents is not part of the decl. */
383 fputc ('\n', outfile
);
384 cwalk (DECL_SIZE (node
), node
, indent
);
385 walk (TREE_TYPE (node
), node
, indent
);
386 walk (DECL_VOFFSET (node
), node
, indent
);
387 walk (DECL_CONTEXT (node
), node
, indent
);
388 if (code
== FUNCTION_DECL
)
390 walk (DECL_ARGUMENTS (node
), node
, indent
);
391 walk (DECL_RESULT (node
), node
, indent
);
393 if ((int) (DECL_INITIAL (node
)) != 1)
394 walk (DECL_INITIAL (node
), node
, indent
);
398 prtypemodeinfo (node
);
400 #ifdef PRINT_LANG_TYPE
401 print_lang_type (node
);
404 part ("pointers_to_this", TYPE_POINTER_TO (node
));
405 if (code
== ARRAY_TYPE
|| code
== SET_TYPE
)
407 part ("domain", TYPE_DOMAIN (node
));
408 cpart ("separation", TYPE_SEP (node
), '*');
409 fprintf (outfile
, "%d;", TYPE_SEP_UNIT (node
));
411 else if (code
== INTEGER_TYPE
)
413 cpart ("min", TYPE_MIN_VALUE (node
), ';');
414 cpart ("max", TYPE_MAX_VALUE (node
), ';');
415 fprintf (outfile
, "precision = %d;", TYPE_PRECISION (node
));
417 else if (code
== ENUMERAL_TYPE
)
419 cpart ("min", TYPE_MIN_VALUE (node
), ';');
420 cpart ("max", TYPE_MAX_VALUE (node
), ';');
421 part ("values", TYPE_VALUES (node
));
422 fprintf (outfile
, "precision = %d;", TYPE_PRECISION (node
));
424 else if (code
== REAL_TYPE
)
426 fprintf (outfile
, "precision = %d;", TYPE_PRECISION (node
));
428 else if (code
== RECORD_TYPE
429 || code
== UNION_TYPE
)
431 part ("fields", TYPE_FIELDS (node
));
433 else if (code
== FUNCTION_TYPE
)
435 part ("arg_types", TYPE_ARG_TYPES (node
));
437 else if (code
== METHOD_TYPE
)
439 part ("arg_types", TYPE_ARG_TYPES (node
));
441 #ifdef PRINT_LANG_TYPE
442 walk_lang_type (node
);
444 part ("chain", TREE_CHAIN (node
));
445 /* A type's chain's contents are not printed because the chain of types
446 is not part of the meaning of any particular type. */
448 fputc ('\n', outfile
);
449 cwalk (TYPE_SIZE (node
), node
, indent
);
450 walk (TREE_TYPE (node
), node
, indent
);
451 walk (TYPE_VALUES (node
), node
, indent
);
452 walk (TYPE_SEP (node
), node
, indent
);
453 walk (TYPE_POINTER_TO (node
), node
, indent
);
454 walk (TYPE_REFERENCE_TO (node
), node
, indent
);
460 fputs (" ops =", outfile
);
461 first_rtl
= len
= tree_code_length
[(int) code
];
462 /* These kinds of nodes contain rtx's, not trees,
463 after a certain point. Print the rtx's as rtx's. */
472 case METHOD_CALL_EXPR
:
475 case WITH_CLEANUP_EXPR
:
476 /* Should be defined to be 2. */
482 for (i
= 0; i
< len
; i
++)
487 if (TREE_OPERAND (node
, i
))
488 print_rtl (outfile
, TREE_OPERAND (node
, i
));
490 fprintf (outfile
, "(nil)");
491 fprintf (outfile
, "\n");
495 fputs (" ", outfile
);
496 wruid (TREE_OPERAND (node
, i
));
497 fputs (";", outfile
);
500 part ("chain", TREE_CHAIN (node
));
501 fputc ('\n', outfile
);
502 walk (TREE_TYPE (node
), node
, indent
);
503 for (i
= 0; i
< len
&& i
< first_rtl
; i
++)
504 walk (TREE_OPERAND (node
, i
), node
, indent
);
509 fprintf (outfile
, " at %s line %d;",
510 STMT_SOURCE_FILE (node
), STMT_SOURCE_LINE (node
));
511 switch (TREE_CODE (node
))
514 part ("cond", STMT_COND (node
));
515 part ("then", STMT_THEN (node
));
516 part ("else", STMT_ELSE (node
));
521 part ("vars", STMT_VARS (node
));
522 part ("tags", STMT_TYPE_TAGS (node
));
523 part ("supercontext", STMT_SUPERCONTEXT (node
));
524 part ("bind_size", STMT_BIND_SIZE (node
));
525 part ("body", STMT_BODY (node
));
526 part ("subblocks", STMT_SUBBLOCKS (node
));
530 part ("case_index", STMT_CASE_INDEX (node
));
531 part ("case_list", STMT_CASE_LIST (node
));
535 part ("body", STMT_BODY (node
));
538 part ("chain", TREE_CHAIN (node
));
539 fputc ('\n', outfile
);
540 walk (TREE_TYPE (node
), node
, indent
);
541 switch (TREE_CODE (node
))
544 walk (STMT_COND (node
), node
, indent
);
545 walk (STMT_THEN (node
), node
, indent
);
546 walk (STMT_ELSE (node
), node
, indent
);
551 walk (STMT_VARS (node
), node
, indent
);
552 walk (STMT_TYPE_TAGS (node
), node
, indent
);
553 walk (STMT_SUPERCONTEXT (node
), node
, indent
);
554 walk (STMT_BIND_SIZE (node
), node
, indent
);
555 walk (STMT_BODY (node
), node
, indent
);
556 walk (STMT_SUBBLOCKS (node
), node
, indent
);
560 walk (STMT_CASE_INDEX (node
), node
, indent
);
561 walk (STMT_CASE_LIST (node
), node
, indent
);
565 walk (STMT_BODY (node
), node
, indent
);
574 if (TREE_INT_CST_HIGH (node
) == 0)
575 fprintf (outfile
, " = %1u;", TREE_INT_CST_LOW (node
));
576 else if (TREE_INT_CST_HIGH (node
) == -1
577 && TREE_INT_CST_LOW (node
) != 0)
578 fprintf (outfile
, " = -%1u;", -TREE_INT_CST_LOW (node
));
580 fprintf (outfile
, " = 0x%x%08x;",
581 TREE_INT_CST_HIGH (node
),
582 TREE_INT_CST_LOW (node
));
586 #ifndef REAL_IS_NOT_DOUBLE
587 fprintf (outfile
, " = %e;", TREE_REAL_CST (node
));
591 char *p
= (char *) &TREE_REAL_CST (node
);
592 fprintf (outfile
, " = 0x");
593 for (i
= 0; i
< sizeof TREE_REAL_CST (node
); i
++)
594 fprintf (outfile
, "%02x", *p
++);
595 fprintf (outfile
, ";");
597 #endif /* REAL_IS_NOT_DOUBLE */
601 part ("realpart", TREE_REALPART (node
));
602 part ("imagpart", TREE_IMAGPART (node
));
603 walk (TREE_REALPART (node
), node
, indent
);
604 walk (TREE_IMAGPART (node
), node
, indent
);
608 fprintf (outfile
, " = \"%s\";", TREE_STRING_POINTER (node
));
611 part ("chain", TREE_CHAIN (node
));
612 fputc ('\n', outfile
);
613 walk (TREE_TYPE (node
), node
, indent
);
617 if (code
== IDENTIFIER_NODE
)
619 fprintf (outfile
, " = %s;\n", IDENTIFIER_POINTER (node
));
622 else if (code
== TREE_LIST
)
625 part ("purpose", TREE_PURPOSE (node
));
626 part ("value", TREE_VALUE (node
));
627 part ("chain", TREE_CHAIN (node
));
628 fputc ('\n', outfile
);
629 walk (TREE_TYPE (node
), node
, indent
);
630 walk (TREE_PURPOSE (node
), node
, indent
);
631 walk (TREE_VALUE (node
), node
, indent
);
633 else if (code
== TREE_VEC
)
636 len
= TREE_VEC_LENGTH (node
);
637 fprintf (outfile
, "length = %d\n", len
);
638 for (i
= 0; i
< len
; i
++)
640 fputs (" ", outfile
);
641 wruid (TREE_VEC_ELT (node
, i
));
642 fputs (";", outfile
);
644 part ("chain", TREE_CHAIN (node
));
645 fputc ('\n', outfile
);
646 walk (TREE_TYPE (node
), node
, indent
);
647 for (i
= 0; i
< len
; i
++)
648 walk (TREE_VEC_ELT (node
, i
), node
, indent
);
650 else if (code
== OP_IDENTIFIER
)
653 part ("op1", TREE_PURPOSE (node
));
654 part ("op2", TREE_VALUE (node
));
655 part ("chain", TREE_CHAIN (node
));
656 fputc ('\n', outfile
);
657 walk (TREE_TYPE (node
), node
, indent
);
658 walk (TREE_PURPOSE (node
), node
, indent
);
659 walk (TREE_VALUE (node
), node
, indent
);
661 else if (code
== ERROR_MARK
)
662 fputc ('\n', outfile
);
671 if (TREE_CHAIN (node
) != NULL
&& ! nochain
)
672 dump (TREE_CHAIN (node
), indent
);