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)
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 modula2::pf(func), or to be called from code. */
194 /* pe print expression. Expected to be printed interactively from
195 the debugger: print modula2::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 modula2::pet(expr), or to
210 be called from code. */
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);
551 /* hextree displays the critical fields for function, block and
552 bind_expr trees in raw hex. */
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
));
584 pretty
*state
= initPretty (FALSE
);
586 printf ("(* VAR_DECL %p <", (void *)t
);
587 if (DECL_SEEN_IN_BIND_EXPR_P (t
))
589 if (DECL_EXTERNAL (t
))
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");
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");
613 /* translation produce a pseudo implementation module from the tree t. */
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");
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");
637 m2pp_module_block (pretty
*s
, tree t
)
642 for (; t
!= NULL_TREE
; t
= TREE_CHAIN (t
))
644 switch (TREE_CODE (t
))
647 if (!DECL_EXTERNAL (t
))
649 pretty
*p
= dupPretty (s
);
653 m2pp_function (p
, t
);
663 int o
= getindent (s
);
666 m2pp_print (s
, "\n");
668 setindent (s
, o
+ 3);
669 m2pp_identifier (s
, t
);
670 m2pp_print (s
, " = ");
673 m2pp_type (s
, TREE_TYPE (t
));
676 m2pp_print (s
, ";\n");
683 m2pp_identifier (s
, t
);
687 m2pp_type (s
, TREE_TYPE (t
));
689 m2pp_print (s
, ";\n");
694 printf ("is this node legal here? \n");
695 m2pp_decl_expr (s
, t
);
699 m2pp_unknown (s
, __FUNCTION__
, get_tree_code_name (TREE_CODE (t
)));
704 /* m2pp_begin emit a BEGIN if necessary. */
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);
719 m2pp_print (s
, "BEGIN\n");
720 setindent (s
, getindent (s
) + 3);
722 s
->issued_begin
= TRUE
;
728 /* m2pp_function walk over the function. */
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
)
739 setindent (s
, getindent (s
) - 3);
740 m2pp_print (s
, "END");
742 m2pp_identifier (s
, t
);
744 m2pp_print (s
, ";\n");
748 /* m2pp_bind_expr displays the bind expr tree node. */
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");
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
));
766 m2pp_print (s
, "; \n");
768 m2pp_statement_sequence (s
, BIND_EXPR_BODY (t
));
772 /* m2pp_block_list iterates over the list of blocks. */
775 m2pp_block_list (pretty
*s
, tree t
)
777 for (; t
; t
= BLOCK_CHAIN (t
))
781 /* m2pp_block prints the VARiables and the TYPEs inside a block. */
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");
791 m2pp_var_list (s
, BLOCK_VARS (t
));
795 /* m2pp_var_type_decl displays the variable and type declaration. */
798 m2pp_var_type_decl (pretty
*s
, tree t
)
800 m2pp_identifier (s
, t
);
804 m2pp_type (s
, TREE_TYPE (t
));
806 m2pp_print (s
, ";\n");
809 /* m2pp_var_list print a variable list. */
812 m2pp_var_list (pretty
*s
, tree t
)
815 for (; t
; t
= TREE_CHAIN (t
))
817 if (TREE_CODE (t
) == FUNCTION_DECL
)
819 pretty
*p
= dupPretty (s
);
823 m2pp_function (p
, t
);
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
));
836 m2pp_var_type_decl (s
, t
);
841 /* m2pp_type_list print a variable list. */
844 m2pp_type_list (pretty
*s
, tree t
)
847 for (; t
; t
= TREE_CHAIN (t
))
849 m2pp_identifier (s
, t
);
853 m2pp_type (s
, TREE_TYPE (t
));
855 m2pp_print (s
, ";\n");
860 /* m2pp_needspace sets appropriate flag to TRUE. */
863 m2pp_needspace (pretty
*s
)
865 s
->needs_space
= TRUE
;
868 /* m2pp_identifer prints an identifier. */
871 m2pp_identifier (pretty
*s
, tree 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
));
883 if (TREE_CODE (t
) == CONST_DECL
)
884 snprintf (name
, 100, "C_%u", DECL_UID (t
));
886 snprintf (name
, 100, "D_%u", DECL_UID (t
));
887 m2pp_print (s
, name
);
892 /* m2pp_ident_pointer displays an ident pointer. */
895 m2pp_ident_pointer (pretty
*s
, tree t
)
898 m2pp_print (s
, IDENTIFIER_POINTER (t
));
901 /* m2pp_parameter prints out a param decl tree. */
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");
912 m2pp_identifier (s
, t
);
915 m2pp_simple_type (s
, TREE_TYPE (TREE_TYPE (t
)));
919 m2pp_identifier (s
, t
);
922 m2pp_simple_type (s
, TREE_TYPE (t
));
927 /* m2pp_param_type prints out the type of parameter. */
930 m2pp_param_type (pretty
*s
, tree t
)
932 if (t
&& (TREE_CODE (t
) == REFERENCE_TYPE
))
934 m2pp_print (s
, "VAR");
936 m2pp_simple_type (s
, TREE_TYPE (t
));
939 m2pp_simple_type (s
, t
);
942 /* m2pp_procedure_type displays a procedure type. */
945 m2pp_procedure_type (pretty
*s
, tree t
)
948 if (TREE_CODE (t
) == FUNCTION_TYPE
)
950 tree i
= TYPE_ARG_TYPES (t
);
951 tree returnType
= TREE_TYPE (TREE_TYPE (t
));
954 m2pp_print (s
, "PROCEDURE");
958 int o
= getindent (s
);
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. */
974 m2pp_param_type (s
, TREE_VALUE (i
));
975 m2pp_print (s
, ", ...");
986 m2pp_param_type (s
, TREE_VALUE (i
));
994 else if (returnType
!= NULL_TREE
)
997 m2pp_print (s
, "()");
999 if (returnType
!= NULL_TREE
)
1002 m2pp_print (s
, ": ");
1003 m2pp_simple_type (s
, returnType
);
1009 /* m2pp_comment_header displays a simple header with some critical
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
);
1021 m2pp_print (s
, "-");
1023 if (TREE_PUBLIC (t
))
1026 m2pp_print (s
, "public,");
1028 if (TREE_STATIC (t
))
1031 m2pp_print (s
, "static,");
1033 if (DECL_EXTERNAL (t
))
1036 m2pp_print (s
, "extern");
1038 m2pp_print (s
, "\n");
1040 m2pp_print (s
, "*)\n\n");
1043 /* m2pp_function_header displays the function header. */
1046 m2pp_function_header (pretty
*s
, tree 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
);
1060 int o
= getindent (s
);
1063 m2pp_print (s
, "(");
1066 while (i
!= NULL_TREE
)
1068 m2pp_parameter (s
, i
);
1071 m2pp_print (s
, ";\n");
1073 m2pp_print (s
, ")");
1077 else if (returnType
!= void_type_node
)
1079 m2pp_print (s
, "()");
1082 if (returnType
!= void_type_node
)
1084 m2pp_print (s
, ": ");
1085 m2pp_simple_type (s
, returnType
);
1088 m2pp_print (s
, "; ");
1090 m2pp_print (s
, "\n");
1095 /* m2pp_add_var adds a variable into a list as defined by, data. */
1098 m2pp_add_var (tree
*tp
, int *walk_subtrees
, void *data
)
1101 pretty
*s
= (pretty
*)data
;
1102 enum tree_code code
= TREE_CODE (t
);
1104 if (code
== VAR_DECL
)
1107 m2pp_identifier (s
, t
);
1109 m2pp_print (s
, ":");
1111 m2pp_type (s
, TREE_TYPE (t
));
1113 m2pp_print (s
, ";\n");
1115 if (code
== SSA_NAME
)
1119 m2pp_identifier (s
, SSA_NAME_VAR (t
));
1121 m2pp_print (s
, ":");
1123 m2pp_type (s
, TREE_TYPE (t
));
1125 m2pp_print (s
, ";\n");
1132 /* m2pp_function_vars displays variables as defined by the function
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");
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. */
1152 m2pp_print (pretty
*s
, const char *p
)
1162 s
->needs_space
= FALSE
;
1170 s
->needs_indent
= TRUE
;
1176 if (s
->needs_indent
)
1179 printf ("%*c", s
->indent
, ' ');
1180 s
->needs_indent
= FALSE
;
1181 s
->curpos
+= s
->indent
;
1191 /* m2pp_print_char prints out a character ch obeying needs_space
1192 and needs_indent. */
1195 m2pp_print_char (pretty
*s
, char ch
)
1200 s
->needs_space
= FALSE
;
1203 if (s
->needs_indent
)
1206 printf ("%*c", s
->indent
, ' ');
1207 s
->needs_indent
= FALSE
;
1208 s
->curpos
+= s
->indent
;
1221 /* m2pp_integer display the appropriate integer type. */
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");
1261 if (TYPE_UNSIGNED (t
))
1262 m2pp_print (s
, "CARDINAL");
1264 m2pp_print (s
, "INTEGER");
1265 m2pp_integer_cst (s
, TYPE_SIZE (t
));
1270 m2pp_integer (pretty
*s
, tree t ATTRIBUTE_UNUSED
)
1272 m2pp_print (s
, "INTEGER");
1276 /* m2pp_complex display the actual complex type. */
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");
1299 m2pp_print (s
, "unknown COMPLEX type");
1305 m2pp_complex (pretty
*s
, tree t ATTRIBUTE_UNUSED
)
1307 m2pp_print (s
, "a COMPLEX type");
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");
1335 m2pp_print (s
, "unknown REAL");
1338 /* m2pp_type prints a full type. */
1341 m2pp_type (pretty
*s
, tree t
)
1343 if (begin_printed (t
))
1345 m2pp_print (s
, "<...>");
1348 if ((TREE_CODE (t
) != FIELD_DECL
) && (TREE_CODE (t
) != TYPE_DECL
))
1349 m2pp_gimpified (s
, t
);
1350 switch (TREE_CODE (t
))
1353 m2pp_integer (s
, t
);
1356 m2pp_real_type (s
, t
);
1362 m2pp_union_type (s
, t
);
1365 m2pp_record_type (s
, t
);
1372 m2pp_function_type (s
, t
);
1376 m2pp_identifier (s
, t
);
1379 m2pp_pointer_type (s
, t
);
1383 m2pp_set_type (s
, t
);
1387 m2pp_print (s
, "ADDRESS");
1390 m2pp_complex (s
, t
);
1393 m2pp_unknown (s
, __FUNCTION__
, get_tree_code_name (TREE_CODE (t
)));
1397 /* m2pp_set_type prints out the set type. */
1400 m2pp_set_type (pretty
*s
, tree t
)
1403 m2pp_print (s
, "SET OF");
1405 m2pp_type (s
, TREE_TYPE (t
));
1409 /* m2pp_enum print out the enumeration type. */
1412 m2pp_enum (pretty
*s
, tree t
)
1414 tree chain_p
= TYPE_VALUES (t
);
1417 m2pp_print (s
, "(");
1420 m2pp_ident_pointer (s
, TREE_PURPOSE (chain_p
));
1421 chain_p
= TREE_CHAIN (chain_p
);
1423 m2pp_print (s
, ", ");
1425 m2pp_print (s
, ")");
1429 /* m2pp_array prints out the array type. */
1432 m2pp_array (pretty
*s
, tree t
)
1435 m2pp_print (s
, "ARRAY");
1437 m2pp_subrange (s
, TYPE_DOMAIN (t
));
1439 m2pp_print (s
, "OF");
1441 m2pp_type (s
, TREE_TYPE (t
));
1445 /* m2pp_subrange prints out the subrange, but probably the lower
1446 bound will always be zero. */
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. */
1464 m2pp_gimpified (pretty
*s
, tree t
)
1466 if (!TYPE_SIZES_GIMPLIFIED (t
))
1468 m2pp_print (s
, "(* <!g> *)");
1473 /* m2pp_printer_type display the pointer type. */
1476 m2pp_pointer_type (pretty
*s
, tree 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");
1487 m2pp_print (s
, "POINTER TO");
1489 m2pp_type (s
, TREE_TYPE (t
));
1495 /* m2pp_record_alignment prints out whether this record is aligned
1499 m2pp_record_alignment (pretty
*s
, tree t
)
1501 if (TYPE_PACKED (t
))
1502 m2pp_print (s
, "<* bytealignment (0) *>\n");
1506 m2pp_getaligned (tree 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
);
1522 m2pp_recordfield_alignment (pretty
*s
, tree t
)
1524 unsigned int aligned
= m2pp_getaligned (t
);
1528 int o
= getindent (s
);
1529 int p
= getcurpos (s
);
1531 m2pp_print (s
, "<* bytealignment (");
1532 setindent (s
, p
+ 18);
1534 printf ("%d", aligned
/ BITS_PER_UNIT
);
1536 m2pp_print (s
, ")");
1539 m2pp_print (s
, "*>");
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. */
1565 m2pp_record_type (pretty
*s
, tree t
)
1568 if (TREE_CODE (t
) == RECORD_TYPE
)
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");
1587 m2pp_print (s
, "END");
1593 /* m2pp_record_type displays the record type. */
1596 m2pp_union_type (pretty
*s
, tree t
)
1599 if (TREE_CODE (t
) == UNION_TYPE
)
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");
1617 m2pp_print (s
, "END");
1623 /* m2pp_print_mode. */
1626 m2pp_print_mode (pretty
*s
, tree t
)
1628 int mode
= SCALAR_FLOAT_TYPE_MODE (t
);
1631 snprintf (buf
, sizeof (buf
), "%d", mode
);
1632 m2pp_print (s
, "<*");
1634 m2pp_print (s
, buf
);
1636 m2pp_print (s
, "*>");
1639 /* m2pp_simple_type. */
1642 m2pp_simple_type (pretty
*s
, tree t
)
1644 if (begin_printed (t
))
1646 m2pp_print (s
, "<...>");
1650 m2pp_gimpified (s
, t
);
1651 switch (TREE_CODE (t
))
1654 m2pp_integer (s
, t
);
1657 m2pp_real_type (s
, t
);
1658 m2pp_print_mode (s
, t
);
1661 m2pp_print (s
, "BOOLEAN");
1664 m2pp_print (s
, "ADDRESS");
1667 m2pp_identifier (s
, t
);
1670 m2pp_pointer_type (s
, t
);
1673 m2pp_record_type (s
, t
);
1676 m2pp_union_type (s
, t
);
1682 m2pp_complex (s
, t
);
1685 m2pp_unknown (s
, __FUNCTION__
, get_tree_code_name (TREE_CODE (t
)));
1689 /* m2pp_float issue a VAL (type, expr) expression. */
1692 m2pp_float (pretty
*s
, tree t
)
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. */
1705 m2pp_expression (pretty
*s
, tree t
)
1707 enum tree_code code
= TREE_CODE (t
);
1712 m2pp_relop (s
, t
, "=");
1715 m2pp_relop (s
, t
, "#");
1718 m2pp_relop (s
, t
, "<=");
1721 m2pp_relop (s
, t
, ">=");
1724 m2pp_relop (s
, t
, "<");
1727 m2pp_relop (s
, t
, ">");
1733 m2pp_simple_expression (s
, t
);
1737 /* m2pp_relop displays the lhs relop rhs. */
1740 m2pp_relop (pretty
*s
, tree t
, const char *p
)
1742 m2pp_expression (s
, TREE_OPERAND (t
, 0));
1746 m2pp_expression (s
, TREE_OPERAND (t
, 1));
1749 /* m2pp_compound_expression handle compound expression tree. */
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
, "}");
1762 /* m2pp_target_expression handle target expression tree. */
1765 m2pp_target_expression (pretty
*s
, tree t
)
1767 m2pp_print (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
, ",");
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
, ",");
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
, ",");
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
, ",");
1797 m2pp_print (s
, "}");
1801 /* m2pp_constructor print out a constructor. */
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. */
1829 m2pp_complex_expr (pretty
*s
, tree t
)
1831 if (TREE_CODE (t
) == COMPLEX_CST
)
1833 m2pp_print (s
, "CMPLX(");
1835 m2pp_expression (s
, TREE_REALPART (t
));
1836 m2pp_print (s
, ",");
1838 m2pp_expression (s
, TREE_IMAGPART (t
));
1839 m2pp_print (s
, ")");
1843 m2pp_print (s
, "CMPLX(");
1845 m2pp_expression (s
, TREE_OPERAND (t
, 0));
1846 m2pp_print (s
, ",");
1848 m2pp_expression (s
, TREE_OPERAND (t
, 1));
1849 m2pp_print (s
, ")");
1853 /* m2pp_imagpart_expr handle imagpart_expr tree. */
1856 m2pp_imagpart_expr (pretty
*s
, tree t
)
1858 m2pp_print (s
, "IM(");
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
));
1865 m2pp_print (s
, ")");
1868 /* m2pp_realpart_expr handle imagpart_expr tree. */
1871 m2pp_realpart_expr (pretty
*s
, tree t
)
1873 m2pp_print (s
, "RE(");
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
));
1880 m2pp_print (s
, ")");
1883 /* m2pp_bit_ior_expr generate a C style bit or. */
1886 m2pp_bit_ior_expr (pretty
*s
, tree t
)
1888 m2pp_binary (s
, t
, "|");
1891 /* m2pp_truth_expr. */
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
, ")");
1902 m2pp_print (s
, "(");
1903 m2pp_expression (s
, TREE_OPERAND (t
, 1));
1904 m2pp_print (s
, ")");
1907 /* m2pp_simple_expression handle GCC expression tree. */
1910 m2pp_simple_expression (pretty
*s
, tree t
)
1912 enum tree_code code
= TREE_CODE (t
);
1917 m2pp_print (s
, "(* !!! ERROR NODE !!! *)");
1920 m2pp_constructor (s
, t
);
1922 case IDENTIFIER_NODE
:
1923 m2pp_ident_pointer (s
, t
);
1926 m2pp_identifier (s
, t
);
1929 m2pp_identifier (s
, t
);
1935 m2pp_print (s
, "(* BLOCK NODE *)");
1941 m2pp_integer_cst (s
, t
);
1944 m2pp_real_cst (s
, t
);
1947 m2pp_string_cst (s
, t
);
1950 m2pp_indirect_ref (s
, t
);
1953 m2pp_addr_expr (s
, t
);
1959 m2pp_convert (s
, t
);
1962 m2pp_var_decl (s
, t
);
1965 m2pp_result_decl (s
, t
);
1968 m2pp_binary (s
, t
, "+");
1971 m2pp_binary (s
, t
, "-");
1974 m2pp_binary (s
, t
, "*");
1976 case FLOOR_DIV_EXPR
:
1978 case TRUNC_DIV_EXPR
:
1979 case ROUND_DIV_EXPR
:
1980 m2pp_binary (s
, t
, "DIV");
1982 case FLOOR_MOD_EXPR
:
1984 case TRUNC_MOD_EXPR
:
1985 case ROUND_MOD_EXPR
:
1986 m2pp_binary (s
, t
, "MOD");
1989 m2pp_unary (s
, t
, "-");
1992 m2pp_call_expr (s
, t
);
1998 m2pp_component_ref (s
, t
);
2001 m2pp_return_expr (s
, t
);
2004 m2pp_array_ref (s
, t
);
2006 case NON_LVALUE_EXPR
:
2007 m2pp_non_lvalue_expr (s
, t
);
2010 m2pp_expression (s
, EXPR_STMT_EXPR (t
));
2014 m2pp_print (s
, "GCC_EXCEPTION_OBJECT");
2019 m2pp_assignment (s
, t
);
2022 m2pp_compound_expression (s
, t
);
2025 m2pp_target_expression (s
, t
);
2031 m2pp_identifier (s
, t
);
2034 m2pp_complex_expr (s
, t
);
2037 m2pp_realpart_expr (s
, t
);
2040 m2pp_imagpart_expr (s
, t
);
2043 m2pp_identifier (s
, t
);
2045 case POINTER_PLUS_EXPR
:
2046 m2pp_binary (s
, t
, "+");
2048 case CLEANUP_POINT_EXPR
:
2049 m2pp_cleanup_point_expr (s
, t
);
2052 m2pp_bit_ior_expr (s
, t
);
2054 case TRUTH_ANDIF_EXPR
:
2055 m2pp_truth_expr (s
, t
, "AND");
2057 case TRUTH_ORIF_EXPR
:
2058 m2pp_truth_expr (s
, t
, "OR");
2061 m2pp_unknown (s
, __FUNCTION__
, get_tree_code_name (code
));
2065 /* non_lvalue_expr indicates that operand 0 is not an lvalue. */
2068 m2pp_non_lvalue_expr (pretty
*s
, tree t
)
2071 m2pp_print (s
, "assert_non_lvalue(");
2073 m2pp_expression (s
, TREE_OPERAND (t
, 0));
2075 m2pp_print (s
, ")");
2078 /* m2pp_array_ref prints out the array reference. */
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. */
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. */
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
);
2109 m2pp_expression (s
, right
);
2112 /* m2pp_unary print the unary operator, p, and expression. */
2115 m2pp_unary (pretty
*s
, tree t
, const char *p
)
2117 tree expr
= TREE_OPERAND (t
, 0);
2121 m2pp_expression (s
, expr
);
2124 /* m2pp_integer_cst displays the integer constant. */
2127 m2pp_integer_cst (pretty
*s
, tree t
)
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. */
2138 m2pp_real_cst (pretty
*s
, tree t ATTRIBUTE_UNUSED
)
2140 m2pp_print (s
, "<unknown real>");
2143 /* m2pp_string_cst displays the real constant. */
2146 m2pp_string_cst (pretty
*s
, tree t
)
2148 const char *p
= TREE_STRING_POINTER (t
);
2151 m2pp_print (s
, "\"");
2152 while (p
[i
] != '\0')
2154 m2pp_print_char (s
, p
[i
]);
2157 m2pp_print (s
, "\"");
2160 /* m2pp_statement_sequence iterates over a statement list
2161 displaying each statement in turn. */
2164 m2pp_statement_sequence (pretty
*s
, tree t
)
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
));
2177 m2pp_statement (s
, t
);
2181 /* m2pp_unknown displays an error message. */
2184 m2pp_unknown (pretty
*s
, const char *s1
, const char *s2
)
2193 /* m2pp_throw displays a throw statement. */
2196 m2pp_throw (pretty
*s
, tree t
)
2198 tree expr
= TREE_OPERAND (t
, 0);
2201 if (expr
== NULL_TREE
)
2202 m2pp_print (s
, "THROW ;\n");
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. */
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. */
2235 m2pp_try_finally_expr (pretty
*s
, tree t
)
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);
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");
2251 /* m2pp_if_stmt pretty print a C++ if_stmt. */
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");
2273 m2pp_asm_expr (pretty
*state
, tree node
)
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. */
2303 m2pp_statement (pretty
*s
, tree t
)
2305 enum tree_code code
= TREE_CODE (t
);
2311 m2pp_conditional (s
, t
);
2314 m2pp_label_expr (s
, t
);
2317 m2pp_label_decl (s
, t
);
2324 m2pp_assignment (s
, t
);
2327 m2pp_procedure_call (s
, t
);
2330 m2pp_block_list (s
, t
);
2333 m2pp_bind_expr (s
, t
);
2336 m2pp_return_expr (s
, t
);
2339 m2pp_decl_expr (s
, t
);
2342 m2pp_try_block (s
, t
);
2345 m2pp_handler (s
, t
);
2347 case CLEANUP_POINT_EXPR
:
2348 m2pp_cleanup_point_expr (s
, t
);
2353 case TRY_CATCH_EXPR
:
2354 m2pp_try_catch_expr (s
, t
);
2356 case TRY_FINALLY_EXPR
:
2357 m2pp_try_finally_expr (s
, t
);
2360 m2pp_catch_expr (s
, t
);
2363 m2pp_asm_expr (s
, t
);
2367 m2pp_if_stmt (s
, t
);
2371 m2pp_print (s
, "<ERROR CODE>\n");
2374 m2pp_unknown (s
, __FUNCTION__
, get_tree_code_name (TREE_CODE (t
)));
2378 /* m2pp_try_catch_expr is used after gimplification. */
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));
2386 m2pp_print (s
, "EXCEPT\n");
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. */
2396 m2pp_cleanup_point_expr (pretty
*s
, tree t
)
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. */
2407 m2pp_decl_expr (pretty
*s
, tree t
)
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. */
2417 m2pp_procedure_call (pretty
*s
, tree t
)
2420 m2pp_call_expr (s
, t
);
2422 m2pp_print (s
, ";\n");
2425 /* args displays each argument in an iter list by calling expression. */
2428 m2pp_args (pretty
*s
, tree e
)
2430 call_expr_arg_iterator iter
;
2433 m2pp_print (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
, ",");
2444 m2pp_print (s
, ")");
2447 /* m2pp_call_expr print a call to a procedure or function. */
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
;
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);
2466 m2pp_expression (s
, proc
);
2467 if (args
|| has_return_type
)
2471 /* m2pp_return_expr displays the return statement. */
2474 m2pp_return_expr (pretty
*s
, tree t
)
2476 tree e
= TREE_OPERAND (t
, 0);
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");
2488 m2pp_expression (s
, TREE_OPERAND (e
, 0));
2492 m2pp_print (s
, "RETURN");
2494 m2pp_expression (s
, e
);
2497 m2pp_print (s
, ";\n");
2500 /* m2pp_try_block displays the try block. */
2503 m2pp_try_block (pretty
*s
, tree t
)
2505 tree stmts
= TRY_STMTS (t
);
2506 tree handlers
= TRY_HANDLERS (t
);
2509 m2pp_print (s
, "(* TRY *)\n");
2510 m2pp_statement_sequence (s
, stmts
);
2512 m2pp_print (s
, "EXCEPT\n");
2514 m2pp_statement_sequence (s
, handlers
);
2515 m2pp_print (s
, "(* END TRY *)\n");
2518 /* m2pp_try_block displays the handler block. */
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. */
2544 m2pp_assignment (pretty
*s
, tree t
)
2549 m2pp_designator (s
, TREE_OPERAND (t
, 0));
2551 m2pp_print (s
, ":=");
2554 setindent (s
, getcurpos (s
) + 1);
2555 m2pp_expression (s
, TREE_OPERAND (t
, 1));
2557 m2pp_print (s
, ";\n");
2561 /* m2pp_designator displays the lhs of an assignment. */
2564 m2pp_designator (pretty
*s
, tree t
)
2566 m2pp_expression (s
, t
);
2569 /* m2pp_indirect_ref displays the indirect operator. */
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. */
2584 m2pp_conditional (pretty
*s
, tree t
)
2589 m2pp_print (s
, "IF");
2591 m2pp_expression (s
, TREE_OPERAND (t
, 0));
2592 m2pp_print (s
, "\nTHEN\n");
2594 setindent (s
, o
+ 3);
2595 m2pp_statement_sequence (s
, TREE_OPERAND (t
, 1));
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));
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. */
2611 m2pp_label_decl (pretty
*s
, tree t
)
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. */
2622 m2pp_label_expr (pretty
*s
, tree t
)
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. */
2632 m2pp_goto (pretty
*s
, tree t
)
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. */
2643 m2pp_list (pretty
*s
, tree t
)
2647 m2pp_print (s
, "(");
2649 while (t
!= NULL_TREE
)
2651 m2pp_expression (s
, TREE_VALUE (t
));
2653 if (t
== u
|| t
== NULL_TREE
)
2655 m2pp_print (s
, ",");
2659 m2pp_print (s
, ")");
2662 /* m2pp_offset displays the offset operator. */
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. */
2680 m2pp_addr_expr (pretty
*s
, tree t
)
2683 m2pp_print (s
, "ADR (");
2684 m2pp_expression (s
, TREE_OPERAND (t
, 0));
2685 m2pp_print (s
, ")");
2688 /* m2pp_nop generate a CAST expression. */
2691 m2pp_nop (pretty
*s
, tree t
)
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. */
2704 m2pp_convert (pretty
*s
, tree t
)
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. */
2717 m2pp_var_decl (pretty
*s
, tree t
)
2719 m2pp_identifier (s
, t
);
2722 /* m2pp_result_decl generate a result declaration (variable). */
2725 m2pp_result_decl (pretty
*s
, tree t
)
2727 m2pp_identifier (s
, t
);
2730 /* m2pp_component_ref generate a record field access. */
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));