1 /* Pretty formatting of GENERIC trees in C syntax.
2 Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
3 Adapted from c-pretty-print.c by Diego Novillo <dnovillo@redhat.com>
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24 #include "coretypes.h"
28 #include "diagnostic.h"
31 #include "tree-flow.h"
32 #include "langhooks.h"
33 #include "tree-iterator.h"
35 /* Local functions, macros and variables. */
36 static int op_prio (tree);
37 static const char *op_symbol (tree);
38 static void pretty_print_string (pretty_printer *, const char*);
39 static void print_call_name (pretty_printer *, tree);
40 static void newline_and_indent (pretty_printer *, int);
41 static void maybe_init_pretty_print (FILE *);
42 static void print_declaration (pretty_printer *, tree, int, int);
43 static void print_struct_decl (pretty_printer *, tree, int, int);
44 static void do_niy (pretty_printer *, tree);
45 static void dump_vops (pretty_printer *, tree, int, int);
46 static void dump_generic_bb_buff (pretty_printer *, basic_block, int, int);
48 #define INDENT(SPACE) do { \
49 int i; for (i = 0; i<SPACE; i++) pp_space (buffer); } while (0)
51 #define NIY do_niy(buffer,node)
53 #define PRINT_FUNCTION_NAME(NODE) pp_printf \
54 (buffer, "%s", TREE_CODE (NODE) == NOP_EXPR ? \
55 lang_hooks.decl_printable_name (TREE_OPERAND (NODE, 0), 1) : \
56 lang_hooks.decl_printable_name (NODE, 1))
58 static pretty_printer buffer;
59 static int initialized = 0;
60 static bool dumping_stmts;
62 /* Try to print something for an unknown tree code. */
65 do_niy (pretty_printer *buffer, tree node)
69 pp_string (buffer, "<<< Unknown tree: ");
70 pp_string (buffer, tree_code_name[(int) TREE_CODE (node)]);
72 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (node))))
74 len = first_rtl_op (TREE_CODE (node));
75 for (i = 0; i < len; ++i)
77 newline_and_indent (buffer, 2);
78 dump_generic_node (buffer, TREE_OPERAND (node, i), 2, 0, false);
82 pp_string (buffer, " >>>\n");
86 debug_generic_expr (tree t)
88 print_generic_expr (stderr, t, TDF_VOPS|TDF_UID);
89 fprintf (stderr, "\n");
93 debug_generic_stmt (tree t)
95 print_generic_stmt (stderr, t, TDF_VOPS|TDF_UID);
96 fprintf (stderr, "\n");
99 /* Prints declaration DECL to the FILE with details specified by FLAGS. */
101 print_generic_decl (FILE *file, tree decl, int flags)
103 maybe_init_pretty_print (file);
104 dumping_stmts = true;
105 print_declaration (&buffer, decl, 2, flags);
106 pp_write_text_to_stream (&buffer);
109 /* Print tree T, and its successors, on file FILE. FLAGS specifies details
110 to show in the dump. See TDF_* in tree.h. */
113 print_generic_stmt (FILE *file, tree t, int flags)
115 maybe_init_pretty_print (file);
116 dumping_stmts = true;
117 dump_generic_node (&buffer, t, 0, flags, true);
121 /* Print tree T, and its successors, on file FILE. FLAGS specifies details
122 to show in the dump. See TDF_* in tree.h. The output is indented by
126 print_generic_stmt_indented (FILE *file, tree t, int flags, int indent)
130 maybe_init_pretty_print (file);
131 dumping_stmts = true;
133 for (i = 0; i < indent; i++)
135 dump_generic_node (&buffer, t, indent, flags, true);
139 /* Print a single expression T on file FILE. FLAGS specifies details to show
140 in the dump. See TDF_* in tree.h. */
143 print_generic_expr (FILE *file, tree t, int flags)
145 maybe_init_pretty_print (file);
146 dumping_stmts = false;
147 dump_generic_node (&buffer, t, 0, flags, false);
150 /* Dump the name of a _DECL node and its DECL_UID if TDF_UID is set
154 dump_decl_name (pretty_printer *buffer, tree node, int flags)
156 if (DECL_NAME (node))
157 pp_tree_identifier (buffer, DECL_NAME (node));
159 if ((flags & TDF_UID)
160 || DECL_NAME (node) == NULL_TREE)
162 if (TREE_CODE (node) == LABEL_DECL
163 && LABEL_DECL_UID (node) != -1)
164 pp_printf (buffer, "<L" HOST_WIDE_INT_PRINT_DEC ">",
165 LABEL_DECL_UID (node));
167 pp_printf (buffer, "<D%u>", DECL_UID (node));
171 /* Dump a function declaration. NODE is the FUNCTION_TYPE. BUFFER, SPC and
172 FLAGS are as in dump_generic_node. */
175 dump_function_declaration (pretty_printer *buffer, tree node,
178 bool wrote_arg = false;
182 pp_character (buffer, '(');
184 /* Print the argument types. The last element in the list is a VOID_TYPE.
185 The following avoids printing the last element. */
186 arg = TYPE_ARG_TYPES (node);
187 while (arg && TREE_CHAIN (arg) && arg != error_mark_node)
190 dump_generic_node (buffer, TREE_VALUE (arg), spc, flags, false);
191 arg = TREE_CHAIN (arg);
192 if (TREE_CHAIN (arg) && TREE_CODE (TREE_CHAIN (arg)) == TREE_LIST)
194 pp_character (buffer, ',');
200 pp_string (buffer, "void");
202 pp_character (buffer, ')');
205 /* Dump the node NODE on the pretty_printer BUFFER, SPC spaces of indent.
206 FLAGS specifies details to show in the dump (see TDF_* in tree.h). If
207 IS_STMT is true, the object printed is considered to be a statement
208 and it is terminated by ';' if appropriate. */
211 dump_generic_node (pretty_printer *buffer, tree node, int spc, int flags,
219 if (node == NULL_TREE)
222 is_expr = EXPR_P (node);
224 if (TREE_CODE (node) != ERROR_MARK
225 && is_gimple_stmt (node)
226 && (flags & TDF_VOPS)
228 dump_vops (buffer, node, spc, flags);
231 && (flags & TDF_LINENO)
232 && EXPR_HAS_LOCATION (node))
234 expanded_location xloc = expand_location (EXPR_LOCATION (node));
235 pp_character (buffer, '[');
238 pp_string (buffer, xloc.file);
239 pp_string (buffer, " : ");
241 pp_decimal_int (buffer, xloc.line);
242 pp_string (buffer, "] ");
245 switch (TREE_CODE (node))
248 pp_string (buffer, "<<< error >>>");
251 case IDENTIFIER_NODE:
252 pp_tree_identifier (buffer, node);
256 while (node && node != error_mark_node)
258 if (TREE_PURPOSE (node))
260 dump_generic_node (buffer, TREE_PURPOSE (node), spc, flags, false);
263 dump_generic_node (buffer, TREE_VALUE (node), spc, flags, false);
264 node = TREE_CHAIN (node);
265 if (node && TREE_CODE (node) == TREE_LIST)
267 pp_character (buffer, ',');
274 dump_generic_node (buffer, BINFO_TYPE (node), spc, flags, false);
290 unsigned int quals = TYPE_QUALS (node);
293 if (quals & TYPE_QUAL_CONST)
294 pp_string (buffer, "const ");
295 else if (quals & TYPE_QUAL_VOLATILE)
296 pp_string (buffer, "volatile ");
297 else if (quals & TYPE_QUAL_RESTRICT)
298 pp_string (buffer, "restrict ");
300 class = TREE_CODE_CLASS (TREE_CODE (node));
304 if (DECL_NAME (node))
305 dump_decl_name (buffer, node, flags);
307 pp_string (buffer, "<unnamed type decl>");
309 else if (class == 't')
311 if (TYPE_NAME (node))
313 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
314 pp_tree_identifier (buffer, TYPE_NAME (node));
315 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
316 && DECL_NAME (TYPE_NAME (node)))
317 dump_decl_name (buffer, TYPE_NAME (node), flags);
319 pp_string (buffer, "<unnamed type>");
322 pp_string (buffer, "<unnamed type>");
329 str = (TREE_CODE (node) == POINTER_TYPE ? "*" : "&");
331 if (TREE_CODE (TREE_TYPE (node)) == FUNCTION_TYPE)
333 tree fnode = TREE_TYPE (node);
335 dump_generic_node (buffer, TREE_TYPE (fnode), spc, flags, false);
337 pp_character (buffer, '(');
338 pp_string (buffer, str);
339 if (TYPE_NAME (node) && DECL_NAME (TYPE_NAME (node)))
340 dump_decl_name (buffer, TYPE_NAME (node), flags);
342 pp_printf (buffer, "<T%x>", TYPE_UID (node));
344 pp_character (buffer, ')');
345 dump_function_declaration (buffer, fnode, spc, flags);
349 unsigned int quals = TYPE_QUALS (node);
351 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
353 pp_string (buffer, str);
355 if (quals & TYPE_QUAL_CONST)
356 pp_string (buffer, " const");
357 else if (quals & TYPE_QUAL_VOLATILE)
358 pp_string (buffer, "volatile");
359 else if (quals & TYPE_QUAL_RESTRICT)
360 pp_string (buffer, " restrict");
369 dump_decl_name (buffer, TYPE_NAME (TYPE_METHOD_BASETYPE (node)), flags);
370 pp_string (buffer, "::");
381 /* Print the array type. */
382 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
384 /* Print the dimensions. */
386 while (tmp && TREE_CODE (tmp) == ARRAY_TYPE)
388 pp_character (buffer, '[');
391 tree size = TYPE_SIZE (tmp);
392 if (TREE_CODE (size) == INTEGER_CST)
393 pp_wide_integer (buffer,
394 TREE_INT_CST_LOW (TYPE_SIZE (tmp)) /
395 TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (tmp))));
396 else if (TREE_CODE (size) == MULT_EXPR)
397 dump_generic_node (buffer, TREE_OPERAND (size, 0), spc, flags, false);
400 pp_character (buffer, ']');
401 tmp = TREE_TYPE (tmp);
412 case QUAL_UNION_TYPE:
413 /* Print the name of the structure. */
414 if (TREE_CODE (node) == RECORD_TYPE)
415 pp_string (buffer, "struct ");
416 else if (TREE_CODE (node) == UNION_TYPE)
417 pp_string (buffer, "union ");
419 if (TYPE_NAME (node))
420 dump_generic_node (buffer, TYPE_NAME (node), spc, flags, false);
422 print_struct_decl (buffer, node, spc, flags);
430 if (TREE_CODE (TREE_TYPE (node)) == POINTER_TYPE)
432 /* In the case of a pointer, one may want to divide by the
433 size of the pointed-to type. Unfortunately, this not
434 straightforward. The C front-end maps expressions
439 in such a way that the two INTEGER_CST nodes for "5" have
440 different values but identical types. In the latter
441 case, the 5 is multiplied by sizeof (int) in c-common.c
442 (pointer_int_sum) to convert it to a byte address, and
443 yet the type of the node is left unchanged. Argh. What
444 is consistent though is that the number value corresponds
445 to bytes (UNITS) offset.
447 NB: Neither of the following divisors can be trivially
448 used to recover the original literal:
450 TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (node)))
451 TYPE_PRECISION (TREE_TYPE (TREE_TYPE (node))) */
452 pp_wide_integer (buffer, TREE_INT_CST_LOW (node));
453 pp_string (buffer, "B"); /* pseudo-unit */
455 else if (! host_integerp (node, 0))
459 if (tree_int_cst_sgn (val) < 0)
461 pp_character (buffer, '-');
462 val = build_int_2 (-TREE_INT_CST_LOW (val),
463 ~TREE_INT_CST_HIGH (val)
464 + !TREE_INT_CST_LOW (val));
466 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
469 static char format[10]; /* "%x%09999x\0" */
471 sprintf (format, "%%x%%0%dx", HOST_BITS_PER_INT / 4);
472 sprintf (pp_buffer (buffer)->digit_buffer, format,
473 TREE_INT_CST_HIGH (val),
474 TREE_INT_CST_LOW (val));
475 pp_string (buffer, pp_buffer (buffer)->digit_buffer);
479 pp_wide_integer (buffer, TREE_INT_CST_LOW (node));
483 /* Code copied from print_node. */
486 if (TREE_OVERFLOW (node))
487 pp_string (buffer, " overflow");
489 #if !defined(REAL_IS_NOT_DOUBLE) || defined(REAL_ARITHMETIC)
490 d = TREE_REAL_CST (node);
491 if (REAL_VALUE_ISINF (d))
492 pp_string (buffer, " Inf");
493 else if (REAL_VALUE_ISNAN (d))
494 pp_string (buffer, " Nan");
498 real_to_decimal (string, &d, sizeof (string), 0, 1);
499 pp_string (buffer, string);
504 unsigned char *p = (unsigned char *) &TREE_REAL_CST (node);
505 pp_string (buffer, "0x");
506 for (i = 0; i < sizeof TREE_REAL_CST (node); i++)
507 output_formatted_integer (buffer, "%02x", *p++);
514 pp_string (buffer, "__complex__ (");
515 dump_generic_node (buffer, TREE_REALPART (node), spc, flags, false);
516 pp_string (buffer, ", ");
517 dump_generic_node (buffer, TREE_IMAGPART (node), spc, flags, false);
518 pp_string (buffer, ")");
522 pp_string (buffer, "\"");
523 pretty_print_string (buffer, TREE_STRING_POINTER (node));
524 pp_string (buffer, "\"");
530 pp_string (buffer, "{ ");
531 for (elt = TREE_VECTOR_CST_ELTS (node); elt; elt = TREE_CHAIN (elt))
533 dump_generic_node (buffer, TREE_VALUE (elt), spc, flags, false);
534 if (TREE_CHAIN (elt))
535 pp_string (buffer, ", ");
537 pp_string (buffer, " }");
546 dump_decl_name (buffer, node, flags);
550 if (DECL_NAME (node))
551 dump_decl_name (buffer, node, flags);
552 else if (LABEL_DECL_UID (node) != -1)
553 pp_printf (buffer, "<L" HOST_WIDE_INT_PRINT_DEC ">",
554 LABEL_DECL_UID (node));
556 pp_printf (buffer, "<D%u>", DECL_UID (node));
560 if (DECL_IS_BUILTIN (node))
562 /* Don't print the declaration of built-in types. */
565 if (DECL_NAME (node))
566 dump_decl_name (buffer, node, flags);
569 if ((TREE_CODE (TREE_TYPE (node)) == RECORD_TYPE
570 || TREE_CODE (TREE_TYPE (node)) == UNION_TYPE)
571 && TYPE_METHODS (TREE_TYPE (node)))
573 /* The type is a c++ class: all structures have at least
575 pp_string (buffer, "class ");
576 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
581 (TREE_CODE (TREE_TYPE (node)) == UNION_TYPE
582 ? "union" : "struct "));
583 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
592 dump_decl_name (buffer, node, flags);
596 pp_string (buffer, "<retval>");
600 op0 = TREE_OPERAND (node, 0);
602 if (TREE_CODE (op0) == INDIRECT_REF)
604 op0 = TREE_OPERAND (op0, 0);
607 if (op_prio (op0) < op_prio (node))
608 pp_character (buffer, '(');
609 dump_generic_node (buffer, op0, spc, flags, false);
610 if (op_prio (op0) < op_prio (node))
611 pp_character (buffer, ')');
612 pp_string (buffer, str);
613 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
615 op0 = component_ref_field_offset (node);
616 if (op0 && TREE_CODE (op0) != INTEGER_CST)
618 pp_string (buffer, "{off: ");
619 dump_generic_node (buffer, op0, spc, flags, false);
620 pp_character (buffer, '}');
625 pp_string (buffer, "BIT_FIELD_REF <");
626 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
627 pp_string (buffer, ", ");
628 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
629 pp_string (buffer, ", ");
630 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
631 pp_string (buffer, ">");
639 case ARRAY_RANGE_REF:
640 op0 = TREE_OPERAND (node, 0);
641 if (op_prio (op0) < op_prio (node))
642 pp_character (buffer, '(');
643 dump_generic_node (buffer, op0, spc, flags, false);
644 if (op_prio (op0) < op_prio (node))
645 pp_character (buffer, ')');
646 pp_character (buffer, '[');
647 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
648 if (TREE_CODE (node) == ARRAY_RANGE_REF)
649 pp_string (buffer, " ...");
650 pp_character (buffer, ']');
652 op0 = array_ref_low_bound (node);
653 op1 = array_ref_element_size (node);
655 if (!integer_zerop (op0)
656 || (TYPE_SIZE_UNIT (TREE_TYPE (node))
657 && !operand_equal_p (op1, TYPE_SIZE_UNIT (TREE_TYPE (node)), 0)))
659 pp_string (buffer, "{lb: ");
660 dump_generic_node (buffer, op0, spc, flags, false);
661 pp_string (buffer, " sz: ");
662 dump_generic_node (buffer, op1, spc, flags, false);
663 pp_character (buffer, '}');
670 bool is_struct_init = FALSE;
671 pp_character (buffer, '{');
672 lnode = CONSTRUCTOR_ELTS (node);
673 if (TREE_CODE (TREE_TYPE (node)) == RECORD_TYPE
674 || TREE_CODE (TREE_TYPE (node)) == UNION_TYPE)
675 is_struct_init = TRUE;
676 while (lnode && lnode != error_mark_node)
679 if (TREE_PURPOSE (lnode) && is_struct_init)
681 pp_character (buffer, '.');
682 dump_generic_node (buffer, TREE_PURPOSE (lnode), spc, flags, false);
683 pp_string (buffer, "=");
685 val = TREE_VALUE (lnode);
686 if (val && TREE_CODE (val) == ADDR_EXPR)
687 if (TREE_CODE (TREE_OPERAND (val, 0)) == FUNCTION_DECL)
688 val = TREE_OPERAND (val, 0);
689 if (val && TREE_CODE (val) == FUNCTION_DECL)
691 dump_decl_name (buffer, val, flags);
695 dump_generic_node (buffer, TREE_VALUE (lnode), spc, flags, false);
697 lnode = TREE_CHAIN (lnode);
698 if (lnode && TREE_CODE (lnode) == TREE_LIST)
700 pp_character (buffer, ',');
704 pp_character (buffer, '}');
711 if (flags & TDF_SLIM)
713 pp_string (buffer, "<COMPOUND_EXPR>");
717 dump_generic_node (buffer, TREE_OPERAND (node, 0),
718 spc, flags, dumping_stmts);
720 newline_and_indent (buffer, spc);
723 pp_character (buffer, ',');
727 for (tp = &TREE_OPERAND (node, 1);
728 TREE_CODE (*tp) == COMPOUND_EXPR;
729 tp = &TREE_OPERAND (*tp, 1))
731 dump_generic_node (buffer, TREE_OPERAND (*tp, 0),
732 spc, flags, dumping_stmts);
734 newline_and_indent (buffer, spc);
737 pp_character (buffer, ',');
742 dump_generic_node (buffer, *tp, spc, flags, dumping_stmts);
748 tree_stmt_iterator si;
751 if ((flags & TDF_SLIM) || !dumping_stmts)
753 pp_string (buffer, "<STATEMENT_LIST>");
757 for (si = tsi_start (node); !tsi_end_p (si); tsi_next (&si))
760 newline_and_indent (buffer, spc);
763 dump_generic_node (buffer, tsi_stmt (si), spc, flags, true);
770 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
772 pp_character (buffer, '=');
774 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
778 pp_string (buffer, "TARGET_EXPR <");
779 dump_generic_node (buffer, TARGET_EXPR_SLOT (node), spc, flags, false);
780 pp_character (buffer, ',');
782 dump_generic_node (buffer, TARGET_EXPR_INITIAL (node), spc, flags, false);
783 pp_character (buffer, '>');
787 print_declaration (buffer, DECL_EXPR_DECL (node), spc, flags);
792 if (TREE_TYPE (node) == NULL || TREE_TYPE (node) == void_type_node)
794 pp_string (buffer, "if (");
795 dump_generic_node (buffer, COND_EXPR_COND (node), spc, flags, false);
796 pp_character (buffer, ')');
797 /* The lowered cond_exprs should always be printed in full. */
798 if (COND_EXPR_THEN (node)
799 && TREE_CODE (COND_EXPR_THEN (node)) == GOTO_EXPR
800 && COND_EXPR_ELSE (node)
801 && TREE_CODE (COND_EXPR_ELSE (node)) == GOTO_EXPR)
804 dump_generic_node (buffer, COND_EXPR_THEN (node), 0, flags, true);
805 pp_string (buffer, " else ");
806 dump_generic_node (buffer, COND_EXPR_ELSE (node), 0, flags, true);
808 else if (!(flags & TDF_SLIM))
810 /* Output COND_EXPR_THEN. */
811 if (COND_EXPR_THEN (node))
813 newline_and_indent (buffer, spc+2);
814 pp_character (buffer, '{');
815 newline_and_indent (buffer, spc+4);
816 dump_generic_node (buffer, COND_EXPR_THEN (node), spc+4,
818 newline_and_indent (buffer, spc+2);
819 pp_character (buffer, '}');
822 /* Output COND_EXPR_ELSE. */
823 if (COND_EXPR_ELSE (node))
825 newline_and_indent (buffer, spc);
826 pp_string (buffer, "else");
827 newline_and_indent (buffer, spc+2);
828 pp_character (buffer, '{');
829 newline_and_indent (buffer, spc+4);
830 dump_generic_node (buffer, COND_EXPR_ELSE (node), spc+4,
832 newline_and_indent (buffer, spc+2);
833 pp_character (buffer, '}');
840 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
842 pp_character (buffer, '?');
844 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
846 pp_character (buffer, ':');
848 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
853 pp_character (buffer, '{');
854 if (!(flags & TDF_SLIM))
856 if (BIND_EXPR_VARS (node))
860 for (op0 = BIND_EXPR_VARS (node); op0; op0 = TREE_CHAIN (op0))
862 print_declaration (buffer, op0, spc+2, flags);
867 newline_and_indent (buffer, spc+2);
868 dump_generic_node (buffer, BIND_EXPR_BODY (node), spc+2, flags, true);
869 newline_and_indent (buffer, spc);
870 pp_character (buffer, '}');
876 print_call_name (buffer, node);
878 /* Print parameters. */
880 pp_character (buffer, '(');
881 op1 = TREE_OPERAND (node, 1);
883 dump_generic_node (buffer, op1, spc, flags, false);
884 pp_character (buffer, ')');
886 op1 = TREE_OPERAND (node, 2);
889 pp_string (buffer, " [static-chain: ");
890 dump_generic_node (buffer, op1, spc, flags, false);
891 pp_character (buffer, ']');
894 if (CALL_EXPR_TAILCALL (node))
895 pp_string (buffer, " [tail call]");
898 case WITH_CLEANUP_EXPR:
902 case CLEANUP_POINT_EXPR:
903 pp_string (buffer, "<<cleanup_point ");
904 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
905 pp_string (buffer, ">>");
908 case PLACEHOLDER_EXPR:
909 pp_string (buffer, "<PLACEHOLDER_EXPR ");
910 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
911 pp_character (buffer, '>');
914 /* Binary arithmetic and logic expressions. */
935 case TRUTH_ANDIF_EXPR:
936 case TRUTH_ORIF_EXPR:
955 const char *op = op_symbol (node);
956 op0 = TREE_OPERAND (node, 0);
957 op1 = TREE_OPERAND (node, 1);
959 /* When the operands are expressions with less priority,
960 keep semantics of the tree representation. */
961 if (op_prio (op0) < op_prio (node))
963 pp_character (buffer, '(');
964 dump_generic_node (buffer, op0, spc, flags, false);
965 pp_character (buffer, ')');
968 dump_generic_node (buffer, op0, spc, flags, false);
971 pp_string (buffer, op);
974 /* When the operands are expressions with less priority,
975 keep semantics of the tree representation. */
976 if (op_prio (op1) < op_prio (node))
978 pp_character (buffer, '(');
979 dump_generic_node (buffer, op1, spc, flags, false);
980 pp_character (buffer, ')');
983 dump_generic_node (buffer, op1, spc, flags, false);
987 /* Unary arithmetic and logic expressions. */
993 case PREDECREMENT_EXPR:
994 case PREINCREMENT_EXPR:
996 if (TREE_CODE (node) == ADDR_EXPR
997 && (TREE_CODE (TREE_OPERAND (node, 0)) == STRING_CST
998 || TREE_CODE (TREE_OPERAND (node, 0)) == FUNCTION_DECL))
999 ; /* Do not output '&' for strings and function pointers. */
1001 pp_string (buffer, op_symbol (node));
1003 if (op_prio (TREE_OPERAND (node, 0)) < op_prio (node))
1005 pp_character (buffer, '(');
1006 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1007 pp_character (buffer, ')');
1010 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1013 case POSTDECREMENT_EXPR:
1014 case POSTINCREMENT_EXPR:
1015 if (op_prio (TREE_OPERAND (node, 0)) < op_prio (node))
1017 pp_character (buffer, '(');
1018 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1019 pp_character (buffer, ')');
1022 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1023 pp_string (buffer, op_symbol (node));
1027 pp_string (buffer, "MIN_EXPR <");
1028 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1029 pp_string (buffer, ", ");
1030 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1031 pp_character (buffer, '>');
1035 pp_string (buffer, "MAX_EXPR <");
1036 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1037 pp_string (buffer, ", ");
1038 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1039 pp_character (buffer, '>');
1043 pp_string (buffer, "ABS_EXPR <");
1044 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1045 pp_character (buffer, '>');
1064 case FIX_TRUNC_EXPR:
1066 case FIX_FLOOR_EXPR:
1067 case FIX_ROUND_EXPR:
1071 type = TREE_TYPE (node);
1072 op0 = TREE_OPERAND (node, 0);
1073 if (type != TREE_TYPE (op0))
1075 pp_character (buffer, '(');
1076 dump_generic_node (buffer, type, spc, flags, false);
1077 pp_string (buffer, ")");
1079 if (op_prio (op0) < op_prio (node))
1080 pp_character (buffer, '(');
1081 dump_generic_node (buffer, op0, spc, flags, false);
1082 if (op_prio (op0) < op_prio (node))
1083 pp_character (buffer, ')');
1086 case VIEW_CONVERT_EXPR:
1087 pp_string (buffer, "VIEW_CONVERT_EXPR<");
1088 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
1089 pp_string (buffer, ">(");
1090 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1091 pp_character (buffer, ')');
1094 case NON_LVALUE_EXPR:
1095 pp_string (buffer, "NON_LVALUE_EXPR <");
1096 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1097 pp_character (buffer, '>');
1101 pp_string (buffer, "SAVE_EXPR <");
1102 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1103 pp_character (buffer, '>');
1107 pp_string (buffer, "UNSAVE_EXPR <");
1108 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1109 pp_character (buffer, '>');
1116 case ENTRY_VALUE_EXPR:
1121 pp_string (buffer, "COMPLEX_EXPR <");
1122 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1123 pp_string (buffer, ", ");
1124 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1125 pp_string (buffer, ">");
1129 pp_string (buffer, "CONJ_EXPR <");
1130 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1131 pp_string (buffer, ">");
1135 pp_string (buffer, "REALPART_EXPR <");
1136 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1137 pp_string (buffer, ">");
1141 pp_string (buffer, "IMAGPART_EXPR <");
1142 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1143 pp_string (buffer, ">");
1147 pp_string (buffer, "VA_ARG_EXPR <");
1148 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1149 pp_string (buffer, ">");
1152 case TRY_FINALLY_EXPR:
1153 case TRY_CATCH_EXPR:
1154 pp_string (buffer, "try");
1155 newline_and_indent (buffer, spc+2);
1156 pp_string (buffer, "{");
1157 newline_and_indent (buffer, spc+4);
1158 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc+4, flags, true);
1159 newline_and_indent (buffer, spc+2);
1160 pp_string (buffer, "}");
1161 newline_and_indent (buffer, spc);
1163 (TREE_CODE (node) == TRY_CATCH_EXPR) ? "catch" : "finally");
1164 newline_and_indent (buffer, spc+2);
1165 pp_string (buffer, "{");
1166 newline_and_indent (buffer, spc+4);
1167 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc+4, flags, true);
1168 newline_and_indent (buffer, spc+2);
1169 pp_string (buffer, "}");
1174 pp_string (buffer, "catch (");
1175 dump_generic_node (buffer, CATCH_TYPES (node), spc+2, flags, false);
1176 pp_string (buffer, ")");
1177 newline_and_indent (buffer, spc+2);
1178 pp_string (buffer, "{");
1179 newline_and_indent (buffer, spc+4);
1180 dump_generic_node (buffer, CATCH_BODY (node), spc+4, flags, true);
1181 newline_and_indent (buffer, spc+2);
1182 pp_string (buffer, "}");
1186 case EH_FILTER_EXPR:
1187 pp_string (buffer, "<<<eh_filter (");
1188 dump_generic_node (buffer, EH_FILTER_TYPES (node), spc+2, flags, false);
1189 pp_string (buffer, ")>>>");
1190 newline_and_indent (buffer, spc+2);
1191 pp_string (buffer, "{");
1192 newline_and_indent (buffer, spc+4);
1193 dump_generic_node (buffer, EH_FILTER_FAILURE (node), spc+4, flags, true);
1194 newline_and_indent (buffer, spc+2);
1195 pp_string (buffer, "}");
1199 case GOTO_SUBROUTINE_EXPR:
1204 op0 = TREE_OPERAND (node, 0);
1205 /* If this is for break or continue, don't bother printing it. */
1206 if (DECL_NAME (op0))
1208 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1209 if (strcmp (name, "break") == 0
1210 || strcmp (name, "continue") == 0)
1213 dump_generic_node (buffer, op0, spc, flags, false);
1214 pp_character (buffer, ':');
1215 if (DECL_NONLOCAL (op0))
1216 pp_string (buffer, " [non-local]");
1219 case LABELED_BLOCK_EXPR:
1220 op0 = LABELED_BLOCK_LABEL (node);
1221 /* If this is for break or continue, don't bother printing it. */
1222 if (DECL_NAME (op0))
1224 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1225 if (strcmp (name, "break") == 0
1226 || strcmp (name, "continue") == 0)
1228 dump_generic_node (buffer, LABELED_BLOCK_BODY (node), spc, flags, false);
1232 dump_generic_node (buffer, LABELED_BLOCK_LABEL (node), spc, flags, false);
1233 pp_string (buffer, ": {");
1234 if (!(flags & TDF_SLIM))
1235 newline_and_indent (buffer, spc+2);
1236 dump_generic_node (buffer, LABELED_BLOCK_BODY (node), spc+2, flags, true);
1238 newline_and_indent (buffer, spc);
1239 pp_character (buffer, '}');
1243 case EXIT_BLOCK_EXPR:
1244 op0 = LABELED_BLOCK_LABEL (EXIT_BLOCK_LABELED_BLOCK (node));
1245 /* If this is for a break or continue, print it accordingly. */
1246 if (DECL_NAME (op0))
1248 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1249 if (strcmp (name, "break") == 0
1250 || strcmp (name, "continue") == 0)
1252 pp_string (buffer, name);
1256 pp_string (buffer, "<<<exit block ");
1257 dump_generic_node (buffer, op0, spc, flags, false);
1258 pp_string (buffer, ">>>");
1262 pp_string (buffer, "<<<exception object>>>");
1266 pp_string (buffer, "<<<filter object>>>");
1270 pp_string (buffer, "while (1)");
1271 if (!(flags & TDF_SLIM))
1273 newline_and_indent (buffer, spc+2);
1274 pp_character (buffer, '{');
1275 newline_and_indent (buffer, spc+4);
1276 dump_generic_node (buffer, LOOP_EXPR_BODY (node), spc+4, flags, true);
1277 newline_and_indent (buffer, spc+2);
1278 pp_character (buffer, '}');
1284 pp_string (buffer, "return");
1285 op0 = TREE_OPERAND (node, 0);
1289 if (TREE_CODE (op0) == MODIFY_EXPR)
1290 dump_generic_node (buffer, TREE_OPERAND (op0, 1), spc, flags, false);
1292 dump_generic_node (buffer, op0, spc, flags, false);
1297 pp_string (buffer, "if (");
1298 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1299 pp_string (buffer, ") break");
1303 pp_string (buffer, "switch (");
1304 dump_generic_node (buffer, SWITCH_COND (node), spc, flags, false);
1305 pp_character (buffer, ')');
1306 if (!(flags & TDF_SLIM))
1308 newline_and_indent (buffer, spc+2);
1309 pp_character (buffer, '{');
1310 if (SWITCH_BODY (node))
1312 newline_and_indent (buffer, spc+4);
1313 dump_generic_node (buffer, SWITCH_BODY (node), spc+4, flags, true);
1317 tree vec = SWITCH_LABELS (node);
1318 size_t i, n = TREE_VEC_LENGTH (vec);
1319 for (i = 0; i < n; ++i)
1321 tree elt = TREE_VEC_ELT (vec, i);
1322 newline_and_indent (buffer, spc+4);
1323 dump_generic_node (buffer, elt, spc+4, flags, false);
1324 pp_string (buffer, " goto ");
1325 dump_generic_node (buffer, CASE_LABEL (elt), spc+4, flags, true);
1326 pp_semicolon (buffer);
1329 newline_and_indent (buffer, spc+2);
1330 pp_character (buffer, '}');
1336 op0 = GOTO_DESTINATION (node);
1337 if (TREE_CODE (op0) != SSA_NAME
1341 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1342 if (strcmp (name, "break") == 0
1343 || strcmp (name, "continue") == 0)
1345 pp_string (buffer, name);
1349 pp_string (buffer, "goto ");
1350 dump_generic_node (buffer, op0, spc, flags, false);
1354 pp_string (buffer, "resx");
1355 /* ??? Any sensible way to present the eh region? */
1359 pp_string (buffer, "__asm__");
1360 if (ASM_VOLATILE_P (node))
1361 pp_string (buffer, " __volatile__");
1362 pp_character (buffer, '(');
1363 dump_generic_node (buffer, ASM_STRING (node), spc, flags, false);
1364 pp_character (buffer, ':');
1365 dump_generic_node (buffer, ASM_OUTPUTS (node), spc, flags, false);
1366 pp_character (buffer, ':');
1367 dump_generic_node (buffer, ASM_INPUTS (node), spc, flags, false);
1368 if (ASM_CLOBBERS (node))
1370 pp_character (buffer, ':');
1371 dump_generic_node (buffer, ASM_CLOBBERS (node), spc, flags, false);
1373 pp_string (buffer, ")");
1376 case CASE_LABEL_EXPR:
1377 if (CASE_LOW (node) && CASE_HIGH (node))
1379 pp_string (buffer, "case ");
1380 dump_generic_node (buffer, CASE_LOW (node), spc, flags, false);
1381 pp_string (buffer, " ... ");
1382 dump_generic_node (buffer, CASE_HIGH (node), spc, flags, false);
1384 else if (CASE_LOW (node))
1386 pp_string (buffer, "case ");
1387 dump_generic_node (buffer, CASE_LOW (node), spc, flags, false);
1390 pp_string (buffer, "default ");
1391 pp_character (buffer, ':');
1395 pp_string (buffer, "OBJ_TYPE_REF(");
1396 dump_generic_node (buffer, OBJ_TYPE_REF_EXPR (node), spc, flags, false);
1397 pp_character (buffer, ';');
1398 dump_generic_node (buffer, OBJ_TYPE_REF_OBJECT (node), spc, flags, false);
1399 pp_character (buffer, '-');
1400 pp_character (buffer, '>');
1401 dump_generic_node (buffer, OBJ_TYPE_REF_TOKEN (node), spc, flags, false);
1402 pp_character (buffer, ')');
1409 dump_generic_node (buffer, PHI_RESULT (node), spc, flags, false);
1410 pp_string (buffer, " = PHI <");
1411 for (i = 0; i < PHI_NUM_ARGS (node); i++)
1413 dump_generic_node (buffer, PHI_ARG_DEF (node, i), spc, flags, false);
1414 pp_string (buffer, "(");
1415 pp_decimal_int (buffer, PHI_ARG_EDGE (node, i)->src->index);
1416 pp_string (buffer, ")");
1417 if (i < PHI_NUM_ARGS (node) - 1)
1418 pp_string (buffer, ", ");
1420 pp_string (buffer, ">;");
1425 dump_generic_node (buffer, SSA_NAME_VAR (node), spc, flags, false);
1426 pp_string (buffer, "_");
1427 pp_decimal_int (buffer, SSA_NAME_VERSION (node));
1431 pp_printf (buffer, "VH.%d", VALUE_HANDLE_ID (node));
1438 if (is_stmt && is_expr)
1439 pp_semicolon (buffer);
1440 pp_write_text_to_stream (buffer);
1445 /* Print the declaration of a variable. */
1448 print_declaration (pretty_printer *buffer, tree t, int spc, int flags)
1452 if (TREE_CODE (t) == TYPE_DECL)
1453 pp_string (buffer, "typedef ");
1455 if (DECL_REGISTER (t))
1456 pp_string (buffer, "register ");
1458 if (TREE_PUBLIC (t) && DECL_EXTERNAL (t))
1459 pp_string (buffer, "extern ");
1460 else if (TREE_STATIC (t))
1461 pp_string (buffer, "static ");
1463 /* Print the type and name. */
1464 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
1468 /* Print array's type. */
1469 tmp = TREE_TYPE (t);
1470 while (TREE_CODE (TREE_TYPE (tmp)) == ARRAY_TYPE)
1471 tmp = TREE_TYPE (tmp);
1472 dump_generic_node (buffer, TREE_TYPE (tmp), spc, flags, false);
1474 /* Print variable's name. */
1476 dump_generic_node (buffer, t, spc, flags, false);
1478 /* Print the dimensions. */
1479 tmp = TREE_TYPE (t);
1480 while (TREE_CODE (tmp) == ARRAY_TYPE)
1482 pp_character (buffer, '[');
1483 if (TYPE_DOMAIN (tmp))
1485 if (TREE_CODE (TYPE_SIZE (tmp)) == INTEGER_CST)
1486 pp_wide_integer (buffer,
1487 TREE_INT_CST_LOW (TYPE_SIZE (tmp)) /
1488 TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (tmp))));
1490 dump_generic_node (buffer, TYPE_SIZE_UNIT (tmp), spc, flags,
1493 pp_character (buffer, ']');
1494 tmp = TREE_TYPE (tmp);
1497 else if (TREE_CODE (t) == FUNCTION_DECL)
1499 dump_generic_node (buffer, TREE_TYPE (TREE_TYPE (t)), spc, flags, false);
1501 dump_decl_name (buffer, t, flags);
1502 dump_function_declaration (buffer, TREE_TYPE (t), spc, flags);
1506 /* Print type declaration. */
1507 dump_generic_node (buffer, TREE_TYPE (t), spc, flags, false);
1509 /* Print variable's name. */
1511 dump_generic_node (buffer, t, spc, flags, false);
1514 /* The initial value of a function serves to determine wether the function
1515 is declared or defined. So the following does not apply to function
1517 if (TREE_CODE (t) != FUNCTION_DECL)
1519 /* Print the initial value. */
1520 if (DECL_INITIAL (t))
1523 pp_character (buffer, '=');
1525 dump_generic_node (buffer, DECL_INITIAL (t), spc, flags, false);
1529 pp_character (buffer, ';');
1533 /* Prints a structure: name, fields, and methods.
1534 FIXME: Still incomplete. */
1537 print_struct_decl (pretty_printer *buffer, tree node, int spc, int flags)
1539 /* Print the name of the structure. */
1540 if (TYPE_NAME (node))
1543 if (TREE_CODE (node) == RECORD_TYPE)
1544 pp_string (buffer, "struct ");
1545 else if ((TREE_CODE (node) == UNION_TYPE
1546 || TREE_CODE (node) == QUAL_UNION_TYPE))
1547 pp_string (buffer, "union ");
1549 dump_generic_node (buffer, TYPE_NAME (node), spc, 0, false);
1552 /* Print the contents of the structure. */
1553 pp_newline (buffer);
1555 pp_character (buffer, '{');
1556 pp_newline (buffer);
1558 /* Print the fields of the structure. */
1561 tmp = TYPE_FIELDS (node);
1564 /* Avoid to print recursively the structure. */
1565 /* FIXME : Not implemented correctly...,
1566 what about the case when we have a cycle in the contain graph? ...
1567 Maybe this could be solved by looking at the scope in which the
1568 structure was declared. */
1569 if (TREE_TYPE (tmp) != node
1570 || (TREE_CODE (TREE_TYPE (tmp)) == POINTER_TYPE
1571 && TREE_TYPE (TREE_TYPE (tmp)) != node))
1573 print_declaration (buffer, tmp, spc+2, flags);
1574 pp_newline (buffer);
1576 tmp = TREE_CHAIN (tmp);
1580 pp_character (buffer, '}');
1583 /* Return the priority of the operator OP.
1585 From lowest to highest precedence with either left-to-right (L-R)
1586 or right-to-left (R-L) associativity]:
1589 2 [R-L] = += -= *= /= %= &= ^= |= <<= >>=
1601 14 [R-L] ! ~ ++ -- + - * & (type) sizeof
1602 15 [L-R] fn() [] -> .
1604 unary +, - and * have higher precedence than the corresponding binary
1613 switch (TREE_CODE (op))
1628 case TRUTH_ORIF_EXPR:
1631 case TRUTH_AND_EXPR:
1632 case TRUTH_ANDIF_EXPR:
1639 case TRUTH_XOR_EXPR:
1656 case UNORDERED_EXPR:
1674 case TRUNC_DIV_EXPR:
1676 case FLOOR_DIV_EXPR:
1677 case ROUND_DIV_EXPR:
1679 case EXACT_DIV_EXPR:
1680 case TRUNC_MOD_EXPR:
1682 case FLOOR_MOD_EXPR:
1683 case ROUND_MOD_EXPR:
1686 case TRUTH_NOT_EXPR:
1688 case POSTINCREMENT_EXPR:
1689 case POSTDECREMENT_EXPR:
1690 case PREINCREMENT_EXPR:
1691 case PREDECREMENT_EXPR:
1698 case FIX_TRUNC_EXPR:
1700 case FIX_FLOOR_EXPR:
1701 case FIX_ROUND_EXPR:
1707 case ARRAY_RANGE_REF:
1711 /* Special expressions. */
1720 case NON_LVALUE_EXPR:
1721 return op_prio (TREE_OPERAND (op, 0));
1724 /* Return an arbitrarily high precedence to avoid surrounding single
1725 VAR_DECLs in ()s. */
1731 /* Return the symbol associated with operator OP. */
1739 switch (TREE_CODE (op))
1745 case TRUTH_ORIF_EXPR:
1748 case TRUTH_AND_EXPR:
1749 case TRUTH_ANDIF_EXPR:
1755 case TRUTH_XOR_EXPR:
1765 case UNORDERED_EXPR:
1815 case TRUTH_NOT_EXPR:
1822 case TRUNC_DIV_EXPR:
1824 case FLOOR_DIV_EXPR:
1825 case ROUND_DIV_EXPR:
1827 case EXACT_DIV_EXPR:
1830 case TRUNC_MOD_EXPR:
1832 case FLOOR_MOD_EXPR:
1833 case ROUND_MOD_EXPR:
1836 case PREDECREMENT_EXPR:
1839 case PREINCREMENT_EXPR:
1842 case POSTDECREMENT_EXPR:
1845 case POSTINCREMENT_EXPR:
1848 case REFERENCE_EXPR:
1852 return "<<< ??? >>>";
1856 /* Prints the name of a CALL_EXPR. */
1859 print_call_name (pretty_printer *buffer, tree node)
1863 if (TREE_CODE (node) != CALL_EXPR)
1866 op0 = TREE_OPERAND (node, 0);
1868 if (TREE_CODE (op0) == NON_LVALUE_EXPR)
1869 op0 = TREE_OPERAND (op0, 0);
1871 switch (TREE_CODE (op0))
1875 PRINT_FUNCTION_NAME (op0);
1881 dump_generic_node (buffer, TREE_OPERAND (op0, 0), 0, 0, false);
1885 pp_string (buffer, "(");
1886 dump_generic_node (buffer, TREE_OPERAND (op0, 0), 0, 0, false);
1887 pp_string (buffer, ") ? ");
1888 dump_generic_node (buffer, TREE_OPERAND (op0, 1), 0, 0, false);
1889 pp_string (buffer, " : ");
1890 dump_generic_node (buffer, TREE_OPERAND (op0, 2), 0, 0, false);
1894 /* The function is a pointer contained in a structure. */
1895 if (TREE_CODE (TREE_OPERAND (op0, 0)) == INDIRECT_REF ||
1896 TREE_CODE (TREE_OPERAND (op0, 0)) == VAR_DECL)
1897 PRINT_FUNCTION_NAME (TREE_OPERAND (op0, 1));
1899 dump_generic_node (buffer, TREE_OPERAND (op0, 0), 0, 0, false);
1901 We can have several levels of structures and a function
1902 pointer inside. This is not implemented yet... */
1907 if (TREE_CODE (TREE_OPERAND (op0, 0)) == VAR_DECL)
1908 PRINT_FUNCTION_NAME (TREE_OPERAND (op0, 0));
1910 dump_generic_node (buffer, op0, 0, 0, false);
1915 dump_generic_node (buffer, op0, 0, 0, false);
1923 /* Parses the string STR and replaces new-lines by '\n', tabs by '\t', ... */
1926 pretty_print_string (pretty_printer *buffer, const char *str)
1936 pp_string (buffer, "\\b");
1940 pp_string (buffer, "\\f");
1944 pp_string (buffer, "\\n");
1948 pp_string (buffer, "\\r");
1952 pp_string (buffer, "\\t");
1956 pp_string (buffer, "\\v");
1960 pp_string (buffer, "\\\\");
1964 pp_string (buffer, "\\\"");
1968 pp_string (buffer, "\\'");
1972 pp_string (buffer, "\\0");
1976 pp_string (buffer, "\\1");
1980 pp_string (buffer, "\\2");
1984 pp_string (buffer, "\\3");
1988 pp_string (buffer, "\\4");
1992 pp_string (buffer, "\\5");
1996 pp_string (buffer, "\\6");
2000 pp_string (buffer, "\\7");
2004 pp_character (buffer, str[0]);
2012 maybe_init_pretty_print (FILE *file)
2016 pp_construct (&buffer, /* prefix */NULL, /* line-width */0);
2017 pp_needs_newline (&buffer) = true;
2021 buffer.buffer->stream = file;
2025 newline_and_indent (pretty_printer *buffer, int spc)
2027 pp_newline (buffer);
2032 dump_vops (pretty_printer *buffer, tree stmt, int spc, int flags)
2035 stmt_ann_t ann = stmt_ann (stmt);
2036 v_may_def_optype v_may_defs = V_MAY_DEF_OPS (ann);
2037 v_must_def_optype v_must_defs = V_MUST_DEF_OPS (ann);
2038 vuse_optype vuses = VUSE_OPS (ann);
2040 for (i = 0; i < NUM_V_MAY_DEFS (v_may_defs); i++)
2042 pp_string (buffer, "# ");
2043 dump_generic_node (buffer, V_MAY_DEF_RESULT (v_may_defs, i),
2044 spc + 2, flags, false);
2045 pp_string (buffer, " = V_MAY_DEF <");
2046 dump_generic_node (buffer, V_MAY_DEF_OP (v_may_defs, i),
2047 spc + 2, flags, false);
2048 pp_string (buffer, ">;");
2049 newline_and_indent (buffer, spc);
2052 for (i = 0; i < NUM_V_MUST_DEFS (v_must_defs); i++)
2054 tree v_must_def = V_MUST_DEF_OP (v_must_defs, i);
2055 pp_string (buffer, "# V_MUST_DEF <");
2056 dump_generic_node (buffer, v_must_def, spc + 2, flags, false);
2057 pp_string (buffer, ">;");
2058 newline_and_indent (buffer, spc);
2061 for (i = 0; i < NUM_VUSES (vuses); i++)
2063 tree vuse = VUSE_OP (vuses, i);
2064 pp_string (buffer, "# VUSE <");
2065 dump_generic_node (buffer, vuse, spc + 2, flags, false);
2066 pp_string (buffer, ">;");
2067 newline_and_indent (buffer, spc);
2071 /* Dumps basic block BB to FILE with details described by FLAGS and
2072 indented by INDENT spaces. */
2075 dump_generic_bb (FILE *file, basic_block bb, int indent, int flags)
2077 maybe_init_pretty_print (file);
2078 dumping_stmts = true;
2079 dump_generic_bb_buff (&buffer, bb, indent, flags);
2083 /* Dumps header of basic block BB to buffer BUFFER indented by INDENT
2084 spaces and details described by flags. */
2087 dump_bb_header (pretty_printer *buffer, basic_block bb, int indent, int flags)
2092 if (flags & TDF_BLOCKS)
2095 pp_string (buffer, "# BLOCK ");
2096 pp_decimal_int (buffer, bb->index);
2098 if (flags & TDF_LINENO)
2100 block_stmt_iterator bsi;
2102 for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
2103 if (get_lineno (bsi_stmt (bsi)) != -1)
2105 pp_string (buffer, ", starting at line ");
2106 pp_decimal_int (buffer, get_lineno (bsi_stmt (bsi)));
2110 newline_and_indent (buffer, indent);
2112 pp_string (buffer, "# PRED:");
2113 pp_write_text_to_stream (buffer);
2114 for (e = bb->pred; e; e = e->pred_next)
2115 if (flags & TDF_SLIM)
2117 pp_string (buffer, " ");
2118 if (e->src == ENTRY_BLOCK_PTR)
2119 pp_string (buffer, "ENTRY");
2121 pp_decimal_int (buffer, e->src->index);
2124 dump_edge_info (buffer->buffer->stream, e, 0);
2125 pp_newline (buffer);
2129 stmt = first_stmt (bb);
2130 if (!stmt || TREE_CODE (stmt) != LABEL_EXPR)
2132 INDENT (indent - 2);
2133 pp_string (buffer, "<bb ");
2134 pp_decimal_int (buffer, bb->index);
2135 pp_string (buffer, ">:");
2136 pp_newline (buffer);
2141 /* Dumps end of basic block BB to buffer BUFFER indented by INDENT
2145 dump_bb_end (pretty_printer *buffer, basic_block bb, int indent, int flags)
2150 pp_string (buffer, "# SUCC:");
2151 pp_write_text_to_stream (buffer);
2152 for (e = bb->succ; e; e = e->succ_next)
2153 if (flags & TDF_SLIM)
2155 pp_string (buffer, " ");
2156 if (e->dest == EXIT_BLOCK_PTR)
2157 pp_string (buffer, "EXIT");
2159 pp_decimal_int (buffer, e->dest->index);
2162 dump_edge_info (buffer->buffer->stream, e, 1);
2163 pp_newline (buffer);
2166 /* Dumps phi nodes of basic block BB to buffer BUFFER with details described by
2167 FLAGS indented by INDENT spaces. */
2170 dump_phi_nodes (pretty_printer *buffer, basic_block bb, int indent, int flags)
2172 tree phi = phi_nodes (bb);
2176 for (; phi; phi = PHI_CHAIN (phi))
2178 if (is_gimple_reg (PHI_RESULT (phi)) || (flags & TDF_VOPS))
2181 pp_string (buffer, "# ");
2182 dump_generic_node (buffer, phi, indent, flags, false);
2183 pp_newline (buffer);
2188 /* Dump jump to basic block BB that is represented implicitly in the cfg
2192 pp_cfg_jump (pretty_printer *buffer, basic_block bb)
2196 stmt = first_stmt (bb);
2198 pp_string (buffer, "goto <bb ");
2199 pp_decimal_int (buffer, bb->index);
2200 pp_string (buffer, ">");
2201 if (stmt && TREE_CODE (stmt) == LABEL_EXPR)
2203 pp_string (buffer, " (");
2204 dump_generic_node (buffer, LABEL_EXPR_LABEL (stmt), 0, 0, false);
2205 pp_string (buffer, ")");
2207 pp_semicolon (buffer);
2210 /* Dump edges represented implicitly in basic block BB to BUFFER, indented
2211 by INDENT spaces, with details given by FLAGS. */
2214 dump_implicit_edges (pretty_printer *buffer, basic_block bb, int indent,
2219 /* If there is a fallthru edge, we may need to add an artificial goto to the
2221 for (e = bb->succ; e; e = e->succ_next)
2222 if (e->flags & EDGE_FALLTHRU)
2224 if (e && e->dest != bb->next_bb)
2228 if ((flags & TDF_LINENO)
2229 #ifdef USE_MAPPED_LOCATION
2230 && e->goto_locus != UNKNOWN_LOCATION
2236 expanded_location goto_xloc;
2237 #ifdef USE_MAPPED_LOCATION
2238 goto_xloc = expand_location (e->goto_locus);
2240 goto_xloc = *e->goto_locus;
2242 pp_character (buffer, '[');
2245 pp_string (buffer, goto_xloc.file);
2246 pp_string (buffer, " : ");
2248 pp_decimal_int (buffer, goto_xloc.line);
2249 pp_string (buffer, "] ");
2252 pp_cfg_jump (buffer, e->dest);
2253 pp_newline (buffer);
2257 /* Dumps basic block BB to buffer BUFFER with details described by FLAGS and
2258 indented by INDENT spaces. */
2261 dump_generic_bb_buff (pretty_printer *buffer, basic_block bb,
2262 int indent, int flags)
2264 block_stmt_iterator bsi;
2266 int label_indent = indent - 2;
2268 if (label_indent < 0)
2271 dump_bb_header (buffer, bb, indent, flags);
2274 dump_phi_nodes (buffer, bb, indent, flags);
2276 for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
2280 stmt = bsi_stmt (bsi);
2282 curr_indent = TREE_CODE (stmt) == LABEL_EXPR ? label_indent : indent;
2284 INDENT (curr_indent);
2285 dump_generic_node (buffer, stmt, curr_indent, flags, true);
2286 pp_newline (buffer);
2289 dump_implicit_edges (buffer, bb, indent, flags);
2291 if (flags & TDF_BLOCKS)
2292 dump_bb_end (buffer, bb, indent, flags);