1 /* Pretty formatting of GENERIC trees in C syntax.
2 Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
3 Adapted from c-pretty-print.c by Diego Novillo <dnovillo@redhat.com>
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24 #include "coretypes.h"
28 #include "diagnostic.h"
31 #include "tree-flow.h"
32 #include "langhooks.h"
33 #include "tree-iterator.h"
34 #include "tree-chrec.h"
36 /* Local functions, macros and variables. */
37 static int op_prio (tree
);
38 static const char *op_symbol (tree
);
39 static void pretty_print_string (pretty_printer
*, const char*);
40 static void print_call_name (pretty_printer
*, tree
);
41 static void newline_and_indent (pretty_printer
*, int);
42 static void maybe_init_pretty_print (FILE *);
43 static void print_declaration (pretty_printer
*, tree
, int, int);
44 static void print_struct_decl (pretty_printer
*, tree
, int, int);
45 static void do_niy (pretty_printer
*, tree
);
46 static void dump_vops (pretty_printer
*, tree
, int, int);
47 static void dump_generic_bb_buff (pretty_printer
*, basic_block
, int, int);
49 #define INDENT(SPACE) do { \
50 int i; for (i = 0; i<SPACE; i++) pp_space (buffer); } while (0)
52 #define NIY do_niy(buffer,node)
54 #define PRINT_FUNCTION_NAME(NODE) pp_printf \
55 (buffer, "%s", TREE_CODE (NODE) == NOP_EXPR ? \
56 lang_hooks.decl_printable_name (TREE_OPERAND (NODE, 0), 1) : \
57 lang_hooks.decl_printable_name (NODE, 1))
59 static pretty_printer buffer
;
60 static int initialized
= 0;
61 static bool dumping_stmts
;
63 /* Try to print something for an unknown tree code. */
66 do_niy (pretty_printer
*buffer
, tree node
)
70 pp_string (buffer
, "<<< Unknown tree: ");
71 pp_string (buffer
, tree_code_name
[(int) TREE_CODE (node
)]);
73 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (node
))))
75 len
= first_rtl_op (TREE_CODE (node
));
76 for (i
= 0; i
< len
; ++i
)
78 newline_and_indent (buffer
, 2);
79 dump_generic_node (buffer
, TREE_OPERAND (node
, i
), 2, 0, false);
83 pp_string (buffer
, " >>>\n");
87 debug_generic_expr (tree t
)
89 print_generic_expr (stderr
, t
, TDF_VOPS
|TDF_UID
);
90 fprintf (stderr
, "\n");
94 debug_generic_stmt (tree t
)
96 print_generic_stmt (stderr
, t
, TDF_VOPS
|TDF_UID
);
97 fprintf (stderr
, "\n");
100 /* Prints declaration DECL to the FILE with details specified by FLAGS. */
102 print_generic_decl (FILE *file
, tree decl
, int flags
)
104 maybe_init_pretty_print (file
);
105 dumping_stmts
= true;
106 print_declaration (&buffer
, decl
, 2, flags
);
107 pp_write_text_to_stream (&buffer
);
110 /* Print tree T, and its successors, on file FILE. FLAGS specifies details
111 to show in the dump. See TDF_* in tree.h. */
114 print_generic_stmt (FILE *file
, tree t
, int flags
)
116 maybe_init_pretty_print (file
);
117 dumping_stmts
= true;
118 dump_generic_node (&buffer
, t
, 0, flags
, true);
122 /* Print tree T, and its successors, on file FILE. FLAGS specifies details
123 to show in the dump. See TDF_* in tree.h. The output is indented by
127 print_generic_stmt_indented (FILE *file
, tree t
, int flags
, int indent
)
131 maybe_init_pretty_print (file
);
132 dumping_stmts
= true;
134 for (i
= 0; i
< indent
; i
++)
136 dump_generic_node (&buffer
, t
, indent
, flags
, true);
140 /* Print a single expression T on file FILE. FLAGS specifies details to show
141 in the dump. See TDF_* in tree.h. */
144 print_generic_expr (FILE *file
, tree t
, int flags
)
146 maybe_init_pretty_print (file
);
147 dumping_stmts
= false;
148 dump_generic_node (&buffer
, t
, 0, flags
, false);
151 /* Dump the name of a _DECL node and its DECL_UID if TDF_UID is set
155 dump_decl_name (pretty_printer
*buffer
, tree node
, int flags
)
157 if (DECL_NAME (node
))
158 pp_tree_identifier (buffer
, DECL_NAME (node
));
160 if ((flags
& TDF_UID
)
161 || DECL_NAME (node
) == NULL_TREE
)
163 if (TREE_CODE (node
) == LABEL_DECL
164 && LABEL_DECL_UID (node
) != -1)
165 pp_printf (buffer
, "L." HOST_WIDE_INT_PRINT_DEC
,
166 LABEL_DECL_UID (node
));
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);
305 unsigned int quals
= TYPE_QUALS (node
);
308 if (quals
& TYPE_QUAL_CONST
)
309 pp_string (buffer
, "const ");
310 else if (quals
& TYPE_QUAL_VOLATILE
)
311 pp_string (buffer
, "volatile ");
312 else if (quals
& TYPE_QUAL_RESTRICT
)
313 pp_string (buffer
, "restrict ");
315 class = TREE_CODE_CLASS (TREE_CODE (node
));
319 if (DECL_NAME (node
))
320 dump_decl_name (buffer
, node
, flags
);
322 pp_string (buffer
, "<unnamed type decl>");
324 else if (class == 't')
326 if (TYPE_NAME (node
))
328 if (TREE_CODE (TYPE_NAME (node
)) == IDENTIFIER_NODE
)
329 pp_tree_identifier (buffer
, TYPE_NAME (node
));
330 else if (TREE_CODE (TYPE_NAME (node
)) == TYPE_DECL
331 && DECL_NAME (TYPE_NAME (node
)))
332 dump_decl_name (buffer
, TYPE_NAME (node
), flags
);
334 pp_string (buffer
, "<unnamed type>");
337 pp_string (buffer
, "<unnamed type>");
344 str
= (TREE_CODE (node
) == POINTER_TYPE
? "*" : "&");
346 if (TREE_CODE (TREE_TYPE (node
)) == FUNCTION_TYPE
)
348 tree fnode
= TREE_TYPE (node
);
350 dump_generic_node (buffer
, TREE_TYPE (fnode
), spc
, flags
, false);
352 pp_character (buffer
, '(');
353 pp_string (buffer
, str
);
354 if (TYPE_NAME (node
) && DECL_NAME (TYPE_NAME (node
)))
355 dump_decl_name (buffer
, TYPE_NAME (node
), flags
);
357 pp_printf (buffer
, "<T%x>", TYPE_UID (node
));
359 pp_character (buffer
, ')');
360 dump_function_declaration (buffer
, fnode
, spc
, flags
);
364 unsigned int quals
= TYPE_QUALS (node
);
366 dump_generic_node (buffer
, TREE_TYPE (node
), spc
, flags
, false);
368 pp_string (buffer
, str
);
370 if (quals
& TYPE_QUAL_CONST
)
371 pp_string (buffer
, " const");
372 else if (quals
& TYPE_QUAL_VOLATILE
)
373 pp_string (buffer
, "volatile");
374 else if (quals
& TYPE_QUAL_RESTRICT
)
375 pp_string (buffer
, " restrict");
384 dump_decl_name (buffer
, TYPE_NAME (TYPE_METHOD_BASETYPE (node
)), flags
);
385 pp_string (buffer
, "::");
396 /* Print the innermost component type. */
397 for (tmp
= TREE_TYPE (node
); TREE_CODE (tmp
) == ARRAY_TYPE
;
398 tmp
= TREE_TYPE (tmp
))
400 dump_generic_node (buffer
, tmp
, spc
, flags
, false);
402 /* Print the dimensions. */
403 for (tmp
= node
; TREE_CODE (tmp
) == ARRAY_TYPE
;
404 tmp
= TREE_TYPE (tmp
))
406 tree domain
= TYPE_DOMAIN (tmp
);
408 pp_character (buffer
, '[');
411 if (TYPE_MIN_VALUE (domain
)
412 && !integer_zerop (TYPE_MIN_VALUE (domain
)))
414 dump_generic_node (buffer
, TYPE_MIN_VALUE (domain
),
416 pp_string (buffer
, " .. ");
419 if (TYPE_MAX_VALUE (domain
))
420 dump_generic_node (buffer
, TYPE_MAX_VALUE (domain
),
424 pp_string (buffer
, "<unknown>");
426 pp_character (buffer
, ']');
437 case QUAL_UNION_TYPE
:
438 /* Print the name of the structure. */
439 if (TREE_CODE (node
) == RECORD_TYPE
)
440 pp_string (buffer
, "struct ");
441 else if (TREE_CODE (node
) == UNION_TYPE
)
442 pp_string (buffer
, "union ");
444 if (TYPE_NAME (node
))
445 dump_generic_node (buffer
, TYPE_NAME (node
), spc
, flags
, false);
447 print_struct_decl (buffer
, node
, spc
, flags
);
455 if (TREE_CODE (TREE_TYPE (node
)) == POINTER_TYPE
)
457 /* In the case of a pointer, one may want to divide by the
458 size of the pointed-to type. Unfortunately, this not
459 straightforward. The C front-end maps expressions
464 in such a way that the two INTEGER_CST nodes for "5" have
465 different values but identical types. In the latter
466 case, the 5 is multiplied by sizeof (int) in c-common.c
467 (pointer_int_sum) to convert it to a byte address, and
468 yet the type of the node is left unchanged. Argh. What
469 is consistent though is that the number value corresponds
470 to bytes (UNITS) offset.
472 NB: Neither of the following divisors can be trivially
473 used to recover the original literal:
475 TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (node)))
476 TYPE_PRECISION (TREE_TYPE (TREE_TYPE (node))) */
477 pp_wide_integer (buffer
, TREE_INT_CST_LOW (node
));
478 pp_string (buffer
, "B"); /* pseudo-unit */
480 else if (! host_integerp (node
, 0))
484 if (tree_int_cst_sgn (val
) < 0)
486 pp_character (buffer
, '-');
487 val
= build_int_cst_wide (NULL_TREE
,
488 -TREE_INT_CST_LOW (val
),
489 ~TREE_INT_CST_HIGH (val
)
490 + !TREE_INT_CST_LOW (val
));
492 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
495 static char format
[10]; /* "%x%09999x\0" */
497 sprintf (format
, "%%x%%0%dx", HOST_BITS_PER_INT
/ 4);
498 sprintf (pp_buffer (buffer
)->digit_buffer
, format
,
499 TREE_INT_CST_HIGH (val
),
500 TREE_INT_CST_LOW (val
));
501 pp_string (buffer
, pp_buffer (buffer
)->digit_buffer
);
505 pp_wide_integer (buffer
, TREE_INT_CST_LOW (node
));
509 /* Code copied from print_node. */
512 if (TREE_OVERFLOW (node
))
513 pp_string (buffer
, " overflow");
515 #if !defined(REAL_IS_NOT_DOUBLE) || defined(REAL_ARITHMETIC)
516 d
= TREE_REAL_CST (node
);
517 if (REAL_VALUE_ISINF (d
))
518 pp_string (buffer
, " Inf");
519 else if (REAL_VALUE_ISNAN (d
))
520 pp_string (buffer
, " Nan");
524 real_to_decimal (string
, &d
, sizeof (string
), 0, 1);
525 pp_string (buffer
, string
);
530 unsigned char *p
= (unsigned char *) &TREE_REAL_CST (node
);
531 pp_string (buffer
, "0x");
532 for (i
= 0; i
< sizeof TREE_REAL_CST (node
); i
++)
533 output_formatted_integer (buffer
, "%02x", *p
++);
540 pp_string (buffer
, "__complex__ (");
541 dump_generic_node (buffer
, TREE_REALPART (node
), spc
, flags
, false);
542 pp_string (buffer
, ", ");
543 dump_generic_node (buffer
, TREE_IMAGPART (node
), spc
, flags
, false);
544 pp_string (buffer
, ")");
548 pp_string (buffer
, "\"");
549 pretty_print_string (buffer
, TREE_STRING_POINTER (node
));
550 pp_string (buffer
, "\"");
556 pp_string (buffer
, "{ ");
557 for (elt
= TREE_VECTOR_CST_ELTS (node
); elt
; elt
= TREE_CHAIN (elt
))
559 dump_generic_node (buffer
, TREE_VALUE (elt
), spc
, flags
, false);
560 if (TREE_CHAIN (elt
))
561 pp_string (buffer
, ", ");
563 pp_string (buffer
, " }");
572 dump_decl_name (buffer
, node
, flags
);
576 if (DECL_NAME (node
))
577 dump_decl_name (buffer
, node
, flags
);
578 else if (LABEL_DECL_UID (node
) != -1)
579 pp_printf (buffer
, "<L" HOST_WIDE_INT_PRINT_DEC
">",
580 LABEL_DECL_UID (node
));
582 pp_printf (buffer
, "<D%u>", DECL_UID (node
));
586 if (DECL_IS_BUILTIN (node
))
588 /* Don't print the declaration of built-in types. */
591 if (DECL_NAME (node
))
592 dump_decl_name (buffer
, node
, flags
);
595 if ((TREE_CODE (TREE_TYPE (node
)) == RECORD_TYPE
596 || TREE_CODE (TREE_TYPE (node
)) == UNION_TYPE
)
597 && TYPE_METHODS (TREE_TYPE (node
)))
599 /* The type is a c++ class: all structures have at least
601 pp_string (buffer
, "class ");
602 dump_generic_node (buffer
, TREE_TYPE (node
), spc
, flags
, false);
607 (TREE_CODE (TREE_TYPE (node
)) == UNION_TYPE
608 ? "union" : "struct "));
609 dump_generic_node (buffer
, TREE_TYPE (node
), spc
, flags
, false);
618 dump_decl_name (buffer
, node
, flags
);
622 pp_string (buffer
, "<retval>");
626 op0
= TREE_OPERAND (node
, 0);
628 if (TREE_CODE (op0
) == INDIRECT_REF
)
630 op0
= TREE_OPERAND (op0
, 0);
633 if (op_prio (op0
) < op_prio (node
))
634 pp_character (buffer
, '(');
635 dump_generic_node (buffer
, op0
, spc
, flags
, false);
636 if (op_prio (op0
) < op_prio (node
))
637 pp_character (buffer
, ')');
638 pp_string (buffer
, str
);
639 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
641 if (TREE_CODE (op0
) != VALUE_HANDLE
)
643 op0
= component_ref_field_offset (node
);
644 if (op0
&& TREE_CODE (op0
) != INTEGER_CST
)
646 pp_string (buffer
, "{off: ");
647 dump_generic_node (buffer
, op0
, spc
, flags
, false);
648 pp_character (buffer
, '}');
654 pp_string (buffer
, "BIT_FIELD_REF <");
655 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
656 pp_string (buffer
, ", ");
657 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
658 pp_string (buffer
, ", ");
659 dump_generic_node (buffer
, TREE_OPERAND (node
, 2), spc
, flags
, false);
660 pp_string (buffer
, ">");
664 case ARRAY_RANGE_REF
:
665 op0
= TREE_OPERAND (node
, 0);
666 if (op_prio (op0
) < op_prio (node
))
667 pp_character (buffer
, '(');
668 dump_generic_node (buffer
, op0
, spc
, flags
, false);
669 if (op_prio (op0
) < op_prio (node
))
670 pp_character (buffer
, ')');
671 pp_character (buffer
, '[');
672 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
673 if (TREE_CODE (node
) == ARRAY_RANGE_REF
)
674 pp_string (buffer
, " ...");
675 pp_character (buffer
, ']');
677 op0
= array_ref_low_bound (node
);
678 op1
= array_ref_element_size (node
);
680 if (!integer_zerop (op0
)
681 || (TYPE_SIZE_UNIT (TREE_TYPE (node
))
682 && !operand_equal_p (op1
, TYPE_SIZE_UNIT (TREE_TYPE (node
)), 0)))
684 pp_string (buffer
, "{lb: ");
685 dump_generic_node (buffer
, op0
, spc
, flags
, false);
686 pp_string (buffer
, " sz: ");
687 dump_generic_node (buffer
, op1
, spc
, flags
, false);
688 pp_character (buffer
, '}');
695 bool is_struct_init
= FALSE
;
696 pp_character (buffer
, '{');
697 lnode
= CONSTRUCTOR_ELTS (node
);
698 if (TREE_CODE (TREE_TYPE (node
)) == RECORD_TYPE
699 || TREE_CODE (TREE_TYPE (node
)) == UNION_TYPE
)
700 is_struct_init
= TRUE
;
701 while (lnode
&& lnode
!= error_mark_node
)
704 if (TREE_PURPOSE (lnode
) && is_struct_init
)
706 pp_character (buffer
, '.');
707 dump_generic_node (buffer
, TREE_PURPOSE (lnode
), spc
, flags
, false);
708 pp_string (buffer
, "=");
710 val
= TREE_VALUE (lnode
);
711 if (val
&& TREE_CODE (val
) == ADDR_EXPR
)
712 if (TREE_CODE (TREE_OPERAND (val
, 0)) == FUNCTION_DECL
)
713 val
= TREE_OPERAND (val
, 0);
714 if (val
&& TREE_CODE (val
) == FUNCTION_DECL
)
716 dump_decl_name (buffer
, val
, flags
);
720 dump_generic_node (buffer
, TREE_VALUE (lnode
), spc
, flags
, false);
722 lnode
= TREE_CHAIN (lnode
);
723 if (lnode
&& TREE_CODE (lnode
) == TREE_LIST
)
725 pp_character (buffer
, ',');
729 pp_character (buffer
, '}');
736 if (flags
& TDF_SLIM
)
738 pp_string (buffer
, "<COMPOUND_EXPR>");
742 dump_generic_node (buffer
, TREE_OPERAND (node
, 0),
743 spc
, flags
, dumping_stmts
);
745 newline_and_indent (buffer
, spc
);
748 pp_character (buffer
, ',');
752 for (tp
= &TREE_OPERAND (node
, 1);
753 TREE_CODE (*tp
) == COMPOUND_EXPR
;
754 tp
= &TREE_OPERAND (*tp
, 1))
756 dump_generic_node (buffer
, TREE_OPERAND (*tp
, 0),
757 spc
, flags
, dumping_stmts
);
759 newline_and_indent (buffer
, spc
);
762 pp_character (buffer
, ',');
767 dump_generic_node (buffer
, *tp
, spc
, flags
, dumping_stmts
);
773 tree_stmt_iterator si
;
776 if ((flags
& TDF_SLIM
) || !dumping_stmts
)
778 pp_string (buffer
, "<STATEMENT_LIST>");
782 for (si
= tsi_start (node
); !tsi_end_p (si
); tsi_next (&si
))
785 newline_and_indent (buffer
, spc
);
788 dump_generic_node (buffer
, tsi_stmt (si
), spc
, flags
, true);
795 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
797 pp_character (buffer
, '=');
799 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
803 pp_string (buffer
, "TARGET_EXPR <");
804 dump_generic_node (buffer
, TARGET_EXPR_SLOT (node
), spc
, flags
, false);
805 pp_character (buffer
, ',');
807 dump_generic_node (buffer
, TARGET_EXPR_INITIAL (node
), spc
, flags
, false);
808 pp_character (buffer
, '>');
812 print_declaration (buffer
, DECL_EXPR_DECL (node
), spc
, flags
);
817 if (TREE_TYPE (node
) == NULL
|| TREE_TYPE (node
) == void_type_node
)
819 pp_string (buffer
, "if (");
820 dump_generic_node (buffer
, COND_EXPR_COND (node
), spc
, flags
, false);
821 pp_character (buffer
, ')');
822 /* The lowered cond_exprs should always be printed in full. */
823 if (COND_EXPR_THEN (node
)
824 && TREE_CODE (COND_EXPR_THEN (node
)) == GOTO_EXPR
825 && COND_EXPR_ELSE (node
)
826 && TREE_CODE (COND_EXPR_ELSE (node
)) == GOTO_EXPR
)
829 dump_generic_node (buffer
, COND_EXPR_THEN (node
), 0, flags
, true);
830 pp_string (buffer
, " else ");
831 dump_generic_node (buffer
, COND_EXPR_ELSE (node
), 0, flags
, true);
833 else if (!(flags
& TDF_SLIM
))
835 /* Output COND_EXPR_THEN. */
836 if (COND_EXPR_THEN (node
))
838 newline_and_indent (buffer
, spc
+2);
839 pp_character (buffer
, '{');
840 newline_and_indent (buffer
, spc
+4);
841 dump_generic_node (buffer
, COND_EXPR_THEN (node
), spc
+4,
843 newline_and_indent (buffer
, spc
+2);
844 pp_character (buffer
, '}');
847 /* Output COND_EXPR_ELSE. */
848 if (COND_EXPR_ELSE (node
))
850 newline_and_indent (buffer
, spc
);
851 pp_string (buffer
, "else");
852 newline_and_indent (buffer
, spc
+2);
853 pp_character (buffer
, '{');
854 newline_and_indent (buffer
, spc
+4);
855 dump_generic_node (buffer
, COND_EXPR_ELSE (node
), spc
+4,
857 newline_and_indent (buffer
, spc
+2);
858 pp_character (buffer
, '}');
865 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
867 pp_character (buffer
, '?');
869 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
871 pp_character (buffer
, ':');
873 dump_generic_node (buffer
, TREE_OPERAND (node
, 2), spc
, flags
, false);
878 pp_character (buffer
, '{');
879 if (!(flags
& TDF_SLIM
))
881 if (BIND_EXPR_VARS (node
))
885 for (op0
= BIND_EXPR_VARS (node
); op0
; op0
= TREE_CHAIN (op0
))
887 print_declaration (buffer
, op0
, spc
+2, flags
);
892 newline_and_indent (buffer
, spc
+2);
893 dump_generic_node (buffer
, BIND_EXPR_BODY (node
), spc
+2, flags
, true);
894 newline_and_indent (buffer
, spc
);
895 pp_character (buffer
, '}');
901 print_call_name (buffer
, node
);
903 /* Print parameters. */
905 pp_character (buffer
, '(');
906 op1
= TREE_OPERAND (node
, 1);
908 dump_generic_node (buffer
, op1
, spc
, flags
, false);
909 pp_character (buffer
, ')');
911 op1
= TREE_OPERAND (node
, 2);
914 pp_string (buffer
, " [static-chain: ");
915 dump_generic_node (buffer
, op1
, spc
, flags
, false);
916 pp_character (buffer
, ']');
919 if (CALL_EXPR_HAS_RETURN_SLOT_ADDR (node
))
920 pp_string (buffer
, " [return slot addr]");
921 if (CALL_EXPR_TAILCALL (node
))
922 pp_string (buffer
, " [tail call]");
925 case WITH_CLEANUP_EXPR
:
929 case CLEANUP_POINT_EXPR
:
930 pp_string (buffer
, "<<cleanup_point ");
931 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
932 pp_string (buffer
, ">>");
935 case PLACEHOLDER_EXPR
:
936 pp_string (buffer
, "<PLACEHOLDER_EXPR ");
937 dump_generic_node (buffer
, TREE_TYPE (node
), spc
, flags
, false);
938 pp_character (buffer
, '>');
941 /* Binary arithmetic and logic expressions. */
962 case TRUTH_ANDIF_EXPR
:
963 case TRUTH_ORIF_EXPR
:
982 const char *op
= op_symbol (node
);
983 op0
= TREE_OPERAND (node
, 0);
984 op1
= TREE_OPERAND (node
, 1);
986 /* When the operands are expressions with less priority,
987 keep semantics of the tree representation. */
988 if (op_prio (op0
) < op_prio (node
))
990 pp_character (buffer
, '(');
991 dump_generic_node (buffer
, op0
, spc
, flags
, false);
992 pp_character (buffer
, ')');
995 dump_generic_node (buffer
, op0
, spc
, flags
, false);
998 pp_string (buffer
, op
);
1001 /* When the operands are expressions with less priority,
1002 keep semantics of the tree representation. */
1003 if (op_prio (op1
) < op_prio (node
))
1005 pp_character (buffer
, '(');
1006 dump_generic_node (buffer
, op1
, spc
, flags
, false);
1007 pp_character (buffer
, ')');
1010 dump_generic_node (buffer
, op1
, spc
, flags
, false);
1014 /* Unary arithmetic and logic expressions. */
1017 case TRUTH_NOT_EXPR
:
1019 case PREDECREMENT_EXPR
:
1020 case PREINCREMENT_EXPR
:
1022 if (TREE_CODE (node
) == ADDR_EXPR
1023 && (TREE_CODE (TREE_OPERAND (node
, 0)) == STRING_CST
1024 || TREE_CODE (TREE_OPERAND (node
, 0)) == FUNCTION_DECL
))
1025 ; /* Do not output '&' for strings and function pointers. */
1027 pp_string (buffer
, op_symbol (node
));
1029 if (op_prio (TREE_OPERAND (node
, 0)) < op_prio (node
))
1031 pp_character (buffer
, '(');
1032 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1033 pp_character (buffer
, ')');
1036 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1039 case POSTDECREMENT_EXPR
:
1040 case POSTINCREMENT_EXPR
:
1041 if (op_prio (TREE_OPERAND (node
, 0)) < op_prio (node
))
1043 pp_character (buffer
, '(');
1044 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1045 pp_character (buffer
, ')');
1048 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1049 pp_string (buffer
, op_symbol (node
));
1053 pp_string (buffer
, "MIN_EXPR <");
1054 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1055 pp_string (buffer
, ", ");
1056 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
1057 pp_character (buffer
, '>');
1061 pp_string (buffer
, "MAX_EXPR <");
1062 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1063 pp_string (buffer
, ", ");
1064 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
1065 pp_character (buffer
, '>');
1069 pp_string (buffer
, "ABS_EXPR <");
1070 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1071 pp_character (buffer
, '>');
1078 case FIX_TRUNC_EXPR
:
1080 case FIX_FLOOR_EXPR
:
1081 case FIX_ROUND_EXPR
:
1085 type
= TREE_TYPE (node
);
1086 op0
= TREE_OPERAND (node
, 0);
1087 if (type
!= TREE_TYPE (op0
))
1089 pp_character (buffer
, '(');
1090 dump_generic_node (buffer
, type
, spc
, flags
, false);
1091 pp_string (buffer
, ") ");
1093 if (op_prio (op0
) < op_prio (node
))
1094 pp_character (buffer
, '(');
1095 dump_generic_node (buffer
, op0
, spc
, flags
, false);
1096 if (op_prio (op0
) < op_prio (node
))
1097 pp_character (buffer
, ')');
1100 case VIEW_CONVERT_EXPR
:
1101 pp_string (buffer
, "VIEW_CONVERT_EXPR<");
1102 dump_generic_node (buffer
, TREE_TYPE (node
), spc
, flags
, false);
1103 pp_string (buffer
, ">(");
1104 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1105 pp_character (buffer
, ')');
1108 case NON_LVALUE_EXPR
:
1109 pp_string (buffer
, "NON_LVALUE_EXPR <");
1110 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1111 pp_character (buffer
, '>');
1115 pp_string (buffer
, "SAVE_EXPR <");
1116 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1117 pp_character (buffer
, '>');
1121 pp_string (buffer
, "COMPLEX_EXPR <");
1122 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1123 pp_string (buffer
, ", ");
1124 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
1125 pp_string (buffer
, ">");
1129 pp_string (buffer
, "CONJ_EXPR <");
1130 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1131 pp_string (buffer
, ">");
1135 pp_string (buffer
, "REALPART_EXPR <");
1136 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1137 pp_string (buffer
, ">");
1141 pp_string (buffer
, "IMAGPART_EXPR <");
1142 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1143 pp_string (buffer
, ">");
1147 pp_string (buffer
, "VA_ARG_EXPR <");
1148 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1149 pp_string (buffer
, ">");
1152 case TRY_FINALLY_EXPR
:
1153 case TRY_CATCH_EXPR
:
1154 pp_string (buffer
, "try");
1155 newline_and_indent (buffer
, spc
+2);
1156 pp_string (buffer
, "{");
1157 newline_and_indent (buffer
, spc
+4);
1158 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
+4, flags
, true);
1159 newline_and_indent (buffer
, spc
+2);
1160 pp_string (buffer
, "}");
1161 newline_and_indent (buffer
, spc
);
1163 (TREE_CODE (node
) == TRY_CATCH_EXPR
) ? "catch" : "finally");
1164 newline_and_indent (buffer
, spc
+2);
1165 pp_string (buffer
, "{");
1166 newline_and_indent (buffer
, spc
+4);
1167 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
+4, flags
, true);
1168 newline_and_indent (buffer
, spc
+2);
1169 pp_string (buffer
, "}");
1174 pp_string (buffer
, "catch (");
1175 dump_generic_node (buffer
, CATCH_TYPES (node
), spc
+2, flags
, false);
1176 pp_string (buffer
, ")");
1177 newline_and_indent (buffer
, spc
+2);
1178 pp_string (buffer
, "{");
1179 newline_and_indent (buffer
, spc
+4);
1180 dump_generic_node (buffer
, CATCH_BODY (node
), spc
+4, flags
, true);
1181 newline_and_indent (buffer
, spc
+2);
1182 pp_string (buffer
, "}");
1186 case EH_FILTER_EXPR
:
1187 pp_string (buffer
, "<<<eh_filter (");
1188 dump_generic_node (buffer
, EH_FILTER_TYPES (node
), spc
+2, flags
, false);
1189 pp_string (buffer
, ")>>>");
1190 newline_and_indent (buffer
, spc
+2);
1191 pp_string (buffer
, "{");
1192 newline_and_indent (buffer
, spc
+4);
1193 dump_generic_node (buffer
, EH_FILTER_FAILURE (node
), spc
+4, flags
, true);
1194 newline_and_indent (buffer
, spc
+2);
1195 pp_string (buffer
, "}");
1200 op0
= TREE_OPERAND (node
, 0);
1201 /* If this is for break or continue, don't bother printing it. */
1202 if (DECL_NAME (op0
))
1204 const char *name
= IDENTIFIER_POINTER (DECL_NAME (op0
));
1205 if (strcmp (name
, "break") == 0
1206 || strcmp (name
, "continue") == 0)
1209 dump_generic_node (buffer
, op0
, spc
, flags
, false);
1210 pp_character (buffer
, ':');
1211 if (DECL_NONLOCAL (op0
))
1212 pp_string (buffer
, " [non-local]");
1215 case LABELED_BLOCK_EXPR
:
1216 op0
= LABELED_BLOCK_LABEL (node
);
1217 /* If this is for break or continue, don't bother printing it. */
1218 if (DECL_NAME (op0
))
1220 const char *name
= IDENTIFIER_POINTER (DECL_NAME (op0
));
1221 if (strcmp (name
, "break") == 0
1222 || strcmp (name
, "continue") == 0)
1224 dump_generic_node (buffer
, LABELED_BLOCK_BODY (node
), spc
, flags
, false);
1228 dump_generic_node (buffer
, LABELED_BLOCK_LABEL (node
), spc
, flags
, false);
1229 pp_string (buffer
, ": {");
1230 if (!(flags
& TDF_SLIM
))
1231 newline_and_indent (buffer
, spc
+2);
1232 dump_generic_node (buffer
, LABELED_BLOCK_BODY (node
), spc
+2, flags
, true);
1234 newline_and_indent (buffer
, spc
);
1235 pp_character (buffer
, '}');
1239 case EXIT_BLOCK_EXPR
:
1240 op0
= LABELED_BLOCK_LABEL (EXIT_BLOCK_LABELED_BLOCK (node
));
1241 /* If this is for a break or continue, print it accordingly. */
1242 if (DECL_NAME (op0
))
1244 const char *name
= IDENTIFIER_POINTER (DECL_NAME (op0
));
1245 if (strcmp (name
, "break") == 0
1246 || strcmp (name
, "continue") == 0)
1248 pp_string (buffer
, name
);
1252 pp_string (buffer
, "<<<exit block ");
1253 dump_generic_node (buffer
, op0
, spc
, flags
, false);
1254 pp_string (buffer
, ">>>");
1258 pp_string (buffer
, "<<<exception object>>>");
1262 pp_string (buffer
, "<<<filter object>>>");
1266 pp_string (buffer
, "while (1)");
1267 if (!(flags
& TDF_SLIM
))
1269 newline_and_indent (buffer
, spc
+2);
1270 pp_character (buffer
, '{');
1271 newline_and_indent (buffer
, spc
+4);
1272 dump_generic_node (buffer
, LOOP_EXPR_BODY (node
), spc
+4, flags
, true);
1273 newline_and_indent (buffer
, spc
+2);
1274 pp_character (buffer
, '}');
1280 pp_string (buffer
, "return");
1281 op0
= TREE_OPERAND (node
, 0);
1285 if (TREE_CODE (op0
) == MODIFY_EXPR
)
1286 dump_generic_node (buffer
, TREE_OPERAND (op0
, 1), spc
, flags
, false);
1288 dump_generic_node (buffer
, op0
, spc
, flags
, false);
1293 pp_string (buffer
, "if (");
1294 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1295 pp_string (buffer
, ") break");
1299 pp_string (buffer
, "switch (");
1300 dump_generic_node (buffer
, SWITCH_COND (node
), spc
, flags
, false);
1301 pp_character (buffer
, ')');
1302 if (!(flags
& TDF_SLIM
))
1304 newline_and_indent (buffer
, spc
+2);
1305 pp_character (buffer
, '{');
1306 if (SWITCH_BODY (node
))
1308 newline_and_indent (buffer
, spc
+4);
1309 dump_generic_node (buffer
, SWITCH_BODY (node
), spc
+4, flags
, true);
1313 tree vec
= SWITCH_LABELS (node
);
1314 size_t i
, n
= TREE_VEC_LENGTH (vec
);
1315 for (i
= 0; i
< n
; ++i
)
1317 tree elt
= TREE_VEC_ELT (vec
, i
);
1318 newline_and_indent (buffer
, spc
+4);
1319 dump_generic_node (buffer
, elt
, spc
+4, flags
, false);
1320 pp_string (buffer
, " goto ");
1321 dump_generic_node (buffer
, CASE_LABEL (elt
), spc
+4, flags
, true);
1322 pp_semicolon (buffer
);
1325 newline_and_indent (buffer
, spc
+2);
1326 pp_character (buffer
, '}');
1332 op0
= GOTO_DESTINATION (node
);
1333 if (TREE_CODE (op0
) != SSA_NAME
1337 const char *name
= IDENTIFIER_POINTER (DECL_NAME (op0
));
1338 if (strcmp (name
, "break") == 0
1339 || strcmp (name
, "continue") == 0)
1341 pp_string (buffer
, name
);
1345 pp_string (buffer
, "goto ");
1346 dump_generic_node (buffer
, op0
, spc
, flags
, false);
1350 pp_string (buffer
, "resx");
1351 /* ??? Any sensible way to present the eh region? */
1355 pp_string (buffer
, "__asm__");
1356 if (ASM_VOLATILE_P (node
))
1357 pp_string (buffer
, " __volatile__");
1358 pp_character (buffer
, '(');
1359 dump_generic_node (buffer
, ASM_STRING (node
), spc
, flags
, false);
1360 pp_character (buffer
, ':');
1361 dump_generic_node (buffer
, ASM_OUTPUTS (node
), spc
, flags
, false);
1362 pp_character (buffer
, ':');
1363 dump_generic_node (buffer
, ASM_INPUTS (node
), spc
, flags
, false);
1364 if (ASM_CLOBBERS (node
))
1366 pp_character (buffer
, ':');
1367 dump_generic_node (buffer
, ASM_CLOBBERS (node
), spc
, flags
, false);
1369 pp_string (buffer
, ")");
1372 case CASE_LABEL_EXPR
:
1373 if (CASE_LOW (node
) && CASE_HIGH (node
))
1375 pp_string (buffer
, "case ");
1376 dump_generic_node (buffer
, CASE_LOW (node
), spc
, flags
, false);
1377 pp_string (buffer
, " ... ");
1378 dump_generic_node (buffer
, CASE_HIGH (node
), spc
, flags
, false);
1380 else if (CASE_LOW (node
))
1382 pp_string (buffer
, "case ");
1383 dump_generic_node (buffer
, CASE_LOW (node
), spc
, flags
, false);
1386 pp_string (buffer
, "default ");
1387 pp_character (buffer
, ':');
1391 pp_string (buffer
, "OBJ_TYPE_REF(");
1392 dump_generic_node (buffer
, OBJ_TYPE_REF_EXPR (node
), spc
, flags
, false);
1393 pp_character (buffer
, ';');
1394 dump_generic_node (buffer
, OBJ_TYPE_REF_OBJECT (node
), spc
, flags
, false);
1395 pp_character (buffer
, '-');
1396 pp_character (buffer
, '>');
1397 dump_generic_node (buffer
, OBJ_TYPE_REF_TOKEN (node
), spc
, flags
, false);
1398 pp_character (buffer
, ')');
1405 dump_generic_node (buffer
, PHI_RESULT (node
), spc
, flags
, false);
1406 pp_string (buffer
, " = PHI <");
1407 for (i
= 0; i
< PHI_NUM_ARGS (node
); i
++)
1409 dump_generic_node (buffer
, PHI_ARG_DEF (node
, i
), spc
, flags
, false);
1410 pp_string (buffer
, "(");
1411 pp_decimal_int (buffer
, PHI_ARG_EDGE (node
, i
)->src
->index
);
1412 pp_string (buffer
, ")");
1413 if (i
< PHI_NUM_ARGS (node
) - 1)
1414 pp_string (buffer
, ", ");
1416 pp_string (buffer
, ">;");
1421 dump_generic_node (buffer
, SSA_NAME_VAR (node
), spc
, flags
, false);
1422 pp_string (buffer
, "_");
1423 pp_decimal_int (buffer
, SSA_NAME_VERSION (node
));
1426 case WITH_SIZE_EXPR
:
1427 pp_string (buffer
, "WITH_SIZE_EXPR <");
1428 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1429 pp_string (buffer
, ", ");
1430 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
1431 pp_string (buffer
, ">");
1435 pp_printf (buffer
, "VH.%d", VALUE_HANDLE_ID (node
));
1439 pp_string (buffer
, "scev_known");
1442 case SCEV_NOT_KNOWN
:
1443 pp_string (buffer
, "scev_not_known");
1446 case POLYNOMIAL_CHREC
:
1447 pp_string (buffer
, "{");
1448 dump_generic_node (buffer
, CHREC_LEFT (node
), spc
, flags
, false);
1449 pp_string (buffer
, ", +, ");
1450 dump_generic_node (buffer
, CHREC_RIGHT (node
), spc
, flags
, false);
1451 pp_string (buffer
, "}_");
1452 dump_generic_node (buffer
, CHREC_VAR (node
), spc
, flags
, false);
1460 if (is_stmt
&& is_expr
)
1461 pp_semicolon (buffer
);
1462 pp_write_text_to_stream (buffer
);
1467 /* Print the declaration of a variable. */
1470 print_declaration (pretty_printer
*buffer
, tree t
, int spc
, int flags
)
1474 if (TREE_CODE (t
) == TYPE_DECL
)
1475 pp_string (buffer
, "typedef ");
1477 if (DECL_REGISTER (t
))
1478 pp_string (buffer
, "register ");
1480 if (TREE_PUBLIC (t
) && DECL_EXTERNAL (t
))
1481 pp_string (buffer
, "extern ");
1482 else if (TREE_STATIC (t
))
1483 pp_string (buffer
, "static ");
1485 /* Print the type and name. */
1486 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
1490 /* Print array's type. */
1491 tmp
= TREE_TYPE (t
);
1492 while (TREE_CODE (TREE_TYPE (tmp
)) == ARRAY_TYPE
)
1493 tmp
= TREE_TYPE (tmp
);
1494 dump_generic_node (buffer
, TREE_TYPE (tmp
), spc
, flags
, false);
1496 /* Print variable's name. */
1498 dump_generic_node (buffer
, t
, spc
, flags
, false);
1500 /* Print the dimensions. */
1501 tmp
= TREE_TYPE (t
);
1502 while (TREE_CODE (tmp
) == ARRAY_TYPE
)
1504 pp_character (buffer
, '[');
1505 if (TYPE_DOMAIN (tmp
))
1507 if (TREE_CODE (TYPE_SIZE (tmp
)) == INTEGER_CST
)
1508 pp_wide_integer (buffer
,
1509 TREE_INT_CST_LOW (TYPE_SIZE (tmp
)) /
1510 TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (tmp
))));
1512 dump_generic_node (buffer
, TYPE_SIZE_UNIT (tmp
), spc
, flags
,
1515 pp_character (buffer
, ']');
1516 tmp
= TREE_TYPE (tmp
);
1519 else if (TREE_CODE (t
) == FUNCTION_DECL
)
1521 dump_generic_node (buffer
, TREE_TYPE (TREE_TYPE (t
)), spc
, flags
, false);
1523 dump_decl_name (buffer
, t
, flags
);
1524 dump_function_declaration (buffer
, TREE_TYPE (t
), spc
, flags
);
1528 /* Print type declaration. */
1529 dump_generic_node (buffer
, TREE_TYPE (t
), spc
, flags
, false);
1531 /* Print variable's name. */
1533 dump_generic_node (buffer
, t
, spc
, flags
, false);
1536 /* The initial value of a function serves to determine wether the function
1537 is declared or defined. So the following does not apply to function
1539 if (TREE_CODE (t
) != FUNCTION_DECL
)
1541 /* Print the initial value. */
1542 if (DECL_INITIAL (t
))
1545 pp_character (buffer
, '=');
1547 dump_generic_node (buffer
, DECL_INITIAL (t
), spc
, flags
, false);
1551 pp_character (buffer
, ';');
1555 /* Prints a structure: name, fields, and methods.
1556 FIXME: Still incomplete. */
1559 print_struct_decl (pretty_printer
*buffer
, tree node
, int spc
, int flags
)
1561 /* Print the name of the structure. */
1562 if (TYPE_NAME (node
))
1565 if (TREE_CODE (node
) == RECORD_TYPE
)
1566 pp_string (buffer
, "struct ");
1567 else if ((TREE_CODE (node
) == UNION_TYPE
1568 || TREE_CODE (node
) == QUAL_UNION_TYPE
))
1569 pp_string (buffer
, "union ");
1571 dump_generic_node (buffer
, TYPE_NAME (node
), spc
, 0, false);
1574 /* Print the contents of the structure. */
1575 pp_newline (buffer
);
1577 pp_character (buffer
, '{');
1578 pp_newline (buffer
);
1580 /* Print the fields of the structure. */
1583 tmp
= TYPE_FIELDS (node
);
1586 /* Avoid to print recursively the structure. */
1587 /* FIXME : Not implemented correctly...,
1588 what about the case when we have a cycle in the contain graph? ...
1589 Maybe this could be solved by looking at the scope in which the
1590 structure was declared. */
1591 if (TREE_TYPE (tmp
) != node
1592 || (TREE_CODE (TREE_TYPE (tmp
)) == POINTER_TYPE
1593 && TREE_TYPE (TREE_TYPE (tmp
)) != node
))
1595 print_declaration (buffer
, tmp
, spc
+2, flags
);
1596 pp_newline (buffer
);
1598 tmp
= TREE_CHAIN (tmp
);
1602 pp_character (buffer
, '}');
1605 /* Return the priority of the operator OP.
1607 From lowest to highest precedence with either left-to-right (L-R)
1608 or right-to-left (R-L) associativity]:
1611 2 [R-L] = += -= *= /= %= &= ^= |= <<= >>=
1623 14 [R-L] ! ~ ++ -- + - * & (type) sizeof
1624 15 [L-R] fn() [] -> .
1626 unary +, - and * have higher precedence than the corresponding binary
1635 switch (TREE_CODE (op
))
1650 case TRUTH_ORIF_EXPR
:
1653 case TRUTH_AND_EXPR
:
1654 case TRUTH_ANDIF_EXPR
:
1661 case TRUTH_XOR_EXPR
:
1678 case UNORDERED_EXPR
:
1696 case TRUNC_DIV_EXPR
:
1698 case FLOOR_DIV_EXPR
:
1699 case ROUND_DIV_EXPR
:
1701 case EXACT_DIV_EXPR
:
1702 case TRUNC_MOD_EXPR
:
1704 case FLOOR_MOD_EXPR
:
1705 case ROUND_MOD_EXPR
:
1708 case TRUTH_NOT_EXPR
:
1710 case POSTINCREMENT_EXPR
:
1711 case POSTDECREMENT_EXPR
:
1712 case PREINCREMENT_EXPR
:
1713 case PREDECREMENT_EXPR
:
1720 case FIX_TRUNC_EXPR
:
1722 case FIX_FLOOR_EXPR
:
1723 case FIX_ROUND_EXPR
:
1729 case ARRAY_RANGE_REF
:
1733 /* Special expressions. */
1742 case NON_LVALUE_EXPR
:
1743 return op_prio (TREE_OPERAND (op
, 0));
1746 /* Return an arbitrarily high precedence to avoid surrounding single
1747 VAR_DECLs in ()s. */
1753 /* Return the symbol associated with operator OP. */
1760 switch (TREE_CODE (op
))
1766 case TRUTH_ORIF_EXPR
:
1769 case TRUTH_AND_EXPR
:
1770 case TRUTH_ANDIF_EXPR
:
1776 case TRUTH_XOR_EXPR
:
1786 case UNORDERED_EXPR
:
1836 case TRUTH_NOT_EXPR
:
1843 case TRUNC_DIV_EXPR
:
1850 case FLOOR_DIV_EXPR
:
1853 case ROUND_DIV_EXPR
:
1856 case EXACT_DIV_EXPR
:
1859 case TRUNC_MOD_EXPR
:
1865 case FLOOR_MOD_EXPR
:
1868 case ROUND_MOD_EXPR
:
1871 case PREDECREMENT_EXPR
:
1874 case PREINCREMENT_EXPR
:
1877 case POSTDECREMENT_EXPR
:
1880 case POSTINCREMENT_EXPR
:
1884 return "<<< ??? >>>";
1888 /* Prints the name of a CALL_EXPR. */
1891 print_call_name (pretty_printer
*buffer
, tree node
)
1895 gcc_assert (TREE_CODE (node
) == CALL_EXPR
);
1897 op0
= TREE_OPERAND (node
, 0);
1899 if (TREE_CODE (op0
) == NON_LVALUE_EXPR
)
1900 op0
= TREE_OPERAND (op0
, 0);
1902 switch (TREE_CODE (op0
))
1906 dump_function_name (buffer
, op0
);
1912 dump_generic_node (buffer
, TREE_OPERAND (op0
, 0), 0, 0, false);
1916 pp_string (buffer
, "(");
1917 dump_generic_node (buffer
, TREE_OPERAND (op0
, 0), 0, 0, false);
1918 pp_string (buffer
, ") ? ");
1919 dump_generic_node (buffer
, TREE_OPERAND (op0
, 1), 0, 0, false);
1920 pp_string (buffer
, " : ");
1921 dump_generic_node (buffer
, TREE_OPERAND (op0
, 2), 0, 0, false);
1925 /* The function is a pointer contained in a structure. */
1926 if (TREE_CODE (TREE_OPERAND (op0
, 0)) == INDIRECT_REF
||
1927 TREE_CODE (TREE_OPERAND (op0
, 0)) == VAR_DECL
)
1928 dump_function_name (buffer
, TREE_OPERAND (op0
, 1));
1930 dump_generic_node (buffer
, TREE_OPERAND (op0
, 0), 0, 0, false);
1932 We can have several levels of structures and a function
1933 pointer inside. This is not implemented yet... */
1938 if (TREE_CODE (TREE_OPERAND (op0
, 0)) == VAR_DECL
)
1939 dump_function_name (buffer
, TREE_OPERAND (op0
, 0));
1941 dump_generic_node (buffer
, op0
, 0, 0, false);
1946 dump_generic_node (buffer
, op0
, 0, 0, false);
1954 /* Parses the string STR and replaces new-lines by '\n', tabs by '\t', ... */
1957 pretty_print_string (pretty_printer
*buffer
, const char *str
)
1967 pp_string (buffer
, "\\b");
1971 pp_string (buffer
, "\\f");
1975 pp_string (buffer
, "\\n");
1979 pp_string (buffer
, "\\r");
1983 pp_string (buffer
, "\\t");
1987 pp_string (buffer
, "\\v");
1991 pp_string (buffer
, "\\\\");
1995 pp_string (buffer
, "\\\"");
1999 pp_string (buffer
, "\\'");
2003 pp_string (buffer
, "\\0");
2007 pp_string (buffer
, "\\1");
2011 pp_string (buffer
, "\\2");
2015 pp_string (buffer
, "\\3");
2019 pp_string (buffer
, "\\4");
2023 pp_string (buffer
, "\\5");
2027 pp_string (buffer
, "\\6");
2031 pp_string (buffer
, "\\7");
2035 pp_character (buffer
, str
[0]);
2043 maybe_init_pretty_print (FILE *file
)
2047 pp_construct (&buffer
, /* prefix */NULL
, /* line-width */0);
2048 pp_needs_newline (&buffer
) = true;
2052 buffer
.buffer
->stream
= file
;
2056 newline_and_indent (pretty_printer
*buffer
, int spc
)
2058 pp_newline (buffer
);
2063 dump_vops (pretty_printer
*buffer
, tree stmt
, int spc
, int flags
)
2066 use_operand_p use_p
;
2067 def_operand_p def_p
;
2070 FOR_EACH_SSA_MAYDEF_OPERAND (def_p
, use_p
, stmt
, iter
)
2072 pp_string (buffer
, "# ");
2073 dump_generic_node (buffer
, DEF_FROM_PTR (def_p
),
2074 spc
+ 2, flags
, false);
2075 pp_string (buffer
, " = V_MAY_DEF <");
2076 dump_generic_node (buffer
, USE_FROM_PTR (use_p
),
2077 spc
+ 2, flags
, false);
2078 pp_string (buffer
, ">;");
2079 newline_and_indent (buffer
, spc
);
2082 FOR_EACH_SSA_TREE_OPERAND (def
, stmt
, iter
, SSA_OP_VMUSTDEF
)
2084 pp_string (buffer
, "# V_MUST_DEF <");
2085 dump_generic_node (buffer
, def
, spc
+ 2, flags
, false);
2086 pp_string (buffer
, ">;");
2087 newline_and_indent (buffer
, spc
);
2090 FOR_EACH_SSA_TREE_OPERAND (use
, stmt
, iter
, SSA_OP_VUSE
)
2092 pp_string (buffer
, "# VUSE <");
2093 dump_generic_node (buffer
, use
, spc
+ 2, flags
, false);
2094 pp_string (buffer
, ">;");
2095 newline_and_indent (buffer
, spc
);
2099 /* Dumps basic block BB to FILE with details described by FLAGS and
2100 indented by INDENT spaces. */
2103 dump_generic_bb (FILE *file
, basic_block bb
, int indent
, int flags
)
2105 maybe_init_pretty_print (file
);
2106 dumping_stmts
= true;
2107 dump_generic_bb_buff (&buffer
, bb
, indent
, flags
);
2111 /* Dumps header of basic block BB to buffer BUFFER indented by INDENT
2112 spaces and details described by flags. */
2115 dump_bb_header (pretty_printer
*buffer
, basic_block bb
, int indent
, int flags
)
2120 if (flags
& TDF_BLOCKS
)
2123 pp_string (buffer
, "# BLOCK ");
2124 pp_decimal_int (buffer
, bb
->index
);
2126 if (flags
& TDF_LINENO
)
2128 block_stmt_iterator bsi
;
2130 for (bsi
= bsi_start (bb
); !bsi_end_p (bsi
); bsi_next (&bsi
))
2131 if (get_lineno (bsi_stmt (bsi
)) != -1)
2133 pp_string (buffer
, ", starting at line ");
2134 pp_decimal_int (buffer
, get_lineno (bsi_stmt (bsi
)));
2138 newline_and_indent (buffer
, indent
);
2140 pp_string (buffer
, "# PRED:");
2141 pp_write_text_to_stream (buffer
);
2142 for (e
= bb
->pred
; e
; e
= e
->pred_next
)
2143 if (flags
& TDF_SLIM
)
2145 pp_string (buffer
, " ");
2146 if (e
->src
== ENTRY_BLOCK_PTR
)
2147 pp_string (buffer
, "ENTRY");
2149 pp_decimal_int (buffer
, e
->src
->index
);
2152 dump_edge_info (buffer
->buffer
->stream
, e
, 0);
2153 pp_newline (buffer
);
2157 stmt
= first_stmt (bb
);
2158 if (!stmt
|| TREE_CODE (stmt
) != LABEL_EXPR
)
2160 INDENT (indent
- 2);
2161 pp_string (buffer
, "<bb ");
2162 pp_decimal_int (buffer
, bb
->index
);
2163 pp_string (buffer
, ">:");
2164 pp_newline (buffer
);
2167 pp_write_text_to_stream (buffer
);
2168 check_bb_profile (bb
, buffer
->buffer
->stream
);
2171 /* Dumps end of basic block BB to buffer BUFFER indented by INDENT
2175 dump_bb_end (pretty_printer
*buffer
, basic_block bb
, int indent
, int flags
)
2180 pp_string (buffer
, "# SUCC:");
2181 pp_write_text_to_stream (buffer
);
2182 for (e
= bb
->succ
; e
; e
= e
->succ_next
)
2183 if (flags
& TDF_SLIM
)
2185 pp_string (buffer
, " ");
2186 if (e
->dest
== EXIT_BLOCK_PTR
)
2187 pp_string (buffer
, "EXIT");
2189 pp_decimal_int (buffer
, e
->dest
->index
);
2192 dump_edge_info (buffer
->buffer
->stream
, e
, 1);
2193 pp_newline (buffer
);
2196 /* Dumps phi nodes of basic block BB to buffer BUFFER with details described by
2197 FLAGS indented by INDENT spaces. */
2200 dump_phi_nodes (pretty_printer
*buffer
, basic_block bb
, int indent
, int flags
)
2202 tree phi
= phi_nodes (bb
);
2206 for (; phi
; phi
= PHI_CHAIN (phi
))
2208 if (is_gimple_reg (PHI_RESULT (phi
)) || (flags
& TDF_VOPS
))
2211 pp_string (buffer
, "# ");
2212 dump_generic_node (buffer
, phi
, indent
, flags
, false);
2213 pp_newline (buffer
);
2218 /* Dump jump to basic block BB that is represented implicitly in the cfg
2222 pp_cfg_jump (pretty_printer
*buffer
, basic_block bb
)
2226 stmt
= first_stmt (bb
);
2228 pp_string (buffer
, "goto <bb ");
2229 pp_decimal_int (buffer
, bb
->index
);
2230 pp_string (buffer
, ">");
2231 if (stmt
&& TREE_CODE (stmt
) == LABEL_EXPR
)
2233 pp_string (buffer
, " (");
2234 dump_generic_node (buffer
, LABEL_EXPR_LABEL (stmt
), 0, 0, false);
2235 pp_string (buffer
, ")");
2237 pp_semicolon (buffer
);
2240 /* Dump edges represented implicitly in basic block BB to BUFFER, indented
2241 by INDENT spaces, with details given by FLAGS. */
2244 dump_implicit_edges (pretty_printer
*buffer
, basic_block bb
, int indent
,
2249 /* If there is a fallthru edge, we may need to add an artificial goto to the
2251 for (e
= bb
->succ
; e
; e
= e
->succ_next
)
2252 if (e
->flags
& EDGE_FALLTHRU
)
2254 if (e
&& e
->dest
!= bb
->next_bb
)
2258 if ((flags
& TDF_LINENO
)
2259 #ifdef USE_MAPPED_LOCATION
2260 && e
->goto_locus
!= UNKNOWN_LOCATION
2266 expanded_location goto_xloc
;
2267 #ifdef USE_MAPPED_LOCATION
2268 goto_xloc
= expand_location (e
->goto_locus
);
2270 goto_xloc
= *e
->goto_locus
;
2272 pp_character (buffer
, '[');
2275 pp_string (buffer
, goto_xloc
.file
);
2276 pp_string (buffer
, " : ");
2278 pp_decimal_int (buffer
, goto_xloc
.line
);
2279 pp_string (buffer
, "] ");
2282 pp_cfg_jump (buffer
, e
->dest
);
2283 pp_newline (buffer
);
2287 /* Dumps basic block BB to buffer BUFFER with details described by FLAGS and
2288 indented by INDENT spaces. */
2291 dump_generic_bb_buff (pretty_printer
*buffer
, basic_block bb
,
2292 int indent
, int flags
)
2294 block_stmt_iterator bsi
;
2296 int label_indent
= indent
- 2;
2298 if (label_indent
< 0)
2301 dump_bb_header (buffer
, bb
, indent
, flags
);
2304 dump_phi_nodes (buffer
, bb
, indent
, flags
);
2306 for (bsi
= bsi_start (bb
); !bsi_end_p (bsi
); bsi_next (&bsi
))
2310 stmt
= bsi_stmt (bsi
);
2312 curr_indent
= TREE_CODE (stmt
) == LABEL_EXPR
? label_indent
: indent
;
2314 INDENT (curr_indent
);
2315 dump_generic_node (buffer
, stmt
, curr_indent
, flags
, true);
2316 pp_newline (buffer
);
2319 dump_implicit_edges (buffer
, bb
, indent
, flags
);
2321 if (flags
& TDF_BLOCKS
)
2322 dump_bb_end (buffer
, bb
, indent
, flags
);