PR target/49824
[official-gcc.git] / gcc / tree-pretty-print.c
blob24d70c3ff38c0055ead9d5f4d6bdf2a76f020043
1 /* Pretty formatting of GENERIC trees in C syntax.
2 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
3 2011 Free Software Foundation, Inc.
4 Adapted from c-pretty-print.c by Diego Novillo <dnovillo@redhat.com>
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "tree.h"
27 #include "output.h"
28 #include "tree-pretty-print.h"
29 #include "hashtab.h"
30 #include "tree-flow.h"
31 #include "langhooks.h"
32 #include "tree-iterator.h"
33 #include "tree-chrec.h"
34 #include "tree-pass.h"
35 #include "value-prof.h"
36 #include "predict.h"
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 tree-pass.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_flush (&buffer);
140 /* Print tree T, and its successors, on file FILE. FLAGS specifies details
141 to show in the dump. See TDF_* in tree-pass.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_flush (&buffer);
157 /* Print a single expression T on file FILE. FLAGS specifies details to show
158 in the dump. See TDF_* in tree-pass.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);
167 /* Dump the name of a _DECL node and its DECL_UID if TDF_UID is set
168 in FLAGS. */
170 static void
171 dump_decl_name (pretty_printer *buffer, tree node, int flags)
173 if (DECL_NAME (node))
175 if ((flags & TDF_ASMNAME) && DECL_ASSEMBLER_NAME_SET_P (node))
176 pp_tree_identifier (buffer, DECL_ASSEMBLER_NAME (node));
177 else
178 pp_tree_identifier (buffer, DECL_NAME (node));
180 if ((flags & TDF_UID) || DECL_NAME (node) == NULL_TREE)
182 if (TREE_CODE (node) == LABEL_DECL && LABEL_DECL_UID (node) != -1)
183 pp_printf (buffer, "L.%d", (int) LABEL_DECL_UID (node));
184 else if (TREE_CODE (node) == DEBUG_EXPR_DECL)
186 if (flags & TDF_NOUID)
187 pp_string (buffer, "D#xxxx");
188 else
189 pp_printf (buffer, "D#%i", DEBUG_TEMP_UID (node));
191 else
193 char c = TREE_CODE (node) == CONST_DECL ? 'C' : 'D';
194 if (flags & TDF_NOUID)
195 pp_printf (buffer, "%c.xxxx", c);
196 else
197 pp_printf (buffer, "%c.%u", c, DECL_UID (node));
200 if ((flags & TDF_ALIAS) && DECL_PT_UID (node) != DECL_UID (node))
202 if (flags & TDF_NOUID)
203 pp_printf (buffer, "ptD.xxxx");
204 else
205 pp_printf (buffer, "ptD.%u", DECL_PT_UID (node));
209 /* Like the above, but used for pretty printing function calls. */
211 static void
212 dump_function_name (pretty_printer *buffer, tree node, int flags)
214 if (TREE_CODE (node) == NOP_EXPR)
215 node = TREE_OPERAND (node, 0);
216 if (DECL_NAME (node) && (flags & TDF_ASMNAME) == 0)
217 pp_string (buffer, lang_hooks.decl_printable_name (node, 1));
218 else
219 dump_decl_name (buffer, node, flags);
222 /* Dump a function declaration. NODE is the FUNCTION_TYPE. BUFFER, SPC and
223 FLAGS are as in dump_generic_node. */
225 static void
226 dump_function_declaration (pretty_printer *buffer, tree node,
227 int spc, int flags)
229 bool wrote_arg = false;
230 tree arg;
232 pp_space (buffer);
233 pp_character (buffer, '(');
235 /* Print the argument types. */
236 arg = TYPE_ARG_TYPES (node);
237 while (arg && arg != void_list_node && arg != error_mark_node)
239 if (wrote_arg)
241 pp_character (buffer, ',');
242 pp_space (buffer);
244 wrote_arg = true;
245 dump_generic_node (buffer, TREE_VALUE (arg), spc, flags, false);
246 arg = TREE_CHAIN (arg);
249 /* Drop the trailing void_type_node if we had any previous argument. */
250 if (arg == void_list_node && !wrote_arg)
251 pp_string (buffer, "void");
252 /* Properly dump vararg function types. */
253 else if (!arg && wrote_arg)
254 pp_string (buffer, ", ...");
255 /* Avoid printing any arg for unprototyped functions. */
257 pp_character (buffer, ')');
260 /* Dump the domain associated with an array. */
262 static void
263 dump_array_domain (pretty_printer *buffer, tree domain, int spc, int flags)
265 pp_character (buffer, '[');
266 if (domain)
268 tree min = TYPE_MIN_VALUE (domain);
269 tree max = TYPE_MAX_VALUE (domain);
271 if (min && max
272 && integer_zerop (min)
273 && host_integerp (max, 0))
274 pp_wide_integer (buffer, TREE_INT_CST_LOW (max) + 1);
275 else
277 if (min)
278 dump_generic_node (buffer, min, spc, flags, false);
279 pp_character (buffer, ':');
280 if (max)
281 dump_generic_node (buffer, max, spc, flags, false);
284 else
285 pp_string (buffer, "<unknown>");
286 pp_character (buffer, ']');
290 /* Dump OpenMP clause CLAUSE. BUFFER, CLAUSE, SPC and FLAGS are as in
291 dump_generic_node. */
293 static void
294 dump_omp_clause (pretty_printer *buffer, tree clause, int spc, int flags)
296 const char *name;
298 switch (OMP_CLAUSE_CODE (clause))
300 case OMP_CLAUSE_PRIVATE:
301 name = "private";
302 goto print_remap;
303 case OMP_CLAUSE_SHARED:
304 name = "shared";
305 goto print_remap;
306 case OMP_CLAUSE_FIRSTPRIVATE:
307 name = "firstprivate";
308 goto print_remap;
309 case OMP_CLAUSE_LASTPRIVATE:
310 name = "lastprivate";
311 goto print_remap;
312 case OMP_CLAUSE_COPYIN:
313 name = "copyin";
314 goto print_remap;
315 case OMP_CLAUSE_COPYPRIVATE:
316 name = "copyprivate";
317 goto print_remap;
318 print_remap:
319 pp_string (buffer, name);
320 pp_character (buffer, '(');
321 dump_generic_node (buffer, OMP_CLAUSE_DECL (clause),
322 spc, flags, false);
323 pp_character (buffer, ')');
324 break;
326 case OMP_CLAUSE_REDUCTION:
327 pp_string (buffer, "reduction(");
328 pp_string (buffer, op_symbol_code (OMP_CLAUSE_REDUCTION_CODE (clause)));
329 pp_character (buffer, ':');
330 dump_generic_node (buffer, OMP_CLAUSE_DECL (clause),
331 spc, flags, false);
332 pp_character (buffer, ')');
333 break;
335 case OMP_CLAUSE_IF:
336 pp_string (buffer, "if(");
337 dump_generic_node (buffer, OMP_CLAUSE_IF_EXPR (clause),
338 spc, flags, false);
339 pp_character (buffer, ')');
340 break;
342 case OMP_CLAUSE_NUM_THREADS:
343 pp_string (buffer, "num_threads(");
344 dump_generic_node (buffer, OMP_CLAUSE_NUM_THREADS_EXPR (clause),
345 spc, flags, false);
346 pp_character (buffer, ')');
347 break;
349 case OMP_CLAUSE_NOWAIT:
350 pp_string (buffer, "nowait");
351 break;
352 case OMP_CLAUSE_ORDERED:
353 pp_string (buffer, "ordered");
354 break;
356 case OMP_CLAUSE_DEFAULT:
357 pp_string (buffer, "default(");
358 switch (OMP_CLAUSE_DEFAULT_KIND (clause))
360 case OMP_CLAUSE_DEFAULT_UNSPECIFIED:
361 break;
362 case OMP_CLAUSE_DEFAULT_SHARED:
363 pp_string (buffer, "shared");
364 break;
365 case OMP_CLAUSE_DEFAULT_NONE:
366 pp_string (buffer, "none");
367 break;
368 case OMP_CLAUSE_DEFAULT_PRIVATE:
369 pp_string (buffer, "private");
370 break;
371 case OMP_CLAUSE_DEFAULT_FIRSTPRIVATE:
372 pp_string (buffer, "firstprivate");
373 break;
374 default:
375 gcc_unreachable ();
377 pp_character (buffer, ')');
378 break;
380 case OMP_CLAUSE_SCHEDULE:
381 pp_string (buffer, "schedule(");
382 switch (OMP_CLAUSE_SCHEDULE_KIND (clause))
384 case OMP_CLAUSE_SCHEDULE_STATIC:
385 pp_string (buffer, "static");
386 break;
387 case OMP_CLAUSE_SCHEDULE_DYNAMIC:
388 pp_string (buffer, "dynamic");
389 break;
390 case OMP_CLAUSE_SCHEDULE_GUIDED:
391 pp_string (buffer, "guided");
392 break;
393 case OMP_CLAUSE_SCHEDULE_RUNTIME:
394 pp_string (buffer, "runtime");
395 break;
396 case OMP_CLAUSE_SCHEDULE_AUTO:
397 pp_string (buffer, "auto");
398 break;
399 default:
400 gcc_unreachable ();
402 if (OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clause))
404 pp_character (buffer, ',');
405 dump_generic_node (buffer,
406 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clause),
407 spc, flags, false);
409 pp_character (buffer, ')');
410 break;
412 case OMP_CLAUSE_UNTIED:
413 pp_string (buffer, "untied");
414 break;
416 case OMP_CLAUSE_COLLAPSE:
417 pp_string (buffer, "collapse(");
418 dump_generic_node (buffer,
419 OMP_CLAUSE_COLLAPSE_EXPR (clause),
420 spc, flags, false);
421 pp_character (buffer, ')');
422 break;
424 case OMP_CLAUSE_FINAL:
425 pp_string (buffer, "final(");
426 dump_generic_node (buffer, OMP_CLAUSE_FINAL_EXPR (clause),
427 spc, flags, false);
428 pp_character (buffer, ')');
429 break;
431 case OMP_CLAUSE_MERGEABLE:
432 pp_string (buffer, "mergeable");
433 break;
435 default:
436 /* Should never happen. */
437 dump_generic_node (buffer, clause, spc, flags, false);
438 break;
443 /* Dump the list of OpenMP clauses. BUFFER, SPC and FLAGS are as in
444 dump_generic_node. */
446 void
447 dump_omp_clauses (pretty_printer *buffer, tree clause, int spc, int flags)
449 if (clause == NULL)
450 return;
452 pp_space (buffer);
453 while (1)
455 dump_omp_clause (buffer, clause, spc, flags);
456 clause = OMP_CLAUSE_CHAIN (clause);
457 if (clause == NULL)
458 return;
459 pp_space (buffer);
464 /* Dump location LOC to BUFFER. */
466 static void
467 dump_location (pretty_printer *buffer, location_t loc)
469 expanded_location xloc = expand_location (loc);
471 pp_character (buffer, '[');
472 if (xloc.file)
474 pp_string (buffer, xloc.file);
475 pp_string (buffer, " : ");
477 pp_decimal_int (buffer, xloc.line);
478 pp_string (buffer, "] ");
482 /* Dump lexical block BLOCK. BUFFER, SPC and FLAGS are as in
483 dump_generic_node. */
485 static void
486 dump_block_node (pretty_printer *buffer, tree block, int spc, int flags)
488 tree t;
490 pp_printf (buffer, "BLOCK #%d ", BLOCK_NUMBER (block));
492 if (flags & TDF_ADDRESS)
493 pp_printf (buffer, "[%p] ", (void *) block);
495 if (BLOCK_ABSTRACT (block))
496 pp_string (buffer, "[abstract] ");
498 if (TREE_ASM_WRITTEN (block))
499 pp_string (buffer, "[written] ");
501 if (flags & TDF_SLIM)
502 return;
504 if (BLOCK_SOURCE_LOCATION (block))
505 dump_location (buffer, BLOCK_SOURCE_LOCATION (block));
507 newline_and_indent (buffer, spc + 2);
509 if (BLOCK_SUPERCONTEXT (block))
511 pp_string (buffer, "SUPERCONTEXT: ");
512 dump_generic_node (buffer, BLOCK_SUPERCONTEXT (block), 0,
513 flags | TDF_SLIM, false);
514 newline_and_indent (buffer, spc + 2);
517 if (BLOCK_SUBBLOCKS (block))
519 pp_string (buffer, "SUBBLOCKS: ");
520 for (t = BLOCK_SUBBLOCKS (block); t; t = BLOCK_CHAIN (t))
522 dump_generic_node (buffer, t, 0, flags | TDF_SLIM, false);
523 pp_string (buffer, " ");
525 newline_and_indent (buffer, spc + 2);
528 if (BLOCK_CHAIN (block))
530 pp_string (buffer, "SIBLINGS: ");
531 for (t = BLOCK_CHAIN (block); t; t = BLOCK_CHAIN (t))
533 dump_generic_node (buffer, t, 0, flags | TDF_SLIM, false);
534 pp_string (buffer, " ");
536 newline_and_indent (buffer, spc + 2);
539 if (BLOCK_VARS (block))
541 pp_string (buffer, "VARS: ");
542 for (t = BLOCK_VARS (block); t; t = TREE_CHAIN (t))
544 dump_generic_node (buffer, t, 0, flags, false);
545 pp_string (buffer, " ");
547 newline_and_indent (buffer, spc + 2);
550 if (VEC_length (tree, BLOCK_NONLOCALIZED_VARS (block)) > 0)
552 unsigned i;
553 VEC(tree,gc) *nlv = BLOCK_NONLOCALIZED_VARS (block);
555 pp_string (buffer, "NONLOCALIZED_VARS: ");
556 FOR_EACH_VEC_ELT (tree, nlv, i, t)
558 dump_generic_node (buffer, t, 0, flags, false);
559 pp_string (buffer, " ");
561 newline_and_indent (buffer, spc + 2);
564 if (BLOCK_ABSTRACT_ORIGIN (block))
566 pp_string (buffer, "ABSTRACT_ORIGIN: ");
567 dump_generic_node (buffer, BLOCK_ABSTRACT_ORIGIN (block), 0,
568 flags | TDF_SLIM, false);
569 newline_and_indent (buffer, spc + 2);
572 if (BLOCK_FRAGMENT_ORIGIN (block))
574 pp_string (buffer, "FRAGMENT_ORIGIN: ");
575 dump_generic_node (buffer, BLOCK_FRAGMENT_ORIGIN (block), 0,
576 flags | TDF_SLIM, false);
577 newline_and_indent (buffer, spc + 2);
580 if (BLOCK_FRAGMENT_CHAIN (block))
582 pp_string (buffer, "FRAGMENT_CHAIN: ");
583 for (t = BLOCK_FRAGMENT_CHAIN (block); t; t = BLOCK_FRAGMENT_CHAIN (t))
585 dump_generic_node (buffer, t, 0, flags | TDF_SLIM, false);
586 pp_string (buffer, " ");
588 newline_and_indent (buffer, spc + 2);
593 /* Dump the node NODE on the pretty_printer BUFFER, SPC spaces of
594 indent. FLAGS specifies details to show in the dump (see TDF_* in
595 tree-pass.h). If IS_STMT is true, the object printed is considered
596 to be a statement and it is terminated by ';' if appropriate. */
599 dump_generic_node (pretty_printer *buffer, tree node, int spc, int flags,
600 bool is_stmt)
602 tree type;
603 tree op0, op1;
604 const char *str;
605 bool is_expr;
607 if (node == NULL_TREE)
608 return spc;
610 is_expr = EXPR_P (node);
612 if (is_stmt && (flags & TDF_STMTADDR))
613 pp_printf (buffer, "<&%p> ", (void *)node);
615 if ((flags & TDF_LINENO) && EXPR_HAS_LOCATION (node))
616 dump_location (buffer, EXPR_LOCATION (node));
618 switch (TREE_CODE (node))
620 case ERROR_MARK:
621 pp_string (buffer, "<<< error >>>");
622 break;
624 case IDENTIFIER_NODE:
625 pp_tree_identifier (buffer, node);
626 break;
628 case TREE_LIST:
629 while (node && node != error_mark_node)
631 if (TREE_PURPOSE (node))
633 dump_generic_node (buffer, TREE_PURPOSE (node), spc, flags, false);
634 pp_space (buffer);
636 dump_generic_node (buffer, TREE_VALUE (node), spc, flags, false);
637 node = TREE_CHAIN (node);
638 if (node && TREE_CODE (node) == TREE_LIST)
640 pp_character (buffer, ',');
641 pp_space (buffer);
644 break;
646 case TREE_BINFO:
647 dump_generic_node (buffer, BINFO_TYPE (node), spc, flags, false);
648 break;
650 case TREE_VEC:
652 size_t i;
653 if (TREE_VEC_LENGTH (node) > 0)
655 size_t len = TREE_VEC_LENGTH (node);
656 for (i = 0; i < len - 1; i++)
658 dump_generic_node (buffer, TREE_VEC_ELT (node, i), spc, flags,
659 false);
660 pp_character (buffer, ',');
661 pp_space (buffer);
663 dump_generic_node (buffer, TREE_VEC_ELT (node, len - 1), spc,
664 flags, false);
667 break;
669 case VOID_TYPE:
670 case INTEGER_TYPE:
671 case REAL_TYPE:
672 case FIXED_POINT_TYPE:
673 case COMPLEX_TYPE:
674 case VECTOR_TYPE:
675 case ENUMERAL_TYPE:
676 case BOOLEAN_TYPE:
678 unsigned int quals = TYPE_QUALS (node);
679 enum tree_code_class tclass;
681 if (quals & TYPE_QUAL_CONST)
682 pp_string (buffer, "const ");
683 else if (quals & TYPE_QUAL_VOLATILE)
684 pp_string (buffer, "volatile ");
685 else if (quals & TYPE_QUAL_RESTRICT)
686 pp_string (buffer, "restrict ");
688 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (node)))
690 pp_string (buffer, "<address-space-");
691 pp_decimal_int (buffer, TYPE_ADDR_SPACE (node));
692 pp_string (buffer, "> ");
695 tclass = TREE_CODE_CLASS (TREE_CODE (node));
697 if (tclass == tcc_declaration)
699 if (DECL_NAME (node))
700 dump_decl_name (buffer, node, flags);
701 else
702 pp_string (buffer, "<unnamed type decl>");
704 else if (tclass == tcc_type)
706 if (TYPE_NAME (node))
708 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
709 pp_tree_identifier (buffer, TYPE_NAME (node));
710 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
711 && DECL_NAME (TYPE_NAME (node)))
712 dump_decl_name (buffer, TYPE_NAME (node), flags);
713 else
714 pp_string (buffer, "<unnamed type>");
716 else if (TREE_CODE (node) == VECTOR_TYPE)
718 pp_string (buffer, "vector");
719 pp_character (buffer, '(');
720 pp_wide_integer (buffer, TYPE_VECTOR_SUBPARTS (node));
721 pp_string (buffer, ") ");
722 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
724 else if (TREE_CODE (node) == INTEGER_TYPE)
726 pp_string (buffer, (TYPE_UNSIGNED (node)
727 ? "<unnamed-unsigned:"
728 : "<unnamed-signed:"));
729 pp_decimal_int (buffer, TYPE_PRECISION (node));
730 pp_string (buffer, ">");
732 else if (TREE_CODE (node) == COMPLEX_TYPE)
734 pp_string (buffer, "__complex__ ");
735 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
737 else if (TREE_CODE (node) == REAL_TYPE)
739 pp_string (buffer, "<float:");
740 pp_decimal_int (buffer, TYPE_PRECISION (node));
741 pp_string (buffer, ">");
743 else if (TREE_CODE (node) == FIXED_POINT_TYPE)
745 pp_string (buffer, "<fixed-point-");
746 pp_string (buffer, TYPE_SATURATING (node) ? "sat:" : "nonsat:");
747 pp_decimal_int (buffer, TYPE_PRECISION (node));
748 pp_string (buffer, ">");
750 else if (TREE_CODE (node) == VOID_TYPE)
751 pp_string (buffer, "void");
752 else
753 pp_string (buffer, "<unnamed type>");
755 break;
758 case POINTER_TYPE:
759 case REFERENCE_TYPE:
760 str = (TREE_CODE (node) == POINTER_TYPE ? "*" : "&");
762 if (TREE_TYPE (node) == NULL)
764 pp_string (buffer, str);
765 pp_string (buffer, "<null type>");
767 else if (TREE_CODE (TREE_TYPE (node)) == FUNCTION_TYPE)
769 tree fnode = TREE_TYPE (node);
771 dump_generic_node (buffer, TREE_TYPE (fnode), spc, flags, false);
772 pp_space (buffer);
773 pp_character (buffer, '(');
774 pp_string (buffer, str);
775 if (TYPE_NAME (node) && DECL_NAME (TYPE_NAME (node)))
776 dump_decl_name (buffer, TYPE_NAME (node), flags);
777 else if (flags & TDF_NOUID)
778 pp_printf (buffer, "<Txxxx>");
779 else
780 pp_printf (buffer, "<T%x>", TYPE_UID (node));
782 pp_character (buffer, ')');
783 dump_function_declaration (buffer, fnode, spc, flags);
785 else
787 unsigned int quals = TYPE_QUALS (node);
789 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
790 pp_space (buffer);
791 pp_string (buffer, str);
793 if (quals & TYPE_QUAL_CONST)
794 pp_string (buffer, " const");
795 if (quals & TYPE_QUAL_VOLATILE)
796 pp_string (buffer, " volatile");
797 if (quals & TYPE_QUAL_RESTRICT)
798 pp_string (buffer, " restrict");
800 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (node)))
802 pp_string (buffer, " <address-space-");
803 pp_decimal_int (buffer, TYPE_ADDR_SPACE (node));
804 pp_string (buffer, ">");
807 if (TYPE_REF_CAN_ALIAS_ALL (node))
808 pp_string (buffer, " {ref-all}");
810 break;
812 case OFFSET_TYPE:
813 NIY;
814 break;
816 case MEM_REF:
818 if (integer_zerop (TREE_OPERAND (node, 1))
819 /* Dump the types of INTEGER_CSTs explicitly, for we can't
820 infer them and MEM_ATTR caching will share MEM_REFs
821 with differently-typed op0s. */
822 && TREE_CODE (TREE_OPERAND (node, 0)) != INTEGER_CST
823 /* Released SSA_NAMES have no TREE_TYPE. */
824 && TREE_TYPE (TREE_OPERAND (node, 0)) != NULL_TREE
825 /* Same pointer types, but ignoring POINTER_TYPE vs.
826 REFERENCE_TYPE. */
827 && (TREE_TYPE (TREE_TYPE (TREE_OPERAND (node, 0)))
828 == TREE_TYPE (TREE_TYPE (TREE_OPERAND (node, 1))))
829 && (TYPE_MODE (TREE_TYPE (TREE_OPERAND (node, 0)))
830 == TYPE_MODE (TREE_TYPE (TREE_OPERAND (node, 1))))
831 && (TYPE_REF_CAN_ALIAS_ALL (TREE_TYPE (TREE_OPERAND (node, 0)))
832 == TYPE_REF_CAN_ALIAS_ALL (TREE_TYPE (TREE_OPERAND (node, 1))))
833 /* Same value types ignoring qualifiers. */
834 && (TYPE_MAIN_VARIANT (TREE_TYPE (node))
835 == TYPE_MAIN_VARIANT
836 (TREE_TYPE (TREE_TYPE (TREE_OPERAND (node, 1))))))
838 if (TREE_CODE (TREE_OPERAND (node, 0)) != ADDR_EXPR)
840 pp_string (buffer, "*");
841 dump_generic_node (buffer, TREE_OPERAND (node, 0),
842 spc, flags, false);
844 else
845 dump_generic_node (buffer,
846 TREE_OPERAND (TREE_OPERAND (node, 0), 0),
847 spc, flags, false);
849 else
851 tree ptype;
853 pp_string (buffer, "MEM[");
854 pp_string (buffer, "(");
855 ptype = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (node, 1)));
856 dump_generic_node (buffer, ptype,
857 spc, flags | TDF_SLIM, false);
858 pp_string (buffer, ")");
859 dump_generic_node (buffer, TREE_OPERAND (node, 0),
860 spc, flags, false);
861 if (!integer_zerop (TREE_OPERAND (node, 1)))
863 pp_string (buffer, " + ");
864 dump_generic_node (buffer, TREE_OPERAND (node, 1),
865 spc, flags, false);
867 pp_string (buffer, "]");
869 break;
872 case TARGET_MEM_REF:
874 const char *sep = "";
875 tree tmp;
877 pp_string (buffer, "MEM[");
879 if (TREE_CODE (TMR_BASE (node)) == ADDR_EXPR)
881 pp_string (buffer, sep);
882 sep = ", ";
883 pp_string (buffer, "symbol: ");
884 dump_generic_node (buffer, TREE_OPERAND (TMR_BASE (node), 0),
885 spc, flags, false);
887 else
889 pp_string (buffer, sep);
890 sep = ", ";
891 pp_string (buffer, "base: ");
892 dump_generic_node (buffer, TMR_BASE (node), spc, flags, false);
894 tmp = TMR_INDEX2 (node);
895 if (tmp)
897 pp_string (buffer, sep);
898 sep = ", ";
899 pp_string (buffer, "base: ");
900 dump_generic_node (buffer, tmp, spc, flags, false);
902 tmp = TMR_INDEX (node);
903 if (tmp)
905 pp_string (buffer, sep);
906 sep = ", ";
907 pp_string (buffer, "index: ");
908 dump_generic_node (buffer, tmp, spc, flags, false);
910 tmp = TMR_STEP (node);
911 if (tmp)
913 pp_string (buffer, sep);
914 sep = ", ";
915 pp_string (buffer, "step: ");
916 dump_generic_node (buffer, tmp, spc, flags, false);
918 tmp = TMR_OFFSET (node);
919 if (tmp)
921 pp_string (buffer, sep);
922 sep = ", ";
923 pp_string (buffer, "offset: ");
924 dump_generic_node (buffer, tmp, spc, flags, false);
926 pp_string (buffer, "]");
928 break;
930 case ARRAY_TYPE:
932 tree tmp;
934 /* Print the innermost component type. */
935 for (tmp = TREE_TYPE (node); TREE_CODE (tmp) == ARRAY_TYPE;
936 tmp = TREE_TYPE (tmp))
938 dump_generic_node (buffer, tmp, spc, flags, false);
940 /* Print the dimensions. */
941 for (tmp = node; TREE_CODE (tmp) == ARRAY_TYPE; tmp = TREE_TYPE (tmp))
942 dump_array_domain (buffer, TYPE_DOMAIN (tmp), spc, flags);
943 break;
946 case RECORD_TYPE:
947 case UNION_TYPE:
948 case QUAL_UNION_TYPE:
950 unsigned int quals = TYPE_QUALS (node);
952 if (quals & TYPE_QUAL_CONST)
953 pp_string (buffer, "const ");
954 if (quals & TYPE_QUAL_VOLATILE)
955 pp_string (buffer, "volatile ");
957 /* Print the name of the structure. */
958 if (TREE_CODE (node) == RECORD_TYPE)
959 pp_string (buffer, "struct ");
960 else if (TREE_CODE (node) == UNION_TYPE)
961 pp_string (buffer, "union ");
963 if (TYPE_NAME (node))
964 dump_generic_node (buffer, TYPE_NAME (node), spc, flags, false);
965 else if (!(flags & TDF_SLIM))
966 /* FIXME: If we eliminate the 'else' above and attempt
967 to show the fields for named types, we may get stuck
968 following a cycle of pointers to structs. The alleged
969 self-reference check in print_struct_decl will not detect
970 cycles involving more than one pointer or struct type. */
971 print_struct_decl (buffer, node, spc, flags);
972 break;
975 case LANG_TYPE:
976 NIY;
977 break;
979 case INTEGER_CST:
980 if (TREE_CODE (TREE_TYPE (node)) == POINTER_TYPE)
982 /* In the case of a pointer, one may want to divide by the
983 size of the pointed-to type. Unfortunately, this not
984 straightforward. The C front-end maps expressions
986 (int *) 5
987 int *p; (p + 5)
989 in such a way that the two INTEGER_CST nodes for "5" have
990 different values but identical types. In the latter
991 case, the 5 is multiplied by sizeof (int) in c-common.c
992 (pointer_int_sum) to convert it to a byte address, and
993 yet the type of the node is left unchanged. Argh. What
994 is consistent though is that the number value corresponds
995 to bytes (UNITS) offset.
997 NB: Neither of the following divisors can be trivially
998 used to recover the original literal:
1000 TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (node)))
1001 TYPE_PRECISION (TREE_TYPE (TREE_TYPE (node))) */
1002 pp_wide_integer (buffer, TREE_INT_CST_LOW (node));
1003 pp_string (buffer, "B"); /* pseudo-unit */
1005 else if (host_integerp (node, 0))
1006 pp_wide_integer (buffer, TREE_INT_CST_LOW (node));
1007 else if (host_integerp (node, 1))
1008 pp_unsigned_wide_integer (buffer, TREE_INT_CST_LOW (node));
1009 else
1011 tree val = node;
1012 unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (val);
1013 HOST_WIDE_INT high = TREE_INT_CST_HIGH (val);
1015 if (tree_int_cst_sgn (val) < 0)
1017 pp_character (buffer, '-');
1018 high = ~high + !low;
1019 low = -low;
1021 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
1022 systems? */
1023 sprintf (pp_buffer (buffer)->digit_buffer,
1024 HOST_WIDE_INT_PRINT_DOUBLE_HEX,
1025 (unsigned HOST_WIDE_INT) high, low);
1026 pp_string (buffer, pp_buffer (buffer)->digit_buffer);
1028 break;
1030 case REAL_CST:
1031 /* Code copied from print_node. */
1033 REAL_VALUE_TYPE d;
1034 if (TREE_OVERFLOW (node))
1035 pp_string (buffer, " overflow");
1037 #if !defined(REAL_IS_NOT_DOUBLE) || defined(REAL_ARITHMETIC)
1038 d = TREE_REAL_CST (node);
1039 if (REAL_VALUE_ISINF (d))
1040 pp_string (buffer, REAL_VALUE_NEGATIVE (d) ? " -Inf" : " Inf");
1041 else if (REAL_VALUE_ISNAN (d))
1042 pp_string (buffer, " Nan");
1043 else
1045 char string[100];
1046 real_to_decimal (string, &d, sizeof (string), 0, 1);
1047 pp_string (buffer, string);
1049 #else
1051 HOST_WIDE_INT i;
1052 unsigned char *p = (unsigned char *) &TREE_REAL_CST (node);
1053 pp_string (buffer, "0x");
1054 for (i = 0; i < sizeof TREE_REAL_CST (node); i++)
1055 output_formatted_integer (buffer, "%02x", *p++);
1057 #endif
1058 break;
1061 case FIXED_CST:
1063 char string[100];
1064 fixed_to_decimal (string, TREE_FIXED_CST_PTR (node), sizeof (string));
1065 pp_string (buffer, string);
1066 break;
1069 case COMPLEX_CST:
1070 pp_string (buffer, "__complex__ (");
1071 dump_generic_node (buffer, TREE_REALPART (node), spc, flags, false);
1072 pp_string (buffer, ", ");
1073 dump_generic_node (buffer, TREE_IMAGPART (node), spc, flags, false);
1074 pp_string (buffer, ")");
1075 break;
1077 case STRING_CST:
1078 pp_string (buffer, "\"");
1079 pretty_print_string (buffer, TREE_STRING_POINTER (node));
1080 pp_string (buffer, "\"");
1081 break;
1083 case VECTOR_CST:
1085 tree elt;
1086 pp_string (buffer, "{ ");
1087 for (elt = TREE_VECTOR_CST_ELTS (node); elt; elt = TREE_CHAIN (elt))
1089 dump_generic_node (buffer, TREE_VALUE (elt), spc, flags, false);
1090 if (TREE_CHAIN (elt))
1091 pp_string (buffer, ", ");
1093 pp_string (buffer, " }");
1095 break;
1097 case FUNCTION_TYPE:
1098 case METHOD_TYPE:
1099 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
1100 pp_space (buffer);
1101 if (TREE_CODE (node) == METHOD_TYPE)
1103 if (TYPE_METHOD_BASETYPE (node))
1104 dump_decl_name (buffer, TYPE_NAME (TYPE_METHOD_BASETYPE (node)),
1105 flags);
1106 else
1107 pp_string (buffer, "<null method basetype>");
1108 pp_string (buffer, "::");
1110 if (TYPE_NAME (node) && DECL_NAME (TYPE_NAME (node)))
1111 dump_decl_name (buffer, TYPE_NAME (node), flags);
1112 else if (flags & TDF_NOUID)
1113 pp_printf (buffer, "<Txxxx>");
1114 else
1115 pp_printf (buffer, "<T%x>", TYPE_UID (node));
1116 dump_function_declaration (buffer, node, spc, flags);
1117 break;
1119 case FUNCTION_DECL:
1120 case CONST_DECL:
1121 dump_decl_name (buffer, node, flags);
1122 break;
1124 case LABEL_DECL:
1125 if (DECL_NAME (node))
1126 dump_decl_name (buffer, node, flags);
1127 else if (LABEL_DECL_UID (node) != -1)
1128 pp_printf (buffer, "<L%d>", (int) LABEL_DECL_UID (node));
1129 else
1131 if (flags & TDF_NOUID)
1132 pp_string (buffer, "<D.xxxx>");
1133 else
1134 pp_printf (buffer, "<D.%u>", DECL_UID (node));
1136 break;
1138 case TYPE_DECL:
1139 if (DECL_IS_BUILTIN (node))
1141 /* Don't print the declaration of built-in types. */
1142 break;
1144 if (DECL_NAME (node))
1145 dump_decl_name (buffer, node, flags);
1146 else if (TYPE_NAME (TREE_TYPE (node)) != node)
1148 if ((TREE_CODE (TREE_TYPE (node)) == RECORD_TYPE
1149 || TREE_CODE (TREE_TYPE (node)) == UNION_TYPE)
1150 && TYPE_METHODS (TREE_TYPE (node)))
1152 /* The type is a c++ class: all structures have at least
1153 4 methods. */
1154 pp_string (buffer, "class ");
1155 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
1157 else
1159 pp_string (buffer,
1160 (TREE_CODE (TREE_TYPE (node)) == UNION_TYPE
1161 ? "union" : "struct "));
1162 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
1165 else
1166 pp_string (buffer, "<anon>");
1167 break;
1169 case VAR_DECL:
1170 case PARM_DECL:
1171 case FIELD_DECL:
1172 case DEBUG_EXPR_DECL:
1173 case NAMESPACE_DECL:
1174 dump_decl_name (buffer, node, flags);
1175 break;
1177 case RESULT_DECL:
1178 pp_string (buffer, "<retval>");
1179 break;
1181 case COMPONENT_REF:
1182 op0 = TREE_OPERAND (node, 0);
1183 str = ".";
1184 if (op0
1185 && (TREE_CODE (op0) == INDIRECT_REF
1186 || (TREE_CODE (op0) == MEM_REF
1187 && TREE_CODE (TREE_OPERAND (op0, 0)) != ADDR_EXPR
1188 && integer_zerop (TREE_OPERAND (op0, 1))
1189 /* Dump the types of INTEGER_CSTs explicitly, for we
1190 can't infer them and MEM_ATTR caching will share
1191 MEM_REFs with differently-typed op0s. */
1192 && TREE_CODE (TREE_OPERAND (op0, 0)) != INTEGER_CST
1193 /* Released SSA_NAMES have no TREE_TYPE. */
1194 && TREE_TYPE (TREE_OPERAND (op0, 0)) != NULL_TREE
1195 /* Same pointer types, but ignoring POINTER_TYPE vs.
1196 REFERENCE_TYPE. */
1197 && (TREE_TYPE (TREE_TYPE (TREE_OPERAND (op0, 0)))
1198 == TREE_TYPE (TREE_TYPE (TREE_OPERAND (op0, 1))))
1199 && (TYPE_MODE (TREE_TYPE (TREE_OPERAND (op0, 0)))
1200 == TYPE_MODE (TREE_TYPE (TREE_OPERAND (op0, 1))))
1201 && (TYPE_REF_CAN_ALIAS_ALL (TREE_TYPE (TREE_OPERAND (op0, 0)))
1202 == TYPE_REF_CAN_ALIAS_ALL (TREE_TYPE (TREE_OPERAND (op0, 1))))
1203 /* Same value types ignoring qualifiers. */
1204 && (TYPE_MAIN_VARIANT (TREE_TYPE (op0))
1205 == TYPE_MAIN_VARIANT
1206 (TREE_TYPE (TREE_TYPE (TREE_OPERAND (op0, 1))))))))
1208 op0 = TREE_OPERAND (op0, 0);
1209 str = "->";
1211 if (op_prio (op0) < op_prio (node))
1212 pp_character (buffer, '(');
1213 dump_generic_node (buffer, op0, spc, flags, false);
1214 if (op_prio (op0) < op_prio (node))
1215 pp_character (buffer, ')');
1216 pp_string (buffer, str);
1217 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1218 op0 = component_ref_field_offset (node);
1219 if (op0 && TREE_CODE (op0) != INTEGER_CST)
1221 pp_string (buffer, "{off: ");
1222 dump_generic_node (buffer, op0, spc, flags, false);
1223 pp_character (buffer, '}');
1225 break;
1227 case BIT_FIELD_REF:
1228 pp_string (buffer, "BIT_FIELD_REF <");
1229 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1230 pp_string (buffer, ", ");
1231 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1232 pp_string (buffer, ", ");
1233 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
1234 pp_string (buffer, ">");
1235 break;
1237 case ARRAY_REF:
1238 case ARRAY_RANGE_REF:
1239 op0 = TREE_OPERAND (node, 0);
1240 if (op_prio (op0) < op_prio (node))
1241 pp_character (buffer, '(');
1242 dump_generic_node (buffer, op0, spc, flags, false);
1243 if (op_prio (op0) < op_prio (node))
1244 pp_character (buffer, ')');
1245 pp_character (buffer, '[');
1246 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1247 if (TREE_CODE (node) == ARRAY_RANGE_REF)
1248 pp_string (buffer, " ...");
1249 pp_character (buffer, ']');
1251 op0 = array_ref_low_bound (node);
1252 op1 = array_ref_element_size (node);
1254 if (!integer_zerop (op0)
1255 || TREE_OPERAND (node, 2)
1256 || TREE_OPERAND (node, 3))
1258 pp_string (buffer, "{lb: ");
1259 dump_generic_node (buffer, op0, spc, flags, false);
1260 pp_string (buffer, " sz: ");
1261 dump_generic_node (buffer, op1, spc, flags, false);
1262 pp_character (buffer, '}');
1264 break;
1266 case CONSTRUCTOR:
1268 unsigned HOST_WIDE_INT ix;
1269 tree field, val;
1270 bool is_struct_init = false;
1271 bool is_array_init = false;
1272 double_int curidx = double_int_zero;
1273 pp_character (buffer, '{');
1274 if (TREE_CODE (TREE_TYPE (node)) == RECORD_TYPE
1275 || TREE_CODE (TREE_TYPE (node)) == UNION_TYPE)
1276 is_struct_init = true;
1277 else if (TREE_CODE (TREE_TYPE (node)) == ARRAY_TYPE
1278 && TYPE_DOMAIN (TREE_TYPE (node))
1279 && TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (node)))
1280 && TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (node))))
1281 == INTEGER_CST)
1283 tree minv = TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (node)));
1284 is_array_init = true;
1285 curidx = tree_to_double_int (minv);
1287 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (node), ix, field, val)
1289 if (field)
1291 if (is_struct_init)
1293 pp_character (buffer, '.');
1294 dump_generic_node (buffer, field, spc, flags, false);
1295 pp_character (buffer, '=');
1297 else if (is_array_init
1298 && (TREE_CODE (field) != INTEGER_CST
1299 || !double_int_equal_p (tree_to_double_int (field),
1300 curidx)))
1302 pp_character (buffer, '[');
1303 if (TREE_CODE (field) == RANGE_EXPR)
1305 dump_generic_node (buffer, TREE_OPERAND (field, 0), spc,
1306 flags, false);
1307 pp_string (buffer, " ... ");
1308 dump_generic_node (buffer, TREE_OPERAND (field, 1), spc,
1309 flags, false);
1310 if (TREE_CODE (TREE_OPERAND (field, 1)) == INTEGER_CST)
1311 curidx = tree_to_double_int (TREE_OPERAND (field, 1));
1313 else
1314 dump_generic_node (buffer, field, spc, flags, false);
1315 if (TREE_CODE (field) == INTEGER_CST)
1316 curidx = tree_to_double_int (field);
1317 pp_string (buffer, "]=");
1320 if (is_array_init)
1321 curidx = double_int_add (curidx, double_int_one);
1322 if (val && TREE_CODE (val) == ADDR_EXPR)
1323 if (TREE_CODE (TREE_OPERAND (val, 0)) == FUNCTION_DECL)
1324 val = TREE_OPERAND (val, 0);
1325 if (val && TREE_CODE (val) == FUNCTION_DECL)
1326 dump_decl_name (buffer, val, flags);
1327 else
1328 dump_generic_node (buffer, val, spc, flags, false);
1329 if (ix != VEC_length (constructor_elt, CONSTRUCTOR_ELTS (node)) - 1)
1331 pp_character (buffer, ',');
1332 pp_space (buffer);
1335 pp_character (buffer, '}');
1337 break;
1339 case COMPOUND_EXPR:
1341 tree *tp;
1342 if (flags & TDF_SLIM)
1344 pp_string (buffer, "<COMPOUND_EXPR>");
1345 break;
1348 dump_generic_node (buffer, TREE_OPERAND (node, 0),
1349 spc, flags, !(flags & TDF_SLIM));
1350 if (flags & TDF_SLIM)
1351 newline_and_indent (buffer, spc);
1352 else
1354 pp_character (buffer, ',');
1355 pp_space (buffer);
1358 for (tp = &TREE_OPERAND (node, 1);
1359 TREE_CODE (*tp) == COMPOUND_EXPR;
1360 tp = &TREE_OPERAND (*tp, 1))
1362 dump_generic_node (buffer, TREE_OPERAND (*tp, 0),
1363 spc, flags, !(flags & TDF_SLIM));
1364 if (flags & TDF_SLIM)
1365 newline_and_indent (buffer, spc);
1366 else
1368 pp_character (buffer, ',');
1369 pp_space (buffer);
1373 dump_generic_node (buffer, *tp, spc, flags, !(flags & TDF_SLIM));
1375 break;
1377 case STATEMENT_LIST:
1379 tree_stmt_iterator si;
1380 bool first = true;
1382 if (flags & TDF_SLIM)
1384 pp_string (buffer, "<STATEMENT_LIST>");
1385 break;
1388 for (si = tsi_start (node); !tsi_end_p (si); tsi_next (&si))
1390 if (!first)
1391 newline_and_indent (buffer, spc);
1392 else
1393 first = false;
1394 dump_generic_node (buffer, tsi_stmt (si), spc, flags, true);
1397 break;
1399 case MODIFY_EXPR:
1400 case INIT_EXPR:
1401 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags,
1402 false);
1403 pp_space (buffer);
1404 pp_character (buffer, '=');
1405 if (TREE_CODE (node) == MODIFY_EXPR
1406 && MOVE_NONTEMPORAL (node))
1407 pp_string (buffer, "{nt}");
1408 pp_space (buffer);
1409 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags,
1410 false);
1411 break;
1413 case TARGET_EXPR:
1414 pp_string (buffer, "TARGET_EXPR <");
1415 dump_generic_node (buffer, TARGET_EXPR_SLOT (node), spc, flags, false);
1416 pp_character (buffer, ',');
1417 pp_space (buffer);
1418 dump_generic_node (buffer, TARGET_EXPR_INITIAL (node), spc, flags, false);
1419 pp_character (buffer, '>');
1420 break;
1422 case DECL_EXPR:
1423 print_declaration (buffer, DECL_EXPR_DECL (node), spc, flags);
1424 is_stmt = false;
1425 break;
1427 case COND_EXPR:
1428 if (TREE_TYPE (node) == NULL || TREE_TYPE (node) == void_type_node)
1430 pp_string (buffer, "if (");
1431 dump_generic_node (buffer, COND_EXPR_COND (node), spc, flags, false);
1432 pp_character (buffer, ')');
1433 /* The lowered cond_exprs should always be printed in full. */
1434 if (COND_EXPR_THEN (node)
1435 && (IS_EMPTY_STMT (COND_EXPR_THEN (node))
1436 || TREE_CODE (COND_EXPR_THEN (node)) == GOTO_EXPR)
1437 && COND_EXPR_ELSE (node)
1438 && (IS_EMPTY_STMT (COND_EXPR_ELSE (node))
1439 || TREE_CODE (COND_EXPR_ELSE (node)) == GOTO_EXPR))
1441 pp_space (buffer);
1442 dump_generic_node (buffer, COND_EXPR_THEN (node),
1443 0, flags, true);
1444 if (!IS_EMPTY_STMT (COND_EXPR_ELSE (node)))
1446 pp_string (buffer, " else ");
1447 dump_generic_node (buffer, COND_EXPR_ELSE (node),
1448 0, flags, true);
1451 else if (!(flags & TDF_SLIM))
1453 /* Output COND_EXPR_THEN. */
1454 if (COND_EXPR_THEN (node))
1456 newline_and_indent (buffer, spc+2);
1457 pp_character (buffer, '{');
1458 newline_and_indent (buffer, spc+4);
1459 dump_generic_node (buffer, COND_EXPR_THEN (node), spc+4,
1460 flags, true);
1461 newline_and_indent (buffer, spc+2);
1462 pp_character (buffer, '}');
1465 /* Output COND_EXPR_ELSE. */
1466 if (COND_EXPR_ELSE (node)
1467 && !IS_EMPTY_STMT (COND_EXPR_ELSE (node)))
1469 newline_and_indent (buffer, spc);
1470 pp_string (buffer, "else");
1471 newline_and_indent (buffer, spc+2);
1472 pp_character (buffer, '{');
1473 newline_and_indent (buffer, spc+4);
1474 dump_generic_node (buffer, COND_EXPR_ELSE (node), spc+4,
1475 flags, true);
1476 newline_and_indent (buffer, spc+2);
1477 pp_character (buffer, '}');
1480 is_expr = false;
1482 else
1484 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1485 pp_space (buffer);
1486 pp_character (buffer, '?');
1487 pp_space (buffer);
1488 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1489 pp_space (buffer);
1490 pp_character (buffer, ':');
1491 pp_space (buffer);
1492 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
1494 break;
1496 case BIND_EXPR:
1497 pp_character (buffer, '{');
1498 if (!(flags & TDF_SLIM))
1500 if (BIND_EXPR_VARS (node))
1502 pp_newline (buffer);
1504 for (op0 = BIND_EXPR_VARS (node); op0; op0 = DECL_CHAIN (op0))
1506 print_declaration (buffer, op0, spc+2, flags);
1507 pp_newline (buffer);
1511 newline_and_indent (buffer, spc+2);
1512 dump_generic_node (buffer, BIND_EXPR_BODY (node), spc+2, flags, true);
1513 newline_and_indent (buffer, spc);
1514 pp_character (buffer, '}');
1516 is_expr = false;
1517 break;
1519 case CALL_EXPR:
1520 print_call_name (buffer, CALL_EXPR_FN (node), flags);
1522 /* Print parameters. */
1523 pp_space (buffer);
1524 pp_character (buffer, '(');
1526 tree arg;
1527 call_expr_arg_iterator iter;
1528 FOR_EACH_CALL_EXPR_ARG (arg, iter, node)
1530 dump_generic_node (buffer, arg, spc, flags, false);
1531 if (more_call_expr_args_p (&iter))
1533 pp_character (buffer, ',');
1534 pp_space (buffer);
1538 if (CALL_EXPR_VA_ARG_PACK (node))
1540 if (call_expr_nargs (node) > 0)
1542 pp_character (buffer, ',');
1543 pp_space (buffer);
1545 pp_string (buffer, "__builtin_va_arg_pack ()");
1547 pp_character (buffer, ')');
1549 op1 = CALL_EXPR_STATIC_CHAIN (node);
1550 if (op1)
1552 pp_string (buffer, " [static-chain: ");
1553 dump_generic_node (buffer, op1, spc, flags, false);
1554 pp_character (buffer, ']');
1557 if (CALL_EXPR_RETURN_SLOT_OPT (node))
1558 pp_string (buffer, " [return slot optimization]");
1559 if (CALL_EXPR_TAILCALL (node))
1560 pp_string (buffer, " [tail call]");
1561 break;
1563 case WITH_CLEANUP_EXPR:
1564 NIY;
1565 break;
1567 case CLEANUP_POINT_EXPR:
1568 pp_string (buffer, "<<cleanup_point ");
1569 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1570 pp_string (buffer, ">>");
1571 break;
1573 case PLACEHOLDER_EXPR:
1574 pp_string (buffer, "<PLACEHOLDER_EXPR ");
1575 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
1576 pp_character (buffer, '>');
1577 break;
1579 /* Binary arithmetic and logic expressions. */
1580 case WIDEN_SUM_EXPR:
1581 case WIDEN_MULT_EXPR:
1582 case MULT_EXPR:
1583 case PLUS_EXPR:
1584 case POINTER_PLUS_EXPR:
1585 case MINUS_EXPR:
1586 case TRUNC_DIV_EXPR:
1587 case CEIL_DIV_EXPR:
1588 case FLOOR_DIV_EXPR:
1589 case ROUND_DIV_EXPR:
1590 case TRUNC_MOD_EXPR:
1591 case CEIL_MOD_EXPR:
1592 case FLOOR_MOD_EXPR:
1593 case ROUND_MOD_EXPR:
1594 case RDIV_EXPR:
1595 case EXACT_DIV_EXPR:
1596 case LSHIFT_EXPR:
1597 case RSHIFT_EXPR:
1598 case LROTATE_EXPR:
1599 case RROTATE_EXPR:
1600 case VEC_LSHIFT_EXPR:
1601 case VEC_RSHIFT_EXPR:
1602 case WIDEN_LSHIFT_EXPR:
1603 case BIT_IOR_EXPR:
1604 case BIT_XOR_EXPR:
1605 case BIT_AND_EXPR:
1606 case TRUTH_ANDIF_EXPR:
1607 case TRUTH_ORIF_EXPR:
1608 case TRUTH_AND_EXPR:
1609 case TRUTH_OR_EXPR:
1610 case TRUTH_XOR_EXPR:
1611 case LT_EXPR:
1612 case LE_EXPR:
1613 case GT_EXPR:
1614 case GE_EXPR:
1615 case EQ_EXPR:
1616 case NE_EXPR:
1617 case UNLT_EXPR:
1618 case UNLE_EXPR:
1619 case UNGT_EXPR:
1620 case UNGE_EXPR:
1621 case UNEQ_EXPR:
1622 case LTGT_EXPR:
1623 case ORDERED_EXPR:
1624 case UNORDERED_EXPR:
1626 const char *op = op_symbol (node);
1627 op0 = TREE_OPERAND (node, 0);
1628 op1 = TREE_OPERAND (node, 1);
1630 /* When the operands are expressions with less priority,
1631 keep semantics of the tree representation. */
1632 if (op_prio (op0) <= op_prio (node))
1634 pp_character (buffer, '(');
1635 dump_generic_node (buffer, op0, spc, flags, false);
1636 pp_character (buffer, ')');
1638 else
1639 dump_generic_node (buffer, op0, spc, flags, false);
1641 pp_space (buffer);
1642 pp_string (buffer, op);
1643 pp_space (buffer);
1645 /* When the operands are expressions with less priority,
1646 keep semantics of the tree representation. */
1647 if (op_prio (op1) <= op_prio (node))
1649 pp_character (buffer, '(');
1650 dump_generic_node (buffer, op1, spc, flags, false);
1651 pp_character (buffer, ')');
1653 else
1654 dump_generic_node (buffer, op1, spc, flags, false);
1656 break;
1658 /* Unary arithmetic and logic expressions. */
1659 case NEGATE_EXPR:
1660 case BIT_NOT_EXPR:
1661 case TRUTH_NOT_EXPR:
1662 case ADDR_EXPR:
1663 case PREDECREMENT_EXPR:
1664 case PREINCREMENT_EXPR:
1665 case INDIRECT_REF:
1666 if (TREE_CODE (node) == ADDR_EXPR
1667 && (TREE_CODE (TREE_OPERAND (node, 0)) == STRING_CST
1668 || TREE_CODE (TREE_OPERAND (node, 0)) == FUNCTION_DECL))
1669 ; /* Do not output '&' for strings and function pointers. */
1670 else
1671 pp_string (buffer, op_symbol (node));
1673 if (op_prio (TREE_OPERAND (node, 0)) < op_prio (node))
1675 pp_character (buffer, '(');
1676 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1677 pp_character (buffer, ')');
1679 else
1680 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1681 break;
1683 case POSTDECREMENT_EXPR:
1684 case POSTINCREMENT_EXPR:
1685 if (op_prio (TREE_OPERAND (node, 0)) < op_prio (node))
1687 pp_character (buffer, '(');
1688 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1689 pp_character (buffer, ')');
1691 else
1692 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1693 pp_string (buffer, op_symbol (node));
1694 break;
1696 case MIN_EXPR:
1697 pp_string (buffer, "MIN_EXPR <");
1698 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1699 pp_string (buffer, ", ");
1700 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1701 pp_character (buffer, '>');
1702 break;
1704 case MAX_EXPR:
1705 pp_string (buffer, "MAX_EXPR <");
1706 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1707 pp_string (buffer, ", ");
1708 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1709 pp_character (buffer, '>');
1710 break;
1712 case ABS_EXPR:
1713 pp_string (buffer, "ABS_EXPR <");
1714 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1715 pp_character (buffer, '>');
1716 break;
1718 case RANGE_EXPR:
1719 NIY;
1720 break;
1722 case ADDR_SPACE_CONVERT_EXPR:
1723 case FIXED_CONVERT_EXPR:
1724 case FIX_TRUNC_EXPR:
1725 case FLOAT_EXPR:
1726 CASE_CONVERT:
1727 type = TREE_TYPE (node);
1728 op0 = TREE_OPERAND (node, 0);
1729 if (type != TREE_TYPE (op0))
1731 pp_character (buffer, '(');
1732 dump_generic_node (buffer, type, spc, flags, false);
1733 pp_string (buffer, ") ");
1735 if (op_prio (op0) < op_prio (node))
1736 pp_character (buffer, '(');
1737 dump_generic_node (buffer, op0, spc, flags, false);
1738 if (op_prio (op0) < op_prio (node))
1739 pp_character (buffer, ')');
1740 break;
1742 case VIEW_CONVERT_EXPR:
1743 pp_string (buffer, "VIEW_CONVERT_EXPR<");
1744 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
1745 pp_string (buffer, ">(");
1746 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1747 pp_character (buffer, ')');
1748 break;
1750 case PAREN_EXPR:
1751 pp_string (buffer, "((");
1752 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1753 pp_string (buffer, "))");
1754 break;
1756 case NON_LVALUE_EXPR:
1757 pp_string (buffer, "NON_LVALUE_EXPR <");
1758 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1759 pp_character (buffer, '>');
1760 break;
1762 case SAVE_EXPR:
1763 pp_string (buffer, "SAVE_EXPR <");
1764 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1765 pp_character (buffer, '>');
1766 break;
1768 case COMPLEX_EXPR:
1769 pp_string (buffer, "COMPLEX_EXPR <");
1770 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1771 pp_string (buffer, ", ");
1772 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1773 pp_string (buffer, ">");
1774 break;
1776 case CONJ_EXPR:
1777 pp_string (buffer, "CONJ_EXPR <");
1778 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1779 pp_string (buffer, ">");
1780 break;
1782 case REALPART_EXPR:
1783 pp_string (buffer, "REALPART_EXPR <");
1784 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1785 pp_string (buffer, ">");
1786 break;
1788 case IMAGPART_EXPR:
1789 pp_string (buffer, "IMAGPART_EXPR <");
1790 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1791 pp_string (buffer, ">");
1792 break;
1794 case VA_ARG_EXPR:
1795 pp_string (buffer, "VA_ARG_EXPR <");
1796 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1797 pp_string (buffer, ">");
1798 break;
1800 case TRY_FINALLY_EXPR:
1801 case TRY_CATCH_EXPR:
1802 pp_string (buffer, "try");
1803 newline_and_indent (buffer, spc+2);
1804 pp_string (buffer, "{");
1805 newline_and_indent (buffer, spc+4);
1806 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc+4, flags, true);
1807 newline_and_indent (buffer, spc+2);
1808 pp_string (buffer, "}");
1809 newline_and_indent (buffer, spc);
1810 pp_string (buffer,
1811 (TREE_CODE (node) == TRY_CATCH_EXPR) ? "catch" : "finally");
1812 newline_and_indent (buffer, spc+2);
1813 pp_string (buffer, "{");
1814 newline_and_indent (buffer, spc+4);
1815 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc+4, flags, true);
1816 newline_and_indent (buffer, spc+2);
1817 pp_string (buffer, "}");
1818 is_expr = false;
1819 break;
1821 case CATCH_EXPR:
1822 pp_string (buffer, "catch (");
1823 dump_generic_node (buffer, CATCH_TYPES (node), spc+2, flags, false);
1824 pp_string (buffer, ")");
1825 newline_and_indent (buffer, spc+2);
1826 pp_string (buffer, "{");
1827 newline_and_indent (buffer, spc+4);
1828 dump_generic_node (buffer, CATCH_BODY (node), spc+4, flags, true);
1829 newline_and_indent (buffer, spc+2);
1830 pp_string (buffer, "}");
1831 is_expr = false;
1832 break;
1834 case EH_FILTER_EXPR:
1835 pp_string (buffer, "<<<eh_filter (");
1836 dump_generic_node (buffer, EH_FILTER_TYPES (node), spc+2, flags, false);
1837 pp_string (buffer, ")>>>");
1838 newline_and_indent (buffer, spc+2);
1839 pp_string (buffer, "{");
1840 newline_and_indent (buffer, spc+4);
1841 dump_generic_node (buffer, EH_FILTER_FAILURE (node), spc+4, flags, true);
1842 newline_and_indent (buffer, spc+2);
1843 pp_string (buffer, "}");
1844 is_expr = false;
1845 break;
1847 case LABEL_EXPR:
1848 op0 = TREE_OPERAND (node, 0);
1849 /* If this is for break or continue, don't bother printing it. */
1850 if (DECL_NAME (op0))
1852 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1853 if (strcmp (name, "break") == 0
1854 || strcmp (name, "continue") == 0)
1855 break;
1857 dump_generic_node (buffer, op0, spc, flags, false);
1858 pp_character (buffer, ':');
1859 if (DECL_NONLOCAL (op0))
1860 pp_string (buffer, " [non-local]");
1861 break;
1863 case LOOP_EXPR:
1864 pp_string (buffer, "while (1)");
1865 if (!(flags & TDF_SLIM))
1867 newline_and_indent (buffer, spc+2);
1868 pp_character (buffer, '{');
1869 newline_and_indent (buffer, spc+4);
1870 dump_generic_node (buffer, LOOP_EXPR_BODY (node), spc+4, flags, true);
1871 newline_and_indent (buffer, spc+2);
1872 pp_character (buffer, '}');
1874 is_expr = false;
1875 break;
1877 case PREDICT_EXPR:
1878 pp_string (buffer, "// predicted ");
1879 if (PREDICT_EXPR_OUTCOME (node))
1880 pp_string (buffer, "likely by ");
1881 else
1882 pp_string (buffer, "unlikely by ");
1883 pp_string (buffer, predictor_name (PREDICT_EXPR_PREDICTOR (node)));
1884 pp_string (buffer, " predictor.");
1885 break;
1887 case RETURN_EXPR:
1888 pp_string (buffer, "return");
1889 op0 = TREE_OPERAND (node, 0);
1890 if (op0)
1892 pp_space (buffer);
1893 if (TREE_CODE (op0) == MODIFY_EXPR)
1894 dump_generic_node (buffer, TREE_OPERAND (op0, 1),
1895 spc, flags, false);
1896 else
1897 dump_generic_node (buffer, op0, spc, flags, false);
1899 break;
1901 case EXIT_EXPR:
1902 pp_string (buffer, "if (");
1903 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1904 pp_string (buffer, ") break");
1905 break;
1907 case SWITCH_EXPR:
1908 pp_string (buffer, "switch (");
1909 dump_generic_node (buffer, SWITCH_COND (node), spc, flags, false);
1910 pp_character (buffer, ')');
1911 if (!(flags & TDF_SLIM))
1913 newline_and_indent (buffer, spc+2);
1914 pp_character (buffer, '{');
1915 if (SWITCH_BODY (node))
1917 newline_and_indent (buffer, spc+4);
1918 dump_generic_node (buffer, SWITCH_BODY (node), spc+4, flags,
1919 true);
1921 else
1923 tree vec = SWITCH_LABELS (node);
1924 size_t i, n = TREE_VEC_LENGTH (vec);
1925 for (i = 0; i < n; ++i)
1927 tree elt = TREE_VEC_ELT (vec, i);
1928 newline_and_indent (buffer, spc+4);
1929 if (elt)
1931 dump_generic_node (buffer, elt, spc+4, flags, false);
1932 pp_string (buffer, " goto ");
1933 dump_generic_node (buffer, CASE_LABEL (elt), spc+4,
1934 flags, true);
1935 pp_semicolon (buffer);
1937 else
1938 pp_string (buffer, "case ???: goto ???;");
1941 newline_and_indent (buffer, spc+2);
1942 pp_character (buffer, '}');
1944 is_expr = false;
1945 break;
1947 case GOTO_EXPR:
1948 op0 = GOTO_DESTINATION (node);
1949 if (TREE_CODE (op0) != SSA_NAME && DECL_P (op0) && DECL_NAME (op0))
1951 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1952 if (strcmp (name, "break") == 0
1953 || strcmp (name, "continue") == 0)
1955 pp_string (buffer, name);
1956 break;
1959 pp_string (buffer, "goto ");
1960 dump_generic_node (buffer, op0, spc, flags, false);
1961 break;
1963 case ASM_EXPR:
1964 pp_string (buffer, "__asm__");
1965 if (ASM_VOLATILE_P (node))
1966 pp_string (buffer, " __volatile__");
1967 pp_character (buffer, '(');
1968 dump_generic_node (buffer, ASM_STRING (node), spc, flags, false);
1969 pp_character (buffer, ':');
1970 dump_generic_node (buffer, ASM_OUTPUTS (node), spc, flags, false);
1971 pp_character (buffer, ':');
1972 dump_generic_node (buffer, ASM_INPUTS (node), spc, flags, false);
1973 if (ASM_CLOBBERS (node))
1975 pp_character (buffer, ':');
1976 dump_generic_node (buffer, ASM_CLOBBERS (node), spc, flags, false);
1978 pp_string (buffer, ")");
1979 break;
1981 case CASE_LABEL_EXPR:
1982 if (CASE_LOW (node) && CASE_HIGH (node))
1984 pp_string (buffer, "case ");
1985 dump_generic_node (buffer, CASE_LOW (node), spc, flags, false);
1986 pp_string (buffer, " ... ");
1987 dump_generic_node (buffer, CASE_HIGH (node), spc, flags, false);
1989 else if (CASE_LOW (node))
1991 pp_string (buffer, "case ");
1992 dump_generic_node (buffer, CASE_LOW (node), spc, flags, false);
1994 else
1995 pp_string (buffer, "default");
1996 pp_character (buffer, ':');
1997 break;
1999 case OBJ_TYPE_REF:
2000 pp_string (buffer, "OBJ_TYPE_REF(");
2001 dump_generic_node (buffer, OBJ_TYPE_REF_EXPR (node), spc, flags, false);
2002 pp_character (buffer, ';');
2003 dump_generic_node (buffer, OBJ_TYPE_REF_OBJECT (node), spc, flags, false);
2004 pp_character (buffer, '-');
2005 pp_character (buffer, '>');
2006 dump_generic_node (buffer, OBJ_TYPE_REF_TOKEN (node), spc, flags, false);
2007 pp_character (buffer, ')');
2008 break;
2010 case SSA_NAME:
2011 dump_generic_node (buffer, SSA_NAME_VAR (node), spc, flags, false);
2012 pp_string (buffer, "_");
2013 pp_decimal_int (buffer, SSA_NAME_VERSION (node));
2014 if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (node))
2015 pp_string (buffer, "(ab)");
2016 else if (SSA_NAME_IS_DEFAULT_DEF (node))
2017 pp_string (buffer, "(D)");
2018 break;
2020 case WITH_SIZE_EXPR:
2021 pp_string (buffer, "WITH_SIZE_EXPR <");
2022 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2023 pp_string (buffer, ", ");
2024 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2025 pp_string (buffer, ">");
2026 break;
2028 case ASSERT_EXPR:
2029 pp_string (buffer, "ASSERT_EXPR <");
2030 dump_generic_node (buffer, ASSERT_EXPR_VAR (node), spc, flags, false);
2031 pp_string (buffer, ", ");
2032 dump_generic_node (buffer, ASSERT_EXPR_COND (node), spc, flags, false);
2033 pp_string (buffer, ">");
2034 break;
2036 case SCEV_KNOWN:
2037 pp_string (buffer, "scev_known");
2038 break;
2040 case SCEV_NOT_KNOWN:
2041 pp_string (buffer, "scev_not_known");
2042 break;
2044 case POLYNOMIAL_CHREC:
2045 pp_string (buffer, "{");
2046 dump_generic_node (buffer, CHREC_LEFT (node), spc, flags, false);
2047 pp_string (buffer, ", +, ");
2048 dump_generic_node (buffer, CHREC_RIGHT (node), spc, flags, false);
2049 pp_string (buffer, "}_");
2050 dump_generic_node (buffer, CHREC_VAR (node), spc, flags, false);
2051 is_stmt = false;
2052 break;
2054 case REALIGN_LOAD_EXPR:
2055 pp_string (buffer, "REALIGN_LOAD <");
2056 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2057 pp_string (buffer, ", ");
2058 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2059 pp_string (buffer, ", ");
2060 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
2061 pp_string (buffer, ">");
2062 break;
2064 case VEC_COND_EXPR:
2065 pp_string (buffer, " VEC_COND_EXPR < ");
2066 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2067 pp_string (buffer, " , ");
2068 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2069 pp_string (buffer, " , ");
2070 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
2071 pp_string (buffer, " > ");
2072 break;
2074 case VEC_PERM_EXPR:
2075 pp_string (buffer, " VEC_PERM_EXPR < ");
2076 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2077 pp_string (buffer, " , ");
2078 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2079 pp_string (buffer, " , ");
2080 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
2081 pp_string (buffer, " > ");
2082 break;
2084 case DOT_PROD_EXPR:
2085 pp_string (buffer, " DOT_PROD_EXPR < ");
2086 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2087 pp_string (buffer, ", ");
2088 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2089 pp_string (buffer, ", ");
2090 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
2091 pp_string (buffer, " > ");
2092 break;
2094 case WIDEN_MULT_PLUS_EXPR:
2095 pp_string (buffer, " WIDEN_MULT_PLUS_EXPR < ");
2096 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2097 pp_string (buffer, ", ");
2098 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2099 pp_string (buffer, ", ");
2100 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
2101 pp_string (buffer, " > ");
2102 break;
2104 case WIDEN_MULT_MINUS_EXPR:
2105 pp_string (buffer, " WIDEN_MULT_MINUS_EXPR < ");
2106 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2107 pp_string (buffer, ", ");
2108 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2109 pp_string (buffer, ", ");
2110 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
2111 pp_string (buffer, " > ");
2112 break;
2114 case FMA_EXPR:
2115 pp_string (buffer, " FMA_EXPR < ");
2116 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2117 pp_string (buffer, ", ");
2118 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2119 pp_string (buffer, ", ");
2120 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
2121 pp_string (buffer, " > ");
2122 break;
2124 case OMP_PARALLEL:
2125 pp_string (buffer, "#pragma omp parallel");
2126 dump_omp_clauses (buffer, OMP_PARALLEL_CLAUSES (node), spc, flags);
2128 dump_omp_body:
2129 if (!(flags & TDF_SLIM) && OMP_BODY (node))
2131 newline_and_indent (buffer, spc + 2);
2132 pp_character (buffer, '{');
2133 newline_and_indent (buffer, spc + 4);
2134 dump_generic_node (buffer, OMP_BODY (node), spc + 4, flags, false);
2135 newline_and_indent (buffer, spc + 2);
2136 pp_character (buffer, '}');
2138 is_expr = false;
2139 break;
2141 case OMP_TASK:
2142 pp_string (buffer, "#pragma omp task");
2143 dump_omp_clauses (buffer, OMP_TASK_CLAUSES (node), spc, flags);
2144 goto dump_omp_body;
2146 case OMP_FOR:
2147 pp_string (buffer, "#pragma omp for");
2148 dump_omp_clauses (buffer, OMP_FOR_CLAUSES (node), spc, flags);
2150 if (!(flags & TDF_SLIM))
2152 int i;
2154 if (OMP_FOR_PRE_BODY (node))
2156 newline_and_indent (buffer, spc + 2);
2157 pp_character (buffer, '{');
2158 spc += 4;
2159 newline_and_indent (buffer, spc);
2160 dump_generic_node (buffer, OMP_FOR_PRE_BODY (node),
2161 spc, flags, false);
2163 spc -= 2;
2164 for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (node)); i++)
2166 spc += 2;
2167 newline_and_indent (buffer, spc);
2168 pp_string (buffer, "for (");
2169 dump_generic_node (buffer, TREE_VEC_ELT (OMP_FOR_INIT (node), i),
2170 spc, flags, false);
2171 pp_string (buffer, "; ");
2172 dump_generic_node (buffer, TREE_VEC_ELT (OMP_FOR_COND (node), i),
2173 spc, flags, false);
2174 pp_string (buffer, "; ");
2175 dump_generic_node (buffer, TREE_VEC_ELT (OMP_FOR_INCR (node), i),
2176 spc, flags, false);
2177 pp_string (buffer, ")");
2179 if (OMP_FOR_BODY (node))
2181 newline_and_indent (buffer, spc + 2);
2182 pp_character (buffer, '{');
2183 newline_and_indent (buffer, spc + 4);
2184 dump_generic_node (buffer, OMP_FOR_BODY (node), spc + 4, flags,
2185 false);
2186 newline_and_indent (buffer, spc + 2);
2187 pp_character (buffer, '}');
2189 spc -= 2 * TREE_VEC_LENGTH (OMP_FOR_INIT (node)) - 2;
2190 if (OMP_FOR_PRE_BODY (node))
2192 spc -= 4;
2193 newline_and_indent (buffer, spc + 2);
2194 pp_character (buffer, '}');
2197 is_expr = false;
2198 break;
2200 case OMP_SECTIONS:
2201 pp_string (buffer, "#pragma omp sections");
2202 dump_omp_clauses (buffer, OMP_SECTIONS_CLAUSES (node), spc, flags);
2203 goto dump_omp_body;
2205 case OMP_SECTION:
2206 pp_string (buffer, "#pragma omp section");
2207 goto dump_omp_body;
2209 case OMP_MASTER:
2210 pp_string (buffer, "#pragma omp master");
2211 goto dump_omp_body;
2213 case OMP_ORDERED:
2214 pp_string (buffer, "#pragma omp ordered");
2215 goto dump_omp_body;
2217 case OMP_CRITICAL:
2218 pp_string (buffer, "#pragma omp critical");
2219 if (OMP_CRITICAL_NAME (node))
2221 pp_space (buffer);
2222 pp_character (buffer, '(');
2223 dump_generic_node (buffer, OMP_CRITICAL_NAME (node), spc,
2224 flags, false);
2225 pp_character (buffer, ')');
2227 goto dump_omp_body;
2229 case OMP_ATOMIC:
2230 pp_string (buffer, "#pragma omp atomic");
2231 newline_and_indent (buffer, spc + 2);
2232 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2233 pp_space (buffer);
2234 pp_character (buffer, '=');
2235 pp_space (buffer);
2236 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2237 break;
2239 case OMP_ATOMIC_READ:
2240 pp_string (buffer, "#pragma omp atomic read");
2241 newline_and_indent (buffer, spc + 2);
2242 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2243 pp_space (buffer);
2244 break;
2246 case OMP_ATOMIC_CAPTURE_OLD:
2247 case OMP_ATOMIC_CAPTURE_NEW:
2248 pp_string (buffer, "#pragma omp atomic capture");
2249 newline_and_indent (buffer, spc + 2);
2250 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2251 pp_space (buffer);
2252 pp_character (buffer, '=');
2253 pp_space (buffer);
2254 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2255 break;
2257 case OMP_SINGLE:
2258 pp_string (buffer, "#pragma omp single");
2259 dump_omp_clauses (buffer, OMP_SINGLE_CLAUSES (node), spc, flags);
2260 goto dump_omp_body;
2262 case OMP_CLAUSE:
2263 dump_omp_clause (buffer, node, spc, flags);
2264 is_expr = false;
2265 break;
2267 case REDUC_MAX_EXPR:
2268 pp_string (buffer, " REDUC_MAX_EXPR < ");
2269 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2270 pp_string (buffer, " > ");
2271 break;
2273 case REDUC_MIN_EXPR:
2274 pp_string (buffer, " REDUC_MIN_EXPR < ");
2275 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2276 pp_string (buffer, " > ");
2277 break;
2279 case REDUC_PLUS_EXPR:
2280 pp_string (buffer, " REDUC_PLUS_EXPR < ");
2281 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2282 pp_string (buffer, " > ");
2283 break;
2285 case VEC_WIDEN_MULT_HI_EXPR:
2286 pp_string (buffer, " VEC_WIDEN_MULT_HI_EXPR < ");
2287 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2288 pp_string (buffer, ", ");
2289 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2290 pp_string (buffer, " > ");
2291 break;
2293 case VEC_WIDEN_MULT_LO_EXPR:
2294 pp_string (buffer, " VEC_WIDEN_MULT_LO_EXPR < ");
2295 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2296 pp_string (buffer, ", ");
2297 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2298 pp_string (buffer, " > ");
2299 break;
2301 case VEC_WIDEN_LSHIFT_HI_EXPR:
2302 pp_string (buffer, " VEC_WIDEN_LSHIFT_HI_EXPR < ");
2303 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2304 pp_string (buffer, ", ");
2305 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2306 pp_string (buffer, " > ");
2307 break;
2309 case VEC_WIDEN_LSHIFT_LO_EXPR:
2310 pp_string (buffer, " VEC_WIDEN_LSHIFT_HI_EXPR < ");
2311 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2312 pp_string (buffer, ", ");
2313 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2314 pp_string (buffer, " > ");
2315 break;
2317 case VEC_UNPACK_HI_EXPR:
2318 pp_string (buffer, " VEC_UNPACK_HI_EXPR < ");
2319 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2320 pp_string (buffer, " > ");
2321 break;
2323 case VEC_UNPACK_LO_EXPR:
2324 pp_string (buffer, " VEC_UNPACK_LO_EXPR < ");
2325 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2326 pp_string (buffer, " > ");
2327 break;
2329 case VEC_UNPACK_FLOAT_HI_EXPR:
2330 pp_string (buffer, " VEC_UNPACK_FLOAT_HI_EXPR < ");
2331 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2332 pp_string (buffer, " > ");
2333 break;
2335 case VEC_UNPACK_FLOAT_LO_EXPR:
2336 pp_string (buffer, " VEC_UNPACK_FLOAT_LO_EXPR < ");
2337 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2338 pp_string (buffer, " > ");
2339 break;
2341 case VEC_PACK_TRUNC_EXPR:
2342 pp_string (buffer, " VEC_PACK_TRUNC_EXPR < ");
2343 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2344 pp_string (buffer, ", ");
2345 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2346 pp_string (buffer, " > ");
2347 break;
2349 case VEC_PACK_SAT_EXPR:
2350 pp_string (buffer, " VEC_PACK_SAT_EXPR < ");
2351 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2352 pp_string (buffer, ", ");
2353 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2354 pp_string (buffer, " > ");
2355 break;
2357 case VEC_PACK_FIX_TRUNC_EXPR:
2358 pp_string (buffer, " VEC_PACK_FIX_TRUNC_EXPR < ");
2359 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2360 pp_string (buffer, ", ");
2361 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2362 pp_string (buffer, " > ");
2363 break;
2365 case BLOCK:
2366 dump_block_node (buffer, node, spc, flags);
2367 break;
2369 case VEC_EXTRACT_EVEN_EXPR:
2370 pp_string (buffer, " VEC_EXTRACT_EVEN_EXPR < ");
2371 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2372 pp_string (buffer, ", ");
2373 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2374 pp_string (buffer, " > ");
2375 break;
2377 case VEC_EXTRACT_ODD_EXPR:
2378 pp_string (buffer, " VEC_EXTRACT_ODD_EXPR < ");
2379 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2380 pp_string (buffer, ", ");
2381 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2382 pp_string (buffer, " > ");
2383 break;
2385 case VEC_INTERLEAVE_HIGH_EXPR:
2386 pp_string (buffer, " VEC_INTERLEAVE_HIGH_EXPR < ");
2387 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2388 pp_string (buffer, ", ");
2389 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2390 pp_string (buffer, " > ");
2391 break;
2393 case VEC_INTERLEAVE_LOW_EXPR:
2394 pp_string (buffer, " VEC_INTERLEAVE_LOW_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 default:
2402 NIY;
2405 if (is_stmt && is_expr)
2406 pp_semicolon (buffer);
2408 /* If we're building a diagnostic, the formatted text will be written
2409 into BUFFER's stream by the caller; otherwise, write it now. */
2410 if (!(flags & TDF_DIAGNOSTIC))
2411 pp_write_text_to_stream (buffer);
2413 return spc;
2416 /* Print the declaration of a variable. */
2418 void
2419 print_declaration (pretty_printer *buffer, tree t, int spc, int flags)
2421 INDENT (spc);
2423 if (TREE_CODE (t) == TYPE_DECL)
2424 pp_string (buffer, "typedef ");
2426 if (CODE_CONTAINS_STRUCT (TREE_CODE (t), TS_DECL_WRTL) && DECL_REGISTER (t))
2427 pp_string (buffer, "register ");
2429 if (TREE_PUBLIC (t) && DECL_EXTERNAL (t))
2430 pp_string (buffer, "extern ");
2431 else if (TREE_STATIC (t))
2432 pp_string (buffer, "static ");
2434 /* Print the type and name. */
2435 if (TREE_TYPE (t) && TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
2437 tree tmp;
2439 /* Print array's type. */
2440 tmp = TREE_TYPE (t);
2441 while (TREE_CODE (TREE_TYPE (tmp)) == ARRAY_TYPE)
2442 tmp = TREE_TYPE (tmp);
2443 dump_generic_node (buffer, TREE_TYPE (tmp), spc, flags, false);
2445 /* Print variable's name. */
2446 pp_space (buffer);
2447 dump_generic_node (buffer, t, spc, flags, false);
2449 /* Print the dimensions. */
2450 tmp = TREE_TYPE (t);
2451 while (TREE_CODE (tmp) == ARRAY_TYPE)
2453 dump_array_domain (buffer, TYPE_DOMAIN (tmp), spc, flags);
2454 tmp = TREE_TYPE (tmp);
2457 else if (TREE_CODE (t) == FUNCTION_DECL)
2459 dump_generic_node (buffer, TREE_TYPE (TREE_TYPE (t)), spc, flags, false);
2460 pp_space (buffer);
2461 dump_decl_name (buffer, t, flags);
2462 dump_function_declaration (buffer, TREE_TYPE (t), spc, flags);
2464 else
2466 /* Print type declaration. */
2467 dump_generic_node (buffer, TREE_TYPE (t), spc, flags, false);
2469 /* Print variable's name. */
2470 pp_space (buffer);
2471 dump_generic_node (buffer, t, spc, flags, false);
2474 if (TREE_CODE (t) == VAR_DECL && DECL_HARD_REGISTER (t))
2476 pp_string (buffer, " __asm__ ");
2477 pp_character (buffer, '(');
2478 dump_generic_node (buffer, DECL_ASSEMBLER_NAME (t), spc, flags, false);
2479 pp_character (buffer, ')');
2482 /* The initial value of a function serves to determine whether the function
2483 is declared or defined. So the following does not apply to function
2484 nodes. */
2485 if (TREE_CODE (t) != FUNCTION_DECL)
2487 /* Print the initial value. */
2488 if (DECL_INITIAL (t))
2490 pp_space (buffer);
2491 pp_character (buffer, '=');
2492 pp_space (buffer);
2493 dump_generic_node (buffer, DECL_INITIAL (t), spc, flags, false);
2497 if (TREE_CODE (t) == VAR_DECL && DECL_HAS_VALUE_EXPR_P (t))
2499 pp_string (buffer, " [value-expr: ");
2500 dump_generic_node (buffer, DECL_VALUE_EXPR (t), spc, flags, false);
2501 pp_character (buffer, ']');
2504 pp_character (buffer, ';');
2508 /* Prints a structure: name, fields, and methods.
2509 FIXME: Still incomplete. */
2511 static void
2512 print_struct_decl (pretty_printer *buffer, const_tree node, int spc, int flags)
2514 /* Print the name of the structure. */
2515 if (TYPE_NAME (node))
2517 INDENT (spc);
2518 if (TREE_CODE (node) == RECORD_TYPE)
2519 pp_string (buffer, "struct ");
2520 else if ((TREE_CODE (node) == UNION_TYPE
2521 || TREE_CODE (node) == QUAL_UNION_TYPE))
2522 pp_string (buffer, "union ");
2524 dump_generic_node (buffer, TYPE_NAME (node), spc, 0, false);
2527 /* Print the contents of the structure. */
2528 pp_newline (buffer);
2529 INDENT (spc);
2530 pp_character (buffer, '{');
2531 pp_newline (buffer);
2533 /* Print the fields of the structure. */
2535 tree tmp;
2536 tmp = TYPE_FIELDS (node);
2537 while (tmp)
2539 /* Avoid to print recursively the structure. */
2540 /* FIXME : Not implemented correctly...,
2541 what about the case when we have a cycle in the contain graph? ...
2542 Maybe this could be solved by looking at the scope in which the
2543 structure was declared. */
2544 if (TREE_TYPE (tmp) != node
2545 && (TREE_CODE (TREE_TYPE (tmp)) != POINTER_TYPE
2546 || TREE_TYPE (TREE_TYPE (tmp)) != node))
2548 print_declaration (buffer, tmp, spc+2, flags);
2549 pp_newline (buffer);
2551 tmp = DECL_CHAIN (tmp);
2554 INDENT (spc);
2555 pp_character (buffer, '}');
2558 /* Return the priority of the operator CODE.
2560 From lowest to highest precedence with either left-to-right (L-R)
2561 or right-to-left (R-L) associativity]:
2563 1 [L-R] ,
2564 2 [R-L] = += -= *= /= %= &= ^= |= <<= >>=
2565 3 [R-L] ?:
2566 4 [L-R] ||
2567 5 [L-R] &&
2568 6 [L-R] |
2569 7 [L-R] ^
2570 8 [L-R] &
2571 9 [L-R] == !=
2572 10 [L-R] < <= > >=
2573 11 [L-R] << >>
2574 12 [L-R] + -
2575 13 [L-R] * / %
2576 14 [R-L] ! ~ ++ -- + - * & (type) sizeof
2577 15 [L-R] fn() [] -> .
2579 unary +, - and * have higher precedence than the corresponding binary
2580 operators. */
2583 op_code_prio (enum tree_code code)
2585 switch (code)
2587 case TREE_LIST:
2588 case COMPOUND_EXPR:
2589 case BIND_EXPR:
2590 return 1;
2592 case MODIFY_EXPR:
2593 case INIT_EXPR:
2594 return 2;
2596 case COND_EXPR:
2597 return 3;
2599 case TRUTH_OR_EXPR:
2600 case TRUTH_ORIF_EXPR:
2601 return 4;
2603 case TRUTH_AND_EXPR:
2604 case TRUTH_ANDIF_EXPR:
2605 return 5;
2607 case BIT_IOR_EXPR:
2608 return 6;
2610 case BIT_XOR_EXPR:
2611 case TRUTH_XOR_EXPR:
2612 return 7;
2614 case BIT_AND_EXPR:
2615 return 8;
2617 case EQ_EXPR:
2618 case NE_EXPR:
2619 return 9;
2621 case UNLT_EXPR:
2622 case UNLE_EXPR:
2623 case UNGT_EXPR:
2624 case UNGE_EXPR:
2625 case UNEQ_EXPR:
2626 case LTGT_EXPR:
2627 case ORDERED_EXPR:
2628 case UNORDERED_EXPR:
2629 case LT_EXPR:
2630 case LE_EXPR:
2631 case GT_EXPR:
2632 case GE_EXPR:
2633 return 10;
2635 case LSHIFT_EXPR:
2636 case RSHIFT_EXPR:
2637 case LROTATE_EXPR:
2638 case RROTATE_EXPR:
2639 case VEC_WIDEN_LSHIFT_HI_EXPR:
2640 case VEC_WIDEN_LSHIFT_LO_EXPR:
2641 case WIDEN_LSHIFT_EXPR:
2642 return 11;
2644 case WIDEN_SUM_EXPR:
2645 case PLUS_EXPR:
2646 case POINTER_PLUS_EXPR:
2647 case MINUS_EXPR:
2648 return 12;
2650 case VEC_WIDEN_MULT_HI_EXPR:
2651 case VEC_WIDEN_MULT_LO_EXPR:
2652 case WIDEN_MULT_EXPR:
2653 case DOT_PROD_EXPR:
2654 case WIDEN_MULT_PLUS_EXPR:
2655 case WIDEN_MULT_MINUS_EXPR:
2656 case MULT_EXPR:
2657 case TRUNC_DIV_EXPR:
2658 case CEIL_DIV_EXPR:
2659 case FLOOR_DIV_EXPR:
2660 case ROUND_DIV_EXPR:
2661 case RDIV_EXPR:
2662 case EXACT_DIV_EXPR:
2663 case TRUNC_MOD_EXPR:
2664 case CEIL_MOD_EXPR:
2665 case FLOOR_MOD_EXPR:
2666 case ROUND_MOD_EXPR:
2667 case FMA_EXPR:
2668 return 13;
2670 case TRUTH_NOT_EXPR:
2671 case BIT_NOT_EXPR:
2672 case POSTINCREMENT_EXPR:
2673 case POSTDECREMENT_EXPR:
2674 case PREINCREMENT_EXPR:
2675 case PREDECREMENT_EXPR:
2676 case NEGATE_EXPR:
2677 case INDIRECT_REF:
2678 case ADDR_EXPR:
2679 case FLOAT_EXPR:
2680 CASE_CONVERT:
2681 case FIX_TRUNC_EXPR:
2682 case TARGET_EXPR:
2683 return 14;
2685 case CALL_EXPR:
2686 case ARRAY_REF:
2687 case ARRAY_RANGE_REF:
2688 case COMPONENT_REF:
2689 return 15;
2691 /* Special expressions. */
2692 case MIN_EXPR:
2693 case MAX_EXPR:
2694 case ABS_EXPR:
2695 case REALPART_EXPR:
2696 case IMAGPART_EXPR:
2697 case REDUC_MAX_EXPR:
2698 case REDUC_MIN_EXPR:
2699 case REDUC_PLUS_EXPR:
2700 case VEC_LSHIFT_EXPR:
2701 case VEC_RSHIFT_EXPR:
2702 case VEC_UNPACK_HI_EXPR:
2703 case VEC_UNPACK_LO_EXPR:
2704 case VEC_UNPACK_FLOAT_HI_EXPR:
2705 case VEC_UNPACK_FLOAT_LO_EXPR:
2706 case VEC_PACK_TRUNC_EXPR:
2707 case VEC_PACK_SAT_EXPR:
2708 return 16;
2710 default:
2711 /* Return an arbitrarily high precedence to avoid surrounding single
2712 VAR_DECLs in ()s. */
2713 return 9999;
2717 /* Return the priority of the operator OP. */
2720 op_prio (const_tree op)
2722 enum tree_code code;
2724 if (op == NULL)
2725 return 9999;
2727 code = TREE_CODE (op);
2728 if (code == SAVE_EXPR || code == NON_LVALUE_EXPR)
2729 return op_prio (TREE_OPERAND (op, 0));
2731 return op_code_prio (code);
2734 /* Return the symbol associated with operator CODE. */
2736 const char *
2737 op_symbol_code (enum tree_code code)
2739 switch (code)
2741 case MODIFY_EXPR:
2742 return "=";
2744 case TRUTH_OR_EXPR:
2745 case TRUTH_ORIF_EXPR:
2746 return "||";
2748 case TRUTH_AND_EXPR:
2749 case TRUTH_ANDIF_EXPR:
2750 return "&&";
2752 case BIT_IOR_EXPR:
2753 return "|";
2755 case TRUTH_XOR_EXPR:
2756 case BIT_XOR_EXPR:
2757 return "^";
2759 case ADDR_EXPR:
2760 case BIT_AND_EXPR:
2761 return "&";
2763 case ORDERED_EXPR:
2764 return "ord";
2765 case UNORDERED_EXPR:
2766 return "unord";
2768 case EQ_EXPR:
2769 return "==";
2770 case UNEQ_EXPR:
2771 return "u==";
2773 case NE_EXPR:
2774 return "!=";
2776 case LT_EXPR:
2777 return "<";
2778 case UNLT_EXPR:
2779 return "u<";
2781 case LE_EXPR:
2782 return "<=";
2783 case UNLE_EXPR:
2784 return "u<=";
2786 case GT_EXPR:
2787 return ">";
2788 case UNGT_EXPR:
2789 return "u>";
2791 case GE_EXPR:
2792 return ">=";
2793 case UNGE_EXPR:
2794 return "u>=";
2796 case LTGT_EXPR:
2797 return "<>";
2799 case LSHIFT_EXPR:
2800 return "<<";
2802 case RSHIFT_EXPR:
2803 return ">>";
2805 case LROTATE_EXPR:
2806 return "r<<";
2808 case RROTATE_EXPR:
2809 return "r>>";
2811 case VEC_LSHIFT_EXPR:
2812 return "v<<";
2814 case VEC_RSHIFT_EXPR:
2815 return "v>>";
2817 case WIDEN_LSHIFT_EXPR:
2818 return "w<<";
2820 case POINTER_PLUS_EXPR:
2821 return "+";
2823 case PLUS_EXPR:
2824 return "+";
2826 case REDUC_PLUS_EXPR:
2827 return "r+";
2829 case WIDEN_SUM_EXPR:
2830 return "w+";
2832 case WIDEN_MULT_EXPR:
2833 return "w*";
2835 case NEGATE_EXPR:
2836 case MINUS_EXPR:
2837 return "-";
2839 case BIT_NOT_EXPR:
2840 return "~";
2842 case TRUTH_NOT_EXPR:
2843 return "!";
2845 case MULT_EXPR:
2846 case INDIRECT_REF:
2847 return "*";
2849 case TRUNC_DIV_EXPR:
2850 case RDIV_EXPR:
2851 return "/";
2853 case CEIL_DIV_EXPR:
2854 return "/[cl]";
2856 case FLOOR_DIV_EXPR:
2857 return "/[fl]";
2859 case ROUND_DIV_EXPR:
2860 return "/[rd]";
2862 case EXACT_DIV_EXPR:
2863 return "/[ex]";
2865 case TRUNC_MOD_EXPR:
2866 return "%";
2868 case CEIL_MOD_EXPR:
2869 return "%[cl]";
2871 case FLOOR_MOD_EXPR:
2872 return "%[fl]";
2874 case ROUND_MOD_EXPR:
2875 return "%[rd]";
2877 case PREDECREMENT_EXPR:
2878 return " --";
2880 case PREINCREMENT_EXPR:
2881 return " ++";
2883 case POSTDECREMENT_EXPR:
2884 return "-- ";
2886 case POSTINCREMENT_EXPR:
2887 return "++ ";
2889 case MAX_EXPR:
2890 return "max";
2892 case MIN_EXPR:
2893 return "min";
2895 default:
2896 return "<<< ??? >>>";
2900 /* Return the symbol associated with operator OP. */
2902 static const char *
2903 op_symbol (const_tree op)
2905 return op_symbol_code (TREE_CODE (op));
2908 /* Prints the name of a call. NODE is the CALL_EXPR_FN of a CALL_EXPR or
2909 the gimple_call_fn of a GIMPLE_CALL. */
2911 void
2912 print_call_name (pretty_printer *buffer, tree node, int flags)
2914 tree op0 = node;
2916 if (TREE_CODE (op0) == NON_LVALUE_EXPR)
2917 op0 = TREE_OPERAND (op0, 0);
2919 again:
2920 switch (TREE_CODE (op0))
2922 case VAR_DECL:
2923 case PARM_DECL:
2924 case FUNCTION_DECL:
2925 dump_function_name (buffer, op0, flags);
2926 break;
2928 case ADDR_EXPR:
2929 case INDIRECT_REF:
2930 case NOP_EXPR:
2931 op0 = TREE_OPERAND (op0, 0);
2932 goto again;
2934 case COND_EXPR:
2935 pp_string (buffer, "(");
2936 dump_generic_node (buffer, TREE_OPERAND (op0, 0), 0, flags, false);
2937 pp_string (buffer, ") ? ");
2938 dump_generic_node (buffer, TREE_OPERAND (op0, 1), 0, flags, false);
2939 pp_string (buffer, " : ");
2940 dump_generic_node (buffer, TREE_OPERAND (op0, 2), 0, flags, false);
2941 break;
2943 case ARRAY_REF:
2944 if (TREE_CODE (TREE_OPERAND (op0, 0)) == VAR_DECL)
2945 dump_function_name (buffer, TREE_OPERAND (op0, 0), flags);
2946 else
2947 dump_generic_node (buffer, op0, 0, flags, false);
2948 break;
2950 case MEM_REF:
2951 if (integer_zerop (TREE_OPERAND (op0, 1)))
2953 op0 = TREE_OPERAND (op0, 0);
2954 goto again;
2956 /* Fallthru. */
2957 case COMPONENT_REF:
2958 case SSA_NAME:
2959 case OBJ_TYPE_REF:
2960 dump_generic_node (buffer, op0, 0, flags, false);
2961 break;
2963 default:
2964 NIY;
2968 /* Parses the string STR and replaces new-lines by '\n', tabs by '\t', ... */
2970 static void
2971 pretty_print_string (pretty_printer *buffer, const char *str)
2973 if (str == NULL)
2974 return;
2976 while (*str)
2978 switch (str[0])
2980 case '\b':
2981 pp_string (buffer, "\\b");
2982 break;
2984 case '\f':
2985 pp_string (buffer, "\\f");
2986 break;
2988 case '\n':
2989 pp_string (buffer, "\\n");
2990 break;
2992 case '\r':
2993 pp_string (buffer, "\\r");
2994 break;
2996 case '\t':
2997 pp_string (buffer, "\\t");
2998 break;
3000 case '\v':
3001 pp_string (buffer, "\\v");
3002 break;
3004 case '\\':
3005 pp_string (buffer, "\\\\");
3006 break;
3008 case '\"':
3009 pp_string (buffer, "\\\"");
3010 break;
3012 case '\'':
3013 pp_string (buffer, "\\'");
3014 break;
3016 /* No need to handle \0; the loop terminates on \0. */
3018 case '\1':
3019 pp_string (buffer, "\\1");
3020 break;
3022 case '\2':
3023 pp_string (buffer, "\\2");
3024 break;
3026 case '\3':
3027 pp_string (buffer, "\\3");
3028 break;
3030 case '\4':
3031 pp_string (buffer, "\\4");
3032 break;
3034 case '\5':
3035 pp_string (buffer, "\\5");
3036 break;
3038 case '\6':
3039 pp_string (buffer, "\\6");
3040 break;
3042 case '\7':
3043 pp_string (buffer, "\\7");
3044 break;
3046 default:
3047 pp_character (buffer, str[0]);
3048 break;
3050 str++;
3054 static void
3055 maybe_init_pretty_print (FILE *file)
3057 if (!initialized)
3059 pp_construct (&buffer, /* prefix */NULL, /* line-width */0);
3060 pp_needs_newline (&buffer) = true;
3061 pp_translate_identifiers (&buffer) = false;
3062 initialized = 1;
3065 buffer.buffer->stream = file;
3068 static void
3069 newline_and_indent (pretty_printer *buffer, int spc)
3071 pp_newline (buffer);
3072 INDENT (spc);
3075 /* Handle a %K format for TEXT. Separate from default_tree_printer so
3076 it can also be used in front ends.
3077 %K: a statement, from which EXPR_LOCATION and TREE_BLOCK will be recorded.
3080 void
3081 percent_K_format (text_info *text)
3083 tree t = va_arg (*text->args_ptr, tree), block;
3084 gcc_assert (text->locus != NULL);
3085 *text->locus = EXPR_LOCATION (t);
3086 gcc_assert (pp_ti_abstract_origin (text) != NULL);
3087 block = TREE_BLOCK (t);
3088 *pp_ti_abstract_origin (text) = NULL;
3089 while (block
3090 && TREE_CODE (block) == BLOCK
3091 && BLOCK_ABSTRACT_ORIGIN (block))
3093 tree ao = BLOCK_ABSTRACT_ORIGIN (block);
3095 while (TREE_CODE (ao) == BLOCK
3096 && BLOCK_ABSTRACT_ORIGIN (ao)
3097 && BLOCK_ABSTRACT_ORIGIN (ao) != ao)
3098 ao = BLOCK_ABSTRACT_ORIGIN (ao);
3100 if (TREE_CODE (ao) == FUNCTION_DECL)
3102 *pp_ti_abstract_origin (text) = block;
3103 break;
3105 block = BLOCK_SUPERCONTEXT (block);
3109 /* Print the identifier ID to PRETTY-PRINTER. */
3111 void
3112 pp_base_tree_identifier (pretty_printer *pp, tree id)
3114 if (pp_translate_identifiers (pp))
3116 const char *text = identifier_to_locale (IDENTIFIER_POINTER (id));
3117 pp_append_text (pp, text, text + strlen (text));
3119 else
3120 pp_append_text (pp, IDENTIFIER_POINTER (id),
3121 IDENTIFIER_POINTER (id) + IDENTIFIER_LENGTH (id));
3124 /* A helper function that is used to dump function information before the
3125 function dump. */
3127 void
3128 dump_function_header (FILE *dump_file, tree fdecl, int flags)
3130 const char *dname, *aname;
3131 struct cgraph_node *node = cgraph_get_node (fdecl);
3132 struct function *fun = DECL_STRUCT_FUNCTION (fdecl);
3134 dname = lang_hooks.decl_printable_name (fdecl, 2);
3136 if (DECL_ASSEMBLER_NAME_SET_P (fdecl))
3137 aname = (IDENTIFIER_POINTER
3138 (DECL_ASSEMBLER_NAME (fdecl)));
3139 else
3140 aname = "<unset-asm-name>";
3142 fprintf (dump_file, "\n;; Function %s (%s, funcdef_no=%d",
3143 dname, aname, fun->funcdef_no);
3144 if (!(flags & TDF_NOUID))
3145 fprintf (dump_file, ", decl_uid=%d", DECL_UID (fdecl));
3146 if (node)
3148 fprintf (dump_file, ", cgraph_uid=%d)%s\n\n", node->uid,
3149 node->frequency == NODE_FREQUENCY_HOT
3150 ? " (hot)"
3151 : node->frequency == NODE_FREQUENCY_UNLIKELY_EXECUTED
3152 ? " (unlikely executed)"
3153 : node->frequency == NODE_FREQUENCY_EXECUTED_ONCE
3154 ? " (executed once)"
3155 : "");
3157 else
3158 fprintf (dump_file, ")\n\n");