Merge from trunk: 215733-215743
[official-gcc.git] / gcc-4_6_3-mobile / gcc / tree-pretty-print.c
blobcc09fbe3a23eda5554b706e401c4f398bc6162bf
1 /* Pretty formatting of GENERIC trees in C syntax.
2 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
3 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"
37 #include "l-ipo.h"
39 /* Local functions, macros and variables. */
40 static const char *op_symbol (const_tree);
41 static void pretty_print_string (pretty_printer *, const char*);
42 static void newline_and_indent (pretty_printer *, int);
43 static void maybe_init_pretty_print (FILE *);
44 static void print_struct_decl (pretty_printer *, const_tree, int, int);
45 static void do_niy (pretty_printer *, const_tree);
47 #define INDENT(SPACE) do { \
48 int i; for (i = 0; i<SPACE; i++) pp_space (buffer); } while (0)
50 #define NIY do_niy(buffer,node)
52 static pretty_printer buffer;
53 static int initialized = 0;
55 /* Try to print something for an unknown tree code. */
57 static void
58 do_niy (pretty_printer *buffer, const_tree node)
60 int i, len;
62 pp_string (buffer, "<<< Unknown tree: ");
63 pp_string (buffer, tree_code_name[(int) TREE_CODE (node)]);
65 if (EXPR_P (node))
67 len = TREE_OPERAND_LENGTH (node);
68 for (i = 0; i < len; ++i)
70 newline_and_indent (buffer, 2);
71 dump_generic_node (buffer, TREE_OPERAND (node, i), 2, 0, false);
75 pp_string (buffer, " >>>");
78 /* Debugging function to print out a generic expression. */
80 DEBUG_FUNCTION void
81 debug_generic_expr (tree t)
83 print_generic_expr (stderr, t, TDF_VOPS|TDF_MEMSYMS);
84 fprintf (stderr, "\n");
87 /* Debugging function to print out a generic statement. */
89 DEBUG_FUNCTION void
90 debug_generic_stmt (tree t)
92 print_generic_stmt (stderr, t, TDF_VOPS|TDF_MEMSYMS);
93 fprintf (stderr, "\n");
96 /* Debugging function to print out a chain of trees . */
98 DEBUG_FUNCTION void
99 debug_tree_chain (tree t)
101 struct pointer_set_t *seen = pointer_set_create ();
103 while (t)
105 print_generic_expr (stderr, t, TDF_VOPS|TDF_MEMSYMS|TDF_UID);
106 fprintf (stderr, " ");
107 t = TREE_CHAIN (t);
108 if (pointer_set_insert (seen, t))
110 fprintf (stderr, "... [cycled back to ");
111 print_generic_expr (stderr, t, TDF_VOPS|TDF_MEMSYMS|TDF_UID);
112 fprintf (stderr, "]");
113 break;
116 fprintf (stderr, "\n");
118 pointer_set_destroy (seen);
121 /* Prints declaration DECL to the FILE with details specified by FLAGS. */
122 void
123 print_generic_decl (FILE *file, tree decl, int flags)
125 maybe_init_pretty_print (file);
126 print_declaration (&buffer, decl, 2, flags);
127 pp_write_text_to_stream (&buffer);
130 /* Print tree T, and its successors, on file FILE. FLAGS specifies details
131 to show in the dump. See TDF_* in tree-pass.h. */
133 void
134 print_generic_stmt (FILE *file, tree t, int flags)
136 maybe_init_pretty_print (file);
137 dump_generic_node (&buffer, t, 0, flags, true);
138 pp_flush (&buffer);
141 /* Print tree T, and its successors, on file FILE. FLAGS specifies details
142 to show in the dump. See TDF_* in tree-pass.h. The output is indented by
143 INDENT spaces. */
145 void
146 print_generic_stmt_indented (FILE *file, tree t, int flags, int indent)
148 int i;
150 maybe_init_pretty_print (file);
152 for (i = 0; i < indent; i++)
153 pp_space (&buffer);
154 dump_generic_node (&buffer, t, indent, flags, true);
155 pp_flush (&buffer);
158 /* Print a single expression T on file FILE. FLAGS specifies details to show
159 in the dump. See TDF_* in tree-pass.h. */
161 void
162 print_generic_expr (FILE *file, tree t, int flags)
164 maybe_init_pretty_print (file);
165 dump_generic_node (&buffer, t, 0, flags, false);
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_character (buffer, '(');
236 /* Print the argument types. The last element in the list is a VOID_TYPE.
237 The following avoids printing the last element. */
238 arg = TYPE_ARG_TYPES (node);
239 while (arg && TREE_CHAIN (arg) && arg != error_mark_node)
241 wrote_arg = true;
242 dump_generic_node (buffer, TREE_VALUE (arg), spc, flags, false);
243 arg = TREE_CHAIN (arg);
244 if (TREE_CHAIN (arg) && TREE_CODE (TREE_CHAIN (arg)) == TREE_LIST)
246 pp_character (buffer, ',');
247 pp_space (buffer);
251 if (!wrote_arg)
252 pp_string (buffer, "void");
254 pp_character (buffer, ')');
257 /* Dump the domain associated with an array. */
259 static void
260 dump_array_domain (pretty_printer *buffer, tree domain, int spc, int flags)
262 pp_character (buffer, '[');
263 if (domain)
265 tree min = TYPE_MIN_VALUE (domain);
266 tree max = TYPE_MAX_VALUE (domain);
268 if (min && max
269 && integer_zerop (min)
270 && host_integerp (max, 0))
271 pp_wide_integer (buffer, TREE_INT_CST_LOW (max) + 1);
272 else
274 if (min)
275 dump_generic_node (buffer, min, spc, flags, false);
276 pp_character (buffer, ':');
277 if (max)
278 dump_generic_node (buffer, max, spc, flags, false);
281 else
282 pp_string (buffer, "<unknown>");
283 pp_character (buffer, ']');
287 /* Dump OpenMP clause CLAUSE. BUFFER, CLAUSE, SPC and FLAGS are as in
288 dump_generic_node. */
290 static void
291 dump_omp_clause (pretty_printer *buffer, tree clause, int spc, int flags)
293 const char *name;
295 switch (OMP_CLAUSE_CODE (clause))
297 case OMP_CLAUSE_PRIVATE:
298 name = "private";
299 goto print_remap;
300 case OMP_CLAUSE_SHARED:
301 name = "shared";
302 goto print_remap;
303 case OMP_CLAUSE_FIRSTPRIVATE:
304 name = "firstprivate";
305 goto print_remap;
306 case OMP_CLAUSE_LASTPRIVATE:
307 name = "lastprivate";
308 goto print_remap;
309 case OMP_CLAUSE_COPYIN:
310 name = "copyin";
311 goto print_remap;
312 case OMP_CLAUSE_COPYPRIVATE:
313 name = "copyprivate";
314 goto print_remap;
315 print_remap:
316 pp_string (buffer, name);
317 pp_character (buffer, '(');
318 dump_generic_node (buffer, OMP_CLAUSE_DECL (clause),
319 spc, flags, false);
320 pp_character (buffer, ')');
321 break;
323 case OMP_CLAUSE_REDUCTION:
324 pp_string (buffer, "reduction(");
325 pp_string (buffer, op_symbol_code (OMP_CLAUSE_REDUCTION_CODE (clause)));
326 pp_character (buffer, ':');
327 dump_generic_node (buffer, OMP_CLAUSE_DECL (clause),
328 spc, flags, false);
329 pp_character (buffer, ')');
330 break;
332 case OMP_CLAUSE_IF:
333 pp_string (buffer, "if(");
334 dump_generic_node (buffer, OMP_CLAUSE_IF_EXPR (clause),
335 spc, flags, false);
336 pp_character (buffer, ')');
337 break;
339 case OMP_CLAUSE_NUM_THREADS:
340 pp_string (buffer, "num_threads(");
341 dump_generic_node (buffer, OMP_CLAUSE_NUM_THREADS_EXPR (clause),
342 spc, flags, false);
343 pp_character (buffer, ')');
344 break;
346 case OMP_CLAUSE_NOWAIT:
347 pp_string (buffer, "nowait");
348 break;
349 case OMP_CLAUSE_ORDERED:
350 pp_string (buffer, "ordered");
351 break;
353 case OMP_CLAUSE_DEFAULT:
354 pp_string (buffer, "default(");
355 switch (OMP_CLAUSE_DEFAULT_KIND (clause))
357 case OMP_CLAUSE_DEFAULT_UNSPECIFIED:
358 break;
359 case OMP_CLAUSE_DEFAULT_SHARED:
360 pp_string (buffer, "shared");
361 break;
362 case OMP_CLAUSE_DEFAULT_NONE:
363 pp_string (buffer, "none");
364 break;
365 case OMP_CLAUSE_DEFAULT_PRIVATE:
366 pp_string (buffer, "private");
367 break;
368 case OMP_CLAUSE_DEFAULT_FIRSTPRIVATE:
369 pp_string (buffer, "firstprivate");
370 break;
371 default:
372 gcc_unreachable ();
374 pp_character (buffer, ')');
375 break;
377 case OMP_CLAUSE_SCHEDULE:
378 pp_string (buffer, "schedule(");
379 switch (OMP_CLAUSE_SCHEDULE_KIND (clause))
381 case OMP_CLAUSE_SCHEDULE_STATIC:
382 pp_string (buffer, "static");
383 break;
384 case OMP_CLAUSE_SCHEDULE_DYNAMIC:
385 pp_string (buffer, "dynamic");
386 break;
387 case OMP_CLAUSE_SCHEDULE_GUIDED:
388 pp_string (buffer, "guided");
389 break;
390 case OMP_CLAUSE_SCHEDULE_RUNTIME:
391 pp_string (buffer, "runtime");
392 break;
393 case OMP_CLAUSE_SCHEDULE_AUTO:
394 pp_string (buffer, "auto");
395 break;
396 default:
397 gcc_unreachable ();
399 if (OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clause))
401 pp_character (buffer, ',');
402 dump_generic_node (buffer,
403 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clause),
404 spc, flags, false);
406 pp_character (buffer, ')');
407 break;
409 case OMP_CLAUSE_UNTIED:
410 pp_string (buffer, "untied");
411 break;
413 case OMP_CLAUSE_COLLAPSE:
414 pp_string (buffer, "collapse(");
415 dump_generic_node (buffer,
416 OMP_CLAUSE_COLLAPSE_EXPR (clause),
417 spc, flags, false);
418 pp_character (buffer, ')');
419 break;
421 default:
422 /* Should never happen. */
423 dump_generic_node (buffer, clause, spc, flags, false);
424 break;
429 /* Dump the list of OpenMP clauses. BUFFER, SPC and FLAGS are as in
430 dump_generic_node. */
432 void
433 dump_omp_clauses (pretty_printer *buffer, tree clause, int spc, int flags)
435 if (clause == NULL)
436 return;
438 pp_space (buffer);
439 while (1)
441 dump_omp_clause (buffer, clause, spc, flags);
442 clause = OMP_CLAUSE_CHAIN (clause);
443 if (clause == NULL)
444 return;
445 pp_space (buffer);
450 /* Dump location LOC to BUFFER. */
452 static void
453 dump_location (pretty_printer *buffer, location_t loc)
455 expanded_location xloc = expand_location (loc);
456 int discriminator = get_discriminator_from_locus (loc);
458 pp_character (buffer, '[');
459 if (xloc.file)
461 pp_string (buffer, xloc.file);
462 pp_string (buffer, " : ");
464 pp_decimal_int (buffer, xloc.line);
465 if (discriminator)
467 pp_string (buffer, " discrim ");
468 pp_decimal_int (buffer, discriminator);
470 pp_string (buffer, "] ");
474 /* Dump lexical block BLOCK. BUFFER, SPC and FLAGS are as in
475 dump_generic_node. */
477 static void
478 dump_block_node (pretty_printer *buffer, tree block, int spc, int flags)
480 tree t;
482 pp_printf (buffer, "BLOCK #%d ", BLOCK_NUMBER (block));
484 if (flags & TDF_ADDRESS)
485 pp_printf (buffer, "[%p] ", (void *) block);
487 if (BLOCK_ABSTRACT (block))
488 pp_string (buffer, "[abstract] ");
490 if (TREE_ASM_WRITTEN (block))
491 pp_string (buffer, "[written] ");
493 if (flags & TDF_SLIM)
494 return;
496 if (BLOCK_SOURCE_LOCATION (block))
497 dump_location (buffer, BLOCK_SOURCE_LOCATION (block));
499 newline_and_indent (buffer, spc + 2);
501 if (BLOCK_SUPERCONTEXT (block))
503 pp_string (buffer, "SUPERCONTEXT: ");
504 dump_generic_node (buffer, BLOCK_SUPERCONTEXT (block), 0,
505 flags | TDF_SLIM, false);
506 newline_and_indent (buffer, spc + 2);
509 if (BLOCK_SUBBLOCKS (block))
511 pp_string (buffer, "SUBBLOCKS: ");
512 for (t = BLOCK_SUBBLOCKS (block); t; t = BLOCK_CHAIN (t))
514 dump_generic_node (buffer, t, 0, flags | TDF_SLIM, false);
515 pp_string (buffer, " ");
517 newline_and_indent (buffer, spc + 2);
520 if (BLOCK_CHAIN (block))
522 pp_string (buffer, "SIBLINGS: ");
523 for (t = BLOCK_CHAIN (block); t; t = BLOCK_CHAIN (t))
525 dump_generic_node (buffer, t, 0, flags | TDF_SLIM, false);
526 pp_string (buffer, " ");
528 newline_and_indent (buffer, spc + 2);
531 if (BLOCK_VARS (block))
533 pp_string (buffer, "VARS: ");
534 for (t = BLOCK_VARS (block); t; t = TREE_CHAIN (t))
536 dump_generic_node (buffer, t, 0, flags, false);
537 pp_string (buffer, " ");
539 newline_and_indent (buffer, spc + 2);
542 if (VEC_length (tree, BLOCK_NONLOCALIZED_VARS (block)) > 0)
544 unsigned i;
545 VEC(tree,gc) *nlv = BLOCK_NONLOCALIZED_VARS (block);
547 pp_string (buffer, "NONLOCALIZED_VARS: ");
548 FOR_EACH_VEC_ELT (tree, nlv, i, t)
550 dump_generic_node (buffer, t, 0, flags, false);
551 pp_string (buffer, " ");
553 newline_and_indent (buffer, spc + 2);
556 if (BLOCK_ABSTRACT_ORIGIN (block))
558 pp_string (buffer, "ABSTRACT_ORIGIN: ");
559 dump_generic_node (buffer, BLOCK_ABSTRACT_ORIGIN (block), 0,
560 flags | TDF_SLIM, false);
561 newline_and_indent (buffer, spc + 2);
564 if (BLOCK_FRAGMENT_ORIGIN (block))
566 pp_string (buffer, "FRAGMENT_ORIGIN: ");
567 dump_generic_node (buffer, BLOCK_FRAGMENT_ORIGIN (block), 0,
568 flags | TDF_SLIM, false);
569 newline_and_indent (buffer, spc + 2);
572 if (BLOCK_FRAGMENT_CHAIN (block))
574 pp_string (buffer, "FRAGMENT_CHAIN: ");
575 for (t = BLOCK_FRAGMENT_CHAIN (block); t; t = BLOCK_FRAGMENT_CHAIN (t))
577 dump_generic_node (buffer, t, 0, flags | TDF_SLIM, false);
578 pp_string (buffer, " ");
580 newline_and_indent (buffer, spc + 2);
585 /* Dump the node NODE on the pretty_printer BUFFER, SPC spaces of
586 indent. FLAGS specifies details to show in the dump (see TDF_* in
587 tree-pass.h). If IS_STMT is true, the object printed is considered
588 to be a statement and it is terminated by ';' if appropriate. */
591 dump_generic_node (pretty_printer *buffer, tree node, int spc, int flags,
592 bool is_stmt)
594 tree type;
595 tree op0, op1;
596 const char *str;
597 bool is_expr;
599 if (node == NULL_TREE)
600 return spc;
602 is_expr = EXPR_P (node);
604 if (is_stmt && (flags & TDF_STMTADDR))
605 pp_printf (buffer, "<&%p> ", (void *)node);
607 if ((flags & TDF_LINENO) && EXPR_HAS_LOCATION (node))
608 dump_location (buffer, EXPR_LOCATION (node));
610 switch (TREE_CODE (node))
612 case ERROR_MARK:
613 pp_string (buffer, "<<< error >>>");
614 break;
616 case IDENTIFIER_NODE:
617 pp_tree_identifier (buffer, node);
618 break;
620 case TREE_LIST:
621 while (node && node != error_mark_node)
623 if (TREE_PURPOSE (node))
625 dump_generic_node (buffer, TREE_PURPOSE (node), spc, flags, false);
626 pp_space (buffer);
628 dump_generic_node (buffer, TREE_VALUE (node), spc, flags, false);
629 node = TREE_CHAIN (node);
630 if (node && TREE_CODE (node) == TREE_LIST)
632 pp_character (buffer, ',');
633 pp_space (buffer);
636 break;
638 case TREE_BINFO:
639 dump_generic_node (buffer, BINFO_TYPE (node), spc, flags, false);
640 break;
642 case TREE_VEC:
644 size_t i;
645 if (TREE_VEC_LENGTH (node) > 0)
647 size_t len = TREE_VEC_LENGTH (node);
648 for (i = 0; i < len - 1; i++)
650 dump_generic_node (buffer, TREE_VEC_ELT (node, i), spc, flags,
651 false);
652 pp_character (buffer, ',');
653 pp_space (buffer);
655 dump_generic_node (buffer, TREE_VEC_ELT (node, len - 1), spc,
656 flags, false);
659 break;
661 case VOID_TYPE:
662 case INTEGER_TYPE:
663 case REAL_TYPE:
664 case FIXED_POINT_TYPE:
665 case COMPLEX_TYPE:
666 case VECTOR_TYPE:
667 case ENUMERAL_TYPE:
668 case BOOLEAN_TYPE:
670 unsigned int quals = TYPE_QUALS (node);
671 enum tree_code_class tclass;
673 if (quals & TYPE_QUAL_CONST)
674 pp_string (buffer, "const ");
675 else if (quals & TYPE_QUAL_VOLATILE)
676 pp_string (buffer, "volatile ");
677 else if (quals & TYPE_QUAL_RESTRICT)
678 pp_string (buffer, "restrict ");
680 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (node)))
682 pp_string (buffer, "<address-space-");
683 pp_decimal_int (buffer, TYPE_ADDR_SPACE (node));
684 pp_string (buffer, "> ");
687 tclass = TREE_CODE_CLASS (TREE_CODE (node));
689 if (tclass == tcc_declaration)
691 if (DECL_NAME (node))
692 dump_decl_name (buffer, node, flags);
693 else
694 pp_string (buffer, "<unnamed type decl>");
696 else if (tclass == tcc_type)
698 if (TYPE_NAME (node))
700 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
701 pp_tree_identifier (buffer, TYPE_NAME (node));
702 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
703 && DECL_NAME (TYPE_NAME (node)))
704 dump_decl_name (buffer, TYPE_NAME (node), flags);
705 else
706 pp_string (buffer, "<unnamed type>");
708 else if (TREE_CODE (node) == VECTOR_TYPE)
710 pp_string (buffer, "vector");
711 pp_character (buffer, '(');
712 pp_wide_integer (buffer, TYPE_VECTOR_SUBPARTS (node));
713 pp_string (buffer, ") ");
714 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
716 else if (TREE_CODE (node) == INTEGER_TYPE)
718 pp_string (buffer, (TYPE_UNSIGNED (node)
719 ? "<unnamed-unsigned:"
720 : "<unnamed-signed:"));
721 pp_decimal_int (buffer, TYPE_PRECISION (node));
722 pp_string (buffer, ">");
724 else if (TREE_CODE (node) == COMPLEX_TYPE)
726 pp_string (buffer, "__complex__ ");
727 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
729 else if (TREE_CODE (node) == REAL_TYPE)
731 pp_string (buffer, "<float:");
732 pp_decimal_int (buffer, TYPE_PRECISION (node));
733 pp_string (buffer, ">");
735 else if (TREE_CODE (node) == FIXED_POINT_TYPE)
737 pp_string (buffer, "<fixed-point-");
738 pp_string (buffer, TYPE_SATURATING (node) ? "sat:" : "nonsat:");
739 pp_decimal_int (buffer, TYPE_PRECISION (node));
740 pp_string (buffer, ">");
742 else if (TREE_CODE (node) == VOID_TYPE)
743 pp_string (buffer, "void");
744 else
745 pp_string (buffer, "<unnamed type>");
747 break;
750 case POINTER_TYPE:
751 case REFERENCE_TYPE:
752 str = (TREE_CODE (node) == POINTER_TYPE ? "*" : "&");
754 if (TREE_TYPE (node) == NULL)
756 pp_string (buffer, str);
757 pp_string (buffer, "<null type>");
759 else if (TREE_CODE (TREE_TYPE (node)) == FUNCTION_TYPE)
761 tree fnode = TREE_TYPE (node);
763 dump_generic_node (buffer, TREE_TYPE (fnode), spc, flags, false);
764 pp_space (buffer);
765 pp_character (buffer, '(');
766 pp_string (buffer, str);
767 if (TYPE_NAME (node) && DECL_NAME (TYPE_NAME (node)))
768 dump_decl_name (buffer, TYPE_NAME (node), flags);
769 else if (flags & TDF_NOUID)
770 pp_printf (buffer, "<Txxxx>");
771 else
772 pp_printf (buffer, "<T%x>", TYPE_UID (node));
774 pp_character (buffer, ')');
775 dump_function_declaration (buffer, fnode, spc, flags);
777 else
779 unsigned int quals = TYPE_QUALS (node);
781 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
782 pp_space (buffer);
783 pp_string (buffer, str);
785 if (quals & TYPE_QUAL_CONST)
786 pp_string (buffer, " const");
787 if (quals & TYPE_QUAL_VOLATILE)
788 pp_string (buffer, " volatile");
789 if (quals & TYPE_QUAL_RESTRICT)
790 pp_string (buffer, " restrict");
792 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (node)))
794 pp_string (buffer, " <address-space-");
795 pp_decimal_int (buffer, TYPE_ADDR_SPACE (node));
796 pp_string (buffer, ">");
799 if (TYPE_REF_CAN_ALIAS_ALL (node))
800 pp_string (buffer, " {ref-all}");
802 break;
804 case OFFSET_TYPE:
805 NIY;
806 break;
808 case MEM_REF:
810 if (integer_zerop (TREE_OPERAND (node, 1))
811 /* Dump the types of INTEGER_CSTs explicitly, for we can't
812 infer them and MEM_ATTR caching will share MEM_REFs
813 with differently-typed op0s. */
814 && TREE_CODE (TREE_OPERAND (node, 0)) != INTEGER_CST
815 /* Same pointer types, but ignoring POINTER_TYPE vs.
816 REFERENCE_TYPE. */
817 && (TREE_TYPE (TREE_TYPE (TREE_OPERAND (node, 0)))
818 == TREE_TYPE (TREE_TYPE (TREE_OPERAND (node, 1))))
819 && (TYPE_MODE (TREE_TYPE (TREE_OPERAND (node, 0)))
820 == TYPE_MODE (TREE_TYPE (TREE_OPERAND (node, 1))))
821 && (TYPE_REF_CAN_ALIAS_ALL (TREE_TYPE (TREE_OPERAND (node, 0)))
822 == TYPE_REF_CAN_ALIAS_ALL (TREE_TYPE (TREE_OPERAND (node, 1))))
823 /* Same value types ignoring qualifiers. */
824 && (TYPE_MAIN_VARIANT (TREE_TYPE (node))
825 == TYPE_MAIN_VARIANT
826 (TREE_TYPE (TREE_TYPE (TREE_OPERAND (node, 1))))))
828 if (TREE_CODE (TREE_OPERAND (node, 0)) != ADDR_EXPR)
830 pp_string (buffer, "*");
831 dump_generic_node (buffer, TREE_OPERAND (node, 0),
832 spc, flags, false);
834 else
835 dump_generic_node (buffer,
836 TREE_OPERAND (TREE_OPERAND (node, 0), 0),
837 spc, flags, false);
839 else
841 tree ptype;
843 pp_string (buffer, "MEM[");
844 pp_string (buffer, "(");
845 ptype = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (node, 1)));
846 dump_generic_node (buffer, ptype,
847 spc, flags | TDF_SLIM, false);
848 pp_string (buffer, ")");
849 dump_generic_node (buffer, TREE_OPERAND (node, 0),
850 spc, flags, false);
851 if (!integer_zerop (TREE_OPERAND (node, 1)))
853 pp_string (buffer, " + ");
854 dump_generic_node (buffer, TREE_OPERAND (node, 1),
855 spc, flags, false);
857 pp_string (buffer, "]");
859 break;
862 case TARGET_MEM_REF:
864 const char *sep = "";
865 tree tmp;
867 pp_string (buffer, "MEM[");
869 if (TREE_CODE (TMR_BASE (node)) == ADDR_EXPR)
871 pp_string (buffer, sep);
872 sep = ", ";
873 pp_string (buffer, "symbol: ");
874 dump_generic_node (buffer, TREE_OPERAND (TMR_BASE (node), 0),
875 spc, flags, false);
877 else
879 pp_string (buffer, sep);
880 sep = ", ";
881 pp_string (buffer, "base: ");
882 dump_generic_node (buffer, TMR_BASE (node), spc, flags, false);
884 tmp = TMR_INDEX2 (node);
885 if (tmp)
887 pp_string (buffer, sep);
888 sep = ", ";
889 pp_string (buffer, "base: ");
890 dump_generic_node (buffer, tmp, spc, flags, false);
892 tmp = TMR_INDEX (node);
893 if (tmp)
895 pp_string (buffer, sep);
896 sep = ", ";
897 pp_string (buffer, "index: ");
898 dump_generic_node (buffer, tmp, spc, flags, false);
900 tmp = TMR_STEP (node);
901 if (tmp)
903 pp_string (buffer, sep);
904 sep = ", ";
905 pp_string (buffer, "step: ");
906 dump_generic_node (buffer, tmp, spc, flags, false);
908 tmp = TMR_OFFSET (node);
909 if (tmp)
911 pp_string (buffer, sep);
912 sep = ", ";
913 pp_string (buffer, "offset: ");
914 dump_generic_node (buffer, tmp, spc, flags, false);
916 pp_string (buffer, "]");
918 break;
920 case ARRAY_TYPE:
922 tree tmp;
924 /* Print the innermost component type. */
925 for (tmp = TREE_TYPE (node); TREE_CODE (tmp) == ARRAY_TYPE;
926 tmp = TREE_TYPE (tmp))
928 dump_generic_node (buffer, tmp, spc, flags, false);
930 /* Print the dimensions. */
931 for (tmp = node; TREE_CODE (tmp) == ARRAY_TYPE; tmp = TREE_TYPE (tmp))
932 dump_array_domain (buffer, TYPE_DOMAIN (tmp), spc, flags);
933 break;
936 case RECORD_TYPE:
937 case UNION_TYPE:
938 case QUAL_UNION_TYPE:
940 unsigned int quals = TYPE_QUALS (node);
942 if (quals & TYPE_QUAL_CONST)
943 pp_string (buffer, "const ");
944 if (quals & TYPE_QUAL_VOLATILE)
945 pp_string (buffer, "volatile ");
947 /* Print the name of the structure. */
948 if (TREE_CODE (node) == RECORD_TYPE)
949 pp_string (buffer, "struct ");
950 else if (TREE_CODE (node) == UNION_TYPE)
951 pp_string (buffer, "union ");
953 if (TYPE_NAME (node))
954 dump_generic_node (buffer, TYPE_NAME (node), spc, flags, false);
955 else if (!(flags & TDF_SLIM))
956 /* FIXME: If we eliminate the 'else' above and attempt
957 to show the fields for named types, we may get stuck
958 following a cycle of pointers to structs. The alleged
959 self-reference check in print_struct_decl will not detect
960 cycles involving more than one pointer or struct type. */
961 print_struct_decl (buffer, node, spc, flags);
962 break;
965 case LANG_TYPE:
966 NIY;
967 break;
969 case INTEGER_CST:
970 if (TREE_CODE (TREE_TYPE (node)) == POINTER_TYPE)
972 /* In the case of a pointer, one may want to divide by the
973 size of the pointed-to type. Unfortunately, this not
974 straightforward. The C front-end maps expressions
976 (int *) 5
977 int *p; (p + 5)
979 in such a way that the two INTEGER_CST nodes for "5" have
980 different values but identical types. In the latter
981 case, the 5 is multiplied by sizeof (int) in c-common.c
982 (pointer_int_sum) to convert it to a byte address, and
983 yet the type of the node is left unchanged. Argh. What
984 is consistent though is that the number value corresponds
985 to bytes (UNITS) offset.
987 NB: Neither of the following divisors can be trivially
988 used to recover the original literal:
990 TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (node)))
991 TYPE_PRECISION (TREE_TYPE (TREE_TYPE (node))) */
992 pp_wide_integer (buffer, TREE_INT_CST_LOW (node));
993 pp_string (buffer, "B"); /* pseudo-unit */
995 else if (! host_integerp (node, 0))
997 tree val = node;
998 unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (val);
999 HOST_WIDE_INT high = TREE_INT_CST_HIGH (val);
1001 if (tree_int_cst_sgn (val) < 0)
1003 pp_character (buffer, '-');
1004 high = ~high + !low;
1005 low = -low;
1007 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
1008 systems? */
1009 sprintf (pp_buffer (buffer)->digit_buffer,
1010 HOST_WIDE_INT_PRINT_DOUBLE_HEX,
1011 (unsigned HOST_WIDE_INT) high, low);
1012 pp_string (buffer, pp_buffer (buffer)->digit_buffer);
1014 else
1015 pp_wide_integer (buffer, TREE_INT_CST_LOW (node));
1016 break;
1018 case REAL_CST:
1019 /* Code copied from print_node. */
1021 REAL_VALUE_TYPE d;
1022 if (TREE_OVERFLOW (node))
1023 pp_string (buffer, " overflow");
1025 #if !defined(REAL_IS_NOT_DOUBLE) || defined(REAL_ARITHMETIC)
1026 d = TREE_REAL_CST (node);
1027 if (REAL_VALUE_ISINF (d))
1028 pp_string (buffer, REAL_VALUE_NEGATIVE (d) ? " -Inf" : " Inf");
1029 else if (REAL_VALUE_ISNAN (d))
1030 pp_string (buffer, " Nan");
1031 else
1033 char string[100];
1034 real_to_decimal (string, &d, sizeof (string), 0, 1);
1035 pp_string (buffer, string);
1037 #else
1039 HOST_WIDE_INT i;
1040 unsigned char *p = (unsigned char *) &TREE_REAL_CST (node);
1041 pp_string (buffer, "0x");
1042 for (i = 0; i < sizeof TREE_REAL_CST (node); i++)
1043 output_formatted_integer (buffer, "%02x", *p++);
1045 #endif
1046 break;
1049 case FIXED_CST:
1051 char string[100];
1052 fixed_to_decimal (string, TREE_FIXED_CST_PTR (node), sizeof (string));
1053 pp_string (buffer, string);
1054 break;
1057 case COMPLEX_CST:
1058 pp_string (buffer, "__complex__ (");
1059 dump_generic_node (buffer, TREE_REALPART (node), spc, flags, false);
1060 pp_string (buffer, ", ");
1061 dump_generic_node (buffer, TREE_IMAGPART (node), spc, flags, false);
1062 pp_string (buffer, ")");
1063 break;
1065 case STRING_CST:
1066 pp_string (buffer, "\"");
1067 pretty_print_string (buffer, TREE_STRING_POINTER (node));
1068 pp_string (buffer, "\"");
1069 break;
1071 case VECTOR_CST:
1073 tree elt;
1074 pp_string (buffer, "{ ");
1075 for (elt = TREE_VECTOR_CST_ELTS (node); elt; elt = TREE_CHAIN (elt))
1077 dump_generic_node (buffer, TREE_VALUE (elt), spc, flags, false);
1078 if (TREE_CHAIN (elt))
1079 pp_string (buffer, ", ");
1081 pp_string (buffer, " }");
1083 break;
1085 case FUNCTION_TYPE:
1086 case METHOD_TYPE:
1087 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
1088 pp_space (buffer);
1089 if (TREE_CODE (node) == METHOD_TYPE)
1091 if (TYPE_METHOD_BASETYPE (node))
1092 dump_decl_name (buffer, TYPE_NAME (TYPE_METHOD_BASETYPE (node)),
1093 flags);
1094 else
1095 pp_string (buffer, "<null method basetype>");
1096 pp_string (buffer, "::");
1098 if (TYPE_NAME (node) && DECL_NAME (TYPE_NAME (node)))
1099 dump_decl_name (buffer, TYPE_NAME (node), flags);
1100 else if (flags & TDF_NOUID)
1101 pp_printf (buffer, "<Txxxx>");
1102 else
1103 pp_printf (buffer, "<T%x>", TYPE_UID (node));
1104 dump_function_declaration (buffer, node, spc, flags);
1105 break;
1107 case FUNCTION_DECL:
1108 case CONST_DECL:
1109 dump_decl_name (buffer, node, flags);
1110 break;
1112 case LABEL_DECL:
1113 if (DECL_NAME (node))
1114 dump_decl_name (buffer, node, flags);
1115 else if (LABEL_DECL_UID (node) != -1)
1116 pp_printf (buffer, "<L%d>", (int) LABEL_DECL_UID (node));
1117 else
1119 if (flags & TDF_NOUID)
1120 pp_string (buffer, "<D.xxxx>");
1121 else
1122 pp_printf (buffer, "<D.%u>", DECL_UID (node));
1124 break;
1126 case TYPE_DECL:
1127 if (DECL_IS_BUILTIN (node))
1129 /* Don't print the declaration of built-in types. */
1130 break;
1132 if (DECL_NAME (node))
1133 dump_decl_name (buffer, node, flags);
1134 else if (TYPE_NAME (TREE_TYPE (node)) != node)
1136 if ((TREE_CODE (TREE_TYPE (node)) == RECORD_TYPE
1137 || TREE_CODE (TREE_TYPE (node)) == UNION_TYPE)
1138 && TYPE_METHODS (TREE_TYPE (node)))
1140 /* The type is a c++ class: all structures have at least
1141 4 methods. */
1142 pp_string (buffer, "class ");
1143 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
1145 else
1147 pp_string (buffer,
1148 (TREE_CODE (TREE_TYPE (node)) == UNION_TYPE
1149 ? "union" : "struct "));
1150 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
1153 else
1154 pp_string (buffer, "<anon>");
1155 break;
1157 case VAR_DECL:
1158 case PARM_DECL:
1159 case FIELD_DECL:
1160 case DEBUG_EXPR_DECL:
1161 case NAMESPACE_DECL:
1162 dump_decl_name (buffer, node, flags);
1163 break;
1165 case RESULT_DECL:
1166 pp_string (buffer, "<retval>");
1167 break;
1169 case COMPONENT_REF:
1170 op0 = TREE_OPERAND (node, 0);
1171 str = ".";
1172 if (op0
1173 && (TREE_CODE (op0) == INDIRECT_REF
1174 || (TREE_CODE (op0) == MEM_REF
1175 && TREE_CODE (TREE_OPERAND (op0, 0)) != ADDR_EXPR
1176 && integer_zerop (TREE_OPERAND (op0, 1))
1177 /* Dump the types of INTEGER_CSTs explicitly, for we
1178 can't infer them and MEM_ATTR caching will share
1179 MEM_REFs with differently-typed op0s. */
1180 && TREE_CODE (TREE_OPERAND (op0, 0)) != INTEGER_CST
1181 /* Same pointer types, but ignoring POINTER_TYPE vs.
1182 REFERENCE_TYPE. */
1183 && (TREE_TYPE (TREE_TYPE (TREE_OPERAND (op0, 0)))
1184 == TREE_TYPE (TREE_TYPE (TREE_OPERAND (op0, 1))))
1185 && (TYPE_MODE (TREE_TYPE (TREE_OPERAND (op0, 0)))
1186 == TYPE_MODE (TREE_TYPE (TREE_OPERAND (op0, 1))))
1187 && (TYPE_REF_CAN_ALIAS_ALL (TREE_TYPE (TREE_OPERAND (op0, 0)))
1188 == TYPE_REF_CAN_ALIAS_ALL (TREE_TYPE (TREE_OPERAND (op0, 1))))
1189 /* Same value types ignoring qualifiers. */
1190 && (TYPE_MAIN_VARIANT (TREE_TYPE (op0))
1191 == TYPE_MAIN_VARIANT
1192 (TREE_TYPE (TREE_TYPE (TREE_OPERAND (op0, 1))))))))
1194 op0 = TREE_OPERAND (op0, 0);
1195 str = "->";
1197 if (op_prio (op0) < op_prio (node))
1198 pp_character (buffer, '(');
1199 dump_generic_node (buffer, op0, spc, flags, false);
1200 if (op_prio (op0) < op_prio (node))
1201 pp_character (buffer, ')');
1202 pp_string (buffer, str);
1203 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1204 op0 = component_ref_field_offset (node);
1205 if (op0 && TREE_CODE (op0) != INTEGER_CST)
1207 pp_string (buffer, "{off: ");
1208 dump_generic_node (buffer, op0, spc, flags, false);
1209 pp_character (buffer, '}');
1211 break;
1213 case BIT_FIELD_REF:
1214 pp_string (buffer, "BIT_FIELD_REF <");
1215 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1216 pp_string (buffer, ", ");
1217 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1218 pp_string (buffer, ", ");
1219 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
1220 pp_string (buffer, ">");
1221 break;
1223 case ARRAY_REF:
1224 case ARRAY_RANGE_REF:
1225 op0 = TREE_OPERAND (node, 0);
1226 if (op_prio (op0) < op_prio (node))
1227 pp_character (buffer, '(');
1228 dump_generic_node (buffer, op0, spc, flags, false);
1229 if (op_prio (op0) < op_prio (node))
1230 pp_character (buffer, ')');
1231 pp_character (buffer, '[');
1232 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1233 if (TREE_CODE (node) == ARRAY_RANGE_REF)
1234 pp_string (buffer, " ...");
1235 pp_character (buffer, ']');
1237 op0 = array_ref_low_bound (node);
1238 op1 = array_ref_element_size (node);
1240 if (!integer_zerop (op0)
1241 || TREE_OPERAND (node, 2)
1242 || TREE_OPERAND (node, 3))
1244 pp_string (buffer, "{lb: ");
1245 dump_generic_node (buffer, op0, spc, flags, false);
1246 pp_string (buffer, " sz: ");
1247 dump_generic_node (buffer, op1, spc, flags, false);
1248 pp_character (buffer, '}');
1250 break;
1252 case CONSTRUCTOR:
1254 unsigned HOST_WIDE_INT ix;
1255 tree field, val;
1256 bool is_struct_init = FALSE;
1257 pp_character (buffer, '{');
1258 if (TREE_CODE (TREE_TYPE (node)) == RECORD_TYPE
1259 || TREE_CODE (TREE_TYPE (node)) == UNION_TYPE)
1260 is_struct_init = TRUE;
1261 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (node), ix, field, val)
1263 if (field && is_struct_init)
1265 pp_character (buffer, '.');
1266 dump_generic_node (buffer, field, spc, flags, false);
1267 pp_string (buffer, "=");
1269 if (val && TREE_CODE (val) == ADDR_EXPR)
1270 if (TREE_CODE (TREE_OPERAND (val, 0)) == FUNCTION_DECL)
1271 val = TREE_OPERAND (val, 0);
1272 if (val && TREE_CODE (val) == FUNCTION_DECL)
1273 dump_decl_name (buffer, val, flags);
1274 else
1275 dump_generic_node (buffer, val, spc, flags, false);
1276 if (ix != VEC_length (constructor_elt, CONSTRUCTOR_ELTS (node)) - 1)
1278 pp_character (buffer, ',');
1279 pp_space (buffer);
1282 pp_character (buffer, '}');
1284 break;
1286 case COMPOUND_EXPR:
1288 tree *tp;
1289 if (flags & TDF_SLIM)
1291 pp_string (buffer, "<COMPOUND_EXPR>");
1292 break;
1295 dump_generic_node (buffer, TREE_OPERAND (node, 0),
1296 spc, flags, !(flags & TDF_SLIM));
1297 if (flags & TDF_SLIM)
1298 newline_and_indent (buffer, spc);
1299 else
1301 pp_character (buffer, ',');
1302 pp_space (buffer);
1305 for (tp = &TREE_OPERAND (node, 1);
1306 TREE_CODE (*tp) == COMPOUND_EXPR;
1307 tp = &TREE_OPERAND (*tp, 1))
1309 dump_generic_node (buffer, TREE_OPERAND (*tp, 0),
1310 spc, flags, !(flags & TDF_SLIM));
1311 if (flags & TDF_SLIM)
1312 newline_and_indent (buffer, spc);
1313 else
1315 pp_character (buffer, ',');
1316 pp_space (buffer);
1320 dump_generic_node (buffer, *tp, spc, flags, !(flags & TDF_SLIM));
1322 break;
1324 case STATEMENT_LIST:
1326 tree_stmt_iterator si;
1327 bool first = true;
1329 if (flags & TDF_SLIM)
1331 pp_string (buffer, "<STATEMENT_LIST>");
1332 break;
1335 for (si = tsi_start (node); !tsi_end_p (si); tsi_next (&si))
1337 if (!first)
1338 newline_and_indent (buffer, spc);
1339 else
1340 first = false;
1341 dump_generic_node (buffer, tsi_stmt (si), spc, flags, true);
1344 break;
1346 case MODIFY_EXPR:
1347 case INIT_EXPR:
1348 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags,
1349 false);
1350 pp_space (buffer);
1351 pp_character (buffer, '=');
1352 if (TREE_CODE (node) == MODIFY_EXPR
1353 && MOVE_NONTEMPORAL (node))
1354 pp_string (buffer, "{nt}");
1355 pp_space (buffer);
1356 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags,
1357 false);
1358 break;
1360 case TARGET_EXPR:
1361 pp_string (buffer, "TARGET_EXPR <");
1362 dump_generic_node (buffer, TARGET_EXPR_SLOT (node), spc, flags, false);
1363 pp_character (buffer, ',');
1364 pp_space (buffer);
1365 dump_generic_node (buffer, TARGET_EXPR_INITIAL (node), spc, flags, false);
1366 pp_character (buffer, '>');
1367 break;
1369 case DECL_EXPR:
1370 print_declaration (buffer, DECL_EXPR_DECL (node), spc, flags);
1371 is_stmt = false;
1372 break;
1374 case COND_EXPR:
1375 if (TREE_TYPE (node) == NULL || TREE_TYPE (node) == void_type_node)
1377 pp_string (buffer, "if (");
1378 dump_generic_node (buffer, COND_EXPR_COND (node), spc, flags, false);
1379 pp_character (buffer, ')');
1380 /* The lowered cond_exprs should always be printed in full. */
1381 if (COND_EXPR_THEN (node)
1382 && (IS_EMPTY_STMT (COND_EXPR_THEN (node))
1383 || TREE_CODE (COND_EXPR_THEN (node)) == GOTO_EXPR)
1384 && COND_EXPR_ELSE (node)
1385 && (IS_EMPTY_STMT (COND_EXPR_ELSE (node))
1386 || TREE_CODE (COND_EXPR_ELSE (node)) == GOTO_EXPR))
1388 pp_space (buffer);
1389 dump_generic_node (buffer, COND_EXPR_THEN (node),
1390 0, flags, true);
1391 if (!IS_EMPTY_STMT (COND_EXPR_ELSE (node)))
1393 pp_string (buffer, " else ");
1394 dump_generic_node (buffer, COND_EXPR_ELSE (node),
1395 0, flags, true);
1398 else if (!(flags & TDF_SLIM))
1400 /* Output COND_EXPR_THEN. */
1401 if (COND_EXPR_THEN (node))
1403 newline_and_indent (buffer, spc+2);
1404 pp_character (buffer, '{');
1405 newline_and_indent (buffer, spc+4);
1406 dump_generic_node (buffer, COND_EXPR_THEN (node), spc+4,
1407 flags, true);
1408 newline_and_indent (buffer, spc+2);
1409 pp_character (buffer, '}');
1412 /* Output COND_EXPR_ELSE. */
1413 if (COND_EXPR_ELSE (node)
1414 && !IS_EMPTY_STMT (COND_EXPR_ELSE (node)))
1416 newline_and_indent (buffer, spc);
1417 pp_string (buffer, "else");
1418 newline_and_indent (buffer, spc+2);
1419 pp_character (buffer, '{');
1420 newline_and_indent (buffer, spc+4);
1421 dump_generic_node (buffer, COND_EXPR_ELSE (node), spc+4,
1422 flags, true);
1423 newline_and_indent (buffer, spc+2);
1424 pp_character (buffer, '}');
1427 is_expr = false;
1429 else
1431 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1432 pp_space (buffer);
1433 pp_character (buffer, '?');
1434 pp_space (buffer);
1435 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1436 pp_space (buffer);
1437 pp_character (buffer, ':');
1438 pp_space (buffer);
1439 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
1441 break;
1443 case BIND_EXPR:
1444 pp_character (buffer, '{');
1445 if (!(flags & TDF_SLIM))
1447 if (BIND_EXPR_VARS (node))
1449 pp_newline (buffer);
1451 for (op0 = BIND_EXPR_VARS (node); op0; op0 = DECL_CHAIN (op0))
1453 print_declaration (buffer, op0, spc+2, flags);
1454 pp_newline (buffer);
1458 newline_and_indent (buffer, spc+2);
1459 dump_generic_node (buffer, BIND_EXPR_BODY (node), spc+2, flags, true);
1460 newline_and_indent (buffer, spc);
1461 pp_character (buffer, '}');
1463 is_expr = false;
1464 break;
1466 case CALL_EXPR:
1467 print_call_name (buffer, CALL_EXPR_FN (node), flags);
1469 /* Print parameters. */
1470 pp_space (buffer);
1471 pp_character (buffer, '(');
1473 tree arg;
1474 call_expr_arg_iterator iter;
1475 FOR_EACH_CALL_EXPR_ARG (arg, iter, node)
1477 dump_generic_node (buffer, arg, spc, flags, false);
1478 if (more_call_expr_args_p (&iter))
1480 pp_character (buffer, ',');
1481 pp_space (buffer);
1485 if (CALL_EXPR_VA_ARG_PACK (node))
1487 if (call_expr_nargs (node) > 0)
1489 pp_character (buffer, ',');
1490 pp_space (buffer);
1492 pp_string (buffer, "__builtin_va_arg_pack ()");
1494 pp_character (buffer, ')');
1496 op1 = CALL_EXPR_STATIC_CHAIN (node);
1497 if (op1)
1499 pp_string (buffer, " [static-chain: ");
1500 dump_generic_node (buffer, op1, spc, flags, false);
1501 pp_character (buffer, ']');
1504 if (CALL_EXPR_RETURN_SLOT_OPT (node))
1505 pp_string (buffer, " [return slot optimization]");
1506 if (CALL_EXPR_TAILCALL (node))
1507 pp_string (buffer, " [tail call]");
1508 break;
1510 case WITH_CLEANUP_EXPR:
1511 NIY;
1512 break;
1514 case CLEANUP_POINT_EXPR:
1515 pp_string (buffer, "<<cleanup_point ");
1516 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1517 pp_string (buffer, ">>");
1518 break;
1520 case PLACEHOLDER_EXPR:
1521 pp_string (buffer, "<PLACEHOLDER_EXPR ");
1522 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
1523 pp_character (buffer, '>');
1524 break;
1526 /* Binary arithmetic and logic expressions. */
1527 case WIDEN_SUM_EXPR:
1528 case WIDEN_MULT_EXPR:
1529 case MULT_EXPR:
1530 case PLUS_EXPR:
1531 case POINTER_PLUS_EXPR:
1532 case MINUS_EXPR:
1533 case TRUNC_DIV_EXPR:
1534 case CEIL_DIV_EXPR:
1535 case FLOOR_DIV_EXPR:
1536 case ROUND_DIV_EXPR:
1537 case TRUNC_MOD_EXPR:
1538 case CEIL_MOD_EXPR:
1539 case FLOOR_MOD_EXPR:
1540 case ROUND_MOD_EXPR:
1541 case RDIV_EXPR:
1542 case EXACT_DIV_EXPR:
1543 case LSHIFT_EXPR:
1544 case RSHIFT_EXPR:
1545 case LROTATE_EXPR:
1546 case RROTATE_EXPR:
1547 case VEC_LSHIFT_EXPR:
1548 case VEC_RSHIFT_EXPR:
1549 case BIT_IOR_EXPR:
1550 case BIT_XOR_EXPR:
1551 case BIT_AND_EXPR:
1552 case TRUTH_ANDIF_EXPR:
1553 case TRUTH_ORIF_EXPR:
1554 case TRUTH_AND_EXPR:
1555 case TRUTH_OR_EXPR:
1556 case TRUTH_XOR_EXPR:
1557 case LT_EXPR:
1558 case LE_EXPR:
1559 case GT_EXPR:
1560 case GE_EXPR:
1561 case EQ_EXPR:
1562 case NE_EXPR:
1563 case UNLT_EXPR:
1564 case UNLE_EXPR:
1565 case UNGT_EXPR:
1566 case UNGE_EXPR:
1567 case UNEQ_EXPR:
1568 case LTGT_EXPR:
1569 case ORDERED_EXPR:
1570 case UNORDERED_EXPR:
1572 const char *op = op_symbol (node);
1573 op0 = TREE_OPERAND (node, 0);
1574 op1 = TREE_OPERAND (node, 1);
1576 /* When the operands are expressions with less priority,
1577 keep semantics of the tree representation. */
1578 if (op_prio (op0) <= op_prio (node))
1580 pp_character (buffer, '(');
1581 dump_generic_node (buffer, op0, spc, flags, false);
1582 pp_character (buffer, ')');
1584 else
1585 dump_generic_node (buffer, op0, spc, flags, false);
1587 pp_space (buffer);
1588 pp_string (buffer, op);
1589 pp_space (buffer);
1591 /* When the operands are expressions with less priority,
1592 keep semantics of the tree representation. */
1593 if (op_prio (op1) <= op_prio (node))
1595 pp_character (buffer, '(');
1596 dump_generic_node (buffer, op1, spc, flags, false);
1597 pp_character (buffer, ')');
1599 else
1600 dump_generic_node (buffer, op1, spc, flags, false);
1602 break;
1604 /* Unary arithmetic and logic expressions. */
1605 case NEGATE_EXPR:
1606 case BIT_NOT_EXPR:
1607 case TRUTH_NOT_EXPR:
1608 case ADDR_EXPR:
1609 case PREDECREMENT_EXPR:
1610 case PREINCREMENT_EXPR:
1611 case INDIRECT_REF:
1612 if (TREE_CODE (node) == ADDR_EXPR
1613 && (TREE_CODE (TREE_OPERAND (node, 0)) == STRING_CST
1614 || TREE_CODE (TREE_OPERAND (node, 0)) == FUNCTION_DECL))
1615 ; /* Do not output '&' for strings and function pointers. */
1616 else
1617 pp_string (buffer, op_symbol (node));
1619 if (op_prio (TREE_OPERAND (node, 0)) < op_prio (node))
1621 pp_character (buffer, '(');
1622 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1623 pp_character (buffer, ')');
1625 else
1626 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1627 break;
1629 case POSTDECREMENT_EXPR:
1630 case POSTINCREMENT_EXPR:
1631 if (op_prio (TREE_OPERAND (node, 0)) < op_prio (node))
1633 pp_character (buffer, '(');
1634 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1635 pp_character (buffer, ')');
1637 else
1638 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1639 pp_string (buffer, op_symbol (node));
1640 break;
1642 case MIN_EXPR:
1643 pp_string (buffer, "MIN_EXPR <");
1644 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1645 pp_string (buffer, ", ");
1646 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1647 pp_character (buffer, '>');
1648 break;
1650 case MAX_EXPR:
1651 pp_string (buffer, "MAX_EXPR <");
1652 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1653 pp_string (buffer, ", ");
1654 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1655 pp_character (buffer, '>');
1656 break;
1658 case ABS_EXPR:
1659 pp_string (buffer, "ABS_EXPR <");
1660 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1661 pp_character (buffer, '>');
1662 break;
1664 case RANGE_EXPR:
1665 NIY;
1666 break;
1668 case ADDR_SPACE_CONVERT_EXPR:
1669 case FIXED_CONVERT_EXPR:
1670 case FIX_TRUNC_EXPR:
1671 case FLOAT_EXPR:
1672 CASE_CONVERT:
1673 type = TREE_TYPE (node);
1674 op0 = TREE_OPERAND (node, 0);
1675 if (type != TREE_TYPE (op0))
1677 pp_character (buffer, '(');
1678 dump_generic_node (buffer, type, spc, flags, false);
1679 pp_string (buffer, ") ");
1681 if (op_prio (op0) < op_prio (node))
1682 pp_character (buffer, '(');
1683 dump_generic_node (buffer, op0, spc, flags, false);
1684 if (op_prio (op0) < op_prio (node))
1685 pp_character (buffer, ')');
1686 break;
1688 case VIEW_CONVERT_EXPR:
1689 pp_string (buffer, "VIEW_CONVERT_EXPR<");
1690 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
1691 pp_string (buffer, ">(");
1692 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1693 pp_character (buffer, ')');
1694 break;
1696 case PAREN_EXPR:
1697 pp_string (buffer, "((");
1698 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1699 pp_string (buffer, "))");
1700 break;
1702 case NON_LVALUE_EXPR:
1703 pp_string (buffer, "NON_LVALUE_EXPR <");
1704 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1705 pp_character (buffer, '>');
1706 break;
1708 case SAVE_EXPR:
1709 pp_string (buffer, "SAVE_EXPR <");
1710 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1711 pp_character (buffer, '>');
1712 break;
1714 case COMPLEX_EXPR:
1715 pp_string (buffer, "COMPLEX_EXPR <");
1716 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1717 pp_string (buffer, ", ");
1718 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1719 pp_string (buffer, ">");
1720 break;
1722 case CONJ_EXPR:
1723 pp_string (buffer, "CONJ_EXPR <");
1724 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1725 pp_string (buffer, ">");
1726 break;
1728 case REALPART_EXPR:
1729 pp_string (buffer, "REALPART_EXPR <");
1730 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1731 pp_string (buffer, ">");
1732 break;
1734 case IMAGPART_EXPR:
1735 pp_string (buffer, "IMAGPART_EXPR <");
1736 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1737 pp_string (buffer, ">");
1738 break;
1740 case VA_ARG_EXPR:
1741 pp_string (buffer, "VA_ARG_EXPR <");
1742 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1743 pp_string (buffer, ">");
1744 break;
1746 case TRY_FINALLY_EXPR:
1747 case TRY_CATCH_EXPR:
1748 pp_string (buffer, "try");
1749 newline_and_indent (buffer, spc+2);
1750 pp_string (buffer, "{");
1751 newline_and_indent (buffer, spc+4);
1752 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc+4, flags, true);
1753 newline_and_indent (buffer, spc+2);
1754 pp_string (buffer, "}");
1755 newline_and_indent (buffer, spc);
1756 pp_string (buffer,
1757 (TREE_CODE (node) == TRY_CATCH_EXPR) ? "catch" : "finally");
1758 newline_and_indent (buffer, spc+2);
1759 pp_string (buffer, "{");
1760 newline_and_indent (buffer, spc+4);
1761 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc+4, flags, true);
1762 newline_and_indent (buffer, spc+2);
1763 pp_string (buffer, "}");
1764 is_expr = false;
1765 break;
1767 case CATCH_EXPR:
1768 pp_string (buffer, "catch (");
1769 dump_generic_node (buffer, CATCH_TYPES (node), spc+2, flags, false);
1770 pp_string (buffer, ")");
1771 newline_and_indent (buffer, spc+2);
1772 pp_string (buffer, "{");
1773 newline_and_indent (buffer, spc+4);
1774 dump_generic_node (buffer, CATCH_BODY (node), spc+4, flags, true);
1775 newline_and_indent (buffer, spc+2);
1776 pp_string (buffer, "}");
1777 is_expr = false;
1778 break;
1780 case EH_FILTER_EXPR:
1781 pp_string (buffer, "<<<eh_filter (");
1782 dump_generic_node (buffer, EH_FILTER_TYPES (node), spc+2, flags, false);
1783 pp_string (buffer, ")>>>");
1784 newline_and_indent (buffer, spc+2);
1785 pp_string (buffer, "{");
1786 newline_and_indent (buffer, spc+4);
1787 dump_generic_node (buffer, EH_FILTER_FAILURE (node), spc+4, flags, true);
1788 newline_and_indent (buffer, spc+2);
1789 pp_string (buffer, "}");
1790 is_expr = false;
1791 break;
1793 case LABEL_EXPR:
1794 op0 = TREE_OPERAND (node, 0);
1795 /* If this is for break or continue, don't bother printing it. */
1796 if (DECL_NAME (op0))
1798 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1799 if (strcmp (name, "break") == 0
1800 || strcmp (name, "continue") == 0)
1801 break;
1803 dump_generic_node (buffer, op0, spc, flags, false);
1804 pp_character (buffer, ':');
1805 if (DECL_NONLOCAL (op0))
1806 pp_string (buffer, " [non-local]");
1807 break;
1809 case LOOP_EXPR:
1810 pp_string (buffer, "while (1)");
1811 if (!(flags & TDF_SLIM))
1813 newline_and_indent (buffer, spc+2);
1814 pp_character (buffer, '{');
1815 newline_and_indent (buffer, spc+4);
1816 dump_generic_node (buffer, LOOP_EXPR_BODY (node), spc+4, flags, true);
1817 newline_and_indent (buffer, spc+2);
1818 pp_character (buffer, '}');
1820 is_expr = false;
1821 break;
1823 case PREDICT_EXPR:
1824 pp_string (buffer, "// predicted ");
1825 if (PREDICT_EXPR_OUTCOME (node))
1826 pp_string (buffer, "likely by ");
1827 else
1828 pp_string (buffer, "unlikely by ");
1829 pp_string (buffer, predictor_name (PREDICT_EXPR_PREDICTOR (node)));
1830 pp_string (buffer, " predictor.");
1831 break;
1833 case RETURN_EXPR:
1834 pp_string (buffer, "return");
1835 op0 = TREE_OPERAND (node, 0);
1836 if (op0)
1838 pp_space (buffer);
1839 if (TREE_CODE (op0) == MODIFY_EXPR)
1840 dump_generic_node (buffer, TREE_OPERAND (op0, 1),
1841 spc, flags, false);
1842 else
1843 dump_generic_node (buffer, op0, spc, flags, false);
1845 break;
1847 case EXIT_EXPR:
1848 pp_string (buffer, "if (");
1849 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1850 pp_string (buffer, ") break");
1851 break;
1853 case SWITCH_EXPR:
1854 pp_string (buffer, "switch (");
1855 dump_generic_node (buffer, SWITCH_COND (node), spc, flags, false);
1856 pp_character (buffer, ')');
1857 if (!(flags & TDF_SLIM))
1859 newline_and_indent (buffer, spc+2);
1860 pp_character (buffer, '{');
1861 if (SWITCH_BODY (node))
1863 newline_and_indent (buffer, spc+4);
1864 dump_generic_node (buffer, SWITCH_BODY (node), spc+4, flags,
1865 true);
1867 else
1869 tree vec = SWITCH_LABELS (node);
1870 size_t i, n = TREE_VEC_LENGTH (vec);
1871 for (i = 0; i < n; ++i)
1873 tree elt = TREE_VEC_ELT (vec, i);
1874 newline_and_indent (buffer, spc+4);
1875 if (elt)
1877 dump_generic_node (buffer, elt, spc+4, flags, false);
1878 pp_string (buffer, " goto ");
1879 dump_generic_node (buffer, CASE_LABEL (elt), spc+4,
1880 flags, true);
1881 pp_semicolon (buffer);
1883 else
1884 pp_string (buffer, "case ???: goto ???;");
1887 newline_and_indent (buffer, spc+2);
1888 pp_character (buffer, '}');
1890 is_expr = false;
1891 break;
1893 case GOTO_EXPR:
1894 op0 = GOTO_DESTINATION (node);
1895 if (TREE_CODE (op0) != SSA_NAME && DECL_P (op0) && DECL_NAME (op0))
1897 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1898 if (strcmp (name, "break") == 0
1899 || strcmp (name, "continue") == 0)
1901 pp_string (buffer, name);
1902 break;
1905 pp_string (buffer, "goto ");
1906 dump_generic_node (buffer, op0, spc, flags, false);
1907 break;
1909 case ASM_EXPR:
1910 pp_string (buffer, "__asm__");
1911 if (ASM_VOLATILE_P (node))
1912 pp_string (buffer, " __volatile__");
1913 pp_character (buffer, '(');
1914 dump_generic_node (buffer, ASM_STRING (node), spc, flags, false);
1915 pp_character (buffer, ':');
1916 dump_generic_node (buffer, ASM_OUTPUTS (node), spc, flags, false);
1917 pp_character (buffer, ':');
1918 dump_generic_node (buffer, ASM_INPUTS (node), spc, flags, false);
1919 if (ASM_CLOBBERS (node))
1921 pp_character (buffer, ':');
1922 dump_generic_node (buffer, ASM_CLOBBERS (node), spc, flags, false);
1924 pp_string (buffer, ")");
1925 break;
1927 case CASE_LABEL_EXPR:
1928 if (CASE_LOW (node) && CASE_HIGH (node))
1930 pp_string (buffer, "case ");
1931 dump_generic_node (buffer, CASE_LOW (node), spc, flags, false);
1932 pp_string (buffer, " ... ");
1933 dump_generic_node (buffer, CASE_HIGH (node), spc, flags, false);
1935 else if (CASE_LOW (node))
1937 pp_string (buffer, "case ");
1938 dump_generic_node (buffer, CASE_LOW (node), spc, flags, false);
1940 else
1941 pp_string (buffer, "default");
1942 pp_character (buffer, ':');
1943 break;
1945 case OBJ_TYPE_REF:
1946 pp_string (buffer, "OBJ_TYPE_REF(");
1947 dump_generic_node (buffer, OBJ_TYPE_REF_EXPR (node), spc, flags, false);
1948 pp_character (buffer, ';');
1949 dump_generic_node (buffer, OBJ_TYPE_REF_OBJECT (node), spc, flags, false);
1950 pp_character (buffer, '-');
1951 pp_character (buffer, '>');
1952 dump_generic_node (buffer, OBJ_TYPE_REF_TOKEN (node), spc, flags, false);
1953 pp_character (buffer, ')');
1954 break;
1956 case SSA_NAME:
1957 dump_generic_node (buffer, SSA_NAME_VAR (node), spc, flags, false);
1958 pp_string (buffer, "_");
1959 pp_decimal_int (buffer, SSA_NAME_VERSION (node));
1960 if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (node))
1961 pp_string (buffer, "(ab)");
1962 else if (SSA_NAME_IS_DEFAULT_DEF (node))
1963 pp_string (buffer, "(D)");
1964 break;
1966 case WITH_SIZE_EXPR:
1967 pp_string (buffer, "WITH_SIZE_EXPR <");
1968 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1969 pp_string (buffer, ", ");
1970 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1971 pp_string (buffer, ">");
1972 break;
1974 case ASSERT_EXPR:
1975 pp_string (buffer, "ASSERT_EXPR <");
1976 dump_generic_node (buffer, ASSERT_EXPR_VAR (node), spc, flags, false);
1977 pp_string (buffer, ", ");
1978 dump_generic_node (buffer, ASSERT_EXPR_COND (node), spc, flags, false);
1979 pp_string (buffer, ">");
1980 break;
1982 case SCEV_KNOWN:
1983 pp_string (buffer, "scev_known");
1984 break;
1986 case SCEV_NOT_KNOWN:
1987 pp_string (buffer, "scev_not_known");
1988 break;
1990 case POLYNOMIAL_CHREC:
1991 pp_string (buffer, "{");
1992 dump_generic_node (buffer, CHREC_LEFT (node), spc, flags, false);
1993 pp_string (buffer, ", +, ");
1994 dump_generic_node (buffer, CHREC_RIGHT (node), spc, flags, false);
1995 pp_string (buffer, "}_");
1996 dump_generic_node (buffer, CHREC_VAR (node), spc, flags, false);
1997 is_stmt = false;
1998 break;
2000 case REALIGN_LOAD_EXPR:
2001 pp_string (buffer, "REALIGN_LOAD <");
2002 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2003 pp_string (buffer, ", ");
2004 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2005 pp_string (buffer, ", ");
2006 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
2007 pp_string (buffer, ">");
2008 break;
2010 case VEC_COND_EXPR:
2011 pp_string (buffer, " VEC_COND_EXPR < ");
2012 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2013 pp_string (buffer, " , ");
2014 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2015 pp_string (buffer, " , ");
2016 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
2017 pp_string (buffer, " > ");
2018 break;
2020 case DOT_PROD_EXPR:
2021 pp_string (buffer, " DOT_PROD_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 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
2027 pp_string (buffer, " > ");
2028 break;
2030 case WIDEN_MULT_PLUS_EXPR:
2031 pp_string (buffer, " WIDEN_MULT_PLUS_EXPR < ");
2032 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2033 pp_string (buffer, ", ");
2034 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2035 pp_string (buffer, ", ");
2036 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
2037 pp_string (buffer, " > ");
2038 break;
2040 case WIDEN_MULT_MINUS_EXPR:
2041 pp_string (buffer, " WIDEN_MULT_MINUS_EXPR < ");
2042 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2043 pp_string (buffer, ", ");
2044 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2045 pp_string (buffer, ", ");
2046 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
2047 pp_string (buffer, " > ");
2048 break;
2050 case FMA_EXPR:
2051 pp_string (buffer, " FMA_EXPR < ");
2052 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2053 pp_string (buffer, ", ");
2054 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2055 pp_string (buffer, ", ");
2056 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
2057 pp_string (buffer, " > ");
2058 break;
2060 case OMP_PARALLEL:
2061 pp_string (buffer, "#pragma omp parallel");
2062 dump_omp_clauses (buffer, OMP_PARALLEL_CLAUSES (node), spc, flags);
2064 dump_omp_body:
2065 if (!(flags & TDF_SLIM) && OMP_BODY (node))
2067 newline_and_indent (buffer, spc + 2);
2068 pp_character (buffer, '{');
2069 newline_and_indent (buffer, spc + 4);
2070 dump_generic_node (buffer, OMP_BODY (node), spc + 4, flags, false);
2071 newline_and_indent (buffer, spc + 2);
2072 pp_character (buffer, '}');
2074 is_expr = false;
2075 break;
2077 case OMP_TASK:
2078 pp_string (buffer, "#pragma omp task");
2079 dump_omp_clauses (buffer, OMP_TASK_CLAUSES (node), spc, flags);
2080 goto dump_omp_body;
2082 case OMP_FOR:
2083 pp_string (buffer, "#pragma omp for");
2084 dump_omp_clauses (buffer, OMP_FOR_CLAUSES (node), spc, flags);
2086 if (!(flags & TDF_SLIM))
2088 int i;
2090 if (OMP_FOR_PRE_BODY (node))
2092 newline_and_indent (buffer, spc + 2);
2093 pp_character (buffer, '{');
2094 spc += 4;
2095 newline_and_indent (buffer, spc);
2096 dump_generic_node (buffer, OMP_FOR_PRE_BODY (node),
2097 spc, flags, false);
2099 spc -= 2;
2100 for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (node)); i++)
2102 spc += 2;
2103 newline_and_indent (buffer, spc);
2104 pp_string (buffer, "for (");
2105 dump_generic_node (buffer, TREE_VEC_ELT (OMP_FOR_INIT (node), i),
2106 spc, flags, false);
2107 pp_string (buffer, "; ");
2108 dump_generic_node (buffer, TREE_VEC_ELT (OMP_FOR_COND (node), i),
2109 spc, flags, false);
2110 pp_string (buffer, "; ");
2111 dump_generic_node (buffer, TREE_VEC_ELT (OMP_FOR_INCR (node), i),
2112 spc, flags, false);
2113 pp_string (buffer, ")");
2115 if (OMP_FOR_BODY (node))
2117 newline_and_indent (buffer, spc + 2);
2118 pp_character (buffer, '{');
2119 newline_and_indent (buffer, spc + 4);
2120 dump_generic_node (buffer, OMP_FOR_BODY (node), spc + 4, flags,
2121 false);
2122 newline_and_indent (buffer, spc + 2);
2123 pp_character (buffer, '}');
2125 spc -= 2 * TREE_VEC_LENGTH (OMP_FOR_INIT (node)) - 2;
2126 if (OMP_FOR_PRE_BODY (node))
2128 spc -= 4;
2129 newline_and_indent (buffer, spc + 2);
2130 pp_character (buffer, '}');
2133 is_expr = false;
2134 break;
2136 case OMP_SECTIONS:
2137 pp_string (buffer, "#pragma omp sections");
2138 dump_omp_clauses (buffer, OMP_SECTIONS_CLAUSES (node), spc, flags);
2139 goto dump_omp_body;
2141 case OMP_SECTION:
2142 pp_string (buffer, "#pragma omp section");
2143 goto dump_omp_body;
2145 case OMP_MASTER:
2146 pp_string (buffer, "#pragma omp master");
2147 goto dump_omp_body;
2149 case OMP_ORDERED:
2150 pp_string (buffer, "#pragma omp ordered");
2151 goto dump_omp_body;
2153 case OMP_CRITICAL:
2154 pp_string (buffer, "#pragma omp critical");
2155 if (OMP_CRITICAL_NAME (node))
2157 pp_space (buffer);
2158 pp_character (buffer, '(');
2159 dump_generic_node (buffer, OMP_CRITICAL_NAME (node), spc,
2160 flags, false);
2161 pp_character (buffer, ')');
2163 goto dump_omp_body;
2165 case OMP_ATOMIC:
2166 pp_string (buffer, "#pragma omp atomic");
2167 newline_and_indent (buffer, spc + 2);
2168 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2169 pp_space (buffer);
2170 pp_character (buffer, '=');
2171 pp_space (buffer);
2172 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2173 break;
2175 case OMP_SINGLE:
2176 pp_string (buffer, "#pragma omp single");
2177 dump_omp_clauses (buffer, OMP_SINGLE_CLAUSES (node), spc, flags);
2178 goto dump_omp_body;
2180 case OMP_CLAUSE:
2181 dump_omp_clause (buffer, node, spc, flags);
2182 is_expr = false;
2183 break;
2185 case REDUC_MAX_EXPR:
2186 pp_string (buffer, " REDUC_MAX_EXPR < ");
2187 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2188 pp_string (buffer, " > ");
2189 break;
2191 case REDUC_MIN_EXPR:
2192 pp_string (buffer, " REDUC_MIN_EXPR < ");
2193 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2194 pp_string (buffer, " > ");
2195 break;
2197 case REDUC_PLUS_EXPR:
2198 pp_string (buffer, " REDUC_PLUS_EXPR < ");
2199 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2200 pp_string (buffer, " > ");
2201 break;
2203 case VEC_WIDEN_MULT_HI_EXPR:
2204 pp_string (buffer, " VEC_WIDEN_MULT_HI_EXPR < ");
2205 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2206 pp_string (buffer, ", ");
2207 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2208 pp_string (buffer, " > ");
2209 break;
2211 case VEC_WIDEN_MULT_LO_EXPR:
2212 pp_string (buffer, " VEC_WIDEN_MULT_LO_EXPR < ");
2213 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2214 pp_string (buffer, ", ");
2215 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2216 pp_string (buffer, " > ");
2217 break;
2219 case VEC_UNPACK_HI_EXPR:
2220 pp_string (buffer, " VEC_UNPACK_HI_EXPR < ");
2221 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2222 pp_string (buffer, " > ");
2223 break;
2225 case VEC_UNPACK_LO_EXPR:
2226 pp_string (buffer, " VEC_UNPACK_LO_EXPR < ");
2227 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2228 pp_string (buffer, " > ");
2229 break;
2231 case VEC_UNPACK_FLOAT_HI_EXPR:
2232 pp_string (buffer, " VEC_UNPACK_FLOAT_HI_EXPR < ");
2233 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2234 pp_string (buffer, " > ");
2235 break;
2237 case VEC_UNPACK_FLOAT_LO_EXPR:
2238 pp_string (buffer, " VEC_UNPACK_FLOAT_LO_EXPR < ");
2239 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2240 pp_string (buffer, " > ");
2241 break;
2243 case VEC_PACK_TRUNC_EXPR:
2244 pp_string (buffer, " VEC_PACK_TRUNC_EXPR < ");
2245 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2246 pp_string (buffer, ", ");
2247 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2248 pp_string (buffer, " > ");
2249 break;
2251 case VEC_PACK_SAT_EXPR:
2252 pp_string (buffer, " VEC_PACK_SAT_EXPR < ");
2253 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2254 pp_string (buffer, ", ");
2255 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2256 pp_string (buffer, " > ");
2257 break;
2259 case VEC_PACK_FIX_TRUNC_EXPR:
2260 pp_string (buffer, " VEC_PACK_FIX_TRUNC_EXPR < ");
2261 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2262 pp_string (buffer, ", ");
2263 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2264 pp_string (buffer, " > ");
2265 break;
2267 case BLOCK:
2268 dump_block_node (buffer, node, spc, flags);
2269 break;
2271 case VEC_EXTRACT_EVEN_EXPR:
2272 pp_string (buffer, " VEC_EXTRACT_EVEN_EXPR < ");
2273 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2274 pp_string (buffer, ", ");
2275 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2276 pp_string (buffer, " > ");
2277 break;
2279 case VEC_EXTRACT_ODD_EXPR:
2280 pp_string (buffer, " VEC_EXTRACT_ODD_EXPR < ");
2281 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2282 pp_string (buffer, ", ");
2283 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2284 pp_string (buffer, " > ");
2285 break;
2287 case VEC_INTERLEAVE_HIGH_EXPR:
2288 pp_string (buffer, " VEC_INTERLEAVE_HIGH_EXPR < ");
2289 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2290 pp_string (buffer, ", ");
2291 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2292 pp_string (buffer, " > ");
2293 break;
2295 case VEC_INTERLEAVE_LOW_EXPR:
2296 pp_string (buffer, " VEC_INTERLEAVE_LOW_EXPR < ");
2297 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2298 pp_string (buffer, ", ");
2299 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2300 pp_string (buffer, " > ");
2301 break;
2303 default:
2304 NIY;
2307 if (is_stmt && is_expr)
2308 pp_semicolon (buffer);
2310 /* If we're building a diagnostic, the formatted text will be written
2311 into BUFFER's stream by the caller; otherwise, write it now. */
2312 if (!(flags & TDF_DIAGNOSTIC))
2313 pp_write_text_to_stream (buffer);
2315 return spc;
2318 /* Print the declaration of a variable. */
2320 void
2321 print_declaration (pretty_printer *buffer, tree t, int spc, int flags)
2323 INDENT (spc);
2325 if (TREE_CODE (t) == TYPE_DECL)
2326 pp_string (buffer, "typedef ");
2328 if (CODE_CONTAINS_STRUCT (TREE_CODE (t), TS_DECL_WRTL) && DECL_REGISTER (t))
2329 pp_string (buffer, "register ");
2331 if (TREE_PUBLIC (t) && DECL_EXTERNAL (t))
2332 pp_string (buffer, "extern ");
2333 else if (TREE_STATIC (t))
2334 pp_string (buffer, "static ");
2336 /* Print the type and name. */
2337 if (TREE_TYPE (t) && TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
2339 tree tmp;
2341 /* Print array's type. */
2342 tmp = TREE_TYPE (t);
2343 while (TREE_CODE (TREE_TYPE (tmp)) == ARRAY_TYPE)
2344 tmp = TREE_TYPE (tmp);
2345 dump_generic_node (buffer, TREE_TYPE (tmp), spc, flags, false);
2347 /* Print variable's name. */
2348 pp_space (buffer);
2349 dump_generic_node (buffer, t, spc, flags, false);
2351 /* Print the dimensions. */
2352 tmp = TREE_TYPE (t);
2353 while (TREE_CODE (tmp) == ARRAY_TYPE)
2355 dump_array_domain (buffer, TYPE_DOMAIN (tmp), spc, flags);
2356 tmp = TREE_TYPE (tmp);
2359 else if (TREE_CODE (t) == FUNCTION_DECL)
2361 dump_generic_node (buffer, TREE_TYPE (TREE_TYPE (t)), spc, flags, false);
2362 pp_space (buffer);
2363 dump_decl_name (buffer, t, flags);
2364 dump_function_declaration (buffer, TREE_TYPE (t), spc, flags);
2366 else
2368 /* Print type declaration. */
2369 dump_generic_node (buffer, TREE_TYPE (t), spc, flags, false);
2371 /* Print variable's name. */
2372 pp_space (buffer);
2373 dump_generic_node (buffer, t, spc, flags, false);
2376 if (TREE_CODE (t) == VAR_DECL && DECL_HARD_REGISTER (t))
2378 pp_string (buffer, " __asm__ ");
2379 pp_character (buffer, '(');
2380 dump_generic_node (buffer, DECL_ASSEMBLER_NAME (t), spc, flags, false);
2381 pp_character (buffer, ')');
2384 /* The initial value of a function serves to determine whether the function
2385 is declared or defined. So the following does not apply to function
2386 nodes. */
2387 if (TREE_CODE (t) != FUNCTION_DECL)
2389 /* Print the initial value. */
2390 if (DECL_INITIAL (t))
2392 pp_space (buffer);
2393 pp_character (buffer, '=');
2394 pp_space (buffer);
2395 dump_generic_node (buffer, DECL_INITIAL (t), spc, flags, false);
2399 if (TREE_CODE (t) == VAR_DECL && DECL_HAS_VALUE_EXPR_P (t))
2401 pp_string (buffer, " [value-expr: ");
2402 dump_generic_node (buffer, DECL_VALUE_EXPR (t), spc, flags, false);
2403 pp_character (buffer, ']');
2406 pp_character (buffer, ';');
2410 /* Prints a structure: name, fields, and methods.
2411 FIXME: Still incomplete. */
2413 static void
2414 print_struct_decl (pretty_printer *buffer, const_tree node, int spc, int flags)
2416 /* Print the name of the structure. */
2417 if (TYPE_NAME (node))
2419 INDENT (spc);
2420 if (TREE_CODE (node) == RECORD_TYPE)
2421 pp_string (buffer, "struct ");
2422 else if ((TREE_CODE (node) == UNION_TYPE
2423 || TREE_CODE (node) == QUAL_UNION_TYPE))
2424 pp_string (buffer, "union ");
2426 dump_generic_node (buffer, TYPE_NAME (node), spc, 0, false);
2429 /* Print the contents of the structure. */
2430 pp_newline (buffer);
2431 INDENT (spc);
2432 pp_character (buffer, '{');
2433 pp_newline (buffer);
2435 /* Print the fields of the structure. */
2437 tree tmp;
2438 tmp = TYPE_FIELDS (node);
2439 while (tmp)
2441 /* Avoid to print recursively the structure. */
2442 /* FIXME : Not implemented correctly...,
2443 what about the case when we have a cycle in the contain graph? ...
2444 Maybe this could be solved by looking at the scope in which the
2445 structure was declared. */
2446 if (TREE_TYPE (tmp) != node
2447 && (TREE_CODE (TREE_TYPE (tmp)) != POINTER_TYPE
2448 || TREE_TYPE (TREE_TYPE (tmp)) != node))
2450 print_declaration (buffer, tmp, spc+2, flags);
2451 pp_newline (buffer);
2453 tmp = DECL_CHAIN (tmp);
2456 INDENT (spc);
2457 pp_character (buffer, '}');
2460 /* Return the priority of the operator CODE.
2462 From lowest to highest precedence with either left-to-right (L-R)
2463 or right-to-left (R-L) associativity]:
2465 1 [L-R] ,
2466 2 [R-L] = += -= *= /= %= &= ^= |= <<= >>=
2467 3 [R-L] ?:
2468 4 [L-R] ||
2469 5 [L-R] &&
2470 6 [L-R] |
2471 7 [L-R] ^
2472 8 [L-R] &
2473 9 [L-R] == !=
2474 10 [L-R] < <= > >=
2475 11 [L-R] << >>
2476 12 [L-R] + -
2477 13 [L-R] * / %
2478 14 [R-L] ! ~ ++ -- + - * & (type) sizeof
2479 15 [L-R] fn() [] -> .
2481 unary +, - and * have higher precedence than the corresponding binary
2482 operators. */
2485 op_code_prio (enum tree_code code)
2487 switch (code)
2489 case TREE_LIST:
2490 case COMPOUND_EXPR:
2491 case BIND_EXPR:
2492 return 1;
2494 case MODIFY_EXPR:
2495 case INIT_EXPR:
2496 return 2;
2498 case COND_EXPR:
2499 return 3;
2501 case TRUTH_OR_EXPR:
2502 case TRUTH_ORIF_EXPR:
2503 return 4;
2505 case TRUTH_AND_EXPR:
2506 case TRUTH_ANDIF_EXPR:
2507 return 5;
2509 case BIT_IOR_EXPR:
2510 return 6;
2512 case BIT_XOR_EXPR:
2513 case TRUTH_XOR_EXPR:
2514 return 7;
2516 case BIT_AND_EXPR:
2517 return 8;
2519 case EQ_EXPR:
2520 case NE_EXPR:
2521 return 9;
2523 case UNLT_EXPR:
2524 case UNLE_EXPR:
2525 case UNGT_EXPR:
2526 case UNGE_EXPR:
2527 case UNEQ_EXPR:
2528 case LTGT_EXPR:
2529 case ORDERED_EXPR:
2530 case UNORDERED_EXPR:
2531 case LT_EXPR:
2532 case LE_EXPR:
2533 case GT_EXPR:
2534 case GE_EXPR:
2535 return 10;
2537 case LSHIFT_EXPR:
2538 case RSHIFT_EXPR:
2539 case LROTATE_EXPR:
2540 case RROTATE_EXPR:
2541 return 11;
2543 case WIDEN_SUM_EXPR:
2544 case PLUS_EXPR:
2545 case POINTER_PLUS_EXPR:
2546 case MINUS_EXPR:
2547 return 12;
2549 case VEC_WIDEN_MULT_HI_EXPR:
2550 case VEC_WIDEN_MULT_LO_EXPR:
2551 case WIDEN_MULT_EXPR:
2552 case DOT_PROD_EXPR:
2553 case WIDEN_MULT_PLUS_EXPR:
2554 case WIDEN_MULT_MINUS_EXPR:
2555 case MULT_EXPR:
2556 case TRUNC_DIV_EXPR:
2557 case CEIL_DIV_EXPR:
2558 case FLOOR_DIV_EXPR:
2559 case ROUND_DIV_EXPR:
2560 case RDIV_EXPR:
2561 case EXACT_DIV_EXPR:
2562 case TRUNC_MOD_EXPR:
2563 case CEIL_MOD_EXPR:
2564 case FLOOR_MOD_EXPR:
2565 case ROUND_MOD_EXPR:
2566 case FMA_EXPR:
2567 return 13;
2569 case TRUTH_NOT_EXPR:
2570 case BIT_NOT_EXPR:
2571 case POSTINCREMENT_EXPR:
2572 case POSTDECREMENT_EXPR:
2573 case PREINCREMENT_EXPR:
2574 case PREDECREMENT_EXPR:
2575 case NEGATE_EXPR:
2576 case INDIRECT_REF:
2577 case ADDR_EXPR:
2578 case FLOAT_EXPR:
2579 CASE_CONVERT:
2580 case FIX_TRUNC_EXPR:
2581 case TARGET_EXPR:
2582 return 14;
2584 case CALL_EXPR:
2585 case ARRAY_REF:
2586 case ARRAY_RANGE_REF:
2587 case COMPONENT_REF:
2588 return 15;
2590 /* Special expressions. */
2591 case MIN_EXPR:
2592 case MAX_EXPR:
2593 case ABS_EXPR:
2594 case REALPART_EXPR:
2595 case IMAGPART_EXPR:
2596 case REDUC_MAX_EXPR:
2597 case REDUC_MIN_EXPR:
2598 case REDUC_PLUS_EXPR:
2599 case VEC_LSHIFT_EXPR:
2600 case VEC_RSHIFT_EXPR:
2601 case VEC_UNPACK_HI_EXPR:
2602 case VEC_UNPACK_LO_EXPR:
2603 case VEC_UNPACK_FLOAT_HI_EXPR:
2604 case VEC_UNPACK_FLOAT_LO_EXPR:
2605 case VEC_PACK_TRUNC_EXPR:
2606 case VEC_PACK_SAT_EXPR:
2607 return 16;
2609 default:
2610 /* Return an arbitrarily high precedence to avoid surrounding single
2611 VAR_DECLs in ()s. */
2612 return 9999;
2616 /* Return the priority of the operator OP. */
2619 op_prio (const_tree op)
2621 enum tree_code code;
2623 if (op == NULL)
2624 return 9999;
2626 code = TREE_CODE (op);
2627 if (code == SAVE_EXPR || code == NON_LVALUE_EXPR)
2628 return op_prio (TREE_OPERAND (op, 0));
2630 return op_code_prio (code);
2633 /* Return the symbol associated with operator CODE. */
2635 const char *
2636 op_symbol_code (enum tree_code code)
2638 switch (code)
2640 case MODIFY_EXPR:
2641 return "=";
2643 case TRUTH_OR_EXPR:
2644 case TRUTH_ORIF_EXPR:
2645 return "||";
2647 case TRUTH_AND_EXPR:
2648 case TRUTH_ANDIF_EXPR:
2649 return "&&";
2651 case BIT_IOR_EXPR:
2652 return "|";
2654 case TRUTH_XOR_EXPR:
2655 case BIT_XOR_EXPR:
2656 return "^";
2658 case ADDR_EXPR:
2659 case BIT_AND_EXPR:
2660 return "&";
2662 case ORDERED_EXPR:
2663 return "ord";
2664 case UNORDERED_EXPR:
2665 return "unord";
2667 case EQ_EXPR:
2668 return "==";
2669 case UNEQ_EXPR:
2670 return "u==";
2672 case NE_EXPR:
2673 return "!=";
2675 case LT_EXPR:
2676 return "<";
2677 case UNLT_EXPR:
2678 return "u<";
2680 case LE_EXPR:
2681 return "<=";
2682 case UNLE_EXPR:
2683 return "u<=";
2685 case GT_EXPR:
2686 return ">";
2687 case UNGT_EXPR:
2688 return "u>";
2690 case GE_EXPR:
2691 return ">=";
2692 case UNGE_EXPR:
2693 return "u>=";
2695 case LTGT_EXPR:
2696 return "<>";
2698 case LSHIFT_EXPR:
2699 return "<<";
2701 case RSHIFT_EXPR:
2702 return ">>";
2704 case LROTATE_EXPR:
2705 return "r<<";
2707 case RROTATE_EXPR:
2708 return "r>>";
2710 case VEC_LSHIFT_EXPR:
2711 return "v<<";
2713 case VEC_RSHIFT_EXPR:
2714 return "v>>";
2716 case POINTER_PLUS_EXPR:
2717 return "+";
2719 case PLUS_EXPR:
2720 return "+";
2722 case REDUC_PLUS_EXPR:
2723 return "r+";
2725 case WIDEN_SUM_EXPR:
2726 return "w+";
2728 case WIDEN_MULT_EXPR:
2729 return "w*";
2731 case NEGATE_EXPR:
2732 case MINUS_EXPR:
2733 return "-";
2735 case BIT_NOT_EXPR:
2736 return "~";
2738 case TRUTH_NOT_EXPR:
2739 return "!";
2741 case MULT_EXPR:
2742 case INDIRECT_REF:
2743 return "*";
2745 case TRUNC_DIV_EXPR:
2746 case RDIV_EXPR:
2747 return "/";
2749 case CEIL_DIV_EXPR:
2750 return "/[cl]";
2752 case FLOOR_DIV_EXPR:
2753 return "/[fl]";
2755 case ROUND_DIV_EXPR:
2756 return "/[rd]";
2758 case EXACT_DIV_EXPR:
2759 return "/[ex]";
2761 case TRUNC_MOD_EXPR:
2762 return "%";
2764 case CEIL_MOD_EXPR:
2765 return "%[cl]";
2767 case FLOOR_MOD_EXPR:
2768 return "%[fl]";
2770 case ROUND_MOD_EXPR:
2771 return "%[rd]";
2773 case PREDECREMENT_EXPR:
2774 return " --";
2776 case PREINCREMENT_EXPR:
2777 return " ++";
2779 case POSTDECREMENT_EXPR:
2780 return "-- ";
2782 case POSTINCREMENT_EXPR:
2783 return "++ ";
2785 case MAX_EXPR:
2786 return "max";
2788 case MIN_EXPR:
2789 return "min";
2791 default:
2792 return "<<< ??? >>>";
2796 /* Return the symbol associated with operator OP. */
2798 static const char *
2799 op_symbol (const_tree op)
2801 return op_symbol_code (TREE_CODE (op));
2804 /* Prints the name of a call. NODE is the CALL_EXPR_FN of a CALL_EXPR or
2805 the gimple_call_fn of a GIMPLE_CALL. */
2807 void
2808 print_call_name (pretty_printer *buffer, tree node, int flags)
2810 tree op0 = node;
2812 if (TREE_CODE (op0) == NON_LVALUE_EXPR)
2813 op0 = TREE_OPERAND (op0, 0);
2815 again:
2816 switch (TREE_CODE (op0))
2818 case VAR_DECL:
2819 case PARM_DECL:
2820 case FUNCTION_DECL:
2821 dump_function_name (buffer, op0, flags);
2822 break;
2824 case ADDR_EXPR:
2825 case INDIRECT_REF:
2826 case NOP_EXPR:
2827 op0 = TREE_OPERAND (op0, 0);
2828 goto again;
2830 case COND_EXPR:
2831 pp_string (buffer, "(");
2832 dump_generic_node (buffer, TREE_OPERAND (op0, 0), 0, flags, false);
2833 pp_string (buffer, ") ? ");
2834 dump_generic_node (buffer, TREE_OPERAND (op0, 1), 0, flags, false);
2835 pp_string (buffer, " : ");
2836 dump_generic_node (buffer, TREE_OPERAND (op0, 2), 0, flags, false);
2837 break;
2839 case ARRAY_REF:
2840 if (TREE_CODE (TREE_OPERAND (op0, 0)) == VAR_DECL)
2841 dump_function_name (buffer, TREE_OPERAND (op0, 0), flags);
2842 else
2843 dump_generic_node (buffer, op0, 0, flags, false);
2844 break;
2846 case MEM_REF:
2847 if (integer_zerop (TREE_OPERAND (op0, 1)))
2849 op0 = TREE_OPERAND (op0, 0);
2850 goto again;
2852 /* Fallthru. */
2853 case COMPONENT_REF:
2854 case SSA_NAME:
2855 case OBJ_TYPE_REF:
2856 dump_generic_node (buffer, op0, 0, flags, false);
2857 break;
2859 default:
2860 NIY;
2864 /* Parses the string STR and replaces new-lines by '\n', tabs by '\t', ... */
2866 static void
2867 pretty_print_string (pretty_printer *buffer, const char *str)
2869 if (str == NULL)
2870 return;
2872 while (*str)
2874 switch (str[0])
2876 case '\b':
2877 pp_string (buffer, "\\b");
2878 break;
2880 case '\f':
2881 pp_string (buffer, "\\f");
2882 break;
2884 case '\n':
2885 pp_string (buffer, "\\n");
2886 break;
2888 case '\r':
2889 pp_string (buffer, "\\r");
2890 break;
2892 case '\t':
2893 pp_string (buffer, "\\t");
2894 break;
2896 case '\v':
2897 pp_string (buffer, "\\v");
2898 break;
2900 case '\\':
2901 pp_string (buffer, "\\\\");
2902 break;
2904 case '\"':
2905 pp_string (buffer, "\\\"");
2906 break;
2908 case '\'':
2909 pp_string (buffer, "\\'");
2910 break;
2912 /* No need to handle \0; the loop terminates on \0. */
2914 case '\1':
2915 pp_string (buffer, "\\1");
2916 break;
2918 case '\2':
2919 pp_string (buffer, "\\2");
2920 break;
2922 case '\3':
2923 pp_string (buffer, "\\3");
2924 break;
2926 case '\4':
2927 pp_string (buffer, "\\4");
2928 break;
2930 case '\5':
2931 pp_string (buffer, "\\5");
2932 break;
2934 case '\6':
2935 pp_string (buffer, "\\6");
2936 break;
2938 case '\7':
2939 pp_string (buffer, "\\7");
2940 break;
2942 default:
2943 pp_character (buffer, str[0]);
2944 break;
2946 str++;
2950 static void
2951 maybe_init_pretty_print (FILE *file)
2953 if (!initialized)
2955 pp_construct (&buffer, /* prefix */NULL, /* line-width */0);
2956 pp_needs_newline (&buffer) = true;
2957 pp_translate_identifiers (&buffer) = false;
2958 initialized = 1;
2961 buffer.buffer->stream = file;
2964 static void
2965 newline_and_indent (pretty_printer *buffer, int spc)
2967 pp_newline (buffer);
2968 INDENT (spc);
2971 /* Handle a %K format for TEXT. Separate from default_tree_printer so
2972 it can also be used in front ends.
2973 %K: a statement, from which EXPR_LOCATION and TREE_BLOCK will be recorded.
2976 void
2977 percent_K_format (text_info *text)
2979 tree t = va_arg (*text->args_ptr, tree), block;
2980 gcc_assert (text->locus != NULL);
2981 *text->locus = EXPR_LOCATION (t);
2982 gcc_assert (pp_ti_abstract_origin (text) != NULL);
2983 block = TREE_BLOCK (t);
2984 *pp_ti_abstract_origin (text) = NULL;
2985 while (block
2986 && TREE_CODE (block) == BLOCK
2987 && BLOCK_ABSTRACT_ORIGIN (block))
2989 tree ao = BLOCK_ABSTRACT_ORIGIN (block);
2991 while (TREE_CODE (ao) == BLOCK
2992 && BLOCK_ABSTRACT_ORIGIN (ao)
2993 && BLOCK_ABSTRACT_ORIGIN (ao) != ao)
2994 ao = BLOCK_ABSTRACT_ORIGIN (ao);
2996 if (TREE_CODE (ao) == FUNCTION_DECL)
2998 *pp_ti_abstract_origin (text) = block;
2999 break;
3001 block = BLOCK_SUPERCONTEXT (block);
3005 /* Print the identifier ID to PRETTY-PRINTER. */
3007 void
3008 pp_base_tree_identifier (pretty_printer *pp, tree id)
3010 if (pp_translate_identifiers (pp))
3012 const char *text = identifier_to_locale (IDENTIFIER_POINTER (id));
3013 pp_append_text (pp, text, text + strlen (text));
3015 else
3016 pp_append_text (pp, IDENTIFIER_POINTER (id),
3017 IDENTIFIER_POINTER (id) + IDENTIFIER_LENGTH (id));
3020 /* A helper function that is used to dump function information before the
3021 function dump. */
3023 void
3024 dump_function_header (FILE *dump_file, tree fdecl, int flags)
3026 const char *dname, *aname;
3027 struct cgraph_node *node = cgraph_get_node (fdecl);
3028 struct function *fun = DECL_STRUCT_FUNCTION (fdecl);
3030 dname = lang_hooks.decl_printable_name (fdecl, 2);
3032 if (DECL_ASSEMBLER_NAME_SET_P (fdecl))
3033 aname = (IDENTIFIER_POINTER
3034 (DECL_ASSEMBLER_NAME (fdecl)));
3035 else
3036 aname = "<unset-asm-name>";
3038 if (L_IPO_COMP_MODE)
3039 fprintf (dump_file, "\n;; Function %s (%s, funcdef_no=%d:%d",
3040 dname, aname, FUNC_DECL_MODULE_ID (fun),
3041 FUNC_DECL_FUNC_ID (fun));
3042 else
3043 fprintf (dump_file, "\n;; Function %s (%s, funcdef_no=%d",
3044 dname, aname, fun->funcdef_no);
3045 if (!(flags & TDF_NOUID))
3046 fprintf (dump_file, ", decl_uid=%d", DECL_UID (fdecl));
3047 if (node)
3049 fprintf (dump_file, ", cgraph_uid=%d)%s\n\n", node->uid,
3050 node->frequency == NODE_FREQUENCY_HOT
3051 ? " (hot)"
3052 : node->frequency == NODE_FREQUENCY_UNLIKELY_EXECUTED
3053 ? " (unlikely executed)"
3054 : node->frequency == NODE_FREQUENCY_EXECUTED_ONCE
3055 ? " (executed once)"
3056 : "");
3058 else
3059 fprintf (dump_file, ")\n\n");