1 /* Pretty formatting of GENERIC trees in C syntax.
2 Copyright (C) 2001, 2002, 2003, 2004 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)]);
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));
169 char c = TREE_CODE (node) == CONST_DECL ? 'C' : 'D';
170 pp_printf (buffer, "%c.%u", c, DECL_UID (node));
175 /* Like the above, but used for pretty printing function calls. */
178 dump_function_name (pretty_printer *buffer, tree node)
180 if (DECL_NAME (node))
181 PRINT_FUNCTION_NAME (node);
183 dump_decl_name (buffer, node, 0);
186 /* Dump a function declaration. NODE is the FUNCTION_TYPE. BUFFER, SPC and
187 FLAGS are as in dump_generic_node. */
190 dump_function_declaration (pretty_printer *buffer, tree node,
193 bool wrote_arg = false;
197 pp_character (buffer, '(');
199 /* Print the argument types. The last element in the list is a VOID_TYPE.
200 The following avoids printing the last element. */
201 arg = TYPE_ARG_TYPES (node);
202 while (arg && TREE_CHAIN (arg) && arg != error_mark_node)
205 dump_generic_node (buffer, TREE_VALUE (arg), spc, flags, false);
206 arg = TREE_CHAIN (arg);
207 if (TREE_CHAIN (arg) && TREE_CODE (TREE_CHAIN (arg)) == TREE_LIST)
209 pp_character (buffer, ',');
215 pp_string (buffer, "void");
217 pp_character (buffer, ')');
220 /* Dump the node NODE on the pretty_printer BUFFER, SPC spaces of indent.
221 FLAGS specifies details to show in the dump (see TDF_* in tree.h). If
222 IS_STMT is true, the object printed is considered to be a statement
223 and it is terminated by ';' if appropriate. */
226 dump_generic_node (pretty_printer *buffer, tree node, int spc, int flags,
234 if (node == NULL_TREE)
237 is_expr = EXPR_P (node);
239 if (TREE_CODE (node) != ERROR_MARK
240 && is_gimple_stmt (node)
241 && (flags & TDF_VOPS)
243 dump_vops (buffer, node, spc, flags);
246 && (flags & TDF_LINENO)
247 && EXPR_HAS_LOCATION (node))
249 expanded_location xloc = expand_location (EXPR_LOCATION (node));
250 pp_character (buffer, '[');
253 pp_string (buffer, xloc.file);
254 pp_string (buffer, " : ");
256 pp_decimal_int (buffer, xloc.line);
257 pp_string (buffer, "] ");
260 switch (TREE_CODE (node))
263 pp_string (buffer, "<<< error >>>");
266 case IDENTIFIER_NODE:
267 pp_tree_identifier (buffer, node);
271 while (node && node != error_mark_node)
273 if (TREE_PURPOSE (node))
275 dump_generic_node (buffer, TREE_PURPOSE (node), spc, flags, false);
278 dump_generic_node (buffer, TREE_VALUE (node), spc, flags, false);
279 node = TREE_CHAIN (node);
280 if (node && TREE_CODE (node) == TREE_LIST)
282 pp_character (buffer, ',');
289 dump_generic_node (buffer, BINFO_TYPE (node), spc, flags, false);
294 if (TREE_VEC_LENGTH (node) > 0)
296 size_t len = TREE_VEC_LENGTH (node);
297 for (i = 0; i < len - 1; i++)
299 dump_generic_node (buffer, TREE_VEC_ELT (node, i), spc, flags,
301 pp_character (buffer, ',');
304 dump_generic_node (buffer, TREE_VEC_ELT (node, len - 1), spc,
323 unsigned int quals = TYPE_QUALS (node);
324 enum tree_code_class class;
326 if (quals & TYPE_QUAL_CONST)
327 pp_string (buffer, "const ");
328 else if (quals & TYPE_QUAL_VOLATILE)
329 pp_string (buffer, "volatile ");
330 else if (quals & TYPE_QUAL_RESTRICT)
331 pp_string (buffer, "restrict ");
333 class = TREE_CODE_CLASS (TREE_CODE (node));
335 if (class == tcc_declaration)
337 if (DECL_NAME (node))
338 dump_decl_name (buffer, node, flags);
340 pp_string (buffer, "<unnamed type decl>");
342 else if (class == tcc_type)
344 if (TYPE_NAME (node))
346 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
347 pp_tree_identifier (buffer, TYPE_NAME (node));
348 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
349 && DECL_NAME (TYPE_NAME (node)))
350 dump_decl_name (buffer, TYPE_NAME (node), flags);
352 pp_string (buffer, "<unnamed type>");
354 else if (TREE_CODE (node) == VECTOR_TYPE)
356 pp_string (buffer, "vector ");
357 dump_generic_node (buffer, TREE_TYPE (node),
361 pp_string (buffer, "<unnamed type>");
368 str = (TREE_CODE (node) == POINTER_TYPE ? "*" : "&");
370 if (TREE_CODE (TREE_TYPE (node)) == FUNCTION_TYPE)
372 tree fnode = TREE_TYPE (node);
374 dump_generic_node (buffer, TREE_TYPE (fnode), spc, flags, false);
376 pp_character (buffer, '(');
377 pp_string (buffer, str);
378 if (TYPE_NAME (node) && DECL_NAME (TYPE_NAME (node)))
379 dump_decl_name (buffer, TYPE_NAME (node), flags);
381 pp_printf (buffer, "<T%x>", TYPE_UID (node));
383 pp_character (buffer, ')');
384 dump_function_declaration (buffer, fnode, spc, flags);
388 unsigned int quals = TYPE_QUALS (node);
390 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
392 pp_string (buffer, str);
394 if (quals & TYPE_QUAL_CONST)
395 pp_string (buffer, " const");
396 else if (quals & TYPE_QUAL_VOLATILE)
397 pp_string (buffer, "volatile");
398 else if (quals & TYPE_QUAL_RESTRICT)
399 pp_string (buffer, " restrict");
408 dump_decl_name (buffer, TYPE_NAME (TYPE_METHOD_BASETYPE (node)), flags);
409 pp_string (buffer, "::");
420 /* Print the innermost component type. */
421 for (tmp = TREE_TYPE (node); TREE_CODE (tmp) == ARRAY_TYPE;
422 tmp = TREE_TYPE (tmp))
424 dump_generic_node (buffer, tmp, spc, flags, false);
426 /* Print the dimensions. */
427 for (tmp = node; TREE_CODE (tmp) == ARRAY_TYPE;
428 tmp = TREE_TYPE (tmp))
430 tree domain = TYPE_DOMAIN (tmp);
432 pp_character (buffer, '[');
435 if (TYPE_MIN_VALUE (domain)
436 && !integer_zerop (TYPE_MIN_VALUE (domain)))
438 dump_generic_node (buffer, TYPE_MIN_VALUE (domain),
440 pp_string (buffer, " .. ");
443 if (TYPE_MAX_VALUE (domain))
444 dump_generic_node (buffer, TYPE_MAX_VALUE (domain),
448 pp_string (buffer, "<unknown>");
450 pp_character (buffer, ']');
461 case QUAL_UNION_TYPE:
462 /* Print the name of the structure. */
463 if (TREE_CODE (node) == RECORD_TYPE)
464 pp_string (buffer, "struct ");
465 else if (TREE_CODE (node) == UNION_TYPE)
466 pp_string (buffer, "union ");
468 if (TYPE_NAME (node))
469 dump_generic_node (buffer, TYPE_NAME (node), spc, flags, false);
471 print_struct_decl (buffer, node, spc, flags);
479 if (TREE_CODE (TREE_TYPE (node)) == POINTER_TYPE)
481 /* In the case of a pointer, one may want to divide by the
482 size of the pointed-to type. Unfortunately, this not
483 straightforward. The C front-end maps expressions
488 in such a way that the two INTEGER_CST nodes for "5" have
489 different values but identical types. In the latter
490 case, the 5 is multiplied by sizeof (int) in c-common.c
491 (pointer_int_sum) to convert it to a byte address, and
492 yet the type of the node is left unchanged. Argh. What
493 is consistent though is that the number value corresponds
494 to bytes (UNITS) offset.
496 NB: Neither of the following divisors can be trivially
497 used to recover the original literal:
499 TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (node)))
500 TYPE_PRECISION (TREE_TYPE (TREE_TYPE (node))) */
501 pp_wide_integer (buffer, TREE_INT_CST_LOW (node));
502 pp_string (buffer, "B"); /* pseudo-unit */
504 else if (! host_integerp (node, 0))
508 if (tree_int_cst_sgn (val) < 0)
510 pp_character (buffer, '-');
511 val = build_int_cst_wide (NULL_TREE,
512 -TREE_INT_CST_LOW (val),
513 ~TREE_INT_CST_HIGH (val)
514 + !TREE_INT_CST_LOW (val));
516 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
519 static char format[10]; /* "%x%09999x\0" */
521 sprintf (format, "%%x%%0%dx", HOST_BITS_PER_INT / 4);
522 sprintf (pp_buffer (buffer)->digit_buffer, format,
523 TREE_INT_CST_HIGH (val),
524 TREE_INT_CST_LOW (val));
525 pp_string (buffer, pp_buffer (buffer)->digit_buffer);
529 pp_wide_integer (buffer, TREE_INT_CST_LOW (node));
533 /* Code copied from print_node. */
536 if (TREE_OVERFLOW (node))
537 pp_string (buffer, " overflow");
539 #if !defined(REAL_IS_NOT_DOUBLE) || defined(REAL_ARITHMETIC)
540 d = TREE_REAL_CST (node);
541 if (REAL_VALUE_ISINF (d))
542 pp_string (buffer, " Inf");
543 else if (REAL_VALUE_ISNAN (d))
544 pp_string (buffer, " Nan");
548 real_to_decimal (string, &d, sizeof (string), 0, 1);
549 pp_string (buffer, string);
554 unsigned char *p = (unsigned char *) &TREE_REAL_CST (node);
555 pp_string (buffer, "0x");
556 for (i = 0; i < sizeof TREE_REAL_CST (node); i++)
557 output_formatted_integer (buffer, "%02x", *p++);
564 pp_string (buffer, "__complex__ (");
565 dump_generic_node (buffer, TREE_REALPART (node), spc, flags, false);
566 pp_string (buffer, ", ");
567 dump_generic_node (buffer, TREE_IMAGPART (node), spc, flags, false);
568 pp_string (buffer, ")");
572 pp_string (buffer, "\"");
573 pretty_print_string (buffer, TREE_STRING_POINTER (node));
574 pp_string (buffer, "\"");
580 pp_string (buffer, "{ ");
581 for (elt = TREE_VECTOR_CST_ELTS (node); elt; elt = TREE_CHAIN (elt))
583 dump_generic_node (buffer, TREE_VALUE (elt), spc, flags, false);
584 if (TREE_CHAIN (elt))
585 pp_string (buffer, ", ");
587 pp_string (buffer, " }");
596 dump_decl_name (buffer, node, flags);
600 if (DECL_NAME (node))
601 dump_decl_name (buffer, node, flags);
602 else if (LABEL_DECL_UID (node) != -1)
603 pp_printf (buffer, "<L" HOST_WIDE_INT_PRINT_DEC ">",
604 LABEL_DECL_UID (node));
606 pp_printf (buffer, "<D%u>", DECL_UID (node));
610 if (DECL_IS_BUILTIN (node))
612 /* Don't print the declaration of built-in types. */
615 if (DECL_NAME (node))
616 dump_decl_name (buffer, node, flags);
619 if ((TREE_CODE (TREE_TYPE (node)) == RECORD_TYPE
620 || TREE_CODE (TREE_TYPE (node)) == UNION_TYPE)
621 && TYPE_METHODS (TREE_TYPE (node)))
623 /* The type is a c++ class: all structures have at least
625 pp_string (buffer, "class ");
626 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
631 (TREE_CODE (TREE_TYPE (node)) == UNION_TYPE
632 ? "union" : "struct "));
633 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
642 dump_decl_name (buffer, node, flags);
646 pp_string (buffer, "<retval>");
650 op0 = TREE_OPERAND (node, 0);
652 if (TREE_CODE (op0) == INDIRECT_REF)
654 op0 = TREE_OPERAND (op0, 0);
657 if (op_prio (op0) < op_prio (node))
658 pp_character (buffer, '(');
659 dump_generic_node (buffer, op0, spc, flags, false);
660 if (op_prio (op0) < op_prio (node))
661 pp_character (buffer, ')');
662 pp_string (buffer, str);
663 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
665 if (TREE_CODE (op0) != VALUE_HANDLE)
667 op0 = component_ref_field_offset (node);
668 if (op0 && TREE_CODE (op0) != INTEGER_CST)
670 pp_string (buffer, "{off: ");
671 dump_generic_node (buffer, op0, spc, flags, false);
672 pp_character (buffer, '}');
678 pp_string (buffer, "BIT_FIELD_REF <");
679 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
680 pp_string (buffer, ", ");
681 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
682 pp_string (buffer, ", ");
683 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
684 pp_string (buffer, ">");
688 case ARRAY_RANGE_REF:
689 op0 = TREE_OPERAND (node, 0);
690 if (op_prio (op0) < op_prio (node))
691 pp_character (buffer, '(');
692 dump_generic_node (buffer, op0, spc, flags, false);
693 if (op_prio (op0) < op_prio (node))
694 pp_character (buffer, ')');
695 pp_character (buffer, '[');
696 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
697 if (TREE_CODE (node) == ARRAY_RANGE_REF)
698 pp_string (buffer, " ...");
699 pp_character (buffer, ']');
701 op0 = array_ref_low_bound (node);
702 op1 = array_ref_element_size (node);
704 if (!integer_zerop (op0)
705 || (TYPE_SIZE_UNIT (TREE_TYPE (node))
706 && !operand_equal_p (op1, TYPE_SIZE_UNIT (TREE_TYPE (node)), 0)))
708 pp_string (buffer, "{lb: ");
709 dump_generic_node (buffer, op0, spc, flags, false);
710 pp_string (buffer, " sz: ");
711 dump_generic_node (buffer, op1, spc, flags, false);
712 pp_character (buffer, '}');
719 bool is_struct_init = FALSE;
720 pp_character (buffer, '{');
721 lnode = CONSTRUCTOR_ELTS (node);
722 if (TREE_CODE (TREE_TYPE (node)) == RECORD_TYPE
723 || TREE_CODE (TREE_TYPE (node)) == UNION_TYPE)
724 is_struct_init = TRUE;
725 while (lnode && lnode != error_mark_node)
728 if (TREE_PURPOSE (lnode) && is_struct_init)
730 pp_character (buffer, '.');
731 dump_generic_node (buffer, TREE_PURPOSE (lnode), spc, flags, false);
732 pp_string (buffer, "=");
734 val = TREE_VALUE (lnode);
735 if (val && TREE_CODE (val) == ADDR_EXPR)
736 if (TREE_CODE (TREE_OPERAND (val, 0)) == FUNCTION_DECL)
737 val = TREE_OPERAND (val, 0);
738 if (val && TREE_CODE (val) == FUNCTION_DECL)
740 dump_decl_name (buffer, val, flags);
744 dump_generic_node (buffer, TREE_VALUE (lnode), spc, flags, false);
746 lnode = TREE_CHAIN (lnode);
747 if (lnode && TREE_CODE (lnode) == TREE_LIST)
749 pp_character (buffer, ',');
753 pp_character (buffer, '}');
760 if (flags & TDF_SLIM)
762 pp_string (buffer, "<COMPOUND_EXPR>");
766 dump_generic_node (buffer, TREE_OPERAND (node, 0),
767 spc, flags, dumping_stmts);
769 newline_and_indent (buffer, spc);
772 pp_character (buffer, ',');
776 for (tp = &TREE_OPERAND (node, 1);
777 TREE_CODE (*tp) == COMPOUND_EXPR;
778 tp = &TREE_OPERAND (*tp, 1))
780 dump_generic_node (buffer, TREE_OPERAND (*tp, 0),
781 spc, flags, dumping_stmts);
783 newline_and_indent (buffer, spc);
786 pp_character (buffer, ',');
791 dump_generic_node (buffer, *tp, spc, flags, dumping_stmts);
797 tree_stmt_iterator si;
800 if ((flags & TDF_SLIM) || !dumping_stmts)
802 pp_string (buffer, "<STATEMENT_LIST>");
806 for (si = tsi_start (node); !tsi_end_p (si); tsi_next (&si))
809 newline_and_indent (buffer, spc);
812 dump_generic_node (buffer, tsi_stmt (si), spc, flags, true);
819 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
821 pp_character (buffer, '=');
823 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
827 pp_string (buffer, "TARGET_EXPR <");
828 dump_generic_node (buffer, TARGET_EXPR_SLOT (node), spc, flags, false);
829 pp_character (buffer, ',');
831 dump_generic_node (buffer, TARGET_EXPR_INITIAL (node), spc, flags, false);
832 pp_character (buffer, '>');
836 print_declaration (buffer, DECL_EXPR_DECL (node), spc, flags);
841 if (TREE_TYPE (node) == NULL || TREE_TYPE (node) == void_type_node)
843 pp_string (buffer, "if (");
844 dump_generic_node (buffer, COND_EXPR_COND (node), spc, flags, false);
845 pp_character (buffer, ')');
846 /* The lowered cond_exprs should always be printed in full. */
847 if (COND_EXPR_THEN (node)
848 && TREE_CODE (COND_EXPR_THEN (node)) == GOTO_EXPR
849 && COND_EXPR_ELSE (node)
850 && TREE_CODE (COND_EXPR_ELSE (node)) == GOTO_EXPR)
853 dump_generic_node (buffer, COND_EXPR_THEN (node), 0, flags, true);
854 pp_string (buffer, " else ");
855 dump_generic_node (buffer, COND_EXPR_ELSE (node), 0, flags, true);
857 else if (!(flags & TDF_SLIM))
859 /* Output COND_EXPR_THEN. */
860 if (COND_EXPR_THEN (node))
862 newline_and_indent (buffer, spc+2);
863 pp_character (buffer, '{');
864 newline_and_indent (buffer, spc+4);
865 dump_generic_node (buffer, COND_EXPR_THEN (node), spc+4,
867 newline_and_indent (buffer, spc+2);
868 pp_character (buffer, '}');
871 /* Output COND_EXPR_ELSE. */
872 if (COND_EXPR_ELSE (node))
874 newline_and_indent (buffer, spc);
875 pp_string (buffer, "else");
876 newline_and_indent (buffer, spc+2);
877 pp_character (buffer, '{');
878 newline_and_indent (buffer, spc+4);
879 dump_generic_node (buffer, COND_EXPR_ELSE (node), spc+4,
881 newline_and_indent (buffer, spc+2);
882 pp_character (buffer, '}');
889 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
891 pp_character (buffer, '?');
893 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
895 pp_character (buffer, ':');
897 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
902 pp_character (buffer, '{');
903 if (!(flags & TDF_SLIM))
905 if (BIND_EXPR_VARS (node))
909 for (op0 = BIND_EXPR_VARS (node); op0; op0 = TREE_CHAIN (op0))
911 print_declaration (buffer, op0, spc+2, flags);
916 newline_and_indent (buffer, spc+2);
917 dump_generic_node (buffer, BIND_EXPR_BODY (node), spc+2, flags, true);
918 newline_and_indent (buffer, spc);
919 pp_character (buffer, '}');
925 print_call_name (buffer, node);
927 /* Print parameters. */
929 pp_character (buffer, '(');
930 op1 = TREE_OPERAND (node, 1);
932 dump_generic_node (buffer, op1, spc, flags, false);
933 pp_character (buffer, ')');
935 op1 = TREE_OPERAND (node, 2);
938 pp_string (buffer, " [static-chain: ");
939 dump_generic_node (buffer, op1, spc, flags, false);
940 pp_character (buffer, ']');
943 if (CALL_EXPR_HAS_RETURN_SLOT_ADDR (node))
944 pp_string (buffer, " [return slot addr]");
945 if (CALL_EXPR_TAILCALL (node))
946 pp_string (buffer, " [tail call]");
949 case WITH_CLEANUP_EXPR:
953 case CLEANUP_POINT_EXPR:
954 pp_string (buffer, "<<cleanup_point ");
955 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
956 pp_string (buffer, ">>");
959 case PLACEHOLDER_EXPR:
960 pp_string (buffer, "<PLACEHOLDER_EXPR ");
961 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
962 pp_character (buffer, '>');
965 /* Binary arithmetic and logic expressions. */
986 case TRUTH_ANDIF_EXPR:
987 case TRUTH_ORIF_EXPR:
1004 case UNORDERED_EXPR:
1006 const char *op = op_symbol (node);
1007 op0 = TREE_OPERAND (node, 0);
1008 op1 = TREE_OPERAND (node, 1);
1010 /* When the operands are expressions with less priority,
1011 keep semantics of the tree representation. */
1012 if (op_prio (op0) < op_prio (node))
1014 pp_character (buffer, '(');
1015 dump_generic_node (buffer, op0, spc, flags, false);
1016 pp_character (buffer, ')');
1019 dump_generic_node (buffer, op0, spc, flags, false);
1022 pp_string (buffer, op);
1025 /* When the operands are expressions with less priority,
1026 keep semantics of the tree representation. */
1027 if (op_prio (op1) < op_prio (node))
1029 pp_character (buffer, '(');
1030 dump_generic_node (buffer, op1, spc, flags, false);
1031 pp_character (buffer, ')');
1034 dump_generic_node (buffer, op1, spc, flags, false);
1038 /* Unary arithmetic and logic expressions. */
1041 case TRUTH_NOT_EXPR:
1043 case PREDECREMENT_EXPR:
1044 case PREINCREMENT_EXPR:
1045 case ALIGN_INDIRECT_REF:
1046 case MISALIGNED_INDIRECT_REF:
1048 if (TREE_CODE (node) == ADDR_EXPR
1049 && (TREE_CODE (TREE_OPERAND (node, 0)) == STRING_CST
1050 || TREE_CODE (TREE_OPERAND (node, 0)) == FUNCTION_DECL))
1051 ; /* Do not output '&' for strings and function pointers. */
1053 pp_string (buffer, op_symbol (node));
1055 if (op_prio (TREE_OPERAND (node, 0)) < op_prio (node))
1057 pp_character (buffer, '(');
1058 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1059 pp_character (buffer, ')');
1062 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1064 if (TREE_CODE (node) == MISALIGNED_INDIRECT_REF)
1066 pp_string (buffer, "{misalignment: ");
1067 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1068 pp_character (buffer, '}');
1072 case POSTDECREMENT_EXPR:
1073 case POSTINCREMENT_EXPR:
1074 if (op_prio (TREE_OPERAND (node, 0)) < op_prio (node))
1076 pp_character (buffer, '(');
1077 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1078 pp_character (buffer, ')');
1081 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1082 pp_string (buffer, op_symbol (node));
1086 pp_string (buffer, "MIN_EXPR <");
1087 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1088 pp_string (buffer, ", ");
1089 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1090 pp_character (buffer, '>');
1094 pp_string (buffer, "MAX_EXPR <");
1095 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1096 pp_string (buffer, ", ");
1097 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1098 pp_character (buffer, '>');
1102 pp_string (buffer, "ABS_EXPR <");
1103 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1104 pp_character (buffer, '>');
1111 case FIX_TRUNC_EXPR:
1113 case FIX_FLOOR_EXPR:
1114 case FIX_ROUND_EXPR:
1118 type = TREE_TYPE (node);
1119 op0 = TREE_OPERAND (node, 0);
1120 if (type != TREE_TYPE (op0))
1122 pp_character (buffer, '(');
1123 dump_generic_node (buffer, type, spc, flags, false);
1124 pp_string (buffer, ") ");
1126 if (op_prio (op0) < op_prio (node))
1127 pp_character (buffer, '(');
1128 dump_generic_node (buffer, op0, spc, flags, false);
1129 if (op_prio (op0) < op_prio (node))
1130 pp_character (buffer, ')');
1133 case VIEW_CONVERT_EXPR:
1134 pp_string (buffer, "VIEW_CONVERT_EXPR<");
1135 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
1136 pp_string (buffer, ">(");
1137 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1138 pp_character (buffer, ')');
1141 case NON_LVALUE_EXPR:
1142 pp_string (buffer, "NON_LVALUE_EXPR <");
1143 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1144 pp_character (buffer, '>');
1148 pp_string (buffer, "SAVE_EXPR <");
1149 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1150 pp_character (buffer, '>');
1154 pp_string (buffer, "COMPLEX_EXPR <");
1155 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1156 pp_string (buffer, ", ");
1157 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1158 pp_string (buffer, ">");
1162 pp_string (buffer, "CONJ_EXPR <");
1163 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1164 pp_string (buffer, ">");
1168 pp_string (buffer, "REALPART_EXPR <");
1169 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1170 pp_string (buffer, ">");
1174 pp_string (buffer, "IMAGPART_EXPR <");
1175 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1176 pp_string (buffer, ">");
1180 pp_string (buffer, "VA_ARG_EXPR <");
1181 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1182 pp_string (buffer, ">");
1185 case TRY_FINALLY_EXPR:
1186 case TRY_CATCH_EXPR:
1187 pp_string (buffer, "try");
1188 newline_and_indent (buffer, spc+2);
1189 pp_string (buffer, "{");
1190 newline_and_indent (buffer, spc+4);
1191 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc+4, flags, true);
1192 newline_and_indent (buffer, spc+2);
1193 pp_string (buffer, "}");
1194 newline_and_indent (buffer, spc);
1196 (TREE_CODE (node) == TRY_CATCH_EXPR) ? "catch" : "finally");
1197 newline_and_indent (buffer, spc+2);
1198 pp_string (buffer, "{");
1199 newline_and_indent (buffer, spc+4);
1200 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc+4, flags, true);
1201 newline_and_indent (buffer, spc+2);
1202 pp_string (buffer, "}");
1207 pp_string (buffer, "catch (");
1208 dump_generic_node (buffer, CATCH_TYPES (node), spc+2, flags, false);
1209 pp_string (buffer, ")");
1210 newline_and_indent (buffer, spc+2);
1211 pp_string (buffer, "{");
1212 newline_and_indent (buffer, spc+4);
1213 dump_generic_node (buffer, CATCH_BODY (node), spc+4, flags, true);
1214 newline_and_indent (buffer, spc+2);
1215 pp_string (buffer, "}");
1219 case EH_FILTER_EXPR:
1220 pp_string (buffer, "<<<eh_filter (");
1221 dump_generic_node (buffer, EH_FILTER_TYPES (node), spc+2, flags, false);
1222 pp_string (buffer, ")>>>");
1223 newline_and_indent (buffer, spc+2);
1224 pp_string (buffer, "{");
1225 newline_and_indent (buffer, spc+4);
1226 dump_generic_node (buffer, EH_FILTER_FAILURE (node), spc+4, flags, true);
1227 newline_and_indent (buffer, spc+2);
1228 pp_string (buffer, "}");
1233 op0 = TREE_OPERAND (node, 0);
1234 /* If this is for break or continue, don't bother printing it. */
1235 if (DECL_NAME (op0))
1237 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1238 if (strcmp (name, "break") == 0
1239 || strcmp (name, "continue") == 0)
1242 dump_generic_node (buffer, op0, spc, flags, false);
1243 pp_character (buffer, ':');
1244 if (DECL_NONLOCAL (op0))
1245 pp_string (buffer, " [non-local]");
1248 case LABELED_BLOCK_EXPR:
1249 op0 = LABELED_BLOCK_LABEL (node);
1250 /* If this is for break or continue, don't bother printing it. */
1251 if (DECL_NAME (op0))
1253 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1254 if (strcmp (name, "break") == 0
1255 || strcmp (name, "continue") == 0)
1257 dump_generic_node (buffer, LABELED_BLOCK_BODY (node), spc, flags, false);
1261 dump_generic_node (buffer, LABELED_BLOCK_LABEL (node), spc, flags, false);
1262 pp_string (buffer, ": {");
1263 if (!(flags & TDF_SLIM))
1264 newline_and_indent (buffer, spc+2);
1265 dump_generic_node (buffer, LABELED_BLOCK_BODY (node), spc+2, flags, true);
1267 newline_and_indent (buffer, spc);
1268 pp_character (buffer, '}');
1272 case EXIT_BLOCK_EXPR:
1273 op0 = LABELED_BLOCK_LABEL (EXIT_BLOCK_LABELED_BLOCK (node));
1274 /* If this is for a break or continue, print it accordingly. */
1275 if (DECL_NAME (op0))
1277 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1278 if (strcmp (name, "break") == 0
1279 || strcmp (name, "continue") == 0)
1281 pp_string (buffer, name);
1285 pp_string (buffer, "<<<exit block ");
1286 dump_generic_node (buffer, op0, spc, flags, false);
1287 pp_string (buffer, ">>>");
1291 pp_string (buffer, "<<<exception object>>>");
1295 pp_string (buffer, "<<<filter object>>>");
1299 pp_string (buffer, "while (1)");
1300 if (!(flags & TDF_SLIM))
1302 newline_and_indent (buffer, spc+2);
1303 pp_character (buffer, '{');
1304 newline_and_indent (buffer, spc+4);
1305 dump_generic_node (buffer, LOOP_EXPR_BODY (node), spc+4, flags, true);
1306 newline_and_indent (buffer, spc+2);
1307 pp_character (buffer, '}');
1313 pp_string (buffer, "return");
1314 op0 = TREE_OPERAND (node, 0);
1318 if (TREE_CODE (op0) == MODIFY_EXPR)
1319 dump_generic_node (buffer, TREE_OPERAND (op0, 1), spc, flags, false);
1321 dump_generic_node (buffer, op0, spc, flags, false);
1326 pp_string (buffer, "if (");
1327 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1328 pp_string (buffer, ") break");
1332 pp_string (buffer, "switch (");
1333 dump_generic_node (buffer, SWITCH_COND (node), spc, flags, false);
1334 pp_character (buffer, ')');
1335 if (!(flags & TDF_SLIM))
1337 newline_and_indent (buffer, spc+2);
1338 pp_character (buffer, '{');
1339 if (SWITCH_BODY (node))
1341 newline_and_indent (buffer, spc+4);
1342 dump_generic_node (buffer, SWITCH_BODY (node), spc+4, flags, true);
1346 tree vec = SWITCH_LABELS (node);
1347 size_t i, n = TREE_VEC_LENGTH (vec);
1348 for (i = 0; i < n; ++i)
1350 tree elt = TREE_VEC_ELT (vec, i);
1351 newline_and_indent (buffer, spc+4);
1352 dump_generic_node (buffer, elt, spc+4, flags, false);
1353 pp_string (buffer, " goto ");
1354 dump_generic_node (buffer, CASE_LABEL (elt), spc+4, flags, true);
1355 pp_semicolon (buffer);
1358 newline_and_indent (buffer, spc+2);
1359 pp_character (buffer, '}');
1365 op0 = GOTO_DESTINATION (node);
1366 if (TREE_CODE (op0) != SSA_NAME && DECL_P (op0) && DECL_NAME (op0))
1368 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1369 if (strcmp (name, "break") == 0
1370 || strcmp (name, "continue") == 0)
1372 pp_string (buffer, name);
1376 pp_string (buffer, "goto ");
1377 dump_generic_node (buffer, op0, spc, flags, false);
1381 pp_string (buffer, "resx");
1382 /* ??? Any sensible way to present the eh region? */
1386 pp_string (buffer, "__asm__");
1387 if (ASM_VOLATILE_P (node))
1388 pp_string (buffer, " __volatile__");
1389 pp_character (buffer, '(');
1390 dump_generic_node (buffer, ASM_STRING (node), spc, flags, false);
1391 pp_character (buffer, ':');
1392 dump_generic_node (buffer, ASM_OUTPUTS (node), spc, flags, false);
1393 pp_character (buffer, ':');
1394 dump_generic_node (buffer, ASM_INPUTS (node), spc, flags, false);
1395 if (ASM_CLOBBERS (node))
1397 pp_character (buffer, ':');
1398 dump_generic_node (buffer, ASM_CLOBBERS (node), spc, flags, false);
1400 pp_string (buffer, ")");
1403 case CASE_LABEL_EXPR:
1404 if (CASE_LOW (node) && CASE_HIGH (node))
1406 pp_string (buffer, "case ");
1407 dump_generic_node (buffer, CASE_LOW (node), spc, flags, false);
1408 pp_string (buffer, " ... ");
1409 dump_generic_node (buffer, CASE_HIGH (node), spc, flags, false);
1411 else if (CASE_LOW (node))
1413 pp_string (buffer, "case ");
1414 dump_generic_node (buffer, CASE_LOW (node), spc, flags, false);
1417 pp_string (buffer, "default ");
1418 pp_character (buffer, ':');
1422 pp_string (buffer, "OBJ_TYPE_REF(");
1423 dump_generic_node (buffer, OBJ_TYPE_REF_EXPR (node), spc, flags, false);
1424 pp_character (buffer, ';');
1425 dump_generic_node (buffer, OBJ_TYPE_REF_OBJECT (node), spc, flags, false);
1426 pp_character (buffer, '-');
1427 pp_character (buffer, '>');
1428 dump_generic_node (buffer, OBJ_TYPE_REF_TOKEN (node), spc, flags, false);
1429 pp_character (buffer, ')');
1436 dump_generic_node (buffer, PHI_RESULT (node), spc, flags, false);
1437 pp_string (buffer, " = PHI <");
1438 for (i = 0; i < PHI_NUM_ARGS (node); i++)
1440 dump_generic_node (buffer, PHI_ARG_DEF (node, i), spc, flags, false);
1441 pp_string (buffer, "(");
1442 pp_decimal_int (buffer, PHI_ARG_EDGE (node, i)->src->index);
1443 pp_string (buffer, ")");
1444 if (i < PHI_NUM_ARGS (node) - 1)
1445 pp_string (buffer, ", ");
1447 pp_string (buffer, ">;");
1452 dump_generic_node (buffer, SSA_NAME_VAR (node), spc, flags, false);
1453 pp_string (buffer, "_");
1454 pp_decimal_int (buffer, SSA_NAME_VERSION (node));
1457 case WITH_SIZE_EXPR:
1458 pp_string (buffer, "WITH_SIZE_EXPR <");
1459 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1460 pp_string (buffer, ", ");
1461 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1462 pp_string (buffer, ">");
1466 pp_printf (buffer, "VH.%d", VALUE_HANDLE_ID (node));
1470 pp_string (buffer, "scev_known");
1473 case SCEV_NOT_KNOWN:
1474 pp_string (buffer, "scev_not_known");
1477 case POLYNOMIAL_CHREC:
1478 pp_string (buffer, "{");
1479 dump_generic_node (buffer, CHREC_LEFT (node), spc, flags, false);
1480 pp_string (buffer, ", +, ");
1481 dump_generic_node (buffer, CHREC_RIGHT (node), spc, flags, false);
1482 pp_string (buffer, "}_");
1483 dump_generic_node (buffer, CHREC_VAR (node), spc, flags, false);
1487 case REALIGN_LOAD_EXPR:
1488 pp_string (buffer, "REALIGN_LOAD <");
1489 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1490 pp_string (buffer, ", ");
1491 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1492 pp_string (buffer, ", ");
1493 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
1494 pp_string (buffer, ">");
1498 pp_string (buffer, " VEC_COND_EXPR < ");
1499 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1500 pp_string (buffer, " , ");
1501 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1502 pp_string (buffer, " , ");
1503 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
1504 pp_string (buffer, " > ");
1511 if (is_stmt && is_expr)
1512 pp_semicolon (buffer);
1513 pp_write_text_to_stream (buffer);
1518 /* Print the declaration of a variable. */
1521 print_declaration (pretty_printer *buffer, tree t, int spc, int flags)
1525 if (TREE_CODE (t) == TYPE_DECL)
1526 pp_string (buffer, "typedef ");
1528 if (DECL_REGISTER (t))
1529 pp_string (buffer, "register ");
1531 if (TREE_PUBLIC (t) && DECL_EXTERNAL (t))
1532 pp_string (buffer, "extern ");
1533 else if (TREE_STATIC (t))
1534 pp_string (buffer, "static ");
1536 /* Print the type and name. */
1537 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
1541 /* Print array's type. */
1542 tmp = TREE_TYPE (t);
1543 while (TREE_CODE (TREE_TYPE (tmp)) == ARRAY_TYPE)
1544 tmp = TREE_TYPE (tmp);
1545 dump_generic_node (buffer, TREE_TYPE (tmp), spc, flags, false);
1547 /* Print variable's name. */
1549 dump_generic_node (buffer, t, spc, flags, false);
1551 /* Print the dimensions. */
1552 tmp = TREE_TYPE (t);
1553 while (TREE_CODE (tmp) == ARRAY_TYPE)
1555 pp_character (buffer, '[');
1556 if (TYPE_DOMAIN (tmp))
1558 if (TREE_CODE (TYPE_SIZE (tmp)) == INTEGER_CST)
1559 pp_wide_integer (buffer,
1560 TREE_INT_CST_LOW (TYPE_SIZE (tmp)) /
1561 TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (tmp))));
1563 dump_generic_node (buffer, TYPE_SIZE_UNIT (tmp), spc, flags,
1566 pp_character (buffer, ']');
1567 tmp = TREE_TYPE (tmp);
1570 else if (TREE_CODE (t) == FUNCTION_DECL)
1572 dump_generic_node (buffer, TREE_TYPE (TREE_TYPE (t)), spc, flags, false);
1574 dump_decl_name (buffer, t, flags);
1575 dump_function_declaration (buffer, TREE_TYPE (t), spc, flags);
1579 /* Print type declaration. */
1580 dump_generic_node (buffer, TREE_TYPE (t), spc, flags, false);
1582 /* Print variable's name. */
1584 dump_generic_node (buffer, t, spc, flags, false);
1587 if (TREE_CODE (t) == VAR_DECL && DECL_HARD_REGISTER (t))
1589 pp_string (buffer, " __asm__ ");
1590 pp_character (buffer, '(');
1591 dump_generic_node (buffer, DECL_ASSEMBLER_NAME (t), spc, flags, false);
1592 pp_character (buffer, ')');
1595 /* The initial value of a function serves to determine wether the function
1596 is declared or defined. So the following does not apply to function
1598 if (TREE_CODE (t) != FUNCTION_DECL)
1600 /* Print the initial value. */
1601 if (DECL_INITIAL (t))
1604 pp_character (buffer, '=');
1606 dump_generic_node (buffer, DECL_INITIAL (t), spc, flags, false);
1610 pp_character (buffer, ';');
1614 /* Prints a structure: name, fields, and methods.
1615 FIXME: Still incomplete. */
1618 print_struct_decl (pretty_printer *buffer, tree node, int spc, int flags)
1620 /* Print the name of the structure. */
1621 if (TYPE_NAME (node))
1624 if (TREE_CODE (node) == RECORD_TYPE)
1625 pp_string (buffer, "struct ");
1626 else if ((TREE_CODE (node) == UNION_TYPE
1627 || TREE_CODE (node) == QUAL_UNION_TYPE))
1628 pp_string (buffer, "union ");
1630 dump_generic_node (buffer, TYPE_NAME (node), spc, 0, false);
1633 /* Print the contents of the structure. */
1634 pp_newline (buffer);
1636 pp_character (buffer, '{');
1637 pp_newline (buffer);
1639 /* Print the fields of the structure. */
1642 tmp = TYPE_FIELDS (node);
1645 /* Avoid to print recursively the structure. */
1646 /* FIXME : Not implemented correctly...,
1647 what about the case when we have a cycle in the contain graph? ...
1648 Maybe this could be solved by looking at the scope in which the
1649 structure was declared. */
1650 if (TREE_TYPE (tmp) != node
1651 || (TREE_CODE (TREE_TYPE (tmp)) == POINTER_TYPE
1652 && TREE_TYPE (TREE_TYPE (tmp)) != node))
1654 print_declaration (buffer, tmp, spc+2, flags);
1655 pp_newline (buffer);
1657 tmp = TREE_CHAIN (tmp);
1661 pp_character (buffer, '}');
1664 /* Return the priority of the operator OP.
1666 From lowest to highest precedence with either left-to-right (L-R)
1667 or right-to-left (R-L) associativity]:
1670 2 [R-L] = += -= *= /= %= &= ^= |= <<= >>=
1682 14 [R-L] ! ~ ++ -- + - * & (type) sizeof
1683 15 [L-R] fn() [] -> .
1685 unary +, - and * have higher precedence than the corresponding binary
1694 switch (TREE_CODE (op))
1709 case TRUTH_ORIF_EXPR:
1712 case TRUTH_AND_EXPR:
1713 case TRUTH_ANDIF_EXPR:
1720 case TRUTH_XOR_EXPR:
1737 case UNORDERED_EXPR:
1755 case TRUNC_DIV_EXPR:
1757 case FLOOR_DIV_EXPR:
1758 case ROUND_DIV_EXPR:
1760 case EXACT_DIV_EXPR:
1761 case TRUNC_MOD_EXPR:
1763 case FLOOR_MOD_EXPR:
1764 case ROUND_MOD_EXPR:
1767 case TRUTH_NOT_EXPR:
1769 case POSTINCREMENT_EXPR:
1770 case POSTDECREMENT_EXPR:
1771 case PREINCREMENT_EXPR:
1772 case PREDECREMENT_EXPR:
1774 case ALIGN_INDIRECT_REF:
1775 case MISALIGNED_INDIRECT_REF:
1781 case FIX_TRUNC_EXPR:
1783 case FIX_FLOOR_EXPR:
1784 case FIX_ROUND_EXPR:
1790 case ARRAY_RANGE_REF:
1794 /* Special expressions. */
1803 case NON_LVALUE_EXPR:
1804 return op_prio (TREE_OPERAND (op, 0));
1807 /* Return an arbitrarily high precedence to avoid surrounding single
1808 VAR_DECLs in ()s. */
1814 /* Return the symbol associated with operator OP. */
1821 switch (TREE_CODE (op))
1827 case TRUTH_ORIF_EXPR:
1830 case TRUTH_AND_EXPR:
1831 case TRUTH_ANDIF_EXPR:
1837 case TRUTH_XOR_EXPR:
1847 case UNORDERED_EXPR:
1897 case TRUTH_NOT_EXPR:
1904 case ALIGN_INDIRECT_REF:
1907 case MISALIGNED_INDIRECT_REF:
1910 case TRUNC_DIV_EXPR:
1917 case FLOOR_DIV_EXPR:
1920 case ROUND_DIV_EXPR:
1923 case EXACT_DIV_EXPR:
1926 case TRUNC_MOD_EXPR:
1932 case FLOOR_MOD_EXPR:
1935 case ROUND_MOD_EXPR:
1938 case PREDECREMENT_EXPR:
1941 case PREINCREMENT_EXPR:
1944 case POSTDECREMENT_EXPR:
1947 case POSTINCREMENT_EXPR:
1951 return "<<< ??? >>>";
1955 /* Prints the name of a CALL_EXPR. */
1958 print_call_name (pretty_printer *buffer, tree node)
1962 gcc_assert (TREE_CODE (node) == CALL_EXPR);
1964 op0 = TREE_OPERAND (node, 0);
1966 if (TREE_CODE (op0) == NON_LVALUE_EXPR)
1967 op0 = TREE_OPERAND (op0, 0);
1969 switch (TREE_CODE (op0))
1973 dump_function_name (buffer, op0);
1979 dump_generic_node (buffer, TREE_OPERAND (op0, 0), 0, 0, false);
1983 pp_string (buffer, "(");
1984 dump_generic_node (buffer, TREE_OPERAND (op0, 0), 0, 0, false);
1985 pp_string (buffer, ") ? ");
1986 dump_generic_node (buffer, TREE_OPERAND (op0, 1), 0, 0, false);
1987 pp_string (buffer, " : ");
1988 dump_generic_node (buffer, TREE_OPERAND (op0, 2), 0, 0, false);
1992 /* The function is a pointer contained in a structure. */
1993 if (TREE_CODE (TREE_OPERAND (op0, 0)) == INDIRECT_REF ||
1994 TREE_CODE (TREE_OPERAND (op0, 0)) == VAR_DECL)
1995 dump_function_name (buffer, TREE_OPERAND (op0, 1));
1997 dump_generic_node (buffer, TREE_OPERAND (op0, 0), 0, 0, false);
1999 We can have several levels of structures and a function
2000 pointer inside. This is not implemented yet... */
2005 if (TREE_CODE (TREE_OPERAND (op0, 0)) == VAR_DECL)
2006 dump_function_name (buffer, TREE_OPERAND (op0, 0));
2008 dump_generic_node (buffer, op0, 0, 0, false);
2013 dump_generic_node (buffer, op0, 0, 0, false);
2021 /* Parses the string STR and replaces new-lines by '\n', tabs by '\t', ... */
2024 pretty_print_string (pretty_printer *buffer, const char *str)
2034 pp_string (buffer, "\\b");
2038 pp_string (buffer, "\\f");
2042 pp_string (buffer, "\\n");
2046 pp_string (buffer, "\\r");
2050 pp_string (buffer, "\\t");
2054 pp_string (buffer, "\\v");
2058 pp_string (buffer, "\\\\");
2062 pp_string (buffer, "\\\"");
2066 pp_string (buffer, "\\'");
2070 pp_string (buffer, "\\0");
2074 pp_string (buffer, "\\1");
2078 pp_string (buffer, "\\2");
2082 pp_string (buffer, "\\3");
2086 pp_string (buffer, "\\4");
2090 pp_string (buffer, "\\5");
2094 pp_string (buffer, "\\6");
2098 pp_string (buffer, "\\7");
2102 pp_character (buffer, str[0]);
2110 maybe_init_pretty_print (FILE *file)
2114 pp_construct (&buffer, /* prefix */NULL, /* line-width */0);
2115 pp_needs_newline (&buffer) = true;
2119 buffer.buffer->stream = file;
2123 newline_and_indent (pretty_printer *buffer, int spc)
2125 pp_newline (buffer);
2130 dump_vops (pretty_printer *buffer, tree stmt, int spc, int flags)
2133 use_operand_p use_p;
2134 def_operand_p def_p;
2137 FOR_EACH_SSA_MAYDEF_OPERAND (def_p, use_p, stmt, iter)
2139 pp_string (buffer, "# ");
2140 dump_generic_node (buffer, DEF_FROM_PTR (def_p),
2141 spc + 2, flags, false);
2142 pp_string (buffer, " = V_MAY_DEF <");
2143 dump_generic_node (buffer, USE_FROM_PTR (use_p),
2144 spc + 2, flags, false);
2145 pp_string (buffer, ">;");
2146 newline_and_indent (buffer, spc);
2149 FOR_EACH_SSA_TREE_OPERAND (def, stmt, iter, SSA_OP_VMUSTDEF)
2151 pp_string (buffer, "# V_MUST_DEF <");
2152 dump_generic_node (buffer, def, spc + 2, flags, false);
2153 pp_string (buffer, ">;");
2154 newline_and_indent (buffer, spc);
2157 FOR_EACH_SSA_TREE_OPERAND (use, stmt, iter, SSA_OP_VUSE)
2159 pp_string (buffer, "# VUSE <");
2160 dump_generic_node (buffer, use, spc + 2, flags, false);
2161 pp_string (buffer, ">;");
2162 newline_and_indent (buffer, spc);
2166 /* Dumps basic block BB to FILE with details described by FLAGS and
2167 indented by INDENT spaces. */
2170 dump_generic_bb (FILE *file, basic_block bb, int indent, int flags)
2172 maybe_init_pretty_print (file);
2173 dumping_stmts = true;
2174 dump_generic_bb_buff (&buffer, bb, indent, flags);
2178 /* Dumps header of basic block BB to buffer BUFFER indented by INDENT
2179 spaces and details described by flags. */
2182 dump_bb_header (pretty_printer *buffer, basic_block bb, int indent, int flags)
2188 if (flags & TDF_BLOCKS)
2191 pp_string (buffer, "# BLOCK ");
2192 pp_decimal_int (buffer, bb->index);
2194 if (flags & TDF_LINENO)
2196 block_stmt_iterator bsi;
2198 for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
2199 if (get_lineno (bsi_stmt (bsi)) != -1)
2201 pp_string (buffer, ", starting at line ");
2202 pp_decimal_int (buffer, get_lineno (bsi_stmt (bsi)));
2206 newline_and_indent (buffer, indent);
2208 pp_string (buffer, "# PRED:");
2209 pp_write_text_to_stream (buffer);
2210 FOR_EACH_EDGE (e, ei, bb->preds)
2211 if (flags & TDF_SLIM)
2213 pp_string (buffer, " ");
2214 if (e->src == ENTRY_BLOCK_PTR)
2215 pp_string (buffer, "ENTRY");
2217 pp_decimal_int (buffer, e->src->index);
2220 dump_edge_info (buffer->buffer->stream, e, 0);
2221 pp_newline (buffer);
2225 stmt = first_stmt (bb);
2226 if (!stmt || TREE_CODE (stmt) != LABEL_EXPR)
2228 INDENT (indent - 2);
2229 pp_string (buffer, "<bb ");
2230 pp_decimal_int (buffer, bb->index);
2231 pp_string (buffer, ">:");
2232 pp_newline (buffer);
2235 pp_write_text_to_stream (buffer);
2236 check_bb_profile (bb, buffer->buffer->stream);
2239 /* Dumps end of basic block BB to buffer BUFFER indented by INDENT
2243 dump_bb_end (pretty_printer *buffer, basic_block bb, int indent, int flags)
2249 pp_string (buffer, "# SUCC:");
2250 pp_write_text_to_stream (buffer);
2251 FOR_EACH_EDGE (e, ei, bb->succs)
2252 if (flags & TDF_SLIM)
2254 pp_string (buffer, " ");
2255 if (e->dest == EXIT_BLOCK_PTR)
2256 pp_string (buffer, "EXIT");
2258 pp_decimal_int (buffer, e->dest->index);
2261 dump_edge_info (buffer->buffer->stream, e, 1);
2262 pp_newline (buffer);
2265 /* Dumps phi nodes of basic block BB to buffer BUFFER with details described by
2266 FLAGS indented by INDENT spaces. */
2269 dump_phi_nodes (pretty_printer *buffer, basic_block bb, int indent, int flags)
2271 tree phi = phi_nodes (bb);
2275 for (; phi; phi = PHI_CHAIN (phi))
2277 if (is_gimple_reg (PHI_RESULT (phi)) || (flags & TDF_VOPS))
2280 pp_string (buffer, "# ");
2281 dump_generic_node (buffer, phi, indent, flags, false);
2282 pp_newline (buffer);
2287 /* Dump jump to basic block BB that is represented implicitly in the cfg
2291 pp_cfg_jump (pretty_printer *buffer, basic_block bb)
2295 stmt = first_stmt (bb);
2297 pp_string (buffer, "goto <bb ");
2298 pp_decimal_int (buffer, bb->index);
2299 pp_string (buffer, ">");
2300 if (stmt && TREE_CODE (stmt) == LABEL_EXPR)
2302 pp_string (buffer, " (");
2303 dump_generic_node (buffer, LABEL_EXPR_LABEL (stmt), 0, 0, false);
2304 pp_string (buffer, ")");
2306 pp_semicolon (buffer);
2309 /* Dump edges represented implicitly in basic block BB to BUFFER, indented
2310 by INDENT spaces, with details given by FLAGS. */
2313 dump_implicit_edges (pretty_printer *buffer, basic_block bb, int indent,
2319 /* If there is a fallthru edge, we may need to add an artificial goto to the
2321 FOR_EACH_EDGE (e, ei, bb->succs)
2322 if (e->flags & EDGE_FALLTHRU)
2324 if (e && e->dest != bb->next_bb)
2328 if ((flags & TDF_LINENO)
2329 #ifdef USE_MAPPED_LOCATION
2330 && e->goto_locus != UNKNOWN_LOCATION
2336 expanded_location goto_xloc;
2337 #ifdef USE_MAPPED_LOCATION
2338 goto_xloc = expand_location (e->goto_locus);
2340 goto_xloc = *e->goto_locus;
2342 pp_character (buffer, '[');
2345 pp_string (buffer, goto_xloc.file);
2346 pp_string (buffer, " : ");
2348 pp_decimal_int (buffer, goto_xloc.line);
2349 pp_string (buffer, "] ");
2352 pp_cfg_jump (buffer, e->dest);
2353 pp_newline (buffer);
2357 /* Dumps basic block BB to buffer BUFFER with details described by FLAGS and
2358 indented by INDENT spaces. */
2361 dump_generic_bb_buff (pretty_printer *buffer, basic_block bb,
2362 int indent, int flags)
2364 block_stmt_iterator bsi;
2366 int label_indent = indent - 2;
2368 if (label_indent < 0)
2371 dump_bb_header (buffer, bb, indent, flags);
2374 dump_phi_nodes (buffer, bb, indent, flags);
2376 for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
2380 stmt = bsi_stmt (bsi);
2382 curr_indent = TREE_CODE (stmt) == LABEL_EXPR ? label_indent : indent;
2384 INDENT (curr_indent);
2385 dump_generic_node (buffer, stmt, curr_indent, flags, true);
2386 pp_newline (buffer);
2389 dump_implicit_edges (buffer, bb, indent, flags);
2391 if (flags & TDF_BLOCKS)
2392 dump_bb_end (buffer, bb, indent, flags);