1 /* Prints out tree in human readable form - GNU C-compiler
2 Copyright (C) 1990, 1991, 1993 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 2, 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
[];
32 /* Define the hash table of nodes already seen.
33 Such nodes are not repeated; brief cross-references are used. */
43 static struct bucket
**table
;
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. */
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);
59 fprintf (stderr
, "\n");
62 /* Print a node in brief fashion, with just the code, address and name. */
65 print_node_brief (file
, prefix
, node
, indent
)
76 class = TREE_CODE_CLASS (TREE_CODE (node
));
78 /* Always print the slot this node is in, and its code, address and
82 fprintf (file
, "%s <%s ", prefix
, tree_code_name
[(int) TREE_CODE (node
)]);
83 fprintf (file
, HOST_PTR_PRINTF
, (HOST_WIDE_INT
) node
);
88 fprintf (file
, " %s", IDENTIFIER_POINTER (DECL_NAME (node
)));
90 else if (class == 't')
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
)))
99 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node
))));
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
)
107 if (TREE_INT_CST_HIGH (node
) == 0)
108 fprintf (file
, " %1u", TREE_INT_CST_LOW (node
));
109 else if (TREE_INT_CST_HIGH (node
) == -1
110 && TREE_INT_CST_LOW (node
) != 0)
111 fprintf (file
, " -%1u", -TREE_INT_CST_LOW (node
));
114 #if HOST_BITS_PER_WIDE_INT == 64
115 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
121 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
127 TREE_INT_CST_HIGH (node
), TREE_INT_CST_LOW (node
));
129 if (TREE_CODE (node
) == REAL_CST
)
131 #ifndef REAL_IS_NOT_DOUBLE
132 fprintf (file
, " %e", TREE_REAL_CST (node
));
136 char *p
= (char *) &TREE_REAL_CST (node
);
137 fprintf (file
, " 0x");
138 for (i
= 0; i
< sizeof TREE_REAL_CST (node
); i
++)
139 fprintf (file
, "%02x", *p
++);
142 #endif /* REAL_IS_NOT_DOUBLE */
149 indent_to (file
, column
)
155 /* Since this is the long way, indent to desired column. */
157 fprintf (file
, "\n");
158 for (i
= 0; i
< column
; i
++)
162 /* Print the node NODE in full on file FILE, preceded by PREFIX,
163 starting in column INDENT. */
166 print_node (file
, prefix
, node
, indent
)
174 enum machine_mode mode
;
183 class = TREE_CODE_CLASS (TREE_CODE (node
));
185 /* Don't get too deep in nesting. If the user wants to see deeper,
186 it is easy to use the address of a lowest-level node
187 as an argument in another call to debug_tree. */
191 print_node_brief (file
, prefix
, node
, indent
);
195 if (indent
> 8 && (class == 't' || class == 'd'))
197 print_node_brief (file
, prefix
, node
, indent
);
201 /* It is unsafe to look at any other filds of an ERROR_MARK node. */
202 if (TREE_CODE (node
) == ERROR_MARK
)
204 print_node_brief (file
, prefix
, node
, indent
);
208 hash
= ((unsigned HOST_WIDE_INT
) node
) % HASH_SIZE
;
210 /* If node is in the table, just mention its address. */
211 for (b
= table
[hash
]; b
; b
= b
->next
)
214 print_node_brief (file
, prefix
, node
, indent
);
218 /* Add this node to the table. */
219 b
= (struct bucket
*) oballoc (sizeof (struct bucket
));
221 b
->next
= table
[hash
];
224 /* Indent to the specified column, since this is the long form. */
225 indent_to (file
, indent
);
227 /* Print the slot this node is in, and its code, and address. */
228 fprintf (file
, "%s <%s ", prefix
, tree_code_name
[(int) TREE_CODE (node
)]);
229 fprintf (file
, HOST_PTR_PRINTF
, (HOST_WIDE_INT
) node
);
231 /* Print the name, if any. */
234 if (DECL_NAME (node
))
235 fprintf (file
, " %s", IDENTIFIER_POINTER (DECL_NAME (node
)));
237 else if (class == 't')
239 if (TYPE_NAME (node
))
241 if (TREE_CODE (TYPE_NAME (node
)) == IDENTIFIER_NODE
)
242 fprintf (file
, " %s", IDENTIFIER_POINTER (TYPE_NAME (node
)));
243 else if (TREE_CODE (TYPE_NAME (node
)) == TYPE_DECL
244 && DECL_NAME (TYPE_NAME (node
)))
245 fprintf (file
, " %s",
246 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node
))));
249 if (TREE_CODE (node
) == IDENTIFIER_NODE
)
250 fprintf (file
, " %s", IDENTIFIER_POINTER (node
));
252 if (TREE_CODE (node
) == INTEGER_CST
)
255 print_node_brief (file
, "type", TREE_TYPE (node
), indent
+ 4);
259 print_node (file
, "type", TREE_TYPE (node
), indent
+ 4);
260 if (TREE_TYPE (node
))
261 indent_to (file
, indent
+ 3);
263 print_obstack_name ((char *) node
, file
, "");
264 indent_to (file
, indent
+ 3);
267 /* If a permanent object is in the wrong obstack, or the reverse, warn. */
268 if (object_permanent_p (node
) != TREE_PERMANENT (node
))
270 if (TREE_PERMANENT (node
))
271 fputs (" !!permanent object in non-permanent obstack!!", file
);
273 fputs (" !!non-permanent object in permanent obstack!!", file
);
274 indent_to (file
, indent
+ 3);
277 if (TREE_SIDE_EFFECTS (node
))
278 fputs (" side-effects", file
);
279 if (TREE_READONLY (node
))
280 fputs (" readonly", file
);
281 if (TREE_CONSTANT (node
))
282 fputs (" constant", file
);
283 if (TREE_ADDRESSABLE (node
))
284 fputs (" addressable", file
);
285 if (TREE_THIS_VOLATILE (node
))
286 fputs (" volatile", file
);
287 if (TREE_UNSIGNED (node
))
288 fputs (" unsigned", file
);
289 if (TREE_ASM_WRITTEN (node
))
290 fputs (" asm_written", file
);
291 if (TREE_USED (node
))
292 fputs (" used", file
);
293 if (TREE_RAISES (node
))
294 fputs (" raises", file
);
295 if (TREE_PERMANENT (node
))
296 fputs (" permanent", file
);
297 if (TREE_PUBLIC (node
))
298 fputs (" public", file
);
299 if (TREE_STATIC (node
))
300 fputs (" static", file
);
301 if (TREE_LANG_FLAG_0 (node
))
302 fputs (" tree_0", file
);
303 if (TREE_LANG_FLAG_1 (node
))
304 fputs (" tree_1", file
);
305 if (TREE_LANG_FLAG_2 (node
))
306 fputs (" tree_2", file
);
307 if (TREE_LANG_FLAG_3 (node
))
308 fputs (" tree_3", file
);
309 if (TREE_LANG_FLAG_4 (node
))
310 fputs (" tree_4", file
);
311 if (TREE_LANG_FLAG_5 (node
))
312 fputs (" tree_5", file
);
313 if (TREE_LANG_FLAG_6 (node
))
314 fputs (" tree_6", file
);
316 /* DECL_ nodes have additional attributes. */
318 switch (TREE_CODE_CLASS (TREE_CODE (node
)))
321 mode
= DECL_MODE (node
);
323 if (DECL_EXTERNAL (node
))
324 fputs (" external", file
);
325 if (DECL_NONLOCAL (node
))
326 fputs (" nonlocal", file
);
327 if (DECL_REGISTER (node
))
328 fputs (" regdecl", file
);
329 if (DECL_INLINE (node
))
330 fputs (" inline", file
);
331 if (DECL_BIT_FIELD (node
))
332 fputs (" bit-field", file
);
333 if (DECL_VIRTUAL_P (node
))
334 fputs (" virtual", file
);
335 if (DECL_IGNORED_P (node
))
336 fputs (" ignored", file
);
337 if (DECL_IN_SYSTEM_HEADER (node
))
338 fputs (" in_system_header", file
);
339 if (DECL_LANG_FLAG_0 (node
))
340 fputs (" decl_0", file
);
341 if (DECL_LANG_FLAG_1 (node
))
342 fputs (" decl_1", file
);
343 if (DECL_LANG_FLAG_2 (node
))
344 fputs (" decl_2", file
);
345 if (DECL_LANG_FLAG_3 (node
))
346 fputs (" decl_3", file
);
347 if (DECL_LANG_FLAG_4 (node
))
348 fputs (" decl_4", file
);
349 if (DECL_LANG_FLAG_5 (node
))
350 fputs (" decl_5", file
);
351 if (DECL_LANG_FLAG_6 (node
))
352 fputs (" decl_6", file
);
353 if (DECL_LANG_FLAG_7 (node
))
354 fputs (" decl_7", file
);
356 fprintf (file
, " %s", mode_name
[(int) mode
]);
358 fprintf (file
, " file %s line %d",
359 DECL_SOURCE_FILE (node
), DECL_SOURCE_LINE (node
));
361 print_node (file
, "size", DECL_SIZE (node
), indent
+ 4);
362 indent_to (file
, indent
+ 3);
363 if (TREE_CODE (node
) != FUNCTION_DECL
)
364 fprintf (file
, " align %d", DECL_ALIGN (node
));
365 else if (DECL_INLINE (node
))
366 fprintf (file
, " frame_size %d", DECL_FRAME_SIZE (node
));
367 else if (DECL_BUILT_IN (node
))
368 fprintf (file
, " built-in code %d", DECL_FUNCTION_CODE (node
));
369 if (TREE_CODE (node
) == FIELD_DECL
)
370 print_node (file
, "bitpos", DECL_FIELD_BITPOS (node
), indent
+ 4);
371 print_node_brief (file
, "context", DECL_CONTEXT (node
), indent
+ 4);
372 print_node_brief (file
, "abstract_origin",
373 DECL_ABSTRACT_ORIGIN (node
), indent
+ 4);
375 print_node (file
, "arguments", DECL_ARGUMENTS (node
), indent
+ 4);
376 print_node (file
, "result", DECL_RESULT (node
), indent
+ 4);
377 print_node_brief (file
, "initial", DECL_INITIAL (node
), indent
+ 4);
379 print_lang_decl (file
, node
, indent
);
381 if (DECL_RTL (node
) != 0)
383 indent_to (file
, indent
+ 4);
384 print_rtl (file
, DECL_RTL (node
));
387 if (DECL_SAVED_INSNS (node
) != 0)
389 indent_to (file
, indent
+ 4);
390 if (TREE_CODE (node
) == PARM_DECL
)
392 fprintf (file
, "incoming-rtl ");
393 print_rtl (file
, DECL_INCOMING_RTL (node
));
395 else if (TREE_CODE (node
) == FUNCTION_DECL
)
397 fprintf (file
, "saved-insns ");
398 fprintf (file
, HOST_PTR_PRINTF
,
399 (HOST_WIDE_INT
) DECL_SAVED_INSNS (node
));
403 /* Print the decl chain only if decl is at second level. */
405 print_node (file
, "chain", TREE_CHAIN (node
), indent
+ 4);
407 print_node_brief (file
, "chain", TREE_CHAIN (node
), indent
+ 4);
411 if (TYPE_NO_FORCE_BLK (node
))
412 fputs (" no_force_blk", file
);
413 if (TYPE_LANG_FLAG_0 (node
))
414 fputs (" type_0", file
);
415 if (TYPE_LANG_FLAG_1 (node
))
416 fputs (" type_1", file
);
417 if (TYPE_LANG_FLAG_2 (node
))
418 fputs (" type_2", file
);
419 if (TYPE_LANG_FLAG_3 (node
))
420 fputs (" type_3", file
);
421 if (TYPE_LANG_FLAG_4 (node
))
422 fputs (" type_4", file
);
423 if (TYPE_LANG_FLAG_5 (node
))
424 fputs (" type_5", file
);
425 if (TYPE_LANG_FLAG_6 (node
))
426 fputs (" type_6", file
);
428 mode
= TYPE_MODE (node
);
429 fprintf (file
, " %s", mode_name
[(int) mode
]);
431 print_node (file
, "size", TYPE_SIZE (node
), indent
+ 4);
432 indent_to (file
, indent
+ 3);
434 fprintf (file
, " align %d", TYPE_ALIGN (node
));
435 fprintf (file
, " symtab %d", TYPE_SYMTAB_ADDRESS (node
));
437 if (TREE_CODE (node
) == ARRAY_TYPE
|| TREE_CODE (node
) == SET_TYPE
)
438 print_node (file
, "domain", TYPE_DOMAIN (node
), indent
+ 4);
439 else if (TREE_CODE (node
) == INTEGER_TYPE
440 || TREE_CODE (node
) == BOOLEAN_TYPE
441 || TREE_CODE (node
) == CHAR_TYPE
)
443 fprintf (file
, " precision %d", TYPE_PRECISION (node
));
444 print_node (file
, "min", TYPE_MIN_VALUE (node
), indent
+ 4);
445 print_node (file
, "max", TYPE_MAX_VALUE (node
), indent
+ 4);
447 else if (TREE_CODE (node
) == ENUMERAL_TYPE
)
449 fprintf (file
, " precision %d", TYPE_PRECISION (node
));
450 print_node (file
, "min", TYPE_MIN_VALUE (node
), indent
+ 4);
451 print_node (file
, "max", TYPE_MAX_VALUE (node
), indent
+ 4);
452 print_node (file
, "values", TYPE_VALUES (node
), indent
+ 4);
454 else if (TREE_CODE (node
) == REAL_TYPE
)
455 fprintf (file
, " precision %d", TYPE_PRECISION (node
));
456 else if (TREE_CODE (node
) == RECORD_TYPE
457 || TREE_CODE (node
) == UNION_TYPE
458 || TREE_CODE (node
) == QUAL_UNION_TYPE
)
459 print_node (file
, "fields", TYPE_FIELDS (node
), indent
+ 4);
460 else if (TREE_CODE (node
) == FUNCTION_TYPE
|| TREE_CODE (node
) == METHOD_TYPE
)
462 if (TYPE_METHOD_BASETYPE (node
))
463 print_node_brief (file
, "method basetype", TYPE_METHOD_BASETYPE (node
), indent
+ 4);
464 print_node (file
, "arg-types", TYPE_ARG_TYPES (node
), indent
+ 4);
466 if (TYPE_CONTEXT (node
))
467 print_node_brief (file
, "context", TYPE_CONTEXT (node
), indent
+ 4);
469 print_lang_type (file
, node
, indent
);
471 if (TYPE_POINTER_TO (node
) || TREE_CHAIN (node
))
472 indent_to (file
, indent
+ 3);
473 print_node_brief (file
, "pointer_to_this", TYPE_POINTER_TO (node
), indent
+ 4);
474 print_node_brief (file
, "reference_to_this", TYPE_REFERENCE_TO (node
), indent
+ 4);
475 print_node_brief (file
, "chain", TREE_CHAIN (node
), indent
+ 4);
479 print_node (file
, "vars", BLOCK_VARS (node
), indent
+ 4);
480 print_node (file
, "tags", BLOCK_TYPE_TAGS (node
), indent
+ 4);
481 print_node (file
, "supercontext", BLOCK_SUPERCONTEXT (node
), indent
+ 4);
482 print_node (file
, "subblocks", BLOCK_SUBBLOCKS (node
), indent
+ 4);
483 print_node (file
, "chain", BLOCK_CHAIN (node
), indent
+ 4);
484 print_node (file
, "abstract_origin",
485 BLOCK_ABSTRACT_ORIGIN (node
), indent
+ 4);
494 switch (TREE_CODE (node
))
497 print_node (file
, "vars", TREE_OPERAND (node
, 0), indent
+ 4);
498 print_node (file
, "body", TREE_OPERAND (node
, 1), indent
+ 4);
499 print_node (file
, "block", TREE_OPERAND (node
, 2), indent
+ 4);
503 first_rtl
= len
= tree_code_length
[(int) TREE_CODE (node
)];
504 /* These kinds of nodes contain rtx's, not trees,
505 after a certain point. Print the rtx's as rtx's. */
506 switch (TREE_CODE (node
))
514 case METHOD_CALL_EXPR
:
517 case WITH_CLEANUP_EXPR
:
518 /* Should be defined to be 2. */
524 for (i
= 0; i
< len
; i
++)
528 indent_to (file
, indent
+ 4);
529 fprintf (file
, "rtl %d ", i
);
530 if (TREE_OPERAND (node
, i
))
531 print_rtl (file
, (struct rtx_def
*) TREE_OPERAND (node
, i
));
533 fprintf (file
, "(nil)");
534 fprintf (file
, "\n");
540 sprintf (temp
, "arg %d", i
);
541 print_node (file
, temp
, TREE_OPERAND (node
, i
), indent
+ 4);
548 switch (TREE_CODE (node
))
551 if (TREE_INT_CST_HIGH (node
) == 0)
552 fprintf (file
, " %1u", TREE_INT_CST_LOW (node
));
553 else if (TREE_INT_CST_HIGH (node
) == -1
554 && TREE_INT_CST_LOW (node
) != 0)
555 fprintf (file
, " -%1u", -TREE_INT_CST_LOW (node
));
558 #if HOST_BITS_PER_WIDE_INT == 64
559 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
565 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
571 TREE_INT_CST_HIGH (node
), TREE_INT_CST_LOW (node
));
575 #ifndef REAL_IS_NOT_DOUBLE
576 fprintf (file
, " %e", TREE_REAL_CST (node
));
579 char *p
= (char *) &TREE_REAL_CST (node
);
580 fprintf (file
, " 0x");
581 for (i
= 0; i
< sizeof TREE_REAL_CST (node
); i
++)
582 fprintf (file
, "%02x", *p
++);
585 #endif /* REAL_IS_NOT_DOUBLE */
589 print_node (file
, "real", TREE_REALPART (node
), indent
+ 4);
590 print_node (file
, "imag", TREE_IMAGPART (node
), indent
+ 4);
594 fprintf (file
, " \"%s\"", TREE_STRING_POINTER (node
));
595 /* Print the chain at second level. */
597 print_node (file
, "chain", TREE_CHAIN (node
), indent
+ 4);
599 print_node_brief (file
, "chain", TREE_CHAIN (node
), indent
+ 4);
602 case IDENTIFIER_NODE
:
603 print_lang_identifier (file
, node
, indent
);
607 print_node (file
, "purpose", TREE_PURPOSE (node
), indent
+ 4);
608 print_node (file
, "value", TREE_VALUE (node
), indent
+ 4);
609 print_node (file
, "chain", TREE_CHAIN (node
), indent
+ 4);
613 len
= TREE_VEC_LENGTH (node
);
614 for (i
= 0; i
< len
; i
++)
615 if (TREE_VEC_ELT (node
, i
))
618 sprintf (temp
, "elt %d", i
);
619 indent_to (file
, indent
+ 4);
620 print_node_brief (file
, temp
, TREE_VEC_ELT (node
, i
), 0);
625 print_node (file
, "op1", TREE_PURPOSE (node
), indent
+ 4);
626 print_node (file
, "op2", TREE_VALUE (node
), indent
+ 4);