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, '>');
1112 case ENTRY_VALUE_EXPR:
1117 pp_string (buffer, "COMPLEX_EXPR <");
1118 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1119 pp_string (buffer, ", ");
1120 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1121 pp_string (buffer, ">");
1125 pp_string (buffer, "CONJ_EXPR <");
1126 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1127 pp_string (buffer, ">");
1131 pp_string (buffer, "REALPART_EXPR <");
1132 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1133 pp_string (buffer, ">");
1137 pp_string (buffer, "IMAGPART_EXPR <");
1138 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1139 pp_string (buffer, ">");
1143 pp_string (buffer, "VA_ARG_EXPR <");
1144 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1145 pp_string (buffer, ">");
1148 case TRY_FINALLY_EXPR:
1149 case TRY_CATCH_EXPR:
1150 pp_string (buffer, "try");
1151 newline_and_indent (buffer, spc+2);
1152 pp_string (buffer, "{");
1153 newline_and_indent (buffer, spc+4);
1154 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc+4, flags, true);
1155 newline_and_indent (buffer, spc+2);
1156 pp_string (buffer, "}");
1157 newline_and_indent (buffer, spc);
1159 (TREE_CODE (node) == TRY_CATCH_EXPR) ? "catch" : "finally");
1160 newline_and_indent (buffer, spc+2);
1161 pp_string (buffer, "{");
1162 newline_and_indent (buffer, spc+4);
1163 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc+4, flags, true);
1164 newline_and_indent (buffer, spc+2);
1165 pp_string (buffer, "}");
1170 pp_string (buffer, "catch (");
1171 dump_generic_node (buffer, CATCH_TYPES (node), spc+2, flags, false);
1172 pp_string (buffer, ")");
1173 newline_and_indent (buffer, spc+2);
1174 pp_string (buffer, "{");
1175 newline_and_indent (buffer, spc+4);
1176 dump_generic_node (buffer, CATCH_BODY (node), spc+4, flags, true);
1177 newline_and_indent (buffer, spc+2);
1178 pp_string (buffer, "}");
1182 case EH_FILTER_EXPR:
1183 pp_string (buffer, "<<<eh_filter (");
1184 dump_generic_node (buffer, EH_FILTER_TYPES (node), spc+2, flags, false);
1185 pp_string (buffer, ")>>>");
1186 newline_and_indent (buffer, spc+2);
1187 pp_string (buffer, "{");
1188 newline_and_indent (buffer, spc+4);
1189 dump_generic_node (buffer, EH_FILTER_FAILURE (node), spc+4, flags, true);
1190 newline_and_indent (buffer, spc+2);
1191 pp_string (buffer, "}");
1195 case GOTO_SUBROUTINE_EXPR:
1200 op0 = TREE_OPERAND (node, 0);
1201 /* If this is for break or continue, don't bother printing it. */
1202 if (DECL_NAME (op0))
1204 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1205 if (strcmp (name, "break") == 0
1206 || strcmp (name, "continue") == 0)
1209 dump_generic_node (buffer, op0, spc, flags, false);
1210 pp_character (buffer, ':');
1211 if (DECL_NONLOCAL (op0))
1212 pp_string (buffer, " [non-local]");
1215 case LABELED_BLOCK_EXPR:
1216 op0 = LABELED_BLOCK_LABEL (node);
1217 /* If this is for break or continue, don't bother printing it. */
1218 if (DECL_NAME (op0))
1220 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1221 if (strcmp (name, "break") == 0
1222 || strcmp (name, "continue") == 0)
1224 dump_generic_node (buffer, LABELED_BLOCK_BODY (node), spc, flags, false);
1228 dump_generic_node (buffer, LABELED_BLOCK_LABEL (node), spc, flags, false);
1229 pp_string (buffer, ": {");
1230 if (!(flags & TDF_SLIM))
1231 newline_and_indent (buffer, spc+2);
1232 dump_generic_node (buffer, LABELED_BLOCK_BODY (node), spc+2, flags, true);
1234 newline_and_indent (buffer, spc);
1235 pp_character (buffer, '}');
1239 case EXIT_BLOCK_EXPR:
1240 op0 = LABELED_BLOCK_LABEL (EXIT_BLOCK_LABELED_BLOCK (node));
1241 /* If this is for a break or continue, print it accordingly. */
1242 if (DECL_NAME (op0))
1244 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1245 if (strcmp (name, "break") == 0
1246 || strcmp (name, "continue") == 0)
1248 pp_string (buffer, name);
1252 pp_string (buffer, "<<<exit block ");
1253 dump_generic_node (buffer, op0, spc, flags, false);
1254 pp_string (buffer, ">>>");
1258 pp_string (buffer, "<<<exception object>>>");
1262 pp_string (buffer, "<<<filter object>>>");
1266 pp_string (buffer, "while (1)");
1267 if (!(flags & TDF_SLIM))
1269 newline_and_indent (buffer, spc+2);
1270 pp_character (buffer, '{');
1271 newline_and_indent (buffer, spc+4);
1272 dump_generic_node (buffer, LOOP_EXPR_BODY (node), spc+4, flags, true);
1273 newline_and_indent (buffer, spc+2);
1274 pp_character (buffer, '}');
1280 pp_string (buffer, "return");
1281 op0 = TREE_OPERAND (node, 0);
1285 if (TREE_CODE (op0) == MODIFY_EXPR)
1286 dump_generic_node (buffer, TREE_OPERAND (op0, 1), spc, flags, false);
1288 dump_generic_node (buffer, op0, spc, flags, false);
1293 pp_string (buffer, "if (");
1294 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1295 pp_string (buffer, ") break");
1299 pp_string (buffer, "switch (");
1300 dump_generic_node (buffer, SWITCH_COND (node), spc, flags, false);
1301 pp_character (buffer, ')');
1302 if (!(flags & TDF_SLIM))
1304 newline_and_indent (buffer, spc+2);
1305 pp_character (buffer, '{');
1306 if (SWITCH_BODY (node))
1308 newline_and_indent (buffer, spc+4);
1309 dump_generic_node (buffer, SWITCH_BODY (node), spc+4, flags, true);
1313 tree vec = SWITCH_LABELS (node);
1314 size_t i, n = TREE_VEC_LENGTH (vec);
1315 for (i = 0; i < n; ++i)
1317 tree elt = TREE_VEC_ELT (vec, i);
1318 newline_and_indent (buffer, spc+4);
1319 dump_generic_node (buffer, elt, spc+4, flags, false);
1320 pp_string (buffer, " goto ");
1321 dump_generic_node (buffer, CASE_LABEL (elt), spc+4, flags, true);
1322 pp_semicolon (buffer);
1325 newline_and_indent (buffer, spc+2);
1326 pp_character (buffer, '}');
1332 op0 = GOTO_DESTINATION (node);
1333 if (TREE_CODE (op0) != SSA_NAME
1337 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1338 if (strcmp (name, "break") == 0
1339 || strcmp (name, "continue") == 0)
1341 pp_string (buffer, name);
1345 pp_string (buffer, "goto ");
1346 dump_generic_node (buffer, op0, spc, flags, false);
1350 pp_string (buffer, "resx");
1351 /* ??? Any sensible way to present the eh region? */
1355 pp_string (buffer, "__asm__");
1356 if (ASM_VOLATILE_P (node))
1357 pp_string (buffer, " __volatile__");
1358 pp_character (buffer, '(');
1359 dump_generic_node (buffer, ASM_STRING (node), spc, flags, false);
1360 pp_character (buffer, ':');
1361 dump_generic_node (buffer, ASM_OUTPUTS (node), spc, flags, false);
1362 pp_character (buffer, ':');
1363 dump_generic_node (buffer, ASM_INPUTS (node), spc, flags, false);
1364 if (ASM_CLOBBERS (node))
1366 pp_character (buffer, ':');
1367 dump_generic_node (buffer, ASM_CLOBBERS (node), spc, flags, false);
1369 pp_string (buffer, ")");
1372 case CASE_LABEL_EXPR:
1373 if (CASE_LOW (node) && CASE_HIGH (node))
1375 pp_string (buffer, "case ");
1376 dump_generic_node (buffer, CASE_LOW (node), spc, flags, false);
1377 pp_string (buffer, " ... ");
1378 dump_generic_node (buffer, CASE_HIGH (node), spc, flags, false);
1380 else if (CASE_LOW (node))
1382 pp_string (buffer, "case ");
1383 dump_generic_node (buffer, CASE_LOW (node), spc, flags, false);
1386 pp_string (buffer, "default ");
1387 pp_character (buffer, ':');
1391 pp_string (buffer, "OBJ_TYPE_REF(");
1392 dump_generic_node (buffer, OBJ_TYPE_REF_EXPR (node), spc, flags, false);
1393 pp_character (buffer, ';');
1394 dump_generic_node (buffer, OBJ_TYPE_REF_OBJECT (node), spc, flags, false);
1395 pp_character (buffer, '-');
1396 pp_character (buffer, '>');
1397 dump_generic_node (buffer, OBJ_TYPE_REF_TOKEN (node), spc, flags, false);
1398 pp_character (buffer, ')');
1405 dump_generic_node (buffer, PHI_RESULT (node), spc, flags, false);
1406 pp_string (buffer, " = PHI <");
1407 for (i = 0; i < PHI_NUM_ARGS (node); i++)
1409 dump_generic_node (buffer, PHI_ARG_DEF (node, i), spc, flags, false);
1410 pp_string (buffer, "(");
1411 pp_decimal_int (buffer, PHI_ARG_EDGE (node, i)->src->index);
1412 pp_string (buffer, ")");
1413 if (i < PHI_NUM_ARGS (node) - 1)
1414 pp_string (buffer, ", ");
1416 pp_string (buffer, ">;");
1421 dump_generic_node (buffer, SSA_NAME_VAR (node), spc, flags, false);
1422 pp_string (buffer, "_");
1423 pp_decimal_int (buffer, SSA_NAME_VERSION (node));
1427 pp_printf (buffer, "VH.%d", VALUE_HANDLE_ID (node));
1434 if (is_stmt && is_expr)
1435 pp_semicolon (buffer);
1436 pp_write_text_to_stream (buffer);
1441 /* Print the declaration of a variable. */
1444 print_declaration (pretty_printer *buffer, tree t, int spc, int flags)
1448 if (TREE_CODE (t) == TYPE_DECL)
1449 pp_string (buffer, "typedef ");
1451 if (DECL_REGISTER (t))
1452 pp_string (buffer, "register ");
1454 if (TREE_PUBLIC (t) && DECL_EXTERNAL (t))
1455 pp_string (buffer, "extern ");
1456 else if (TREE_STATIC (t))
1457 pp_string (buffer, "static ");
1459 /* Print the type and name. */
1460 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
1464 /* Print array's type. */
1465 tmp = TREE_TYPE (t);
1466 while (TREE_CODE (TREE_TYPE (tmp)) == ARRAY_TYPE)
1467 tmp = TREE_TYPE (tmp);
1468 dump_generic_node (buffer, TREE_TYPE (tmp), spc, flags, false);
1470 /* Print variable's name. */
1472 dump_generic_node (buffer, t, spc, flags, false);
1474 /* Print the dimensions. */
1475 tmp = TREE_TYPE (t);
1476 while (TREE_CODE (tmp) == ARRAY_TYPE)
1478 pp_character (buffer, '[');
1479 if (TYPE_DOMAIN (tmp))
1481 if (TREE_CODE (TYPE_SIZE (tmp)) == INTEGER_CST)
1482 pp_wide_integer (buffer,
1483 TREE_INT_CST_LOW (TYPE_SIZE (tmp)) /
1484 TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (tmp))));
1486 dump_generic_node (buffer, TYPE_SIZE_UNIT (tmp), spc, flags,
1489 pp_character (buffer, ']');
1490 tmp = TREE_TYPE (tmp);
1493 else if (TREE_CODE (t) == FUNCTION_DECL)
1495 dump_generic_node (buffer, TREE_TYPE (TREE_TYPE (t)), spc, flags, false);
1497 dump_decl_name (buffer, t, flags);
1498 dump_function_declaration (buffer, TREE_TYPE (t), spc, flags);
1502 /* Print type declaration. */
1503 dump_generic_node (buffer, TREE_TYPE (t), spc, flags, false);
1505 /* Print variable's name. */
1507 dump_generic_node (buffer, t, spc, flags, false);
1510 /* The initial value of a function serves to determine wether the function
1511 is declared or defined. So the following does not apply to function
1513 if (TREE_CODE (t) != FUNCTION_DECL)
1515 /* Print the initial value. */
1516 if (DECL_INITIAL (t))
1519 pp_character (buffer, '=');
1521 dump_generic_node (buffer, DECL_INITIAL (t), spc, flags, false);
1525 pp_character (buffer, ';');
1529 /* Prints a structure: name, fields, and methods.
1530 FIXME: Still incomplete. */
1533 print_struct_decl (pretty_printer *buffer, tree node, int spc, int flags)
1535 /* Print the name of the structure. */
1536 if (TYPE_NAME (node))
1539 if (TREE_CODE (node) == RECORD_TYPE)
1540 pp_string (buffer, "struct ");
1541 else if ((TREE_CODE (node) == UNION_TYPE
1542 || TREE_CODE (node) == QUAL_UNION_TYPE))
1543 pp_string (buffer, "union ");
1545 dump_generic_node (buffer, TYPE_NAME (node), spc, 0, false);
1548 /* Print the contents of the structure. */
1549 pp_newline (buffer);
1551 pp_character (buffer, '{');
1552 pp_newline (buffer);
1554 /* Print the fields of the structure. */
1557 tmp = TYPE_FIELDS (node);
1560 /* Avoid to print recursively the structure. */
1561 /* FIXME : Not implemented correctly...,
1562 what about the case when we have a cycle in the contain graph? ...
1563 Maybe this could be solved by looking at the scope in which the
1564 structure was declared. */
1565 if (TREE_TYPE (tmp) != node
1566 || (TREE_CODE (TREE_TYPE (tmp)) == POINTER_TYPE
1567 && TREE_TYPE (TREE_TYPE (tmp)) != node))
1569 print_declaration (buffer, tmp, spc+2, flags);
1570 pp_newline (buffer);
1572 tmp = TREE_CHAIN (tmp);
1576 pp_character (buffer, '}');
1579 /* Return the priority of the operator OP.
1581 From lowest to highest precedence with either left-to-right (L-R)
1582 or right-to-left (R-L) associativity]:
1585 2 [R-L] = += -= *= /= %= &= ^= |= <<= >>=
1597 14 [R-L] ! ~ ++ -- + - * & (type) sizeof
1598 15 [L-R] fn() [] -> .
1600 unary +, - and * have higher precedence than the corresponding binary
1609 switch (TREE_CODE (op))
1624 case TRUTH_ORIF_EXPR:
1627 case TRUTH_AND_EXPR:
1628 case TRUTH_ANDIF_EXPR:
1635 case TRUTH_XOR_EXPR:
1652 case UNORDERED_EXPR:
1670 case TRUNC_DIV_EXPR:
1672 case FLOOR_DIV_EXPR:
1673 case ROUND_DIV_EXPR:
1675 case EXACT_DIV_EXPR:
1676 case TRUNC_MOD_EXPR:
1678 case FLOOR_MOD_EXPR:
1679 case ROUND_MOD_EXPR:
1682 case TRUTH_NOT_EXPR:
1684 case POSTINCREMENT_EXPR:
1685 case POSTDECREMENT_EXPR:
1686 case PREINCREMENT_EXPR:
1687 case PREDECREMENT_EXPR:
1694 case FIX_TRUNC_EXPR:
1696 case FIX_FLOOR_EXPR:
1697 case FIX_ROUND_EXPR:
1703 case ARRAY_RANGE_REF:
1707 /* Special expressions. */
1716 case NON_LVALUE_EXPR:
1717 return op_prio (TREE_OPERAND (op, 0));
1720 /* Return an arbitrarily high precedence to avoid surrounding single
1721 VAR_DECLs in ()s. */
1727 /* Return the symbol associated with operator OP. */
1735 switch (TREE_CODE (op))
1741 case TRUTH_ORIF_EXPR:
1744 case TRUTH_AND_EXPR:
1745 case TRUTH_ANDIF_EXPR:
1751 case TRUTH_XOR_EXPR:
1761 case UNORDERED_EXPR:
1811 case TRUTH_NOT_EXPR:
1818 case TRUNC_DIV_EXPR:
1820 case FLOOR_DIV_EXPR:
1821 case ROUND_DIV_EXPR:
1823 case EXACT_DIV_EXPR:
1826 case TRUNC_MOD_EXPR:
1828 case FLOOR_MOD_EXPR:
1829 case ROUND_MOD_EXPR:
1832 case PREDECREMENT_EXPR:
1835 case PREINCREMENT_EXPR:
1838 case POSTDECREMENT_EXPR:
1841 case POSTINCREMENT_EXPR:
1844 case REFERENCE_EXPR:
1848 return "<<< ??? >>>";
1852 /* Prints the name of a CALL_EXPR. */
1855 print_call_name (pretty_printer *buffer, tree node)
1859 if (TREE_CODE (node) != CALL_EXPR)
1862 op0 = TREE_OPERAND (node, 0);
1864 if (TREE_CODE (op0) == NON_LVALUE_EXPR)
1865 op0 = TREE_OPERAND (op0, 0);
1867 switch (TREE_CODE (op0))
1871 PRINT_FUNCTION_NAME (op0);
1877 dump_generic_node (buffer, TREE_OPERAND (op0, 0), 0, 0, false);
1881 pp_string (buffer, "(");
1882 dump_generic_node (buffer, TREE_OPERAND (op0, 0), 0, 0, false);
1883 pp_string (buffer, ") ? ");
1884 dump_generic_node (buffer, TREE_OPERAND (op0, 1), 0, 0, false);
1885 pp_string (buffer, " : ");
1886 dump_generic_node (buffer, TREE_OPERAND (op0, 2), 0, 0, false);
1890 /* The function is a pointer contained in a structure. */
1891 if (TREE_CODE (TREE_OPERAND (op0, 0)) == INDIRECT_REF ||
1892 TREE_CODE (TREE_OPERAND (op0, 0)) == VAR_DECL)
1893 PRINT_FUNCTION_NAME (TREE_OPERAND (op0, 1));
1895 dump_generic_node (buffer, TREE_OPERAND (op0, 0), 0, 0, false);
1897 We can have several levels of structures and a function
1898 pointer inside. This is not implemented yet... */
1903 if (TREE_CODE (TREE_OPERAND (op0, 0)) == VAR_DECL)
1904 PRINT_FUNCTION_NAME (TREE_OPERAND (op0, 0));
1906 dump_generic_node (buffer, op0, 0, 0, false);
1911 dump_generic_node (buffer, op0, 0, 0, false);
1919 /* Parses the string STR and replaces new-lines by '\n', tabs by '\t', ... */
1922 pretty_print_string (pretty_printer *buffer, const char *str)
1932 pp_string (buffer, "\\b");
1936 pp_string (buffer, "\\f");
1940 pp_string (buffer, "\\n");
1944 pp_string (buffer, "\\r");
1948 pp_string (buffer, "\\t");
1952 pp_string (buffer, "\\v");
1956 pp_string (buffer, "\\\\");
1960 pp_string (buffer, "\\\"");
1964 pp_string (buffer, "\\'");
1968 pp_string (buffer, "\\0");
1972 pp_string (buffer, "\\1");
1976 pp_string (buffer, "\\2");
1980 pp_string (buffer, "\\3");
1984 pp_string (buffer, "\\4");
1988 pp_string (buffer, "\\5");
1992 pp_string (buffer, "\\6");
1996 pp_string (buffer, "\\7");
2000 pp_character (buffer, str[0]);
2008 maybe_init_pretty_print (FILE *file)
2012 pp_construct (&buffer, /* prefix */NULL, /* line-width */0);
2013 pp_needs_newline (&buffer) = true;
2017 buffer.buffer->stream = file;
2021 newline_and_indent (pretty_printer *buffer, int spc)
2023 pp_newline (buffer);
2028 dump_vops (pretty_printer *buffer, tree stmt, int spc, int flags)
2031 stmt_ann_t ann = stmt_ann (stmt);
2032 v_may_def_optype v_may_defs = V_MAY_DEF_OPS (ann);
2033 v_must_def_optype v_must_defs = V_MUST_DEF_OPS (ann);
2034 vuse_optype vuses = VUSE_OPS (ann);
2036 for (i = 0; i < NUM_V_MAY_DEFS (v_may_defs); i++)
2038 pp_string (buffer, "# ");
2039 dump_generic_node (buffer, V_MAY_DEF_RESULT (v_may_defs, i),
2040 spc + 2, flags, false);
2041 pp_string (buffer, " = V_MAY_DEF <");
2042 dump_generic_node (buffer, V_MAY_DEF_OP (v_may_defs, i),
2043 spc + 2, flags, false);
2044 pp_string (buffer, ">;");
2045 newline_and_indent (buffer, spc);
2048 for (i = 0; i < NUM_V_MUST_DEFS (v_must_defs); i++)
2050 tree v_must_def = V_MUST_DEF_OP (v_must_defs, i);
2051 pp_string (buffer, "# V_MUST_DEF <");
2052 dump_generic_node (buffer, v_must_def, spc + 2, flags, false);
2053 pp_string (buffer, ">;");
2054 newline_and_indent (buffer, spc);
2057 for (i = 0; i < NUM_VUSES (vuses); i++)
2059 tree vuse = VUSE_OP (vuses, i);
2060 pp_string (buffer, "# VUSE <");
2061 dump_generic_node (buffer, vuse, spc + 2, flags, false);
2062 pp_string (buffer, ">;");
2063 newline_and_indent (buffer, spc);
2067 /* Dumps basic block BB to FILE with details described by FLAGS and
2068 indented by INDENT spaces. */
2071 dump_generic_bb (FILE *file, basic_block bb, int indent, int flags)
2073 maybe_init_pretty_print (file);
2074 dumping_stmts = true;
2075 dump_generic_bb_buff (&buffer, bb, indent, flags);
2079 /* Dumps header of basic block BB to buffer BUFFER indented by INDENT
2080 spaces and details described by flags. */
2083 dump_bb_header (pretty_printer *buffer, basic_block bb, int indent, int flags)
2088 if (flags & TDF_BLOCKS)
2091 pp_string (buffer, "# BLOCK ");
2092 pp_decimal_int (buffer, bb->index);
2094 if (flags & TDF_LINENO)
2096 block_stmt_iterator bsi;
2098 for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
2099 if (get_lineno (bsi_stmt (bsi)) != -1)
2101 pp_string (buffer, ", starting at line ");
2102 pp_decimal_int (buffer, get_lineno (bsi_stmt (bsi)));
2106 newline_and_indent (buffer, indent);
2108 pp_string (buffer, "# PRED:");
2109 pp_write_text_to_stream (buffer);
2110 for (e = bb->pred; e; e = e->pred_next)
2111 if (flags & TDF_SLIM)
2113 pp_string (buffer, " ");
2114 if (e->src == ENTRY_BLOCK_PTR)
2115 pp_string (buffer, "ENTRY");
2117 pp_decimal_int (buffer, e->src->index);
2120 dump_edge_info (buffer->buffer->stream, e, 0);
2121 pp_newline (buffer);
2125 stmt = first_stmt (bb);
2126 if (!stmt || TREE_CODE (stmt) != LABEL_EXPR)
2128 INDENT (indent - 2);
2129 pp_string (buffer, "<bb ");
2130 pp_decimal_int (buffer, bb->index);
2131 pp_string (buffer, ">:");
2132 pp_newline (buffer);
2137 /* Dumps end of basic block BB to buffer BUFFER indented by INDENT
2141 dump_bb_end (pretty_printer *buffer, basic_block bb, int indent, int flags)
2146 pp_string (buffer, "# SUCC:");
2147 pp_write_text_to_stream (buffer);
2148 for (e = bb->succ; e; e = e->succ_next)
2149 if (flags & TDF_SLIM)
2151 pp_string (buffer, " ");
2152 if (e->dest == EXIT_BLOCK_PTR)
2153 pp_string (buffer, "EXIT");
2155 pp_decimal_int (buffer, e->dest->index);
2158 dump_edge_info (buffer->buffer->stream, e, 1);
2159 pp_newline (buffer);
2162 /* Dumps phi nodes of basic block BB to buffer BUFFER with details described by
2163 FLAGS indented by INDENT spaces. */
2166 dump_phi_nodes (pretty_printer *buffer, basic_block bb, int indent, int flags)
2168 tree phi = phi_nodes (bb);
2172 for (; phi; phi = PHI_CHAIN (phi))
2174 if (is_gimple_reg (PHI_RESULT (phi)) || (flags & TDF_VOPS))
2177 pp_string (buffer, "# ");
2178 dump_generic_node (buffer, phi, indent, flags, false);
2179 pp_newline (buffer);
2184 /* Dump jump to basic block BB that is represented implicitly in the cfg
2188 pp_cfg_jump (pretty_printer *buffer, basic_block bb)
2192 stmt = first_stmt (bb);
2194 pp_string (buffer, "goto <bb ");
2195 pp_decimal_int (buffer, bb->index);
2196 pp_string (buffer, ">");
2197 if (stmt && TREE_CODE (stmt) == LABEL_EXPR)
2199 pp_string (buffer, " (");
2200 dump_generic_node (buffer, LABEL_EXPR_LABEL (stmt), 0, 0, false);
2201 pp_string (buffer, ")");
2203 pp_semicolon (buffer);
2206 /* Dump edges represented implicitly in basic block BB to BUFFER, indented
2207 by INDENT spaces, with details given by FLAGS. */
2210 dump_implicit_edges (pretty_printer *buffer, basic_block bb, int indent,
2215 /* If there is a fallthru edge, we may need to add an artificial goto to the
2217 for (e = bb->succ; e; e = e->succ_next)
2218 if (e->flags & EDGE_FALLTHRU)
2220 if (e && e->dest != bb->next_bb)
2224 if ((flags & TDF_LINENO)
2225 #ifdef USE_MAPPED_LOCATION
2226 && e->goto_locus != UNKNOWN_LOCATION
2232 expanded_location goto_xloc;
2233 #ifdef USE_MAPPED_LOCATION
2234 goto_xloc = expand_location (e->goto_locus);
2236 goto_xloc = *e->goto_locus;
2238 pp_character (buffer, '[');
2241 pp_string (buffer, goto_xloc.file);
2242 pp_string (buffer, " : ");
2244 pp_decimal_int (buffer, goto_xloc.line);
2245 pp_string (buffer, "] ");
2248 pp_cfg_jump (buffer, e->dest);
2249 pp_newline (buffer);
2253 /* Dumps basic block BB to buffer BUFFER with details described by FLAGS and
2254 indented by INDENT spaces. */
2257 dump_generic_bb_buff (pretty_printer *buffer, basic_block bb,
2258 int indent, int flags)
2260 block_stmt_iterator bsi;
2262 int label_indent = indent - 2;
2264 if (label_indent < 0)
2267 dump_bb_header (buffer, bb, indent, flags);
2270 dump_phi_nodes (buffer, bb, indent, flags);
2272 for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
2276 stmt = bsi_stmt (bsi);
2278 curr_indent = TREE_CODE (stmt) == LABEL_EXPR ? label_indent : indent;
2280 INDENT (curr_indent);
2281 dump_generic_node (buffer, stmt, curr_indent, flags, true);
2282 pp_newline (buffer);
2285 dump_implicit_edges (buffer, bb, indent, flags);
2287 if (flags & TDF_BLOCKS)
2288 dump_bb_end (buffer, bb, indent, flags);