gcc/
[official-gcc.git] / gcc / tree-pretty-print.c
blobbd6fd81d47e4439dce65f02ab65d1a80051d3f1c
1 /* Pretty formatting of GENERIC trees in C syntax.
2 Copyright (C) 2001-2013 Free Software Foundation, Inc.
3 Adapted from c-pretty-print.c by Diego Novillo <dnovillo@redhat.com>
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tm.h"
25 #include "tree.h"
26 #include "tree-pretty-print.h"
27 #include "hashtab.h"
28 #include "tree-ssa.h"
29 #include "langhooks.h"
30 #include "tree-iterator.h"
31 #include "tree-chrec.h"
32 #include "dumpfile.h"
33 #include "value-prof.h"
34 #include "predict.h"
36 #include <new> // For placement-new.
38 /* Local functions, macros and variables. */
39 static const char *op_symbol (const_tree);
40 static void pretty_print_string (pretty_printer *, const char*);
41 static void newline_and_indent (pretty_printer *, int);
42 static void maybe_init_pretty_print (FILE *);
43 static void print_struct_decl (pretty_printer *, const_tree, int, int);
44 static void do_niy (pretty_printer *, const_tree);
46 #define INDENT(SPACE) do { \
47 int i; for (i = 0; i<SPACE; i++) pp_space (buffer); } while (0)
49 #define NIY do_niy(buffer,node)
51 static pretty_printer buffer;
52 static int initialized = 0;
54 /* Try to print something for an unknown tree code. */
56 static void
57 do_niy (pretty_printer *buffer, const_tree node)
59 int i, len;
61 pp_string (buffer, "<<< Unknown tree: ");
62 pp_string (buffer, tree_code_name[(int) TREE_CODE (node)]);
64 if (EXPR_P (node))
66 len = TREE_OPERAND_LENGTH (node);
67 for (i = 0; i < len; ++i)
69 newline_and_indent (buffer, 2);
70 dump_generic_node (buffer, TREE_OPERAND (node, i), 2, 0, false);
74 pp_string (buffer, " >>>");
77 /* Debugging function to print out a generic expression. */
79 DEBUG_FUNCTION void
80 debug_generic_expr (tree t)
82 print_generic_expr (stderr, t, TDF_VOPS|TDF_MEMSYMS);
83 fprintf (stderr, "\n");
86 /* Debugging function to print out a generic statement. */
88 DEBUG_FUNCTION void
89 debug_generic_stmt (tree t)
91 print_generic_stmt (stderr, t, TDF_VOPS|TDF_MEMSYMS);
92 fprintf (stderr, "\n");
95 /* Debugging function to print out a chain of trees . */
97 DEBUG_FUNCTION void
98 debug_tree_chain (tree t)
100 struct pointer_set_t *seen = pointer_set_create ();
102 while (t)
104 print_generic_expr (stderr, t, TDF_VOPS|TDF_MEMSYMS|TDF_UID);
105 fprintf (stderr, " ");
106 t = TREE_CHAIN (t);
107 if (pointer_set_insert (seen, t))
109 fprintf (stderr, "... [cycled back to ");
110 print_generic_expr (stderr, t, TDF_VOPS|TDF_MEMSYMS|TDF_UID);
111 fprintf (stderr, "]");
112 break;
115 fprintf (stderr, "\n");
117 pointer_set_destroy (seen);
120 /* Prints declaration DECL to the FILE with details specified by FLAGS. */
121 void
122 print_generic_decl (FILE *file, tree decl, int flags)
124 maybe_init_pretty_print (file);
125 print_declaration (&buffer, decl, 2, flags);
126 pp_write_text_to_stream (&buffer);
129 /* Print tree T, and its successors, on file FILE. FLAGS specifies details
130 to show in the dump. See TDF_* in dumpfile.h. */
132 void
133 print_generic_stmt (FILE *file, tree t, int flags)
135 maybe_init_pretty_print (file);
136 dump_generic_node (&buffer, t, 0, flags, true);
137 pp_newline_and_flush (&buffer);
140 /* Print tree T, and its successors, on file FILE. FLAGS specifies details
141 to show in the dump. See TDF_* in dumpfile.h. The output is indented by
142 INDENT spaces. */
144 void
145 print_generic_stmt_indented (FILE *file, tree t, int flags, int indent)
147 int i;
149 maybe_init_pretty_print (file);
151 for (i = 0; i < indent; i++)
152 pp_space (&buffer);
153 dump_generic_node (&buffer, t, indent, flags, true);
154 pp_newline_and_flush (&buffer);
157 /* Print a single expression T on file FILE. FLAGS specifies details to show
158 in the dump. See TDF_* in dumpfile.h. */
160 void
161 print_generic_expr (FILE *file, tree t, int flags)
163 maybe_init_pretty_print (file);
164 dump_generic_node (&buffer, t, 0, flags, false);
165 pp_flush (&buffer);
168 /* Dump the name of a _DECL node and its DECL_UID if TDF_UID is set
169 in FLAGS. */
171 static void
172 dump_decl_name (pretty_printer *buffer, tree node, int flags)
174 if (DECL_NAME (node))
176 if ((flags & TDF_ASMNAME) && DECL_ASSEMBLER_NAME_SET_P (node))
177 pp_tree_identifier (buffer, DECL_ASSEMBLER_NAME (node));
178 else
179 pp_tree_identifier (buffer, DECL_NAME (node));
181 if ((flags & TDF_UID) || DECL_NAME (node) == NULL_TREE)
183 if (TREE_CODE (node) == LABEL_DECL && LABEL_DECL_UID (node) != -1)
184 pp_printf (buffer, "L.%d", (int) LABEL_DECL_UID (node));
185 else if (TREE_CODE (node) == DEBUG_EXPR_DECL)
187 if (flags & TDF_NOUID)
188 pp_string (buffer, "D#xxxx");
189 else
190 pp_printf (buffer, "D#%i", DEBUG_TEMP_UID (node));
192 else
194 char c = TREE_CODE (node) == CONST_DECL ? 'C' : 'D';
195 if (flags & TDF_NOUID)
196 pp_printf (buffer, "%c.xxxx", c);
197 else
198 pp_printf (buffer, "%c.%u", c, DECL_UID (node));
201 if ((flags & TDF_ALIAS) && DECL_PT_UID (node) != DECL_UID (node))
203 if (flags & TDF_NOUID)
204 pp_printf (buffer, "ptD.xxxx");
205 else
206 pp_printf (buffer, "ptD.%u", DECL_PT_UID (node));
210 /* Like the above, but used for pretty printing function calls. */
212 static void
213 dump_function_name (pretty_printer *buffer, tree node, int flags)
215 if (TREE_CODE (node) == NOP_EXPR)
216 node = TREE_OPERAND (node, 0);
217 if (DECL_NAME (node) && (flags & TDF_ASMNAME) == 0)
218 pp_string (buffer, lang_hooks.decl_printable_name (node, 1));
219 else
220 dump_decl_name (buffer, node, flags);
223 /* Dump a function declaration. NODE is the FUNCTION_TYPE. BUFFER, SPC and
224 FLAGS are as in dump_generic_node. */
226 static void
227 dump_function_declaration (pretty_printer *buffer, tree node,
228 int spc, int flags)
230 bool wrote_arg = false;
231 tree arg;
233 pp_space (buffer);
234 pp_left_paren (buffer);
236 /* Print the argument types. */
237 arg = TYPE_ARG_TYPES (node);
238 while (arg && arg != void_list_node && arg != error_mark_node)
240 if (wrote_arg)
242 pp_comma (buffer);
243 pp_space (buffer);
245 wrote_arg = true;
246 dump_generic_node (buffer, TREE_VALUE (arg), spc, flags, false);
247 arg = TREE_CHAIN (arg);
250 /* Drop the trailing void_type_node if we had any previous argument. */
251 if (arg == void_list_node && !wrote_arg)
252 pp_string (buffer, "void");
253 /* Properly dump vararg function types. */
254 else if (!arg && wrote_arg)
255 pp_string (buffer, ", ...");
256 /* Avoid printing any arg for unprototyped functions. */
258 pp_right_paren (buffer);
261 /* Dump the domain associated with an array. */
263 static void
264 dump_array_domain (pretty_printer *buffer, tree domain, int spc, int flags)
266 pp_left_bracket (buffer);
267 if (domain)
269 tree min = TYPE_MIN_VALUE (domain);
270 tree max = TYPE_MAX_VALUE (domain);
272 if (min && max
273 && integer_zerop (min)
274 && host_integerp (max, 0))
275 pp_wide_integer (buffer, TREE_INT_CST_LOW (max) + 1);
276 else
278 if (min)
279 dump_generic_node (buffer, min, spc, flags, false);
280 pp_colon (buffer);
281 if (max)
282 dump_generic_node (buffer, max, spc, flags, false);
285 else
286 pp_string (buffer, "<unknown>");
287 pp_right_bracket (buffer);
291 /* Dump OpenMP clause CLAUSE. BUFFER, CLAUSE, SPC and FLAGS are as in
292 dump_generic_node. */
294 static void
295 dump_omp_clause (pretty_printer *buffer, tree clause, int spc, int flags)
297 const char *name;
299 switch (OMP_CLAUSE_CODE (clause))
301 case OMP_CLAUSE_PRIVATE:
302 name = "private";
303 goto print_remap;
304 case OMP_CLAUSE_SHARED:
305 name = "shared";
306 goto print_remap;
307 case OMP_CLAUSE_FIRSTPRIVATE:
308 name = "firstprivate";
309 goto print_remap;
310 case OMP_CLAUSE_LASTPRIVATE:
311 name = "lastprivate";
312 goto print_remap;
313 case OMP_CLAUSE_COPYIN:
314 name = "copyin";
315 goto print_remap;
316 case OMP_CLAUSE_COPYPRIVATE:
317 name = "copyprivate";
318 goto print_remap;
319 case OMP_CLAUSE_UNIFORM:
320 name = "uniform";
321 goto print_remap;
322 print_remap:
323 pp_string (buffer, name);
324 pp_left_paren (buffer);
325 dump_generic_node (buffer, OMP_CLAUSE_DECL (clause),
326 spc, flags, false);
327 pp_right_paren (buffer);
328 break;
330 case OMP_CLAUSE_REDUCTION:
331 pp_string (buffer, "reduction(");
332 pp_string (buffer, op_symbol_code (OMP_CLAUSE_REDUCTION_CODE (clause)));
333 pp_colon (buffer);
334 dump_generic_node (buffer, OMP_CLAUSE_DECL (clause),
335 spc, flags, false);
336 pp_right_paren (buffer);
337 break;
339 case OMP_CLAUSE_IF:
340 pp_string (buffer, "if(");
341 dump_generic_node (buffer, OMP_CLAUSE_IF_EXPR (clause),
342 spc, flags, false);
343 pp_right_paren (buffer);
344 break;
346 case OMP_CLAUSE_NUM_THREADS:
347 pp_string (buffer, "num_threads(");
348 dump_generic_node (buffer, OMP_CLAUSE_NUM_THREADS_EXPR (clause),
349 spc, flags, false);
350 pp_right_paren (buffer);
351 break;
353 case OMP_CLAUSE_NOWAIT:
354 pp_string (buffer, "nowait");
355 break;
356 case OMP_CLAUSE_ORDERED:
357 pp_string (buffer, "ordered");
358 break;
360 case OMP_CLAUSE_DEFAULT:
361 pp_string (buffer, "default(");
362 switch (OMP_CLAUSE_DEFAULT_KIND (clause))
364 case OMP_CLAUSE_DEFAULT_UNSPECIFIED:
365 break;
366 case OMP_CLAUSE_DEFAULT_SHARED:
367 pp_string (buffer, "shared");
368 break;
369 case OMP_CLAUSE_DEFAULT_NONE:
370 pp_string (buffer, "none");
371 break;
372 case OMP_CLAUSE_DEFAULT_PRIVATE:
373 pp_string (buffer, "private");
374 break;
375 case OMP_CLAUSE_DEFAULT_FIRSTPRIVATE:
376 pp_string (buffer, "firstprivate");
377 break;
378 default:
379 gcc_unreachable ();
381 pp_right_paren (buffer);
382 break;
384 case OMP_CLAUSE_SCHEDULE:
385 pp_string (buffer, "schedule(");
386 switch (OMP_CLAUSE_SCHEDULE_KIND (clause))
388 case OMP_CLAUSE_SCHEDULE_STATIC:
389 pp_string (buffer, "static");
390 break;
391 case OMP_CLAUSE_SCHEDULE_DYNAMIC:
392 pp_string (buffer, "dynamic");
393 break;
394 case OMP_CLAUSE_SCHEDULE_GUIDED:
395 pp_string (buffer, "guided");
396 break;
397 case OMP_CLAUSE_SCHEDULE_RUNTIME:
398 pp_string (buffer, "runtime");
399 break;
400 case OMP_CLAUSE_SCHEDULE_AUTO:
401 pp_string (buffer, "auto");
402 break;
403 default:
404 gcc_unreachable ();
406 if (OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clause))
408 pp_comma (buffer);
409 dump_generic_node (buffer,
410 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clause),
411 spc, flags, false);
413 pp_right_paren (buffer);
414 break;
416 case OMP_CLAUSE_UNTIED:
417 pp_string (buffer, "untied");
418 break;
420 case OMP_CLAUSE_COLLAPSE:
421 pp_string (buffer, "collapse(");
422 dump_generic_node (buffer,
423 OMP_CLAUSE_COLLAPSE_EXPR (clause),
424 spc, flags, false);
425 pp_right_paren (buffer);
426 break;
428 case OMP_CLAUSE_FINAL:
429 pp_string (buffer, "final(");
430 dump_generic_node (buffer, OMP_CLAUSE_FINAL_EXPR (clause),
431 spc, flags, false);
432 pp_right_paren (buffer);
433 break;
435 case OMP_CLAUSE_MERGEABLE:
436 pp_string (buffer, "mergeable");
437 break;
439 case OMP_CLAUSE_LINEAR:
440 pp_string (buffer, "linear(");
441 dump_generic_node (buffer, OMP_CLAUSE_DECL (clause),
442 spc, flags, false);
443 pp_character (buffer, ':');
444 dump_generic_node (buffer, OMP_CLAUSE_LINEAR_STEP (clause),
445 spc, flags, false);
446 pp_character (buffer, ')');
447 break;
449 case OMP_CLAUSE_SAFELEN:
450 pp_string (buffer, "safelen(");
451 dump_generic_node (buffer, OMP_CLAUSE_SAFELEN_EXPR (clause),
452 spc, flags, false);
453 pp_character (buffer, ')');
454 break;
456 case OMP_CLAUSE__SIMDUID_:
457 pp_string (buffer, "_simduid_(");
458 dump_generic_node (buffer, OMP_CLAUSE__SIMDUID__DECL (clause),
459 spc, flags, false);
460 pp_character (buffer, ')');
461 break;
463 default:
464 /* Should never happen. */
465 dump_generic_node (buffer, clause, spc, flags, false);
466 break;
471 /* Dump the list of OpenMP clauses. BUFFER, SPC and FLAGS are as in
472 dump_generic_node. */
474 void
475 dump_omp_clauses (pretty_printer *buffer, tree clause, int spc, int flags)
477 if (clause == NULL)
478 return;
480 pp_space (buffer);
481 while (1)
483 dump_omp_clause (buffer, clause, spc, flags);
484 clause = OMP_CLAUSE_CHAIN (clause);
485 if (clause == NULL)
486 return;
487 pp_space (buffer);
492 /* Dump location LOC to BUFFER. */
494 static void
495 dump_location (pretty_printer *buffer, location_t loc)
497 expanded_location xloc = expand_location (loc);
499 pp_left_bracket (buffer);
500 if (xloc.file)
502 pp_string (buffer, xloc.file);
503 pp_string (buffer, " : ");
505 pp_decimal_int (buffer, xloc.line);
506 pp_string (buffer, "] ");
510 /* Dump lexical block BLOCK. BUFFER, SPC and FLAGS are as in
511 dump_generic_node. */
513 static void
514 dump_block_node (pretty_printer *buffer, tree block, int spc, int flags)
516 tree t;
518 pp_printf (buffer, "BLOCK #%d ", BLOCK_NUMBER (block));
520 if (flags & TDF_ADDRESS)
521 pp_printf (buffer, "[%p] ", (void *) block);
523 if (BLOCK_ABSTRACT (block))
524 pp_string (buffer, "[abstract] ");
526 if (TREE_ASM_WRITTEN (block))
527 pp_string (buffer, "[written] ");
529 if (flags & TDF_SLIM)
530 return;
532 if (BLOCK_SOURCE_LOCATION (block))
533 dump_location (buffer, BLOCK_SOURCE_LOCATION (block));
535 newline_and_indent (buffer, spc + 2);
537 if (BLOCK_SUPERCONTEXT (block))
539 pp_string (buffer, "SUPERCONTEXT: ");
540 dump_generic_node (buffer, BLOCK_SUPERCONTEXT (block), 0,
541 flags | TDF_SLIM, false);
542 newline_and_indent (buffer, spc + 2);
545 if (BLOCK_SUBBLOCKS (block))
547 pp_string (buffer, "SUBBLOCKS: ");
548 for (t = BLOCK_SUBBLOCKS (block); t; t = BLOCK_CHAIN (t))
550 dump_generic_node (buffer, t, 0, flags | TDF_SLIM, false);
551 pp_space (buffer);
553 newline_and_indent (buffer, spc + 2);
556 if (BLOCK_CHAIN (block))
558 pp_string (buffer, "SIBLINGS: ");
559 for (t = BLOCK_CHAIN (block); t; t = BLOCK_CHAIN (t))
561 dump_generic_node (buffer, t, 0, flags | TDF_SLIM, false);
562 pp_space (buffer);
564 newline_and_indent (buffer, spc + 2);
567 if (BLOCK_VARS (block))
569 pp_string (buffer, "VARS: ");
570 for (t = BLOCK_VARS (block); t; t = TREE_CHAIN (t))
572 dump_generic_node (buffer, t, 0, flags, false);
573 pp_space (buffer);
575 newline_and_indent (buffer, spc + 2);
578 if (vec_safe_length (BLOCK_NONLOCALIZED_VARS (block)) > 0)
580 unsigned i;
581 vec<tree, va_gc> *nlv = BLOCK_NONLOCALIZED_VARS (block);
583 pp_string (buffer, "NONLOCALIZED_VARS: ");
584 FOR_EACH_VEC_ELT (*nlv, i, t)
586 dump_generic_node (buffer, t, 0, flags, false);
587 pp_space (buffer);
589 newline_and_indent (buffer, spc + 2);
592 if (BLOCK_ABSTRACT_ORIGIN (block))
594 pp_string (buffer, "ABSTRACT_ORIGIN: ");
595 dump_generic_node (buffer, BLOCK_ABSTRACT_ORIGIN (block), 0,
596 flags | TDF_SLIM, false);
597 newline_and_indent (buffer, spc + 2);
600 if (BLOCK_FRAGMENT_ORIGIN (block))
602 pp_string (buffer, "FRAGMENT_ORIGIN: ");
603 dump_generic_node (buffer, BLOCK_FRAGMENT_ORIGIN (block), 0,
604 flags | TDF_SLIM, false);
605 newline_and_indent (buffer, spc + 2);
608 if (BLOCK_FRAGMENT_CHAIN (block))
610 pp_string (buffer, "FRAGMENT_CHAIN: ");
611 for (t = BLOCK_FRAGMENT_CHAIN (block); t; t = BLOCK_FRAGMENT_CHAIN (t))
613 dump_generic_node (buffer, t, 0, flags | TDF_SLIM, false);
614 pp_space (buffer);
616 newline_and_indent (buffer, spc + 2);
621 /* Dump the node NODE on the pretty_printer BUFFER, SPC spaces of
622 indent. FLAGS specifies details to show in the dump (see TDF_* in
623 dumpfile.h). If IS_STMT is true, the object printed is considered
624 to be a statement and it is terminated by ';' if appropriate. */
627 dump_generic_node (pretty_printer *buffer, tree node, int spc, int flags,
628 bool is_stmt)
630 tree type;
631 tree op0, op1;
632 const char *str;
633 bool is_expr;
634 enum tree_code code;
636 if (node == NULL_TREE)
637 return spc;
639 is_expr = EXPR_P (node);
641 if (is_stmt && (flags & TDF_STMTADDR))
642 pp_printf (buffer, "<&%p> ", (void *)node);
644 if ((flags & TDF_LINENO) && EXPR_HAS_LOCATION (node))
645 dump_location (buffer, EXPR_LOCATION (node));
647 code = TREE_CODE (node);
648 switch (code)
650 case ERROR_MARK:
651 pp_string (buffer, "<<< error >>>");
652 break;
654 case IDENTIFIER_NODE:
655 pp_tree_identifier (buffer, node);
656 break;
658 case TREE_LIST:
659 while (node && node != error_mark_node)
661 if (TREE_PURPOSE (node))
663 dump_generic_node (buffer, TREE_PURPOSE (node), spc, flags, false);
664 pp_space (buffer);
666 dump_generic_node (buffer, TREE_VALUE (node), spc, flags, false);
667 node = TREE_CHAIN (node);
668 if (node && TREE_CODE (node) == TREE_LIST)
670 pp_comma (buffer);
671 pp_space (buffer);
674 break;
676 case TREE_BINFO:
677 dump_generic_node (buffer, BINFO_TYPE (node), spc, flags, false);
678 break;
680 case TREE_VEC:
682 size_t i;
683 if (TREE_VEC_LENGTH (node) > 0)
685 size_t len = TREE_VEC_LENGTH (node);
686 for (i = 0; i < len - 1; i++)
688 dump_generic_node (buffer, TREE_VEC_ELT (node, i), spc, flags,
689 false);
690 pp_comma (buffer);
691 pp_space (buffer);
693 dump_generic_node (buffer, TREE_VEC_ELT (node, len - 1), spc,
694 flags, false);
697 break;
699 case VOID_TYPE:
700 case INTEGER_TYPE:
701 case REAL_TYPE:
702 case FIXED_POINT_TYPE:
703 case COMPLEX_TYPE:
704 case VECTOR_TYPE:
705 case ENUMERAL_TYPE:
706 case BOOLEAN_TYPE:
708 unsigned int quals = TYPE_QUALS (node);
709 enum tree_code_class tclass;
711 if (quals & TYPE_QUAL_CONST)
712 pp_string (buffer, "const ");
713 else if (quals & TYPE_QUAL_VOLATILE)
714 pp_string (buffer, "volatile ");
715 else if (quals & TYPE_QUAL_RESTRICT)
716 pp_string (buffer, "restrict ");
718 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (node)))
720 pp_string (buffer, "<address-space-");
721 pp_decimal_int (buffer, TYPE_ADDR_SPACE (node));
722 pp_string (buffer, "> ");
725 tclass = TREE_CODE_CLASS (TREE_CODE (node));
727 if (tclass == tcc_declaration)
729 if (DECL_NAME (node))
730 dump_decl_name (buffer, node, flags);
731 else
732 pp_string (buffer, "<unnamed type decl>");
734 else if (tclass == tcc_type)
736 if (TYPE_NAME (node))
738 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
739 pp_tree_identifier (buffer, TYPE_NAME (node));
740 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
741 && DECL_NAME (TYPE_NAME (node)))
742 dump_decl_name (buffer, TYPE_NAME (node), flags);
743 else
744 pp_string (buffer, "<unnamed type>");
746 else if (TREE_CODE (node) == VECTOR_TYPE)
748 pp_string (buffer, "vector");
749 pp_left_paren (buffer);
750 pp_wide_integer (buffer, TYPE_VECTOR_SUBPARTS (node));
751 pp_string (buffer, ") ");
752 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
754 else if (TREE_CODE (node) == INTEGER_TYPE)
756 if (TYPE_PRECISION (node) == CHAR_TYPE_SIZE)
757 pp_string (buffer, (TYPE_UNSIGNED (node)
758 ? "unsigned char"
759 : "signed char"));
760 else if (TYPE_PRECISION (node) == SHORT_TYPE_SIZE)
761 pp_string (buffer, (TYPE_UNSIGNED (node)
762 ? "unsigned short"
763 : "signed short"));
764 else if (TYPE_PRECISION (node) == INT_TYPE_SIZE)
765 pp_string (buffer, (TYPE_UNSIGNED (node)
766 ? "unsigned int"
767 : "signed int"));
768 else if (TYPE_PRECISION (node) == LONG_TYPE_SIZE)
769 pp_string (buffer, (TYPE_UNSIGNED (node)
770 ? "unsigned long"
771 : "signed long"));
772 else if (TYPE_PRECISION (node) == LONG_LONG_TYPE_SIZE)
773 pp_string (buffer, (TYPE_UNSIGNED (node)
774 ? "unsigned long long"
775 : "signed long long"));
776 else if (TYPE_PRECISION (node) >= CHAR_TYPE_SIZE
777 && exact_log2 (TYPE_PRECISION (node)) != -1)
779 pp_string (buffer, (TYPE_UNSIGNED (node) ? "uint" : "int"));
780 pp_decimal_int (buffer, TYPE_PRECISION (node));
781 pp_string (buffer, "_t");
783 else
785 pp_string (buffer, (TYPE_UNSIGNED (node)
786 ? "<unnamed-unsigned:"
787 : "<unnamed-signed:"));
788 pp_decimal_int (buffer, TYPE_PRECISION (node));
789 pp_greater (buffer);
792 else if (TREE_CODE (node) == COMPLEX_TYPE)
794 pp_string (buffer, "__complex__ ");
795 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
797 else if (TREE_CODE (node) == REAL_TYPE)
799 pp_string (buffer, "<float:");
800 pp_decimal_int (buffer, TYPE_PRECISION (node));
801 pp_greater (buffer);
803 else if (TREE_CODE (node) == FIXED_POINT_TYPE)
805 pp_string (buffer, "<fixed-point-");
806 pp_string (buffer, TYPE_SATURATING (node) ? "sat:" : "nonsat:");
807 pp_decimal_int (buffer, TYPE_PRECISION (node));
808 pp_greater (buffer);
810 else if (TREE_CODE (node) == VOID_TYPE)
811 pp_string (buffer, "void");
812 else
813 pp_string (buffer, "<unnamed type>");
815 break;
818 case POINTER_TYPE:
819 case REFERENCE_TYPE:
820 str = (TREE_CODE (node) == POINTER_TYPE ? "*" : "&");
822 if (TREE_TYPE (node) == NULL)
824 pp_string (buffer, str);
825 pp_string (buffer, "<null type>");
827 else if (TREE_CODE (TREE_TYPE (node)) == FUNCTION_TYPE)
829 tree fnode = TREE_TYPE (node);
831 dump_generic_node (buffer, TREE_TYPE (fnode), spc, flags, false);
832 pp_space (buffer);
833 pp_left_paren (buffer);
834 pp_string (buffer, str);
835 if (TYPE_NAME (node) && DECL_NAME (TYPE_NAME (node)))
836 dump_decl_name (buffer, TYPE_NAME (node), flags);
837 else if (flags & TDF_NOUID)
838 pp_printf (buffer, "<Txxxx>");
839 else
840 pp_printf (buffer, "<T%x>", TYPE_UID (node));
842 pp_right_paren (buffer);
843 dump_function_declaration (buffer, fnode, spc, flags);
845 else
847 unsigned int quals = TYPE_QUALS (node);
849 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
850 pp_space (buffer);
851 pp_string (buffer, str);
853 if (quals & TYPE_QUAL_CONST)
854 pp_string (buffer, " const");
855 if (quals & TYPE_QUAL_VOLATILE)
856 pp_string (buffer, " volatile");
857 if (quals & TYPE_QUAL_RESTRICT)
858 pp_string (buffer, " restrict");
860 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (node)))
862 pp_string (buffer, " <address-space-");
863 pp_decimal_int (buffer, TYPE_ADDR_SPACE (node));
864 pp_greater (buffer);
867 if (TYPE_REF_CAN_ALIAS_ALL (node))
868 pp_string (buffer, " {ref-all}");
870 break;
872 case OFFSET_TYPE:
873 NIY;
874 break;
876 case MEM_REF:
878 if (integer_zerop (TREE_OPERAND (node, 1))
879 /* Dump the types of INTEGER_CSTs explicitly, for we can't
880 infer them and MEM_ATTR caching will share MEM_REFs
881 with differently-typed op0s. */
882 && TREE_CODE (TREE_OPERAND (node, 0)) != INTEGER_CST
883 /* Released SSA_NAMES have no TREE_TYPE. */
884 && TREE_TYPE (TREE_OPERAND (node, 0)) != NULL_TREE
885 /* Same pointer types, but ignoring POINTER_TYPE vs.
886 REFERENCE_TYPE. */
887 && (TREE_TYPE (TREE_TYPE (TREE_OPERAND (node, 0)))
888 == TREE_TYPE (TREE_TYPE (TREE_OPERAND (node, 1))))
889 && (TYPE_MODE (TREE_TYPE (TREE_OPERAND (node, 0)))
890 == TYPE_MODE (TREE_TYPE (TREE_OPERAND (node, 1))))
891 && (TYPE_REF_CAN_ALIAS_ALL (TREE_TYPE (TREE_OPERAND (node, 0)))
892 == TYPE_REF_CAN_ALIAS_ALL (TREE_TYPE (TREE_OPERAND (node, 1))))
893 /* Same value types ignoring qualifiers. */
894 && (TYPE_MAIN_VARIANT (TREE_TYPE (node))
895 == TYPE_MAIN_VARIANT
896 (TREE_TYPE (TREE_TYPE (TREE_OPERAND (node, 1))))))
898 if (TREE_CODE (TREE_OPERAND (node, 0)) != ADDR_EXPR)
900 pp_star (buffer);
901 dump_generic_node (buffer, TREE_OPERAND (node, 0),
902 spc, flags, false);
904 else
905 dump_generic_node (buffer,
906 TREE_OPERAND (TREE_OPERAND (node, 0), 0),
907 spc, flags, false);
909 else
911 tree ptype;
913 pp_string (buffer, "MEM[");
914 pp_left_paren (buffer);
915 ptype = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (node, 1)));
916 dump_generic_node (buffer, ptype,
917 spc, flags | TDF_SLIM, false);
918 pp_right_paren (buffer);
919 dump_generic_node (buffer, TREE_OPERAND (node, 0),
920 spc, flags, false);
921 if (!integer_zerop (TREE_OPERAND (node, 1)))
923 pp_string (buffer, " + ");
924 dump_generic_node (buffer, TREE_OPERAND (node, 1),
925 spc, flags, false);
927 pp_right_bracket (buffer);
929 break;
932 case TARGET_MEM_REF:
934 const char *sep = "";
935 tree tmp;
937 pp_string (buffer, "MEM[");
939 if (TREE_CODE (TMR_BASE (node)) == ADDR_EXPR)
941 pp_string (buffer, sep);
942 sep = ", ";
943 pp_string (buffer, "symbol: ");
944 dump_generic_node (buffer, TREE_OPERAND (TMR_BASE (node), 0),
945 spc, flags, false);
947 else
949 pp_string (buffer, sep);
950 sep = ", ";
951 pp_string (buffer, "base: ");
952 dump_generic_node (buffer, TMR_BASE (node), spc, flags, false);
954 tmp = TMR_INDEX2 (node);
955 if (tmp)
957 pp_string (buffer, sep);
958 sep = ", ";
959 pp_string (buffer, "base: ");
960 dump_generic_node (buffer, tmp, spc, flags, false);
962 tmp = TMR_INDEX (node);
963 if (tmp)
965 pp_string (buffer, sep);
966 sep = ", ";
967 pp_string (buffer, "index: ");
968 dump_generic_node (buffer, tmp, spc, flags, false);
970 tmp = TMR_STEP (node);
971 if (tmp)
973 pp_string (buffer, sep);
974 sep = ", ";
975 pp_string (buffer, "step: ");
976 dump_generic_node (buffer, tmp, spc, flags, false);
978 tmp = TMR_OFFSET (node);
979 if (tmp)
981 pp_string (buffer, sep);
982 sep = ", ";
983 pp_string (buffer, "offset: ");
984 dump_generic_node (buffer, tmp, spc, flags, false);
986 pp_right_bracket (buffer);
988 break;
990 case ARRAY_TYPE:
992 tree tmp;
994 /* Print the innermost component type. */
995 for (tmp = TREE_TYPE (node); TREE_CODE (tmp) == ARRAY_TYPE;
996 tmp = TREE_TYPE (tmp))
998 dump_generic_node (buffer, tmp, spc, flags, false);
1000 /* Print the dimensions. */
1001 for (tmp = node; TREE_CODE (tmp) == ARRAY_TYPE; tmp = TREE_TYPE (tmp))
1002 dump_array_domain (buffer, TYPE_DOMAIN (tmp), spc, flags);
1003 break;
1006 case RECORD_TYPE:
1007 case UNION_TYPE:
1008 case QUAL_UNION_TYPE:
1010 unsigned int quals = TYPE_QUALS (node);
1012 if (quals & TYPE_QUAL_CONST)
1013 pp_string (buffer, "const ");
1014 if (quals & TYPE_QUAL_VOLATILE)
1015 pp_string (buffer, "volatile ");
1017 /* Print the name of the structure. */
1018 if (TREE_CODE (node) == RECORD_TYPE)
1019 pp_string (buffer, "struct ");
1020 else if (TREE_CODE (node) == UNION_TYPE)
1021 pp_string (buffer, "union ");
1023 if (TYPE_NAME (node))
1024 dump_generic_node (buffer, TYPE_NAME (node), spc, flags, false);
1025 else if (!(flags & TDF_SLIM))
1026 /* FIXME: If we eliminate the 'else' above and attempt
1027 to show the fields for named types, we may get stuck
1028 following a cycle of pointers to structs. The alleged
1029 self-reference check in print_struct_decl will not detect
1030 cycles involving more than one pointer or struct type. */
1031 print_struct_decl (buffer, node, spc, flags);
1032 break;
1035 case LANG_TYPE:
1036 NIY;
1037 break;
1039 case INTEGER_CST:
1040 if (TREE_CODE (TREE_TYPE (node)) == POINTER_TYPE)
1042 /* In the case of a pointer, one may want to divide by the
1043 size of the pointed-to type. Unfortunately, this not
1044 straightforward. The C front-end maps expressions
1046 (int *) 5
1047 int *p; (p + 5)
1049 in such a way that the two INTEGER_CST nodes for "5" have
1050 different values but identical types. In the latter
1051 case, the 5 is multiplied by sizeof (int) in c-common.c
1052 (pointer_int_sum) to convert it to a byte address, and
1053 yet the type of the node is left unchanged. Argh. What
1054 is consistent though is that the number value corresponds
1055 to bytes (UNITS) offset.
1057 NB: Neither of the following divisors can be trivially
1058 used to recover the original literal:
1060 TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (node)))
1061 TYPE_PRECISION (TREE_TYPE (TREE_TYPE (node))) */
1062 pp_wide_integer (buffer, TREE_INT_CST_LOW (node));
1063 pp_string (buffer, "B"); /* pseudo-unit */
1065 else
1066 pp_double_int (buffer, tree_to_double_int (node),
1067 TYPE_UNSIGNED (TREE_TYPE (node)));
1068 break;
1070 case REAL_CST:
1071 /* Code copied from print_node. */
1073 REAL_VALUE_TYPE d;
1074 if (TREE_OVERFLOW (node))
1075 pp_string (buffer, " overflow");
1077 #if !defined(REAL_IS_NOT_DOUBLE) || defined(REAL_ARITHMETIC)
1078 d = TREE_REAL_CST (node);
1079 if (REAL_VALUE_ISINF (d))
1080 pp_string (buffer, REAL_VALUE_NEGATIVE (d) ? " -Inf" : " Inf");
1081 else if (REAL_VALUE_ISNAN (d))
1082 pp_string (buffer, " Nan");
1083 else
1085 char string[100];
1086 real_to_decimal (string, &d, sizeof (string), 0, 1);
1087 pp_string (buffer, string);
1089 #else
1091 HOST_WIDE_INT i;
1092 unsigned char *p = (unsigned char *) &TREE_REAL_CST (node);
1093 pp_string (buffer, "0x");
1094 for (i = 0; i < sizeof TREE_REAL_CST (node); i++)
1095 output_formatted_integer (buffer, "%02x", *p++);
1097 #endif
1098 break;
1101 case FIXED_CST:
1103 char string[100];
1104 fixed_to_decimal (string, TREE_FIXED_CST_PTR (node), sizeof (string));
1105 pp_string (buffer, string);
1106 break;
1109 case COMPLEX_CST:
1110 pp_string (buffer, "__complex__ (");
1111 dump_generic_node (buffer, TREE_REALPART (node), spc, flags, false);
1112 pp_string (buffer, ", ");
1113 dump_generic_node (buffer, TREE_IMAGPART (node), spc, flags, false);
1114 pp_right_paren (buffer);
1115 break;
1117 case STRING_CST:
1118 pp_string (buffer, "\"");
1119 pretty_print_string (buffer, TREE_STRING_POINTER (node));
1120 pp_string (buffer, "\"");
1121 break;
1123 case VECTOR_CST:
1125 unsigned i;
1126 pp_string (buffer, "{ ");
1127 for (i = 0; i < VECTOR_CST_NELTS (node); ++i)
1129 if (i != 0)
1130 pp_string (buffer, ", ");
1131 dump_generic_node (buffer, VECTOR_CST_ELT (node, i),
1132 spc, flags, false);
1134 pp_string (buffer, " }");
1136 break;
1138 case FUNCTION_TYPE:
1139 case METHOD_TYPE:
1140 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
1141 pp_space (buffer);
1142 if (TREE_CODE (node) == METHOD_TYPE)
1144 if (TYPE_METHOD_BASETYPE (node))
1145 dump_decl_name (buffer, TYPE_NAME (TYPE_METHOD_BASETYPE (node)),
1146 flags);
1147 else
1148 pp_string (buffer, "<null method basetype>");
1149 pp_colon_colon (buffer);
1151 if (TYPE_NAME (node) && DECL_NAME (TYPE_NAME (node)))
1152 dump_decl_name (buffer, TYPE_NAME (node), flags);
1153 else if (flags & TDF_NOUID)
1154 pp_printf (buffer, "<Txxxx>");
1155 else
1156 pp_printf (buffer, "<T%x>", TYPE_UID (node));
1157 dump_function_declaration (buffer, node, spc, flags);
1158 break;
1160 case FUNCTION_DECL:
1161 case CONST_DECL:
1162 dump_decl_name (buffer, node, flags);
1163 break;
1165 case LABEL_DECL:
1166 if (DECL_NAME (node))
1167 dump_decl_name (buffer, node, flags);
1168 else if (LABEL_DECL_UID (node) != -1)
1169 pp_printf (buffer, "<L%d>", (int) LABEL_DECL_UID (node));
1170 else
1172 if (flags & TDF_NOUID)
1173 pp_string (buffer, "<D.xxxx>");
1174 else
1175 pp_printf (buffer, "<D.%u>", DECL_UID (node));
1177 break;
1179 case TYPE_DECL:
1180 if (DECL_IS_BUILTIN (node))
1182 /* Don't print the declaration of built-in types. */
1183 break;
1185 if (DECL_NAME (node))
1186 dump_decl_name (buffer, node, flags);
1187 else if (TYPE_NAME (TREE_TYPE (node)) != node)
1189 if ((TREE_CODE (TREE_TYPE (node)) == RECORD_TYPE
1190 || TREE_CODE (TREE_TYPE (node)) == UNION_TYPE)
1191 && TYPE_METHODS (TREE_TYPE (node)))
1193 /* The type is a c++ class: all structures have at least
1194 4 methods. */
1195 pp_string (buffer, "class ");
1196 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
1198 else
1200 pp_string (buffer,
1201 (TREE_CODE (TREE_TYPE (node)) == UNION_TYPE
1202 ? "union" : "struct "));
1203 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
1206 else
1207 pp_string (buffer, "<anon>");
1208 break;
1210 case VAR_DECL:
1211 case PARM_DECL:
1212 case FIELD_DECL:
1213 case DEBUG_EXPR_DECL:
1214 case NAMESPACE_DECL:
1215 dump_decl_name (buffer, node, flags);
1216 break;
1218 case RESULT_DECL:
1219 pp_string (buffer, "<retval>");
1220 break;
1222 case COMPONENT_REF:
1223 op0 = TREE_OPERAND (node, 0);
1224 str = ".";
1225 if (op0
1226 && (TREE_CODE (op0) == INDIRECT_REF
1227 || (TREE_CODE (op0) == MEM_REF
1228 && TREE_CODE (TREE_OPERAND (op0, 0)) != ADDR_EXPR
1229 && integer_zerop (TREE_OPERAND (op0, 1))
1230 /* Dump the types of INTEGER_CSTs explicitly, for we
1231 can't infer them and MEM_ATTR caching will share
1232 MEM_REFs with differently-typed op0s. */
1233 && TREE_CODE (TREE_OPERAND (op0, 0)) != INTEGER_CST
1234 /* Released SSA_NAMES have no TREE_TYPE. */
1235 && TREE_TYPE (TREE_OPERAND (op0, 0)) != NULL_TREE
1236 /* Same pointer types, but ignoring POINTER_TYPE vs.
1237 REFERENCE_TYPE. */
1238 && (TREE_TYPE (TREE_TYPE (TREE_OPERAND (op0, 0)))
1239 == TREE_TYPE (TREE_TYPE (TREE_OPERAND (op0, 1))))
1240 && (TYPE_MODE (TREE_TYPE (TREE_OPERAND (op0, 0)))
1241 == TYPE_MODE (TREE_TYPE (TREE_OPERAND (op0, 1))))
1242 && (TYPE_REF_CAN_ALIAS_ALL (TREE_TYPE (TREE_OPERAND (op0, 0)))
1243 == TYPE_REF_CAN_ALIAS_ALL (TREE_TYPE (TREE_OPERAND (op0, 1))))
1244 /* Same value types ignoring qualifiers. */
1245 && (TYPE_MAIN_VARIANT (TREE_TYPE (op0))
1246 == TYPE_MAIN_VARIANT
1247 (TREE_TYPE (TREE_TYPE (TREE_OPERAND (op0, 1))))))))
1249 op0 = TREE_OPERAND (op0, 0);
1250 str = "->";
1252 if (op_prio (op0) < op_prio (node))
1253 pp_left_paren (buffer);
1254 dump_generic_node (buffer, op0, spc, flags, false);
1255 if (op_prio (op0) < op_prio (node))
1256 pp_right_paren (buffer);
1257 pp_string (buffer, str);
1258 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1259 op0 = component_ref_field_offset (node);
1260 if (op0 && TREE_CODE (op0) != INTEGER_CST)
1262 pp_string (buffer, "{off: ");
1263 dump_generic_node (buffer, op0, spc, flags, false);
1264 pp_right_brace (buffer);
1266 break;
1268 case BIT_FIELD_REF:
1269 pp_string (buffer, "BIT_FIELD_REF <");
1270 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1271 pp_string (buffer, ", ");
1272 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1273 pp_string (buffer, ", ");
1274 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
1275 pp_greater (buffer);
1276 break;
1278 case ARRAY_REF:
1279 case ARRAY_RANGE_REF:
1280 op0 = TREE_OPERAND (node, 0);
1281 if (op_prio (op0) < op_prio (node))
1282 pp_left_paren (buffer);
1283 dump_generic_node (buffer, op0, spc, flags, false);
1284 if (op_prio (op0) < op_prio (node))
1285 pp_right_paren (buffer);
1286 pp_left_bracket (buffer);
1287 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1288 if (TREE_CODE (node) == ARRAY_RANGE_REF)
1289 pp_string (buffer, " ...");
1290 pp_right_bracket (buffer);
1292 op0 = array_ref_low_bound (node);
1293 op1 = array_ref_element_size (node);
1295 if (!integer_zerop (op0)
1296 || TREE_OPERAND (node, 2)
1297 || TREE_OPERAND (node, 3))
1299 pp_string (buffer, "{lb: ");
1300 dump_generic_node (buffer, op0, spc, flags, false);
1301 pp_string (buffer, " sz: ");
1302 dump_generic_node (buffer, op1, spc, flags, false);
1303 pp_right_brace (buffer);
1305 break;
1307 case CONSTRUCTOR:
1309 unsigned HOST_WIDE_INT ix;
1310 tree field, val;
1311 bool is_struct_init = false;
1312 bool is_array_init = false;
1313 double_int curidx = double_int_zero;
1314 pp_left_brace (buffer);
1315 if (TREE_CLOBBER_P (node))
1316 pp_string (buffer, "CLOBBER");
1317 else if (TREE_CODE (TREE_TYPE (node)) == RECORD_TYPE
1318 || TREE_CODE (TREE_TYPE (node)) == UNION_TYPE)
1319 is_struct_init = true;
1320 else if (TREE_CODE (TREE_TYPE (node)) == ARRAY_TYPE
1321 && TYPE_DOMAIN (TREE_TYPE (node))
1322 && TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (node)))
1323 && TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (node))))
1324 == INTEGER_CST)
1326 tree minv = TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (node)));
1327 is_array_init = true;
1328 curidx = tree_to_double_int (minv);
1330 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (node), ix, field, val)
1332 if (field)
1334 if (is_struct_init)
1336 pp_dot (buffer);
1337 dump_generic_node (buffer, field, spc, flags, false);
1338 pp_equal (buffer);
1340 else if (is_array_init
1341 && (TREE_CODE (field) != INTEGER_CST
1342 || tree_to_double_int (field) != curidx))
1344 pp_left_bracket (buffer);
1345 if (TREE_CODE (field) == RANGE_EXPR)
1347 dump_generic_node (buffer, TREE_OPERAND (field, 0), spc,
1348 flags, false);
1349 pp_string (buffer, " ... ");
1350 dump_generic_node (buffer, TREE_OPERAND (field, 1), spc,
1351 flags, false);
1352 if (TREE_CODE (TREE_OPERAND (field, 1)) == INTEGER_CST)
1353 curidx = tree_to_double_int (TREE_OPERAND (field, 1));
1355 else
1356 dump_generic_node (buffer, field, spc, flags, false);
1357 if (TREE_CODE (field) == INTEGER_CST)
1358 curidx = tree_to_double_int (field);
1359 pp_string (buffer, "]=");
1362 if (is_array_init)
1363 curidx += double_int_one;
1364 if (val && TREE_CODE (val) == ADDR_EXPR)
1365 if (TREE_CODE (TREE_OPERAND (val, 0)) == FUNCTION_DECL)
1366 val = TREE_OPERAND (val, 0);
1367 if (val && TREE_CODE (val) == FUNCTION_DECL)
1368 dump_decl_name (buffer, val, flags);
1369 else
1370 dump_generic_node (buffer, val, spc, flags, false);
1371 if (ix != vec_safe_length (CONSTRUCTOR_ELTS (node)) - 1)
1373 pp_comma (buffer);
1374 pp_space (buffer);
1377 pp_right_brace (buffer);
1379 break;
1381 case COMPOUND_EXPR:
1383 tree *tp;
1384 if (flags & TDF_SLIM)
1386 pp_string (buffer, "<COMPOUND_EXPR>");
1387 break;
1390 dump_generic_node (buffer, TREE_OPERAND (node, 0),
1391 spc, flags, !(flags & TDF_SLIM));
1392 if (flags & TDF_SLIM)
1393 newline_and_indent (buffer, spc);
1394 else
1396 pp_comma (buffer);
1397 pp_space (buffer);
1400 for (tp = &TREE_OPERAND (node, 1);
1401 TREE_CODE (*tp) == COMPOUND_EXPR;
1402 tp = &TREE_OPERAND (*tp, 1))
1404 dump_generic_node (buffer, TREE_OPERAND (*tp, 0),
1405 spc, flags, !(flags & TDF_SLIM));
1406 if (flags & TDF_SLIM)
1407 newline_and_indent (buffer, spc);
1408 else
1410 pp_comma (buffer);
1411 pp_space (buffer);
1415 dump_generic_node (buffer, *tp, spc, flags, !(flags & TDF_SLIM));
1417 break;
1419 case STATEMENT_LIST:
1421 tree_stmt_iterator si;
1422 bool first = true;
1424 if (flags & TDF_SLIM)
1426 pp_string (buffer, "<STATEMENT_LIST>");
1427 break;
1430 for (si = tsi_start (node); !tsi_end_p (si); tsi_next (&si))
1432 if (!first)
1433 newline_and_indent (buffer, spc);
1434 else
1435 first = false;
1436 dump_generic_node (buffer, tsi_stmt (si), spc, flags, true);
1439 break;
1441 case MODIFY_EXPR:
1442 case INIT_EXPR:
1443 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags,
1444 false);
1445 pp_space (buffer);
1446 pp_equal (buffer);
1447 pp_space (buffer);
1448 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags,
1449 false);
1450 break;
1452 case TARGET_EXPR:
1453 pp_string (buffer, "TARGET_EXPR <");
1454 dump_generic_node (buffer, TARGET_EXPR_SLOT (node), spc, flags, false);
1455 pp_comma (buffer);
1456 pp_space (buffer);
1457 dump_generic_node (buffer, TARGET_EXPR_INITIAL (node), spc, flags, false);
1458 pp_greater (buffer);
1459 break;
1461 case DECL_EXPR:
1462 print_declaration (buffer, DECL_EXPR_DECL (node), spc, flags);
1463 is_stmt = false;
1464 break;
1466 case COND_EXPR:
1467 if (TREE_TYPE (node) == NULL || TREE_TYPE (node) == void_type_node)
1469 pp_string (buffer, "if (");
1470 dump_generic_node (buffer, COND_EXPR_COND (node), spc, flags, false);
1471 pp_right_paren (buffer);
1472 /* The lowered cond_exprs should always be printed in full. */
1473 if (COND_EXPR_THEN (node)
1474 && (IS_EMPTY_STMT (COND_EXPR_THEN (node))
1475 || TREE_CODE (COND_EXPR_THEN (node)) == GOTO_EXPR)
1476 && COND_EXPR_ELSE (node)
1477 && (IS_EMPTY_STMT (COND_EXPR_ELSE (node))
1478 || TREE_CODE (COND_EXPR_ELSE (node)) == GOTO_EXPR))
1480 pp_space (buffer);
1481 dump_generic_node (buffer, COND_EXPR_THEN (node),
1482 0, flags, true);
1483 if (!IS_EMPTY_STMT (COND_EXPR_ELSE (node)))
1485 pp_string (buffer, " else ");
1486 dump_generic_node (buffer, COND_EXPR_ELSE (node),
1487 0, flags, true);
1490 else if (!(flags & TDF_SLIM))
1492 /* Output COND_EXPR_THEN. */
1493 if (COND_EXPR_THEN (node))
1495 newline_and_indent (buffer, spc+2);
1496 pp_left_brace (buffer);
1497 newline_and_indent (buffer, spc+4);
1498 dump_generic_node (buffer, COND_EXPR_THEN (node), spc+4,
1499 flags, true);
1500 newline_and_indent (buffer, spc+2);
1501 pp_right_brace (buffer);
1504 /* Output COND_EXPR_ELSE. */
1505 if (COND_EXPR_ELSE (node)
1506 && !IS_EMPTY_STMT (COND_EXPR_ELSE (node)))
1508 newline_and_indent (buffer, spc);
1509 pp_string (buffer, "else");
1510 newline_and_indent (buffer, spc+2);
1511 pp_left_brace (buffer);
1512 newline_and_indent (buffer, spc+4);
1513 dump_generic_node (buffer, COND_EXPR_ELSE (node), spc+4,
1514 flags, true);
1515 newline_and_indent (buffer, spc+2);
1516 pp_right_brace (buffer);
1519 is_expr = false;
1521 else
1523 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1524 pp_space (buffer);
1525 pp_question (buffer);
1526 pp_space (buffer);
1527 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1528 pp_space (buffer);
1529 pp_colon (buffer);
1530 pp_space (buffer);
1531 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
1533 break;
1535 case BIND_EXPR:
1536 pp_left_brace (buffer);
1537 if (!(flags & TDF_SLIM))
1539 if (BIND_EXPR_VARS (node))
1541 pp_newline (buffer);
1543 for (op0 = BIND_EXPR_VARS (node); op0; op0 = DECL_CHAIN (op0))
1545 print_declaration (buffer, op0, spc+2, flags);
1546 pp_newline (buffer);
1550 newline_and_indent (buffer, spc+2);
1551 dump_generic_node (buffer, BIND_EXPR_BODY (node), spc+2, flags, true);
1552 newline_and_indent (buffer, spc);
1553 pp_right_brace (buffer);
1555 is_expr = false;
1556 break;
1558 case CALL_EXPR:
1559 print_call_name (buffer, CALL_EXPR_FN (node), flags);
1561 /* Print parameters. */
1562 pp_space (buffer);
1563 pp_left_paren (buffer);
1565 tree arg;
1566 call_expr_arg_iterator iter;
1567 FOR_EACH_CALL_EXPR_ARG (arg, iter, node)
1569 dump_generic_node (buffer, arg, spc, flags, false);
1570 if (more_call_expr_args_p (&iter))
1572 pp_comma (buffer);
1573 pp_space (buffer);
1577 if (CALL_EXPR_VA_ARG_PACK (node))
1579 if (call_expr_nargs (node) > 0)
1581 pp_comma (buffer);
1582 pp_space (buffer);
1584 pp_string (buffer, "__builtin_va_arg_pack ()");
1586 pp_right_paren (buffer);
1588 op1 = CALL_EXPR_STATIC_CHAIN (node);
1589 if (op1)
1591 pp_string (buffer, " [static-chain: ");
1592 dump_generic_node (buffer, op1, spc, flags, false);
1593 pp_right_bracket (buffer);
1596 if (CALL_EXPR_RETURN_SLOT_OPT (node))
1597 pp_string (buffer, " [return slot optimization]");
1598 if (CALL_EXPR_TAILCALL (node))
1599 pp_string (buffer, " [tail call]");
1600 break;
1602 case WITH_CLEANUP_EXPR:
1603 NIY;
1604 break;
1606 case CLEANUP_POINT_EXPR:
1607 pp_string (buffer, "<<cleanup_point ");
1608 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1609 pp_string (buffer, ">>");
1610 break;
1612 case PLACEHOLDER_EXPR:
1613 pp_string (buffer, "<PLACEHOLDER_EXPR ");
1614 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
1615 pp_greater (buffer);
1616 break;
1618 /* Binary arithmetic and logic expressions. */
1619 case WIDEN_SUM_EXPR:
1620 case WIDEN_MULT_EXPR:
1621 case MULT_EXPR:
1622 case MULT_HIGHPART_EXPR:
1623 case PLUS_EXPR:
1624 case POINTER_PLUS_EXPR:
1625 case MINUS_EXPR:
1626 case TRUNC_DIV_EXPR:
1627 case CEIL_DIV_EXPR:
1628 case FLOOR_DIV_EXPR:
1629 case ROUND_DIV_EXPR:
1630 case TRUNC_MOD_EXPR:
1631 case CEIL_MOD_EXPR:
1632 case FLOOR_MOD_EXPR:
1633 case ROUND_MOD_EXPR:
1634 case RDIV_EXPR:
1635 case EXACT_DIV_EXPR:
1636 case LSHIFT_EXPR:
1637 case RSHIFT_EXPR:
1638 case LROTATE_EXPR:
1639 case RROTATE_EXPR:
1640 case VEC_LSHIFT_EXPR:
1641 case VEC_RSHIFT_EXPR:
1642 case WIDEN_LSHIFT_EXPR:
1643 case BIT_IOR_EXPR:
1644 case BIT_XOR_EXPR:
1645 case BIT_AND_EXPR:
1646 case TRUTH_ANDIF_EXPR:
1647 case TRUTH_ORIF_EXPR:
1648 case TRUTH_AND_EXPR:
1649 case TRUTH_OR_EXPR:
1650 case TRUTH_XOR_EXPR:
1651 case LT_EXPR:
1652 case LE_EXPR:
1653 case GT_EXPR:
1654 case GE_EXPR:
1655 case EQ_EXPR:
1656 case NE_EXPR:
1657 case UNLT_EXPR:
1658 case UNLE_EXPR:
1659 case UNGT_EXPR:
1660 case UNGE_EXPR:
1661 case UNEQ_EXPR:
1662 case LTGT_EXPR:
1663 case ORDERED_EXPR:
1664 case UNORDERED_EXPR:
1666 const char *op = op_symbol (node);
1667 op0 = TREE_OPERAND (node, 0);
1668 op1 = TREE_OPERAND (node, 1);
1670 /* When the operands are expressions with less priority,
1671 keep semantics of the tree representation. */
1672 if (op_prio (op0) <= op_prio (node))
1674 pp_left_paren (buffer);
1675 dump_generic_node (buffer, op0, spc, flags, false);
1676 pp_right_paren (buffer);
1678 else
1679 dump_generic_node (buffer, op0, spc, flags, false);
1681 pp_space (buffer);
1682 pp_string (buffer, op);
1683 pp_space (buffer);
1685 /* When the operands are expressions with less priority,
1686 keep semantics of the tree representation. */
1687 if (op_prio (op1) <= op_prio (node))
1689 pp_left_paren (buffer);
1690 dump_generic_node (buffer, op1, spc, flags, false);
1691 pp_right_paren (buffer);
1693 else
1694 dump_generic_node (buffer, op1, spc, flags, false);
1696 break;
1698 /* Unary arithmetic and logic expressions. */
1699 case NEGATE_EXPR:
1700 case BIT_NOT_EXPR:
1701 case TRUTH_NOT_EXPR:
1702 case ADDR_EXPR:
1703 case PREDECREMENT_EXPR:
1704 case PREINCREMENT_EXPR:
1705 case INDIRECT_REF:
1706 if (TREE_CODE (node) == ADDR_EXPR
1707 && (TREE_CODE (TREE_OPERAND (node, 0)) == STRING_CST
1708 || TREE_CODE (TREE_OPERAND (node, 0)) == FUNCTION_DECL))
1709 ; /* Do not output '&' for strings and function pointers. */
1710 else
1711 pp_string (buffer, op_symbol (node));
1713 if (op_prio (TREE_OPERAND (node, 0)) < op_prio (node))
1715 pp_left_paren (buffer);
1716 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1717 pp_right_paren (buffer);
1719 else
1720 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1721 break;
1723 case POSTDECREMENT_EXPR:
1724 case POSTINCREMENT_EXPR:
1725 if (op_prio (TREE_OPERAND (node, 0)) < op_prio (node))
1727 pp_left_paren (buffer);
1728 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1729 pp_right_paren (buffer);
1731 else
1732 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1733 pp_string (buffer, op_symbol (node));
1734 break;
1736 case MIN_EXPR:
1737 pp_string (buffer, "MIN_EXPR <");
1738 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1739 pp_string (buffer, ", ");
1740 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1741 pp_greater (buffer);
1742 break;
1744 case MAX_EXPR:
1745 pp_string (buffer, "MAX_EXPR <");
1746 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1747 pp_string (buffer, ", ");
1748 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1749 pp_greater (buffer);
1750 break;
1752 case ABS_EXPR:
1753 pp_string (buffer, "ABS_EXPR <");
1754 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1755 pp_greater (buffer);
1756 break;
1758 case RANGE_EXPR:
1759 NIY;
1760 break;
1762 case ADDR_SPACE_CONVERT_EXPR:
1763 case FIXED_CONVERT_EXPR:
1764 case FIX_TRUNC_EXPR:
1765 case FLOAT_EXPR:
1766 CASE_CONVERT:
1767 type = TREE_TYPE (node);
1768 op0 = TREE_OPERAND (node, 0);
1769 if (type != TREE_TYPE (op0))
1771 pp_left_paren (buffer);
1772 dump_generic_node (buffer, type, spc, flags, false);
1773 pp_string (buffer, ") ");
1775 if (op_prio (op0) < op_prio (node))
1776 pp_left_paren (buffer);
1777 dump_generic_node (buffer, op0, spc, flags, false);
1778 if (op_prio (op0) < op_prio (node))
1779 pp_right_paren (buffer);
1780 break;
1782 case VIEW_CONVERT_EXPR:
1783 pp_string (buffer, "VIEW_CONVERT_EXPR<");
1784 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
1785 pp_string (buffer, ">(");
1786 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1787 pp_right_paren (buffer);
1788 break;
1790 case PAREN_EXPR:
1791 pp_string (buffer, "((");
1792 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1793 pp_string (buffer, "))");
1794 break;
1796 case NON_LVALUE_EXPR:
1797 pp_string (buffer, "NON_LVALUE_EXPR <");
1798 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1799 pp_greater (buffer);
1800 break;
1802 case SAVE_EXPR:
1803 pp_string (buffer, "SAVE_EXPR <");
1804 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1805 pp_greater (buffer);
1806 break;
1808 case COMPLEX_EXPR:
1809 pp_string (buffer, "COMPLEX_EXPR <");
1810 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1811 pp_string (buffer, ", ");
1812 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1813 pp_greater (buffer);
1814 break;
1816 case CONJ_EXPR:
1817 pp_string (buffer, "CONJ_EXPR <");
1818 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1819 pp_greater (buffer);
1820 break;
1822 case REALPART_EXPR:
1823 pp_string (buffer, "REALPART_EXPR <");
1824 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1825 pp_greater (buffer);
1826 break;
1828 case IMAGPART_EXPR:
1829 pp_string (buffer, "IMAGPART_EXPR <");
1830 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1831 pp_greater (buffer);
1832 break;
1834 case VA_ARG_EXPR:
1835 pp_string (buffer, "VA_ARG_EXPR <");
1836 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1837 pp_greater (buffer);
1838 break;
1840 case TRY_FINALLY_EXPR:
1841 case TRY_CATCH_EXPR:
1842 pp_string (buffer, "try");
1843 newline_and_indent (buffer, spc+2);
1844 pp_left_brace (buffer);
1845 newline_and_indent (buffer, spc+4);
1846 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc+4, flags, true);
1847 newline_and_indent (buffer, spc+2);
1848 pp_right_brace (buffer);
1849 newline_and_indent (buffer, spc);
1850 pp_string (buffer,
1851 (TREE_CODE (node) == TRY_CATCH_EXPR) ? "catch" : "finally");
1852 newline_and_indent (buffer, spc+2);
1853 pp_left_brace (buffer);
1854 newline_and_indent (buffer, spc+4);
1855 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc+4, flags, true);
1856 newline_and_indent (buffer, spc+2);
1857 pp_right_brace (buffer);
1858 is_expr = false;
1859 break;
1861 case CATCH_EXPR:
1862 pp_string (buffer, "catch (");
1863 dump_generic_node (buffer, CATCH_TYPES (node), spc+2, flags, false);
1864 pp_right_paren (buffer);
1865 newline_and_indent (buffer, spc+2);
1866 pp_left_brace (buffer);
1867 newline_and_indent (buffer, spc+4);
1868 dump_generic_node (buffer, CATCH_BODY (node), spc+4, flags, true);
1869 newline_and_indent (buffer, spc+2);
1870 pp_right_brace (buffer);
1871 is_expr = false;
1872 break;
1874 case EH_FILTER_EXPR:
1875 pp_string (buffer, "<<<eh_filter (");
1876 dump_generic_node (buffer, EH_FILTER_TYPES (node), spc+2, flags, false);
1877 pp_string (buffer, ")>>>");
1878 newline_and_indent (buffer, spc+2);
1879 pp_left_brace (buffer);
1880 newline_and_indent (buffer, spc+4);
1881 dump_generic_node (buffer, EH_FILTER_FAILURE (node), spc+4, flags, true);
1882 newline_and_indent (buffer, spc+2);
1883 pp_right_brace (buffer);
1884 is_expr = false;
1885 break;
1887 case LABEL_EXPR:
1888 op0 = TREE_OPERAND (node, 0);
1889 /* If this is for break or continue, don't bother printing it. */
1890 if (DECL_NAME (op0))
1892 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1893 if (strcmp (name, "break") == 0
1894 || strcmp (name, "continue") == 0)
1895 break;
1897 dump_generic_node (buffer, op0, spc, flags, false);
1898 pp_colon (buffer);
1899 if (DECL_NONLOCAL (op0))
1900 pp_string (buffer, " [non-local]");
1901 break;
1903 case LOOP_EXPR:
1904 pp_string (buffer, "while (1)");
1905 if (!(flags & TDF_SLIM))
1907 newline_and_indent (buffer, spc+2);
1908 pp_left_brace (buffer);
1909 newline_and_indent (buffer, spc+4);
1910 dump_generic_node (buffer, LOOP_EXPR_BODY (node), spc+4, flags, true);
1911 newline_and_indent (buffer, spc+2);
1912 pp_right_brace (buffer);
1914 is_expr = false;
1915 break;
1917 case PREDICT_EXPR:
1918 pp_string (buffer, "// predicted ");
1919 if (PREDICT_EXPR_OUTCOME (node))
1920 pp_string (buffer, "likely by ");
1921 else
1922 pp_string (buffer, "unlikely by ");
1923 pp_string (buffer, predictor_name (PREDICT_EXPR_PREDICTOR (node)));
1924 pp_string (buffer, " predictor.");
1925 break;
1927 case RETURN_EXPR:
1928 pp_string (buffer, "return");
1929 op0 = TREE_OPERAND (node, 0);
1930 if (op0)
1932 pp_space (buffer);
1933 if (TREE_CODE (op0) == MODIFY_EXPR)
1934 dump_generic_node (buffer, TREE_OPERAND (op0, 1),
1935 spc, flags, false);
1936 else
1937 dump_generic_node (buffer, op0, spc, flags, false);
1939 break;
1941 case EXIT_EXPR:
1942 pp_string (buffer, "if (");
1943 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1944 pp_string (buffer, ") break");
1945 break;
1947 case SWITCH_EXPR:
1948 pp_string (buffer, "switch (");
1949 dump_generic_node (buffer, SWITCH_COND (node), spc, flags, false);
1950 pp_right_paren (buffer);
1951 if (!(flags & TDF_SLIM))
1953 newline_and_indent (buffer, spc+2);
1954 pp_left_brace (buffer);
1955 if (SWITCH_BODY (node))
1957 newline_and_indent (buffer, spc+4);
1958 dump_generic_node (buffer, SWITCH_BODY (node), spc+4, flags,
1959 true);
1961 else
1963 tree vec = SWITCH_LABELS (node);
1964 size_t i, n = TREE_VEC_LENGTH (vec);
1965 for (i = 0; i < n; ++i)
1967 tree elt = TREE_VEC_ELT (vec, i);
1968 newline_and_indent (buffer, spc+4);
1969 if (elt)
1971 dump_generic_node (buffer, elt, spc+4, flags, false);
1972 pp_string (buffer, " goto ");
1973 dump_generic_node (buffer, CASE_LABEL (elt), spc+4,
1974 flags, true);
1975 pp_semicolon (buffer);
1977 else
1978 pp_string (buffer, "case ???: goto ???;");
1981 newline_and_indent (buffer, spc+2);
1982 pp_right_brace (buffer);
1984 is_expr = false;
1985 break;
1987 case GOTO_EXPR:
1988 op0 = GOTO_DESTINATION (node);
1989 if (TREE_CODE (op0) != SSA_NAME && DECL_P (op0) && DECL_NAME (op0))
1991 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1992 if (strcmp (name, "break") == 0
1993 || strcmp (name, "continue") == 0)
1995 pp_string (buffer, name);
1996 break;
1999 pp_string (buffer, "goto ");
2000 dump_generic_node (buffer, op0, spc, flags, false);
2001 break;
2003 case ASM_EXPR:
2004 pp_string (buffer, "__asm__");
2005 if (ASM_VOLATILE_P (node))
2006 pp_string (buffer, " __volatile__");
2007 pp_left_paren (buffer);
2008 dump_generic_node (buffer, ASM_STRING (node), spc, flags, false);
2009 pp_colon (buffer);
2010 dump_generic_node (buffer, ASM_OUTPUTS (node), spc, flags, false);
2011 pp_colon (buffer);
2012 dump_generic_node (buffer, ASM_INPUTS (node), spc, flags, false);
2013 if (ASM_CLOBBERS (node))
2015 pp_colon (buffer);
2016 dump_generic_node (buffer, ASM_CLOBBERS (node), spc, flags, false);
2018 pp_right_paren (buffer);
2019 break;
2021 case CASE_LABEL_EXPR:
2022 if (CASE_LOW (node) && CASE_HIGH (node))
2024 pp_string (buffer, "case ");
2025 dump_generic_node (buffer, CASE_LOW (node), spc, flags, false);
2026 pp_string (buffer, " ... ");
2027 dump_generic_node (buffer, CASE_HIGH (node), spc, flags, false);
2029 else if (CASE_LOW (node))
2031 pp_string (buffer, "case ");
2032 dump_generic_node (buffer, CASE_LOW (node), spc, flags, false);
2034 else
2035 pp_string (buffer, "default");
2036 pp_colon (buffer);
2037 break;
2039 case OBJ_TYPE_REF:
2040 pp_string (buffer, "OBJ_TYPE_REF(");
2041 dump_generic_node (buffer, OBJ_TYPE_REF_EXPR (node), spc, flags, false);
2042 pp_semicolon (buffer);
2043 dump_generic_node (buffer, OBJ_TYPE_REF_OBJECT (node), spc, flags, false);
2044 pp_arrow (buffer);
2045 dump_generic_node (buffer, OBJ_TYPE_REF_TOKEN (node), spc, flags, false);
2046 pp_right_paren (buffer);
2047 break;
2049 case SSA_NAME:
2050 if (SSA_NAME_IDENTIFIER (node))
2051 dump_generic_node (buffer, SSA_NAME_IDENTIFIER (node),
2052 spc, flags, false);
2053 pp_underscore (buffer);
2054 pp_decimal_int (buffer, SSA_NAME_VERSION (node));
2055 if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (node))
2056 pp_string (buffer, "(ab)");
2057 else if (SSA_NAME_IS_DEFAULT_DEF (node))
2058 pp_string (buffer, "(D)");
2059 break;
2061 case WITH_SIZE_EXPR:
2062 pp_string (buffer, "WITH_SIZE_EXPR <");
2063 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2064 pp_string (buffer, ", ");
2065 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2066 pp_greater (buffer);
2067 break;
2069 case ASSERT_EXPR:
2070 pp_string (buffer, "ASSERT_EXPR <");
2071 dump_generic_node (buffer, ASSERT_EXPR_VAR (node), spc, flags, false);
2072 pp_string (buffer, ", ");
2073 dump_generic_node (buffer, ASSERT_EXPR_COND (node), spc, flags, false);
2074 pp_greater (buffer);
2075 break;
2077 case SCEV_KNOWN:
2078 pp_string (buffer, "scev_known");
2079 break;
2081 case SCEV_NOT_KNOWN:
2082 pp_string (buffer, "scev_not_known");
2083 break;
2085 case POLYNOMIAL_CHREC:
2086 pp_left_brace (buffer);
2087 dump_generic_node (buffer, CHREC_LEFT (node), spc, flags, false);
2088 pp_string (buffer, ", +, ");
2089 dump_generic_node (buffer, CHREC_RIGHT (node), spc, flags, false);
2090 pp_string (buffer, "}_");
2091 dump_generic_node (buffer, CHREC_VAR (node), spc, flags, false);
2092 is_stmt = false;
2093 break;
2095 case REALIGN_LOAD_EXPR:
2096 pp_string (buffer, "REALIGN_LOAD <");
2097 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2098 pp_string (buffer, ", ");
2099 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2100 pp_string (buffer, ", ");
2101 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
2102 pp_greater (buffer);
2103 break;
2105 case VEC_COND_EXPR:
2106 pp_string (buffer, " VEC_COND_EXPR < ");
2107 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2108 pp_string (buffer, " , ");
2109 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2110 pp_string (buffer, " , ");
2111 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
2112 pp_string (buffer, " > ");
2113 break;
2115 case VEC_PERM_EXPR:
2116 pp_string (buffer, " VEC_PERM_EXPR < ");
2117 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2118 pp_string (buffer, " , ");
2119 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2120 pp_string (buffer, " , ");
2121 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
2122 pp_string (buffer, " > ");
2123 break;
2125 case DOT_PROD_EXPR:
2126 pp_string (buffer, " DOT_PROD_EXPR < ");
2127 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2128 pp_string (buffer, ", ");
2129 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2130 pp_string (buffer, ", ");
2131 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
2132 pp_string (buffer, " > ");
2133 break;
2135 case WIDEN_MULT_PLUS_EXPR:
2136 pp_string (buffer, " WIDEN_MULT_PLUS_EXPR < ");
2137 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2138 pp_string (buffer, ", ");
2139 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2140 pp_string (buffer, ", ");
2141 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
2142 pp_string (buffer, " > ");
2143 break;
2145 case WIDEN_MULT_MINUS_EXPR:
2146 pp_string (buffer, " WIDEN_MULT_MINUS_EXPR < ");
2147 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2148 pp_string (buffer, ", ");
2149 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2150 pp_string (buffer, ", ");
2151 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
2152 pp_string (buffer, " > ");
2153 break;
2155 case FMA_EXPR:
2156 pp_string (buffer, " FMA_EXPR < ");
2157 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2158 pp_string (buffer, ", ");
2159 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2160 pp_string (buffer, ", ");
2161 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
2162 pp_string (buffer, " > ");
2163 break;
2165 case OMP_PARALLEL:
2166 pp_string (buffer, "#pragma omp parallel");
2167 dump_omp_clauses (buffer, OMP_PARALLEL_CLAUSES (node), spc, flags);
2169 dump_omp_body:
2170 if (!(flags & TDF_SLIM) && OMP_BODY (node))
2172 newline_and_indent (buffer, spc + 2);
2173 pp_left_brace (buffer);
2174 newline_and_indent (buffer, spc + 4);
2175 dump_generic_node (buffer, OMP_BODY (node), spc + 4, flags, false);
2176 newline_and_indent (buffer, spc + 2);
2177 pp_right_brace (buffer);
2179 is_expr = false;
2180 break;
2182 case OMP_TASK:
2183 pp_string (buffer, "#pragma omp task");
2184 dump_omp_clauses (buffer, OMP_TASK_CLAUSES (node), spc, flags);
2185 goto dump_omp_body;
2187 case OMP_FOR:
2188 pp_string (buffer, "#pragma omp for");
2189 goto dump_omp_loop;
2191 case OMP_SIMD:
2192 pp_string (buffer, "#pragma omp simd");
2193 goto dump_omp_loop;
2195 dump_omp_loop:
2196 dump_omp_clauses (buffer, OMP_FOR_CLAUSES (node), spc, flags);
2198 if (!(flags & TDF_SLIM))
2200 int i;
2202 if (OMP_FOR_PRE_BODY (node))
2204 newline_and_indent (buffer, spc + 2);
2205 pp_left_brace (buffer);
2206 spc += 4;
2207 newline_and_indent (buffer, spc);
2208 dump_generic_node (buffer, OMP_FOR_PRE_BODY (node),
2209 spc, flags, false);
2211 spc -= 2;
2212 for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (node)); i++)
2214 spc += 2;
2215 newline_and_indent (buffer, spc);
2216 pp_string (buffer, "for (");
2217 dump_generic_node (buffer, TREE_VEC_ELT (OMP_FOR_INIT (node), i),
2218 spc, flags, false);
2219 pp_string (buffer, "; ");
2220 dump_generic_node (buffer, TREE_VEC_ELT (OMP_FOR_COND (node), i),
2221 spc, flags, false);
2222 pp_string (buffer, "; ");
2223 dump_generic_node (buffer, TREE_VEC_ELT (OMP_FOR_INCR (node), i),
2224 spc, flags, false);
2225 pp_right_paren (buffer);
2227 if (OMP_FOR_BODY (node))
2229 newline_and_indent (buffer, spc + 2);
2230 pp_left_brace (buffer);
2231 newline_and_indent (buffer, spc + 4);
2232 dump_generic_node (buffer, OMP_FOR_BODY (node), spc + 4, flags,
2233 false);
2234 newline_and_indent (buffer, spc + 2);
2235 pp_right_brace (buffer);
2237 spc -= 2 * TREE_VEC_LENGTH (OMP_FOR_INIT (node)) - 2;
2238 if (OMP_FOR_PRE_BODY (node))
2240 spc -= 4;
2241 newline_and_indent (buffer, spc + 2);
2242 pp_right_brace (buffer);
2245 is_expr = false;
2246 break;
2248 case OMP_SECTIONS:
2249 pp_string (buffer, "#pragma omp sections");
2250 dump_omp_clauses (buffer, OMP_SECTIONS_CLAUSES (node), spc, flags);
2251 goto dump_omp_body;
2253 case OMP_SECTION:
2254 pp_string (buffer, "#pragma omp section");
2255 goto dump_omp_body;
2257 case OMP_MASTER:
2258 pp_string (buffer, "#pragma omp master");
2259 goto dump_omp_body;
2261 case OMP_ORDERED:
2262 pp_string (buffer, "#pragma omp ordered");
2263 goto dump_omp_body;
2265 case OMP_CRITICAL:
2266 pp_string (buffer, "#pragma omp critical");
2267 if (OMP_CRITICAL_NAME (node))
2269 pp_space (buffer);
2270 pp_left_paren (buffer);
2271 dump_generic_node (buffer, OMP_CRITICAL_NAME (node), spc,
2272 flags, false);
2273 pp_right_paren (buffer);
2275 goto dump_omp_body;
2277 case OMP_ATOMIC:
2278 pp_string (buffer, "#pragma omp atomic");
2279 newline_and_indent (buffer, spc + 2);
2280 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2281 pp_space (buffer);
2282 pp_equal (buffer);
2283 pp_space (buffer);
2284 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2285 break;
2287 case OMP_ATOMIC_READ:
2288 pp_string (buffer, "#pragma omp atomic read");
2289 newline_and_indent (buffer, spc + 2);
2290 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2291 pp_space (buffer);
2292 break;
2294 case OMP_ATOMIC_CAPTURE_OLD:
2295 case OMP_ATOMIC_CAPTURE_NEW:
2296 pp_string (buffer, "#pragma omp atomic capture");
2297 newline_and_indent (buffer, spc + 2);
2298 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2299 pp_space (buffer);
2300 pp_equal (buffer);
2301 pp_space (buffer);
2302 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2303 break;
2305 case OMP_SINGLE:
2306 pp_string (buffer, "#pragma omp single");
2307 dump_omp_clauses (buffer, OMP_SINGLE_CLAUSES (node), spc, flags);
2308 goto dump_omp_body;
2310 case OMP_CLAUSE:
2311 dump_omp_clause (buffer, node, spc, flags);
2312 is_expr = false;
2313 break;
2315 case TRANSACTION_EXPR:
2316 if (TRANSACTION_EXPR_OUTER (node))
2317 pp_string (buffer, "__transaction_atomic [[outer]]");
2318 else if (TRANSACTION_EXPR_RELAXED (node))
2319 pp_string (buffer, "__transaction_relaxed");
2320 else
2321 pp_string (buffer, "__transaction_atomic");
2322 if (!(flags & TDF_SLIM) && TRANSACTION_EXPR_BODY (node))
2324 newline_and_indent (buffer, spc);
2325 pp_left_brace (buffer);
2326 newline_and_indent (buffer, spc + 2);
2327 dump_generic_node (buffer, TRANSACTION_EXPR_BODY (node),
2328 spc + 2, flags, false);
2329 newline_and_indent (buffer, spc);
2330 pp_right_brace (buffer);
2332 is_expr = false;
2333 break;
2335 case REDUC_MAX_EXPR:
2336 pp_string (buffer, " REDUC_MAX_EXPR < ");
2337 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2338 pp_string (buffer, " > ");
2339 break;
2341 case REDUC_MIN_EXPR:
2342 pp_string (buffer, " REDUC_MIN_EXPR < ");
2343 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2344 pp_string (buffer, " > ");
2345 break;
2347 case REDUC_PLUS_EXPR:
2348 pp_string (buffer, " REDUC_PLUS_EXPR < ");
2349 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2350 pp_string (buffer, " > ");
2351 break;
2353 case VEC_WIDEN_MULT_HI_EXPR:
2354 case VEC_WIDEN_MULT_LO_EXPR:
2355 case VEC_WIDEN_MULT_EVEN_EXPR:
2356 case VEC_WIDEN_MULT_ODD_EXPR:
2357 case VEC_WIDEN_LSHIFT_HI_EXPR:
2358 case VEC_WIDEN_LSHIFT_LO_EXPR:
2359 pp_space (buffer);
2360 for (str = tree_code_name [code]; *str; str++)
2361 pp_character (buffer, TOUPPER (*str));
2362 pp_string (buffer, " < ");
2363 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2364 pp_string (buffer, ", ");
2365 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2366 pp_string (buffer, " > ");
2367 break;
2369 case VEC_UNPACK_HI_EXPR:
2370 pp_string (buffer, " VEC_UNPACK_HI_EXPR < ");
2371 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2372 pp_string (buffer, " > ");
2373 break;
2375 case VEC_UNPACK_LO_EXPR:
2376 pp_string (buffer, " VEC_UNPACK_LO_EXPR < ");
2377 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2378 pp_string (buffer, " > ");
2379 break;
2381 case VEC_UNPACK_FLOAT_HI_EXPR:
2382 pp_string (buffer, " VEC_UNPACK_FLOAT_HI_EXPR < ");
2383 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2384 pp_string (buffer, " > ");
2385 break;
2387 case VEC_UNPACK_FLOAT_LO_EXPR:
2388 pp_string (buffer, " VEC_UNPACK_FLOAT_LO_EXPR < ");
2389 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2390 pp_string (buffer, " > ");
2391 break;
2393 case VEC_PACK_TRUNC_EXPR:
2394 pp_string (buffer, " VEC_PACK_TRUNC_EXPR < ");
2395 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2396 pp_string (buffer, ", ");
2397 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2398 pp_string (buffer, " > ");
2399 break;
2401 case VEC_PACK_SAT_EXPR:
2402 pp_string (buffer, " VEC_PACK_SAT_EXPR < ");
2403 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2404 pp_string (buffer, ", ");
2405 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2406 pp_string (buffer, " > ");
2407 break;
2409 case VEC_PACK_FIX_TRUNC_EXPR:
2410 pp_string (buffer, " VEC_PACK_FIX_TRUNC_EXPR < ");
2411 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2412 pp_string (buffer, ", ");
2413 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2414 pp_string (buffer, " > ");
2415 break;
2417 case BLOCK:
2418 dump_block_node (buffer, node, spc, flags);
2419 break;
2421 default:
2422 NIY;
2425 if (is_stmt && is_expr)
2426 pp_semicolon (buffer);
2428 return spc;
2431 /* Print the declaration of a variable. */
2433 void
2434 print_declaration (pretty_printer *buffer, tree t, int spc, int flags)
2436 INDENT (spc);
2438 if (TREE_CODE (t) == TYPE_DECL)
2439 pp_string (buffer, "typedef ");
2441 if (CODE_CONTAINS_STRUCT (TREE_CODE (t), TS_DECL_WRTL) && DECL_REGISTER (t))
2442 pp_string (buffer, "register ");
2444 if (TREE_PUBLIC (t) && DECL_EXTERNAL (t))
2445 pp_string (buffer, "extern ");
2446 else if (TREE_STATIC (t))
2447 pp_string (buffer, "static ");
2449 /* Print the type and name. */
2450 if (TREE_TYPE (t) && TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
2452 tree tmp;
2454 /* Print array's type. */
2455 tmp = TREE_TYPE (t);
2456 while (TREE_CODE (TREE_TYPE (tmp)) == ARRAY_TYPE)
2457 tmp = TREE_TYPE (tmp);
2458 dump_generic_node (buffer, TREE_TYPE (tmp), spc, flags, false);
2460 /* Print variable's name. */
2461 pp_space (buffer);
2462 dump_generic_node (buffer, t, spc, flags, false);
2464 /* Print the dimensions. */
2465 tmp = TREE_TYPE (t);
2466 while (TREE_CODE (tmp) == ARRAY_TYPE)
2468 dump_array_domain (buffer, TYPE_DOMAIN (tmp), spc, flags);
2469 tmp = TREE_TYPE (tmp);
2472 else if (TREE_CODE (t) == FUNCTION_DECL)
2474 dump_generic_node (buffer, TREE_TYPE (TREE_TYPE (t)), spc, flags, false);
2475 pp_space (buffer);
2476 dump_decl_name (buffer, t, flags);
2477 dump_function_declaration (buffer, TREE_TYPE (t), spc, flags);
2479 else
2481 /* Print type declaration. */
2482 dump_generic_node (buffer, TREE_TYPE (t), spc, flags, false);
2484 /* Print variable's name. */
2485 pp_space (buffer);
2486 dump_generic_node (buffer, t, spc, flags, false);
2489 if (TREE_CODE (t) == VAR_DECL && DECL_HARD_REGISTER (t))
2491 pp_string (buffer, " __asm__ ");
2492 pp_left_paren (buffer);
2493 dump_generic_node (buffer, DECL_ASSEMBLER_NAME (t), spc, flags, false);
2494 pp_right_paren (buffer);
2497 /* The initial value of a function serves to determine whether the function
2498 is declared or defined. So the following does not apply to function
2499 nodes. */
2500 if (TREE_CODE (t) != FUNCTION_DECL)
2502 /* Print the initial value. */
2503 if (DECL_INITIAL (t))
2505 pp_space (buffer);
2506 pp_equal (buffer);
2507 pp_space (buffer);
2508 dump_generic_node (buffer, DECL_INITIAL (t), spc, flags, false);
2512 if (TREE_CODE (t) == VAR_DECL && DECL_HAS_VALUE_EXPR_P (t))
2514 pp_string (buffer, " [value-expr: ");
2515 dump_generic_node (buffer, DECL_VALUE_EXPR (t), spc, flags, false);
2516 pp_right_bracket (buffer);
2519 pp_semicolon (buffer);
2523 /* Prints a structure: name, fields, and methods.
2524 FIXME: Still incomplete. */
2526 static void
2527 print_struct_decl (pretty_printer *buffer, const_tree node, int spc, int flags)
2529 /* Print the name of the structure. */
2530 if (TYPE_NAME (node))
2532 INDENT (spc);
2533 if (TREE_CODE (node) == RECORD_TYPE)
2534 pp_string (buffer, "struct ");
2535 else if ((TREE_CODE (node) == UNION_TYPE
2536 || TREE_CODE (node) == QUAL_UNION_TYPE))
2537 pp_string (buffer, "union ");
2539 dump_generic_node (buffer, TYPE_NAME (node), spc, 0, false);
2542 /* Print the contents of the structure. */
2543 pp_newline (buffer);
2544 INDENT (spc);
2545 pp_left_brace (buffer);
2546 pp_newline (buffer);
2548 /* Print the fields of the structure. */
2550 tree tmp;
2551 tmp = TYPE_FIELDS (node);
2552 while (tmp)
2554 /* Avoid to print recursively the structure. */
2555 /* FIXME : Not implemented correctly...,
2556 what about the case when we have a cycle in the contain graph? ...
2557 Maybe this could be solved by looking at the scope in which the
2558 structure was declared. */
2559 if (TREE_TYPE (tmp) != node
2560 && (TREE_CODE (TREE_TYPE (tmp)) != POINTER_TYPE
2561 || TREE_TYPE (TREE_TYPE (tmp)) != node))
2563 print_declaration (buffer, tmp, spc+2, flags);
2564 pp_newline (buffer);
2566 tmp = DECL_CHAIN (tmp);
2569 INDENT (spc);
2570 pp_right_brace (buffer);
2573 /* Return the priority of the operator CODE.
2575 From lowest to highest precedence with either left-to-right (L-R)
2576 or right-to-left (R-L) associativity]:
2578 1 [L-R] ,
2579 2 [R-L] = += -= *= /= %= &= ^= |= <<= >>=
2580 3 [R-L] ?:
2581 4 [L-R] ||
2582 5 [L-R] &&
2583 6 [L-R] |
2584 7 [L-R] ^
2585 8 [L-R] &
2586 9 [L-R] == !=
2587 10 [L-R] < <= > >=
2588 11 [L-R] << >>
2589 12 [L-R] + -
2590 13 [L-R] * / %
2591 14 [R-L] ! ~ ++ -- + - * & (type) sizeof
2592 15 [L-R] fn() [] -> .
2594 unary +, - and * have higher precedence than the corresponding binary
2595 operators. */
2598 op_code_prio (enum tree_code code)
2600 switch (code)
2602 case TREE_LIST:
2603 case COMPOUND_EXPR:
2604 case BIND_EXPR:
2605 return 1;
2607 case MODIFY_EXPR:
2608 case INIT_EXPR:
2609 return 2;
2611 case COND_EXPR:
2612 return 3;
2614 case TRUTH_OR_EXPR:
2615 case TRUTH_ORIF_EXPR:
2616 return 4;
2618 case TRUTH_AND_EXPR:
2619 case TRUTH_ANDIF_EXPR:
2620 return 5;
2622 case BIT_IOR_EXPR:
2623 return 6;
2625 case BIT_XOR_EXPR:
2626 case TRUTH_XOR_EXPR:
2627 return 7;
2629 case BIT_AND_EXPR:
2630 return 8;
2632 case EQ_EXPR:
2633 case NE_EXPR:
2634 return 9;
2636 case UNLT_EXPR:
2637 case UNLE_EXPR:
2638 case UNGT_EXPR:
2639 case UNGE_EXPR:
2640 case UNEQ_EXPR:
2641 case LTGT_EXPR:
2642 case ORDERED_EXPR:
2643 case UNORDERED_EXPR:
2644 case LT_EXPR:
2645 case LE_EXPR:
2646 case GT_EXPR:
2647 case GE_EXPR:
2648 return 10;
2650 case LSHIFT_EXPR:
2651 case RSHIFT_EXPR:
2652 case LROTATE_EXPR:
2653 case RROTATE_EXPR:
2654 case VEC_WIDEN_LSHIFT_HI_EXPR:
2655 case VEC_WIDEN_LSHIFT_LO_EXPR:
2656 case WIDEN_LSHIFT_EXPR:
2657 return 11;
2659 case WIDEN_SUM_EXPR:
2660 case PLUS_EXPR:
2661 case POINTER_PLUS_EXPR:
2662 case MINUS_EXPR:
2663 return 12;
2665 case VEC_WIDEN_MULT_HI_EXPR:
2666 case VEC_WIDEN_MULT_LO_EXPR:
2667 case WIDEN_MULT_EXPR:
2668 case DOT_PROD_EXPR:
2669 case WIDEN_MULT_PLUS_EXPR:
2670 case WIDEN_MULT_MINUS_EXPR:
2671 case MULT_EXPR:
2672 case MULT_HIGHPART_EXPR:
2673 case TRUNC_DIV_EXPR:
2674 case CEIL_DIV_EXPR:
2675 case FLOOR_DIV_EXPR:
2676 case ROUND_DIV_EXPR:
2677 case RDIV_EXPR:
2678 case EXACT_DIV_EXPR:
2679 case TRUNC_MOD_EXPR:
2680 case CEIL_MOD_EXPR:
2681 case FLOOR_MOD_EXPR:
2682 case ROUND_MOD_EXPR:
2683 case FMA_EXPR:
2684 return 13;
2686 case TRUTH_NOT_EXPR:
2687 case BIT_NOT_EXPR:
2688 case POSTINCREMENT_EXPR:
2689 case POSTDECREMENT_EXPR:
2690 case PREINCREMENT_EXPR:
2691 case PREDECREMENT_EXPR:
2692 case NEGATE_EXPR:
2693 case INDIRECT_REF:
2694 case ADDR_EXPR:
2695 case FLOAT_EXPR:
2696 CASE_CONVERT:
2697 case FIX_TRUNC_EXPR:
2698 case TARGET_EXPR:
2699 return 14;
2701 case CALL_EXPR:
2702 case ARRAY_REF:
2703 case ARRAY_RANGE_REF:
2704 case COMPONENT_REF:
2705 return 15;
2707 /* Special expressions. */
2708 case MIN_EXPR:
2709 case MAX_EXPR:
2710 case ABS_EXPR:
2711 case REALPART_EXPR:
2712 case IMAGPART_EXPR:
2713 case REDUC_MAX_EXPR:
2714 case REDUC_MIN_EXPR:
2715 case REDUC_PLUS_EXPR:
2716 case VEC_LSHIFT_EXPR:
2717 case VEC_RSHIFT_EXPR:
2718 case VEC_UNPACK_HI_EXPR:
2719 case VEC_UNPACK_LO_EXPR:
2720 case VEC_UNPACK_FLOAT_HI_EXPR:
2721 case VEC_UNPACK_FLOAT_LO_EXPR:
2722 case VEC_PACK_TRUNC_EXPR:
2723 case VEC_PACK_SAT_EXPR:
2724 return 16;
2726 default:
2727 /* Return an arbitrarily high precedence to avoid surrounding single
2728 VAR_DECLs in ()s. */
2729 return 9999;
2733 /* Return the priority of the operator OP. */
2736 op_prio (const_tree op)
2738 enum tree_code code;
2740 if (op == NULL)
2741 return 9999;
2743 code = TREE_CODE (op);
2744 if (code == SAVE_EXPR || code == NON_LVALUE_EXPR)
2745 return op_prio (TREE_OPERAND (op, 0));
2747 return op_code_prio (code);
2750 /* Return the symbol associated with operator CODE. */
2752 const char *
2753 op_symbol_code (enum tree_code code)
2755 switch (code)
2757 case MODIFY_EXPR:
2758 return "=";
2760 case TRUTH_OR_EXPR:
2761 case TRUTH_ORIF_EXPR:
2762 return "||";
2764 case TRUTH_AND_EXPR:
2765 case TRUTH_ANDIF_EXPR:
2766 return "&&";
2768 case BIT_IOR_EXPR:
2769 return "|";
2771 case TRUTH_XOR_EXPR:
2772 case BIT_XOR_EXPR:
2773 return "^";
2775 case ADDR_EXPR:
2776 case BIT_AND_EXPR:
2777 return "&";
2779 case ORDERED_EXPR:
2780 return "ord";
2781 case UNORDERED_EXPR:
2782 return "unord";
2784 case EQ_EXPR:
2785 return "==";
2786 case UNEQ_EXPR:
2787 return "u==";
2789 case NE_EXPR:
2790 return "!=";
2792 case LT_EXPR:
2793 return "<";
2794 case UNLT_EXPR:
2795 return "u<";
2797 case LE_EXPR:
2798 return "<=";
2799 case UNLE_EXPR:
2800 return "u<=";
2802 case GT_EXPR:
2803 return ">";
2804 case UNGT_EXPR:
2805 return "u>";
2807 case GE_EXPR:
2808 return ">=";
2809 case UNGE_EXPR:
2810 return "u>=";
2812 case LTGT_EXPR:
2813 return "<>";
2815 case LSHIFT_EXPR:
2816 return "<<";
2818 case RSHIFT_EXPR:
2819 return ">>";
2821 case LROTATE_EXPR:
2822 return "r<<";
2824 case RROTATE_EXPR:
2825 return "r>>";
2827 case VEC_LSHIFT_EXPR:
2828 return "v<<";
2830 case VEC_RSHIFT_EXPR:
2831 return "v>>";
2833 case WIDEN_LSHIFT_EXPR:
2834 return "w<<";
2836 case POINTER_PLUS_EXPR:
2837 return "+";
2839 case PLUS_EXPR:
2840 return "+";
2842 case REDUC_PLUS_EXPR:
2843 return "r+";
2845 case WIDEN_SUM_EXPR:
2846 return "w+";
2848 case WIDEN_MULT_EXPR:
2849 return "w*";
2851 case MULT_HIGHPART_EXPR:
2852 return "h*";
2854 case NEGATE_EXPR:
2855 case MINUS_EXPR:
2856 return "-";
2858 case BIT_NOT_EXPR:
2859 return "~";
2861 case TRUTH_NOT_EXPR:
2862 return "!";
2864 case MULT_EXPR:
2865 case INDIRECT_REF:
2866 return "*";
2868 case TRUNC_DIV_EXPR:
2869 case RDIV_EXPR:
2870 return "/";
2872 case CEIL_DIV_EXPR:
2873 return "/[cl]";
2875 case FLOOR_DIV_EXPR:
2876 return "/[fl]";
2878 case ROUND_DIV_EXPR:
2879 return "/[rd]";
2881 case EXACT_DIV_EXPR:
2882 return "/[ex]";
2884 case TRUNC_MOD_EXPR:
2885 return "%";
2887 case CEIL_MOD_EXPR:
2888 return "%[cl]";
2890 case FLOOR_MOD_EXPR:
2891 return "%[fl]";
2893 case ROUND_MOD_EXPR:
2894 return "%[rd]";
2896 case PREDECREMENT_EXPR:
2897 return " --";
2899 case PREINCREMENT_EXPR:
2900 return " ++";
2902 case POSTDECREMENT_EXPR:
2903 return "-- ";
2905 case POSTINCREMENT_EXPR:
2906 return "++ ";
2908 case MAX_EXPR:
2909 return "max";
2911 case MIN_EXPR:
2912 return "min";
2914 default:
2915 return "<<< ??? >>>";
2919 /* Return the symbol associated with operator OP. */
2921 static const char *
2922 op_symbol (const_tree op)
2924 return op_symbol_code (TREE_CODE (op));
2927 /* Prints the name of a call. NODE is the CALL_EXPR_FN of a CALL_EXPR or
2928 the gimple_call_fn of a GIMPLE_CALL. */
2930 void
2931 print_call_name (pretty_printer *buffer, tree node, int flags)
2933 tree op0 = node;
2935 if (TREE_CODE (op0) == NON_LVALUE_EXPR)
2936 op0 = TREE_OPERAND (op0, 0);
2938 again:
2939 switch (TREE_CODE (op0))
2941 case VAR_DECL:
2942 case PARM_DECL:
2943 case FUNCTION_DECL:
2944 dump_function_name (buffer, op0, flags);
2945 break;
2947 case ADDR_EXPR:
2948 case INDIRECT_REF:
2949 case NOP_EXPR:
2950 op0 = TREE_OPERAND (op0, 0);
2951 goto again;
2953 case COND_EXPR:
2954 pp_left_paren (buffer);
2955 dump_generic_node (buffer, TREE_OPERAND (op0, 0), 0, flags, false);
2956 pp_string (buffer, ") ? ");
2957 dump_generic_node (buffer, TREE_OPERAND (op0, 1), 0, flags, false);
2958 pp_string (buffer, " : ");
2959 dump_generic_node (buffer, TREE_OPERAND (op0, 2), 0, flags, false);
2960 break;
2962 case ARRAY_REF:
2963 if (TREE_CODE (TREE_OPERAND (op0, 0)) == VAR_DECL)
2964 dump_function_name (buffer, TREE_OPERAND (op0, 0), flags);
2965 else
2966 dump_generic_node (buffer, op0, 0, flags, false);
2967 break;
2969 case MEM_REF:
2970 if (integer_zerop (TREE_OPERAND (op0, 1)))
2972 op0 = TREE_OPERAND (op0, 0);
2973 goto again;
2975 /* Fallthru. */
2976 case COMPONENT_REF:
2977 case SSA_NAME:
2978 case OBJ_TYPE_REF:
2979 dump_generic_node (buffer, op0, 0, flags, false);
2980 break;
2982 default:
2983 NIY;
2987 /* Parses the string STR and replaces new-lines by '\n', tabs by '\t', ... */
2989 static void
2990 pretty_print_string (pretty_printer *buffer, const char *str)
2992 if (str == NULL)
2993 return;
2995 while (*str)
2997 switch (str[0])
2999 case '\b':
3000 pp_string (buffer, "\\b");
3001 break;
3003 case '\f':
3004 pp_string (buffer, "\\f");
3005 break;
3007 case '\n':
3008 pp_string (buffer, "\\n");
3009 break;
3011 case '\r':
3012 pp_string (buffer, "\\r");
3013 break;
3015 case '\t':
3016 pp_string (buffer, "\\t");
3017 break;
3019 case '\v':
3020 pp_string (buffer, "\\v");
3021 break;
3023 case '\\':
3024 pp_string (buffer, "\\\\");
3025 break;
3027 case '\"':
3028 pp_string (buffer, "\\\"");
3029 break;
3031 case '\'':
3032 pp_string (buffer, "\\'");
3033 break;
3035 /* No need to handle \0; the loop terminates on \0. */
3037 case '\1':
3038 pp_string (buffer, "\\1");
3039 break;
3041 case '\2':
3042 pp_string (buffer, "\\2");
3043 break;
3045 case '\3':
3046 pp_string (buffer, "\\3");
3047 break;
3049 case '\4':
3050 pp_string (buffer, "\\4");
3051 break;
3053 case '\5':
3054 pp_string (buffer, "\\5");
3055 break;
3057 case '\6':
3058 pp_string (buffer, "\\6");
3059 break;
3061 case '\7':
3062 pp_string (buffer, "\\7");
3063 break;
3065 default:
3066 pp_character (buffer, str[0]);
3067 break;
3069 str++;
3073 static void
3074 maybe_init_pretty_print (FILE *file)
3076 if (!initialized)
3078 new (&buffer) pretty_printer ();
3079 pp_needs_newline (&buffer) = true;
3080 pp_translate_identifiers (&buffer) = false;
3081 initialized = 1;
3084 buffer.buffer->stream = file;
3087 static void
3088 newline_and_indent (pretty_printer *buffer, int spc)
3090 pp_newline (buffer);
3091 INDENT (spc);
3094 /* Handle a %K format for TEXT. Separate from default_tree_printer so
3095 it can also be used in front ends.
3096 %K: a statement, from which EXPR_LOCATION and TREE_BLOCK will be recorded.
3099 void
3100 percent_K_format (text_info *text)
3102 tree t = va_arg (*text->args_ptr, tree), block;
3103 gcc_assert (text->locus != NULL);
3104 *text->locus = EXPR_LOCATION (t);
3105 gcc_assert (pp_ti_abstract_origin (text) != NULL);
3106 block = TREE_BLOCK (t);
3107 *pp_ti_abstract_origin (text) = NULL;
3108 while (block
3109 && TREE_CODE (block) == BLOCK
3110 && BLOCK_ABSTRACT_ORIGIN (block))
3112 tree ao = BLOCK_ABSTRACT_ORIGIN (block);
3114 while (TREE_CODE (ao) == BLOCK
3115 && BLOCK_ABSTRACT_ORIGIN (ao)
3116 && BLOCK_ABSTRACT_ORIGIN (ao) != ao)
3117 ao = BLOCK_ABSTRACT_ORIGIN (ao);
3119 if (TREE_CODE (ao) == FUNCTION_DECL)
3121 *pp_ti_abstract_origin (text) = block;
3122 break;
3124 block = BLOCK_SUPERCONTEXT (block);
3128 /* Print the identifier ID to PRETTY-PRINTER. */
3130 void
3131 pp_tree_identifier (pretty_printer *pp, tree id)
3133 if (pp_translate_identifiers (pp))
3135 const char *text = identifier_to_locale (IDENTIFIER_POINTER (id));
3136 pp_append_text (pp, text, text + strlen (text));
3138 else
3139 pp_append_text (pp, IDENTIFIER_POINTER (id),
3140 IDENTIFIER_POINTER (id) + IDENTIFIER_LENGTH (id));
3143 /* A helper function that is used to dump function information before the
3144 function dump. */
3146 void
3147 dump_function_header (FILE *dump_file, tree fdecl, int flags)
3149 const char *dname, *aname;
3150 struct cgraph_node *node = cgraph_get_node (fdecl);
3151 struct function *fun = DECL_STRUCT_FUNCTION (fdecl);
3153 dname = lang_hooks.decl_printable_name (fdecl, 2);
3155 if (DECL_ASSEMBLER_NAME_SET_P (fdecl))
3156 aname = (IDENTIFIER_POINTER
3157 (DECL_ASSEMBLER_NAME (fdecl)));
3158 else
3159 aname = "<unset-asm-name>";
3161 fprintf (dump_file, "\n;; Function %s (%s, funcdef_no=%d",
3162 dname, aname, fun->funcdef_no);
3163 if (!(flags & TDF_NOUID))
3164 fprintf (dump_file, ", decl_uid=%d", DECL_UID (fdecl));
3165 if (node)
3167 fprintf (dump_file, ", symbol_order=%d)%s\n\n", node->symbol.order,
3168 node->frequency == NODE_FREQUENCY_HOT
3169 ? " (hot)"
3170 : node->frequency == NODE_FREQUENCY_UNLIKELY_EXECUTED
3171 ? " (unlikely executed)"
3172 : node->frequency == NODE_FREQUENCY_EXECUTED_ONCE
3173 ? " (executed once)"
3174 : "");
3176 else
3177 fprintf (dump_file, ")\n\n");
3180 /* Dump double_int D to pretty_printer PP. UNS is true
3181 if D is unsigned and false otherwise. */
3182 void
3183 pp_double_int (pretty_printer *pp, double_int d, bool uns)
3185 if (d.fits_shwi ())
3186 pp_wide_integer (pp, d.low);
3187 else if (d.fits_uhwi ())
3188 pp_unsigned_wide_integer (pp, d.low);
3189 else
3191 unsigned HOST_WIDE_INT low = d.low;
3192 HOST_WIDE_INT high = d.high;
3193 if (!uns && d.is_negative ())
3195 pp_minus (pp);
3196 high = ~high + !low;
3197 low = -low;
3199 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
3200 systems? */
3201 sprintf (pp_buffer (pp)->digit_buffer,
3202 HOST_WIDE_INT_PRINT_DOUBLE_HEX,
3203 (unsigned HOST_WIDE_INT) high, low);
3204 pp_string (pp, pp_buffer (pp)->digit_buffer);