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 #define MASK_POINTER(P) ((unsigned)((unsigned long)(P) & 0xffff))
60 static pretty_printer buffer;
61 static int initialized = 0;
62 static bool dumping_stmts;
64 /* Try to print something for an unknown tree code. */
67 do_niy (pretty_printer *buffer, tree node)
71 pp_string (buffer, "<<< Unknown tree: ");
72 pp_string (buffer, tree_code_name[(int) TREE_CODE (node)]);
74 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (node))))
76 len = first_rtl_op (TREE_CODE (node));
77 for (i = 0; i < len; ++i)
79 newline_and_indent (buffer, 2);
80 dump_generic_node (buffer, TREE_OPERAND (node, i), 2, 0, false);
84 pp_string (buffer, " >>>\n");
88 debug_generic_expr (tree t)
90 print_generic_expr (stderr, t, TDF_VOPS|TDF_UID);
91 fprintf (stderr, "\n");
95 debug_generic_stmt (tree t)
97 print_generic_stmt (stderr, t, TDF_VOPS|TDF_UID);
98 fprintf (stderr, "\n");
101 /* Prints declaration DECL to the FILE with details specified by FLAGS. */
103 print_generic_decl (FILE *file, tree decl, int flags)
105 maybe_init_pretty_print (file);
106 dumping_stmts = true;
107 print_declaration (&buffer, decl, 2, flags);
108 pp_write_text_to_stream (&buffer);
111 /* Print tree T, and its successors, on file FILE. FLAGS specifies details
112 to show in the dump. See TDF_* in tree.h. */
115 print_generic_stmt (FILE *file, tree t, int flags)
117 maybe_init_pretty_print (file);
118 dumping_stmts = true;
119 dump_generic_node (&buffer, t, 0, flags, true);
123 /* Print tree T, and its successors, on file FILE. FLAGS specifies details
124 to show in the dump. See TDF_* in tree.h. The output is indented by
128 print_generic_stmt_indented (FILE *file, tree t, int flags, int indent)
132 maybe_init_pretty_print (file);
133 dumping_stmts = true;
135 for (i = 0; i < indent; i++)
137 dump_generic_node (&buffer, t, indent, flags, true);
141 /* Print a single expression T on file FILE. FLAGS specifies details to show
142 in the dump. See TDF_* in tree.h. */
145 print_generic_expr (FILE *file, tree t, int flags)
147 maybe_init_pretty_print (file);
148 dumping_stmts = false;
149 dump_generic_node (&buffer, t, 0, flags, false);
152 /* Dump the name of a _DECL node and its DECL_UID if TDF_UID is set
156 dump_decl_name (pretty_printer *buffer, tree node, int flags)
158 if (DECL_NAME (node))
159 pp_tree_identifier (buffer, DECL_NAME (node));
161 if ((flags & TDF_UID)
162 || DECL_NAME (node) == NULL_TREE)
164 if (TREE_CODE (node) == LABEL_DECL
165 && LABEL_DECL_UID (node) != -1)
166 pp_printf (buffer, "<L" HOST_WIDE_INT_PRINT_DEC ">",
167 LABEL_DECL_UID (node));
169 pp_printf (buffer, "<D%u>", DECL_UID (node));
173 /* Dump the node NODE on the pretty_printer BUFFER, SPC spaces of indent.
174 FLAGS specifies details to show in the dump (see TDF_* in tree.h). If
175 IS_STMT is true, the object printed is considered to be a statement
176 and it is terminated by ';' if appropriate. */
179 dump_generic_node (pretty_printer *buffer, tree node, int spc, int flags,
187 if (node == NULL_TREE)
190 is_expr = EXPR_P (node);
192 if (TREE_CODE (node) != ERROR_MARK
193 && is_gimple_stmt (node)
194 && (flags & TDF_VOPS)
196 dump_vops (buffer, node, spc, flags);
199 && (flags & TDF_LINENO)
200 && EXPR_HAS_LOCATION (node))
202 pp_character (buffer, '[');
203 if (EXPR_FILENAME (node))
205 pp_string (buffer, EXPR_FILENAME (node));
206 pp_string (buffer, " : ");
208 pp_decimal_int (buffer, EXPR_LINENO (node));
209 pp_string (buffer, "] ");
212 switch (TREE_CODE (node))
215 pp_string (buffer, "<<< error >>>");
218 case IDENTIFIER_NODE:
219 pp_tree_identifier (buffer, node);
223 while (node && node != error_mark_node)
225 if (TREE_PURPOSE (node))
227 dump_generic_node (buffer, TREE_PURPOSE (node), spc, flags, false);
230 dump_generic_node (buffer, TREE_VALUE (node), spc, flags, false);
231 node = TREE_CHAIN (node);
232 if (node && TREE_CODE (node) == TREE_LIST)
234 pp_character (buffer, ',');
241 dump_generic_node (buffer, BINFO_TYPE (node), spc, flags, false);
257 unsigned int quals = TYPE_QUALS (node);
260 if (quals & TYPE_QUAL_CONST)
261 pp_string (buffer, "const ");
262 else if (quals & TYPE_QUAL_VOLATILE)
263 pp_string (buffer, "volatile ");
264 else if (quals & TYPE_QUAL_RESTRICT)
265 pp_string (buffer, "restrict ");
267 class = TREE_CODE_CLASS (TREE_CODE (node));
271 if (DECL_NAME (node))
272 dump_decl_name (buffer, node, flags);
274 pp_string (buffer, "<unnamed type decl>");
276 else if (class == 't')
278 if (TYPE_NAME (node))
280 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
281 pp_tree_identifier (buffer, TYPE_NAME (node));
282 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
283 && DECL_NAME (TYPE_NAME (node)))
284 dump_decl_name (buffer, TYPE_NAME (node), flags);
286 pp_string (buffer, "<unnamed type>");
289 pp_string (buffer, "<unnamed type>");
296 str = (TREE_CODE (node) == POINTER_TYPE ? "*" : "&");
298 if (TREE_CODE (TREE_TYPE (node)) == FUNCTION_TYPE)
300 tree fnode = TREE_TYPE (node);
301 dump_generic_node (buffer, TREE_TYPE (fnode), spc, flags, false);
303 pp_character (buffer, '(');
304 pp_string (buffer, str);
305 if (TYPE_NAME (node) && DECL_NAME (TYPE_NAME (node)))
306 dump_decl_name (buffer, TYPE_NAME (node), flags);
308 pp_printf (buffer, "<T%x>", TYPE_UID (node));
310 pp_character (buffer, ')');
312 pp_character (buffer, '(');
313 /* Print the argument types. The last element in the list is a
314 VOID_TYPE. The following avoid to print the last element. */
316 tree tmp = TYPE_ARG_TYPES (fnode);
317 while (tmp && TREE_CHAIN (tmp) && tmp != error_mark_node)
319 dump_generic_node (buffer, TREE_VALUE (tmp), spc, flags, false);
320 tmp = TREE_CHAIN (tmp);
321 if (TREE_CHAIN (tmp) && TREE_CODE (TREE_CHAIN (tmp)) == TREE_LIST)
323 pp_character (buffer, ',');
328 pp_character (buffer, ')');
332 unsigned int quals = TYPE_QUALS (node);
334 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
336 pp_string (buffer, str);
338 if (quals & TYPE_QUAL_CONST)
339 pp_string (buffer, " const");
340 else if (quals & TYPE_QUAL_VOLATILE)
341 pp_string (buffer, "volatile");
342 else if (quals & TYPE_QUAL_RESTRICT)
343 pp_string (buffer, " restrict");
352 dump_decl_name (buffer, TYPE_NAME (TYPE_METHOD_BASETYPE (node)), flags);
353 pp_string (buffer, "::");
364 /* Print the array type. */
365 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
367 /* Print the dimensions. */
369 while (tmp && TREE_CODE (tmp) == ARRAY_TYPE)
371 pp_character (buffer, '[');
374 tree size = TYPE_SIZE (tmp);
375 if (TREE_CODE (size) == INTEGER_CST)
376 pp_wide_integer (buffer,
377 TREE_INT_CST_LOW (TYPE_SIZE (tmp)) /
378 TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (tmp))));
379 else if (TREE_CODE (size) == MULT_EXPR)
380 dump_generic_node (buffer, TREE_OPERAND (size, 0), spc, flags, false);
383 pp_character (buffer, ']');
384 tmp = TREE_TYPE (tmp);
395 /* Print the name of the structure. */
396 if (TREE_CODE (node) == RECORD_TYPE)
397 pp_string (buffer, "struct ");
398 else if (TREE_CODE (node) == UNION_TYPE)
399 pp_string (buffer, "union ");
401 if (TYPE_NAME (node))
402 dump_generic_node (buffer, TYPE_NAME (node), spc, flags, false);
404 print_struct_decl (buffer, node, spc, flags);
407 case QUAL_UNION_TYPE:
417 if (TREE_CODE (TREE_TYPE (node)) == POINTER_TYPE)
419 /* In the case of a pointer, one may want to divide by the
420 size of the pointed-to type. Unfortunately, this not
421 straightforward. The C front-end maps expressions
426 in such a way that the two INTEGER_CST nodes for "5" have
427 different values but identical types. In the latter
428 case, the 5 is multiplied by sizeof (int) in c-common.c
429 (pointer_int_sum) to convert it to a byte address, and
430 yet the type of the node is left unchanged. Argh. What
431 is consistent though is that the number value corresponds
432 to bytes (UNITS) offset.
434 NB: Neither of the following divisors can be trivially
435 used to recover the original literal:
437 TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (node)))
438 TYPE_PRECISION (TREE_TYPE (TREE_TYPE (node))) */
439 pp_wide_integer (buffer, TREE_INT_CST_LOW (node));
440 pp_string (buffer, "B"); /* pseudo-unit */
442 else if (! host_integerp (node, 0))
446 if (tree_int_cst_sgn (val) < 0)
448 pp_character (buffer, '-');
449 val = build_int_2 (-TREE_INT_CST_LOW (val),
450 ~TREE_INT_CST_HIGH (val)
451 + !TREE_INT_CST_LOW (val));
453 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
456 static char format[10]; /* "%x%09999x\0" */
458 sprintf (format, "%%x%%0%dx", HOST_BITS_PER_INT / 4);
459 sprintf (pp_buffer (buffer)->digit_buffer, format,
460 TREE_INT_CST_HIGH (val),
461 TREE_INT_CST_LOW (val));
462 pp_string (buffer, pp_buffer (buffer)->digit_buffer);
466 pp_wide_integer (buffer, TREE_INT_CST_LOW (node));
470 /* Code copied from print_node. */
473 if (TREE_OVERFLOW (node))
474 pp_string (buffer, " overflow");
476 #if !defined(REAL_IS_NOT_DOUBLE) || defined(REAL_ARITHMETIC)
477 d = TREE_REAL_CST (node);
478 if (REAL_VALUE_ISINF (d))
479 pp_string (buffer, " Inf");
480 else if (REAL_VALUE_ISNAN (d))
481 pp_string (buffer, " Nan");
485 real_to_decimal (string, &d, sizeof (string), 0, 1);
486 pp_string (buffer, string);
491 unsigned char *p = (unsigned char *) &TREE_REAL_CST (node);
492 pp_string (buffer, "0x");
493 for (i = 0; i < sizeof TREE_REAL_CST (node); i++)
494 output_formatted_integer (buffer, "%02x", *p++);
501 pp_string (buffer, "__complex__ (");
502 dump_generic_node (buffer, TREE_REALPART (node), spc, flags, false);
503 pp_string (buffer, ", ");
504 dump_generic_node (buffer, TREE_IMAGPART (node), spc, flags, false);
505 pp_string (buffer, ")");
509 pp_string (buffer, "\"");
510 pretty_print_string (buffer, TREE_STRING_POINTER (node));
511 pp_string (buffer, "\"");
517 pp_string (buffer, "{ ");
518 for (elt = TREE_VECTOR_CST_ELTS (node); elt; elt = TREE_CHAIN (elt))
520 dump_generic_node (buffer, TREE_VALUE (elt), spc, flags, false);
521 if (TREE_CHAIN (elt))
522 pp_string (buffer, ", ");
524 pp_string (buffer, " }");
533 dump_decl_name (buffer, node, flags);
537 if (DECL_NAME (node))
538 dump_decl_name (buffer, node, flags);
539 else if (LABEL_DECL_UID (node) != -1)
540 pp_printf (buffer, "<L" HOST_WIDE_INT_PRINT_DEC ">",
541 LABEL_DECL_UID (node));
543 pp_printf (buffer, "<D%u>", DECL_UID (node));
547 if (strcmp (DECL_SOURCE_FILE (node), "<built-in>") == 0)
549 /* Don't print the declaration of built-in types. */
552 if (DECL_NAME (node))
554 dump_decl_name (buffer, node, flags);
558 if (TYPE_METHODS (TREE_TYPE (node)))
560 /* The type is a c++ class: all structures have at least
562 pp_string (buffer, "class ");
563 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
567 pp_string (buffer, "struct ");
568 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
569 pp_character (buffer, ';');
579 dump_decl_name (buffer, node, flags);
583 pp_string (buffer, "<retval>");
587 op0 = TREE_OPERAND (node, 0);
589 if (TREE_CODE (op0) == INDIRECT_REF)
591 op0 = TREE_OPERAND (op0, 0);
594 if (op_prio (op0) < op_prio (node))
595 pp_character (buffer, '(');
596 dump_generic_node (buffer, op0, spc, flags, false);
597 if (op_prio (op0) < op_prio (node))
598 pp_character (buffer, ')');
599 pp_string (buffer, str);
600 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
604 pp_string (buffer, "BIT_FIELD_REF <");
605 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
606 pp_string (buffer, ", ");
607 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
608 pp_string (buffer, ", ");
609 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
610 pp_string (buffer, ">");
618 op0 = TREE_OPERAND (node, 0);
619 if (op_prio (op0) < op_prio (node))
620 pp_character (buffer, '(');
621 dump_generic_node (buffer, op0, spc, flags, false);
622 if (op_prio (op0) < op_prio (node))
623 pp_character (buffer, ')');
624 pp_character (buffer, '[');
625 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
626 pp_character (buffer, ']');
629 case ARRAY_RANGE_REF:
636 bool is_struct_init = FALSE;
637 pp_character (buffer, '{');
638 lnode = CONSTRUCTOR_ELTS (node);
639 if (TREE_CODE (TREE_TYPE (node)) == RECORD_TYPE
640 || TREE_CODE (TREE_TYPE (node)) == UNION_TYPE)
641 is_struct_init = TRUE;
642 while (lnode && lnode != error_mark_node)
645 if (TREE_PURPOSE (lnode) && is_struct_init)
647 pp_character (buffer, '.');
648 dump_generic_node (buffer, TREE_PURPOSE (lnode), spc, flags, false);
649 pp_string (buffer, "=");
651 val = TREE_VALUE (lnode);
652 if (val && TREE_CODE (val) == ADDR_EXPR)
653 if (TREE_CODE (TREE_OPERAND (val, 0)) == FUNCTION_DECL)
654 val = TREE_OPERAND (val, 0);
655 if (val && TREE_CODE (val) == FUNCTION_DECL)
657 dump_decl_name (buffer, val, flags);
661 dump_generic_node (buffer, TREE_VALUE (lnode), spc, flags, false);
663 lnode = TREE_CHAIN (lnode);
664 if (lnode && TREE_CODE (lnode) == TREE_LIST)
666 pp_character (buffer, ',');
670 pp_character (buffer, '}');
677 if (flags & TDF_SLIM)
679 pp_string (buffer, "<COMPOUND_EXPR>");
683 dump_generic_node (buffer, TREE_OPERAND (node, 0),
684 spc, flags, dumping_stmts);
686 newline_and_indent (buffer, spc);
689 pp_character (buffer, ',');
693 for (tp = &TREE_OPERAND (node, 1);
694 TREE_CODE (*tp) == COMPOUND_EXPR;
695 tp = &TREE_OPERAND (*tp, 1))
697 dump_generic_node (buffer, TREE_OPERAND (*tp, 0),
698 spc, flags, dumping_stmts);
700 newline_and_indent (buffer, spc);
703 pp_character (buffer, ',');
708 dump_generic_node (buffer, *tp, spc, flags, dumping_stmts);
714 tree_stmt_iterator si;
717 if ((flags & TDF_SLIM) || !dumping_stmts)
719 pp_string (buffer, "<STATEMENT_LIST>");
723 for (si = tsi_start (node); !tsi_end_p (si); tsi_next (&si))
726 newline_and_indent (buffer, spc);
729 dump_generic_node (buffer, tsi_stmt (si), spc, flags, true);
736 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
738 pp_character (buffer, '=');
740 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
744 pp_string (buffer, "TARGET_EXPR <");
745 dump_generic_node (buffer, TARGET_EXPR_SLOT (node), spc, flags, false);
746 pp_character (buffer, ',');
748 dump_generic_node (buffer, TARGET_EXPR_INITIAL (node), spc, flags, false);
749 pp_character (buffer, '>');
753 if (TREE_TYPE (node) == void_type_node)
755 pp_string (buffer, "if (");
756 dump_generic_node (buffer, COND_EXPR_COND (node), spc, flags, false);
757 pp_character (buffer, ')');
758 /* The lowered cond_exprs should always be printed in full. */
759 if (COND_EXPR_THEN (node)
760 && TREE_CODE (COND_EXPR_THEN (node)) == GOTO_EXPR
761 && COND_EXPR_ELSE (node)
762 && TREE_CODE (COND_EXPR_ELSE (node)) == GOTO_EXPR)
765 dump_generic_node (buffer, COND_EXPR_THEN (node), 0, flags, true);
766 pp_string (buffer, " else ");
767 dump_generic_node (buffer, COND_EXPR_ELSE (node), 0, flags, true);
769 else if (!(flags & TDF_SLIM))
771 /* Output COND_EXPR_THEN. */
772 if (COND_EXPR_THEN (node))
774 newline_and_indent (buffer, spc+2);
775 pp_character (buffer, '{');
776 newline_and_indent (buffer, spc+4);
777 dump_generic_node (buffer, COND_EXPR_THEN (node), spc+4,
779 newline_and_indent (buffer, spc+2);
780 pp_character (buffer, '}');
783 /* Output COND_EXPR_ELSE. */
784 if (COND_EXPR_ELSE (node))
786 newline_and_indent (buffer, spc);
787 pp_string (buffer, "else");
788 newline_and_indent (buffer, spc+2);
789 pp_character (buffer, '{');
790 newline_and_indent (buffer, spc+4);
791 dump_generic_node (buffer, COND_EXPR_ELSE (node), spc+4,
793 newline_and_indent (buffer, spc+2);
794 pp_character (buffer, '}');
801 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
803 pp_character (buffer, '?');
805 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
807 pp_character (buffer, ':');
809 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
814 pp_character (buffer, '{');
815 if (!(flags & TDF_SLIM))
817 if (BIND_EXPR_VARS (node))
821 for (op0 = BIND_EXPR_VARS (node); op0; op0 = TREE_CHAIN (op0))
823 print_declaration (buffer, op0, spc+2, flags);
828 newline_and_indent (buffer, spc+2);
829 dump_generic_node (buffer, BIND_EXPR_BODY (node), spc+2, flags, true);
830 newline_and_indent (buffer, spc);
831 pp_character (buffer, '}');
837 print_call_name (buffer, node);
839 /* Print parameters. */
841 pp_character (buffer, '(');
842 op1 = TREE_OPERAND (node, 1);
844 dump_generic_node (buffer, op1, spc, flags, false);
845 pp_character (buffer, ')');
847 op1 = TREE_OPERAND (node, 2);
850 pp_string (buffer, " [static-chain: ");
851 dump_generic_node (buffer, op1, spc, flags, false);
852 pp_character (buffer, ']');
855 if (CALL_EXPR_TAILCALL (node))
856 pp_string (buffer, " [tail call]");
859 case WITH_CLEANUP_EXPR:
863 case CLEANUP_POINT_EXPR:
864 pp_string (buffer, "<<cleanup_point ");
865 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
866 pp_string (buffer, ">>");
869 case PLACEHOLDER_EXPR:
873 /* Binary arithmetic and logic expressions. */
894 case TRUTH_ANDIF_EXPR:
895 case TRUTH_ORIF_EXPR:
914 const char *op = op_symbol (node);
915 op0 = TREE_OPERAND (node, 0);
916 op1 = TREE_OPERAND (node, 1);
918 /* When the operands are expressions with less priority,
919 keep semantics of the tree representation. */
920 if (op_prio (op0) < op_prio (node))
922 pp_character (buffer, '(');
923 dump_generic_node (buffer, op0, spc, flags, false);
924 pp_character (buffer, ')');
927 dump_generic_node (buffer, op0, spc, flags, false);
930 pp_string (buffer, op);
933 /* When the operands are expressions with less priority,
934 keep semantics of the tree representation. */
935 if (op_prio (op1) < op_prio (node))
937 pp_character (buffer, '(');
938 dump_generic_node (buffer, op1, spc, flags, false);
939 pp_character (buffer, ')');
942 dump_generic_node (buffer, op1, spc, flags, false);
946 /* Unary arithmetic and logic expressions. */
952 case PREDECREMENT_EXPR:
953 case PREINCREMENT_EXPR:
955 if (TREE_CODE (node) == ADDR_EXPR
956 && (TREE_CODE (TREE_OPERAND (node, 0)) == STRING_CST
957 || TREE_CODE (TREE_OPERAND (node, 0)) == FUNCTION_DECL))
958 ; /* Do not output '&' for strings and function pointers. */
960 pp_string (buffer, op_symbol (node));
962 if (op_prio (TREE_OPERAND (node, 0)) < op_prio (node))
964 pp_character (buffer, '(');
965 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
966 pp_character (buffer, ')');
969 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
972 case POSTDECREMENT_EXPR:
973 case POSTINCREMENT_EXPR:
974 if (op_prio (TREE_OPERAND (node, 0)) < op_prio (node))
976 pp_character (buffer, '(');
977 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
978 pp_character (buffer, ')');
981 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
982 pp_string (buffer, op_symbol (node));
986 pp_string (buffer, "MIN_EXPR <");
987 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
988 pp_string (buffer, ", ");
989 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
990 pp_character (buffer, '>');
994 pp_string (buffer, "MAX_EXPR <");
995 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
996 pp_string (buffer, ", ");
997 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
998 pp_character (buffer, '>');
1002 pp_string (buffer, "ABS_EXPR <");
1003 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1004 pp_character (buffer, '>');
1023 case FIX_TRUNC_EXPR:
1025 case FIX_FLOOR_EXPR:
1026 case FIX_ROUND_EXPR:
1030 type = TREE_TYPE (node);
1031 op0 = TREE_OPERAND (node, 0);
1032 if (type != TREE_TYPE (op0))
1034 pp_character (buffer, '(');
1035 dump_generic_node (buffer, type, spc, flags, false);
1036 pp_string (buffer, ")");
1038 if (op_prio (op0) < op_prio (node))
1039 pp_character (buffer, '(');
1040 dump_generic_node (buffer, op0, spc, flags, false);
1041 if (op_prio (op0) < op_prio (node))
1042 pp_character (buffer, ')');
1045 case VIEW_CONVERT_EXPR:
1046 pp_string (buffer, "VIEW_CONVERT_EXPR<");
1047 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
1048 pp_string (buffer, ">(");
1049 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1050 pp_character (buffer, ')');
1053 case NON_LVALUE_EXPR:
1054 pp_string (buffer, "NON_LVALUE_EXPR <");
1055 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1056 pp_character (buffer, '>');
1060 pp_string (buffer, "SAVE_EXPR <");
1061 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1062 pp_character (buffer, '>');
1066 pp_string (buffer, "UNSAVE_EXPR <");
1067 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1068 pp_character (buffer, '>');
1075 case ENTRY_VALUE_EXPR:
1080 pp_string (buffer, "COMPLEX_EXPR <");
1081 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1082 pp_string (buffer, ", ");
1083 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1084 pp_string (buffer, ">");
1088 pp_string (buffer, "CONJ_EXPR <");
1089 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1090 pp_string (buffer, ">");
1094 pp_string (buffer, "REALPART_EXPR <");
1095 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1096 pp_string (buffer, ">");
1100 pp_string (buffer, "IMAGPART_EXPR <");
1101 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1102 pp_string (buffer, ">");
1106 pp_string (buffer, "VA_ARG_EXPR <");
1107 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1108 pp_string (buffer, ">");
1111 case TRY_FINALLY_EXPR:
1112 case TRY_CATCH_EXPR:
1113 pp_string (buffer, "try");
1114 newline_and_indent (buffer, spc+2);
1115 pp_string (buffer, "{");
1116 newline_and_indent (buffer, spc+4);
1117 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc+4, flags, true);
1118 newline_and_indent (buffer, spc+2);
1119 pp_string (buffer, "}");
1120 newline_and_indent (buffer, spc);
1122 (TREE_CODE (node) == TRY_CATCH_EXPR) ? "catch" : "finally");
1123 newline_and_indent (buffer, spc+2);
1124 pp_string (buffer, "{");
1125 newline_and_indent (buffer, spc+4);
1126 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc+4, flags, true);
1127 newline_and_indent (buffer, spc+2);
1128 pp_string (buffer, "}");
1133 pp_string (buffer, "catch (");
1134 dump_generic_node (buffer, CATCH_TYPES (node), spc+2, flags, false);
1135 pp_string (buffer, ")");
1136 newline_and_indent (buffer, spc+2);
1137 pp_string (buffer, "{");
1138 newline_and_indent (buffer, spc+4);
1139 dump_generic_node (buffer, CATCH_BODY (node), spc+4, flags, true);
1140 newline_and_indent (buffer, spc+2);
1141 pp_string (buffer, "}");
1145 case EH_FILTER_EXPR:
1146 pp_string (buffer, "<<<eh_filter (");
1147 dump_generic_node (buffer, EH_FILTER_TYPES (node), spc+2, flags, false);
1148 pp_string (buffer, ")>>>");
1149 newline_and_indent (buffer, spc+2);
1150 pp_string (buffer, "{");
1151 newline_and_indent (buffer, spc+4);
1152 dump_generic_node (buffer, EH_FILTER_FAILURE (node), spc+4, flags, true);
1153 newline_and_indent (buffer, spc+2);
1154 pp_string (buffer, "}");
1158 case GOTO_SUBROUTINE_EXPR:
1163 op0 = TREE_OPERAND (node, 0);
1164 /* If this is for break or continue, don't bother printing it. */
1165 if (DECL_NAME (op0))
1167 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1168 if (strcmp (name, "break") == 0
1169 || strcmp (name, "continue") == 0)
1172 dump_generic_node (buffer, op0, spc, flags, false);
1173 pp_character (buffer, ':');
1174 if (DECL_NONLOCAL (op0))
1175 pp_string (buffer, " [non-local]");
1178 case LABELED_BLOCK_EXPR:
1179 op0 = LABELED_BLOCK_LABEL (node);
1180 /* If this is for break or continue, don't bother printing it. */
1181 if (DECL_NAME (op0))
1183 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1184 if (strcmp (name, "break") == 0
1185 || strcmp (name, "continue") == 0)
1187 dump_generic_node (buffer, LABELED_BLOCK_BODY (node), spc, flags, false);
1191 dump_generic_node (buffer, LABELED_BLOCK_LABEL (node), spc, flags, false);
1192 pp_string (buffer, ": {");
1193 if (!(flags & TDF_SLIM))
1194 newline_and_indent (buffer, spc+2);
1195 dump_generic_node (buffer, LABELED_BLOCK_BODY (node), spc+2, flags, true);
1197 newline_and_indent (buffer, spc);
1198 pp_character (buffer, '}');
1202 case EXIT_BLOCK_EXPR:
1203 op0 = LABELED_BLOCK_LABEL (EXIT_BLOCK_LABELED_BLOCK (node));
1204 /* If this is for a break or continue, print it accordingly. */
1205 if (DECL_NAME (op0))
1207 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1208 if (strcmp (name, "break") == 0
1209 || strcmp (name, "continue") == 0)
1211 pp_string (buffer, name);
1215 pp_string (buffer, "<<<exit block ");
1216 dump_generic_node (buffer, op0, spc, flags, false);
1217 pp_string (buffer, ">>>");
1221 pp_string (buffer, "<<<exception object>>>");
1225 pp_string (buffer, "<<<filter object>>>");
1229 pp_string (buffer, "while (1)");
1230 if (!(flags & TDF_SLIM))
1232 newline_and_indent (buffer, spc+2);
1233 pp_character (buffer, '{');
1234 newline_and_indent (buffer, spc+4);
1235 dump_generic_node (buffer, LOOP_EXPR_BODY (node), spc+4, flags, true);
1236 newline_and_indent (buffer, spc+2);
1237 pp_character (buffer, '}');
1243 pp_string (buffer, "return");
1244 op0 = TREE_OPERAND (node, 0);
1248 if (TREE_CODE (op0) == MODIFY_EXPR)
1249 dump_generic_node (buffer, TREE_OPERAND (op0, 1), spc, flags, false);
1251 dump_generic_node (buffer, op0, spc, flags, false);
1256 pp_string (buffer, "if (");
1257 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1258 pp_string (buffer, ") break");
1262 pp_string (buffer, "switch (");
1263 dump_generic_node (buffer, SWITCH_COND (node), spc, flags, false);
1264 pp_character (buffer, ')');
1265 if (!(flags & TDF_SLIM))
1267 newline_and_indent (buffer, spc+2);
1268 pp_character (buffer, '{');
1269 if (SWITCH_BODY (node))
1271 newline_and_indent (buffer, spc+4);
1272 dump_generic_node (buffer, SWITCH_BODY (node), spc+4, flags, true);
1276 tree vec = SWITCH_LABELS (node);
1277 size_t i, n = TREE_VEC_LENGTH (vec);
1278 for (i = 0; i < n; ++i)
1280 tree elt = TREE_VEC_ELT (vec, i);
1281 newline_and_indent (buffer, spc+4);
1282 dump_generic_node (buffer, elt, spc+4, flags, false);
1283 pp_string (buffer, " goto ");
1284 dump_generic_node (buffer, CASE_LABEL (elt), spc+4, flags, true);
1285 pp_semicolon (buffer);
1288 newline_and_indent (buffer, spc+2);
1289 pp_character (buffer, '}');
1295 op0 = GOTO_DESTINATION (node);
1296 if (TREE_CODE (op0) != SSA_NAME
1300 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1301 if (strcmp (name, "break") == 0
1302 || strcmp (name, "continue") == 0)
1304 pp_string (buffer, name);
1308 pp_string (buffer, "goto ");
1309 dump_generic_node (buffer, op0, spc, flags, false);
1313 pp_string (buffer, "resx");
1314 /* ??? Any sensible way to present the eh region? */
1318 pp_string (buffer, "__asm__");
1319 if (ASM_VOLATILE_P (node))
1320 pp_string (buffer, " __volatile__");
1321 pp_character (buffer, '(');
1322 dump_generic_node (buffer, ASM_STRING (node), spc, flags, false);
1323 pp_character (buffer, ':');
1324 dump_generic_node (buffer, ASM_OUTPUTS (node), spc, flags, false);
1325 pp_character (buffer, ':');
1326 dump_generic_node (buffer, ASM_INPUTS (node), spc, flags, false);
1327 if (ASM_CLOBBERS (node))
1329 pp_character (buffer, ':');
1330 dump_generic_node (buffer, ASM_CLOBBERS (node), spc, flags, false);
1332 pp_string (buffer, ")");
1335 case CASE_LABEL_EXPR:
1336 if (CASE_LOW (node) && CASE_HIGH (node))
1338 pp_string (buffer, "case ");
1339 dump_generic_node (buffer, CASE_LOW (node), spc, flags, false);
1340 pp_string (buffer, " ... ");
1341 dump_generic_node (buffer, CASE_HIGH (node), spc, flags, false);
1343 else if (CASE_LOW (node))
1345 pp_string (buffer, "case ");
1346 dump_generic_node (buffer, CASE_LOW (node), spc, flags, false);
1349 pp_string (buffer, "default ");
1350 pp_character (buffer, ':');
1354 pp_string (buffer, "VTABLE_REF <(");
1355 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1356 pp_string (buffer, "),");
1357 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1358 pp_character (buffer, ',');
1359 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
1360 pp_character (buffer, '>');
1367 dump_generic_node (buffer, PHI_RESULT (node), spc, flags, false);
1368 pp_string (buffer, " = PHI <");
1369 for (i = 0; i < PHI_NUM_ARGS (node); i++)
1371 dump_generic_node (buffer, PHI_ARG_DEF (node, i), spc, flags, false);
1372 pp_string (buffer, "(");
1373 pp_decimal_int (buffer, PHI_ARG_EDGE (node, i)->src->index);
1374 pp_string (buffer, ")");
1375 if (i < PHI_NUM_ARGS (node) - 1)
1376 pp_string (buffer, ", ");
1378 pp_string (buffer, ">;");
1383 dump_generic_node (buffer, SSA_NAME_VAR (node), spc, flags, false);
1384 pp_string (buffer, "_");
1385 pp_decimal_int (buffer, SSA_NAME_VERSION (node));
1392 if (is_stmt && is_expr)
1393 pp_semicolon (buffer);
1394 pp_write_text_to_stream (buffer);
1399 /* Print the declaration of a variable. */
1402 print_declaration (pretty_printer *buffer, tree t, int spc, int flags)
1404 /* Don't print type declarations. */
1405 if (TREE_CODE (t) == TYPE_DECL)
1410 if (DECL_REGISTER (t))
1411 pp_string (buffer, "register ");
1413 if (TREE_PUBLIC (t) && DECL_EXTERNAL (t))
1414 pp_string (buffer, "extern ");
1415 else if (TREE_STATIC (t))
1416 pp_string (buffer, "static ");
1418 /* Print the type and name. */
1419 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
1423 /* Print array's type. */
1424 tmp = TREE_TYPE (t);
1425 while (TREE_CODE (TREE_TYPE (tmp)) == ARRAY_TYPE)
1426 tmp = TREE_TYPE (tmp);
1427 dump_generic_node (buffer, TREE_TYPE (tmp), spc, flags, false);
1429 /* Print variable's name. */
1431 dump_generic_node (buffer, t, spc, flags, false);
1433 /* Print the dimensions. */
1434 tmp = TREE_TYPE (t);
1435 while (TREE_CODE (tmp) == ARRAY_TYPE)
1437 pp_character (buffer, '[');
1438 if (TYPE_DOMAIN (tmp))
1440 if (TREE_CODE (TYPE_SIZE (tmp)) == INTEGER_CST)
1441 pp_wide_integer (buffer,
1442 TREE_INT_CST_LOW (TYPE_SIZE (tmp)) /
1443 TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (tmp))));
1445 dump_generic_node (buffer, TYPE_SIZE_UNIT (tmp), spc, flags,
1448 pp_character (buffer, ']');
1449 tmp = TREE_TYPE (tmp);
1454 /* Print type declaration. */
1455 dump_generic_node (buffer, TREE_TYPE (t), spc, flags, false);
1457 /* Print variable's name. */
1459 dump_generic_node (buffer, t, spc, flags, false);
1462 /* The initial value of a function serves to determine wether the function
1463 is declared or defined. So the following does not apply to function
1465 if (TREE_CODE (t) != FUNCTION_DECL)
1467 /* Print the initial value. */
1468 if (DECL_INITIAL (t))
1471 pp_character (buffer, '=');
1473 dump_generic_node (buffer, DECL_INITIAL (t), spc, flags, false);
1477 pp_character (buffer, ';');
1481 /* Prints a structure: name, fields, and methods.
1482 FIXME: Still incomplete. */
1485 print_struct_decl (pretty_printer *buffer, tree node, int spc, int flags)
1487 /* Print the name of the structure. */
1488 if (TYPE_NAME (node))
1491 if (TREE_CODE (node) == RECORD_TYPE)
1492 pp_string (buffer, "struct ");
1493 else if (TREE_CODE (node) == UNION_TYPE)
1494 pp_string (buffer, "union ");
1497 dump_generic_node (buffer, TYPE_NAME (node), spc, 0, false);
1500 /* Print the contents of the structure. */
1501 pp_newline (buffer);
1503 pp_character (buffer, '{');
1504 pp_newline (buffer);
1506 /* Print the fields of the structure. */
1509 tmp = TYPE_FIELDS (node);
1512 /* Avoid to print recursively the structure. */
1513 /* FIXME : Not implemented correctly...,
1514 what about the case when we have a cycle in the contain graph? ...
1515 Maybe this could be solved by looking at the scope in which the
1516 structure was declared. */
1517 if (TREE_TYPE (tmp) != node
1518 || (TREE_CODE (TREE_TYPE (tmp)) == POINTER_TYPE &&
1519 TREE_TYPE (TREE_TYPE (tmp)) != node))
1521 print_declaration (buffer, tmp, spc+2, flags);
1522 pp_newline (buffer);
1528 tmp = TREE_CHAIN (tmp);
1532 pp_character (buffer, '}');
1535 /* Return the priority of the operator OP.
1537 From lowest to highest precedence with either left-to-right (L-R)
1538 or right-to-left (R-L) associativity]:
1541 2 [R-L] = += -= *= /= %= &= ^= |= <<= >>=
1553 14 [R-L] ! ~ ++ -- + - * & (type) sizeof
1554 15 [L-R] fn() [] -> .
1556 unary +, - and * have higher precedence than the corresponding binary
1565 switch (TREE_CODE (op))
1580 case TRUTH_ORIF_EXPR:
1583 case TRUTH_AND_EXPR:
1584 case TRUTH_ANDIF_EXPR:
1591 case TRUTH_XOR_EXPR:
1608 case UNORDERED_EXPR:
1626 case TRUNC_DIV_EXPR:
1628 case FLOOR_DIV_EXPR:
1629 case ROUND_DIV_EXPR:
1631 case EXACT_DIV_EXPR:
1632 case TRUNC_MOD_EXPR:
1634 case FLOOR_MOD_EXPR:
1635 case ROUND_MOD_EXPR:
1638 case TRUTH_NOT_EXPR:
1640 case POSTINCREMENT_EXPR:
1641 case POSTDECREMENT_EXPR:
1642 case PREINCREMENT_EXPR:
1643 case PREDECREMENT_EXPR:
1650 case FIX_TRUNC_EXPR:
1652 case FIX_FLOOR_EXPR:
1653 case FIX_ROUND_EXPR:
1662 /* Special expressions. */
1671 case NON_LVALUE_EXPR:
1672 return op_prio (TREE_OPERAND (op, 0));
1675 /* Return an arbitrarily high precedence to avoid surrounding single
1676 VAR_DECLs in ()s. */
1682 /* Return the symbol associated with operator OP. */
1690 switch (TREE_CODE (op))
1696 case TRUTH_ORIF_EXPR:
1699 case TRUTH_AND_EXPR:
1700 case TRUTH_ANDIF_EXPR:
1706 case TRUTH_XOR_EXPR:
1716 case UNORDERED_EXPR:
1766 case TRUTH_NOT_EXPR:
1773 case TRUNC_DIV_EXPR:
1775 case FLOOR_DIV_EXPR:
1776 case ROUND_DIV_EXPR:
1778 case EXACT_DIV_EXPR:
1781 case TRUNC_MOD_EXPR:
1783 case FLOOR_MOD_EXPR:
1784 case ROUND_MOD_EXPR:
1787 case PREDECREMENT_EXPR:
1790 case PREINCREMENT_EXPR:
1793 case POSTDECREMENT_EXPR:
1796 case POSTINCREMENT_EXPR:
1799 case REFERENCE_EXPR:
1803 return "<<< ??? >>>";
1807 /* Prints the name of a CALL_EXPR. */
1810 print_call_name (pretty_printer *buffer, tree node)
1814 if (TREE_CODE (node) != CALL_EXPR)
1817 op0 = TREE_OPERAND (node, 0);
1819 if (TREE_CODE (op0) == NON_LVALUE_EXPR)
1820 op0 = TREE_OPERAND (op0, 0);
1822 switch (TREE_CODE (op0))
1826 PRINT_FUNCTION_NAME (op0);
1832 dump_generic_node (buffer, TREE_OPERAND (op0, 0), 0, 0, false);
1836 pp_string (buffer, "(");
1837 dump_generic_node (buffer, TREE_OPERAND (op0, 0), 0, 0, false);
1838 pp_string (buffer, ") ? ");
1839 dump_generic_node (buffer, TREE_OPERAND (op0, 1), 0, 0, false);
1840 pp_string (buffer, " : ");
1841 dump_generic_node (buffer, TREE_OPERAND (op0, 2), 0, 0, false);
1845 /* The function is a pointer contained in a structure. */
1846 if (TREE_CODE (TREE_OPERAND (op0, 0)) == INDIRECT_REF ||
1847 TREE_CODE (TREE_OPERAND (op0, 0)) == VAR_DECL)
1848 PRINT_FUNCTION_NAME (TREE_OPERAND (op0, 1));
1850 dump_generic_node (buffer, TREE_OPERAND (op0, 0), 0, 0, false);
1852 We can have several levels of structures and a function
1853 pointer inside. This is not implemented yet... */
1858 if (TREE_CODE (TREE_OPERAND (op0, 0)) == VAR_DECL)
1859 PRINT_FUNCTION_NAME (TREE_OPERAND (op0, 0));
1861 dump_generic_node (buffer, op0, 0, 0, false);
1865 dump_generic_node (buffer, op0, 0, 0, false);
1873 /* Parses the string STR and replaces new-lines by '\n', tabs by '\t', ... */
1876 pretty_print_string (pretty_printer *buffer, const char *str)
1886 pp_string (buffer, "\\b");
1890 pp_string (buffer, "\\f");
1894 pp_string (buffer, "\\n");
1898 pp_string (buffer, "\\r");
1902 pp_string (buffer, "\\t");
1906 pp_string (buffer, "\\v");
1910 pp_string (buffer, "\\\\");
1914 pp_string (buffer, "\\\"");
1918 pp_string (buffer, "\\'");
1922 pp_string (buffer, "\\0");
1926 pp_string (buffer, "\\1");
1930 pp_string (buffer, "\\2");
1934 pp_string (buffer, "\\3");
1938 pp_string (buffer, "\\4");
1942 pp_string (buffer, "\\5");
1946 pp_string (buffer, "\\6");
1950 pp_string (buffer, "\\7");
1954 pp_character (buffer, str[0]);
1962 maybe_init_pretty_print (FILE *file)
1966 pp_construct (&buffer, /* prefix */NULL, /* line-width */0);
1967 pp_needs_newline (&buffer) = true;
1971 buffer.buffer->stream = file;
1975 newline_and_indent (pretty_printer *buffer, int spc)
1977 pp_newline (buffer);
1982 dump_vops (pretty_printer *buffer, tree stmt, int spc, int flags)
1985 stmt_ann_t ann = stmt_ann (stmt);
1986 v_may_def_optype v_may_defs = V_MAY_DEF_OPS (ann);
1987 v_must_def_optype v_must_defs = V_MUST_DEF_OPS (ann);
1988 vuse_optype vuses = VUSE_OPS (ann);
1990 for (i = 0; i < NUM_V_MAY_DEFS (v_may_defs); i++)
1992 pp_string (buffer, "# ");
1993 dump_generic_node (buffer, V_MAY_DEF_RESULT (v_may_defs, i),
1994 spc + 2, flags, false);
1995 pp_string (buffer, " = V_MAY_DEF <");
1996 dump_generic_node (buffer, V_MAY_DEF_OP (v_may_defs, i),
1997 spc + 2, flags, false);
1998 pp_string (buffer, ">;");
1999 newline_and_indent (buffer, spc);
2002 for (i = 0; i < NUM_V_MUST_DEFS (v_must_defs); i++)
2004 tree v_must_def = V_MUST_DEF_OP (v_must_defs, i);
2005 pp_string (buffer, "# V_MUST_DEF <");
2006 dump_generic_node (buffer, v_must_def, spc + 2, flags, false);
2007 pp_string (buffer, ">;");
2008 newline_and_indent (buffer, spc);
2011 for (i = 0; i < NUM_VUSES (vuses); i++)
2013 tree vuse = VUSE_OP (vuses, i);
2014 pp_string (buffer, "# VUSE <");
2015 dump_generic_node (buffer, vuse, spc + 2, flags, false);
2016 pp_string (buffer, ">;");
2017 newline_and_indent (buffer, spc);
2021 /* Dumps basic block BB to FILE with details described by FLAGS and
2022 indented by INDENT spaces. */
2025 dump_generic_bb (FILE *file, basic_block bb, int indent, int flags)
2027 maybe_init_pretty_print (file);
2028 dumping_stmts = true;
2029 dump_generic_bb_buff (&buffer, bb, indent, flags);
2033 /* Dumps header of basic block BB to buffer BUFFER indented by INDENT
2034 spaces and details described by flags. */
2037 dump_bb_header (pretty_printer *buffer, basic_block bb, int indent, int flags)
2042 if (flags & TDF_BLOCKS)
2045 pp_string (buffer, "# BLOCK ");
2046 pp_decimal_int (buffer, bb->index);
2048 if (flags & TDF_LINENO)
2050 block_stmt_iterator bsi;
2052 for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
2053 if (get_lineno (bsi_stmt (bsi)) != -1)
2055 pp_string (buffer, ", starting at line ");
2056 pp_decimal_int (buffer, get_lineno (bsi_stmt (bsi)));
2060 newline_and_indent (buffer, indent);
2062 pp_string (buffer, "# PRED:");
2063 pp_write_text_to_stream (buffer);
2064 for (e = bb->pred; e; e = e->pred_next)
2065 if (flags & TDF_SLIM)
2067 pp_string (buffer, " ");
2068 if (e->src == ENTRY_BLOCK_PTR)
2069 pp_string (buffer, "ENTRY");
2071 pp_decimal_int (buffer, e->src->index);
2074 dump_edge_info (buffer->buffer->stream, e, 0);
2075 pp_newline (buffer);
2079 stmt = first_stmt (bb);
2080 if (!stmt || TREE_CODE (stmt) != LABEL_EXPR)
2082 INDENT (indent - 2);
2083 pp_string (buffer, "<bb ");
2084 pp_decimal_int (buffer, bb->index);
2085 pp_string (buffer, ">:");
2086 pp_newline (buffer);
2091 /* Dumps end of basic block BB to buffer BUFFER indented by INDENT
2095 dump_bb_end (pretty_printer *buffer, basic_block bb, int indent, int flags)
2100 pp_string (buffer, "# SUCC:");
2101 pp_write_text_to_stream (buffer);
2102 for (e = bb->succ; e; e = e->succ_next)
2103 if (flags & TDF_SLIM)
2105 pp_string (buffer, " ");
2106 if (e->dest == EXIT_BLOCK_PTR)
2107 pp_string (buffer, "EXIT");
2109 pp_decimal_int (buffer, e->dest->index);
2112 dump_edge_info (buffer->buffer->stream, e, 1);
2113 pp_newline (buffer);
2116 /* Dumps phi nodes of basic block BB to buffer BUFFER with details described by
2117 FLAGS indented by INDENT spaces. */
2120 dump_phi_nodes (pretty_printer *buffer, basic_block bb, int indent, int flags)
2122 tree phi = phi_nodes (bb);
2126 for (; phi; phi = PHI_CHAIN (phi))
2128 if (is_gimple_reg (PHI_RESULT (phi)) || (flags & TDF_VOPS))
2131 pp_string (buffer, "# ");
2132 dump_generic_node (buffer, phi, indent, flags, false);
2133 pp_newline (buffer);
2138 /* Dump jump to basic block BB that is represented implicitly in the cfg
2142 pp_cfg_jump (pretty_printer *buffer, basic_block bb)
2146 stmt = first_stmt (bb);
2148 pp_string (buffer, "goto <bb ");
2149 pp_decimal_int (buffer, bb->index);
2150 pp_string (buffer, ">");
2151 if (stmt && TREE_CODE (stmt) == LABEL_EXPR)
2153 pp_string (buffer, " (");
2154 dump_generic_node (buffer, LABEL_EXPR_LABEL (stmt), 0, 0, false);
2155 pp_string (buffer, ")");
2157 pp_semicolon (buffer);
2160 /* Dump edges represented implicitly in basic block BB to BUFFER, indented
2161 by INDENT spaces, with details given by FLAGS. */
2164 dump_implicit_edges (pretty_printer *buffer, basic_block bb, int indent,
2169 /* If there is a fallthru edge, we may need to add an artificial goto to the
2171 for (e = bb->succ; e; e = e->succ_next)
2172 if (e->flags & EDGE_FALLTHRU)
2174 if (e && e->dest != bb->next_bb)
2178 if ((flags & TDF_LINENO) && e->goto_locus)
2180 pp_character (buffer, '[');
2181 if (e->goto_locus->file)
2183 pp_string (buffer, e->goto_locus->file);
2184 pp_string (buffer, " : ");
2186 pp_decimal_int (buffer, e->goto_locus->line);
2187 pp_string (buffer, "] ");
2190 pp_cfg_jump (buffer, e->dest);
2191 pp_newline (buffer);
2195 /* Dumps basic block BB to buffer BUFFER with details described by FLAGS and
2196 indented by INDENT spaces. */
2199 dump_generic_bb_buff (pretty_printer *buffer, basic_block bb,
2200 int indent, int flags)
2202 block_stmt_iterator bsi;
2204 int label_indent = indent - 2;
2206 if (label_indent < 0)
2209 dump_bb_header (buffer, bb, indent, flags);
2212 dump_phi_nodes (buffer, bb, indent, flags);
2214 for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
2218 stmt = bsi_stmt (bsi);
2220 curr_indent = TREE_CODE (stmt) == LABEL_EXPR ? label_indent : indent;
2222 INDENT (curr_indent);
2223 dump_generic_node (buffer, stmt, curr_indent, flags, true);
2224 pp_newline (buffer);
2227 dump_implicit_edges (buffer, bb, indent, flags);
2229 if (flags & TDF_BLOCKS)
2230 dump_bb_end (buffer, bb, indent, flags);