1 /* Pretty formatting of GENERIC trees in C syntax.
2 Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
3 Adapted from c-pretty-print.c by Diego Novillo <dnovillo@redhat.com>
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24 #include "coretypes.h"
28 #include "diagnostic.h"
31 #include "tree-flow.h"
32 #include "langhooks.h"
33 #include "tree-iterator.h"
34 #include "tree-chrec.h"
36 /* Local functions, macros and variables. */
37 static int op_prio (tree
);
38 static const char *op_symbol (tree
);
39 static void pretty_print_string (pretty_printer
*, const char*);
40 static void print_call_name (pretty_printer
*, tree
);
41 static void newline_and_indent (pretty_printer
*, int);
42 static void maybe_init_pretty_print (FILE *);
43 static void print_declaration (pretty_printer
*, tree
, int, int);
44 static void print_struct_decl (pretty_printer
*, tree
, int, int);
45 static void do_niy (pretty_printer
*, tree
);
46 static void dump_vops (pretty_printer
*, tree
, int, int);
47 static void dump_generic_bb_buff (pretty_printer
*, basic_block
, int, int);
49 #define INDENT(SPACE) do { \
50 int i; for (i = 0; i<SPACE; i++) pp_space (buffer); } while (0)
52 #define NIY do_niy(buffer,node)
54 #define PRINT_FUNCTION_NAME(NODE) pp_printf \
55 (buffer, "%s", TREE_CODE (NODE) == NOP_EXPR ? \
56 lang_hooks.decl_printable_name (TREE_OPERAND (NODE, 0), 1) : \
57 lang_hooks.decl_printable_name (NODE, 1))
59 static pretty_printer buffer
;
60 static int initialized
= 0;
61 static bool dumping_stmts
;
63 /* Try to print something for an unknown tree code. */
66 do_niy (pretty_printer
*buffer
, tree node
)
70 pp_string (buffer
, "<<< Unknown tree: ");
71 pp_string (buffer
, tree_code_name
[(int) TREE_CODE (node
)]);
73 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (node
))))
75 len
= first_rtl_op (TREE_CODE (node
));
76 for (i
= 0; i
< len
; ++i
)
78 newline_and_indent (buffer
, 2);
79 dump_generic_node (buffer
, TREE_OPERAND (node
, i
), 2, 0, false);
83 pp_string (buffer
, " >>>\n");
87 debug_generic_expr (tree t
)
89 print_generic_expr (stderr
, t
, TDF_VOPS
|TDF_UID
);
90 fprintf (stderr
, "\n");
94 debug_generic_stmt (tree t
)
96 print_generic_stmt (stderr
, t
, TDF_VOPS
|TDF_UID
);
97 fprintf (stderr
, "\n");
100 /* Prints declaration DECL to the FILE with details specified by FLAGS. */
102 print_generic_decl (FILE *file
, tree decl
, int flags
)
104 maybe_init_pretty_print (file
);
105 dumping_stmts
= true;
106 print_declaration (&buffer
, decl
, 2, flags
);
107 pp_write_text_to_stream (&buffer
);
110 /* Print tree T, and its successors, on file FILE. FLAGS specifies details
111 to show in the dump. See TDF_* in tree.h. */
114 print_generic_stmt (FILE *file
, tree t
, int flags
)
116 maybe_init_pretty_print (file
);
117 dumping_stmts
= true;
118 dump_generic_node (&buffer
, t
, 0, flags
, true);
122 /* Print tree T, and its successors, on file FILE. FLAGS specifies details
123 to show in the dump. See TDF_* in tree.h. The output is indented by
127 print_generic_stmt_indented (FILE *file
, tree t
, int flags
, int indent
)
131 maybe_init_pretty_print (file
);
132 dumping_stmts
= true;
134 for (i
= 0; i
< indent
; i
++)
136 dump_generic_node (&buffer
, t
, indent
, flags
, true);
140 /* Print a single expression T on file FILE. FLAGS specifies details to show
141 in the dump. See TDF_* in tree.h. */
144 print_generic_expr (FILE *file
, tree t
, int flags
)
146 maybe_init_pretty_print (file
);
147 dumping_stmts
= false;
148 dump_generic_node (&buffer
, t
, 0, flags
, false);
151 /* Dump the name of a _DECL node and its DECL_UID if TDF_UID is set
155 dump_decl_name (pretty_printer
*buffer
, tree node
, int flags
)
157 if (DECL_NAME (node
))
158 pp_tree_identifier (buffer
, DECL_NAME (node
));
160 if ((flags
& TDF_UID
)
161 || DECL_NAME (node
) == NULL_TREE
)
163 if (TREE_CODE (node
) == LABEL_DECL
164 && LABEL_DECL_UID (node
) != -1)
165 pp_printf (buffer
, "<L" HOST_WIDE_INT_PRINT_DEC
">",
166 LABEL_DECL_UID (node
));
169 char c
= TREE_CODE (node
) == CONST_DECL
? 'C' : 'D';
170 pp_printf (buffer
, "<%c%u>", c
, DECL_UID (node
));
175 /* Dump a function declaration. NODE is the FUNCTION_TYPE. BUFFER, SPC and
176 FLAGS are as in dump_generic_node. */
179 dump_function_declaration (pretty_printer
*buffer
, tree node
,
182 bool wrote_arg
= false;
186 pp_character (buffer
, '(');
188 /* Print the argument types. The last element in the list is a VOID_TYPE.
189 The following avoids printing the last element. */
190 arg
= TYPE_ARG_TYPES (node
);
191 while (arg
&& TREE_CHAIN (arg
) && arg
!= error_mark_node
)
194 dump_generic_node (buffer
, TREE_VALUE (arg
), spc
, flags
, false);
195 arg
= TREE_CHAIN (arg
);
196 if (TREE_CHAIN (arg
) && TREE_CODE (TREE_CHAIN (arg
)) == TREE_LIST
)
198 pp_character (buffer
, ',');
204 pp_string (buffer
, "void");
206 pp_character (buffer
, ')');
209 /* Dump the node NODE on the pretty_printer BUFFER, SPC spaces of indent.
210 FLAGS specifies details to show in the dump (see TDF_* in tree.h). If
211 IS_STMT is true, the object printed is considered to be a statement
212 and it is terminated by ';' if appropriate. */
215 dump_generic_node (pretty_printer
*buffer
, tree node
, int spc
, int flags
,
223 if (node
== NULL_TREE
)
226 is_expr
= EXPR_P (node
);
228 if (TREE_CODE (node
) != ERROR_MARK
229 && is_gimple_stmt (node
)
230 && (flags
& TDF_VOPS
)
232 dump_vops (buffer
, node
, spc
, flags
);
235 && (flags
& TDF_LINENO
)
236 && EXPR_HAS_LOCATION (node
))
238 expanded_location xloc
= expand_location (EXPR_LOCATION (node
));
239 pp_character (buffer
, '[');
242 pp_string (buffer
, xloc
.file
);
243 pp_string (buffer
, " : ");
245 pp_decimal_int (buffer
, xloc
.line
);
246 pp_string (buffer
, "] ");
249 switch (TREE_CODE (node
))
252 pp_string (buffer
, "<<< error >>>");
255 case IDENTIFIER_NODE
:
256 pp_tree_identifier (buffer
, node
);
260 while (node
&& node
!= error_mark_node
)
262 if (TREE_PURPOSE (node
))
264 dump_generic_node (buffer
, TREE_PURPOSE (node
), spc
, flags
, false);
267 dump_generic_node (buffer
, TREE_VALUE (node
), spc
, flags
, false);
268 node
= TREE_CHAIN (node
);
269 if (node
&& TREE_CODE (node
) == TREE_LIST
)
271 pp_character (buffer
, ',');
278 dump_generic_node (buffer
, BINFO_TYPE (node
), spc
, flags
, false);
294 unsigned int quals
= TYPE_QUALS (node
);
297 if (quals
& TYPE_QUAL_CONST
)
298 pp_string (buffer
, "const ");
299 else if (quals
& TYPE_QUAL_VOLATILE
)
300 pp_string (buffer
, "volatile ");
301 else if (quals
& TYPE_QUAL_RESTRICT
)
302 pp_string (buffer
, "restrict ");
304 class = TREE_CODE_CLASS (TREE_CODE (node
));
308 if (DECL_NAME (node
))
309 dump_decl_name (buffer
, node
, flags
);
311 pp_string (buffer
, "<unnamed type decl>");
313 else if (class == 't')
315 if (TYPE_NAME (node
))
317 if (TREE_CODE (TYPE_NAME (node
)) == IDENTIFIER_NODE
)
318 pp_tree_identifier (buffer
, TYPE_NAME (node
));
319 else if (TREE_CODE (TYPE_NAME (node
)) == TYPE_DECL
320 && DECL_NAME (TYPE_NAME (node
)))
321 dump_decl_name (buffer
, TYPE_NAME (node
), flags
);
323 pp_string (buffer
, "<unnamed type>");
326 pp_string (buffer
, "<unnamed type>");
333 str
= (TREE_CODE (node
) == POINTER_TYPE
? "*" : "&");
335 if (TREE_CODE (TREE_TYPE (node
)) == FUNCTION_TYPE
)
337 tree fnode
= TREE_TYPE (node
);
339 dump_generic_node (buffer
, TREE_TYPE (fnode
), spc
, flags
, false);
341 pp_character (buffer
, '(');
342 pp_string (buffer
, str
);
343 if (TYPE_NAME (node
) && DECL_NAME (TYPE_NAME (node
)))
344 dump_decl_name (buffer
, TYPE_NAME (node
), flags
);
346 pp_printf (buffer
, "<T%x>", TYPE_UID (node
));
348 pp_character (buffer
, ')');
349 dump_function_declaration (buffer
, fnode
, spc
, flags
);
353 unsigned int quals
= TYPE_QUALS (node
);
355 dump_generic_node (buffer
, TREE_TYPE (node
), spc
, flags
, false);
357 pp_string (buffer
, str
);
359 if (quals
& TYPE_QUAL_CONST
)
360 pp_string (buffer
, " const");
361 else if (quals
& TYPE_QUAL_VOLATILE
)
362 pp_string (buffer
, "volatile");
363 else if (quals
& TYPE_QUAL_RESTRICT
)
364 pp_string (buffer
, " restrict");
373 dump_decl_name (buffer
, TYPE_NAME (TYPE_METHOD_BASETYPE (node
)), flags
);
374 pp_string (buffer
, "::");
385 /* Print the innermost component type. */
386 for (tmp
= TREE_TYPE (node
); TREE_CODE (tmp
) == ARRAY_TYPE
;
387 tmp
= TREE_TYPE (tmp
))
389 dump_generic_node (buffer
, tmp
, spc
, flags
, false);
391 /* Print the dimensions. */
392 for (tmp
= node
; TREE_CODE (tmp
) == ARRAY_TYPE
;
393 tmp
= TREE_TYPE (tmp
))
395 tree domain
= TYPE_DOMAIN (tmp
);
397 pp_character (buffer
, '[');
400 if (TYPE_MIN_VALUE (domain
)
401 && !integer_zerop (TYPE_MIN_VALUE (domain
)))
403 dump_generic_node (buffer
, TYPE_MIN_VALUE (domain
),
405 pp_string (buffer
, " .. ");
408 if (TYPE_MAX_VALUE (domain
))
409 dump_generic_node (buffer
, TYPE_MAX_VALUE (domain
),
413 pp_string (buffer
, "<unknown>");
415 pp_character (buffer
, ']');
426 case QUAL_UNION_TYPE
:
427 /* Print the name of the structure. */
428 if (TREE_CODE (node
) == RECORD_TYPE
)
429 pp_string (buffer
, "struct ");
430 else if (TREE_CODE (node
) == UNION_TYPE
)
431 pp_string (buffer
, "union ");
433 if (TYPE_NAME (node
))
434 dump_generic_node (buffer
, TYPE_NAME (node
), spc
, flags
, false);
436 print_struct_decl (buffer
, node
, spc
, flags
);
444 if (TREE_CODE (TREE_TYPE (node
)) == POINTER_TYPE
)
446 /* In the case of a pointer, one may want to divide by the
447 size of the pointed-to type. Unfortunately, this not
448 straightforward. The C front-end maps expressions
453 in such a way that the two INTEGER_CST nodes for "5" have
454 different values but identical types. In the latter
455 case, the 5 is multiplied by sizeof (int) in c-common.c
456 (pointer_int_sum) to convert it to a byte address, and
457 yet the type of the node is left unchanged. Argh. What
458 is consistent though is that the number value corresponds
459 to bytes (UNITS) offset.
461 NB: Neither of the following divisors can be trivially
462 used to recover the original literal:
464 TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (node)))
465 TYPE_PRECISION (TREE_TYPE (TREE_TYPE (node))) */
466 pp_wide_integer (buffer
, TREE_INT_CST_LOW (node
));
467 pp_string (buffer
, "B"); /* pseudo-unit */
469 else if (! host_integerp (node
, 0))
473 if (tree_int_cst_sgn (val
) < 0)
475 pp_character (buffer
, '-');
476 val
= build_int_2 (-TREE_INT_CST_LOW (val
),
477 ~TREE_INT_CST_HIGH (val
)
478 + !TREE_INT_CST_LOW (val
));
480 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
483 static char format
[10]; /* "%x%09999x\0" */
485 sprintf (format
, "%%x%%0%dx", HOST_BITS_PER_INT
/ 4);
486 sprintf (pp_buffer (buffer
)->digit_buffer
, format
,
487 TREE_INT_CST_HIGH (val
),
488 TREE_INT_CST_LOW (val
));
489 pp_string (buffer
, pp_buffer (buffer
)->digit_buffer
);
493 pp_wide_integer (buffer
, TREE_INT_CST_LOW (node
));
497 /* Code copied from print_node. */
500 if (TREE_OVERFLOW (node
))
501 pp_string (buffer
, " overflow");
503 #if !defined(REAL_IS_NOT_DOUBLE) || defined(REAL_ARITHMETIC)
504 d
= TREE_REAL_CST (node
);
505 if (REAL_VALUE_ISINF (d
))
506 pp_string (buffer
, " Inf");
507 else if (REAL_VALUE_ISNAN (d
))
508 pp_string (buffer
, " Nan");
512 real_to_decimal (string
, &d
, sizeof (string
), 0, 1);
513 pp_string (buffer
, string
);
518 unsigned char *p
= (unsigned char *) &TREE_REAL_CST (node
);
519 pp_string (buffer
, "0x");
520 for (i
= 0; i
< sizeof TREE_REAL_CST (node
); i
++)
521 output_formatted_integer (buffer
, "%02x", *p
++);
528 pp_string (buffer
, "__complex__ (");
529 dump_generic_node (buffer
, TREE_REALPART (node
), spc
, flags
, false);
530 pp_string (buffer
, ", ");
531 dump_generic_node (buffer
, TREE_IMAGPART (node
), spc
, flags
, false);
532 pp_string (buffer
, ")");
536 pp_string (buffer
, "\"");
537 pretty_print_string (buffer
, TREE_STRING_POINTER (node
));
538 pp_string (buffer
, "\"");
544 pp_string (buffer
, "{ ");
545 for (elt
= TREE_VECTOR_CST_ELTS (node
); elt
; elt
= TREE_CHAIN (elt
))
547 dump_generic_node (buffer
, TREE_VALUE (elt
), spc
, flags
, false);
548 if (TREE_CHAIN (elt
))
549 pp_string (buffer
, ", ");
551 pp_string (buffer
, " }");
560 dump_decl_name (buffer
, node
, flags
);
564 if (DECL_NAME (node
))
565 dump_decl_name (buffer
, node
, flags
);
566 else if (LABEL_DECL_UID (node
) != -1)
567 pp_printf (buffer
, "<L" HOST_WIDE_INT_PRINT_DEC
">",
568 LABEL_DECL_UID (node
));
570 pp_printf (buffer
, "<D%u>", DECL_UID (node
));
574 if (DECL_IS_BUILTIN (node
))
576 /* Don't print the declaration of built-in types. */
579 if (DECL_NAME (node
))
580 dump_decl_name (buffer
, node
, flags
);
583 if ((TREE_CODE (TREE_TYPE (node
)) == RECORD_TYPE
584 || TREE_CODE (TREE_TYPE (node
)) == UNION_TYPE
)
585 && TYPE_METHODS (TREE_TYPE (node
)))
587 /* The type is a c++ class: all structures have at least
589 pp_string (buffer
, "class ");
590 dump_generic_node (buffer
, TREE_TYPE (node
), spc
, flags
, false);
595 (TREE_CODE (TREE_TYPE (node
)) == UNION_TYPE
596 ? "union" : "struct "));
597 dump_generic_node (buffer
, TREE_TYPE (node
), spc
, flags
, false);
606 dump_decl_name (buffer
, node
, flags
);
610 pp_string (buffer
, "<retval>");
614 op0
= TREE_OPERAND (node
, 0);
616 if (TREE_CODE (op0
) == INDIRECT_REF
)
618 op0
= TREE_OPERAND (op0
, 0);
621 if (op_prio (op0
) < op_prio (node
))
622 pp_character (buffer
, '(');
623 dump_generic_node (buffer
, op0
, spc
, flags
, false);
624 if (op_prio (op0
) < op_prio (node
))
625 pp_character (buffer
, ')');
626 pp_string (buffer
, str
);
627 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
629 op0
= component_ref_field_offset (node
);
630 if (op0
&& TREE_CODE (op0
) != INTEGER_CST
)
632 pp_string (buffer
, "{off: ");
633 dump_generic_node (buffer
, op0
, spc
, flags
, false);
634 pp_character (buffer
, '}');
639 pp_string (buffer
, "BIT_FIELD_REF <");
640 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
641 pp_string (buffer
, ", ");
642 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
643 pp_string (buffer
, ", ");
644 dump_generic_node (buffer
, TREE_OPERAND (node
, 2), spc
, flags
, false);
645 pp_string (buffer
, ">");
649 case ARRAY_RANGE_REF
:
650 op0
= TREE_OPERAND (node
, 0);
651 if (op_prio (op0
) < op_prio (node
))
652 pp_character (buffer
, '(');
653 dump_generic_node (buffer
, op0
, spc
, flags
, false);
654 if (op_prio (op0
) < op_prio (node
))
655 pp_character (buffer
, ')');
656 pp_character (buffer
, '[');
657 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
658 if (TREE_CODE (node
) == ARRAY_RANGE_REF
)
659 pp_string (buffer
, " ...");
660 pp_character (buffer
, ']');
662 op0
= array_ref_low_bound (node
);
663 op1
= array_ref_element_size (node
);
665 if (!integer_zerop (op0
)
666 || (TYPE_SIZE_UNIT (TREE_TYPE (node
))
667 && !operand_equal_p (op1
, TYPE_SIZE_UNIT (TREE_TYPE (node
)), 0)))
669 pp_string (buffer
, "{lb: ");
670 dump_generic_node (buffer
, op0
, spc
, flags
, false);
671 pp_string (buffer
, " sz: ");
672 dump_generic_node (buffer
, op1
, spc
, flags
, false);
673 pp_character (buffer
, '}');
680 bool is_struct_init
= FALSE
;
681 pp_character (buffer
, '{');
682 lnode
= CONSTRUCTOR_ELTS (node
);
683 if (TREE_CODE (TREE_TYPE (node
)) == RECORD_TYPE
684 || TREE_CODE (TREE_TYPE (node
)) == UNION_TYPE
)
685 is_struct_init
= TRUE
;
686 while (lnode
&& lnode
!= error_mark_node
)
689 if (TREE_PURPOSE (lnode
) && is_struct_init
)
691 pp_character (buffer
, '.');
692 dump_generic_node (buffer
, TREE_PURPOSE (lnode
), spc
, flags
, false);
693 pp_string (buffer
, "=");
695 val
= TREE_VALUE (lnode
);
696 if (val
&& TREE_CODE (val
) == ADDR_EXPR
)
697 if (TREE_CODE (TREE_OPERAND (val
, 0)) == FUNCTION_DECL
)
698 val
= TREE_OPERAND (val
, 0);
699 if (val
&& TREE_CODE (val
) == FUNCTION_DECL
)
701 dump_decl_name (buffer
, val
, flags
);
705 dump_generic_node (buffer
, TREE_VALUE (lnode
), spc
, flags
, false);
707 lnode
= TREE_CHAIN (lnode
);
708 if (lnode
&& TREE_CODE (lnode
) == TREE_LIST
)
710 pp_character (buffer
, ',');
714 pp_character (buffer
, '}');
721 if (flags
& TDF_SLIM
)
723 pp_string (buffer
, "<COMPOUND_EXPR>");
727 dump_generic_node (buffer
, TREE_OPERAND (node
, 0),
728 spc
, flags
, dumping_stmts
);
730 newline_and_indent (buffer
, spc
);
733 pp_character (buffer
, ',');
737 for (tp
= &TREE_OPERAND (node
, 1);
738 TREE_CODE (*tp
) == COMPOUND_EXPR
;
739 tp
= &TREE_OPERAND (*tp
, 1))
741 dump_generic_node (buffer
, TREE_OPERAND (*tp
, 0),
742 spc
, flags
, dumping_stmts
);
744 newline_and_indent (buffer
, spc
);
747 pp_character (buffer
, ',');
752 dump_generic_node (buffer
, *tp
, spc
, flags
, dumping_stmts
);
758 tree_stmt_iterator si
;
761 if ((flags
& TDF_SLIM
) || !dumping_stmts
)
763 pp_string (buffer
, "<STATEMENT_LIST>");
767 for (si
= tsi_start (node
); !tsi_end_p (si
); tsi_next (&si
))
770 newline_and_indent (buffer
, spc
);
773 dump_generic_node (buffer
, tsi_stmt (si
), spc
, flags
, true);
780 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
782 pp_character (buffer
, '=');
784 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
788 pp_string (buffer
, "TARGET_EXPR <");
789 dump_generic_node (buffer
, TARGET_EXPR_SLOT (node
), spc
, flags
, false);
790 pp_character (buffer
, ',');
792 dump_generic_node (buffer
, TARGET_EXPR_INITIAL (node
), spc
, flags
, false);
793 pp_character (buffer
, '>');
797 print_declaration (buffer
, DECL_EXPR_DECL (node
), spc
, flags
);
802 if (TREE_TYPE (node
) == NULL
|| TREE_TYPE (node
) == void_type_node
)
804 pp_string (buffer
, "if (");
805 dump_generic_node (buffer
, COND_EXPR_COND (node
), spc
, flags
, false);
806 pp_character (buffer
, ')');
807 /* The lowered cond_exprs should always be printed in full. */
808 if (COND_EXPR_THEN (node
)
809 && TREE_CODE (COND_EXPR_THEN (node
)) == GOTO_EXPR
810 && COND_EXPR_ELSE (node
)
811 && TREE_CODE (COND_EXPR_ELSE (node
)) == GOTO_EXPR
)
814 dump_generic_node (buffer
, COND_EXPR_THEN (node
), 0, flags
, true);
815 pp_string (buffer
, " else ");
816 dump_generic_node (buffer
, COND_EXPR_ELSE (node
), 0, flags
, true);
818 else if (!(flags
& TDF_SLIM
))
820 /* Output COND_EXPR_THEN. */
821 if (COND_EXPR_THEN (node
))
823 newline_and_indent (buffer
, spc
+2);
824 pp_character (buffer
, '{');
825 newline_and_indent (buffer
, spc
+4);
826 dump_generic_node (buffer
, COND_EXPR_THEN (node
), spc
+4,
828 newline_and_indent (buffer
, spc
+2);
829 pp_character (buffer
, '}');
832 /* Output COND_EXPR_ELSE. */
833 if (COND_EXPR_ELSE (node
))
835 newline_and_indent (buffer
, spc
);
836 pp_string (buffer
, "else");
837 newline_and_indent (buffer
, spc
+2);
838 pp_character (buffer
, '{');
839 newline_and_indent (buffer
, spc
+4);
840 dump_generic_node (buffer
, COND_EXPR_ELSE (node
), spc
+4,
842 newline_and_indent (buffer
, spc
+2);
843 pp_character (buffer
, '}');
850 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
852 pp_character (buffer
, '?');
854 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
856 pp_character (buffer
, ':');
858 dump_generic_node (buffer
, TREE_OPERAND (node
, 2), spc
, flags
, false);
863 pp_character (buffer
, '{');
864 if (!(flags
& TDF_SLIM
))
866 if (BIND_EXPR_VARS (node
))
870 for (op0
= BIND_EXPR_VARS (node
); op0
; op0
= TREE_CHAIN (op0
))
872 print_declaration (buffer
, op0
, spc
+2, flags
);
877 newline_and_indent (buffer
, spc
+2);
878 dump_generic_node (buffer
, BIND_EXPR_BODY (node
), spc
+2, flags
, true);
879 newline_and_indent (buffer
, spc
);
880 pp_character (buffer
, '}');
886 print_call_name (buffer
, node
);
888 /* Print parameters. */
890 pp_character (buffer
, '(');
891 op1
= TREE_OPERAND (node
, 1);
893 dump_generic_node (buffer
, op1
, spc
, flags
, false);
894 pp_character (buffer
, ')');
896 op1
= TREE_OPERAND (node
, 2);
899 pp_string (buffer
, " [static-chain: ");
900 dump_generic_node (buffer
, op1
, spc
, flags
, false);
901 pp_character (buffer
, ']');
904 if (CALL_EXPR_HAS_RETURN_SLOT_ADDR (node
))
905 pp_string (buffer
, " [return slot addr]");
906 if (CALL_EXPR_TAILCALL (node
))
907 pp_string (buffer
, " [tail call]");
910 case WITH_CLEANUP_EXPR
:
914 case CLEANUP_POINT_EXPR
:
915 pp_string (buffer
, "<<cleanup_point ");
916 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
917 pp_string (buffer
, ">>");
920 case PLACEHOLDER_EXPR
:
921 pp_string (buffer
, "<PLACEHOLDER_EXPR ");
922 dump_generic_node (buffer
, TREE_TYPE (node
), spc
, flags
, false);
923 pp_character (buffer
, '>');
926 /* Binary arithmetic and logic expressions. */
947 case TRUTH_ANDIF_EXPR
:
948 case TRUTH_ORIF_EXPR
:
967 const char *op
= op_symbol (node
);
968 op0
= TREE_OPERAND (node
, 0);
969 op1
= TREE_OPERAND (node
, 1);
971 /* When the operands are expressions with less priority,
972 keep semantics of the tree representation. */
973 if (op_prio (op0
) < op_prio (node
))
975 pp_character (buffer
, '(');
976 dump_generic_node (buffer
, op0
, spc
, flags
, false);
977 pp_character (buffer
, ')');
980 dump_generic_node (buffer
, op0
, spc
, flags
, false);
983 pp_string (buffer
, op
);
986 /* When the operands are expressions with less priority,
987 keep semantics of the tree representation. */
988 if (op_prio (op1
) < op_prio (node
))
990 pp_character (buffer
, '(');
991 dump_generic_node (buffer
, op1
, spc
, flags
, false);
992 pp_character (buffer
, ')');
995 dump_generic_node (buffer
, op1
, spc
, flags
, false);
999 /* Unary arithmetic and logic expressions. */
1002 case TRUTH_NOT_EXPR
:
1004 case PREDECREMENT_EXPR
:
1005 case PREINCREMENT_EXPR
:
1007 if (TREE_CODE (node
) == ADDR_EXPR
1008 && (TREE_CODE (TREE_OPERAND (node
, 0)) == STRING_CST
1009 || TREE_CODE (TREE_OPERAND (node
, 0)) == FUNCTION_DECL
))
1010 ; /* Do not output '&' for strings and function pointers. */
1012 pp_string (buffer
, op_symbol (node
));
1014 if (op_prio (TREE_OPERAND (node
, 0)) < op_prio (node
))
1016 pp_character (buffer
, '(');
1017 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1018 pp_character (buffer
, ')');
1021 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1024 case POSTDECREMENT_EXPR
:
1025 case POSTINCREMENT_EXPR
:
1026 if (op_prio (TREE_OPERAND (node
, 0)) < op_prio (node
))
1028 pp_character (buffer
, '(');
1029 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1030 pp_character (buffer
, ')');
1033 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1034 pp_string (buffer
, op_symbol (node
));
1038 pp_string (buffer
, "MIN_EXPR <");
1039 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1040 pp_string (buffer
, ", ");
1041 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
1042 pp_character (buffer
, '>');
1046 pp_string (buffer
, "MAX_EXPR <");
1047 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1048 pp_string (buffer
, ", ");
1049 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
1050 pp_character (buffer
, '>');
1054 pp_string (buffer
, "ABS_EXPR <");
1055 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1056 pp_character (buffer
, '>');
1063 case FIX_TRUNC_EXPR
:
1065 case FIX_FLOOR_EXPR
:
1066 case FIX_ROUND_EXPR
:
1070 type
= TREE_TYPE (node
);
1071 op0
= TREE_OPERAND (node
, 0);
1072 if (type
!= TREE_TYPE (op0
))
1074 pp_character (buffer
, '(');
1075 dump_generic_node (buffer
, type
, spc
, flags
, false);
1076 pp_string (buffer
, ")");
1078 if (op_prio (op0
) < op_prio (node
))
1079 pp_character (buffer
, '(');
1080 dump_generic_node (buffer
, op0
, spc
, flags
, false);
1081 if (op_prio (op0
) < op_prio (node
))
1082 pp_character (buffer
, ')');
1085 case VIEW_CONVERT_EXPR
:
1086 pp_string (buffer
, "VIEW_CONVERT_EXPR<");
1087 dump_generic_node (buffer
, TREE_TYPE (node
), spc
, flags
, false);
1088 pp_string (buffer
, ">(");
1089 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1090 pp_character (buffer
, ')');
1093 case NON_LVALUE_EXPR
:
1094 pp_string (buffer
, "NON_LVALUE_EXPR <");
1095 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1096 pp_character (buffer
, '>');
1100 pp_string (buffer
, "SAVE_EXPR <");
1101 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1102 pp_character (buffer
, '>');
1105 case ENTRY_VALUE_EXPR
:
1110 pp_string (buffer
, "COMPLEX_EXPR <");
1111 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1112 pp_string (buffer
, ", ");
1113 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
1114 pp_string (buffer
, ">");
1118 pp_string (buffer
, "CONJ_EXPR <");
1119 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1120 pp_string (buffer
, ">");
1124 pp_string (buffer
, "REALPART_EXPR <");
1125 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1126 pp_string (buffer
, ">");
1130 pp_string (buffer
, "IMAGPART_EXPR <");
1131 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1132 pp_string (buffer
, ">");
1136 pp_string (buffer
, "VA_ARG_EXPR <");
1137 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1138 pp_string (buffer
, ">");
1141 case TRY_FINALLY_EXPR
:
1142 case TRY_CATCH_EXPR
:
1143 pp_string (buffer
, "try");
1144 newline_and_indent (buffer
, spc
+2);
1145 pp_string (buffer
, "{");
1146 newline_and_indent (buffer
, spc
+4);
1147 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
+4, flags
, true);
1148 newline_and_indent (buffer
, spc
+2);
1149 pp_string (buffer
, "}");
1150 newline_and_indent (buffer
, spc
);
1152 (TREE_CODE (node
) == TRY_CATCH_EXPR
) ? "catch" : "finally");
1153 newline_and_indent (buffer
, spc
+2);
1154 pp_string (buffer
, "{");
1155 newline_and_indent (buffer
, spc
+4);
1156 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
+4, flags
, true);
1157 newline_and_indent (buffer
, spc
+2);
1158 pp_string (buffer
, "}");
1163 pp_string (buffer
, "catch (");
1164 dump_generic_node (buffer
, CATCH_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
, CATCH_BODY (node
), spc
+4, flags
, true);
1170 newline_and_indent (buffer
, spc
+2);
1171 pp_string (buffer
, "}");
1175 case EH_FILTER_EXPR
:
1176 pp_string (buffer
, "<<<eh_filter (");
1177 dump_generic_node (buffer
, EH_FILTER_TYPES (node
), spc
+2, flags
, false);
1178 pp_string (buffer
, ")>>>");
1179 newline_and_indent (buffer
, spc
+2);
1180 pp_string (buffer
, "{");
1181 newline_and_indent (buffer
, spc
+4);
1182 dump_generic_node (buffer
, EH_FILTER_FAILURE (node
), spc
+4, flags
, true);
1183 newline_and_indent (buffer
, spc
+2);
1184 pp_string (buffer
, "}");
1189 op0
= TREE_OPERAND (node
, 0);
1190 /* If this is for break or continue, don't bother printing it. */
1191 if (DECL_NAME (op0
))
1193 const char *name
= IDENTIFIER_POINTER (DECL_NAME (op0
));
1194 if (strcmp (name
, "break") == 0
1195 || strcmp (name
, "continue") == 0)
1198 dump_generic_node (buffer
, op0
, spc
, flags
, false);
1199 pp_character (buffer
, ':');
1200 if (DECL_NONLOCAL (op0
))
1201 pp_string (buffer
, " [non-local]");
1204 case LABELED_BLOCK_EXPR
:
1205 op0
= LABELED_BLOCK_LABEL (node
);
1206 /* If this is for break or continue, don't bother printing it. */
1207 if (DECL_NAME (op0
))
1209 const char *name
= IDENTIFIER_POINTER (DECL_NAME (op0
));
1210 if (strcmp (name
, "break") == 0
1211 || strcmp (name
, "continue") == 0)
1213 dump_generic_node (buffer
, LABELED_BLOCK_BODY (node
), spc
, flags
, false);
1217 dump_generic_node (buffer
, LABELED_BLOCK_LABEL (node
), spc
, flags
, false);
1218 pp_string (buffer
, ": {");
1219 if (!(flags
& TDF_SLIM
))
1220 newline_and_indent (buffer
, spc
+2);
1221 dump_generic_node (buffer
, LABELED_BLOCK_BODY (node
), spc
+2, flags
, true);
1223 newline_and_indent (buffer
, spc
);
1224 pp_character (buffer
, '}');
1228 case EXIT_BLOCK_EXPR
:
1229 op0
= LABELED_BLOCK_LABEL (EXIT_BLOCK_LABELED_BLOCK (node
));
1230 /* If this is for a break or continue, print it accordingly. */
1231 if (DECL_NAME (op0
))
1233 const char *name
= IDENTIFIER_POINTER (DECL_NAME (op0
));
1234 if (strcmp (name
, "break") == 0
1235 || strcmp (name
, "continue") == 0)
1237 pp_string (buffer
, name
);
1241 pp_string (buffer
, "<<<exit block ");
1242 dump_generic_node (buffer
, op0
, spc
, flags
, false);
1243 pp_string (buffer
, ">>>");
1247 pp_string (buffer
, "<<<exception object>>>");
1251 pp_string (buffer
, "<<<filter object>>>");
1255 pp_string (buffer
, "while (1)");
1256 if (!(flags
& TDF_SLIM
))
1258 newline_and_indent (buffer
, spc
+2);
1259 pp_character (buffer
, '{');
1260 newline_and_indent (buffer
, spc
+4);
1261 dump_generic_node (buffer
, LOOP_EXPR_BODY (node
), spc
+4, flags
, true);
1262 newline_and_indent (buffer
, spc
+2);
1263 pp_character (buffer
, '}');
1269 pp_string (buffer
, "return");
1270 op0
= TREE_OPERAND (node
, 0);
1274 if (TREE_CODE (op0
) == MODIFY_EXPR
)
1275 dump_generic_node (buffer
, TREE_OPERAND (op0
, 1), spc
, flags
, false);
1277 dump_generic_node (buffer
, op0
, spc
, flags
, false);
1282 pp_string (buffer
, "if (");
1283 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1284 pp_string (buffer
, ") break");
1288 pp_string (buffer
, "switch (");
1289 dump_generic_node (buffer
, SWITCH_COND (node
), spc
, flags
, false);
1290 pp_character (buffer
, ')');
1291 if (!(flags
& TDF_SLIM
))
1293 newline_and_indent (buffer
, spc
+2);
1294 pp_character (buffer
, '{');
1295 if (SWITCH_BODY (node
))
1297 newline_and_indent (buffer
, spc
+4);
1298 dump_generic_node (buffer
, SWITCH_BODY (node
), spc
+4, flags
, true);
1302 tree vec
= SWITCH_LABELS (node
);
1303 size_t i
, n
= TREE_VEC_LENGTH (vec
);
1304 for (i
= 0; i
< n
; ++i
)
1306 tree elt
= TREE_VEC_ELT (vec
, i
);
1307 newline_and_indent (buffer
, spc
+4);
1308 dump_generic_node (buffer
, elt
, spc
+4, flags
, false);
1309 pp_string (buffer
, " goto ");
1310 dump_generic_node (buffer
, CASE_LABEL (elt
), spc
+4, flags
, true);
1311 pp_semicolon (buffer
);
1314 newline_and_indent (buffer
, spc
+2);
1315 pp_character (buffer
, '}');
1321 op0
= GOTO_DESTINATION (node
);
1322 if (TREE_CODE (op0
) != SSA_NAME
1326 const char *name
= IDENTIFIER_POINTER (DECL_NAME (op0
));
1327 if (strcmp (name
, "break") == 0
1328 || strcmp (name
, "continue") == 0)
1330 pp_string (buffer
, name
);
1334 pp_string (buffer
, "goto ");
1335 dump_generic_node (buffer
, op0
, spc
, flags
, false);
1339 pp_string (buffer
, "resx");
1340 /* ??? Any sensible way to present the eh region? */
1344 pp_string (buffer
, "__asm__");
1345 if (ASM_VOLATILE_P (node
))
1346 pp_string (buffer
, " __volatile__");
1347 pp_character (buffer
, '(');
1348 dump_generic_node (buffer
, ASM_STRING (node
), spc
, flags
, false);
1349 pp_character (buffer
, ':');
1350 dump_generic_node (buffer
, ASM_OUTPUTS (node
), spc
, flags
, false);
1351 pp_character (buffer
, ':');
1352 dump_generic_node (buffer
, ASM_INPUTS (node
), spc
, flags
, false);
1353 if (ASM_CLOBBERS (node
))
1355 pp_character (buffer
, ':');
1356 dump_generic_node (buffer
, ASM_CLOBBERS (node
), spc
, flags
, false);
1358 pp_string (buffer
, ")");
1361 case CASE_LABEL_EXPR
:
1362 if (CASE_LOW (node
) && CASE_HIGH (node
))
1364 pp_string (buffer
, "case ");
1365 dump_generic_node (buffer
, CASE_LOW (node
), spc
, flags
, false);
1366 pp_string (buffer
, " ... ");
1367 dump_generic_node (buffer
, CASE_HIGH (node
), spc
, flags
, false);
1369 else if (CASE_LOW (node
))
1371 pp_string (buffer
, "case ");
1372 dump_generic_node (buffer
, CASE_LOW (node
), spc
, flags
, false);
1375 pp_string (buffer
, "default ");
1376 pp_character (buffer
, ':');
1380 pp_string (buffer
, "OBJ_TYPE_REF(");
1381 dump_generic_node (buffer
, OBJ_TYPE_REF_EXPR (node
), spc
, flags
, false);
1382 pp_character (buffer
, ';');
1383 dump_generic_node (buffer
, OBJ_TYPE_REF_OBJECT (node
), spc
, flags
, false);
1384 pp_character (buffer
, '-');
1385 pp_character (buffer
, '>');
1386 dump_generic_node (buffer
, OBJ_TYPE_REF_TOKEN (node
), spc
, flags
, false);
1387 pp_character (buffer
, ')');
1394 dump_generic_node (buffer
, PHI_RESULT (node
), spc
, flags
, false);
1395 pp_string (buffer
, " = PHI <");
1396 for (i
= 0; i
< PHI_NUM_ARGS (node
); i
++)
1398 dump_generic_node (buffer
, PHI_ARG_DEF (node
, i
), spc
, flags
, false);
1399 pp_string (buffer
, "(");
1400 pp_decimal_int (buffer
, PHI_ARG_EDGE (node
, i
)->src
->index
);
1401 pp_string (buffer
, ")");
1402 if (i
< PHI_NUM_ARGS (node
) - 1)
1403 pp_string (buffer
, ", ");
1405 pp_string (buffer
, ">;");
1410 dump_generic_node (buffer
, SSA_NAME_VAR (node
), spc
, flags
, false);
1411 pp_string (buffer
, "_");
1412 pp_decimal_int (buffer
, SSA_NAME_VERSION (node
));
1415 case WITH_SIZE_EXPR
:
1416 pp_string (buffer
, "WITH_SIZE_EXPR <");
1417 dump_generic_node (buffer
, TREE_OPERAND (node
, 0), spc
, flags
, false);
1418 pp_string (buffer
, ", ");
1419 dump_generic_node (buffer
, TREE_OPERAND (node
, 1), spc
, flags
, false);
1420 pp_string (buffer
, ">");
1424 pp_printf (buffer
, "VH.%d", VALUE_HANDLE_ID (node
));
1428 pp_string (buffer
, "scev_known");
1431 case SCEV_NOT_KNOWN
:
1432 pp_string (buffer
, "scev_not_known");
1435 case POLYNOMIAL_CHREC
:
1436 pp_string (buffer
, "{");
1437 dump_generic_node (buffer
, CHREC_LEFT (node
), spc
, flags
, false);
1438 pp_string (buffer
, ", +, ");
1439 dump_generic_node (buffer
, CHREC_RIGHT (node
), spc
, flags
, false);
1440 pp_string (buffer
, "}_");
1441 dump_generic_node (buffer
, CHREC_VAR (node
), spc
, flags
, false);
1449 if (is_stmt
&& is_expr
)
1450 pp_semicolon (buffer
);
1451 pp_write_text_to_stream (buffer
);
1456 /* Print the declaration of a variable. */
1459 print_declaration (pretty_printer
*buffer
, tree t
, int spc
, int flags
)
1463 if (TREE_CODE (t
) == TYPE_DECL
)
1464 pp_string (buffer
, "typedef ");
1466 if (DECL_REGISTER (t
))
1467 pp_string (buffer
, "register ");
1469 if (TREE_PUBLIC (t
) && DECL_EXTERNAL (t
))
1470 pp_string (buffer
, "extern ");
1471 else if (TREE_STATIC (t
))
1472 pp_string (buffer
, "static ");
1474 /* Print the type and name. */
1475 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
1479 /* Print array's type. */
1480 tmp
= TREE_TYPE (t
);
1481 while (TREE_CODE (TREE_TYPE (tmp
)) == ARRAY_TYPE
)
1482 tmp
= TREE_TYPE (tmp
);
1483 dump_generic_node (buffer
, TREE_TYPE (tmp
), spc
, flags
, false);
1485 /* Print variable's name. */
1487 dump_generic_node (buffer
, t
, spc
, flags
, false);
1489 /* Print the dimensions. */
1490 tmp
= TREE_TYPE (t
);
1491 while (TREE_CODE (tmp
) == ARRAY_TYPE
)
1493 pp_character (buffer
, '[');
1494 if (TYPE_DOMAIN (tmp
))
1496 if (TREE_CODE (TYPE_SIZE (tmp
)) == INTEGER_CST
)
1497 pp_wide_integer (buffer
,
1498 TREE_INT_CST_LOW (TYPE_SIZE (tmp
)) /
1499 TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (tmp
))));
1501 dump_generic_node (buffer
, TYPE_SIZE_UNIT (tmp
), spc
, flags
,
1504 pp_character (buffer
, ']');
1505 tmp
= TREE_TYPE (tmp
);
1508 else if (TREE_CODE (t
) == FUNCTION_DECL
)
1510 dump_generic_node (buffer
, TREE_TYPE (TREE_TYPE (t
)), spc
, flags
, false);
1512 dump_decl_name (buffer
, t
, flags
);
1513 dump_function_declaration (buffer
, TREE_TYPE (t
), spc
, flags
);
1517 /* Print type declaration. */
1518 dump_generic_node (buffer
, TREE_TYPE (t
), spc
, flags
, false);
1520 /* Print variable's name. */
1522 dump_generic_node (buffer
, t
, spc
, flags
, false);
1525 /* The initial value of a function serves to determine wether the function
1526 is declared or defined. So the following does not apply to function
1528 if (TREE_CODE (t
) != FUNCTION_DECL
)
1530 /* Print the initial value. */
1531 if (DECL_INITIAL (t
))
1534 pp_character (buffer
, '=');
1536 dump_generic_node (buffer
, DECL_INITIAL (t
), spc
, flags
, false);
1540 pp_character (buffer
, ';');
1544 /* Prints a structure: name, fields, and methods.
1545 FIXME: Still incomplete. */
1548 print_struct_decl (pretty_printer
*buffer
, tree node
, int spc
, int flags
)
1550 /* Print the name of the structure. */
1551 if (TYPE_NAME (node
))
1554 if (TREE_CODE (node
) == RECORD_TYPE
)
1555 pp_string (buffer
, "struct ");
1556 else if ((TREE_CODE (node
) == UNION_TYPE
1557 || TREE_CODE (node
) == QUAL_UNION_TYPE
))
1558 pp_string (buffer
, "union ");
1560 dump_generic_node (buffer
, TYPE_NAME (node
), spc
, 0, false);
1563 /* Print the contents of the structure. */
1564 pp_newline (buffer
);
1566 pp_character (buffer
, '{');
1567 pp_newline (buffer
);
1569 /* Print the fields of the structure. */
1572 tmp
= TYPE_FIELDS (node
);
1575 /* Avoid to print recursively the structure. */
1576 /* FIXME : Not implemented correctly...,
1577 what about the case when we have a cycle in the contain graph? ...
1578 Maybe this could be solved by looking at the scope in which the
1579 structure was declared. */
1580 if (TREE_TYPE (tmp
) != node
1581 || (TREE_CODE (TREE_TYPE (tmp
)) == POINTER_TYPE
1582 && TREE_TYPE (TREE_TYPE (tmp
)) != node
))
1584 print_declaration (buffer
, tmp
, spc
+2, flags
);
1585 pp_newline (buffer
);
1587 tmp
= TREE_CHAIN (tmp
);
1591 pp_character (buffer
, '}');
1594 /* Return the priority of the operator OP.
1596 From lowest to highest precedence with either left-to-right (L-R)
1597 or right-to-left (R-L) associativity]:
1600 2 [R-L] = += -= *= /= %= &= ^= |= <<= >>=
1612 14 [R-L] ! ~ ++ -- + - * & (type) sizeof
1613 15 [L-R] fn() [] -> .
1615 unary +, - and * have higher precedence than the corresponding binary
1624 switch (TREE_CODE (op
))
1639 case TRUTH_ORIF_EXPR
:
1642 case TRUTH_AND_EXPR
:
1643 case TRUTH_ANDIF_EXPR
:
1650 case TRUTH_XOR_EXPR
:
1667 case UNORDERED_EXPR
:
1685 case TRUNC_DIV_EXPR
:
1687 case FLOOR_DIV_EXPR
:
1688 case ROUND_DIV_EXPR
:
1690 case EXACT_DIV_EXPR
:
1691 case TRUNC_MOD_EXPR
:
1693 case FLOOR_MOD_EXPR
:
1694 case ROUND_MOD_EXPR
:
1697 case TRUTH_NOT_EXPR
:
1699 case POSTINCREMENT_EXPR
:
1700 case POSTDECREMENT_EXPR
:
1701 case PREINCREMENT_EXPR
:
1702 case PREDECREMENT_EXPR
:
1709 case FIX_TRUNC_EXPR
:
1711 case FIX_FLOOR_EXPR
:
1712 case FIX_ROUND_EXPR
:
1718 case ARRAY_RANGE_REF
:
1722 /* Special expressions. */
1731 case NON_LVALUE_EXPR
:
1732 return op_prio (TREE_OPERAND (op
, 0));
1735 /* Return an arbitrarily high precedence to avoid surrounding single
1736 VAR_DECLs in ()s. */
1742 /* Return the symbol associated with operator OP. */
1750 switch (TREE_CODE (op
))
1756 case TRUTH_ORIF_EXPR
:
1759 case TRUTH_AND_EXPR
:
1760 case TRUTH_ANDIF_EXPR
:
1766 case TRUTH_XOR_EXPR
:
1776 case UNORDERED_EXPR
:
1826 case TRUTH_NOT_EXPR
:
1833 case TRUNC_DIV_EXPR
:
1835 case FLOOR_DIV_EXPR
:
1836 case ROUND_DIV_EXPR
:
1838 case EXACT_DIV_EXPR
:
1841 case TRUNC_MOD_EXPR
:
1843 case FLOOR_MOD_EXPR
:
1844 case ROUND_MOD_EXPR
:
1847 case PREDECREMENT_EXPR
:
1850 case PREINCREMENT_EXPR
:
1853 case POSTDECREMENT_EXPR
:
1856 case POSTINCREMENT_EXPR
:
1860 return "<<< ??? >>>";
1864 /* Prints the name of a CALL_EXPR. */
1867 print_call_name (pretty_printer
*buffer
, tree node
)
1871 if (TREE_CODE (node
) != CALL_EXPR
)
1874 op0
= TREE_OPERAND (node
, 0);
1876 if (TREE_CODE (op0
) == NON_LVALUE_EXPR
)
1877 op0
= TREE_OPERAND (op0
, 0);
1879 switch (TREE_CODE (op0
))
1883 PRINT_FUNCTION_NAME (op0
);
1889 dump_generic_node (buffer
, TREE_OPERAND (op0
, 0), 0, 0, false);
1893 pp_string (buffer
, "(");
1894 dump_generic_node (buffer
, TREE_OPERAND (op0
, 0), 0, 0, false);
1895 pp_string (buffer
, ") ? ");
1896 dump_generic_node (buffer
, TREE_OPERAND (op0
, 1), 0, 0, false);
1897 pp_string (buffer
, " : ");
1898 dump_generic_node (buffer
, TREE_OPERAND (op0
, 2), 0, 0, false);
1902 /* The function is a pointer contained in a structure. */
1903 if (TREE_CODE (TREE_OPERAND (op0
, 0)) == INDIRECT_REF
||
1904 TREE_CODE (TREE_OPERAND (op0
, 0)) == VAR_DECL
)
1905 PRINT_FUNCTION_NAME (TREE_OPERAND (op0
, 1));
1907 dump_generic_node (buffer
, TREE_OPERAND (op0
, 0), 0, 0, false);
1909 We can have several levels of structures and a function
1910 pointer inside. This is not implemented yet... */
1915 if (TREE_CODE (TREE_OPERAND (op0
, 0)) == VAR_DECL
)
1916 PRINT_FUNCTION_NAME (TREE_OPERAND (op0
, 0));
1918 dump_generic_node (buffer
, op0
, 0, 0, false);
1923 dump_generic_node (buffer
, op0
, 0, 0, false);
1931 /* Parses the string STR and replaces new-lines by '\n', tabs by '\t', ... */
1934 pretty_print_string (pretty_printer
*buffer
, const char *str
)
1944 pp_string (buffer
, "\\b");
1948 pp_string (buffer
, "\\f");
1952 pp_string (buffer
, "\\n");
1956 pp_string (buffer
, "\\r");
1960 pp_string (buffer
, "\\t");
1964 pp_string (buffer
, "\\v");
1968 pp_string (buffer
, "\\\\");
1972 pp_string (buffer
, "\\\"");
1976 pp_string (buffer
, "\\'");
1980 pp_string (buffer
, "\\0");
1984 pp_string (buffer
, "\\1");
1988 pp_string (buffer
, "\\2");
1992 pp_string (buffer
, "\\3");
1996 pp_string (buffer
, "\\4");
2000 pp_string (buffer
, "\\5");
2004 pp_string (buffer
, "\\6");
2008 pp_string (buffer
, "\\7");
2012 pp_character (buffer
, str
[0]);
2020 maybe_init_pretty_print (FILE *file
)
2024 pp_construct (&buffer
, /* prefix */NULL
, /* line-width */0);
2025 pp_needs_newline (&buffer
) = true;
2029 buffer
.buffer
->stream
= file
;
2033 newline_and_indent (pretty_printer
*buffer
, int spc
)
2035 pp_newline (buffer
);
2040 dump_vops (pretty_printer
*buffer
, tree stmt
, int spc
, int flags
)
2043 stmt_ann_t ann
= stmt_ann (stmt
);
2044 v_may_def_optype v_may_defs
= V_MAY_DEF_OPS (ann
);
2045 v_must_def_optype v_must_defs
= V_MUST_DEF_OPS (ann
);
2046 vuse_optype vuses
= VUSE_OPS (ann
);
2048 for (i
= 0; i
< NUM_V_MAY_DEFS (v_may_defs
); i
++)
2050 pp_string (buffer
, "# ");
2051 dump_generic_node (buffer
, V_MAY_DEF_RESULT (v_may_defs
, i
),
2052 spc
+ 2, flags
, false);
2053 pp_string (buffer
, " = V_MAY_DEF <");
2054 dump_generic_node (buffer
, V_MAY_DEF_OP (v_may_defs
, i
),
2055 spc
+ 2, flags
, false);
2056 pp_string (buffer
, ">;");
2057 newline_and_indent (buffer
, spc
);
2060 for (i
= 0; i
< NUM_V_MUST_DEFS (v_must_defs
); i
++)
2062 tree v_must_def
= V_MUST_DEF_OP (v_must_defs
, i
);
2063 pp_string (buffer
, "# V_MUST_DEF <");
2064 dump_generic_node (buffer
, v_must_def
, spc
+ 2, flags
, false);
2065 pp_string (buffer
, ">;");
2066 newline_and_indent (buffer
, spc
);
2069 for (i
= 0; i
< NUM_VUSES (vuses
); i
++)
2071 tree vuse
= VUSE_OP (vuses
, i
);
2072 pp_string (buffer
, "# VUSE <");
2073 dump_generic_node (buffer
, vuse
, spc
+ 2, flags
, false);
2074 pp_string (buffer
, ">;");
2075 newline_and_indent (buffer
, spc
);
2079 /* Dumps basic block BB to FILE with details described by FLAGS and
2080 indented by INDENT spaces. */
2083 dump_generic_bb (FILE *file
, basic_block bb
, int indent
, int flags
)
2085 maybe_init_pretty_print (file
);
2086 dumping_stmts
= true;
2087 dump_generic_bb_buff (&buffer
, bb
, indent
, flags
);
2091 /* Dumps header of basic block BB to buffer BUFFER indented by INDENT
2092 spaces and details described by flags. */
2095 dump_bb_header (pretty_printer
*buffer
, basic_block bb
, int indent
, int flags
)
2100 if (flags
& TDF_BLOCKS
)
2103 pp_string (buffer
, "# BLOCK ");
2104 pp_decimal_int (buffer
, bb
->index
);
2106 if (flags
& TDF_LINENO
)
2108 block_stmt_iterator bsi
;
2110 for (bsi
= bsi_start (bb
); !bsi_end_p (bsi
); bsi_next (&bsi
))
2111 if (get_lineno (bsi_stmt (bsi
)) != -1)
2113 pp_string (buffer
, ", starting at line ");
2114 pp_decimal_int (buffer
, get_lineno (bsi_stmt (bsi
)));
2118 newline_and_indent (buffer
, indent
);
2120 pp_string (buffer
, "# PRED:");
2121 pp_write_text_to_stream (buffer
);
2122 FOR_EACH_EDGE (e
, bb
->preds
)
2124 if (flags
& TDF_SLIM
)
2126 pp_string (buffer
, " ");
2127 if (e
->src
== ENTRY_BLOCK_PTR
)
2128 pp_string (buffer
, "ENTRY");
2130 pp_decimal_int (buffer
, e
->src
->index
);
2133 dump_edge_info (buffer
->buffer
->stream
, e
, 0);
2136 pp_newline (buffer
);
2140 stmt
= first_stmt (bb
);
2141 if (!stmt
|| TREE_CODE (stmt
) != LABEL_EXPR
)
2143 INDENT (indent
- 2);
2144 pp_string (buffer
, "<bb ");
2145 pp_decimal_int (buffer
, bb
->index
);
2146 pp_string (buffer
, ">:");
2147 pp_newline (buffer
);
2152 /* Dumps end of basic block BB to buffer BUFFER indented by INDENT
2156 dump_bb_end (pretty_printer
*buffer
, basic_block bb
, int indent
, int flags
)
2161 pp_string (buffer
, "# SUCC:");
2162 pp_write_text_to_stream (buffer
);
2164 FOR_EACH_EDGE (e
, bb
->succs
)
2166 if (flags
& TDF_SLIM
)
2168 pp_string (buffer
, " ");
2169 if (e
->dest
== EXIT_BLOCK_PTR
)
2170 pp_string (buffer
, "EXIT");
2172 pp_decimal_int (buffer
, e
->dest
->index
);
2175 dump_edge_info (buffer
->buffer
->stream
, e
, 1);
2178 pp_newline (buffer
);
2181 /* Dumps phi nodes of basic block BB to buffer BUFFER with details described by
2182 FLAGS indented by INDENT spaces. */
2185 dump_phi_nodes (pretty_printer
*buffer
, basic_block bb
, int indent
, int flags
)
2187 tree phi
= phi_nodes (bb
);
2191 for (; phi
; phi
= PHI_CHAIN (phi
))
2193 if (is_gimple_reg (PHI_RESULT (phi
)) || (flags
& TDF_VOPS
))
2196 pp_string (buffer
, "# ");
2197 dump_generic_node (buffer
, phi
, indent
, flags
, false);
2198 pp_newline (buffer
);
2203 /* Dump jump to basic block BB that is represented implicitly in the cfg
2207 pp_cfg_jump (pretty_printer
*buffer
, basic_block bb
)
2211 stmt
= first_stmt (bb
);
2213 pp_string (buffer
, "goto <bb ");
2214 pp_decimal_int (buffer
, bb
->index
);
2215 pp_string (buffer
, ">");
2216 if (stmt
&& TREE_CODE (stmt
) == LABEL_EXPR
)
2218 pp_string (buffer
, " (");
2219 dump_generic_node (buffer
, LABEL_EXPR_LABEL (stmt
), 0, 0, false);
2220 pp_string (buffer
, ")");
2222 pp_semicolon (buffer
);
2225 /* Dump edges represented implicitly in basic block BB to BUFFER, indented
2226 by INDENT spaces, with details given by FLAGS. */
2229 dump_implicit_edges (pretty_printer
*buffer
, basic_block bb
, int indent
,
2234 /* If there is a fallthru edge, we may need to add an artificial goto to the
2236 FOR_EACH_EDGE (e
, bb
->succs
)
2238 if (e
->flags
& EDGE_FALLTHRU
)
2242 if (e
&& e
->dest
!= bb
->next_bb
)
2246 if ((flags
& TDF_LINENO
)
2247 #ifdef USE_MAPPED_LOCATION
2248 && e
->goto_locus
!= UNKNOWN_LOCATION
2254 expanded_location goto_xloc
;
2255 #ifdef USE_MAPPED_LOCATION
2256 goto_xloc
= expand_location (e
->goto_locus
);
2258 goto_xloc
= *e
->goto_locus
;
2260 pp_character (buffer
, '[');
2263 pp_string (buffer
, goto_xloc
.file
);
2264 pp_string (buffer
, " : ");
2266 pp_decimal_int (buffer
, goto_xloc
.line
);
2267 pp_string (buffer
, "] ");
2270 pp_cfg_jump (buffer
, e
->dest
);
2271 pp_newline (buffer
);
2275 /* Dumps basic block BB to buffer BUFFER with details described by FLAGS and
2276 indented by INDENT spaces. */
2279 dump_generic_bb_buff (pretty_printer
*buffer
, basic_block bb
,
2280 int indent
, int flags
)
2282 block_stmt_iterator bsi
;
2284 int label_indent
= indent
- 2;
2286 if (label_indent
< 0)
2289 dump_bb_header (buffer
, bb
, indent
, flags
);
2292 dump_phi_nodes (buffer
, bb
, indent
, flags
);
2294 for (bsi
= bsi_start (bb
); !bsi_end_p (bsi
); bsi_next (&bsi
))
2298 stmt
= bsi_stmt (bsi
);
2300 curr_indent
= TREE_CODE (stmt
) == LABEL_EXPR
? label_indent
: indent
;
2302 INDENT (curr_indent
);
2303 dump_generic_node (buffer
, stmt
, curr_indent
, flags
, true);
2304 pp_newline (buffer
);
2307 dump_implicit_edges (buffer
, bb
, indent
, flags
);
2309 if (flags
& TDF_BLOCKS
)
2310 dump_bb_end (buffer
, bb
, indent
, flags
);