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");
401 if (TYPE_REF_CAN_ALIAS_ALL (node
))
402 pp_string (buffer
, " {ref-all}");
411 dump_decl_name (buffer
, TYPE_NAME (TYPE_METHOD_BASETYPE (node
)), flags
);
412 pp_string (buffer
, "::");
423 /* Print the innermost component type. */
424 for (tmp
= TREE_TYPE (node
); TREE_CODE (tmp
) == ARRAY_TYPE
;
425 tmp
= TREE_TYPE (tmp
))
427 dump_generic_node (buffer
, tmp
, spc
, flags
, false);
429 /* Print the dimensions. */
430 for (tmp
= node
; TREE_CODE (tmp
) == ARRAY_TYPE
;
431 tmp
= TREE_TYPE (tmp
))
433 tree domain
= TYPE_DOMAIN (tmp
);
435 pp_character (buffer
, '[');
438 if (TYPE_MIN_VALUE (domain
)
439 && !integer_zerop (TYPE_MIN_VALUE (domain
)))
441 dump_generic_node (buffer
, TYPE_MIN_VALUE (domain
),
443 pp_string (buffer
, " .. ");
446 if (TYPE_MAX_VALUE (domain
))
447 dump_generic_node (buffer
, TYPE_MAX_VALUE (domain
),
451 pp_string (buffer
, "<unknown>");
453 pp_character (buffer
, ']');
464 case QUAL_UNION_TYPE
:
465 /* Print the name of the structure. */
466 if (TREE_CODE (node
) == RECORD_TYPE
)
467 pp_string (buffer
, "struct ");
468 else if (TREE_CODE (node
) == UNION_TYPE
)
469 pp_string (buffer
, "union ");
471 if (TYPE_NAME (node
))
472 dump_generic_node (buffer
, TYPE_NAME (node
), spc
, flags
, false);
474 print_struct_decl (buffer
, node
, spc
, flags
);
482 if (TREE_CODE (TREE_TYPE (node
)) == POINTER_TYPE
)
484 /* In the case of a pointer, one may want to divide by the
485 size of the pointed-to type. Unfortunately, this not
486 straightforward. The C front-end maps expressions
491 in such a way that the two INTEGER_CST nodes for "5" have
492 different values but identical types. In the latter
493 case, the 5 is multiplied by sizeof (int) in c-common.c
494 (pointer_int_sum) to convert it to a byte address, and
495 yet the type of the node is left unchanged. Argh. What
496 is consistent though is that the number value corresponds
497 to bytes (UNITS) offset.
499 NB: Neither of the following divisors can be trivially
500 used to recover the original literal:
502 TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (node)))
503 TYPE_PRECISION (TREE_TYPE (TREE_TYPE (node))) */
504 pp_wide_integer (buffer
, TREE_INT_CST_LOW (node
));
505 pp_string (buffer
, "B"); /* pseudo-unit */
507 else if (! host_integerp (node
, 0))
511 if (tree_int_cst_sgn (val
) < 0)
513 pp_character (buffer
, '-');
514 val
= build_int_cst_wide (NULL_TREE
,
515 -TREE_INT_CST_LOW (val
),
516 ~TREE_INT_CST_HIGH (val
)
517 + !TREE_INT_CST_LOW (val
));
519 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
522 static char format
[10]; /* "%x%09999x\0" */
524 sprintf (format
, "%%x%%0%dx", HOST_BITS_PER_INT
/ 4);
525 sprintf (pp_buffer (buffer
)->digit_buffer
, format
,
526 TREE_INT_CST_HIGH (val
),
527 TREE_INT_CST_LOW (val
));
528 pp_string (buffer
, pp_buffer (buffer
)->digit_buffer
);
532 pp_wide_integer (buffer
, TREE_INT_CST_LOW (node
));
536 /* Code copied from print_node. */
539 if (TREE_OVERFLOW (node
))
540 pp_string (buffer
, " overflow");
542 #if !defined(REAL_IS_NOT_DOUBLE) || defined(REAL_ARITHMETIC)
543 d
= TREE_REAL_CST (node
);
544 if (REAL_VALUE_ISINF (d
))
545 pp_string (buffer
, " Inf");
546 else if (REAL_VALUE_ISNAN (d
))
547 pp_string (buffer
, " Nan");
551 real_to_decimal (string
, &d
, sizeof (string
), 0, 1);
552 pp_string (buffer
, string
);
557 unsigned char *p
= (unsigned char *) &TREE_REAL_CST (node
);
558 pp_string (buffer
, "0x");
559 for (i
= 0; i
< sizeof TREE_REAL_CST (node
); i
++)
560 output_formatted_integer (buffer
, "%02x", *p
++);
567 pp_string (buffer
, "__complex__ (");
568 dump_generic_node (buffer
, TREE_REALPART (node
), spc
, flags
, false);
569 pp_string (buffer
, ", ");
570 dump_generic_node (buffer
, TREE_IMAGPART (node
), spc
, flags
, false);
571 pp_string (buffer
, ")");
575 pp_string (buffer
, "\"");
576 pretty_print_string (buffer
, TREE_STRING_POINTER (node
));
577 pp_string (buffer
, "\"");
583 pp_string (buffer
, "{ ");
584 for (elt
= TREE_VECTOR_CST_ELTS (node
); elt
; elt
= TREE_CHAIN (elt
))
586 dump_generic_node (buffer
, TREE_VALUE (elt
), spc
, flags
, false);
587 if (TREE_CHAIN (elt
))
588 pp_string (buffer
, ", ");
590 pp_string (buffer
, " }");
599 dump_decl_name (buffer
, node
, flags
);
603 if (DECL_NAME (node
))
604 dump_decl_name (buffer
, node
, flags
);
605 else if (LABEL_DECL_UID (node
) != -1)
606 pp_printf (buffer
, "<L" HOST_WIDE_INT_PRINT_DEC
">",
607 LABEL_DECL_UID (node
));
609 pp_printf (buffer
, "<D%u>", DECL_UID (node
));
613 if (DECL_IS_BUILTIN (node
))
615 /* Don't print the declaration of built-in types. */
618 if (DECL_NAME (node
))
619 dump_decl_name (buffer
, node
, flags
);
622 if ((TREE_CODE (TREE_TYPE (node
)) == RECORD_TYPE
623 || TREE_CODE (TREE_TYPE (node
)) == UNION_TYPE
)
624 && TYPE_METHODS (TREE_TYPE (node
)))
626 /* The type is a c++ class: all structures have at least
628 pp_string (buffer
, "class ");
629 dump_generic_node (buffer
, TREE_TYPE (node
), spc
, flags
, false);
634 (TREE_CODE (TREE_TYPE (node
)) == UNION_TYPE
635 ? "union" : "struct "));
636 dump_generic_node (buffer
, TREE_TYPE (node
), spc
, flags
, false);
645 dump_decl_name (buffer
, node
, flags
);
649 pp_string (buffer
, "<retval>");
653 op0
= TREE_OPERAND (node
, 0);
655 if (TREE_CODE (op0
) == INDIRECT_REF
)
657 op0
= TREE_OPERAND (op0
, 0);
660 if (op_prio (op0
) < op_prio (node
))
661 pp_character (buffer
, '(');
662 dump_generic_node (buffer
, op0
, spc
, flags
, false);
663 if (op_prio (op0
) < op_prio (node
))
664 pp_character (buffer
, ')');
665 pp_string (buffer
, str
);
666 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
668 if (TREE_CODE (op0
) != VALUE_HANDLE
)
670 op0
= component_ref_field_offset (node
);
671 if (op0
&& TREE_CODE (op0
) != INTEGER_CST
)
673 pp_string (buffer
, "{off: ");
674 dump_generic_node (buffer
, op0
, spc
, flags
, false);
675 pp_character (buffer
, '}');
681 pp_string (buffer
, "BIT_FIELD_REF <");
682 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
683 pp_string (buffer
, ", ");
684 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
685 pp_string (buffer
, ", ");
686 dump_generic_node (buffer
, TREE_OPERAND (node
, 2), spc
, flags
, false);
687 pp_string (buffer
, ">");
691 case ARRAY_RANGE_REF
:
692 op0
= TREE_OPERAND (node
, 0);
693 if (op_prio (op0
) < op_prio (node
))
694 pp_character (buffer
, '(');
695 dump_generic_node (buffer
, op0
, spc
, flags
, false);
696 if (op_prio (op0
) < op_prio (node
))
697 pp_character (buffer
, ')');
698 pp_character (buffer
, '[');
699 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
700 if (TREE_CODE (node
) == ARRAY_RANGE_REF
)
701 pp_string (buffer
, " ...");
702 pp_character (buffer
, ']');
704 op0
= array_ref_low_bound (node
);
705 op1
= array_ref_element_size (node
);
707 if (!integer_zerop (op0
)
708 || (TYPE_SIZE_UNIT (TREE_TYPE (node
))
709 && !operand_equal_p (op1
, TYPE_SIZE_UNIT (TREE_TYPE (node
)), 0)))
711 pp_string (buffer
, "{lb: ");
712 dump_generic_node (buffer
, op0
, spc
, flags
, false);
713 pp_string (buffer
, " sz: ");
714 dump_generic_node (buffer
, op1
, spc
, flags
, false);
715 pp_character (buffer
, '}');
722 bool is_struct_init
= FALSE
;
723 pp_character (buffer
, '{');
724 lnode
= CONSTRUCTOR_ELTS (node
);
725 if (TREE_CODE (TREE_TYPE (node
)) == RECORD_TYPE
726 || TREE_CODE (TREE_TYPE (node
)) == UNION_TYPE
)
727 is_struct_init
= TRUE
;
728 while (lnode
&& lnode
!= error_mark_node
)
731 if (TREE_PURPOSE (lnode
) && is_struct_init
)
733 pp_character (buffer
, '.');
734 dump_generic_node (buffer
, TREE_PURPOSE (lnode
), spc
, flags
, false);
735 pp_string (buffer
, "=");
737 val
= TREE_VALUE (lnode
);
738 if (val
&& TREE_CODE (val
) == ADDR_EXPR
)
739 if (TREE_CODE (TREE_OPERAND (val
, 0)) == FUNCTION_DECL
)
740 val
= TREE_OPERAND (val
, 0);
741 if (val
&& TREE_CODE (val
) == FUNCTION_DECL
)
743 dump_decl_name (buffer
, val
, flags
);
747 dump_generic_node (buffer
, TREE_VALUE (lnode
), spc
, flags
, false);
749 lnode
= TREE_CHAIN (lnode
);
750 if (lnode
&& TREE_CODE (lnode
) == TREE_LIST
)
752 pp_character (buffer
, ',');
756 pp_character (buffer
, '}');
763 if (flags
& TDF_SLIM
)
765 pp_string (buffer
, "<COMPOUND_EXPR>");
769 dump_generic_node (buffer
, TREE_OPERAND (node
, 0),
770 spc
, flags
, dumping_stmts
);
772 newline_and_indent (buffer
, spc
);
775 pp_character (buffer
, ',');
779 for (tp
= &TREE_OPERAND (node
, 1);
780 TREE_CODE (*tp
) == COMPOUND_EXPR
;
781 tp
= &TREE_OPERAND (*tp
, 1))
783 dump_generic_node (buffer
, TREE_OPERAND (*tp
, 0),
784 spc
, flags
, dumping_stmts
);
786 newline_and_indent (buffer
, spc
);
789 pp_character (buffer
, ',');
794 dump_generic_node (buffer
, *tp
, spc
, flags
, dumping_stmts
);
800 tree_stmt_iterator si
;
803 if ((flags
& TDF_SLIM
) || !dumping_stmts
)
805 pp_string (buffer
, "<STATEMENT_LIST>");
809 for (si
= tsi_start (node
); !tsi_end_p (si
); tsi_next (&si
))
812 newline_and_indent (buffer
, spc
);
815 dump_generic_node (buffer
, tsi_stmt (si
), spc
, flags
, true);
822 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
824 pp_character (buffer
, '=');
826 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
830 pp_string (buffer
, "TARGET_EXPR <");
831 dump_generic_node (buffer
, TARGET_EXPR_SLOT (node
), spc
, flags
, false);
832 pp_character (buffer
, ',');
834 dump_generic_node (buffer
, TARGET_EXPR_INITIAL (node
), spc
, flags
, false);
835 pp_character (buffer
, '>');
839 print_declaration (buffer
, DECL_EXPR_DECL (node
), spc
, flags
);
844 if (TREE_TYPE (node
) == NULL
|| TREE_TYPE (node
) == void_type_node
)
846 pp_string (buffer
, "if (");
847 dump_generic_node (buffer
, COND_EXPR_COND (node
), spc
, flags
, false);
848 pp_character (buffer
, ')');
849 /* The lowered cond_exprs should always be printed in full. */
850 if (COND_EXPR_THEN (node
)
851 && (IS_EMPTY_STMT (COND_EXPR_THEN (node
))
852 || TREE_CODE (COND_EXPR_THEN (node
)) == GOTO_EXPR
)
853 && COND_EXPR_ELSE (node
)
854 && (IS_EMPTY_STMT (COND_EXPR_ELSE (node
))
855 || TREE_CODE (COND_EXPR_ELSE (node
)) == GOTO_EXPR
))
858 dump_generic_node (buffer
, COND_EXPR_THEN (node
), 0, flags
, true);
859 pp_string (buffer
, " else ");
860 dump_generic_node (buffer
, COND_EXPR_ELSE (node
), 0, flags
, true);
862 else if (!(flags
& TDF_SLIM
))
864 /* Output COND_EXPR_THEN. */
865 if (COND_EXPR_THEN (node
))
867 newline_and_indent (buffer
, spc
+2);
868 pp_character (buffer
, '{');
869 newline_and_indent (buffer
, spc
+4);
870 dump_generic_node (buffer
, COND_EXPR_THEN (node
), spc
+4,
872 newline_and_indent (buffer
, spc
+2);
873 pp_character (buffer
, '}');
876 /* Output COND_EXPR_ELSE. */
877 if (COND_EXPR_ELSE (node
))
879 newline_and_indent (buffer
, spc
);
880 pp_string (buffer
, "else");
881 newline_and_indent (buffer
, spc
+2);
882 pp_character (buffer
, '{');
883 newline_and_indent (buffer
, spc
+4);
884 dump_generic_node (buffer
, COND_EXPR_ELSE (node
), spc
+4,
886 newline_and_indent (buffer
, spc
+2);
887 pp_character (buffer
, '}');
894 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
896 pp_character (buffer
, '?');
898 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
900 pp_character (buffer
, ':');
902 dump_generic_node (buffer
, TREE_OPERAND (node
, 2), spc
, flags
, false);
907 pp_character (buffer
, '{');
908 if (!(flags
& TDF_SLIM
))
910 if (BIND_EXPR_VARS (node
))
914 for (op0
= BIND_EXPR_VARS (node
); op0
; op0
= TREE_CHAIN (op0
))
916 print_declaration (buffer
, op0
, spc
+2, flags
);
921 newline_and_indent (buffer
, spc
+2);
922 dump_generic_node (buffer
, BIND_EXPR_BODY (node
), spc
+2, flags
, true);
923 newline_and_indent (buffer
, spc
);
924 pp_character (buffer
, '}');
930 print_call_name (buffer
, node
);
932 /* Print parameters. */
934 pp_character (buffer
, '(');
935 op1
= TREE_OPERAND (node
, 1);
937 dump_generic_node (buffer
, op1
, spc
, flags
, false);
938 pp_character (buffer
, ')');
940 op1
= TREE_OPERAND (node
, 2);
943 pp_string (buffer
, " [static-chain: ");
944 dump_generic_node (buffer
, op1
, spc
, flags
, false);
945 pp_character (buffer
, ']');
948 if (CALL_EXPR_HAS_RETURN_SLOT_ADDR (node
))
949 pp_string (buffer
, " [return slot addr]");
950 if (CALL_EXPR_TAILCALL (node
))
951 pp_string (buffer
, " [tail call]");
954 case WITH_CLEANUP_EXPR
:
958 case CLEANUP_POINT_EXPR
:
959 pp_string (buffer
, "<<cleanup_point ");
960 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
961 pp_string (buffer
, ">>");
964 case PLACEHOLDER_EXPR
:
965 pp_string (buffer
, "<PLACEHOLDER_EXPR ");
966 dump_generic_node (buffer
, TREE_TYPE (node
), spc
, flags
, false);
967 pp_character (buffer
, '>');
970 /* Binary arithmetic and logic expressions. */
991 case TRUTH_ANDIF_EXPR
:
992 case TRUTH_ORIF_EXPR
:
1009 case UNORDERED_EXPR
:
1011 const char *op
= op_symbol (node
);
1012 op0
= TREE_OPERAND (node
, 0);
1013 op1
= TREE_OPERAND (node
, 1);
1015 /* When the operands are expressions with less priority,
1016 keep semantics of the tree representation. */
1017 if (op_prio (op0
) < op_prio (node
))
1019 pp_character (buffer
, '(');
1020 dump_generic_node (buffer
, op0
, spc
, flags
, false);
1021 pp_character (buffer
, ')');
1024 dump_generic_node (buffer
, op0
, spc
, flags
, false);
1027 pp_string (buffer
, op
);
1030 /* When the operands are expressions with less priority,
1031 keep semantics of the tree representation. */
1032 if (op_prio (op1
) < op_prio (node
))
1034 pp_character (buffer
, '(');
1035 dump_generic_node (buffer
, op1
, spc
, flags
, false);
1036 pp_character (buffer
, ')');
1039 dump_generic_node (buffer
, op1
, spc
, flags
, false);
1043 /* Unary arithmetic and logic expressions. */
1046 case TRUTH_NOT_EXPR
:
1048 case PREDECREMENT_EXPR
:
1049 case PREINCREMENT_EXPR
:
1050 case ALIGN_INDIRECT_REF
:
1051 case MISALIGNED_INDIRECT_REF
:
1053 if (TREE_CODE (node
) == ADDR_EXPR
1054 && (TREE_CODE (TREE_OPERAND (node
, 0)) == STRING_CST
1055 || TREE_CODE (TREE_OPERAND (node
, 0)) == FUNCTION_DECL
))
1056 ; /* Do not output '&' for strings and function pointers. */
1058 pp_string (buffer
, op_symbol (node
));
1060 if (op_prio (TREE_OPERAND (node
, 0)) < op_prio (node
))
1062 pp_character (buffer
, '(');
1063 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1064 pp_character (buffer
, ')');
1067 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1069 if (TREE_CODE (node
) == MISALIGNED_INDIRECT_REF
)
1071 pp_string (buffer
, "{misalignment: ");
1072 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
1073 pp_character (buffer
, '}');
1077 case POSTDECREMENT_EXPR
:
1078 case POSTINCREMENT_EXPR
:
1079 if (op_prio (TREE_OPERAND (node
, 0)) < op_prio (node
))
1081 pp_character (buffer
, '(');
1082 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1083 pp_character (buffer
, ')');
1086 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1087 pp_string (buffer
, op_symbol (node
));
1091 pp_string (buffer
, "MIN_EXPR <");
1092 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1093 pp_string (buffer
, ", ");
1094 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
1095 pp_character (buffer
, '>');
1099 pp_string (buffer
, "MAX_EXPR <");
1100 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1101 pp_string (buffer
, ", ");
1102 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
1103 pp_character (buffer
, '>');
1107 pp_string (buffer
, "ABS_EXPR <");
1108 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1109 pp_character (buffer
, '>');
1116 case FIX_TRUNC_EXPR
:
1118 case FIX_FLOOR_EXPR
:
1119 case FIX_ROUND_EXPR
:
1123 type
= TREE_TYPE (node
);
1124 op0
= TREE_OPERAND (node
, 0);
1125 if (type
!= TREE_TYPE (op0
))
1127 pp_character (buffer
, '(');
1128 dump_generic_node (buffer
, type
, spc
, flags
, false);
1129 pp_string (buffer
, ") ");
1131 if (op_prio (op0
) < op_prio (node
))
1132 pp_character (buffer
, '(');
1133 dump_generic_node (buffer
, op0
, spc
, flags
, false);
1134 if (op_prio (op0
) < op_prio (node
))
1135 pp_character (buffer
, ')');
1138 case VIEW_CONVERT_EXPR
:
1139 pp_string (buffer
, "VIEW_CONVERT_EXPR<");
1140 dump_generic_node (buffer
, TREE_TYPE (node
), spc
, flags
, false);
1141 pp_string (buffer
, ">(");
1142 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1143 pp_character (buffer
, ')');
1146 case NON_LVALUE_EXPR
:
1147 pp_string (buffer
, "NON_LVALUE_EXPR <");
1148 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1149 pp_character (buffer
, '>');
1153 pp_string (buffer
, "SAVE_EXPR <");
1154 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1155 pp_character (buffer
, '>');
1159 pp_string (buffer
, "COMPLEX_EXPR <");
1160 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1161 pp_string (buffer
, ", ");
1162 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
1163 pp_string (buffer
, ">");
1167 pp_string (buffer
, "CONJ_EXPR <");
1168 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1169 pp_string (buffer
, ">");
1173 pp_string (buffer
, "REALPART_EXPR <");
1174 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1175 pp_string (buffer
, ">");
1179 pp_string (buffer
, "IMAGPART_EXPR <");
1180 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1181 pp_string (buffer
, ">");
1185 pp_string (buffer
, "VA_ARG_EXPR <");
1186 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1187 pp_string (buffer
, ">");
1190 case TRY_FINALLY_EXPR
:
1191 case TRY_CATCH_EXPR
:
1192 pp_string (buffer
, "try");
1193 newline_and_indent (buffer
, spc
+2);
1194 pp_string (buffer
, "{");
1195 newline_and_indent (buffer
, spc
+4);
1196 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
+4, flags
, true);
1197 newline_and_indent (buffer
, spc
+2);
1198 pp_string (buffer
, "}");
1199 newline_and_indent (buffer
, spc
);
1201 (TREE_CODE (node
) == TRY_CATCH_EXPR
) ? "catch" : "finally");
1202 newline_and_indent (buffer
, spc
+2);
1203 pp_string (buffer
, "{");
1204 newline_and_indent (buffer
, spc
+4);
1205 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
+4, flags
, true);
1206 newline_and_indent (buffer
, spc
+2);
1207 pp_string (buffer
, "}");
1212 pp_string (buffer
, "catch (");
1213 dump_generic_node (buffer
, CATCH_TYPES (node
), spc
+2, flags
, false);
1214 pp_string (buffer
, ")");
1215 newline_and_indent (buffer
, spc
+2);
1216 pp_string (buffer
, "{");
1217 newline_and_indent (buffer
, spc
+4);
1218 dump_generic_node (buffer
, CATCH_BODY (node
), spc
+4, flags
, true);
1219 newline_and_indent (buffer
, spc
+2);
1220 pp_string (buffer
, "}");
1224 case EH_FILTER_EXPR
:
1225 pp_string (buffer
, "<<<eh_filter (");
1226 dump_generic_node (buffer
, EH_FILTER_TYPES (node
), spc
+2, flags
, false);
1227 pp_string (buffer
, ")>>>");
1228 newline_and_indent (buffer
, spc
+2);
1229 pp_string (buffer
, "{");
1230 newline_and_indent (buffer
, spc
+4);
1231 dump_generic_node (buffer
, EH_FILTER_FAILURE (node
), spc
+4, flags
, true);
1232 newline_and_indent (buffer
, spc
+2);
1233 pp_string (buffer
, "}");
1238 op0
= TREE_OPERAND (node
, 0);
1239 /* If this is for break or continue, don't bother printing it. */
1240 if (DECL_NAME (op0
))
1242 const char *name
= IDENTIFIER_POINTER (DECL_NAME (op0
));
1243 if (strcmp (name
, "break") == 0
1244 || strcmp (name
, "continue") == 0)
1247 dump_generic_node (buffer
, op0
, spc
, flags
, false);
1248 pp_character (buffer
, ':');
1249 if (DECL_NONLOCAL (op0
))
1250 pp_string (buffer
, " [non-local]");
1254 pp_string (buffer
, "<<<exception object>>>");
1258 pp_string (buffer
, "<<<filter object>>>");
1262 pp_string (buffer
, "while (1)");
1263 if (!(flags
& TDF_SLIM
))
1265 newline_and_indent (buffer
, spc
+2);
1266 pp_character (buffer
, '{');
1267 newline_and_indent (buffer
, spc
+4);
1268 dump_generic_node (buffer
, LOOP_EXPR_BODY (node
), spc
+4, flags
, true);
1269 newline_and_indent (buffer
, spc
+2);
1270 pp_character (buffer
, '}');
1276 pp_string (buffer
, "return");
1277 op0
= TREE_OPERAND (node
, 0);
1281 if (TREE_CODE (op0
) == MODIFY_EXPR
)
1282 dump_generic_node (buffer
, TREE_OPERAND (op0
, 1), spc
, flags
, false);
1284 dump_generic_node (buffer
, op0
, spc
, flags
, false);
1289 pp_string (buffer
, "if (");
1290 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1291 pp_string (buffer
, ") break");
1295 pp_string (buffer
, "switch (");
1296 dump_generic_node (buffer
, SWITCH_COND (node
), spc
, flags
, false);
1297 pp_character (buffer
, ')');
1298 if (!(flags
& TDF_SLIM
))
1300 newline_and_indent (buffer
, spc
+2);
1301 pp_character (buffer
, '{');
1302 if (SWITCH_BODY (node
))
1304 newline_and_indent (buffer
, spc
+4);
1305 dump_generic_node (buffer
, SWITCH_BODY (node
), spc
+4, flags
, true);
1309 tree vec
= SWITCH_LABELS (node
);
1310 size_t i
, n
= TREE_VEC_LENGTH (vec
);
1311 for (i
= 0; i
< n
; ++i
)
1313 tree elt
= TREE_VEC_ELT (vec
, i
);
1314 newline_and_indent (buffer
, spc
+4);
1315 dump_generic_node (buffer
, elt
, spc
+4, flags
, false);
1316 pp_string (buffer
, " goto ");
1317 dump_generic_node (buffer
, CASE_LABEL (elt
), spc
+4, flags
, true);
1318 pp_semicolon (buffer
);
1321 newline_and_indent (buffer
, spc
+2);
1322 pp_character (buffer
, '}');
1328 op0
= GOTO_DESTINATION (node
);
1329 if (TREE_CODE (op0
) != SSA_NAME
&& DECL_P (op0
) && DECL_NAME (op0
))
1331 const char *name
= IDENTIFIER_POINTER (DECL_NAME (op0
));
1332 if (strcmp (name
, "break") == 0
1333 || strcmp (name
, "continue") == 0)
1335 pp_string (buffer
, name
);
1339 pp_string (buffer
, "goto ");
1340 dump_generic_node (buffer
, op0
, spc
, flags
, false);
1344 pp_string (buffer
, "resx");
1345 /* ??? Any sensible way to present the eh region? */
1349 pp_string (buffer
, "__asm__");
1350 if (ASM_VOLATILE_P (node
))
1351 pp_string (buffer
, " __volatile__");
1352 pp_character (buffer
, '(');
1353 dump_generic_node (buffer
, ASM_STRING (node
), spc
, flags
, false);
1354 pp_character (buffer
, ':');
1355 dump_generic_node (buffer
, ASM_OUTPUTS (node
), spc
, flags
, false);
1356 pp_character (buffer
, ':');
1357 dump_generic_node (buffer
, ASM_INPUTS (node
), spc
, flags
, false);
1358 if (ASM_CLOBBERS (node
))
1360 pp_character (buffer
, ':');
1361 dump_generic_node (buffer
, ASM_CLOBBERS (node
), spc
, flags
, false);
1363 pp_string (buffer
, ")");
1366 case CASE_LABEL_EXPR
:
1367 if (CASE_LOW (node
) && CASE_HIGH (node
))
1369 pp_string (buffer
, "case ");
1370 dump_generic_node (buffer
, CASE_LOW (node
), spc
, flags
, false);
1371 pp_string (buffer
, " ... ");
1372 dump_generic_node (buffer
, CASE_HIGH (node
), spc
, flags
, false);
1374 else if (CASE_LOW (node
))
1376 pp_string (buffer
, "case ");
1377 dump_generic_node (buffer
, CASE_LOW (node
), spc
, flags
, false);
1380 pp_string (buffer
, "default ");
1381 pp_character (buffer
, ':');
1385 pp_string (buffer
, "OBJ_TYPE_REF(");
1386 dump_generic_node (buffer
, OBJ_TYPE_REF_EXPR (node
), spc
, flags
, false);
1387 pp_character (buffer
, ';');
1388 dump_generic_node (buffer
, OBJ_TYPE_REF_OBJECT (node
), spc
, flags
, false);
1389 pp_character (buffer
, '-');
1390 pp_character (buffer
, '>');
1391 dump_generic_node (buffer
, OBJ_TYPE_REF_TOKEN (node
), spc
, flags
, false);
1392 pp_character (buffer
, ')');
1399 dump_generic_node (buffer
, PHI_RESULT (node
), spc
, flags
, false);
1400 pp_string (buffer
, " = PHI <");
1401 for (i
= 0; i
< PHI_NUM_ARGS (node
); i
++)
1403 dump_generic_node (buffer
, PHI_ARG_DEF (node
, i
), spc
, flags
, false);
1404 pp_string (buffer
, "(");
1405 pp_decimal_int (buffer
, PHI_ARG_EDGE (node
, i
)->src
->index
);
1406 pp_string (buffer
, ")");
1407 if (i
< PHI_NUM_ARGS (node
) - 1)
1408 pp_string (buffer
, ", ");
1410 pp_string (buffer
, ">;");
1415 dump_generic_node (buffer
, SSA_NAME_VAR (node
), spc
, flags
, false);
1416 pp_string (buffer
, "_");
1417 pp_decimal_int (buffer
, SSA_NAME_VERSION (node
));
1420 case WITH_SIZE_EXPR
:
1421 pp_string (buffer
, "WITH_SIZE_EXPR <");
1422 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1423 pp_string (buffer
, ", ");
1424 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
1425 pp_string (buffer
, ">");
1429 pp_printf (buffer
, "VH.%d", VALUE_HANDLE_ID (node
));
1433 pp_string (buffer
, "scev_known");
1436 case SCEV_NOT_KNOWN
:
1437 pp_string (buffer
, "scev_not_known");
1440 case POLYNOMIAL_CHREC
:
1441 pp_string (buffer
, "{");
1442 dump_generic_node (buffer
, CHREC_LEFT (node
), spc
, flags
, false);
1443 pp_string (buffer
, ", +, ");
1444 dump_generic_node (buffer
, CHREC_RIGHT (node
), spc
, flags
, false);
1445 pp_string (buffer
, "}_");
1446 dump_generic_node (buffer
, CHREC_VAR (node
), spc
, flags
, false);
1450 case REALIGN_LOAD_EXPR
:
1451 pp_string (buffer
, "REALIGN_LOAD <");
1452 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1453 pp_string (buffer
, ", ");
1454 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
1455 pp_string (buffer
, ", ");
1456 dump_generic_node (buffer
, TREE_OPERAND (node
, 2), spc
, flags
, false);
1457 pp_string (buffer
, ">");
1461 pp_string (buffer
, " VEC_COND_EXPR < ");
1462 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1463 pp_string (buffer
, " , ");
1464 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
1465 pp_string (buffer
, " , ");
1466 dump_generic_node (buffer
, TREE_OPERAND (node
, 2), spc
, flags
, false);
1467 pp_string (buffer
, " > ");
1474 if (is_stmt
&& is_expr
)
1475 pp_semicolon (buffer
);
1476 pp_write_text_to_stream (buffer
);
1481 /* Print the declaration of a variable. */
1484 print_declaration (pretty_printer
*buffer
, tree t
, int spc
, int flags
)
1488 if (TREE_CODE (t
) == TYPE_DECL
)
1489 pp_string (buffer
, "typedef ");
1491 if (DECL_REGISTER (t
))
1492 pp_string (buffer
, "register ");
1494 if (TREE_PUBLIC (t
) && DECL_EXTERNAL (t
))
1495 pp_string (buffer
, "extern ");
1496 else if (TREE_STATIC (t
))
1497 pp_string (buffer
, "static ");
1499 /* Print the type and name. */
1500 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
1504 /* Print array's type. */
1505 tmp
= TREE_TYPE (t
);
1506 while (TREE_CODE (TREE_TYPE (tmp
)) == ARRAY_TYPE
)
1507 tmp
= TREE_TYPE (tmp
);
1508 dump_generic_node (buffer
, TREE_TYPE (tmp
), spc
, flags
, false);
1510 /* Print variable's name. */
1512 dump_generic_node (buffer
, t
, spc
, flags
, false);
1514 /* Print the dimensions. */
1515 tmp
= TREE_TYPE (t
);
1516 while (TREE_CODE (tmp
) == ARRAY_TYPE
)
1518 pp_character (buffer
, '[');
1519 if (TYPE_DOMAIN (tmp
))
1521 if (TYPE_MIN_VALUE (TYPE_DOMAIN (tmp
))
1522 && !integer_zerop (TYPE_MIN_VALUE (TYPE_DOMAIN (tmp
))))
1524 dump_generic_node (buffer
,
1525 TYPE_MIN_VALUE (TYPE_DOMAIN (tmp
)),
1527 pp_string (buffer
, " .. ");
1530 if (TYPE_MAX_VALUE (TYPE_DOMAIN (tmp
)))
1531 dump_generic_node (buffer
, TYPE_MAX_VALUE (TYPE_DOMAIN (tmp
)),
1534 pp_character (buffer
, ']');
1535 tmp
= TREE_TYPE (tmp
);
1538 else if (TREE_CODE (t
) == FUNCTION_DECL
)
1540 dump_generic_node (buffer
, TREE_TYPE (TREE_TYPE (t
)), spc
, flags
, false);
1542 dump_decl_name (buffer
, t
, flags
);
1543 dump_function_declaration (buffer
, TREE_TYPE (t
), spc
, flags
);
1547 /* Print type declaration. */
1548 dump_generic_node (buffer
, TREE_TYPE (t
), spc
, flags
, false);
1550 /* Print variable's name. */
1552 dump_generic_node (buffer
, t
, spc
, flags
, false);
1555 if (TREE_CODE (t
) == VAR_DECL
&& DECL_HARD_REGISTER (t
))
1557 pp_string (buffer
, " __asm__ ");
1558 pp_character (buffer
, '(');
1559 dump_generic_node (buffer
, DECL_ASSEMBLER_NAME (t
), spc
, flags
, false);
1560 pp_character (buffer
, ')');
1563 /* The initial value of a function serves to determine wether the function
1564 is declared or defined. So the following does not apply to function
1566 if (TREE_CODE (t
) != FUNCTION_DECL
)
1568 /* Print the initial value. */
1569 if (DECL_INITIAL (t
))
1572 pp_character (buffer
, '=');
1574 dump_generic_node (buffer
, DECL_INITIAL (t
), spc
, flags
, false);
1578 pp_character (buffer
, ';');
1582 /* Prints a structure: name, fields, and methods.
1583 FIXME: Still incomplete. */
1586 print_struct_decl (pretty_printer
*buffer
, tree node
, int spc
, int flags
)
1588 /* Print the name of the structure. */
1589 if (TYPE_NAME (node
))
1592 if (TREE_CODE (node
) == RECORD_TYPE
)
1593 pp_string (buffer
, "struct ");
1594 else if ((TREE_CODE (node
) == UNION_TYPE
1595 || TREE_CODE (node
) == QUAL_UNION_TYPE
))
1596 pp_string (buffer
, "union ");
1598 dump_generic_node (buffer
, TYPE_NAME (node
), spc
, 0, false);
1601 /* Print the contents of the structure. */
1602 pp_newline (buffer
);
1604 pp_character (buffer
, '{');
1605 pp_newline (buffer
);
1607 /* Print the fields of the structure. */
1610 tmp
= TYPE_FIELDS (node
);
1613 /* Avoid to print recursively the structure. */
1614 /* FIXME : Not implemented correctly...,
1615 what about the case when we have a cycle in the contain graph? ...
1616 Maybe this could be solved by looking at the scope in which the
1617 structure was declared. */
1618 if (TREE_TYPE (tmp
) != node
1619 || (TREE_CODE (TREE_TYPE (tmp
)) == POINTER_TYPE
1620 && TREE_TYPE (TREE_TYPE (tmp
)) != node
))
1622 print_declaration (buffer
, tmp
, spc
+2, flags
);
1623 pp_newline (buffer
);
1625 tmp
= TREE_CHAIN (tmp
);
1629 pp_character (buffer
, '}');
1632 /* Return the priority of the operator OP.
1634 From lowest to highest precedence with either left-to-right (L-R)
1635 or right-to-left (R-L) associativity]:
1638 2 [R-L] = += -= *= /= %= &= ^= |= <<= >>=
1650 14 [R-L] ! ~ ++ -- + - * & (type) sizeof
1651 15 [L-R] fn() [] -> .
1653 unary +, - and * have higher precedence than the corresponding binary
1662 switch (TREE_CODE (op
))
1677 case TRUTH_ORIF_EXPR
:
1680 case TRUTH_AND_EXPR
:
1681 case TRUTH_ANDIF_EXPR
:
1688 case TRUTH_XOR_EXPR
:
1705 case UNORDERED_EXPR
:
1723 case TRUNC_DIV_EXPR
:
1725 case FLOOR_DIV_EXPR
:
1726 case ROUND_DIV_EXPR
:
1728 case EXACT_DIV_EXPR
:
1729 case TRUNC_MOD_EXPR
:
1731 case FLOOR_MOD_EXPR
:
1732 case ROUND_MOD_EXPR
:
1735 case TRUTH_NOT_EXPR
:
1737 case POSTINCREMENT_EXPR
:
1738 case POSTDECREMENT_EXPR
:
1739 case PREINCREMENT_EXPR
:
1740 case PREDECREMENT_EXPR
:
1742 case ALIGN_INDIRECT_REF
:
1743 case MISALIGNED_INDIRECT_REF
:
1749 case FIX_TRUNC_EXPR
:
1751 case FIX_FLOOR_EXPR
:
1752 case FIX_ROUND_EXPR
:
1758 case ARRAY_RANGE_REF
:
1762 /* Special expressions. */
1771 case NON_LVALUE_EXPR
:
1772 return op_prio (TREE_OPERAND (op
, 0));
1775 /* Return an arbitrarily high precedence to avoid surrounding single
1776 VAR_DECLs in ()s. */
1782 /* Return the symbol associated with operator OP. */
1789 switch (TREE_CODE (op
))
1795 case TRUTH_ORIF_EXPR
:
1798 case TRUTH_AND_EXPR
:
1799 case TRUTH_ANDIF_EXPR
:
1805 case TRUTH_XOR_EXPR
:
1815 case UNORDERED_EXPR
:
1865 case TRUTH_NOT_EXPR
:
1872 case ALIGN_INDIRECT_REF
:
1875 case MISALIGNED_INDIRECT_REF
:
1878 case TRUNC_DIV_EXPR
:
1885 case FLOOR_DIV_EXPR
:
1888 case ROUND_DIV_EXPR
:
1891 case EXACT_DIV_EXPR
:
1894 case TRUNC_MOD_EXPR
:
1900 case FLOOR_MOD_EXPR
:
1903 case ROUND_MOD_EXPR
:
1906 case PREDECREMENT_EXPR
:
1909 case PREINCREMENT_EXPR
:
1912 case POSTDECREMENT_EXPR
:
1915 case POSTINCREMENT_EXPR
:
1919 return "<<< ??? >>>";
1923 /* Prints the name of a CALL_EXPR. */
1926 print_call_name (pretty_printer
*buffer
, tree node
)
1930 gcc_assert (TREE_CODE (node
) == CALL_EXPR
);
1932 op0
= TREE_OPERAND (node
, 0);
1934 if (TREE_CODE (op0
) == NON_LVALUE_EXPR
)
1935 op0
= TREE_OPERAND (op0
, 0);
1937 switch (TREE_CODE (op0
))
1941 dump_function_name (buffer
, op0
);
1947 dump_generic_node (buffer
, TREE_OPERAND (op0
, 0), 0, 0, false);
1951 pp_string (buffer
, "(");
1952 dump_generic_node (buffer
, TREE_OPERAND (op0
, 0), 0, 0, false);
1953 pp_string (buffer
, ") ? ");
1954 dump_generic_node (buffer
, TREE_OPERAND (op0
, 1), 0, 0, false);
1955 pp_string (buffer
, " : ");
1956 dump_generic_node (buffer
, TREE_OPERAND (op0
, 2), 0, 0, false);
1960 /* The function is a pointer contained in a structure. */
1961 if (TREE_CODE (TREE_OPERAND (op0
, 0)) == INDIRECT_REF
||
1962 TREE_CODE (TREE_OPERAND (op0
, 0)) == VAR_DECL
)
1963 dump_function_name (buffer
, TREE_OPERAND (op0
, 1));
1965 dump_generic_node (buffer
, TREE_OPERAND (op0
, 0), 0, 0, false);
1967 We can have several levels of structures and a function
1968 pointer inside. This is not implemented yet... */
1973 if (TREE_CODE (TREE_OPERAND (op0
, 0)) == VAR_DECL
)
1974 dump_function_name (buffer
, TREE_OPERAND (op0
, 0));
1976 dump_generic_node (buffer
, op0
, 0, 0, false);
1981 dump_generic_node (buffer
, op0
, 0, 0, false);
1989 /* Parses the string STR and replaces new-lines by '\n', tabs by '\t', ... */
1992 pretty_print_string (pretty_printer
*buffer
, const char *str
)
2002 pp_string (buffer
, "\\b");
2006 pp_string (buffer
, "\\f");
2010 pp_string (buffer
, "\\n");
2014 pp_string (buffer
, "\\r");
2018 pp_string (buffer
, "\\t");
2022 pp_string (buffer
, "\\v");
2026 pp_string (buffer
, "\\\\");
2030 pp_string (buffer
, "\\\"");
2034 pp_string (buffer
, "\\'");
2038 pp_string (buffer
, "\\0");
2042 pp_string (buffer
, "\\1");
2046 pp_string (buffer
, "\\2");
2050 pp_string (buffer
, "\\3");
2054 pp_string (buffer
, "\\4");
2058 pp_string (buffer
, "\\5");
2062 pp_string (buffer
, "\\6");
2066 pp_string (buffer
, "\\7");
2070 pp_character (buffer
, str
[0]);
2078 maybe_init_pretty_print (FILE *file
)
2082 pp_construct (&buffer
, /* prefix */NULL
, /* line-width */0);
2083 pp_needs_newline (&buffer
) = true;
2087 buffer
.buffer
->stream
= file
;
2091 newline_and_indent (pretty_printer
*buffer
, int spc
)
2093 pp_newline (buffer
);
2098 dump_vops (pretty_printer
*buffer
, tree stmt
, int spc
, int flags
)
2101 use_operand_p use_p
;
2102 def_operand_p def_p
;
2103 use_operand_p kill_p
;
2106 FOR_EACH_SSA_MAYDEF_OPERAND (def_p
, use_p
, stmt
, iter
)
2108 pp_string (buffer
, "# ");
2109 dump_generic_node (buffer
, DEF_FROM_PTR (def_p
),
2110 spc
+ 2, flags
, false);
2111 pp_string (buffer
, " = V_MAY_DEF <");
2112 dump_generic_node (buffer
, USE_FROM_PTR (use_p
),
2113 spc
+ 2, flags
, false);
2114 pp_string (buffer
, ">;");
2115 newline_and_indent (buffer
, spc
);
2118 FOR_EACH_SSA_MUSTDEF_OPERAND (def_p
, kill_p
, stmt
, iter
)
2120 pp_string (buffer
, "# ");
2121 dump_generic_node (buffer
, DEF_FROM_PTR (def_p
),
2122 spc
+ 2, flags
, false);
2123 pp_string (buffer
, " = V_MUST_DEF <");
2124 dump_generic_node (buffer
, USE_FROM_PTR (kill_p
),
2125 spc
+ 2, flags
, false);
2126 pp_string (buffer
, ">;");
2127 newline_and_indent (buffer
, spc
);
2130 FOR_EACH_SSA_TREE_OPERAND (use
, stmt
, iter
, SSA_OP_VUSE
)
2132 pp_string (buffer
, "# VUSE <");
2133 dump_generic_node (buffer
, use
, spc
+ 2, flags
, false);
2134 pp_string (buffer
, ">;");
2135 newline_and_indent (buffer
, spc
);
2139 /* Dumps basic block BB to FILE with details described by FLAGS and
2140 indented by INDENT spaces. */
2143 dump_generic_bb (FILE *file
, basic_block bb
, int indent
, int flags
)
2145 maybe_init_pretty_print (file
);
2146 dumping_stmts
= true;
2147 dump_generic_bb_buff (&buffer
, bb
, indent
, flags
);
2151 /* Dumps header of basic block BB to buffer BUFFER indented by INDENT
2152 spaces and details described by flags. */
2155 dump_bb_header (pretty_printer
*buffer
, basic_block bb
, int indent
, int flags
)
2161 if (flags
& TDF_BLOCKS
)
2164 pp_string (buffer
, "# BLOCK ");
2165 pp_decimal_int (buffer
, bb
->index
);
2167 if (flags
& TDF_LINENO
)
2169 block_stmt_iterator bsi
;
2171 for (bsi
= bsi_start (bb
); !bsi_end_p (bsi
); bsi_next (&bsi
))
2172 if (get_lineno (bsi_stmt (bsi
)) != -1)
2174 pp_string (buffer
, ", starting at line ");
2175 pp_decimal_int (buffer
, get_lineno (bsi_stmt (bsi
)));
2179 newline_and_indent (buffer
, indent
);
2181 pp_string (buffer
, "# PRED:");
2182 pp_write_text_to_stream (buffer
);
2183 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
2184 if (flags
& TDF_SLIM
)
2186 pp_string (buffer
, " ");
2187 if (e
->src
== ENTRY_BLOCK_PTR
)
2188 pp_string (buffer
, "ENTRY");
2190 pp_decimal_int (buffer
, e
->src
->index
);
2193 dump_edge_info (buffer
->buffer
->stream
, e
, 0);
2194 pp_newline (buffer
);
2198 stmt
= first_stmt (bb
);
2199 if (!stmt
|| TREE_CODE (stmt
) != LABEL_EXPR
)
2201 INDENT (indent
- 2);
2202 pp_string (buffer
, "<bb ");
2203 pp_decimal_int (buffer
, bb
->index
);
2204 pp_string (buffer
, ">:");
2205 pp_newline (buffer
);
2208 pp_write_text_to_stream (buffer
);
2209 check_bb_profile (bb
, buffer
->buffer
->stream
);
2212 /* Dumps end of basic block BB to buffer BUFFER indented by INDENT
2216 dump_bb_end (pretty_printer
*buffer
, basic_block bb
, int indent
, int flags
)
2222 pp_string (buffer
, "# SUCC:");
2223 pp_write_text_to_stream (buffer
);
2224 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
2225 if (flags
& TDF_SLIM
)
2227 pp_string (buffer
, " ");
2228 if (e
->dest
== EXIT_BLOCK_PTR
)
2229 pp_string (buffer
, "EXIT");
2231 pp_decimal_int (buffer
, e
->dest
->index
);
2234 dump_edge_info (buffer
->buffer
->stream
, e
, 1);
2235 pp_newline (buffer
);
2238 /* Dumps phi nodes of basic block BB to buffer BUFFER with details described by
2239 FLAGS indented by INDENT spaces. */
2242 dump_phi_nodes (pretty_printer
*buffer
, basic_block bb
, int indent
, int flags
)
2244 tree phi
= phi_nodes (bb
);
2248 for (; phi
; phi
= PHI_CHAIN (phi
))
2250 if (is_gimple_reg (PHI_RESULT (phi
)) || (flags
& TDF_VOPS
))
2253 pp_string (buffer
, "# ");
2254 dump_generic_node (buffer
, phi
, indent
, flags
, false);
2255 pp_newline (buffer
);
2260 /* Dump jump to basic block BB that is represented implicitly in the cfg
2264 pp_cfg_jump (pretty_printer
*buffer
, basic_block bb
)
2268 stmt
= first_stmt (bb
);
2270 pp_string (buffer
, "goto <bb ");
2271 pp_decimal_int (buffer
, bb
->index
);
2272 pp_string (buffer
, ">");
2273 if (stmt
&& TREE_CODE (stmt
) == LABEL_EXPR
)
2275 pp_string (buffer
, " (");
2276 dump_generic_node (buffer
, LABEL_EXPR_LABEL (stmt
), 0, 0, false);
2277 pp_string (buffer
, ")");
2279 pp_semicolon (buffer
);
2282 /* Dump edges represented implicitly in basic block BB to BUFFER, indented
2283 by INDENT spaces, with details given by FLAGS. */
2286 dump_implicit_edges (pretty_printer
*buffer
, basic_block bb
, int indent
,
2292 /* If there is a fallthru edge, we may need to add an artificial goto to the
2294 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
2295 if (e
->flags
& EDGE_FALLTHRU
)
2297 if (e
&& e
->dest
!= bb
->next_bb
)
2301 if ((flags
& TDF_LINENO
)
2302 #ifdef USE_MAPPED_LOCATION
2303 && e
->goto_locus
!= UNKNOWN_LOCATION
2309 expanded_location goto_xloc
;
2310 #ifdef USE_MAPPED_LOCATION
2311 goto_xloc
= expand_location (e
->goto_locus
);
2313 goto_xloc
= *e
->goto_locus
;
2315 pp_character (buffer
, '[');
2318 pp_string (buffer
, goto_xloc
.file
);
2319 pp_string (buffer
, " : ");
2321 pp_decimal_int (buffer
, goto_xloc
.line
);
2322 pp_string (buffer
, "] ");
2325 pp_cfg_jump (buffer
, e
->dest
);
2326 pp_newline (buffer
);
2330 /* Dumps basic block BB to buffer BUFFER with details described by FLAGS and
2331 indented by INDENT spaces. */
2334 dump_generic_bb_buff (pretty_printer
*buffer
, basic_block bb
,
2335 int indent
, int flags
)
2337 block_stmt_iterator bsi
;
2339 int label_indent
= indent
- 2;
2341 if (label_indent
< 0)
2344 dump_bb_header (buffer
, bb
, indent
, flags
);
2347 dump_phi_nodes (buffer
, bb
, indent
, flags
);
2349 for (bsi
= bsi_start (bb
); !bsi_end_p (bsi
); bsi_next (&bsi
))
2353 stmt
= bsi_stmt (bsi
);
2355 curr_indent
= TREE_CODE (stmt
) == LABEL_EXPR
? label_indent
: indent
;
2357 INDENT (curr_indent
);
2358 dump_generic_node (buffer
, stmt
, curr_indent
, flags
, true);
2359 pp_newline (buffer
);
2362 dump_implicit_edges (buffer
, bb
, indent
, flags
);
2364 if (flags
& TDF_BLOCKS
)
2365 dump_bb_end (buffer
, bb
, indent
, flags
);