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 static pretty_printer buffer
;
59 static int initialized
= 0;
60 static bool dumping_stmts
;
62 /* Try to print something for an unknown tree code. */
65 do_niy (pretty_printer
*buffer
, tree node
)
69 pp_string (buffer
, "<<< Unknown tree: ");
70 pp_string (buffer
, tree_code_name
[(int) TREE_CODE (node
)]);
72 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (node
))))
74 len
= first_rtl_op (TREE_CODE (node
));
75 for (i
= 0; i
< len
; ++i
)
77 newline_and_indent (buffer
, 2);
78 dump_generic_node (buffer
, TREE_OPERAND (node
, i
), 2, 0, false);
82 pp_string (buffer
, " >>>\n");
86 debug_generic_expr (tree t
)
88 print_generic_expr (stderr
, t
, TDF_VOPS
|TDF_UID
);
89 fprintf (stderr
, "\n");
93 debug_generic_stmt (tree t
)
95 print_generic_stmt (stderr
, t
, TDF_VOPS
|TDF_UID
);
96 fprintf (stderr
, "\n");
99 /* Prints declaration DECL to the FILE with details specified by FLAGS. */
101 print_generic_decl (FILE *file
, tree decl
, int flags
)
103 maybe_init_pretty_print (file
);
104 dumping_stmts
= true;
105 print_declaration (&buffer
, decl
, 2, flags
);
106 pp_write_text_to_stream (&buffer
);
109 /* Print tree T, and its successors, on file FILE. FLAGS specifies details
110 to show in the dump. See TDF_* in tree.h. */
113 print_generic_stmt (FILE *file
, tree t
, int flags
)
115 maybe_init_pretty_print (file
);
116 dumping_stmts
= true;
117 dump_generic_node (&buffer
, t
, 0, flags
, true);
121 /* Print tree T, and its successors, on file FILE. FLAGS specifies details
122 to show in the dump. See TDF_* in tree.h. The output is indented by
126 print_generic_stmt_indented (FILE *file
, tree t
, int flags
, int indent
)
130 maybe_init_pretty_print (file
);
131 dumping_stmts
= true;
133 for (i
= 0; i
< indent
; i
++)
135 dump_generic_node (&buffer
, t
, indent
, flags
, true);
139 /* Print a single expression T on file FILE. FLAGS specifies details to show
140 in the dump. See TDF_* in tree.h. */
143 print_generic_expr (FILE *file
, tree t
, int flags
)
145 maybe_init_pretty_print (file
);
146 dumping_stmts
= false;
147 dump_generic_node (&buffer
, t
, 0, flags
, false);
150 /* Dump the name of a _DECL node and its DECL_UID if TDF_UID is set
154 dump_decl_name (pretty_printer
*buffer
, tree node
, int flags
)
156 if (DECL_NAME (node
))
157 pp_tree_identifier (buffer
, DECL_NAME (node
));
159 if ((flags
& TDF_UID
)
160 || DECL_NAME (node
) == NULL_TREE
)
162 if (TREE_CODE (node
) == LABEL_DECL
163 && LABEL_DECL_UID (node
) != -1)
164 pp_printf (buffer
, "<L" HOST_WIDE_INT_PRINT_DEC
">",
165 LABEL_DECL_UID (node
));
167 pp_printf (buffer
, "<D%u>", DECL_UID (node
));
171 /* Dump the node NODE on the pretty_printer BUFFER, SPC spaces of indent.
172 FLAGS specifies details to show in the dump (see TDF_* in tree.h). If
173 IS_STMT is true, the object printed is considered to be a statement
174 and it is terminated by ';' if appropriate. */
177 dump_generic_node (pretty_printer
*buffer
, tree node
, int spc
, int flags
,
185 if (node
== NULL_TREE
)
188 is_expr
= EXPR_P (node
);
190 if (TREE_CODE (node
) != ERROR_MARK
191 && is_gimple_stmt (node
)
192 && (flags
& TDF_VOPS
)
194 dump_vops (buffer
, node
, spc
, flags
);
197 && (flags
& TDF_LINENO
)
198 && EXPR_HAS_LOCATION (node
))
200 pp_character (buffer
, '[');
201 if (EXPR_FILENAME (node
))
203 pp_string (buffer
, EXPR_FILENAME (node
));
204 pp_string (buffer
, " : ");
206 pp_decimal_int (buffer
, EXPR_LINENO (node
));
207 pp_string (buffer
, "] ");
210 switch (TREE_CODE (node
))
213 pp_string (buffer
, "<<< error >>>");
216 case IDENTIFIER_NODE
:
217 pp_tree_identifier (buffer
, node
);
221 while (node
&& node
!= error_mark_node
)
223 if (TREE_PURPOSE (node
))
225 dump_generic_node (buffer
, TREE_PURPOSE (node
), spc
, flags
, false);
228 dump_generic_node (buffer
, TREE_VALUE (node
), spc
, flags
, false);
229 node
= TREE_CHAIN (node
);
230 if (node
&& TREE_CODE (node
) == TREE_LIST
)
232 pp_character (buffer
, ',');
239 dump_generic_node (buffer
, BINFO_TYPE (node
), spc
, flags
, false);
255 unsigned int quals
= TYPE_QUALS (node
);
258 if (quals
& TYPE_QUAL_CONST
)
259 pp_string (buffer
, "const ");
260 else if (quals
& TYPE_QUAL_VOLATILE
)
261 pp_string (buffer
, "volatile ");
262 else if (quals
& TYPE_QUAL_RESTRICT
)
263 pp_string (buffer
, "restrict ");
265 class = TREE_CODE_CLASS (TREE_CODE (node
));
269 if (DECL_NAME (node
))
270 dump_decl_name (buffer
, node
, flags
);
272 pp_string (buffer
, "<unnamed type decl>");
274 else if (class == 't')
276 if (TYPE_NAME (node
))
278 if (TREE_CODE (TYPE_NAME (node
)) == IDENTIFIER_NODE
)
279 pp_tree_identifier (buffer
, TYPE_NAME (node
));
280 else if (TREE_CODE (TYPE_NAME (node
)) == TYPE_DECL
281 && DECL_NAME (TYPE_NAME (node
)))
282 dump_decl_name (buffer
, TYPE_NAME (node
), flags
);
284 pp_string (buffer
, "<unnamed type>");
287 pp_string (buffer
, "<unnamed type>");
294 str
= (TREE_CODE (node
) == POINTER_TYPE
? "*" : "&");
296 if (TREE_CODE (TREE_TYPE (node
)) == FUNCTION_TYPE
)
298 tree fnode
= TREE_TYPE (node
);
299 dump_generic_node (buffer
, TREE_TYPE (fnode
), spc
, flags
, false);
301 pp_character (buffer
, '(');
302 pp_string (buffer
, str
);
303 if (TYPE_NAME (node
) && DECL_NAME (TYPE_NAME (node
)))
304 dump_decl_name (buffer
, TYPE_NAME (node
), flags
);
306 pp_printf (buffer
, "<T%x>", TYPE_UID (node
));
308 pp_character (buffer
, ')');
310 pp_character (buffer
, '(');
311 /* Print the argument types. The last element in the list is a
312 VOID_TYPE. The following avoid to print the last element. */
314 tree tmp
= TYPE_ARG_TYPES (fnode
);
315 while (tmp
&& TREE_CHAIN (tmp
) && tmp
!= error_mark_node
)
317 dump_generic_node (buffer
, TREE_VALUE (tmp
), spc
, flags
, false);
318 tmp
= TREE_CHAIN (tmp
);
319 if (TREE_CHAIN (tmp
) && TREE_CODE (TREE_CHAIN (tmp
)) == TREE_LIST
)
321 pp_character (buffer
, ',');
326 pp_character (buffer
, ')');
330 unsigned int quals
= TYPE_QUALS (node
);
332 dump_generic_node (buffer
, TREE_TYPE (node
), spc
, flags
, false);
334 pp_string (buffer
, str
);
336 if (quals
& TYPE_QUAL_CONST
)
337 pp_string (buffer
, " const");
338 else if (quals
& TYPE_QUAL_VOLATILE
)
339 pp_string (buffer
, "volatile");
340 else if (quals
& TYPE_QUAL_RESTRICT
)
341 pp_string (buffer
, " restrict");
350 dump_decl_name (buffer
, TYPE_NAME (TYPE_METHOD_BASETYPE (node
)), flags
);
351 pp_string (buffer
, "::");
362 /* Print the array type. */
363 dump_generic_node (buffer
, TREE_TYPE (node
), spc
, flags
, false);
365 /* Print the dimensions. */
367 while (tmp
&& TREE_CODE (tmp
) == ARRAY_TYPE
)
369 pp_character (buffer
, '[');
372 tree size
= TYPE_SIZE (tmp
);
373 if (TREE_CODE (size
) == INTEGER_CST
)
374 pp_wide_integer (buffer
,
375 TREE_INT_CST_LOW (TYPE_SIZE (tmp
)) /
376 TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (tmp
))));
377 else if (TREE_CODE (size
) == MULT_EXPR
)
378 dump_generic_node (buffer
, TREE_OPERAND (size
, 0), spc
, flags
, false);
381 pp_character (buffer
, ']');
382 tmp
= TREE_TYPE (tmp
);
393 case QUAL_UNION_TYPE
:
394 /* Print the name of the structure. */
395 if (TREE_CODE (node
) == RECORD_TYPE
)
396 pp_string (buffer
, "struct ");
397 else if (TREE_CODE (node
) == UNION_TYPE
)
398 pp_string (buffer
, "union ");
400 if (TYPE_NAME (node
))
401 dump_generic_node (buffer
, TYPE_NAME (node
), spc
, flags
, false);
403 print_struct_decl (buffer
, node
, spc
, flags
);
411 if (TREE_CODE (TREE_TYPE (node
)) == POINTER_TYPE
)
413 /* In the case of a pointer, one may want to divide by the
414 size of the pointed-to type. Unfortunately, this not
415 straightforward. The C front-end maps expressions
420 in such a way that the two INTEGER_CST nodes for "5" have
421 different values but identical types. In the latter
422 case, the 5 is multiplied by sizeof (int) in c-common.c
423 (pointer_int_sum) to convert it to a byte address, and
424 yet the type of the node is left unchanged. Argh. What
425 is consistent though is that the number value corresponds
426 to bytes (UNITS) offset.
428 NB: Neither of the following divisors can be trivially
429 used to recover the original literal:
431 TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (node)))
432 TYPE_PRECISION (TREE_TYPE (TREE_TYPE (node))) */
433 pp_wide_integer (buffer
, TREE_INT_CST_LOW (node
));
434 pp_string (buffer
, "B"); /* pseudo-unit */
436 else if (! host_integerp (node
, 0))
440 if (tree_int_cst_sgn (val
) < 0)
442 pp_character (buffer
, '-');
443 val
= build_int_2 (-TREE_INT_CST_LOW (val
),
444 ~TREE_INT_CST_HIGH (val
)
445 + !TREE_INT_CST_LOW (val
));
447 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
450 static char format
[10]; /* "%x%09999x\0" */
452 sprintf (format
, "%%x%%0%dx", HOST_BITS_PER_INT
/ 4);
453 sprintf (pp_buffer (buffer
)->digit_buffer
, format
,
454 TREE_INT_CST_HIGH (val
),
455 TREE_INT_CST_LOW (val
));
456 pp_string (buffer
, pp_buffer (buffer
)->digit_buffer
);
460 pp_wide_integer (buffer
, TREE_INT_CST_LOW (node
));
464 /* Code copied from print_node. */
467 if (TREE_OVERFLOW (node
))
468 pp_string (buffer
, " overflow");
470 #if !defined(REAL_IS_NOT_DOUBLE) || defined(REAL_ARITHMETIC)
471 d
= TREE_REAL_CST (node
);
472 if (REAL_VALUE_ISINF (d
))
473 pp_string (buffer
, " Inf");
474 else if (REAL_VALUE_ISNAN (d
))
475 pp_string (buffer
, " Nan");
479 real_to_decimal (string
, &d
, sizeof (string
), 0, 1);
480 pp_string (buffer
, string
);
485 unsigned char *p
= (unsigned char *) &TREE_REAL_CST (node
);
486 pp_string (buffer
, "0x");
487 for (i
= 0; i
< sizeof TREE_REAL_CST (node
); i
++)
488 output_formatted_integer (buffer
, "%02x", *p
++);
495 pp_string (buffer
, "__complex__ (");
496 dump_generic_node (buffer
, TREE_REALPART (node
), spc
, flags
, false);
497 pp_string (buffer
, ", ");
498 dump_generic_node (buffer
, TREE_IMAGPART (node
), spc
, flags
, false);
499 pp_string (buffer
, ")");
503 pp_string (buffer
, "\"");
504 pretty_print_string (buffer
, TREE_STRING_POINTER (node
));
505 pp_string (buffer
, "\"");
511 pp_string (buffer
, "{ ");
512 for (elt
= TREE_VECTOR_CST_ELTS (node
); elt
; elt
= TREE_CHAIN (elt
))
514 dump_generic_node (buffer
, TREE_VALUE (elt
), spc
, flags
, false);
515 if (TREE_CHAIN (elt
))
516 pp_string (buffer
, ", ");
518 pp_string (buffer
, " }");
527 dump_decl_name (buffer
, node
, flags
);
531 if (DECL_NAME (node
))
532 dump_decl_name (buffer
, node
, flags
);
533 else if (LABEL_DECL_UID (node
) != -1)
534 pp_printf (buffer
, "<L" HOST_WIDE_INT_PRINT_DEC
">",
535 LABEL_DECL_UID (node
));
537 pp_printf (buffer
, "<D%u>", DECL_UID (node
));
541 if (strcmp (DECL_SOURCE_FILE (node
), "<built-in>") == 0)
543 /* Don't print the declaration of built-in types. */
546 if (DECL_NAME (node
))
548 dump_decl_name (buffer
, node
, flags
);
552 if ((TREE_CODE (TREE_TYPE (node
)) == RECORD_TYPE
553 || TREE_CODE (TREE_TYPE (node
)) == UNION_TYPE
)
554 && 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
));
1407 pp_printf (buffer
, "VH.%d", VALUE_HANDLE_ID (node
));
1414 if (is_stmt
&& is_expr
)
1415 pp_semicolon (buffer
);
1416 pp_write_text_to_stream (buffer
);
1421 /* Print the declaration of a variable. */
1424 print_declaration (pretty_printer
*buffer
, tree t
, int spc
, int flags
)
1426 /* Don't print type declarations. */
1427 if (TREE_CODE (t
) == TYPE_DECL
)
1432 if (DECL_REGISTER (t
))
1433 pp_string (buffer
, "register ");
1435 if (TREE_PUBLIC (t
) && DECL_EXTERNAL (t
))
1436 pp_string (buffer
, "extern ");
1437 else if (TREE_STATIC (t
))
1438 pp_string (buffer
, "static ");
1440 /* Print the type and name. */
1441 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
1445 /* Print array's type. */
1446 tmp
= TREE_TYPE (t
);
1447 while (TREE_CODE (TREE_TYPE (tmp
)) == ARRAY_TYPE
)
1448 tmp
= TREE_TYPE (tmp
);
1449 dump_generic_node (buffer
, TREE_TYPE (tmp
), spc
, flags
, false);
1451 /* Print variable's name. */
1453 dump_generic_node (buffer
, t
, spc
, flags
, false);
1455 /* Print the dimensions. */
1456 tmp
= TREE_TYPE (t
);
1457 while (TREE_CODE (tmp
) == ARRAY_TYPE
)
1459 pp_character (buffer
, '[');
1460 if (TYPE_DOMAIN (tmp
))
1462 if (TREE_CODE (TYPE_SIZE (tmp
)) == INTEGER_CST
)
1463 pp_wide_integer (buffer
,
1464 TREE_INT_CST_LOW (TYPE_SIZE (tmp
)) /
1465 TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (tmp
))));
1467 dump_generic_node (buffer
, TYPE_SIZE_UNIT (tmp
), spc
, flags
,
1470 pp_character (buffer
, ']');
1471 tmp
= TREE_TYPE (tmp
);
1476 /* Print type declaration. */
1477 dump_generic_node (buffer
, TREE_TYPE (t
), spc
, flags
, false);
1479 /* Print variable's name. */
1481 dump_generic_node (buffer
, t
, spc
, flags
, false);
1484 /* The initial value of a function serves to determine wether the function
1485 is declared or defined. So the following does not apply to function
1487 if (TREE_CODE (t
) != FUNCTION_DECL
)
1489 /* Print the initial value. */
1490 if (DECL_INITIAL (t
))
1493 pp_character (buffer
, '=');
1495 dump_generic_node (buffer
, DECL_INITIAL (t
), spc
, flags
, false);
1499 pp_character (buffer
, ';');
1503 /* Prints a structure: name, fields, and methods.
1504 FIXME: Still incomplete. */
1507 print_struct_decl (pretty_printer
*buffer
, tree node
, int spc
, int flags
)
1509 /* Print the name of the structure. */
1510 if (TYPE_NAME (node
))
1513 if (TREE_CODE (node
) == RECORD_TYPE
)
1514 pp_string (buffer
, "struct ");
1515 else if ((TREE_CODE (node
) == UNION_TYPE
1516 || TREE_CODE (node
) == QUAL_UNION_TYPE
))
1517 pp_string (buffer
, "union ");
1519 dump_generic_node (buffer
, TYPE_NAME (node
), spc
, 0, false);
1522 /* Print the contents of the structure. */
1523 pp_newline (buffer
);
1525 pp_character (buffer
, '{');
1526 pp_newline (buffer
);
1528 /* Print the fields of the structure. */
1531 tmp
= TYPE_FIELDS (node
);
1534 /* Avoid to print recursively the structure. */
1535 /* FIXME : Not implemented correctly...,
1536 what about the case when we have a cycle in the contain graph? ...
1537 Maybe this could be solved by looking at the scope in which the
1538 structure was declared. */
1539 if (TREE_TYPE (tmp
) != node
1540 || (TREE_CODE (TREE_TYPE (tmp
)) == POINTER_TYPE
1541 && TREE_TYPE (TREE_TYPE (tmp
)) != node
))
1543 print_declaration (buffer
, tmp
, spc
+2, flags
);
1544 pp_newline (buffer
);
1550 tmp
= TREE_CHAIN (tmp
);
1554 pp_character (buffer
, '}');
1557 /* Return the priority of the operator OP.
1559 From lowest to highest precedence with either left-to-right (L-R)
1560 or right-to-left (R-L) associativity]:
1563 2 [R-L] = += -= *= /= %= &= ^= |= <<= >>=
1575 14 [R-L] ! ~ ++ -- + - * & (type) sizeof
1576 15 [L-R] fn() [] -> .
1578 unary +, - and * have higher precedence than the corresponding binary
1587 switch (TREE_CODE (op
))
1602 case TRUTH_ORIF_EXPR
:
1605 case TRUTH_AND_EXPR
:
1606 case TRUTH_ANDIF_EXPR
:
1613 case TRUTH_XOR_EXPR
:
1630 case UNORDERED_EXPR
:
1648 case TRUNC_DIV_EXPR
:
1650 case FLOOR_DIV_EXPR
:
1651 case ROUND_DIV_EXPR
:
1653 case EXACT_DIV_EXPR
:
1654 case TRUNC_MOD_EXPR
:
1656 case FLOOR_MOD_EXPR
:
1657 case ROUND_MOD_EXPR
:
1660 case TRUTH_NOT_EXPR
:
1662 case POSTINCREMENT_EXPR
:
1663 case POSTDECREMENT_EXPR
:
1664 case PREINCREMENT_EXPR
:
1665 case PREDECREMENT_EXPR
:
1672 case FIX_TRUNC_EXPR
:
1674 case FIX_FLOOR_EXPR
:
1675 case FIX_ROUND_EXPR
:
1681 case ARRAY_RANGE_REF
:
1685 /* Special expressions. */
1694 case NON_LVALUE_EXPR
:
1695 return op_prio (TREE_OPERAND (op
, 0));
1698 /* Return an arbitrarily high precedence to avoid surrounding single
1699 VAR_DECLs in ()s. */
1705 /* Return the symbol associated with operator OP. */
1713 switch (TREE_CODE (op
))
1719 case TRUTH_ORIF_EXPR
:
1722 case TRUTH_AND_EXPR
:
1723 case TRUTH_ANDIF_EXPR
:
1729 case TRUTH_XOR_EXPR
:
1739 case UNORDERED_EXPR
:
1789 case TRUTH_NOT_EXPR
:
1796 case TRUNC_DIV_EXPR
:
1798 case FLOOR_DIV_EXPR
:
1799 case ROUND_DIV_EXPR
:
1801 case EXACT_DIV_EXPR
:
1804 case TRUNC_MOD_EXPR
:
1806 case FLOOR_MOD_EXPR
:
1807 case ROUND_MOD_EXPR
:
1810 case PREDECREMENT_EXPR
:
1813 case PREINCREMENT_EXPR
:
1816 case POSTDECREMENT_EXPR
:
1819 case POSTINCREMENT_EXPR
:
1822 case REFERENCE_EXPR
:
1826 return "<<< ??? >>>";
1830 /* Prints the name of a CALL_EXPR. */
1833 print_call_name (pretty_printer
*buffer
, tree node
)
1837 if (TREE_CODE (node
) != CALL_EXPR
)
1840 op0
= TREE_OPERAND (node
, 0);
1842 if (TREE_CODE (op0
) == NON_LVALUE_EXPR
)
1843 op0
= TREE_OPERAND (op0
, 0);
1845 switch (TREE_CODE (op0
))
1849 PRINT_FUNCTION_NAME (op0
);
1855 dump_generic_node (buffer
, TREE_OPERAND (op0
, 0), 0, 0, false);
1859 pp_string (buffer
, "(");
1860 dump_generic_node (buffer
, TREE_OPERAND (op0
, 0), 0, 0, false);
1861 pp_string (buffer
, ") ? ");
1862 dump_generic_node (buffer
, TREE_OPERAND (op0
, 1), 0, 0, false);
1863 pp_string (buffer
, " : ");
1864 dump_generic_node (buffer
, TREE_OPERAND (op0
, 2), 0, 0, false);
1868 /* The function is a pointer contained in a structure. */
1869 if (TREE_CODE (TREE_OPERAND (op0
, 0)) == INDIRECT_REF
||
1870 TREE_CODE (TREE_OPERAND (op0
, 0)) == VAR_DECL
)
1871 PRINT_FUNCTION_NAME (TREE_OPERAND (op0
, 1));
1873 dump_generic_node (buffer
, TREE_OPERAND (op0
, 0), 0, 0, false);
1875 We can have several levels of structures and a function
1876 pointer inside. This is not implemented yet... */
1881 if (TREE_CODE (TREE_OPERAND (op0
, 0)) == VAR_DECL
)
1882 PRINT_FUNCTION_NAME (TREE_OPERAND (op0
, 0));
1884 dump_generic_node (buffer
, op0
, 0, 0, false);
1889 dump_generic_node (buffer
, op0
, 0, 0, false);
1897 /* Parses the string STR and replaces new-lines by '\n', tabs by '\t', ... */
1900 pretty_print_string (pretty_printer
*buffer
, const char *str
)
1910 pp_string (buffer
, "\\b");
1914 pp_string (buffer
, "\\f");
1918 pp_string (buffer
, "\\n");
1922 pp_string (buffer
, "\\r");
1926 pp_string (buffer
, "\\t");
1930 pp_string (buffer
, "\\v");
1934 pp_string (buffer
, "\\\\");
1938 pp_string (buffer
, "\\\"");
1942 pp_string (buffer
, "\\'");
1946 pp_string (buffer
, "\\0");
1950 pp_string (buffer
, "\\1");
1954 pp_string (buffer
, "\\2");
1958 pp_string (buffer
, "\\3");
1962 pp_string (buffer
, "\\4");
1966 pp_string (buffer
, "\\5");
1970 pp_string (buffer
, "\\6");
1974 pp_string (buffer
, "\\7");
1978 pp_character (buffer
, str
[0]);
1986 maybe_init_pretty_print (FILE *file
)
1990 pp_construct (&buffer
, /* prefix */NULL
, /* line-width */0);
1991 pp_needs_newline (&buffer
) = true;
1995 buffer
.buffer
->stream
= file
;
1999 newline_and_indent (pretty_printer
*buffer
, int spc
)
2001 pp_newline (buffer
);
2006 dump_vops (pretty_printer
*buffer
, tree stmt
, int spc
, int flags
)
2009 stmt_ann_t ann
= stmt_ann (stmt
);
2010 v_may_def_optype v_may_defs
= V_MAY_DEF_OPS (ann
);
2011 v_must_def_optype v_must_defs
= V_MUST_DEF_OPS (ann
);
2012 vuse_optype vuses
= VUSE_OPS (ann
);
2014 for (i
= 0; i
< NUM_V_MAY_DEFS (v_may_defs
); i
++)
2016 pp_string (buffer
, "# ");
2017 dump_generic_node (buffer
, V_MAY_DEF_RESULT (v_may_defs
, i
),
2018 spc
+ 2, flags
, false);
2019 pp_string (buffer
, " = V_MAY_DEF <");
2020 dump_generic_node (buffer
, V_MAY_DEF_OP (v_may_defs
, i
),
2021 spc
+ 2, flags
, false);
2022 pp_string (buffer
, ">;");
2023 newline_and_indent (buffer
, spc
);
2026 for (i
= 0; i
< NUM_V_MUST_DEFS (v_must_defs
); i
++)
2028 tree v_must_def
= V_MUST_DEF_OP (v_must_defs
, i
);
2029 pp_string (buffer
, "# V_MUST_DEF <");
2030 dump_generic_node (buffer
, v_must_def
, spc
+ 2, flags
, false);
2031 pp_string (buffer
, ">;");
2032 newline_and_indent (buffer
, spc
);
2035 for (i
= 0; i
< NUM_VUSES (vuses
); i
++)
2037 tree vuse
= VUSE_OP (vuses
, i
);
2038 pp_string (buffer
, "# VUSE <");
2039 dump_generic_node (buffer
, vuse
, spc
+ 2, flags
, false);
2040 pp_string (buffer
, ">;");
2041 newline_and_indent (buffer
, spc
);
2045 /* Dumps basic block BB to FILE with details described by FLAGS and
2046 indented by INDENT spaces. */
2049 dump_generic_bb (FILE *file
, basic_block bb
, int indent
, int flags
)
2051 maybe_init_pretty_print (file
);
2052 dumping_stmts
= true;
2053 dump_generic_bb_buff (&buffer
, bb
, indent
, flags
);
2057 /* Dumps header of basic block BB to buffer BUFFER indented by INDENT
2058 spaces and details described by flags. */
2061 dump_bb_header (pretty_printer
*buffer
, basic_block bb
, int indent
, int flags
)
2066 if (flags
& TDF_BLOCKS
)
2069 pp_string (buffer
, "# BLOCK ");
2070 pp_decimal_int (buffer
, bb
->index
);
2072 if (flags
& TDF_LINENO
)
2074 block_stmt_iterator bsi
;
2076 for (bsi
= bsi_start (bb
); !bsi_end_p (bsi
); bsi_next (&bsi
))
2077 if (get_lineno (bsi_stmt (bsi
)) != -1)
2079 pp_string (buffer
, ", starting at line ");
2080 pp_decimal_int (buffer
, get_lineno (bsi_stmt (bsi
)));
2084 newline_and_indent (buffer
, indent
);
2086 pp_string (buffer
, "# PRED:");
2087 pp_write_text_to_stream (buffer
);
2088 for (e
= bb
->pred
; e
; e
= e
->pred_next
)
2089 if (flags
& TDF_SLIM
)
2091 pp_string (buffer
, " ");
2092 if (e
->src
== ENTRY_BLOCK_PTR
)
2093 pp_string (buffer
, "ENTRY");
2095 pp_decimal_int (buffer
, e
->src
->index
);
2098 dump_edge_info (buffer
->buffer
->stream
, e
, 0);
2099 pp_newline (buffer
);
2103 stmt
= first_stmt (bb
);
2104 if (!stmt
|| TREE_CODE (stmt
) != LABEL_EXPR
)
2106 INDENT (indent
- 2);
2107 pp_string (buffer
, "<bb ");
2108 pp_decimal_int (buffer
, bb
->index
);
2109 pp_string (buffer
, ">:");
2110 pp_newline (buffer
);
2115 /* Dumps end of basic block BB to buffer BUFFER indented by INDENT
2119 dump_bb_end (pretty_printer
*buffer
, basic_block bb
, int indent
, int flags
)
2124 pp_string (buffer
, "# SUCC:");
2125 pp_write_text_to_stream (buffer
);
2126 for (e
= bb
->succ
; e
; e
= e
->succ_next
)
2127 if (flags
& TDF_SLIM
)
2129 pp_string (buffer
, " ");
2130 if (e
->dest
== EXIT_BLOCK_PTR
)
2131 pp_string (buffer
, "EXIT");
2133 pp_decimal_int (buffer
, e
->dest
->index
);
2136 dump_edge_info (buffer
->buffer
->stream
, e
, 1);
2137 pp_newline (buffer
);
2140 /* Dumps phi nodes of basic block BB to buffer BUFFER with details described by
2141 FLAGS indented by INDENT spaces. */
2144 dump_phi_nodes (pretty_printer
*buffer
, basic_block bb
, int indent
, int flags
)
2146 tree phi
= phi_nodes (bb
);
2150 for (; phi
; phi
= PHI_CHAIN (phi
))
2152 if (is_gimple_reg (PHI_RESULT (phi
)) || (flags
& TDF_VOPS
))
2155 pp_string (buffer
, "# ");
2156 dump_generic_node (buffer
, phi
, indent
, flags
, false);
2157 pp_newline (buffer
);
2162 /* Dump jump to basic block BB that is represented implicitly in the cfg
2166 pp_cfg_jump (pretty_printer
*buffer
, basic_block bb
)
2170 stmt
= first_stmt (bb
);
2172 pp_string (buffer
, "goto <bb ");
2173 pp_decimal_int (buffer
, bb
->index
);
2174 pp_string (buffer
, ">");
2175 if (stmt
&& TREE_CODE (stmt
) == LABEL_EXPR
)
2177 pp_string (buffer
, " (");
2178 dump_generic_node (buffer
, LABEL_EXPR_LABEL (stmt
), 0, 0, false);
2179 pp_string (buffer
, ")");
2181 pp_semicolon (buffer
);
2184 /* Dump edges represented implicitly in basic block BB to BUFFER, indented
2185 by INDENT spaces, with details given by FLAGS. */
2188 dump_implicit_edges (pretty_printer
*buffer
, basic_block bb
, int indent
,
2193 /* If there is a fallthru edge, we may need to add an artificial goto to the
2195 for (e
= bb
->succ
; e
; e
= e
->succ_next
)
2196 if (e
->flags
& EDGE_FALLTHRU
)
2198 if (e
&& e
->dest
!= bb
->next_bb
)
2202 if ((flags
& TDF_LINENO
) && e
->goto_locus
)
2204 pp_character (buffer
, '[');
2205 if (e
->goto_locus
->file
)
2207 pp_string (buffer
, e
->goto_locus
->file
);
2208 pp_string (buffer
, " : ");
2210 pp_decimal_int (buffer
, e
->goto_locus
->line
);
2211 pp_string (buffer
, "] ");
2214 pp_cfg_jump (buffer
, e
->dest
);
2215 pp_newline (buffer
);
2219 /* Dumps basic block BB to buffer BUFFER with details described by FLAGS and
2220 indented by INDENT spaces. */
2223 dump_generic_bb_buff (pretty_printer
*buffer
, basic_block bb
,
2224 int indent
, int flags
)
2226 block_stmt_iterator bsi
;
2228 int label_indent
= indent
- 2;
2230 if (label_indent
< 0)
2233 dump_bb_header (buffer
, bb
, indent
, flags
);
2236 dump_phi_nodes (buffer
, bb
, indent
, flags
);
2238 for (bsi
= bsi_start (bb
); !bsi_end_p (bsi
); bsi_next (&bsi
))
2242 stmt
= bsi_stmt (bsi
);
2244 curr_indent
= TREE_CODE (stmt
) == LABEL_EXPR
? label_indent
: indent
;
2246 INDENT (curr_indent
);
2247 dump_generic_node (buffer
, stmt
, curr_indent
, flags
, true);
2248 pp_newline (buffer
);
2251 dump_implicit_edges (buffer
, bb
, indent
, flags
);
2253 if (flags
& TDF_BLOCKS
)
2254 dump_bb_end (buffer
, bb
, indent
, flags
);