1 /* Prints out tree in human readable form - GNU C-compiler
2 Copyright (C) 1990, 1991, 1993, 1994 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);
55 table = (struct bucket **) oballoc (HASH_SIZE * sizeof (struct bucket *));
56 bzero ((char *) table, HASH_SIZE * sizeof (struct bucket *));
57 print_node (stderr, "", node, 0);
60 fprintf (stderr, "\n");
63 /* Print a node in brief fashion, with just the code, address and name. */
66 print_node_brief (file, prefix, node, indent)
77 class = TREE_CODE_CLASS (TREE_CODE (node));
79 /* Always print the slot this node is in, and its code, address and
83 fprintf (file, "%s <%s ", prefix, tree_code_name[(int) TREE_CODE (node)]);
84 fprintf (file, HOST_PTR_PRINTF, (HOST_WIDE_INT) node);
89 fprintf (file, " %s", IDENTIFIER_POINTER (DECL_NAME (node)));
91 else if (class == 't')
95 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
96 fprintf (file, " %s", IDENTIFIER_POINTER (TYPE_NAME (node)));
97 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
98 && DECL_NAME (TYPE_NAME (node)))
100 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node))));
103 if (TREE_CODE (node) == IDENTIFIER_NODE)
104 fprintf (file, " %s", IDENTIFIER_POINTER (node));
105 /* We might as well always print the value of an integer. */
106 if (TREE_CODE (node) == INTEGER_CST)
108 if (TREE_CONSTANT_OVERFLOW (node))
109 fprintf (file, " overflow");
111 if (TREE_INT_CST_HIGH (node) == 0)
113 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
118 TREE_INT_CST_LOW (node));
119 else if (TREE_INT_CST_HIGH (node) == -1
120 && TREE_INT_CST_LOW (node) != 0)
122 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
127 -TREE_INT_CST_LOW (node));
130 #if HOST_BITS_PER_WIDE_INT == 64
131 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
137 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
143 TREE_INT_CST_HIGH (node), TREE_INT_CST_LOW (node));
145 if (TREE_CODE (node) == REAL_CST)
147 #ifndef REAL_IS_NOT_DOUBLE
148 fprintf (file, " %e", TREE_REAL_CST (node));
152 unsigned char *p = (unsigned char *) &TREE_REAL_CST (node);
153 fprintf (file, " 0x");
154 for (i = 0; i < sizeof TREE_REAL_CST (node); i++)
155 fprintf (file, "%02x", *p++);
158 #endif /* REAL_IS_NOT_DOUBLE */
165 indent_to (file, column)
171 /* Since this is the long way, indent to desired column. */
173 fprintf (file, "\n");
174 for (i = 0; i < column; i++)
178 /* Print the node NODE in full on file FILE, preceded by PREFIX,
179 starting in column INDENT. */
182 print_node (file, prefix, node, indent)
190 enum machine_mode mode;
199 class = TREE_CODE_CLASS (TREE_CODE (node));
201 /* Don't get too deep in nesting. If the user wants to see deeper,
202 it is easy to use the address of a lowest-level node
203 as an argument in another call to debug_tree. */
207 print_node_brief (file, prefix, node, indent);
211 if (indent > 8 && (class == 't' || class == 'd'))
213 print_node_brief (file, prefix, node, indent);
217 /* It is unsafe to look at any other filds of an ERROR_MARK node. */
218 if (TREE_CODE (node) == ERROR_MARK)
220 print_node_brief (file, prefix, node, indent);
224 hash = ((unsigned HOST_WIDE_INT) node) % HASH_SIZE;
226 /* If node is in the table, just mention its address. */
227 for (b = table[hash]; b; b = b->next)
230 print_node_brief (file, prefix, node, indent);
234 /* Add this node to the table. */
235 b = (struct bucket *) oballoc (sizeof (struct bucket));
237 b->next = table[hash];
240 /* Indent to the specified column, since this is the long form. */
241 indent_to (file, indent);
243 /* Print the slot this node is in, and its code, and address. */
244 fprintf (file, "%s <%s ", prefix, tree_code_name[(int) TREE_CODE (node)]);
245 fprintf (file, HOST_PTR_PRINTF, (HOST_WIDE_INT) node);
247 /* Print the name, if any. */
250 if (DECL_NAME (node))
251 fprintf (file, " %s", IDENTIFIER_POINTER (DECL_NAME (node)));
253 else if (class == 't')
255 if (TYPE_NAME (node))
257 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
258 fprintf (file, " %s", IDENTIFIER_POINTER (TYPE_NAME (node)));
259 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
260 && DECL_NAME (TYPE_NAME (node)))
261 fprintf (file, " %s",
262 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node))));
265 if (TREE_CODE (node) == IDENTIFIER_NODE)
266 fprintf (file, " %s", IDENTIFIER_POINTER (node));
268 if (TREE_CODE (node) == INTEGER_CST)
271 print_node_brief (file, "type", TREE_TYPE (node), indent + 4);
275 print_node (file, "type", TREE_TYPE (node), indent + 4);
276 if (TREE_TYPE (node))
277 indent_to (file, indent + 3);
279 print_obstack_name ((char *) node, file, "");
280 indent_to (file, indent + 3);
283 /* If a permanent object is in the wrong obstack, or the reverse, warn. */
284 if (object_permanent_p (node) != TREE_PERMANENT (node))
286 if (TREE_PERMANENT (node))
287 fputs (" !!permanent object in non-permanent obstack!!", file);
289 fputs (" !!non-permanent object in permanent obstack!!", file);
290 indent_to (file, indent + 3);
293 if (TREE_SIDE_EFFECTS (node))
294 fputs (" side-effects", file);
295 if (TREE_READONLY (node))
296 fputs (" readonly", file);
297 if (TREE_CONSTANT (node))
298 fputs (" constant", file);
299 if (TREE_ADDRESSABLE (node))
300 fputs (" addressable", file);
301 if (TREE_THIS_VOLATILE (node))
302 fputs (" volatile", file);
303 if (TREE_UNSIGNED (node))
304 fputs (" unsigned", file);
305 if (TREE_ASM_WRITTEN (node))
306 fputs (" asm_written", file);
307 if (TREE_USED (node))
308 fputs (" used", file);
309 if (TREE_RAISES (node))
310 fputs (" raises", file);
311 if (TREE_PERMANENT (node))
312 fputs (" permanent", file);
313 if (TREE_PUBLIC (node))
314 fputs (" public", file);
315 if (TREE_STATIC (node))
316 fputs (" static", file);
317 if (TREE_LANG_FLAG_0 (node))
318 fputs (" tree_0", file);
319 if (TREE_LANG_FLAG_1 (node))
320 fputs (" tree_1", file);
321 if (TREE_LANG_FLAG_2 (node))
322 fputs (" tree_2", file);
323 if (TREE_LANG_FLAG_3 (node))
324 fputs (" tree_3", file);
325 if (TREE_LANG_FLAG_4 (node))
326 fputs (" tree_4", file);
327 if (TREE_LANG_FLAG_5 (node))
328 fputs (" tree_5", file);
329 if (TREE_LANG_FLAG_6 (node))
330 fputs (" tree_6", file);
332 /* DECL_ nodes have additional attributes. */
334 switch (TREE_CODE_CLASS (TREE_CODE (node)))
337 mode = DECL_MODE (node);
339 if (DECL_EXTERNAL (node))
340 fputs (" external", file);
341 if (DECL_NONLOCAL (node))
342 fputs (" nonlocal", file);
343 if (DECL_REGISTER (node))
344 fputs (" regdecl", file);
345 if (DECL_INLINE (node))
346 fputs (" inline", file);
347 if (DECL_BIT_FIELD (node))
348 fputs (" bit-field", file);
349 if (DECL_VIRTUAL_P (node))
350 fputs (" virtual", file);
351 if (DECL_IGNORED_P (node))
352 fputs (" ignored", file);
353 if (DECL_IN_SYSTEM_HEADER (node))
354 fputs (" in_system_header", file);
355 if (DECL_LANG_FLAG_0 (node))
356 fputs (" decl_0", file);
357 if (DECL_LANG_FLAG_1 (node))
358 fputs (" decl_1", file);
359 if (DECL_LANG_FLAG_2 (node))
360 fputs (" decl_2", file);
361 if (DECL_LANG_FLAG_3 (node))
362 fputs (" decl_3", file);
363 if (DECL_LANG_FLAG_4 (node))
364 fputs (" decl_4", file);
365 if (DECL_LANG_FLAG_5 (node))
366 fputs (" decl_5", file);
367 if (DECL_LANG_FLAG_6 (node))
368 fputs (" decl_6", file);
369 if (DECL_LANG_FLAG_7 (node))
370 fputs (" decl_7", file);
372 fprintf (file, " %s", mode_name[(int) mode]);
374 fprintf (file, " file %s line %d",
375 DECL_SOURCE_FILE (node), DECL_SOURCE_LINE (node));
377 print_node (file, "size", DECL_SIZE (node), indent + 4);
378 indent_to (file, indent + 3);
379 if (TREE_CODE (node) != FUNCTION_DECL)
380 fprintf (file, " align %d", DECL_ALIGN (node));
381 else if (DECL_INLINE (node))
382 fprintf (file, " frame_size %d", DECL_FRAME_SIZE (node));
383 else if (DECL_BUILT_IN (node))
384 fprintf (file, " built-in code %d", DECL_FUNCTION_CODE (node));
385 if (TREE_CODE (node) == FIELD_DECL)
386 print_node (file, "bitpos", DECL_FIELD_BITPOS (node), indent + 4);
387 print_node_brief (file, "context", DECL_CONTEXT (node), indent + 4);
388 print_node_brief (file, "abstract_origin",
389 DECL_ABSTRACT_ORIGIN (node), indent + 4);
391 print_node (file, "arguments", DECL_ARGUMENTS (node), indent + 4);
392 print_node (file, "result", DECL_RESULT (node), indent + 4);
393 print_node_brief (file, "initial", DECL_INITIAL (node), indent + 4);
395 print_lang_decl (file, node, indent);
397 if (DECL_RTL (node) != 0)
399 indent_to (file, indent + 4);
400 print_rtl (file, DECL_RTL (node));
403 if (DECL_SAVED_INSNS (node) != 0)
405 indent_to (file, indent + 4);
406 if (TREE_CODE (node) == PARM_DECL)
408 fprintf (file, "incoming-rtl ");
409 print_rtl (file, DECL_INCOMING_RTL (node));
411 else if (TREE_CODE (node) == FUNCTION_DECL)
413 fprintf (file, "saved-insns ");
414 fprintf (file, HOST_PTR_PRINTF,
415 (HOST_WIDE_INT) DECL_SAVED_INSNS (node));
419 /* Print the decl chain only if decl is at second level. */
421 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
423 print_node_brief (file, "chain", TREE_CHAIN (node), indent + 4);
427 if (TYPE_NO_FORCE_BLK (node))
428 fputs (" no_force_blk", file);
429 if (TYPE_LANG_FLAG_0 (node))
430 fputs (" type_0", file);
431 if (TYPE_LANG_FLAG_1 (node))
432 fputs (" type_1", file);
433 if (TYPE_LANG_FLAG_2 (node))
434 fputs (" type_2", file);
435 if (TYPE_LANG_FLAG_3 (node))
436 fputs (" type_3", file);
437 if (TYPE_LANG_FLAG_4 (node))
438 fputs (" type_4", file);
439 if (TYPE_LANG_FLAG_5 (node))
440 fputs (" type_5", file);
441 if (TYPE_LANG_FLAG_6 (node))
442 fputs (" type_6", file);
444 mode = TYPE_MODE (node);
445 fprintf (file, " %s", mode_name[(int) mode]);
447 print_node (file, "size", TYPE_SIZE (node), indent + 4);
448 indent_to (file, indent + 3);
450 fprintf (file, " align %d", TYPE_ALIGN (node));
451 fprintf (file, " symtab %d", TYPE_SYMTAB_ADDRESS (node));
453 print_node (file, "attributes", TYPE_ATTRIBUTES (node), indent + 4);
455 if (TREE_CODE (node) == ARRAY_TYPE || TREE_CODE (node) == SET_TYPE)
456 print_node (file, "domain", TYPE_DOMAIN (node), indent + 4);
457 else if (TREE_CODE (node) == INTEGER_TYPE
458 || TREE_CODE (node) == BOOLEAN_TYPE
459 || TREE_CODE (node) == CHAR_TYPE)
461 fprintf (file, " precision %d", TYPE_PRECISION (node));
462 print_node (file, "min", TYPE_MIN_VALUE (node), indent + 4);
463 print_node (file, "max", TYPE_MAX_VALUE (node), indent + 4);
465 else if (TREE_CODE (node) == ENUMERAL_TYPE)
467 fprintf (file, " precision %d", TYPE_PRECISION (node));
468 print_node (file, "min", TYPE_MIN_VALUE (node), indent + 4);
469 print_node (file, "max", TYPE_MAX_VALUE (node), indent + 4);
470 print_node (file, "values", TYPE_VALUES (node), indent + 4);
472 else if (TREE_CODE (node) == REAL_TYPE)
473 fprintf (file, " precision %d", TYPE_PRECISION (node));
474 else if (TREE_CODE (node) == RECORD_TYPE
475 || TREE_CODE (node) == UNION_TYPE
476 || TREE_CODE (node) == QUAL_UNION_TYPE)
477 print_node (file, "fields", TYPE_FIELDS (node), indent + 4);
478 else if (TREE_CODE (node) == FUNCTION_TYPE || TREE_CODE (node) == METHOD_TYPE)
480 if (TYPE_METHOD_BASETYPE (node))
481 print_node_brief (file, "method basetype", TYPE_METHOD_BASETYPE (node), indent + 4);
482 print_node (file, "arg-types", TYPE_ARG_TYPES (node), indent + 4);
484 if (TYPE_CONTEXT (node))
485 print_node_brief (file, "context", TYPE_CONTEXT (node), indent + 4);
487 print_lang_type (file, node, indent);
489 if (TYPE_POINTER_TO (node) || TREE_CHAIN (node))
490 indent_to (file, indent + 3);
491 print_node_brief (file, "pointer_to_this", TYPE_POINTER_TO (node), indent + 4);
492 print_node_brief (file, "reference_to_this", TYPE_REFERENCE_TO (node), indent + 4);
493 print_node_brief (file, "chain", TREE_CHAIN (node), indent + 4);
497 print_node (file, "vars", BLOCK_VARS (node), indent + 4);
498 print_node (file, "tags", BLOCK_TYPE_TAGS (node), indent + 4);
499 print_node (file, "supercontext", BLOCK_SUPERCONTEXT (node), indent + 4);
500 print_node (file, "subblocks", BLOCK_SUBBLOCKS (node), indent + 4);
501 print_node (file, "chain", BLOCK_CHAIN (node), indent + 4);
502 print_node (file, "abstract_origin",
503 BLOCK_ABSTRACT_ORIGIN (node), indent + 4);
512 switch (TREE_CODE (node))
515 print_node (file, "vars", TREE_OPERAND (node, 0), indent + 4);
516 print_node (file, "body", TREE_OPERAND (node, 1), indent + 4);
517 print_node (file, "block", TREE_OPERAND (node, 2), indent + 4);
521 first_rtl = len = tree_code_length[(int) TREE_CODE (node)];
522 /* These kinds of nodes contain rtx's, not trees,
523 after a certain point. Print the rtx's as rtx's. */
524 switch (TREE_CODE (node))
532 case METHOD_CALL_EXPR:
535 case WITH_CLEANUP_EXPR:
536 /* Should be defined to be 2. */
542 for (i = 0; i < len; i++)
546 indent_to (file, indent + 4);
547 fprintf (file, "rtl %d ", i);
548 if (TREE_OPERAND (node, i))
549 print_rtl (file, (struct rtx_def *) TREE_OPERAND (node, i));
551 fprintf (file, "(nil)");
552 fprintf (file, "\n");
558 sprintf (temp, "arg %d", i);
559 print_node (file, temp, TREE_OPERAND (node, i), indent + 4);
566 switch (TREE_CODE (node))
569 if (TREE_CONSTANT_OVERFLOW (node))
570 fprintf (file, " overflow");
572 if (TREE_INT_CST_HIGH (node) == 0)
574 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
579 TREE_INT_CST_LOW (node));
580 else if (TREE_INT_CST_HIGH (node) == -1
581 && TREE_INT_CST_LOW (node) != 0)
583 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
588 -TREE_INT_CST_LOW (node));
591 #if HOST_BITS_PER_WIDE_INT == 64
592 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
598 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
604 TREE_INT_CST_HIGH (node), TREE_INT_CST_LOW (node));
608 #ifndef REAL_IS_NOT_DOUBLE
609 fprintf (file, " %e", TREE_REAL_CST (node));
612 char *p = (char *) &TREE_REAL_CST (node);
613 fprintf (file, " 0x");
614 for (i = 0; i < sizeof TREE_REAL_CST (node); i++)
615 fprintf (file, "%02x", *p++);
618 #endif /* REAL_IS_NOT_DOUBLE */
622 print_node (file, "real", TREE_REALPART (node), indent + 4);
623 print_node (file, "imag", TREE_IMAGPART (node), indent + 4);
627 fprintf (file, " \"%s\"", TREE_STRING_POINTER (node));
628 /* Print the chain at second level. */
630 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
632 print_node_brief (file, "chain", TREE_CHAIN (node), indent + 4);
635 case IDENTIFIER_NODE:
636 print_lang_identifier (file, node, indent);
640 print_node (file, "purpose", TREE_PURPOSE (node), indent + 4);
641 print_node (file, "value", TREE_VALUE (node), indent + 4);
642 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
646 len = TREE_VEC_LENGTH (node);
647 for (i = 0; i < len; i++)
648 if (TREE_VEC_ELT (node, i))
651 sprintf (temp, "elt %d", i);
652 indent_to (file, indent + 4);
653 print_node_brief (file, temp, TREE_VEC_ELT (node, i), 0);
658 print_node (file, "op1", TREE_PURPOSE (node), indent + 4);
659 print_node (file, "op2", TREE_VALUE (node), indent + 4);