]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/print-tree.c
Re-factor tree.h - Part 1.
[thirdparty/gcc.git] / gcc / print-tree.c
1 /* Prints out tree in human readable form - GCC
2 Copyright (C) 1990-2013 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
10
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
19
20
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tm.h"
25 #include "tree.h"
26 #include "ggc.h"
27 #include "langhooks.h"
28 #include "tree-iterator.h"
29 #include "diagnostic.h"
30 #include "gimple-pretty-print.h" /* FIXME */
31 #include "cgraph.h"
32 #include "tree-cfg.h"
33 #include "tree-dump.h"
34 #include "dumpfile.h"
35
36 /* Define the hash table of nodes already seen.
37 Such nodes are not repeated; brief cross-references are used. */
38
39 #define HASH_SIZE 37
40
41 struct bucket
42 {
43 tree node;
44 struct bucket *next;
45 };
46
47 static struct bucket **table;
48
49 /* Print PREFIX and ADDR to FILE. */
50 void
51 dump_addr (FILE *file, const char *prefix, const void *addr)
52 {
53 if (flag_dump_noaddr || flag_dump_unnumbered)
54 fprintf (file, "%s#", prefix);
55 else
56 fprintf (file, "%s" HOST_PTR_PRINTF, prefix, addr);
57 }
58
59 /* Print a node in brief fashion, with just the code, address and name. */
60
61 void
62 print_node_brief (FILE *file, const char *prefix, const_tree node, int indent)
63 {
64 enum tree_code_class tclass;
65
66 if (node == 0)
67 return;
68
69 tclass = TREE_CODE_CLASS (TREE_CODE (node));
70
71 /* Always print the slot this node is in, and its code, address and
72 name if any. */
73 if (indent > 0)
74 fprintf (file, " ");
75 fprintf (file, "%s <%s", prefix, get_tree_code_name (TREE_CODE (node)));
76 dump_addr (file, " ", node);
77
78 if (tclass == tcc_declaration)
79 {
80 if (DECL_NAME (node))
81 fprintf (file, " %s", IDENTIFIER_POINTER (DECL_NAME (node)));
82 else if (TREE_CODE (node) == LABEL_DECL
83 && LABEL_DECL_UID (node) != -1)
84 {
85 if (dump_flags & TDF_NOUID)
86 fprintf (file, " L.xxxx");
87 else
88 fprintf (file, " L.%d", (int) LABEL_DECL_UID (node));
89 }
90 else
91 {
92 if (dump_flags & TDF_NOUID)
93 fprintf (file, " %c.xxxx",
94 TREE_CODE (node) == CONST_DECL ? 'C' : 'D');
95 else
96 fprintf (file, " %c.%u",
97 TREE_CODE (node) == CONST_DECL ? 'C' : 'D',
98 DECL_UID (node));
99 }
100 }
101 else if (tclass == tcc_type)
102 {
103 if (TYPE_NAME (node))
104 {
105 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
106 fprintf (file, " %s", IDENTIFIER_POINTER (TYPE_NAME (node)));
107 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
108 && DECL_NAME (TYPE_NAME (node)))
109 fprintf (file, " %s",
110 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node))));
111 }
112 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (node)))
113 fprintf (file, " address-space-%d", TYPE_ADDR_SPACE (node));
114 }
115 if (TREE_CODE (node) == IDENTIFIER_NODE)
116 fprintf (file, " %s", IDENTIFIER_POINTER (node));
117
118 /* We might as well always print the value of an integer or real. */
119 if (TREE_CODE (node) == INTEGER_CST)
120 {
121 if (TREE_OVERFLOW (node))
122 fprintf (file, " overflow");
123
124 fprintf (file, " ");
125 if (TREE_INT_CST_HIGH (node) == 0)
126 fprintf (file, HOST_WIDE_INT_PRINT_UNSIGNED, TREE_INT_CST_LOW (node));
127 else if (TREE_INT_CST_HIGH (node) == -1
128 && TREE_INT_CST_LOW (node) != 0)
129 fprintf (file, "-" HOST_WIDE_INT_PRINT_UNSIGNED,
130 -TREE_INT_CST_LOW (node));
131 else
132 fprintf (file, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
133 (unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (node),
134 (unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (node));
135 }
136 if (TREE_CODE (node) == REAL_CST)
137 {
138 REAL_VALUE_TYPE d;
139
140 if (TREE_OVERFLOW (node))
141 fprintf (file, " overflow");
142
143 d = TREE_REAL_CST (node);
144 if (REAL_VALUE_ISINF (d))
145 fprintf (file, REAL_VALUE_NEGATIVE (d) ? " -Inf" : " Inf");
146 else if (REAL_VALUE_ISNAN (d))
147 fprintf (file, " Nan");
148 else
149 {
150 char string[60];
151 real_to_decimal (string, &d, sizeof (string), 0, 1);
152 fprintf (file, " %s", string);
153 }
154 }
155 if (TREE_CODE (node) == FIXED_CST)
156 {
157 FIXED_VALUE_TYPE f;
158 char string[60];
159
160 if (TREE_OVERFLOW (node))
161 fprintf (file, " overflow");
162
163 f = TREE_FIXED_CST (node);
164 fixed_to_decimal (string, &f, sizeof (string));
165 fprintf (file, " %s", string);
166 }
167
168 fprintf (file, ">");
169 }
170
171 void
172 indent_to (FILE *file, int column)
173 {
174 int i;
175
176 /* Since this is the long way, indent to desired column. */
177 if (column > 0)
178 fprintf (file, "\n");
179 for (i = 0; i < column; i++)
180 fprintf (file, " ");
181 }
182 \f
183 /* Print the node NODE in full on file FILE, preceded by PREFIX,
184 starting in column INDENT. */
185
186 void
187 print_node (FILE *file, const char *prefix, tree node, int indent)
188 {
189 int hash;
190 struct bucket *b;
191 enum machine_mode mode;
192 enum tree_code_class tclass;
193 int len;
194 int i;
195 expanded_location xloc;
196 enum tree_code code;
197
198 if (node == 0)
199 return;
200
201 code = TREE_CODE (node);
202 tclass = TREE_CODE_CLASS (code);
203
204 /* Don't get too deep in nesting. If the user wants to see deeper,
205 it is easy to use the address of a lowest-level node
206 as an argument in another call to debug_tree. */
207
208 if (indent > 24)
209 {
210 print_node_brief (file, prefix, node, indent);
211 return;
212 }
213
214 if (indent > 8 && (tclass == tcc_type || tclass == tcc_declaration))
215 {
216 print_node_brief (file, prefix, node, indent);
217 return;
218 }
219
220 /* It is unsafe to look at any other fields of an ERROR_MARK node. */
221 if (code == ERROR_MARK)
222 {
223 print_node_brief (file, prefix, node, indent);
224 return;
225 }
226
227 /* Allow this function to be called if the table is not there. */
228 if (table)
229 {
230 hash = ((uintptr_t) node) % HASH_SIZE;
231
232 /* If node is in the table, just mention its address. */
233 for (b = table[hash]; b; b = b->next)
234 if (b->node == node)
235 {
236 print_node_brief (file, prefix, node, indent);
237 return;
238 }
239
240 /* Add this node to the table. */
241 b = XNEW (struct bucket);
242 b->node = node;
243 b->next = table[hash];
244 table[hash] = b;
245 }
246
247 /* Indent to the specified column, since this is the long form. */
248 indent_to (file, indent);
249
250 /* Print the slot this node is in, and its code, and address. */
251 fprintf (file, "%s <%s", prefix, get_tree_code_name (code));
252 dump_addr (file, " ", node);
253
254 /* Print the name, if any. */
255 if (tclass == tcc_declaration)
256 {
257 if (DECL_NAME (node))
258 fprintf (file, " %s", IDENTIFIER_POINTER (DECL_NAME (node)));
259 else if (code == LABEL_DECL
260 && LABEL_DECL_UID (node) != -1)
261 {
262 if (dump_flags & TDF_NOUID)
263 fprintf (file, " L.xxxx");
264 else
265 fprintf (file, " L.%d", (int) LABEL_DECL_UID (node));
266 }
267 else
268 {
269 if (dump_flags & TDF_NOUID)
270 fprintf (file, " %c.xxxx", code == CONST_DECL ? 'C' : 'D');
271 else
272 fprintf (file, " %c.%u", code == CONST_DECL ? 'C' : 'D',
273 DECL_UID (node));
274 }
275 }
276 else if (tclass == tcc_type)
277 {
278 if (TYPE_NAME (node))
279 {
280 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
281 fprintf (file, " %s", IDENTIFIER_POINTER (TYPE_NAME (node)));
282 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
283 && DECL_NAME (TYPE_NAME (node)))
284 fprintf (file, " %s",
285 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node))));
286 }
287 }
288 if (code == IDENTIFIER_NODE)
289 fprintf (file, " %s", IDENTIFIER_POINTER (node));
290
291 if (code == INTEGER_CST)
292 {
293 if (indent <= 4)
294 print_node_brief (file, "type", TREE_TYPE (node), indent + 4);
295 }
296 else if (CODE_CONTAINS_STRUCT (code, TS_TYPED))
297 {
298 print_node (file, "type", TREE_TYPE (node), indent + 4);
299 if (TREE_TYPE (node))
300 indent_to (file, indent + 3);
301 }
302
303 if (!TYPE_P (node) && TREE_SIDE_EFFECTS (node))
304 fputs (" side-effects", file);
305
306 if (TYPE_P (node) ? TYPE_READONLY (node) : TREE_READONLY (node))
307 fputs (" readonly", file);
308 if (TYPE_P (node) && TYPE_ATOMIC (node))
309 fputs (" atomic", file);
310 if (!TYPE_P (node) && TREE_CONSTANT (node))
311 fputs (" constant", file);
312 else if (TYPE_P (node) && TYPE_SIZES_GIMPLIFIED (node))
313 fputs (" sizes-gimplified", file);
314
315 if (TYPE_P (node) && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (node)))
316 fprintf (file, " address-space-%d", TYPE_ADDR_SPACE (node));
317
318 if (TREE_ADDRESSABLE (node))
319 fputs (" addressable", file);
320 if (TREE_THIS_VOLATILE (node))
321 fputs (" volatile", file);
322 if (TREE_ASM_WRITTEN (node))
323 fputs (" asm_written", file);
324 if (TREE_USED (node))
325 fputs (" used", file);
326 if (TREE_NOTHROW (node))
327 fputs (TYPE_P (node) ? " align-ok" : " nothrow", file);
328 if (TREE_PUBLIC (node))
329 fputs (" public", file);
330 if (TREE_PRIVATE (node))
331 fputs (" private", file);
332 if (TREE_PROTECTED (node))
333 fputs (" protected", file);
334 if (TREE_STATIC (node))
335 fputs (" static", file);
336 if (TREE_DEPRECATED (node))
337 fputs (" deprecated", file);
338 if (TREE_VISITED (node))
339 fputs (" visited", file);
340
341 if (code != TREE_VEC && code != SSA_NAME)
342 {
343 if (TREE_LANG_FLAG_0 (node))
344 fputs (" tree_0", file);
345 if (TREE_LANG_FLAG_1 (node))
346 fputs (" tree_1", file);
347 if (TREE_LANG_FLAG_2 (node))
348 fputs (" tree_2", file);
349 if (TREE_LANG_FLAG_3 (node))
350 fputs (" tree_3", file);
351 if (TREE_LANG_FLAG_4 (node))
352 fputs (" tree_4", file);
353 if (TREE_LANG_FLAG_5 (node))
354 fputs (" tree_5", file);
355 if (TREE_LANG_FLAG_6 (node))
356 fputs (" tree_6", file);
357 }
358
359 /* DECL_ nodes have additional attributes. */
360
361 switch (TREE_CODE_CLASS (code))
362 {
363 case tcc_declaration:
364 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
365 {
366 if (DECL_UNSIGNED (node))
367 fputs (" unsigned", file);
368 if (DECL_IGNORED_P (node))
369 fputs (" ignored", file);
370 if (DECL_ABSTRACT (node))
371 fputs (" abstract", file);
372 if (DECL_EXTERNAL (node))
373 fputs (" external", file);
374 if (DECL_NONLOCAL (node))
375 fputs (" nonlocal", file);
376 }
377 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
378 {
379 if (DECL_WEAK (node))
380 fputs (" weak", file);
381 if (DECL_IN_SYSTEM_HEADER (node))
382 fputs (" in_system_header", file);
383 }
384 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WRTL)
385 && code != LABEL_DECL
386 && code != FUNCTION_DECL
387 && DECL_REGISTER (node))
388 fputs (" regdecl", file);
389
390 if (code == TYPE_DECL && TYPE_DECL_SUPPRESS_DEBUG (node))
391 fputs (" suppress-debug", file);
392
393 if (code == FUNCTION_DECL
394 && DECL_FUNCTION_SPECIFIC_TARGET (node))
395 fputs (" function-specific-target", file);
396 if (code == FUNCTION_DECL
397 && DECL_FUNCTION_SPECIFIC_OPTIMIZATION (node))
398 fputs (" function-specific-opt", file);
399 if (code == FUNCTION_DECL && DECL_DECLARED_INLINE_P (node))
400 fputs (" autoinline", file);
401 if (code == FUNCTION_DECL && DECL_BUILT_IN (node))
402 fputs (" built-in", file);
403 if (code == FUNCTION_DECL && DECL_STATIC_CHAIN (node))
404 fputs (" static-chain", file);
405 if (TREE_CODE (node) == FUNCTION_DECL && decl_is_tm_clone (node))
406 fputs (" tm-clone", file);
407
408 if (code == FIELD_DECL && DECL_PACKED (node))
409 fputs (" packed", file);
410 if (code == FIELD_DECL && DECL_BIT_FIELD (node))
411 fputs (" bit-field", file);
412 if (code == FIELD_DECL && DECL_NONADDRESSABLE_P (node))
413 fputs (" nonaddressable", file);
414
415 if (code == LABEL_DECL && EH_LANDING_PAD_NR (node))
416 fprintf (file, " landing-pad:%d", EH_LANDING_PAD_NR (node));
417
418 if (code == VAR_DECL && DECL_IN_TEXT_SECTION (node))
419 fputs (" in-text-section", file);
420 if (code == VAR_DECL && DECL_IN_CONSTANT_POOL (node))
421 fputs (" in-constant-pool", file);
422 if (code == VAR_DECL && DECL_COMMON (node))
423 fputs (" common", file);
424 if (code == VAR_DECL && DECL_THREAD_LOCAL_P (node))
425 {
426 enum tls_model kind = DECL_TLS_MODEL (node);
427 switch (kind)
428 {
429 case TLS_MODEL_GLOBAL_DYNAMIC:
430 fputs (" tls-global-dynamic", file);
431 break;
432 case TLS_MODEL_LOCAL_DYNAMIC:
433 fputs (" tls-local-dynamic", file);
434 break;
435 case TLS_MODEL_INITIAL_EXEC:
436 fputs (" tls-initial-exec", file);
437 break;
438 case TLS_MODEL_LOCAL_EXEC:
439 fputs (" tls-local-exec", file);
440 break;
441 default:
442 gcc_unreachable ();
443 }
444 }
445
446 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
447 {
448 if (DECL_VIRTUAL_P (node))
449 fputs (" virtual", file);
450 if (DECL_PRESERVE_P (node))
451 fputs (" preserve", file);
452 if (DECL_LANG_FLAG_0 (node))
453 fputs (" decl_0", file);
454 if (DECL_LANG_FLAG_1 (node))
455 fputs (" decl_1", file);
456 if (DECL_LANG_FLAG_2 (node))
457 fputs (" decl_2", file);
458 if (DECL_LANG_FLAG_3 (node))
459 fputs (" decl_3", file);
460 if (DECL_LANG_FLAG_4 (node))
461 fputs (" decl_4", file);
462 if (DECL_LANG_FLAG_5 (node))
463 fputs (" decl_5", file);
464 if (DECL_LANG_FLAG_6 (node))
465 fputs (" decl_6", file);
466 if (DECL_LANG_FLAG_7 (node))
467 fputs (" decl_7", file);
468
469 mode = DECL_MODE (node);
470 fprintf (file, " %s", GET_MODE_NAME (mode));
471 }
472
473 if ((code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
474 && DECL_BY_REFERENCE (node))
475 fputs (" passed-by-reference", file);
476
477 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS) && DECL_DEFER_OUTPUT (node))
478 fputs (" defer-output", file);
479
480
481 xloc = expand_location (DECL_SOURCE_LOCATION (node));
482 fprintf (file, " file %s line %d col %d", xloc.file, xloc.line,
483 xloc.column);
484
485 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
486 {
487 print_node (file, "size", DECL_SIZE (node), indent + 4);
488 print_node (file, "unit size", DECL_SIZE_UNIT (node), indent + 4);
489
490 if (code != FUNCTION_DECL || DECL_BUILT_IN (node))
491 indent_to (file, indent + 3);
492
493 if (DECL_USER_ALIGN (node))
494 fprintf (file, " user");
495
496 fprintf (file, " align %d", DECL_ALIGN (node));
497 if (code == FIELD_DECL)
498 fprintf (file, " offset_align " HOST_WIDE_INT_PRINT_UNSIGNED,
499 DECL_OFFSET_ALIGN (node));
500
501 if (code == FUNCTION_DECL && DECL_BUILT_IN (node))
502 {
503 if (DECL_BUILT_IN_CLASS (node) == BUILT_IN_MD)
504 fprintf (file, " built-in BUILT_IN_MD %d", DECL_FUNCTION_CODE (node));
505 else
506 fprintf (file, " built-in %s:%s",
507 built_in_class_names[(int) DECL_BUILT_IN_CLASS (node)],
508 built_in_names[(int) DECL_FUNCTION_CODE (node)]);
509 }
510 }
511 if (code == FIELD_DECL)
512 {
513 print_node (file, "offset", DECL_FIELD_OFFSET (node), indent + 4);
514 print_node (file, "bit offset", DECL_FIELD_BIT_OFFSET (node),
515 indent + 4);
516 if (DECL_BIT_FIELD_TYPE (node))
517 print_node (file, "bit_field_type", DECL_BIT_FIELD_TYPE (node),
518 indent + 4);
519 }
520
521 print_node_brief (file, "context", DECL_CONTEXT (node), indent + 4);
522
523 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
524 {
525 print_node_brief (file, "attributes",
526 DECL_ATTRIBUTES (node), indent + 4);
527 if (code != PARM_DECL)
528 print_node_brief (file, "initial", DECL_INITIAL (node),
529 indent + 4);
530 }
531 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WRTL))
532 {
533 print_node_brief (file, "abstract_origin",
534 DECL_ABSTRACT_ORIGIN (node), indent + 4);
535 }
536 if (CODE_CONTAINS_STRUCT (code, TS_DECL_NON_COMMON))
537 {
538 print_node (file, "arguments", DECL_ARGUMENT_FLD (node), indent + 4);
539 print_node (file, "result", DECL_RESULT_FLD (node), indent + 4);
540 }
541
542 lang_hooks.print_decl (file, node, indent);
543
544 if (DECL_RTL_SET_P (node))
545 {
546 indent_to (file, indent + 4);
547 print_rtl (file, DECL_RTL (node));
548 }
549
550 if (code == PARM_DECL)
551 {
552 print_node (file, "arg-type", DECL_ARG_TYPE (node), indent + 4);
553
554 if (DECL_INCOMING_RTL (node) != 0)
555 {
556 indent_to (file, indent + 4);
557 fprintf (file, "incoming-rtl ");
558 print_rtl (file, DECL_INCOMING_RTL (node));
559 }
560 }
561 else if (code == FUNCTION_DECL
562 && DECL_STRUCT_FUNCTION (node) != 0)
563 {
564 indent_to (file, indent + 4);
565 dump_addr (file, "struct-function ", DECL_STRUCT_FUNCTION (node));
566 }
567
568 if ((code == VAR_DECL || code == PARM_DECL)
569 && DECL_HAS_VALUE_EXPR_P (node))
570 print_node (file, "value-expr", DECL_VALUE_EXPR (node), indent + 4);
571
572 /* Print the decl chain only if decl is at second level. */
573 if (indent == 4)
574 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
575 else
576 print_node_brief (file, "chain", TREE_CHAIN (node), indent + 4);
577 break;
578
579 case tcc_type:
580 if (TYPE_UNSIGNED (node))
581 fputs (" unsigned", file);
582
583 /* The no-force-blk flag is used for different things in
584 different types. */
585 if ((code == RECORD_TYPE
586 || code == UNION_TYPE
587 || code == QUAL_UNION_TYPE)
588 && TYPE_NO_FORCE_BLK (node))
589 fputs (" no-force-blk", file);
590
591 if (TYPE_STRING_FLAG (node))
592 fputs (" string-flag", file);
593 if (TYPE_NEEDS_CONSTRUCTING (node))
594 fputs (" needs-constructing", file);
595
596 /* The transparent-union flag is used for different things in
597 different nodes. */
598 if ((code == UNION_TYPE || code == RECORD_TYPE)
599 && TYPE_TRANSPARENT_AGGR (node))
600 fputs (" transparent-aggr", file);
601 else if (code == ARRAY_TYPE
602 && TYPE_NONALIASED_COMPONENT (node))
603 fputs (" nonaliased-component", file);
604
605 if (TYPE_PACKED (node))
606 fputs (" packed", file);
607
608 if (TYPE_RESTRICT (node))
609 fputs (" restrict", file);
610
611 if (TYPE_LANG_FLAG_0 (node))
612 fputs (" type_0", file);
613 if (TYPE_LANG_FLAG_1 (node))
614 fputs (" type_1", file);
615 if (TYPE_LANG_FLAG_2 (node))
616 fputs (" type_2", file);
617 if (TYPE_LANG_FLAG_3 (node))
618 fputs (" type_3", file);
619 if (TYPE_LANG_FLAG_4 (node))
620 fputs (" type_4", file);
621 if (TYPE_LANG_FLAG_5 (node))
622 fputs (" type_5", file);
623 if (TYPE_LANG_FLAG_6 (node))
624 fputs (" type_6", file);
625
626 mode = TYPE_MODE (node);
627 fprintf (file, " %s", GET_MODE_NAME (mode));
628
629 print_node (file, "size", TYPE_SIZE (node), indent + 4);
630 print_node (file, "unit size", TYPE_SIZE_UNIT (node), indent + 4);
631 indent_to (file, indent + 3);
632
633 if (TYPE_USER_ALIGN (node))
634 fprintf (file, " user");
635
636 fprintf (file, " align %d symtab %d alias set " HOST_WIDE_INT_PRINT_DEC,
637 TYPE_ALIGN (node), TYPE_SYMTAB_ADDRESS (node),
638 (HOST_WIDE_INT) TYPE_ALIAS_SET (node));
639
640 if (TYPE_STRUCTURAL_EQUALITY_P (node))
641 fprintf (file, " structural equality");
642 else
643 dump_addr (file, " canonical type ", TYPE_CANONICAL (node));
644
645 print_node (file, "attributes", TYPE_ATTRIBUTES (node), indent + 4);
646
647 if (INTEGRAL_TYPE_P (node) || code == REAL_TYPE
648 || code == FIXED_POINT_TYPE)
649 {
650 fprintf (file, " precision %d", TYPE_PRECISION (node));
651 print_node_brief (file, "min", TYPE_MIN_VALUE (node), indent + 4);
652 print_node_brief (file, "max", TYPE_MAX_VALUE (node), indent + 4);
653 }
654
655 if (code == ENUMERAL_TYPE)
656 print_node (file, "values", TYPE_VALUES (node), indent + 4);
657 else if (code == ARRAY_TYPE)
658 print_node (file, "domain", TYPE_DOMAIN (node), indent + 4);
659 else if (code == VECTOR_TYPE)
660 fprintf (file, " nunits %d", (int) TYPE_VECTOR_SUBPARTS (node));
661 else if (code == RECORD_TYPE
662 || code == UNION_TYPE
663 || code == QUAL_UNION_TYPE)
664 print_node (file, "fields", TYPE_FIELDS (node), indent + 4);
665 else if (code == FUNCTION_TYPE
666 || code == METHOD_TYPE)
667 {
668 if (TYPE_METHOD_BASETYPE (node))
669 print_node_brief (file, "method basetype",
670 TYPE_METHOD_BASETYPE (node), indent + 4);
671 print_node (file, "arg-types", TYPE_ARG_TYPES (node), indent + 4);
672 }
673 else if (code == OFFSET_TYPE)
674 print_node_brief (file, "basetype", TYPE_OFFSET_BASETYPE (node),
675 indent + 4);
676
677 if (TYPE_CONTEXT (node))
678 print_node_brief (file, "context", TYPE_CONTEXT (node), indent + 4);
679
680 lang_hooks.print_type (file, node, indent);
681
682 if (TYPE_POINTER_TO (node) || TREE_CHAIN (node))
683 indent_to (file, indent + 3);
684
685 print_node_brief (file, "pointer_to_this", TYPE_POINTER_TO (node),
686 indent + 4);
687 print_node_brief (file, "reference_to_this", TYPE_REFERENCE_TO (node),
688 indent + 4);
689 print_node_brief (file, "chain", TREE_CHAIN (node), indent + 4);
690 break;
691
692 case tcc_expression:
693 case tcc_comparison:
694 case tcc_unary:
695 case tcc_binary:
696 case tcc_reference:
697 case tcc_statement:
698 case tcc_vl_exp:
699 if (code == BIND_EXPR)
700 {
701 print_node (file, "vars", TREE_OPERAND (node, 0), indent + 4);
702 print_node (file, "body", TREE_OPERAND (node, 1), indent + 4);
703 print_node (file, "block", TREE_OPERAND (node, 2), indent + 4);
704 break;
705 }
706 if (code == CALL_EXPR)
707 {
708 call_expr_arg_iterator iter;
709 tree arg;
710 print_node (file, "fn", CALL_EXPR_FN (node), indent + 4);
711 print_node (file, "static_chain", CALL_EXPR_STATIC_CHAIN (node),
712 indent + 4);
713 i = 0;
714 FOR_EACH_CALL_EXPR_ARG (arg, iter, node)
715 {
716 char temp[10];
717 sprintf (temp, "arg %d", i);
718 print_node (file, temp, arg, indent + 4);
719 i++;
720 }
721 }
722 else
723 {
724 len = TREE_OPERAND_LENGTH (node);
725
726 for (i = 0; i < len; i++)
727 {
728 char temp[10];
729
730 sprintf (temp, "arg %d", i);
731 print_node (file, temp, TREE_OPERAND (node, i), indent + 4);
732 }
733 }
734 if (CODE_CONTAINS_STRUCT (code, TS_COMMON))
735 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
736 break;
737
738 case tcc_constant:
739 case tcc_exceptional:
740 switch (code)
741 {
742 case INTEGER_CST:
743 if (TREE_OVERFLOW (node))
744 fprintf (file, " overflow");
745
746 fprintf (file, " ");
747 if (TREE_INT_CST_HIGH (node) == 0)
748 fprintf (file, HOST_WIDE_INT_PRINT_UNSIGNED,
749 TREE_INT_CST_LOW (node));
750 else if (TREE_INT_CST_HIGH (node) == -1
751 && TREE_INT_CST_LOW (node) != 0)
752 fprintf (file, "-" HOST_WIDE_INT_PRINT_UNSIGNED,
753 -TREE_INT_CST_LOW (node));
754 else
755 fprintf (file, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
756 (unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (node),
757 (unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (node));
758 break;
759
760 case REAL_CST:
761 {
762 REAL_VALUE_TYPE d;
763
764 if (TREE_OVERFLOW (node))
765 fprintf (file, " overflow");
766
767 d = TREE_REAL_CST (node);
768 if (REAL_VALUE_ISINF (d))
769 fprintf (file, REAL_VALUE_NEGATIVE (d) ? " -Inf" : " Inf");
770 else if (REAL_VALUE_ISNAN (d))
771 fprintf (file, " Nan");
772 else
773 {
774 char string[64];
775 real_to_decimal (string, &d, sizeof (string), 0, 1);
776 fprintf (file, " %s", string);
777 }
778 }
779 break;
780
781 case FIXED_CST:
782 {
783 FIXED_VALUE_TYPE f;
784 char string[64];
785
786 if (TREE_OVERFLOW (node))
787 fprintf (file, " overflow");
788
789 f = TREE_FIXED_CST (node);
790 fixed_to_decimal (string, &f, sizeof (string));
791 fprintf (file, " %s", string);
792 }
793 break;
794
795 case VECTOR_CST:
796 {
797 char buf[10];
798 unsigned i;
799
800 for (i = 0; i < VECTOR_CST_NELTS (node); ++i)
801 {
802 sprintf (buf, "elt%u: ", i);
803 print_node (file, buf, VECTOR_CST_ELT (node, i), indent + 4);
804 }
805 }
806 break;
807
808 case COMPLEX_CST:
809 print_node (file, "real", TREE_REALPART (node), indent + 4);
810 print_node (file, "imag", TREE_IMAGPART (node), indent + 4);
811 break;
812
813 case STRING_CST:
814 {
815 const char *p = TREE_STRING_POINTER (node);
816 int i = TREE_STRING_LENGTH (node);
817 fputs (" \"", file);
818 while (--i >= 0)
819 {
820 char ch = *p++;
821 if (ch >= ' ' && ch < 127)
822 putc (ch, file);
823 else
824 fprintf (file, "\\%03o", ch & 0xFF);
825 }
826 fputc ('\"', file);
827 }
828 break;
829
830 case IDENTIFIER_NODE:
831 lang_hooks.print_identifier (file, node, indent);
832 break;
833
834 case TREE_LIST:
835 print_node (file, "purpose", TREE_PURPOSE (node), indent + 4);
836 print_node (file, "value", TREE_VALUE (node), indent + 4);
837 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
838 break;
839
840 case TREE_VEC:
841 len = TREE_VEC_LENGTH (node);
842 for (i = 0; i < len; i++)
843 if (TREE_VEC_ELT (node, i))
844 {
845 char temp[10];
846 sprintf (temp, "elt %d", i);
847 print_node (file, temp, TREE_VEC_ELT (node, i), indent + 4);
848 }
849 break;
850
851 case CONSTRUCTOR:
852 {
853 unsigned HOST_WIDE_INT cnt;
854 tree index, value;
855 len = vec_safe_length (CONSTRUCTOR_ELTS (node));
856 fprintf (file, " lngt %d", len);
857 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (node),
858 cnt, index, value)
859 {
860 print_node (file, "idx", index, indent + 4);
861 print_node (file, "val", value, indent + 4);
862 }
863 }
864 break;
865
866 case STATEMENT_LIST:
867 dump_addr (file, " head ", node->stmt_list.head);
868 dump_addr (file, " tail ", node->stmt_list.tail);
869 fprintf (file, " stmts");
870 {
871 tree_stmt_iterator i;
872 for (i = tsi_start (node); !tsi_end_p (i); tsi_next (&i))
873 {
874 /* Not printing the addresses of the (not-a-tree)
875 'struct tree_stmt_list_node's. */
876 dump_addr (file, " ", tsi_stmt (i));
877 }
878 fprintf (file, "\n");
879 for (i = tsi_start (node); !tsi_end_p (i); tsi_next (&i))
880 {
881 /* Not printing the addresses of the (not-a-tree)
882 'struct tree_stmt_list_node's. */
883 print_node (file, "stmt", tsi_stmt (i), indent + 4);
884 }
885 }
886 break;
887
888 case BLOCK:
889 print_node (file, "vars", BLOCK_VARS (node), indent + 4);
890 print_node (file, "supercontext", BLOCK_SUPERCONTEXT (node),
891 indent + 4);
892 print_node (file, "subblocks", BLOCK_SUBBLOCKS (node), indent + 4);
893 print_node (file, "chain", BLOCK_CHAIN (node), indent + 4);
894 print_node (file, "abstract_origin",
895 BLOCK_ABSTRACT_ORIGIN (node), indent + 4);
896 break;
897
898 case SSA_NAME:
899 print_node_brief (file, "var", SSA_NAME_VAR (node), indent + 4);
900 fprintf (file, "def_stmt ");
901 print_gimple_stmt (file, SSA_NAME_DEF_STMT (node), indent + 4, 0);
902
903 indent_to (file, indent + 4);
904 fprintf (file, "version %u", SSA_NAME_VERSION (node));
905 if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (node))
906 fprintf (file, " in-abnormal-phi");
907 if (SSA_NAME_IN_FREE_LIST (node))
908 fprintf (file, " in-free-list");
909
910 if (SSA_NAME_PTR_INFO (node))
911 {
912 indent_to (file, indent + 3);
913 if (SSA_NAME_PTR_INFO (node))
914 dump_addr (file, " ptr-info ", SSA_NAME_PTR_INFO (node));
915 }
916 break;
917
918 case OMP_CLAUSE:
919 {
920 int i;
921 fprintf (file, " %s",
922 omp_clause_code_name[OMP_CLAUSE_CODE (node)]);
923 for (i = 0; i < omp_clause_num_ops[OMP_CLAUSE_CODE (node)]; i++)
924 {
925 indent_to (file, indent + 4);
926 fprintf (file, "op %d:", i);
927 print_node_brief (file, "", OMP_CLAUSE_OPERAND (node, i), 0);
928 }
929 }
930 break;
931
932 case OPTIMIZATION_NODE:
933 cl_optimization_print (file, indent + 4, TREE_OPTIMIZATION (node));
934 break;
935
936 case TARGET_OPTION_NODE:
937 cl_target_option_print (file, indent + 4, TREE_TARGET_OPTION (node));
938 break;
939 case IMPORTED_DECL:
940 fprintf (file, " imported declaration");
941 print_node_brief (file, "associated declaration",
942 IMPORTED_DECL_ASSOCIATED_DECL (node),
943 indent + 4);
944 break;
945
946 default:
947 if (EXCEPTIONAL_CLASS_P (node))
948 lang_hooks.print_xnode (file, node, indent);
949 break;
950 }
951
952 break;
953 }
954
955 if (EXPR_HAS_LOCATION (node))
956 {
957 expanded_location xloc = expand_location (EXPR_LOCATION (node));
958 indent_to (file, indent+4);
959 fprintf (file, "%s:%d:%d", xloc.file, xloc.line, xloc.column);
960 }
961
962 fprintf (file, ">");
963 }
964
965
966 /* Print the node NODE on standard error, for debugging.
967 Most nodes referred to by this one are printed recursively
968 down to a depth of six. */
969
970 DEBUG_FUNCTION void
971 debug_tree (tree node)
972 {
973 table = XCNEWVEC (struct bucket *, HASH_SIZE);
974 print_node (stderr, "", node, 0);
975 free (table);
976 table = 0;
977 putc ('\n', stderr);
978 }
979
980 DEBUG_FUNCTION void
981 debug_raw (const tree_node &ref)
982 {
983 debug_tree (const_cast <tree> (&ref));
984 }
985
986 DEBUG_FUNCTION void
987 debug_raw (const tree_node *ptr)
988 {
989 if (ptr)
990 debug_raw (*ptr);
991 else
992 fprintf (stderr, "<nil>\n");
993 }
994
995 static void
996 dump_tree_via_hooks (const tree_node *ptr, int options)
997 {
998 if (DECL_P (ptr))
999 lang_hooks.print_decl (stderr, const_cast <tree_node*> (ptr), 0);
1000 else if (TYPE_P (ptr))
1001 lang_hooks.print_type (stderr, const_cast <tree_node*> (ptr), 0);
1002 else if (TREE_CODE (ptr) == IDENTIFIER_NODE)
1003 lang_hooks.print_identifier (stderr, const_cast <tree_node*> (ptr), 0);
1004 else
1005 print_generic_expr (stderr, const_cast <tree_node*> (ptr), options);
1006 fprintf (stderr, "\n");
1007 }
1008
1009 DEBUG_FUNCTION void
1010 debug (const tree_node &ref)
1011 {
1012 dump_tree_via_hooks (&ref, 0);
1013 }
1014
1015 DEBUG_FUNCTION void
1016 debug (const tree_node *ptr)
1017 {
1018 if (ptr)
1019 debug (*ptr);
1020 else
1021 fprintf (stderr, "<nil>\n");
1022 }
1023
1024 DEBUG_FUNCTION void
1025 debug_verbose (const tree_node &ref)
1026 {
1027 dump_tree_via_hooks (&ref, TDF_VERBOSE);
1028 }
1029
1030 DEBUG_FUNCTION void
1031 debug_verbose (const tree_node *ptr)
1032 {
1033 if (ptr)
1034 debug_verbose (*ptr);
1035 else
1036 fprintf (stderr, "<nil>\n");
1037 }
1038
1039 DEBUG_FUNCTION void
1040 debug_head (const tree_node &ref)
1041 {
1042 debug (ref);
1043 }
1044
1045 DEBUG_FUNCTION void
1046 debug_head (const tree_node *ptr)
1047 {
1048 if (ptr)
1049 debug_head (*ptr);
1050 else
1051 fprintf (stderr, "<nil>\n");
1052 }
1053
1054 DEBUG_FUNCTION void
1055 debug_body (const tree_node &ref)
1056 {
1057 if (TREE_CODE (&ref) == FUNCTION_DECL)
1058 dump_function_to_file (const_cast <tree_node*> (&ref), stderr, 0);
1059 else
1060 debug (ref);
1061 }
1062
1063 DEBUG_FUNCTION void
1064 debug_body (const tree_node *ptr)
1065 {
1066 if (ptr)
1067 debug_body (*ptr);
1068 else
1069 fprintf (stderr, "<nil>\n");
1070 }
1071
1072 /* Print the vector of trees VEC on standard error, for debugging.
1073 Most nodes referred to by this one are printed recursively
1074 down to a depth of six. */
1075
1076 DEBUG_FUNCTION void
1077 debug_raw (vec<tree, va_gc> &ref)
1078 {
1079 tree elt;
1080 unsigned ix;
1081
1082 /* Print the slot this node is in, and its code, and address. */
1083 fprintf (stderr, "<VEC");
1084 dump_addr (stderr, " ", ref.address ());
1085
1086 FOR_EACH_VEC_ELT (ref, ix, elt)
1087 {
1088 fprintf (stderr, "elt %d ", ix);
1089 debug_raw (elt);
1090 }
1091 }
1092
1093 DEBUG_FUNCTION void
1094 debug (vec<tree, va_gc> &ref)
1095 {
1096 tree elt;
1097 unsigned ix;
1098
1099 /* Print the slot this node is in, and its code, and address. */
1100 fprintf (stderr, "<VEC");
1101 dump_addr (stderr, " ", ref.address ());
1102
1103 FOR_EACH_VEC_ELT (ref, ix, elt)
1104 {
1105 fprintf (stderr, "elt %d ", ix);
1106 debug (elt);
1107 }
1108 }
1109
1110 DEBUG_FUNCTION void
1111 debug (vec<tree, va_gc> *ptr)
1112 {
1113 if (ptr)
1114 debug (*ptr);
1115 else
1116 fprintf (stderr, "<nil>\n");
1117 }
1118
1119 DEBUG_FUNCTION void
1120 debug_raw (vec<tree, va_gc> *ptr)
1121 {
1122 if (ptr)
1123 debug_raw (*ptr);
1124 else
1125 fprintf (stderr, "<nil>\n");
1126 }
1127
1128 DEBUG_FUNCTION void
1129 debug_vec_tree (vec<tree, va_gc> *vec)
1130 {
1131 debug_raw (vec);
1132 }