xfail scan-tree-dump-not throw in g++.dg/pr99966.C on hppa*64*-*-*
[official-gcc.git] / gcc / m2 / m2pp.cc
blob2f4c45ced1419a5233b4509ad59bc16cfcb2e8c2
1 /* m2pp.c pretty print trees, output in Modula-2 where possible.
3 Copyright (C) 2007-2024 Free Software Foundation, Inc.
4 Contributed by Gaius Mulley <gaius@glam.ac.uk>.
6 This file is part of GNU Modula-2.
8 GNU Modula-2 is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
13 GNU Modula-2 is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Modula-2; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 #if defined(GM2)
23 #include "gm2-gcc/gcc-consolidation.h"
25 #include "m2-tree.h"
26 #include "gm2-lang.h"
28 #include "gm2-gcc/m2tree.h"
29 #include "gm2-gcc/m2expr.h"
30 #include "gm2-gcc/m2type.h"
31 #include "gm2-gcc/m2decl.h"
32 #else
33 #include "config.h"
34 #include "system.h"
35 #include "coretypes.h"
36 #include "cp/cp-tree.h"
37 #include "stringpool.h"
38 #include "gm2-gcc/gcc-consolidation.h"
39 #include "../cp/cp-tree.h"
40 #endif
42 #define M2PP_C
43 #include "m2/m2pp.h"
45 namespace modula2 {
47 #undef DEBUGGING
49 typedef struct pretty_t
51 int needs_space;
52 int needs_indent;
53 int curpos;
54 int indent;
55 int issued_begin;
56 int in_vars;
57 int in_types;
58 tree block;
59 int bits;
60 } pretty;
62 typedef struct m2stack_t
64 tree value;
65 struct m2stack_t *next;
66 } stack;
68 /* Prototypes. */
70 static pretty *initPretty (int bits);
71 static pretty *dupPretty (pretty *s);
72 static int getindent (pretty *s);
73 static void setindent (pretty *s, int n);
74 static int getcurpos (pretty *s);
75 static void m2pp_identifier (pretty *s, tree t);
76 static void m2pp_needspace (pretty *s);
77 static void m2pp_function (pretty *s, tree t);
78 static void m2pp_function_header (pretty *s, tree t);
79 static void m2pp_function_vars (pretty *s, tree t);
80 static void m2pp_statement_sequence (pretty *s, tree t);
81 static void m2pp_print (pretty *s, const char *p);
82 static void m2pp_print_char (pretty *s, char ch);
83 static void m2pp_parameter (pretty *s, tree t);
84 static void m2pp_type (pretty *s, tree t);
85 static void m2pp_ident_pointer (pretty *s, tree t);
86 static void m2pp_set_type (pretty *s, tree t);
87 static void m2pp_enum (pretty *s, tree t);
88 static void m2pp_array (pretty *s, tree t);
89 static void m2pp_subrange (pretty *s, tree t);
90 static void m2pp_gimpified (pretty *s, tree t);
91 static void m2pp_pointer_type (pretty *s, tree t);
92 static void m2pp_record_type (pretty *s, tree t);
93 static void m2pp_union_type (pretty *s, tree t);
94 static void m2pp_simple_type (pretty *s, tree t);
95 static void m2pp_expression (pretty *s, tree t);
96 static void m2pp_relop (pretty *s, tree t, const char *p);
97 static void m2pp_simple_expression (pretty *s, tree t);
98 static void m2pp_statement_sequence (pretty *s, tree t);
99 static void m2pp_unknown (pretty *s, const char *s1, const char *s2);
100 static void m2pp_statement (pretty *s, tree t);
101 static void m2pp_assignment (pretty *s, tree t);
102 static void m2pp_designator (pretty *s, tree t);
103 static void m2pp_conditional (pretty *s, tree t);
104 static void m2pp_label_expr (pretty *s, tree t);
105 static void m2pp_label_decl (pretty *s, tree t);
106 static void m2pp_goto (pretty *s, tree t);
107 static void m2pp_list (pretty *s, tree t);
108 static void m2pp_offset (pretty *s, tree t);
109 static void m2pp_indirect_ref (pretty *s, tree t);
110 static void m2pp_integer_cst (pretty *s, tree t);
111 static void m2pp_real_cst (pretty *s, tree t);
112 static void m2pp_string_cst (pretty *s, tree t);
113 static void m2pp_integer (pretty *s, tree t);
114 static void m2pp_addr_expr (pretty *s, tree t);
115 static void m2pp_nop (pretty *s, tree t);
116 static void m2pp_convert (pretty *s, tree t);
117 static void m2pp_var_decl (pretty *s, tree t);
118 static void m2pp_binary (pretty *s, tree t, const char *p);
119 static void m2pp_unary (pretty *s, tree t, const char *p);
120 static void m2pp_call_expr (pretty *s, tree t);
121 static void m2pp_procedure_call (pretty *s, tree t);
122 static void m2pp_ssa (pretty *s, tree t);
123 static void m2pp_block (pretty *s, tree t);
124 static void m2pp_block_list (pretty *s, tree t);
125 static void m2pp_var_list (pretty *s, tree t);
126 static void m2pp_bind_expr (pretty *s, tree t);
127 static void m2pp_return_expr (pretty *s, tree t);
128 static void m2pp_result_decl (pretty *s, tree t);
129 static void m2pp_try_block (pretty *s, tree t);
130 static void m2pp_cleanup_point_expr (pretty *s, tree t);
131 static void m2pp_handler (pretty *s, tree t);
132 static void m2pp_component_ref (pretty *s, tree t);
133 static void m2pp_array_ref (pretty *s, tree t);
134 static void m2pp_begin (pretty *s);
135 static void m2pp_var (pretty *s);
136 static void m2pp_types (pretty *s);
137 static void m2pp_decl_expr (pretty *s, tree t);
138 static void m2pp_var_type_decl (pretty *s, tree t);
139 static void m2pp_non_lvalue_expr (pretty *s, tree t);
140 static void m2pp_procedure_type (pretty *s, tree t);
141 static void m2pp_param_type (pretty *s, tree t);
142 static void m2pp_type_lowlevel (pretty *s, tree t);
143 static void m2pp_try_catch_expr (pretty *s, tree t);
144 static void m2pp_throw (pretty *s, tree t);
145 static void m2pp_catch_expr (pretty *s, tree t);
146 static void m2pp_try_finally_expr (pretty *s, tree t);
147 static void m2pp_complex (pretty *s, tree t);
148 static void killPretty (pretty *s);
149 static void m2pp_compound_expression (pretty *s, tree t);
150 static void m2pp_target_expression (pretty *s, tree t);
151 static void m2pp_constructor (pretty *s, tree t);
152 static void m2pp_translation (pretty *s, tree t);
153 static void m2pp_module_block (pretty *s, tree t);
154 static void push (tree t);
155 static void pop (void);
156 static int begin_printed (tree t);
157 static void m2pp_decl_list (pretty *s, tree t);
158 static void m2pp_loc (pretty *s, tree t);
160 void pet (tree t);
161 void m2pp_integer (pretty *s, tree t);
163 extern void stop (void);
165 static stack *stackPtr = NULL;
167 /* do_pf helper function for pf. */
169 void
170 do_pf (tree t, int bits)
172 pretty *state = initPretty (bits);
174 if (TREE_CODE (t) == TRANSLATION_UNIT_DECL)
175 m2pp_translation (state, t);
176 else if (TREE_CODE (t) == BLOCK)
177 m2pp_module_block (state, t);
178 else if (TREE_CODE (t) == FUNCTION_DECL)
179 m2pp_function (state, t);
180 else
181 m2pp_statement_sequence (state, t);
182 killPretty (state);
185 /* pf print function. Expected to be printed interactively from
186 the debugger: print modula2::pf(func), or to be called from code. */
188 void
189 pf (tree t)
191 do_pf (t, FALSE);
194 /* pe print expression. Expected to be printed interactively from
195 the debugger: print modula2::pe(expr), or to be called from code. */
197 void
198 pe (tree t)
200 pretty *state = initPretty (FALSE);
202 m2pp_expression (state, t);
203 m2pp_needspace (state);
204 m2pp_print (state, ";\n");
205 killPretty (state);
208 /* pet print expression and its type. Expected to be printed
209 interactively from the debugger: print modula2::pet(expr), or to
210 be called from code. */
212 void
213 pet (tree t)
215 pretty *state = initPretty (FALSE);
217 m2pp_expression (state, t);
218 m2pp_needspace (state);
219 m2pp_print (state, ":");
220 m2pp_type (state, TREE_TYPE (t));
221 m2pp_print (state, ";\n");
222 killPretty (state);
225 /* pt print type. Expected to be printed interactively from the
226 debugger: print pt(expr), or to be called from code. */
228 void
229 pt (tree t)
231 pretty *state = initPretty (FALSE);
232 m2pp_type (state, t);
233 m2pp_needspace (state);
234 m2pp_print (state, ";\n");
235 killPretty (state);
238 /* ptl print type low level. Expected to be printed interactively
239 from the debugger: print ptl(type), or to be called from code. */
241 void
242 ptl (tree t)
244 pretty *state = initPretty (FALSE);
245 m2pp_type_lowlevel (state, t);
246 m2pp_needspace (state);
247 m2pp_print (state, ";\n");
248 killPretty (state);
251 /* ptcl print TREE_CHAINed list. */
253 void
254 ptcl (tree t)
256 pretty *state = initPretty (FALSE);
258 m2pp_decl_list (state, t);
259 m2pp_print (state, "\n");
260 killPretty (state);
263 /* loc if tree has a location then display it within a comment. */
265 static void
266 m2pp_loc (pretty *s, tree t)
268 if (CAN_HAVE_LOCATION_P (t))
270 if (EXPR_HAS_LOCATION (t))
272 if (EXPR_LOCATION (t) == UNKNOWN_LOCATION)
273 m2pp_print (s, "(* missing location1 *)\n");
274 else
276 expanded_location l = expand_location (EXPR_LOCATION (t));
278 m2pp_print (s, "(* ");
279 m2pp_print (s, l.file);
280 m2pp_print (s, ":");
281 printf ("%d", l.line);
282 m2pp_print (s, " *)");
283 m2pp_print (s, "\n");
286 else
288 m2pp_print (s, "(* missing location2 *)\n");
293 /* m2pp_decl_list prints a TREE_CHAINed list for a decl node. */
295 static void
296 m2pp_decl_list (pretty *s, tree t)
298 tree u = t;
300 m2pp_print (s, "(");
301 m2pp_needspace (s);
302 while (t != NULL_TREE)
304 m2pp_identifier (s, t);
305 t = TREE_CHAIN (t);
306 if (t == u || t == NULL_TREE)
307 break;
308 m2pp_print (s, ",");
309 m2pp_needspace (s);
311 m2pp_needspace (s);
312 m2pp_print (s, ")");
315 static void
316 m2pp_decl_bool (pretty *s, tree t)
318 if (TREE_STATIC (t))
319 m2pp_print (s, "static, ");
320 if (DECL_EXTERNAL (t))
321 m2pp_print (s, "external, ");
322 if (DECL_SEEN_IN_BIND_EXPR_P (t))
323 m2pp_print (s, "in bind expr, ");
326 void
327 pv (tree t)
329 if (t)
331 enum tree_code code = TREE_CODE (t);
333 if (code == PARM_DECL)
335 pretty *state = initPretty (FALSE);
336 m2pp_identifier (state, t);
337 m2pp_needspace (state);
338 m2pp_print (state, "<parm_decl context = ");
339 m2pp_identifier (state, DECL_CONTEXT (t));
340 if (DECL_ABSTRACT_ORIGIN (t) == t)
341 m2pp_print (state, ">\n");
342 else
344 m2pp_print (state, ", abstract origin = ");
345 m2pp_identifier (state, DECL_ABSTRACT_ORIGIN (t));
346 m2pp_print (state, ">\n");
347 modula2::pv (DECL_ABSTRACT_ORIGIN (t));
349 killPretty (state);
351 if (code == VAR_DECL)
353 pretty *state = initPretty (FALSE);
354 m2pp_identifier (state, t);
355 m2pp_needspace (state);
356 m2pp_print (state, "(* <var_decl context = ");
357 m2pp_identifier (state, DECL_CONTEXT (t));
358 m2pp_decl_bool (state, t);
359 if (DECL_ABSTRACT_ORIGIN (t) == t)
360 m2pp_print (state, "> *)\n");
361 else
363 m2pp_print (state, ", abstract origin = ");
364 m2pp_identifier (state, DECL_ABSTRACT_ORIGIN (t));
365 m2pp_print (state, "> *)\n");
366 modula2::pv (DECL_ABSTRACT_ORIGIN (t));
368 killPretty (state);
373 #if defined(GM2_MAINTAINER)
375 /* remember an internal debugging hook. */
376 static tree rememberF = NULL;
378 static void
379 remember (tree t)
381 rememberF = t;
382 printf ("type: watch *((tree *) %p) != %p\n", (void *)&DECL_SAVED_TREE (t),
383 (void *)DECL_SAVED_TREE (t));
385 #endif
387 /* push pushes tree t onto stack. */
389 static void
390 push (tree t)
392 stack *s = (stack *)xmalloc (sizeof (stack));
394 s->value = t;
395 s->next = stackPtr;
396 stackPtr = s;
399 /* pop pops a tree, from the stack. */
401 static void
402 pop (void)
404 stack *s = stackPtr;
406 stackPtr = stackPtr->next;
407 free (s);
410 /* being_printed returns TRUE if t is held on the stack. */
412 static int
413 begin_printed (tree t)
415 stack *s = stackPtr;
417 while (s != NULL)
419 if (s->value == t)
420 return TRUE;
421 else
422 s = s->next;
424 return FALSE;
427 /* dupPretty duplicate and return a copy of state s. */
429 static pretty *
430 dupPretty (pretty *s)
432 pretty *p = initPretty (s->bits);
433 *p = *s;
434 return p;
437 /* initPretty initialise the state of the pretty printer. */
439 static pretty *
440 initPretty (int bits)
442 pretty *state = (pretty *)xmalloc (sizeof (pretty));
443 state->needs_space = FALSE;
444 state->needs_indent = FALSE;
445 state->curpos = 0;
446 state->indent = 0;
447 state->issued_begin = FALSE;
448 state->in_vars = FALSE;
449 state->in_types = FALSE;
450 state->block = NULL_TREE;
451 state->bits = bits;
452 return state;
455 /* killPretty cleans up the state. */
457 static void
458 killPretty (pretty *s)
460 free (s);
461 fflush (stdout);
464 /* getindent returns the current indent value. */
466 static int
467 getindent (pretty *s)
469 return s->indent;
472 /* setindent sets the current indent to, n. */
474 static void
475 setindent (pretty *s, int n)
477 s->indent = n;
480 /* getcurpos returns the current cursor position. */
482 static int
483 getcurpos (pretty *s)
485 if (s->needs_space)
486 return s->curpos + 1;
487 else
488 return s->curpos;
491 /* m2pp_type_lowlevel prints out the low level details of a
492 fundamental type. */
494 static void
495 m2pp_type_lowlevel (pretty *s, tree t)
497 if (TREE_CODE (t) == INTEGER_TYPE)
499 m2pp_print (s, "min");
500 m2pp_needspace (s);
501 m2pp_integer_cst (s, TYPE_MIN_VALUE (t));
502 m2pp_print (s, ", max");
503 m2pp_needspace (s);
504 m2pp_integer_cst (s, TYPE_MAX_VALUE (t));
505 m2pp_print (s, ", type size unit");
506 m2pp_needspace (s);
507 m2pp_integer_cst (s, TYPE_SIZE_UNIT (t));
508 m2pp_print (s, ", type size");
509 m2pp_needspace (s);
510 m2pp_integer_cst (s, TYPE_SIZE (t));
512 printf (", precision %d, mode %d, align %d, user align %d",
513 TYPE_PRECISION (t), TYPE_MODE (t), TYPE_ALIGN (t),
514 TYPE_USER_ALIGN (t));
516 m2pp_needspace (s);
517 if (TYPE_UNSIGNED (t))
518 m2pp_print (s, "unsigned\n");
519 else
520 m2pp_print (s, "signed\n");
524 /* m2pp_var emit a VAR if necessary. */
526 static void
527 m2pp_var (pretty *s)
529 if (!s->in_vars)
531 s->in_vars = TRUE;
532 m2pp_print (s, "VAR\n");
533 setindent (s, getindent (s) + 3);
537 /* m2pp_types emit a TYPE if necessary. */
539 static void
540 m2pp_types (pretty *s)
542 if (!s->in_types)
544 s->in_types = TRUE;
545 m2pp_print (s, "TYPE\n");
546 setindent (s, getindent (s) + 3);
550 #ifdef DEBUGGING
551 /* hextree displays the critical fields for function, block and
552 bind_expr trees in raw hex. */
554 static void
555 hextree (tree t)
557 if (t == NULL_TREE)
558 return;
560 if (TREE_CODE (t) == BLOCK)
562 printf ("(* BLOCK %p *)\n", (void *)t);
563 printf ("BLOCK_VARS (t) = %p\n", (void *)BLOCK_VARS (t));
564 printf ("BLOCK_SUPERCONTEXT (t) = %p\n",
565 (void *)BLOCK_SUPERCONTEXT (t));
567 if (TREE_CODE (t) == BIND_EXPR)
569 printf ("(* BIND_EXPR %p *)\n", (void *)t);
570 printf ("BIND_EXPR_VARS (t) = %p\n", (void *)BIND_EXPR_VARS (t));
571 printf ("BIND_EXPR_BLOCK (t) = %p\n", (void *)BIND_EXPR_BLOCK (t));
572 printf ("BIND_EXPR_BODY (t) = %p\n", (void *)BIND_EXPR_BODY (t));
574 if (TREE_CODE (t) == FUNCTION_DECL)
576 printf ("(* FUNCTION_DECL %p *)\n", (void *)t);
577 printf ("DECL_INITIAL (t) = %p\n", (void *)DECL_INITIAL (t));
578 printf ("DECL_SAVED_TREE (t) = %p\n", (void *)DECL_SAVED_TREE (t));
579 hextree (DECL_INITIAL (t));
580 hextree (DECL_SAVED_TREE (t));
582 if (VAR_P (t))
584 pretty *state = initPretty (FALSE);
586 printf ("(* VAR_DECL %p <", (void *)t);
587 if (DECL_SEEN_IN_BIND_EXPR_P (t))
588 printf ("b");
589 if (DECL_EXTERNAL (t))
590 printf ("e");
591 if (TREE_STATIC (t))
592 printf ("s");
593 printf ("> context = %p*)\n", (void *)decl_function_context (t));
594 m2pp_type (state, TREE_TYPE (t));
595 m2pp_needspace (state);
596 m2pp_print (state, ";\n");
597 killPretty (state);
599 if (TREE_CODE (t) == PARM_DECL)
601 pretty *state = initPretty (FALSE);
603 printf ("(* PARM_DECL %p <", (void *)t);
604 printf ("> context = %p*)\n", (void *)decl_function_context (t));
605 m2pp_type (state, TREE_TYPE (t));
606 m2pp_needspace (state);
607 m2pp_print (state, ";\n");
608 killPretty (state);
611 #endif
613 /* translation produce a pseudo implementation module from the tree t. */
615 static void
616 m2pp_translation (pretty *s, tree t)
618 tree block = DECL_INITIAL (t);
620 m2pp_print (s, "IMPLEMENTATION MODULE ");
621 m2pp_identifier (s, t);
622 m2pp_print (s, "\n\n");
624 if (block != NULL)
626 m2pp_module_block (s, block);
627 m2pp_print (s, "\n");
630 m2pp_print (s, "\n");
631 m2pp_print (s, "END ");
632 m2pp_identifier (s, t);
633 m2pp_print (s, ".\n");
636 static void
637 m2pp_module_block (pretty *s, tree t)
639 t = BLOCK_VARS (t);
641 if (t != NULL_TREE)
642 for (; t != NULL_TREE; t = TREE_CHAIN (t))
644 switch (TREE_CODE (t))
646 case FUNCTION_DECL:
647 if (!DECL_EXTERNAL (t))
649 pretty *p = dupPretty (s);
650 printf ("\n");
651 p->in_vars = FALSE;
652 p->in_types = FALSE;
653 m2pp_function (p, t);
654 killPretty (p);
655 printf ("\n");
656 s->in_vars = FALSE;
657 s->in_types = FALSE;
659 break;
661 case TYPE_DECL:
663 int o = getindent (s);
664 int p;
666 m2pp_print (s, "\n");
667 m2pp_types (s);
668 setindent (s, o + 3);
669 m2pp_identifier (s, t);
670 m2pp_print (s, " = ");
671 p = getcurpos (s);
672 setindent (s, p);
673 m2pp_type (s, TREE_TYPE (t));
674 setindent (s, o);
675 m2pp_needspace (s);
676 m2pp_print (s, ";\n");
677 s->in_vars = FALSE;
679 break;
681 case VAR_DECL:
682 m2pp_var (s);
683 m2pp_identifier (s, t);
684 m2pp_needspace (s);
685 m2pp_print (s, ":");
686 m2pp_needspace (s);
687 m2pp_type (s, TREE_TYPE (t));
688 m2pp_needspace (s);
689 m2pp_print (s, ";\n");
690 s->in_types = FALSE;
691 break;
693 case DECL_EXPR:
694 printf ("is this node legal here? \n");
695 m2pp_decl_expr (s, t);
696 break;
698 default:
699 m2pp_unknown (s, __FUNCTION__, get_tree_code_name (TREE_CODE (t)));
704 /* m2pp_begin emit a BEGIN if necessary. */
706 static void
707 m2pp_begin (pretty *s)
709 if (!s->issued_begin)
711 if (s->in_vars || s->in_types)
713 setindent (s, getindent (s) - 3);
714 m2pp_print (s, "BEGIN\n");
715 setindent (s, getindent (s) + 3);
717 else
719 m2pp_print (s, "BEGIN\n");
720 setindent (s, getindent (s) + 3);
722 s->issued_begin = TRUE;
723 s->in_vars = FALSE;
724 s->in_types = FALSE;
728 /* m2pp_function walk over the function. */
730 static void
731 m2pp_function (pretty *s, tree t)
733 m2pp_function_header (s, t);
734 m2pp_function_vars (s, t);
735 m2pp_statement_sequence (s, DECL_SAVED_TREE (t));
736 if (TREE_CODE (t) == FUNCTION_DECL)
738 m2pp_begin (s);
739 setindent (s, getindent (s) - 3);
740 m2pp_print (s, "END");
741 m2pp_needspace (s);
742 m2pp_identifier (s, t);
743 m2pp_needspace (s);
744 m2pp_print (s, ";\n");
748 /* m2pp_bind_expr displays the bind expr tree node. */
750 static void
751 m2pp_bind_expr (pretty *s, tree t)
753 if (TREE_CODE (t) == BIND_EXPR)
755 if (BIND_EXPR_VARS (t))
757 m2pp_print (s, "(* variables in bind_expr *)\n");
758 m2pp_var (s);
759 m2pp_var_list (s, BIND_EXPR_VARS (t));
761 if (BIND_EXPR_BLOCK (t))
763 m2pp_print (s, "(* bind_expr_block *)\n");
764 m2pp_statement_sequence (s, BIND_EXPR_BLOCK (t));
765 m2pp_needspace (s);
766 m2pp_print (s, "; \n");
768 m2pp_statement_sequence (s, BIND_EXPR_BODY (t));
772 /* m2pp_block_list iterates over the list of blocks. */
774 static void
775 m2pp_block_list (pretty *s, tree t)
777 for (; t; t = BLOCK_CHAIN (t))
778 m2pp_block (s, t);
781 /* m2pp_block prints the VARiables and the TYPEs inside a block. */
783 static void
784 m2pp_block (pretty *s, tree t)
786 if ((BLOCK_VARS (t) != NULL_TREE) && (s->block != BLOCK_VARS (t)))
788 s->block = BLOCK_VARS (t);
789 m2pp_print (s, "(* block variables *)\n");
790 m2pp_var (s);
791 m2pp_var_list (s, BLOCK_VARS (t));
795 /* m2pp_var_type_decl displays the variable and type declaration. */
797 static void
798 m2pp_var_type_decl (pretty *s, tree t)
800 m2pp_identifier (s, t);
801 m2pp_needspace (s);
802 m2pp_print (s, ":");
803 m2pp_needspace (s);
804 m2pp_type (s, TREE_TYPE (t));
805 m2pp_needspace (s);
806 m2pp_print (s, ";\n");
809 /* m2pp_var_list print a variable list. */
811 static void
812 m2pp_var_list (pretty *s, tree t)
814 if (t != NULL_TREE)
815 for (; t; t = TREE_CHAIN (t))
817 if (TREE_CODE (t) == FUNCTION_DECL)
819 pretty *p = dupPretty (s);
820 printf ("\n");
821 p->in_vars = FALSE;
822 p->in_types = FALSE;
823 m2pp_function (p, t);
824 killPretty (p);
825 printf ("\n");
827 else if (TREE_CODE (t) == TYPE_DECL)
828 m2pp_identifier (s, t);
829 else if (TREE_CODE (t) == DECL_EXPR)
831 printf ("is this node legal here? \n");
832 // is it legal to have a DECL_EXPR here ?
833 m2pp_var_type_decl (s, DECL_EXPR_DECL (t));
835 else
836 m2pp_var_type_decl (s, t);
840 #if 0
841 /* m2pp_type_list print a variable list. */
843 static void
844 m2pp_type_list (pretty *s, tree t)
846 if (t != NULL_TREE)
847 for (; t; t = TREE_CHAIN (t))
849 m2pp_identifier (s, t);
850 m2pp_needspace (s);
851 m2pp_print (s, "=");
852 m2pp_needspace (s);
853 m2pp_type (s, TREE_TYPE (t));
854 m2pp_needspace (s);
855 m2pp_print (s, ";\n");
858 #endif
860 /* m2pp_needspace sets appropriate flag to TRUE. */
862 static void
863 m2pp_needspace (pretty *s)
865 s->needs_space = TRUE;
868 /* m2pp_identifer prints an identifier. */
870 static void
871 m2pp_identifier (pretty *s, tree t)
873 if (t)
875 if (TREE_CODE (t) == COMPONENT_REF)
876 m2pp_component_ref (s, t);
877 else if (DECL_NAME (t) && IDENTIFIER_POINTER (DECL_NAME (t)))
878 m2pp_ident_pointer (s, DECL_NAME (t));
879 else
881 char name[100];
883 if (TREE_CODE (t) == CONST_DECL)
884 snprintf (name, 100, "C_%u", DECL_UID (t));
885 else
886 snprintf (name, 100, "D_%u", DECL_UID (t));
887 m2pp_print (s, name);
892 /* m2pp_ident_pointer displays an ident pointer. */
894 static void
895 m2pp_ident_pointer (pretty *s, tree t)
897 if (t)
898 m2pp_print (s, IDENTIFIER_POINTER (t));
901 /* m2pp_parameter prints out a param decl tree. */
903 static void
904 m2pp_parameter (pretty *s, tree t)
906 if (TREE_CODE (t) == PARM_DECL)
908 if (TREE_TYPE (t) && (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE))
910 m2pp_print (s, "VAR");
911 m2pp_needspace (s);
912 m2pp_identifier (s, t);
913 m2pp_print (s, ":");
914 m2pp_needspace (s);
915 m2pp_simple_type (s, TREE_TYPE (TREE_TYPE (t)));
917 else
919 m2pp_identifier (s, t);
920 m2pp_print (s, ":");
921 m2pp_needspace (s);
922 m2pp_simple_type (s, TREE_TYPE (t));
927 /* m2pp_param_type prints out the type of parameter. */
929 static void
930 m2pp_param_type (pretty *s, tree t)
932 if (t && (TREE_CODE (t) == REFERENCE_TYPE))
934 m2pp_print (s, "VAR");
935 m2pp_needspace (s);
936 m2pp_simple_type (s, TREE_TYPE (t));
938 else
939 m2pp_simple_type (s, t);
942 /* m2pp_procedure_type displays a procedure type. */
944 static void
945 m2pp_procedure_type (pretty *s, tree t)
947 push (t);
948 if (TREE_CODE (t) == FUNCTION_TYPE)
950 tree i = TYPE_ARG_TYPES (t);
951 tree returnType = TREE_TYPE (TREE_TYPE (t));
953 m2pp_needspace (s);
954 m2pp_print (s, "PROCEDURE");
955 m2pp_needspace (s);
956 if (i != NULL_TREE)
958 int o = getindent (s);
959 int p;
960 int first = TRUE;
962 m2pp_print (s, "(");
963 p = getcurpos (s);
964 setindent (s, p);
965 while (i != NULL_TREE)
967 if (TREE_CHAIN (i) == NULL_TREE)
969 if (TREE_VALUE (i) == void_type_node)
970 /* Ignore void_type_node at the end. */
972 else
974 m2pp_param_type (s, TREE_VALUE (i));
975 m2pp_print (s, ", ...");
977 break;
979 else
981 if (!first)
983 m2pp_print (s, ",");
984 m2pp_needspace (s);
986 m2pp_param_type (s, TREE_VALUE (i));
988 i = TREE_CHAIN (i);
989 first = FALSE;
991 m2pp_print (s, ")");
992 setindent (s, o);
994 else if (returnType != NULL_TREE)
996 m2pp_needspace (s);
997 m2pp_print (s, "()");
999 if (returnType != NULL_TREE)
1001 m2pp_needspace (s);
1002 m2pp_print (s, ": ");
1003 m2pp_simple_type (s, returnType);
1006 pop ();
1009 /* m2pp_comment_header displays a simple header with some critical
1010 tree info. */
1012 static void
1013 m2pp_comment_header (pretty *s, tree t)
1015 int o = getindent (s);
1017 m2pp_print (s, "(*\n");
1018 setindent (s, o + 3);
1019 m2pp_identifier (s, t);
1020 m2pp_needspace (s);
1021 m2pp_print (s, "-");
1022 m2pp_needspace (s);
1023 if (TREE_PUBLIC (t))
1025 m2pp_needspace (s);
1026 m2pp_print (s, "public,");
1028 if (TREE_STATIC (t))
1030 m2pp_needspace (s);
1031 m2pp_print (s, "static,");
1033 if (DECL_EXTERNAL (t))
1035 m2pp_needspace (s);
1036 m2pp_print (s, "extern");
1038 m2pp_print (s, "\n");
1039 setindent (s, o);
1040 m2pp_print (s, "*)\n\n");
1043 /* m2pp_function_header displays the function header. */
1045 static void
1046 m2pp_function_header (pretty *s, tree t)
1048 push (t);
1049 if (TREE_CODE (t) == FUNCTION_DECL)
1051 tree i = DECL_ARGUMENTS (t);
1052 tree returnType = TREE_TYPE (TREE_TYPE (t));
1054 m2pp_comment_header (s, t);
1055 m2pp_print (s, "PROCEDURE ");
1056 m2pp_identifier (s, t);
1057 m2pp_needspace (s);
1058 if (i != NULL_TREE)
1060 int o = getindent (s);
1061 int p;
1063 m2pp_print (s, "(");
1064 p = getcurpos (s);
1065 setindent (s, p);
1066 while (i != NULL_TREE)
1068 m2pp_parameter (s, i);
1069 i = TREE_CHAIN (i);
1070 if (i != NULL_TREE)
1071 m2pp_print (s, ";\n");
1073 m2pp_print (s, ")");
1074 m2pp_needspace (s);
1075 setindent (s, o);
1077 else if (returnType != void_type_node)
1079 m2pp_print (s, "()");
1080 m2pp_needspace (s);
1082 if (returnType != void_type_node)
1084 m2pp_print (s, ": ");
1085 m2pp_simple_type (s, returnType);
1086 m2pp_needspace (s);
1088 m2pp_print (s, "; ");
1089 m2pp_loc (s, t);
1090 m2pp_print (s, "\n");
1092 pop ();
1095 /* m2pp_add_var adds a variable into a list as defined by, data. */
1097 static tree
1098 m2pp_add_var (tree *tp, int *walk_subtrees, void *data)
1100 tree t = *tp;
1101 pretty *s = (pretty *)data;
1102 enum tree_code code = TREE_CODE (t);
1104 if (code == VAR_DECL)
1106 m2pp_var (s);
1107 m2pp_identifier (s, t);
1108 m2pp_needspace (s);
1109 m2pp_print (s, ":");
1110 m2pp_needspace (s);
1111 m2pp_type (s, TREE_TYPE (t));
1112 m2pp_needspace (s);
1113 m2pp_print (s, ";\n");
1115 if (code == SSA_NAME)
1117 m2pp_var (s);
1118 m2pp_ssa (s, t);
1119 m2pp_identifier (s, SSA_NAME_VAR (t));
1120 m2pp_needspace (s);
1121 m2pp_print (s, ":");
1122 m2pp_needspace (s);
1123 m2pp_type (s, TREE_TYPE (t));
1124 m2pp_needspace (s);
1125 m2pp_print (s, ";\n");
1128 *walk_subtrees = 1;
1129 return NULL_TREE;
1132 /* m2pp_function_vars displays variables as defined by the function
1133 tree. */
1135 static void
1136 m2pp_function_vars (pretty *s, tree t)
1138 walk_tree_without_duplicates (&t, m2pp_add_var, s);
1140 if (TREE_CODE (t) == FUNCTION_DECL && DECL_INITIAL (t))
1142 m2pp_print (s, "(* variables in function_decl (decl_initial) *)\n");
1143 m2pp_var (s);
1144 m2pp_statement_sequence (s, DECL_INITIAL (t));
1148 /* m2pp_print print out a string p interpreting '\n' and
1149 adjusting the fields within state s. */
1151 static void
1152 m2pp_print (pretty *s, const char *p)
1154 if (p)
1156 int l = strlen (p);
1157 int i = 0;
1159 if (s->needs_space)
1161 printf (" ");
1162 s->needs_space = FALSE;
1163 s->curpos++;
1166 while (i < l)
1168 if (p[i] == '\n')
1170 s->needs_indent = TRUE;
1171 s->curpos = 0;
1172 printf ("\n");
1174 else
1176 if (s->needs_indent)
1178 if (s->indent > 0)
1179 printf ("%*c", s->indent, ' ');
1180 s->needs_indent = FALSE;
1181 s->curpos += s->indent;
1183 s->curpos++;
1184 putchar (p[i]);
1186 i++;
1191 /* m2pp_print_char prints out a character ch obeying needs_space
1192 and needs_indent. */
1194 static void
1195 m2pp_print_char (pretty *s, char ch)
1197 if (s->needs_space)
1199 printf (" ");
1200 s->needs_space = FALSE;
1201 s->curpos++;
1203 if (s->needs_indent)
1205 if (s->indent > 0)
1206 printf ("%*c", s->indent, ' ');
1207 s->needs_indent = FALSE;
1208 s->curpos += s->indent;
1210 if (ch == '\n')
1212 s->curpos++;
1213 putchar ('\\');
1214 putchar ('n');
1216 else
1217 putchar (ch);
1218 s->curpos++;
1221 /* m2pp_integer display the appropriate integer type. */
1223 #if defined(GM2)
1224 void
1225 m2pp_integer (pretty *s, tree t)
1227 if (t == m2type_GetM2ZType ())
1228 m2pp_print (s, "M2ZTYPE");
1229 else if (t == m2type_GetM2LongIntType ())
1230 m2pp_print (s, "LONGINT");
1231 else if (t == m2type_GetM2IntegerType ())
1232 m2pp_print (s, "INTEGER");
1233 else if (t == m2type_GetM2ShortIntType ())
1234 m2pp_print (s, "SHORTINT");
1235 else if (t == m2type_GetLongIntType ())
1236 m2pp_print (s, "long int");
1237 else if (t == m2type_GetIntegerType ())
1238 m2pp_print (s, "int");
1239 else if (t == m2type_GetShortIntType ())
1240 m2pp_print (s, "short");
1241 else if (t == m2type_GetM2LongCardType ())
1242 m2pp_print (s, "LONGCARD");
1243 else if (t == m2type_GetM2CardinalType ())
1244 m2pp_print (s, "CARDINAL");
1245 else if (t == m2type_GetM2ShortCardType ())
1246 m2pp_print (s, "SHORTCARD");
1247 else if (t == m2type_GetCardinalType ())
1248 m2pp_print (s, "CARDINAL");
1249 else if (t == m2type_GetPointerType ())
1250 m2pp_print (s, "ADDRESS");
1251 else if (t == m2type_GetByteType ())
1252 m2pp_print (s, "BYTE");
1253 else if (t == m2type_GetCharType ())
1254 m2pp_print (s, "CHAR");
1255 else if (t == m2type_GetBitsetType ())
1256 m2pp_print (s, "BITSET");
1257 else if (t == m2type_GetBitnumType ())
1258 m2pp_print (s, "BITNUM");
1259 else
1261 if (TYPE_UNSIGNED (t))
1262 m2pp_print (s, "CARDINAL");
1263 else
1264 m2pp_print (s, "INTEGER");
1265 m2pp_integer_cst (s, TYPE_SIZE (t));
1268 #else
1269 void
1270 m2pp_integer (pretty *s, tree t ATTRIBUTE_UNUSED)
1272 m2pp_print (s, "INTEGER");
1274 #endif
1276 /* m2pp_complex display the actual complex type. */
1278 #if defined(GM2)
1279 static void
1280 m2pp_complex (pretty *s, tree t)
1282 if (t == m2type_GetM2ComplexType ())
1283 m2pp_print (s, "COMPLEX");
1284 else if (t == m2type_GetM2LongComplexType ())
1285 m2pp_print (s, "LONGCOMPLEX");
1286 else if (t == m2type_GetM2ShortComplexType ())
1287 m2pp_print (s, "SHORTCOMPLEX");
1288 else if (t == m2type_GetM2CType ())
1289 m2pp_print (s, "C'omplex' type");
1290 else if (t == m2type_GetM2Complex32 ())
1291 m2pp_print (s, "COMPLEX32");
1292 else if (t == m2type_GetM2Complex64 ())
1293 m2pp_print (s, "COMPLEX64");
1294 else if (t == m2type_GetM2Complex96 ())
1295 m2pp_print (s, "COMPLEX96");
1296 else if (t == m2type_GetM2Complex128 ())
1297 m2pp_print (s, "COMPLEX128");
1298 else
1299 m2pp_print (s, "unknown COMPLEX type");
1302 #else
1304 static void
1305 m2pp_complex (pretty *s, tree t ATTRIBUTE_UNUSED)
1307 m2pp_print (s, "a COMPLEX type");
1309 #endif
1311 void
1312 m2pp_real_type (pretty *s, tree t)
1314 if (t == m2type_GetRealType ())
1315 m2pp_print (s, "C double");
1316 else if (t == m2type_GetShortRealType ())
1317 m2pp_print (s, "C float");
1318 else if (t == m2type_GetLongRealType ())
1319 m2pp_print (s, "C long double");
1320 else if (t == m2type_GetM2RealType ())
1321 m2pp_print (s, "REAL");
1322 else if (t == m2type_GetM2ShortRealType ())
1323 m2pp_print (s, "SHORTREAL");
1324 else if (t == m2type_GetM2LongRealType ())
1325 m2pp_print (s, "LONGREAL");
1326 else if (t == m2type_GetM2Real128 ())
1327 m2pp_print (s, "REAL128");
1328 else if (t == m2type_GetM2Real64 ())
1329 m2pp_print (s, "REAL64");
1330 else if (t == m2type_GetM2Real32 ())
1331 m2pp_print (s, "REAL32");
1332 else if (t == m2type_GetM2RType ())
1333 m2pp_print (s, "R Type");
1334 else
1335 m2pp_print (s, "unknown REAL");
1338 /* m2pp_type prints a full type. */
1340 void
1341 m2pp_type (pretty *s, tree t)
1343 if (begin_printed (t))
1345 m2pp_print (s, "<...>");
1346 return;
1348 if ((TREE_CODE (t) != FIELD_DECL) && (TREE_CODE (t) != TYPE_DECL))
1349 m2pp_gimpified (s, t);
1350 switch (TREE_CODE (t))
1352 case INTEGER_TYPE:
1353 m2pp_integer (s, t);
1354 break;
1355 case REAL_TYPE:
1356 m2pp_real_type (s, t);
1357 break;
1358 case ENUMERAL_TYPE:
1359 m2pp_enum (s, t);
1360 break;
1361 case UNION_TYPE:
1362 m2pp_union_type (s, t);
1363 break;
1364 case RECORD_TYPE:
1365 m2pp_record_type (s, t);
1366 break;
1367 case ARRAY_TYPE:
1368 m2pp_array (s, t);
1369 break;
1370 #if 0
1371 case FUNCTION_TYPE:
1372 m2pp_function_type (s, t);
1373 break;
1374 #endif
1375 case TYPE_DECL:
1376 m2pp_identifier (s, t);
1377 break;
1378 case POINTER_TYPE:
1379 m2pp_pointer_type (s, t);
1380 break;
1381 #if defined(GM2)
1382 case SET_TYPE:
1383 m2pp_set_type (s, t);
1384 break;
1385 #endif
1386 case VOID_TYPE:
1387 m2pp_print (s, "ADDRESS");
1388 break;
1389 case COMPLEX_TYPE:
1390 m2pp_complex (s, t);
1391 break;
1392 default:
1393 m2pp_unknown (s, __FUNCTION__, get_tree_code_name (TREE_CODE (t)));
1397 /* m2pp_set_type prints out the set type. */
1399 static void
1400 m2pp_set_type (pretty *s, tree t)
1402 push (t);
1403 m2pp_print (s, "SET OF");
1404 m2pp_needspace (s);
1405 m2pp_type (s, TREE_TYPE (t));
1406 pop ();
1409 /* m2pp_enum print out the enumeration type. */
1411 static void
1412 m2pp_enum (pretty *s, tree t)
1414 tree chain_p = TYPE_VALUES (t);
1416 push (t);
1417 m2pp_print (s, "(");
1418 while (chain_p)
1420 m2pp_ident_pointer (s, TREE_PURPOSE (chain_p));
1421 chain_p = TREE_CHAIN (chain_p);
1422 if (chain_p)
1423 m2pp_print (s, ", ");
1425 m2pp_print (s, ")");
1426 pop ();
1429 /* m2pp_array prints out the array type. */
1431 static void
1432 m2pp_array (pretty *s, tree t)
1434 push (t);
1435 m2pp_print (s, "ARRAY");
1436 m2pp_needspace (s);
1437 m2pp_subrange (s, TYPE_DOMAIN (t));
1438 m2pp_needspace (s);
1439 m2pp_print (s, "OF");
1440 m2pp_needspace (s);
1441 m2pp_type (s, TREE_TYPE (t));
1442 pop ();
1445 /* m2pp_subrange prints out the subrange, but probably the lower
1446 bound will always be zero. */
1448 static void
1449 m2pp_subrange (pretty *s, tree t)
1451 tree min = TYPE_MIN_VALUE (t);
1452 tree max = TYPE_MAX_VALUE (t);
1454 m2pp_print (s, "[");
1455 m2pp_expression (s, min);
1456 m2pp_print (s, "..");
1457 m2pp_expression (s, max);
1458 m2pp_print (s, "]");
1461 /* m2pp_gimplified print out a gimplified comment. */
1463 static void
1464 m2pp_gimpified (pretty *s, tree t)
1466 if (!TYPE_SIZES_GIMPLIFIED (t))
1468 m2pp_print (s, "(* <!g> *)");
1469 m2pp_needspace (s);
1473 /* m2pp_printer_type display the pointer type. */
1475 static void
1476 m2pp_pointer_type (pretty *s, tree t)
1478 push (t);
1479 if (TREE_CODE (t) == POINTER_TYPE)
1481 if (TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE)
1482 m2pp_procedure_type (s, TREE_TYPE (t));
1483 else if (t == ptr_type_node)
1484 m2pp_print (s, "ADDRESS");
1485 else
1487 m2pp_print (s, "POINTER TO");
1488 m2pp_needspace (s);
1489 m2pp_type (s, TREE_TYPE (t));
1492 pop ();
1495 /* m2pp_record_alignment prints out whether this record is aligned
1496 (packed). */
1498 static void
1499 m2pp_record_alignment (pretty *s, tree t)
1501 if (TYPE_PACKED (t))
1502 m2pp_print (s, "<* bytealignment (0) *>\n");
1505 static unsigned int
1506 m2pp_getaligned (tree t)
1508 if (DECL_P (t))
1510 if (DECL_USER_ALIGN (t))
1511 return DECL_ALIGN (t);
1513 else if (TYPE_P (t))
1515 if (TYPE_USER_ALIGN (t))
1516 return TYPE_ALIGN (t);
1518 return 0;
1521 static void
1522 m2pp_recordfield_alignment (pretty *s, tree t)
1524 unsigned int aligned = m2pp_getaligned (t);
1526 if (aligned != 0)
1528 int o = getindent (s);
1529 int p = getcurpos (s);
1530 m2pp_needspace (s);
1531 m2pp_print (s, "<* bytealignment (");
1532 setindent (s, p + 18);
1534 printf ("%d", aligned / BITS_PER_UNIT);
1536 m2pp_print (s, ")");
1537 m2pp_needspace (s);
1538 setindent (s, p);
1539 m2pp_print (s, "*>");
1540 setindent (s, o);
1544 static void
1545 m2pp_recordfield_bitfield (pretty *s, tree t)
1547 if ((TREE_CODE (t) == FIELD_DECL) && DECL_PACKED (t))
1549 m2pp_print (s, " (* packed");
1550 if (DECL_NONADDRESSABLE_P (t))
1551 m2pp_print (s, ", non-addressible");
1552 if (DECL_BIT_FIELD (t))
1553 m2pp_print (s, ", bit-field");
1554 m2pp_print (s, ", offset: ");
1555 m2pp_expression (s, DECL_FIELD_OFFSET (t));
1556 m2pp_print (s, ", bit offset:");
1557 m2pp_expression (s, DECL_FIELD_BIT_OFFSET (t));
1558 m2pp_print (s, " *) ");
1562 /* m2pp_record_type displays the record type. */
1564 static void
1565 m2pp_record_type (pretty *s, tree t)
1567 push (t);
1568 if (TREE_CODE (t) == RECORD_TYPE)
1570 tree i;
1571 int o = getindent (s);
1572 int p = getcurpos (s);
1574 m2pp_print (s, "RECORD\n");
1575 setindent (s, p + 3);
1576 m2pp_record_alignment (s, t);
1577 for (i = TYPE_FIELDS (t); i != NULL_TREE; i = TREE_CHAIN (i))
1579 m2pp_identifier (s, i);
1580 m2pp_print (s, " : ");
1581 m2pp_type (s, TREE_TYPE (i));
1582 m2pp_recordfield_bitfield (s, i);
1583 m2pp_recordfield_alignment (s, i);
1584 m2pp_print (s, ";\n");
1586 setindent (s, p);
1587 m2pp_print (s, "END");
1588 setindent (s, o);
1590 pop ();
1593 /* m2pp_record_type displays the record type. */
1595 static void
1596 m2pp_union_type (pretty *s, tree t)
1598 push (t);
1599 if (TREE_CODE (t) == UNION_TYPE)
1601 tree i;
1602 int o = getindent (s);
1603 int p = getcurpos (s);
1605 m2pp_print (s, "CASE .. OF\n");
1606 setindent (s, p + 3);
1607 m2pp_record_alignment (s, t);
1608 for (i = TYPE_FIELDS (t); i != NULL_TREE; i = TREE_CHAIN (i))
1610 m2pp_identifier (s, i);
1611 m2pp_print (s, " : ");
1612 m2pp_type (s, TREE_TYPE (i));
1613 m2pp_recordfield_bitfield (s, i);
1614 m2pp_print (s, ";\n");
1616 setindent (s, p);
1617 m2pp_print (s, "END");
1618 setindent (s, o);
1620 pop ();
1623 /* m2pp_print_mode. */
1625 static void
1626 m2pp_print_mode (pretty *s, tree t)
1628 int mode = SCALAR_FLOAT_TYPE_MODE (t);
1629 char buf[100];
1631 snprintf (buf, sizeof (buf), "%d", mode);
1632 m2pp_print (s, "<*");
1633 m2pp_needspace (s);
1634 m2pp_print (s, buf);
1635 m2pp_needspace (s);
1636 m2pp_print (s, "*>");
1639 /* m2pp_simple_type. */
1641 static void
1642 m2pp_simple_type (pretty *s, tree t)
1644 if (begin_printed (t))
1646 m2pp_print (s, "<...>");
1647 return;
1650 m2pp_gimpified (s, t);
1651 switch (TREE_CODE (t))
1653 case INTEGER_TYPE:
1654 m2pp_integer (s, t);
1655 break;
1656 case REAL_TYPE:
1657 m2pp_real_type (s, t);
1658 m2pp_print_mode (s, t);
1659 break;
1660 case BOOLEAN_TYPE:
1661 m2pp_print (s, "BOOLEAN");
1662 break;
1663 case VOID_TYPE:
1664 m2pp_print (s, "ADDRESS");
1665 break;
1666 case TYPE_DECL:
1667 m2pp_identifier (s, t);
1668 break;
1669 case POINTER_TYPE:
1670 m2pp_pointer_type (s, t);
1671 break;
1672 case RECORD_TYPE:
1673 m2pp_record_type (s, t);
1674 break;
1675 case UNION_TYPE:
1676 m2pp_union_type (s, t);
1677 break;
1678 case ENUMERAL_TYPE:
1679 m2pp_enum (s, t);
1680 break;
1681 case COMPLEX_TYPE:
1682 m2pp_complex (s, t);
1683 break;
1684 default:
1685 m2pp_unknown (s, __FUNCTION__, get_tree_code_name (TREE_CODE (t)));
1689 /* m2pp_float issue a VAL (type, expr) expression. */
1691 static void
1692 m2pp_float (pretty *s, tree t)
1694 m2pp_needspace (s);
1695 m2pp_print (s, "VAL (");
1696 m2pp_simple_type (s, TREE_TYPE (t));
1697 m2pp_print (s, ", ");
1698 m2pp_expression (s, TREE_OPERAND (t, 0));
1699 m2pp_print (s, ")");
1702 /* m2pp_expression display an expression. */
1704 static void
1705 m2pp_expression (pretty *s, tree t)
1707 enum tree_code code = TREE_CODE (t);
1709 switch (code)
1711 case EQ_EXPR:
1712 m2pp_relop (s, t, "=");
1713 break;
1714 case NE_EXPR:
1715 m2pp_relop (s, t, "#");
1716 break;
1717 case LE_EXPR:
1718 m2pp_relop (s, t, "<=");
1719 break;
1720 case GE_EXPR:
1721 m2pp_relop (s, t, ">=");
1722 break;
1723 case LT_EXPR:
1724 m2pp_relop (s, t, "<");
1725 break;
1726 case GT_EXPR:
1727 m2pp_relop (s, t, ">");
1728 break;
1729 case FLOAT_EXPR:
1730 m2pp_float (s, t);
1731 break;
1732 default:
1733 m2pp_simple_expression (s, t);
1737 /* m2pp_relop displays the lhs relop rhs. */
1739 static void
1740 m2pp_relop (pretty *s, tree t, const char *p)
1742 m2pp_expression (s, TREE_OPERAND (t, 0));
1743 m2pp_needspace (s);
1744 m2pp_print (s, p);
1745 m2pp_needspace (s);
1746 m2pp_expression (s, TREE_OPERAND (t, 1));
1749 /* m2pp_compound_expression handle compound expression tree. */
1751 static void
1752 m2pp_compound_expression (pretty *s, tree t)
1754 m2pp_print (s, "compound expression {");
1755 m2pp_expression (s, TREE_OPERAND (t, 0));
1756 m2pp_print (s, " (* result ignored *), ");
1757 m2pp_expression (s, TREE_OPERAND (t, 1));
1758 m2pp_print (s, "}");
1759 m2pp_needspace (s);
1762 /* m2pp_target_expression handle target expression tree. */
1764 static void
1765 m2pp_target_expression (pretty *s, tree t)
1767 m2pp_print (s, "{");
1768 m2pp_needspace (s);
1769 if (TREE_OPERAND (t, 0) != NULL_TREE)
1771 m2pp_print (s, "(* target *) ");
1772 m2pp_expression (s, TREE_OPERAND (t, 0));
1773 m2pp_print (s, ",");
1774 m2pp_needspace (s);
1776 if (TREE_OPERAND (t, 1) != NULL_TREE)
1778 m2pp_print (s, "(* initializer *) ");
1779 m2pp_expression (s, TREE_OPERAND (t, 1));
1780 m2pp_print (s, ",");
1781 m2pp_needspace (s);
1783 if (TREE_OPERAND (t, 2) != NULL_TREE)
1785 m2pp_print (s, "(* cleanup *) ");
1786 m2pp_expression (s, TREE_OPERAND (t, 2));
1787 m2pp_print (s, ",");
1788 m2pp_needspace (s);
1790 if (TREE_OPERAND (t, 3) != NULL_TREE)
1792 m2pp_print (s, "(* saved initializer *) ");
1793 m2pp_expression (s, TREE_OPERAND (t, 3));
1794 m2pp_print (s, ",");
1795 m2pp_needspace (s);
1797 m2pp_print (s, "}");
1798 m2pp_needspace (s);
1801 /* m2pp_constructor print out a constructor. */
1803 static void
1804 m2pp_constructor (pretty *s, tree t)
1806 tree purpose, value;
1807 unsigned HOST_WIDE_INT ix;
1809 m2pp_print (s, "{ ");
1810 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t), ix, purpose, value)
1812 m2pp_print (s, "(index: ");
1813 m2pp_simple_expression (s, purpose);
1814 m2pp_print (s, ") ");
1815 m2pp_simple_expression (s, value);
1816 m2pp_print (s, ", ");
1818 m2pp_print (s, "}");
1819 m2pp_print (s, "(* type: ");
1820 setindent (s, getindent (s) + 8);
1821 m2pp_type (s, TREE_TYPE (t));
1822 setindent (s, getindent (s) - 8);
1823 m2pp_print (s, " *)\n");
1826 /* m2pp_complex_expr handle GCC complex_expr tree. */
1828 static void
1829 m2pp_complex_expr (pretty *s, tree t)
1831 if (TREE_CODE (t) == COMPLEX_CST)
1833 m2pp_print (s, "CMPLX(");
1834 m2pp_needspace (s);
1835 m2pp_expression (s, TREE_REALPART (t));
1836 m2pp_print (s, ",");
1837 m2pp_needspace (s);
1838 m2pp_expression (s, TREE_IMAGPART (t));
1839 m2pp_print (s, ")");
1841 else
1843 m2pp_print (s, "CMPLX(");
1844 m2pp_needspace (s);
1845 m2pp_expression (s, TREE_OPERAND (t, 0));
1846 m2pp_print (s, ",");
1847 m2pp_needspace (s);
1848 m2pp_expression (s, TREE_OPERAND (t, 1));
1849 m2pp_print (s, ")");
1853 /* m2pp_imagpart_expr handle imagpart_expr tree. */
1855 static void
1856 m2pp_imagpart_expr (pretty *s, tree t)
1858 m2pp_print (s, "IM(");
1859 m2pp_needspace (s);
1860 if (TREE_CODE (t) == IMAGPART_EXPR)
1861 m2pp_expression (s, TREE_OPERAND (t, 0));
1862 else if (TREE_CODE (t) == COMPLEX_CST)
1863 m2pp_expression (s, TREE_IMAGPART (t));
1864 m2pp_needspace (s);
1865 m2pp_print (s, ")");
1868 /* m2pp_realpart_expr handle imagpart_expr tree. */
1870 static void
1871 m2pp_realpart_expr (pretty *s, tree t)
1873 m2pp_print (s, "RE(");
1874 m2pp_needspace (s);
1875 if (TREE_CODE (t) == REALPART_EXPR)
1876 m2pp_expression (s, TREE_OPERAND (t, 0));
1877 else if (TREE_CODE (t) == COMPLEX_CST)
1878 m2pp_expression (s, TREE_REALPART (t));
1879 m2pp_needspace (s);
1880 m2pp_print (s, ")");
1883 /* m2pp_bit_ior_expr generate a C style bit or. */
1885 static void
1886 m2pp_bit_ior_expr (pretty *s, tree t)
1888 m2pp_binary (s, t, "|");
1891 /* m2pp_truth_expr. */
1893 static void
1894 m2pp_truth_expr (pretty *s, tree t, const char *op)
1896 m2pp_print (s, "(");
1897 m2pp_expression (s, TREE_OPERAND (t, 0));
1898 m2pp_print (s, ")");
1899 m2pp_needspace (s);
1900 m2pp_print (s, op);
1901 m2pp_needspace (s);
1902 m2pp_print (s, "(");
1903 m2pp_expression (s, TREE_OPERAND (t, 1));
1904 m2pp_print (s, ")");
1907 /* m2pp_simple_expression handle GCC expression tree. */
1909 static void
1910 m2pp_simple_expression (pretty *s, tree t)
1912 enum tree_code code = TREE_CODE (t);
1914 switch (code)
1916 case ERROR_MARK:
1917 m2pp_print (s, "(* !!! ERROR NODE !!! *)");
1918 break;
1919 case CONSTRUCTOR:
1920 m2pp_constructor (s, t);
1921 break;
1922 case IDENTIFIER_NODE:
1923 m2pp_ident_pointer (s, t);
1924 break;
1925 case PARM_DECL:
1926 m2pp_identifier (s, t);
1927 break;
1928 case FIELD_DECL:
1929 m2pp_identifier (s, t);
1930 break;
1931 case TREE_LIST:
1932 m2pp_list (s, t);
1933 break;
1934 case BLOCK:
1935 m2pp_print (s, "(* BLOCK NODE *)");
1936 break;
1937 case OFFSET_TYPE:
1938 m2pp_offset (s, t);
1939 break;
1940 case INTEGER_CST:
1941 m2pp_integer_cst (s, t);
1942 break;
1943 case REAL_CST:
1944 m2pp_real_cst (s, t);
1945 break;
1946 case STRING_CST:
1947 m2pp_string_cst (s, t);
1948 break;
1949 case INDIRECT_REF:
1950 m2pp_indirect_ref (s, t);
1951 break;
1952 case ADDR_EXPR:
1953 m2pp_addr_expr (s, t);
1954 break;
1955 case NOP_EXPR:
1956 m2pp_nop (s, t);
1957 break;
1958 case CONVERT_EXPR:
1959 m2pp_convert (s, t);
1960 break;
1961 case VAR_DECL:
1962 m2pp_var_decl (s, t);
1963 break;
1964 case RESULT_DECL:
1965 m2pp_result_decl (s, t);
1966 break;
1967 case PLUS_EXPR:
1968 m2pp_binary (s, t, "+");
1969 break;
1970 case MINUS_EXPR:
1971 m2pp_binary (s, t, "-");
1972 break;
1973 case MULT_EXPR:
1974 m2pp_binary (s, t, "*");
1975 break;
1976 case FLOOR_DIV_EXPR:
1977 case CEIL_DIV_EXPR:
1978 case TRUNC_DIV_EXPR:
1979 case ROUND_DIV_EXPR:
1980 m2pp_binary (s, t, "DIV");
1981 break;
1982 case FLOOR_MOD_EXPR:
1983 case CEIL_MOD_EXPR:
1984 case TRUNC_MOD_EXPR:
1985 case ROUND_MOD_EXPR:
1986 m2pp_binary (s, t, "MOD");
1987 break;
1988 case NEGATE_EXPR:
1989 m2pp_unary (s, t, "-");
1990 break;
1991 case CALL_EXPR:
1992 m2pp_call_expr (s, t);
1993 break;
1994 case SSA_NAME:
1995 m2pp_ssa (s, t);
1996 break;
1997 case COMPONENT_REF:
1998 m2pp_component_ref (s, t);
1999 break;
2000 case RETURN_EXPR:
2001 m2pp_return_expr (s, t);
2002 break;
2003 case ARRAY_REF:
2004 m2pp_array_ref (s, t);
2005 break;
2006 case NON_LVALUE_EXPR:
2007 m2pp_non_lvalue_expr (s, t);
2008 break;
2009 case EXPR_STMT:
2010 m2pp_expression (s, EXPR_STMT_EXPR (t));
2011 break;
2012 #if 0
2013 case EXC_PTR_EXPR:
2014 m2pp_print (s, "GCC_EXCEPTION_OBJECT");
2015 break;
2016 #endif
2017 case INIT_EXPR:
2018 case MODIFY_EXPR:
2019 m2pp_assignment (s, t);
2020 break;
2021 case COMPOUND_EXPR:
2022 m2pp_compound_expression (s, t);
2023 break;
2024 case TARGET_EXPR:
2025 m2pp_target_expression (s, t);
2026 break;
2027 case THROW_EXPR:
2028 m2pp_throw (s, t);
2029 break;
2030 case FUNCTION_DECL:
2031 m2pp_identifier (s, t);
2032 break;
2033 case COMPLEX_EXPR:
2034 m2pp_complex_expr (s, t);
2035 break;
2036 case REALPART_EXPR:
2037 m2pp_realpart_expr (s, t);
2038 break;
2039 case IMAGPART_EXPR:
2040 m2pp_imagpart_expr (s, t);
2041 break;
2042 case CONST_DECL:
2043 m2pp_identifier (s, t);
2044 break;
2045 case POINTER_PLUS_EXPR:
2046 m2pp_binary (s, t, "+");
2047 break;
2048 case CLEANUP_POINT_EXPR:
2049 m2pp_cleanup_point_expr (s, t);
2050 break;
2051 case BIT_IOR_EXPR:
2052 m2pp_bit_ior_expr (s, t);
2053 break;
2054 case TRUTH_ANDIF_EXPR:
2055 m2pp_truth_expr (s, t, "AND");
2056 break;
2057 case TRUTH_ORIF_EXPR:
2058 m2pp_truth_expr (s, t, "OR");
2059 break;
2060 default:
2061 m2pp_unknown (s, __FUNCTION__, get_tree_code_name (code));
2065 /* non_lvalue_expr indicates that operand 0 is not an lvalue. */
2067 static void
2068 m2pp_non_lvalue_expr (pretty *s, tree t)
2070 m2pp_needspace (s);
2071 m2pp_print (s, "assert_non_lvalue(");
2072 m2pp_needspace (s);
2073 m2pp_expression (s, TREE_OPERAND (t, 0));
2074 m2pp_needspace (s);
2075 m2pp_print (s, ")");
2078 /* m2pp_array_ref prints out the array reference. */
2080 static void
2081 m2pp_array_ref (pretty *s, tree t)
2083 m2pp_expression (s, TREE_OPERAND (t, 0));
2084 m2pp_print (s, "[");
2085 m2pp_expression (s, TREE_OPERAND (t, 1));
2086 m2pp_print (s, "]");
2089 /* m2pp_ssa prints out the ssa variable name. */
2091 static void
2092 m2pp_ssa (pretty *s, tree t)
2094 m2pp_identifier (s, SSA_NAME_VAR (t));
2097 /* m2pp_binary print the binary operator, p, and lhs, rhs. */
2099 static void
2100 m2pp_binary (pretty *s, tree t, const char *p)
2102 tree left = TREE_OPERAND (t, 0);
2103 tree right = TREE_OPERAND (t, 1);
2105 m2pp_expression (s, left);
2106 m2pp_needspace (s);
2107 m2pp_print (s, p);
2108 m2pp_needspace (s);
2109 m2pp_expression (s, right);
2112 /* m2pp_unary print the unary operator, p, and expression. */
2114 static void
2115 m2pp_unary (pretty *s, tree t, const char *p)
2117 tree expr = TREE_OPERAND (t, 0);
2119 m2pp_needspace (s);
2120 m2pp_print (s, p);
2121 m2pp_expression (s, expr);
2124 /* m2pp_integer_cst displays the integer constant. */
2126 static void
2127 m2pp_integer_cst (pretty *s, tree t)
2129 char val[100];
2131 snprintf (val, 100, HOST_WIDE_INT_PRINT_UNSIGNED, TREE_INT_CST_LOW (t));
2132 m2pp_print (s, val);
2135 /* m2pp_real_cst displays the real constant. */
2137 static void
2138 m2pp_real_cst (pretty *s, tree t ATTRIBUTE_UNUSED)
2140 m2pp_print (s, "<unknown real>");
2143 /* m2pp_string_cst displays the real constant. */
2145 static void
2146 m2pp_string_cst (pretty *s, tree t)
2148 const char *p = TREE_STRING_POINTER (t);
2149 int i = 0;
2151 m2pp_print (s, "\"");
2152 while (p[i] != '\0')
2154 m2pp_print_char (s, p[i]);
2155 i++;
2157 m2pp_print (s, "\"");
2160 /* m2pp_statement_sequence iterates over a statement list
2161 displaying each statement in turn. */
2163 static void
2164 m2pp_statement_sequence (pretty *s, tree t)
2166 if (t != NULL_TREE)
2168 if (TREE_CODE (t) == STATEMENT_LIST)
2170 tree_stmt_iterator i;
2171 m2pp_print (s, "(* statement list *)\n");
2173 for (i = tsi_start (t); !tsi_end_p (i); tsi_next (&i))
2174 m2pp_statement (s, *tsi_stmt_ptr (i));
2176 else
2177 m2pp_statement (s, t);
2181 /* m2pp_unknown displays an error message. */
2183 static void
2184 m2pp_unknown (pretty *s, const char *s1, const char *s2)
2186 m2pp_begin (s);
2187 m2pp_print (s, s1);
2188 m2pp_needspace (s);
2189 m2pp_print (s, s2);
2190 m2pp_needspace (s);
2193 /* m2pp_throw displays a throw statement. */
2195 static void
2196 m2pp_throw (pretty *s, tree t)
2198 tree expr = TREE_OPERAND (t, 0);
2200 m2pp_begin (s);
2201 if (expr == NULL_TREE)
2202 m2pp_print (s, "THROW ;\n");
2203 else
2205 m2pp_print (s, "THROW (");
2206 m2pp_expression (s, TREE_OPERAND (t, 0));
2207 m2pp_print (s, ")\n");
2211 /* m2pp_catch_expr attempts to reconstruct a catch expr. */
2213 static void
2214 m2pp_catch_expr (pretty *s, tree t)
2216 tree types = CATCH_TYPES (t);
2217 tree body = CATCH_BODY (t);
2219 m2pp_print (s, "(* CATCH expression ");
2220 if (types != NULL_TREE)
2222 m2pp_print (s, "(");
2223 m2pp_expression (s, types);
2224 m2pp_print (s, ")");
2226 m2pp_print (s, "*)\n");
2227 m2pp_print (s, "(* catch body *)\n");
2228 m2pp_statement_sequence (s, body);
2229 m2pp_print (s, "(* end catch body *)\n");
2232 /* m2pp_try_finally_expr attemts to reconstruct a try finally expr. */
2234 static void
2235 m2pp_try_finally_expr (pretty *s, tree t)
2237 m2pp_begin (s);
2238 m2pp_print (s, "(* try_finally_expr *)\n");
2239 setindent (s, getindent (s) + 3);
2240 m2pp_statement_sequence (s, TREE_OPERAND (t, 0));
2241 setindent (s, getindent (s) - 3);
2242 m2pp_print (s,
2243 "(* finally (cleanup which is executed after the above) *)\n");
2244 setindent (s, getindent (s) + 3);
2245 m2pp_statement_sequence (s, TREE_OPERAND (t, 1));
2246 setindent (s, getindent (s) - 3);
2247 m2pp_print (s, "(* end try_finally_expr *)\n");
2250 #if !defined(GM2)
2251 /* m2pp_if_stmt pretty print a C++ if_stmt. */
2253 static void
2254 m2pp_if_stmt (pretty *s, tree t)
2256 m2pp_print (s, "(* only C++ uses if_stmt nodes *)\n");
2257 m2pp_print (s, "IF ");
2258 m2pp_expression (s, TREE_OPERAND (t, 0));
2259 m2pp_print (s, "\n");
2260 m2pp_print (s, "THEN\n");
2261 setindent (s, getindent (s) + 3);
2262 m2pp_statement_sequence (s, TREE_OPERAND (t, 1));
2263 setindent (s, getindent (s) - 3);
2264 m2pp_print (s, "ELSE\n");
2265 setindent (s, getindent (s) + 3);
2266 m2pp_statement_sequence (s, TREE_OPERAND (t, 2));
2267 setindent (s, getindent (s) - 3);
2268 m2pp_print (s, "END\n");
2270 #endif
2272 static void
2273 m2pp_asm_expr (pretty *state, tree node)
2275 m2pp_begin (state);
2276 m2pp_print (state, "ASM");
2277 m2pp_needspace (state);
2278 if (ASM_VOLATILE_P (node))
2280 m2pp_print (state, "VOLATILE");
2281 m2pp_needspace (state);
2283 m2pp_print (state, "(");
2284 m2pp_expression (state, ASM_STRING (node));
2285 m2pp_print (state, ":");
2286 m2pp_needspace (state);
2287 m2pp_expression (state, ASM_OUTPUTS (node));
2288 m2pp_print (state, ":");
2289 m2pp_needspace (state);
2290 m2pp_expression (state, ASM_INPUTS (node));
2291 if (ASM_CLOBBERS (node) != NULL)
2293 m2pp_print (state, ":");
2294 m2pp_needspace (state);
2295 m2pp_expression (state, ASM_CLOBBERS (node));
2297 m2pp_print (state, ");\n");
2300 /* m2pp_statement attempts to reconstruct a statement. */
2302 static void
2303 m2pp_statement (pretty *s, tree t)
2305 enum tree_code code = TREE_CODE (t);
2307 m2pp_loc (s, t);
2308 switch (code)
2310 case COND_EXPR:
2311 m2pp_conditional (s, t);
2312 break;
2313 case LABEL_EXPR:
2314 m2pp_label_expr (s, t);
2315 break;
2316 case LABEL_DECL:
2317 m2pp_label_decl (s, t);
2318 break;
2319 case GOTO_EXPR:
2320 m2pp_goto (s, t);
2321 break;
2322 case INIT_EXPR:
2323 case MODIFY_EXPR:
2324 m2pp_assignment (s, t);
2325 break;
2326 case CALL_EXPR:
2327 m2pp_procedure_call (s, t);
2328 break;
2329 case BLOCK:
2330 m2pp_block_list (s, t);
2331 break;
2332 case BIND_EXPR:
2333 m2pp_bind_expr (s, t);
2334 break;
2335 case RETURN_EXPR:
2336 m2pp_return_expr (s, t);
2337 break;
2338 case DECL_EXPR:
2339 m2pp_decl_expr (s, t);
2340 break;
2341 case TRY_BLOCK:
2342 m2pp_try_block (s, t);
2343 break;
2344 case HANDLER:
2345 m2pp_handler (s, t);
2346 break;
2347 case CLEANUP_POINT_EXPR:
2348 m2pp_cleanup_point_expr (s, t);
2349 break;
2350 case THROW_EXPR:
2351 m2pp_throw (s, t);
2352 break;
2353 case TRY_CATCH_EXPR:
2354 m2pp_try_catch_expr (s, t);
2355 break;
2356 case TRY_FINALLY_EXPR:
2357 m2pp_try_finally_expr (s, t);
2358 break;
2359 case CATCH_EXPR:
2360 m2pp_catch_expr (s, t);
2361 break;
2362 case ASM_EXPR:
2363 m2pp_asm_expr (s, t);
2364 break;
2365 #if defined(CPP)
2366 case IF_STMT:
2367 m2pp_if_stmt (s, t);
2368 break;
2369 #endif
2370 case ERROR_MARK:
2371 m2pp_print (s, "<ERROR CODE>\n");
2372 break;
2373 default:
2374 m2pp_unknown (s, __FUNCTION__, get_tree_code_name (TREE_CODE (t)));
2378 /* m2pp_try_catch_expr is used after gimplification. */
2380 static void
2381 m2pp_try_catch_expr (pretty *s, tree t)
2383 m2pp_print (s, "(* try_catch_expr begins *)\n");
2384 m2pp_statement_sequence (s, TREE_OPERAND (t, 0));
2385 setindent (s, 0);
2386 m2pp_print (s, "EXCEPT\n");
2387 setindent (s, 3);
2388 m2pp_statement_sequence (s, TREE_OPERAND (t, 1));
2389 m2pp_print (s, "(* try_catch_expr ends *)\n");
2392 /* m2pp_cleanup_point_expr emits a comment indicating a GCC
2393 cleanup_point_expr is present. */
2395 static void
2396 m2pp_cleanup_point_expr (pretty *s, tree t)
2398 m2pp_begin (s);
2399 m2pp_print (s, "(* cleanup point begins *)\n");
2400 m2pp_expression (s, TREE_OPERAND (t, 0));
2401 m2pp_print (s, "(* cleanup point ends *)\n");
2404 /* m2pp_decl_expr displays a local declaration. */
2406 static void
2407 m2pp_decl_expr (pretty *s, tree t)
2409 m2pp_var (s);
2410 m2pp_print (s, "(* variable in decl_expr *)\n");
2411 m2pp_var_type_decl (s, DECL_EXPR_DECL (t));
2414 /* m2pp_procedure_call print a call to a procedure. */
2416 static void
2417 m2pp_procedure_call (pretty *s, tree t)
2419 m2pp_begin (s);
2420 m2pp_call_expr (s, t);
2421 m2pp_needspace (s);
2422 m2pp_print (s, ";\n");
2425 /* args displays each argument in an iter list by calling expression. */
2427 static void
2428 m2pp_args (pretty *s, tree e)
2430 call_expr_arg_iterator iter;
2431 tree arg;
2433 m2pp_print (s, "(");
2434 m2pp_needspace (s);
2435 FOR_EACH_CALL_EXPR_ARG (arg, iter, e)
2437 m2pp_expression (s, arg);
2438 if (more_call_expr_args_p (&iter))
2440 m2pp_print (s, ",");
2441 m2pp_needspace (s);
2444 m2pp_print (s, ")");
2447 /* m2pp_call_expr print a call to a procedure or function. */
2449 static void
2450 m2pp_call_expr (pretty *s, tree t)
2452 tree call = CALL_EXPR_FN (t);
2453 tree args = TREE_OPERAND (t, 1);
2454 tree type = TREE_TYPE (t);
2455 int has_return_type = TRUE;
2456 tree proc;
2458 if (type && VOID_TYPE_P (type))
2459 has_return_type = FALSE;
2461 if (TREE_CODE (call) == ADDR_EXPR || TREE_CODE (call) == NON_LVALUE_EXPR)
2462 proc = TREE_OPERAND (call, 0);
2463 else
2464 proc = call;
2466 m2pp_expression (s, proc);
2467 if (args || has_return_type)
2468 m2pp_args (s, t);
2471 /* m2pp_return_expr displays the return statement. */
2473 static void
2474 m2pp_return_expr (pretty *s, tree t)
2476 tree e = TREE_OPERAND (t, 0);
2478 m2pp_begin (s);
2479 if (e == NULL_TREE)
2481 m2pp_print (s, "RETURN");
2483 else if (TREE_CODE (e) == MODIFY_EXPR || (TREE_CODE (e) == INIT_EXPR))
2485 m2pp_assignment (s, e);
2486 m2pp_print (s, "RETURN");
2487 m2pp_needspace (s);
2488 m2pp_expression (s, TREE_OPERAND (e, 0));
2490 else
2492 m2pp_print (s, "RETURN");
2493 m2pp_needspace (s);
2494 m2pp_expression (s, e);
2496 m2pp_needspace (s);
2497 m2pp_print (s, ";\n");
2500 /* m2pp_try_block displays the try block. */
2502 static void
2503 m2pp_try_block (pretty *s, tree t)
2505 tree stmts = TRY_STMTS (t);
2506 tree handlers = TRY_HANDLERS (t);
2508 m2pp_begin (s);
2509 m2pp_print (s, "(* TRY *)\n");
2510 m2pp_statement_sequence (s, stmts);
2511 setindent (s, 0);
2512 m2pp_print (s, "EXCEPT\n");
2513 setindent (s, 3);
2514 m2pp_statement_sequence (s, handlers);
2515 m2pp_print (s, "(* END TRY *)\n");
2518 /* m2pp_try_block displays the handler block. */
2520 static void
2521 m2pp_handler (pretty *s, tree t)
2523 tree parms = HANDLER_PARMS (t);
2524 tree body = HANDLER_BODY (t);
2525 tree type = HANDLER_TYPE (t);
2527 m2pp_print (s, "(* handler *)\n");
2528 if (parms != NULL_TREE)
2530 m2pp_print (s, "(* handler parameter has a type (should be NULL_TREE) "
2531 "in Modula-2 *)\n");
2532 m2pp_print (s, "CATCH (");
2533 m2pp_expression (s, parms);
2534 m2pp_print (s, ")\n");
2536 if (type != NULL_TREE)
2537 m2pp_print (s, "(* handler type (should be NULL_TREE) in Modula-2 *)\n");
2538 m2pp_statement_sequence (s, body);
2541 /* m2pp_assignment prints out the assignment statement. */
2543 static void
2544 m2pp_assignment (pretty *s, tree t)
2546 int o;
2548 m2pp_begin (s);
2549 m2pp_designator (s, TREE_OPERAND (t, 0));
2550 m2pp_needspace (s);
2551 m2pp_print (s, ":=");
2552 m2pp_needspace (s);
2553 o = getindent (s);
2554 setindent (s, getcurpos (s) + 1);
2555 m2pp_expression (s, TREE_OPERAND (t, 1));
2556 m2pp_needspace (s);
2557 m2pp_print (s, ";\n");
2558 setindent (s, o);
2561 /* m2pp_designator displays the lhs of an assignment. */
2563 static void
2564 m2pp_designator (pretty *s, tree t)
2566 m2pp_expression (s, t);
2569 /* m2pp_indirect_ref displays the indirect operator. */
2571 static void
2572 m2pp_indirect_ref (pretty *s, tree t)
2574 m2pp_print (s, "(");
2575 m2pp_expression (s, TREE_OPERAND (t, 0));
2576 m2pp_print (s, ")^");
2579 /* m2pp_conditional builds an IF THEN ELSE END. With more work
2580 this should be moved into statement sequence which could look for
2581 repeat and while loops. */
2583 static void
2584 m2pp_conditional (pretty *s, tree t)
2586 int o;
2588 m2pp_begin (s);
2589 m2pp_print (s, "IF");
2590 m2pp_needspace (s);
2591 m2pp_expression (s, TREE_OPERAND (t, 0));
2592 m2pp_print (s, "\nTHEN\n");
2593 o = getindent (s);
2594 setindent (s, o + 3);
2595 m2pp_statement_sequence (s, TREE_OPERAND (t, 1));
2596 setindent (s, o);
2597 if (TREE_OPERAND (t, 2) != NULL_TREE)
2599 m2pp_print (s, "ELSE\n");
2600 setindent (s, o + 3);
2601 m2pp_statement_sequence (s, TREE_OPERAND (t, 2));
2602 setindent (s, o);
2604 m2pp_print (s, "END ;\n");
2607 /* m2pp_label_decl displays a label. Again should be moved into
2608 statement sequence to determine proper loop constructs. */
2610 static void
2611 m2pp_label_decl (pretty *s, tree t)
2613 m2pp_begin (s);
2614 m2pp_print (s, "(* label ");
2615 m2pp_identifier (s, t);
2616 m2pp_print (s, ": *)\n");
2619 /* m2pp_label_expr skips the LABEL_EXPR to find the LABEL_DECL. */
2621 static void
2622 m2pp_label_expr (pretty *s, tree t)
2624 m2pp_begin (s);
2625 m2pp_statement (s, TREE_OPERAND (t, 0));
2628 /* m2pp_goto displays a goto statement. Again should be moved into
2629 statement sequence to determine proper loop constructs. */
2631 static void
2632 m2pp_goto (pretty *s, tree t)
2634 m2pp_begin (s);
2635 m2pp_print (s, "(* goto ");
2636 m2pp_identifier (s, TREE_OPERAND (t, 0));
2637 m2pp_print (s, " *)\n");
2640 /* m2pp_list prints a TREE_CHAINed list. */
2642 static void
2643 m2pp_list (pretty *s, tree t)
2645 tree u = t;
2647 m2pp_print (s, "(");
2648 m2pp_needspace (s);
2649 while (t != NULL_TREE)
2651 m2pp_expression (s, TREE_VALUE (t));
2652 t = TREE_CHAIN (t);
2653 if (t == u || t == NULL_TREE)
2654 break;
2655 m2pp_print (s, ",");
2656 m2pp_needspace (s);
2658 m2pp_needspace (s);
2659 m2pp_print (s, ")");
2662 /* m2pp_offset displays the offset operator. */
2664 static void
2665 m2pp_offset (pretty *s, tree t)
2667 tree type = TREE_TYPE (t);
2668 tree base = TYPE_OFFSET_BASETYPE (t);
2670 m2pp_print (s, "OFFSET (");
2671 m2pp_type (s, base);
2672 m2pp_print (s, ".");
2673 m2pp_type (s, type);
2674 m2pp_print (s, ")");
2677 /* m2pp_addr_expr create an ADR expression. */
2679 static void
2680 m2pp_addr_expr (pretty *s, tree t)
2682 m2pp_needspace (s);
2683 m2pp_print (s, "ADR (");
2684 m2pp_expression (s, TREE_OPERAND (t, 0));
2685 m2pp_print (s, ")");
2688 /* m2pp_nop generate a CAST expression. */
2690 static void
2691 m2pp_nop (pretty *s, tree t)
2693 m2pp_needspace (s);
2694 m2pp_print (s, "CAST (");
2695 m2pp_simple_type (s, TREE_TYPE (t));
2696 m2pp_print (s, ", ");
2697 m2pp_expression (s, TREE_OPERAND (t, 0));
2698 m2pp_print (s, ")");
2701 /* m2pp_convert generate a CONVERT expression. */
2703 static void
2704 m2pp_convert (pretty *s, tree t)
2706 m2pp_needspace (s);
2707 m2pp_print (s, "CONVERT (");
2708 m2pp_simple_type (s, TREE_TYPE (t));
2709 m2pp_print (s, ", ");
2710 m2pp_expression (s, TREE_OPERAND (t, 0));
2711 m2pp_print (s, ")");
2714 /* m2pp_var_decl generate a variable. */
2716 static void
2717 m2pp_var_decl (pretty *s, tree t)
2719 m2pp_identifier (s, t);
2722 /* m2pp_result_decl generate a result declaration (variable). */
2724 static void
2725 m2pp_result_decl (pretty *s, tree t)
2727 m2pp_identifier (s, t);
2730 /* m2pp_component_ref generate a record field access. */
2732 static void
2733 m2pp_component_ref (pretty *s, tree t)
2735 m2pp_simple_expression (s, TREE_OPERAND (t, 0));
2736 m2pp_print (s, ".");
2737 m2pp_simple_expression (s, TREE_OPERAND (t, 1));