No empty .Rs/.Re
[netbsd-mini2440.git] / gnu / usr.bin / g++ / cc1plus / print-tree.c
blobecbb5f770a2d7552a80f30a12536b2be1c264c29
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)
9 any later version.
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. */
21 #include "config.h"
22 #include "tree.h"
23 #include <stdio.h>
25 extern char **tree_code_name;
27 extern char *mode_name[];
29 extern char spaces[];
31 #define MIN(x,y) ((x < y) ? x : y)
33 static FILE *outfile;
35 extern int tree_node_counter;
37 /* markvec[i] is 1 if node number i has been seen already. */
39 static char *markvec;
41 static void dump ();
42 void dump_tree ();
44 void
45 debug_dump_tree (root)
46 tree root;
48 dump_tree (stderr, root);
51 void
52 dump_tree (outf, root)
53 FILE *outf;
54 tree root;
56 markvec = (char *) alloca (tree_node_counter + 1);
57 bzero (markvec, tree_node_counter + 1);
58 outfile = outf;
59 dump (root, 0);
60 fflush (outf);
63 static
64 void
65 wruid (node)
66 tree node;
69 if (node == NULL)
70 fputs ("<>", outfile);
71 else {
72 fprintf (outfile, "%1d", TREE_UID (node));
76 static
77 void
78 part (title, node)
79 char title[];
80 tree node;
82 fprintf (outfile, " %s = ", title);
83 wruid (node);
84 putc (';', outfile);
87 /* Similar to `part' but prefix with @ if value is not constant
88 and print the constant value if it is constant. */
89 static
90 void
91 cpart (title, ct, punct)
92 char *title;
93 tree ct;
94 char punct;
96 fprintf (outfile, " %s = ", title);
97 if (ct == NULL)
98 fputs ("<>", outfile);
99 else
101 if (!TREE_LITERAL (ct))
103 putc ('@', outfile);
104 wruid (ct);
106 else
107 fprintf (outfile, "%ld", TREE_INT_CST_LOW (ct));
109 putc (punct, outfile);
112 static void
113 walk (node, leaf, indent)
114 tree node;
115 tree leaf;
116 int indent;
118 if (node != NULL
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);
129 static void
130 cwalk (s, leaf, indent)
131 tree s;
132 tree leaf;
133 int indent;
135 if (s != NULL)
136 if (!TREE_LITERAL (s))
137 walk (s, leaf, indent);
140 static void
141 prtypeinfo (node)
142 register tree node;
144 int first;
146 part ("type", TREE_TYPE (node));
147 first = 1;
148 fputs (" [", outfile);
149 if (TREE_EXTERNAL (node))
151 if (!first) putc (' ', outfile);
152 fputs ("external", outfile);
153 first = 0;
155 if (TREE_PUBLIC (node))
157 if (!first) putc (' ', outfile);
158 fputs ("public", outfile);
159 first = 0;
161 if (TREE_STATIC (node))
163 if (!first) putc (' ', outfile);
164 fputs ("static", outfile);
165 first = 0;
167 if (TREE_VOLATILE (node))
169 if (!first) putc (' ', outfile);
170 fputs ("volatile", outfile);
171 first = 0;
173 if (TREE_PACKED (node))
175 if (!first) putc (' ', outfile);
176 fputs ("packed", outfile);
177 first = 0;
179 if (TREE_READONLY (node))
181 if (!first) putc (' ', outfile);
182 fputs ("readonly", outfile);
183 first = 0;
185 if (TREE_LITERAL (node))
187 if (!first) putc (' ', outfile);
188 fputs ("literal", outfile);
189 first = 0;
191 if (TREE_NONLOCAL (node))
193 if (!first) putc (' ', outfile);
194 fputs ("nonlocal", outfile);
195 first = 0;
197 if (TREE_ADDRESSABLE (node))
199 if (!first) putc (' ', outfile);
200 fputs ("addressable", outfile);
201 first = 0;
203 if (TREE_REGDECL (node))
205 if (!first) putc (' ', outfile);
206 fputs ("regdecl", outfile);
207 first = 0;
209 if (TREE_THIS_VOLATILE (node))
211 if (!first) putc (' ', outfile);
212 fputs ("this_vol", outfile);
213 first = 0;
215 if (TREE_UNSIGNED (node))
217 if (!first) putc (' ', outfile);
218 fputs ("unsigned", outfile);
219 first = 0;
221 if (TREE_ASM_WRITTEN (node))
223 if (!first) putc (' ', outfile);
224 fputs ("asm_written", outfile);
225 first = 0;
227 if (TREE_INLINE (node))
229 if (!first) putc (' ', outfile);
230 fputs ("inline", outfile);
231 first = 0;
233 if (TREE_USED (node))
235 if (!first) putc (' ', outfile);
236 fputs ("used", outfile);
237 first = 0;
239 if (TREE_PERMANENT (node))
241 if (!first) putc (' ', outfile);
242 fputs ("permanent", outfile);
243 first = 0;
245 if (TREE_LANG_FLAG_1 (node))
247 if (!first) putc (' ', outfile);
248 fputs ("lang_flag_1", outfile);
249 first = 0;
251 if (TREE_LANG_FLAG_2 (node))
253 if (!first) putc (' ', outfile);
254 fputs ("lang_flag_2", outfile);
255 first = 0;
257 if (TREE_LANG_FLAG_3 (node))
259 if (!first) putc (' ', outfile);
260 fputs ("lang_flag_3", outfile);
261 first = 0;
263 if (TREE_LANG_FLAG_4 (node))
265 if (!first) putc (' ', outfile);
266 fputs ("lang_flag_4", outfile);
267 first = 0;
269 fputs ("] ", outfile);
272 static void
273 prdeclmodeinfo (node)
274 tree 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));
285 static void
286 prtypemodeinfo (node)
287 tree 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));
298 static void
299 skip (indent)
300 int indent;
302 putc ('\n',outfile);
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. */
309 static
310 void
311 dump (node, indent)
312 tree node;
313 int indent;
315 register enum tree_code code = TREE_CODE (node);
316 register int i;
317 register int len, first_rtl;
318 int nochain = 0;
320 if (markvec[TREE_UID (node)])
321 return;
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])
331 case 'd':
332 fputs (" name = ", outfile);
333 if (DECL_NAME (node) == NULL)
334 fputs ("<>;", outfile);
335 else
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));
341 skip (indent);
342 prdeclmodeinfo (node);
343 prtypeinfo (node);
344 #ifdef PRINT_LANG_DECL
345 print_lang_decl (node);
346 #endif
347 skip (indent);
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))
361 skip (indent);
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;");
366 else
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;");
374 else
375 part ("initial", DECL_INITIAL (node));
377 #ifdef PRINT_LANG_DECL
378 walk_lang_decl (node);
379 #endif
380 part ("chain", TREE_CHAIN (node));
381 /* A Decl's chain contents is not part of the decl. */
382 nochain = 1;
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);
395 break;
397 case 't':
398 prtypemodeinfo (node);
399 prtypeinfo (node);
400 #ifdef PRINT_LANG_TYPE
401 print_lang_type (node);
402 #endif
403 skip (indent);
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);
443 #endif
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. */
447 nochain = 1;
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);
455 break;
457 case 'e':
458 case 'r':
459 prtypeinfo (node);
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. */
464 switch (code)
466 case SAVE_EXPR:
467 first_rtl = 1;
468 break;
469 case CALL_EXPR:
470 first_rtl = 2;
471 break;
472 case METHOD_CALL_EXPR:
473 first_rtl = 3;
474 break;
475 case WITH_CLEANUP_EXPR:
476 /* Should be defined to be 2. */
477 first_rtl = 1;
478 break;
479 case RTL_EXPR:
480 first_rtl = 0;
482 for (i = 0; i < len; i++)
484 if (i >= first_rtl)
486 skip (indent);
487 if (TREE_OPERAND (node, i))
488 print_rtl (outfile, TREE_OPERAND (node, i));
489 else
490 fprintf (outfile, "(nil)");
491 fprintf (outfile, "\n");
493 else
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);
505 break;
507 case 's':
508 prtypeinfo (node);
509 fprintf (outfile, " at %s line %d;",
510 STMT_SOURCE_FILE (node), STMT_SOURCE_LINE (node));
511 switch (TREE_CODE (node))
513 case IF_STMT:
514 part ("cond", STMT_COND (node));
515 part ("then", STMT_THEN (node));
516 part ("else", STMT_ELSE (node));
517 break;
519 case LET_STMT:
520 case WITH_STMT:
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));
527 break;
529 case CASE_STMT:
530 part ("case_index", STMT_CASE_INDEX (node));
531 part ("case_list", STMT_CASE_LIST (node));
532 break;
534 default:
535 part ("body", STMT_BODY (node));
536 break;
538 part ("chain", TREE_CHAIN (node));
539 fputc ('\n', outfile);
540 walk (TREE_TYPE (node), node, indent);
541 switch (TREE_CODE (node))
543 case IF_STMT:
544 walk (STMT_COND (node), node, indent);
545 walk (STMT_THEN (node), node, indent);
546 walk (STMT_ELSE (node), node, indent);
547 break;
549 case LET_STMT:
550 case WITH_STMT:
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);
557 break;
559 case CASE_STMT:
560 walk (STMT_CASE_INDEX (node), node, indent);
561 walk (STMT_CASE_LIST (node), node, indent);
562 break;
564 default:
565 walk (STMT_BODY (node), node, indent);
566 break;
568 break;
570 case 'c':
571 switch (code)
573 case INTEGER_CST:
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));
579 else
580 fprintf (outfile, " = 0x%x%08x;",
581 TREE_INT_CST_HIGH (node),
582 TREE_INT_CST_LOW (node));
583 break;
585 case REAL_CST:
586 #ifndef REAL_IS_NOT_DOUBLE
587 fprintf (outfile, " = %e;", TREE_REAL_CST (node));
588 #else
590 int i;
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 */
598 break;
600 case COMPLEX_CST:
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);
605 break;
607 case STRING_CST:
608 fprintf (outfile, " = \"%s\";", TREE_STRING_POINTER (node));
610 prtypeinfo (node);
611 part ("chain", TREE_CHAIN (node));
612 fputc ('\n', outfile);
613 walk (TREE_TYPE (node), node, indent);
614 break;
616 case 'x':
617 if (code == IDENTIFIER_NODE)
619 fprintf (outfile, " = %s;\n", IDENTIFIER_POINTER (node));
620 nochain = 1;
622 else if (code == TREE_LIST)
624 prtypeinfo (node);
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)
635 prtypeinfo (node);
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)
652 prtypeinfo (node);
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);
663 else abort ();
665 break;
667 default:
668 abort ();
669 } /* switch */
671 if (TREE_CHAIN (node) != NULL && ! nochain)
672 dump (TREE_CHAIN (node), indent);