* tree-ssa-loop-manip.c (split_loop_exit_edge): Return the new block.
[official-gcc.git] / gcc / tree-pretty-print.c
blobcfaccb39047c2011968aecc3c81953c567509379
1 /* Pretty formatting of GENERIC trees in C syntax.
2 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006
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 2, 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 COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
21 02110-1301, USA. */
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "tm.h"
27 #include "tree.h"
28 #include "diagnostic.h"
29 #include "real.h"
30 #include "hashtab.h"
31 #include "tree-flow.h"
32 #include "langhooks.h"
33 #include "tree-iterator.h"
34 #include "tree-chrec.h"
35 #include "tree-pass.h"
37 /* Local functions, macros and variables. */
38 static int op_prio (tree);
39 static const char *op_symbol_1 (enum tree_code);
40 static const char *op_symbol (tree);
41 static void pretty_print_string (pretty_printer *, const char*);
42 static void print_call_name (pretty_printer *, tree);
43 static void newline_and_indent (pretty_printer *, int);
44 static void maybe_init_pretty_print (FILE *);
45 static void print_declaration (pretty_printer *, tree, int, int);
46 static void print_struct_decl (pretty_printer *, tree, int, int);
47 static void do_niy (pretty_printer *, tree);
48 static void dump_vops (pretty_printer *, tree, int, int);
49 static void dump_generic_bb_buff (pretty_printer *, basic_block, int, int);
51 #define INDENT(SPACE) do { \
52 int i; for (i = 0; i<SPACE; i++) pp_space (buffer); } while (0)
54 #define NIY do_niy(buffer,node)
56 #define PRINT_FUNCTION_NAME(NODE) pp_printf \
57 (buffer, "%s", TREE_CODE (NODE) == NOP_EXPR ? \
58 lang_hooks.decl_printable_name (TREE_OPERAND (NODE, 0), 1) : \
59 lang_hooks.decl_printable_name (NODE, 1))
61 static pretty_printer buffer;
62 static int initialized = 0;
64 /* Try to print something for an unknown tree code. */
66 static void
67 do_niy (pretty_printer *buffer, tree node)
69 int i, len;
71 pp_string (buffer, "<<< Unknown tree: ");
72 pp_string (buffer, tree_code_name[(int) TREE_CODE (node)]);
74 if (EXPR_P (node))
76 len = TREE_CODE_LENGTH (TREE_CODE (node));
77 for (i = 0; i < len; ++i)
79 newline_and_indent (buffer, 2);
80 dump_generic_node (buffer, TREE_OPERAND (node, i), 2, 0, false);
84 pp_string (buffer, " >>>\n");
87 void
88 debug_generic_expr (tree t)
90 print_generic_expr (stderr, t, TDF_VOPS|TDF_UID);
91 fprintf (stderr, "\n");
94 void
95 debug_generic_stmt (tree t)
97 print_generic_stmt (stderr, t, TDF_VOPS|TDF_UID);
98 fprintf (stderr, "\n");
101 void
102 debug_tree_chain (tree t)
104 while (t)
106 print_generic_expr (stderr, t, TDF_VOPS|TDF_UID);
107 fprintf(stderr, " ");
108 t = TREE_CHAIN (t);
110 fprintf (stderr, "\n");
113 /* Prints declaration DECL to the FILE with details specified by FLAGS. */
114 void
115 print_generic_decl (FILE *file, tree decl, int flags)
117 maybe_init_pretty_print (file);
118 print_declaration (&buffer, decl, 2, flags);
119 pp_write_text_to_stream (&buffer);
122 /* Print tree T, and its successors, on file FILE. FLAGS specifies details
123 to show in the dump. See TDF_* in tree.h. */
125 void
126 print_generic_stmt (FILE *file, tree t, int flags)
128 maybe_init_pretty_print (file);
129 dump_generic_node (&buffer, t, 0, flags, true);
130 pp_flush (&buffer);
133 /* Print tree T, and its successors, on file FILE. FLAGS specifies details
134 to show in the dump. See TDF_* in tree.h. The output is indented by
135 INDENT spaces. */
137 void
138 print_generic_stmt_indented (FILE *file, tree t, int flags, int indent)
140 int i;
142 maybe_init_pretty_print (file);
144 for (i = 0; i < indent; i++)
145 pp_space (&buffer);
146 dump_generic_node (&buffer, t, indent, flags, true);
147 pp_flush (&buffer);
150 /* Print a single expression T on file FILE. FLAGS specifies details to show
151 in the dump. See TDF_* in tree.h. */
153 void
154 print_generic_expr (FILE *file, tree t, int flags)
156 maybe_init_pretty_print (file);
157 dump_generic_node (&buffer, t, 0, flags, false);
160 /* Dump the name of a _DECL node and its DECL_UID if TDF_UID is set
161 in FLAGS. */
163 static void
164 dump_decl_name (pretty_printer *buffer, tree node, int flags)
166 tree t = node;
168 if (DECL_NAME (t))
169 pp_tree_identifier (buffer, DECL_NAME (t));
170 if ((flags & TDF_UID)
171 || DECL_NAME (t) == NULL_TREE)
173 if (TREE_CODE (t) == LABEL_DECL
174 && LABEL_DECL_UID (t) != -1)
175 pp_printf (buffer, "L." HOST_WIDE_INT_PRINT_DEC,
176 LABEL_DECL_UID (t));
177 else
179 char c = TREE_CODE (t) == CONST_DECL ? 'C' : 'D';
180 pp_printf (buffer, "%c.%u", c, DECL_UID (t));
185 /* Like the above, but used for pretty printing function calls. */
187 static void
188 dump_function_name (pretty_printer *buffer, tree node)
190 if (DECL_NAME (node))
191 PRINT_FUNCTION_NAME (node);
192 else
193 dump_decl_name (buffer, node, 0);
196 /* Dump a function declaration. NODE is the FUNCTION_TYPE. BUFFER, SPC and
197 FLAGS are as in dump_generic_node. */
199 static void
200 dump_function_declaration (pretty_printer *buffer, tree node,
201 int spc, int flags)
203 bool wrote_arg = false;
204 tree arg;
206 pp_space (buffer);
207 pp_character (buffer, '(');
209 /* Print the argument types. The last element in the list is a VOID_TYPE.
210 The following avoids printing the last element. */
211 arg = TYPE_ARG_TYPES (node);
212 while (arg && TREE_CHAIN (arg) && arg != error_mark_node)
214 wrote_arg = true;
215 dump_generic_node (buffer, TREE_VALUE (arg), spc, flags, false);
216 arg = TREE_CHAIN (arg);
217 if (TREE_CHAIN (arg) && TREE_CODE (TREE_CHAIN (arg)) == TREE_LIST)
219 pp_character (buffer, ',');
220 pp_space (buffer);
224 if (!wrote_arg)
225 pp_string (buffer, "void");
227 pp_character (buffer, ')');
230 /* Dump the domain associated with an array. */
232 static void
233 dump_array_domain (pretty_printer *buffer, tree domain, int spc, int flags)
235 pp_character (buffer, '[');
236 if (domain)
238 tree min = TYPE_MIN_VALUE (domain);
239 tree max = TYPE_MAX_VALUE (domain);
241 if (min && max
242 && integer_zerop (min)
243 && host_integerp (max, 0))
244 pp_wide_integer (buffer, TREE_INT_CST_LOW (max) + 1);
245 else
247 if (min)
248 dump_generic_node (buffer, min, spc, flags, false);
249 pp_character (buffer, ':');
250 if (max)
251 dump_generic_node (buffer, max, spc, flags, false);
254 else
255 pp_string (buffer, "<unknown>");
256 pp_character (buffer, ']');
260 /* Dump OpenMP clause CLAUSE. BUFFER, CLAUSE, SPC and FLAGS are as in
261 dump_generic_node. */
263 static void
264 dump_omp_clause (pretty_printer *buffer, tree clause, int spc, int flags)
266 const char *name;
268 switch (OMP_CLAUSE_CODE (clause))
270 case OMP_CLAUSE_PRIVATE:
271 name = "private";
272 goto print_remap;
273 case OMP_CLAUSE_SHARED:
274 name = "shared";
275 goto print_remap;
276 case OMP_CLAUSE_FIRSTPRIVATE:
277 name = "firstprivate";
278 goto print_remap;
279 case OMP_CLAUSE_LASTPRIVATE:
280 name = "lastprivate";
281 goto print_remap;
282 case OMP_CLAUSE_COPYIN:
283 name = "copyin";
284 goto print_remap;
285 case OMP_CLAUSE_COPYPRIVATE:
286 name = "copyprivate";
287 goto print_remap;
288 print_remap:
289 pp_string (buffer, name);
290 pp_character (buffer, '(');
291 dump_generic_node (buffer, OMP_CLAUSE_DECL (clause),
292 spc, flags, false);
293 pp_character (buffer, ')');
294 break;
296 case OMP_CLAUSE_REDUCTION:
297 pp_string (buffer, "reduction(");
298 pp_string (buffer, op_symbol_1 (OMP_CLAUSE_REDUCTION_CODE (clause)));
299 pp_character (buffer, ':');
300 dump_generic_node (buffer, OMP_CLAUSE_DECL (clause),
301 spc, flags, false);
302 pp_character (buffer, ')');
303 break;
305 case OMP_CLAUSE_IF:
306 pp_string (buffer, "if(");
307 dump_generic_node (buffer, OMP_CLAUSE_IF_EXPR (clause),
308 spc, flags, false);
309 pp_character (buffer, ')');
310 break;
312 case OMP_CLAUSE_NUM_THREADS:
313 pp_string (buffer, "num_threads(");
314 dump_generic_node (buffer, OMP_CLAUSE_NUM_THREADS_EXPR (clause),
315 spc, flags, false);
316 pp_character (buffer, ')');
317 break;
319 case OMP_CLAUSE_NOWAIT:
320 pp_string (buffer, "nowait");
321 break;
322 case OMP_CLAUSE_ORDERED:
323 pp_string (buffer, "ordered");
324 break;
326 case OMP_CLAUSE_DEFAULT:
327 pp_string (buffer, "default(");
328 switch (OMP_CLAUSE_DEFAULT_KIND (clause))
330 case OMP_CLAUSE_DEFAULT_UNSPECIFIED:
331 break;
332 case OMP_CLAUSE_DEFAULT_SHARED:
333 pp_string (buffer, "shared");
334 break;
335 case OMP_CLAUSE_DEFAULT_NONE:
336 pp_string (buffer, "none");
337 break;
338 case OMP_CLAUSE_DEFAULT_PRIVATE:
339 pp_string (buffer, "private");
340 break;
341 default:
342 gcc_unreachable ();
344 pp_character (buffer, ')');
345 break;
347 case OMP_CLAUSE_SCHEDULE:
348 pp_string (buffer, "schedule(");
349 switch (OMP_CLAUSE_SCHEDULE_KIND (clause))
351 case OMP_CLAUSE_SCHEDULE_STATIC:
352 pp_string (buffer, "static");
353 break;
354 case OMP_CLAUSE_SCHEDULE_DYNAMIC:
355 pp_string (buffer, "dynamic");
356 break;
357 case OMP_CLAUSE_SCHEDULE_GUIDED:
358 pp_string (buffer, "guided");
359 break;
360 case OMP_CLAUSE_SCHEDULE_RUNTIME:
361 pp_string (buffer, "runtime");
362 break;
363 default:
364 gcc_unreachable ();
366 if (OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clause))
368 pp_character (buffer, ',');
369 dump_generic_node (buffer,
370 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clause),
371 spc, flags, false);
373 pp_character (buffer, ')');
374 break;
376 default:
377 /* Should never happen. */
378 dump_generic_node (buffer, clause, spc, flags, false);
379 break;
384 /* Dump the list of OpenMP clauses. BUFFER, SPC and FLAGS are as in
385 dump_generic_node. */
387 static void
388 dump_omp_clauses (pretty_printer *buffer, tree clause, int spc, int flags)
390 if (clause == NULL)
391 return;
393 pp_space (buffer);
394 while (1)
396 dump_omp_clause (buffer, clause, spc, flags);
397 clause = OMP_CLAUSE_CHAIN (clause);
398 if (clause == NULL)
399 return;
400 pp_space (buffer);
405 /* Dump the node NODE on the pretty_printer BUFFER, SPC spaces of indent.
406 FLAGS specifies details to show in the dump (see TDF_* in tree.h). If
407 IS_STMT is true, the object printed is considered to be a statement
408 and it is terminated by ';' if appropriate. */
411 dump_generic_node (pretty_printer *buffer, tree node, int spc, int flags,
412 bool is_stmt)
414 tree type;
415 tree op0, op1;
416 const char *str;
417 bool is_expr;
419 if (node == NULL_TREE)
420 return spc;
422 is_expr = EXPR_P (node);
424 if (TREE_CODE (node) != ERROR_MARK
425 && is_gimple_stmt (node)
426 && (flags & TDF_VOPS)
427 && stmt_ann (node)
428 && TREE_CODE (node) != PHI_NODE)
429 dump_vops (buffer, node, spc, flags);
431 if (is_stmt && (flags & TDF_STMTADDR))
432 pp_printf (buffer, "<&%p> ", (void *)node);
434 if ((flags & TDF_LINENO) && EXPR_HAS_LOCATION (node))
436 expanded_location xloc = expand_location (EXPR_LOCATION (node));
437 pp_character (buffer, '[');
438 if (xloc.file)
440 pp_string (buffer, xloc.file);
441 pp_string (buffer, " : ");
443 pp_decimal_int (buffer, xloc.line);
444 pp_string (buffer, "] ");
447 switch (TREE_CODE (node))
449 case ERROR_MARK:
450 pp_string (buffer, "<<< error >>>");
451 break;
453 case IDENTIFIER_NODE:
454 pp_tree_identifier (buffer, node);
455 break;
457 case TREE_LIST:
458 while (node && node != error_mark_node)
460 if (TREE_PURPOSE (node))
462 dump_generic_node (buffer, TREE_PURPOSE (node), spc, flags, false);
463 pp_space (buffer);
465 dump_generic_node (buffer, TREE_VALUE (node), spc, flags, false);
466 node = TREE_CHAIN (node);
467 if (node && TREE_CODE (node) == TREE_LIST)
469 pp_character (buffer, ',');
470 pp_space (buffer);
473 break;
475 case TREE_BINFO:
476 dump_generic_node (buffer, BINFO_TYPE (node), spc, flags, false);
478 case TREE_VEC:
480 size_t i;
481 if (TREE_VEC_LENGTH (node) > 0)
483 size_t len = TREE_VEC_LENGTH (node);
484 for (i = 0; i < len - 1; i++)
486 dump_generic_node (buffer, TREE_VEC_ELT (node, i), spc, flags,
487 false);
488 pp_character (buffer, ',');
489 pp_space (buffer);
491 dump_generic_node (buffer, TREE_VEC_ELT (node, len - 1), spc,
492 flags, false);
495 break;
497 case VOID_TYPE:
498 case INTEGER_TYPE:
499 case REAL_TYPE:
500 case COMPLEX_TYPE:
501 case VECTOR_TYPE:
502 case ENUMERAL_TYPE:
503 case BOOLEAN_TYPE:
505 unsigned int quals = TYPE_QUALS (node);
506 enum tree_code_class class;
508 if (quals & TYPE_QUAL_CONST)
509 pp_string (buffer, "const ");
510 else if (quals & TYPE_QUAL_VOLATILE)
511 pp_string (buffer, "volatile ");
512 else if (quals & TYPE_QUAL_RESTRICT)
513 pp_string (buffer, "restrict ");
515 class = TREE_CODE_CLASS (TREE_CODE (node));
517 if (class == tcc_declaration)
519 if (DECL_NAME (node))
520 dump_decl_name (buffer, node, flags);
521 else
522 pp_string (buffer, "<unnamed type decl>");
524 else if (class == tcc_type)
526 if (TYPE_NAME (node))
528 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
529 pp_tree_identifier (buffer, TYPE_NAME (node));
530 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
531 && DECL_NAME (TYPE_NAME (node)))
532 dump_decl_name (buffer, TYPE_NAME (node), flags);
533 else
534 pp_string (buffer, "<unnamed type>");
536 else if (TREE_CODE (node) == VECTOR_TYPE)
538 pp_string (buffer, "vector ");
539 dump_generic_node (buffer, TREE_TYPE (node),
540 spc, flags, false);
542 else
543 pp_string (buffer, "<unnamed type>");
545 break;
548 case POINTER_TYPE:
549 case REFERENCE_TYPE:
550 str = (TREE_CODE (node) == POINTER_TYPE ? "*" : "&");
552 if (TREE_CODE (TREE_TYPE (node)) == FUNCTION_TYPE)
554 tree fnode = TREE_TYPE (node);
556 dump_generic_node (buffer, TREE_TYPE (fnode), spc, flags, false);
557 pp_space (buffer);
558 pp_character (buffer, '(');
559 pp_string (buffer, str);
560 if (TYPE_NAME (node) && DECL_NAME (TYPE_NAME (node)))
561 dump_decl_name (buffer, TYPE_NAME (node), flags);
562 else
563 pp_printf (buffer, "<T%x>", TYPE_UID (node));
565 pp_character (buffer, ')');
566 dump_function_declaration (buffer, fnode, spc, flags);
568 else
570 unsigned int quals = TYPE_QUALS (node);
572 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
573 pp_space (buffer);
574 pp_string (buffer, str);
576 if (quals & TYPE_QUAL_CONST)
577 pp_string (buffer, " const");
578 else if (quals & TYPE_QUAL_VOLATILE)
579 pp_string (buffer, "volatile");
580 else if (quals & TYPE_QUAL_RESTRICT)
581 pp_string (buffer, " restrict");
583 if (TYPE_REF_CAN_ALIAS_ALL (node))
584 pp_string (buffer, " {ref-all}");
586 break;
588 case OFFSET_TYPE:
589 NIY;
590 break;
592 case METHOD_TYPE:
593 dump_decl_name (buffer, TYPE_NAME (TYPE_METHOD_BASETYPE (node)), flags);
594 pp_string (buffer, "::");
595 break;
597 case TARGET_MEM_REF:
599 const char *sep = "";
600 tree tmp;
602 pp_string (buffer, "MEM[");
604 tmp = TMR_SYMBOL (node);
605 if (tmp)
607 pp_string (buffer, sep);
608 sep = ", ";
609 pp_string (buffer, "symbol: ");
610 dump_generic_node (buffer, tmp, spc, flags, false);
612 tmp = TMR_BASE (node);
613 if (tmp)
615 pp_string (buffer, sep);
616 sep = ", ";
617 pp_string (buffer, "base: ");
618 dump_generic_node (buffer, tmp, spc, flags, false);
620 tmp = TMR_INDEX (node);
621 if (tmp)
623 pp_string (buffer, sep);
624 sep = ", ";
625 pp_string (buffer, "index: ");
626 dump_generic_node (buffer, tmp, spc, flags, false);
628 tmp = TMR_STEP (node);
629 if (tmp)
631 pp_string (buffer, sep);
632 sep = ", ";
633 pp_string (buffer, "step: ");
634 dump_generic_node (buffer, tmp, spc, flags, false);
636 tmp = TMR_OFFSET (node);
637 if (tmp)
639 pp_string (buffer, sep);
640 sep = ", ";
641 pp_string (buffer, "offset: ");
642 dump_generic_node (buffer, tmp, spc, flags, false);
644 pp_string (buffer, "]");
645 if (flags & TDF_DETAILS)
647 pp_string (buffer, "{");
648 dump_generic_node (buffer, TMR_ORIGINAL (node), spc, flags,
649 false);
650 pp_string (buffer, "}");
653 break;
655 case ARRAY_TYPE:
657 tree tmp;
659 /* Print the innermost component type. */
660 for (tmp = TREE_TYPE (node); TREE_CODE (tmp) == ARRAY_TYPE;
661 tmp = TREE_TYPE (tmp))
663 dump_generic_node (buffer, tmp, spc, flags, false);
665 /* Print the dimensions. */
666 for (tmp = node; TREE_CODE (tmp) == ARRAY_TYPE; tmp = TREE_TYPE (tmp))
667 dump_array_domain (buffer, TYPE_DOMAIN (tmp), spc, flags);
668 break;
671 case RECORD_TYPE:
672 case UNION_TYPE:
673 case QUAL_UNION_TYPE:
674 /* Print the name of the structure. */
675 if (TREE_CODE (node) == RECORD_TYPE)
676 pp_string (buffer, "struct ");
677 else if (TREE_CODE (node) == UNION_TYPE)
678 pp_string (buffer, "union ");
680 if (TYPE_NAME (node))
681 dump_generic_node (buffer, TYPE_NAME (node), spc, flags, false);
682 else
683 print_struct_decl (buffer, node, spc, flags);
684 break;
686 case LANG_TYPE:
687 NIY;
688 break;
690 case INTEGER_CST:
691 if (TREE_CODE (TREE_TYPE (node)) == POINTER_TYPE)
693 /* In the case of a pointer, one may want to divide by the
694 size of the pointed-to type. Unfortunately, this not
695 straightforward. The C front-end maps expressions
697 (int *) 5
698 int *p; (p + 5)
700 in such a way that the two INTEGER_CST nodes for "5" have
701 different values but identical types. In the latter
702 case, the 5 is multiplied by sizeof (int) in c-common.c
703 (pointer_int_sum) to convert it to a byte address, and
704 yet the type of the node is left unchanged. Argh. What
705 is consistent though is that the number value corresponds
706 to bytes (UNITS) offset.
708 NB: Neither of the following divisors can be trivially
709 used to recover the original literal:
711 TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (node)))
712 TYPE_PRECISION (TREE_TYPE (TREE_TYPE (node))) */
713 pp_wide_integer (buffer, TREE_INT_CST_LOW (node));
714 pp_string (buffer, "B"); /* pseudo-unit */
716 else if (! host_integerp (node, 0))
718 tree val = node;
720 if (tree_int_cst_sgn (val) < 0)
722 pp_character (buffer, '-');
723 val = build_int_cst_wide (NULL_TREE,
724 -TREE_INT_CST_LOW (val),
725 ~TREE_INT_CST_HIGH (val)
726 + !TREE_INT_CST_LOW (val));
728 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
729 systems? */
731 static char format[10]; /* "%x%09999x\0" */
732 if (!format[0])
733 sprintf (format, "%%x%%0%dx", HOST_BITS_PER_INT / 4);
734 sprintf (pp_buffer (buffer)->digit_buffer, format,
735 TREE_INT_CST_HIGH (val),
736 TREE_INT_CST_LOW (val));
737 pp_string (buffer, pp_buffer (buffer)->digit_buffer);
740 else
741 pp_wide_integer (buffer, TREE_INT_CST_LOW (node));
742 break;
744 case REAL_CST:
745 /* Code copied from print_node. */
747 REAL_VALUE_TYPE d;
748 if (TREE_OVERFLOW (node))
749 pp_string (buffer, " overflow");
751 #if !defined(REAL_IS_NOT_DOUBLE) || defined(REAL_ARITHMETIC)
752 d = TREE_REAL_CST (node);
753 if (REAL_VALUE_ISINF (d))
754 pp_string (buffer, " Inf");
755 else if (REAL_VALUE_ISNAN (d))
756 pp_string (buffer, " Nan");
757 else
759 char string[100];
760 real_to_decimal (string, &d, sizeof (string), 0, 1);
761 pp_string (buffer, string);
763 #else
765 HOST_WIDE_INT i;
766 unsigned char *p = (unsigned char *) &TREE_REAL_CST (node);
767 pp_string (buffer, "0x");
768 for (i = 0; i < sizeof TREE_REAL_CST (node); i++)
769 output_formatted_integer (buffer, "%02x", *p++);
771 #endif
772 break;
775 case COMPLEX_CST:
776 pp_string (buffer, "__complex__ (");
777 dump_generic_node (buffer, TREE_REALPART (node), spc, flags, false);
778 pp_string (buffer, ", ");
779 dump_generic_node (buffer, TREE_IMAGPART (node), spc, flags, false);
780 pp_string (buffer, ")");
781 break;
783 case STRING_CST:
784 pp_string (buffer, "\"");
785 pretty_print_string (buffer, TREE_STRING_POINTER (node));
786 pp_string (buffer, "\"");
787 break;
789 case VECTOR_CST:
791 tree elt;
792 pp_string (buffer, "{ ");
793 for (elt = TREE_VECTOR_CST_ELTS (node); elt; elt = TREE_CHAIN (elt))
795 dump_generic_node (buffer, TREE_VALUE (elt), spc, flags, false);
796 if (TREE_CHAIN (elt))
797 pp_string (buffer, ", ");
799 pp_string (buffer, " }");
801 break;
803 case FUNCTION_TYPE:
804 break;
806 case FUNCTION_DECL:
807 case CONST_DECL:
808 dump_decl_name (buffer, node, flags);
809 break;
811 case LABEL_DECL:
812 if (DECL_NAME (node))
813 dump_decl_name (buffer, node, flags);
814 else if (LABEL_DECL_UID (node) != -1)
815 pp_printf (buffer, "<L" HOST_WIDE_INT_PRINT_DEC ">",
816 LABEL_DECL_UID (node));
817 else
818 pp_printf (buffer, "<D%u>", DECL_UID (node));
819 break;
821 case TYPE_DECL:
822 if (DECL_IS_BUILTIN (node))
824 /* Don't print the declaration of built-in types. */
825 break;
827 if (DECL_NAME (node))
828 dump_decl_name (buffer, node, flags);
829 else
831 if ((TREE_CODE (TREE_TYPE (node)) == RECORD_TYPE
832 || TREE_CODE (TREE_TYPE (node)) == UNION_TYPE)
833 && TYPE_METHODS (TREE_TYPE (node)))
835 /* The type is a c++ class: all structures have at least
836 4 methods. */
837 pp_string (buffer, "class ");
838 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
840 else
842 pp_string (buffer,
843 (TREE_CODE (TREE_TYPE (node)) == UNION_TYPE
844 ? "union" : "struct "));
845 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
848 break;
850 case SYMBOL_MEMORY_TAG:
851 case NAME_MEMORY_TAG:
852 case STRUCT_FIELD_TAG:
853 case VAR_DECL:
854 case PARM_DECL:
855 case FIELD_DECL:
856 case NAMESPACE_DECL:
857 dump_decl_name (buffer, node, flags);
858 break;
860 case RESULT_DECL:
861 pp_string (buffer, "<retval>");
862 break;
864 case COMPONENT_REF:
865 op0 = TREE_OPERAND (node, 0);
866 str = ".";
867 if (TREE_CODE (op0) == INDIRECT_REF)
869 op0 = TREE_OPERAND (op0, 0);
870 str = "->";
872 if (op_prio (op0) < op_prio (node))
873 pp_character (buffer, '(');
874 dump_generic_node (buffer, op0, spc, flags, false);
875 if (op_prio (op0) < op_prio (node))
876 pp_character (buffer, ')');
877 pp_string (buffer, str);
878 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
880 if (TREE_CODE (op0) != VALUE_HANDLE)
882 op0 = component_ref_field_offset (node);
883 if (op0 && TREE_CODE (op0) != INTEGER_CST)
885 pp_string (buffer, "{off: ");
886 dump_generic_node (buffer, op0, spc, flags, false);
887 pp_character (buffer, '}');
890 break;
892 case BIT_FIELD_REF:
893 pp_string (buffer, "BIT_FIELD_REF <");
894 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
895 pp_string (buffer, ", ");
896 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
897 pp_string (buffer, ", ");
898 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
899 pp_string (buffer, ">");
900 break;
902 case ARRAY_REF:
903 case ARRAY_RANGE_REF:
904 op0 = TREE_OPERAND (node, 0);
905 if (op_prio (op0) < op_prio (node))
906 pp_character (buffer, '(');
907 dump_generic_node (buffer, op0, spc, flags, false);
908 if (op_prio (op0) < op_prio (node))
909 pp_character (buffer, ')');
910 pp_character (buffer, '[');
911 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
912 if (TREE_CODE (node) == ARRAY_RANGE_REF)
913 pp_string (buffer, " ...");
914 pp_character (buffer, ']');
916 op0 = array_ref_low_bound (node);
917 op1 = array_ref_element_size (node);
919 if (!integer_zerop (op0)
920 || (TYPE_SIZE_UNIT (TREE_TYPE (node))
921 && !operand_equal_p (op1, TYPE_SIZE_UNIT (TREE_TYPE (node)), 0)))
923 pp_string (buffer, "{lb: ");
924 dump_generic_node (buffer, op0, spc, flags, false);
925 pp_string (buffer, " sz: ");
926 dump_generic_node (buffer, op1, spc, flags, false);
927 pp_character (buffer, '}');
929 break;
931 case CONSTRUCTOR:
933 unsigned HOST_WIDE_INT ix;
934 tree field, val;
935 bool is_struct_init = FALSE;
936 pp_character (buffer, '{');
937 if (TREE_CODE (TREE_TYPE (node)) == RECORD_TYPE
938 || TREE_CODE (TREE_TYPE (node)) == UNION_TYPE)
939 is_struct_init = TRUE;
940 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (node), ix, field, val)
942 if (field && is_struct_init)
944 pp_character (buffer, '.');
945 dump_generic_node (buffer, field, spc, flags, false);
946 pp_string (buffer, "=");
948 if (val && TREE_CODE (val) == ADDR_EXPR)
949 if (TREE_CODE (TREE_OPERAND (val, 0)) == FUNCTION_DECL)
950 val = TREE_OPERAND (val, 0);
951 if (val && TREE_CODE (val) == FUNCTION_DECL)
952 dump_decl_name (buffer, val, flags);
953 else
954 dump_generic_node (buffer, val, spc, flags, false);
955 if (ix != VEC_length (constructor_elt, CONSTRUCTOR_ELTS (node)) - 1)
957 pp_character (buffer, ',');
958 pp_space (buffer);
961 pp_character (buffer, '}');
963 break;
965 case COMPOUND_EXPR:
967 tree *tp;
968 if (flags & TDF_SLIM)
970 pp_string (buffer, "<COMPOUND_EXPR>");
971 break;
974 dump_generic_node (buffer, TREE_OPERAND (node, 0),
975 spc, flags, !(flags & TDF_SLIM));
976 if (flags & TDF_SLIM)
977 newline_and_indent (buffer, spc);
978 else
980 pp_character (buffer, ',');
981 pp_space (buffer);
984 for (tp = &TREE_OPERAND (node, 1);
985 TREE_CODE (*tp) == COMPOUND_EXPR;
986 tp = &TREE_OPERAND (*tp, 1))
988 dump_generic_node (buffer, TREE_OPERAND (*tp, 0),
989 spc, flags, !(flags & TDF_SLIM));
990 if (flags & TDF_SLIM)
991 newline_and_indent (buffer, spc);
992 else
994 pp_character (buffer, ',');
995 pp_space (buffer);
999 dump_generic_node (buffer, *tp, spc, flags, !(flags & TDF_SLIM));
1001 break;
1003 case STATEMENT_LIST:
1005 tree_stmt_iterator si;
1006 bool first = true;
1008 if (flags & TDF_SLIM)
1010 pp_string (buffer, "<STATEMENT_LIST>");
1011 break;
1014 for (si = tsi_start (node); !tsi_end_p (si); tsi_next (&si))
1016 if (!first)
1017 newline_and_indent (buffer, spc);
1018 else
1019 first = false;
1020 dump_generic_node (buffer, tsi_stmt (si), spc, flags, true);
1023 break;
1025 case MODIFY_EXPR:
1026 case INIT_EXPR:
1027 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1028 pp_space (buffer);
1029 pp_character (buffer, '=');
1030 pp_space (buffer);
1031 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1032 break;
1034 case TARGET_EXPR:
1035 pp_string (buffer, "TARGET_EXPR <");
1036 dump_generic_node (buffer, TARGET_EXPR_SLOT (node), spc, flags, false);
1037 pp_character (buffer, ',');
1038 pp_space (buffer);
1039 dump_generic_node (buffer, TARGET_EXPR_INITIAL (node), spc, flags, false);
1040 pp_character (buffer, '>');
1041 break;
1043 case DECL_EXPR:
1044 print_declaration (buffer, DECL_EXPR_DECL (node), spc, flags);
1045 is_stmt = false;
1046 break;
1048 case COND_EXPR:
1049 if (TREE_TYPE (node) == NULL || TREE_TYPE (node) == void_type_node)
1051 pp_string (buffer, "if (");
1052 dump_generic_node (buffer, COND_EXPR_COND (node), spc, flags, false);
1053 pp_character (buffer, ')');
1054 /* The lowered cond_exprs should always be printed in full. */
1055 if (COND_EXPR_THEN (node)
1056 && (IS_EMPTY_STMT (COND_EXPR_THEN (node))
1057 || TREE_CODE (COND_EXPR_THEN (node)) == GOTO_EXPR)
1058 && COND_EXPR_ELSE (node)
1059 && (IS_EMPTY_STMT (COND_EXPR_ELSE (node))
1060 || TREE_CODE (COND_EXPR_ELSE (node)) == GOTO_EXPR))
1062 pp_space (buffer);
1063 dump_generic_node (buffer, COND_EXPR_THEN (node), 0, flags, true);
1064 pp_string (buffer, " else ");
1065 dump_generic_node (buffer, COND_EXPR_ELSE (node), 0, flags, true);
1067 else if (!(flags & TDF_SLIM))
1069 /* Output COND_EXPR_THEN. */
1070 if (COND_EXPR_THEN (node))
1072 newline_and_indent (buffer, spc+2);
1073 pp_character (buffer, '{');
1074 newline_and_indent (buffer, spc+4);
1075 dump_generic_node (buffer, COND_EXPR_THEN (node), spc+4,
1076 flags, true);
1077 newline_and_indent (buffer, spc+2);
1078 pp_character (buffer, '}');
1081 /* Output COND_EXPR_ELSE. */
1082 if (COND_EXPR_ELSE (node))
1084 newline_and_indent (buffer, spc);
1085 pp_string (buffer, "else");
1086 newline_and_indent (buffer, spc+2);
1087 pp_character (buffer, '{');
1088 newline_and_indent (buffer, spc+4);
1089 dump_generic_node (buffer, COND_EXPR_ELSE (node), spc+4,
1090 flags, true);
1091 newline_and_indent (buffer, spc+2);
1092 pp_character (buffer, '}');
1095 is_expr = false;
1097 else
1099 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1100 pp_space (buffer);
1101 pp_character (buffer, '?');
1102 pp_space (buffer);
1103 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1104 pp_space (buffer);
1105 pp_character (buffer, ':');
1106 pp_space (buffer);
1107 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
1109 break;
1111 case BIND_EXPR:
1112 pp_character (buffer, '{');
1113 if (!(flags & TDF_SLIM))
1115 if (BIND_EXPR_VARS (node))
1117 pp_newline (buffer);
1119 for (op0 = BIND_EXPR_VARS (node); op0; op0 = TREE_CHAIN (op0))
1121 print_declaration (buffer, op0, spc+2, flags);
1122 pp_newline (buffer);
1126 newline_and_indent (buffer, spc+2);
1127 dump_generic_node (buffer, BIND_EXPR_BODY (node), spc+2, flags, true);
1128 newline_and_indent (buffer, spc);
1129 pp_character (buffer, '}');
1131 is_expr = false;
1132 break;
1134 case CALL_EXPR:
1135 print_call_name (buffer, node);
1137 /* Print parameters. */
1138 pp_space (buffer);
1139 pp_character (buffer, '(');
1140 op1 = TREE_OPERAND (node, 1);
1141 if (op1)
1142 dump_generic_node (buffer, op1, spc, flags, false);
1143 pp_character (buffer, ')');
1145 op1 = TREE_OPERAND (node, 2);
1146 if (op1)
1148 pp_string (buffer, " [static-chain: ");
1149 dump_generic_node (buffer, op1, spc, flags, false);
1150 pp_character (buffer, ']');
1153 if (CALL_EXPR_RETURN_SLOT_OPT (node))
1154 pp_string (buffer, " [return slot optimization]");
1155 if (CALL_EXPR_TAILCALL (node))
1156 pp_string (buffer, " [tail call]");
1157 break;
1159 case WITH_CLEANUP_EXPR:
1160 NIY;
1161 break;
1163 case CLEANUP_POINT_EXPR:
1164 pp_string (buffer, "<<cleanup_point ");
1165 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1166 pp_string (buffer, ">>");
1167 break;
1169 case PLACEHOLDER_EXPR:
1170 pp_string (buffer, "<PLACEHOLDER_EXPR ");
1171 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
1172 pp_character (buffer, '>');
1173 break;
1175 /* Binary arithmetic and logic expressions. */
1176 case WIDEN_SUM_EXPR:
1177 case WIDEN_MULT_EXPR:
1178 case MULT_EXPR:
1179 case PLUS_EXPR:
1180 case MINUS_EXPR:
1181 case TRUNC_DIV_EXPR:
1182 case CEIL_DIV_EXPR:
1183 case FLOOR_DIV_EXPR:
1184 case ROUND_DIV_EXPR:
1185 case TRUNC_MOD_EXPR:
1186 case CEIL_MOD_EXPR:
1187 case FLOOR_MOD_EXPR:
1188 case ROUND_MOD_EXPR:
1189 case RDIV_EXPR:
1190 case EXACT_DIV_EXPR:
1191 case LSHIFT_EXPR:
1192 case RSHIFT_EXPR:
1193 case LROTATE_EXPR:
1194 case RROTATE_EXPR:
1195 case VEC_LSHIFT_EXPR:
1196 case VEC_RSHIFT_EXPR:
1197 case BIT_IOR_EXPR:
1198 case BIT_XOR_EXPR:
1199 case BIT_AND_EXPR:
1200 case TRUTH_ANDIF_EXPR:
1201 case TRUTH_ORIF_EXPR:
1202 case TRUTH_AND_EXPR:
1203 case TRUTH_OR_EXPR:
1204 case TRUTH_XOR_EXPR:
1205 case LT_EXPR:
1206 case LE_EXPR:
1207 case GT_EXPR:
1208 case GE_EXPR:
1209 case EQ_EXPR:
1210 case NE_EXPR:
1211 case UNLT_EXPR:
1212 case UNLE_EXPR:
1213 case UNGT_EXPR:
1214 case UNGE_EXPR:
1215 case UNEQ_EXPR:
1216 case LTGT_EXPR:
1217 case ORDERED_EXPR:
1218 case UNORDERED_EXPR:
1220 const char *op = op_symbol (node);
1221 op0 = TREE_OPERAND (node, 0);
1222 op1 = TREE_OPERAND (node, 1);
1224 /* When the operands are expressions with less priority,
1225 keep semantics of the tree representation. */
1226 if (op_prio (op0) < op_prio (node))
1228 pp_character (buffer, '(');
1229 dump_generic_node (buffer, op0, spc, flags, false);
1230 pp_character (buffer, ')');
1232 else
1233 dump_generic_node (buffer, op0, spc, flags, false);
1235 pp_space (buffer);
1236 pp_string (buffer, op);
1237 pp_space (buffer);
1239 /* When the operands are expressions with less priority,
1240 keep semantics of the tree representation. */
1241 if (op_prio (op1) < op_prio (node))
1243 pp_character (buffer, '(');
1244 dump_generic_node (buffer, op1, spc, flags, false);
1245 pp_character (buffer, ')');
1247 else
1248 dump_generic_node (buffer, op1, spc, flags, false);
1250 break;
1252 /* Unary arithmetic and logic expressions. */
1253 case NEGATE_EXPR:
1254 case BIT_NOT_EXPR:
1255 case TRUTH_NOT_EXPR:
1256 case ADDR_EXPR:
1257 case PREDECREMENT_EXPR:
1258 case PREINCREMENT_EXPR:
1259 case ALIGN_INDIRECT_REF:
1260 case MISALIGNED_INDIRECT_REF:
1261 case INDIRECT_REF:
1262 if (TREE_CODE (node) == ADDR_EXPR
1263 && (TREE_CODE (TREE_OPERAND (node, 0)) == STRING_CST
1264 || TREE_CODE (TREE_OPERAND (node, 0)) == FUNCTION_DECL))
1265 ; /* Do not output '&' for strings and function pointers. */
1266 else
1267 pp_string (buffer, op_symbol (node));
1269 if (op_prio (TREE_OPERAND (node, 0)) < op_prio (node))
1271 pp_character (buffer, '(');
1272 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1273 pp_character (buffer, ')');
1275 else
1276 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1278 if (TREE_CODE (node) == MISALIGNED_INDIRECT_REF)
1280 pp_string (buffer, "{misalignment: ");
1281 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1282 pp_character (buffer, '}');
1284 break;
1286 case POSTDECREMENT_EXPR:
1287 case POSTINCREMENT_EXPR:
1288 if (op_prio (TREE_OPERAND (node, 0)) < op_prio (node))
1290 pp_character (buffer, '(');
1291 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1292 pp_character (buffer, ')');
1294 else
1295 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1296 pp_string (buffer, op_symbol (node));
1297 break;
1299 case MIN_EXPR:
1300 pp_string (buffer, "MIN_EXPR <");
1301 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1302 pp_string (buffer, ", ");
1303 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1304 pp_character (buffer, '>');
1305 break;
1307 case MAX_EXPR:
1308 pp_string (buffer, "MAX_EXPR <");
1309 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1310 pp_string (buffer, ", ");
1311 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1312 pp_character (buffer, '>');
1313 break;
1315 case ABS_EXPR:
1316 pp_string (buffer, "ABS_EXPR <");
1317 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1318 pp_character (buffer, '>');
1319 break;
1321 case RANGE_EXPR:
1322 NIY;
1323 break;
1325 case FIX_TRUNC_EXPR:
1326 case FIX_CEIL_EXPR:
1327 case FIX_FLOOR_EXPR:
1328 case FIX_ROUND_EXPR:
1329 case FLOAT_EXPR:
1330 case CONVERT_EXPR:
1331 case NOP_EXPR:
1332 type = TREE_TYPE (node);
1333 op0 = TREE_OPERAND (node, 0);
1334 if (type != TREE_TYPE (op0))
1336 pp_character (buffer, '(');
1337 dump_generic_node (buffer, type, spc, flags, false);
1338 pp_string (buffer, ") ");
1340 if (op_prio (op0) < op_prio (node))
1341 pp_character (buffer, '(');
1342 dump_generic_node (buffer, op0, spc, flags, false);
1343 if (op_prio (op0) < op_prio (node))
1344 pp_character (buffer, ')');
1345 break;
1347 case VIEW_CONVERT_EXPR:
1348 pp_string (buffer, "VIEW_CONVERT_EXPR<");
1349 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
1350 pp_string (buffer, ">(");
1351 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1352 pp_character (buffer, ')');
1353 break;
1355 case NON_LVALUE_EXPR:
1356 pp_string (buffer, "NON_LVALUE_EXPR <");
1357 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1358 pp_character (buffer, '>');
1359 break;
1361 case SAVE_EXPR:
1362 pp_string (buffer, "SAVE_EXPR <");
1363 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1364 pp_character (buffer, '>');
1365 break;
1367 case COMPLEX_EXPR:
1368 pp_string (buffer, "COMPLEX_EXPR <");
1369 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1370 pp_string (buffer, ", ");
1371 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1372 pp_string (buffer, ">");
1373 break;
1375 case CONJ_EXPR:
1376 pp_string (buffer, "CONJ_EXPR <");
1377 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1378 pp_string (buffer, ">");
1379 break;
1381 case REALPART_EXPR:
1382 pp_string (buffer, "REALPART_EXPR <");
1383 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1384 pp_string (buffer, ">");
1385 break;
1387 case IMAGPART_EXPR:
1388 pp_string (buffer, "IMAGPART_EXPR <");
1389 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1390 pp_string (buffer, ">");
1391 break;
1393 case VA_ARG_EXPR:
1394 pp_string (buffer, "VA_ARG_EXPR <");
1395 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1396 pp_string (buffer, ">");
1397 break;
1399 case TRY_FINALLY_EXPR:
1400 case TRY_CATCH_EXPR:
1401 pp_string (buffer, "try");
1402 newline_and_indent (buffer, spc+2);
1403 pp_string (buffer, "{");
1404 newline_and_indent (buffer, spc+4);
1405 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc+4, flags, true);
1406 newline_and_indent (buffer, spc+2);
1407 pp_string (buffer, "}");
1408 newline_and_indent (buffer, spc);
1409 pp_string (buffer,
1410 (TREE_CODE (node) == TRY_CATCH_EXPR) ? "catch" : "finally");
1411 newline_and_indent (buffer, spc+2);
1412 pp_string (buffer, "{");
1413 newline_and_indent (buffer, spc+4);
1414 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc+4, flags, true);
1415 newline_and_indent (buffer, spc+2);
1416 pp_string (buffer, "}");
1417 is_expr = false;
1418 break;
1420 case CATCH_EXPR:
1421 pp_string (buffer, "catch (");
1422 dump_generic_node (buffer, CATCH_TYPES (node), spc+2, flags, false);
1423 pp_string (buffer, ")");
1424 newline_and_indent (buffer, spc+2);
1425 pp_string (buffer, "{");
1426 newline_and_indent (buffer, spc+4);
1427 dump_generic_node (buffer, CATCH_BODY (node), spc+4, flags, true);
1428 newline_and_indent (buffer, spc+2);
1429 pp_string (buffer, "}");
1430 is_expr = false;
1431 break;
1433 case EH_FILTER_EXPR:
1434 pp_string (buffer, "<<<eh_filter (");
1435 dump_generic_node (buffer, EH_FILTER_TYPES (node), spc+2, flags, false);
1436 pp_string (buffer, ")>>>");
1437 newline_and_indent (buffer, spc+2);
1438 pp_string (buffer, "{");
1439 newline_and_indent (buffer, spc+4);
1440 dump_generic_node (buffer, EH_FILTER_FAILURE (node), spc+4, flags, true);
1441 newline_and_indent (buffer, spc+2);
1442 pp_string (buffer, "}");
1443 is_expr = false;
1444 break;
1446 case LABEL_EXPR:
1447 op0 = TREE_OPERAND (node, 0);
1448 /* If this is for break or continue, don't bother printing it. */
1449 if (DECL_NAME (op0))
1451 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1452 if (strcmp (name, "break") == 0
1453 || strcmp (name, "continue") == 0)
1454 break;
1456 dump_generic_node (buffer, op0, spc, flags, false);
1457 pp_character (buffer, ':');
1458 if (DECL_NONLOCAL (op0))
1459 pp_string (buffer, " [non-local]");
1460 break;
1462 case EXC_PTR_EXPR:
1463 pp_string (buffer, "<<<exception object>>>");
1464 break;
1466 case FILTER_EXPR:
1467 pp_string (buffer, "<<<filter object>>>");
1468 break;
1470 case LOOP_EXPR:
1471 pp_string (buffer, "while (1)");
1472 if (!(flags & TDF_SLIM))
1474 newline_and_indent (buffer, spc+2);
1475 pp_character (buffer, '{');
1476 newline_and_indent (buffer, spc+4);
1477 dump_generic_node (buffer, LOOP_EXPR_BODY (node), spc+4, flags, true);
1478 newline_and_indent (buffer, spc+2);
1479 pp_character (buffer, '}');
1481 is_expr = false;
1482 break;
1484 case RETURN_EXPR:
1485 pp_string (buffer, "return");
1486 op0 = TREE_OPERAND (node, 0);
1487 if (op0)
1489 pp_space (buffer);
1490 if (TREE_CODE (op0) == MODIFY_EXPR)
1491 dump_generic_node (buffer, TREE_OPERAND (op0, 1), spc, flags, false);
1492 else
1493 dump_generic_node (buffer, op0, spc, flags, false);
1495 break;
1497 case EXIT_EXPR:
1498 pp_string (buffer, "if (");
1499 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1500 pp_string (buffer, ") break");
1501 break;
1503 case SWITCH_EXPR:
1504 pp_string (buffer, "switch (");
1505 dump_generic_node (buffer, SWITCH_COND (node), spc, flags, false);
1506 pp_character (buffer, ')');
1507 if (!(flags & TDF_SLIM))
1509 newline_and_indent (buffer, spc+2);
1510 pp_character (buffer, '{');
1511 if (SWITCH_BODY (node))
1513 newline_and_indent (buffer, spc+4);
1514 dump_generic_node (buffer, SWITCH_BODY (node), spc+4, flags,
1515 true);
1517 else
1519 tree vec = SWITCH_LABELS (node);
1520 size_t i, n = TREE_VEC_LENGTH (vec);
1521 for (i = 0; i < n; ++i)
1523 tree elt = TREE_VEC_ELT (vec, i);
1524 newline_and_indent (buffer, spc+4);
1525 if (elt)
1527 dump_generic_node (buffer, elt, spc+4, flags, false);
1528 pp_string (buffer, " goto ");
1529 dump_generic_node (buffer, CASE_LABEL (elt), spc+4,
1530 flags, true);
1531 pp_semicolon (buffer);
1533 else
1534 pp_string (buffer, "case ???: goto ???;");
1537 newline_and_indent (buffer, spc+2);
1538 pp_character (buffer, '}');
1540 is_expr = false;
1541 break;
1543 case GOTO_EXPR:
1544 op0 = GOTO_DESTINATION (node);
1545 if (TREE_CODE (op0) != SSA_NAME && DECL_P (op0) && DECL_NAME (op0))
1547 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1548 if (strcmp (name, "break") == 0
1549 || strcmp (name, "continue") == 0)
1551 pp_string (buffer, name);
1552 break;
1555 pp_string (buffer, "goto ");
1556 dump_generic_node (buffer, op0, spc, flags, false);
1557 break;
1559 case RESX_EXPR:
1560 pp_string (buffer, "resx ");
1561 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1562 break;
1564 case ASM_EXPR:
1565 pp_string (buffer, "__asm__");
1566 if (ASM_VOLATILE_P (node))
1567 pp_string (buffer, " __volatile__");
1568 pp_character (buffer, '(');
1569 dump_generic_node (buffer, ASM_STRING (node), spc, flags, false);
1570 pp_character (buffer, ':');
1571 dump_generic_node (buffer, ASM_OUTPUTS (node), spc, flags, false);
1572 pp_character (buffer, ':');
1573 dump_generic_node (buffer, ASM_INPUTS (node), spc, flags, false);
1574 if (ASM_CLOBBERS (node))
1576 pp_character (buffer, ':');
1577 dump_generic_node (buffer, ASM_CLOBBERS (node), spc, flags, false);
1579 pp_string (buffer, ")");
1580 break;
1582 case CASE_LABEL_EXPR:
1583 if (CASE_LOW (node) && CASE_HIGH (node))
1585 pp_string (buffer, "case ");
1586 dump_generic_node (buffer, CASE_LOW (node), spc, flags, false);
1587 pp_string (buffer, " ... ");
1588 dump_generic_node (buffer, CASE_HIGH (node), spc, flags, false);
1590 else if (CASE_LOW (node))
1592 pp_string (buffer, "case ");
1593 dump_generic_node (buffer, CASE_LOW (node), spc, flags, false);
1595 else
1596 pp_string (buffer, "default ");
1597 pp_character (buffer, ':');
1598 break;
1600 case OBJ_TYPE_REF:
1601 pp_string (buffer, "OBJ_TYPE_REF(");
1602 dump_generic_node (buffer, OBJ_TYPE_REF_EXPR (node), spc, flags, false);
1603 pp_character (buffer, ';');
1604 dump_generic_node (buffer, OBJ_TYPE_REF_OBJECT (node), spc, flags, false);
1605 pp_character (buffer, '-');
1606 pp_character (buffer, '>');
1607 dump_generic_node (buffer, OBJ_TYPE_REF_TOKEN (node), spc, flags, false);
1608 pp_character (buffer, ')');
1609 break;
1611 case PHI_NODE:
1613 int i;
1615 dump_generic_node (buffer, PHI_RESULT (node), spc, flags, false);
1616 pp_string (buffer, " = PHI <");
1617 for (i = 0; i < PHI_NUM_ARGS (node); i++)
1619 dump_generic_node (buffer, PHI_ARG_DEF (node, i), spc, flags, false);
1620 pp_string (buffer, "(");
1621 pp_decimal_int (buffer, PHI_ARG_EDGE (node, i)->src->index);
1622 pp_string (buffer, ")");
1623 if (i < PHI_NUM_ARGS (node) - 1)
1624 pp_string (buffer, ", ");
1626 pp_string (buffer, ">;");
1628 break;
1630 case SSA_NAME:
1631 dump_generic_node (buffer, SSA_NAME_VAR (node), spc, flags, false);
1632 pp_string (buffer, "_");
1633 pp_decimal_int (buffer, SSA_NAME_VERSION (node));
1634 if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (node))
1635 pp_string (buffer, "(ab)");
1636 break;
1638 case WITH_SIZE_EXPR:
1639 pp_string (buffer, "WITH_SIZE_EXPR <");
1640 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1641 pp_string (buffer, ", ");
1642 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1643 pp_string (buffer, ">");
1644 break;
1646 case VALUE_HANDLE:
1647 pp_printf (buffer, "VH.%d", VALUE_HANDLE_ID (node));
1648 break;
1650 case ASSERT_EXPR:
1651 pp_string (buffer, "ASSERT_EXPR <");
1652 dump_generic_node (buffer, ASSERT_EXPR_VAR (node), spc, flags, false);
1653 pp_string (buffer, ", ");
1654 dump_generic_node (buffer, ASSERT_EXPR_COND (node), spc, flags, false);
1655 pp_string (buffer, ">");
1656 break;
1658 case SCEV_KNOWN:
1659 pp_string (buffer, "scev_known");
1660 break;
1662 case SCEV_NOT_KNOWN:
1663 pp_string (buffer, "scev_not_known");
1664 break;
1666 case POLYNOMIAL_CHREC:
1667 pp_string (buffer, "{");
1668 dump_generic_node (buffer, CHREC_LEFT (node), spc, flags, false);
1669 pp_string (buffer, ", +, ");
1670 dump_generic_node (buffer, CHREC_RIGHT (node), spc, flags, false);
1671 pp_string (buffer, "}_");
1672 dump_generic_node (buffer, CHREC_VAR (node), spc, flags, false);
1673 is_stmt = false;
1674 break;
1676 case REALIGN_LOAD_EXPR:
1677 pp_string (buffer, "REALIGN_LOAD <");
1678 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1679 pp_string (buffer, ", ");
1680 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1681 pp_string (buffer, ", ");
1682 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
1683 pp_string (buffer, ">");
1684 break;
1686 case VEC_COND_EXPR:
1687 pp_string (buffer, " VEC_COND_EXPR < ");
1688 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1689 pp_string (buffer, " , ");
1690 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1691 pp_string (buffer, " , ");
1692 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
1693 pp_string (buffer, " > ");
1694 break;
1696 case DOT_PROD_EXPR:
1697 pp_string (buffer, " DOT_PROD_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_string (buffer, " , ");
1702 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
1703 pp_string (buffer, " > ");
1704 break;
1706 case OMP_PARALLEL:
1707 pp_string (buffer, "#pragma omp parallel");
1708 dump_omp_clauses (buffer, OMP_PARALLEL_CLAUSES (node), spc, flags);
1709 if (OMP_PARALLEL_FN (node))
1711 pp_string (buffer, " [child fn: ");
1712 dump_generic_node (buffer, OMP_PARALLEL_FN (node), spc, flags, false);
1714 pp_string (buffer, " (");
1716 if (OMP_PARALLEL_DATA_ARG (node))
1717 dump_generic_node (buffer, OMP_PARALLEL_DATA_ARG (node), spc, flags,
1718 false);
1719 else
1720 pp_string (buffer, "???");
1722 pp_string (buffer, ")]");
1725 dump_omp_body:
1726 if (!(flags & TDF_SLIM) && OMP_BODY (node))
1728 newline_and_indent (buffer, spc + 2);
1729 pp_character (buffer, '{');
1730 newline_and_indent (buffer, spc + 4);
1731 dump_generic_node (buffer, OMP_BODY (node), spc + 4, flags, false);
1732 newline_and_indent (buffer, spc + 2);
1733 pp_character (buffer, '}');
1735 is_expr = false;
1736 break;
1738 case OMP_FOR:
1739 pp_string (buffer, "#pragma omp for");
1740 dump_omp_clauses (buffer, OMP_FOR_CLAUSES (node), spc, flags);
1742 if (!(flags & TDF_SLIM))
1744 if (OMP_FOR_PRE_BODY (node))
1746 newline_and_indent (buffer, spc + 2);
1747 pp_character (buffer, '{');
1748 spc += 4;
1749 newline_and_indent (buffer, spc);
1750 dump_generic_node (buffer, OMP_FOR_PRE_BODY (node),
1751 spc, flags, false);
1753 newline_and_indent (buffer, spc);
1754 pp_string (buffer, "for (");
1755 dump_generic_node (buffer, OMP_FOR_INIT (node), spc, flags, false);
1756 pp_string (buffer, "; ");
1757 dump_generic_node (buffer, OMP_FOR_COND (node), spc, flags, false);
1758 pp_string (buffer, "; ");
1759 dump_generic_node (buffer, OMP_FOR_INCR (node), spc, flags, false);
1760 pp_string (buffer, ")");
1761 if (OMP_FOR_BODY (node))
1763 newline_and_indent (buffer, spc + 2);
1764 pp_character (buffer, '{');
1765 newline_and_indent (buffer, spc + 4);
1766 dump_generic_node (buffer, OMP_FOR_BODY (node), spc + 4, flags,
1767 false);
1768 newline_and_indent (buffer, spc + 2);
1769 pp_character (buffer, '}');
1771 if (OMP_FOR_PRE_BODY (node))
1773 spc -= 4;
1774 newline_and_indent (buffer, spc + 2);
1775 pp_character (buffer, '}');
1778 is_expr = false;
1779 break;
1781 case OMP_SECTIONS:
1782 pp_string (buffer, "#pragma omp sections");
1783 if (OMP_SECTIONS_CONTROL (node))
1785 pp_string (buffer, " (");
1786 dump_generic_node (buffer, OMP_SECTIONS_CONTROL (node), spc,
1787 flags, false);
1788 pp_string (buffer, ")");
1790 dump_omp_clauses (buffer, OMP_SECTIONS_CLAUSES (node), spc, flags);
1791 goto dump_omp_body;
1793 case OMP_SECTIONS_SWITCH:
1794 pp_string (buffer, "OMP_SECTIONS_SWITCH");
1795 is_expr = false;
1796 break;
1798 case OMP_SECTION:
1799 pp_string (buffer, "#pragma omp section");
1800 goto dump_omp_body;
1802 case OMP_MASTER:
1803 pp_string (buffer, "#pragma omp master");
1804 goto dump_omp_body;
1806 case OMP_ORDERED:
1807 pp_string (buffer, "#pragma omp ordered");
1808 goto dump_omp_body;
1810 case OMP_CRITICAL:
1811 pp_string (buffer, "#pragma omp critical");
1812 if (OMP_CRITICAL_NAME (node))
1814 pp_space (buffer);
1815 pp_character (buffer, '(');
1816 dump_generic_node (buffer, OMP_CRITICAL_NAME (node), spc,
1817 flags, false);
1818 pp_character (buffer, ')');
1820 goto dump_omp_body;
1822 case OMP_ATOMIC:
1823 pp_string (buffer, "#pragma omp atomic");
1824 newline_and_indent (buffer, spc + 2);
1825 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1826 pp_space (buffer);
1827 pp_character (buffer, '=');
1828 pp_space (buffer);
1829 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1830 break;
1832 case OMP_SINGLE:
1833 pp_string (buffer, "#pragma omp single");
1834 dump_omp_clauses (buffer, OMP_SINGLE_CLAUSES (node), spc, flags);
1835 goto dump_omp_body;
1837 case OMP_RETURN:
1838 pp_string (buffer, "OMP_RETURN");
1839 if (OMP_RETURN_NOWAIT (node))
1840 pp_string (buffer, " [nowait]");
1841 is_expr = false;
1842 break;
1844 case OMP_CONTINUE:
1845 pp_string (buffer, "OMP_CONTINUE (");
1846 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1847 pp_string (buffer, " <- ");
1848 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1849 pp_string (buffer, ")");
1850 is_expr = false;
1851 break;
1853 case OMP_CLAUSE:
1854 dump_omp_clause (buffer, node, spc, flags);
1855 is_expr = false;
1856 break;
1858 case REDUC_MAX_EXPR:
1859 pp_string (buffer, " REDUC_MAX_EXPR < ");
1860 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1861 pp_string (buffer, " > ");
1862 break;
1864 case REDUC_MIN_EXPR:
1865 pp_string (buffer, " REDUC_MIN_EXPR < ");
1866 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1867 pp_string (buffer, " > ");
1868 break;
1870 case REDUC_PLUS_EXPR:
1871 pp_string (buffer, " REDUC_PLUS_EXPR < ");
1872 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1873 pp_string (buffer, " > ");
1874 break;
1876 case BLOCK:
1878 tree t;
1879 pp_string (buffer, "BLOCK");
1881 if (BLOCK_ABSTRACT (node))
1882 pp_string (buffer, " [abstract]");
1884 if (TREE_ASM_WRITTEN (node))
1885 pp_string (buffer, " [written]");
1887 newline_and_indent (buffer, spc + 2);
1889 if (BLOCK_SUPERCONTEXT (node))
1891 pp_string (buffer, "SUPERCONTEXT: ");
1892 if (TREE_CODE (BLOCK_SUPERCONTEXT (node)) == BLOCK)
1893 pp_printf (buffer, "BLOCK %p",
1894 (void *)BLOCK_SUPERCONTEXT (node));
1895 else
1896 dump_generic_node (buffer, BLOCK_SUPERCONTEXT (node), 0, flags,
1897 false);
1898 newline_and_indent (buffer, spc + 2);
1901 if (BLOCK_SUBBLOCKS (node))
1903 pp_string (buffer, "SUBBLOCKS: ");
1904 for (t = BLOCK_SUBBLOCKS (node); t; t = BLOCK_CHAIN (t))
1905 pp_printf (buffer, "%p ", (void *)t);
1906 newline_and_indent (buffer, spc + 2);
1909 if (BLOCK_VARS (node))
1911 pp_string (buffer, "VARS: ");
1912 for (t = BLOCK_VARS (node); t; t = TREE_CHAIN (t))
1914 dump_generic_node (buffer, t, 0, flags, false);
1915 pp_string (buffer, " ");
1917 newline_and_indent (buffer, spc + 2);
1920 if (BLOCK_ABSTRACT_ORIGIN (node))
1922 pp_string (buffer, "ABSTRACT_ORIGIN: ");
1923 if (TREE_CODE (BLOCK_ABSTRACT_ORIGIN (node)) == BLOCK)
1924 pp_printf (buffer, "BLOCK %p",
1925 (void *)BLOCK_ABSTRACT_ORIGIN (node));
1926 else
1927 dump_generic_node (buffer, BLOCK_ABSTRACT_ORIGIN (node), 0, flags,
1928 false);
1929 newline_and_indent (buffer, spc + 2);
1932 break;
1934 default:
1935 NIY;
1938 if (is_stmt && is_expr)
1939 pp_semicolon (buffer);
1940 pp_write_text_to_stream (buffer);
1942 return spc;
1945 /* Print the declaration of a variable. */
1947 static void
1948 print_declaration (pretty_printer *buffer, tree t, int spc, int flags)
1950 INDENT (spc);
1952 if (TREE_CODE (t) == TYPE_DECL)
1953 pp_string (buffer, "typedef ");
1955 if (CODE_CONTAINS_STRUCT (TREE_CODE (t), TS_DECL_WRTL) && DECL_REGISTER (t))
1956 pp_string (buffer, "register ");
1958 if (TREE_PUBLIC (t) && DECL_EXTERNAL (t))
1959 pp_string (buffer, "extern ");
1960 else if (TREE_STATIC (t))
1961 pp_string (buffer, "static ");
1963 /* Print the type and name. */
1964 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
1966 tree tmp;
1968 /* Print array's type. */
1969 tmp = TREE_TYPE (t);
1970 while (TREE_CODE (TREE_TYPE (tmp)) == ARRAY_TYPE)
1971 tmp = TREE_TYPE (tmp);
1972 dump_generic_node (buffer, TREE_TYPE (tmp), spc, flags, false);
1974 /* Print variable's name. */
1975 pp_space (buffer);
1976 dump_generic_node (buffer, t, spc, flags, false);
1978 /* Print the dimensions. */
1979 tmp = TREE_TYPE (t);
1980 while (TREE_CODE (tmp) == ARRAY_TYPE)
1982 dump_array_domain (buffer, TYPE_DOMAIN (tmp), spc, flags);
1983 tmp = TREE_TYPE (tmp);
1986 else if (TREE_CODE (t) == FUNCTION_DECL)
1988 dump_generic_node (buffer, TREE_TYPE (TREE_TYPE (t)), spc, flags, false);
1989 pp_space (buffer);
1990 dump_decl_name (buffer, t, flags);
1991 dump_function_declaration (buffer, TREE_TYPE (t), spc, flags);
1993 else
1995 /* Print type declaration. */
1996 dump_generic_node (buffer, TREE_TYPE (t), spc, flags, false);
1998 /* Print variable's name. */
1999 pp_space (buffer);
2000 dump_generic_node (buffer, t, spc, flags, false);
2003 if (TREE_CODE (t) == VAR_DECL && DECL_HARD_REGISTER (t))
2005 pp_string (buffer, " __asm__ ");
2006 pp_character (buffer, '(');
2007 dump_generic_node (buffer, DECL_ASSEMBLER_NAME (t), spc, flags, false);
2008 pp_character (buffer, ')');
2011 /* The initial value of a function serves to determine wether the function
2012 is declared or defined. So the following does not apply to function
2013 nodes. */
2014 if (TREE_CODE (t) != FUNCTION_DECL)
2016 /* Print the initial value. */
2017 if (DECL_INITIAL (t))
2019 pp_space (buffer);
2020 pp_character (buffer, '=');
2021 pp_space (buffer);
2022 dump_generic_node (buffer, DECL_INITIAL (t), spc, flags, false);
2026 if (TREE_CODE (t) == VAR_DECL && DECL_HAS_VALUE_EXPR_P (t))
2028 pp_string (buffer, " [value-expr: ");
2029 dump_generic_node (buffer, DECL_VALUE_EXPR (t), spc, flags, false);
2030 pp_character (buffer, ']');
2033 pp_character (buffer, ';');
2037 /* Prints a structure: name, fields, and methods.
2038 FIXME: Still incomplete. */
2040 static void
2041 print_struct_decl (pretty_printer *buffer, tree node, int spc, int flags)
2043 /* Print the name of the structure. */
2044 if (TYPE_NAME (node))
2046 INDENT (spc);
2047 if (TREE_CODE (node) == RECORD_TYPE)
2048 pp_string (buffer, "struct ");
2049 else if ((TREE_CODE (node) == UNION_TYPE
2050 || TREE_CODE (node) == QUAL_UNION_TYPE))
2051 pp_string (buffer, "union ");
2053 dump_generic_node (buffer, TYPE_NAME (node), spc, 0, false);
2056 /* Print the contents of the structure. */
2057 pp_newline (buffer);
2058 INDENT (spc);
2059 pp_character (buffer, '{');
2060 pp_newline (buffer);
2062 /* Print the fields of the structure. */
2064 tree tmp;
2065 tmp = TYPE_FIELDS (node);
2066 while (tmp)
2068 /* Avoid to print recursively the structure. */
2069 /* FIXME : Not implemented correctly...,
2070 what about the case when we have a cycle in the contain graph? ...
2071 Maybe this could be solved by looking at the scope in which the
2072 structure was declared. */
2073 if (TREE_TYPE (tmp) != node
2074 || (TREE_CODE (TREE_TYPE (tmp)) == POINTER_TYPE
2075 && TREE_TYPE (TREE_TYPE (tmp)) != node))
2077 print_declaration (buffer, tmp, spc+2, flags);
2078 pp_newline (buffer);
2080 tmp = TREE_CHAIN (tmp);
2083 INDENT (spc);
2084 pp_character (buffer, '}');
2087 /* Return the priority of the operator OP.
2089 From lowest to highest precedence with either left-to-right (L-R)
2090 or right-to-left (R-L) associativity]:
2092 1 [L-R] ,
2093 2 [R-L] = += -= *= /= %= &= ^= |= <<= >>=
2094 3 [R-L] ?:
2095 4 [L-R] ||
2096 5 [L-R] &&
2097 6 [L-R] |
2098 7 [L-R] ^
2099 8 [L-R] &
2100 9 [L-R] == !=
2101 10 [L-R] < <= > >=
2102 11 [L-R] << >>
2103 12 [L-R] + -
2104 13 [L-R] * / %
2105 14 [R-L] ! ~ ++ -- + - * & (type) sizeof
2106 15 [L-R] fn() [] -> .
2108 unary +, - and * have higher precedence than the corresponding binary
2109 operators. */
2111 static int
2112 op_prio (tree op)
2114 if (op == NULL)
2115 return 9999;
2117 switch (TREE_CODE (op))
2119 case TREE_LIST:
2120 case COMPOUND_EXPR:
2121 case BIND_EXPR:
2122 return 1;
2124 case MODIFY_EXPR:
2125 case INIT_EXPR:
2126 return 2;
2128 case COND_EXPR:
2129 return 3;
2131 case TRUTH_OR_EXPR:
2132 case TRUTH_ORIF_EXPR:
2133 return 4;
2135 case TRUTH_AND_EXPR:
2136 case TRUTH_ANDIF_EXPR:
2137 return 5;
2139 case BIT_IOR_EXPR:
2140 return 6;
2142 case BIT_XOR_EXPR:
2143 case TRUTH_XOR_EXPR:
2144 return 7;
2146 case BIT_AND_EXPR:
2147 return 8;
2149 case EQ_EXPR:
2150 case NE_EXPR:
2151 return 9;
2153 case UNLT_EXPR:
2154 case UNLE_EXPR:
2155 case UNGT_EXPR:
2156 case UNGE_EXPR:
2157 case UNEQ_EXPR:
2158 case LTGT_EXPR:
2159 case ORDERED_EXPR:
2160 case UNORDERED_EXPR:
2161 case LT_EXPR:
2162 case LE_EXPR:
2163 case GT_EXPR:
2164 case GE_EXPR:
2165 return 10;
2167 case LSHIFT_EXPR:
2168 case RSHIFT_EXPR:
2169 case LROTATE_EXPR:
2170 case RROTATE_EXPR:
2171 return 11;
2173 case WIDEN_SUM_EXPR:
2174 case PLUS_EXPR:
2175 case MINUS_EXPR:
2176 return 12;
2178 case WIDEN_MULT_EXPR:
2179 case DOT_PROD_EXPR:
2180 case MULT_EXPR:
2181 case TRUNC_DIV_EXPR:
2182 case CEIL_DIV_EXPR:
2183 case FLOOR_DIV_EXPR:
2184 case ROUND_DIV_EXPR:
2185 case RDIV_EXPR:
2186 case EXACT_DIV_EXPR:
2187 case TRUNC_MOD_EXPR:
2188 case CEIL_MOD_EXPR:
2189 case FLOOR_MOD_EXPR:
2190 case ROUND_MOD_EXPR:
2191 return 13;
2193 case TRUTH_NOT_EXPR:
2194 case BIT_NOT_EXPR:
2195 case POSTINCREMENT_EXPR:
2196 case POSTDECREMENT_EXPR:
2197 case PREINCREMENT_EXPR:
2198 case PREDECREMENT_EXPR:
2199 case NEGATE_EXPR:
2200 case ALIGN_INDIRECT_REF:
2201 case MISALIGNED_INDIRECT_REF:
2202 case INDIRECT_REF:
2203 case ADDR_EXPR:
2204 case FLOAT_EXPR:
2205 case NOP_EXPR:
2206 case CONVERT_EXPR:
2207 case FIX_TRUNC_EXPR:
2208 case FIX_CEIL_EXPR:
2209 case FIX_FLOOR_EXPR:
2210 case FIX_ROUND_EXPR:
2211 case TARGET_EXPR:
2212 return 14;
2214 case CALL_EXPR:
2215 case ARRAY_REF:
2216 case ARRAY_RANGE_REF:
2217 case COMPONENT_REF:
2218 return 15;
2220 /* Special expressions. */
2221 case MIN_EXPR:
2222 case MAX_EXPR:
2223 case ABS_EXPR:
2224 case REALPART_EXPR:
2225 case IMAGPART_EXPR:
2226 case REDUC_MAX_EXPR:
2227 case REDUC_MIN_EXPR:
2228 case REDUC_PLUS_EXPR:
2229 case VEC_LSHIFT_EXPR:
2230 case VEC_RSHIFT_EXPR:
2231 return 16;
2233 case SAVE_EXPR:
2234 case NON_LVALUE_EXPR:
2235 return op_prio (TREE_OPERAND (op, 0));
2237 default:
2238 /* Return an arbitrarily high precedence to avoid surrounding single
2239 VAR_DECLs in ()s. */
2240 return 9999;
2245 /* Return the symbol associated with operator OP. */
2247 static const char *
2248 op_symbol_1 (enum tree_code code)
2250 switch (code)
2252 case MODIFY_EXPR:
2253 return "=";
2255 case TRUTH_OR_EXPR:
2256 case TRUTH_ORIF_EXPR:
2257 return "||";
2259 case TRUTH_AND_EXPR:
2260 case TRUTH_ANDIF_EXPR:
2261 return "&&";
2263 case BIT_IOR_EXPR:
2264 return "|";
2266 case TRUTH_XOR_EXPR:
2267 case BIT_XOR_EXPR:
2268 return "^";
2270 case ADDR_EXPR:
2271 case BIT_AND_EXPR:
2272 return "&";
2274 case ORDERED_EXPR:
2275 return "ord";
2276 case UNORDERED_EXPR:
2277 return "unord";
2279 case EQ_EXPR:
2280 return "==";
2281 case UNEQ_EXPR:
2282 return "u==";
2284 case NE_EXPR:
2285 return "!=";
2287 case LT_EXPR:
2288 return "<";
2289 case UNLT_EXPR:
2290 return "u<";
2292 case LE_EXPR:
2293 return "<=";
2294 case UNLE_EXPR:
2295 return "u<=";
2297 case GT_EXPR:
2298 return ">";
2299 case UNGT_EXPR:
2300 return "u>";
2302 case GE_EXPR:
2303 return ">=";
2304 case UNGE_EXPR:
2305 return "u>=";
2307 case LTGT_EXPR:
2308 return "<>";
2310 case LSHIFT_EXPR:
2311 return "<<";
2313 case RSHIFT_EXPR:
2314 return ">>";
2316 case LROTATE_EXPR:
2317 return "r<<";
2319 case RROTATE_EXPR:
2320 return "r>>";
2322 case VEC_LSHIFT_EXPR:
2323 return "v<<";
2325 case VEC_RSHIFT_EXPR:
2326 return "v>>";
2328 case PLUS_EXPR:
2329 return "+";
2331 case REDUC_PLUS_EXPR:
2332 return "r+";
2334 case WIDEN_SUM_EXPR:
2335 return "w+";
2337 case WIDEN_MULT_EXPR:
2338 return "w*";
2340 case NEGATE_EXPR:
2341 case MINUS_EXPR:
2342 return "-";
2344 case BIT_NOT_EXPR:
2345 return "~";
2347 case TRUTH_NOT_EXPR:
2348 return "!";
2350 case MULT_EXPR:
2351 case INDIRECT_REF:
2352 return "*";
2354 case ALIGN_INDIRECT_REF:
2355 return "A*";
2357 case MISALIGNED_INDIRECT_REF:
2358 return "M*";
2360 case TRUNC_DIV_EXPR:
2361 case RDIV_EXPR:
2362 return "/";
2364 case CEIL_DIV_EXPR:
2365 return "/[cl]";
2367 case FLOOR_DIV_EXPR:
2368 return "/[fl]";
2370 case ROUND_DIV_EXPR:
2371 return "/[rd]";
2373 case EXACT_DIV_EXPR:
2374 return "/[ex]";
2376 case TRUNC_MOD_EXPR:
2377 return "%";
2379 case CEIL_MOD_EXPR:
2380 return "%[cl]";
2382 case FLOOR_MOD_EXPR:
2383 return "%[fl]";
2385 case ROUND_MOD_EXPR:
2386 return "%[rd]";
2388 case PREDECREMENT_EXPR:
2389 return " --";
2391 case PREINCREMENT_EXPR:
2392 return " ++";
2394 case POSTDECREMENT_EXPR:
2395 return "-- ";
2397 case POSTINCREMENT_EXPR:
2398 return "++ ";
2400 case MAX_EXPR:
2401 return "max";
2403 case MIN_EXPR:
2404 return "min";
2406 default:
2407 return "<<< ??? >>>";
2411 static const char *
2412 op_symbol (tree op)
2414 return op_symbol_1 (TREE_CODE (op));
2417 /* Prints the name of a CALL_EXPR. */
2419 static void
2420 print_call_name (pretty_printer *buffer, tree node)
2422 tree op0;
2424 gcc_assert (TREE_CODE (node) == CALL_EXPR);
2426 op0 = TREE_OPERAND (node, 0);
2428 if (TREE_CODE (op0) == NON_LVALUE_EXPR)
2429 op0 = TREE_OPERAND (op0, 0);
2431 switch (TREE_CODE (op0))
2433 case VAR_DECL:
2434 case PARM_DECL:
2435 dump_function_name (buffer, op0);
2436 break;
2438 case ADDR_EXPR:
2439 case INDIRECT_REF:
2440 case NOP_EXPR:
2441 dump_generic_node (buffer, TREE_OPERAND (op0, 0), 0, 0, false);
2442 break;
2444 case COND_EXPR:
2445 pp_string (buffer, "(");
2446 dump_generic_node (buffer, TREE_OPERAND (op0, 0), 0, 0, false);
2447 pp_string (buffer, ") ? ");
2448 dump_generic_node (buffer, TREE_OPERAND (op0, 1), 0, 0, false);
2449 pp_string (buffer, " : ");
2450 dump_generic_node (buffer, TREE_OPERAND (op0, 2), 0, 0, false);
2451 break;
2453 case COMPONENT_REF:
2454 /* The function is a pointer contained in a structure. */
2455 if (TREE_CODE (TREE_OPERAND (op0, 0)) == INDIRECT_REF ||
2456 TREE_CODE (TREE_OPERAND (op0, 0)) == VAR_DECL)
2457 dump_function_name (buffer, TREE_OPERAND (op0, 1));
2458 else
2459 dump_generic_node (buffer, TREE_OPERAND (op0, 0), 0, 0, false);
2460 /* else
2461 We can have several levels of structures and a function
2462 pointer inside. This is not implemented yet... */
2463 /* NIY;*/
2464 break;
2466 case ARRAY_REF:
2467 if (TREE_CODE (TREE_OPERAND (op0, 0)) == VAR_DECL)
2468 dump_function_name (buffer, TREE_OPERAND (op0, 0));
2469 else
2470 dump_generic_node (buffer, op0, 0, 0, false);
2471 break;
2473 case SSA_NAME:
2474 case OBJ_TYPE_REF:
2475 dump_generic_node (buffer, op0, 0, 0, false);
2476 break;
2478 default:
2479 NIY;
2483 /* Parses the string STR and replaces new-lines by '\n', tabs by '\t', ... */
2485 static void
2486 pretty_print_string (pretty_printer *buffer, const char *str)
2488 if (str == NULL)
2489 return;
2491 while (*str)
2493 switch (str[0])
2495 case '\b':
2496 pp_string (buffer, "\\b");
2497 break;
2499 case '\f':
2500 pp_string (buffer, "\\f");
2501 break;
2503 case '\n':
2504 pp_string (buffer, "\\n");
2505 break;
2507 case '\r':
2508 pp_string (buffer, "\\r");
2509 break;
2511 case '\t':
2512 pp_string (buffer, "\\t");
2513 break;
2515 case '\v':
2516 pp_string (buffer, "\\v");
2517 break;
2519 case '\\':
2520 pp_string (buffer, "\\\\");
2521 break;
2523 case '\"':
2524 pp_string (buffer, "\\\"");
2525 break;
2527 case '\'':
2528 pp_string (buffer, "\\'");
2529 break;
2531 /* No need to handle \0; the loop terminates on \0. */
2533 case '\1':
2534 pp_string (buffer, "\\1");
2535 break;
2537 case '\2':
2538 pp_string (buffer, "\\2");
2539 break;
2541 case '\3':
2542 pp_string (buffer, "\\3");
2543 break;
2545 case '\4':
2546 pp_string (buffer, "\\4");
2547 break;
2549 case '\5':
2550 pp_string (buffer, "\\5");
2551 break;
2553 case '\6':
2554 pp_string (buffer, "\\6");
2555 break;
2557 case '\7':
2558 pp_string (buffer, "\\7");
2559 break;
2561 default:
2562 pp_character (buffer, str[0]);
2563 break;
2565 str++;
2569 static void
2570 maybe_init_pretty_print (FILE *file)
2572 if (!initialized)
2574 pp_construct (&buffer, /* prefix */NULL, /* line-width */0);
2575 pp_needs_newline (&buffer) = true;
2576 initialized = 1;
2579 buffer.buffer->stream = file;
2582 static void
2583 newline_and_indent (pretty_printer *buffer, int spc)
2585 pp_newline (buffer);
2586 INDENT (spc);
2589 static void
2590 dump_vops (pretty_printer *buffer, tree stmt, int spc, int flags)
2592 tree use;
2593 use_operand_p use_p;
2594 def_operand_p def_p;
2595 use_operand_p kill_p;
2596 ssa_op_iter iter;
2598 if (!ssa_operands_active ())
2599 return;
2601 FOR_EACH_SSA_MAYDEF_OPERAND (def_p, use_p, stmt, iter)
2603 pp_string (buffer, "# ");
2604 dump_generic_node (buffer, DEF_FROM_PTR (def_p),
2605 spc + 2, flags, false);
2606 pp_string (buffer, " = V_MAY_DEF <");
2607 dump_generic_node (buffer, USE_FROM_PTR (use_p),
2608 spc + 2, flags, false);
2609 pp_string (buffer, ">;");
2610 newline_and_indent (buffer, spc);
2613 FOR_EACH_SSA_MUSTDEF_OPERAND (def_p, kill_p, stmt, iter)
2615 pp_string (buffer, "# ");
2616 dump_generic_node (buffer, DEF_FROM_PTR (def_p),
2617 spc + 2, flags, false);
2618 pp_string (buffer, " = V_MUST_DEF <");
2619 dump_generic_node (buffer, USE_FROM_PTR (kill_p),
2620 spc + 2, flags, false);
2621 pp_string (buffer, ">;");
2622 newline_and_indent (buffer, spc);
2625 FOR_EACH_SSA_TREE_OPERAND (use, stmt, iter, SSA_OP_VUSE)
2627 pp_string (buffer, "# VUSE <");
2628 dump_generic_node (buffer, use, spc + 2, flags, false);
2629 pp_string (buffer, ">;");
2630 newline_and_indent (buffer, spc);
2634 /* Dumps basic block BB to FILE with details described by FLAGS and
2635 indented by INDENT spaces. */
2637 void
2638 dump_generic_bb (FILE *file, basic_block bb, int indent, int flags)
2640 maybe_init_pretty_print (file);
2641 dump_generic_bb_buff (&buffer, bb, indent, flags);
2642 pp_flush (&buffer);
2645 /* Dumps header of basic block BB to buffer BUFFER indented by INDENT
2646 spaces and details described by flags. */
2648 static void
2649 dump_bb_header (pretty_printer *buffer, basic_block bb, int indent, int flags)
2651 edge e;
2652 tree stmt;
2653 edge_iterator ei;
2655 if (flags & TDF_BLOCKS)
2657 INDENT (indent);
2658 pp_string (buffer, "# BLOCK ");
2659 pp_decimal_int (buffer, bb->index);
2660 if (bb->frequency)
2662 pp_string (buffer, " freq:");
2663 pp_decimal_int (buffer, bb->frequency);
2665 if (bb->count)
2667 pp_string (buffer, " count:");
2668 pp_widest_integer (buffer, bb->count);
2671 if (flags & TDF_LINENO)
2673 block_stmt_iterator bsi;
2675 for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
2676 if (get_lineno (bsi_stmt (bsi)) != -1)
2678 pp_string (buffer, ", starting at line ");
2679 pp_decimal_int (buffer, get_lineno (bsi_stmt (bsi)));
2680 break;
2683 newline_and_indent (buffer, indent);
2685 pp_string (buffer, "# PRED:");
2686 pp_write_text_to_stream (buffer);
2687 FOR_EACH_EDGE (e, ei, bb->preds)
2688 if (flags & TDF_SLIM)
2690 pp_string (buffer, " ");
2691 if (e->src == ENTRY_BLOCK_PTR)
2692 pp_string (buffer, "ENTRY");
2693 else
2694 pp_decimal_int (buffer, e->src->index);
2696 else
2697 dump_edge_info (buffer->buffer->stream, e, 0);
2698 pp_newline (buffer);
2700 else
2702 stmt = first_stmt (bb);
2703 if (!stmt || TREE_CODE (stmt) != LABEL_EXPR)
2705 INDENT (indent - 2);
2706 pp_string (buffer, "<bb ");
2707 pp_decimal_int (buffer, bb->index);
2708 pp_string (buffer, ">:");
2709 pp_newline (buffer);
2712 pp_write_text_to_stream (buffer);
2713 check_bb_profile (bb, buffer->buffer->stream);
2716 /* Dumps end of basic block BB to buffer BUFFER indented by INDENT
2717 spaces. */
2719 static void
2720 dump_bb_end (pretty_printer *buffer, basic_block bb, int indent, int flags)
2722 edge e;
2723 edge_iterator ei;
2725 INDENT (indent);
2726 pp_string (buffer, "# SUCC:");
2727 pp_write_text_to_stream (buffer);
2728 FOR_EACH_EDGE (e, ei, bb->succs)
2729 if (flags & TDF_SLIM)
2731 pp_string (buffer, " ");
2732 if (e->dest == EXIT_BLOCK_PTR)
2733 pp_string (buffer, "EXIT");
2734 else
2735 pp_decimal_int (buffer, e->dest->index);
2737 else
2738 dump_edge_info (buffer->buffer->stream, e, 1);
2739 pp_newline (buffer);
2742 /* Dumps phi nodes of basic block BB to buffer BUFFER with details described by
2743 FLAGS indented by INDENT spaces. */
2745 static void
2746 dump_phi_nodes (pretty_printer *buffer, basic_block bb, int indent, int flags)
2748 tree phi = phi_nodes (bb);
2749 if (!phi)
2750 return;
2752 for (; phi; phi = PHI_CHAIN (phi))
2754 if (is_gimple_reg (PHI_RESULT (phi)) || (flags & TDF_VOPS))
2756 INDENT (indent);
2757 pp_string (buffer, "# ");
2758 dump_generic_node (buffer, phi, indent, flags, false);
2759 pp_newline (buffer);
2764 /* Dump jump to basic block BB that is represented implicitly in the cfg
2765 to BUFFER. */
2767 static void
2768 pp_cfg_jump (pretty_printer *buffer, basic_block bb)
2770 tree stmt;
2772 stmt = first_stmt (bb);
2774 pp_string (buffer, "goto <bb ");
2775 pp_decimal_int (buffer, bb->index);
2776 pp_string (buffer, ">");
2777 if (stmt && TREE_CODE (stmt) == LABEL_EXPR)
2779 pp_string (buffer, " (");
2780 dump_generic_node (buffer, LABEL_EXPR_LABEL (stmt), 0, 0, false);
2781 pp_string (buffer, ")");
2783 pp_semicolon (buffer);
2786 /* Dump edges represented implicitly in basic block BB to BUFFER, indented
2787 by INDENT spaces, with details given by FLAGS. */
2789 static void
2790 dump_implicit_edges (pretty_printer *buffer, basic_block bb, int indent,
2791 int flags)
2793 edge e;
2794 edge_iterator ei;
2796 /* If there is a fallthru edge, we may need to add an artificial goto to the
2797 dump. */
2798 FOR_EACH_EDGE (e, ei, bb->succs)
2799 if (e->flags & EDGE_FALLTHRU)
2800 break;
2801 if (e && e->dest != bb->next_bb)
2803 INDENT (indent);
2805 if ((flags & TDF_LINENO)
2806 #ifdef USE_MAPPED_LOCATION
2807 && e->goto_locus != UNKNOWN_LOCATION
2808 #else
2809 && e->goto_locus
2810 #endif
2813 expanded_location goto_xloc;
2814 #ifdef USE_MAPPED_LOCATION
2815 goto_xloc = expand_location (e->goto_locus);
2816 #else
2817 goto_xloc = *e->goto_locus;
2818 #endif
2819 pp_character (buffer, '[');
2820 if (goto_xloc.file)
2822 pp_string (buffer, goto_xloc.file);
2823 pp_string (buffer, " : ");
2825 pp_decimal_int (buffer, goto_xloc.line);
2826 pp_string (buffer, "] ");
2829 pp_cfg_jump (buffer, e->dest);
2830 pp_newline (buffer);
2834 /* Dumps basic block BB to buffer BUFFER with details described by FLAGS and
2835 indented by INDENT spaces. */
2837 static void
2838 dump_generic_bb_buff (pretty_printer *buffer, basic_block bb,
2839 int indent, int flags)
2841 block_stmt_iterator bsi;
2842 tree stmt;
2843 int label_indent = indent - 2;
2845 if (label_indent < 0)
2846 label_indent = 0;
2848 dump_bb_header (buffer, bb, indent, flags);
2850 dump_phi_nodes (buffer, bb, indent, flags);
2852 for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
2854 int curr_indent;
2856 stmt = bsi_stmt (bsi);
2858 curr_indent = TREE_CODE (stmt) == LABEL_EXPR ? label_indent : indent;
2860 INDENT (curr_indent);
2861 dump_generic_node (buffer, stmt, curr_indent, flags, true);
2862 pp_newline (buffer);
2865 dump_implicit_edges (buffer, bb, indent, flags);
2867 if (flags & TDF_BLOCKS)
2868 dump_bb_end (buffer, bb, indent, flags);