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 case QUAL_UNION_TYPE
:
396 /* Print the name of the structure. */
397 if (TREE_CODE (node
) == RECORD_TYPE
)
398 pp_string (buffer
, "struct ");
399 else if (TREE_CODE (node
) == UNION_TYPE
)
400 pp_string (buffer
, "union ");
402 if (TYPE_NAME (node
))
403 dump_generic_node (buffer
, TYPE_NAME (node
), spc
, flags
, false);
405 print_struct_decl (buffer
, node
, spc
, flags
);
413 if (TREE_CODE (TREE_TYPE (node
)) == POINTER_TYPE
)
415 /* In the case of a pointer, one may want to divide by the
416 size of the pointed-to type. Unfortunately, this not
417 straightforward. The C front-end maps expressions
422 in such a way that the two INTEGER_CST nodes for "5" have
423 different values but identical types. In the latter
424 case, the 5 is multiplied by sizeof (int) in c-common.c
425 (pointer_int_sum) to convert it to a byte address, and
426 yet the type of the node is left unchanged. Argh. What
427 is consistent though is that the number value corresponds
428 to bytes (UNITS) offset.
430 NB: Neither of the following divisors can be trivially
431 used to recover the original literal:
433 TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (node)))
434 TYPE_PRECISION (TREE_TYPE (TREE_TYPE (node))) */
435 pp_wide_integer (buffer
, TREE_INT_CST_LOW (node
));
436 pp_string (buffer
, "B"); /* pseudo-unit */
438 else if (! host_integerp (node
, 0))
442 if (tree_int_cst_sgn (val
) < 0)
444 pp_character (buffer
, '-');
445 val
= build_int_2 (-TREE_INT_CST_LOW (val
),
446 ~TREE_INT_CST_HIGH (val
)
447 + !TREE_INT_CST_LOW (val
));
449 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
452 static char format
[10]; /* "%x%09999x\0" */
454 sprintf (format
, "%%x%%0%dx", HOST_BITS_PER_INT
/ 4);
455 sprintf (pp_buffer (buffer
)->digit_buffer
, format
,
456 TREE_INT_CST_HIGH (val
),
457 TREE_INT_CST_LOW (val
));
458 pp_string (buffer
, pp_buffer (buffer
)->digit_buffer
);
462 pp_wide_integer (buffer
, TREE_INT_CST_LOW (node
));
466 /* Code copied from print_node. */
469 if (TREE_OVERFLOW (node
))
470 pp_string (buffer
, " overflow");
472 #if !defined(REAL_IS_NOT_DOUBLE) || defined(REAL_ARITHMETIC)
473 d
= TREE_REAL_CST (node
);
474 if (REAL_VALUE_ISINF (d
))
475 pp_string (buffer
, " Inf");
476 else if (REAL_VALUE_ISNAN (d
))
477 pp_string (buffer
, " Nan");
481 real_to_decimal (string
, &d
, sizeof (string
), 0, 1);
482 pp_string (buffer
, string
);
487 unsigned char *p
= (unsigned char *) &TREE_REAL_CST (node
);
488 pp_string (buffer
, "0x");
489 for (i
= 0; i
< sizeof TREE_REAL_CST (node
); i
++)
490 output_formatted_integer (buffer
, "%02x", *p
++);
497 pp_string (buffer
, "__complex__ (");
498 dump_generic_node (buffer
, TREE_REALPART (node
), spc
, flags
, false);
499 pp_string (buffer
, ", ");
500 dump_generic_node (buffer
, TREE_IMAGPART (node
), spc
, flags
, false);
501 pp_string (buffer
, ")");
505 pp_string (buffer
, "\"");
506 pretty_print_string (buffer
, TREE_STRING_POINTER (node
));
507 pp_string (buffer
, "\"");
513 pp_string (buffer
, "{ ");
514 for (elt
= TREE_VECTOR_CST_ELTS (node
); elt
; elt
= TREE_CHAIN (elt
))
516 dump_generic_node (buffer
, TREE_VALUE (elt
), spc
, flags
, false);
517 if (TREE_CHAIN (elt
))
518 pp_string (buffer
, ", ");
520 pp_string (buffer
, " }");
529 dump_decl_name (buffer
, node
, flags
);
533 if (DECL_NAME (node
))
534 dump_decl_name (buffer
, node
, flags
);
535 else if (LABEL_DECL_UID (node
) != -1)
536 pp_printf (buffer
, "<L" HOST_WIDE_INT_PRINT_DEC
">",
537 LABEL_DECL_UID (node
));
539 pp_printf (buffer
, "<D%u>", DECL_UID (node
));
543 if (strcmp (DECL_SOURCE_FILE (node
), "<built-in>") == 0)
545 /* Don't print the declaration of built-in types. */
548 if (DECL_NAME (node
))
550 dump_decl_name (buffer
, node
, flags
);
554 if (TYPE_METHODS (TREE_TYPE (node
)))
556 /* The type is a c++ class: all structures have at least
558 pp_string (buffer
, "class ");
559 dump_generic_node (buffer
, TREE_TYPE (node
), spc
, flags
, false);
563 pp_string (buffer
, "struct ");
564 dump_generic_node (buffer
, TREE_TYPE (node
), spc
, flags
, false);
565 pp_character (buffer
, ';');
575 dump_decl_name (buffer
, node
, flags
);
579 pp_string (buffer
, "<retval>");
583 op0
= TREE_OPERAND (node
, 0);
585 if (TREE_CODE (op0
) == INDIRECT_REF
)
587 op0
= TREE_OPERAND (op0
, 0);
590 if (op_prio (op0
) < op_prio (node
))
591 pp_character (buffer
, '(');
592 dump_generic_node (buffer
, op0
, spc
, flags
, false);
593 if (op_prio (op0
) < op_prio (node
))
594 pp_character (buffer
, ')');
595 pp_string (buffer
, str
);
596 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
597 if (TREE_OPERAND (node
, 2)
598 && TREE_CODE (TREE_OPERAND (node
, 2)) != INTEGER_CST
)
600 pp_string (buffer
, "{off: ");
601 dump_generic_node (buffer
, TREE_OPERAND (node
, 2),
603 pp_character (buffer
, '}');
608 pp_string (buffer
, "BIT_FIELD_REF <");
609 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
610 pp_string (buffer
, ", ");
611 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
612 pp_string (buffer
, ", ");
613 dump_generic_node (buffer
, TREE_OPERAND (node
, 2), spc
, flags
, false);
614 pp_string (buffer
, ">");
622 case ARRAY_RANGE_REF
:
623 op0
= TREE_OPERAND (node
, 0);
624 if (op_prio (op0
) < op_prio (node
))
625 pp_character (buffer
, '(');
626 dump_generic_node (buffer
, op0
, spc
, flags
, false);
627 if (op_prio (op0
) < op_prio (node
))
628 pp_character (buffer
, ')');
629 pp_character (buffer
, '[');
630 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
631 if (TREE_CODE (node
) == ARRAY_RANGE_REF
)
632 pp_string (buffer
, " ...");
633 pp_character (buffer
, ']');
635 if ((TREE_OPERAND (node
, 2)
636 && TREE_CODE (TREE_OPERAND (node
, 2)) != INTEGER_CST
)
637 || (TREE_OPERAND (node
, 3)
638 && TREE_CODE (TREE_OPERAND (node
, 3)) != INTEGER_CST
))
640 pp_string (buffer
, "{lb: ");
641 dump_generic_node (buffer
, TREE_OPERAND (node
, 2),
643 pp_string (buffer
, " sz: ");
644 dump_generic_node (buffer
, TREE_OPERAND (node
, 3),
646 pp_character (buffer
, '}');
653 bool is_struct_init
= FALSE
;
654 pp_character (buffer
, '{');
655 lnode
= CONSTRUCTOR_ELTS (node
);
656 if (TREE_CODE (TREE_TYPE (node
)) == RECORD_TYPE
657 || TREE_CODE (TREE_TYPE (node
)) == UNION_TYPE
)
658 is_struct_init
= TRUE
;
659 while (lnode
&& lnode
!= error_mark_node
)
662 if (TREE_PURPOSE (lnode
) && is_struct_init
)
664 pp_character (buffer
, '.');
665 dump_generic_node (buffer
, TREE_PURPOSE (lnode
), spc
, flags
, false);
666 pp_string (buffer
, "=");
668 val
= TREE_VALUE (lnode
);
669 if (val
&& TREE_CODE (val
) == ADDR_EXPR
)
670 if (TREE_CODE (TREE_OPERAND (val
, 0)) == FUNCTION_DECL
)
671 val
= TREE_OPERAND (val
, 0);
672 if (val
&& TREE_CODE (val
) == FUNCTION_DECL
)
674 dump_decl_name (buffer
, val
, flags
);
678 dump_generic_node (buffer
, TREE_VALUE (lnode
), spc
, flags
, false);
680 lnode
= TREE_CHAIN (lnode
);
681 if (lnode
&& TREE_CODE (lnode
) == TREE_LIST
)
683 pp_character (buffer
, ',');
687 pp_character (buffer
, '}');
694 if (flags
& TDF_SLIM
)
696 pp_string (buffer
, "<COMPOUND_EXPR>");
700 dump_generic_node (buffer
, TREE_OPERAND (node
, 0),
701 spc
, flags
, dumping_stmts
);
703 newline_and_indent (buffer
, spc
);
706 pp_character (buffer
, ',');
710 for (tp
= &TREE_OPERAND (node
, 1);
711 TREE_CODE (*tp
) == COMPOUND_EXPR
;
712 tp
= &TREE_OPERAND (*tp
, 1))
714 dump_generic_node (buffer
, TREE_OPERAND (*tp
, 0),
715 spc
, flags
, dumping_stmts
);
717 newline_and_indent (buffer
, spc
);
720 pp_character (buffer
, ',');
725 dump_generic_node (buffer
, *tp
, spc
, flags
, dumping_stmts
);
731 tree_stmt_iterator si
;
734 if ((flags
& TDF_SLIM
) || !dumping_stmts
)
736 pp_string (buffer
, "<STATEMENT_LIST>");
740 for (si
= tsi_start (node
); !tsi_end_p (si
); tsi_next (&si
))
743 newline_and_indent (buffer
, spc
);
746 dump_generic_node (buffer
, tsi_stmt (si
), spc
, flags
, true);
753 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
755 pp_character (buffer
, '=');
757 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
761 pp_string (buffer
, "TARGET_EXPR <");
762 dump_generic_node (buffer
, TARGET_EXPR_SLOT (node
), spc
, flags
, false);
763 pp_character (buffer
, ',');
765 dump_generic_node (buffer
, TARGET_EXPR_INITIAL (node
), spc
, flags
, false);
766 pp_character (buffer
, '>');
770 if (TREE_TYPE (node
) == void_type_node
)
772 pp_string (buffer
, "if (");
773 dump_generic_node (buffer
, COND_EXPR_COND (node
), spc
, flags
, false);
774 pp_character (buffer
, ')');
775 /* The lowered cond_exprs should always be printed in full. */
776 if (COND_EXPR_THEN (node
)
777 && TREE_CODE (COND_EXPR_THEN (node
)) == GOTO_EXPR
778 && COND_EXPR_ELSE (node
)
779 && TREE_CODE (COND_EXPR_ELSE (node
)) == GOTO_EXPR
)
782 dump_generic_node (buffer
, COND_EXPR_THEN (node
), 0, flags
, true);
783 pp_string (buffer
, " else ");
784 dump_generic_node (buffer
, COND_EXPR_ELSE (node
), 0, flags
, true);
786 else if (!(flags
& TDF_SLIM
))
788 /* Output COND_EXPR_THEN. */
789 if (COND_EXPR_THEN (node
))
791 newline_and_indent (buffer
, spc
+2);
792 pp_character (buffer
, '{');
793 newline_and_indent (buffer
, spc
+4);
794 dump_generic_node (buffer
, COND_EXPR_THEN (node
), spc
+4,
796 newline_and_indent (buffer
, spc
+2);
797 pp_character (buffer
, '}');
800 /* Output COND_EXPR_ELSE. */
801 if (COND_EXPR_ELSE (node
))
803 newline_and_indent (buffer
, spc
);
804 pp_string (buffer
, "else");
805 newline_and_indent (buffer
, spc
+2);
806 pp_character (buffer
, '{');
807 newline_and_indent (buffer
, spc
+4);
808 dump_generic_node (buffer
, COND_EXPR_ELSE (node
), spc
+4,
810 newline_and_indent (buffer
, spc
+2);
811 pp_character (buffer
, '}');
818 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
820 pp_character (buffer
, '?');
822 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
824 pp_character (buffer
, ':');
826 dump_generic_node (buffer
, TREE_OPERAND (node
, 2), spc
, flags
, false);
831 pp_character (buffer
, '{');
832 if (!(flags
& TDF_SLIM
))
834 if (BIND_EXPR_VARS (node
))
838 for (op0
= BIND_EXPR_VARS (node
); op0
; op0
= TREE_CHAIN (op0
))
840 print_declaration (buffer
, op0
, spc
+2, flags
);
845 newline_and_indent (buffer
, spc
+2);
846 dump_generic_node (buffer
, BIND_EXPR_BODY (node
), spc
+2, flags
, true);
847 newline_and_indent (buffer
, spc
);
848 pp_character (buffer
, '}');
854 print_call_name (buffer
, node
);
856 /* Print parameters. */
858 pp_character (buffer
, '(');
859 op1
= TREE_OPERAND (node
, 1);
861 dump_generic_node (buffer
, op1
, spc
, flags
, false);
862 pp_character (buffer
, ')');
864 op1
= TREE_OPERAND (node
, 2);
867 pp_string (buffer
, " [static-chain: ");
868 dump_generic_node (buffer
, op1
, spc
, flags
, false);
869 pp_character (buffer
, ']');
872 if (CALL_EXPR_TAILCALL (node
))
873 pp_string (buffer
, " [tail call]");
876 case WITH_CLEANUP_EXPR
:
880 case CLEANUP_POINT_EXPR
:
881 pp_string (buffer
, "<<cleanup_point ");
882 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
883 pp_string (buffer
, ">>");
886 case PLACEHOLDER_EXPR
:
890 /* Binary arithmetic and logic expressions. */
911 case TRUTH_ANDIF_EXPR
:
912 case TRUTH_ORIF_EXPR
:
931 const char *op
= op_symbol (node
);
932 op0
= TREE_OPERAND (node
, 0);
933 op1
= TREE_OPERAND (node
, 1);
935 /* When the operands are expressions with less priority,
936 keep semantics of the tree representation. */
937 if (op_prio (op0
) < op_prio (node
))
939 pp_character (buffer
, '(');
940 dump_generic_node (buffer
, op0
, spc
, flags
, false);
941 pp_character (buffer
, ')');
944 dump_generic_node (buffer
, op0
, spc
, flags
, false);
947 pp_string (buffer
, op
);
950 /* When the operands are expressions with less priority,
951 keep semantics of the tree representation. */
952 if (op_prio (op1
) < op_prio (node
))
954 pp_character (buffer
, '(');
955 dump_generic_node (buffer
, op1
, spc
, flags
, false);
956 pp_character (buffer
, ')');
959 dump_generic_node (buffer
, op1
, spc
, flags
, false);
963 /* Unary arithmetic and logic expressions. */
969 case PREDECREMENT_EXPR
:
970 case PREINCREMENT_EXPR
:
972 if (TREE_CODE (node
) == ADDR_EXPR
973 && (TREE_CODE (TREE_OPERAND (node
, 0)) == STRING_CST
974 || TREE_CODE (TREE_OPERAND (node
, 0)) == FUNCTION_DECL
))
975 ; /* Do not output '&' for strings and function pointers. */
977 pp_string (buffer
, op_symbol (node
));
979 if (op_prio (TREE_OPERAND (node
, 0)) < op_prio (node
))
981 pp_character (buffer
, '(');
982 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
983 pp_character (buffer
, ')');
986 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
989 case POSTDECREMENT_EXPR
:
990 case POSTINCREMENT_EXPR
:
991 if (op_prio (TREE_OPERAND (node
, 0)) < op_prio (node
))
993 pp_character (buffer
, '(');
994 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
995 pp_character (buffer
, ')');
998 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
999 pp_string (buffer
, op_symbol (node
));
1003 pp_string (buffer
, "MIN_EXPR <");
1004 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1005 pp_string (buffer
, ", ");
1006 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
1007 pp_character (buffer
, '>');
1011 pp_string (buffer
, "MAX_EXPR <");
1012 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1013 pp_string (buffer
, ", ");
1014 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
1015 pp_character (buffer
, '>');
1019 pp_string (buffer
, "ABS_EXPR <");
1020 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1021 pp_character (buffer
, '>');
1040 case FIX_TRUNC_EXPR
:
1042 case FIX_FLOOR_EXPR
:
1043 case FIX_ROUND_EXPR
:
1047 type
= TREE_TYPE (node
);
1048 op0
= TREE_OPERAND (node
, 0);
1049 if (type
!= TREE_TYPE (op0
))
1051 pp_character (buffer
, '(');
1052 dump_generic_node (buffer
, type
, spc
, flags
, false);
1053 pp_string (buffer
, ")");
1055 if (op_prio (op0
) < op_prio (node
))
1056 pp_character (buffer
, '(');
1057 dump_generic_node (buffer
, op0
, spc
, flags
, false);
1058 if (op_prio (op0
) < op_prio (node
))
1059 pp_character (buffer
, ')');
1062 case VIEW_CONVERT_EXPR
:
1063 pp_string (buffer
, "VIEW_CONVERT_EXPR<");
1064 dump_generic_node (buffer
, TREE_TYPE (node
), spc
, flags
, false);
1065 pp_string (buffer
, ">(");
1066 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1067 pp_character (buffer
, ')');
1070 case NON_LVALUE_EXPR
:
1071 pp_string (buffer
, "NON_LVALUE_EXPR <");
1072 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1073 pp_character (buffer
, '>');
1077 pp_string (buffer
, "SAVE_EXPR <");
1078 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1079 pp_character (buffer
, '>');
1083 pp_string (buffer
, "UNSAVE_EXPR <");
1084 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1085 pp_character (buffer
, '>');
1092 case ENTRY_VALUE_EXPR
:
1097 pp_string (buffer
, "COMPLEX_EXPR <");
1098 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1099 pp_string (buffer
, ", ");
1100 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
1101 pp_string (buffer
, ">");
1105 pp_string (buffer
, "CONJ_EXPR <");
1106 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1107 pp_string (buffer
, ">");
1111 pp_string (buffer
, "REALPART_EXPR <");
1112 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1113 pp_string (buffer
, ">");
1117 pp_string (buffer
, "IMAGPART_EXPR <");
1118 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1119 pp_string (buffer
, ">");
1123 pp_string (buffer
, "VA_ARG_EXPR <");
1124 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1125 pp_string (buffer
, ">");
1128 case TRY_FINALLY_EXPR
:
1129 case TRY_CATCH_EXPR
:
1130 pp_string (buffer
, "try");
1131 newline_and_indent (buffer
, spc
+2);
1132 pp_string (buffer
, "{");
1133 newline_and_indent (buffer
, spc
+4);
1134 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
+4, flags
, true);
1135 newline_and_indent (buffer
, spc
+2);
1136 pp_string (buffer
, "}");
1137 newline_and_indent (buffer
, spc
);
1139 (TREE_CODE (node
) == TRY_CATCH_EXPR
) ? "catch" : "finally");
1140 newline_and_indent (buffer
, spc
+2);
1141 pp_string (buffer
, "{");
1142 newline_and_indent (buffer
, spc
+4);
1143 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
+4, flags
, true);
1144 newline_and_indent (buffer
, spc
+2);
1145 pp_string (buffer
, "}");
1150 pp_string (buffer
, "catch (");
1151 dump_generic_node (buffer
, CATCH_TYPES (node
), spc
+2, flags
, false);
1152 pp_string (buffer
, ")");
1153 newline_and_indent (buffer
, spc
+2);
1154 pp_string (buffer
, "{");
1155 newline_and_indent (buffer
, spc
+4);
1156 dump_generic_node (buffer
, CATCH_BODY (node
), spc
+4, flags
, true);
1157 newline_and_indent (buffer
, spc
+2);
1158 pp_string (buffer
, "}");
1162 case EH_FILTER_EXPR
:
1163 pp_string (buffer
, "<<<eh_filter (");
1164 dump_generic_node (buffer
, EH_FILTER_TYPES (node
), spc
+2, flags
, false);
1165 pp_string (buffer
, ")>>>");
1166 newline_and_indent (buffer
, spc
+2);
1167 pp_string (buffer
, "{");
1168 newline_and_indent (buffer
, spc
+4);
1169 dump_generic_node (buffer
, EH_FILTER_FAILURE (node
), spc
+4, flags
, true);
1170 newline_and_indent (buffer
, spc
+2);
1171 pp_string (buffer
, "}");
1175 case GOTO_SUBROUTINE_EXPR
:
1180 op0
= TREE_OPERAND (node
, 0);
1181 /* If this is for break or continue, don't bother printing it. */
1182 if (DECL_NAME (op0
))
1184 const char *name
= IDENTIFIER_POINTER (DECL_NAME (op0
));
1185 if (strcmp (name
, "break") == 0
1186 || strcmp (name
, "continue") == 0)
1189 dump_generic_node (buffer
, op0
, spc
, flags
, false);
1190 pp_character (buffer
, ':');
1191 if (DECL_NONLOCAL (op0
))
1192 pp_string (buffer
, " [non-local]");
1195 case LABELED_BLOCK_EXPR
:
1196 op0
= LABELED_BLOCK_LABEL (node
);
1197 /* If this is for break or continue, don't bother printing it. */
1198 if (DECL_NAME (op0
))
1200 const char *name
= IDENTIFIER_POINTER (DECL_NAME (op0
));
1201 if (strcmp (name
, "break") == 0
1202 || strcmp (name
, "continue") == 0)
1204 dump_generic_node (buffer
, LABELED_BLOCK_BODY (node
), spc
, flags
, false);
1208 dump_generic_node (buffer
, LABELED_BLOCK_LABEL (node
), spc
, flags
, false);
1209 pp_string (buffer
, ": {");
1210 if (!(flags
& TDF_SLIM
))
1211 newline_and_indent (buffer
, spc
+2);
1212 dump_generic_node (buffer
, LABELED_BLOCK_BODY (node
), spc
+2, flags
, true);
1214 newline_and_indent (buffer
, spc
);
1215 pp_character (buffer
, '}');
1219 case EXIT_BLOCK_EXPR
:
1220 op0
= LABELED_BLOCK_LABEL (EXIT_BLOCK_LABELED_BLOCK (node
));
1221 /* If this is for a break or continue, print it accordingly. */
1222 if (DECL_NAME (op0
))
1224 const char *name
= IDENTIFIER_POINTER (DECL_NAME (op0
));
1225 if (strcmp (name
, "break") == 0
1226 || strcmp (name
, "continue") == 0)
1228 pp_string (buffer
, name
);
1232 pp_string (buffer
, "<<<exit block ");
1233 dump_generic_node (buffer
, op0
, spc
, flags
, false);
1234 pp_string (buffer
, ">>>");
1238 pp_string (buffer
, "<<<exception object>>>");
1242 pp_string (buffer
, "<<<filter object>>>");
1246 pp_string (buffer
, "while (1)");
1247 if (!(flags
& TDF_SLIM
))
1249 newline_and_indent (buffer
, spc
+2);
1250 pp_character (buffer
, '{');
1251 newline_and_indent (buffer
, spc
+4);
1252 dump_generic_node (buffer
, LOOP_EXPR_BODY (node
), spc
+4, flags
, true);
1253 newline_and_indent (buffer
, spc
+2);
1254 pp_character (buffer
, '}');
1260 pp_string (buffer
, "return");
1261 op0
= TREE_OPERAND (node
, 0);
1265 if (TREE_CODE (op0
) == MODIFY_EXPR
)
1266 dump_generic_node (buffer
, TREE_OPERAND (op0
, 1), spc
, flags
, false);
1268 dump_generic_node (buffer
, op0
, spc
, flags
, false);
1273 pp_string (buffer
, "if (");
1274 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1275 pp_string (buffer
, ") break");
1279 pp_string (buffer
, "switch (");
1280 dump_generic_node (buffer
, SWITCH_COND (node
), spc
, flags
, false);
1281 pp_character (buffer
, ')');
1282 if (!(flags
& TDF_SLIM
))
1284 newline_and_indent (buffer
, spc
+2);
1285 pp_character (buffer
, '{');
1286 if (SWITCH_BODY (node
))
1288 newline_and_indent (buffer
, spc
+4);
1289 dump_generic_node (buffer
, SWITCH_BODY (node
), spc
+4, flags
, true);
1293 tree vec
= SWITCH_LABELS (node
);
1294 size_t i
, n
= TREE_VEC_LENGTH (vec
);
1295 for (i
= 0; i
< n
; ++i
)
1297 tree elt
= TREE_VEC_ELT (vec
, i
);
1298 newline_and_indent (buffer
, spc
+4);
1299 dump_generic_node (buffer
, elt
, spc
+4, flags
, false);
1300 pp_string (buffer
, " goto ");
1301 dump_generic_node (buffer
, CASE_LABEL (elt
), spc
+4, flags
, true);
1302 pp_semicolon (buffer
);
1305 newline_and_indent (buffer
, spc
+2);
1306 pp_character (buffer
, '}');
1312 op0
= GOTO_DESTINATION (node
);
1313 if (TREE_CODE (op0
) != SSA_NAME
1317 const char *name
= IDENTIFIER_POINTER (DECL_NAME (op0
));
1318 if (strcmp (name
, "break") == 0
1319 || strcmp (name
, "continue") == 0)
1321 pp_string (buffer
, name
);
1325 pp_string (buffer
, "goto ");
1326 dump_generic_node (buffer
, op0
, spc
, flags
, false);
1330 pp_string (buffer
, "resx");
1331 /* ??? Any sensible way to present the eh region? */
1335 pp_string (buffer
, "__asm__");
1336 if (ASM_VOLATILE_P (node
))
1337 pp_string (buffer
, " __volatile__");
1338 pp_character (buffer
, '(');
1339 dump_generic_node (buffer
, ASM_STRING (node
), spc
, flags
, false);
1340 pp_character (buffer
, ':');
1341 dump_generic_node (buffer
, ASM_OUTPUTS (node
), spc
, flags
, false);
1342 pp_character (buffer
, ':');
1343 dump_generic_node (buffer
, ASM_INPUTS (node
), spc
, flags
, false);
1344 if (ASM_CLOBBERS (node
))
1346 pp_character (buffer
, ':');
1347 dump_generic_node (buffer
, ASM_CLOBBERS (node
), spc
, flags
, false);
1349 pp_string (buffer
, ")");
1352 case CASE_LABEL_EXPR
:
1353 if (CASE_LOW (node
) && CASE_HIGH (node
))
1355 pp_string (buffer
, "case ");
1356 dump_generic_node (buffer
, CASE_LOW (node
), spc
, flags
, false);
1357 pp_string (buffer
, " ... ");
1358 dump_generic_node (buffer
, CASE_HIGH (node
), spc
, flags
, false);
1360 else if (CASE_LOW (node
))
1362 pp_string (buffer
, "case ");
1363 dump_generic_node (buffer
, CASE_LOW (node
), spc
, flags
, false);
1366 pp_string (buffer
, "default ");
1367 pp_character (buffer
, ':');
1371 pp_string (buffer
, "VTABLE_REF <(");
1372 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1373 pp_string (buffer
, "),");
1374 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
1375 pp_character (buffer
, ',');
1376 dump_generic_node (buffer
, TREE_OPERAND (node
, 2), spc
, flags
, false);
1377 pp_character (buffer
, '>');
1384 dump_generic_node (buffer
, PHI_RESULT (node
), spc
, flags
, false);
1385 pp_string (buffer
, " = PHI <");
1386 for (i
= 0; i
< PHI_NUM_ARGS (node
); i
++)
1388 dump_generic_node (buffer
, PHI_ARG_DEF (node
, i
), spc
, flags
, false);
1389 pp_string (buffer
, "(");
1390 pp_decimal_int (buffer
, PHI_ARG_EDGE (node
, i
)->src
->index
);
1391 pp_string (buffer
, ")");
1392 if (i
< PHI_NUM_ARGS (node
) - 1)
1393 pp_string (buffer
, ", ");
1395 pp_string (buffer
, ">;");
1400 dump_generic_node (buffer
, SSA_NAME_VAR (node
), spc
, flags
, false);
1401 pp_string (buffer
, "_");
1402 pp_decimal_int (buffer
, SSA_NAME_VERSION (node
));
1409 if (is_stmt
&& is_expr
)
1410 pp_semicolon (buffer
);
1411 pp_write_text_to_stream (buffer
);
1416 /* Print the declaration of a variable. */
1419 print_declaration (pretty_printer
*buffer
, tree t
, int spc
, int flags
)
1421 /* Don't print type declarations. */
1422 if (TREE_CODE (t
) == TYPE_DECL
)
1427 if (DECL_REGISTER (t
))
1428 pp_string (buffer
, "register ");
1430 if (TREE_PUBLIC (t
) && DECL_EXTERNAL (t
))
1431 pp_string (buffer
, "extern ");
1432 else if (TREE_STATIC (t
))
1433 pp_string (buffer
, "static ");
1435 /* Print the type and name. */
1436 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
1440 /* Print array's type. */
1441 tmp
= TREE_TYPE (t
);
1442 while (TREE_CODE (TREE_TYPE (tmp
)) == ARRAY_TYPE
)
1443 tmp
= TREE_TYPE (tmp
);
1444 dump_generic_node (buffer
, TREE_TYPE (tmp
), spc
, flags
, false);
1446 /* Print variable's name. */
1448 dump_generic_node (buffer
, t
, spc
, flags
, false);
1450 /* Print the dimensions. */
1451 tmp
= TREE_TYPE (t
);
1452 while (TREE_CODE (tmp
) == ARRAY_TYPE
)
1454 pp_character (buffer
, '[');
1455 if (TYPE_DOMAIN (tmp
))
1457 if (TREE_CODE (TYPE_SIZE (tmp
)) == INTEGER_CST
)
1458 pp_wide_integer (buffer
,
1459 TREE_INT_CST_LOW (TYPE_SIZE (tmp
)) /
1460 TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (tmp
))));
1462 dump_generic_node (buffer
, TYPE_SIZE_UNIT (tmp
), spc
, flags
,
1465 pp_character (buffer
, ']');
1466 tmp
= TREE_TYPE (tmp
);
1471 /* Print type declaration. */
1472 dump_generic_node (buffer
, TREE_TYPE (t
), spc
, flags
, false);
1474 /* Print variable's name. */
1476 dump_generic_node (buffer
, t
, spc
, flags
, false);
1479 /* The initial value of a function serves to determine wether the function
1480 is declared or defined. So the following does not apply to function
1482 if (TREE_CODE (t
) != FUNCTION_DECL
)
1484 /* Print the initial value. */
1485 if (DECL_INITIAL (t
))
1488 pp_character (buffer
, '=');
1490 dump_generic_node (buffer
, DECL_INITIAL (t
), spc
, flags
, false);
1494 pp_character (buffer
, ';');
1498 /* Prints a structure: name, fields, and methods.
1499 FIXME: Still incomplete. */
1502 print_struct_decl (pretty_printer
*buffer
, tree node
, int spc
, int flags
)
1504 /* Print the name of the structure. */
1505 if (TYPE_NAME (node
))
1508 if (TREE_CODE (node
) == RECORD_TYPE
)
1509 pp_string (buffer
, "struct ");
1510 else if ((TREE_CODE (node
) == UNION_TYPE
1511 || TREE_CODE (node
) == QUAL_UNION_TYPE
))
1512 pp_string (buffer
, "union ");
1514 dump_generic_node (buffer
, TYPE_NAME (node
), spc
, 0, false);
1517 /* Print the contents of the structure. */
1518 pp_newline (buffer
);
1520 pp_character (buffer
, '{');
1521 pp_newline (buffer
);
1523 /* Print the fields of the structure. */
1526 tmp
= TYPE_FIELDS (node
);
1529 /* Avoid to print recursively the structure. */
1530 /* FIXME : Not implemented correctly...,
1531 what about the case when we have a cycle in the contain graph? ...
1532 Maybe this could be solved by looking at the scope in which the
1533 structure was declared. */
1534 if (TREE_TYPE (tmp
) != node
1535 || (TREE_CODE (TREE_TYPE (tmp
)) == POINTER_TYPE
1536 && TREE_TYPE (TREE_TYPE (tmp
)) != node
))
1538 print_declaration (buffer
, tmp
, spc
+2, flags
);
1539 pp_newline (buffer
);
1545 tmp
= TREE_CHAIN (tmp
);
1549 pp_character (buffer
, '}');
1552 /* Return the priority of the operator OP.
1554 From lowest to highest precedence with either left-to-right (L-R)
1555 or right-to-left (R-L) associativity]:
1558 2 [R-L] = += -= *= /= %= &= ^= |= <<= >>=
1570 14 [R-L] ! ~ ++ -- + - * & (type) sizeof
1571 15 [L-R] fn() [] -> .
1573 unary +, - and * have higher precedence than the corresponding binary
1582 switch (TREE_CODE (op
))
1597 case TRUTH_ORIF_EXPR
:
1600 case TRUTH_AND_EXPR
:
1601 case TRUTH_ANDIF_EXPR
:
1608 case TRUTH_XOR_EXPR
:
1625 case UNORDERED_EXPR
:
1643 case TRUNC_DIV_EXPR
:
1645 case FLOOR_DIV_EXPR
:
1646 case ROUND_DIV_EXPR
:
1648 case EXACT_DIV_EXPR
:
1649 case TRUNC_MOD_EXPR
:
1651 case FLOOR_MOD_EXPR
:
1652 case ROUND_MOD_EXPR
:
1655 case TRUTH_NOT_EXPR
:
1657 case POSTINCREMENT_EXPR
:
1658 case POSTDECREMENT_EXPR
:
1659 case PREINCREMENT_EXPR
:
1660 case PREDECREMENT_EXPR
:
1667 case FIX_TRUNC_EXPR
:
1669 case FIX_FLOOR_EXPR
:
1670 case FIX_ROUND_EXPR
:
1676 case ARRAY_RANGE_REF
:
1680 /* Special expressions. */
1689 case NON_LVALUE_EXPR
:
1690 return op_prio (TREE_OPERAND (op
, 0));
1693 /* Return an arbitrarily high precedence to avoid surrounding single
1694 VAR_DECLs in ()s. */
1700 /* Return the symbol associated with operator OP. */
1708 switch (TREE_CODE (op
))
1714 case TRUTH_ORIF_EXPR
:
1717 case TRUTH_AND_EXPR
:
1718 case TRUTH_ANDIF_EXPR
:
1724 case TRUTH_XOR_EXPR
:
1734 case UNORDERED_EXPR
:
1784 case TRUTH_NOT_EXPR
:
1791 case TRUNC_DIV_EXPR
:
1793 case FLOOR_DIV_EXPR
:
1794 case ROUND_DIV_EXPR
:
1796 case EXACT_DIV_EXPR
:
1799 case TRUNC_MOD_EXPR
:
1801 case FLOOR_MOD_EXPR
:
1802 case ROUND_MOD_EXPR
:
1805 case PREDECREMENT_EXPR
:
1808 case PREINCREMENT_EXPR
:
1811 case POSTDECREMENT_EXPR
:
1814 case POSTINCREMENT_EXPR
:
1817 case REFERENCE_EXPR
:
1821 return "<<< ??? >>>";
1825 /* Prints the name of a CALL_EXPR. */
1828 print_call_name (pretty_printer
*buffer
, tree node
)
1832 if (TREE_CODE (node
) != CALL_EXPR
)
1835 op0
= TREE_OPERAND (node
, 0);
1837 if (TREE_CODE (op0
) == NON_LVALUE_EXPR
)
1838 op0
= TREE_OPERAND (op0
, 0);
1840 switch (TREE_CODE (op0
))
1844 PRINT_FUNCTION_NAME (op0
);
1850 dump_generic_node (buffer
, TREE_OPERAND (op0
, 0), 0, 0, false);
1854 pp_string (buffer
, "(");
1855 dump_generic_node (buffer
, TREE_OPERAND (op0
, 0), 0, 0, false);
1856 pp_string (buffer
, ") ? ");
1857 dump_generic_node (buffer
, TREE_OPERAND (op0
, 1), 0, 0, false);
1858 pp_string (buffer
, " : ");
1859 dump_generic_node (buffer
, TREE_OPERAND (op0
, 2), 0, 0, false);
1863 /* The function is a pointer contained in a structure. */
1864 if (TREE_CODE (TREE_OPERAND (op0
, 0)) == INDIRECT_REF
||
1865 TREE_CODE (TREE_OPERAND (op0
, 0)) == VAR_DECL
)
1866 PRINT_FUNCTION_NAME (TREE_OPERAND (op0
, 1));
1868 dump_generic_node (buffer
, TREE_OPERAND (op0
, 0), 0, 0, false);
1870 We can have several levels of structures and a function
1871 pointer inside. This is not implemented yet... */
1876 if (TREE_CODE (TREE_OPERAND (op0
, 0)) == VAR_DECL
)
1877 PRINT_FUNCTION_NAME (TREE_OPERAND (op0
, 0));
1879 dump_generic_node (buffer
, op0
, 0, 0, false);
1883 dump_generic_node (buffer
, op0
, 0, 0, false);
1891 /* Parses the string STR and replaces new-lines by '\n', tabs by '\t', ... */
1894 pretty_print_string (pretty_printer
*buffer
, const char *str
)
1904 pp_string (buffer
, "\\b");
1908 pp_string (buffer
, "\\f");
1912 pp_string (buffer
, "\\n");
1916 pp_string (buffer
, "\\r");
1920 pp_string (buffer
, "\\t");
1924 pp_string (buffer
, "\\v");
1928 pp_string (buffer
, "\\\\");
1932 pp_string (buffer
, "\\\"");
1936 pp_string (buffer
, "\\'");
1940 pp_string (buffer
, "\\0");
1944 pp_string (buffer
, "\\1");
1948 pp_string (buffer
, "\\2");
1952 pp_string (buffer
, "\\3");
1956 pp_string (buffer
, "\\4");
1960 pp_string (buffer
, "\\5");
1964 pp_string (buffer
, "\\6");
1968 pp_string (buffer
, "\\7");
1972 pp_character (buffer
, str
[0]);
1980 maybe_init_pretty_print (FILE *file
)
1984 pp_construct (&buffer
, /* prefix */NULL
, /* line-width */0);
1985 pp_needs_newline (&buffer
) = true;
1989 buffer
.buffer
->stream
= file
;
1993 newline_and_indent (pretty_printer
*buffer
, int spc
)
1995 pp_newline (buffer
);
2000 dump_vops (pretty_printer
*buffer
, tree stmt
, int spc
, int flags
)
2003 stmt_ann_t ann
= stmt_ann (stmt
);
2004 v_may_def_optype v_may_defs
= V_MAY_DEF_OPS (ann
);
2005 v_must_def_optype v_must_defs
= V_MUST_DEF_OPS (ann
);
2006 vuse_optype vuses
= VUSE_OPS (ann
);
2008 for (i
= 0; i
< NUM_V_MAY_DEFS (v_may_defs
); i
++)
2010 pp_string (buffer
, "# ");
2011 dump_generic_node (buffer
, V_MAY_DEF_RESULT (v_may_defs
, i
),
2012 spc
+ 2, flags
, false);
2013 pp_string (buffer
, " = V_MAY_DEF <");
2014 dump_generic_node (buffer
, V_MAY_DEF_OP (v_may_defs
, i
),
2015 spc
+ 2, flags
, false);
2016 pp_string (buffer
, ">;");
2017 newline_and_indent (buffer
, spc
);
2020 for (i
= 0; i
< NUM_V_MUST_DEFS (v_must_defs
); i
++)
2022 tree v_must_def
= V_MUST_DEF_OP (v_must_defs
, i
);
2023 pp_string (buffer
, "# V_MUST_DEF <");
2024 dump_generic_node (buffer
, v_must_def
, spc
+ 2, flags
, false);
2025 pp_string (buffer
, ">;");
2026 newline_and_indent (buffer
, spc
);
2029 for (i
= 0; i
< NUM_VUSES (vuses
); i
++)
2031 tree vuse
= VUSE_OP (vuses
, i
);
2032 pp_string (buffer
, "# VUSE <");
2033 dump_generic_node (buffer
, vuse
, spc
+ 2, flags
, false);
2034 pp_string (buffer
, ">;");
2035 newline_and_indent (buffer
, spc
);
2039 /* Dumps basic block BB to FILE with details described by FLAGS and
2040 indented by INDENT spaces. */
2043 dump_generic_bb (FILE *file
, basic_block bb
, int indent
, int flags
)
2045 maybe_init_pretty_print (file
);
2046 dumping_stmts
= true;
2047 dump_generic_bb_buff (&buffer
, bb
, indent
, flags
);
2051 /* Dumps header of basic block BB to buffer BUFFER indented by INDENT
2052 spaces and details described by flags. */
2055 dump_bb_header (pretty_printer
*buffer
, basic_block bb
, int indent
, int flags
)
2060 if (flags
& TDF_BLOCKS
)
2063 pp_string (buffer
, "# BLOCK ");
2064 pp_decimal_int (buffer
, bb
->index
);
2066 if (flags
& TDF_LINENO
)
2068 block_stmt_iterator bsi
;
2070 for (bsi
= bsi_start (bb
); !bsi_end_p (bsi
); bsi_next (&bsi
))
2071 if (get_lineno (bsi_stmt (bsi
)) != -1)
2073 pp_string (buffer
, ", starting at line ");
2074 pp_decimal_int (buffer
, get_lineno (bsi_stmt (bsi
)));
2078 newline_and_indent (buffer
, indent
);
2080 pp_string (buffer
, "# PRED:");
2081 pp_write_text_to_stream (buffer
);
2082 for (e
= bb
->pred
; e
; e
= e
->pred_next
)
2083 if (flags
& TDF_SLIM
)
2085 pp_string (buffer
, " ");
2086 if (e
->src
== ENTRY_BLOCK_PTR
)
2087 pp_string (buffer
, "ENTRY");
2089 pp_decimal_int (buffer
, e
->src
->index
);
2092 dump_edge_info (buffer
->buffer
->stream
, e
, 0);
2093 pp_newline (buffer
);
2097 stmt
= first_stmt (bb
);
2098 if (!stmt
|| TREE_CODE (stmt
) != LABEL_EXPR
)
2100 INDENT (indent
- 2);
2101 pp_string (buffer
, "<bb ");
2102 pp_decimal_int (buffer
, bb
->index
);
2103 pp_string (buffer
, ">:");
2104 pp_newline (buffer
);
2109 /* Dumps end of basic block BB to buffer BUFFER indented by INDENT
2113 dump_bb_end (pretty_printer
*buffer
, basic_block bb
, int indent
, int flags
)
2118 pp_string (buffer
, "# SUCC:");
2119 pp_write_text_to_stream (buffer
);
2120 for (e
= bb
->succ
; e
; e
= e
->succ_next
)
2121 if (flags
& TDF_SLIM
)
2123 pp_string (buffer
, " ");
2124 if (e
->dest
== EXIT_BLOCK_PTR
)
2125 pp_string (buffer
, "EXIT");
2127 pp_decimal_int (buffer
, e
->dest
->index
);
2130 dump_edge_info (buffer
->buffer
->stream
, e
, 1);
2131 pp_newline (buffer
);
2134 /* Dumps phi nodes of basic block BB to buffer BUFFER with details described by
2135 FLAGS indented by INDENT spaces. */
2138 dump_phi_nodes (pretty_printer
*buffer
, basic_block bb
, int indent
, int flags
)
2140 tree phi
= phi_nodes (bb
);
2144 for (; phi
; phi
= PHI_CHAIN (phi
))
2146 if (is_gimple_reg (PHI_RESULT (phi
)) || (flags
& TDF_VOPS
))
2149 pp_string (buffer
, "# ");
2150 dump_generic_node (buffer
, phi
, indent
, flags
, false);
2151 pp_newline (buffer
);
2156 /* Dump jump to basic block BB that is represented implicitly in the cfg
2160 pp_cfg_jump (pretty_printer
*buffer
, basic_block bb
)
2164 stmt
= first_stmt (bb
);
2166 pp_string (buffer
, "goto <bb ");
2167 pp_decimal_int (buffer
, bb
->index
);
2168 pp_string (buffer
, ">");
2169 if (stmt
&& TREE_CODE (stmt
) == LABEL_EXPR
)
2171 pp_string (buffer
, " (");
2172 dump_generic_node (buffer
, LABEL_EXPR_LABEL (stmt
), 0, 0, false);
2173 pp_string (buffer
, ")");
2175 pp_semicolon (buffer
);
2178 /* Dump edges represented implicitly in basic block BB to BUFFER, indented
2179 by INDENT spaces, with details given by FLAGS. */
2182 dump_implicit_edges (pretty_printer
*buffer
, basic_block bb
, int indent
,
2187 /* If there is a fallthru edge, we may need to add an artificial goto to the
2189 for (e
= bb
->succ
; e
; e
= e
->succ_next
)
2190 if (e
->flags
& EDGE_FALLTHRU
)
2192 if (e
&& e
->dest
!= bb
->next_bb
)
2196 if ((flags
& TDF_LINENO
) && e
->goto_locus
)
2198 pp_character (buffer
, '[');
2199 if (e
->goto_locus
->file
)
2201 pp_string (buffer
, e
->goto_locus
->file
);
2202 pp_string (buffer
, " : ");
2204 pp_decimal_int (buffer
, e
->goto_locus
->line
);
2205 pp_string (buffer
, "] ");
2208 pp_cfg_jump (buffer
, e
->dest
);
2209 pp_newline (buffer
);
2213 /* Dumps basic block BB to buffer BUFFER with details described by FLAGS and
2214 indented by INDENT spaces. */
2217 dump_generic_bb_buff (pretty_printer
*buffer
, basic_block bb
,
2218 int indent
, int flags
)
2220 block_stmt_iterator bsi
;
2222 int label_indent
= indent
- 2;
2224 if (label_indent
< 0)
2227 dump_bb_header (buffer
, bb
, indent
, flags
);
2230 dump_phi_nodes (buffer
, bb
, indent
, flags
);
2232 for (bsi
= bsi_start (bb
); !bsi_end_p (bsi
); bsi_next (&bsi
))
2236 stmt
= bsi_stmt (bsi
);
2238 curr_indent
= TREE_CODE (stmt
) == LABEL_EXPR
? label_indent
: indent
;
2240 INDENT (curr_indent
);
2241 dump_generic_node (buffer
, stmt
, curr_indent
, flags
, true);
2242 pp_newline (buffer
);
2245 dump_implicit_edges (buffer
, bb
, indent
, flags
);
2247 if (flags
& TDF_BLOCKS
)
2248 dump_bb_end (buffer
, bb
, indent
, flags
);