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 dump_generic_node (buffer, TYPE_NAME (TREE_TYPE (node)), spc, flags, false);
745 pp_character (buffer, '(');
746 dump_generic_node (buffer, TARGET_EXPR_INITIAL (node), spc, flags, false);
747 pp_character (buffer, ')');
751 if (TREE_TYPE (node) == void_type_node)
753 pp_string (buffer, "if (");
754 dump_generic_node (buffer, COND_EXPR_COND (node), spc, flags, false);
755 pp_character (buffer, ')');
756 /* The lowered cond_exprs should always be printed in full. */
757 if (COND_EXPR_THEN (node)
758 && TREE_CODE (COND_EXPR_THEN (node)) == GOTO_EXPR
759 && COND_EXPR_ELSE (node)
760 && TREE_CODE (COND_EXPR_ELSE (node)) == GOTO_EXPR)
763 dump_generic_node (buffer, COND_EXPR_THEN (node), 0, flags, true);
764 pp_string (buffer, " else ");
765 dump_generic_node (buffer, COND_EXPR_ELSE (node), 0, flags, true);
767 else if (!(flags & TDF_SLIM))
769 /* Output COND_EXPR_THEN. */
770 if (COND_EXPR_THEN (node))
772 newline_and_indent (buffer, spc+2);
773 pp_character (buffer, '{');
774 newline_and_indent (buffer, spc+4);
775 dump_generic_node (buffer, COND_EXPR_THEN (node), spc+4,
777 newline_and_indent (buffer, spc+2);
778 pp_character (buffer, '}');
781 /* Output COND_EXPR_ELSE. */
782 if (COND_EXPR_ELSE (node))
784 newline_and_indent (buffer, spc);
785 pp_string (buffer, "else");
786 newline_and_indent (buffer, spc+2);
787 pp_character (buffer, '{');
788 newline_and_indent (buffer, spc+4);
789 dump_generic_node (buffer, COND_EXPR_ELSE (node), spc+4,
791 newline_and_indent (buffer, spc+2);
792 pp_character (buffer, '}');
799 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
801 pp_character (buffer, '?');
803 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
805 pp_character (buffer, ':');
807 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
812 pp_character (buffer, '{');
813 if (!(flags & TDF_SLIM))
815 if (BIND_EXPR_VARS (node))
819 for (op0 = BIND_EXPR_VARS (node); op0; op0 = TREE_CHAIN (op0))
821 print_declaration (buffer, op0, spc+2, flags);
826 newline_and_indent (buffer, spc+2);
827 dump_generic_node (buffer, BIND_EXPR_BODY (node), spc+2, flags, true);
828 newline_and_indent (buffer, spc);
829 pp_character (buffer, '}');
835 print_call_name (buffer, node);
837 /* Print parameters. */
839 pp_character (buffer, '(');
840 op1 = TREE_OPERAND (node, 1);
842 dump_generic_node (buffer, op1, spc, flags, false);
843 pp_character (buffer, ')');
845 op1 = TREE_OPERAND (node, 2);
848 pp_string (buffer, " [static-chain: ");
849 dump_generic_node (buffer, op1, spc, flags, false);
850 pp_character (buffer, ']');
853 if (CALL_EXPR_TAILCALL (node))
854 pp_string (buffer, " [tail call]");
857 case WITH_CLEANUP_EXPR:
861 case CLEANUP_POINT_EXPR:
862 pp_string (buffer, "<<cleanup_point ");
863 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
864 pp_string (buffer, ">>");
867 case PLACEHOLDER_EXPR:
871 /* Binary arithmetic and logic expressions. */
892 case TRUTH_ANDIF_EXPR:
893 case TRUTH_ORIF_EXPR:
912 const char *op = op_symbol (node);
913 op0 = TREE_OPERAND (node, 0);
914 op1 = TREE_OPERAND (node, 1);
916 /* When the operands are expressions with less priority,
917 keep semantics of the tree representation. */
918 if (op_prio (op0) < op_prio (node))
920 pp_character (buffer, '(');
921 dump_generic_node (buffer, op0, spc, flags, false);
922 pp_character (buffer, ')');
925 dump_generic_node (buffer, op0, spc, flags, false);
928 pp_string (buffer, op);
931 /* When the operands are expressions with less priority,
932 keep semantics of the tree representation. */
933 if (op_prio (op1) < op_prio (node))
935 pp_character (buffer, '(');
936 dump_generic_node (buffer, op1, spc, flags, false);
937 pp_character (buffer, ')');
940 dump_generic_node (buffer, op1, spc, flags, false);
944 /* Unary arithmetic and logic expressions. */
950 case PREDECREMENT_EXPR:
951 case PREINCREMENT_EXPR:
953 if (TREE_CODE (node) == ADDR_EXPR
954 && (TREE_CODE (TREE_OPERAND (node, 0)) == STRING_CST
955 || TREE_CODE (TREE_OPERAND (node, 0)) == FUNCTION_DECL))
956 ; /* Do not output '&' for strings and function pointers. */
958 pp_string (buffer, op_symbol (node));
960 if (op_prio (TREE_OPERAND (node, 0)) < op_prio (node))
962 pp_character (buffer, '(');
963 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
964 pp_character (buffer, ')');
967 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
970 case POSTDECREMENT_EXPR:
971 case POSTINCREMENT_EXPR:
972 if (op_prio (TREE_OPERAND (node, 0)) < op_prio (node))
974 pp_character (buffer, '(');
975 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
976 pp_character (buffer, ')');
979 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
980 pp_string (buffer, op_symbol (node));
984 pp_string (buffer, "MIN_EXPR <");
985 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
986 pp_string (buffer, ", ");
987 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
988 pp_character (buffer, '>');
992 pp_string (buffer, "MAX_EXPR <");
993 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
994 pp_string (buffer, ", ");
995 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
996 pp_character (buffer, '>');
1000 pp_string (buffer, "ABS_EXPR <");
1001 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1002 pp_character (buffer, '>');
1021 case FIX_TRUNC_EXPR:
1023 case FIX_FLOOR_EXPR:
1024 case FIX_ROUND_EXPR:
1028 type = TREE_TYPE (node);
1029 op0 = TREE_OPERAND (node, 0);
1030 if (type != TREE_TYPE (op0))
1032 pp_character (buffer, '(');
1033 dump_generic_node (buffer, type, spc, flags, false);
1034 pp_string (buffer, ")");
1036 if (op_prio (op0) < op_prio (node))
1037 pp_character (buffer, '(');
1038 dump_generic_node (buffer, op0, spc, flags, false);
1039 if (op_prio (op0) < op_prio (node))
1040 pp_character (buffer, ')');
1043 case VIEW_CONVERT_EXPR:
1044 pp_string (buffer, "VIEW_CONVERT_EXPR<");
1045 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
1046 pp_string (buffer, ">(");
1047 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1048 pp_character (buffer, ')');
1051 case NON_LVALUE_EXPR:
1052 pp_string (buffer, "NON_LVALUE_EXPR <");
1053 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1054 pp_character (buffer, '>');
1058 pp_string (buffer, "SAVE_EXPR <");
1059 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1060 pp_character (buffer, '>');
1064 pp_string (buffer, "UNSAVE_EXPR <");
1065 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1066 pp_character (buffer, '>');
1073 case ENTRY_VALUE_EXPR:
1078 pp_string (buffer, "COMPLEX_EXPR <");
1079 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1080 pp_string (buffer, ", ");
1081 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1082 pp_string (buffer, ">");
1086 pp_string (buffer, "CONJ_EXPR <");
1087 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1088 pp_string (buffer, ">");
1092 pp_string (buffer, "REALPART_EXPR <");
1093 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1094 pp_string (buffer, ">");
1098 pp_string (buffer, "IMAGPART_EXPR <");
1099 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1100 pp_string (buffer, ">");
1104 pp_string (buffer, "VA_ARG_EXPR <");
1105 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1106 pp_string (buffer, ">");
1109 case TRY_FINALLY_EXPR:
1110 case TRY_CATCH_EXPR:
1111 pp_string (buffer, "try");
1112 newline_and_indent (buffer, spc+2);
1113 pp_string (buffer, "{");
1114 newline_and_indent (buffer, spc+4);
1115 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc+4, flags, true);
1116 newline_and_indent (buffer, spc+2);
1117 pp_string (buffer, "}");
1118 newline_and_indent (buffer, spc);
1120 (TREE_CODE (node) == TRY_CATCH_EXPR) ? "catch" : "finally");
1121 newline_and_indent (buffer, spc+2);
1122 pp_string (buffer, "{");
1123 newline_and_indent (buffer, spc+4);
1124 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc+4, flags, true);
1125 newline_and_indent (buffer, spc+2);
1126 pp_string (buffer, "}");
1131 pp_string (buffer, "catch (");
1132 dump_generic_node (buffer, CATCH_TYPES (node), spc+2, flags, false);
1133 pp_string (buffer, ")");
1134 newline_and_indent (buffer, spc+2);
1135 pp_string (buffer, "{");
1136 newline_and_indent (buffer, spc+4);
1137 dump_generic_node (buffer, CATCH_BODY (node), spc+4, flags, true);
1138 newline_and_indent (buffer, spc+2);
1139 pp_string (buffer, "}");
1143 case EH_FILTER_EXPR:
1144 pp_string (buffer, "<<<eh_filter (");
1145 dump_generic_node (buffer, EH_FILTER_TYPES (node), spc+2, flags, false);
1146 pp_string (buffer, ")>>>");
1147 newline_and_indent (buffer, spc+2);
1148 pp_string (buffer, "{");
1149 newline_and_indent (buffer, spc+4);
1150 dump_generic_node (buffer, EH_FILTER_FAILURE (node), spc+4, flags, true);
1151 newline_and_indent (buffer, spc+2);
1152 pp_string (buffer, "}");
1156 case GOTO_SUBROUTINE_EXPR:
1161 op0 = TREE_OPERAND (node, 0);
1162 /* If this is for break or continue, don't bother printing it. */
1163 if (DECL_NAME (op0))
1165 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1166 if (strcmp (name, "break") == 0
1167 || strcmp (name, "continue") == 0)
1170 dump_generic_node (buffer, op0, spc, flags, false);
1171 pp_character (buffer, ':');
1172 if (DECL_NONLOCAL (op0))
1173 pp_string (buffer, " [non-local]");
1176 case LABELED_BLOCK_EXPR:
1177 op0 = LABELED_BLOCK_LABEL (node);
1178 /* If this is for break or continue, don't bother printing it. */
1179 if (DECL_NAME (op0))
1181 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1182 if (strcmp (name, "break") == 0
1183 || strcmp (name, "continue") == 0)
1185 dump_generic_node (buffer, LABELED_BLOCK_BODY (node), spc, flags, false);
1189 dump_generic_node (buffer, LABELED_BLOCK_LABEL (node), spc, flags, false);
1190 pp_string (buffer, ": {");
1191 if (!(flags & TDF_SLIM))
1192 newline_and_indent (buffer, spc+2);
1193 dump_generic_node (buffer, LABELED_BLOCK_BODY (node), spc+2, flags, true);
1195 newline_and_indent (buffer, spc);
1196 pp_character (buffer, '}');
1200 case EXIT_BLOCK_EXPR:
1201 op0 = LABELED_BLOCK_LABEL (EXIT_BLOCK_LABELED_BLOCK (node));
1202 /* If this is for a break or continue, print it accordingly. */
1203 if (DECL_NAME (op0))
1205 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1206 if (strcmp (name, "break") == 0
1207 || strcmp (name, "continue") == 0)
1209 pp_string (buffer, name);
1213 pp_string (buffer, "<<<exit block ");
1214 dump_generic_node (buffer, op0, spc, flags, false);
1215 pp_string (buffer, ">>>");
1219 pp_string (buffer, "<<<exception object>>>");
1223 pp_string (buffer, "<<<filter object>>>");
1227 pp_string (buffer, "while (1)");
1228 if (!(flags & TDF_SLIM))
1230 newline_and_indent (buffer, spc+2);
1231 pp_character (buffer, '{');
1232 newline_and_indent (buffer, spc+4);
1233 dump_generic_node (buffer, LOOP_EXPR_BODY (node), spc+4, flags, true);
1234 newline_and_indent (buffer, spc+2);
1235 pp_character (buffer, '}');
1241 pp_string (buffer, "return");
1242 op0 = TREE_OPERAND (node, 0);
1246 if (TREE_CODE (op0) == MODIFY_EXPR)
1247 dump_generic_node (buffer, TREE_OPERAND (op0, 1), spc, flags, false);
1249 dump_generic_node (buffer, op0, spc, flags, false);
1254 pp_string (buffer, "if (");
1255 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1256 pp_string (buffer, ") break");
1260 pp_string (buffer, "switch (");
1261 dump_generic_node (buffer, SWITCH_COND (node), spc, flags, false);
1262 pp_character (buffer, ')');
1263 if (!(flags & TDF_SLIM))
1265 newline_and_indent (buffer, spc+2);
1266 pp_character (buffer, '{');
1267 if (SWITCH_BODY (node))
1269 newline_and_indent (buffer, spc+4);
1270 dump_generic_node (buffer, SWITCH_BODY (node), spc+4, flags, true);
1274 tree vec = SWITCH_LABELS (node);
1275 size_t i, n = TREE_VEC_LENGTH (vec);
1276 for (i = 0; i < n; ++i)
1278 tree elt = TREE_VEC_ELT (vec, i);
1279 newline_and_indent (buffer, spc+4);
1280 dump_generic_node (buffer, elt, spc+4, flags, false);
1281 pp_string (buffer, " goto ");
1282 dump_generic_node (buffer, CASE_LABEL (elt), spc+4, flags, true);
1283 pp_semicolon (buffer);
1286 newline_and_indent (buffer, spc+2);
1287 pp_character (buffer, '}');
1293 op0 = GOTO_DESTINATION (node);
1294 if (TREE_CODE (op0) != SSA_NAME
1298 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1299 if (strcmp (name, "break") == 0
1300 || strcmp (name, "continue") == 0)
1302 pp_string (buffer, name);
1306 pp_string (buffer, "goto ");
1307 dump_generic_node (buffer, op0, spc, flags, false);
1311 pp_string (buffer, "resx");
1312 /* ??? Any sensible way to present the eh region? */
1316 pp_string (buffer, "__asm__");
1317 if (ASM_VOLATILE_P (node))
1318 pp_string (buffer, " __volatile__");
1319 pp_character (buffer, '(');
1320 dump_generic_node (buffer, ASM_STRING (node), spc, flags, false);
1321 pp_character (buffer, ':');
1322 dump_generic_node (buffer, ASM_OUTPUTS (node), spc, flags, false);
1323 pp_character (buffer, ':');
1324 dump_generic_node (buffer, ASM_INPUTS (node), spc, flags, false);
1325 if (ASM_CLOBBERS (node))
1327 pp_character (buffer, ':');
1328 dump_generic_node (buffer, ASM_CLOBBERS (node), spc, flags, false);
1330 pp_string (buffer, ")");
1333 case CASE_LABEL_EXPR:
1334 if (CASE_LOW (node) && CASE_HIGH (node))
1336 pp_string (buffer, "case ");
1337 dump_generic_node (buffer, CASE_LOW (node), spc, flags, false);
1338 pp_string (buffer, " ... ");
1339 dump_generic_node (buffer, CASE_HIGH (node), spc, flags, false);
1341 else if (CASE_LOW (node))
1343 pp_string (buffer, "case ");
1344 dump_generic_node (buffer, CASE_LOW (node), spc, flags, false);
1347 pp_string (buffer, "default ");
1348 pp_character (buffer, ':');
1352 pp_string (buffer, "VTABLE_REF <(");
1353 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1354 pp_string (buffer, "),");
1355 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1356 pp_character (buffer, ',');
1357 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
1358 pp_character (buffer, '>');
1365 pp_string (buffer, " EPHI (");
1366 dump_generic_node (buffer, EREF_NAME (node), spc, flags, false);
1367 pp_string (buffer, ") ");
1368 pp_character (buffer, '[');
1369 pp_string (buffer, " class:");
1370 pp_decimal_int (buffer, EREF_CLASS (node));
1371 if (EPHI_DOWNSAFE (node))
1372 pp_string (buffer, " downsafe");
1373 if (EPHI_CANT_BE_AVAIL (node))
1374 pp_string (buffer, " cant_be_avail");
1375 if (EPHI_STOPS (node))
1376 pp_string (buffer, " stops");
1377 pp_string (buffer, " bb:");
1378 pp_decimal_int (buffer, bb_for_stmt (node)->index);
1379 pp_character (buffer, ']');
1380 if (! (flags & TDF_SLIM))
1382 pp_string (buffer, " <");
1383 for (i = 0; i < EPHI_NUM_ARGS (node); i++)
1385 if (EPHI_ARG_DEF (node, i))
1387 newline_and_indent (buffer, spc + 2);
1388 pp_string (buffer, " edge ");
1389 pp_decimal_int (buffer, EPHI_ARG_EDGE (node, i)->src->index);
1390 pp_string (buffer, "->");
1391 pp_decimal_int (buffer, EPHI_ARG_EDGE (node, i)->dest->index);
1392 pp_string (buffer, " [ ");
1393 if (EPHI_ARG_HAS_REAL_USE (node, i))
1394 pp_string (buffer, " real use");
1395 if (EPHI_ARG_INJURED (node, i))
1396 pp_string (buffer, " injured");
1397 if (EPHI_ARG_STOPS (node, i))
1398 pp_string (buffer, " stops");
1399 pp_string (buffer, " ] ");
1400 pp_string (buffer, " defined by:");
1401 dump_generic_node (buffer, EPHI_ARG_DEF (node, i),
1402 spc + 4, flags | TDF_SLIM, false);
1406 pp_string (buffer, " >");
1411 if (TREE_CODE (node) == EEXIT_NODE)
1412 pp_string (buffer, "EEXIT (");
1413 else if (TREE_CODE (node) == EKILL_NODE)
1414 pp_string (buffer, "EKILL (");
1415 dump_generic_node (buffer, EREF_NAME (node), spc, flags, false);
1416 pp_string (buffer, ") ");
1417 pp_character (buffer, '[');
1418 pp_string (buffer, "class:");
1419 pp_decimal_int (buffer, EREF_CLASS (node));
1420 pp_string (buffer, " bb:");
1421 pp_decimal_int (buffer, bb_for_stmt (node)->index);
1422 pp_character (buffer, ']');
1425 pp_string (buffer, " EUSE (");
1426 dump_generic_node (buffer, EREF_NAME (node), spc, flags, false);
1428 pp_string (buffer, ") ");
1429 pp_character (buffer, '[');
1430 pp_string (buffer, "class:");
1431 pp_decimal_int (buffer, EREF_CLASS (node));
1432 pp_string (buffer, " phiop:");
1433 pp_decimal_int (buffer, EUSE_PHIOP (node));
1434 pp_string (buffer, " bb:");
1435 pp_decimal_int (buffer, bb_for_stmt (node)->index);
1436 if (EUSE_LVAL (node))
1437 pp_string (buffer, " left-occurrence");
1438 pp_string (buffer, " ]");
1445 dump_generic_node (buffer, PHI_RESULT (node), spc, flags, false);
1446 pp_string (buffer, " = PHI <");
1447 for (i = 0; i < PHI_NUM_ARGS (node); i++)
1449 dump_generic_node (buffer, PHI_ARG_DEF (node, i), spc, flags, false);
1450 pp_string (buffer, "(");
1451 pp_decimal_int (buffer, PHI_ARG_EDGE (node, i)->src->index);
1452 pp_string (buffer, ")");
1453 if (i < PHI_NUM_ARGS (node) - 1)
1454 pp_string (buffer, ", ");
1456 pp_string (buffer, ">;");
1461 dump_generic_node (buffer, SSA_NAME_VAR (node), spc, flags, false);
1462 pp_string (buffer, "_");
1463 pp_decimal_int (buffer, SSA_NAME_VERSION (node));
1470 if (is_stmt && is_expr)
1471 pp_semicolon (buffer);
1472 pp_write_text_to_stream (buffer);
1477 /* Print the declaration of a variable. */
1480 print_declaration (pretty_printer *buffer, tree t, int spc, int flags)
1482 /* Don't print type declarations. */
1483 if (TREE_CODE (t) == TYPE_DECL)
1488 if (DECL_REGISTER (t))
1489 pp_string (buffer, "register ");
1491 if (TREE_PUBLIC (t) && DECL_EXTERNAL (t))
1492 pp_string (buffer, "extern ");
1493 else if (TREE_STATIC (t))
1494 pp_string (buffer, "static ");
1496 /* Print the type and name. */
1497 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
1501 /* Print array's type. */
1502 tmp = TREE_TYPE (t);
1503 while (TREE_CODE (TREE_TYPE (tmp)) == ARRAY_TYPE)
1504 tmp = TREE_TYPE (tmp);
1505 dump_generic_node (buffer, TREE_TYPE (tmp), spc, flags, false);
1507 /* Print variable's name. */
1509 dump_generic_node (buffer, t, spc, flags, false);
1511 /* Print the dimensions. */
1512 tmp = TREE_TYPE (t);
1513 while (TREE_CODE (tmp) == ARRAY_TYPE)
1515 pp_character (buffer, '[');
1516 if (TYPE_DOMAIN (tmp))
1518 if (TREE_CODE (TYPE_SIZE (tmp)) == INTEGER_CST)
1519 pp_wide_integer (buffer,
1520 TREE_INT_CST_LOW (TYPE_SIZE (tmp)) /
1521 TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (tmp))));
1523 dump_generic_node (buffer, TYPE_SIZE_UNIT (tmp), spc, flags,
1526 pp_character (buffer, ']');
1527 tmp = TREE_TYPE (tmp);
1532 /* Print type declaration. */
1533 dump_generic_node (buffer, TREE_TYPE (t), spc, flags, false);
1535 /* Print variable's name. */
1537 dump_generic_node (buffer, t, spc, flags, false);
1540 /* The initial value of a function serves to determine wether the function
1541 is declared or defined. So the following does not apply to function
1543 if (TREE_CODE (t) != FUNCTION_DECL)
1545 /* Print the initial value. */
1546 if (DECL_INITIAL (t))
1549 pp_character (buffer, '=');
1551 dump_generic_node (buffer, DECL_INITIAL (t), spc, flags, false);
1555 pp_character (buffer, ';');
1559 /* Prints a structure: name, fields, and methods.
1560 FIXME: Still incomplete. */
1563 print_struct_decl (pretty_printer *buffer, tree node, int spc, int flags)
1565 /* Print the name of the structure. */
1566 if (TYPE_NAME (node))
1569 if (TREE_CODE (node) == RECORD_TYPE)
1570 pp_string (buffer, "struct ");
1571 else if (TREE_CODE (node) == UNION_TYPE)
1572 pp_string (buffer, "union ");
1575 dump_generic_node (buffer, TYPE_NAME (node), spc, 0, false);
1578 /* Print the contents of the structure. */
1579 pp_newline (buffer);
1581 pp_character (buffer, '{');
1582 pp_newline (buffer);
1584 /* Print the fields of the structure. */
1587 tmp = TYPE_FIELDS (node);
1590 /* Avoid to print recursively the structure. */
1591 /* FIXME : Not implemented correctly...,
1592 what about the case when we have a cycle in the contain graph? ...
1593 Maybe this could be solved by looking at the scope in which the
1594 structure was declared. */
1595 if (TREE_TYPE (tmp) != node
1596 || (TREE_CODE (TREE_TYPE (tmp)) == POINTER_TYPE &&
1597 TREE_TYPE (TREE_TYPE (tmp)) != node))
1599 print_declaration (buffer, tmp, spc+2, flags);
1600 pp_newline (buffer);
1606 tmp = TREE_CHAIN (tmp);
1610 pp_character (buffer, '}');
1613 /* Return the priority of the operator OP.
1615 From lowest to highest precedence with either left-to-right (L-R)
1616 or right-to-left (R-L) associativity]:
1619 2 [R-L] = += -= *= /= %= &= ^= |= <<= >>=
1631 14 [R-L] ! ~ ++ -- + - * & (type) sizeof
1632 15 [L-R] fn() [] -> .
1634 unary +, - and * have higher precedence than the corresponding binary
1643 switch (TREE_CODE (op))
1658 case TRUTH_ORIF_EXPR:
1661 case TRUTH_AND_EXPR:
1662 case TRUTH_ANDIF_EXPR:
1669 case TRUTH_XOR_EXPR:
1686 case UNORDERED_EXPR:
1704 case TRUNC_DIV_EXPR:
1706 case FLOOR_DIV_EXPR:
1707 case ROUND_DIV_EXPR:
1709 case EXACT_DIV_EXPR:
1710 case TRUNC_MOD_EXPR:
1712 case FLOOR_MOD_EXPR:
1713 case ROUND_MOD_EXPR:
1716 case TRUTH_NOT_EXPR:
1718 case POSTINCREMENT_EXPR:
1719 case POSTDECREMENT_EXPR:
1720 case PREINCREMENT_EXPR:
1721 case PREDECREMENT_EXPR:
1728 case FIX_TRUNC_EXPR:
1730 case FIX_FLOOR_EXPR:
1731 case FIX_ROUND_EXPR:
1740 /* Special expressions. */
1749 case NON_LVALUE_EXPR:
1750 return op_prio (TREE_OPERAND (op, 0));
1753 /* Return an arbitrarily high precedence to avoid surrounding single
1754 VAR_DECLs in ()s. */
1760 /* Return the symbol associated with operator OP. */
1768 switch (TREE_CODE (op))
1774 case TRUTH_ORIF_EXPR:
1777 case TRUTH_AND_EXPR:
1778 case TRUTH_ANDIF_EXPR:
1784 case TRUTH_XOR_EXPR:
1794 case UNORDERED_EXPR:
1844 case TRUTH_NOT_EXPR:
1851 case TRUNC_DIV_EXPR:
1853 case FLOOR_DIV_EXPR:
1854 case ROUND_DIV_EXPR:
1856 case EXACT_DIV_EXPR:
1859 case TRUNC_MOD_EXPR:
1861 case FLOOR_MOD_EXPR:
1862 case ROUND_MOD_EXPR:
1865 case PREDECREMENT_EXPR:
1868 case PREINCREMENT_EXPR:
1871 case POSTDECREMENT_EXPR:
1874 case POSTINCREMENT_EXPR:
1877 case REFERENCE_EXPR:
1881 return "<<< ??? >>>";
1885 /* Prints the name of a CALL_EXPR. */
1888 print_call_name (pretty_printer *buffer, tree node)
1892 if (TREE_CODE (node) != CALL_EXPR)
1895 op0 = TREE_OPERAND (node, 0);
1897 if (TREE_CODE (op0) == NON_LVALUE_EXPR)
1898 op0 = TREE_OPERAND (op0, 0);
1900 switch (TREE_CODE (op0))
1904 PRINT_FUNCTION_NAME (op0);
1910 dump_generic_node (buffer, TREE_OPERAND (op0, 0), 0, 0, false);
1914 pp_string (buffer, "(");
1915 dump_generic_node (buffer, TREE_OPERAND (op0, 0), 0, 0, false);
1916 pp_string (buffer, ") ? ");
1917 dump_generic_node (buffer, TREE_OPERAND (op0, 1), 0, 0, false);
1918 pp_string (buffer, " : ");
1919 dump_generic_node (buffer, TREE_OPERAND (op0, 2), 0, 0, false);
1923 /* The function is a pointer contained in a structure. */
1924 if (TREE_CODE (TREE_OPERAND (op0, 0)) == INDIRECT_REF ||
1925 TREE_CODE (TREE_OPERAND (op0, 0)) == VAR_DECL)
1926 PRINT_FUNCTION_NAME (TREE_OPERAND (op0, 1));
1928 dump_generic_node (buffer, TREE_OPERAND (op0, 0), 0, 0, false);
1930 We can have several levels of structures and a function
1931 pointer inside. This is not implemented yet... */
1936 if (TREE_CODE (TREE_OPERAND (op0, 0)) == VAR_DECL)
1937 PRINT_FUNCTION_NAME (TREE_OPERAND (op0, 0));
1939 dump_generic_node (buffer, op0, 0, 0, false);
1943 dump_generic_node (buffer, op0, 0, 0, false);
1951 /* Parses the string STR and replaces new-lines by '\n', tabs by '\t', ... */
1954 pretty_print_string (pretty_printer *buffer, const char *str)
1964 pp_string (buffer, "\\b");
1968 pp_string (buffer, "\\f");
1972 pp_string (buffer, "\\n");
1976 pp_string (buffer, "\\r");
1980 pp_string (buffer, "\\t");
1984 pp_string (buffer, "\\v");
1988 pp_string (buffer, "\\\\");
1992 pp_string (buffer, "\\\"");
1996 pp_string (buffer, "\\'");
2000 pp_string (buffer, "\\0");
2004 pp_string (buffer, "\\1");
2008 pp_string (buffer, "\\2");
2012 pp_string (buffer, "\\3");
2016 pp_string (buffer, "\\4");
2020 pp_string (buffer, "\\5");
2024 pp_string (buffer, "\\6");
2028 pp_string (buffer, "\\7");
2032 pp_character (buffer, str[0]);
2040 maybe_init_pretty_print (FILE *file)
2044 pp_construct (&buffer, /* prefix */NULL, /* line-width */0);
2045 pp_needs_newline (&buffer) = true;
2049 buffer.buffer->stream = file;
2053 newline_and_indent (pretty_printer *buffer, int spc)
2055 pp_newline (buffer);
2060 dump_vops (pretty_printer *buffer, tree stmt, int spc, int flags)
2063 stmt_ann_t ann = stmt_ann (stmt);
2064 vdef_optype vdefs = VDEF_OPS (ann);
2065 vuse_optype vuses = VUSE_OPS (ann);
2067 for (i = 0; i < NUM_VDEFS (vdefs); i++)
2069 pp_string (buffer, "# ");
2070 dump_generic_node (buffer, VDEF_RESULT (vdefs, i), spc + 2, flags, false);
2071 pp_string (buffer, " = VDEF <");
2072 dump_generic_node (buffer, VDEF_OP (vdefs, i), spc + 2, flags, false);
2073 pp_string (buffer, ">;");
2074 newline_and_indent (buffer, spc);
2077 for (i = 0; i < NUM_VUSES (vuses); i++)
2079 tree vuse = VUSE_OP (vuses, i);
2080 pp_string (buffer, "# VUSE <");
2081 dump_generic_node (buffer, vuse, spc + 2, flags, false);
2082 pp_string (buffer, ">;");
2083 newline_and_indent (buffer, spc);
2087 /* Dumps basic block BB to FILE with details described by FLAGS and
2088 indented by INDENT spaces. */
2091 dump_generic_bb (FILE *file, basic_block bb, int indent, int flags)
2093 maybe_init_pretty_print (file);
2094 dumping_stmts = true;
2095 dump_generic_bb_buff (&buffer, bb, indent, flags);
2099 /* Dumps header of basic block BB to buffer BUFFER indented by INDENT
2100 spaces and details described by flags. */
2103 dump_bb_header (pretty_printer *buffer, basic_block bb, int indent, int flags)
2108 if (flags & TDF_BLOCKS)
2111 pp_string (buffer, "# BLOCK ");
2112 pp_decimal_int (buffer, bb->index);
2114 if (flags & TDF_LINENO)
2116 block_stmt_iterator bsi;
2118 for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
2119 if (get_lineno (bsi_stmt (bsi)) != -1)
2121 pp_string (buffer, ", starting at line ");
2122 pp_decimal_int (buffer, get_lineno (bsi_stmt (bsi)));
2126 newline_and_indent (buffer, indent);
2128 pp_string (buffer, "# PRED:");
2129 pp_write_text_to_stream (buffer);
2130 for (e = bb->pred; e; e = e->pred_next)
2131 if (flags & TDF_SLIM)
2133 pp_string (buffer, " ");
2134 if (e->src == ENTRY_BLOCK_PTR)
2135 pp_string (buffer, "ENTRY");
2137 pp_decimal_int (buffer, e->src->index);
2140 dump_edge_info (buffer->buffer->stream, e, 0);
2141 pp_newline (buffer);
2145 stmt = first_stmt (bb);
2146 if (!stmt || TREE_CODE (stmt) != LABEL_EXPR)
2148 INDENT (indent - 2);
2149 pp_string (buffer, "<bb ");
2150 pp_decimal_int (buffer, bb->index);
2151 pp_string (buffer, ">:");
2152 pp_newline (buffer);
2157 /* Dumps end of basic block BB to buffer BUFFER indented by INDENT
2161 dump_bb_end (pretty_printer *buffer, basic_block bb, int indent, int flags)
2166 pp_string (buffer, "# SUCC:");
2167 pp_write_text_to_stream (buffer);
2168 for (e = bb->succ; e; e = e->succ_next)
2169 if (flags & TDF_SLIM)
2171 pp_string (buffer, " ");
2172 if (e->dest == EXIT_BLOCK_PTR)
2173 pp_string (buffer, "EXIT");
2175 pp_decimal_int (buffer, e->dest->index);
2178 dump_edge_info (buffer->buffer->stream, e, 1);
2179 pp_newline (buffer);
2182 /* Dumps phi nodes of basic block BB to buffer BUFFER with details described by
2183 FLAGS indented by INDENT spaces. */
2186 dump_phi_nodes (pretty_printer *buffer, basic_block bb, int indent, int flags)
2188 tree phi = phi_nodes (bb);
2192 for (; phi; phi = TREE_CHAIN (phi))
2194 if (is_gimple_reg (PHI_RESULT (phi)) || (flags & TDF_VOPS))
2197 pp_string (buffer, "# ");
2198 dump_generic_node (buffer, phi, indent, flags, false);
2199 pp_newline (buffer);
2204 /* Dump jump to basic block BB that is represented implicitly in the cfg
2208 pp_cfg_jump (pretty_printer *buffer, basic_block bb)
2212 stmt = first_stmt (bb);
2214 pp_string (buffer, "goto <bb ");
2215 pp_decimal_int (buffer, bb->index);
2216 pp_string (buffer, ">");
2217 if (stmt && TREE_CODE (stmt) == LABEL_EXPR)
2219 pp_string (buffer, " (");
2220 dump_generic_node (buffer, LABEL_EXPR_LABEL (stmt), 0, 0, false);
2221 pp_string (buffer, ")");
2223 pp_semicolon (buffer);
2226 /* Dump edges represented implicitly in basic block BB to BUFFER, indented
2227 by INDENT spaces, with details given by FLAGS. */
2230 dump_implicit_edges (pretty_printer *buffer, basic_block bb, int indent)
2234 /* If there is a fallthru edge, we may need to add an artificial goto to the
2236 for (e = bb->succ; e; e = e->succ_next)
2237 if (e->flags & EDGE_FALLTHRU)
2239 if (e && e->dest != bb->next_bb)
2242 pp_cfg_jump (buffer, e->dest);
2243 pp_newline (buffer);
2247 /* Dumps basic block BB to buffer BUFFER with details described by FLAGS and
2248 indented by INDENT spaces. */
2251 dump_generic_bb_buff (pretty_printer *buffer, basic_block bb,
2252 int indent, int flags)
2254 block_stmt_iterator bsi;
2256 int label_indent = indent - 2;
2258 if (label_indent < 0)
2261 dump_bb_header (buffer, bb, indent, flags);
2264 dump_phi_nodes (buffer, bb, indent, flags);
2266 for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
2270 stmt = bsi_stmt (bsi);
2272 curr_indent = TREE_CODE (stmt) == LABEL_EXPR ? label_indent : indent;
2274 INDENT (curr_indent);
2275 dump_generic_node (buffer, stmt, curr_indent, flags, true);
2276 pp_newline (buffer);
2279 dump_implicit_edges (buffer, bb, indent);
2281 if (flags & TDF_BLOCKS)
2282 dump_bb_end (buffer, bb, indent, flags);