1 /* Pretty formatting of GENERIC trees in C syntax.
2 Copyright (C) 2001, 2002, 2003, 2004, 2005 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
= TREE_CODE_LENGTH (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 domain associated with an array. */
223 dump_array_domain (pretty_printer
*buffer
, tree domain
, int spc
, int flags
)
225 pp_character (buffer
, '[');
228 tree min
= TYPE_MIN_VALUE (domain
);
229 tree max
= TYPE_MAX_VALUE (domain
);
232 && integer_zerop (min
)
233 && host_integerp (max
, 0))
234 pp_wide_integer (buffer
, TREE_INT_CST_LOW (max
) + 1);
238 dump_generic_node (buffer
, min
, spc
, flags
, false);
239 pp_character (buffer
, ':');
241 dump_generic_node (buffer
, max
, spc
, flags
, false);
245 pp_string (buffer
, "<unknown>");
246 pp_character (buffer
, ']');
249 /* Dump the node NODE on the pretty_printer BUFFER, SPC spaces of indent.
250 FLAGS specifies details to show in the dump (see TDF_* in tree.h). If
251 IS_STMT is true, the object printed is considered to be a statement
252 and it is terminated by ';' if appropriate. */
255 dump_generic_node (pretty_printer
*buffer
, tree node
, int spc
, int flags
,
263 if (node
== NULL_TREE
)
266 is_expr
= EXPR_P (node
);
268 if (TREE_CODE (node
) != ERROR_MARK
269 && is_gimple_stmt (node
)
270 && (flags
& TDF_VOPS
)
272 dump_vops (buffer
, node
, spc
, flags
);
274 if (is_stmt
&& (flags
& TDF_STMTADDR
))
275 pp_printf (buffer
, "<&%p> ", (void *)node
);
278 && (flags
& TDF_LINENO
)
279 && EXPR_HAS_LOCATION (node
))
281 expanded_location xloc
= expand_location (EXPR_LOCATION (node
));
282 pp_character (buffer
, '[');
285 pp_string (buffer
, xloc
.file
);
286 pp_string (buffer
, " : ");
288 pp_decimal_int (buffer
, xloc
.line
);
289 pp_string (buffer
, "] ");
292 switch (TREE_CODE (node
))
295 pp_string (buffer
, "<<< error >>>");
298 case IDENTIFIER_NODE
:
299 pp_tree_identifier (buffer
, node
);
303 while (node
&& node
!= error_mark_node
)
305 if (TREE_PURPOSE (node
))
307 dump_generic_node (buffer
, TREE_PURPOSE (node
), spc
, flags
, false);
310 dump_generic_node (buffer
, TREE_VALUE (node
), spc
, flags
, false);
311 node
= TREE_CHAIN (node
);
312 if (node
&& TREE_CODE (node
) == TREE_LIST
)
314 pp_character (buffer
, ',');
321 dump_generic_node (buffer
, BINFO_TYPE (node
), spc
, flags
, false);
326 if (TREE_VEC_LENGTH (node
) > 0)
328 size_t len
= TREE_VEC_LENGTH (node
);
329 for (i
= 0; i
< len
- 1; i
++)
331 dump_generic_node (buffer
, TREE_VEC_ELT (node
, i
), spc
, flags
,
333 pp_character (buffer
, ',');
336 dump_generic_node (buffer
, TREE_VEC_ELT (node
, len
- 1), spc
,
355 unsigned int quals
= TYPE_QUALS (node
);
356 enum tree_code_class
class;
358 if (quals
& TYPE_QUAL_CONST
)
359 pp_string (buffer
, "const ");
360 else if (quals
& TYPE_QUAL_VOLATILE
)
361 pp_string (buffer
, "volatile ");
362 else if (quals
& TYPE_QUAL_RESTRICT
)
363 pp_string (buffer
, "restrict ");
365 class = TREE_CODE_CLASS (TREE_CODE (node
));
367 if (class == tcc_declaration
)
369 if (DECL_NAME (node
))
370 dump_decl_name (buffer
, node
, flags
);
372 pp_string (buffer
, "<unnamed type decl>");
374 else if (class == tcc_type
)
376 if (TYPE_NAME (node
))
378 if (TREE_CODE (TYPE_NAME (node
)) == IDENTIFIER_NODE
)
379 pp_tree_identifier (buffer
, TYPE_NAME (node
));
380 else if (TREE_CODE (TYPE_NAME (node
)) == TYPE_DECL
381 && DECL_NAME (TYPE_NAME (node
)))
382 dump_decl_name (buffer
, TYPE_NAME (node
), flags
);
384 pp_string (buffer
, "<unnamed type>");
386 else if (TREE_CODE (node
) == VECTOR_TYPE
)
388 pp_string (buffer
, "vector ");
389 dump_generic_node (buffer
, TREE_TYPE (node
),
393 pp_string (buffer
, "<unnamed type>");
400 str
= (TREE_CODE (node
) == POINTER_TYPE
? "*" : "&");
402 if (TREE_CODE (TREE_TYPE (node
)) == FUNCTION_TYPE
)
404 tree fnode
= TREE_TYPE (node
);
406 dump_generic_node (buffer
, TREE_TYPE (fnode
), spc
, flags
, false);
408 pp_character (buffer
, '(');
409 pp_string (buffer
, str
);
410 if (TYPE_NAME (node
) && DECL_NAME (TYPE_NAME (node
)))
411 dump_decl_name (buffer
, TYPE_NAME (node
), flags
);
413 pp_printf (buffer
, "<T%x>", TYPE_UID (node
));
415 pp_character (buffer
, ')');
416 dump_function_declaration (buffer
, fnode
, spc
, flags
);
420 unsigned int quals
= TYPE_QUALS (node
);
422 dump_generic_node (buffer
, TREE_TYPE (node
), spc
, flags
, false);
424 pp_string (buffer
, str
);
426 if (quals
& TYPE_QUAL_CONST
)
427 pp_string (buffer
, " const");
428 else if (quals
& TYPE_QUAL_VOLATILE
)
429 pp_string (buffer
, "volatile");
430 else if (quals
& TYPE_QUAL_RESTRICT
)
431 pp_string (buffer
, " restrict");
433 if (TYPE_REF_CAN_ALIAS_ALL (node
))
434 pp_string (buffer
, " {ref-all}");
443 dump_decl_name (buffer
, TYPE_NAME (TYPE_METHOD_BASETYPE (node
)), flags
);
444 pp_string (buffer
, "::");
451 /* Print the innermost component type. */
452 for (tmp
= TREE_TYPE (node
); TREE_CODE (tmp
) == ARRAY_TYPE
;
453 tmp
= TREE_TYPE (tmp
))
455 dump_generic_node (buffer
, tmp
, spc
, flags
, false);
457 /* Print the dimensions. */
458 for (tmp
= node
; TREE_CODE (tmp
) == ARRAY_TYPE
; tmp
= TREE_TYPE (tmp
))
459 dump_array_domain (buffer
, TYPE_DOMAIN (tmp
), spc
, flags
);
465 case QUAL_UNION_TYPE
:
466 /* Print the name of the structure. */
467 if (TREE_CODE (node
) == RECORD_TYPE
)
468 pp_string (buffer
, "struct ");
469 else if (TREE_CODE (node
) == UNION_TYPE
)
470 pp_string (buffer
, "union ");
472 if (TYPE_NAME (node
))
473 dump_generic_node (buffer
, TYPE_NAME (node
), spc
, flags
, false);
475 print_struct_decl (buffer
, node
, spc
, flags
);
483 if (TREE_CODE (TREE_TYPE (node
)) == POINTER_TYPE
)
485 /* In the case of a pointer, one may want to divide by the
486 size of the pointed-to type. Unfortunately, this not
487 straightforward. The C front-end maps expressions
492 in such a way that the two INTEGER_CST nodes for "5" have
493 different values but identical types. In the latter
494 case, the 5 is multiplied by sizeof (int) in c-common.c
495 (pointer_int_sum) to convert it to a byte address, and
496 yet the type of the node is left unchanged. Argh. What
497 is consistent though is that the number value corresponds
498 to bytes (UNITS) offset.
500 NB: Neither of the following divisors can be trivially
501 used to recover the original literal:
503 TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (node)))
504 TYPE_PRECISION (TREE_TYPE (TREE_TYPE (node))) */
505 pp_wide_integer (buffer
, TREE_INT_CST_LOW (node
));
506 pp_string (buffer
, "B"); /* pseudo-unit */
508 else if (! host_integerp (node
, 0))
512 if (tree_int_cst_sgn (val
) < 0)
514 pp_character (buffer
, '-');
515 val
= build_int_cst_wide (NULL_TREE
,
516 -TREE_INT_CST_LOW (val
),
517 ~TREE_INT_CST_HIGH (val
)
518 + !TREE_INT_CST_LOW (val
));
520 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
523 static char format
[10]; /* "%x%09999x\0" */
525 sprintf (format
, "%%x%%0%dx", HOST_BITS_PER_INT
/ 4);
526 sprintf (pp_buffer (buffer
)->digit_buffer
, format
,
527 TREE_INT_CST_HIGH (val
),
528 TREE_INT_CST_LOW (val
));
529 pp_string (buffer
, pp_buffer (buffer
)->digit_buffer
);
533 pp_wide_integer (buffer
, TREE_INT_CST_LOW (node
));
537 /* Code copied from print_node. */
540 if (TREE_OVERFLOW (node
))
541 pp_string (buffer
, " overflow");
543 #if !defined(REAL_IS_NOT_DOUBLE) || defined(REAL_ARITHMETIC)
544 d
= TREE_REAL_CST (node
);
545 if (REAL_VALUE_ISINF (d
))
546 pp_string (buffer
, " Inf");
547 else if (REAL_VALUE_ISNAN (d
))
548 pp_string (buffer
, " Nan");
552 real_to_decimal (string
, &d
, sizeof (string
), 0, 1);
553 pp_string (buffer
, string
);
558 unsigned char *p
= (unsigned char *) &TREE_REAL_CST (node
);
559 pp_string (buffer
, "0x");
560 for (i
= 0; i
< sizeof TREE_REAL_CST (node
); i
++)
561 output_formatted_integer (buffer
, "%02x", *p
++);
568 pp_string (buffer
, "__complex__ (");
569 dump_generic_node (buffer
, TREE_REALPART (node
), spc
, flags
, false);
570 pp_string (buffer
, ", ");
571 dump_generic_node (buffer
, TREE_IMAGPART (node
), spc
, flags
, false);
572 pp_string (buffer
, ")");
576 pp_string (buffer
, "\"");
577 pretty_print_string (buffer
, TREE_STRING_POINTER (node
));
578 pp_string (buffer
, "\"");
584 pp_string (buffer
, "{ ");
585 for (elt
= TREE_VECTOR_CST_ELTS (node
); elt
; elt
= TREE_CHAIN (elt
))
587 dump_generic_node (buffer
, TREE_VALUE (elt
), spc
, flags
, false);
588 if (TREE_CHAIN (elt
))
589 pp_string (buffer
, ", ");
591 pp_string (buffer
, " }");
600 dump_decl_name (buffer
, node
, flags
);
604 if (DECL_NAME (node
))
605 dump_decl_name (buffer
, node
, flags
);
606 else if (LABEL_DECL_UID (node
) != -1)
607 pp_printf (buffer
, "<L" HOST_WIDE_INT_PRINT_DEC
">",
608 LABEL_DECL_UID (node
));
610 pp_printf (buffer
, "<D%u>", DECL_UID (node
));
614 if (DECL_IS_BUILTIN (node
))
616 /* Don't print the declaration of built-in types. */
619 if (DECL_NAME (node
))
620 dump_decl_name (buffer
, node
, flags
);
623 if ((TREE_CODE (TREE_TYPE (node
)) == RECORD_TYPE
624 || TREE_CODE (TREE_TYPE (node
)) == UNION_TYPE
)
625 && TYPE_METHODS (TREE_TYPE (node
)))
627 /* The type is a c++ class: all structures have at least
629 pp_string (buffer
, "class ");
630 dump_generic_node (buffer
, TREE_TYPE (node
), spc
, flags
, false);
635 (TREE_CODE (TREE_TYPE (node
)) == UNION_TYPE
636 ? "union" : "struct "));
637 dump_generic_node (buffer
, TREE_TYPE (node
), spc
, flags
, false);
646 dump_decl_name (buffer
, node
, flags
);
650 pp_string (buffer
, "<retval>");
654 op0
= TREE_OPERAND (node
, 0);
656 if (TREE_CODE (op0
) == INDIRECT_REF
)
658 op0
= TREE_OPERAND (op0
, 0);
661 if (op_prio (op0
) < op_prio (node
))
662 pp_character (buffer
, '(');
663 dump_generic_node (buffer
, op0
, spc
, flags
, false);
664 if (op_prio (op0
) < op_prio (node
))
665 pp_character (buffer
, ')');
666 pp_string (buffer
, str
);
667 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
669 if (TREE_CODE (op0
) != VALUE_HANDLE
)
671 op0
= component_ref_field_offset (node
);
672 if (op0
&& TREE_CODE (op0
) != INTEGER_CST
)
674 pp_string (buffer
, "{off: ");
675 dump_generic_node (buffer
, op0
, spc
, flags
, false);
676 pp_character (buffer
, '}');
682 pp_string (buffer
, "BIT_FIELD_REF <");
683 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
684 pp_string (buffer
, ", ");
685 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
686 pp_string (buffer
, ", ");
687 dump_generic_node (buffer
, TREE_OPERAND (node
, 2), spc
, flags
, false);
688 pp_string (buffer
, ">");
692 case ARRAY_RANGE_REF
:
693 op0
= TREE_OPERAND (node
, 0);
694 if (op_prio (op0
) < op_prio (node
))
695 pp_character (buffer
, '(');
696 dump_generic_node (buffer
, op0
, spc
, flags
, false);
697 if (op_prio (op0
) < op_prio (node
))
698 pp_character (buffer
, ')');
699 pp_character (buffer
, '[');
700 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
701 if (TREE_CODE (node
) == ARRAY_RANGE_REF
)
702 pp_string (buffer
, " ...");
703 pp_character (buffer
, ']');
705 op0
= array_ref_low_bound (node
);
706 op1
= array_ref_element_size (node
);
708 if (!integer_zerop (op0
)
709 || (TYPE_SIZE_UNIT (TREE_TYPE (node
))
710 && !operand_equal_p (op1
, TYPE_SIZE_UNIT (TREE_TYPE (node
)), 0)))
712 pp_string (buffer
, "{lb: ");
713 dump_generic_node (buffer
, op0
, spc
, flags
, false);
714 pp_string (buffer
, " sz: ");
715 dump_generic_node (buffer
, op1
, spc
, flags
, false);
716 pp_character (buffer
, '}');
723 bool is_struct_init
= FALSE
;
724 pp_character (buffer
, '{');
725 lnode
= CONSTRUCTOR_ELTS (node
);
726 if (TREE_CODE (TREE_TYPE (node
)) == RECORD_TYPE
727 || TREE_CODE (TREE_TYPE (node
)) == UNION_TYPE
)
728 is_struct_init
= TRUE
;
729 while (lnode
&& lnode
!= error_mark_node
)
732 if (TREE_PURPOSE (lnode
) && is_struct_init
)
734 pp_character (buffer
, '.');
735 dump_generic_node (buffer
, TREE_PURPOSE (lnode
), spc
, flags
, false);
736 pp_string (buffer
, "=");
738 val
= TREE_VALUE (lnode
);
739 if (val
&& TREE_CODE (val
) == ADDR_EXPR
)
740 if (TREE_CODE (TREE_OPERAND (val
, 0)) == FUNCTION_DECL
)
741 val
= TREE_OPERAND (val
, 0);
742 if (val
&& TREE_CODE (val
) == FUNCTION_DECL
)
744 dump_decl_name (buffer
, val
, flags
);
748 dump_generic_node (buffer
, TREE_VALUE (lnode
), spc
, flags
, false);
750 lnode
= TREE_CHAIN (lnode
);
751 if (lnode
&& TREE_CODE (lnode
) == TREE_LIST
)
753 pp_character (buffer
, ',');
757 pp_character (buffer
, '}');
764 if (flags
& TDF_SLIM
)
766 pp_string (buffer
, "<COMPOUND_EXPR>");
770 dump_generic_node (buffer
, TREE_OPERAND (node
, 0),
771 spc
, flags
, dumping_stmts
);
773 newline_and_indent (buffer
, spc
);
776 pp_character (buffer
, ',');
780 for (tp
= &TREE_OPERAND (node
, 1);
781 TREE_CODE (*tp
) == COMPOUND_EXPR
;
782 tp
= &TREE_OPERAND (*tp
, 1))
784 dump_generic_node (buffer
, TREE_OPERAND (*tp
, 0),
785 spc
, flags
, dumping_stmts
);
787 newline_and_indent (buffer
, spc
);
790 pp_character (buffer
, ',');
795 dump_generic_node (buffer
, *tp
, spc
, flags
, dumping_stmts
);
801 tree_stmt_iterator si
;
804 if ((flags
& TDF_SLIM
) || !dumping_stmts
)
806 pp_string (buffer
, "<STATEMENT_LIST>");
810 for (si
= tsi_start (node
); !tsi_end_p (si
); tsi_next (&si
))
813 newline_and_indent (buffer
, spc
);
816 dump_generic_node (buffer
, tsi_stmt (si
), spc
, flags
, true);
823 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
825 pp_character (buffer
, '=');
827 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
831 pp_string (buffer
, "TARGET_EXPR <");
832 dump_generic_node (buffer
, TARGET_EXPR_SLOT (node
), spc
, flags
, false);
833 pp_character (buffer
, ',');
835 dump_generic_node (buffer
, TARGET_EXPR_INITIAL (node
), spc
, flags
, false);
836 pp_character (buffer
, '>');
840 print_declaration (buffer
, DECL_EXPR_DECL (node
), spc
, flags
);
845 if (TREE_TYPE (node
) == NULL
|| TREE_TYPE (node
) == void_type_node
)
847 pp_string (buffer
, "if (");
848 dump_generic_node (buffer
, COND_EXPR_COND (node
), spc
, flags
, false);
849 pp_character (buffer
, ')');
850 /* The lowered cond_exprs should always be printed in full. */
851 if (COND_EXPR_THEN (node
)
852 && (IS_EMPTY_STMT (COND_EXPR_THEN (node
))
853 || TREE_CODE (COND_EXPR_THEN (node
)) == GOTO_EXPR
)
854 && COND_EXPR_ELSE (node
)
855 && (IS_EMPTY_STMT (COND_EXPR_ELSE (node
))
856 || TREE_CODE (COND_EXPR_ELSE (node
)) == GOTO_EXPR
))
859 dump_generic_node (buffer
, COND_EXPR_THEN (node
), 0, flags
, true);
860 pp_string (buffer
, " else ");
861 dump_generic_node (buffer
, COND_EXPR_ELSE (node
), 0, flags
, true);
863 else if (!(flags
& TDF_SLIM
))
865 /* Output COND_EXPR_THEN. */
866 if (COND_EXPR_THEN (node
))
868 newline_and_indent (buffer
, spc
+2);
869 pp_character (buffer
, '{');
870 newline_and_indent (buffer
, spc
+4);
871 dump_generic_node (buffer
, COND_EXPR_THEN (node
), spc
+4,
873 newline_and_indent (buffer
, spc
+2);
874 pp_character (buffer
, '}');
877 /* Output COND_EXPR_ELSE. */
878 if (COND_EXPR_ELSE (node
))
880 newline_and_indent (buffer
, spc
);
881 pp_string (buffer
, "else");
882 newline_and_indent (buffer
, spc
+2);
883 pp_character (buffer
, '{');
884 newline_and_indent (buffer
, spc
+4);
885 dump_generic_node (buffer
, COND_EXPR_ELSE (node
), spc
+4,
887 newline_and_indent (buffer
, spc
+2);
888 pp_character (buffer
, '}');
895 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
897 pp_character (buffer
, '?');
899 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
901 pp_character (buffer
, ':');
903 dump_generic_node (buffer
, TREE_OPERAND (node
, 2), spc
, flags
, false);
908 pp_character (buffer
, '{');
909 if (!(flags
& TDF_SLIM
))
911 if (BIND_EXPR_VARS (node
))
915 for (op0
= BIND_EXPR_VARS (node
); op0
; op0
= TREE_CHAIN (op0
))
917 print_declaration (buffer
, op0
, spc
+2, flags
);
922 newline_and_indent (buffer
, spc
+2);
923 dump_generic_node (buffer
, BIND_EXPR_BODY (node
), spc
+2, flags
, true);
924 newline_and_indent (buffer
, spc
);
925 pp_character (buffer
, '}');
931 print_call_name (buffer
, node
);
933 /* Print parameters. */
935 pp_character (buffer
, '(');
936 op1
= TREE_OPERAND (node
, 1);
938 dump_generic_node (buffer
, op1
, spc
, flags
, false);
939 pp_character (buffer
, ')');
941 op1
= TREE_OPERAND (node
, 2);
944 pp_string (buffer
, " [static-chain: ");
945 dump_generic_node (buffer
, op1
, spc
, flags
, false);
946 pp_character (buffer
, ']');
949 if (CALL_EXPR_HAS_RETURN_SLOT_ADDR (node
))
950 pp_string (buffer
, " [return slot addr]");
951 if (CALL_EXPR_TAILCALL (node
))
952 pp_string (buffer
, " [tail call]");
955 case WITH_CLEANUP_EXPR
:
959 case CLEANUP_POINT_EXPR
:
960 pp_string (buffer
, "<<cleanup_point ");
961 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
962 pp_string (buffer
, ">>");
965 case PLACEHOLDER_EXPR
:
966 pp_string (buffer
, "<PLACEHOLDER_EXPR ");
967 dump_generic_node (buffer
, TREE_TYPE (node
), spc
, flags
, false);
968 pp_character (buffer
, '>');
971 /* Binary arithmetic and logic expressions. */
992 case TRUTH_ANDIF_EXPR
:
993 case TRUTH_ORIF_EXPR
:
1010 case UNORDERED_EXPR
:
1012 const char *op
= op_symbol (node
);
1013 op0
= TREE_OPERAND (node
, 0);
1014 op1
= TREE_OPERAND (node
, 1);
1016 /* When the operands are expressions with less priority,
1017 keep semantics of the tree representation. */
1018 if (op_prio (op0
) < op_prio (node
))
1020 pp_character (buffer
, '(');
1021 dump_generic_node (buffer
, op0
, spc
, flags
, false);
1022 pp_character (buffer
, ')');
1025 dump_generic_node (buffer
, op0
, spc
, flags
, false);
1028 pp_string (buffer
, op
);
1031 /* When the operands are expressions with less priority,
1032 keep semantics of the tree representation. */
1033 if (op_prio (op1
) < op_prio (node
))
1035 pp_character (buffer
, '(');
1036 dump_generic_node (buffer
, op1
, spc
, flags
, false);
1037 pp_character (buffer
, ')');
1040 dump_generic_node (buffer
, op1
, spc
, flags
, false);
1044 /* Unary arithmetic and logic expressions. */
1047 case TRUTH_NOT_EXPR
:
1049 case PREDECREMENT_EXPR
:
1050 case PREINCREMENT_EXPR
:
1051 case ALIGN_INDIRECT_REF
:
1052 case MISALIGNED_INDIRECT_REF
:
1054 if (TREE_CODE (node
) == ADDR_EXPR
1055 && (TREE_CODE (TREE_OPERAND (node
, 0)) == STRING_CST
1056 || TREE_CODE (TREE_OPERAND (node
, 0)) == FUNCTION_DECL
))
1057 ; /* Do not output '&' for strings and function pointers. */
1059 pp_string (buffer
, op_symbol (node
));
1061 if (op_prio (TREE_OPERAND (node
, 0)) < op_prio (node
))
1063 pp_character (buffer
, '(');
1064 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1065 pp_character (buffer
, ')');
1068 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1070 if (TREE_CODE (node
) == MISALIGNED_INDIRECT_REF
)
1072 pp_string (buffer
, "{misalignment: ");
1073 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
1074 pp_character (buffer
, '}');
1078 case POSTDECREMENT_EXPR
:
1079 case POSTINCREMENT_EXPR
:
1080 if (op_prio (TREE_OPERAND (node
, 0)) < op_prio (node
))
1082 pp_character (buffer
, '(');
1083 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1084 pp_character (buffer
, ')');
1087 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1088 pp_string (buffer
, op_symbol (node
));
1092 pp_string (buffer
, "MIN_EXPR <");
1093 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1094 pp_string (buffer
, ", ");
1095 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
1096 pp_character (buffer
, '>');
1100 pp_string (buffer
, "MAX_EXPR <");
1101 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1102 pp_string (buffer
, ", ");
1103 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
1104 pp_character (buffer
, '>');
1108 pp_string (buffer
, "ABS_EXPR <");
1109 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1110 pp_character (buffer
, '>');
1117 case FIX_TRUNC_EXPR
:
1119 case FIX_FLOOR_EXPR
:
1120 case FIX_ROUND_EXPR
:
1124 type
= TREE_TYPE (node
);
1125 op0
= TREE_OPERAND (node
, 0);
1126 if (type
!= TREE_TYPE (op0
))
1128 pp_character (buffer
, '(');
1129 dump_generic_node (buffer
, type
, spc
, flags
, false);
1130 pp_string (buffer
, ") ");
1132 if (op_prio (op0
) < op_prio (node
))
1133 pp_character (buffer
, '(');
1134 dump_generic_node (buffer
, op0
, spc
, flags
, false);
1135 if (op_prio (op0
) < op_prio (node
))
1136 pp_character (buffer
, ')');
1139 case VIEW_CONVERT_EXPR
:
1140 pp_string (buffer
, "VIEW_CONVERT_EXPR<");
1141 dump_generic_node (buffer
, TREE_TYPE (node
), spc
, flags
, false);
1142 pp_string (buffer
, ">(");
1143 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1144 pp_character (buffer
, ')');
1147 case NON_LVALUE_EXPR
:
1148 pp_string (buffer
, "NON_LVALUE_EXPR <");
1149 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1150 pp_character (buffer
, '>');
1154 pp_string (buffer
, "SAVE_EXPR <");
1155 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1156 pp_character (buffer
, '>');
1160 pp_string (buffer
, "COMPLEX_EXPR <");
1161 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1162 pp_string (buffer
, ", ");
1163 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
1164 pp_string (buffer
, ">");
1168 pp_string (buffer
, "CONJ_EXPR <");
1169 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1170 pp_string (buffer
, ">");
1174 pp_string (buffer
, "REALPART_EXPR <");
1175 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1176 pp_string (buffer
, ">");
1180 pp_string (buffer
, "IMAGPART_EXPR <");
1181 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1182 pp_string (buffer
, ">");
1186 pp_string (buffer
, "VA_ARG_EXPR <");
1187 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1188 pp_string (buffer
, ">");
1191 case TRY_FINALLY_EXPR
:
1192 case TRY_CATCH_EXPR
:
1193 pp_string (buffer
, "try");
1194 newline_and_indent (buffer
, spc
+2);
1195 pp_string (buffer
, "{");
1196 newline_and_indent (buffer
, spc
+4);
1197 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
+4, flags
, true);
1198 newline_and_indent (buffer
, spc
+2);
1199 pp_string (buffer
, "}");
1200 newline_and_indent (buffer
, spc
);
1202 (TREE_CODE (node
) == TRY_CATCH_EXPR
) ? "catch" : "finally");
1203 newline_and_indent (buffer
, spc
+2);
1204 pp_string (buffer
, "{");
1205 newline_and_indent (buffer
, spc
+4);
1206 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
+4, flags
, true);
1207 newline_and_indent (buffer
, spc
+2);
1208 pp_string (buffer
, "}");
1213 pp_string (buffer
, "catch (");
1214 dump_generic_node (buffer
, CATCH_TYPES (node
), spc
+2, flags
, false);
1215 pp_string (buffer
, ")");
1216 newline_and_indent (buffer
, spc
+2);
1217 pp_string (buffer
, "{");
1218 newline_and_indent (buffer
, spc
+4);
1219 dump_generic_node (buffer
, CATCH_BODY (node
), spc
+4, flags
, true);
1220 newline_and_indent (buffer
, spc
+2);
1221 pp_string (buffer
, "}");
1225 case EH_FILTER_EXPR
:
1226 pp_string (buffer
, "<<<eh_filter (");
1227 dump_generic_node (buffer
, EH_FILTER_TYPES (node
), spc
+2, flags
, false);
1228 pp_string (buffer
, ")>>>");
1229 newline_and_indent (buffer
, spc
+2);
1230 pp_string (buffer
, "{");
1231 newline_and_indent (buffer
, spc
+4);
1232 dump_generic_node (buffer
, EH_FILTER_FAILURE (node
), spc
+4, flags
, true);
1233 newline_and_indent (buffer
, spc
+2);
1234 pp_string (buffer
, "}");
1239 op0
= TREE_OPERAND (node
, 0);
1240 /* If this is for break or continue, don't bother printing it. */
1241 if (DECL_NAME (op0
))
1243 const char *name
= IDENTIFIER_POINTER (DECL_NAME (op0
));
1244 if (strcmp (name
, "break") == 0
1245 || strcmp (name
, "continue") == 0)
1248 dump_generic_node (buffer
, op0
, spc
, flags
, false);
1249 pp_character (buffer
, ':');
1250 if (DECL_NONLOCAL (op0
))
1251 pp_string (buffer
, " [non-local]");
1255 pp_string (buffer
, "<<<exception object>>>");
1259 pp_string (buffer
, "<<<filter object>>>");
1263 pp_string (buffer
, "while (1)");
1264 if (!(flags
& TDF_SLIM
))
1266 newline_and_indent (buffer
, spc
+2);
1267 pp_character (buffer
, '{');
1268 newline_and_indent (buffer
, spc
+4);
1269 dump_generic_node (buffer
, LOOP_EXPR_BODY (node
), spc
+4, flags
, true);
1270 newline_and_indent (buffer
, spc
+2);
1271 pp_character (buffer
, '}');
1277 pp_string (buffer
, "return");
1278 op0
= TREE_OPERAND (node
, 0);
1282 if (TREE_CODE (op0
) == MODIFY_EXPR
)
1283 dump_generic_node (buffer
, TREE_OPERAND (op0
, 1), spc
, flags
, false);
1285 dump_generic_node (buffer
, op0
, spc
, flags
, false);
1290 pp_string (buffer
, "if (");
1291 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1292 pp_string (buffer
, ") break");
1296 pp_string (buffer
, "switch (");
1297 dump_generic_node (buffer
, SWITCH_COND (node
), spc
, flags
, false);
1298 pp_character (buffer
, ')');
1299 if (!(flags
& TDF_SLIM
))
1301 newline_and_indent (buffer
, spc
+2);
1302 pp_character (buffer
, '{');
1303 if (SWITCH_BODY (node
))
1305 newline_and_indent (buffer
, spc
+4);
1306 dump_generic_node (buffer
, SWITCH_BODY (node
), spc
+4, flags
, true);
1310 tree vec
= SWITCH_LABELS (node
);
1311 size_t i
, n
= TREE_VEC_LENGTH (vec
);
1312 for (i
= 0; i
< n
; ++i
)
1314 tree elt
= TREE_VEC_ELT (vec
, i
);
1315 newline_and_indent (buffer
, spc
+4);
1316 dump_generic_node (buffer
, elt
, spc
+4, flags
, false);
1317 pp_string (buffer
, " goto ");
1318 dump_generic_node (buffer
, CASE_LABEL (elt
), spc
+4, flags
, true);
1319 pp_semicolon (buffer
);
1322 newline_and_indent (buffer
, spc
+2);
1323 pp_character (buffer
, '}');
1329 op0
= GOTO_DESTINATION (node
);
1330 if (TREE_CODE (op0
) != SSA_NAME
&& DECL_P (op0
) && DECL_NAME (op0
))
1332 const char *name
= IDENTIFIER_POINTER (DECL_NAME (op0
));
1333 if (strcmp (name
, "break") == 0
1334 || strcmp (name
, "continue") == 0)
1336 pp_string (buffer
, name
);
1340 pp_string (buffer
, "goto ");
1341 dump_generic_node (buffer
, op0
, spc
, flags
, false);
1345 pp_string (buffer
, "resx");
1346 /* ??? Any sensible way to present the eh region? */
1350 pp_string (buffer
, "__asm__");
1351 if (ASM_VOLATILE_P (node
))
1352 pp_string (buffer
, " __volatile__");
1353 pp_character (buffer
, '(');
1354 dump_generic_node (buffer
, ASM_STRING (node
), spc
, flags
, false);
1355 pp_character (buffer
, ':');
1356 dump_generic_node (buffer
, ASM_OUTPUTS (node
), spc
, flags
, false);
1357 pp_character (buffer
, ':');
1358 dump_generic_node (buffer
, ASM_INPUTS (node
), spc
, flags
, false);
1359 if (ASM_CLOBBERS (node
))
1361 pp_character (buffer
, ':');
1362 dump_generic_node (buffer
, ASM_CLOBBERS (node
), spc
, flags
, false);
1364 pp_string (buffer
, ")");
1367 case CASE_LABEL_EXPR
:
1368 if (CASE_LOW (node
) && CASE_HIGH (node
))
1370 pp_string (buffer
, "case ");
1371 dump_generic_node (buffer
, CASE_LOW (node
), spc
, flags
, false);
1372 pp_string (buffer
, " ... ");
1373 dump_generic_node (buffer
, CASE_HIGH (node
), spc
, flags
, false);
1375 else if (CASE_LOW (node
))
1377 pp_string (buffer
, "case ");
1378 dump_generic_node (buffer
, CASE_LOW (node
), spc
, flags
, false);
1381 pp_string (buffer
, "default ");
1382 pp_character (buffer
, ':');
1386 pp_string (buffer
, "OBJ_TYPE_REF(");
1387 dump_generic_node (buffer
, OBJ_TYPE_REF_EXPR (node
), spc
, flags
, false);
1388 pp_character (buffer
, ';');
1389 dump_generic_node (buffer
, OBJ_TYPE_REF_OBJECT (node
), spc
, flags
, false);
1390 pp_character (buffer
, '-');
1391 pp_character (buffer
, '>');
1392 dump_generic_node (buffer
, OBJ_TYPE_REF_TOKEN (node
), spc
, flags
, false);
1393 pp_character (buffer
, ')');
1400 dump_generic_node (buffer
, PHI_RESULT (node
), spc
, flags
, false);
1401 pp_string (buffer
, " = PHI <");
1402 for (i
= 0; i
< PHI_NUM_ARGS (node
); i
++)
1404 dump_generic_node (buffer
, PHI_ARG_DEF (node
, i
), spc
, flags
, false);
1405 pp_string (buffer
, "(");
1406 pp_decimal_int (buffer
, PHI_ARG_EDGE (node
, i
)->src
->index
);
1407 pp_string (buffer
, ")");
1408 if (i
< PHI_NUM_ARGS (node
) - 1)
1409 pp_string (buffer
, ", ");
1411 pp_string (buffer
, ">;");
1416 dump_generic_node (buffer
, SSA_NAME_VAR (node
), spc
, flags
, false);
1417 pp_string (buffer
, "_");
1418 pp_decimal_int (buffer
, SSA_NAME_VERSION (node
));
1419 if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (node
))
1420 pp_string (buffer
, "(ab)");
1423 case WITH_SIZE_EXPR
:
1424 pp_string (buffer
, "WITH_SIZE_EXPR <");
1425 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1426 pp_string (buffer
, ", ");
1427 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
1428 pp_string (buffer
, ">");
1432 pp_printf (buffer
, "VH.%d", VALUE_HANDLE_ID (node
));
1436 pp_string (buffer
, "ASSERT_EXPR <");
1437 dump_generic_node (buffer
, ASSERT_EXPR_VAR (node
), spc
, flags
, false);
1438 pp_string (buffer
, ", ");
1439 dump_generic_node (buffer
, ASSERT_EXPR_COND (node
), spc
, flags
, false);
1440 pp_string (buffer
, ">");
1444 pp_string (buffer
, "scev_known");
1447 case SCEV_NOT_KNOWN
:
1448 pp_string (buffer
, "scev_not_known");
1451 case POLYNOMIAL_CHREC
:
1452 pp_string (buffer
, "{");
1453 dump_generic_node (buffer
, CHREC_LEFT (node
), spc
, flags
, false);
1454 pp_string (buffer
, ", +, ");
1455 dump_generic_node (buffer
, CHREC_RIGHT (node
), spc
, flags
, false);
1456 pp_string (buffer
, "}_");
1457 dump_generic_node (buffer
, CHREC_VAR (node
), spc
, flags
, false);
1461 case REALIGN_LOAD_EXPR
:
1462 pp_string (buffer
, "REALIGN_LOAD <");
1463 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1464 pp_string (buffer
, ", ");
1465 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
1466 pp_string (buffer
, ", ");
1467 dump_generic_node (buffer
, TREE_OPERAND (node
, 2), spc
, flags
, false);
1468 pp_string (buffer
, ">");
1472 pp_string (buffer
, " VEC_COND_EXPR < ");
1473 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1474 pp_string (buffer
, " , ");
1475 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
1476 pp_string (buffer
, " , ");
1477 dump_generic_node (buffer
, TREE_OPERAND (node
, 2), spc
, flags
, false);
1478 pp_string (buffer
, " > ");
1485 if (is_stmt
&& is_expr
)
1486 pp_semicolon (buffer
);
1487 pp_write_text_to_stream (buffer
);
1492 /* Print the declaration of a variable. */
1495 print_declaration (pretty_printer
*buffer
, tree t
, int spc
, int flags
)
1499 if (TREE_CODE (t
) == TYPE_DECL
)
1500 pp_string (buffer
, "typedef ");
1502 if (DECL_REGISTER (t
))
1503 pp_string (buffer
, "register ");
1505 if (TREE_PUBLIC (t
) && DECL_EXTERNAL (t
))
1506 pp_string (buffer
, "extern ");
1507 else if (TREE_STATIC (t
))
1508 pp_string (buffer
, "static ");
1510 /* Print the type and name. */
1511 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
1515 /* Print array's type. */
1516 tmp
= TREE_TYPE (t
);
1517 while (TREE_CODE (TREE_TYPE (tmp
)) == ARRAY_TYPE
)
1518 tmp
= TREE_TYPE (tmp
);
1519 dump_generic_node (buffer
, TREE_TYPE (tmp
), spc
, flags
, false);
1521 /* Print variable's name. */
1523 dump_generic_node (buffer
, t
, spc
, flags
, false);
1525 /* Print the dimensions. */
1526 tmp
= TREE_TYPE (t
);
1527 while (TREE_CODE (tmp
) == ARRAY_TYPE
)
1529 dump_array_domain (buffer
, TYPE_DOMAIN (tmp
), spc
, flags
);
1530 tmp
= TREE_TYPE (tmp
);
1533 else if (TREE_CODE (t
) == FUNCTION_DECL
)
1535 dump_generic_node (buffer
, TREE_TYPE (TREE_TYPE (t
)), spc
, flags
, false);
1537 dump_decl_name (buffer
, t
, flags
);
1538 dump_function_declaration (buffer
, TREE_TYPE (t
), spc
, flags
);
1542 /* Print type declaration. */
1543 dump_generic_node (buffer
, TREE_TYPE (t
), spc
, flags
, false);
1545 /* Print variable's name. */
1547 dump_generic_node (buffer
, t
, spc
, flags
, false);
1550 if (TREE_CODE (t
) == VAR_DECL
&& DECL_HARD_REGISTER (t
))
1552 pp_string (buffer
, " __asm__ ");
1553 pp_character (buffer
, '(');
1554 dump_generic_node (buffer
, DECL_ASSEMBLER_NAME (t
), spc
, flags
, false);
1555 pp_character (buffer
, ')');
1558 /* The initial value of a function serves to determine wether the function
1559 is declared or defined. So the following does not apply to function
1561 if (TREE_CODE (t
) != FUNCTION_DECL
)
1563 /* Print the initial value. */
1564 if (DECL_INITIAL (t
))
1567 pp_character (buffer
, '=');
1569 dump_generic_node (buffer
, DECL_INITIAL (t
), spc
, flags
, false);
1573 pp_character (buffer
, ';');
1577 /* Prints a structure: name, fields, and methods.
1578 FIXME: Still incomplete. */
1581 print_struct_decl (pretty_printer
*buffer
, tree node
, int spc
, int flags
)
1583 /* Print the name of the structure. */
1584 if (TYPE_NAME (node
))
1587 if (TREE_CODE (node
) == RECORD_TYPE
)
1588 pp_string (buffer
, "struct ");
1589 else if ((TREE_CODE (node
) == UNION_TYPE
1590 || TREE_CODE (node
) == QUAL_UNION_TYPE
))
1591 pp_string (buffer
, "union ");
1593 dump_generic_node (buffer
, TYPE_NAME (node
), spc
, 0, false);
1596 /* Print the contents of the structure. */
1597 pp_newline (buffer
);
1599 pp_character (buffer
, '{');
1600 pp_newline (buffer
);
1602 /* Print the fields of the structure. */
1605 tmp
= TYPE_FIELDS (node
);
1608 /* Avoid to print recursively the structure. */
1609 /* FIXME : Not implemented correctly...,
1610 what about the case when we have a cycle in the contain graph? ...
1611 Maybe this could be solved by looking at the scope in which the
1612 structure was declared. */
1613 if (TREE_TYPE (tmp
) != node
1614 || (TREE_CODE (TREE_TYPE (tmp
)) == POINTER_TYPE
1615 && TREE_TYPE (TREE_TYPE (tmp
)) != node
))
1617 print_declaration (buffer
, tmp
, spc
+2, flags
);
1618 pp_newline (buffer
);
1620 tmp
= TREE_CHAIN (tmp
);
1624 pp_character (buffer
, '}');
1627 /* Return the priority of the operator OP.
1629 From lowest to highest precedence with either left-to-right (L-R)
1630 or right-to-left (R-L) associativity]:
1633 2 [R-L] = += -= *= /= %= &= ^= |= <<= >>=
1645 14 [R-L] ! ~ ++ -- + - * & (type) sizeof
1646 15 [L-R] fn() [] -> .
1648 unary +, - and * have higher precedence than the corresponding binary
1657 switch (TREE_CODE (op
))
1672 case TRUTH_ORIF_EXPR
:
1675 case TRUTH_AND_EXPR
:
1676 case TRUTH_ANDIF_EXPR
:
1683 case TRUTH_XOR_EXPR
:
1700 case UNORDERED_EXPR
:
1718 case TRUNC_DIV_EXPR
:
1720 case FLOOR_DIV_EXPR
:
1721 case ROUND_DIV_EXPR
:
1723 case EXACT_DIV_EXPR
:
1724 case TRUNC_MOD_EXPR
:
1726 case FLOOR_MOD_EXPR
:
1727 case ROUND_MOD_EXPR
:
1730 case TRUTH_NOT_EXPR
:
1732 case POSTINCREMENT_EXPR
:
1733 case POSTDECREMENT_EXPR
:
1734 case PREINCREMENT_EXPR
:
1735 case PREDECREMENT_EXPR
:
1737 case ALIGN_INDIRECT_REF
:
1738 case MISALIGNED_INDIRECT_REF
:
1744 case FIX_TRUNC_EXPR
:
1746 case FIX_FLOOR_EXPR
:
1747 case FIX_ROUND_EXPR
:
1753 case ARRAY_RANGE_REF
:
1757 /* Special expressions. */
1766 case NON_LVALUE_EXPR
:
1767 return op_prio (TREE_OPERAND (op
, 0));
1770 /* Return an arbitrarily high precedence to avoid surrounding single
1771 VAR_DECLs in ()s. */
1777 /* Return the symbol associated with operator OP. */
1784 switch (TREE_CODE (op
))
1790 case TRUTH_ORIF_EXPR
:
1793 case TRUTH_AND_EXPR
:
1794 case TRUTH_ANDIF_EXPR
:
1800 case TRUTH_XOR_EXPR
:
1810 case UNORDERED_EXPR
:
1860 case TRUTH_NOT_EXPR
:
1867 case ALIGN_INDIRECT_REF
:
1870 case MISALIGNED_INDIRECT_REF
:
1873 case TRUNC_DIV_EXPR
:
1880 case FLOOR_DIV_EXPR
:
1883 case ROUND_DIV_EXPR
:
1886 case EXACT_DIV_EXPR
:
1889 case TRUNC_MOD_EXPR
:
1895 case FLOOR_MOD_EXPR
:
1898 case ROUND_MOD_EXPR
:
1901 case PREDECREMENT_EXPR
:
1904 case PREINCREMENT_EXPR
:
1907 case POSTDECREMENT_EXPR
:
1910 case POSTINCREMENT_EXPR
:
1914 return "<<< ??? >>>";
1918 /* Prints the name of a CALL_EXPR. */
1921 print_call_name (pretty_printer
*buffer
, tree node
)
1925 gcc_assert (TREE_CODE (node
) == CALL_EXPR
);
1927 op0
= TREE_OPERAND (node
, 0);
1929 if (TREE_CODE (op0
) == NON_LVALUE_EXPR
)
1930 op0
= TREE_OPERAND (op0
, 0);
1932 switch (TREE_CODE (op0
))
1936 dump_function_name (buffer
, op0
);
1942 dump_generic_node (buffer
, TREE_OPERAND (op0
, 0), 0, 0, false);
1946 pp_string (buffer
, "(");
1947 dump_generic_node (buffer
, TREE_OPERAND (op0
, 0), 0, 0, false);
1948 pp_string (buffer
, ") ? ");
1949 dump_generic_node (buffer
, TREE_OPERAND (op0
, 1), 0, 0, false);
1950 pp_string (buffer
, " : ");
1951 dump_generic_node (buffer
, TREE_OPERAND (op0
, 2), 0, 0, false);
1955 /* The function is a pointer contained in a structure. */
1956 if (TREE_CODE (TREE_OPERAND (op0
, 0)) == INDIRECT_REF
||
1957 TREE_CODE (TREE_OPERAND (op0
, 0)) == VAR_DECL
)
1958 dump_function_name (buffer
, TREE_OPERAND (op0
, 1));
1960 dump_generic_node (buffer
, TREE_OPERAND (op0
, 0), 0, 0, false);
1962 We can have several levels of structures and a function
1963 pointer inside. This is not implemented yet... */
1968 if (TREE_CODE (TREE_OPERAND (op0
, 0)) == VAR_DECL
)
1969 dump_function_name (buffer
, TREE_OPERAND (op0
, 0));
1971 dump_generic_node (buffer
, op0
, 0, 0, false);
1976 dump_generic_node (buffer
, op0
, 0, 0, false);
1984 /* Parses the string STR and replaces new-lines by '\n', tabs by '\t', ... */
1987 pretty_print_string (pretty_printer
*buffer
, const char *str
)
1997 pp_string (buffer
, "\\b");
2001 pp_string (buffer
, "\\f");
2005 pp_string (buffer
, "\\n");
2009 pp_string (buffer
, "\\r");
2013 pp_string (buffer
, "\\t");
2017 pp_string (buffer
, "\\v");
2021 pp_string (buffer
, "\\\\");
2025 pp_string (buffer
, "\\\"");
2029 pp_string (buffer
, "\\'");
2033 pp_string (buffer
, "\\0");
2037 pp_string (buffer
, "\\1");
2041 pp_string (buffer
, "\\2");
2045 pp_string (buffer
, "\\3");
2049 pp_string (buffer
, "\\4");
2053 pp_string (buffer
, "\\5");
2057 pp_string (buffer
, "\\6");
2061 pp_string (buffer
, "\\7");
2065 pp_character (buffer
, str
[0]);
2073 maybe_init_pretty_print (FILE *file
)
2077 pp_construct (&buffer
, /* prefix */NULL
, /* line-width */0);
2078 pp_needs_newline (&buffer
) = true;
2082 buffer
.buffer
->stream
= file
;
2086 newline_and_indent (pretty_printer
*buffer
, int spc
)
2088 pp_newline (buffer
);
2093 dump_vops (pretty_printer
*buffer
, tree stmt
, int spc
, int flags
)
2096 use_operand_p use_p
;
2097 def_operand_p def_p
;
2098 use_operand_p kill_p
;
2101 FOR_EACH_SSA_MAYDEF_OPERAND (def_p
, use_p
, stmt
, iter
)
2103 pp_string (buffer
, "# ");
2104 dump_generic_node (buffer
, DEF_FROM_PTR (def_p
),
2105 spc
+ 2, flags
, false);
2106 pp_string (buffer
, " = V_MAY_DEF <");
2107 dump_generic_node (buffer
, USE_FROM_PTR (use_p
),
2108 spc
+ 2, flags
, false);
2109 pp_string (buffer
, ">;");
2110 newline_and_indent (buffer
, spc
);
2113 FOR_EACH_SSA_MUSTDEF_OPERAND (def_p
, kill_p
, stmt
, iter
)
2115 pp_string (buffer
, "# ");
2116 dump_generic_node (buffer
, DEF_FROM_PTR (def_p
),
2117 spc
+ 2, flags
, false);
2118 pp_string (buffer
, " = V_MUST_DEF <");
2119 dump_generic_node (buffer
, USE_FROM_PTR (kill_p
),
2120 spc
+ 2, flags
, false);
2121 pp_string (buffer
, ">;");
2122 newline_and_indent (buffer
, spc
);
2125 FOR_EACH_SSA_TREE_OPERAND (use
, stmt
, iter
, SSA_OP_VUSE
)
2127 pp_string (buffer
, "# VUSE <");
2128 dump_generic_node (buffer
, use
, spc
+ 2, flags
, false);
2129 pp_string (buffer
, ">;");
2130 newline_and_indent (buffer
, spc
);
2134 /* Dumps basic block BB to FILE with details described by FLAGS and
2135 indented by INDENT spaces. */
2138 dump_generic_bb (FILE *file
, basic_block bb
, int indent
, int flags
)
2140 maybe_init_pretty_print (file
);
2141 dumping_stmts
= true;
2142 dump_generic_bb_buff (&buffer
, bb
, indent
, flags
);
2146 /* Dumps header of basic block BB to buffer BUFFER indented by INDENT
2147 spaces and details described by flags. */
2150 dump_bb_header (pretty_printer
*buffer
, basic_block bb
, int indent
, int flags
)
2156 if (flags
& TDF_BLOCKS
)
2159 pp_string (buffer
, "# BLOCK ");
2160 pp_decimal_int (buffer
, bb
->index
);
2162 if (flags
& TDF_LINENO
)
2164 block_stmt_iterator bsi
;
2166 for (bsi
= bsi_start (bb
); !bsi_end_p (bsi
); bsi_next (&bsi
))
2167 if (get_lineno (bsi_stmt (bsi
)) != -1)
2169 pp_string (buffer
, ", starting at line ");
2170 pp_decimal_int (buffer
, get_lineno (bsi_stmt (bsi
)));
2174 newline_and_indent (buffer
, indent
);
2176 pp_string (buffer
, "# PRED:");
2177 pp_write_text_to_stream (buffer
);
2178 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
2179 if (flags
& TDF_SLIM
)
2181 pp_string (buffer
, " ");
2182 if (e
->src
== ENTRY_BLOCK_PTR
)
2183 pp_string (buffer
, "ENTRY");
2185 pp_decimal_int (buffer
, e
->src
->index
);
2188 dump_edge_info (buffer
->buffer
->stream
, e
, 0);
2189 pp_newline (buffer
);
2193 stmt
= first_stmt (bb
);
2194 if (!stmt
|| TREE_CODE (stmt
) != LABEL_EXPR
)
2196 INDENT (indent
- 2);
2197 pp_string (buffer
, "<bb ");
2198 pp_decimal_int (buffer
, bb
->index
);
2199 pp_string (buffer
, ">:");
2200 pp_newline (buffer
);
2203 pp_write_text_to_stream (buffer
);
2204 check_bb_profile (bb
, buffer
->buffer
->stream
);
2207 /* Dumps end of basic block BB to buffer BUFFER indented by INDENT
2211 dump_bb_end (pretty_printer
*buffer
, basic_block bb
, int indent
, int flags
)
2217 pp_string (buffer
, "# SUCC:");
2218 pp_write_text_to_stream (buffer
);
2219 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
2220 if (flags
& TDF_SLIM
)
2222 pp_string (buffer
, " ");
2223 if (e
->dest
== EXIT_BLOCK_PTR
)
2224 pp_string (buffer
, "EXIT");
2226 pp_decimal_int (buffer
, e
->dest
->index
);
2229 dump_edge_info (buffer
->buffer
->stream
, e
, 1);
2230 pp_newline (buffer
);
2233 /* Dumps phi nodes of basic block BB to buffer BUFFER with details described by
2234 FLAGS indented by INDENT spaces. */
2237 dump_phi_nodes (pretty_printer
*buffer
, basic_block bb
, int indent
, int flags
)
2239 tree phi
= phi_nodes (bb
);
2243 for (; phi
; phi
= PHI_CHAIN (phi
))
2245 if (is_gimple_reg (PHI_RESULT (phi
)) || (flags
& TDF_VOPS
))
2248 pp_string (buffer
, "# ");
2249 dump_generic_node (buffer
, phi
, indent
, flags
, false);
2250 pp_newline (buffer
);
2255 /* Dump jump to basic block BB that is represented implicitly in the cfg
2259 pp_cfg_jump (pretty_printer
*buffer
, basic_block bb
)
2263 stmt
= first_stmt (bb
);
2265 pp_string (buffer
, "goto <bb ");
2266 pp_decimal_int (buffer
, bb
->index
);
2267 pp_string (buffer
, ">");
2268 if (stmt
&& TREE_CODE (stmt
) == LABEL_EXPR
)
2270 pp_string (buffer
, " (");
2271 dump_generic_node (buffer
, LABEL_EXPR_LABEL (stmt
), 0, 0, false);
2272 pp_string (buffer
, ")");
2274 pp_semicolon (buffer
);
2277 /* Dump edges represented implicitly in basic block BB to BUFFER, indented
2278 by INDENT spaces, with details given by FLAGS. */
2281 dump_implicit_edges (pretty_printer
*buffer
, basic_block bb
, int indent
,
2287 /* If there is a fallthru edge, we may need to add an artificial goto to the
2289 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
2290 if (e
->flags
& EDGE_FALLTHRU
)
2292 if (e
&& e
->dest
!= bb
->next_bb
)
2296 if ((flags
& TDF_LINENO
)
2297 #ifdef USE_MAPPED_LOCATION
2298 && e
->goto_locus
!= UNKNOWN_LOCATION
2304 expanded_location goto_xloc
;
2305 #ifdef USE_MAPPED_LOCATION
2306 goto_xloc
= expand_location (e
->goto_locus
);
2308 goto_xloc
= *e
->goto_locus
;
2310 pp_character (buffer
, '[');
2313 pp_string (buffer
, goto_xloc
.file
);
2314 pp_string (buffer
, " : ");
2316 pp_decimal_int (buffer
, goto_xloc
.line
);
2317 pp_string (buffer
, "] ");
2320 pp_cfg_jump (buffer
, e
->dest
);
2321 pp_newline (buffer
);
2325 /* Dumps basic block BB to buffer BUFFER with details described by FLAGS and
2326 indented by INDENT spaces. */
2329 dump_generic_bb_buff (pretty_printer
*buffer
, basic_block bb
,
2330 int indent
, int flags
)
2332 block_stmt_iterator bsi
;
2334 int label_indent
= indent
- 2;
2336 if (label_indent
< 0)
2339 dump_bb_header (buffer
, bb
, indent
, flags
);
2342 dump_phi_nodes (buffer
, bb
, indent
, flags
);
2344 for (bsi
= bsi_start (bb
); !bsi_end_p (bsi
); bsi_next (&bsi
))
2348 stmt
= bsi_stmt (bsi
);
2350 curr_indent
= TREE_CODE (stmt
) == LABEL_EXPR
? label_indent
: indent
;
2352 INDENT (curr_indent
);
2353 dump_generic_node (buffer
, stmt
, curr_indent
, flags
, true);
2354 pp_newline (buffer
);
2357 dump_implicit_edges (buffer
, bb
, indent
, flags
);
2359 if (flags
& TDF_BLOCKS
)
2360 dump_bb_end (buffer
, bb
, indent
, flags
);