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 innermost component type. */
382 for (tmp = TREE_TYPE (node); TREE_CODE (tmp) == ARRAY_TYPE;
383 tmp = TREE_TYPE (tmp))
385 dump_generic_node (buffer, tmp, spc, flags, false);
387 /* Print the dimensions. */
388 for (tmp = node; TREE_CODE (tmp) == ARRAY_TYPE;
389 tmp = TREE_TYPE (tmp))
391 tree domain = TYPE_DOMAIN (tmp);
393 pp_character (buffer, '[');
396 if (TYPE_MIN_VALUE (domain)
397 && !integer_zerop (TYPE_MIN_VALUE (domain)))
399 dump_generic_node (buffer, TYPE_MIN_VALUE (domain),
401 pp_string (buffer, " .. ");
404 if (TYPE_MAX_VALUE (domain))
405 dump_generic_node (buffer, TYPE_MAX_VALUE (domain),
409 pp_string (buffer, "<unknown>");
411 pp_character (buffer, ']');
422 case QUAL_UNION_TYPE:
423 /* Print the name of the structure. */
424 if (TREE_CODE (node) == RECORD_TYPE)
425 pp_string (buffer, "struct ");
426 else if (TREE_CODE (node) == UNION_TYPE)
427 pp_string (buffer, "union ");
429 if (TYPE_NAME (node))
430 dump_generic_node (buffer, TYPE_NAME (node), spc, flags, false);
432 print_struct_decl (buffer, node, spc, flags);
440 if (TREE_CODE (TREE_TYPE (node)) == POINTER_TYPE)
442 /* In the case of a pointer, one may want to divide by the
443 size of the pointed-to type. Unfortunately, this not
444 straightforward. The C front-end maps expressions
449 in such a way that the two INTEGER_CST nodes for "5" have
450 different values but identical types. In the latter
451 case, the 5 is multiplied by sizeof (int) in c-common.c
452 (pointer_int_sum) to convert it to a byte address, and
453 yet the type of the node is left unchanged. Argh. What
454 is consistent though is that the number value corresponds
455 to bytes (UNITS) offset.
457 NB: Neither of the following divisors can be trivially
458 used to recover the original literal:
460 TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (node)))
461 TYPE_PRECISION (TREE_TYPE (TREE_TYPE (node))) */
462 pp_wide_integer (buffer, TREE_INT_CST_LOW (node));
463 pp_string (buffer, "B"); /* pseudo-unit */
465 else if (! host_integerp (node, 0))
469 if (tree_int_cst_sgn (val) < 0)
471 pp_character (buffer, '-');
472 val = build_int_2 (-TREE_INT_CST_LOW (val),
473 ~TREE_INT_CST_HIGH (val)
474 + !TREE_INT_CST_LOW (val));
476 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
479 static char format[10]; /* "%x%09999x\0" */
481 sprintf (format, "%%x%%0%dx", HOST_BITS_PER_INT / 4);
482 sprintf (pp_buffer (buffer)->digit_buffer, format,
483 TREE_INT_CST_HIGH (val),
484 TREE_INT_CST_LOW (val));
485 pp_string (buffer, pp_buffer (buffer)->digit_buffer);
489 pp_wide_integer (buffer, TREE_INT_CST_LOW (node));
493 /* Code copied from print_node. */
496 if (TREE_OVERFLOW (node))
497 pp_string (buffer, " overflow");
499 #if !defined(REAL_IS_NOT_DOUBLE) || defined(REAL_ARITHMETIC)
500 d = TREE_REAL_CST (node);
501 if (REAL_VALUE_ISINF (d))
502 pp_string (buffer, " Inf");
503 else if (REAL_VALUE_ISNAN (d))
504 pp_string (buffer, " Nan");
508 real_to_decimal (string, &d, sizeof (string), 0, 1);
509 pp_string (buffer, string);
514 unsigned char *p = (unsigned char *) &TREE_REAL_CST (node);
515 pp_string (buffer, "0x");
516 for (i = 0; i < sizeof TREE_REAL_CST (node); i++)
517 output_formatted_integer (buffer, "%02x", *p++);
524 pp_string (buffer, "__complex__ (");
525 dump_generic_node (buffer, TREE_REALPART (node), spc, flags, false);
526 pp_string (buffer, ", ");
527 dump_generic_node (buffer, TREE_IMAGPART (node), spc, flags, false);
528 pp_string (buffer, ")");
532 pp_string (buffer, "\"");
533 pretty_print_string (buffer, TREE_STRING_POINTER (node));
534 pp_string (buffer, "\"");
540 pp_string (buffer, "{ ");
541 for (elt = TREE_VECTOR_CST_ELTS (node); elt; elt = TREE_CHAIN (elt))
543 dump_generic_node (buffer, TREE_VALUE (elt), spc, flags, false);
544 if (TREE_CHAIN (elt))
545 pp_string (buffer, ", ");
547 pp_string (buffer, " }");
556 dump_decl_name (buffer, node, flags);
560 if (DECL_NAME (node))
561 dump_decl_name (buffer, node, flags);
562 else if (LABEL_DECL_UID (node) != -1)
563 pp_printf (buffer, "<L" HOST_WIDE_INT_PRINT_DEC ">",
564 LABEL_DECL_UID (node));
566 pp_printf (buffer, "<D%u>", DECL_UID (node));
570 if (DECL_IS_BUILTIN (node))
572 /* Don't print the declaration of built-in types. */
575 if (DECL_NAME (node))
576 dump_decl_name (buffer, node, flags);
579 if ((TREE_CODE (TREE_TYPE (node)) == RECORD_TYPE
580 || TREE_CODE (TREE_TYPE (node)) == UNION_TYPE)
581 && TYPE_METHODS (TREE_TYPE (node)))
583 /* The type is a c++ class: all structures have at least
585 pp_string (buffer, "class ");
586 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
591 (TREE_CODE (TREE_TYPE (node)) == UNION_TYPE
592 ? "union" : "struct "));
593 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
602 dump_decl_name (buffer, node, flags);
606 pp_string (buffer, "<retval>");
610 op0 = TREE_OPERAND (node, 0);
612 if (TREE_CODE (op0) == INDIRECT_REF)
614 op0 = TREE_OPERAND (op0, 0);
617 if (op_prio (op0) < op_prio (node))
618 pp_character (buffer, '(');
619 dump_generic_node (buffer, op0, spc, flags, false);
620 if (op_prio (op0) < op_prio (node))
621 pp_character (buffer, ')');
622 pp_string (buffer, str);
623 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
625 op0 = component_ref_field_offset (node);
626 if (op0 && TREE_CODE (op0) != INTEGER_CST)
628 pp_string (buffer, "{off: ");
629 dump_generic_node (buffer, op0, spc, flags, false);
630 pp_character (buffer, '}');
635 pp_string (buffer, "BIT_FIELD_REF <");
636 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
637 pp_string (buffer, ", ");
638 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
639 pp_string (buffer, ", ");
640 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
641 pp_string (buffer, ">");
649 case ARRAY_RANGE_REF:
650 op0 = TREE_OPERAND (node, 0);
651 if (op_prio (op0) < op_prio (node))
652 pp_character (buffer, '(');
653 dump_generic_node (buffer, op0, spc, flags, false);
654 if (op_prio (op0) < op_prio (node))
655 pp_character (buffer, ')');
656 pp_character (buffer, '[');
657 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
658 if (TREE_CODE (node) == ARRAY_RANGE_REF)
659 pp_string (buffer, " ...");
660 pp_character (buffer, ']');
662 op0 = array_ref_low_bound (node);
663 op1 = array_ref_element_size (node);
665 if (!integer_zerop (op0)
666 || (TYPE_SIZE_UNIT (TREE_TYPE (node))
667 && !operand_equal_p (op1, TYPE_SIZE_UNIT (TREE_TYPE (node)), 0)))
669 pp_string (buffer, "{lb: ");
670 dump_generic_node (buffer, op0, spc, flags, false);
671 pp_string (buffer, " sz: ");
672 dump_generic_node (buffer, op1, spc, flags, false);
673 pp_character (buffer, '}');
680 bool is_struct_init = FALSE;
681 pp_character (buffer, '{');
682 lnode = CONSTRUCTOR_ELTS (node);
683 if (TREE_CODE (TREE_TYPE (node)) == RECORD_TYPE
684 || TREE_CODE (TREE_TYPE (node)) == UNION_TYPE)
685 is_struct_init = TRUE;
686 while (lnode && lnode != error_mark_node)
689 if (TREE_PURPOSE (lnode) && is_struct_init)
691 pp_character (buffer, '.');
692 dump_generic_node (buffer, TREE_PURPOSE (lnode), spc, flags, false);
693 pp_string (buffer, "=");
695 val = TREE_VALUE (lnode);
696 if (val && TREE_CODE (val) == ADDR_EXPR)
697 if (TREE_CODE (TREE_OPERAND (val, 0)) == FUNCTION_DECL)
698 val = TREE_OPERAND (val, 0);
699 if (val && TREE_CODE (val) == FUNCTION_DECL)
701 dump_decl_name (buffer, val, flags);
705 dump_generic_node (buffer, TREE_VALUE (lnode), spc, flags, false);
707 lnode = TREE_CHAIN (lnode);
708 if (lnode && TREE_CODE (lnode) == TREE_LIST)
710 pp_character (buffer, ',');
714 pp_character (buffer, '}');
721 if (flags & TDF_SLIM)
723 pp_string (buffer, "<COMPOUND_EXPR>");
727 dump_generic_node (buffer, TREE_OPERAND (node, 0),
728 spc, flags, dumping_stmts);
730 newline_and_indent (buffer, spc);
733 pp_character (buffer, ',');
737 for (tp = &TREE_OPERAND (node, 1);
738 TREE_CODE (*tp) == COMPOUND_EXPR;
739 tp = &TREE_OPERAND (*tp, 1))
741 dump_generic_node (buffer, TREE_OPERAND (*tp, 0),
742 spc, flags, dumping_stmts);
744 newline_and_indent (buffer, spc);
747 pp_character (buffer, ',');
752 dump_generic_node (buffer, *tp, spc, flags, dumping_stmts);
758 tree_stmt_iterator si;
761 if ((flags & TDF_SLIM) || !dumping_stmts)
763 pp_string (buffer, "<STATEMENT_LIST>");
767 for (si = tsi_start (node); !tsi_end_p (si); tsi_next (&si))
770 newline_and_indent (buffer, spc);
773 dump_generic_node (buffer, tsi_stmt (si), spc, flags, true);
780 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
782 pp_character (buffer, '=');
784 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
788 pp_string (buffer, "TARGET_EXPR <");
789 dump_generic_node (buffer, TARGET_EXPR_SLOT (node), spc, flags, false);
790 pp_character (buffer, ',');
792 dump_generic_node (buffer, TARGET_EXPR_INITIAL (node), spc, flags, false);
793 pp_character (buffer, '>');
797 print_declaration (buffer, DECL_EXPR_DECL (node), spc, flags);
802 if (TREE_TYPE (node) == NULL || TREE_TYPE (node) == void_type_node)
804 pp_string (buffer, "if (");
805 dump_generic_node (buffer, COND_EXPR_COND (node), spc, flags, false);
806 pp_character (buffer, ')');
807 /* The lowered cond_exprs should always be printed in full. */
808 if (COND_EXPR_THEN (node)
809 && TREE_CODE (COND_EXPR_THEN (node)) == GOTO_EXPR
810 && COND_EXPR_ELSE (node)
811 && TREE_CODE (COND_EXPR_ELSE (node)) == GOTO_EXPR)
814 dump_generic_node (buffer, COND_EXPR_THEN (node), 0, flags, true);
815 pp_string (buffer, " else ");
816 dump_generic_node (buffer, COND_EXPR_ELSE (node), 0, flags, true);
818 else if (!(flags & TDF_SLIM))
820 /* Output COND_EXPR_THEN. */
821 if (COND_EXPR_THEN (node))
823 newline_and_indent (buffer, spc+2);
824 pp_character (buffer, '{');
825 newline_and_indent (buffer, spc+4);
826 dump_generic_node (buffer, COND_EXPR_THEN (node), spc+4,
828 newline_and_indent (buffer, spc+2);
829 pp_character (buffer, '}');
832 /* Output COND_EXPR_ELSE. */
833 if (COND_EXPR_ELSE (node))
835 newline_and_indent (buffer, spc);
836 pp_string (buffer, "else");
837 newline_and_indent (buffer, spc+2);
838 pp_character (buffer, '{');
839 newline_and_indent (buffer, spc+4);
840 dump_generic_node (buffer, COND_EXPR_ELSE (node), spc+4,
842 newline_and_indent (buffer, spc+2);
843 pp_character (buffer, '}');
850 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
852 pp_character (buffer, '?');
854 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
856 pp_character (buffer, ':');
858 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
863 pp_character (buffer, '{');
864 if (!(flags & TDF_SLIM))
866 if (BIND_EXPR_VARS (node))
870 for (op0 = BIND_EXPR_VARS (node); op0; op0 = TREE_CHAIN (op0))
872 print_declaration (buffer, op0, spc+2, flags);
877 newline_and_indent (buffer, spc+2);
878 dump_generic_node (buffer, BIND_EXPR_BODY (node), spc+2, flags, true);
879 newline_and_indent (buffer, spc);
880 pp_character (buffer, '}');
886 print_call_name (buffer, node);
888 /* Print parameters. */
890 pp_character (buffer, '(');
891 op1 = TREE_OPERAND (node, 1);
893 dump_generic_node (buffer, op1, spc, flags, false);
894 pp_character (buffer, ')');
896 op1 = TREE_OPERAND (node, 2);
899 pp_string (buffer, " [static-chain: ");
900 dump_generic_node (buffer, op1, spc, flags, false);
901 pp_character (buffer, ']');
904 if (CALL_EXPR_TAILCALL (node))
905 pp_string (buffer, " [tail call]");
908 case WITH_CLEANUP_EXPR:
912 case CLEANUP_POINT_EXPR:
913 pp_string (buffer, "<<cleanup_point ");
914 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
915 pp_string (buffer, ">>");
918 case PLACEHOLDER_EXPR:
919 pp_string (buffer, "<PLACEHOLDER_EXPR ");
920 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
921 pp_character (buffer, '>');
924 /* Binary arithmetic and logic expressions. */
945 case TRUTH_ANDIF_EXPR:
946 case TRUTH_ORIF_EXPR:
965 const char *op = op_symbol (node);
966 op0 = TREE_OPERAND (node, 0);
967 op1 = TREE_OPERAND (node, 1);
969 /* When the operands are expressions with less priority,
970 keep semantics of the tree representation. */
971 if (op_prio (op0) < op_prio (node))
973 pp_character (buffer, '(');
974 dump_generic_node (buffer, op0, spc, flags, false);
975 pp_character (buffer, ')');
978 dump_generic_node (buffer, op0, spc, flags, false);
981 pp_string (buffer, op);
984 /* When the operands are expressions with less priority,
985 keep semantics of the tree representation. */
986 if (op_prio (op1) < op_prio (node))
988 pp_character (buffer, '(');
989 dump_generic_node (buffer, op1, spc, flags, false);
990 pp_character (buffer, ')');
993 dump_generic_node (buffer, op1, spc, flags, false);
997 /* Unary arithmetic and logic expressions. */
1000 case TRUTH_NOT_EXPR:
1002 case REFERENCE_EXPR:
1003 case PREDECREMENT_EXPR:
1004 case PREINCREMENT_EXPR:
1006 if (TREE_CODE (node) == ADDR_EXPR
1007 && (TREE_CODE (TREE_OPERAND (node, 0)) == STRING_CST
1008 || TREE_CODE (TREE_OPERAND (node, 0)) == FUNCTION_DECL))
1009 ; /* Do not output '&' for strings and function pointers. */
1011 pp_string (buffer, op_symbol (node));
1013 if (op_prio (TREE_OPERAND (node, 0)) < op_prio (node))
1015 pp_character (buffer, '(');
1016 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1017 pp_character (buffer, ')');
1020 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1023 case POSTDECREMENT_EXPR:
1024 case POSTINCREMENT_EXPR:
1025 if (op_prio (TREE_OPERAND (node, 0)) < op_prio (node))
1027 pp_character (buffer, '(');
1028 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1029 pp_character (buffer, ')');
1032 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1033 pp_string (buffer, op_symbol (node));
1037 pp_string (buffer, "MIN_EXPR <");
1038 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1039 pp_string (buffer, ", ");
1040 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1041 pp_character (buffer, '>');
1045 pp_string (buffer, "MAX_EXPR <");
1046 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1047 pp_string (buffer, ", ");
1048 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1049 pp_character (buffer, '>');
1053 pp_string (buffer, "ABS_EXPR <");
1054 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1055 pp_character (buffer, '>');
1074 case FIX_TRUNC_EXPR:
1076 case FIX_FLOOR_EXPR:
1077 case FIX_ROUND_EXPR:
1081 type = TREE_TYPE (node);
1082 op0 = TREE_OPERAND (node, 0);
1083 if (type != TREE_TYPE (op0))
1085 pp_character (buffer, '(');
1086 dump_generic_node (buffer, type, spc, flags, false);
1087 pp_string (buffer, ")");
1089 if (op_prio (op0) < op_prio (node))
1090 pp_character (buffer, '(');
1091 dump_generic_node (buffer, op0, spc, flags, false);
1092 if (op_prio (op0) < op_prio (node))
1093 pp_character (buffer, ')');
1096 case VIEW_CONVERT_EXPR:
1097 pp_string (buffer, "VIEW_CONVERT_EXPR<");
1098 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
1099 pp_string (buffer, ">(");
1100 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1101 pp_character (buffer, ')');
1104 case NON_LVALUE_EXPR:
1105 pp_string (buffer, "NON_LVALUE_EXPR <");
1106 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1107 pp_character (buffer, '>');
1111 pp_string (buffer, "SAVE_EXPR <");
1112 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1113 pp_character (buffer, '>');
1117 pp_string (buffer, "UNSAVE_EXPR <");
1118 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1119 pp_character (buffer, '>');
1122 case ENTRY_VALUE_EXPR:
1127 pp_string (buffer, "COMPLEX_EXPR <");
1128 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1129 pp_string (buffer, ", ");
1130 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1131 pp_string (buffer, ">");
1135 pp_string (buffer, "CONJ_EXPR <");
1136 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1137 pp_string (buffer, ">");
1141 pp_string (buffer, "REALPART_EXPR <");
1142 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1143 pp_string (buffer, ">");
1147 pp_string (buffer, "IMAGPART_EXPR <");
1148 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1149 pp_string (buffer, ">");
1153 pp_string (buffer, "VA_ARG_EXPR <");
1154 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1155 pp_string (buffer, ">");
1158 case TRY_FINALLY_EXPR:
1159 case TRY_CATCH_EXPR:
1160 pp_string (buffer, "try");
1161 newline_and_indent (buffer, spc+2);
1162 pp_string (buffer, "{");
1163 newline_and_indent (buffer, spc+4);
1164 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc+4, flags, true);
1165 newline_and_indent (buffer, spc+2);
1166 pp_string (buffer, "}");
1167 newline_and_indent (buffer, spc);
1169 (TREE_CODE (node) == TRY_CATCH_EXPR) ? "catch" : "finally");
1170 newline_and_indent (buffer, spc+2);
1171 pp_string (buffer, "{");
1172 newline_and_indent (buffer, spc+4);
1173 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc+4, flags, true);
1174 newline_and_indent (buffer, spc+2);
1175 pp_string (buffer, "}");
1180 pp_string (buffer, "catch (");
1181 dump_generic_node (buffer, CATCH_TYPES (node), spc+2, flags, false);
1182 pp_string (buffer, ")");
1183 newline_and_indent (buffer, spc+2);
1184 pp_string (buffer, "{");
1185 newline_and_indent (buffer, spc+4);
1186 dump_generic_node (buffer, CATCH_BODY (node), spc+4, flags, true);
1187 newline_and_indent (buffer, spc+2);
1188 pp_string (buffer, "}");
1192 case EH_FILTER_EXPR:
1193 pp_string (buffer, "<<<eh_filter (");
1194 dump_generic_node (buffer, EH_FILTER_TYPES (node), spc+2, flags, false);
1195 pp_string (buffer, ")>>>");
1196 newline_and_indent (buffer, spc+2);
1197 pp_string (buffer, "{");
1198 newline_and_indent (buffer, spc+4);
1199 dump_generic_node (buffer, EH_FILTER_FAILURE (node), spc+4, flags, true);
1200 newline_and_indent (buffer, spc+2);
1201 pp_string (buffer, "}");
1205 case GOTO_SUBROUTINE_EXPR:
1210 op0 = TREE_OPERAND (node, 0);
1211 /* If this is for break or continue, don't bother printing it. */
1212 if (DECL_NAME (op0))
1214 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1215 if (strcmp (name, "break") == 0
1216 || strcmp (name, "continue") == 0)
1219 dump_generic_node (buffer, op0, spc, flags, false);
1220 pp_character (buffer, ':');
1221 if (DECL_NONLOCAL (op0))
1222 pp_string (buffer, " [non-local]");
1225 case LABELED_BLOCK_EXPR:
1226 op0 = LABELED_BLOCK_LABEL (node);
1227 /* If this is for break or continue, don't bother printing it. */
1228 if (DECL_NAME (op0))
1230 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1231 if (strcmp (name, "break") == 0
1232 || strcmp (name, "continue") == 0)
1234 dump_generic_node (buffer, LABELED_BLOCK_BODY (node), spc, flags, false);
1238 dump_generic_node (buffer, LABELED_BLOCK_LABEL (node), spc, flags, false);
1239 pp_string (buffer, ": {");
1240 if (!(flags & TDF_SLIM))
1241 newline_and_indent (buffer, spc+2);
1242 dump_generic_node (buffer, LABELED_BLOCK_BODY (node), spc+2, flags, true);
1244 newline_and_indent (buffer, spc);
1245 pp_character (buffer, '}');
1249 case EXIT_BLOCK_EXPR:
1250 op0 = LABELED_BLOCK_LABEL (EXIT_BLOCK_LABELED_BLOCK (node));
1251 /* If this is for a break or continue, print it accordingly. */
1252 if (DECL_NAME (op0))
1254 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1255 if (strcmp (name, "break") == 0
1256 || strcmp (name, "continue") == 0)
1258 pp_string (buffer, name);
1262 pp_string (buffer, "<<<exit block ");
1263 dump_generic_node (buffer, op0, spc, flags, false);
1264 pp_string (buffer, ">>>");
1268 pp_string (buffer, "<<<exception object>>>");
1272 pp_string (buffer, "<<<filter object>>>");
1276 pp_string (buffer, "while (1)");
1277 if (!(flags & TDF_SLIM))
1279 newline_and_indent (buffer, spc+2);
1280 pp_character (buffer, '{');
1281 newline_and_indent (buffer, spc+4);
1282 dump_generic_node (buffer, LOOP_EXPR_BODY (node), spc+4, flags, true);
1283 newline_and_indent (buffer, spc+2);
1284 pp_character (buffer, '}');
1290 pp_string (buffer, "return");
1291 op0 = TREE_OPERAND (node, 0);
1295 if (TREE_CODE (op0) == MODIFY_EXPR)
1296 dump_generic_node (buffer, TREE_OPERAND (op0, 1), spc, flags, false);
1298 dump_generic_node (buffer, op0, spc, flags, false);
1303 pp_string (buffer, "if (");
1304 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1305 pp_string (buffer, ") break");
1309 pp_string (buffer, "switch (");
1310 dump_generic_node (buffer, SWITCH_COND (node), spc, flags, false);
1311 pp_character (buffer, ')');
1312 if (!(flags & TDF_SLIM))
1314 newline_and_indent (buffer, spc+2);
1315 pp_character (buffer, '{');
1316 if (SWITCH_BODY (node))
1318 newline_and_indent (buffer, spc+4);
1319 dump_generic_node (buffer, SWITCH_BODY (node), spc+4, flags, true);
1323 tree vec = SWITCH_LABELS (node);
1324 size_t i, n = TREE_VEC_LENGTH (vec);
1325 for (i = 0; i < n; ++i)
1327 tree elt = TREE_VEC_ELT (vec, i);
1328 newline_and_indent (buffer, spc+4);
1329 dump_generic_node (buffer, elt, spc+4, flags, false);
1330 pp_string (buffer, " goto ");
1331 dump_generic_node (buffer, CASE_LABEL (elt), spc+4, flags, true);
1332 pp_semicolon (buffer);
1335 newline_and_indent (buffer, spc+2);
1336 pp_character (buffer, '}');
1342 op0 = GOTO_DESTINATION (node);
1343 if (TREE_CODE (op0) != SSA_NAME
1347 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1348 if (strcmp (name, "break") == 0
1349 || strcmp (name, "continue") == 0)
1351 pp_string (buffer, name);
1355 pp_string (buffer, "goto ");
1356 dump_generic_node (buffer, op0, spc, flags, false);
1360 pp_string (buffer, "resx");
1361 /* ??? Any sensible way to present the eh region? */
1365 pp_string (buffer, "__asm__");
1366 if (ASM_VOLATILE_P (node))
1367 pp_string (buffer, " __volatile__");
1368 pp_character (buffer, '(');
1369 dump_generic_node (buffer, ASM_STRING (node), spc, flags, false);
1370 pp_character (buffer, ':');
1371 dump_generic_node (buffer, ASM_OUTPUTS (node), spc, flags, false);
1372 pp_character (buffer, ':');
1373 dump_generic_node (buffer, ASM_INPUTS (node), spc, flags, false);
1374 if (ASM_CLOBBERS (node))
1376 pp_character (buffer, ':');
1377 dump_generic_node (buffer, ASM_CLOBBERS (node), spc, flags, false);
1379 pp_string (buffer, ")");
1382 case CASE_LABEL_EXPR:
1383 if (CASE_LOW (node) && CASE_HIGH (node))
1385 pp_string (buffer, "case ");
1386 dump_generic_node (buffer, CASE_LOW (node), spc, flags, false);
1387 pp_string (buffer, " ... ");
1388 dump_generic_node (buffer, CASE_HIGH (node), spc, flags, false);
1390 else if (CASE_LOW (node))
1392 pp_string (buffer, "case ");
1393 dump_generic_node (buffer, CASE_LOW (node), spc, flags, false);
1396 pp_string (buffer, "default ");
1397 pp_character (buffer, ':');
1401 pp_string (buffer, "OBJ_TYPE_REF(");
1402 dump_generic_node (buffer, OBJ_TYPE_REF_EXPR (node), spc, flags, false);
1403 pp_character (buffer, ';');
1404 dump_generic_node (buffer, OBJ_TYPE_REF_OBJECT (node), spc, flags, false);
1405 pp_character (buffer, '-');
1406 pp_character (buffer, '>');
1407 dump_generic_node (buffer, OBJ_TYPE_REF_TOKEN (node), spc, flags, false);
1408 pp_character (buffer, ')');
1415 dump_generic_node (buffer, PHI_RESULT (node), spc, flags, false);
1416 pp_string (buffer, " = PHI <");
1417 for (i = 0; i < PHI_NUM_ARGS (node); i++)
1419 dump_generic_node (buffer, PHI_ARG_DEF (node, i), spc, flags, false);
1420 pp_string (buffer, "(");
1421 pp_decimal_int (buffer, PHI_ARG_EDGE (node, i)->src->index);
1422 pp_string (buffer, ")");
1423 if (i < PHI_NUM_ARGS (node) - 1)
1424 pp_string (buffer, ", ");
1426 pp_string (buffer, ">;");
1431 dump_generic_node (buffer, SSA_NAME_VAR (node), spc, flags, false);
1432 pp_string (buffer, "_");
1433 pp_decimal_int (buffer, SSA_NAME_VERSION (node));
1437 pp_printf (buffer, "VH.%d", VALUE_HANDLE_ID (node));
1444 if (is_stmt && is_expr)
1445 pp_semicolon (buffer);
1446 pp_write_text_to_stream (buffer);
1451 /* Print the declaration of a variable. */
1454 print_declaration (pretty_printer *buffer, tree t, int spc, int flags)
1458 if (TREE_CODE (t) == TYPE_DECL)
1459 pp_string (buffer, "typedef ");
1461 if (DECL_REGISTER (t))
1462 pp_string (buffer, "register ");
1464 if (TREE_PUBLIC (t) && DECL_EXTERNAL (t))
1465 pp_string (buffer, "extern ");
1466 else if (TREE_STATIC (t))
1467 pp_string (buffer, "static ");
1469 /* Print the type and name. */
1470 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
1474 /* Print array's type. */
1475 tmp = TREE_TYPE (t);
1476 while (TREE_CODE (TREE_TYPE (tmp)) == ARRAY_TYPE)
1477 tmp = TREE_TYPE (tmp);
1478 dump_generic_node (buffer, TREE_TYPE (tmp), spc, flags, false);
1480 /* Print variable's name. */
1482 dump_generic_node (buffer, t, spc, flags, false);
1484 /* Print the dimensions. */
1485 tmp = TREE_TYPE (t);
1486 while (TREE_CODE (tmp) == ARRAY_TYPE)
1488 pp_character (buffer, '[');
1489 if (TYPE_DOMAIN (tmp))
1491 if (TREE_CODE (TYPE_SIZE (tmp)) == INTEGER_CST)
1492 pp_wide_integer (buffer,
1493 TREE_INT_CST_LOW (TYPE_SIZE (tmp)) /
1494 TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (tmp))));
1496 dump_generic_node (buffer, TYPE_SIZE_UNIT (tmp), spc, flags,
1499 pp_character (buffer, ']');
1500 tmp = TREE_TYPE (tmp);
1503 else if (TREE_CODE (t) == FUNCTION_DECL)
1505 dump_generic_node (buffer, TREE_TYPE (TREE_TYPE (t)), spc, flags, false);
1507 dump_decl_name (buffer, t, flags);
1508 dump_function_declaration (buffer, TREE_TYPE (t), spc, flags);
1512 /* Print type declaration. */
1513 dump_generic_node (buffer, TREE_TYPE (t), spc, flags, false);
1515 /* Print variable's name. */
1517 dump_generic_node (buffer, t, spc, flags, false);
1520 /* The initial value of a function serves to determine wether the function
1521 is declared or defined. So the following does not apply to function
1523 if (TREE_CODE (t) != FUNCTION_DECL)
1525 /* Print the initial value. */
1526 if (DECL_INITIAL (t))
1529 pp_character (buffer, '=');
1531 dump_generic_node (buffer, DECL_INITIAL (t), spc, flags, false);
1535 pp_character (buffer, ';');
1539 /* Prints a structure: name, fields, and methods.
1540 FIXME: Still incomplete. */
1543 print_struct_decl (pretty_printer *buffer, tree node, int spc, int flags)
1545 /* Print the name of the structure. */
1546 if (TYPE_NAME (node))
1549 if (TREE_CODE (node) == RECORD_TYPE)
1550 pp_string (buffer, "struct ");
1551 else if ((TREE_CODE (node) == UNION_TYPE
1552 || TREE_CODE (node) == QUAL_UNION_TYPE))
1553 pp_string (buffer, "union ");
1555 dump_generic_node (buffer, TYPE_NAME (node), spc, 0, false);
1558 /* Print the contents of the structure. */
1559 pp_newline (buffer);
1561 pp_character (buffer, '{');
1562 pp_newline (buffer);
1564 /* Print the fields of the structure. */
1567 tmp = TYPE_FIELDS (node);
1570 /* Avoid to print recursively the structure. */
1571 /* FIXME : Not implemented correctly...,
1572 what about the case when we have a cycle in the contain graph? ...
1573 Maybe this could be solved by looking at the scope in which the
1574 structure was declared. */
1575 if (TREE_TYPE (tmp) != node
1576 || (TREE_CODE (TREE_TYPE (tmp)) == POINTER_TYPE
1577 && TREE_TYPE (TREE_TYPE (tmp)) != node))
1579 print_declaration (buffer, tmp, spc+2, flags);
1580 pp_newline (buffer);
1582 tmp = TREE_CHAIN (tmp);
1586 pp_character (buffer, '}');
1589 /* Return the priority of the operator OP.
1591 From lowest to highest precedence with either left-to-right (L-R)
1592 or right-to-left (R-L) associativity]:
1595 2 [R-L] = += -= *= /= %= &= ^= |= <<= >>=
1607 14 [R-L] ! ~ ++ -- + - * & (type) sizeof
1608 15 [L-R] fn() [] -> .
1610 unary +, - and * have higher precedence than the corresponding binary
1619 switch (TREE_CODE (op))
1634 case TRUTH_ORIF_EXPR:
1637 case TRUTH_AND_EXPR:
1638 case TRUTH_ANDIF_EXPR:
1645 case TRUTH_XOR_EXPR:
1662 case UNORDERED_EXPR:
1680 case TRUNC_DIV_EXPR:
1682 case FLOOR_DIV_EXPR:
1683 case ROUND_DIV_EXPR:
1685 case EXACT_DIV_EXPR:
1686 case TRUNC_MOD_EXPR:
1688 case FLOOR_MOD_EXPR:
1689 case ROUND_MOD_EXPR:
1692 case TRUTH_NOT_EXPR:
1694 case POSTINCREMENT_EXPR:
1695 case POSTDECREMENT_EXPR:
1696 case PREINCREMENT_EXPR:
1697 case PREDECREMENT_EXPR:
1704 case FIX_TRUNC_EXPR:
1706 case FIX_FLOOR_EXPR:
1707 case FIX_ROUND_EXPR:
1713 case ARRAY_RANGE_REF:
1717 /* Special expressions. */
1726 case NON_LVALUE_EXPR:
1727 return op_prio (TREE_OPERAND (op, 0));
1730 /* Return an arbitrarily high precedence to avoid surrounding single
1731 VAR_DECLs in ()s. */
1737 /* Return the symbol associated with operator OP. */
1745 switch (TREE_CODE (op))
1751 case TRUTH_ORIF_EXPR:
1754 case TRUTH_AND_EXPR:
1755 case TRUTH_ANDIF_EXPR:
1761 case TRUTH_XOR_EXPR:
1771 case UNORDERED_EXPR:
1821 case TRUTH_NOT_EXPR:
1828 case TRUNC_DIV_EXPR:
1830 case FLOOR_DIV_EXPR:
1831 case ROUND_DIV_EXPR:
1833 case EXACT_DIV_EXPR:
1836 case TRUNC_MOD_EXPR:
1838 case FLOOR_MOD_EXPR:
1839 case ROUND_MOD_EXPR:
1842 case PREDECREMENT_EXPR:
1845 case PREINCREMENT_EXPR:
1848 case POSTDECREMENT_EXPR:
1851 case POSTINCREMENT_EXPR:
1854 case REFERENCE_EXPR:
1858 return "<<< ??? >>>";
1862 /* Prints the name of a CALL_EXPR. */
1865 print_call_name (pretty_printer *buffer, tree node)
1869 if (TREE_CODE (node) != CALL_EXPR)
1872 op0 = TREE_OPERAND (node, 0);
1874 if (TREE_CODE (op0) == NON_LVALUE_EXPR)
1875 op0 = TREE_OPERAND (op0, 0);
1877 switch (TREE_CODE (op0))
1881 PRINT_FUNCTION_NAME (op0);
1887 dump_generic_node (buffer, TREE_OPERAND (op0, 0), 0, 0, false);
1891 pp_string (buffer, "(");
1892 dump_generic_node (buffer, TREE_OPERAND (op0, 0), 0, 0, false);
1893 pp_string (buffer, ") ? ");
1894 dump_generic_node (buffer, TREE_OPERAND (op0, 1), 0, 0, false);
1895 pp_string (buffer, " : ");
1896 dump_generic_node (buffer, TREE_OPERAND (op0, 2), 0, 0, false);
1900 /* The function is a pointer contained in a structure. */
1901 if (TREE_CODE (TREE_OPERAND (op0, 0)) == INDIRECT_REF ||
1902 TREE_CODE (TREE_OPERAND (op0, 0)) == VAR_DECL)
1903 PRINT_FUNCTION_NAME (TREE_OPERAND (op0, 1));
1905 dump_generic_node (buffer, TREE_OPERAND (op0, 0), 0, 0, false);
1907 We can have several levels of structures and a function
1908 pointer inside. This is not implemented yet... */
1913 if (TREE_CODE (TREE_OPERAND (op0, 0)) == VAR_DECL)
1914 PRINT_FUNCTION_NAME (TREE_OPERAND (op0, 0));
1916 dump_generic_node (buffer, op0, 0, 0, false);
1921 dump_generic_node (buffer, op0, 0, 0, false);
1929 /* Parses the string STR and replaces new-lines by '\n', tabs by '\t', ... */
1932 pretty_print_string (pretty_printer *buffer, const char *str)
1942 pp_string (buffer, "\\b");
1946 pp_string (buffer, "\\f");
1950 pp_string (buffer, "\\n");
1954 pp_string (buffer, "\\r");
1958 pp_string (buffer, "\\t");
1962 pp_string (buffer, "\\v");
1966 pp_string (buffer, "\\\\");
1970 pp_string (buffer, "\\\"");
1974 pp_string (buffer, "\\'");
1978 pp_string (buffer, "\\0");
1982 pp_string (buffer, "\\1");
1986 pp_string (buffer, "\\2");
1990 pp_string (buffer, "\\3");
1994 pp_string (buffer, "\\4");
1998 pp_string (buffer, "\\5");
2002 pp_string (buffer, "\\6");
2006 pp_string (buffer, "\\7");
2010 pp_character (buffer, str[0]);
2018 maybe_init_pretty_print (FILE *file)
2022 pp_construct (&buffer, /* prefix */NULL, /* line-width */0);
2023 pp_needs_newline (&buffer) = true;
2027 buffer.buffer->stream = file;
2031 newline_and_indent (pretty_printer *buffer, int spc)
2033 pp_newline (buffer);
2038 dump_vops (pretty_printer *buffer, tree stmt, int spc, int flags)
2041 stmt_ann_t ann = stmt_ann (stmt);
2042 v_may_def_optype v_may_defs = V_MAY_DEF_OPS (ann);
2043 v_must_def_optype v_must_defs = V_MUST_DEF_OPS (ann);
2044 vuse_optype vuses = VUSE_OPS (ann);
2046 for (i = 0; i < NUM_V_MAY_DEFS (v_may_defs); i++)
2048 pp_string (buffer, "# ");
2049 dump_generic_node (buffer, V_MAY_DEF_RESULT (v_may_defs, i),
2050 spc + 2, flags, false);
2051 pp_string (buffer, " = V_MAY_DEF <");
2052 dump_generic_node (buffer, V_MAY_DEF_OP (v_may_defs, i),
2053 spc + 2, flags, false);
2054 pp_string (buffer, ">;");
2055 newline_and_indent (buffer, spc);
2058 for (i = 0; i < NUM_V_MUST_DEFS (v_must_defs); i++)
2060 tree v_must_def = V_MUST_DEF_OP (v_must_defs, i);
2061 pp_string (buffer, "# V_MUST_DEF <");
2062 dump_generic_node (buffer, v_must_def, spc + 2, flags, false);
2063 pp_string (buffer, ">;");
2064 newline_and_indent (buffer, spc);
2067 for (i = 0; i < NUM_VUSES (vuses); i++)
2069 tree vuse = VUSE_OP (vuses, i);
2070 pp_string (buffer, "# VUSE <");
2071 dump_generic_node (buffer, vuse, spc + 2, flags, false);
2072 pp_string (buffer, ">;");
2073 newline_and_indent (buffer, spc);
2077 /* Dumps basic block BB to FILE with details described by FLAGS and
2078 indented by INDENT spaces. */
2081 dump_generic_bb (FILE *file, basic_block bb, int indent, int flags)
2083 maybe_init_pretty_print (file);
2084 dumping_stmts = true;
2085 dump_generic_bb_buff (&buffer, bb, indent, flags);
2089 /* Dumps header of basic block BB to buffer BUFFER indented by INDENT
2090 spaces and details described by flags. */
2093 dump_bb_header (pretty_printer *buffer, basic_block bb, int indent, int flags)
2098 if (flags & TDF_BLOCKS)
2101 pp_string (buffer, "# BLOCK ");
2102 pp_decimal_int (buffer, bb->index);
2104 if (flags & TDF_LINENO)
2106 block_stmt_iterator bsi;
2108 for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
2109 if (get_lineno (bsi_stmt (bsi)) != -1)
2111 pp_string (buffer, ", starting at line ");
2112 pp_decimal_int (buffer, get_lineno (bsi_stmt (bsi)));
2116 newline_and_indent (buffer, indent);
2118 pp_string (buffer, "# PRED:");
2119 pp_write_text_to_stream (buffer);
2120 for (e = bb->pred; e; e = e->pred_next)
2121 if (flags & TDF_SLIM)
2123 pp_string (buffer, " ");
2124 if (e->src == ENTRY_BLOCK_PTR)
2125 pp_string (buffer, "ENTRY");
2127 pp_decimal_int (buffer, e->src->index);
2130 dump_edge_info (buffer->buffer->stream, e, 0);
2131 pp_newline (buffer);
2135 stmt = first_stmt (bb);
2136 if (!stmt || TREE_CODE (stmt) != LABEL_EXPR)
2138 INDENT (indent - 2);
2139 pp_string (buffer, "<bb ");
2140 pp_decimal_int (buffer, bb->index);
2141 pp_string (buffer, ">:");
2142 pp_newline (buffer);
2147 /* Dumps end of basic block BB to buffer BUFFER indented by INDENT
2151 dump_bb_end (pretty_printer *buffer, basic_block bb, int indent, int flags)
2156 pp_string (buffer, "# SUCC:");
2157 pp_write_text_to_stream (buffer);
2158 for (e = bb->succ; e; e = e->succ_next)
2159 if (flags & TDF_SLIM)
2161 pp_string (buffer, " ");
2162 if (e->dest == EXIT_BLOCK_PTR)
2163 pp_string (buffer, "EXIT");
2165 pp_decimal_int (buffer, e->dest->index);
2168 dump_edge_info (buffer->buffer->stream, e, 1);
2169 pp_newline (buffer);
2172 /* Dumps phi nodes of basic block BB to buffer BUFFER with details described by
2173 FLAGS indented by INDENT spaces. */
2176 dump_phi_nodes (pretty_printer *buffer, basic_block bb, int indent, int flags)
2178 tree phi = phi_nodes (bb);
2182 for (; phi; phi = PHI_CHAIN (phi))
2184 if (is_gimple_reg (PHI_RESULT (phi)) || (flags & TDF_VOPS))
2187 pp_string (buffer, "# ");
2188 dump_generic_node (buffer, phi, indent, flags, false);
2189 pp_newline (buffer);
2194 /* Dump jump to basic block BB that is represented implicitly in the cfg
2198 pp_cfg_jump (pretty_printer *buffer, basic_block bb)
2202 stmt = first_stmt (bb);
2204 pp_string (buffer, "goto <bb ");
2205 pp_decimal_int (buffer, bb->index);
2206 pp_string (buffer, ">");
2207 if (stmt && TREE_CODE (stmt) == LABEL_EXPR)
2209 pp_string (buffer, " (");
2210 dump_generic_node (buffer, LABEL_EXPR_LABEL (stmt), 0, 0, false);
2211 pp_string (buffer, ")");
2213 pp_semicolon (buffer);
2216 /* Dump edges represented implicitly in basic block BB to BUFFER, indented
2217 by INDENT spaces, with details given by FLAGS. */
2220 dump_implicit_edges (pretty_printer *buffer, basic_block bb, int indent,
2225 /* If there is a fallthru edge, we may need to add an artificial goto to the
2227 for (e = bb->succ; e; e = e->succ_next)
2228 if (e->flags & EDGE_FALLTHRU)
2230 if (e && e->dest != bb->next_bb)
2234 if ((flags & TDF_LINENO)
2235 #ifdef USE_MAPPED_LOCATION
2236 && e->goto_locus != UNKNOWN_LOCATION
2242 expanded_location goto_xloc;
2243 #ifdef USE_MAPPED_LOCATION
2244 goto_xloc = expand_location (e->goto_locus);
2246 goto_xloc = *e->goto_locus;
2248 pp_character (buffer, '[');
2251 pp_string (buffer, goto_xloc.file);
2252 pp_string (buffer, " : ");
2254 pp_decimal_int (buffer, goto_xloc.line);
2255 pp_string (buffer, "] ");
2258 pp_cfg_jump (buffer, e->dest);
2259 pp_newline (buffer);
2263 /* Dumps basic block BB to buffer BUFFER with details described by FLAGS and
2264 indented by INDENT spaces. */
2267 dump_generic_bb_buff (pretty_printer *buffer, basic_block bb,
2268 int indent, int flags)
2270 block_stmt_iterator bsi;
2272 int label_indent = indent - 2;
2274 if (label_indent < 0)
2277 dump_bb_header (buffer, bb, indent, flags);
2280 dump_phi_nodes (buffer, bb, indent, flags);
2282 for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
2286 stmt = bsi_stmt (bsi);
2288 curr_indent = TREE_CODE (stmt) == LABEL_EXPR ? label_indent : indent;
2290 INDENT (curr_indent);
2291 dump_generic_node (buffer, stmt, curr_indent, flags, true);
2292 pp_newline (buffer);
2295 dump_implicit_edges (buffer, bb, indent, flags);
2297 if (flags & TDF_BLOCKS)
2298 dump_bb_end (buffer, bb, indent, flags);