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