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_CONSTANT_OVERFLOW (node))
108 fprintf (file, " overflow");
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));
117 #if HOST_BITS_PER_WIDE_INT == 64
118 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
124 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
130 TREE_INT_CST_HIGH (node), TREE_INT_CST_LOW (node));
132 if (TREE_CODE (node) == REAL_CST)
134 #ifndef REAL_IS_NOT_DOUBLE
135 fprintf (file, " %e", TREE_REAL_CST (node));
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++);
145 #endif /* REAL_IS_NOT_DOUBLE */
152 indent_to (file, column)
158 /* Since this is the long way, indent to desired column. */
160 fprintf (file, "\n");
161 for (i = 0; i < column; i++)
165 /* Print the node NODE in full on file FILE, preceded by PREFIX,
166 starting in column INDENT. */
169 print_node (file, prefix, node, indent)
177 enum machine_mode mode;
186 class = TREE_CODE_CLASS (TREE_CODE (node));
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. */
194 print_node_brief (file, prefix, node, indent);
198 if (indent > 8 && (class == 't' || class == 'd'))
200 print_node_brief (file, prefix, node, indent);
204 /* It is unsafe to look at any other filds of an ERROR_MARK node. */
205 if (TREE_CODE (node) == ERROR_MARK)
207 print_node_brief (file, prefix, node, indent);
211 hash = ((unsigned HOST_WIDE_INT) node) % HASH_SIZE;
213 /* If node is in the table, just mention its address. */
214 for (b = table[hash]; b; b = b->next)
217 print_node_brief (file, prefix, node, indent);
221 /* Add this node to the table. */
222 b = (struct bucket *) oballoc (sizeof (struct bucket));
224 b->next = table[hash];
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 fprintf (file, HOST_PTR_PRINTF, (HOST_WIDE_INT) node);
234 /* Print the name, if any. */
237 if (DECL_NAME (node))
238 fprintf (file, " %s", IDENTIFIER_POINTER (DECL_NAME (node)));
240 else if (class == 't')
242 if (TYPE_NAME (node))
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))));
252 if (TREE_CODE (node) == IDENTIFIER_NODE)
253 fprintf (file, " %s", IDENTIFIER_POINTER (node));
255 if (TREE_CODE (node) == INTEGER_CST)
258 print_node_brief (file, "type", TREE_TYPE (node), indent + 4);
262 print_node (file, "type", TREE_TYPE (node), indent + 4);
263 if (TREE_TYPE (node))
264 indent_to (file, indent + 3);
266 print_obstack_name ((char *) node, file, "");
267 indent_to (file, indent + 3);
270 /* If a permanent object is in the wrong obstack, or the reverse, warn. */
271 if (object_permanent_p (node) != TREE_PERMANENT (node))
273 if (TREE_PERMANENT (node))
274 fputs (" !!permanent object in non-permanent obstack!!", file);
276 fputs (" !!non-permanent object in permanent obstack!!", file);
277 indent_to (file, indent + 3);
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);
319 /* DECL_ nodes have additional attributes. */
321 switch (TREE_CODE_CLASS (TREE_CODE (node)))
324 mode = DECL_MODE (node);
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);
359 fprintf (file, " %s", mode_name[(int) mode]);
361 fprintf (file, " file %s line %d",
362 DECL_SOURCE_FILE (node), DECL_SOURCE_LINE (node));
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);
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);
382 print_lang_decl (file, node, indent);
384 if (DECL_RTL (node) != 0)
386 indent_to (file, indent + 4);
387 print_rtl (file, DECL_RTL (node));
390 if (DECL_SAVED_INSNS (node) != 0)
392 indent_to (file, indent + 4);
393 if (TREE_CODE (node) == PARM_DECL)
395 fprintf (file, "incoming-rtl ");
396 print_rtl (file, DECL_INCOMING_RTL (node));
398 else if (TREE_CODE (node) == FUNCTION_DECL)
400 fprintf (file, "saved-insns ");
401 fprintf (file, HOST_PTR_PRINTF,
402 (HOST_WIDE_INT) DECL_SAVED_INSNS (node));
406 /* Print the decl chain only if decl is at second level. */
408 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
410 print_node_brief (file, "chain", TREE_CHAIN (node), indent + 4);
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);
431 mode = TYPE_MODE (node);
432 fprintf (file, " %s", mode_name[(int) mode]);
434 print_node (file, "size", TYPE_SIZE (node), indent + 4);
435 indent_to (file, indent + 3);
437 fprintf (file, " align %d", TYPE_ALIGN (node));
438 fprintf (file, " symtab %d", TYPE_SYMTAB_ADDRESS (node));
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)
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);
450 else if (TREE_CODE (node) == ENUMERAL_TYPE)
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);
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)
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);
469 if (TYPE_CONTEXT (node))
470 print_node_brief (file, "context", TYPE_CONTEXT (node), indent + 4);
472 print_lang_type (file, node, indent);
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);
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);
497 switch (TREE_CODE (node))
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);
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))
517 case METHOD_CALL_EXPR:
520 case WITH_CLEANUP_EXPR:
521 /* Should be defined to be 2. */
527 for (i = 0; i < len; i++)
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));
536 fprintf (file, "(nil)");
537 fprintf (file, "\n");
543 sprintf (temp, "arg %d", i);
544 print_node (file, temp, TREE_OPERAND (node, i), indent + 4);
551 switch (TREE_CODE (node))
554 if (TREE_CONSTANT_OVERFLOW (node))
555 fprintf (file, " overflow");
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));
564 #if HOST_BITS_PER_WIDE_INT == 64
565 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
571 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
577 TREE_INT_CST_HIGH (node), TREE_INT_CST_LOW (node));
581 #ifndef REAL_IS_NOT_DOUBLE
582 fprintf (file, " %e", TREE_REAL_CST (node));
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++);
591 #endif /* REAL_IS_NOT_DOUBLE */
595 print_node (file, "real", TREE_REALPART (node), indent + 4);
596 print_node (file, "imag", TREE_IMAGPART (node), indent + 4);
600 fprintf (file, " \"%s\"", TREE_STRING_POINTER (node));
601 /* Print the chain at second level. */
603 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
605 print_node_brief (file, "chain", TREE_CHAIN (node), indent + 4);
608 case IDENTIFIER_NODE:
609 print_lang_identifier (file, node, indent);
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);
619 len = TREE_VEC_LENGTH (node);
620 for (i = 0; i < len; i++)
621 if (TREE_VEC_ELT (node, i))
624 sprintf (temp, "elt %d", i);
625 indent_to (file, indent + 4);
626 print_node_brief (file, temp, TREE_VEC_ELT (node, i), 0);
631 print_node (file, "op1", TREE_PURPOSE (node), indent + 4);
632 print_node (file, "op2", TREE_VALUE (node), indent + 4);