* config/arm/symbian.h (STARTFILE_SPEC): Remove crt*.o.
[official-gcc.git] / gcc / tree-pretty-print.c
blob9337c3856fd33614b5c3fcb85fe9eda3d87f6e33
1 /* Pretty formatting of GENERIC trees in C syntax.
2 Copyright (C) 2001, 2002, 2003, 2004 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
10 version.
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
15 for more details.
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
20 02111-1307, USA. */
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "errors.h"
27 #include "tree.h"
28 #include "diagnostic.h"
29 #include "real.h"
30 #include "hashtab.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. */
65 static void
66 do_niy (pretty_printer *buffer, tree node)
68 int i, len;
70 pp_string (buffer, "<<< Unknown tree: ");
71 pp_string (buffer, tree_code_name[(int) TREE_CODE (node)]);
73 if (EXPR_P (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");
86 void
87 debug_generic_expr (tree t)
89 print_generic_expr (stderr, t, TDF_VOPS|TDF_UID);
90 fprintf (stderr, "\n");
93 void
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. */
101 void
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. */
113 void
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);
119 pp_flush (&buffer);
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
124 INDENT spaces. */
126 void
127 print_generic_stmt_indented (FILE *file, tree t, int flags, int indent)
129 int i;
131 maybe_init_pretty_print (file);
132 dumping_stmts = true;
134 for (i = 0; i < indent; i++)
135 pp_space (&buffer);
136 dump_generic_node (&buffer, t, indent, flags, true);
137 pp_flush (&buffer);
140 /* Print a single expression T on file FILE. FLAGS specifies details to show
141 in the dump. See TDF_* in tree.h. */
143 void
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
152 in FLAGS. */
154 static void
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));
167 else
169 char c = TREE_CODE (node) == CONST_DECL ? 'C' : 'D';
170 pp_printf (buffer, "%c.%u", c, DECL_UID (node));
175 /* Like the above, but used for pretty printing function calls. */
177 static void
178 dump_function_name (pretty_printer *buffer, tree node)
180 if (DECL_NAME (node))
181 PRINT_FUNCTION_NAME (node);
182 else
183 dump_decl_name (buffer, node, 0);
186 /* Dump a function declaration. NODE is the FUNCTION_TYPE. BUFFER, SPC and
187 FLAGS are as in dump_generic_node. */
189 static void
190 dump_function_declaration (pretty_printer *buffer, tree node,
191 int spc, int flags)
193 bool wrote_arg = false;
194 tree arg;
196 pp_space (buffer);
197 pp_character (buffer, '(');
199 /* Print the argument types. The last element in the list is a VOID_TYPE.
200 The following avoids printing the last element. */
201 arg = TYPE_ARG_TYPES (node);
202 while (arg && TREE_CHAIN (arg) && arg != error_mark_node)
204 wrote_arg = true;
205 dump_generic_node (buffer, TREE_VALUE (arg), spc, flags, false);
206 arg = TREE_CHAIN (arg);
207 if (TREE_CHAIN (arg) && TREE_CODE (TREE_CHAIN (arg)) == TREE_LIST)
209 pp_character (buffer, ',');
210 pp_space (buffer);
214 if (!wrote_arg)
215 pp_string (buffer, "void");
217 pp_character (buffer, ')');
220 /* Dump the node NODE on the pretty_printer BUFFER, SPC spaces of indent.
221 FLAGS specifies details to show in the dump (see TDF_* in tree.h). If
222 IS_STMT is true, the object printed is considered to be a statement
223 and it is terminated by ';' if appropriate. */
226 dump_generic_node (pretty_printer *buffer, tree node, int spc, int flags,
227 bool is_stmt)
229 tree type;
230 tree op0, op1;
231 const char *str;
232 bool is_expr;
234 if (node == NULL_TREE)
235 return spc;
237 is_expr = EXPR_P (node);
239 if (TREE_CODE (node) != ERROR_MARK
240 && is_gimple_stmt (node)
241 && (flags & TDF_VOPS)
242 && stmt_ann (node))
243 dump_vops (buffer, node, spc, flags);
245 if (dumping_stmts
246 && (flags & TDF_LINENO)
247 && EXPR_HAS_LOCATION (node))
249 expanded_location xloc = expand_location (EXPR_LOCATION (node));
250 pp_character (buffer, '[');
251 if (xloc.file)
253 pp_string (buffer, xloc.file);
254 pp_string (buffer, " : ");
256 pp_decimal_int (buffer, xloc.line);
257 pp_string (buffer, "] ");
260 switch (TREE_CODE (node))
262 case ERROR_MARK:
263 pp_string (buffer, "<<< error >>>");
264 break;
266 case IDENTIFIER_NODE:
267 pp_tree_identifier (buffer, node);
268 break;
270 case TREE_LIST:
271 while (node && node != error_mark_node)
273 if (TREE_PURPOSE (node))
275 dump_generic_node (buffer, TREE_PURPOSE (node), spc, flags, false);
276 pp_space (buffer);
278 dump_generic_node (buffer, TREE_VALUE (node), spc, flags, false);
279 node = TREE_CHAIN (node);
280 if (node && TREE_CODE (node) == TREE_LIST)
282 pp_character (buffer, ',');
283 pp_space (buffer);
286 break;
288 case TREE_VEC:
289 dump_generic_node (buffer, BINFO_TYPE (node), spc, flags, false);
290 break;
292 case BLOCK:
293 NIY;
294 break;
296 case VOID_TYPE:
297 case INTEGER_TYPE:
298 case REAL_TYPE:
299 case COMPLEX_TYPE:
300 case VECTOR_TYPE:
301 case ENUMERAL_TYPE:
302 case BOOLEAN_TYPE:
303 case CHAR_TYPE:
305 unsigned int quals = TYPE_QUALS (node);
306 enum tree_code_class class;
308 if (quals & TYPE_QUAL_CONST)
309 pp_string (buffer, "const ");
310 else if (quals & TYPE_QUAL_VOLATILE)
311 pp_string (buffer, "volatile ");
312 else if (quals & TYPE_QUAL_RESTRICT)
313 pp_string (buffer, "restrict ");
315 class = TREE_CODE_CLASS (TREE_CODE (node));
317 if (class == tcc_declaration)
319 if (DECL_NAME (node))
320 dump_decl_name (buffer, node, flags);
321 else
322 pp_string (buffer, "<unnamed type decl>");
324 else if (class == tcc_type)
326 if (TYPE_NAME (node))
328 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
329 pp_tree_identifier (buffer, TYPE_NAME (node));
330 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
331 && DECL_NAME (TYPE_NAME (node)))
332 dump_decl_name (buffer, TYPE_NAME (node), flags);
333 else
334 pp_string (buffer, "<unnamed type>");
336 else if (TREE_CODE (node) == VECTOR_TYPE)
338 pp_string (buffer, "vector ");
339 dump_generic_node (buffer, TREE_TYPE (node),
340 spc, flags, false);
342 else
343 pp_string (buffer, "<unnamed type>");
345 break;
348 case POINTER_TYPE:
349 case REFERENCE_TYPE:
350 str = (TREE_CODE (node) == POINTER_TYPE ? "*" : "&");
352 if (TREE_CODE (TREE_TYPE (node)) == FUNCTION_TYPE)
354 tree fnode = TREE_TYPE (node);
356 dump_generic_node (buffer, TREE_TYPE (fnode), spc, flags, false);
357 pp_space (buffer);
358 pp_character (buffer, '(');
359 pp_string (buffer, str);
360 if (TYPE_NAME (node) && DECL_NAME (TYPE_NAME (node)))
361 dump_decl_name (buffer, TYPE_NAME (node), flags);
362 else
363 pp_printf (buffer, "<T%x>", TYPE_UID (node));
365 pp_character (buffer, ')');
366 dump_function_declaration (buffer, fnode, spc, flags);
368 else
370 unsigned int quals = TYPE_QUALS (node);
372 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
373 pp_space (buffer);
374 pp_string (buffer, str);
376 if (quals & TYPE_QUAL_CONST)
377 pp_string (buffer, " const");
378 else if (quals & TYPE_QUAL_VOLATILE)
379 pp_string (buffer, "volatile");
380 else if (quals & TYPE_QUAL_RESTRICT)
381 pp_string (buffer, " restrict");
383 break;
385 case OFFSET_TYPE:
386 NIY;
387 break;
389 case METHOD_TYPE:
390 dump_decl_name (buffer, TYPE_NAME (TYPE_METHOD_BASETYPE (node)), flags);
391 pp_string (buffer, "::");
392 break;
394 case FILE_TYPE:
395 NIY;
396 break;
398 case ARRAY_TYPE:
400 tree tmp;
402 /* Print the innermost component type. */
403 for (tmp = TREE_TYPE (node); TREE_CODE (tmp) == ARRAY_TYPE;
404 tmp = TREE_TYPE (tmp))
406 dump_generic_node (buffer, tmp, spc, flags, false);
408 /* Print the dimensions. */
409 for (tmp = node; TREE_CODE (tmp) == ARRAY_TYPE;
410 tmp = TREE_TYPE (tmp))
412 tree domain = TYPE_DOMAIN (tmp);
414 pp_character (buffer, '[');
415 if (domain)
417 if (TYPE_MIN_VALUE (domain)
418 && !integer_zerop (TYPE_MIN_VALUE (domain)))
420 dump_generic_node (buffer, TYPE_MIN_VALUE (domain),
421 spc, flags, false);
422 pp_string (buffer, " .. ");
425 if (TYPE_MAX_VALUE (domain))
426 dump_generic_node (buffer, TYPE_MAX_VALUE (domain),
427 spc, flags, false);
429 else
430 pp_string (buffer, "<unknown>");
432 pp_character (buffer, ']');
434 break;
437 case SET_TYPE:
438 NIY;
439 break;
441 case RECORD_TYPE:
442 case UNION_TYPE:
443 case QUAL_UNION_TYPE:
444 /* Print the name of the structure. */
445 if (TREE_CODE (node) == RECORD_TYPE)
446 pp_string (buffer, "struct ");
447 else if (TREE_CODE (node) == UNION_TYPE)
448 pp_string (buffer, "union ");
450 if (TYPE_NAME (node))
451 dump_generic_node (buffer, TYPE_NAME (node), spc, flags, false);
452 else
453 print_struct_decl (buffer, node, spc, flags);
454 break;
456 case LANG_TYPE:
457 NIY;
458 break;
460 case INTEGER_CST:
461 if (TREE_CODE (TREE_TYPE (node)) == POINTER_TYPE)
463 /* In the case of a pointer, one may want to divide by the
464 size of the pointed-to type. Unfortunately, this not
465 straightforward. The C front-end maps expressions
467 (int *) 5
468 int *p; (p + 5)
470 in such a way that the two INTEGER_CST nodes for "5" have
471 different values but identical types. In the latter
472 case, the 5 is multiplied by sizeof (int) in c-common.c
473 (pointer_int_sum) to convert it to a byte address, and
474 yet the type of the node is left unchanged. Argh. What
475 is consistent though is that the number value corresponds
476 to bytes (UNITS) offset.
478 NB: Neither of the following divisors can be trivially
479 used to recover the original literal:
481 TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (node)))
482 TYPE_PRECISION (TREE_TYPE (TREE_TYPE (node))) */
483 pp_wide_integer (buffer, TREE_INT_CST_LOW (node));
484 pp_string (buffer, "B"); /* pseudo-unit */
486 else if (! host_integerp (node, 0))
488 tree val = node;
490 if (tree_int_cst_sgn (val) < 0)
492 pp_character (buffer, '-');
493 val = build_int_cst_wide (NULL_TREE,
494 -TREE_INT_CST_LOW (val),
495 ~TREE_INT_CST_HIGH (val)
496 + !TREE_INT_CST_LOW (val));
498 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
499 systems? */
501 static char format[10]; /* "%x%09999x\0" */
502 if (!format[0])
503 sprintf (format, "%%x%%0%dx", HOST_BITS_PER_INT / 4);
504 sprintf (pp_buffer (buffer)->digit_buffer, format,
505 TREE_INT_CST_HIGH (val),
506 TREE_INT_CST_LOW (val));
507 pp_string (buffer, pp_buffer (buffer)->digit_buffer);
510 else
511 pp_wide_integer (buffer, TREE_INT_CST_LOW (node));
512 break;
514 case REAL_CST:
515 /* Code copied from print_node. */
517 REAL_VALUE_TYPE d;
518 if (TREE_OVERFLOW (node))
519 pp_string (buffer, " overflow");
521 #if !defined(REAL_IS_NOT_DOUBLE) || defined(REAL_ARITHMETIC)
522 d = TREE_REAL_CST (node);
523 if (REAL_VALUE_ISINF (d))
524 pp_string (buffer, " Inf");
525 else if (REAL_VALUE_ISNAN (d))
526 pp_string (buffer, " Nan");
527 else
529 char string[100];
530 real_to_decimal (string, &d, sizeof (string), 0, 1);
531 pp_string (buffer, string);
533 #else
535 HOST_WIDE_INT i;
536 unsigned char *p = (unsigned char *) &TREE_REAL_CST (node);
537 pp_string (buffer, "0x");
538 for (i = 0; i < sizeof TREE_REAL_CST (node); i++)
539 output_formatted_integer (buffer, "%02x", *p++);
541 #endif
542 break;
545 case COMPLEX_CST:
546 pp_string (buffer, "__complex__ (");
547 dump_generic_node (buffer, TREE_REALPART (node), spc, flags, false);
548 pp_string (buffer, ", ");
549 dump_generic_node (buffer, TREE_IMAGPART (node), spc, flags, false);
550 pp_string (buffer, ")");
551 break;
553 case STRING_CST:
554 pp_string (buffer, "\"");
555 pretty_print_string (buffer, TREE_STRING_POINTER (node));
556 pp_string (buffer, "\"");
557 break;
559 case VECTOR_CST:
561 tree elt;
562 pp_string (buffer, "{ ");
563 for (elt = TREE_VECTOR_CST_ELTS (node); elt; elt = TREE_CHAIN (elt))
565 dump_generic_node (buffer, TREE_VALUE (elt), spc, flags, false);
566 if (TREE_CHAIN (elt))
567 pp_string (buffer, ", ");
569 pp_string (buffer, " }");
571 break;
573 case FUNCTION_TYPE:
574 break;
576 case FUNCTION_DECL:
577 case CONST_DECL:
578 dump_decl_name (buffer, node, flags);
579 break;
581 case LABEL_DECL:
582 if (DECL_NAME (node))
583 dump_decl_name (buffer, node, flags);
584 else if (LABEL_DECL_UID (node) != -1)
585 pp_printf (buffer, "<L" HOST_WIDE_INT_PRINT_DEC ">",
586 LABEL_DECL_UID (node));
587 else
588 pp_printf (buffer, "<D%u>", DECL_UID (node));
589 break;
591 case TYPE_DECL:
592 if (DECL_IS_BUILTIN (node))
594 /* Don't print the declaration of built-in types. */
595 break;
597 if (DECL_NAME (node))
598 dump_decl_name (buffer, node, flags);
599 else
601 if ((TREE_CODE (TREE_TYPE (node)) == RECORD_TYPE
602 || TREE_CODE (TREE_TYPE (node)) == UNION_TYPE)
603 && TYPE_METHODS (TREE_TYPE (node)))
605 /* The type is a c++ class: all structures have at least
606 4 methods. */
607 pp_string (buffer, "class ");
608 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
610 else
612 pp_string (buffer,
613 (TREE_CODE (TREE_TYPE (node)) == UNION_TYPE
614 ? "union" : "struct "));
615 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
618 break;
620 case VAR_DECL:
621 case PARM_DECL:
622 case FIELD_DECL:
623 case NAMESPACE_DECL:
624 dump_decl_name (buffer, node, flags);
625 break;
627 case RESULT_DECL:
628 pp_string (buffer, "<retval>");
629 break;
631 case COMPONENT_REF:
632 op0 = TREE_OPERAND (node, 0);
633 str = ".";
634 if (TREE_CODE (op0) == INDIRECT_REF)
636 op0 = TREE_OPERAND (op0, 0);
637 str = "->";
639 if (op_prio (op0) < op_prio (node))
640 pp_character (buffer, '(');
641 dump_generic_node (buffer, op0, spc, flags, false);
642 if (op_prio (op0) < op_prio (node))
643 pp_character (buffer, ')');
644 pp_string (buffer, str);
645 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
647 if (TREE_CODE (op0) != VALUE_HANDLE)
649 op0 = component_ref_field_offset (node);
650 if (op0 && TREE_CODE (op0) != INTEGER_CST)
652 pp_string (buffer, "{off: ");
653 dump_generic_node (buffer, op0, spc, flags, false);
654 pp_character (buffer, '}');
657 break;
659 case BIT_FIELD_REF:
660 pp_string (buffer, "BIT_FIELD_REF <");
661 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
662 pp_string (buffer, ", ");
663 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
664 pp_string (buffer, ", ");
665 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
666 pp_string (buffer, ">");
667 break;
669 case ARRAY_REF:
670 case ARRAY_RANGE_REF:
671 op0 = TREE_OPERAND (node, 0);
672 if (op_prio (op0) < op_prio (node))
673 pp_character (buffer, '(');
674 dump_generic_node (buffer, op0, spc, flags, false);
675 if (op_prio (op0) < op_prio (node))
676 pp_character (buffer, ')');
677 pp_character (buffer, '[');
678 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
679 if (TREE_CODE (node) == ARRAY_RANGE_REF)
680 pp_string (buffer, " ...");
681 pp_character (buffer, ']');
683 op0 = array_ref_low_bound (node);
684 op1 = array_ref_element_size (node);
686 if (!integer_zerop (op0)
687 || (TYPE_SIZE_UNIT (TREE_TYPE (node))
688 && !operand_equal_p (op1, TYPE_SIZE_UNIT (TREE_TYPE (node)), 0)))
690 pp_string (buffer, "{lb: ");
691 dump_generic_node (buffer, op0, spc, flags, false);
692 pp_string (buffer, " sz: ");
693 dump_generic_node (buffer, op1, spc, flags, false);
694 pp_character (buffer, '}');
696 break;
698 case CONSTRUCTOR:
700 tree lnode;
701 bool is_struct_init = FALSE;
702 pp_character (buffer, '{');
703 lnode = CONSTRUCTOR_ELTS (node);
704 if (TREE_CODE (TREE_TYPE (node)) == RECORD_TYPE
705 || TREE_CODE (TREE_TYPE (node)) == UNION_TYPE)
706 is_struct_init = TRUE;
707 while (lnode && lnode != error_mark_node)
709 tree val;
710 if (TREE_PURPOSE (lnode) && is_struct_init)
712 pp_character (buffer, '.');
713 dump_generic_node (buffer, TREE_PURPOSE (lnode), spc, flags, false);
714 pp_string (buffer, "=");
716 val = TREE_VALUE (lnode);
717 if (val && TREE_CODE (val) == ADDR_EXPR)
718 if (TREE_CODE (TREE_OPERAND (val, 0)) == FUNCTION_DECL)
719 val = TREE_OPERAND (val, 0);
720 if (val && TREE_CODE (val) == FUNCTION_DECL)
722 dump_decl_name (buffer, val, flags);
724 else
726 dump_generic_node (buffer, TREE_VALUE (lnode), spc, flags, false);
728 lnode = TREE_CHAIN (lnode);
729 if (lnode && TREE_CODE (lnode) == TREE_LIST)
731 pp_character (buffer, ',');
732 pp_space (buffer);
735 pp_character (buffer, '}');
737 break;
739 case COMPOUND_EXPR:
741 tree *tp;
742 if (flags & TDF_SLIM)
744 pp_string (buffer, "<COMPOUND_EXPR>");
745 break;
748 dump_generic_node (buffer, TREE_OPERAND (node, 0),
749 spc, flags, dumping_stmts);
750 if (dumping_stmts)
751 newline_and_indent (buffer, spc);
752 else
754 pp_character (buffer, ',');
755 pp_space (buffer);
758 for (tp = &TREE_OPERAND (node, 1);
759 TREE_CODE (*tp) == COMPOUND_EXPR;
760 tp = &TREE_OPERAND (*tp, 1))
762 dump_generic_node (buffer, TREE_OPERAND (*tp, 0),
763 spc, flags, dumping_stmts);
764 if (dumping_stmts)
765 newline_and_indent (buffer, spc);
766 else
768 pp_character (buffer, ',');
769 pp_space (buffer);
773 dump_generic_node (buffer, *tp, spc, flags, dumping_stmts);
775 break;
777 case STATEMENT_LIST:
779 tree_stmt_iterator si;
780 bool first = true;
782 if ((flags & TDF_SLIM) || !dumping_stmts)
784 pp_string (buffer, "<STATEMENT_LIST>");
785 break;
788 for (si = tsi_start (node); !tsi_end_p (si); tsi_next (&si))
790 if (!first)
791 newline_and_indent (buffer, spc);
792 else
793 first = false;
794 dump_generic_node (buffer, tsi_stmt (si), spc, flags, true);
797 break;
799 case MODIFY_EXPR:
800 case INIT_EXPR:
801 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
802 pp_space (buffer);
803 pp_character (buffer, '=');
804 pp_space (buffer);
805 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
806 break;
808 case TARGET_EXPR:
809 pp_string (buffer, "TARGET_EXPR <");
810 dump_generic_node (buffer, TARGET_EXPR_SLOT (node), spc, flags, false);
811 pp_character (buffer, ',');
812 pp_space (buffer);
813 dump_generic_node (buffer, TARGET_EXPR_INITIAL (node), spc, flags, false);
814 pp_character (buffer, '>');
815 break;
817 case DECL_EXPR:
818 print_declaration (buffer, DECL_EXPR_DECL (node), spc, flags);
819 is_stmt = false;
820 break;
822 case COND_EXPR:
823 if (TREE_TYPE (node) == NULL || TREE_TYPE (node) == void_type_node)
825 pp_string (buffer, "if (");
826 dump_generic_node (buffer, COND_EXPR_COND (node), spc, flags, false);
827 pp_character (buffer, ')');
828 /* The lowered cond_exprs should always be printed in full. */
829 if (COND_EXPR_THEN (node)
830 && TREE_CODE (COND_EXPR_THEN (node)) == GOTO_EXPR
831 && COND_EXPR_ELSE (node)
832 && TREE_CODE (COND_EXPR_ELSE (node)) == GOTO_EXPR)
834 pp_space (buffer);
835 dump_generic_node (buffer, COND_EXPR_THEN (node), 0, flags, true);
836 pp_string (buffer, " else ");
837 dump_generic_node (buffer, COND_EXPR_ELSE (node), 0, flags, true);
839 else if (!(flags & TDF_SLIM))
841 /* Output COND_EXPR_THEN. */
842 if (COND_EXPR_THEN (node))
844 newline_and_indent (buffer, spc+2);
845 pp_character (buffer, '{');
846 newline_and_indent (buffer, spc+4);
847 dump_generic_node (buffer, COND_EXPR_THEN (node), spc+4,
848 flags, true);
849 newline_and_indent (buffer, spc+2);
850 pp_character (buffer, '}');
853 /* Output COND_EXPR_ELSE. */
854 if (COND_EXPR_ELSE (node))
856 newline_and_indent (buffer, spc);
857 pp_string (buffer, "else");
858 newline_and_indent (buffer, spc+2);
859 pp_character (buffer, '{');
860 newline_and_indent (buffer, spc+4);
861 dump_generic_node (buffer, COND_EXPR_ELSE (node), spc+4,
862 flags, true);
863 newline_and_indent (buffer, spc+2);
864 pp_character (buffer, '}');
867 is_expr = false;
869 else
871 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
872 pp_space (buffer);
873 pp_character (buffer, '?');
874 pp_space (buffer);
875 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
876 pp_space (buffer);
877 pp_character (buffer, ':');
878 pp_space (buffer);
879 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
881 break;
883 case BIND_EXPR:
884 pp_character (buffer, '{');
885 if (!(flags & TDF_SLIM))
887 if (BIND_EXPR_VARS (node))
889 pp_newline (buffer);
891 for (op0 = BIND_EXPR_VARS (node); op0; op0 = TREE_CHAIN (op0))
893 print_declaration (buffer, op0, spc+2, flags);
894 pp_newline (buffer);
898 newline_and_indent (buffer, spc+2);
899 dump_generic_node (buffer, BIND_EXPR_BODY (node), spc+2, flags, true);
900 newline_and_indent (buffer, spc);
901 pp_character (buffer, '}');
903 is_expr = false;
904 break;
906 case CALL_EXPR:
907 print_call_name (buffer, node);
909 /* Print parameters. */
910 pp_space (buffer);
911 pp_character (buffer, '(');
912 op1 = TREE_OPERAND (node, 1);
913 if (op1)
914 dump_generic_node (buffer, op1, spc, flags, false);
915 pp_character (buffer, ')');
917 op1 = TREE_OPERAND (node, 2);
918 if (op1)
920 pp_string (buffer, " [static-chain: ");
921 dump_generic_node (buffer, op1, spc, flags, false);
922 pp_character (buffer, ']');
925 if (CALL_EXPR_HAS_RETURN_SLOT_ADDR (node))
926 pp_string (buffer, " [return slot addr]");
927 if (CALL_EXPR_TAILCALL (node))
928 pp_string (buffer, " [tail call]");
929 break;
931 case WITH_CLEANUP_EXPR:
932 NIY;
933 break;
935 case CLEANUP_POINT_EXPR:
936 pp_string (buffer, "<<cleanup_point ");
937 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
938 pp_string (buffer, ">>");
939 break;
941 case PLACEHOLDER_EXPR:
942 pp_string (buffer, "<PLACEHOLDER_EXPR ");
943 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
944 pp_character (buffer, '>');
945 break;
947 /* Binary arithmetic and logic expressions. */
948 case MULT_EXPR:
949 case PLUS_EXPR:
950 case MINUS_EXPR:
951 case TRUNC_DIV_EXPR:
952 case CEIL_DIV_EXPR:
953 case FLOOR_DIV_EXPR:
954 case ROUND_DIV_EXPR:
955 case TRUNC_MOD_EXPR:
956 case CEIL_MOD_EXPR:
957 case FLOOR_MOD_EXPR:
958 case ROUND_MOD_EXPR:
959 case RDIV_EXPR:
960 case EXACT_DIV_EXPR:
961 case LSHIFT_EXPR:
962 case RSHIFT_EXPR:
963 case LROTATE_EXPR:
964 case RROTATE_EXPR:
965 case BIT_IOR_EXPR:
966 case BIT_XOR_EXPR:
967 case BIT_AND_EXPR:
968 case TRUTH_ANDIF_EXPR:
969 case TRUTH_ORIF_EXPR:
970 case TRUTH_AND_EXPR:
971 case TRUTH_OR_EXPR:
972 case TRUTH_XOR_EXPR:
973 case LT_EXPR:
974 case LE_EXPR:
975 case GT_EXPR:
976 case GE_EXPR:
977 case EQ_EXPR:
978 case NE_EXPR:
979 case UNLT_EXPR:
980 case UNLE_EXPR:
981 case UNGT_EXPR:
982 case UNGE_EXPR:
983 case UNEQ_EXPR:
984 case LTGT_EXPR:
985 case ORDERED_EXPR:
986 case UNORDERED_EXPR:
988 const char *op = op_symbol (node);
989 op0 = TREE_OPERAND (node, 0);
990 op1 = TREE_OPERAND (node, 1);
992 /* When the operands are expressions with less priority,
993 keep semantics of the tree representation. */
994 if (op_prio (op0) < op_prio (node))
996 pp_character (buffer, '(');
997 dump_generic_node (buffer, op0, spc, flags, false);
998 pp_character (buffer, ')');
1000 else
1001 dump_generic_node (buffer, op0, spc, flags, false);
1003 pp_space (buffer);
1004 pp_string (buffer, op);
1005 pp_space (buffer);
1007 /* When the operands are expressions with less priority,
1008 keep semantics of the tree representation. */
1009 if (op_prio (op1) < op_prio (node))
1011 pp_character (buffer, '(');
1012 dump_generic_node (buffer, op1, spc, flags, false);
1013 pp_character (buffer, ')');
1015 else
1016 dump_generic_node (buffer, op1, spc, flags, false);
1018 break;
1020 /* Unary arithmetic and logic expressions. */
1021 case NEGATE_EXPR:
1022 case BIT_NOT_EXPR:
1023 case TRUTH_NOT_EXPR:
1024 case ADDR_EXPR:
1025 case PREDECREMENT_EXPR:
1026 case PREINCREMENT_EXPR:
1027 case ALIGN_INDIRECT_REF:
1028 case MISALIGNED_INDIRECT_REF:
1029 case INDIRECT_REF:
1030 if (TREE_CODE (node) == ADDR_EXPR
1031 && (TREE_CODE (TREE_OPERAND (node, 0)) == STRING_CST
1032 || TREE_CODE (TREE_OPERAND (node, 0)) == FUNCTION_DECL))
1033 ; /* Do not output '&' for strings and function pointers. */
1034 else
1035 pp_string (buffer, op_symbol (node));
1037 if (op_prio (TREE_OPERAND (node, 0)) < op_prio (node))
1039 pp_character (buffer, '(');
1040 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1041 pp_character (buffer, ')');
1043 else
1044 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1046 if (TREE_CODE (node) == MISALIGNED_INDIRECT_REF)
1048 pp_string (buffer, "{misalignment: ");
1049 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1050 pp_character (buffer, '}');
1052 break;
1054 case POSTDECREMENT_EXPR:
1055 case POSTINCREMENT_EXPR:
1056 if (op_prio (TREE_OPERAND (node, 0)) < op_prio (node))
1058 pp_character (buffer, '(');
1059 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1060 pp_character (buffer, ')');
1062 else
1063 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1064 pp_string (buffer, op_symbol (node));
1065 break;
1067 case MIN_EXPR:
1068 pp_string (buffer, "MIN_EXPR <");
1069 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1070 pp_string (buffer, ", ");
1071 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1072 pp_character (buffer, '>');
1073 break;
1075 case MAX_EXPR:
1076 pp_string (buffer, "MAX_EXPR <");
1077 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1078 pp_string (buffer, ", ");
1079 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1080 pp_character (buffer, '>');
1081 break;
1083 case ABS_EXPR:
1084 pp_string (buffer, "ABS_EXPR <");
1085 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1086 pp_character (buffer, '>');
1087 break;
1089 case RANGE_EXPR:
1090 NIY;
1091 break;
1093 case FIX_TRUNC_EXPR:
1094 case FIX_CEIL_EXPR:
1095 case FIX_FLOOR_EXPR:
1096 case FIX_ROUND_EXPR:
1097 case FLOAT_EXPR:
1098 case CONVERT_EXPR:
1099 case NOP_EXPR:
1100 type = TREE_TYPE (node);
1101 op0 = TREE_OPERAND (node, 0);
1102 if (type != TREE_TYPE (op0))
1104 pp_character (buffer, '(');
1105 dump_generic_node (buffer, type, spc, flags, false);
1106 pp_string (buffer, ") ");
1108 if (op_prio (op0) < op_prio (node))
1109 pp_character (buffer, '(');
1110 dump_generic_node (buffer, op0, spc, flags, false);
1111 if (op_prio (op0) < op_prio (node))
1112 pp_character (buffer, ')');
1113 break;
1115 case VIEW_CONVERT_EXPR:
1116 pp_string (buffer, "VIEW_CONVERT_EXPR<");
1117 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
1118 pp_string (buffer, ">(");
1119 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1120 pp_character (buffer, ')');
1121 break;
1123 case NON_LVALUE_EXPR:
1124 pp_string (buffer, "NON_LVALUE_EXPR <");
1125 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1126 pp_character (buffer, '>');
1127 break;
1129 case SAVE_EXPR:
1130 pp_string (buffer, "SAVE_EXPR <");
1131 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1132 pp_character (buffer, '>');
1133 break;
1135 case COMPLEX_EXPR:
1136 pp_string (buffer, "COMPLEX_EXPR <");
1137 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1138 pp_string (buffer, ", ");
1139 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1140 pp_string (buffer, ">");
1141 break;
1143 case CONJ_EXPR:
1144 pp_string (buffer, "CONJ_EXPR <");
1145 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1146 pp_string (buffer, ">");
1147 break;
1149 case REALPART_EXPR:
1150 pp_string (buffer, "REALPART_EXPR <");
1151 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1152 pp_string (buffer, ">");
1153 break;
1155 case IMAGPART_EXPR:
1156 pp_string (buffer, "IMAGPART_EXPR <");
1157 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1158 pp_string (buffer, ">");
1159 break;
1161 case VA_ARG_EXPR:
1162 pp_string (buffer, "VA_ARG_EXPR <");
1163 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1164 pp_string (buffer, ">");
1165 break;
1167 case TRY_FINALLY_EXPR:
1168 case TRY_CATCH_EXPR:
1169 pp_string (buffer, "try");
1170 newline_and_indent (buffer, spc+2);
1171 pp_string (buffer, "{");
1172 newline_and_indent (buffer, spc+4);
1173 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc+4, flags, true);
1174 newline_and_indent (buffer, spc+2);
1175 pp_string (buffer, "}");
1176 newline_and_indent (buffer, spc);
1177 pp_string (buffer,
1178 (TREE_CODE (node) == TRY_CATCH_EXPR) ? "catch" : "finally");
1179 newline_and_indent (buffer, spc+2);
1180 pp_string (buffer, "{");
1181 newline_and_indent (buffer, spc+4);
1182 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc+4, flags, true);
1183 newline_and_indent (buffer, spc+2);
1184 pp_string (buffer, "}");
1185 is_expr = false;
1186 break;
1188 case CATCH_EXPR:
1189 pp_string (buffer, "catch (");
1190 dump_generic_node (buffer, CATCH_TYPES (node), spc+2, flags, false);
1191 pp_string (buffer, ")");
1192 newline_and_indent (buffer, spc+2);
1193 pp_string (buffer, "{");
1194 newline_and_indent (buffer, spc+4);
1195 dump_generic_node (buffer, CATCH_BODY (node), spc+4, flags, true);
1196 newline_and_indent (buffer, spc+2);
1197 pp_string (buffer, "}");
1198 is_expr = false;
1199 break;
1201 case EH_FILTER_EXPR:
1202 pp_string (buffer, "<<<eh_filter (");
1203 dump_generic_node (buffer, EH_FILTER_TYPES (node), spc+2, flags, false);
1204 pp_string (buffer, ")>>>");
1205 newline_and_indent (buffer, spc+2);
1206 pp_string (buffer, "{");
1207 newline_and_indent (buffer, spc+4);
1208 dump_generic_node (buffer, EH_FILTER_FAILURE (node), spc+4, flags, true);
1209 newline_and_indent (buffer, spc+2);
1210 pp_string (buffer, "}");
1211 is_expr = false;
1212 break;
1214 case LABEL_EXPR:
1215 op0 = TREE_OPERAND (node, 0);
1216 /* If this is for break or continue, don't bother printing it. */
1217 if (DECL_NAME (op0))
1219 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1220 if (strcmp (name, "break") == 0
1221 || strcmp (name, "continue") == 0)
1222 break;
1224 dump_generic_node (buffer, op0, spc, flags, false);
1225 pp_character (buffer, ':');
1226 if (DECL_NONLOCAL (op0))
1227 pp_string (buffer, " [non-local]");
1228 break;
1230 case LABELED_BLOCK_EXPR:
1231 op0 = LABELED_BLOCK_LABEL (node);
1232 /* If this is for break or continue, don't bother printing it. */
1233 if (DECL_NAME (op0))
1235 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1236 if (strcmp (name, "break") == 0
1237 || strcmp (name, "continue") == 0)
1239 dump_generic_node (buffer, LABELED_BLOCK_BODY (node), spc, flags, false);
1240 break;
1243 dump_generic_node (buffer, LABELED_BLOCK_LABEL (node), spc, flags, false);
1244 pp_string (buffer, ": {");
1245 if (!(flags & TDF_SLIM))
1246 newline_and_indent (buffer, spc+2);
1247 dump_generic_node (buffer, LABELED_BLOCK_BODY (node), spc+2, flags, true);
1248 if (!flags)
1249 newline_and_indent (buffer, spc);
1250 pp_character (buffer, '}');
1251 is_expr = false;
1252 break;
1254 case EXIT_BLOCK_EXPR:
1255 op0 = LABELED_BLOCK_LABEL (EXIT_BLOCK_LABELED_BLOCK (node));
1256 /* If this is for a break or continue, print it accordingly. */
1257 if (DECL_NAME (op0))
1259 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1260 if (strcmp (name, "break") == 0
1261 || strcmp (name, "continue") == 0)
1263 pp_string (buffer, name);
1264 break;
1267 pp_string (buffer, "<<<exit block ");
1268 dump_generic_node (buffer, op0, spc, flags, false);
1269 pp_string (buffer, ">>>");
1270 break;
1272 case EXC_PTR_EXPR:
1273 pp_string (buffer, "<<<exception object>>>");
1274 break;
1276 case FILTER_EXPR:
1277 pp_string (buffer, "<<<filter object>>>");
1278 break;
1280 case LOOP_EXPR:
1281 pp_string (buffer, "while (1)");
1282 if (!(flags & TDF_SLIM))
1284 newline_and_indent (buffer, spc+2);
1285 pp_character (buffer, '{');
1286 newline_and_indent (buffer, spc+4);
1287 dump_generic_node (buffer, LOOP_EXPR_BODY (node), spc+4, flags, true);
1288 newline_and_indent (buffer, spc+2);
1289 pp_character (buffer, '}');
1291 is_expr = false;
1292 break;
1294 case RETURN_EXPR:
1295 pp_string (buffer, "return");
1296 op0 = TREE_OPERAND (node, 0);
1297 if (op0)
1299 pp_space (buffer);
1300 if (TREE_CODE (op0) == MODIFY_EXPR)
1301 dump_generic_node (buffer, TREE_OPERAND (op0, 1), spc, flags, false);
1302 else
1303 dump_generic_node (buffer, op0, spc, flags, false);
1305 break;
1307 case EXIT_EXPR:
1308 pp_string (buffer, "if (");
1309 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1310 pp_string (buffer, ") break");
1311 break;
1313 case SWITCH_EXPR:
1314 pp_string (buffer, "switch (");
1315 dump_generic_node (buffer, SWITCH_COND (node), spc, flags, false);
1316 pp_character (buffer, ')');
1317 if (!(flags & TDF_SLIM))
1319 newline_and_indent (buffer, spc+2);
1320 pp_character (buffer, '{');
1321 if (SWITCH_BODY (node))
1323 newline_and_indent (buffer, spc+4);
1324 dump_generic_node (buffer, SWITCH_BODY (node), spc+4, flags, true);
1326 else
1328 tree vec = SWITCH_LABELS (node);
1329 size_t i, n = TREE_VEC_LENGTH (vec);
1330 for (i = 0; i < n; ++i)
1332 tree elt = TREE_VEC_ELT (vec, i);
1333 newline_and_indent (buffer, spc+4);
1334 dump_generic_node (buffer, elt, spc+4, flags, false);
1335 pp_string (buffer, " goto ");
1336 dump_generic_node (buffer, CASE_LABEL (elt), spc+4, flags, true);
1337 pp_semicolon (buffer);
1340 newline_and_indent (buffer, spc+2);
1341 pp_character (buffer, '}');
1343 is_expr = false;
1344 break;
1346 case GOTO_EXPR:
1347 op0 = GOTO_DESTINATION (node);
1348 if (TREE_CODE (op0) != SSA_NAME && DECL_P (op0) && DECL_NAME (op0))
1350 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1351 if (strcmp (name, "break") == 0
1352 || strcmp (name, "continue") == 0)
1354 pp_string (buffer, name);
1355 break;
1358 pp_string (buffer, "goto ");
1359 dump_generic_node (buffer, op0, spc, flags, false);
1360 break;
1362 case RESX_EXPR:
1363 pp_string (buffer, "resx");
1364 /* ??? Any sensible way to present the eh region? */
1365 break;
1367 case ASM_EXPR:
1368 pp_string (buffer, "__asm__");
1369 if (ASM_VOLATILE_P (node))
1370 pp_string (buffer, " __volatile__");
1371 pp_character (buffer, '(');
1372 dump_generic_node (buffer, ASM_STRING (node), spc, flags, false);
1373 pp_character (buffer, ':');
1374 dump_generic_node (buffer, ASM_OUTPUTS (node), spc, flags, false);
1375 pp_character (buffer, ':');
1376 dump_generic_node (buffer, ASM_INPUTS (node), spc, flags, false);
1377 if (ASM_CLOBBERS (node))
1379 pp_character (buffer, ':');
1380 dump_generic_node (buffer, ASM_CLOBBERS (node), spc, flags, false);
1382 pp_string (buffer, ")");
1383 break;
1385 case CASE_LABEL_EXPR:
1386 if (CASE_LOW (node) && CASE_HIGH (node))
1388 pp_string (buffer, "case ");
1389 dump_generic_node (buffer, CASE_LOW (node), spc, flags, false);
1390 pp_string (buffer, " ... ");
1391 dump_generic_node (buffer, CASE_HIGH (node), spc, flags, false);
1393 else if (CASE_LOW (node))
1395 pp_string (buffer, "case ");
1396 dump_generic_node (buffer, CASE_LOW (node), spc, flags, false);
1398 else
1399 pp_string (buffer, "default ");
1400 pp_character (buffer, ':');
1401 break;
1403 case OBJ_TYPE_REF:
1404 pp_string (buffer, "OBJ_TYPE_REF(");
1405 dump_generic_node (buffer, OBJ_TYPE_REF_EXPR (node), spc, flags, false);
1406 pp_character (buffer, ';');
1407 dump_generic_node (buffer, OBJ_TYPE_REF_OBJECT (node), spc, flags, false);
1408 pp_character (buffer, '-');
1409 pp_character (buffer, '>');
1410 dump_generic_node (buffer, OBJ_TYPE_REF_TOKEN (node), spc, flags, false);
1411 pp_character (buffer, ')');
1412 break;
1414 case PHI_NODE:
1416 int i;
1418 dump_generic_node (buffer, PHI_RESULT (node), spc, flags, false);
1419 pp_string (buffer, " = PHI <");
1420 for (i = 0; i < PHI_NUM_ARGS (node); i++)
1422 dump_generic_node (buffer, PHI_ARG_DEF (node, i), spc, flags, false);
1423 pp_string (buffer, "(");
1424 pp_decimal_int (buffer, PHI_ARG_EDGE (node, i)->src->index);
1425 pp_string (buffer, ")");
1426 if (i < PHI_NUM_ARGS (node) - 1)
1427 pp_string (buffer, ", ");
1429 pp_string (buffer, ">;");
1431 break;
1433 case SSA_NAME:
1434 dump_generic_node (buffer, SSA_NAME_VAR (node), spc, flags, false);
1435 pp_string (buffer, "_");
1436 pp_decimal_int (buffer, SSA_NAME_VERSION (node));
1437 break;
1439 case WITH_SIZE_EXPR:
1440 pp_string (buffer, "WITH_SIZE_EXPR <");
1441 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1442 pp_string (buffer, ", ");
1443 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1444 pp_string (buffer, ">");
1445 break;
1447 case VALUE_HANDLE:
1448 pp_printf (buffer, "VH.%d", VALUE_HANDLE_ID (node));
1449 break;
1451 case SCEV_KNOWN:
1452 pp_string (buffer, "scev_known");
1453 break;
1455 case SCEV_NOT_KNOWN:
1456 pp_string (buffer, "scev_not_known");
1457 break;
1459 case POLYNOMIAL_CHREC:
1460 pp_string (buffer, "{");
1461 dump_generic_node (buffer, CHREC_LEFT (node), spc, flags, false);
1462 pp_string (buffer, ", +, ");
1463 dump_generic_node (buffer, CHREC_RIGHT (node), spc, flags, false);
1464 pp_string (buffer, "}_");
1465 dump_generic_node (buffer, CHREC_VAR (node), spc, flags, false);
1466 is_stmt = false;
1467 break;
1469 case REALIGN_LOAD_EXPR:
1470 pp_string (buffer, "REALIGN_LOAD <");
1471 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1472 pp_string (buffer, ", ");
1473 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1474 pp_string (buffer, ", ");
1475 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
1476 pp_string (buffer, ">");
1477 break;
1479 case VEC_COND_EXPR:
1480 pp_string (buffer, " VEC_COND_EXPR < ");
1481 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1482 pp_string (buffer, " , ");
1483 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1484 pp_string (buffer, " , ");
1485 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
1486 pp_string (buffer, " > ");
1487 break;
1489 default:
1490 NIY;
1493 if (is_stmt && is_expr)
1494 pp_semicolon (buffer);
1495 pp_write_text_to_stream (buffer);
1497 return spc;
1500 /* Print the declaration of a variable. */
1502 static void
1503 print_declaration (pretty_printer *buffer, tree t, int spc, int flags)
1505 INDENT (spc);
1507 if (TREE_CODE (t) == TYPE_DECL)
1508 pp_string (buffer, "typedef ");
1510 if (DECL_REGISTER (t))
1511 pp_string (buffer, "register ");
1513 if (TREE_PUBLIC (t) && DECL_EXTERNAL (t))
1514 pp_string (buffer, "extern ");
1515 else if (TREE_STATIC (t))
1516 pp_string (buffer, "static ");
1518 /* Print the type and name. */
1519 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
1521 tree tmp;
1523 /* Print array's type. */
1524 tmp = TREE_TYPE (t);
1525 while (TREE_CODE (TREE_TYPE (tmp)) == ARRAY_TYPE)
1526 tmp = TREE_TYPE (tmp);
1527 dump_generic_node (buffer, TREE_TYPE (tmp), spc, flags, false);
1529 /* Print variable's name. */
1530 pp_space (buffer);
1531 dump_generic_node (buffer, t, spc, flags, false);
1533 /* Print the dimensions. */
1534 tmp = TREE_TYPE (t);
1535 while (TREE_CODE (tmp) == ARRAY_TYPE)
1537 pp_character (buffer, '[');
1538 if (TYPE_DOMAIN (tmp))
1540 if (TREE_CODE (TYPE_SIZE (tmp)) == INTEGER_CST)
1541 pp_wide_integer (buffer,
1542 TREE_INT_CST_LOW (TYPE_SIZE (tmp)) /
1543 TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (tmp))));
1544 else
1545 dump_generic_node (buffer, TYPE_SIZE_UNIT (tmp), spc, flags,
1546 false);
1548 pp_character (buffer, ']');
1549 tmp = TREE_TYPE (tmp);
1552 else if (TREE_CODE (t) == FUNCTION_DECL)
1554 dump_generic_node (buffer, TREE_TYPE (TREE_TYPE (t)), spc, flags, false);
1555 pp_space (buffer);
1556 dump_decl_name (buffer, t, flags);
1557 dump_function_declaration (buffer, TREE_TYPE (t), spc, flags);
1559 else
1561 /* Print type declaration. */
1562 dump_generic_node (buffer, TREE_TYPE (t), spc, flags, false);
1564 /* Print variable's name. */
1565 pp_space (buffer);
1566 dump_generic_node (buffer, t, spc, flags, false);
1569 if (TREE_CODE (t) == VAR_DECL && DECL_HARD_REGISTER (t))
1571 pp_string (buffer, " __asm__ ");
1572 pp_character (buffer, '(');
1573 dump_generic_node (buffer, DECL_ASSEMBLER_NAME (t), spc, flags, false);
1574 pp_character (buffer, ')');
1577 /* The initial value of a function serves to determine wether the function
1578 is declared or defined. So the following does not apply to function
1579 nodes. */
1580 if (TREE_CODE (t) != FUNCTION_DECL)
1582 /* Print the initial value. */
1583 if (DECL_INITIAL (t))
1585 pp_space (buffer);
1586 pp_character (buffer, '=');
1587 pp_space (buffer);
1588 dump_generic_node (buffer, DECL_INITIAL (t), spc, flags, false);
1592 pp_character (buffer, ';');
1596 /* Prints a structure: name, fields, and methods.
1597 FIXME: Still incomplete. */
1599 static void
1600 print_struct_decl (pretty_printer *buffer, tree node, int spc, int flags)
1602 /* Print the name of the structure. */
1603 if (TYPE_NAME (node))
1605 INDENT (spc);
1606 if (TREE_CODE (node) == RECORD_TYPE)
1607 pp_string (buffer, "struct ");
1608 else if ((TREE_CODE (node) == UNION_TYPE
1609 || TREE_CODE (node) == QUAL_UNION_TYPE))
1610 pp_string (buffer, "union ");
1612 dump_generic_node (buffer, TYPE_NAME (node), spc, 0, false);
1615 /* Print the contents of the structure. */
1616 pp_newline (buffer);
1617 INDENT (spc);
1618 pp_character (buffer, '{');
1619 pp_newline (buffer);
1621 /* Print the fields of the structure. */
1623 tree tmp;
1624 tmp = TYPE_FIELDS (node);
1625 while (tmp)
1627 /* Avoid to print recursively the structure. */
1628 /* FIXME : Not implemented correctly...,
1629 what about the case when we have a cycle in the contain graph? ...
1630 Maybe this could be solved by looking at the scope in which the
1631 structure was declared. */
1632 if (TREE_TYPE (tmp) != node
1633 || (TREE_CODE (TREE_TYPE (tmp)) == POINTER_TYPE
1634 && TREE_TYPE (TREE_TYPE (tmp)) != node))
1636 print_declaration (buffer, tmp, spc+2, flags);
1637 pp_newline (buffer);
1639 tmp = TREE_CHAIN (tmp);
1642 INDENT (spc);
1643 pp_character (buffer, '}');
1646 /* Return the priority of the operator OP.
1648 From lowest to highest precedence with either left-to-right (L-R)
1649 or right-to-left (R-L) associativity]:
1651 1 [L-R] ,
1652 2 [R-L] = += -= *= /= %= &= ^= |= <<= >>=
1653 3 [R-L] ?:
1654 4 [L-R] ||
1655 5 [L-R] &&
1656 6 [L-R] |
1657 7 [L-R] ^
1658 8 [L-R] &
1659 9 [L-R] == !=
1660 10 [L-R] < <= > >=
1661 11 [L-R] << >>
1662 12 [L-R] + -
1663 13 [L-R] * / %
1664 14 [R-L] ! ~ ++ -- + - * & (type) sizeof
1665 15 [L-R] fn() [] -> .
1667 unary +, - and * have higher precedence than the corresponding binary
1668 operators. */
1670 static int
1671 op_prio (tree op)
1673 if (op == NULL)
1674 return 9999;
1676 switch (TREE_CODE (op))
1678 case TREE_LIST:
1679 case COMPOUND_EXPR:
1680 case BIND_EXPR:
1681 return 1;
1683 case MODIFY_EXPR:
1684 case INIT_EXPR:
1685 return 2;
1687 case COND_EXPR:
1688 return 3;
1690 case TRUTH_OR_EXPR:
1691 case TRUTH_ORIF_EXPR:
1692 return 4;
1694 case TRUTH_AND_EXPR:
1695 case TRUTH_ANDIF_EXPR:
1696 return 5;
1698 case BIT_IOR_EXPR:
1699 return 6;
1701 case BIT_XOR_EXPR:
1702 case TRUTH_XOR_EXPR:
1703 return 7;
1705 case BIT_AND_EXPR:
1706 return 8;
1708 case EQ_EXPR:
1709 case NE_EXPR:
1710 return 9;
1712 case UNLT_EXPR:
1713 case UNLE_EXPR:
1714 case UNGT_EXPR:
1715 case UNGE_EXPR:
1716 case UNEQ_EXPR:
1717 case LTGT_EXPR:
1718 case ORDERED_EXPR:
1719 case UNORDERED_EXPR:
1720 case LT_EXPR:
1721 case LE_EXPR:
1722 case GT_EXPR:
1723 case GE_EXPR:
1724 return 10;
1726 case LSHIFT_EXPR:
1727 case RSHIFT_EXPR:
1728 case LROTATE_EXPR:
1729 case RROTATE_EXPR:
1730 return 11;
1732 case PLUS_EXPR:
1733 case MINUS_EXPR:
1734 return 12;
1736 case MULT_EXPR:
1737 case TRUNC_DIV_EXPR:
1738 case CEIL_DIV_EXPR:
1739 case FLOOR_DIV_EXPR:
1740 case ROUND_DIV_EXPR:
1741 case RDIV_EXPR:
1742 case EXACT_DIV_EXPR:
1743 case TRUNC_MOD_EXPR:
1744 case CEIL_MOD_EXPR:
1745 case FLOOR_MOD_EXPR:
1746 case ROUND_MOD_EXPR:
1747 return 13;
1749 case TRUTH_NOT_EXPR:
1750 case BIT_NOT_EXPR:
1751 case POSTINCREMENT_EXPR:
1752 case POSTDECREMENT_EXPR:
1753 case PREINCREMENT_EXPR:
1754 case PREDECREMENT_EXPR:
1755 case NEGATE_EXPR:
1756 case ALIGN_INDIRECT_REF:
1757 case MISALIGNED_INDIRECT_REF:
1758 case INDIRECT_REF:
1759 case ADDR_EXPR:
1760 case FLOAT_EXPR:
1761 case NOP_EXPR:
1762 case CONVERT_EXPR:
1763 case FIX_TRUNC_EXPR:
1764 case FIX_CEIL_EXPR:
1765 case FIX_FLOOR_EXPR:
1766 case FIX_ROUND_EXPR:
1767 case TARGET_EXPR:
1768 return 14;
1770 case CALL_EXPR:
1771 case ARRAY_REF:
1772 case ARRAY_RANGE_REF:
1773 case COMPONENT_REF:
1774 return 15;
1776 /* Special expressions. */
1777 case MIN_EXPR:
1778 case MAX_EXPR:
1779 case ABS_EXPR:
1780 case REALPART_EXPR:
1781 case IMAGPART_EXPR:
1782 return 16;
1784 case SAVE_EXPR:
1785 case NON_LVALUE_EXPR:
1786 return op_prio (TREE_OPERAND (op, 0));
1788 default:
1789 /* Return an arbitrarily high precedence to avoid surrounding single
1790 VAR_DECLs in ()s. */
1791 return 9999;
1796 /* Return the symbol associated with operator OP. */
1798 static const char *
1799 op_symbol (tree op)
1801 gcc_assert (op);
1803 switch (TREE_CODE (op))
1805 case MODIFY_EXPR:
1806 return "=";
1808 case TRUTH_OR_EXPR:
1809 case TRUTH_ORIF_EXPR:
1810 return "||";
1812 case TRUTH_AND_EXPR:
1813 case TRUTH_ANDIF_EXPR:
1814 return "&&";
1816 case BIT_IOR_EXPR:
1817 return "|";
1819 case TRUTH_XOR_EXPR:
1820 case BIT_XOR_EXPR:
1821 return "^";
1823 case ADDR_EXPR:
1824 case BIT_AND_EXPR:
1825 return "&";
1827 case ORDERED_EXPR:
1828 return "ord";
1829 case UNORDERED_EXPR:
1830 return "unord";
1832 case EQ_EXPR:
1833 return "==";
1834 case UNEQ_EXPR:
1835 return "u==";
1837 case NE_EXPR:
1838 return "!=";
1840 case LT_EXPR:
1841 return "<";
1842 case UNLT_EXPR:
1843 return "u<";
1845 case LE_EXPR:
1846 return "<=";
1847 case UNLE_EXPR:
1848 return "u<=";
1850 case GT_EXPR:
1851 return ">";
1852 case UNGT_EXPR:
1853 return "u>";
1855 case GE_EXPR:
1856 return ">=";
1857 case UNGE_EXPR:
1858 return "u>=";
1860 case LTGT_EXPR:
1861 return "<>";
1863 case LSHIFT_EXPR:
1864 return "<<";
1866 case RSHIFT_EXPR:
1867 return ">>";
1869 case PLUS_EXPR:
1870 return "+";
1872 case NEGATE_EXPR:
1873 case MINUS_EXPR:
1874 return "-";
1876 case BIT_NOT_EXPR:
1877 return "~";
1879 case TRUTH_NOT_EXPR:
1880 return "!";
1882 case MULT_EXPR:
1883 case INDIRECT_REF:
1884 return "*";
1886 case ALIGN_INDIRECT_REF:
1887 return "A*";
1889 case MISALIGNED_INDIRECT_REF:
1890 return "M*";
1892 case TRUNC_DIV_EXPR:
1893 case RDIV_EXPR:
1894 return "/";
1896 case CEIL_DIV_EXPR:
1897 return "/[cl]";
1899 case FLOOR_DIV_EXPR:
1900 return "/[fl]";
1902 case ROUND_DIV_EXPR:
1903 return "/[rd]";
1905 case EXACT_DIV_EXPR:
1906 return "/[ex]";
1908 case TRUNC_MOD_EXPR:
1909 return "%";
1911 case CEIL_MOD_EXPR:
1912 return "%[cl]";
1914 case FLOOR_MOD_EXPR:
1915 return "%[fl]";
1917 case ROUND_MOD_EXPR:
1918 return "%[rd]";
1920 case PREDECREMENT_EXPR:
1921 return " --";
1923 case PREINCREMENT_EXPR:
1924 return " ++";
1926 case POSTDECREMENT_EXPR:
1927 return "-- ";
1929 case POSTINCREMENT_EXPR:
1930 return "++ ";
1932 default:
1933 return "<<< ??? >>>";
1937 /* Prints the name of a CALL_EXPR. */
1939 static void
1940 print_call_name (pretty_printer *buffer, tree node)
1942 tree op0;
1944 gcc_assert (TREE_CODE (node) == CALL_EXPR);
1946 op0 = TREE_OPERAND (node, 0);
1948 if (TREE_CODE (op0) == NON_LVALUE_EXPR)
1949 op0 = TREE_OPERAND (op0, 0);
1951 switch (TREE_CODE (op0))
1953 case VAR_DECL:
1954 case PARM_DECL:
1955 dump_function_name (buffer, op0);
1956 break;
1958 case ADDR_EXPR:
1959 case INDIRECT_REF:
1960 case NOP_EXPR:
1961 dump_generic_node (buffer, TREE_OPERAND (op0, 0), 0, 0, false);
1962 break;
1964 case COND_EXPR:
1965 pp_string (buffer, "(");
1966 dump_generic_node (buffer, TREE_OPERAND (op0, 0), 0, 0, false);
1967 pp_string (buffer, ") ? ");
1968 dump_generic_node (buffer, TREE_OPERAND (op0, 1), 0, 0, false);
1969 pp_string (buffer, " : ");
1970 dump_generic_node (buffer, TREE_OPERAND (op0, 2), 0, 0, false);
1971 break;
1973 case COMPONENT_REF:
1974 /* The function is a pointer contained in a structure. */
1975 if (TREE_CODE (TREE_OPERAND (op0, 0)) == INDIRECT_REF ||
1976 TREE_CODE (TREE_OPERAND (op0, 0)) == VAR_DECL)
1977 dump_function_name (buffer, TREE_OPERAND (op0, 1));
1978 else
1979 dump_generic_node (buffer, TREE_OPERAND (op0, 0), 0, 0, false);
1980 /* else
1981 We can have several levels of structures and a function
1982 pointer inside. This is not implemented yet... */
1983 /* NIY;*/
1984 break;
1986 case ARRAY_REF:
1987 if (TREE_CODE (TREE_OPERAND (op0, 0)) == VAR_DECL)
1988 dump_function_name (buffer, TREE_OPERAND (op0, 0));
1989 else
1990 dump_generic_node (buffer, op0, 0, 0, false);
1991 break;
1993 case SSA_NAME:
1994 case OBJ_TYPE_REF:
1995 dump_generic_node (buffer, op0, 0, 0, false);
1996 break;
1998 default:
1999 NIY;
2003 /* Parses the string STR and replaces new-lines by '\n', tabs by '\t', ... */
2005 static void
2006 pretty_print_string (pretty_printer *buffer, const char *str)
2008 if (str == NULL)
2009 return;
2011 while (*str)
2013 switch (str[0])
2015 case '\b':
2016 pp_string (buffer, "\\b");
2017 break;
2019 case '\f':
2020 pp_string (buffer, "\\f");
2021 break;
2023 case '\n':
2024 pp_string (buffer, "\\n");
2025 break;
2027 case '\r':
2028 pp_string (buffer, "\\r");
2029 break;
2031 case '\t':
2032 pp_string (buffer, "\\t");
2033 break;
2035 case '\v':
2036 pp_string (buffer, "\\v");
2037 break;
2039 case '\\':
2040 pp_string (buffer, "\\\\");
2041 break;
2043 case '\"':
2044 pp_string (buffer, "\\\"");
2045 break;
2047 case '\'':
2048 pp_string (buffer, "\\'");
2049 break;
2051 case '\0':
2052 pp_string (buffer, "\\0");
2053 break;
2055 case '\1':
2056 pp_string (buffer, "\\1");
2057 break;
2059 case '\2':
2060 pp_string (buffer, "\\2");
2061 break;
2063 case '\3':
2064 pp_string (buffer, "\\3");
2065 break;
2067 case '\4':
2068 pp_string (buffer, "\\4");
2069 break;
2071 case '\5':
2072 pp_string (buffer, "\\5");
2073 break;
2075 case '\6':
2076 pp_string (buffer, "\\6");
2077 break;
2079 case '\7':
2080 pp_string (buffer, "\\7");
2081 break;
2083 default:
2084 pp_character (buffer, str[0]);
2085 break;
2087 str++;
2091 static void
2092 maybe_init_pretty_print (FILE *file)
2094 if (!initialized)
2096 pp_construct (&buffer, /* prefix */NULL, /* line-width */0);
2097 pp_needs_newline (&buffer) = true;
2098 initialized = 1;
2101 buffer.buffer->stream = file;
2104 static void
2105 newline_and_indent (pretty_printer *buffer, int spc)
2107 pp_newline (buffer);
2108 INDENT (spc);
2111 static void
2112 dump_vops (pretty_printer *buffer, tree stmt, int spc, int flags)
2114 tree use, def;
2115 use_operand_p use_p;
2116 def_operand_p def_p;
2117 ssa_op_iter iter;
2119 FOR_EACH_SSA_MAYDEF_OPERAND (def_p, use_p, stmt, iter)
2121 pp_string (buffer, "# ");
2122 dump_generic_node (buffer, DEF_FROM_PTR (def_p),
2123 spc + 2, flags, false);
2124 pp_string (buffer, " = V_MAY_DEF <");
2125 dump_generic_node (buffer, USE_FROM_PTR (use_p),
2126 spc + 2, flags, false);
2127 pp_string (buffer, ">;");
2128 newline_and_indent (buffer, spc);
2131 FOR_EACH_SSA_TREE_OPERAND (def, stmt, iter, SSA_OP_VMUSTDEF)
2133 pp_string (buffer, "# V_MUST_DEF <");
2134 dump_generic_node (buffer, def, spc + 2, flags, false);
2135 pp_string (buffer, ">;");
2136 newline_and_indent (buffer, spc);
2139 FOR_EACH_SSA_TREE_OPERAND (use, stmt, iter, SSA_OP_VUSE)
2141 pp_string (buffer, "# VUSE <");
2142 dump_generic_node (buffer, use, spc + 2, flags, false);
2143 pp_string (buffer, ">;");
2144 newline_and_indent (buffer, spc);
2148 /* Dumps basic block BB to FILE with details described by FLAGS and
2149 indented by INDENT spaces. */
2151 void
2152 dump_generic_bb (FILE *file, basic_block bb, int indent, int flags)
2154 maybe_init_pretty_print (file);
2155 dumping_stmts = true;
2156 dump_generic_bb_buff (&buffer, bb, indent, flags);
2157 pp_flush (&buffer);
2160 /* Dumps header of basic block BB to buffer BUFFER indented by INDENT
2161 spaces and details described by flags. */
2163 static void
2164 dump_bb_header (pretty_printer *buffer, basic_block bb, int indent, int flags)
2166 edge e;
2167 tree stmt;
2168 edge_iterator ei;
2170 if (flags & TDF_BLOCKS)
2172 INDENT (indent);
2173 pp_string (buffer, "# BLOCK ");
2174 pp_decimal_int (buffer, bb->index);
2176 if (flags & TDF_LINENO)
2178 block_stmt_iterator bsi;
2180 for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
2181 if (get_lineno (bsi_stmt (bsi)) != -1)
2183 pp_string (buffer, ", starting at line ");
2184 pp_decimal_int (buffer, get_lineno (bsi_stmt (bsi)));
2185 break;
2188 newline_and_indent (buffer, indent);
2190 pp_string (buffer, "# PRED:");
2191 pp_write_text_to_stream (buffer);
2192 FOR_EACH_EDGE (e, ei, bb->preds)
2193 if (flags & TDF_SLIM)
2195 pp_string (buffer, " ");
2196 if (e->src == ENTRY_BLOCK_PTR)
2197 pp_string (buffer, "ENTRY");
2198 else
2199 pp_decimal_int (buffer, e->src->index);
2201 else
2202 dump_edge_info (buffer->buffer->stream, e, 0);
2203 pp_newline (buffer);
2205 else
2207 stmt = first_stmt (bb);
2208 if (!stmt || TREE_CODE (stmt) != LABEL_EXPR)
2210 INDENT (indent - 2);
2211 pp_string (buffer, "<bb ");
2212 pp_decimal_int (buffer, bb->index);
2213 pp_string (buffer, ">:");
2214 pp_newline (buffer);
2217 pp_write_text_to_stream (buffer);
2218 check_bb_profile (bb, buffer->buffer->stream);
2221 /* Dumps end of basic block BB to buffer BUFFER indented by INDENT
2222 spaces. */
2224 static void
2225 dump_bb_end (pretty_printer *buffer, basic_block bb, int indent, int flags)
2227 edge e;
2228 edge_iterator ei;
2230 INDENT (indent);
2231 pp_string (buffer, "# SUCC:");
2232 pp_write_text_to_stream (buffer);
2233 FOR_EACH_EDGE (e, ei, bb->succs)
2234 if (flags & TDF_SLIM)
2236 pp_string (buffer, " ");
2237 if (e->dest == EXIT_BLOCK_PTR)
2238 pp_string (buffer, "EXIT");
2239 else
2240 pp_decimal_int (buffer, e->dest->index);
2242 else
2243 dump_edge_info (buffer->buffer->stream, e, 1);
2244 pp_newline (buffer);
2247 /* Dumps phi nodes of basic block BB to buffer BUFFER with details described by
2248 FLAGS indented by INDENT spaces. */
2250 static void
2251 dump_phi_nodes (pretty_printer *buffer, basic_block bb, int indent, int flags)
2253 tree phi = phi_nodes (bb);
2254 if (!phi)
2255 return;
2257 for (; phi; phi = PHI_CHAIN (phi))
2259 if (is_gimple_reg (PHI_RESULT (phi)) || (flags & TDF_VOPS))
2261 INDENT (indent);
2262 pp_string (buffer, "# ");
2263 dump_generic_node (buffer, phi, indent, flags, false);
2264 pp_newline (buffer);
2269 /* Dump jump to basic block BB that is represented implicitly in the cfg
2270 to BUFFER. */
2272 static void
2273 pp_cfg_jump (pretty_printer *buffer, basic_block bb)
2275 tree stmt;
2277 stmt = first_stmt (bb);
2279 pp_string (buffer, "goto <bb ");
2280 pp_decimal_int (buffer, bb->index);
2281 pp_string (buffer, ">");
2282 if (stmt && TREE_CODE (stmt) == LABEL_EXPR)
2284 pp_string (buffer, " (");
2285 dump_generic_node (buffer, LABEL_EXPR_LABEL (stmt), 0, 0, false);
2286 pp_string (buffer, ")");
2288 pp_semicolon (buffer);
2291 /* Dump edges represented implicitly in basic block BB to BUFFER, indented
2292 by INDENT spaces, with details given by FLAGS. */
2294 static void
2295 dump_implicit_edges (pretty_printer *buffer, basic_block bb, int indent,
2296 int flags)
2298 edge e;
2299 edge_iterator ei;
2301 /* If there is a fallthru edge, we may need to add an artificial goto to the
2302 dump. */
2303 FOR_EACH_EDGE (e, ei, bb->succs)
2304 if (e->flags & EDGE_FALLTHRU)
2305 break;
2306 if (e && e->dest != bb->next_bb)
2308 INDENT (indent);
2310 if ((flags & TDF_LINENO)
2311 #ifdef USE_MAPPED_LOCATION
2312 && e->goto_locus != UNKNOWN_LOCATION
2313 #else
2314 && e->goto_locus
2315 #endif
2318 expanded_location goto_xloc;
2319 #ifdef USE_MAPPED_LOCATION
2320 goto_xloc = expand_location (e->goto_locus);
2321 #else
2322 goto_xloc = *e->goto_locus;
2323 #endif
2324 pp_character (buffer, '[');
2325 if (goto_xloc.file)
2327 pp_string (buffer, goto_xloc.file);
2328 pp_string (buffer, " : ");
2330 pp_decimal_int (buffer, goto_xloc.line);
2331 pp_string (buffer, "] ");
2334 pp_cfg_jump (buffer, e->dest);
2335 pp_newline (buffer);
2339 /* Dumps basic block BB to buffer BUFFER with details described by FLAGS and
2340 indented by INDENT spaces. */
2342 static void
2343 dump_generic_bb_buff (pretty_printer *buffer, basic_block bb,
2344 int indent, int flags)
2346 block_stmt_iterator bsi;
2347 tree stmt;
2348 int label_indent = indent - 2;
2350 if (label_indent < 0)
2351 label_indent = 0;
2353 dump_bb_header (buffer, bb, indent, flags);
2355 if (bb_ann (bb))
2356 dump_phi_nodes (buffer, bb, indent, flags);
2358 for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
2360 int curr_indent;
2362 stmt = bsi_stmt (bsi);
2364 curr_indent = TREE_CODE (stmt) == LABEL_EXPR ? label_indent : indent;
2366 INDENT (curr_indent);
2367 dump_generic_node (buffer, stmt, curr_indent, flags, true);
2368 pp_newline (buffer);
2371 dump_implicit_edges (buffer, bb, indent, flags);
2373 if (flags & TDF_BLOCKS)
2374 dump_bb_end (buffer, bb, indent, flags);