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
, "OBJ_TYPE_REF(");
1372 dump_generic_node (buffer
, OBJ_TYPE_REF_EXPR (node
), spc
, flags
, false);
1373 pp_character (buffer
, ';');
1374 dump_generic_node (buffer
, OBJ_TYPE_REF_OBJECT (node
), spc
, flags
, false);
1375 pp_character (buffer
, '-');
1376 pp_character (buffer
, '>');
1377 dump_generic_node (buffer
, OBJ_TYPE_REF_TOKEN (node
), spc
, flags
, false);
1378 pp_character (buffer
, ')');
1385 dump_generic_node (buffer
, PHI_RESULT (node
), spc
, flags
, false);
1386 pp_string (buffer
, " = PHI <");
1387 for (i
= 0; i
< PHI_NUM_ARGS (node
); i
++)
1389 dump_generic_node (buffer
, PHI_ARG_DEF (node
, i
), spc
, flags
, false);
1390 pp_string (buffer
, "(");
1391 pp_decimal_int (buffer
, PHI_ARG_EDGE (node
, i
)->src
->index
);
1392 pp_string (buffer
, ")");
1393 if (i
< PHI_NUM_ARGS (node
) - 1)
1394 pp_string (buffer
, ", ");
1396 pp_string (buffer
, ">;");
1401 dump_generic_node (buffer
, SSA_NAME_VAR (node
), spc
, flags
, false);
1402 pp_string (buffer
, "_");
1403 pp_decimal_int (buffer
, SSA_NAME_VERSION (node
));
1410 if (is_stmt
&& is_expr
)
1411 pp_semicolon (buffer
);
1412 pp_write_text_to_stream (buffer
);
1417 /* Print the declaration of a variable. */
1420 print_declaration (pretty_printer
*buffer
, tree t
, int spc
, int flags
)
1422 /* Don't print type declarations. */
1423 if (TREE_CODE (t
) == TYPE_DECL
)
1428 if (DECL_REGISTER (t
))
1429 pp_string (buffer
, "register ");
1431 if (TREE_PUBLIC (t
) && DECL_EXTERNAL (t
))
1432 pp_string (buffer
, "extern ");
1433 else if (TREE_STATIC (t
))
1434 pp_string (buffer
, "static ");
1436 /* Print the type and name. */
1437 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
1441 /* Print array's type. */
1442 tmp
= TREE_TYPE (t
);
1443 while (TREE_CODE (TREE_TYPE (tmp
)) == ARRAY_TYPE
)
1444 tmp
= TREE_TYPE (tmp
);
1445 dump_generic_node (buffer
, TREE_TYPE (tmp
), spc
, flags
, false);
1447 /* Print variable's name. */
1449 dump_generic_node (buffer
, t
, spc
, flags
, false);
1451 /* Print the dimensions. */
1452 tmp
= TREE_TYPE (t
);
1453 while (TREE_CODE (tmp
) == ARRAY_TYPE
)
1455 pp_character (buffer
, '[');
1456 if (TYPE_DOMAIN (tmp
))
1458 if (TREE_CODE (TYPE_SIZE (tmp
)) == INTEGER_CST
)
1459 pp_wide_integer (buffer
,
1460 TREE_INT_CST_LOW (TYPE_SIZE (tmp
)) /
1461 TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (tmp
))));
1463 dump_generic_node (buffer
, TYPE_SIZE_UNIT (tmp
), spc
, flags
,
1466 pp_character (buffer
, ']');
1467 tmp
= TREE_TYPE (tmp
);
1472 /* Print type declaration. */
1473 dump_generic_node (buffer
, TREE_TYPE (t
), spc
, flags
, false);
1475 /* Print variable's name. */
1477 dump_generic_node (buffer
, t
, spc
, flags
, false);
1480 /* The initial value of a function serves to determine wether the function
1481 is declared or defined. So the following does not apply to function
1483 if (TREE_CODE (t
) != FUNCTION_DECL
)
1485 /* Print the initial value. */
1486 if (DECL_INITIAL (t
))
1489 pp_character (buffer
, '=');
1491 dump_generic_node (buffer
, DECL_INITIAL (t
), spc
, flags
, false);
1495 pp_character (buffer
, ';');
1499 /* Prints a structure: name, fields, and methods.
1500 FIXME: Still incomplete. */
1503 print_struct_decl (pretty_printer
*buffer
, tree node
, int spc
, int flags
)
1505 /* Print the name of the structure. */
1506 if (TYPE_NAME (node
))
1509 if (TREE_CODE (node
) == RECORD_TYPE
)
1510 pp_string (buffer
, "struct ");
1511 else if ((TREE_CODE (node
) == UNION_TYPE
1512 || TREE_CODE (node
) == QUAL_UNION_TYPE
))
1513 pp_string (buffer
, "union ");
1515 dump_generic_node (buffer
, TYPE_NAME (node
), spc
, 0, false);
1518 /* Print the contents of the structure. */
1519 pp_newline (buffer
);
1521 pp_character (buffer
, '{');
1522 pp_newline (buffer
);
1524 /* Print the fields of the structure. */
1527 tmp
= TYPE_FIELDS (node
);
1530 /* Avoid to print recursively the structure. */
1531 /* FIXME : Not implemented correctly...,
1532 what about the case when we have a cycle in the contain graph? ...
1533 Maybe this could be solved by looking at the scope in which the
1534 structure was declared. */
1535 if (TREE_TYPE (tmp
) != node
1536 || (TREE_CODE (TREE_TYPE (tmp
)) == POINTER_TYPE
1537 && TREE_TYPE (TREE_TYPE (tmp
)) != node
))
1539 print_declaration (buffer
, tmp
, spc
+2, flags
);
1540 pp_newline (buffer
);
1546 tmp
= TREE_CHAIN (tmp
);
1550 pp_character (buffer
, '}');
1553 /* Return the priority of the operator OP.
1555 From lowest to highest precedence with either left-to-right (L-R)
1556 or right-to-left (R-L) associativity]:
1559 2 [R-L] = += -= *= /= %= &= ^= |= <<= >>=
1571 14 [R-L] ! ~ ++ -- + - * & (type) sizeof
1572 15 [L-R] fn() [] -> .
1574 unary +, - and * have higher precedence than the corresponding binary
1583 switch (TREE_CODE (op
))
1598 case TRUTH_ORIF_EXPR
:
1601 case TRUTH_AND_EXPR
:
1602 case TRUTH_ANDIF_EXPR
:
1609 case TRUTH_XOR_EXPR
:
1626 case UNORDERED_EXPR
:
1644 case TRUNC_DIV_EXPR
:
1646 case FLOOR_DIV_EXPR
:
1647 case ROUND_DIV_EXPR
:
1649 case EXACT_DIV_EXPR
:
1650 case TRUNC_MOD_EXPR
:
1652 case FLOOR_MOD_EXPR
:
1653 case ROUND_MOD_EXPR
:
1656 case TRUTH_NOT_EXPR
:
1658 case POSTINCREMENT_EXPR
:
1659 case POSTDECREMENT_EXPR
:
1660 case PREINCREMENT_EXPR
:
1661 case PREDECREMENT_EXPR
:
1668 case FIX_TRUNC_EXPR
:
1670 case FIX_FLOOR_EXPR
:
1671 case FIX_ROUND_EXPR
:
1677 case ARRAY_RANGE_REF
:
1681 /* Special expressions. */
1690 case NON_LVALUE_EXPR
:
1691 return op_prio (TREE_OPERAND (op
, 0));
1694 /* Return an arbitrarily high precedence to avoid surrounding single
1695 VAR_DECLs in ()s. */
1701 /* Return the symbol associated with operator OP. */
1709 switch (TREE_CODE (op
))
1715 case TRUTH_ORIF_EXPR
:
1718 case TRUTH_AND_EXPR
:
1719 case TRUTH_ANDIF_EXPR
:
1725 case TRUTH_XOR_EXPR
:
1735 case UNORDERED_EXPR
:
1785 case TRUTH_NOT_EXPR
:
1792 case TRUNC_DIV_EXPR
:
1794 case FLOOR_DIV_EXPR
:
1795 case ROUND_DIV_EXPR
:
1797 case EXACT_DIV_EXPR
:
1800 case TRUNC_MOD_EXPR
:
1802 case FLOOR_MOD_EXPR
:
1803 case ROUND_MOD_EXPR
:
1806 case PREDECREMENT_EXPR
:
1809 case PREINCREMENT_EXPR
:
1812 case POSTDECREMENT_EXPR
:
1815 case POSTINCREMENT_EXPR
:
1818 case REFERENCE_EXPR
:
1822 return "<<< ??? >>>";
1826 /* Prints the name of a CALL_EXPR. */
1829 print_call_name (pretty_printer
*buffer
, tree node
)
1833 if (TREE_CODE (node
) != CALL_EXPR
)
1836 op0
= TREE_OPERAND (node
, 0);
1838 if (TREE_CODE (op0
) == NON_LVALUE_EXPR
)
1839 op0
= TREE_OPERAND (op0
, 0);
1841 switch (TREE_CODE (op0
))
1845 PRINT_FUNCTION_NAME (op0
);
1851 dump_generic_node (buffer
, TREE_OPERAND (op0
, 0), 0, 0, false);
1855 pp_string (buffer
, "(");
1856 dump_generic_node (buffer
, TREE_OPERAND (op0
, 0), 0, 0, false);
1857 pp_string (buffer
, ") ? ");
1858 dump_generic_node (buffer
, TREE_OPERAND (op0
, 1), 0, 0, false);
1859 pp_string (buffer
, " : ");
1860 dump_generic_node (buffer
, TREE_OPERAND (op0
, 2), 0, 0, false);
1864 /* The function is a pointer contained in a structure. */
1865 if (TREE_CODE (TREE_OPERAND (op0
, 0)) == INDIRECT_REF
||
1866 TREE_CODE (TREE_OPERAND (op0
, 0)) == VAR_DECL
)
1867 PRINT_FUNCTION_NAME (TREE_OPERAND (op0
, 1));
1869 dump_generic_node (buffer
, TREE_OPERAND (op0
, 0), 0, 0, false);
1871 We can have several levels of structures and a function
1872 pointer inside. This is not implemented yet... */
1877 if (TREE_CODE (TREE_OPERAND (op0
, 0)) == VAR_DECL
)
1878 PRINT_FUNCTION_NAME (TREE_OPERAND (op0
, 0));
1880 dump_generic_node (buffer
, op0
, 0, 0, false);
1885 dump_generic_node (buffer
, op0
, 0, 0, false);
1893 /* Parses the string STR and replaces new-lines by '\n', tabs by '\t', ... */
1896 pretty_print_string (pretty_printer
*buffer
, const char *str
)
1906 pp_string (buffer
, "\\b");
1910 pp_string (buffer
, "\\f");
1914 pp_string (buffer
, "\\n");
1918 pp_string (buffer
, "\\r");
1922 pp_string (buffer
, "\\t");
1926 pp_string (buffer
, "\\v");
1930 pp_string (buffer
, "\\\\");
1934 pp_string (buffer
, "\\\"");
1938 pp_string (buffer
, "\\'");
1942 pp_string (buffer
, "\\0");
1946 pp_string (buffer
, "\\1");
1950 pp_string (buffer
, "\\2");
1954 pp_string (buffer
, "\\3");
1958 pp_string (buffer
, "\\4");
1962 pp_string (buffer
, "\\5");
1966 pp_string (buffer
, "\\6");
1970 pp_string (buffer
, "\\7");
1974 pp_character (buffer
, str
[0]);
1982 maybe_init_pretty_print (FILE *file
)
1986 pp_construct (&buffer
, /* prefix */NULL
, /* line-width */0);
1987 pp_needs_newline (&buffer
) = true;
1991 buffer
.buffer
->stream
= file
;
1995 newline_and_indent (pretty_printer
*buffer
, int spc
)
1997 pp_newline (buffer
);
2002 dump_vops (pretty_printer
*buffer
, tree stmt
, int spc
, int flags
)
2005 stmt_ann_t ann
= stmt_ann (stmt
);
2006 v_may_def_optype v_may_defs
= V_MAY_DEF_OPS (ann
);
2007 v_must_def_optype v_must_defs
= V_MUST_DEF_OPS (ann
);
2008 vuse_optype vuses
= VUSE_OPS (ann
);
2010 for (i
= 0; i
< NUM_V_MAY_DEFS (v_may_defs
); i
++)
2012 pp_string (buffer
, "# ");
2013 dump_generic_node (buffer
, V_MAY_DEF_RESULT (v_may_defs
, i
),
2014 spc
+ 2, flags
, false);
2015 pp_string (buffer
, " = V_MAY_DEF <");
2016 dump_generic_node (buffer
, V_MAY_DEF_OP (v_may_defs
, i
),
2017 spc
+ 2, flags
, false);
2018 pp_string (buffer
, ">;");
2019 newline_and_indent (buffer
, spc
);
2022 for (i
= 0; i
< NUM_V_MUST_DEFS (v_must_defs
); i
++)
2024 tree v_must_def
= V_MUST_DEF_OP (v_must_defs
, i
);
2025 pp_string (buffer
, "# V_MUST_DEF <");
2026 dump_generic_node (buffer
, v_must_def
, spc
+ 2, flags
, false);
2027 pp_string (buffer
, ">;");
2028 newline_and_indent (buffer
, spc
);
2031 for (i
= 0; i
< NUM_VUSES (vuses
); i
++)
2033 tree vuse
= VUSE_OP (vuses
, i
);
2034 pp_string (buffer
, "# VUSE <");
2035 dump_generic_node (buffer
, vuse
, spc
+ 2, flags
, false);
2036 pp_string (buffer
, ">;");
2037 newline_and_indent (buffer
, spc
);
2041 /* Dumps basic block BB to FILE with details described by FLAGS and
2042 indented by INDENT spaces. */
2045 dump_generic_bb (FILE *file
, basic_block bb
, int indent
, int flags
)
2047 maybe_init_pretty_print (file
);
2048 dumping_stmts
= true;
2049 dump_generic_bb_buff (&buffer
, bb
, indent
, flags
);
2053 /* Dumps header of basic block BB to buffer BUFFER indented by INDENT
2054 spaces and details described by flags. */
2057 dump_bb_header (pretty_printer
*buffer
, basic_block bb
, int indent
, int flags
)
2062 if (flags
& TDF_BLOCKS
)
2065 pp_string (buffer
, "# BLOCK ");
2066 pp_decimal_int (buffer
, bb
->index
);
2068 if (flags
& TDF_LINENO
)
2070 block_stmt_iterator bsi
;
2072 for (bsi
= bsi_start (bb
); !bsi_end_p (bsi
); bsi_next (&bsi
))
2073 if (get_lineno (bsi_stmt (bsi
)) != -1)
2075 pp_string (buffer
, ", starting at line ");
2076 pp_decimal_int (buffer
, get_lineno (bsi_stmt (bsi
)));
2080 newline_and_indent (buffer
, indent
);
2082 pp_string (buffer
, "# PRED:");
2083 pp_write_text_to_stream (buffer
);
2084 for (e
= bb
->pred
; e
; e
= e
->pred_next
)
2085 if (flags
& TDF_SLIM
)
2087 pp_string (buffer
, " ");
2088 if (e
->src
== ENTRY_BLOCK_PTR
)
2089 pp_string (buffer
, "ENTRY");
2091 pp_decimal_int (buffer
, e
->src
->index
);
2094 dump_edge_info (buffer
->buffer
->stream
, e
, 0);
2095 pp_newline (buffer
);
2099 stmt
= first_stmt (bb
);
2100 if (!stmt
|| TREE_CODE (stmt
) != LABEL_EXPR
)
2102 INDENT (indent
- 2);
2103 pp_string (buffer
, "<bb ");
2104 pp_decimal_int (buffer
, bb
->index
);
2105 pp_string (buffer
, ">:");
2106 pp_newline (buffer
);
2111 /* Dumps end of basic block BB to buffer BUFFER indented by INDENT
2115 dump_bb_end (pretty_printer
*buffer
, basic_block bb
, int indent
, int flags
)
2120 pp_string (buffer
, "# SUCC:");
2121 pp_write_text_to_stream (buffer
);
2122 for (e
= bb
->succ
; e
; e
= e
->succ_next
)
2123 if (flags
& TDF_SLIM
)
2125 pp_string (buffer
, " ");
2126 if (e
->dest
== EXIT_BLOCK_PTR
)
2127 pp_string (buffer
, "EXIT");
2129 pp_decimal_int (buffer
, e
->dest
->index
);
2132 dump_edge_info (buffer
->buffer
->stream
, e
, 1);
2133 pp_newline (buffer
);
2136 /* Dumps phi nodes of basic block BB to buffer BUFFER with details described by
2137 FLAGS indented by INDENT spaces. */
2140 dump_phi_nodes (pretty_printer
*buffer
, basic_block bb
, int indent
, int flags
)
2142 tree phi
= phi_nodes (bb
);
2146 for (; phi
; phi
= PHI_CHAIN (phi
))
2148 if (is_gimple_reg (PHI_RESULT (phi
)) || (flags
& TDF_VOPS
))
2151 pp_string (buffer
, "# ");
2152 dump_generic_node (buffer
, phi
, indent
, flags
, false);
2153 pp_newline (buffer
);
2158 /* Dump jump to basic block BB that is represented implicitly in the cfg
2162 pp_cfg_jump (pretty_printer
*buffer
, basic_block bb
)
2166 stmt
= first_stmt (bb
);
2168 pp_string (buffer
, "goto <bb ");
2169 pp_decimal_int (buffer
, bb
->index
);
2170 pp_string (buffer
, ">");
2171 if (stmt
&& TREE_CODE (stmt
) == LABEL_EXPR
)
2173 pp_string (buffer
, " (");
2174 dump_generic_node (buffer
, LABEL_EXPR_LABEL (stmt
), 0, 0, false);
2175 pp_string (buffer
, ")");
2177 pp_semicolon (buffer
);
2180 /* Dump edges represented implicitly in basic block BB to BUFFER, indented
2181 by INDENT spaces, with details given by FLAGS. */
2184 dump_implicit_edges (pretty_printer
*buffer
, basic_block bb
, int indent
,
2189 /* If there is a fallthru edge, we may need to add an artificial goto to the
2191 for (e
= bb
->succ
; e
; e
= e
->succ_next
)
2192 if (e
->flags
& EDGE_FALLTHRU
)
2194 if (e
&& e
->dest
!= bb
->next_bb
)
2198 if ((flags
& TDF_LINENO
) && e
->goto_locus
)
2200 pp_character (buffer
, '[');
2201 if (e
->goto_locus
->file
)
2203 pp_string (buffer
, e
->goto_locus
->file
);
2204 pp_string (buffer
, " : ");
2206 pp_decimal_int (buffer
, e
->goto_locus
->line
);
2207 pp_string (buffer
, "] ");
2210 pp_cfg_jump (buffer
, e
->dest
);
2211 pp_newline (buffer
);
2215 /* Dumps basic block BB to buffer BUFFER with details described by FLAGS and
2216 indented by INDENT spaces. */
2219 dump_generic_bb_buff (pretty_printer
*buffer
, basic_block bb
,
2220 int indent
, int flags
)
2222 block_stmt_iterator bsi
;
2224 int label_indent
= indent
- 2;
2226 if (label_indent
< 0)
2229 dump_bb_header (buffer
, bb
, indent
, flags
);
2232 dump_phi_nodes (buffer
, bb
, indent
, flags
);
2234 for (bsi
= bsi_start (bb
); !bsi_end_p (bsi
); bsi_next (&bsi
))
2238 stmt
= bsi_stmt (bsi
);
2240 curr_indent
= TREE_CODE (stmt
) == LABEL_EXPR
? label_indent
: indent
;
2242 INDENT (curr_indent
);
2243 dump_generic_node (buffer
, stmt
, curr_indent
, flags
, true);
2244 pp_newline (buffer
);
2247 dump_implicit_edges (buffer
, bb
, indent
, flags
);
2249 if (flags
& TDF_BLOCKS
)
2250 dump_bb_end (buffer
, bb
, indent
, flags
);