1 /* m2pp.c pretty print trees, output in Modula-2 where possible.
3 Copyright (C) 2007-2023 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)
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/>. */
23 #include "gm2-gcc/gcc-consolidation.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"
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"
49 typedef struct pretty_t
62 typedef struct m2stack_t
65 struct m2stack_t
*next
;
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
);
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. */
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
);
181 m2pp_statement_sequence (state
, t
);
185 /* pf print function. Expected to be printed interactively from
186 the debugger: print pf(func), or to be called from code. */
194 /* pe print expression. Expected to be printed interactively from
195 the debugger: print pe(expr), or to be called from code. */
200 pretty
*state
= initPretty (FALSE
);
202 m2pp_expression (state
, t
);
203 m2pp_needspace (state
);
204 m2pp_print (state
, ";\n");
208 /* pet print expression and its type. Expected to be printed
209 interactively from the debugger: print pet(expr), or to be called
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");
225 /* pt print type. Expected to be printed interactively from the
226 debugger: print pt(expr), or to be called from code. */
231 pretty
*state
= initPretty (FALSE
);
232 m2pp_type (state
, t
);
233 m2pp_needspace (state
);
234 m2pp_print (state
, ";\n");
238 /* ptl print type low level. Expected to be printed interactively
239 from the debugger: print ptl(type), or to be called from code. */
244 pretty
*state
= initPretty (FALSE
);
245 m2pp_type_lowlevel (state
, t
);
246 m2pp_needspace (state
);
247 m2pp_print (state
, ";\n");
251 /* ptcl print TREE_CHAINed list. */
256 pretty
*state
= initPretty (FALSE
);
258 m2pp_decl_list (state
, t
);
259 m2pp_print (state
, "\n");
263 /* loc if tree has a location then display it within a comment. */
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");
276 expanded_location l
= expand_location (EXPR_LOCATION (t
));
278 m2pp_print (s
, "(* ");
279 m2pp_print (s
, l
.file
);
281 printf ("%d", l
.line
);
282 m2pp_print (s
, " *)");
283 m2pp_print (s
, "\n");
288 m2pp_print (s
, "(* missing location2 *)\n");
293 /* m2pp_decl_list prints a TREE_CHAINed list for a decl node. */
296 m2pp_decl_list (pretty
*s
, tree t
)
302 while (t
!= NULL_TREE
)
304 m2pp_identifier (s
, t
);
306 if (t
== u
|| t
== NULL_TREE
)
316 m2pp_decl_bool (pretty
*s
, tree 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, ");
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");
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
));
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");
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
));
373 #if defined(GM2_MAINTAINER)
375 /* remember an internal debugging hook. */
376 static tree rememberF
= NULL
;
382 printf ("type: watch *((tree *) %p) != %p\n", (void *)&DECL_SAVED_TREE (t
),
383 (void *)DECL_SAVED_TREE (t
));
387 /* push pushes tree t onto stack. */
392 stack
*s
= (stack
*)xmalloc (sizeof (stack
));
399 /* pop pops a tree, from the stack. */
406 stackPtr
= stackPtr
->next
;
410 /* being_printed returns TRUE if t is held on the stack. */
413 begin_printed (tree t
)
427 /* dupPretty duplicate and return a copy of state s. */
430 dupPretty (pretty
*s
)
432 pretty
*p
= initPretty (s
->bits
);
437 /* initPretty initialise the state of the pretty printer. */
440 initPretty (int bits
)
442 pretty
*state
= (pretty
*)xmalloc (sizeof (pretty
));
443 state
->needs_space
= FALSE
;
444 state
->needs_indent
= FALSE
;
447 state
->issued_begin
= FALSE
;
448 state
->in_vars
= FALSE
;
449 state
->in_types
= FALSE
;
450 state
->block
= NULL_TREE
;
455 /* killPretty cleans up the state. */
458 killPretty (pretty
*s
)
464 /* getindent returns the current indent value. */
467 getindent (pretty
*s
)
472 /* setindent sets the current indent to, n. */
475 setindent (pretty
*s
, int n
)
480 /* getcurpos returns the current cursor position. */
483 getcurpos (pretty
*s
)
486 return s
->curpos
+ 1;
491 /* m2pp_type_lowlevel prints out the low level details of a
495 m2pp_type_lowlevel (pretty
*s
, tree t
)
497 if (TREE_CODE (t
) == INTEGER_TYPE
)
499 m2pp_print (s
, "min");
501 m2pp_integer_cst (s
, TYPE_MIN_VALUE (t
));
502 m2pp_print (s
, ", max");
504 m2pp_integer_cst (s
, TYPE_MAX_VALUE (t
));
505 m2pp_print (s
, ", type size unit");
507 m2pp_integer_cst (s
, TYPE_SIZE_UNIT (t
));
508 m2pp_print (s
, ", type size");
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
));
517 if (TYPE_UNSIGNED (t
))
518 m2pp_print (s
, "unsigned\n");
520 m2pp_print (s
, "signed\n");
524 /* m2pp_var emit a VAR if necessary. */
532 m2pp_print (s
, "VAR\n");
533 setindent (s
, getindent (s
) + 3);
537 /* m2pp_types emit a TYPE if necessary. */
540 m2pp_types (pretty
*s
)
545 m2pp_print (s
, "TYPE\n");
546 setindent (s
, getindent (s
) + 3);
550 /* hextree displays the critical fields for function, block and
551 bind_expr trees in raw hex. */
559 if (TREE_CODE (t
) == BLOCK
)
561 printf ("(* BLOCK %p *)\n", (void *)t
);
562 printf ("BLOCK_VARS (t) = %p\n", (void *)BLOCK_VARS (t
));
563 printf ("BLOCK_SUPERCONTEXT (t) = %p\n",
564 (void *)BLOCK_SUPERCONTEXT (t
));
566 if (TREE_CODE (t
) == BIND_EXPR
)
568 printf ("(* BIND_EXPR %p *)\n", (void *)t
);
569 printf ("BIND_EXPR_VARS (t) = %p\n", (void *)BIND_EXPR_VARS (t
));
570 printf ("BIND_EXPR_BLOCK (t) = %p\n", (void *)BIND_EXPR_BLOCK (t
));
571 printf ("BIND_EXPR_BODY (t) = %p\n", (void *)BIND_EXPR_BODY (t
));
573 if (TREE_CODE (t
) == FUNCTION_DECL
)
575 printf ("(* FUNCTION_DECL %p *)\n", (void *)t
);
576 printf ("DECL_INITIAL (t) = %p\n", (void *)DECL_INITIAL (t
));
577 printf ("DECL_SAVED_TREE (t) = %p\n", (void *)DECL_SAVED_TREE (t
));
578 hextree (DECL_INITIAL (t
));
579 hextree (DECL_SAVED_TREE (t
));
581 if (TREE_CODE (t
) == VAR_DECL
)
583 pretty
*state
= initPretty (FALSE
);
585 printf ("(* VAR_DECL %p <", (void *)t
);
586 if (DECL_SEEN_IN_BIND_EXPR_P (t
))
588 if (DECL_EXTERNAL (t
))
592 printf ("> context = %p*)\n", (void *)decl_function_context (t
));
593 m2pp_type (state
, TREE_TYPE (t
));
594 m2pp_needspace (state
);
595 m2pp_print (state
, ";\n");
598 if (TREE_CODE (t
) == PARM_DECL
)
600 pretty
*state
= initPretty (FALSE
);
602 printf ("(* PARM_DECL %p <", (void *)t
);
603 printf ("> context = %p*)\n", (void *)decl_function_context (t
));
604 m2pp_type (state
, TREE_TYPE (t
));
605 m2pp_needspace (state
);
606 m2pp_print (state
, ";\n");
611 /* translation produce a pseudo implementation module from the tree t. */
614 m2pp_translation (pretty
*s
, tree t
)
616 tree block
= DECL_INITIAL (t
);
618 m2pp_print (s
, "IMPLEMENTATION MODULE ");
619 m2pp_identifier (s
, t
);
620 m2pp_print (s
, "\n\n");
624 m2pp_module_block (s
, block
);
625 m2pp_print (s
, "\n");
628 m2pp_print (s
, "\n");
629 m2pp_print (s
, "END ");
630 m2pp_identifier (s
, t
);
631 m2pp_print (s
, ".\n");
635 m2pp_module_block (pretty
*s
, tree t
)
640 for (; t
!= NULL_TREE
; t
= TREE_CHAIN (t
))
642 switch (TREE_CODE (t
))
645 if (!DECL_EXTERNAL (t
))
647 pretty
*p
= dupPretty (s
);
651 m2pp_function (p
, t
);
661 int o
= getindent (s
);
664 m2pp_print (s
, "\n");
666 setindent (s
, o
+ 3);
667 m2pp_identifier (s
, t
);
668 m2pp_print (s
, " = ");
671 m2pp_type (s
, TREE_TYPE (t
));
674 m2pp_print (s
, ";\n");
681 m2pp_identifier (s
, t
);
685 m2pp_type (s
, TREE_TYPE (t
));
687 m2pp_print (s
, ";\n");
692 printf ("is this node legal here? \n");
693 m2pp_decl_expr (s
, t
);
697 m2pp_unknown (s
, __FUNCTION__
, get_tree_code_name (TREE_CODE (t
)));
702 /* m2pp_begin emit a BEGIN if necessary. */
705 m2pp_begin (pretty
*s
)
707 if (!s
->issued_begin
)
709 if (s
->in_vars
|| s
->in_types
)
711 setindent (s
, getindent (s
) - 3);
712 m2pp_print (s
, "BEGIN\n");
713 setindent (s
, getindent (s
) + 3);
717 m2pp_print (s
, "BEGIN\n");
718 setindent (s
, getindent (s
) + 3);
720 s
->issued_begin
= TRUE
;
726 /* m2pp_function walk over the function. */
729 m2pp_function (pretty
*s
, tree t
)
731 m2pp_function_header (s
, t
);
732 m2pp_function_vars (s
, t
);
733 m2pp_statement_sequence (s
, DECL_SAVED_TREE (t
));
734 if (TREE_CODE (t
) == FUNCTION_DECL
)
737 setindent (s
, getindent (s
) - 3);
738 m2pp_print (s
, "END");
740 m2pp_identifier (s
, t
);
742 m2pp_print (s
, ";\n");
746 /* m2pp_bind_expr displays the bind expr tree node. */
749 m2pp_bind_expr (pretty
*s
, tree t
)
751 if (TREE_CODE (t
) == BIND_EXPR
)
753 if (BIND_EXPR_VARS (t
))
755 m2pp_print (s
, "(* variables in bind_expr *)\n");
757 m2pp_var_list (s
, BIND_EXPR_VARS (t
));
759 if (BIND_EXPR_BLOCK (t
))
761 m2pp_print (s
, "(* bind_expr_block *)\n");
762 m2pp_statement_sequence (s
, BIND_EXPR_BLOCK (t
));
764 m2pp_print (s
, "; \n");
766 m2pp_statement_sequence (s
, BIND_EXPR_BODY (t
));
770 /* m2pp_block_list iterates over the list of blocks. */
773 m2pp_block_list (pretty
*s
, tree t
)
775 for (; t
; t
= BLOCK_CHAIN (t
))
779 /* m2pp_block prints the VARiables and the TYPEs inside a block. */
782 m2pp_block (pretty
*s
, tree t
)
784 if ((BLOCK_VARS (t
) != NULL_TREE
) && (s
->block
!= BLOCK_VARS (t
)))
786 s
->block
= BLOCK_VARS (t
);
787 m2pp_print (s
, "(* block variables *)\n");
789 m2pp_var_list (s
, BLOCK_VARS (t
));
793 /* m2pp_var_type_decl displays the variable and type declaration. */
796 m2pp_var_type_decl (pretty
*s
, tree t
)
798 m2pp_identifier (s
, t
);
802 m2pp_type (s
, TREE_TYPE (t
));
804 m2pp_print (s
, ";\n");
807 /* m2pp_var_list print a variable list. */
810 m2pp_var_list (pretty
*s
, tree t
)
813 for (; t
; t
= TREE_CHAIN (t
))
815 if (TREE_CODE (t
) == FUNCTION_DECL
)
817 pretty
*p
= dupPretty (s
);
821 m2pp_function (p
, t
);
825 else if (TREE_CODE (t
) == TYPE_DECL
)
826 m2pp_identifier (s
, t
);
827 else if (TREE_CODE (t
) == DECL_EXPR
)
829 printf ("is this node legal here? \n");
830 // is it legal to have a DECL_EXPR here ?
831 m2pp_var_type_decl (s
, DECL_EXPR_DECL (t
));
834 m2pp_var_type_decl (s
, t
);
839 /* m2pp_type_list print a variable list. */
842 m2pp_type_list (pretty
*s
, tree t
)
845 for (; t
; t
= TREE_CHAIN (t
))
847 m2pp_identifier (s
, t
);
851 m2pp_type (s
, TREE_TYPE (t
));
853 m2pp_print (s
, ";\n");
858 /* m2pp_needspace sets appropriate flag to TRUE. */
861 m2pp_needspace (pretty
*s
)
863 s
->needs_space
= TRUE
;
866 /* m2pp_identifer prints an identifier. */
869 m2pp_identifier (pretty
*s
, tree t
)
873 if (TREE_CODE (t
) == COMPONENT_REF
)
874 m2pp_component_ref (s
, t
);
875 else if (DECL_NAME (t
) && IDENTIFIER_POINTER (DECL_NAME (t
)))
876 m2pp_ident_pointer (s
, DECL_NAME (t
));
881 if (TREE_CODE (t
) == CONST_DECL
)
882 snprintf (name
, 100, "C_%u", DECL_UID (t
));
884 snprintf (name
, 100, "D_%u", DECL_UID (t
));
885 m2pp_print (s
, name
);
890 /* m2pp_ident_pointer displays an ident pointer. */
893 m2pp_ident_pointer (pretty
*s
, tree t
)
896 m2pp_print (s
, IDENTIFIER_POINTER (t
));
899 /* m2pp_parameter prints out a param decl tree. */
902 m2pp_parameter (pretty
*s
, tree t
)
904 if (TREE_CODE (t
) == PARM_DECL
)
906 if (TREE_TYPE (t
) && (TREE_CODE (TREE_TYPE (t
)) == REFERENCE_TYPE
))
908 m2pp_print (s
, "VAR");
910 m2pp_identifier (s
, t
);
913 m2pp_simple_type (s
, TREE_TYPE (TREE_TYPE (t
)));
917 m2pp_identifier (s
, t
);
920 m2pp_simple_type (s
, TREE_TYPE (t
));
925 /* m2pp_param_type prints out the type of parameter. */
928 m2pp_param_type (pretty
*s
, tree t
)
930 if (t
&& (TREE_CODE (t
) == REFERENCE_TYPE
))
932 m2pp_print (s
, "VAR");
934 m2pp_simple_type (s
, TREE_TYPE (t
));
937 m2pp_simple_type (s
, t
);
940 /* m2pp_procedure_type displays a procedure type. */
943 m2pp_procedure_type (pretty
*s
, tree t
)
946 if (TREE_CODE (t
) == FUNCTION_TYPE
)
948 tree i
= TYPE_ARG_TYPES (t
);
949 tree returnType
= TREE_TYPE (TREE_TYPE (t
));
952 m2pp_print (s
, "PROCEDURE");
956 int o
= getindent (s
);
963 while (i
!= NULL_TREE
)
965 if (TREE_CHAIN (i
) == NULL_TREE
)
967 if (TREE_VALUE (i
) == void_type_node
)
968 /* Ignore void_type_node at the end. */
972 m2pp_param_type (s
, TREE_VALUE (i
));
973 m2pp_print (s
, ", ...");
984 m2pp_param_type (s
, TREE_VALUE (i
));
992 else if (returnType
!= NULL_TREE
)
995 m2pp_print (s
, "()");
997 if (returnType
!= NULL_TREE
)
1000 m2pp_print (s
, ": ");
1001 m2pp_simple_type (s
, returnType
);
1007 /* m2pp_comment_header displays a simple header with some critical
1011 m2pp_comment_header (pretty
*s
, tree t
)
1013 int o
= getindent (s
);
1015 m2pp_print (s
, "(*\n");
1016 setindent (s
, o
+ 3);
1017 m2pp_identifier (s
, t
);
1019 m2pp_print (s
, "-");
1021 if (TREE_PUBLIC (t
))
1024 m2pp_print (s
, "public,");
1026 if (TREE_STATIC (t
))
1029 m2pp_print (s
, "static,");
1031 if (DECL_EXTERNAL (t
))
1034 m2pp_print (s
, "extern");
1036 m2pp_print (s
, "\n");
1038 m2pp_print (s
, "*)\n\n");
1041 /* m2pp_function_header displays the function header. */
1044 m2pp_function_header (pretty
*s
, tree t
)
1047 if (TREE_CODE (t
) == FUNCTION_DECL
)
1049 tree i
= DECL_ARGUMENTS (t
);
1050 tree returnType
= TREE_TYPE (TREE_TYPE (t
));
1052 m2pp_comment_header (s
, t
);
1053 m2pp_print (s
, "PROCEDURE ");
1054 m2pp_identifier (s
, t
);
1058 int o
= getindent (s
);
1061 m2pp_print (s
, "(");
1064 while (i
!= NULL_TREE
)
1066 m2pp_parameter (s
, i
);
1069 m2pp_print (s
, ";\n");
1071 m2pp_print (s
, ")");
1075 else if (returnType
!= void_type_node
)
1077 m2pp_print (s
, "()");
1080 if (returnType
!= void_type_node
)
1082 m2pp_print (s
, ": ");
1083 m2pp_simple_type (s
, returnType
);
1086 m2pp_print (s
, "; ");
1088 m2pp_print (s
, "\n");
1093 /* m2pp_add_var adds a variable into a list as defined by, data. */
1096 m2pp_add_var (tree
*tp
, int *walk_subtrees
, void *data
)
1099 pretty
*s
= (pretty
*)data
;
1100 enum tree_code code
= TREE_CODE (t
);
1102 if (code
== VAR_DECL
)
1105 m2pp_identifier (s
, t
);
1107 m2pp_print (s
, ":");
1109 m2pp_type (s
, TREE_TYPE (t
));
1111 m2pp_print (s
, ";\n");
1113 if (code
== SSA_NAME
)
1117 m2pp_identifier (s
, SSA_NAME_VAR (t
));
1119 m2pp_print (s
, ":");
1121 m2pp_type (s
, TREE_TYPE (t
));
1123 m2pp_print (s
, ";\n");
1130 /* m2pp_function_vars displays variables as defined by the function
1134 m2pp_function_vars (pretty
*s
, tree t
)
1136 walk_tree_without_duplicates (&t
, m2pp_add_var
, s
);
1138 if (TREE_CODE (t
) == FUNCTION_DECL
&& DECL_INITIAL (t
))
1140 m2pp_print (s
, "(* variables in function_decl (decl_initial) *)\n");
1142 m2pp_statement_sequence (s
, DECL_INITIAL (t
));
1146 /* m2pp_print print out a string p interpreting '\n' and
1147 adjusting the fields within state s. */
1150 m2pp_print (pretty
*s
, const char *p
)
1160 s
->needs_space
= FALSE
;
1168 s
->needs_indent
= TRUE
;
1174 if (s
->needs_indent
)
1177 printf ("%*c", s
->indent
, ' ');
1178 s
->needs_indent
= FALSE
;
1179 s
->curpos
+= s
->indent
;
1189 /* m2pp_print_char prints out a character ch obeying needs_space
1190 and needs_indent. */
1193 m2pp_print_char (pretty
*s
, char ch
)
1198 s
->needs_space
= FALSE
;
1201 if (s
->needs_indent
)
1204 printf ("%*c", s
->indent
, ' ');
1205 s
->needs_indent
= FALSE
;
1206 s
->curpos
+= s
->indent
;
1219 /* m2pp_integer display the appropriate integer type. */
1223 m2pp_integer (pretty
*s
, tree t
)
1225 if (t
== m2type_GetM2ZType ())
1226 m2pp_print (s
, "M2ZTYPE");
1227 else if (t
== m2type_GetM2LongIntType ())
1228 m2pp_print (s
, "LONGINT");
1229 else if (t
== m2type_GetM2IntegerType ())
1230 m2pp_print (s
, "INTEGER");
1231 else if (t
== m2type_GetM2ShortIntType ())
1232 m2pp_print (s
, "SHORTINT");
1233 else if (t
== m2type_GetLongIntType ())
1234 m2pp_print (s
, "long int");
1235 else if (t
== m2type_GetIntegerType ())
1236 m2pp_print (s
, "int");
1237 else if (t
== m2type_GetShortIntType ())
1238 m2pp_print (s
, "short");
1239 else if (t
== m2type_GetM2LongCardType ())
1240 m2pp_print (s
, "LONGCARD");
1241 else if (t
== m2type_GetM2CardinalType ())
1242 m2pp_print (s
, "CARDINAL");
1243 else if (t
== m2type_GetM2ShortCardType ())
1244 m2pp_print (s
, "SHORTCARD");
1245 else if (t
== m2type_GetCardinalType ())
1246 m2pp_print (s
, "CARDINAL");
1247 else if (t
== m2type_GetPointerType ())
1248 m2pp_print (s
, "ADDRESS");
1249 else if (t
== m2type_GetByteType ())
1250 m2pp_print (s
, "BYTE");
1251 else if (t
== m2type_GetCharType ())
1252 m2pp_print (s
, "CHAR");
1253 else if (t
== m2type_GetBitsetType ())
1254 m2pp_print (s
, "BITSET");
1255 else if (t
== m2type_GetBitnumType ())
1256 m2pp_print (s
, "BITNUM");
1259 if (TYPE_UNSIGNED (t
))
1260 m2pp_print (s
, "CARDINAL");
1262 m2pp_print (s
, "INTEGER");
1263 m2pp_integer_cst (s
, TYPE_SIZE (t
));
1268 m2pp_integer (pretty
*s
, tree t ATTRIBUTE_UNUSED
)
1270 m2pp_print (s
, "INTEGER");
1274 /* m2pp_complex display the actual complex type. */
1278 m2pp_complex (pretty
*s
, tree t
)
1280 if (t
== m2type_GetM2ComplexType ())
1281 m2pp_print (s
, "COMPLEX");
1282 else if (t
== m2type_GetM2LongComplexType ())
1283 m2pp_print (s
, "LONGCOMPLEX");
1284 else if (t
== m2type_GetM2ShortComplexType ())
1285 m2pp_print (s
, "SHORTCOMPLEX");
1286 else if (t
== m2type_GetM2CType ())
1287 m2pp_print (s
, "C'omplex' type");
1288 else if (t
== m2type_GetM2Complex32 ())
1289 m2pp_print (s
, "COMPLEX32");
1290 else if (t
== m2type_GetM2Complex64 ())
1291 m2pp_print (s
, "COMPLEX64");
1292 else if (t
== m2type_GetM2Complex96 ())
1293 m2pp_print (s
, "COMPLEX96");
1294 else if (t
== m2type_GetM2Complex128 ())
1295 m2pp_print (s
, "COMPLEX128");
1297 m2pp_print (s
, "unknown COMPLEX type");
1303 m2pp_complex (pretty
*s
, tree t ATTRIBUTE_UNUSED
)
1305 m2pp_print (s
, "a COMPLEX type");
1309 /* m2pp_type prints a full type. */
1312 m2pp_type (pretty
*s
, tree t
)
1314 if (begin_printed (t
))
1316 m2pp_print (s
, "<...>");
1319 if ((TREE_CODE (t
) != FIELD_DECL
) && (TREE_CODE (t
) != TYPE_DECL
))
1320 m2pp_gimpified (s
, t
);
1321 switch (TREE_CODE (t
))
1324 m2pp_integer (s
, t
);
1327 m2pp_print (s
, "REAL");
1333 m2pp_union_type (s
, t
);
1336 m2pp_record_type (s
, t
);
1343 m2pp_function_type (s
, t
);
1347 m2pp_identifier (s
, t
);
1350 m2pp_pointer_type (s
, t
);
1354 m2pp_set_type (s
, t
);
1358 m2pp_print (s
, "ADDRESS");
1361 m2pp_complex (s
, t
);
1364 m2pp_unknown (s
, __FUNCTION__
, get_tree_code_name (TREE_CODE (t
)));
1368 /* m2pp_set_type prints out the set type. */
1371 m2pp_set_type (pretty
*s
, tree t
)
1374 m2pp_print (s
, "SET OF");
1376 m2pp_type (s
, TREE_TYPE (t
));
1380 /* m2pp_enum print out the enumeration type. */
1383 m2pp_enum (pretty
*s
, tree t
)
1385 tree chain_p
= TYPE_VALUES (t
);
1388 m2pp_print (s
, "(");
1391 m2pp_ident_pointer (s
, TREE_PURPOSE (chain_p
));
1392 chain_p
= TREE_CHAIN (chain_p
);
1394 m2pp_print (s
, ", ");
1396 m2pp_print (s
, ")");
1400 /* m2pp_array prints out the array type. */
1403 m2pp_array (pretty
*s
, tree t
)
1406 m2pp_print (s
, "ARRAY");
1408 m2pp_subrange (s
, TYPE_DOMAIN (t
));
1410 m2pp_print (s
, "OF");
1412 m2pp_type (s
, TREE_TYPE (t
));
1416 /* m2pp_subrange prints out the subrange, but probably the lower
1417 bound will always be zero. */
1420 m2pp_subrange (pretty
*s
, tree t
)
1422 tree min
= TYPE_MIN_VALUE (t
);
1423 tree max
= TYPE_MAX_VALUE (t
);
1425 m2pp_print (s
, "[");
1426 m2pp_expression (s
, min
);
1427 m2pp_print (s
, "..");
1428 m2pp_expression (s
, max
);
1429 m2pp_print (s
, "]");
1432 /* m2pp_gimplified print out a gimplified comment. */
1435 m2pp_gimpified (pretty
*s
, tree t
)
1437 if (!TYPE_SIZES_GIMPLIFIED (t
))
1439 m2pp_print (s
, "(* <!g> *)");
1444 /* m2pp_printer_type display the pointer type. */
1447 m2pp_pointer_type (pretty
*s
, tree t
)
1450 if (TREE_CODE (t
) == POINTER_TYPE
)
1452 if (TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
1453 m2pp_procedure_type (s
, TREE_TYPE (t
));
1454 else if (t
== ptr_type_node
)
1455 m2pp_print (s
, "ADDRESS");
1458 m2pp_print (s
, "POINTER TO");
1460 m2pp_type (s
, TREE_TYPE (t
));
1466 /* m2pp_record_alignment prints out whether this record is aligned
1470 m2pp_record_alignment (pretty
*s
, tree t
)
1472 if (TYPE_PACKED (t
))
1473 m2pp_print (s
, "<* bytealignment (0) *>\n");
1477 m2pp_getaligned (tree t
)
1481 if (DECL_USER_ALIGN (t
))
1482 return DECL_ALIGN (t
);
1484 else if (TYPE_P (t
))
1486 if (TYPE_USER_ALIGN (t
))
1487 return TYPE_ALIGN (t
);
1493 m2pp_recordfield_alignment (pretty
*s
, tree t
)
1495 unsigned int aligned
= m2pp_getaligned (t
);
1499 int o
= getindent (s
);
1500 int p
= getcurpos (s
);
1502 m2pp_print (s
, "<* bytealignment (");
1503 setindent (s
, p
+ 18);
1505 printf ("%d", aligned
/ BITS_PER_UNIT
);
1507 m2pp_print (s
, ")");
1510 m2pp_print (s
, "*>");
1516 m2pp_recordfield_bitfield (pretty
*s
, tree t
)
1518 if ((TREE_CODE (t
) == FIELD_DECL
) && DECL_PACKED (t
))
1520 m2pp_print (s
, " (* packed");
1521 if (DECL_NONADDRESSABLE_P (t
))
1522 m2pp_print (s
, ", non-addressible");
1523 if (DECL_BIT_FIELD (t
))
1524 m2pp_print (s
, ", bit-field");
1525 m2pp_print (s
, ", offset: ");
1526 m2pp_expression (s
, DECL_FIELD_OFFSET (t
));
1527 m2pp_print (s
, ", bit offset:");
1528 m2pp_expression (s
, DECL_FIELD_BIT_OFFSET (t
));
1529 m2pp_print (s
, " *) ");
1533 /* m2pp_record_type displays the record type. */
1536 m2pp_record_type (pretty
*s
, tree t
)
1539 if (TREE_CODE (t
) == RECORD_TYPE
)
1542 int o
= getindent (s
);
1543 int p
= getcurpos (s
);
1545 m2pp_print (s
, "RECORD\n");
1546 setindent (s
, p
+ 3);
1547 m2pp_record_alignment (s
, t
);
1548 for (i
= TYPE_FIELDS (t
); i
!= NULL_TREE
; i
= TREE_CHAIN (i
))
1550 m2pp_identifier (s
, i
);
1551 m2pp_print (s
, " : ");
1552 m2pp_type (s
, TREE_TYPE (i
));
1553 m2pp_recordfield_bitfield (s
, i
);
1554 m2pp_recordfield_alignment (s
, i
);
1555 m2pp_print (s
, ";\n");
1558 m2pp_print (s
, "END");
1564 /* m2pp_record_type displays the record type. */
1567 m2pp_union_type (pretty
*s
, tree t
)
1570 if (TREE_CODE (t
) == UNION_TYPE
)
1573 int o
= getindent (s
);
1574 int p
= getcurpos (s
);
1576 m2pp_print (s
, "CASE .. OF\n");
1577 setindent (s
, p
+ 3);
1578 m2pp_record_alignment (s
, t
);
1579 for (i
= TYPE_FIELDS (t
); i
!= NULL_TREE
; i
= TREE_CHAIN (i
))
1581 m2pp_identifier (s
, i
);
1582 m2pp_print (s
, " : ");
1583 m2pp_type (s
, TREE_TYPE (i
));
1584 m2pp_recordfield_bitfield (s
, i
);
1585 m2pp_print (s
, ";\n");
1588 m2pp_print (s
, "END");
1594 /* m2pp_simple_type. */
1597 m2pp_simple_type (pretty
*s
, tree t
)
1599 if (begin_printed (t
))
1601 m2pp_print (s
, "<...>");
1605 m2pp_gimpified (s
, t
);
1606 switch (TREE_CODE (t
))
1609 m2pp_integer (s
, t
);
1612 m2pp_print (s
, "REAL");
1615 m2pp_print (s
, "BOOLEAN");
1618 m2pp_print (s
, "ADDRESS");
1621 m2pp_identifier (s
, t
);
1624 m2pp_pointer_type (s
, t
);
1627 m2pp_record_type (s
, t
);
1630 m2pp_union_type (s
, t
);
1636 m2pp_complex (s
, t
);
1639 m2pp_unknown (s
, __FUNCTION__
, get_tree_code_name (TREE_CODE (t
)));
1643 /* m2pp_expression display an expression. */
1646 m2pp_expression (pretty
*s
, tree t
)
1648 enum tree_code code
= TREE_CODE (t
);
1653 m2pp_relop (s
, t
, "=");
1656 m2pp_relop (s
, t
, "#");
1659 m2pp_relop (s
, t
, "<=");
1662 m2pp_relop (s
, t
, ">=");
1665 m2pp_relop (s
, t
, "<");
1668 m2pp_relop (s
, t
, ">");
1671 m2pp_simple_expression (s
, t
);
1675 /* m2pp_relop displays the lhs relop rhs. */
1678 m2pp_relop (pretty
*s
, tree t
, const char *p
)
1680 m2pp_expression (s
, TREE_OPERAND (t
, 0));
1684 m2pp_expression (s
, TREE_OPERAND (t
, 1));
1687 /* m2pp_compound_expression handle compound expression tree. */
1690 m2pp_compound_expression (pretty
*s
, tree t
)
1692 m2pp_print (s
, "compound expression {");
1693 m2pp_expression (s
, TREE_OPERAND (t
, 0));
1694 m2pp_print (s
, " (* result ignored *), ");
1695 m2pp_expression (s
, TREE_OPERAND (t
, 1));
1696 m2pp_print (s
, "}");
1700 /* m2pp_target_expression handle target expression tree. */
1703 m2pp_target_expression (pretty
*s
, tree t
)
1705 m2pp_print (s
, "{");
1707 if (TREE_OPERAND (t
, 0) != NULL_TREE
)
1709 m2pp_print (s
, "(* target *) ");
1710 m2pp_expression (s
, TREE_OPERAND (t
, 0));
1711 m2pp_print (s
, ",");
1714 if (TREE_OPERAND (t
, 1) != NULL_TREE
)
1716 m2pp_print (s
, "(* initializer *) ");
1717 m2pp_expression (s
, TREE_OPERAND (t
, 1));
1718 m2pp_print (s
, ",");
1721 if (TREE_OPERAND (t
, 2) != NULL_TREE
)
1723 m2pp_print (s
, "(* cleanup *) ");
1724 m2pp_expression (s
, TREE_OPERAND (t
, 2));
1725 m2pp_print (s
, ",");
1728 if (TREE_OPERAND (t
, 3) != NULL_TREE
)
1730 m2pp_print (s
, "(* saved initializer *) ");
1731 m2pp_expression (s
, TREE_OPERAND (t
, 3));
1732 m2pp_print (s
, ",");
1735 m2pp_print (s
, "}");
1739 /* m2pp_constructor print out a constructor. */
1742 m2pp_constructor (pretty
*s
, tree t
)
1744 tree purpose
, value
;
1745 unsigned HOST_WIDE_INT ix
;
1747 m2pp_print (s
, "{ ");
1748 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t
), ix
, purpose
, value
)
1750 m2pp_print (s
, "(index: ");
1751 m2pp_simple_expression (s
, purpose
);
1752 m2pp_print (s
, ") ");
1753 m2pp_simple_expression (s
, value
);
1754 m2pp_print (s
, ", ");
1756 m2pp_print (s
, "}");
1757 m2pp_print (s
, "(* type: ");
1758 setindent (s
, getindent (s
) + 8);
1759 m2pp_type (s
, TREE_TYPE (t
));
1760 setindent (s
, getindent (s
) - 8);
1761 m2pp_print (s
, " *)\n");
1764 /* m2pp_complex_expr handle GCC complex_expr tree. */
1767 m2pp_complex_expr (pretty
*s
, tree t
)
1769 if (TREE_CODE (t
) == COMPLEX_CST
)
1771 m2pp_print (s
, "CMPLX(");
1773 m2pp_expression (s
, TREE_REALPART (t
));
1774 m2pp_print (s
, ",");
1776 m2pp_expression (s
, TREE_IMAGPART (t
));
1777 m2pp_print (s
, ")");
1781 m2pp_print (s
, "CMPLX(");
1783 m2pp_expression (s
, TREE_OPERAND (t
, 0));
1784 m2pp_print (s
, ",");
1786 m2pp_expression (s
, TREE_OPERAND (t
, 1));
1787 m2pp_print (s
, ")");
1791 /* m2pp_imagpart_expr handle imagpart_expr tree. */
1794 m2pp_imagpart_expr (pretty
*s
, tree t
)
1796 m2pp_print (s
, "IM(");
1798 if (TREE_CODE (t
) == IMAGPART_EXPR
)
1799 m2pp_expression (s
, TREE_OPERAND (t
, 0));
1800 else if (TREE_CODE (t
) == COMPLEX_CST
)
1801 m2pp_expression (s
, TREE_IMAGPART (t
));
1803 m2pp_print (s
, ")");
1806 /* m2pp_realpart_expr handle imagpart_expr tree. */
1809 m2pp_realpart_expr (pretty
*s
, tree t
)
1811 m2pp_print (s
, "RE(");
1813 if (TREE_CODE (t
) == REALPART_EXPR
)
1814 m2pp_expression (s
, TREE_OPERAND (t
, 0));
1815 else if (TREE_CODE (t
) == COMPLEX_CST
)
1816 m2pp_expression (s
, TREE_REALPART (t
));
1818 m2pp_print (s
, ")");
1821 /* m2pp_bit_ior_expr generate a C style bit or. */
1824 m2pp_bit_ior_expr (pretty
*s
, tree t
)
1826 m2pp_binary (s
, t
, "|");
1829 /* m2pp_truth_expr. */
1832 m2pp_truth_expr (pretty
*s
, tree t
, const char *op
)
1834 m2pp_print (s
, "(");
1835 m2pp_expression (s
, TREE_OPERAND (t
, 0));
1836 m2pp_print (s
, ")");
1840 m2pp_print (s
, "(");
1841 m2pp_expression (s
, TREE_OPERAND (t
, 1));
1842 m2pp_print (s
, ")");
1845 /* m2pp_simple_expression handle GCC expression tree. */
1848 m2pp_simple_expression (pretty
*s
, tree t
)
1850 enum tree_code code
= TREE_CODE (t
);
1855 m2pp_print (s
, "(* !!! ERROR NODE !!! *)");
1858 m2pp_constructor (s
, t
);
1860 case IDENTIFIER_NODE
:
1861 m2pp_ident_pointer (s
, t
);
1864 m2pp_identifier (s
, t
);
1867 m2pp_identifier (s
, t
);
1873 m2pp_print (s
, "(* BLOCK NODE *)");
1879 m2pp_integer_cst (s
, t
);
1882 m2pp_real_cst (s
, t
);
1885 m2pp_string_cst (s
, t
);
1888 m2pp_indirect_ref (s
, t
);
1891 m2pp_addr_expr (s
, t
);
1897 m2pp_convert (s
, t
);
1900 m2pp_var_decl (s
, t
);
1903 m2pp_result_decl (s
, t
);
1906 m2pp_binary (s
, t
, "+");
1909 m2pp_binary (s
, t
, "-");
1912 m2pp_binary (s
, t
, "*");
1914 case FLOOR_DIV_EXPR
:
1916 case TRUNC_DIV_EXPR
:
1917 case ROUND_DIV_EXPR
:
1918 m2pp_binary (s
, t
, "DIV");
1920 case FLOOR_MOD_EXPR
:
1922 case TRUNC_MOD_EXPR
:
1923 case ROUND_MOD_EXPR
:
1924 m2pp_binary (s
, t
, "MOD");
1927 m2pp_unary (s
, t
, "-");
1930 m2pp_call_expr (s
, t
);
1936 m2pp_component_ref (s
, t
);
1939 m2pp_return_expr (s
, t
);
1942 m2pp_array_ref (s
, t
);
1944 case NON_LVALUE_EXPR
:
1945 m2pp_non_lvalue_expr (s
, t
);
1948 m2pp_expression (s
, EXPR_STMT_EXPR (t
));
1952 m2pp_print (s
, "GCC_EXCEPTION_OBJECT");
1957 m2pp_assignment (s
, t
);
1960 m2pp_compound_expression (s
, t
);
1963 m2pp_target_expression (s
, t
);
1969 m2pp_identifier (s
, t
);
1972 m2pp_complex_expr (s
, t
);
1975 m2pp_realpart_expr (s
, t
);
1978 m2pp_imagpart_expr (s
, t
);
1981 m2pp_identifier (s
, t
);
1983 case POINTER_PLUS_EXPR
:
1984 m2pp_binary (s
, t
, "+");
1986 case CLEANUP_POINT_EXPR
:
1987 m2pp_cleanup_point_expr (s
, t
);
1990 m2pp_bit_ior_expr (s
, t
);
1992 case TRUTH_ANDIF_EXPR
:
1993 m2pp_truth_expr (s
, t
, "AND");
1995 case TRUTH_ORIF_EXPR
:
1996 m2pp_truth_expr (s
, t
, "OR");
1999 m2pp_unknown (s
, __FUNCTION__
, get_tree_code_name (code
));
2003 /* non_lvalue_expr indicates that operand 0 is not an lvalue. */
2006 m2pp_non_lvalue_expr (pretty
*s
, tree t
)
2009 m2pp_print (s
, "assert_non_lvalue(");
2011 m2pp_expression (s
, TREE_OPERAND (t
, 0));
2013 m2pp_print (s
, ")");
2016 /* m2pp_array_ref prints out the array reference. */
2019 m2pp_array_ref (pretty
*s
, tree t
)
2021 m2pp_expression (s
, TREE_OPERAND (t
, 0));
2022 m2pp_print (s
, "[");
2023 m2pp_expression (s
, TREE_OPERAND (t
, 1));
2024 m2pp_print (s
, "]");
2027 /* m2pp_ssa prints out the ssa variable name. */
2030 m2pp_ssa (pretty
*s
, tree t
)
2032 m2pp_identifier (s
, SSA_NAME_VAR (t
));
2035 /* m2pp_binary print the binary operator, p, and lhs, rhs. */
2038 m2pp_binary (pretty
*s
, tree t
, const char *p
)
2040 tree left
= TREE_OPERAND (t
, 0);
2041 tree right
= TREE_OPERAND (t
, 1);
2043 m2pp_expression (s
, left
);
2047 m2pp_expression (s
, right
);
2050 /* m2pp_unary print the unary operator, p, and expression. */
2053 m2pp_unary (pretty
*s
, tree t
, const char *p
)
2055 tree expr
= TREE_OPERAND (t
, 0);
2059 m2pp_expression (s
, expr
);
2062 /* m2pp_integer_cst displays the integer constant. */
2065 m2pp_integer_cst (pretty
*s
, tree t
)
2069 snprintf (val
, 100, "%lud", TREE_INT_CST_LOW (t
));
2070 m2pp_print (s
, val
);
2073 /* m2pp_real_cst displays the real constant. */
2076 m2pp_real_cst (pretty
*s
, tree t ATTRIBUTE_UNUSED
)
2078 m2pp_print (s
, "<unknown real>");
2081 /* m2pp_string_cst displays the real constant. */
2084 m2pp_string_cst (pretty
*s
, tree t
)
2086 const char *p
= TREE_STRING_POINTER (t
);
2089 m2pp_print (s
, "\"");
2090 while (p
[i
] != '\0')
2092 m2pp_print_char (s
, p
[i
]);
2095 m2pp_print (s
, "\"");
2098 /* m2pp_statement_sequence iterates over a statement list
2099 displaying each statement in turn. */
2102 m2pp_statement_sequence (pretty
*s
, tree t
)
2106 if (TREE_CODE (t
) == STATEMENT_LIST
)
2108 tree_stmt_iterator i
;
2109 m2pp_print (s
, "(* statement list *)\n");
2111 for (i
= tsi_start (t
); !tsi_end_p (i
); tsi_next (&i
))
2112 m2pp_statement (s
, *tsi_stmt_ptr (i
));
2115 m2pp_statement (s
, t
);
2119 /* m2pp_unknown displays an error message. */
2122 m2pp_unknown (pretty
*s
, const char *s1
, const char *s2
)
2131 /* m2pp_throw displays a throw statement. */
2134 m2pp_throw (pretty
*s
, tree t
)
2136 tree expr
= TREE_OPERAND (t
, 0);
2139 if (expr
== NULL_TREE
)
2140 m2pp_print (s
, "THROW ;\n");
2143 m2pp_print (s
, "THROW (");
2144 m2pp_expression (s
, TREE_OPERAND (t
, 0));
2145 m2pp_print (s
, ")\n");
2149 /* m2pp_catch_expr attempts to reconstruct a catch expr. */
2152 m2pp_catch_expr (pretty
*s
, tree t
)
2154 tree types
= CATCH_TYPES (t
);
2155 tree body
= CATCH_BODY (t
);
2157 m2pp_print (s
, "(* CATCH expression ");
2158 if (types
!= NULL_TREE
)
2160 m2pp_print (s
, "(");
2161 m2pp_expression (s
, types
);
2162 m2pp_print (s
, ")");
2164 m2pp_print (s
, "*)\n");
2165 m2pp_print (s
, "(* catch body *)\n");
2166 m2pp_statement_sequence (s
, body
);
2167 m2pp_print (s
, "(* end catch body *)\n");
2170 /* m2pp_try_finally_expr attemts to reconstruct a try finally expr. */
2173 m2pp_try_finally_expr (pretty
*s
, tree t
)
2176 m2pp_print (s
, "(* try_finally_expr *)\n");
2177 setindent (s
, getindent (s
) + 3);
2178 m2pp_statement_sequence (s
, TREE_OPERAND (t
, 0));
2179 setindent (s
, getindent (s
) - 3);
2181 "(* finally (cleanup which is executed after the above) *)\n");
2182 setindent (s
, getindent (s
) + 3);
2183 m2pp_statement_sequence (s
, TREE_OPERAND (t
, 1));
2184 setindent (s
, getindent (s
) - 3);
2185 m2pp_print (s
, "(* end try_finally_expr *)\n");
2189 /* m2pp_if_stmt pretty print a C++ if_stmt. */
2192 m2pp_if_stmt (pretty
*s
, tree t
)
2194 m2pp_print (s
, "(* only C++ uses if_stmt nodes *)\n");
2195 m2pp_print (s
, "IF ");
2196 m2pp_expression (s
, TREE_OPERAND (t
, 0));
2197 m2pp_print (s
, "\n");
2198 m2pp_print (s
, "THEN\n");
2199 setindent (s
, getindent (s
) + 3);
2200 m2pp_statement_sequence (s
, TREE_OPERAND (t
, 1));
2201 setindent (s
, getindent (s
) - 3);
2202 m2pp_print (s
, "ELSE\n");
2203 setindent (s
, getindent (s
) + 3);
2204 m2pp_statement_sequence (s
, TREE_OPERAND (t
, 2));
2205 setindent (s
, getindent (s
) - 3);
2206 m2pp_print (s
, "END\n");
2210 /* m2pp_statement attempts to reconstruct a statement. */
2213 m2pp_statement (pretty
*s
, tree t
)
2215 enum tree_code code
= TREE_CODE (t
);
2221 m2pp_conditional (s
, t
);
2224 m2pp_label_expr (s
, t
);
2227 m2pp_label_decl (s
, t
);
2234 m2pp_assignment (s
, t
);
2237 m2pp_procedure_call (s
, t
);
2240 m2pp_block_list (s
, t
);
2243 m2pp_bind_expr (s
, t
);
2246 m2pp_return_expr (s
, t
);
2249 m2pp_decl_expr (s
, t
);
2252 m2pp_try_block (s
, t
);
2255 m2pp_handler (s
, t
);
2257 case CLEANUP_POINT_EXPR
:
2258 m2pp_cleanup_point_expr (s
, t
);
2263 case TRY_CATCH_EXPR
:
2264 m2pp_try_catch_expr (s
, t
);
2266 case TRY_FINALLY_EXPR
:
2267 m2pp_try_finally_expr (s
, t
);
2270 m2pp_catch_expr (s
, t
);
2274 m2pp_if_stmt (s
, t
);
2278 m2pp_print (s
, "<ERROR CODE>\n");
2281 m2pp_unknown (s
, __FUNCTION__
, get_tree_code_name (TREE_CODE (t
)));
2285 /* m2pp_try_catch_expr is used after gimplification. */
2288 m2pp_try_catch_expr (pretty
*s
, tree t
)
2290 m2pp_print (s
, "(* try_catch_expr begins *)\n");
2291 m2pp_statement_sequence (s
, TREE_OPERAND (t
, 0));
2293 m2pp_print (s
, "EXCEPT\n");
2295 m2pp_statement_sequence (s
, TREE_OPERAND (t
, 1));
2296 m2pp_print (s
, "(* try_catch_expr ends *)\n");
2299 /* m2pp_cleanup_point_expr emits a comment indicating a GCC
2300 cleanup_point_expr is present. */
2303 m2pp_cleanup_point_expr (pretty
*s
, tree t
)
2306 m2pp_print (s
, "(* cleanup point begins *)\n");
2307 m2pp_expression (s
, TREE_OPERAND (t
, 0));
2308 m2pp_print (s
, "(* cleanup point ends *)\n");
2311 /* m2pp_decl_expr displays a local declaration. */
2314 m2pp_decl_expr (pretty
*s
, tree t
)
2317 m2pp_print (s
, "(* variable in decl_expr *)\n");
2318 m2pp_var_type_decl (s
, DECL_EXPR_DECL (t
));
2321 /* m2pp_procedure_call print a call to a procedure. */
2324 m2pp_procedure_call (pretty
*s
, tree t
)
2327 m2pp_call_expr (s
, t
);
2329 m2pp_print (s
, ";\n");
2332 /* args displays each argument in an iter list by calling expression. */
2335 m2pp_args (pretty
*s
, tree e
)
2337 call_expr_arg_iterator iter
;
2340 m2pp_print (s
, "(");
2342 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, e
)
2344 m2pp_expression (s
, arg
);
2345 if (more_call_expr_args_p (&iter
))
2347 m2pp_print (s
, ",");
2351 m2pp_print (s
, ")");
2354 /* m2pp_call_expr print a call to a procedure or function. */
2357 m2pp_call_expr (pretty
*s
, tree t
)
2359 tree call
= CALL_EXPR_FN (t
);
2360 tree args
= TREE_OPERAND (t
, 1);
2361 tree type
= TREE_TYPE (t
);
2362 int has_return_type
= TRUE
;
2365 if (type
&& (TREE_CODE (type
) == VOID_TYPE
))
2366 has_return_type
= FALSE
;
2368 if (TREE_CODE (call
) == ADDR_EXPR
|| TREE_CODE (call
) == NON_LVALUE_EXPR
)
2369 proc
= TREE_OPERAND (call
, 0);
2373 m2pp_expression (s
, proc
);
2374 if (args
|| has_return_type
)
2378 /* m2pp_return_expr displays the return statement. */
2381 m2pp_return_expr (pretty
*s
, tree t
)
2383 tree e
= TREE_OPERAND (t
, 0);
2388 m2pp_print (s
, "RETURN");
2390 else if (TREE_CODE (e
) == MODIFY_EXPR
|| (TREE_CODE (e
) == INIT_EXPR
))
2392 m2pp_assignment (s
, e
);
2393 m2pp_print (s
, "RETURN");
2395 m2pp_expression (s
, TREE_OPERAND (e
, 0));
2399 m2pp_print (s
, "RETURN");
2401 m2pp_expression (s
, e
);
2404 m2pp_print (s
, ";\n");
2407 /* m2pp_try_block displays the try block. */
2410 m2pp_try_block (pretty
*s
, tree t
)
2412 tree stmts
= TRY_STMTS (t
);
2413 tree handlers
= TRY_HANDLERS (t
);
2416 m2pp_print (s
, "(* TRY *)\n");
2417 m2pp_statement_sequence (s
, stmts
);
2419 m2pp_print (s
, "EXCEPT\n");
2421 m2pp_statement_sequence (s
, handlers
);
2422 m2pp_print (s
, "(* END TRY *)\n");
2425 /* m2pp_try_block displays the handler block. */
2428 m2pp_handler (pretty
*s
, tree t
)
2430 tree parms
= HANDLER_PARMS (t
);
2431 tree body
= HANDLER_BODY (t
);
2432 tree type
= HANDLER_TYPE (t
);
2434 m2pp_print (s
, "(* handler *)\n");
2435 if (parms
!= NULL_TREE
)
2437 m2pp_print (s
, "(* handler parameter has a type (should be NULL_TREE) "
2438 "in Modula-2 *)\n");
2439 m2pp_print (s
, "CATCH (");
2440 m2pp_expression (s
, parms
);
2441 m2pp_print (s
, ")\n");
2443 if (type
!= NULL_TREE
)
2444 m2pp_print (s
, "(* handler type (should be NULL_TREE) in Modula-2 *)\n");
2445 m2pp_statement_sequence (s
, body
);
2448 /* m2pp_assignment prints out the assignment statement. */
2451 m2pp_assignment (pretty
*s
, tree t
)
2456 m2pp_designator (s
, TREE_OPERAND (t
, 0));
2458 m2pp_print (s
, ":=");
2461 setindent (s
, getcurpos (s
) + 1);
2462 m2pp_expression (s
, TREE_OPERAND (t
, 1));
2464 m2pp_print (s
, ";\n");
2468 /* m2pp_designator displays the lhs of an assignment. */
2471 m2pp_designator (pretty
*s
, tree t
)
2473 m2pp_expression (s
, t
);
2476 /* m2pp_indirect_ref displays the indirect operator. */
2479 m2pp_indirect_ref (pretty
*s
, tree t
)
2481 m2pp_print (s
, "(");
2482 m2pp_expression (s
, TREE_OPERAND (t
, 0));
2483 m2pp_print (s
, ")^");
2486 /* m2pp_conditional builds an IF THEN ELSE END. With more work
2487 this should be moved into statement sequence which could look for
2488 repeat and while loops. */
2491 m2pp_conditional (pretty
*s
, tree t
)
2496 m2pp_print (s
, "IF");
2498 m2pp_expression (s
, TREE_OPERAND (t
, 0));
2499 m2pp_print (s
, "\nTHEN\n");
2501 setindent (s
, o
+ 3);
2502 m2pp_statement_sequence (s
, TREE_OPERAND (t
, 1));
2504 if (TREE_OPERAND (t
, 2) != NULL_TREE
)
2506 m2pp_print (s
, "ELSE\n");
2507 setindent (s
, o
+ 3);
2508 m2pp_statement_sequence (s
, TREE_OPERAND (t
, 2));
2511 m2pp_print (s
, "END ;\n");
2514 /* m2pp_label_decl displays a label. Again should be moved into
2515 statement sequence to determine proper loop constructs. */
2518 m2pp_label_decl (pretty
*s
, tree t
)
2521 m2pp_print (s
, "(* label ");
2522 m2pp_identifier (s
, t
);
2523 m2pp_print (s
, ": *)\n");
2526 /* m2pp_label_expr skips the LABEL_EXPR to find the LABEL_DECL. */
2529 m2pp_label_expr (pretty
*s
, tree t
)
2532 m2pp_statement (s
, TREE_OPERAND (t
, 0));
2535 /* m2pp_goto displays a goto statement. Again should be moved into
2536 statement sequence to determine proper loop constructs. */
2539 m2pp_goto (pretty
*s
, tree t
)
2542 m2pp_print (s
, "(* goto ");
2543 m2pp_identifier (s
, TREE_OPERAND (t
, 0));
2544 m2pp_print (s
, " *)\n");
2547 /* m2pp_list prints a TREE_CHAINed list. */
2550 m2pp_list (pretty
*s
, tree t
)
2554 m2pp_print (s
, "(");
2556 while (t
!= NULL_TREE
)
2558 m2pp_expression (s
, TREE_VALUE (t
));
2560 if (t
== u
|| t
== NULL_TREE
)
2562 m2pp_print (s
, ",");
2566 m2pp_print (s
, ")");
2569 /* m2pp_offset displays the offset operator. */
2572 m2pp_offset (pretty
*s
, tree t
)
2574 tree type
= TREE_TYPE (t
);
2575 tree base
= TYPE_OFFSET_BASETYPE (t
);
2577 m2pp_print (s
, "OFFSET (");
2578 m2pp_type (s
, base
);
2579 m2pp_print (s
, ".");
2580 m2pp_type (s
, type
);
2581 m2pp_print (s
, ")");
2584 /* m2pp_addr_expr create an ADR expression. */
2587 m2pp_addr_expr (pretty
*s
, tree t
)
2590 m2pp_print (s
, "ADR (");
2591 m2pp_expression (s
, TREE_OPERAND (t
, 0));
2592 m2pp_print (s
, ")");
2595 /* m2pp_nop generate a CAST expression. */
2598 m2pp_nop (pretty
*s
, tree t
)
2601 m2pp_print (s
, "CAST (");
2602 m2pp_simple_type (s
, TREE_TYPE (t
));
2603 m2pp_print (s
, ", ");
2604 m2pp_expression (s
, TREE_OPERAND (t
, 0));
2605 m2pp_print (s
, ")");
2608 /* m2pp_convert generate a CONVERT expression. */
2611 m2pp_convert (pretty
*s
, tree t
)
2614 m2pp_print (s
, "CONVERT (");
2615 m2pp_simple_type (s
, TREE_TYPE (t
));
2616 m2pp_print (s
, ", ");
2617 m2pp_expression (s
, TREE_OPERAND (t
, 0));
2618 m2pp_print (s
, ")");
2621 /* m2pp_var_decl generate a variable. */
2624 m2pp_var_decl (pretty
*s
, tree t
)
2626 m2pp_identifier (s
, t
);
2629 /* m2pp_result_decl generate a result declaration (variable). */
2632 m2pp_result_decl (pretty
*s
, tree t
)
2634 m2pp_identifier (s
, t
);
2637 /* m2pp_component_ref generate a record field access. */
2640 m2pp_component_ref (pretty
*s
, tree t
)
2642 m2pp_simple_expression (s
, TREE_OPERAND (t
, 0));
2643 m2pp_print (s
, ".");
2644 m2pp_simple_expression (s
, TREE_OPERAND (t
, 1));