OSDN Git Service

(print_node, print_node_brief): Say something when
[pf3gnuchains/gcc-fork.git] / gcc / print-tree.c
1 /* Prints out tree in human readable form - GNU C-compiler
2    Copyright (C) 1990, 1991, 1993 Free Software Foundation, Inc.
3
4 This file is part of GNU CC.
5
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 2, or (at your option)
9 any later version.
10
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.
15
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.  */
19
20
21 #include "config.h"
22 #include "tree.h"
23 #include <stdio.h>
24
25 extern char **tree_code_name;
26
27 extern char *mode_name[];
28
29 void print_node ();
30 void indent_to ();
31
32 /* Define the hash table of nodes already seen.
33    Such nodes are not repeated; brief cross-references are used.  */
34
35 #define HASH_SIZE 37
36
37 struct bucket
38 {
39   tree node;
40   struct bucket *next;
41 };
42
43 static struct bucket **table;
44
45 /* Print the node NODE on standard error, for debugging.
46    Most nodes referred to by this one are printed recursively
47    down to a depth of six.  */
48
49 void
50 debug_tree (node)
51      tree node;
52 {
53   char *object = (char *) oballoc (0);
54   table = (struct bucket **) oballoc (HASH_SIZE * sizeof (struct bucket *));
55   bzero (table, HASH_SIZE * sizeof (struct bucket *));
56   print_node (stderr, "", node, 0);
57   table = 0;
58   obfree (object);
59   fprintf (stderr, "\n");
60 }
61
62 /* Print a node in brief fashion, with just the code, address and name.  */
63
64 void
65 print_node_brief (file, prefix, node, indent)
66      FILE *file;
67      char *prefix;
68      tree node;
69      int indent;
70 {
71   char class;
72
73   if (node == 0)
74     return;
75
76   class = TREE_CODE_CLASS (TREE_CODE (node));
77
78   /* Always print the slot this node is in, and its code, address and
79      name if any.  */
80   if (indent > 0)
81     fprintf (file, " ");
82   fprintf (file, "%s <%s ", prefix, tree_code_name[(int) TREE_CODE (node)]);
83   fprintf (file, HOST_PTR_PRINTF, (HOST_WIDE_INT) node);
84
85   if (class == 'd')
86     {
87       if (DECL_NAME (node))
88         fprintf (file, " %s", IDENTIFIER_POINTER (DECL_NAME (node)));
89     }
90   else if (class == 't')
91     {
92       if (TYPE_NAME (node))
93         {
94           if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
95             fprintf (file, " %s", IDENTIFIER_POINTER (TYPE_NAME (node)));
96           else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
97                    && DECL_NAME (TYPE_NAME (node)))
98             fprintf (file, " %s",
99                      IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node))));
100         }
101     }
102   if (TREE_CODE (node) == IDENTIFIER_NODE)
103     fprintf (file, " %s", IDENTIFIER_POINTER (node));
104   /* We might as well always print the value of an integer.  */
105   if (TREE_CODE (node) == INTEGER_CST)
106     {
107       if (TREE_CONSTANT_OVERFLOW (node))
108         fprintf (file, " overflow");
109
110       if (TREE_INT_CST_HIGH (node) == 0)
111         fprintf (file, " %1u", TREE_INT_CST_LOW (node));
112       else if (TREE_INT_CST_HIGH (node) == -1
113                && TREE_INT_CST_LOW (node) != 0)
114         fprintf (file, " -%1u", -TREE_INT_CST_LOW (node));
115       else
116         fprintf (file,
117 #if HOST_BITS_PER_WIDE_INT == 64
118 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
119                  " 0x%lx%016lx",
120 #else
121                  " 0x%x%016x",
122 #endif
123 #else
124 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
125                  " 0x%lx%08lx",
126 #else
127                  " 0x%x%08x",
128 #endif
129 #endif
130                  TREE_INT_CST_HIGH (node), TREE_INT_CST_LOW (node));
131     }
132   if (TREE_CODE (node) == REAL_CST)
133     {
134 #ifndef REAL_IS_NOT_DOUBLE
135       fprintf (file, " %e", TREE_REAL_CST (node));
136 #else
137       {
138         int i;
139         unsigned char *p = (unsigned char *) &TREE_REAL_CST (node);
140         fprintf (file, " 0x");
141         for (i = 0; i < sizeof TREE_REAL_CST (node); i++)
142           fprintf (file, "%02x", *p++);
143         fprintf (file, "");
144       }
145 #endif /* REAL_IS_NOT_DOUBLE */
146     }
147
148   fprintf (file, ">");
149 }
150
151 void
152 indent_to (file, column)
153      FILE *file;
154      int column;
155 {
156   int i;
157
158   /* Since this is the long way, indent to desired column.  */
159   if (column > 0)
160     fprintf (file, "\n");
161   for (i = 0; i < column; i++)
162     fprintf (file, " ");
163 }
164 \f
165 /* Print the node NODE in full on file FILE, preceded by PREFIX,
166    starting in column INDENT.  */
167
168 void
169 print_node (file, prefix, node, indent)
170      FILE *file;
171      char *prefix;
172      tree node;
173      int indent;
174 {
175   int hash;
176   struct bucket *b;
177   enum machine_mode mode;
178   char class;
179   int len;
180   int first_rtl;
181   int i;
182
183   if (node == 0)
184     return;
185
186   class = TREE_CODE_CLASS (TREE_CODE (node));
187
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.  */
191
192   if (indent > 24)
193     {
194       print_node_brief (file, prefix, node, indent);
195       return;
196     }
197
198   if (indent > 8 && (class == 't' || class == 'd'))
199     {
200       print_node_brief (file, prefix, node, indent);
201       return;
202     }
203
204   /* It is unsafe to look at any other filds of an ERROR_MARK node. */
205   if (TREE_CODE (node) == ERROR_MARK)
206     {
207       print_node_brief (file, prefix, node, indent);
208       return;
209     }
210
211   hash = ((unsigned HOST_WIDE_INT) node) % HASH_SIZE;
212
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)
216       {
217         print_node_brief (file, prefix, node, indent);
218         return;
219       }
220
221   /* Add this node to the table.  */
222   b = (struct bucket *) oballoc (sizeof (struct bucket));
223   b->node = node;
224   b->next = table[hash];
225   table[hash] = b;
226
227   /* Indent to the specified column, since this is the long form.  */
228   indent_to (file, indent);
229
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   fprintf (file, HOST_PTR_PRINTF, (HOST_WIDE_INT) node);
233
234   /* Print the name, if any.  */
235   if (class == 'd')
236     {
237       if (DECL_NAME (node))
238         fprintf (file, " %s", IDENTIFIER_POINTER (DECL_NAME (node)));
239     }
240   else if (class == 't')
241     {
242       if (TYPE_NAME (node))
243         {
244           if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
245             fprintf (file, " %s", IDENTIFIER_POINTER (TYPE_NAME (node)));
246           else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
247                    && DECL_NAME (TYPE_NAME (node)))
248             fprintf (file, " %s",
249                      IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node))));
250         }
251     }
252   if (TREE_CODE (node) == IDENTIFIER_NODE)
253     fprintf (file, " %s", IDENTIFIER_POINTER (node));
254
255   if (TREE_CODE (node) == INTEGER_CST)
256     {
257       if (indent <= 4)
258         print_node_brief (file, "type", TREE_TYPE (node), indent + 4);
259     }
260   else
261     {
262       print_node (file, "type", TREE_TYPE (node), indent + 4);
263       if (TREE_TYPE (node))
264         indent_to (file, indent + 3);
265
266       print_obstack_name ((char *) node, file, "");
267       indent_to (file, indent + 3);
268     }
269
270   /* If a permanent object is in the wrong obstack, or the reverse, warn.  */
271   if (object_permanent_p (node) != TREE_PERMANENT (node))
272     {
273       if (TREE_PERMANENT (node))
274         fputs (" !!permanent object in non-permanent obstack!!", file);
275       else
276         fputs (" !!non-permanent object in permanent obstack!!", file);
277       indent_to (file, indent + 3);
278     }
279
280   if (TREE_SIDE_EFFECTS (node))
281     fputs (" side-effects", file);
282   if (TREE_READONLY (node))
283     fputs (" readonly", file);
284   if (TREE_CONSTANT (node))
285     fputs (" constant", file);
286   if (TREE_ADDRESSABLE (node))
287     fputs (" addressable", file);
288   if (TREE_THIS_VOLATILE (node))
289     fputs (" volatile", file);
290   if (TREE_UNSIGNED (node))
291     fputs (" unsigned", file);
292   if (TREE_ASM_WRITTEN (node))
293     fputs (" asm_written", file);
294   if (TREE_USED (node))
295     fputs (" used", file);
296   if (TREE_RAISES (node))
297     fputs (" raises", file);
298   if (TREE_PERMANENT (node))
299     fputs (" permanent", file);
300   if (TREE_PUBLIC (node))
301     fputs (" public", file);
302   if (TREE_STATIC (node))
303     fputs (" static", file);
304   if (TREE_LANG_FLAG_0 (node))
305     fputs (" tree_0", file);
306   if (TREE_LANG_FLAG_1 (node))
307     fputs (" tree_1", file);
308   if (TREE_LANG_FLAG_2 (node))
309     fputs (" tree_2", file);
310   if (TREE_LANG_FLAG_3 (node))
311     fputs (" tree_3", file);
312   if (TREE_LANG_FLAG_4 (node))
313     fputs (" tree_4", file);
314   if (TREE_LANG_FLAG_5 (node))
315     fputs (" tree_5", file);
316   if (TREE_LANG_FLAG_6 (node))
317     fputs (" tree_6", file);
318
319   /* DECL_ nodes have additional attributes.  */
320
321   switch (TREE_CODE_CLASS (TREE_CODE (node)))
322     {
323     case 'd':
324       mode = DECL_MODE (node);
325
326       if (DECL_EXTERNAL (node))
327         fputs (" external", file);
328       if (DECL_NONLOCAL (node))
329         fputs (" nonlocal", file);
330       if (DECL_REGISTER (node))
331         fputs (" regdecl", file);
332       if (DECL_INLINE (node))
333         fputs (" inline", file);
334       if (DECL_BIT_FIELD (node))
335         fputs (" bit-field", file);
336       if (DECL_VIRTUAL_P (node))
337         fputs (" virtual", file);
338       if (DECL_IGNORED_P (node))
339         fputs (" ignored", file);
340       if (DECL_IN_SYSTEM_HEADER (node))
341         fputs (" in_system_header", file);
342       if (DECL_LANG_FLAG_0 (node))
343         fputs (" decl_0", file);
344       if (DECL_LANG_FLAG_1 (node))
345         fputs (" decl_1", file);
346       if (DECL_LANG_FLAG_2 (node))
347         fputs (" decl_2", file);
348       if (DECL_LANG_FLAG_3 (node))
349         fputs (" decl_3", file);
350       if (DECL_LANG_FLAG_4 (node))
351         fputs (" decl_4", file);
352       if (DECL_LANG_FLAG_5 (node))
353         fputs (" decl_5", file);
354       if (DECL_LANG_FLAG_6 (node))
355         fputs (" decl_6", file);
356       if (DECL_LANG_FLAG_7 (node))
357         fputs (" decl_7", file);
358
359       fprintf (file, " %s", mode_name[(int) mode]);
360
361       fprintf (file, " file %s line %d",
362                DECL_SOURCE_FILE (node), DECL_SOURCE_LINE (node));
363
364       print_node (file, "size", DECL_SIZE (node), indent + 4);
365       indent_to (file, indent + 3);
366       if (TREE_CODE (node) != FUNCTION_DECL)
367         fprintf (file, " align %d", DECL_ALIGN (node));
368       else if (DECL_INLINE (node))
369         fprintf (file, " frame_size %d", DECL_FRAME_SIZE (node));
370       else if (DECL_BUILT_IN (node))
371         fprintf (file, " built-in code %d", DECL_FUNCTION_CODE (node));
372       if (TREE_CODE (node) == FIELD_DECL)
373         print_node (file, "bitpos", DECL_FIELD_BITPOS (node), indent + 4);
374       print_node_brief (file, "context", DECL_CONTEXT (node), indent + 4);
375       print_node_brief (file, "abstract_origin",
376                         DECL_ABSTRACT_ORIGIN (node), indent + 4);
377
378       print_node (file, "arguments", DECL_ARGUMENTS (node), indent + 4);
379       print_node (file, "result", DECL_RESULT (node), indent + 4);
380       print_node_brief (file, "initial", DECL_INITIAL (node), indent + 4);
381
382       print_lang_decl (file, node, indent);
383
384       if (DECL_RTL (node) != 0)
385         {
386           indent_to (file, indent + 4);
387           print_rtl (file, DECL_RTL (node));
388         }
389
390       if (DECL_SAVED_INSNS (node) != 0)
391         {
392           indent_to (file, indent + 4);
393           if (TREE_CODE (node) == PARM_DECL)
394             {
395               fprintf (file, "incoming-rtl ");
396               print_rtl (file, DECL_INCOMING_RTL (node));
397             }
398           else if (TREE_CODE (node) == FUNCTION_DECL)
399             {
400               fprintf (file, "saved-insns ");
401               fprintf (file, HOST_PTR_PRINTF,
402                        (HOST_WIDE_INT) DECL_SAVED_INSNS (node));
403             }
404         }
405
406       /* Print the decl chain only if decl is at second level.  */
407       if (indent == 4)
408         print_node (file, "chain", TREE_CHAIN (node), indent + 4);
409       else
410         print_node_brief (file, "chain", TREE_CHAIN (node), indent + 4);
411       break;
412
413     case 't':
414       if (TYPE_NO_FORCE_BLK (node))
415         fputs (" no_force_blk", file);
416       if (TYPE_LANG_FLAG_0 (node))
417         fputs (" type_0", file);
418       if (TYPE_LANG_FLAG_1 (node))
419         fputs (" type_1", file);
420       if (TYPE_LANG_FLAG_2 (node))
421         fputs (" type_2", file);
422       if (TYPE_LANG_FLAG_3 (node))
423         fputs (" type_3", file);
424       if (TYPE_LANG_FLAG_4 (node))
425         fputs (" type_4", file);
426       if (TYPE_LANG_FLAG_5 (node))
427         fputs (" type_5", file);
428       if (TYPE_LANG_FLAG_6 (node))
429         fputs (" type_6", file);
430
431       mode = TYPE_MODE (node);
432       fprintf (file, " %s", mode_name[(int) mode]);
433
434       print_node (file, "size", TYPE_SIZE (node), indent + 4);
435       indent_to (file, indent + 3);
436
437       fprintf (file, " align %d", TYPE_ALIGN (node));
438       fprintf (file, " symtab %d", TYPE_SYMTAB_ADDRESS (node));
439
440       if (TREE_CODE (node) == ARRAY_TYPE || TREE_CODE (node) == SET_TYPE)
441         print_node (file, "domain", TYPE_DOMAIN (node), indent + 4);
442       else if (TREE_CODE (node) == INTEGER_TYPE
443                || TREE_CODE (node) == BOOLEAN_TYPE
444                || TREE_CODE (node) == CHAR_TYPE)
445         {
446           fprintf (file, " precision %d", TYPE_PRECISION (node));
447           print_node (file, "min", TYPE_MIN_VALUE (node), indent + 4);
448           print_node (file, "max", TYPE_MAX_VALUE (node), indent + 4);
449         }
450       else if (TREE_CODE (node) == ENUMERAL_TYPE)
451         {
452           fprintf (file, " precision %d", TYPE_PRECISION (node));
453           print_node (file, "min", TYPE_MIN_VALUE (node), indent + 4);
454           print_node (file, "max", TYPE_MAX_VALUE (node), indent + 4);
455           print_node (file, "values", TYPE_VALUES (node), indent + 4);
456         }
457       else if (TREE_CODE (node) == REAL_TYPE)
458         fprintf (file, " precision %d", TYPE_PRECISION (node));
459       else if (TREE_CODE (node) == RECORD_TYPE
460                || TREE_CODE (node) == UNION_TYPE
461                || TREE_CODE (node) == QUAL_UNION_TYPE)
462         print_node (file, "fields", TYPE_FIELDS (node), indent + 4);
463       else if (TREE_CODE (node) == FUNCTION_TYPE || TREE_CODE (node) == METHOD_TYPE)
464         {
465           if (TYPE_METHOD_BASETYPE (node))
466             print_node_brief (file, "method basetype", TYPE_METHOD_BASETYPE (node), indent + 4);
467           print_node (file, "arg-types", TYPE_ARG_TYPES (node), indent + 4);
468         }
469       if (TYPE_CONTEXT (node))
470         print_node_brief (file, "context", TYPE_CONTEXT (node), indent + 4);
471
472       print_lang_type (file, node, indent);
473
474       if (TYPE_POINTER_TO (node) || TREE_CHAIN (node))
475         indent_to (file, indent + 3);
476       print_node_brief (file, "pointer_to_this", TYPE_POINTER_TO (node), indent + 4);
477       print_node_brief (file, "reference_to_this", TYPE_REFERENCE_TO (node), indent + 4);
478       print_node_brief (file, "chain", TREE_CHAIN (node), indent + 4);
479       break;
480
481     case 'b':
482       print_node (file, "vars", BLOCK_VARS (node), indent + 4);
483       print_node (file, "tags", BLOCK_TYPE_TAGS (node), indent + 4);
484       print_node (file, "supercontext", BLOCK_SUPERCONTEXT (node), indent + 4);
485       print_node (file, "subblocks", BLOCK_SUBBLOCKS (node), indent + 4);
486       print_node (file, "chain", BLOCK_CHAIN (node), indent + 4);
487       print_node (file, "abstract_origin",
488                   BLOCK_ABSTRACT_ORIGIN (node), indent + 4);
489       return;
490
491     case 'e':
492     case '<':
493     case '1':
494     case '2':
495     case 'r':
496     case 's':
497       switch (TREE_CODE (node))
498         {
499         case BIND_EXPR:
500           print_node (file, "vars", TREE_OPERAND (node, 0), indent + 4);
501           print_node (file, "body", TREE_OPERAND (node, 1), indent + 4);
502           print_node (file, "block", TREE_OPERAND (node, 2), indent + 4);
503           return;
504         }
505
506       first_rtl = len = tree_code_length[(int) TREE_CODE (node)];
507       /* These kinds of nodes contain rtx's, not trees,
508          after a certain point.  Print the rtx's as rtx's.  */
509       switch (TREE_CODE (node))
510         {
511         case SAVE_EXPR:
512           first_rtl = 2;
513           break;
514         case CALL_EXPR:
515           first_rtl = 2;
516           break;
517         case METHOD_CALL_EXPR:
518           first_rtl = 3;
519           break;
520         case WITH_CLEANUP_EXPR:
521           /* Should be defined to be 2.  */
522           first_rtl = 1;
523           break;
524         case RTL_EXPR:
525           first_rtl = 0;
526         }
527       for (i = 0; i < len; i++)
528         {
529           if (i >= first_rtl)
530             {
531               indent_to (file, indent + 4);
532               fprintf (file, "rtl %d ", i);
533               if (TREE_OPERAND (node, i))
534                 print_rtl (file, (struct rtx_def *) TREE_OPERAND (node, i));
535               else
536                 fprintf (file, "(nil)");
537               fprintf (file, "\n");
538             }
539           else
540             {
541               char temp[10];
542
543               sprintf (temp, "arg %d", i);
544               print_node (file, temp, TREE_OPERAND (node, i), indent + 4);
545             }
546         }
547       break;
548
549     case 'c':
550     case 'x':
551       switch (TREE_CODE (node))
552         {
553         case INTEGER_CST:
554           if (TREE_CONSTANT_OVERFLOW (node))
555             fprintf (file, " overflow");
556
557           if (TREE_INT_CST_HIGH (node) == 0)
558             fprintf (file, " %1u", TREE_INT_CST_LOW (node));
559           else if (TREE_INT_CST_HIGH (node) == -1
560                    && TREE_INT_CST_LOW (node) != 0)
561             fprintf (file, " -%1u", -TREE_INT_CST_LOW (node));
562           else
563             fprintf (file,
564 #if HOST_BITS_PER_WIDE_INT == 64
565 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
566                      " 0x%lx%016lx",
567 #else
568                      " 0x%x%016x",
569 #endif
570 #else
571 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
572                      " 0x%lx%08lx",
573 #else
574                      " 0x%x%08x",
575 #endif
576 #endif
577                      TREE_INT_CST_HIGH (node), TREE_INT_CST_LOW (node));
578           break;
579
580         case REAL_CST:
581 #ifndef REAL_IS_NOT_DOUBLE
582           fprintf (file, " %e", TREE_REAL_CST (node));
583 #else
584           {
585             char *p = (char *) &TREE_REAL_CST (node);
586             fprintf (file, " 0x");
587             for (i = 0; i < sizeof TREE_REAL_CST (node); i++)
588               fprintf (file, "%02x", *p++);
589             fprintf (file, "");
590           }
591 #endif /* REAL_IS_NOT_DOUBLE */
592           break;
593
594         case COMPLEX_CST:
595           print_node (file, "real", TREE_REALPART (node), indent + 4);
596           print_node (file, "imag", TREE_IMAGPART (node), indent + 4);
597           break;
598
599         case STRING_CST:
600           fprintf (file, " \"%s\"", TREE_STRING_POINTER (node));
601           /* Print the chain at second level.  */
602           if (indent == 4)
603             print_node (file, "chain", TREE_CHAIN (node), indent + 4);
604           else
605             print_node_brief (file, "chain", TREE_CHAIN (node), indent + 4);
606           break;
607
608         case IDENTIFIER_NODE:
609           print_lang_identifier (file, node, indent);
610           break;
611
612         case TREE_LIST:
613           print_node (file, "purpose", TREE_PURPOSE (node), indent + 4);
614           print_node (file, "value", TREE_VALUE (node), indent + 4);
615           print_node (file, "chain", TREE_CHAIN (node), indent + 4);
616           break;
617
618         case TREE_VEC:
619           len = TREE_VEC_LENGTH (node);
620           for (i = 0; i < len; i++)
621             if (TREE_VEC_ELT (node, i))
622               {
623                 char temp[10];
624                 sprintf (temp, "elt %d", i);
625                 indent_to (file, indent + 4);
626                 print_node_brief (file, temp, TREE_VEC_ELT (node, i), 0);
627               }
628           break;
629
630         case OP_IDENTIFIER:
631           print_node (file, "op1", TREE_PURPOSE (node), indent + 4);
632           print_node (file, "op2", TREE_VALUE (node), indent + 4);
633         }
634
635       break;
636     }
637
638   fprintf (file, ">");
639 }