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"
35 /* Local functions, macros and variables. */
36 static int op_prio (tree
);
37 static const char *op_symbol (tree
);
38 static void pretty_print_string (pretty_printer
*, const char*);
39 static void print_call_name (pretty_printer
*, tree
);
40 static void newline_and_indent (pretty_printer
*, int);
41 static void maybe_init_pretty_print (FILE *);
42 static void print_declaration (pretty_printer
*, tree
, int, int);
43 static void print_struct_decl (pretty_printer
*, tree
, int, int);
44 static void do_niy (pretty_printer
*, tree
);
45 static void dump_vops (pretty_printer
*, tree
, int, int);
46 static void dump_generic_bb_buff (pretty_printer
*, basic_block
, int, int);
48 #define INDENT(SPACE) do { \
49 int i; for (i = 0; i<SPACE; i++) pp_space (buffer); } while (0)
51 #define NIY do_niy(buffer,node)
53 #define PRINT_FUNCTION_NAME(NODE) pp_printf \
54 (buffer, "%s", TREE_CODE (NODE) == NOP_EXPR ? \
55 lang_hooks.decl_printable_name (TREE_OPERAND (NODE, 0), 1) : \
56 lang_hooks.decl_printable_name (NODE, 1))
58 #define MASK_POINTER(P) ((unsigned)((unsigned long)(P) & 0xffff))
60 static pretty_printer buffer
;
61 static int initialized
= 0;
62 static bool dumping_stmts
;
64 /* Try to print something for an unknown tree code. */
67 do_niy (pretty_printer
*buffer
, tree node
)
71 pp_string (buffer
, "<<< Unknown tree: ");
72 pp_string (buffer
, tree_code_name
[(int) TREE_CODE (node
)]);
74 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (node
))))
76 len
= first_rtl_op (TREE_CODE (node
));
77 for (i
= 0; i
< len
; ++i
)
79 newline_and_indent (buffer
, 2);
80 dump_generic_node (buffer
, TREE_OPERAND (node
, i
), 2, 0, false);
84 pp_string (buffer
, " >>>\n");
88 debug_generic_expr (tree t
)
90 print_generic_expr (stderr
, t
, TDF_VOPS
|TDF_UID
);
91 fprintf (stderr
, "\n");
95 debug_generic_stmt (tree t
)
97 print_generic_stmt (stderr
, t
, TDF_VOPS
|TDF_UID
);
98 fprintf (stderr
, "\n");
101 /* Prints declaration DECL to the FILE with details specified by FLAGS. */
103 print_generic_decl (FILE *file
, tree decl
, int flags
)
105 maybe_init_pretty_print (file
);
106 dumping_stmts
= true;
107 print_declaration (&buffer
, decl
, 2, flags
);
108 pp_write_text_to_stream (&buffer
);
111 /* Print tree T, and its successors, on file FILE. FLAGS specifies details
112 to show in the dump. See TDF_* in tree.h. */
115 print_generic_stmt (FILE *file
, tree t
, int flags
)
117 maybe_init_pretty_print (file
);
118 dumping_stmts
= true;
119 dump_generic_node (&buffer
, t
, 0, flags
, true);
123 /* Print tree T, and its successors, on file FILE. FLAGS specifies details
124 to show in the dump. See TDF_* in tree.h. The output is indented by
128 print_generic_stmt_indented (FILE *file
, tree t
, int flags
, int indent
)
132 maybe_init_pretty_print (file
);
133 dumping_stmts
= true;
135 for (i
= 0; i
< indent
; i
++)
137 dump_generic_node (&buffer
, t
, indent
, flags
, true);
141 /* Print a single expression T on file FILE. FLAGS specifies details to show
142 in the dump. See TDF_* in tree.h. */
145 print_generic_expr (FILE *file
, tree t
, int flags
)
147 maybe_init_pretty_print (file
);
148 dumping_stmts
= false;
149 dump_generic_node (&buffer
, t
, 0, flags
, false);
152 /* Dump the name of a _DECL node and its DECL_UID if TDF_UID is set
156 dump_decl_name (pretty_printer
*buffer
, tree node
, int flags
)
158 if (DECL_NAME (node
))
159 pp_tree_identifier (buffer
, DECL_NAME (node
));
161 if ((flags
& TDF_UID
)
162 || DECL_NAME (node
) == NULL_TREE
)
164 if (TREE_CODE (node
) == LABEL_DECL
165 && LABEL_DECL_UID (node
) != -1)
166 pp_printf (buffer
, "<L" HOST_WIDE_INT_PRINT_DEC
">",
167 LABEL_DECL_UID (node
));
169 pp_printf (buffer
, "<D%u>", DECL_UID (node
));
173 /* Dump the node NODE on the pretty_printer BUFFER, SPC spaces of indent.
174 FLAGS specifies details to show in the dump (see TDF_* in tree.h). If
175 IS_STMT is true, the object printed is considered to be a statement
176 and it is terminated by ';' if appropriate. */
179 dump_generic_node (pretty_printer
*buffer
, tree node
, int spc
, int flags
,
187 if (node
== NULL_TREE
)
190 is_expr
= EXPR_P (node
);
192 if (TREE_CODE (node
) != ERROR_MARK
193 && is_gimple_stmt (node
)
194 && (flags
& TDF_VOPS
)
196 dump_vops (buffer
, node
, spc
, flags
);
199 && (flags
& TDF_LINENO
)
200 && EXPR_HAS_LOCATION (node
))
202 pp_character (buffer
, '[');
203 if (EXPR_FILENAME (node
))
205 pp_string (buffer
, EXPR_FILENAME (node
));
206 pp_string (buffer
, " : ");
208 pp_decimal_int (buffer
, EXPR_LINENO (node
));
209 pp_string (buffer
, "] ");
212 switch (TREE_CODE (node
))
215 pp_string (buffer
, "<<< error >>>");
218 case IDENTIFIER_NODE
:
219 pp_tree_identifier (buffer
, node
);
223 while (node
&& node
!= error_mark_node
)
225 if (TREE_PURPOSE (node
))
227 dump_generic_node (buffer
, TREE_PURPOSE (node
), spc
, flags
, false);
230 dump_generic_node (buffer
, TREE_VALUE (node
), spc
, flags
, false);
231 node
= TREE_CHAIN (node
);
232 if (node
&& TREE_CODE (node
) == TREE_LIST
)
234 pp_character (buffer
, ',');
241 dump_generic_node (buffer
, BINFO_TYPE (node
), spc
, flags
, false);
257 unsigned int quals
= TYPE_QUALS (node
);
260 if (quals
& TYPE_QUAL_CONST
)
261 pp_string (buffer
, "const ");
262 else if (quals
& TYPE_QUAL_VOLATILE
)
263 pp_string (buffer
, "volatile ");
264 else if (quals
& TYPE_QUAL_RESTRICT
)
265 pp_string (buffer
, "restrict ");
267 class = TREE_CODE_CLASS (TREE_CODE (node
));
271 if (DECL_NAME (node
))
272 dump_decl_name (buffer
, node
, flags
);
274 pp_string (buffer
, "<unnamed type decl>");
276 else if (class == 't')
278 if (TYPE_NAME (node
))
280 if (TREE_CODE (TYPE_NAME (node
)) == IDENTIFIER_NODE
)
281 pp_tree_identifier (buffer
, TYPE_NAME (node
));
282 else if (TREE_CODE (TYPE_NAME (node
)) == TYPE_DECL
283 && DECL_NAME (TYPE_NAME (node
)))
284 dump_decl_name (buffer
, TYPE_NAME (node
), flags
);
286 pp_string (buffer
, "<unnamed type>");
289 pp_string (buffer
, "<unnamed type>");
296 str
= (TREE_CODE (node
) == POINTER_TYPE
? "*" : "&");
298 if (TREE_CODE (TREE_TYPE (node
)) == FUNCTION_TYPE
)
300 tree fnode
= TREE_TYPE (node
);
301 dump_generic_node (buffer
, TREE_TYPE (fnode
), spc
, flags
, false);
303 pp_character (buffer
, '(');
304 pp_string (buffer
, str
);
305 if (TYPE_NAME (node
) && DECL_NAME (TYPE_NAME (node
)))
306 dump_decl_name (buffer
, TYPE_NAME (node
), flags
);
308 pp_printf (buffer
, "<T%x>", TYPE_UID (node
));
310 pp_character (buffer
, ')');
312 pp_character (buffer
, '(');
313 /* Print the argument types. The last element in the list is a
314 VOID_TYPE. The following avoid to print the last element. */
316 tree tmp
= TYPE_ARG_TYPES (fnode
);
317 while (tmp
&& TREE_CHAIN (tmp
) && tmp
!= error_mark_node
)
319 dump_generic_node (buffer
, TREE_VALUE (tmp
), spc
, flags
, false);
320 tmp
= TREE_CHAIN (tmp
);
321 if (TREE_CHAIN (tmp
) && TREE_CODE (TREE_CHAIN (tmp
)) == TREE_LIST
)
323 pp_character (buffer
, ',');
328 pp_character (buffer
, ')');
332 unsigned int quals
= TYPE_QUALS (node
);
334 dump_generic_node (buffer
, TREE_TYPE (node
), spc
, flags
, false);
336 pp_string (buffer
, str
);
338 if (quals
& TYPE_QUAL_CONST
)
339 pp_string (buffer
, " const");
340 else if (quals
& TYPE_QUAL_VOLATILE
)
341 pp_string (buffer
, "volatile");
342 else if (quals
& TYPE_QUAL_RESTRICT
)
343 pp_string (buffer
, " restrict");
352 dump_decl_name (buffer
, TYPE_NAME (TYPE_METHOD_BASETYPE (node
)), flags
);
353 pp_string (buffer
, "::");
364 /* Print the array type. */
365 dump_generic_node (buffer
, TREE_TYPE (node
), spc
, flags
, false);
367 /* Print the dimensions. */
369 while (tmp
&& TREE_CODE (tmp
) == ARRAY_TYPE
)
371 pp_character (buffer
, '[');
374 tree size
= TYPE_SIZE (tmp
);
375 if (TREE_CODE (size
) == INTEGER_CST
)
376 pp_wide_integer (buffer
,
377 TREE_INT_CST_LOW (TYPE_SIZE (tmp
)) /
378 TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (tmp
))));
379 else if (TREE_CODE (size
) == MULT_EXPR
)
380 dump_generic_node (buffer
, TREE_OPERAND (size
, 0), spc
, flags
, false);
383 pp_character (buffer
, ']');
384 tmp
= TREE_TYPE (tmp
);
395 /* Print the name of the structure. */
396 if (TREE_CODE (node
) == RECORD_TYPE
)
397 pp_string (buffer
, "struct ");
398 else if (TREE_CODE (node
) == UNION_TYPE
)
399 pp_string (buffer
, "union ");
401 if (TYPE_NAME (node
))
402 dump_generic_node (buffer
, TYPE_NAME (node
), spc
, flags
, false);
404 print_struct_decl (buffer
, node
, spc
, flags
);
407 case QUAL_UNION_TYPE
:
417 if (TREE_CODE (TREE_TYPE (node
)) == POINTER_TYPE
)
419 /* In the case of a pointer, one may want to divide by the
420 size of the pointed-to type. Unfortunately, this not
421 straightforward. The C front-end maps expressions
426 in such a way that the two INTEGER_CST nodes for "5" have
427 different values but identical types. In the latter
428 case, the 5 is multiplied by sizeof (int) in c-common.c
429 (pointer_int_sum) to convert it to a byte address, and
430 yet the type of the node is left unchanged. Argh. What
431 is consistent though is that the number value corresponds
432 to bytes (UNITS) offset.
434 NB: Neither of the following divisors can be trivially
435 used to recover the original literal:
437 TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (node)))
438 TYPE_PRECISION (TREE_TYPE (TREE_TYPE (node))) */
439 pp_wide_integer (buffer
, TREE_INT_CST_LOW (node
));
440 pp_string (buffer
, "B"); /* pseudo-unit */
442 else if (! host_integerp (node
, 0))
446 if (tree_int_cst_sgn (val
) < 0)
448 pp_character (buffer
, '-');
449 val
= build_int_2 (-TREE_INT_CST_LOW (val
),
450 ~TREE_INT_CST_HIGH (val
)
451 + !TREE_INT_CST_LOW (val
));
453 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
456 static char format
[10]; /* "%x%09999x\0" */
458 sprintf (format
, "%%x%%0%dx", HOST_BITS_PER_INT
/ 4);
459 sprintf (pp_buffer (buffer
)->digit_buffer
, format
,
460 TREE_INT_CST_HIGH (val
),
461 TREE_INT_CST_LOW (val
));
462 pp_string (buffer
, pp_buffer (buffer
)->digit_buffer
);
466 pp_wide_integer (buffer
, TREE_INT_CST_LOW (node
));
470 /* Code copied from print_node. */
473 if (TREE_OVERFLOW (node
))
474 pp_string (buffer
, " overflow");
476 #if !defined(REAL_IS_NOT_DOUBLE) || defined(REAL_ARITHMETIC)
477 d
= TREE_REAL_CST (node
);
478 if (REAL_VALUE_ISINF (d
))
479 pp_string (buffer
, " Inf");
480 else if (REAL_VALUE_ISNAN (d
))
481 pp_string (buffer
, " Nan");
485 real_to_decimal (string
, &d
, sizeof (string
), 0, 1);
486 pp_string (buffer
, string
);
491 unsigned char *p
= (unsigned char *) &TREE_REAL_CST (node
);
492 pp_string (buffer
, "0x");
493 for (i
= 0; i
< sizeof TREE_REAL_CST (node
); i
++)
494 output_formatted_integer (buffer
, "%02x", *p
++);
501 pp_string (buffer
, "__complex__ (");
502 dump_generic_node (buffer
, TREE_REALPART (node
), spc
, flags
, false);
503 pp_string (buffer
, ", ");
504 dump_generic_node (buffer
, TREE_IMAGPART (node
), spc
, flags
, false);
505 pp_string (buffer
, ")");
509 pp_string (buffer
, "\"");
510 pretty_print_string (buffer
, TREE_STRING_POINTER (node
));
511 pp_string (buffer
, "\"");
517 pp_string (buffer
, "{ ");
518 for (elt
= TREE_VECTOR_CST_ELTS (node
); elt
; elt
= TREE_CHAIN (elt
))
520 dump_generic_node (buffer
, TREE_VALUE (elt
), spc
, flags
, false);
521 if (TREE_CHAIN (elt
))
522 pp_string (buffer
, ", ");
524 pp_string (buffer
, " }");
533 dump_decl_name (buffer
, node
, flags
);
537 if (DECL_NAME (node
))
538 dump_decl_name (buffer
, node
, flags
);
539 else if (LABEL_DECL_UID (node
) != -1)
540 pp_printf (buffer
, "<L" HOST_WIDE_INT_PRINT_DEC
">",
541 LABEL_DECL_UID (node
));
543 pp_printf (buffer
, "<D%u>", DECL_UID (node
));
547 if (strcmp (DECL_SOURCE_FILE (node
), "<built-in>") == 0)
549 /* Don't print the declaration of built-in types. */
552 if (DECL_NAME (node
))
554 dump_decl_name (buffer
, node
, flags
);
558 if (TYPE_METHODS (TREE_TYPE (node
)))
560 /* The type is a c++ class: all structures have at least
562 pp_string (buffer
, "class ");
563 dump_generic_node (buffer
, TREE_TYPE (node
), spc
, flags
, false);
567 pp_string (buffer
, "struct ");
568 dump_generic_node (buffer
, TREE_TYPE (node
), spc
, flags
, false);
569 pp_character (buffer
, ';');
579 dump_decl_name (buffer
, node
, flags
);
583 pp_string (buffer
, "<retval>");
587 op0
= TREE_OPERAND (node
, 0);
589 if (TREE_CODE (op0
) == INDIRECT_REF
)
591 op0
= TREE_OPERAND (op0
, 0);
594 if (op_prio (op0
) < op_prio (node
))
595 pp_character (buffer
, '(');
596 dump_generic_node (buffer
, op0
, spc
, flags
, false);
597 if (op_prio (op0
) < op_prio (node
))
598 pp_character (buffer
, ')');
599 pp_string (buffer
, str
);
600 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
604 pp_string (buffer
, "BIT_FIELD_REF <");
605 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
606 pp_string (buffer
, ", ");
607 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
608 pp_string (buffer
, ", ");
609 dump_generic_node (buffer
, TREE_OPERAND (node
, 2), spc
, flags
, false);
610 pp_string (buffer
, ">");
618 op0
= TREE_OPERAND (node
, 0);
619 if (op_prio (op0
) < op_prio (node
))
620 pp_character (buffer
, '(');
621 dump_generic_node (buffer
, op0
, spc
, flags
, false);
622 if (op_prio (op0
) < op_prio (node
))
623 pp_character (buffer
, ')');
624 pp_character (buffer
, '[');
625 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
626 pp_character (buffer
, ']');
629 case ARRAY_RANGE_REF
:
636 bool is_struct_init
= FALSE
;
637 pp_character (buffer
, '{');
638 lnode
= CONSTRUCTOR_ELTS (node
);
639 if (TREE_CODE (TREE_TYPE (node
)) == RECORD_TYPE
640 || TREE_CODE (TREE_TYPE (node
)) == UNION_TYPE
)
641 is_struct_init
= TRUE
;
642 while (lnode
&& lnode
!= error_mark_node
)
645 if (TREE_PURPOSE (lnode
) && is_struct_init
)
647 pp_character (buffer
, '.');
648 dump_generic_node (buffer
, TREE_PURPOSE (lnode
), spc
, flags
, false);
649 pp_string (buffer
, "=");
651 val
= TREE_VALUE (lnode
);
652 if (val
&& TREE_CODE (val
) == ADDR_EXPR
)
653 if (TREE_CODE (TREE_OPERAND (val
, 0)) == FUNCTION_DECL
)
654 val
= TREE_OPERAND (val
, 0);
655 if (val
&& TREE_CODE (val
) == FUNCTION_DECL
)
657 dump_decl_name (buffer
, val
, flags
);
661 dump_generic_node (buffer
, TREE_VALUE (lnode
), spc
, flags
, false);
663 lnode
= TREE_CHAIN (lnode
);
664 if (lnode
&& TREE_CODE (lnode
) == TREE_LIST
)
666 pp_character (buffer
, ',');
670 pp_character (buffer
, '}');
677 if (flags
& TDF_SLIM
)
679 pp_string (buffer
, "<COMPOUND_EXPR>");
683 dump_generic_node (buffer
, TREE_OPERAND (node
, 0),
684 spc
, flags
, dumping_stmts
);
686 newline_and_indent (buffer
, spc
);
689 pp_character (buffer
, ',');
693 for (tp
= &TREE_OPERAND (node
, 1);
694 TREE_CODE (*tp
) == COMPOUND_EXPR
;
695 tp
= &TREE_OPERAND (*tp
, 1))
697 dump_generic_node (buffer
, TREE_OPERAND (*tp
, 0),
698 spc
, flags
, dumping_stmts
);
700 newline_and_indent (buffer
, spc
);
703 pp_character (buffer
, ',');
708 dump_generic_node (buffer
, *tp
, spc
, flags
, dumping_stmts
);
714 tree_stmt_iterator si
;
717 if ((flags
& TDF_SLIM
) || !dumping_stmts
)
719 pp_string (buffer
, "<STATEMENT_LIST>");
723 for (si
= tsi_start (node
); !tsi_end_p (si
); tsi_next (&si
))
726 newline_and_indent (buffer
, spc
);
729 dump_generic_node (buffer
, tsi_stmt (si
), spc
, flags
, true);
736 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
738 pp_character (buffer
, '=');
740 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
744 dump_generic_node (buffer
, TYPE_NAME (TREE_TYPE (node
)), spc
, flags
, false);
745 pp_character (buffer
, '(');
746 dump_generic_node (buffer
, TARGET_EXPR_INITIAL (node
), spc
, flags
, false);
747 pp_character (buffer
, ')');
751 if (TREE_TYPE (node
) == void_type_node
)
753 pp_string (buffer
, "if (");
754 dump_generic_node (buffer
, COND_EXPR_COND (node
), spc
, flags
, false);
755 pp_character (buffer
, ')');
756 /* The lowered cond_exprs should always be printed in full. */
757 if (COND_EXPR_THEN (node
)
758 && TREE_CODE (COND_EXPR_THEN (node
)) == GOTO_EXPR
759 && COND_EXPR_ELSE (node
)
760 && TREE_CODE (COND_EXPR_ELSE (node
)) == GOTO_EXPR
)
763 dump_generic_node (buffer
, COND_EXPR_THEN (node
), 0, flags
, true);
764 pp_string (buffer
, " else ");
765 dump_generic_node (buffer
, COND_EXPR_ELSE (node
), 0, flags
, true);
767 else if (!(flags
& TDF_SLIM
))
769 /* Output COND_EXPR_THEN. */
770 if (COND_EXPR_THEN (node
))
772 newline_and_indent (buffer
, spc
+2);
773 pp_character (buffer
, '{');
774 newline_and_indent (buffer
, spc
+4);
775 dump_generic_node (buffer
, COND_EXPR_THEN (node
), spc
+4,
777 newline_and_indent (buffer
, spc
+2);
778 pp_character (buffer
, '}');
781 /* Output COND_EXPR_ELSE. */
782 if (COND_EXPR_ELSE (node
))
784 newline_and_indent (buffer
, spc
);
785 pp_string (buffer
, "else");
786 newline_and_indent (buffer
, spc
+2);
787 pp_character (buffer
, '{');
788 newline_and_indent (buffer
, spc
+4);
789 dump_generic_node (buffer
, COND_EXPR_ELSE (node
), spc
+4,
791 newline_and_indent (buffer
, spc
+2);
792 pp_character (buffer
, '}');
799 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
801 pp_character (buffer
, '?');
803 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
805 pp_character (buffer
, ':');
807 dump_generic_node (buffer
, TREE_OPERAND (node
, 2), spc
, flags
, false);
812 pp_character (buffer
, '{');
813 if (!(flags
& TDF_SLIM
))
815 if (BIND_EXPR_VARS (node
))
819 for (op0
= BIND_EXPR_VARS (node
); op0
; op0
= TREE_CHAIN (op0
))
821 print_declaration (buffer
, op0
, spc
+2, flags
);
826 newline_and_indent (buffer
, spc
+2);
827 dump_generic_node (buffer
, BIND_EXPR_BODY (node
), spc
+2, flags
, true);
828 newline_and_indent (buffer
, spc
);
829 pp_character (buffer
, '}');
835 print_call_name (buffer
, node
);
837 /* Print parameters. */
839 pp_character (buffer
, '(');
840 op1
= TREE_OPERAND (node
, 1);
842 dump_generic_node (buffer
, op1
, spc
, flags
, false);
843 pp_character (buffer
, ')');
845 op1
= TREE_OPERAND (node
, 2);
848 pp_string (buffer
, " [static-chain: ");
849 dump_generic_node (buffer
, op1
, spc
, flags
, false);
850 pp_character (buffer
, ']');
853 if (CALL_EXPR_TAILCALL (node
))
854 pp_string (buffer
, " [tail call]");
857 case WITH_CLEANUP_EXPR
:
861 case CLEANUP_POINT_EXPR
:
862 pp_string (buffer
, "<<cleanup_point ");
863 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
864 pp_string (buffer
, ">>");
867 case PLACEHOLDER_EXPR
:
871 /* Binary arithmetic and logic expressions. */
892 case TRUTH_ANDIF_EXPR
:
893 case TRUTH_ORIF_EXPR
:
909 const char *op
= op_symbol (node
);
910 op0
= TREE_OPERAND (node
, 0);
911 op1
= TREE_OPERAND (node
, 1);
913 /* When the operands are expressions with less priority,
914 keep semantics of the tree representation. */
915 if (op_prio (op0
) < op_prio (node
))
917 pp_character (buffer
, '(');
918 dump_generic_node (buffer
, op0
, spc
, flags
, false);
919 pp_character (buffer
, ')');
922 dump_generic_node (buffer
, op0
, spc
, flags
, false);
925 pp_string (buffer
, op
);
928 /* When the operands are expressions with less priority,
929 keep semantics of the tree representation. */
930 if (op_prio (op1
) < op_prio (node
))
932 pp_character (buffer
, '(');
933 dump_generic_node (buffer
, op1
, spc
, flags
, false);
934 pp_character (buffer
, ')');
937 dump_generic_node (buffer
, op1
, spc
, flags
, false);
941 /* Unary arithmetic and logic expressions. */
947 case PREDECREMENT_EXPR
:
948 case PREINCREMENT_EXPR
:
950 if (TREE_CODE (node
) == ADDR_EXPR
951 && (TREE_CODE (TREE_OPERAND (node
, 0)) == STRING_CST
952 || TREE_CODE (TREE_OPERAND (node
, 0)) == FUNCTION_DECL
))
953 ; /* Do not output '&' for strings and function pointers. */
955 pp_string (buffer
, op_symbol (node
));
957 if (op_prio (TREE_OPERAND (node
, 0)) < op_prio (node
))
959 pp_character (buffer
, '(');
960 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
961 pp_character (buffer
, ')');
964 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
967 case POSTDECREMENT_EXPR
:
968 case POSTINCREMENT_EXPR
:
969 if (op_prio (TREE_OPERAND (node
, 0)) < op_prio (node
))
971 pp_character (buffer
, '(');
972 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
973 pp_character (buffer
, ')');
976 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
977 pp_string (buffer
, op_symbol (node
));
981 pp_string (buffer
, "MIN_EXPR <");
982 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
983 pp_string (buffer
, ", ");
984 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
985 pp_character (buffer
, '>');
989 pp_string (buffer
, "MAX_EXPR <");
990 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
991 pp_string (buffer
, ", ");
992 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
993 pp_character (buffer
, '>');
997 pp_string (buffer
, "ABS_EXPR <");
998 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
999 pp_character (buffer
, '>');
1002 case UNORDERED_EXPR
:
1026 case FIX_TRUNC_EXPR
:
1028 case FIX_FLOOR_EXPR
:
1029 case FIX_ROUND_EXPR
:
1033 type
= TREE_TYPE (node
);
1034 op0
= TREE_OPERAND (node
, 0);
1035 if (type
!= TREE_TYPE (op0
))
1037 pp_character (buffer
, '(');
1038 dump_generic_node (buffer
, type
, spc
, flags
, false);
1039 pp_string (buffer
, ")");
1041 if (op_prio (op0
) < op_prio (node
))
1042 pp_character (buffer
, '(');
1043 dump_generic_node (buffer
, op0
, spc
, flags
, false);
1044 if (op_prio (op0
) < op_prio (node
))
1045 pp_character (buffer
, ')');
1048 case VIEW_CONVERT_EXPR
:
1049 pp_string (buffer
, "VIEW_CONVERT_EXPR<");
1050 dump_generic_node (buffer
, TREE_TYPE (node
), spc
, flags
, false);
1051 pp_string (buffer
, ">(");
1052 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1053 pp_character (buffer
, ')');
1056 case NON_LVALUE_EXPR
:
1057 pp_string (buffer
, "NON_LVALUE_EXPR <");
1058 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1059 pp_character (buffer
, '>');
1063 pp_string (buffer
, "SAVE_EXPR <");
1064 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1065 pp_character (buffer
, '>');
1069 pp_string (buffer
, "UNSAVE_EXPR <");
1070 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1071 pp_character (buffer
, '>');
1078 case ENTRY_VALUE_EXPR
:
1083 pp_string (buffer
, "COMPLEX_EXPR <");
1084 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1085 pp_string (buffer
, ", ");
1086 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
1087 pp_string (buffer
, ">");
1091 pp_string (buffer
, "CONJ_EXPR <");
1092 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1093 pp_string (buffer
, ">");
1097 pp_string (buffer
, "REALPART_EXPR <");
1098 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1099 pp_string (buffer
, ">");
1103 pp_string (buffer
, "IMAGPART_EXPR <");
1104 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1105 pp_string (buffer
, ">");
1109 pp_string (buffer
, "VA_ARG_EXPR <");
1110 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1111 pp_string (buffer
, ">");
1114 case TRY_FINALLY_EXPR
:
1115 case TRY_CATCH_EXPR
:
1116 pp_string (buffer
, "try");
1117 newline_and_indent (buffer
, spc
+2);
1118 pp_string (buffer
, "{");
1119 newline_and_indent (buffer
, spc
+4);
1120 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
+4, flags
, true);
1121 newline_and_indent (buffer
, spc
+2);
1122 pp_string (buffer
, "}");
1123 newline_and_indent (buffer
, spc
);
1125 (TREE_CODE (node
) == TRY_CATCH_EXPR
) ? "catch" : "finally");
1126 newline_and_indent (buffer
, spc
+2);
1127 pp_string (buffer
, "{");
1128 newline_and_indent (buffer
, spc
+4);
1129 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
+4, flags
, true);
1130 newline_and_indent (buffer
, spc
+2);
1131 pp_string (buffer
, "}");
1136 pp_string (buffer
, "catch (");
1137 dump_generic_node (buffer
, CATCH_TYPES (node
), spc
+2, flags
, false);
1138 pp_string (buffer
, ")");
1139 newline_and_indent (buffer
, spc
+2);
1140 pp_string (buffer
, "{");
1141 newline_and_indent (buffer
, spc
+4);
1142 dump_generic_node (buffer
, CATCH_BODY (node
), spc
+4, flags
, true);
1143 newline_and_indent (buffer
, spc
+2);
1144 pp_string (buffer
, "}");
1148 case EH_FILTER_EXPR
:
1149 pp_string (buffer
, "<<<eh_filter (");
1150 dump_generic_node (buffer
, EH_FILTER_TYPES (node
), spc
+2, flags
, false);
1151 pp_string (buffer
, ")>>>");
1152 newline_and_indent (buffer
, spc
+2);
1153 pp_string (buffer
, "{");
1154 newline_and_indent (buffer
, spc
+4);
1155 dump_generic_node (buffer
, EH_FILTER_FAILURE (node
), spc
+4, flags
, true);
1156 newline_and_indent (buffer
, spc
+2);
1157 pp_string (buffer
, "}");
1161 case GOTO_SUBROUTINE_EXPR
:
1166 op0
= TREE_OPERAND (node
, 0);
1167 /* If this is for break or continue, don't bother printing it. */
1168 if (DECL_NAME (op0
))
1170 const char *name
= IDENTIFIER_POINTER (DECL_NAME (op0
));
1171 if (strcmp (name
, "break") == 0
1172 || strcmp (name
, "continue") == 0)
1175 dump_generic_node (buffer
, op0
, spc
, flags
, false);
1176 pp_character (buffer
, ':');
1177 if (DECL_NONLOCAL (op0
))
1178 pp_string (buffer
, " [non-local]");
1181 case LABELED_BLOCK_EXPR
:
1182 op0
= LABELED_BLOCK_LABEL (node
);
1183 /* If this is for break or continue, don't bother printing it. */
1184 if (DECL_NAME (op0
))
1186 const char *name
= IDENTIFIER_POINTER (DECL_NAME (op0
));
1187 if (strcmp (name
, "break") == 0
1188 || strcmp (name
, "continue") == 0)
1190 dump_generic_node (buffer
, LABELED_BLOCK_BODY (node
), spc
, flags
, false);
1194 dump_generic_node (buffer
, LABELED_BLOCK_LABEL (node
), spc
, flags
, false);
1195 pp_string (buffer
, ": {");
1196 if (!(flags
& TDF_SLIM
))
1197 newline_and_indent (buffer
, spc
+2);
1198 dump_generic_node (buffer
, LABELED_BLOCK_BODY (node
), spc
+2, flags
, true);
1200 newline_and_indent (buffer
, spc
);
1201 pp_character (buffer
, '}');
1205 case EXIT_BLOCK_EXPR
:
1206 op0
= LABELED_BLOCK_LABEL (EXIT_BLOCK_LABELED_BLOCK (node
));
1207 /* If this is for a break or continue, print it accordingly. */
1208 if (DECL_NAME (op0
))
1210 const char *name
= IDENTIFIER_POINTER (DECL_NAME (op0
));
1211 if (strcmp (name
, "break") == 0
1212 || strcmp (name
, "continue") == 0)
1214 pp_string (buffer
, name
);
1218 pp_string (buffer
, "<<<exit block ");
1219 dump_generic_node (buffer
, op0
, spc
, flags
, false);
1220 pp_string (buffer
, ">>>");
1224 pp_string (buffer
, "<<<exception object>>>");
1228 pp_string (buffer
, "<<<filter object>>>");
1232 pp_string (buffer
, "while (1)");
1233 if (!(flags
& TDF_SLIM
))
1235 newline_and_indent (buffer
, spc
+2);
1236 pp_character (buffer
, '{');
1237 newline_and_indent (buffer
, spc
+4);
1238 dump_generic_node (buffer
, LOOP_EXPR_BODY (node
), spc
+4, flags
, true);
1239 newline_and_indent (buffer
, spc
+2);
1240 pp_character (buffer
, '}');
1246 pp_string (buffer
, "return");
1247 op0
= TREE_OPERAND (node
, 0);
1251 if (TREE_CODE (op0
) == MODIFY_EXPR
)
1252 dump_generic_node (buffer
, TREE_OPERAND (op0
, 1), spc
, flags
, false);
1254 dump_generic_node (buffer
, op0
, spc
, flags
, false);
1259 pp_string (buffer
, "if (");
1260 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1261 pp_string (buffer
, ") break");
1265 pp_string (buffer
, "switch (");
1266 dump_generic_node (buffer
, SWITCH_COND (node
), spc
, flags
, false);
1267 pp_character (buffer
, ')');
1268 if (!(flags
& TDF_SLIM
))
1270 newline_and_indent (buffer
, spc
+2);
1271 pp_character (buffer
, '{');
1272 if (SWITCH_BODY (node
))
1274 newline_and_indent (buffer
, spc
+4);
1275 dump_generic_node (buffer
, SWITCH_BODY (node
), spc
+4, flags
, true);
1279 tree vec
= SWITCH_LABELS (node
);
1280 size_t i
, n
= TREE_VEC_LENGTH (vec
);
1281 for (i
= 0; i
< n
; ++i
)
1283 tree elt
= TREE_VEC_ELT (vec
, i
);
1284 newline_and_indent (buffer
, spc
+4);
1285 dump_generic_node (buffer
, elt
, spc
+4, flags
, false);
1286 pp_string (buffer
, " goto ");
1287 dump_generic_node (buffer
, CASE_LABEL (elt
), spc
+4, flags
, true);
1288 pp_semicolon (buffer
);
1291 newline_and_indent (buffer
, spc
+2);
1292 pp_character (buffer
, '}');
1298 op0
= GOTO_DESTINATION (node
);
1299 if (TREE_CODE (op0
) != SSA_NAME
1303 const char *name
= IDENTIFIER_POINTER (DECL_NAME (op0
));
1304 if (strcmp (name
, "break") == 0
1305 || strcmp (name
, "continue") == 0)
1307 pp_string (buffer
, name
);
1311 pp_string (buffer
, "goto ");
1312 dump_generic_node (buffer
, op0
, spc
, flags
, false);
1316 pp_string (buffer
, "resx");
1317 /* ??? Any sensible way to present the eh region? */
1321 pp_string (buffer
, "__asm__");
1322 if (ASM_VOLATILE_P (node
))
1323 pp_string (buffer
, " __volatile__");
1324 pp_character (buffer
, '(');
1325 dump_generic_node (buffer
, ASM_STRING (node
), spc
, flags
, false);
1326 pp_character (buffer
, ':');
1327 dump_generic_node (buffer
, ASM_OUTPUTS (node
), spc
, flags
, false);
1328 pp_character (buffer
, ':');
1329 dump_generic_node (buffer
, ASM_INPUTS (node
), spc
, flags
, false);
1330 if (ASM_CLOBBERS (node
))
1332 pp_character (buffer
, ':');
1333 dump_generic_node (buffer
, ASM_CLOBBERS (node
), spc
, flags
, false);
1335 pp_string (buffer
, ")");
1338 case CASE_LABEL_EXPR
:
1339 if (CASE_LOW (node
) && CASE_HIGH (node
))
1341 pp_string (buffer
, "case ");
1342 dump_generic_node (buffer
, CASE_LOW (node
), spc
, flags
, false);
1343 pp_string (buffer
, " ... ");
1344 dump_generic_node (buffer
, CASE_HIGH (node
), spc
, flags
, false);
1346 else if (CASE_LOW (node
))
1348 pp_string (buffer
, "case ");
1349 dump_generic_node (buffer
, CASE_LOW (node
), spc
, flags
, false);
1352 pp_string (buffer
, "default ");
1353 pp_character (buffer
, ':');
1357 pp_string (buffer
, "VTABLE_REF <(");
1358 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1359 pp_string (buffer
, "),");
1360 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
1361 pp_character (buffer
, ',');
1362 dump_generic_node (buffer
, TREE_OPERAND (node
, 2), spc
, flags
, false);
1363 pp_character (buffer
, '>');
1370 pp_string (buffer
, " EPHI (");
1371 dump_generic_node (buffer
, EREF_NAME (node
), spc
, flags
, false);
1372 pp_string (buffer
, ") ");
1373 pp_character (buffer
, '[');
1374 pp_string (buffer
, " class:");
1375 pp_decimal_int (buffer
, EREF_CLASS (node
));
1376 if (EPHI_DOWNSAFE (node
))
1377 pp_string (buffer
, " downsafe");
1378 if (EPHI_CANT_BE_AVAIL (node
))
1379 pp_string (buffer
, " cant_be_avail");
1380 if (EPHI_STOPS (node
))
1381 pp_string (buffer
, " stops");
1382 pp_string (buffer
, " bb:");
1383 pp_decimal_int (buffer
, bb_for_stmt (node
)->index
);
1384 pp_character (buffer
, ']');
1385 if (! (flags
& TDF_SLIM
))
1387 pp_string (buffer
, " <");
1388 for (i
= 0; i
< EPHI_NUM_ARGS (node
); i
++)
1390 if (EPHI_ARG_DEF (node
, i
))
1392 newline_and_indent (buffer
, spc
+ 2);
1393 pp_string (buffer
, " edge ");
1394 pp_decimal_int (buffer
, EPHI_ARG_EDGE (node
, i
)->src
->index
);
1395 pp_string (buffer
, "->");
1396 pp_decimal_int (buffer
, EPHI_ARG_EDGE (node
, i
)->dest
->index
);
1397 pp_string (buffer
, " [ ");
1398 if (EPHI_ARG_HAS_REAL_USE (node
, i
))
1399 pp_string (buffer
, " real use");
1400 if (EPHI_ARG_INJURED (node
, i
))
1401 pp_string (buffer
, " injured");
1402 if (EPHI_ARG_STOPS (node
, i
))
1403 pp_string (buffer
, " stops");
1404 pp_string (buffer
, " ] ");
1405 pp_string (buffer
, " defined by:");
1406 dump_generic_node (buffer
, EPHI_ARG_DEF (node
, i
),
1407 spc
+ 4, flags
| TDF_SLIM
, false);
1411 pp_string (buffer
, " >");
1416 if (TREE_CODE (node
) == EEXIT_NODE
)
1417 pp_string (buffer
, "EEXIT (");
1418 else if (TREE_CODE (node
) == EKILL_NODE
)
1419 pp_string (buffer
, "EKILL (");
1420 dump_generic_node (buffer
, EREF_NAME (node
), spc
, flags
, false);
1421 pp_string (buffer
, ") ");
1422 pp_character (buffer
, '[');
1423 pp_string (buffer
, "class:");
1424 pp_decimal_int (buffer
, EREF_CLASS (node
));
1425 pp_string (buffer
, " bb:");
1426 pp_decimal_int (buffer
, bb_for_stmt (node
)->index
);
1427 pp_character (buffer
, ']');
1430 pp_string (buffer
, " EUSE (");
1431 dump_generic_node (buffer
, EREF_NAME (node
), spc
, flags
, false);
1433 pp_string (buffer
, ") ");
1434 pp_character (buffer
, '[');
1435 pp_string (buffer
, "class:");
1436 pp_decimal_int (buffer
, EREF_CLASS (node
));
1437 pp_string (buffer
, " phiop:");
1438 pp_decimal_int (buffer
, EUSE_PHIOP (node
));
1439 pp_string (buffer
, " bb:");
1440 pp_decimal_int (buffer
, bb_for_stmt (node
)->index
);
1441 if (EUSE_LVAL (node
))
1442 pp_string (buffer
, " left-occurrence");
1443 pp_string (buffer
, " ]");
1450 dump_generic_node (buffer
, PHI_RESULT (node
), spc
, flags
, false);
1451 pp_string (buffer
, " = PHI <");
1452 for (i
= 0; i
< PHI_NUM_ARGS (node
); i
++)
1454 dump_generic_node (buffer
, PHI_ARG_DEF (node
, i
), spc
, flags
, false);
1455 pp_string (buffer
, "(");
1456 pp_decimal_int (buffer
, PHI_ARG_EDGE (node
, i
)->src
->index
);
1457 pp_string (buffer
, ")");
1458 if (i
< PHI_NUM_ARGS (node
) - 1)
1459 pp_string (buffer
, ", ");
1461 pp_string (buffer
, ">;");
1466 dump_generic_node (buffer
, SSA_NAME_VAR (node
), spc
, flags
, false);
1467 pp_string (buffer
, "_");
1468 pp_decimal_int (buffer
, SSA_NAME_VERSION (node
));
1475 if (is_stmt
&& is_expr
)
1476 pp_semicolon (buffer
);
1477 pp_write_text_to_stream (buffer
);
1482 /* Print the declaration of a variable. */
1485 print_declaration (pretty_printer
*buffer
, tree t
, int spc
, int flags
)
1487 /* Don't print type declarations. */
1488 if (TREE_CODE (t
) == TYPE_DECL
)
1493 if (DECL_REGISTER (t
))
1494 pp_string (buffer
, "register ");
1496 if (TREE_PUBLIC (t
) && DECL_EXTERNAL (t
))
1497 pp_string (buffer
, "extern ");
1498 else if (TREE_STATIC (t
))
1499 pp_string (buffer
, "static ");
1501 /* Print the type and name. */
1502 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
1506 /* Print array's type. */
1507 tmp
= TREE_TYPE (t
);
1508 while (TREE_CODE (TREE_TYPE (tmp
)) == ARRAY_TYPE
)
1509 tmp
= TREE_TYPE (tmp
);
1510 dump_generic_node (buffer
, TREE_TYPE (tmp
), spc
, flags
, false);
1512 /* Print variable's name. */
1514 dump_generic_node (buffer
, t
, spc
, flags
, false);
1516 /* Print the dimensions. */
1517 tmp
= TREE_TYPE (t
);
1518 while (TREE_CODE (tmp
) == ARRAY_TYPE
)
1520 pp_character (buffer
, '[');
1521 if (TYPE_DOMAIN (tmp
))
1523 if (TREE_CODE (TYPE_SIZE (tmp
)) == INTEGER_CST
)
1524 pp_wide_integer (buffer
,
1525 TREE_INT_CST_LOW (TYPE_SIZE (tmp
)) /
1526 TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (tmp
))));
1528 dump_generic_node (buffer
, TYPE_SIZE_UNIT (tmp
), spc
, flags
,
1531 pp_character (buffer
, ']');
1532 tmp
= TREE_TYPE (tmp
);
1537 /* Print type declaration. */
1538 dump_generic_node (buffer
, TREE_TYPE (t
), spc
, flags
, false);
1540 /* Print variable's name. */
1542 dump_generic_node (buffer
, t
, spc
, flags
, false);
1545 /* The initial value of a function serves to determine wether the function
1546 is declared or defined. So the following does not apply to function
1548 if (TREE_CODE (t
) != FUNCTION_DECL
)
1550 /* Print the initial value. */
1551 if (DECL_INITIAL (t
))
1554 pp_character (buffer
, '=');
1556 dump_generic_node (buffer
, DECL_INITIAL (t
), spc
, flags
, false);
1560 pp_character (buffer
, ';');
1564 /* Prints a structure: name, fields, and methods.
1565 FIXME: Still incomplete. */
1568 print_struct_decl (pretty_printer
*buffer
, tree node
, int spc
, int flags
)
1570 /* Print the name of the structure. */
1571 if (TYPE_NAME (node
))
1574 if (TREE_CODE (node
) == RECORD_TYPE
)
1575 pp_string (buffer
, "struct ");
1576 else if (TREE_CODE (node
) == UNION_TYPE
)
1577 pp_string (buffer
, "union ");
1580 dump_generic_node (buffer
, TYPE_NAME (node
), spc
, 0, false);
1583 /* Print the contents of the structure. */
1584 pp_newline (buffer
);
1586 pp_character (buffer
, '{');
1587 pp_newline (buffer
);
1589 /* Print the fields of the structure. */
1592 tmp
= TYPE_FIELDS (node
);
1595 /* Avoid to print recursively the structure. */
1596 /* FIXME : Not implemented correctly...,
1597 what about the case when we have a cycle in the contain graph? ...
1598 Maybe this could be solved by looking at the scope in which the
1599 structure was declared. */
1600 if (TREE_TYPE (tmp
) != node
1601 || (TREE_CODE (TREE_TYPE (tmp
)) == POINTER_TYPE
&&
1602 TREE_TYPE (TREE_TYPE (tmp
)) != node
))
1604 print_declaration (buffer
, tmp
, spc
+2, flags
);
1605 pp_newline (buffer
);
1611 tmp
= TREE_CHAIN (tmp
);
1615 pp_character (buffer
, '}');
1618 /* Return the priority of the operator OP.
1620 From lowest to highest precedence with either left-to-right (L-R)
1621 or right-to-left (R-L) associativity]:
1624 2 [R-L] = += -= *= /= %= &= ^= |= <<= >>=
1636 14 [R-L] ! ~ ++ -- + - * & (type) sizeof
1637 15 [L-R] fn() [] -> .
1639 unary +, - and * have higher precedence than the corresponding binary
1648 switch (TREE_CODE (op
))
1663 case TRUTH_ORIF_EXPR
:
1666 case TRUTH_AND_EXPR
:
1667 case TRUTH_ANDIF_EXPR
:
1674 case TRUTH_XOR_EXPR
:
1701 case TRUNC_DIV_EXPR
:
1703 case FLOOR_DIV_EXPR
:
1704 case ROUND_DIV_EXPR
:
1706 case EXACT_DIV_EXPR
:
1707 case TRUNC_MOD_EXPR
:
1709 case FLOOR_MOD_EXPR
:
1710 case ROUND_MOD_EXPR
:
1713 case TRUTH_NOT_EXPR
:
1715 case POSTINCREMENT_EXPR
:
1716 case POSTDECREMENT_EXPR
:
1717 case PREINCREMENT_EXPR
:
1718 case PREDECREMENT_EXPR
:
1725 case FIX_TRUNC_EXPR
:
1727 case FIX_FLOOR_EXPR
:
1728 case FIX_ROUND_EXPR
:
1737 /* Special expressions. */
1746 case NON_LVALUE_EXPR
:
1747 return op_prio (TREE_OPERAND (op
, 0));
1750 /* Return an arbitrarily high precedence to avoid surrounding single
1751 VAR_DECLs in ()s. */
1757 /* Return the symbol associated with operator OP. */
1765 switch (TREE_CODE (op
))
1771 case TRUTH_ORIF_EXPR
:
1774 case TRUTH_AND_EXPR
:
1775 case TRUTH_ANDIF_EXPR
:
1781 case TRUTH_XOR_EXPR
:
1828 case TRUTH_NOT_EXPR
:
1835 case TRUNC_DIV_EXPR
:
1837 case FLOOR_DIV_EXPR
:
1838 case ROUND_DIV_EXPR
:
1840 case EXACT_DIV_EXPR
:
1843 case TRUNC_MOD_EXPR
:
1845 case FLOOR_MOD_EXPR
:
1846 case ROUND_MOD_EXPR
:
1849 case PREDECREMENT_EXPR
:
1852 case PREINCREMENT_EXPR
:
1855 case POSTDECREMENT_EXPR
:
1858 case POSTINCREMENT_EXPR
:
1861 case REFERENCE_EXPR
:
1865 return "<<< ??? >>>";
1869 /* Prints the name of a CALL_EXPR. */
1872 print_call_name (pretty_printer
*buffer
, tree node
)
1876 if (TREE_CODE (node
) != CALL_EXPR
)
1879 op0
= TREE_OPERAND (node
, 0);
1881 if (TREE_CODE (op0
) == NON_LVALUE_EXPR
)
1882 op0
= TREE_OPERAND (op0
, 0);
1884 switch (TREE_CODE (op0
))
1888 PRINT_FUNCTION_NAME (op0
);
1894 dump_generic_node (buffer
, TREE_OPERAND (op0
, 0), 0, 0, false);
1898 pp_string (buffer
, "(");
1899 dump_generic_node (buffer
, TREE_OPERAND (op0
, 0), 0, 0, false);
1900 pp_string (buffer
, ") ? ");
1901 dump_generic_node (buffer
, TREE_OPERAND (op0
, 1), 0, 0, false);
1902 pp_string (buffer
, " : ");
1903 dump_generic_node (buffer
, TREE_OPERAND (op0
, 2), 0, 0, false);
1907 /* The function is a pointer contained in a structure. */
1908 if (TREE_CODE (TREE_OPERAND (op0
, 0)) == INDIRECT_REF
||
1909 TREE_CODE (TREE_OPERAND (op0
, 0)) == VAR_DECL
)
1910 PRINT_FUNCTION_NAME (TREE_OPERAND (op0
, 1));
1912 dump_generic_node (buffer
, TREE_OPERAND (op0
, 0), 0, 0, false);
1914 We can have several levels of structures and a function
1915 pointer inside. This is not implemented yet... */
1920 if (TREE_CODE (TREE_OPERAND (op0
, 0)) == VAR_DECL
)
1921 PRINT_FUNCTION_NAME (TREE_OPERAND (op0
, 0));
1923 dump_generic_node (buffer
, op0
, 0, 0, false);
1927 dump_generic_node (buffer
, op0
, 0, 0, false);
1935 /* Parses the string STR and replaces new-lines by '\n', tabs by '\t', ... */
1938 pretty_print_string (pretty_printer
*buffer
, const char *str
)
1948 pp_string (buffer
, "\\b");
1952 pp_string (buffer
, "\\f");
1956 pp_string (buffer
, "\\n");
1960 pp_string (buffer
, "\\r");
1964 pp_string (buffer
, "\\t");
1968 pp_string (buffer
, "\\v");
1972 pp_string (buffer
, "\\\\");
1976 pp_string (buffer
, "\\\"");
1980 pp_string (buffer
, "\\'");
1984 pp_string (buffer
, "\\0");
1988 pp_string (buffer
, "\\1");
1992 pp_string (buffer
, "\\2");
1996 pp_string (buffer
, "\\3");
2000 pp_string (buffer
, "\\4");
2004 pp_string (buffer
, "\\5");
2008 pp_string (buffer
, "\\6");
2012 pp_string (buffer
, "\\7");
2016 pp_character (buffer
, str
[0]);
2024 maybe_init_pretty_print (FILE *file
)
2028 pp_construct (&buffer
, /* prefix */NULL
, /* line-width */0);
2029 pp_needs_newline (&buffer
) = true;
2033 buffer
.buffer
->stream
= file
;
2037 newline_and_indent (pretty_printer
*buffer
, int spc
)
2039 pp_newline (buffer
);
2044 dump_vops (pretty_printer
*buffer
, tree stmt
, int spc
, int flags
)
2047 stmt_ann_t ann
= stmt_ann (stmt
);
2048 vdef_optype vdefs
= VDEF_OPS (ann
);
2049 vuse_optype vuses
= VUSE_OPS (ann
);
2051 for (i
= 0; i
< NUM_VDEFS (vdefs
); i
++)
2053 pp_string (buffer
, "# ");
2054 dump_generic_node (buffer
, VDEF_RESULT (vdefs
, i
), spc
+ 2, flags
, false);
2055 pp_string (buffer
, " = VDEF <");
2056 dump_generic_node (buffer
, VDEF_OP (vdefs
, i
), spc
+ 2, flags
, false);
2057 pp_string (buffer
, ">;");
2058 newline_and_indent (buffer
, spc
);
2061 for (i
= 0; i
< NUM_VUSES (vuses
); i
++)
2063 tree vuse
= VUSE_OP (vuses
, i
);
2064 pp_string (buffer
, "# VUSE <");
2065 dump_generic_node (buffer
, vuse
, spc
+ 2, flags
, false);
2066 pp_string (buffer
, ">;");
2067 newline_and_indent (buffer
, spc
);
2071 /* Dumps basic block BB to FILE with details described by FLAGS and
2072 indented by INDENT spaces. */
2075 dump_generic_bb (FILE *file
, basic_block bb
, int indent
, int flags
)
2077 maybe_init_pretty_print (file
);
2078 dumping_stmts
= true;
2079 dump_generic_bb_buff (&buffer
, bb
, indent
, flags
);
2083 /* Dumps header of basic block BB to buffer BUFFER indented by INDENT
2084 spaces and details described by flags. */
2087 dump_bb_header (pretty_printer
*buffer
, basic_block bb
, int indent
, int flags
)
2092 if (flags
& TDF_BLOCKS
)
2095 pp_string (buffer
, "# BLOCK ");
2096 pp_decimal_int (buffer
, bb
->index
);
2098 if (flags
& TDF_LINENO
)
2100 block_stmt_iterator bsi
;
2102 for (bsi
= bsi_start (bb
); !bsi_end_p (bsi
); bsi_next (&bsi
))
2103 if (get_lineno (bsi_stmt (bsi
)) != -1)
2105 pp_string (buffer
, ", starting at line ");
2106 pp_decimal_int (buffer
, get_lineno (bsi_stmt (bsi
)));
2110 newline_and_indent (buffer
, indent
);
2112 pp_string (buffer
, "# PRED:");
2113 pp_write_text_to_stream (buffer
);
2114 for (e
= bb
->pred
; e
; e
= e
->pred_next
)
2115 if (flags
& TDF_SLIM
)
2117 pp_string (buffer
, " ");
2118 if (e
->src
== ENTRY_BLOCK_PTR
)
2119 pp_string (buffer
, "ENTRY");
2121 pp_decimal_int (buffer
, e
->src
->index
);
2124 dump_edge_info (buffer
->buffer
->stream
, e
, 0);
2125 pp_newline (buffer
);
2129 stmt
= first_stmt (bb
);
2130 if (!stmt
|| TREE_CODE (stmt
) != LABEL_EXPR
)
2132 INDENT (indent
- 2);
2133 pp_string (buffer
, "<bb ");
2134 pp_decimal_int (buffer
, bb
->index
);
2135 pp_string (buffer
, ">:");
2136 pp_newline (buffer
);
2141 /* Dumps end of basic block BB to buffer BUFFER indented by INDENT
2145 dump_bb_end (pretty_printer
*buffer
, basic_block bb
, int indent
, int flags
)
2150 pp_string (buffer
, "# SUCC:");
2151 pp_write_text_to_stream (buffer
);
2152 for (e
= bb
->succ
; e
; e
= e
->succ_next
)
2153 if (flags
& TDF_SLIM
)
2155 pp_string (buffer
, " ");
2156 if (e
->dest
== EXIT_BLOCK_PTR
)
2157 pp_string (buffer
, "EXIT");
2159 pp_decimal_int (buffer
, e
->dest
->index
);
2162 dump_edge_info (buffer
->buffer
->stream
, e
, 1);
2163 pp_newline (buffer
);
2166 /* Dumps phi nodes of basic block BB to buffer BUFFER with details described by
2167 FLAGS indented by INDENT spaces. */
2170 dump_phi_nodes (pretty_printer
*buffer
, basic_block bb
, int indent
, int flags
)
2172 tree phi
= phi_nodes (bb
);
2176 for (; phi
; phi
= TREE_CHAIN (phi
))
2178 if (is_gimple_reg (PHI_RESULT (phi
)) || (flags
& TDF_VOPS
))
2181 pp_string (buffer
, "# ");
2182 dump_generic_node (buffer
, phi
, indent
, flags
, false);
2183 pp_newline (buffer
);
2188 /* Dump jump to basic block BB that is represented implicitly in the cfg
2192 pp_cfg_jump (pretty_printer
*buffer
, basic_block bb
)
2196 stmt
= first_stmt (bb
);
2198 pp_string (buffer
, "goto <bb ");
2199 pp_decimal_int (buffer
, bb
->index
);
2200 pp_string (buffer
, ">");
2201 if (stmt
&& TREE_CODE (stmt
) == LABEL_EXPR
)
2203 pp_string (buffer
, " (");
2204 dump_generic_node (buffer
, LABEL_EXPR_LABEL (stmt
), 0, 0, false);
2205 pp_string (buffer
, ")");
2207 pp_semicolon (buffer
);
2210 /* Dump edges represented implicitly in basic block BB to BUFFER, indented
2211 by INDENT spaces, with details given by FLAGS. */
2214 dump_implicit_edges (pretty_printer
*buffer
, basic_block bb
, int indent
)
2218 /* If there is a fallthru edge, we may need to add an artificial goto to the
2220 for (e
= bb
->succ
; e
; e
= e
->succ_next
)
2221 if (e
->flags
& EDGE_FALLTHRU
)
2223 if (e
&& e
->dest
!= bb
->next_bb
)
2226 pp_cfg_jump (buffer
, e
->dest
);
2227 pp_newline (buffer
);
2231 /* Dumps basic block BB to buffer BUFFER with details described by FLAGS and
2232 indented by INDENT spaces. */
2235 dump_generic_bb_buff (pretty_printer
*buffer
, basic_block bb
,
2236 int indent
, int flags
)
2238 block_stmt_iterator bsi
;
2240 int label_indent
= indent
- 2;
2242 if (label_indent
< 0)
2245 dump_bb_header (buffer
, bb
, indent
, flags
);
2248 dump_phi_nodes (buffer
, bb
, indent
, flags
);
2250 for (bsi
= bsi_start (bb
); !bsi_end_p (bsi
); bsi_next (&bsi
))
2254 stmt
= bsi_stmt (bsi
);
2256 curr_indent
= TREE_CODE (stmt
) == LABEL_EXPR
? label_indent
: indent
;
2258 INDENT (curr_indent
);
2259 dump_generic_node (buffer
, stmt
, curr_indent
, flags
, true);
2260 pp_newline (buffer
);
2263 dump_implicit_edges (buffer
, bb
, indent
);
2265 if (flags
& TDF_BLOCKS
)
2266 dump_bb_end (buffer
, bb
, indent
, flags
);