1 /* Pretty formatting of GENERIC trees in C syntax.
2 Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
3 Adapted from c-pretty-print.c by Diego Novillo <dnovillo@redhat.com>
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24 #include "coretypes.h"
28 #include "diagnostic.h"
31 #include "tree-flow.h"
32 #include "langhooks.h"
33 #include "tree-iterator.h"
34 #include "tree-chrec.h"
36 /* Local functions, macros and variables. */
37 static int op_prio (tree
);
38 static const char *op_symbol (tree
);
39 static void pretty_print_string (pretty_printer
*, const char*);
40 static void print_call_name (pretty_printer
*, tree
);
41 static void newline_and_indent (pretty_printer
*, int);
42 static void maybe_init_pretty_print (FILE *);
43 static void print_declaration (pretty_printer
*, tree
, int, int);
44 static void print_struct_decl (pretty_printer
*, tree
, int, int);
45 static void do_niy (pretty_printer
*, tree
);
46 static void dump_vops (pretty_printer
*, tree
, int, int);
47 static void dump_generic_bb_buff (pretty_printer
*, basic_block
, int, int);
49 #define INDENT(SPACE) do { \
50 int i; for (i = 0; i<SPACE; i++) pp_space (buffer); } while (0)
52 #define NIY do_niy(buffer,node)
54 #define PRINT_FUNCTION_NAME(NODE) pp_printf \
55 (buffer, "%s", TREE_CODE (NODE) == NOP_EXPR ? \
56 lang_hooks.decl_printable_name (TREE_OPERAND (NODE, 0), 1) : \
57 lang_hooks.decl_printable_name (NODE, 1))
59 static pretty_printer buffer
;
60 static int initialized
= 0;
61 static bool dumping_stmts
;
63 /* Try to print something for an unknown tree code. */
66 do_niy (pretty_printer
*buffer
, tree node
)
70 pp_string (buffer
, "<<< Unknown tree: ");
71 pp_string (buffer
, tree_code_name
[(int) TREE_CODE (node
)]);
75 len
= first_rtl_op (TREE_CODE (node
));
76 for (i
= 0; i
< len
; ++i
)
78 newline_and_indent (buffer
, 2);
79 dump_generic_node (buffer
, TREE_OPERAND (node
, i
), 2, 0, false);
83 pp_string (buffer
, " >>>\n");
87 debug_generic_expr (tree t
)
89 print_generic_expr (stderr
, t
, TDF_VOPS
|TDF_UID
);
90 fprintf (stderr
, "\n");
94 debug_generic_stmt (tree t
)
96 print_generic_stmt (stderr
, t
, TDF_VOPS
|TDF_UID
);
97 fprintf (stderr
, "\n");
100 /* Prints declaration DECL to the FILE with details specified by FLAGS. */
102 print_generic_decl (FILE *file
, tree decl
, int flags
)
104 maybe_init_pretty_print (file
);
105 dumping_stmts
= true;
106 print_declaration (&buffer
, decl
, 2, flags
);
107 pp_write_text_to_stream (&buffer
);
110 /* Print tree T, and its successors, on file FILE. FLAGS specifies details
111 to show in the dump. See TDF_* in tree.h. */
114 print_generic_stmt (FILE *file
, tree t
, int flags
)
116 maybe_init_pretty_print (file
);
117 dumping_stmts
= true;
118 dump_generic_node (&buffer
, t
, 0, flags
, true);
122 /* Print tree T, and its successors, on file FILE. FLAGS specifies details
123 to show in the dump. See TDF_* in tree.h. The output is indented by
127 print_generic_stmt_indented (FILE *file
, tree t
, int flags
, int indent
)
131 maybe_init_pretty_print (file
);
132 dumping_stmts
= true;
134 for (i
= 0; i
< indent
; i
++)
136 dump_generic_node (&buffer
, t
, indent
, flags
, true);
140 /* Print a single expression T on file FILE. FLAGS specifies details to show
141 in the dump. See TDF_* in tree.h. */
144 print_generic_expr (FILE *file
, tree t
, int flags
)
146 maybe_init_pretty_print (file
);
147 dumping_stmts
= false;
148 dump_generic_node (&buffer
, t
, 0, flags
, false);
151 /* Dump the name of a _DECL node and its DECL_UID if TDF_UID is set
155 dump_decl_name (pretty_printer
*buffer
, tree node
, int flags
)
157 if (DECL_NAME (node
))
158 pp_tree_identifier (buffer
, DECL_NAME (node
));
160 if ((flags
& TDF_UID
)
161 || DECL_NAME (node
) == NULL_TREE
)
163 if (TREE_CODE (node
) == LABEL_DECL
164 && LABEL_DECL_UID (node
) != -1)
165 pp_printf (buffer
, "L." HOST_WIDE_INT_PRINT_DEC
,
166 LABEL_DECL_UID (node
));
169 char c
= TREE_CODE (node
) == CONST_DECL
? 'C' : 'D';
170 pp_printf (buffer
, "%c.%u", c
, DECL_UID (node
));
175 /* Like the above, but used for pretty printing function calls. */
178 dump_function_name (pretty_printer
*buffer
, tree node
)
180 if (DECL_NAME (node
))
181 PRINT_FUNCTION_NAME (node
);
183 dump_decl_name (buffer
, node
, 0);
186 /* Dump a function declaration. NODE is the FUNCTION_TYPE. BUFFER, SPC and
187 FLAGS are as in dump_generic_node. */
190 dump_function_declaration (pretty_printer
*buffer
, tree node
,
193 bool wrote_arg
= false;
197 pp_character (buffer
, '(');
199 /* Print the argument types. The last element in the list is a VOID_TYPE.
200 The following avoids printing the last element. */
201 arg
= TYPE_ARG_TYPES (node
);
202 while (arg
&& TREE_CHAIN (arg
) && arg
!= error_mark_node
)
205 dump_generic_node (buffer
, TREE_VALUE (arg
), spc
, flags
, false);
206 arg
= TREE_CHAIN (arg
);
207 if (TREE_CHAIN (arg
) && TREE_CODE (TREE_CHAIN (arg
)) == TREE_LIST
)
209 pp_character (buffer
, ',');
215 pp_string (buffer
, "void");
217 pp_character (buffer
, ')');
220 /* Dump the node NODE on the pretty_printer BUFFER, SPC spaces of indent.
221 FLAGS specifies details to show in the dump (see TDF_* in tree.h). If
222 IS_STMT is true, the object printed is considered to be a statement
223 and it is terminated by ';' if appropriate. */
226 dump_generic_node (pretty_printer
*buffer
, tree node
, int spc
, int flags
,
234 if (node
== NULL_TREE
)
237 is_expr
= EXPR_P (node
);
239 if (TREE_CODE (node
) != ERROR_MARK
240 && is_gimple_stmt (node
)
241 && (flags
& TDF_VOPS
)
243 dump_vops (buffer
, node
, spc
, flags
);
246 && (flags
& TDF_LINENO
)
247 && EXPR_HAS_LOCATION (node
))
249 expanded_location xloc
= expand_location (EXPR_LOCATION (node
));
250 pp_character (buffer
, '[');
253 pp_string (buffer
, xloc
.file
);
254 pp_string (buffer
, " : ");
256 pp_decimal_int (buffer
, xloc
.line
);
257 pp_string (buffer
, "] ");
260 switch (TREE_CODE (node
))
263 pp_string (buffer
, "<<< error >>>");
266 case IDENTIFIER_NODE
:
267 pp_tree_identifier (buffer
, node
);
271 while (node
&& node
!= error_mark_node
)
273 if (TREE_PURPOSE (node
))
275 dump_generic_node (buffer
, TREE_PURPOSE (node
), spc
, flags
, false);
278 dump_generic_node (buffer
, TREE_VALUE (node
), spc
, flags
, false);
279 node
= TREE_CHAIN (node
);
280 if (node
&& TREE_CODE (node
) == TREE_LIST
)
282 pp_character (buffer
, ',');
289 dump_generic_node (buffer
, BINFO_TYPE (node
), spc
, flags
, false);
294 if (TREE_VEC_LENGTH (node
) > 0)
296 size_t len
= TREE_VEC_LENGTH (node
);
297 for (i
= 0; i
< len
- 1; i
++)
299 dump_generic_node (buffer
, TREE_VEC_ELT (node
, i
), spc
, flags
,
301 pp_character (buffer
, ',');
304 dump_generic_node (buffer
, TREE_VEC_ELT (node
, len
- 1), spc
,
323 unsigned int quals
= TYPE_QUALS (node
);
324 enum tree_code_class
class;
326 if (quals
& TYPE_QUAL_CONST
)
327 pp_string (buffer
, "const ");
328 else if (quals
& TYPE_QUAL_VOLATILE
)
329 pp_string (buffer
, "volatile ");
330 else if (quals
& TYPE_QUAL_RESTRICT
)
331 pp_string (buffer
, "restrict ");
333 class = TREE_CODE_CLASS (TREE_CODE (node
));
335 if (class == tcc_declaration
)
337 if (DECL_NAME (node
))
338 dump_decl_name (buffer
, node
, flags
);
340 pp_string (buffer
, "<unnamed type decl>");
342 else if (class == tcc_type
)
344 if (TYPE_NAME (node
))
346 if (TREE_CODE (TYPE_NAME (node
)) == IDENTIFIER_NODE
)
347 pp_tree_identifier (buffer
, TYPE_NAME (node
));
348 else if (TREE_CODE (TYPE_NAME (node
)) == TYPE_DECL
349 && DECL_NAME (TYPE_NAME (node
)))
350 dump_decl_name (buffer
, TYPE_NAME (node
), flags
);
352 pp_string (buffer
, "<unnamed type>");
354 else if (TREE_CODE (node
) == VECTOR_TYPE
)
356 pp_string (buffer
, "vector ");
357 dump_generic_node (buffer
, TREE_TYPE (node
),
361 pp_string (buffer
, "<unnamed type>");
368 str
= (TREE_CODE (node
) == POINTER_TYPE
? "*" : "&");
370 if (TREE_CODE (TREE_TYPE (node
)) == FUNCTION_TYPE
)
372 tree fnode
= TREE_TYPE (node
);
374 dump_generic_node (buffer
, TREE_TYPE (fnode
), spc
, flags
, false);
376 pp_character (buffer
, '(');
377 pp_string (buffer
, str
);
378 if (TYPE_NAME (node
) && DECL_NAME (TYPE_NAME (node
)))
379 dump_decl_name (buffer
, TYPE_NAME (node
), flags
);
381 pp_printf (buffer
, "<T%x>", TYPE_UID (node
));
383 pp_character (buffer
, ')');
384 dump_function_declaration (buffer
, fnode
, spc
, flags
);
388 unsigned int quals
= TYPE_QUALS (node
);
390 dump_generic_node (buffer
, TREE_TYPE (node
), spc
, flags
, false);
392 pp_string (buffer
, str
);
394 if (quals
& TYPE_QUAL_CONST
)
395 pp_string (buffer
, " const");
396 else if (quals
& TYPE_QUAL_VOLATILE
)
397 pp_string (buffer
, "volatile");
398 else if (quals
& TYPE_QUAL_RESTRICT
)
399 pp_string (buffer
, " restrict");
408 dump_decl_name (buffer
, TYPE_NAME (TYPE_METHOD_BASETYPE (node
)), flags
);
409 pp_string (buffer
, "::");
420 /* Print the innermost component type. */
421 for (tmp
= TREE_TYPE (node
); TREE_CODE (tmp
) == ARRAY_TYPE
;
422 tmp
= TREE_TYPE (tmp
))
424 dump_generic_node (buffer
, tmp
, spc
, flags
, false);
426 /* Print the dimensions. */
427 for (tmp
= node
; TREE_CODE (tmp
) == ARRAY_TYPE
;
428 tmp
= TREE_TYPE (tmp
))
430 tree domain
= TYPE_DOMAIN (tmp
);
432 pp_character (buffer
, '[');
435 if (TYPE_MIN_VALUE (domain
)
436 && !integer_zerop (TYPE_MIN_VALUE (domain
)))
438 dump_generic_node (buffer
, TYPE_MIN_VALUE (domain
),
440 pp_string (buffer
, " .. ");
443 if (TYPE_MAX_VALUE (domain
))
444 dump_generic_node (buffer
, TYPE_MAX_VALUE (domain
),
448 pp_string (buffer
, "<unknown>");
450 pp_character (buffer
, ']');
461 case QUAL_UNION_TYPE
:
462 /* Print the name of the structure. */
463 if (TREE_CODE (node
) == RECORD_TYPE
)
464 pp_string (buffer
, "struct ");
465 else if (TREE_CODE (node
) == UNION_TYPE
)
466 pp_string (buffer
, "union ");
468 if (TYPE_NAME (node
))
469 dump_generic_node (buffer
, TYPE_NAME (node
), spc
, flags
, false);
471 print_struct_decl (buffer
, node
, spc
, flags
);
479 if (TREE_CODE (TREE_TYPE (node
)) == POINTER_TYPE
)
481 /* In the case of a pointer, one may want to divide by the
482 size of the pointed-to type. Unfortunately, this not
483 straightforward. The C front-end maps expressions
488 in such a way that the two INTEGER_CST nodes for "5" have
489 different values but identical types. In the latter
490 case, the 5 is multiplied by sizeof (int) in c-common.c
491 (pointer_int_sum) to convert it to a byte address, and
492 yet the type of the node is left unchanged. Argh. What
493 is consistent though is that the number value corresponds
494 to bytes (UNITS) offset.
496 NB: Neither of the following divisors can be trivially
497 used to recover the original literal:
499 TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (node)))
500 TYPE_PRECISION (TREE_TYPE (TREE_TYPE (node))) */
501 pp_wide_integer (buffer
, TREE_INT_CST_LOW (node
));
502 pp_string (buffer
, "B"); /* pseudo-unit */
504 else if (! host_integerp (node
, 0))
508 if (tree_int_cst_sgn (val
) < 0)
510 pp_character (buffer
, '-');
511 val
= build_int_cst_wide (NULL_TREE
,
512 -TREE_INT_CST_LOW (val
),
513 ~TREE_INT_CST_HIGH (val
)
514 + !TREE_INT_CST_LOW (val
));
516 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
519 static char format
[10]; /* "%x%09999x\0" */
521 sprintf (format
, "%%x%%0%dx", HOST_BITS_PER_INT
/ 4);
522 sprintf (pp_buffer (buffer
)->digit_buffer
, format
,
523 TREE_INT_CST_HIGH (val
),
524 TREE_INT_CST_LOW (val
));
525 pp_string (buffer
, pp_buffer (buffer
)->digit_buffer
);
529 pp_wide_integer (buffer
, TREE_INT_CST_LOW (node
));
533 /* Code copied from print_node. */
536 if (TREE_OVERFLOW (node
))
537 pp_string (buffer
, " overflow");
539 #if !defined(REAL_IS_NOT_DOUBLE) || defined(REAL_ARITHMETIC)
540 d
= TREE_REAL_CST (node
);
541 if (REAL_VALUE_ISINF (d
))
542 pp_string (buffer
, " Inf");
543 else if (REAL_VALUE_ISNAN (d
))
544 pp_string (buffer
, " Nan");
548 real_to_decimal (string
, &d
, sizeof (string
), 0, 1);
549 pp_string (buffer
, string
);
554 unsigned char *p
= (unsigned char *) &TREE_REAL_CST (node
);
555 pp_string (buffer
, "0x");
556 for (i
= 0; i
< sizeof TREE_REAL_CST (node
); i
++)
557 output_formatted_integer (buffer
, "%02x", *p
++);
564 pp_string (buffer
, "__complex__ (");
565 dump_generic_node (buffer
, TREE_REALPART (node
), spc
, flags
, false);
566 pp_string (buffer
, ", ");
567 dump_generic_node (buffer
, TREE_IMAGPART (node
), spc
, flags
, false);
568 pp_string (buffer
, ")");
572 pp_string (buffer
, "\"");
573 pretty_print_string (buffer
, TREE_STRING_POINTER (node
));
574 pp_string (buffer
, "\"");
580 pp_string (buffer
, "{ ");
581 for (elt
= TREE_VECTOR_CST_ELTS (node
); elt
; elt
= TREE_CHAIN (elt
))
583 dump_generic_node (buffer
, TREE_VALUE (elt
), spc
, flags
, false);
584 if (TREE_CHAIN (elt
))
585 pp_string (buffer
, ", ");
587 pp_string (buffer
, " }");
596 dump_decl_name (buffer
, node
, flags
);
600 if (DECL_NAME (node
))
601 dump_decl_name (buffer
, node
, flags
);
602 else if (LABEL_DECL_UID (node
) != -1)
603 pp_printf (buffer
, "<L" HOST_WIDE_INT_PRINT_DEC
">",
604 LABEL_DECL_UID (node
));
606 pp_printf (buffer
, "<D%u>", DECL_UID (node
));
610 if (DECL_IS_BUILTIN (node
))
612 /* Don't print the declaration of built-in types. */
615 if (DECL_NAME (node
))
616 dump_decl_name (buffer
, node
, flags
);
619 if ((TREE_CODE (TREE_TYPE (node
)) == RECORD_TYPE
620 || TREE_CODE (TREE_TYPE (node
)) == UNION_TYPE
)
621 && TYPE_METHODS (TREE_TYPE (node
)))
623 /* The type is a c++ class: all structures have at least
625 pp_string (buffer
, "class ");
626 dump_generic_node (buffer
, TREE_TYPE (node
), spc
, flags
, false);
631 (TREE_CODE (TREE_TYPE (node
)) == UNION_TYPE
632 ? "union" : "struct "));
633 dump_generic_node (buffer
, TREE_TYPE (node
), spc
, flags
, false);
642 dump_decl_name (buffer
, node
, flags
);
646 pp_string (buffer
, "<retval>");
650 op0
= TREE_OPERAND (node
, 0);
652 if (TREE_CODE (op0
) == INDIRECT_REF
)
654 op0
= TREE_OPERAND (op0
, 0);
657 if (op_prio (op0
) < op_prio (node
))
658 pp_character (buffer
, '(');
659 dump_generic_node (buffer
, op0
, spc
, flags
, false);
660 if (op_prio (op0
) < op_prio (node
))
661 pp_character (buffer
, ')');
662 pp_string (buffer
, str
);
663 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
665 if (TREE_CODE (op0
) != VALUE_HANDLE
)
667 op0
= component_ref_field_offset (node
);
668 if (op0
&& TREE_CODE (op0
) != INTEGER_CST
)
670 pp_string (buffer
, "{off: ");
671 dump_generic_node (buffer
, op0
, spc
, flags
, false);
672 pp_character (buffer
, '}');
678 pp_string (buffer
, "BIT_FIELD_REF <");
679 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
680 pp_string (buffer
, ", ");
681 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
682 pp_string (buffer
, ", ");
683 dump_generic_node (buffer
, TREE_OPERAND (node
, 2), spc
, flags
, false);
684 pp_string (buffer
, ">");
688 case ARRAY_RANGE_REF
:
689 op0
= TREE_OPERAND (node
, 0);
690 if (op_prio (op0
) < op_prio (node
))
691 pp_character (buffer
, '(');
692 dump_generic_node (buffer
, op0
, spc
, flags
, false);
693 if (op_prio (op0
) < op_prio (node
))
694 pp_character (buffer
, ')');
695 pp_character (buffer
, '[');
696 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
697 if (TREE_CODE (node
) == ARRAY_RANGE_REF
)
698 pp_string (buffer
, " ...");
699 pp_character (buffer
, ']');
701 op0
= array_ref_low_bound (node
);
702 op1
= array_ref_element_size (node
);
704 if (!integer_zerop (op0
)
705 || (TYPE_SIZE_UNIT (TREE_TYPE (node
))
706 && !operand_equal_p (op1
, TYPE_SIZE_UNIT (TREE_TYPE (node
)), 0)))
708 pp_string (buffer
, "{lb: ");
709 dump_generic_node (buffer
, op0
, spc
, flags
, false);
710 pp_string (buffer
, " sz: ");
711 dump_generic_node (buffer
, op1
, spc
, flags
, false);
712 pp_character (buffer
, '}');
719 bool is_struct_init
= FALSE
;
720 pp_character (buffer
, '{');
721 lnode
= CONSTRUCTOR_ELTS (node
);
722 if (TREE_CODE (TREE_TYPE (node
)) == RECORD_TYPE
723 || TREE_CODE (TREE_TYPE (node
)) == UNION_TYPE
)
724 is_struct_init
= TRUE
;
725 while (lnode
&& lnode
!= error_mark_node
)
728 if (TREE_PURPOSE (lnode
) && is_struct_init
)
730 pp_character (buffer
, '.');
731 dump_generic_node (buffer
, TREE_PURPOSE (lnode
), spc
, flags
, false);
732 pp_string (buffer
, "=");
734 val
= TREE_VALUE (lnode
);
735 if (val
&& TREE_CODE (val
) == ADDR_EXPR
)
736 if (TREE_CODE (TREE_OPERAND (val
, 0)) == FUNCTION_DECL
)
737 val
= TREE_OPERAND (val
, 0);
738 if (val
&& TREE_CODE (val
) == FUNCTION_DECL
)
740 dump_decl_name (buffer
, val
, flags
);
744 dump_generic_node (buffer
, TREE_VALUE (lnode
), spc
, flags
, false);
746 lnode
= TREE_CHAIN (lnode
);
747 if (lnode
&& TREE_CODE (lnode
) == TREE_LIST
)
749 pp_character (buffer
, ',');
753 pp_character (buffer
, '}');
760 if (flags
& TDF_SLIM
)
762 pp_string (buffer
, "<COMPOUND_EXPR>");
766 dump_generic_node (buffer
, TREE_OPERAND (node
, 0),
767 spc
, flags
, dumping_stmts
);
769 newline_and_indent (buffer
, spc
);
772 pp_character (buffer
, ',');
776 for (tp
= &TREE_OPERAND (node
, 1);
777 TREE_CODE (*tp
) == COMPOUND_EXPR
;
778 tp
= &TREE_OPERAND (*tp
, 1))
780 dump_generic_node (buffer
, TREE_OPERAND (*tp
, 0),
781 spc
, flags
, dumping_stmts
);
783 newline_and_indent (buffer
, spc
);
786 pp_character (buffer
, ',');
791 dump_generic_node (buffer
, *tp
, spc
, flags
, dumping_stmts
);
797 tree_stmt_iterator si
;
800 if ((flags
& TDF_SLIM
) || !dumping_stmts
)
802 pp_string (buffer
, "<STATEMENT_LIST>");
806 for (si
= tsi_start (node
); !tsi_end_p (si
); tsi_next (&si
))
809 newline_and_indent (buffer
, spc
);
812 dump_generic_node (buffer
, tsi_stmt (si
), spc
, flags
, true);
819 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
821 pp_character (buffer
, '=');
823 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
827 pp_string (buffer
, "TARGET_EXPR <");
828 dump_generic_node (buffer
, TARGET_EXPR_SLOT (node
), spc
, flags
, false);
829 pp_character (buffer
, ',');
831 dump_generic_node (buffer
, TARGET_EXPR_INITIAL (node
), spc
, flags
, false);
832 pp_character (buffer
, '>');
836 print_declaration (buffer
, DECL_EXPR_DECL (node
), spc
, flags
);
841 if (TREE_TYPE (node
) == NULL
|| TREE_TYPE (node
) == void_type_node
)
843 pp_string (buffer
, "if (");
844 dump_generic_node (buffer
, COND_EXPR_COND (node
), spc
, flags
, false);
845 pp_character (buffer
, ')');
846 /* The lowered cond_exprs should always be printed in full. */
847 if (COND_EXPR_THEN (node
)
848 && (IS_EMPTY_STMT (COND_EXPR_THEN (node
))
849 || TREE_CODE (COND_EXPR_THEN (node
)) == GOTO_EXPR
)
850 && COND_EXPR_ELSE (node
)
851 && (IS_EMPTY_STMT (COND_EXPR_ELSE (node
))
852 || TREE_CODE (COND_EXPR_ELSE (node
)) == GOTO_EXPR
))
855 dump_generic_node (buffer
, COND_EXPR_THEN (node
), 0, flags
, true);
856 pp_string (buffer
, " else ");
857 dump_generic_node (buffer
, COND_EXPR_ELSE (node
), 0, flags
, true);
859 else if (!(flags
& TDF_SLIM
))
861 /* Output COND_EXPR_THEN. */
862 if (COND_EXPR_THEN (node
))
864 newline_and_indent (buffer
, spc
+2);
865 pp_character (buffer
, '{');
866 newline_and_indent (buffer
, spc
+4);
867 dump_generic_node (buffer
, COND_EXPR_THEN (node
), spc
+4,
869 newline_and_indent (buffer
, spc
+2);
870 pp_character (buffer
, '}');
873 /* Output COND_EXPR_ELSE. */
874 if (COND_EXPR_ELSE (node
))
876 newline_and_indent (buffer
, spc
);
877 pp_string (buffer
, "else");
878 newline_and_indent (buffer
, spc
+2);
879 pp_character (buffer
, '{');
880 newline_and_indent (buffer
, spc
+4);
881 dump_generic_node (buffer
, COND_EXPR_ELSE (node
), spc
+4,
883 newline_and_indent (buffer
, spc
+2);
884 pp_character (buffer
, '}');
891 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
893 pp_character (buffer
, '?');
895 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
897 pp_character (buffer
, ':');
899 dump_generic_node (buffer
, TREE_OPERAND (node
, 2), spc
, flags
, false);
904 pp_character (buffer
, '{');
905 if (!(flags
& TDF_SLIM
))
907 if (BIND_EXPR_VARS (node
))
911 for (op0
= BIND_EXPR_VARS (node
); op0
; op0
= TREE_CHAIN (op0
))
913 print_declaration (buffer
, op0
, spc
+2, flags
);
918 newline_and_indent (buffer
, spc
+2);
919 dump_generic_node (buffer
, BIND_EXPR_BODY (node
), spc
+2, flags
, true);
920 newline_and_indent (buffer
, spc
);
921 pp_character (buffer
, '}');
927 print_call_name (buffer
, node
);
929 /* Print parameters. */
931 pp_character (buffer
, '(');
932 op1
= TREE_OPERAND (node
, 1);
934 dump_generic_node (buffer
, op1
, spc
, flags
, false);
935 pp_character (buffer
, ')');
937 op1
= TREE_OPERAND (node
, 2);
940 pp_string (buffer
, " [static-chain: ");
941 dump_generic_node (buffer
, op1
, spc
, flags
, false);
942 pp_character (buffer
, ']');
945 if (CALL_EXPR_HAS_RETURN_SLOT_ADDR (node
))
946 pp_string (buffer
, " [return slot addr]");
947 if (CALL_EXPR_TAILCALL (node
))
948 pp_string (buffer
, " [tail call]");
951 case WITH_CLEANUP_EXPR
:
955 case CLEANUP_POINT_EXPR
:
956 pp_string (buffer
, "<<cleanup_point ");
957 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
958 pp_string (buffer
, ">>");
961 case PLACEHOLDER_EXPR
:
962 pp_string (buffer
, "<PLACEHOLDER_EXPR ");
963 dump_generic_node (buffer
, TREE_TYPE (node
), spc
, flags
, false);
964 pp_character (buffer
, '>');
967 /* Binary arithmetic and logic expressions. */
988 case TRUTH_ANDIF_EXPR
:
989 case TRUTH_ORIF_EXPR
:
1006 case UNORDERED_EXPR
:
1008 const char *op
= op_symbol (node
);
1009 op0
= TREE_OPERAND (node
, 0);
1010 op1
= TREE_OPERAND (node
, 1);
1012 /* When the operands are expressions with less priority,
1013 keep semantics of the tree representation. */
1014 if (op_prio (op0
) < op_prio (node
))
1016 pp_character (buffer
, '(');
1017 dump_generic_node (buffer
, op0
, spc
, flags
, false);
1018 pp_character (buffer
, ')');
1021 dump_generic_node (buffer
, op0
, spc
, flags
, false);
1024 pp_string (buffer
, op
);
1027 /* When the operands are expressions with less priority,
1028 keep semantics of the tree representation. */
1029 if (op_prio (op1
) < op_prio (node
))
1031 pp_character (buffer
, '(');
1032 dump_generic_node (buffer
, op1
, spc
, flags
, false);
1033 pp_character (buffer
, ')');
1036 dump_generic_node (buffer
, op1
, spc
, flags
, false);
1040 /* Unary arithmetic and logic expressions. */
1043 case TRUTH_NOT_EXPR
:
1045 case PREDECREMENT_EXPR
:
1046 case PREINCREMENT_EXPR
:
1047 case ALIGN_INDIRECT_REF
:
1048 case MISALIGNED_INDIRECT_REF
:
1050 if (TREE_CODE (node
) == ADDR_EXPR
1051 && (TREE_CODE (TREE_OPERAND (node
, 0)) == STRING_CST
1052 || TREE_CODE (TREE_OPERAND (node
, 0)) == FUNCTION_DECL
))
1053 ; /* Do not output '&' for strings and function pointers. */
1055 pp_string (buffer
, op_symbol (node
));
1057 if (op_prio (TREE_OPERAND (node
, 0)) < op_prio (node
))
1059 pp_character (buffer
, '(');
1060 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1061 pp_character (buffer
, ')');
1064 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1066 if (TREE_CODE (node
) == MISALIGNED_INDIRECT_REF
)
1068 pp_string (buffer
, "{misalignment: ");
1069 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
1070 pp_character (buffer
, '}');
1074 case POSTDECREMENT_EXPR
:
1075 case POSTINCREMENT_EXPR
:
1076 if (op_prio (TREE_OPERAND (node
, 0)) < op_prio (node
))
1078 pp_character (buffer
, '(');
1079 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1080 pp_character (buffer
, ')');
1083 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1084 pp_string (buffer
, op_symbol (node
));
1088 pp_string (buffer
, "MIN_EXPR <");
1089 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1090 pp_string (buffer
, ", ");
1091 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
1092 pp_character (buffer
, '>');
1096 pp_string (buffer
, "MAX_EXPR <");
1097 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1098 pp_string (buffer
, ", ");
1099 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
1100 pp_character (buffer
, '>');
1104 pp_string (buffer
, "ABS_EXPR <");
1105 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1106 pp_character (buffer
, '>');
1113 case FIX_TRUNC_EXPR
:
1115 case FIX_FLOOR_EXPR
:
1116 case FIX_ROUND_EXPR
:
1120 type
= TREE_TYPE (node
);
1121 op0
= TREE_OPERAND (node
, 0);
1122 if (type
!= TREE_TYPE (op0
))
1124 pp_character (buffer
, '(');
1125 dump_generic_node (buffer
, type
, spc
, flags
, false);
1126 pp_string (buffer
, ") ");
1128 if (op_prio (op0
) < op_prio (node
))
1129 pp_character (buffer
, '(');
1130 dump_generic_node (buffer
, op0
, spc
, flags
, false);
1131 if (op_prio (op0
) < op_prio (node
))
1132 pp_character (buffer
, ')');
1135 case VIEW_CONVERT_EXPR
:
1136 pp_string (buffer
, "VIEW_CONVERT_EXPR<");
1137 dump_generic_node (buffer
, TREE_TYPE (node
), spc
, flags
, false);
1138 pp_string (buffer
, ">(");
1139 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1140 pp_character (buffer
, ')');
1143 case NON_LVALUE_EXPR
:
1144 pp_string (buffer
, "NON_LVALUE_EXPR <");
1145 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1146 pp_character (buffer
, '>');
1150 pp_string (buffer
, "SAVE_EXPR <");
1151 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1152 pp_character (buffer
, '>');
1156 pp_string (buffer
, "COMPLEX_EXPR <");
1157 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1158 pp_string (buffer
, ", ");
1159 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
1160 pp_string (buffer
, ">");
1164 pp_string (buffer
, "CONJ_EXPR <");
1165 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1166 pp_string (buffer
, ">");
1170 pp_string (buffer
, "REALPART_EXPR <");
1171 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1172 pp_string (buffer
, ">");
1176 pp_string (buffer
, "IMAGPART_EXPR <");
1177 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1178 pp_string (buffer
, ">");
1182 pp_string (buffer
, "VA_ARG_EXPR <");
1183 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1184 pp_string (buffer
, ">");
1187 case TRY_FINALLY_EXPR
:
1188 case TRY_CATCH_EXPR
:
1189 pp_string (buffer
, "try");
1190 newline_and_indent (buffer
, spc
+2);
1191 pp_string (buffer
, "{");
1192 newline_and_indent (buffer
, spc
+4);
1193 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
+4, flags
, true);
1194 newline_and_indent (buffer
, spc
+2);
1195 pp_string (buffer
, "}");
1196 newline_and_indent (buffer
, spc
);
1198 (TREE_CODE (node
) == TRY_CATCH_EXPR
) ? "catch" : "finally");
1199 newline_and_indent (buffer
, spc
+2);
1200 pp_string (buffer
, "{");
1201 newline_and_indent (buffer
, spc
+4);
1202 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
+4, flags
, true);
1203 newline_and_indent (buffer
, spc
+2);
1204 pp_string (buffer
, "}");
1209 pp_string (buffer
, "catch (");
1210 dump_generic_node (buffer
, CATCH_TYPES (node
), spc
+2, flags
, false);
1211 pp_string (buffer
, ")");
1212 newline_and_indent (buffer
, spc
+2);
1213 pp_string (buffer
, "{");
1214 newline_and_indent (buffer
, spc
+4);
1215 dump_generic_node (buffer
, CATCH_BODY (node
), spc
+4, flags
, true);
1216 newline_and_indent (buffer
, spc
+2);
1217 pp_string (buffer
, "}");
1221 case EH_FILTER_EXPR
:
1222 pp_string (buffer
, "<<<eh_filter (");
1223 dump_generic_node (buffer
, EH_FILTER_TYPES (node
), spc
+2, flags
, false);
1224 pp_string (buffer
, ")>>>");
1225 newline_and_indent (buffer
, spc
+2);
1226 pp_string (buffer
, "{");
1227 newline_and_indent (buffer
, spc
+4);
1228 dump_generic_node (buffer
, EH_FILTER_FAILURE (node
), spc
+4, flags
, true);
1229 newline_and_indent (buffer
, spc
+2);
1230 pp_string (buffer
, "}");
1235 op0
= TREE_OPERAND (node
, 0);
1236 /* If this is for break or continue, don't bother printing it. */
1237 if (DECL_NAME (op0
))
1239 const char *name
= IDENTIFIER_POINTER (DECL_NAME (op0
));
1240 if (strcmp (name
, "break") == 0
1241 || strcmp (name
, "continue") == 0)
1244 dump_generic_node (buffer
, op0
, spc
, flags
, false);
1245 pp_character (buffer
, ':');
1246 if (DECL_NONLOCAL (op0
))
1247 pp_string (buffer
, " [non-local]");
1251 pp_string (buffer
, "<<<exception object>>>");
1255 pp_string (buffer
, "<<<filter object>>>");
1259 pp_string (buffer
, "while (1)");
1260 if (!(flags
& TDF_SLIM
))
1262 newline_and_indent (buffer
, spc
+2);
1263 pp_character (buffer
, '{');
1264 newline_and_indent (buffer
, spc
+4);
1265 dump_generic_node (buffer
, LOOP_EXPR_BODY (node
), spc
+4, flags
, true);
1266 newline_and_indent (buffer
, spc
+2);
1267 pp_character (buffer
, '}');
1273 pp_string (buffer
, "return");
1274 op0
= TREE_OPERAND (node
, 0);
1278 if (TREE_CODE (op0
) == MODIFY_EXPR
)
1279 dump_generic_node (buffer
, TREE_OPERAND (op0
, 1), spc
, flags
, false);
1281 dump_generic_node (buffer
, op0
, spc
, flags
, false);
1286 pp_string (buffer
, "if (");
1287 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1288 pp_string (buffer
, ") break");
1292 pp_string (buffer
, "switch (");
1293 dump_generic_node (buffer
, SWITCH_COND (node
), spc
, flags
, false);
1294 pp_character (buffer
, ')');
1295 if (!(flags
& TDF_SLIM
))
1297 newline_and_indent (buffer
, spc
+2);
1298 pp_character (buffer
, '{');
1299 if (SWITCH_BODY (node
))
1301 newline_and_indent (buffer
, spc
+4);
1302 dump_generic_node (buffer
, SWITCH_BODY (node
), spc
+4, flags
, true);
1306 tree vec
= SWITCH_LABELS (node
);
1307 size_t i
, n
= TREE_VEC_LENGTH (vec
);
1308 for (i
= 0; i
< n
; ++i
)
1310 tree elt
= TREE_VEC_ELT (vec
, i
);
1311 newline_and_indent (buffer
, spc
+4);
1312 dump_generic_node (buffer
, elt
, spc
+4, flags
, false);
1313 pp_string (buffer
, " goto ");
1314 dump_generic_node (buffer
, CASE_LABEL (elt
), spc
+4, flags
, true);
1315 pp_semicolon (buffer
);
1318 newline_and_indent (buffer
, spc
+2);
1319 pp_character (buffer
, '}');
1325 op0
= GOTO_DESTINATION (node
);
1326 if (TREE_CODE (op0
) != SSA_NAME
&& DECL_P (op0
) && DECL_NAME (op0
))
1328 const char *name
= IDENTIFIER_POINTER (DECL_NAME (op0
));
1329 if (strcmp (name
, "break") == 0
1330 || strcmp (name
, "continue") == 0)
1332 pp_string (buffer
, name
);
1336 pp_string (buffer
, "goto ");
1337 dump_generic_node (buffer
, op0
, spc
, flags
, false);
1341 pp_string (buffer
, "resx");
1342 /* ??? Any sensible way to present the eh region? */
1346 pp_string (buffer
, "__asm__");
1347 if (ASM_VOLATILE_P (node
))
1348 pp_string (buffer
, " __volatile__");
1349 pp_character (buffer
, '(');
1350 dump_generic_node (buffer
, ASM_STRING (node
), spc
, flags
, false);
1351 pp_character (buffer
, ':');
1352 dump_generic_node (buffer
, ASM_OUTPUTS (node
), spc
, flags
, false);
1353 pp_character (buffer
, ':');
1354 dump_generic_node (buffer
, ASM_INPUTS (node
), spc
, flags
, false);
1355 if (ASM_CLOBBERS (node
))
1357 pp_character (buffer
, ':');
1358 dump_generic_node (buffer
, ASM_CLOBBERS (node
), spc
, flags
, false);
1360 pp_string (buffer
, ")");
1363 case CASE_LABEL_EXPR
:
1364 if (CASE_LOW (node
) && CASE_HIGH (node
))
1366 pp_string (buffer
, "case ");
1367 dump_generic_node (buffer
, CASE_LOW (node
), spc
, flags
, false);
1368 pp_string (buffer
, " ... ");
1369 dump_generic_node (buffer
, CASE_HIGH (node
), spc
, flags
, false);
1371 else if (CASE_LOW (node
))
1373 pp_string (buffer
, "case ");
1374 dump_generic_node (buffer
, CASE_LOW (node
), spc
, flags
, false);
1377 pp_string (buffer
, "default ");
1378 pp_character (buffer
, ':');
1382 pp_string (buffer
, "OBJ_TYPE_REF(");
1383 dump_generic_node (buffer
, OBJ_TYPE_REF_EXPR (node
), spc
, flags
, false);
1384 pp_character (buffer
, ';');
1385 dump_generic_node (buffer
, OBJ_TYPE_REF_OBJECT (node
), spc
, flags
, false);
1386 pp_character (buffer
, '-');
1387 pp_character (buffer
, '>');
1388 dump_generic_node (buffer
, OBJ_TYPE_REF_TOKEN (node
), spc
, flags
, false);
1389 pp_character (buffer
, ')');
1396 dump_generic_node (buffer
, PHI_RESULT (node
), spc
, flags
, false);
1397 pp_string (buffer
, " = PHI <");
1398 for (i
= 0; i
< PHI_NUM_ARGS (node
); i
++)
1400 dump_generic_node (buffer
, PHI_ARG_DEF (node
, i
), spc
, flags
, false);
1401 pp_string (buffer
, "(");
1402 pp_decimal_int (buffer
, PHI_ARG_EDGE (node
, i
)->src
->index
);
1403 pp_string (buffer
, ")");
1404 if (i
< PHI_NUM_ARGS (node
) - 1)
1405 pp_string (buffer
, ", ");
1407 pp_string (buffer
, ">;");
1412 dump_generic_node (buffer
, SSA_NAME_VAR (node
), spc
, flags
, false);
1413 pp_string (buffer
, "_");
1414 pp_decimal_int (buffer
, SSA_NAME_VERSION (node
));
1417 case WITH_SIZE_EXPR
:
1418 pp_string (buffer
, "WITH_SIZE_EXPR <");
1419 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1420 pp_string (buffer
, ", ");
1421 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
1422 pp_string (buffer
, ">");
1426 pp_printf (buffer
, "VH.%d", VALUE_HANDLE_ID (node
));
1430 pp_string (buffer
, "scev_known");
1433 case SCEV_NOT_KNOWN
:
1434 pp_string (buffer
, "scev_not_known");
1437 case POLYNOMIAL_CHREC
:
1438 pp_string (buffer
, "{");
1439 dump_generic_node (buffer
, CHREC_LEFT (node
), spc
, flags
, false);
1440 pp_string (buffer
, ", +, ");
1441 dump_generic_node (buffer
, CHREC_RIGHT (node
), spc
, flags
, false);
1442 pp_string (buffer
, "}_");
1443 dump_generic_node (buffer
, CHREC_VAR (node
), spc
, flags
, false);
1447 case REALIGN_LOAD_EXPR
:
1448 pp_string (buffer
, "REALIGN_LOAD <");
1449 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1450 pp_string (buffer
, ", ");
1451 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
1452 pp_string (buffer
, ", ");
1453 dump_generic_node (buffer
, TREE_OPERAND (node
, 2), spc
, flags
, false);
1454 pp_string (buffer
, ">");
1458 pp_string (buffer
, " VEC_COND_EXPR < ");
1459 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1460 pp_string (buffer
, " , ");
1461 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
1462 pp_string (buffer
, " , ");
1463 dump_generic_node (buffer
, TREE_OPERAND (node
, 2), spc
, flags
, false);
1464 pp_string (buffer
, " > ");
1471 if (is_stmt
&& is_expr
)
1472 pp_semicolon (buffer
);
1473 pp_write_text_to_stream (buffer
);
1478 /* Print the declaration of a variable. */
1481 print_declaration (pretty_printer
*buffer
, tree t
, int spc
, int flags
)
1485 if (TREE_CODE (t
) == TYPE_DECL
)
1486 pp_string (buffer
, "typedef ");
1488 if (DECL_REGISTER (t
))
1489 pp_string (buffer
, "register ");
1491 if (TREE_PUBLIC (t
) && DECL_EXTERNAL (t
))
1492 pp_string (buffer
, "extern ");
1493 else if (TREE_STATIC (t
))
1494 pp_string (buffer
, "static ");
1496 /* Print the type and name. */
1497 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
1501 /* Print array's type. */
1502 tmp
= TREE_TYPE (t
);
1503 while (TREE_CODE (TREE_TYPE (tmp
)) == ARRAY_TYPE
)
1504 tmp
= TREE_TYPE (tmp
);
1505 dump_generic_node (buffer
, TREE_TYPE (tmp
), spc
, flags
, false);
1507 /* Print variable's name. */
1509 dump_generic_node (buffer
, t
, spc
, flags
, false);
1511 /* Print the dimensions. */
1512 tmp
= TREE_TYPE (t
);
1513 while (TREE_CODE (tmp
) == ARRAY_TYPE
)
1515 pp_character (buffer
, '[');
1516 if (TYPE_DOMAIN (tmp
))
1518 if (TREE_CODE (TYPE_SIZE (tmp
)) == INTEGER_CST
)
1519 pp_wide_integer (buffer
,
1520 TREE_INT_CST_LOW (TYPE_SIZE (tmp
)) /
1521 TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (tmp
))));
1523 dump_generic_node (buffer
, TYPE_SIZE_UNIT (tmp
), spc
, flags
,
1526 pp_character (buffer
, ']');
1527 tmp
= TREE_TYPE (tmp
);
1530 else if (TREE_CODE (t
) == FUNCTION_DECL
)
1532 dump_generic_node (buffer
, TREE_TYPE (TREE_TYPE (t
)), spc
, flags
, false);
1534 dump_decl_name (buffer
, t
, flags
);
1535 dump_function_declaration (buffer
, TREE_TYPE (t
), spc
, flags
);
1539 /* Print type declaration. */
1540 dump_generic_node (buffer
, TREE_TYPE (t
), spc
, flags
, false);
1542 /* Print variable's name. */
1544 dump_generic_node (buffer
, t
, spc
, flags
, false);
1547 if (TREE_CODE (t
) == VAR_DECL
&& DECL_HARD_REGISTER (t
))
1549 pp_string (buffer
, " __asm__ ");
1550 pp_character (buffer
, '(');
1551 dump_generic_node (buffer
, DECL_ASSEMBLER_NAME (t
), spc
, flags
, false);
1552 pp_character (buffer
, ')');
1555 /* The initial value of a function serves to determine wether the function
1556 is declared or defined. So the following does not apply to function
1558 if (TREE_CODE (t
) != FUNCTION_DECL
)
1560 /* Print the initial value. */
1561 if (DECL_INITIAL (t
))
1564 pp_character (buffer
, '=');
1566 dump_generic_node (buffer
, DECL_INITIAL (t
), spc
, flags
, false);
1570 pp_character (buffer
, ';');
1574 /* Prints a structure: name, fields, and methods.
1575 FIXME: Still incomplete. */
1578 print_struct_decl (pretty_printer
*buffer
, tree node
, int spc
, int flags
)
1580 /* Print the name of the structure. */
1581 if (TYPE_NAME (node
))
1584 if (TREE_CODE (node
) == RECORD_TYPE
)
1585 pp_string (buffer
, "struct ");
1586 else if ((TREE_CODE (node
) == UNION_TYPE
1587 || TREE_CODE (node
) == QUAL_UNION_TYPE
))
1588 pp_string (buffer
, "union ");
1590 dump_generic_node (buffer
, TYPE_NAME (node
), spc
, 0, false);
1593 /* Print the contents of the structure. */
1594 pp_newline (buffer
);
1596 pp_character (buffer
, '{');
1597 pp_newline (buffer
);
1599 /* Print the fields of the structure. */
1602 tmp
= TYPE_FIELDS (node
);
1605 /* Avoid to print recursively the structure. */
1606 /* FIXME : Not implemented correctly...,
1607 what about the case when we have a cycle in the contain graph? ...
1608 Maybe this could be solved by looking at the scope in which the
1609 structure was declared. */
1610 if (TREE_TYPE (tmp
) != node
1611 || (TREE_CODE (TREE_TYPE (tmp
)) == POINTER_TYPE
1612 && TREE_TYPE (TREE_TYPE (tmp
)) != node
))
1614 print_declaration (buffer
, tmp
, spc
+2, flags
);
1615 pp_newline (buffer
);
1617 tmp
= TREE_CHAIN (tmp
);
1621 pp_character (buffer
, '}');
1624 /* Return the priority of the operator OP.
1626 From lowest to highest precedence with either left-to-right (L-R)
1627 or right-to-left (R-L) associativity]:
1630 2 [R-L] = += -= *= /= %= &= ^= |= <<= >>=
1642 14 [R-L] ! ~ ++ -- + - * & (type) sizeof
1643 15 [L-R] fn() [] -> .
1645 unary +, - and * have higher precedence than the corresponding binary
1654 switch (TREE_CODE (op
))
1669 case TRUTH_ORIF_EXPR
:
1672 case TRUTH_AND_EXPR
:
1673 case TRUTH_ANDIF_EXPR
:
1680 case TRUTH_XOR_EXPR
:
1697 case UNORDERED_EXPR
:
1715 case TRUNC_DIV_EXPR
:
1717 case FLOOR_DIV_EXPR
:
1718 case ROUND_DIV_EXPR
:
1720 case EXACT_DIV_EXPR
:
1721 case TRUNC_MOD_EXPR
:
1723 case FLOOR_MOD_EXPR
:
1724 case ROUND_MOD_EXPR
:
1727 case TRUTH_NOT_EXPR
:
1729 case POSTINCREMENT_EXPR
:
1730 case POSTDECREMENT_EXPR
:
1731 case PREINCREMENT_EXPR
:
1732 case PREDECREMENT_EXPR
:
1734 case ALIGN_INDIRECT_REF
:
1735 case MISALIGNED_INDIRECT_REF
:
1741 case FIX_TRUNC_EXPR
:
1743 case FIX_FLOOR_EXPR
:
1744 case FIX_ROUND_EXPR
:
1750 case ARRAY_RANGE_REF
:
1754 /* Special expressions. */
1763 case NON_LVALUE_EXPR
:
1764 return op_prio (TREE_OPERAND (op
, 0));
1767 /* Return an arbitrarily high precedence to avoid surrounding single
1768 VAR_DECLs in ()s. */
1774 /* Return the symbol associated with operator OP. */
1781 switch (TREE_CODE (op
))
1787 case TRUTH_ORIF_EXPR
:
1790 case TRUTH_AND_EXPR
:
1791 case TRUTH_ANDIF_EXPR
:
1797 case TRUTH_XOR_EXPR
:
1807 case UNORDERED_EXPR
:
1857 case TRUTH_NOT_EXPR
:
1864 case ALIGN_INDIRECT_REF
:
1867 case MISALIGNED_INDIRECT_REF
:
1870 case TRUNC_DIV_EXPR
:
1877 case FLOOR_DIV_EXPR
:
1880 case ROUND_DIV_EXPR
:
1883 case EXACT_DIV_EXPR
:
1886 case TRUNC_MOD_EXPR
:
1892 case FLOOR_MOD_EXPR
:
1895 case ROUND_MOD_EXPR
:
1898 case PREDECREMENT_EXPR
:
1901 case PREINCREMENT_EXPR
:
1904 case POSTDECREMENT_EXPR
:
1907 case POSTINCREMENT_EXPR
:
1911 return "<<< ??? >>>";
1915 /* Prints the name of a CALL_EXPR. */
1918 print_call_name (pretty_printer
*buffer
, tree node
)
1922 gcc_assert (TREE_CODE (node
) == CALL_EXPR
);
1924 op0
= TREE_OPERAND (node
, 0);
1926 if (TREE_CODE (op0
) == NON_LVALUE_EXPR
)
1927 op0
= TREE_OPERAND (op0
, 0);
1929 switch (TREE_CODE (op0
))
1933 dump_function_name (buffer
, op0
);
1939 dump_generic_node (buffer
, TREE_OPERAND (op0
, 0), 0, 0, false);
1943 pp_string (buffer
, "(");
1944 dump_generic_node (buffer
, TREE_OPERAND (op0
, 0), 0, 0, false);
1945 pp_string (buffer
, ") ? ");
1946 dump_generic_node (buffer
, TREE_OPERAND (op0
, 1), 0, 0, false);
1947 pp_string (buffer
, " : ");
1948 dump_generic_node (buffer
, TREE_OPERAND (op0
, 2), 0, 0, false);
1952 /* The function is a pointer contained in a structure. */
1953 if (TREE_CODE (TREE_OPERAND (op0
, 0)) == INDIRECT_REF
||
1954 TREE_CODE (TREE_OPERAND (op0
, 0)) == VAR_DECL
)
1955 dump_function_name (buffer
, TREE_OPERAND (op0
, 1));
1957 dump_generic_node (buffer
, TREE_OPERAND (op0
, 0), 0, 0, false);
1959 We can have several levels of structures and a function
1960 pointer inside. This is not implemented yet... */
1965 if (TREE_CODE (TREE_OPERAND (op0
, 0)) == VAR_DECL
)
1966 dump_function_name (buffer
, TREE_OPERAND (op0
, 0));
1968 dump_generic_node (buffer
, op0
, 0, 0, false);
1973 dump_generic_node (buffer
, op0
, 0, 0, false);
1981 /* Parses the string STR and replaces new-lines by '\n', tabs by '\t', ... */
1984 pretty_print_string (pretty_printer
*buffer
, const char *str
)
1994 pp_string (buffer
, "\\b");
1998 pp_string (buffer
, "\\f");
2002 pp_string (buffer
, "\\n");
2006 pp_string (buffer
, "\\r");
2010 pp_string (buffer
, "\\t");
2014 pp_string (buffer
, "\\v");
2018 pp_string (buffer
, "\\\\");
2022 pp_string (buffer
, "\\\"");
2026 pp_string (buffer
, "\\'");
2030 pp_string (buffer
, "\\0");
2034 pp_string (buffer
, "\\1");
2038 pp_string (buffer
, "\\2");
2042 pp_string (buffer
, "\\3");
2046 pp_string (buffer
, "\\4");
2050 pp_string (buffer
, "\\5");
2054 pp_string (buffer
, "\\6");
2058 pp_string (buffer
, "\\7");
2062 pp_character (buffer
, str
[0]);
2070 maybe_init_pretty_print (FILE *file
)
2074 pp_construct (&buffer
, /* prefix */NULL
, /* line-width */0);
2075 pp_needs_newline (&buffer
) = true;
2079 buffer
.buffer
->stream
= file
;
2083 newline_and_indent (pretty_printer
*buffer
, int spc
)
2085 pp_newline (buffer
);
2090 dump_vops (pretty_printer
*buffer
, tree stmt
, int spc
, int flags
)
2093 use_operand_p use_p
;
2094 def_operand_p def_p
;
2095 use_operand_p kill_p
;
2098 FOR_EACH_SSA_MAYDEF_OPERAND (def_p
, use_p
, stmt
, iter
)
2100 pp_string (buffer
, "# ");
2101 dump_generic_node (buffer
, DEF_FROM_PTR (def_p
),
2102 spc
+ 2, flags
, false);
2103 pp_string (buffer
, " = V_MAY_DEF <");
2104 dump_generic_node (buffer
, USE_FROM_PTR (use_p
),
2105 spc
+ 2, flags
, false);
2106 pp_string (buffer
, ">;");
2107 newline_and_indent (buffer
, spc
);
2110 FOR_EACH_SSA_MUSTDEF_OPERAND (def_p
, kill_p
, stmt
, iter
)
2112 pp_string (buffer
, "# ");
2113 dump_generic_node (buffer
, DEF_FROM_PTR (def_p
),
2114 spc
+ 2, flags
, false);
2115 pp_string (buffer
, " = V_MUST_DEF <");
2116 dump_generic_node (buffer
, USE_FROM_PTR (kill_p
),
2117 spc
+ 2, flags
, false);
2118 pp_string (buffer
, ">;");
2119 newline_and_indent (buffer
, spc
);
2122 FOR_EACH_SSA_TREE_OPERAND (use
, stmt
, iter
, SSA_OP_VUSE
)
2124 pp_string (buffer
, "# VUSE <");
2125 dump_generic_node (buffer
, use
, spc
+ 2, flags
, false);
2126 pp_string (buffer
, ">;");
2127 newline_and_indent (buffer
, spc
);
2131 /* Dumps basic block BB to FILE with details described by FLAGS and
2132 indented by INDENT spaces. */
2135 dump_generic_bb (FILE *file
, basic_block bb
, int indent
, int flags
)
2137 maybe_init_pretty_print (file
);
2138 dumping_stmts
= true;
2139 dump_generic_bb_buff (&buffer
, bb
, indent
, flags
);
2143 /* Dumps header of basic block BB to buffer BUFFER indented by INDENT
2144 spaces and details described by flags. */
2147 dump_bb_header (pretty_printer
*buffer
, basic_block bb
, int indent
, int flags
)
2153 if (flags
& TDF_BLOCKS
)
2156 pp_string (buffer
, "# BLOCK ");
2157 pp_decimal_int (buffer
, bb
->index
);
2159 if (flags
& TDF_LINENO
)
2161 block_stmt_iterator bsi
;
2163 for (bsi
= bsi_start (bb
); !bsi_end_p (bsi
); bsi_next (&bsi
))
2164 if (get_lineno (bsi_stmt (bsi
)) != -1)
2166 pp_string (buffer
, ", starting at line ");
2167 pp_decimal_int (buffer
, get_lineno (bsi_stmt (bsi
)));
2171 newline_and_indent (buffer
, indent
);
2173 pp_string (buffer
, "# PRED:");
2174 pp_write_text_to_stream (buffer
);
2175 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
2176 if (flags
& TDF_SLIM
)
2178 pp_string (buffer
, " ");
2179 if (e
->src
== ENTRY_BLOCK_PTR
)
2180 pp_string (buffer
, "ENTRY");
2182 pp_decimal_int (buffer
, e
->src
->index
);
2185 dump_edge_info (buffer
->buffer
->stream
, e
, 0);
2186 pp_newline (buffer
);
2190 stmt
= first_stmt (bb
);
2191 if (!stmt
|| TREE_CODE (stmt
) != LABEL_EXPR
)
2193 INDENT (indent
- 2);
2194 pp_string (buffer
, "<bb ");
2195 pp_decimal_int (buffer
, bb
->index
);
2196 pp_string (buffer
, ">:");
2197 pp_newline (buffer
);
2200 pp_write_text_to_stream (buffer
);
2201 check_bb_profile (bb
, buffer
->buffer
->stream
);
2204 /* Dumps end of basic block BB to buffer BUFFER indented by INDENT
2208 dump_bb_end (pretty_printer
*buffer
, basic_block bb
, int indent
, int flags
)
2214 pp_string (buffer
, "# SUCC:");
2215 pp_write_text_to_stream (buffer
);
2216 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
2217 if (flags
& TDF_SLIM
)
2219 pp_string (buffer
, " ");
2220 if (e
->dest
== EXIT_BLOCK_PTR
)
2221 pp_string (buffer
, "EXIT");
2223 pp_decimal_int (buffer
, e
->dest
->index
);
2226 dump_edge_info (buffer
->buffer
->stream
, e
, 1);
2227 pp_newline (buffer
);
2230 /* Dumps phi nodes of basic block BB to buffer BUFFER with details described by
2231 FLAGS indented by INDENT spaces. */
2234 dump_phi_nodes (pretty_printer
*buffer
, basic_block bb
, int indent
, int flags
)
2236 tree phi
= phi_nodes (bb
);
2240 for (; phi
; phi
= PHI_CHAIN (phi
))
2242 if (is_gimple_reg (PHI_RESULT (phi
)) || (flags
& TDF_VOPS
))
2245 pp_string (buffer
, "# ");
2246 dump_generic_node (buffer
, phi
, indent
, flags
, false);
2247 pp_newline (buffer
);
2252 /* Dump jump to basic block BB that is represented implicitly in the cfg
2256 pp_cfg_jump (pretty_printer
*buffer
, basic_block bb
)
2260 stmt
= first_stmt (bb
);
2262 pp_string (buffer
, "goto <bb ");
2263 pp_decimal_int (buffer
, bb
->index
);
2264 pp_string (buffer
, ">");
2265 if (stmt
&& TREE_CODE (stmt
) == LABEL_EXPR
)
2267 pp_string (buffer
, " (");
2268 dump_generic_node (buffer
, LABEL_EXPR_LABEL (stmt
), 0, 0, false);
2269 pp_string (buffer
, ")");
2271 pp_semicolon (buffer
);
2274 /* Dump edges represented implicitly in basic block BB to BUFFER, indented
2275 by INDENT spaces, with details given by FLAGS. */
2278 dump_implicit_edges (pretty_printer
*buffer
, basic_block bb
, int indent
,
2284 /* If there is a fallthru edge, we may need to add an artificial goto to the
2286 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
2287 if (e
->flags
& EDGE_FALLTHRU
)
2289 if (e
&& e
->dest
!= bb
->next_bb
)
2293 if ((flags
& TDF_LINENO
)
2294 #ifdef USE_MAPPED_LOCATION
2295 && e
->goto_locus
!= UNKNOWN_LOCATION
2301 expanded_location goto_xloc
;
2302 #ifdef USE_MAPPED_LOCATION
2303 goto_xloc
= expand_location (e
->goto_locus
);
2305 goto_xloc
= *e
->goto_locus
;
2307 pp_character (buffer
, '[');
2310 pp_string (buffer
, goto_xloc
.file
);
2311 pp_string (buffer
, " : ");
2313 pp_decimal_int (buffer
, goto_xloc
.line
);
2314 pp_string (buffer
, "] ");
2317 pp_cfg_jump (buffer
, e
->dest
);
2318 pp_newline (buffer
);
2322 /* Dumps basic block BB to buffer BUFFER with details described by FLAGS and
2323 indented by INDENT spaces. */
2326 dump_generic_bb_buff (pretty_printer
*buffer
, basic_block bb
,
2327 int indent
, int flags
)
2329 block_stmt_iterator bsi
;
2331 int label_indent
= indent
- 2;
2333 if (label_indent
< 0)
2336 dump_bb_header (buffer
, bb
, indent
, flags
);
2339 dump_phi_nodes (buffer
, bb
, indent
, flags
);
2341 for (bsi
= bsi_start (bb
); !bsi_end_p (bsi
); bsi_next (&bsi
))
2345 stmt
= bsi_stmt (bsi
);
2347 curr_indent
= TREE_CODE (stmt
) == LABEL_EXPR
? label_indent
: indent
;
2349 INDENT (curr_indent
);
2350 dump_generic_node (buffer
, stmt
, curr_indent
, flags
, true);
2351 pp_newline (buffer
);
2354 dump_implicit_edges (buffer
, bb
, indent
, flags
);
2356 if (flags
& TDF_BLOCKS
)
2357 dump_bb_end (buffer
, bb
, indent
, flags
);