decl.c (value_annotation_hasher::handle_cache_entry): Delete.
[gcc.git] / gcc / print-tree.c
1 /* Prints out tree in human readable form - GCC
2 Copyright (C) 1990-2015 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 "alias.h"
26 #include "symtab.h"
27 #include "tree.h"
28 #include "varasm.h"
29 #include "print-rtl.h"
30 #include "stor-layout.h"
31 #include "langhooks.h"
32 #include "tree-iterator.h"
33 #include "diagnostic.h"
34 #include "gimple-pretty-print.h" /* FIXME */
35 #include "plugin-api.h"
36 #include "hard-reg-set.h"
37 #include "function.h"
38 #include "ipa-ref.h"
39 #include "cgraph.h"
40 #include "tree-cfg.h"
41 #include "tree-dump.h"
42 #include "dumpfile.h"
43 #include "wide-int-print.h"
44
45 /* Define the hash table of nodes already seen.
46 Such nodes are not repeated; brief cross-references are used. */
47
48 #define HASH_SIZE 37
49
50 struct bucket
51 {
52 tree node;
53 struct bucket *next;
54 };
55
56 static struct bucket **table;
57
58 /* Print PREFIX and ADDR to FILE. */
59 void
60 dump_addr (FILE *file, const char *prefix, const void *addr)
61 {
62 if (flag_dump_noaddr || flag_dump_unnumbered)
63 fprintf (file, "%s#", prefix);
64 else
65 fprintf (file, "%s" HOST_PTR_PRINTF, prefix, addr);
66 }
67
68 /* Print a node in brief fashion, with just the code, address and name. */
69
70 void
71 print_node_brief (FILE *file, const char *prefix, const_tree node, int indent)
72 {
73 enum tree_code_class tclass;
74
75 if (node == 0)
76 return;
77
78 tclass = TREE_CODE_CLASS (TREE_CODE (node));
79
80 /* Always print the slot this node is in, and its code, address and
81 name if any. */
82 if (indent > 0)
83 fprintf (file, " ");
84 fprintf (file, "%s <%s", prefix, get_tree_code_name (TREE_CODE (node)));
85 dump_addr (file, " ", node);
86
87 if (tclass == tcc_declaration)
88 {
89 if (DECL_NAME (node))
90 fprintf (file, " %s", IDENTIFIER_POINTER (DECL_NAME (node)));
91 else if (TREE_CODE (node) == LABEL_DECL
92 && LABEL_DECL_UID (node) != -1)
93 {
94 if (dump_flags & TDF_NOUID)
95 fprintf (file, " L.xxxx");
96 else
97 fprintf (file, " L.%d", (int) LABEL_DECL_UID (node));
98 }
99 else
100 {
101 if (dump_flags & TDF_NOUID)
102 fprintf (file, " %c.xxxx",
103 TREE_CODE (node) == CONST_DECL ? 'C' : 'D');
104 else
105 fprintf (file, " %c.%u",
106 TREE_CODE (node) == CONST_DECL ? 'C' : 'D',
107 DECL_UID (node));
108 }
109 }
110 else if (tclass == tcc_type)
111 {
112 if (TYPE_NAME (node))
113 {
114 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
115 fprintf (file, " %s", IDENTIFIER_POINTER (TYPE_NAME (node)));
116 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
117 && DECL_NAME (TYPE_NAME (node)))
118 fprintf (file, " %s",
119 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node))));
120 }
121 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (node)))
122 fprintf (file, " address-space-%d", TYPE_ADDR_SPACE (node));
123 }
124 if (TREE_CODE (node) == IDENTIFIER_NODE)
125 fprintf (file, " %s", IDENTIFIER_POINTER (node));
126
127 /* We might as well always print the value of an integer or real. */
128 if (TREE_CODE (node) == INTEGER_CST)
129 {
130 if (TREE_OVERFLOW (node))
131 fprintf (file, " overflow");
132
133 fprintf (file, " ");
134 print_dec (node, file, TYPE_SIGN (TREE_TYPE (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 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 != INTEGER_CST && 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_P (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 fputs (" ", file);
427 fputs (tls_model_names[DECL_TLS_MODEL (node)], file);
428 }
429
430 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
431 {
432 if (DECL_VIRTUAL_P (node))
433 fputs (" virtual", file);
434 if (DECL_PRESERVE_P (node))
435 fputs (" preserve", file);
436 if (DECL_LANG_FLAG_0 (node))
437 fputs (" decl_0", file);
438 if (DECL_LANG_FLAG_1 (node))
439 fputs (" decl_1", file);
440 if (DECL_LANG_FLAG_2 (node))
441 fputs (" decl_2", file);
442 if (DECL_LANG_FLAG_3 (node))
443 fputs (" decl_3", file);
444 if (DECL_LANG_FLAG_4 (node))
445 fputs (" decl_4", file);
446 if (DECL_LANG_FLAG_5 (node))
447 fputs (" decl_5", file);
448 if (DECL_LANG_FLAG_6 (node))
449 fputs (" decl_6", file);
450 if (DECL_LANG_FLAG_7 (node))
451 fputs (" decl_7", file);
452
453 mode = DECL_MODE (node);
454 fprintf (file, " %s", GET_MODE_NAME (mode));
455 }
456
457 if ((code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
458 && DECL_BY_REFERENCE (node))
459 fputs (" passed-by-reference", file);
460
461 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS) && DECL_DEFER_OUTPUT (node))
462 fputs (" defer-output", file);
463
464
465 xloc = expand_location (DECL_SOURCE_LOCATION (node));
466 fprintf (file, " file %s line %d col %d", xloc.file, xloc.line,
467 xloc.column);
468
469 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
470 {
471 print_node (file, "size", DECL_SIZE (node), indent + 4);
472 print_node (file, "unit size", DECL_SIZE_UNIT (node), indent + 4);
473
474 if (code != FUNCTION_DECL || DECL_BUILT_IN (node))
475 indent_to (file, indent + 3);
476
477 if (DECL_USER_ALIGN (node))
478 fprintf (file, " user");
479
480 fprintf (file, " align %d", DECL_ALIGN (node));
481 if (code == FIELD_DECL)
482 fprintf (file, " offset_align " HOST_WIDE_INT_PRINT_UNSIGNED,
483 DECL_OFFSET_ALIGN (node));
484
485 if (code == FUNCTION_DECL && DECL_BUILT_IN (node))
486 {
487 if (DECL_BUILT_IN_CLASS (node) == BUILT_IN_MD)
488 fprintf (file, " built-in BUILT_IN_MD %d", DECL_FUNCTION_CODE (node));
489 else
490 fprintf (file, " built-in %s:%s",
491 built_in_class_names[(int) DECL_BUILT_IN_CLASS (node)],
492 built_in_names[(int) DECL_FUNCTION_CODE (node)]);
493 }
494 }
495 if (code == FIELD_DECL)
496 {
497 print_node (file, "offset", DECL_FIELD_OFFSET (node), indent + 4);
498 print_node (file, "bit offset", DECL_FIELD_BIT_OFFSET (node),
499 indent + 4);
500 if (DECL_BIT_FIELD_TYPE (node))
501 print_node (file, "bit_field_type", DECL_BIT_FIELD_TYPE (node),
502 indent + 4);
503 }
504
505 print_node_brief (file, "context", DECL_CONTEXT (node), indent + 4);
506
507 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
508 {
509 print_node_brief (file, "attributes",
510 DECL_ATTRIBUTES (node), indent + 4);
511 if (code != PARM_DECL)
512 print_node_brief (file, "initial", DECL_INITIAL (node),
513 indent + 4);
514 }
515 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WRTL))
516 {
517 print_node_brief (file, "abstract_origin",
518 DECL_ABSTRACT_ORIGIN (node), indent + 4);
519 }
520 if (CODE_CONTAINS_STRUCT (code, TS_DECL_NON_COMMON))
521 {
522 print_node (file, "result", DECL_RESULT_FLD (node), indent + 4);
523 }
524
525 lang_hooks.print_decl (file, node, indent);
526
527 if (DECL_RTL_SET_P (node))
528 {
529 indent_to (file, indent + 4);
530 print_rtl (file, DECL_RTL (node));
531 }
532
533 if (code == PARM_DECL)
534 {
535 print_node (file, "arg-type", DECL_ARG_TYPE (node), indent + 4);
536
537 if (DECL_INCOMING_RTL (node) != 0)
538 {
539 indent_to (file, indent + 4);
540 fprintf (file, "incoming-rtl ");
541 print_rtl (file, DECL_INCOMING_RTL (node));
542 }
543 }
544 else if (code == FUNCTION_DECL
545 && DECL_STRUCT_FUNCTION (node) != 0)
546 {
547 print_node (file, "arguments", DECL_ARGUMENTS (node), indent + 4);
548 indent_to (file, indent + 4);
549 dump_addr (file, "struct-function ", DECL_STRUCT_FUNCTION (node));
550 }
551
552 if ((code == VAR_DECL || code == PARM_DECL)
553 && DECL_HAS_VALUE_EXPR_P (node))
554 print_node (file, "value-expr", DECL_VALUE_EXPR (node), indent + 4);
555
556 /* Print the decl chain only if decl is at second level. */
557 if (indent == 4)
558 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
559 else
560 print_node_brief (file, "chain", TREE_CHAIN (node), indent + 4);
561 break;
562
563 case tcc_type:
564 if (TYPE_UNSIGNED (node))
565 fputs (" unsigned", file);
566
567 if (TYPE_NO_FORCE_BLK (node))
568 fputs (" no-force-blk", file);
569
570 if (TYPE_STRING_FLAG (node))
571 fputs (" string-flag", file);
572
573 if (TYPE_NEEDS_CONSTRUCTING (node))
574 fputs (" needs-constructing", file);
575
576 /* The transparent-union flag is used for different things in
577 different nodes. */
578 if ((code == UNION_TYPE || code == RECORD_TYPE)
579 && TYPE_TRANSPARENT_AGGR (node))
580 fputs (" transparent-aggr", file);
581 else if (code == ARRAY_TYPE
582 && TYPE_NONALIASED_COMPONENT (node))
583 fputs (" nonaliased-component", file);
584
585 if (TYPE_PACKED (node))
586 fputs (" packed", file);
587
588 if (TYPE_RESTRICT (node))
589 fputs (" restrict", file);
590
591 if (TYPE_LANG_FLAG_0 (node))
592 fputs (" type_0", file);
593 if (TYPE_LANG_FLAG_1 (node))
594 fputs (" type_1", file);
595 if (TYPE_LANG_FLAG_2 (node))
596 fputs (" type_2", file);
597 if (TYPE_LANG_FLAG_3 (node))
598 fputs (" type_3", file);
599 if (TYPE_LANG_FLAG_4 (node))
600 fputs (" type_4", file);
601 if (TYPE_LANG_FLAG_5 (node))
602 fputs (" type_5", file);
603 if (TYPE_LANG_FLAG_6 (node))
604 fputs (" type_6", file);
605
606 mode = TYPE_MODE (node);
607 fprintf (file, " %s", GET_MODE_NAME (mode));
608
609 print_node (file, "size", TYPE_SIZE (node), indent + 4);
610 print_node (file, "unit size", TYPE_SIZE_UNIT (node), indent + 4);
611 indent_to (file, indent + 3);
612
613 if (TYPE_USER_ALIGN (node))
614 fprintf (file, " user");
615
616 fprintf (file, " align %d symtab %d alias set " HOST_WIDE_INT_PRINT_DEC,
617 TYPE_ALIGN (node), TYPE_SYMTAB_ADDRESS (node),
618 (HOST_WIDE_INT) TYPE_ALIAS_SET (node));
619
620 if (TYPE_STRUCTURAL_EQUALITY_P (node))
621 fprintf (file, " structural equality");
622 else
623 dump_addr (file, " canonical type ", TYPE_CANONICAL (node));
624
625 print_node (file, "attributes", TYPE_ATTRIBUTES (node), indent + 4);
626
627 if (INTEGRAL_TYPE_P (node) || code == REAL_TYPE
628 || code == FIXED_POINT_TYPE)
629 {
630 fprintf (file, " precision %d", TYPE_PRECISION (node));
631 print_node_brief (file, "min", TYPE_MIN_VALUE (node), indent + 4);
632 print_node_brief (file, "max", TYPE_MAX_VALUE (node), indent + 4);
633 }
634
635 if (code == ENUMERAL_TYPE)
636 print_node (file, "values", TYPE_VALUES (node), indent + 4);
637 else if (code == ARRAY_TYPE)
638 print_node (file, "domain", TYPE_DOMAIN (node), indent + 4);
639 else if (code == VECTOR_TYPE)
640 fprintf (file, " nunits %d", (int) TYPE_VECTOR_SUBPARTS (node));
641 else if (code == RECORD_TYPE
642 || code == UNION_TYPE
643 || code == QUAL_UNION_TYPE)
644 print_node (file, "fields", TYPE_FIELDS (node), indent + 4);
645 else if (code == FUNCTION_TYPE
646 || code == METHOD_TYPE)
647 {
648 if (TYPE_METHOD_BASETYPE (node))
649 print_node_brief (file, "method basetype",
650 TYPE_METHOD_BASETYPE (node), indent + 4);
651 print_node (file, "arg-types", TYPE_ARG_TYPES (node), indent + 4);
652 }
653 else if (code == OFFSET_TYPE)
654 print_node_brief (file, "basetype", TYPE_OFFSET_BASETYPE (node),
655 indent + 4);
656
657 if (TYPE_CONTEXT (node))
658 print_node_brief (file, "context", TYPE_CONTEXT (node), indent + 4);
659
660 lang_hooks.print_type (file, node, indent);
661
662 if (TYPE_POINTER_TO (node) || TREE_CHAIN (node))
663 indent_to (file, indent + 3);
664
665 print_node_brief (file, "pointer_to_this", TYPE_POINTER_TO (node),
666 indent + 4);
667 print_node_brief (file, "reference_to_this", TYPE_REFERENCE_TO (node),
668 indent + 4);
669 print_node_brief (file, "chain", TREE_CHAIN (node), indent + 4);
670 break;
671
672 case tcc_expression:
673 case tcc_comparison:
674 case tcc_unary:
675 case tcc_binary:
676 case tcc_reference:
677 case tcc_statement:
678 case tcc_vl_exp:
679 if (code == BIND_EXPR)
680 {
681 print_node (file, "vars", TREE_OPERAND (node, 0), indent + 4);
682 print_node (file, "body", TREE_OPERAND (node, 1), indent + 4);
683 print_node (file, "block", TREE_OPERAND (node, 2), indent + 4);
684 break;
685 }
686 if (code == CALL_EXPR)
687 {
688 call_expr_arg_iterator iter;
689 tree arg;
690 print_node (file, "fn", CALL_EXPR_FN (node), indent + 4);
691 print_node (file, "static_chain", CALL_EXPR_STATIC_CHAIN (node),
692 indent + 4);
693 i = 0;
694 FOR_EACH_CALL_EXPR_ARG (arg, iter, node)
695 {
696 char temp[10];
697 sprintf (temp, "arg %d", i);
698 print_node (file, temp, arg, indent + 4);
699 i++;
700 }
701 }
702 else
703 {
704 len = TREE_OPERAND_LENGTH (node);
705
706 for (i = 0; i < len; i++)
707 {
708 char temp[10];
709
710 sprintf (temp, "arg %d", i);
711 print_node (file, temp, TREE_OPERAND (node, i), indent + 4);
712 }
713 }
714 if (CODE_CONTAINS_STRUCT (code, TS_COMMON))
715 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
716 break;
717
718 case tcc_constant:
719 case tcc_exceptional:
720 switch (code)
721 {
722 case INTEGER_CST:
723 if (TREE_OVERFLOW (node))
724 fprintf (file, " overflow");
725
726 fprintf (file, " ");
727 print_dec (node, file, TYPE_SIGN (TREE_TYPE (node)));
728 break;
729
730 case REAL_CST:
731 {
732 REAL_VALUE_TYPE d;
733
734 if (TREE_OVERFLOW (node))
735 fprintf (file, " overflow");
736
737 d = TREE_REAL_CST (node);
738 if (REAL_VALUE_ISINF (d))
739 fprintf (file, REAL_VALUE_NEGATIVE (d) ? " -Inf" : " Inf");
740 else if (REAL_VALUE_ISNAN (d))
741 fprintf (file, " Nan");
742 else
743 {
744 char string[64];
745 real_to_decimal (string, &d, sizeof (string), 0, 1);
746 fprintf (file, " %s", string);
747 }
748 }
749 break;
750
751 case FIXED_CST:
752 {
753 FIXED_VALUE_TYPE f;
754 char string[64];
755
756 if (TREE_OVERFLOW (node))
757 fprintf (file, " overflow");
758
759 f = TREE_FIXED_CST (node);
760 fixed_to_decimal (string, &f, sizeof (string));
761 fprintf (file, " %s", string);
762 }
763 break;
764
765 case VECTOR_CST:
766 {
767 char buf[10];
768 unsigned i;
769
770 for (i = 0; i < VECTOR_CST_NELTS (node); ++i)
771 {
772 sprintf (buf, "elt%u: ", i);
773 print_node (file, buf, VECTOR_CST_ELT (node, i), indent + 4);
774 }
775 }
776 break;
777
778 case COMPLEX_CST:
779 print_node (file, "real", TREE_REALPART (node), indent + 4);
780 print_node (file, "imag", TREE_IMAGPART (node), indent + 4);
781 break;
782
783 case STRING_CST:
784 {
785 const char *p = TREE_STRING_POINTER (node);
786 int i = TREE_STRING_LENGTH (node);
787 fputs (" \"", file);
788 while (--i >= 0)
789 {
790 char ch = *p++;
791 if (ch >= ' ' && ch < 127)
792 putc (ch, file);
793 else
794 fprintf (file, "\\%03o", ch & 0xFF);
795 }
796 fputc ('\"', file);
797 }
798 break;
799
800 case IDENTIFIER_NODE:
801 lang_hooks.print_identifier (file, node, indent);
802 break;
803
804 case TREE_LIST:
805 print_node (file, "purpose", TREE_PURPOSE (node), indent + 4);
806 print_node (file, "value", TREE_VALUE (node), indent + 4);
807 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
808 break;
809
810 case TREE_VEC:
811 len = TREE_VEC_LENGTH (node);
812 for (i = 0; i < len; i++)
813 if (TREE_VEC_ELT (node, i))
814 {
815 char temp[10];
816 sprintf (temp, "elt %d", i);
817 print_node (file, temp, TREE_VEC_ELT (node, i), indent + 4);
818 }
819 break;
820
821 case CONSTRUCTOR:
822 {
823 unsigned HOST_WIDE_INT cnt;
824 tree index, value;
825 len = vec_safe_length (CONSTRUCTOR_ELTS (node));
826 fprintf (file, " lngt %d", len);
827 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (node),
828 cnt, index, value)
829 {
830 print_node (file, "idx", index, indent + 4);
831 print_node (file, "val", value, indent + 4);
832 }
833 }
834 break;
835
836 case STATEMENT_LIST:
837 dump_addr (file, " head ", node->stmt_list.head);
838 dump_addr (file, " tail ", node->stmt_list.tail);
839 fprintf (file, " stmts");
840 {
841 tree_stmt_iterator i;
842 for (i = tsi_start (node); !tsi_end_p (i); tsi_next (&i))
843 {
844 /* Not printing the addresses of the (not-a-tree)
845 'struct tree_stmt_list_node's. */
846 dump_addr (file, " ", tsi_stmt (i));
847 }
848 fprintf (file, "\n");
849 for (i = tsi_start (node); !tsi_end_p (i); tsi_next (&i))
850 {
851 /* Not printing the addresses of the (not-a-tree)
852 'struct tree_stmt_list_node's. */
853 print_node (file, "stmt", tsi_stmt (i), indent + 4);
854 }
855 }
856 break;
857
858 case BLOCK:
859 print_node (file, "vars", BLOCK_VARS (node), indent + 4);
860 print_node (file, "supercontext", BLOCK_SUPERCONTEXT (node),
861 indent + 4);
862 print_node (file, "subblocks", BLOCK_SUBBLOCKS (node), indent + 4);
863 print_node (file, "chain", BLOCK_CHAIN (node), indent + 4);
864 print_node (file, "abstract_origin",
865 BLOCK_ABSTRACT_ORIGIN (node), indent + 4);
866 break;
867
868 case SSA_NAME:
869 print_node_brief (file, "var", SSA_NAME_VAR (node), indent + 4);
870 fprintf (file, "def_stmt ");
871 print_gimple_stmt (file, SSA_NAME_DEF_STMT (node), indent + 4, 0);
872
873 indent_to (file, indent + 4);
874 fprintf (file, "version %u", SSA_NAME_VERSION (node));
875 if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (node))
876 fprintf (file, " in-abnormal-phi");
877 if (SSA_NAME_IN_FREE_LIST (node))
878 fprintf (file, " in-free-list");
879
880 if (SSA_NAME_PTR_INFO (node))
881 {
882 indent_to (file, indent + 3);
883 if (SSA_NAME_PTR_INFO (node))
884 dump_addr (file, " ptr-info ", SSA_NAME_PTR_INFO (node));
885 }
886 break;
887
888 case OMP_CLAUSE:
889 {
890 int i;
891 fprintf (file, " %s",
892 omp_clause_code_name[OMP_CLAUSE_CODE (node)]);
893 for (i = 0; i < omp_clause_num_ops[OMP_CLAUSE_CODE (node)]; i++)
894 {
895 indent_to (file, indent + 4);
896 fprintf (file, "op %d:", i);
897 print_node_brief (file, "", OMP_CLAUSE_OPERAND (node, i), 0);
898 }
899 }
900 break;
901
902 case OPTIMIZATION_NODE:
903 cl_optimization_print (file, indent + 4, TREE_OPTIMIZATION (node));
904 break;
905
906 case TARGET_OPTION_NODE:
907 cl_target_option_print (file, indent + 4, TREE_TARGET_OPTION (node));
908 break;
909 case IMPORTED_DECL:
910 fprintf (file, " imported declaration");
911 print_node_brief (file, "associated declaration",
912 IMPORTED_DECL_ASSOCIATED_DECL (node),
913 indent + 4);
914 break;
915
916 default:
917 if (EXCEPTIONAL_CLASS_P (node))
918 lang_hooks.print_xnode (file, node, indent);
919 break;
920 }
921
922 break;
923 }
924
925 if (EXPR_HAS_LOCATION (node))
926 {
927 expanded_location xloc = expand_location (EXPR_LOCATION (node));
928 indent_to (file, indent+4);
929 fprintf (file, "%s:%d:%d", xloc.file, xloc.line, xloc.column);
930 }
931
932 fprintf (file, ">");
933 }
934
935
936 /* Print the node NODE on standard error, for debugging.
937 Most nodes referred to by this one are printed recursively
938 down to a depth of six. */
939
940 DEBUG_FUNCTION void
941 debug_tree (tree node)
942 {
943 table = XCNEWVEC (struct bucket *, HASH_SIZE);
944 print_node (stderr, "", node, 0);
945 free (table);
946 table = 0;
947 putc ('\n', stderr);
948 }
949
950 DEBUG_FUNCTION void
951 debug_raw (const tree_node &ref)
952 {
953 debug_tree (const_cast <tree> (&ref));
954 }
955
956 DEBUG_FUNCTION void
957 debug_raw (const tree_node *ptr)
958 {
959 if (ptr)
960 debug_raw (*ptr);
961 else
962 fprintf (stderr, "<nil>\n");
963 }
964
965 static void
966 dump_tree_via_hooks (const tree_node *ptr, int options)
967 {
968 if (DECL_P (ptr))
969 lang_hooks.print_decl (stderr, const_cast <tree_node*> (ptr), 0);
970 else if (TYPE_P (ptr))
971 lang_hooks.print_type (stderr, const_cast <tree_node*> (ptr), 0);
972 else if (TREE_CODE (ptr) == IDENTIFIER_NODE)
973 lang_hooks.print_identifier (stderr, const_cast <tree_node*> (ptr), 0);
974 else
975 print_generic_expr (stderr, const_cast <tree_node*> (ptr), options);
976 fprintf (stderr, "\n");
977 }
978
979 DEBUG_FUNCTION void
980 debug (const tree_node &ref)
981 {
982 dump_tree_via_hooks (&ref, 0);
983 }
984
985 DEBUG_FUNCTION void
986 debug (const tree_node *ptr)
987 {
988 if (ptr)
989 debug (*ptr);
990 else
991 fprintf (stderr, "<nil>\n");
992 }
993
994 DEBUG_FUNCTION void
995 debug_verbose (const tree_node &ref)
996 {
997 dump_tree_via_hooks (&ref, TDF_VERBOSE);
998 }
999
1000 DEBUG_FUNCTION void
1001 debug_verbose (const tree_node *ptr)
1002 {
1003 if (ptr)
1004 debug_verbose (*ptr);
1005 else
1006 fprintf (stderr, "<nil>\n");
1007 }
1008
1009 DEBUG_FUNCTION void
1010 debug_head (const tree_node &ref)
1011 {
1012 debug (ref);
1013 }
1014
1015 DEBUG_FUNCTION void
1016 debug_head (const tree_node *ptr)
1017 {
1018 if (ptr)
1019 debug_head (*ptr);
1020 else
1021 fprintf (stderr, "<nil>\n");
1022 }
1023
1024 DEBUG_FUNCTION void
1025 debug_body (const tree_node &ref)
1026 {
1027 if (TREE_CODE (&ref) == FUNCTION_DECL)
1028 dump_function_to_file (const_cast <tree_node*> (&ref), stderr, 0);
1029 else
1030 debug (ref);
1031 }
1032
1033 DEBUG_FUNCTION void
1034 debug_body (const tree_node *ptr)
1035 {
1036 if (ptr)
1037 debug_body (*ptr);
1038 else
1039 fprintf (stderr, "<nil>\n");
1040 }
1041
1042 /* Print the vector of trees VEC on standard error, for debugging.
1043 Most nodes referred to by this one are printed recursively
1044 down to a depth of six. */
1045
1046 DEBUG_FUNCTION void
1047 debug_raw (vec<tree, va_gc> &ref)
1048 {
1049 tree elt;
1050 unsigned ix;
1051
1052 /* Print the slot this node is in, and its code, and address. */
1053 fprintf (stderr, "<VEC");
1054 dump_addr (stderr, " ", ref.address ());
1055
1056 FOR_EACH_VEC_ELT (ref, ix, elt)
1057 {
1058 fprintf (stderr, "elt %d ", ix);
1059 debug_raw (elt);
1060 }
1061 }
1062
1063 DEBUG_FUNCTION void
1064 debug (vec<tree, va_gc> &ref)
1065 {
1066 tree elt;
1067 unsigned ix;
1068
1069 /* Print the slot this node is in, and its code, and address. */
1070 fprintf (stderr, "<VEC");
1071 dump_addr (stderr, " ", ref.address ());
1072
1073 FOR_EACH_VEC_ELT (ref, ix, elt)
1074 {
1075 fprintf (stderr, "elt %d ", ix);
1076 debug (elt);
1077 }
1078 }
1079
1080 DEBUG_FUNCTION void
1081 debug (vec<tree, va_gc> *ptr)
1082 {
1083 if (ptr)
1084 debug (*ptr);
1085 else
1086 fprintf (stderr, "<nil>\n");
1087 }
1088
1089 DEBUG_FUNCTION void
1090 debug_raw (vec<tree, va_gc> *ptr)
1091 {
1092 if (ptr)
1093 debug_raw (*ptr);
1094 else
1095 fprintf (stderr, "<nil>\n");
1096 }
1097
1098 DEBUG_FUNCTION void
1099 debug_vec_tree (vec<tree, va_gc> *vec)
1100 {
1101 debug_raw (vec);
1102 }