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"
34 #include "tree-chrec.h"
36 /* Local functions, macros and variables. */
37 static int op_prio (tree);
38 static const char *op_symbol (tree);
39 static void pretty_print_string (pretty_printer *, const char*);
40 static void print_call_name (pretty_printer *, tree);
41 static void newline_and_indent (pretty_printer *, int);
42 static void maybe_init_pretty_print (FILE *);
43 static void print_declaration (pretty_printer *, tree, int, int);
44 static void print_struct_decl (pretty_printer *, tree, int, int);
45 static void do_niy (pretty_printer *, tree);
46 static void dump_vops (pretty_printer *, tree, int, int);
47 static void dump_generic_bb_buff (pretty_printer *, basic_block, int, int);
49 #define INDENT(SPACE) do { \
50 int i; for (i = 0; i<SPACE; i++) pp_space (buffer); } while (0)
52 #define NIY do_niy(buffer,node)
54 #define PRINT_FUNCTION_NAME(NODE) pp_printf \
55 (buffer, "%s", TREE_CODE (NODE) == NOP_EXPR ? \
56 lang_hooks.decl_printable_name (TREE_OPERAND (NODE, 0), 1) : \
57 lang_hooks.decl_printable_name (NODE, 1))
59 static pretty_printer buffer;
60 static int initialized = 0;
61 static bool dumping_stmts;
63 /* Try to print something for an unknown tree code. */
66 do_niy (pretty_printer *buffer, tree node)
70 pp_string (buffer, "<<< Unknown tree: ");
71 pp_string (buffer, tree_code_name[(int) TREE_CODE (node)]);
73 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (node))))
75 len = first_rtl_op (TREE_CODE (node));
76 for (i = 0; i < len; ++i)
78 newline_and_indent (buffer, 2);
79 dump_generic_node (buffer, TREE_OPERAND (node, i), 2, 0, false);
83 pp_string (buffer, " >>>\n");
87 debug_generic_expr (tree t)
89 print_generic_expr (stderr, t, TDF_VOPS|TDF_UID);
90 fprintf (stderr, "\n");
94 debug_generic_stmt (tree t)
96 print_generic_stmt (stderr, t, TDF_VOPS|TDF_UID);
97 fprintf (stderr, "\n");
100 /* Prints declaration DECL to the FILE with details specified by FLAGS. */
102 print_generic_decl (FILE *file, tree decl, int flags)
104 maybe_init_pretty_print (file);
105 dumping_stmts = true;
106 print_declaration (&buffer, decl, 2, flags);
107 pp_write_text_to_stream (&buffer);
110 /* Print tree T, and its successors, on file FILE. FLAGS specifies details
111 to show in the dump. See TDF_* in tree.h. */
114 print_generic_stmt (FILE *file, tree t, int flags)
116 maybe_init_pretty_print (file);
117 dumping_stmts = true;
118 dump_generic_node (&buffer, t, 0, flags, true);
122 /* Print tree T, and its successors, on file FILE. FLAGS specifies details
123 to show in the dump. See TDF_* in tree.h. The output is indented by
127 print_generic_stmt_indented (FILE *file, tree t, int flags, int indent)
131 maybe_init_pretty_print (file);
132 dumping_stmts = true;
134 for (i = 0; i < indent; i++)
136 dump_generic_node (&buffer, t, indent, flags, true);
140 /* Print a single expression T on file FILE. FLAGS specifies details to show
141 in the dump. See TDF_* in tree.h. */
144 print_generic_expr (FILE *file, tree t, int flags)
146 maybe_init_pretty_print (file);
147 dumping_stmts = false;
148 dump_generic_node (&buffer, t, 0, flags, false);
151 /* Dump the name of a _DECL node and its DECL_UID if TDF_UID is set
155 dump_decl_name (pretty_printer *buffer, tree node, int flags)
157 if (DECL_NAME (node))
158 pp_tree_identifier (buffer, DECL_NAME (node));
160 if ((flags & TDF_UID)
161 || DECL_NAME (node) == NULL_TREE)
163 if (TREE_CODE (node) == LABEL_DECL
164 && LABEL_DECL_UID (node) != -1)
165 pp_printf (buffer, "<L" HOST_WIDE_INT_PRINT_DEC ">",
166 LABEL_DECL_UID (node));
168 pp_printf (buffer, "<D%u>", DECL_UID (node));
172 /* Dump a function declaration. NODE is the FUNCTION_TYPE. BUFFER, SPC and
173 FLAGS are as in dump_generic_node. */
176 dump_function_declaration (pretty_printer *buffer, tree node,
179 bool wrote_arg = false;
183 pp_character (buffer, '(');
185 /* Print the argument types. The last element in the list is a VOID_TYPE.
186 The following avoids printing the last element. */
187 arg = TYPE_ARG_TYPES (node);
188 while (arg && TREE_CHAIN (arg) && arg != error_mark_node)
191 dump_generic_node (buffer, TREE_VALUE (arg), spc, flags, false);
192 arg = TREE_CHAIN (arg);
193 if (TREE_CHAIN (arg) && TREE_CODE (TREE_CHAIN (arg)) == TREE_LIST)
195 pp_character (buffer, ',');
201 pp_string (buffer, "void");
203 pp_character (buffer, ')');
206 /* Dump the node NODE on the pretty_printer BUFFER, SPC spaces of indent.
207 FLAGS specifies details to show in the dump (see TDF_* in tree.h). If
208 IS_STMT is true, the object printed is considered to be a statement
209 and it is terminated by ';' if appropriate. */
212 dump_generic_node (pretty_printer *buffer, tree node, int spc, int flags,
220 if (node == NULL_TREE)
223 is_expr = EXPR_P (node);
225 if (TREE_CODE (node) != ERROR_MARK
226 && is_gimple_stmt (node)
227 && (flags & TDF_VOPS)
229 dump_vops (buffer, node, spc, flags);
232 && (flags & TDF_LINENO)
233 && EXPR_HAS_LOCATION (node))
235 expanded_location xloc = expand_location (EXPR_LOCATION (node));
236 pp_character (buffer, '[');
239 pp_string (buffer, xloc.file);
240 pp_string (buffer, " : ");
242 pp_decimal_int (buffer, xloc.line);
243 pp_string (buffer, "] ");
246 switch (TREE_CODE (node))
249 pp_string (buffer, "<<< error >>>");
252 case IDENTIFIER_NODE:
253 pp_tree_identifier (buffer, node);
257 while (node && node != error_mark_node)
259 if (TREE_PURPOSE (node))
261 dump_generic_node (buffer, TREE_PURPOSE (node), spc, flags, false);
264 dump_generic_node (buffer, TREE_VALUE (node), spc, flags, false);
265 node = TREE_CHAIN (node);
266 if (node && TREE_CODE (node) == TREE_LIST)
268 pp_character (buffer, ',');
275 dump_generic_node (buffer, BINFO_TYPE (node), spc, flags, false);
291 unsigned int quals = TYPE_QUALS (node);
294 if (quals & TYPE_QUAL_CONST)
295 pp_string (buffer, "const ");
296 else if (quals & TYPE_QUAL_VOLATILE)
297 pp_string (buffer, "volatile ");
298 else if (quals & TYPE_QUAL_RESTRICT)
299 pp_string (buffer, "restrict ");
301 class = TREE_CODE_CLASS (TREE_CODE (node));
305 if (DECL_NAME (node))
306 dump_decl_name (buffer, node, flags);
308 pp_string (buffer, "<unnamed type decl>");
310 else if (class == 't')
312 if (TYPE_NAME (node))
314 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
315 pp_tree_identifier (buffer, TYPE_NAME (node));
316 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
317 && DECL_NAME (TYPE_NAME (node)))
318 dump_decl_name (buffer, TYPE_NAME (node), flags);
320 pp_string (buffer, "<unnamed type>");
323 pp_string (buffer, "<unnamed type>");
330 str = (TREE_CODE (node) == POINTER_TYPE ? "*" : "&");
332 if (TREE_CODE (TREE_TYPE (node)) == FUNCTION_TYPE)
334 tree fnode = TREE_TYPE (node);
336 dump_generic_node (buffer, TREE_TYPE (fnode), spc, flags, false);
338 pp_character (buffer, '(');
339 pp_string (buffer, str);
340 if (TYPE_NAME (node) && DECL_NAME (TYPE_NAME (node)))
341 dump_decl_name (buffer, TYPE_NAME (node), flags);
343 pp_printf (buffer, "<T%x>", TYPE_UID (node));
345 pp_character (buffer, ')');
346 dump_function_declaration (buffer, fnode, spc, flags);
350 unsigned int quals = TYPE_QUALS (node);
352 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
354 pp_string (buffer, str);
356 if (quals & TYPE_QUAL_CONST)
357 pp_string (buffer, " const");
358 else if (quals & TYPE_QUAL_VOLATILE)
359 pp_string (buffer, "volatile");
360 else if (quals & TYPE_QUAL_RESTRICT)
361 pp_string (buffer, " restrict");
370 dump_decl_name (buffer, TYPE_NAME (TYPE_METHOD_BASETYPE (node)), flags);
371 pp_string (buffer, "::");
382 /* Print the innermost component type. */
383 for (tmp = TREE_TYPE (node); TREE_CODE (tmp) == ARRAY_TYPE;
384 tmp = TREE_TYPE (tmp))
386 dump_generic_node (buffer, tmp, spc, flags, false);
388 /* Print the dimensions. */
389 for (tmp = node; TREE_CODE (tmp) == ARRAY_TYPE;
390 tmp = TREE_TYPE (tmp))
392 tree domain = TYPE_DOMAIN (tmp);
394 pp_character (buffer, '[');
397 if (TYPE_MIN_VALUE (domain)
398 && !integer_zerop (TYPE_MIN_VALUE (domain)))
400 dump_generic_node (buffer, TYPE_MIN_VALUE (domain),
402 pp_string (buffer, " .. ");
405 if (TYPE_MAX_VALUE (domain))
406 dump_generic_node (buffer, TYPE_MAX_VALUE (domain),
410 pp_string (buffer, "<unknown>");
412 pp_character (buffer, ']');
423 case QUAL_UNION_TYPE:
424 /* Print the name of the structure. */
425 if (TREE_CODE (node) == RECORD_TYPE)
426 pp_string (buffer, "struct ");
427 else if (TREE_CODE (node) == UNION_TYPE)
428 pp_string (buffer, "union ");
430 if (TYPE_NAME (node))
431 dump_generic_node (buffer, TYPE_NAME (node), spc, flags, false);
433 print_struct_decl (buffer, node, spc, flags);
441 if (TREE_CODE (TREE_TYPE (node)) == POINTER_TYPE)
443 /* In the case of a pointer, one may want to divide by the
444 size of the pointed-to type. Unfortunately, this not
445 straightforward. The C front-end maps expressions
450 in such a way that the two INTEGER_CST nodes for "5" have
451 different values but identical types. In the latter
452 case, the 5 is multiplied by sizeof (int) in c-common.c
453 (pointer_int_sum) to convert it to a byte address, and
454 yet the type of the node is left unchanged. Argh. What
455 is consistent though is that the number value corresponds
456 to bytes (UNITS) offset.
458 NB: Neither of the following divisors can be trivially
459 used to recover the original literal:
461 TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (node)))
462 TYPE_PRECISION (TREE_TYPE (TREE_TYPE (node))) */
463 pp_wide_integer (buffer, TREE_INT_CST_LOW (node));
464 pp_string (buffer, "B"); /* pseudo-unit */
466 else if (! host_integerp (node, 0))
470 if (tree_int_cst_sgn (val) < 0)
472 pp_character (buffer, '-');
473 val = build_int_2 (-TREE_INT_CST_LOW (val),
474 ~TREE_INT_CST_HIGH (val)
475 + !TREE_INT_CST_LOW (val));
477 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
480 static char format[10]; /* "%x%09999x\0" */
482 sprintf (format, "%%x%%0%dx", HOST_BITS_PER_INT / 4);
483 sprintf (pp_buffer (buffer)->digit_buffer, format,
484 TREE_INT_CST_HIGH (val),
485 TREE_INT_CST_LOW (val));
486 pp_string (buffer, pp_buffer (buffer)->digit_buffer);
490 pp_wide_integer (buffer, TREE_INT_CST_LOW (node));
494 /* Code copied from print_node. */
497 if (TREE_OVERFLOW (node))
498 pp_string (buffer, " overflow");
500 #if !defined(REAL_IS_NOT_DOUBLE) || defined(REAL_ARITHMETIC)
501 d = TREE_REAL_CST (node);
502 if (REAL_VALUE_ISINF (d))
503 pp_string (buffer, " Inf");
504 else if (REAL_VALUE_ISNAN (d))
505 pp_string (buffer, " Nan");
509 real_to_decimal (string, &d, sizeof (string), 0, 1);
510 pp_string (buffer, string);
515 unsigned char *p = (unsigned char *) &TREE_REAL_CST (node);
516 pp_string (buffer, "0x");
517 for (i = 0; i < sizeof TREE_REAL_CST (node); i++)
518 output_formatted_integer (buffer, "%02x", *p++);
525 pp_string (buffer, "__complex__ (");
526 dump_generic_node (buffer, TREE_REALPART (node), spc, flags, false);
527 pp_string (buffer, ", ");
528 dump_generic_node (buffer, TREE_IMAGPART (node), spc, flags, false);
529 pp_string (buffer, ")");
533 pp_string (buffer, "\"");
534 pretty_print_string (buffer, TREE_STRING_POINTER (node));
535 pp_string (buffer, "\"");
541 pp_string (buffer, "{ ");
542 for (elt = TREE_VECTOR_CST_ELTS (node); elt; elt = TREE_CHAIN (elt))
544 dump_generic_node (buffer, TREE_VALUE (elt), spc, flags, false);
545 if (TREE_CHAIN (elt))
546 pp_string (buffer, ", ");
548 pp_string (buffer, " }");
557 dump_decl_name (buffer, node, flags);
561 if (DECL_NAME (node))
562 dump_decl_name (buffer, node, flags);
563 else if (LABEL_DECL_UID (node) != -1)
564 pp_printf (buffer, "<L" HOST_WIDE_INT_PRINT_DEC ">",
565 LABEL_DECL_UID (node));
567 pp_printf (buffer, "<D%u>", DECL_UID (node));
571 if (DECL_IS_BUILTIN (node))
573 /* Don't print the declaration of built-in types. */
576 if (DECL_NAME (node))
577 dump_decl_name (buffer, node, flags);
580 if ((TREE_CODE (TREE_TYPE (node)) == RECORD_TYPE
581 || TREE_CODE (TREE_TYPE (node)) == UNION_TYPE)
582 && TYPE_METHODS (TREE_TYPE (node)))
584 /* The type is a c++ class: all structures have at least
586 pp_string (buffer, "class ");
587 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
592 (TREE_CODE (TREE_TYPE (node)) == UNION_TYPE
593 ? "union" : "struct "));
594 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
603 dump_decl_name (buffer, node, flags);
607 pp_string (buffer, "<retval>");
611 op0 = TREE_OPERAND (node, 0);
613 if (TREE_CODE (op0) == INDIRECT_REF)
615 op0 = TREE_OPERAND (op0, 0);
618 if (op_prio (op0) < op_prio (node))
619 pp_character (buffer, '(');
620 dump_generic_node (buffer, op0, spc, flags, false);
621 if (op_prio (op0) < op_prio (node))
622 pp_character (buffer, ')');
623 pp_string (buffer, str);
624 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
626 op0 = component_ref_field_offset (node);
627 if (op0 && TREE_CODE (op0) != INTEGER_CST)
629 pp_string (buffer, "{off: ");
630 dump_generic_node (buffer, op0, spc, flags, false);
631 pp_character (buffer, '}');
636 pp_string (buffer, "BIT_FIELD_REF <");
637 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
638 pp_string (buffer, ", ");
639 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
640 pp_string (buffer, ", ");
641 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
642 pp_string (buffer, ">");
646 case ARRAY_RANGE_REF:
647 op0 = TREE_OPERAND (node, 0);
648 if (op_prio (op0) < op_prio (node))
649 pp_character (buffer, '(');
650 dump_generic_node (buffer, op0, spc, flags, false);
651 if (op_prio (op0) < op_prio (node))
652 pp_character (buffer, ')');
653 pp_character (buffer, '[');
654 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
655 if (TREE_CODE (node) == ARRAY_RANGE_REF)
656 pp_string (buffer, " ...");
657 pp_character (buffer, ']');
659 op0 = array_ref_low_bound (node);
660 op1 = array_ref_element_size (node);
662 if (!integer_zerop (op0)
663 || (TYPE_SIZE_UNIT (TREE_TYPE (node))
664 && !operand_equal_p (op1, TYPE_SIZE_UNIT (TREE_TYPE (node)), 0)))
666 pp_string (buffer, "{lb: ");
667 dump_generic_node (buffer, op0, spc, flags, false);
668 pp_string (buffer, " sz: ");
669 dump_generic_node (buffer, op1, spc, flags, false);
670 pp_character (buffer, '}');
677 bool is_struct_init = FALSE;
678 pp_character (buffer, '{');
679 lnode = CONSTRUCTOR_ELTS (node);
680 if (TREE_CODE (TREE_TYPE (node)) == RECORD_TYPE
681 || TREE_CODE (TREE_TYPE (node)) == UNION_TYPE)
682 is_struct_init = TRUE;
683 while (lnode && lnode != error_mark_node)
686 if (TREE_PURPOSE (lnode) && is_struct_init)
688 pp_character (buffer, '.');
689 dump_generic_node (buffer, TREE_PURPOSE (lnode), spc, flags, false);
690 pp_string (buffer, "=");
692 val = TREE_VALUE (lnode);
693 if (val && TREE_CODE (val) == ADDR_EXPR)
694 if (TREE_CODE (TREE_OPERAND (val, 0)) == FUNCTION_DECL)
695 val = TREE_OPERAND (val, 0);
696 if (val && TREE_CODE (val) == FUNCTION_DECL)
698 dump_decl_name (buffer, val, flags);
702 dump_generic_node (buffer, TREE_VALUE (lnode), spc, flags, false);
704 lnode = TREE_CHAIN (lnode);
705 if (lnode && TREE_CODE (lnode) == TREE_LIST)
707 pp_character (buffer, ',');
711 pp_character (buffer, '}');
718 if (flags & TDF_SLIM)
720 pp_string (buffer, "<COMPOUND_EXPR>");
724 dump_generic_node (buffer, TREE_OPERAND (node, 0),
725 spc, flags, dumping_stmts);
727 newline_and_indent (buffer, spc);
730 pp_character (buffer, ',');
734 for (tp = &TREE_OPERAND (node, 1);
735 TREE_CODE (*tp) == COMPOUND_EXPR;
736 tp = &TREE_OPERAND (*tp, 1))
738 dump_generic_node (buffer, TREE_OPERAND (*tp, 0),
739 spc, flags, dumping_stmts);
741 newline_and_indent (buffer, spc);
744 pp_character (buffer, ',');
749 dump_generic_node (buffer, *tp, spc, flags, dumping_stmts);
755 tree_stmt_iterator si;
758 if ((flags & TDF_SLIM) || !dumping_stmts)
760 pp_string (buffer, "<STATEMENT_LIST>");
764 for (si = tsi_start (node); !tsi_end_p (si); tsi_next (&si))
767 newline_and_indent (buffer, spc);
770 dump_generic_node (buffer, tsi_stmt (si), spc, flags, true);
777 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
779 pp_character (buffer, '=');
781 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
785 pp_string (buffer, "TARGET_EXPR <");
786 dump_generic_node (buffer, TARGET_EXPR_SLOT (node), spc, flags, false);
787 pp_character (buffer, ',');
789 dump_generic_node (buffer, TARGET_EXPR_INITIAL (node), spc, flags, false);
790 pp_character (buffer, '>');
794 print_declaration (buffer, DECL_EXPR_DECL (node), spc, flags);
799 if (TREE_TYPE (node) == NULL || TREE_TYPE (node) == void_type_node)
801 pp_string (buffer, "if (");
802 dump_generic_node (buffer, COND_EXPR_COND (node), spc, flags, false);
803 pp_character (buffer, ')');
804 /* The lowered cond_exprs should always be printed in full. */
805 if (COND_EXPR_THEN (node)
806 && TREE_CODE (COND_EXPR_THEN (node)) == GOTO_EXPR
807 && COND_EXPR_ELSE (node)
808 && TREE_CODE (COND_EXPR_ELSE (node)) == GOTO_EXPR)
811 dump_generic_node (buffer, COND_EXPR_THEN (node), 0, flags, true);
812 pp_string (buffer, " else ");
813 dump_generic_node (buffer, COND_EXPR_ELSE (node), 0, flags, true);
815 else if (!(flags & TDF_SLIM))
817 /* Output COND_EXPR_THEN. */
818 if (COND_EXPR_THEN (node))
820 newline_and_indent (buffer, spc+2);
821 pp_character (buffer, '{');
822 newline_and_indent (buffer, spc+4);
823 dump_generic_node (buffer, COND_EXPR_THEN (node), spc+4,
825 newline_and_indent (buffer, spc+2);
826 pp_character (buffer, '}');
829 /* Output COND_EXPR_ELSE. */
830 if (COND_EXPR_ELSE (node))
832 newline_and_indent (buffer, spc);
833 pp_string (buffer, "else");
834 newline_and_indent (buffer, spc+2);
835 pp_character (buffer, '{');
836 newline_and_indent (buffer, spc+4);
837 dump_generic_node (buffer, COND_EXPR_ELSE (node), spc+4,
839 newline_and_indent (buffer, spc+2);
840 pp_character (buffer, '}');
847 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
849 pp_character (buffer, '?');
851 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
853 pp_character (buffer, ':');
855 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
860 pp_character (buffer, '{');
861 if (!(flags & TDF_SLIM))
863 if (BIND_EXPR_VARS (node))
867 for (op0 = BIND_EXPR_VARS (node); op0; op0 = TREE_CHAIN (op0))
869 print_declaration (buffer, op0, spc+2, flags);
874 newline_and_indent (buffer, spc+2);
875 dump_generic_node (buffer, BIND_EXPR_BODY (node), spc+2, flags, true);
876 newline_and_indent (buffer, spc);
877 pp_character (buffer, '}');
883 print_call_name (buffer, node);
885 /* Print parameters. */
887 pp_character (buffer, '(');
888 op1 = TREE_OPERAND (node, 1);
890 dump_generic_node (buffer, op1, spc, flags, false);
891 pp_character (buffer, ')');
893 op1 = TREE_OPERAND (node, 2);
896 pp_string (buffer, " [static-chain: ");
897 dump_generic_node (buffer, op1, spc, flags, false);
898 pp_character (buffer, ']');
901 if (CALL_EXPR_HAS_RETURN_SLOT_ADDR (node))
902 pp_string (buffer, " [return slot addr]");
903 if (CALL_EXPR_TAILCALL (node))
904 pp_string (buffer, " [tail call]");
907 case WITH_CLEANUP_EXPR:
911 case CLEANUP_POINT_EXPR:
912 pp_string (buffer, "<<cleanup_point ");
913 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
914 pp_string (buffer, ">>");
917 case PLACEHOLDER_EXPR:
918 pp_string (buffer, "<PLACEHOLDER_EXPR ");
919 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
920 pp_character (buffer, '>');
923 /* Binary arithmetic and logic expressions. */
944 case TRUTH_ANDIF_EXPR:
945 case TRUTH_ORIF_EXPR:
964 const char *op = op_symbol (node);
965 op0 = TREE_OPERAND (node, 0);
966 op1 = TREE_OPERAND (node, 1);
968 /* When the operands are expressions with less priority,
969 keep semantics of the tree representation. */
970 if (op_prio (op0) < op_prio (node))
972 pp_character (buffer, '(');
973 dump_generic_node (buffer, op0, spc, flags, false);
974 pp_character (buffer, ')');
977 dump_generic_node (buffer, op0, spc, flags, false);
980 pp_string (buffer, op);
983 /* When the operands are expressions with less priority,
984 keep semantics of the tree representation. */
985 if (op_prio (op1) < op_prio (node))
987 pp_character (buffer, '(');
988 dump_generic_node (buffer, op1, spc, flags, false);
989 pp_character (buffer, ')');
992 dump_generic_node (buffer, op1, spc, flags, false);
996 /* Unary arithmetic and logic expressions. */
1001 case PREDECREMENT_EXPR:
1002 case PREINCREMENT_EXPR:
1004 if (TREE_CODE (node) == ADDR_EXPR
1005 && (TREE_CODE (TREE_OPERAND (node, 0)) == STRING_CST
1006 || TREE_CODE (TREE_OPERAND (node, 0)) == FUNCTION_DECL))
1007 ; /* Do not output '&' for strings and function pointers. */
1009 pp_string (buffer, op_symbol (node));
1011 if (op_prio (TREE_OPERAND (node, 0)) < op_prio (node))
1013 pp_character (buffer, '(');
1014 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1015 pp_character (buffer, ')');
1018 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1021 case POSTDECREMENT_EXPR:
1022 case POSTINCREMENT_EXPR:
1023 if (op_prio (TREE_OPERAND (node, 0)) < op_prio (node))
1025 pp_character (buffer, '(');
1026 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1027 pp_character (buffer, ')');
1030 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1031 pp_string (buffer, op_symbol (node));
1035 pp_string (buffer, "MIN_EXPR <");
1036 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1037 pp_string (buffer, ", ");
1038 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1039 pp_character (buffer, '>');
1043 pp_string (buffer, "MAX_EXPR <");
1044 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1045 pp_string (buffer, ", ");
1046 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1047 pp_character (buffer, '>');
1051 pp_string (buffer, "ABS_EXPR <");
1052 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1053 pp_character (buffer, '>');
1060 case FIX_TRUNC_EXPR:
1062 case FIX_FLOOR_EXPR:
1063 case FIX_ROUND_EXPR:
1067 type = TREE_TYPE (node);
1068 op0 = TREE_OPERAND (node, 0);
1069 if (type != TREE_TYPE (op0))
1071 pp_character (buffer, '(');
1072 dump_generic_node (buffer, type, spc, flags, false);
1073 pp_string (buffer, ")");
1075 if (op_prio (op0) < op_prio (node))
1076 pp_character (buffer, '(');
1077 dump_generic_node (buffer, op0, spc, flags, false);
1078 if (op_prio (op0) < op_prio (node))
1079 pp_character (buffer, ')');
1082 case VIEW_CONVERT_EXPR:
1083 pp_string (buffer, "VIEW_CONVERT_EXPR<");
1084 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
1085 pp_string (buffer, ">(");
1086 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1087 pp_character (buffer, ')');
1090 case NON_LVALUE_EXPR:
1091 pp_string (buffer, "NON_LVALUE_EXPR <");
1092 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1093 pp_character (buffer, '>');
1097 pp_string (buffer, "SAVE_EXPR <");
1098 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1099 pp_character (buffer, '>');
1103 pp_string (buffer, "UNSAVE_EXPR <");
1104 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1105 pp_character (buffer, '>');
1108 case ENTRY_VALUE_EXPR:
1113 pp_string (buffer, "COMPLEX_EXPR <");
1114 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1115 pp_string (buffer, ", ");
1116 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1117 pp_string (buffer, ">");
1121 pp_string (buffer, "CONJ_EXPR <");
1122 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1123 pp_string (buffer, ">");
1127 pp_string (buffer, "REALPART_EXPR <");
1128 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1129 pp_string (buffer, ">");
1133 pp_string (buffer, "IMAGPART_EXPR <");
1134 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1135 pp_string (buffer, ">");
1139 pp_string (buffer, "VA_ARG_EXPR <");
1140 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1141 pp_string (buffer, ">");
1144 case TRY_FINALLY_EXPR:
1145 case TRY_CATCH_EXPR:
1146 pp_string (buffer, "try");
1147 newline_and_indent (buffer, spc+2);
1148 pp_string (buffer, "{");
1149 newline_and_indent (buffer, spc+4);
1150 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc+4, flags, true);
1151 newline_and_indent (buffer, spc+2);
1152 pp_string (buffer, "}");
1153 newline_and_indent (buffer, spc);
1155 (TREE_CODE (node) == TRY_CATCH_EXPR) ? "catch" : "finally");
1156 newline_and_indent (buffer, spc+2);
1157 pp_string (buffer, "{");
1158 newline_and_indent (buffer, spc+4);
1159 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc+4, flags, true);
1160 newline_and_indent (buffer, spc+2);
1161 pp_string (buffer, "}");
1166 pp_string (buffer, "catch (");
1167 dump_generic_node (buffer, CATCH_TYPES (node), spc+2, flags, false);
1168 pp_string (buffer, ")");
1169 newline_and_indent (buffer, spc+2);
1170 pp_string (buffer, "{");
1171 newline_and_indent (buffer, spc+4);
1172 dump_generic_node (buffer, CATCH_BODY (node), spc+4, flags, true);
1173 newline_and_indent (buffer, spc+2);
1174 pp_string (buffer, "}");
1178 case EH_FILTER_EXPR:
1179 pp_string (buffer, "<<<eh_filter (");
1180 dump_generic_node (buffer, EH_FILTER_TYPES (node), spc+2, flags, false);
1181 pp_string (buffer, ")>>>");
1182 newline_and_indent (buffer, spc+2);
1183 pp_string (buffer, "{");
1184 newline_and_indent (buffer, spc+4);
1185 dump_generic_node (buffer, EH_FILTER_FAILURE (node), spc+4, flags, true);
1186 newline_and_indent (buffer, spc+2);
1187 pp_string (buffer, "}");
1192 op0 = TREE_OPERAND (node, 0);
1193 /* If this is for break or continue, don't bother printing it. */
1194 if (DECL_NAME (op0))
1196 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1197 if (strcmp (name, "break") == 0
1198 || strcmp (name, "continue") == 0)
1201 dump_generic_node (buffer, op0, spc, flags, false);
1202 pp_character (buffer, ':');
1203 if (DECL_NONLOCAL (op0))
1204 pp_string (buffer, " [non-local]");
1207 case LABELED_BLOCK_EXPR:
1208 op0 = LABELED_BLOCK_LABEL (node);
1209 /* If this is for break or continue, don't bother printing it. */
1210 if (DECL_NAME (op0))
1212 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1213 if (strcmp (name, "break") == 0
1214 || strcmp (name, "continue") == 0)
1216 dump_generic_node (buffer, LABELED_BLOCK_BODY (node), spc, flags, false);
1220 dump_generic_node (buffer, LABELED_BLOCK_LABEL (node), spc, flags, false);
1221 pp_string (buffer, ": {");
1222 if (!(flags & TDF_SLIM))
1223 newline_and_indent (buffer, spc+2);
1224 dump_generic_node (buffer, LABELED_BLOCK_BODY (node), spc+2, flags, true);
1226 newline_and_indent (buffer, spc);
1227 pp_character (buffer, '}');
1231 case EXIT_BLOCK_EXPR:
1232 op0 = LABELED_BLOCK_LABEL (EXIT_BLOCK_LABELED_BLOCK (node));
1233 /* If this is for a break or continue, print it accordingly. */
1234 if (DECL_NAME (op0))
1236 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1237 if (strcmp (name, "break") == 0
1238 || strcmp (name, "continue") == 0)
1240 pp_string (buffer, name);
1244 pp_string (buffer, "<<<exit block ");
1245 dump_generic_node (buffer, op0, spc, flags, false);
1246 pp_string (buffer, ">>>");
1250 pp_string (buffer, "<<<exception object>>>");
1254 pp_string (buffer, "<<<filter object>>>");
1258 pp_string (buffer, "while (1)");
1259 if (!(flags & TDF_SLIM))
1261 newline_and_indent (buffer, spc+2);
1262 pp_character (buffer, '{');
1263 newline_and_indent (buffer, spc+4);
1264 dump_generic_node (buffer, LOOP_EXPR_BODY (node), spc+4, flags, true);
1265 newline_and_indent (buffer, spc+2);
1266 pp_character (buffer, '}');
1272 pp_string (buffer, "return");
1273 op0 = TREE_OPERAND (node, 0);
1277 if (TREE_CODE (op0) == MODIFY_EXPR)
1278 dump_generic_node (buffer, TREE_OPERAND (op0, 1), spc, flags, false);
1280 dump_generic_node (buffer, op0, spc, flags, false);
1285 pp_string (buffer, "if (");
1286 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1287 pp_string (buffer, ") break");
1291 pp_string (buffer, "switch (");
1292 dump_generic_node (buffer, SWITCH_COND (node), spc, flags, false);
1293 pp_character (buffer, ')');
1294 if (!(flags & TDF_SLIM))
1296 newline_and_indent (buffer, spc+2);
1297 pp_character (buffer, '{');
1298 if (SWITCH_BODY (node))
1300 newline_and_indent (buffer, spc+4);
1301 dump_generic_node (buffer, SWITCH_BODY (node), spc+4, flags, true);
1305 tree vec = SWITCH_LABELS (node);
1306 size_t i, n = TREE_VEC_LENGTH (vec);
1307 for (i = 0; i < n; ++i)
1309 tree elt = TREE_VEC_ELT (vec, i);
1310 newline_and_indent (buffer, spc+4);
1311 dump_generic_node (buffer, elt, spc+4, flags, false);
1312 pp_string (buffer, " goto ");
1313 dump_generic_node (buffer, CASE_LABEL (elt), spc+4, flags, true);
1314 pp_semicolon (buffer);
1317 newline_and_indent (buffer, spc+2);
1318 pp_character (buffer, '}');
1324 op0 = GOTO_DESTINATION (node);
1325 if (TREE_CODE (op0) != SSA_NAME
1329 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1330 if (strcmp (name, "break") == 0
1331 || strcmp (name, "continue") == 0)
1333 pp_string (buffer, name);
1337 pp_string (buffer, "goto ");
1338 dump_generic_node (buffer, op0, spc, flags, false);
1342 pp_string (buffer, "resx");
1343 /* ??? Any sensible way to present the eh region? */
1347 pp_string (buffer, "__asm__");
1348 if (ASM_VOLATILE_P (node))
1349 pp_string (buffer, " __volatile__");
1350 pp_character (buffer, '(');
1351 dump_generic_node (buffer, ASM_STRING (node), spc, flags, false);
1352 pp_character (buffer, ':');
1353 dump_generic_node (buffer, ASM_OUTPUTS (node), spc, flags, false);
1354 pp_character (buffer, ':');
1355 dump_generic_node (buffer, ASM_INPUTS (node), spc, flags, false);
1356 if (ASM_CLOBBERS (node))
1358 pp_character (buffer, ':');
1359 dump_generic_node (buffer, ASM_CLOBBERS (node), spc, flags, false);
1361 pp_string (buffer, ")");
1364 case CASE_LABEL_EXPR:
1365 if (CASE_LOW (node) && CASE_HIGH (node))
1367 pp_string (buffer, "case ");
1368 dump_generic_node (buffer, CASE_LOW (node), spc, flags, false);
1369 pp_string (buffer, " ... ");
1370 dump_generic_node (buffer, CASE_HIGH (node), spc, flags, false);
1372 else if (CASE_LOW (node))
1374 pp_string (buffer, "case ");
1375 dump_generic_node (buffer, CASE_LOW (node), spc, flags, false);
1378 pp_string (buffer, "default ");
1379 pp_character (buffer, ':');
1383 pp_string (buffer, "OBJ_TYPE_REF(");
1384 dump_generic_node (buffer, OBJ_TYPE_REF_EXPR (node), spc, flags, false);
1385 pp_character (buffer, ';');
1386 dump_generic_node (buffer, OBJ_TYPE_REF_OBJECT (node), spc, flags, false);
1387 pp_character (buffer, '-');
1388 pp_character (buffer, '>');
1389 dump_generic_node (buffer, OBJ_TYPE_REF_TOKEN (node), spc, flags, false);
1390 pp_character (buffer, ')');
1397 dump_generic_node (buffer, PHI_RESULT (node), spc, flags, false);
1398 pp_string (buffer, " = PHI <");
1399 for (i = 0; i < PHI_NUM_ARGS (node); i++)
1401 dump_generic_node (buffer, PHI_ARG_DEF (node, i), spc, flags, false);
1402 pp_string (buffer, "(");
1403 pp_decimal_int (buffer, PHI_ARG_EDGE (node, i)->src->index);
1404 pp_string (buffer, ")");
1405 if (i < PHI_NUM_ARGS (node) - 1)
1406 pp_string (buffer, ", ");
1408 pp_string (buffer, ">;");
1413 dump_generic_node (buffer, SSA_NAME_VAR (node), spc, flags, false);
1414 pp_string (buffer, "_");
1415 pp_decimal_int (buffer, SSA_NAME_VERSION (node));
1418 case WITH_SIZE_EXPR:
1419 pp_string (buffer, "WITH_SIZE_EXPR <");
1420 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1421 pp_string (buffer, ", ");
1422 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1423 pp_string (buffer, ">");
1427 pp_printf (buffer, "VH.%d", VALUE_HANDLE_ID (node));
1431 pp_string (buffer, "scev_known");
1434 case SCEV_NOT_KNOWN:
1435 pp_string (buffer, "scev_not_known");
1438 case POLYNOMIAL_CHREC:
1439 pp_string (buffer, "{");
1440 dump_generic_node (buffer, CHREC_LEFT (node), spc, flags, false);
1441 pp_string (buffer, ", +, ");
1442 dump_generic_node (buffer, CHREC_RIGHT (node), spc, flags, false);
1443 pp_string (buffer, "}_");
1444 dump_generic_node (buffer, CHREC_VAR (node), spc, flags, false);
1452 if (is_stmt && is_expr)
1453 pp_semicolon (buffer);
1454 pp_write_text_to_stream (buffer);
1459 /* Print the declaration of a variable. */
1462 print_declaration (pretty_printer *buffer, tree t, int spc, int flags)
1466 if (TREE_CODE (t) == TYPE_DECL)
1467 pp_string (buffer, "typedef ");
1469 if (DECL_REGISTER (t))
1470 pp_string (buffer, "register ");
1472 if (TREE_PUBLIC (t) && DECL_EXTERNAL (t))
1473 pp_string (buffer, "extern ");
1474 else if (TREE_STATIC (t))
1475 pp_string (buffer, "static ");
1477 /* Print the type and name. */
1478 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
1482 /* Print array's type. */
1483 tmp = TREE_TYPE (t);
1484 while (TREE_CODE (TREE_TYPE (tmp)) == ARRAY_TYPE)
1485 tmp = TREE_TYPE (tmp);
1486 dump_generic_node (buffer, TREE_TYPE (tmp), spc, flags, false);
1488 /* Print variable's name. */
1490 dump_generic_node (buffer, t, spc, flags, false);
1492 /* Print the dimensions. */
1493 tmp = TREE_TYPE (t);
1494 while (TREE_CODE (tmp) == ARRAY_TYPE)
1496 pp_character (buffer, '[');
1497 if (TYPE_DOMAIN (tmp))
1499 if (TREE_CODE (TYPE_SIZE (tmp)) == INTEGER_CST)
1500 pp_wide_integer (buffer,
1501 TREE_INT_CST_LOW (TYPE_SIZE (tmp)) /
1502 TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (tmp))));
1504 dump_generic_node (buffer, TYPE_SIZE_UNIT (tmp), spc, flags,
1507 pp_character (buffer, ']');
1508 tmp = TREE_TYPE (tmp);
1511 else if (TREE_CODE (t) == FUNCTION_DECL)
1513 dump_generic_node (buffer, TREE_TYPE (TREE_TYPE (t)), spc, flags, false);
1515 dump_decl_name (buffer, t, flags);
1516 dump_function_declaration (buffer, TREE_TYPE (t), spc, flags);
1520 /* Print type declaration. */
1521 dump_generic_node (buffer, TREE_TYPE (t), spc, flags, false);
1523 /* Print variable's name. */
1525 dump_generic_node (buffer, t, spc, flags, false);
1528 /* The initial value of a function serves to determine wether the function
1529 is declared or defined. So the following does not apply to function
1531 if (TREE_CODE (t) != FUNCTION_DECL)
1533 /* Print the initial value. */
1534 if (DECL_INITIAL (t))
1537 pp_character (buffer, '=');
1539 dump_generic_node (buffer, DECL_INITIAL (t), spc, flags, false);
1543 pp_character (buffer, ';');
1547 /* Prints a structure: name, fields, and methods.
1548 FIXME: Still incomplete. */
1551 print_struct_decl (pretty_printer *buffer, tree node, int spc, int flags)
1553 /* Print the name of the structure. */
1554 if (TYPE_NAME (node))
1557 if (TREE_CODE (node) == RECORD_TYPE)
1558 pp_string (buffer, "struct ");
1559 else if ((TREE_CODE (node) == UNION_TYPE
1560 || TREE_CODE (node) == QUAL_UNION_TYPE))
1561 pp_string (buffer, "union ");
1563 dump_generic_node (buffer, TYPE_NAME (node), spc, 0, false);
1566 /* Print the contents of the structure. */
1567 pp_newline (buffer);
1569 pp_character (buffer, '{');
1570 pp_newline (buffer);
1572 /* Print the fields of the structure. */
1575 tmp = TYPE_FIELDS (node);
1578 /* Avoid to print recursively the structure. */
1579 /* FIXME : Not implemented correctly...,
1580 what about the case when we have a cycle in the contain graph? ...
1581 Maybe this could be solved by looking at the scope in which the
1582 structure was declared. */
1583 if (TREE_TYPE (tmp) != node
1584 || (TREE_CODE (TREE_TYPE (tmp)) == POINTER_TYPE
1585 && TREE_TYPE (TREE_TYPE (tmp)) != node))
1587 print_declaration (buffer, tmp, spc+2, flags);
1588 pp_newline (buffer);
1590 tmp = TREE_CHAIN (tmp);
1594 pp_character (buffer, '}');
1597 /* Return the priority of the operator OP.
1599 From lowest to highest precedence with either left-to-right (L-R)
1600 or right-to-left (R-L) associativity]:
1603 2 [R-L] = += -= *= /= %= &= ^= |= <<= >>=
1615 14 [R-L] ! ~ ++ -- + - * & (type) sizeof
1616 15 [L-R] fn() [] -> .
1618 unary +, - and * have higher precedence than the corresponding binary
1627 switch (TREE_CODE (op))
1642 case TRUTH_ORIF_EXPR:
1645 case TRUTH_AND_EXPR:
1646 case TRUTH_ANDIF_EXPR:
1653 case TRUTH_XOR_EXPR:
1670 case UNORDERED_EXPR:
1688 case TRUNC_DIV_EXPR:
1690 case FLOOR_DIV_EXPR:
1691 case ROUND_DIV_EXPR:
1693 case EXACT_DIV_EXPR:
1694 case TRUNC_MOD_EXPR:
1696 case FLOOR_MOD_EXPR:
1697 case ROUND_MOD_EXPR:
1700 case TRUTH_NOT_EXPR:
1702 case POSTINCREMENT_EXPR:
1703 case POSTDECREMENT_EXPR:
1704 case PREINCREMENT_EXPR:
1705 case PREDECREMENT_EXPR:
1712 case FIX_TRUNC_EXPR:
1714 case FIX_FLOOR_EXPR:
1715 case FIX_ROUND_EXPR:
1721 case ARRAY_RANGE_REF:
1725 /* Special expressions. */
1734 case NON_LVALUE_EXPR:
1735 return op_prio (TREE_OPERAND (op, 0));
1738 /* Return an arbitrarily high precedence to avoid surrounding single
1739 VAR_DECLs in ()s. */
1745 /* Return the symbol associated with operator OP. */
1753 switch (TREE_CODE (op))
1759 case TRUTH_ORIF_EXPR:
1762 case TRUTH_AND_EXPR:
1763 case TRUTH_ANDIF_EXPR:
1769 case TRUTH_XOR_EXPR:
1779 case UNORDERED_EXPR:
1829 case TRUTH_NOT_EXPR:
1836 case TRUNC_DIV_EXPR:
1838 case FLOOR_DIV_EXPR:
1839 case ROUND_DIV_EXPR:
1841 case EXACT_DIV_EXPR:
1844 case TRUNC_MOD_EXPR:
1846 case FLOOR_MOD_EXPR:
1847 case ROUND_MOD_EXPR:
1850 case PREDECREMENT_EXPR:
1853 case PREINCREMENT_EXPR:
1856 case POSTDECREMENT_EXPR:
1859 case POSTINCREMENT_EXPR:
1863 return "<<< ??? >>>";
1867 /* Prints the name of a CALL_EXPR. */
1870 print_call_name (pretty_printer *buffer, tree node)
1874 if (TREE_CODE (node) != CALL_EXPR)
1877 op0 = TREE_OPERAND (node, 0);
1879 if (TREE_CODE (op0) == NON_LVALUE_EXPR)
1880 op0 = TREE_OPERAND (op0, 0);
1882 switch (TREE_CODE (op0))
1886 PRINT_FUNCTION_NAME (op0);
1892 dump_generic_node (buffer, TREE_OPERAND (op0, 0), 0, 0, false);
1896 pp_string (buffer, "(");
1897 dump_generic_node (buffer, TREE_OPERAND (op0, 0), 0, 0, false);
1898 pp_string (buffer, ") ? ");
1899 dump_generic_node (buffer, TREE_OPERAND (op0, 1), 0, 0, false);
1900 pp_string (buffer, " : ");
1901 dump_generic_node (buffer, TREE_OPERAND (op0, 2), 0, 0, false);
1905 /* The function is a pointer contained in a structure. */
1906 if (TREE_CODE (TREE_OPERAND (op0, 0)) == INDIRECT_REF ||
1907 TREE_CODE (TREE_OPERAND (op0, 0)) == VAR_DECL)
1908 PRINT_FUNCTION_NAME (TREE_OPERAND (op0, 1));
1910 dump_generic_node (buffer, TREE_OPERAND (op0, 0), 0, 0, false);
1912 We can have several levels of structures and a function
1913 pointer inside. This is not implemented yet... */
1918 if (TREE_CODE (TREE_OPERAND (op0, 0)) == VAR_DECL)
1919 PRINT_FUNCTION_NAME (TREE_OPERAND (op0, 0));
1921 dump_generic_node (buffer, op0, 0, 0, false);
1926 dump_generic_node (buffer, op0, 0, 0, false);
1934 /* Parses the string STR and replaces new-lines by '\n', tabs by '\t', ... */
1937 pretty_print_string (pretty_printer *buffer, const char *str)
1947 pp_string (buffer, "\\b");
1951 pp_string (buffer, "\\f");
1955 pp_string (buffer, "\\n");
1959 pp_string (buffer, "\\r");
1963 pp_string (buffer, "\\t");
1967 pp_string (buffer, "\\v");
1971 pp_string (buffer, "\\\\");
1975 pp_string (buffer, "\\\"");
1979 pp_string (buffer, "\\'");
1983 pp_string (buffer, "\\0");
1987 pp_string (buffer, "\\1");
1991 pp_string (buffer, "\\2");
1995 pp_string (buffer, "\\3");
1999 pp_string (buffer, "\\4");
2003 pp_string (buffer, "\\5");
2007 pp_string (buffer, "\\6");
2011 pp_string (buffer, "\\7");
2015 pp_character (buffer, str[0]);
2023 maybe_init_pretty_print (FILE *file)
2027 pp_construct (&buffer, /* prefix */NULL, /* line-width */0);
2028 pp_needs_newline (&buffer) = true;
2032 buffer.buffer->stream = file;
2036 newline_and_indent (pretty_printer *buffer, int spc)
2038 pp_newline (buffer);
2043 dump_vops (pretty_printer *buffer, tree stmt, int spc, int flags)
2046 stmt_ann_t ann = stmt_ann (stmt);
2047 v_may_def_optype v_may_defs = V_MAY_DEF_OPS (ann);
2048 v_must_def_optype v_must_defs = V_MUST_DEF_OPS (ann);
2049 vuse_optype vuses = VUSE_OPS (ann);
2051 for (i = 0; i < NUM_V_MAY_DEFS (v_may_defs); i++)
2053 pp_string (buffer, "# ");
2054 dump_generic_node (buffer, V_MAY_DEF_RESULT (v_may_defs, i),
2055 spc + 2, flags, false);
2056 pp_string (buffer, " = V_MAY_DEF <");
2057 dump_generic_node (buffer, V_MAY_DEF_OP (v_may_defs, i),
2058 spc + 2, flags, false);
2059 pp_string (buffer, ">;");
2060 newline_and_indent (buffer, spc);
2063 for (i = 0; i < NUM_V_MUST_DEFS (v_must_defs); i++)
2065 tree v_must_def = V_MUST_DEF_OP (v_must_defs, i);
2066 pp_string (buffer, "# V_MUST_DEF <");
2067 dump_generic_node (buffer, v_must_def, spc + 2, flags, false);
2068 pp_string (buffer, ">;");
2069 newline_and_indent (buffer, spc);
2072 for (i = 0; i < NUM_VUSES (vuses); i++)
2074 tree vuse = VUSE_OP (vuses, i);
2075 pp_string (buffer, "# VUSE <");
2076 dump_generic_node (buffer, vuse, spc + 2, flags, false);
2077 pp_string (buffer, ">;");
2078 newline_and_indent (buffer, spc);
2082 /* Dumps basic block BB to FILE with details described by FLAGS and
2083 indented by INDENT spaces. */
2086 dump_generic_bb (FILE *file, basic_block bb, int indent, int flags)
2088 maybe_init_pretty_print (file);
2089 dumping_stmts = true;
2090 dump_generic_bb_buff (&buffer, bb, indent, flags);
2094 /* Dumps header of basic block BB to buffer BUFFER indented by INDENT
2095 spaces and details described by flags. */
2098 dump_bb_header (pretty_printer *buffer, basic_block bb, int indent, int flags)
2103 if (flags & TDF_BLOCKS)
2106 pp_string (buffer, "# BLOCK ");
2107 pp_decimal_int (buffer, bb->index);
2109 if (flags & TDF_LINENO)
2111 block_stmt_iterator bsi;
2113 for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
2114 if (get_lineno (bsi_stmt (bsi)) != -1)
2116 pp_string (buffer, ", starting at line ");
2117 pp_decimal_int (buffer, get_lineno (bsi_stmt (bsi)));
2121 newline_and_indent (buffer, indent);
2123 pp_string (buffer, "# PRED:");
2124 pp_write_text_to_stream (buffer);
2125 for (e = bb->pred; e; e = e->pred_next)
2126 if (flags & TDF_SLIM)
2128 pp_string (buffer, " ");
2129 if (e->src == ENTRY_BLOCK_PTR)
2130 pp_string (buffer, "ENTRY");
2132 pp_decimal_int (buffer, e->src->index);
2135 dump_edge_info (buffer->buffer->stream, e, 0);
2136 pp_newline (buffer);
2140 stmt = first_stmt (bb);
2141 if (!stmt || TREE_CODE (stmt) != LABEL_EXPR)
2143 INDENT (indent - 2);
2144 pp_string (buffer, "<bb ");
2145 pp_decimal_int (buffer, bb->index);
2146 pp_string (buffer, ">:");
2147 pp_newline (buffer);
2152 /* Dumps end of basic block BB to buffer BUFFER indented by INDENT
2156 dump_bb_end (pretty_printer *buffer, basic_block bb, int indent, int flags)
2161 pp_string (buffer, "# SUCC:");
2162 pp_write_text_to_stream (buffer);
2163 for (e = bb->succ; e; e = e->succ_next)
2164 if (flags & TDF_SLIM)
2166 pp_string (buffer, " ");
2167 if (e->dest == EXIT_BLOCK_PTR)
2168 pp_string (buffer, "EXIT");
2170 pp_decimal_int (buffer, e->dest->index);
2173 dump_edge_info (buffer->buffer->stream, e, 1);
2174 pp_newline (buffer);
2177 /* Dumps phi nodes of basic block BB to buffer BUFFER with details described by
2178 FLAGS indented by INDENT spaces. */
2181 dump_phi_nodes (pretty_printer *buffer, basic_block bb, int indent, int flags)
2183 tree phi = phi_nodes (bb);
2187 for (; phi; phi = PHI_CHAIN (phi))
2189 if (is_gimple_reg (PHI_RESULT (phi)) || (flags & TDF_VOPS))
2192 pp_string (buffer, "# ");
2193 dump_generic_node (buffer, phi, indent, flags, false);
2194 pp_newline (buffer);
2199 /* Dump jump to basic block BB that is represented implicitly in the cfg
2203 pp_cfg_jump (pretty_printer *buffer, basic_block bb)
2207 stmt = first_stmt (bb);
2209 pp_string (buffer, "goto <bb ");
2210 pp_decimal_int (buffer, bb->index);
2211 pp_string (buffer, ">");
2212 if (stmt && TREE_CODE (stmt) == LABEL_EXPR)
2214 pp_string (buffer, " (");
2215 dump_generic_node (buffer, LABEL_EXPR_LABEL (stmt), 0, 0, false);
2216 pp_string (buffer, ")");
2218 pp_semicolon (buffer);
2221 /* Dump edges represented implicitly in basic block BB to BUFFER, indented
2222 by INDENT spaces, with details given by FLAGS. */
2225 dump_implicit_edges (pretty_printer *buffer, basic_block bb, int indent,
2230 /* If there is a fallthru edge, we may need to add an artificial goto to the
2232 for (e = bb->succ; e; e = e->succ_next)
2233 if (e->flags & EDGE_FALLTHRU)
2235 if (e && e->dest != bb->next_bb)
2239 if ((flags & TDF_LINENO)
2240 #ifdef USE_MAPPED_LOCATION
2241 && e->goto_locus != UNKNOWN_LOCATION
2247 expanded_location goto_xloc;
2248 #ifdef USE_MAPPED_LOCATION
2249 goto_xloc = expand_location (e->goto_locus);
2251 goto_xloc = *e->goto_locus;
2253 pp_character (buffer, '[');
2256 pp_string (buffer, goto_xloc.file);
2257 pp_string (buffer, " : ");
2259 pp_decimal_int (buffer, goto_xloc.line);
2260 pp_string (buffer, "] ");
2263 pp_cfg_jump (buffer, e->dest);
2264 pp_newline (buffer);
2268 /* Dumps basic block BB to buffer BUFFER with details described by FLAGS and
2269 indented by INDENT spaces. */
2272 dump_generic_bb_buff (pretty_printer *buffer, basic_block bb,
2273 int indent, int flags)
2275 block_stmt_iterator bsi;
2277 int label_indent = indent - 2;
2279 if (label_indent < 0)
2282 dump_bb_header (buffer, bb, indent, flags);
2285 dump_phi_nodes (buffer, bb, indent, flags);
2287 for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
2291 stmt = bsi_stmt (bsi);
2293 curr_indent = TREE_CODE (stmt) == LABEL_EXPR ? label_indent : indent;
2295 INDENT (curr_indent);
2296 dump_generic_node (buffer, stmt, curr_indent, flags, true);
2297 pp_newline (buffer);
2300 dump_implicit_edges (buffer, bb, indent, flags);
2302 if (flags & TDF_BLOCKS)
2303 dump_bb_end (buffer, bb, indent, flags);