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