Line data Source code
1 : /* m2pp.c pretty print trees, output in Modula-2 where possible.
2 :
3 : Copyright (C) 2007-2026 Free Software Foundation, Inc.
4 : Contributed by Gaius Mulley <gaius@glam.ac.uk>.
5 :
6 : This file is part of GNU Modula-2.
7 :
8 : GNU Modula-2 is free software; you can redistribute it and/or modify
9 : it under the terms of the GNU General Public License as published by
10 : the Free Software Foundation; either version 3, or (at your option)
11 : any later version.
12 :
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.
17 :
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/>. */
21 :
22 : #include "gcc-consolidation.h"
23 :
24 : #include "../m2-tree.h"
25 : #include "../gm2-lang.h"
26 :
27 : #include "m2tree.h"
28 : #include "m2expr.h"
29 : #include "m2type.h"
30 : #include "m2decl.h"
31 : #include "m2options.h"
32 : #include "m2langdump.h"
33 :
34 : #define M2PP_C
35 : #include "m2pp.h"
36 :
37 : #define GM2
38 : /* VERBOSE_TYPE_DESC enables type descriptions to be generated in the
39 : assignment and during variable declarations. It generates
40 : moderately ugly output, although the assignment type information
41 : can be useful when tracking down non gimple complient trees (during
42 : assignment). */
43 : #undef VERBOSE_TYPE_DESC
44 :
45 : const char *m2pp_dump_description[M2PP_DUMP_END] =
46 : {
47 : "interactive user invoked output",
48 : "modula-2 gimple trees pre genercize",
49 : "modula-2 gimple trees post genercize",
50 : };
51 :
52 : namespace modula2 {
53 :
54 : #undef DEBUGGING
55 :
56 : typedef struct pretty_t
57 : {
58 : m2pp_dump_kind output;
59 : bool needs_space;
60 : bool needs_indent;
61 : int curpos;
62 : int indent;
63 : bool issued_begin;
64 : bool in_vars;
65 : bool in_types;
66 : tree block;
67 : int bits;
68 : } pretty;
69 :
70 : typedef struct m2stack_t
71 : {
72 : tree value;
73 : struct m2stack_t *next;
74 : } stack;
75 :
76 : /* Prototypes. */
77 :
78 : static pretty *initPretty (m2pp_dump_kind kind, int bits);
79 : static pretty *dupPretty (pretty *s);
80 : static int getindent (pretty *s);
81 : static void setindent (pretty *s, int n);
82 : static int getcurpos (pretty *s);
83 : static void m2pp_identifier (pretty *s, tree t);
84 : static void m2pp_needspace (pretty *s);
85 : static void m2pp_function (pretty *s, tree t);
86 : static void m2pp_function_header (pretty *s, tree t);
87 : static void m2pp_function_vars (pretty *s, tree t);
88 : static void m2pp_statement_sequence (pretty *s, tree t);
89 : static void m2pp_print (pretty *s, const char *p);
90 : static void m2pp_print_char (pretty *s, char ch);
91 : static void m2pp_parameter (pretty *s, tree t);
92 : static void m2pp_type (pretty *s, tree t);
93 : static void m2pp_ident_pointer (pretty *s, tree t);
94 : static void m2pp_set_type (pretty *s, tree t);
95 : static void m2pp_enum (pretty *s, tree t);
96 : static void m2pp_array (pretty *s, tree t);
97 : static void m2pp_subrange (pretty *s, tree t);
98 : static void m2pp_gimpified (pretty *s, tree t);
99 : static void m2pp_pointer_type (pretty *s, tree t);
100 : static void m2pp_record_type (pretty *s, tree t);
101 : static void m2pp_union_type (pretty *s, tree t);
102 : static void m2pp_simple_type (pretty *s, tree t);
103 : static void m2pp_expression (pretty *s, tree t);
104 : static void m2pp_relop (pretty *s, tree t, const char *p);
105 : static void m2pp_simple_expression (pretty *s, tree t);
106 : static void m2pp_statement_sequence (pretty *s, tree t);
107 : static void m2pp_unknown (pretty *s, const char *s1, const char *s2);
108 : static void m2pp_statement (pretty *s, tree t);
109 : static void m2pp_assignment (pretty *s, tree t);
110 : static void m2pp_designator (pretty *s, tree t);
111 : static void m2pp_conditional (pretty *s, tree t);
112 : static void m2pp_label_expr (pretty *s, tree t);
113 : static void m2pp_label_decl (pretty *s, tree t);
114 : static void m2pp_goto (pretty *s, tree t);
115 : static void m2pp_list (pretty *s, tree t);
116 : static void m2pp_offset (pretty *s, tree t);
117 : static void m2pp_indirect_ref (pretty *s, tree t);
118 : static void m2pp_integer_cst (pretty *s, tree t);
119 : static void m2pp_real_cst (pretty *s, tree t);
120 : static void m2pp_string_cst (pretty *s, tree t);
121 : static void m2pp_integer (pretty *s, tree t);
122 : static void m2pp_addr_expr (pretty *s, tree t);
123 : static void m2pp_nop (pretty *s, tree t);
124 : static void m2pp_convert (pretty *s, tree t);
125 : static void m2pp_var_decl (pretty *s, tree t);
126 : static void m2pp_binary (pretty *s, tree t, const char *p);
127 : static void m2pp_unary (pretty *s, tree t, const char *p);
128 : static void m2pp_call_expr (pretty *s, tree t);
129 : static void m2pp_procedure_call (pretty *s, tree t);
130 : static void m2pp_ssa (pretty *s, tree t);
131 : static void m2pp_block (pretty *s, tree t);
132 : static void m2pp_block_list (pretty *s, tree t);
133 : static void m2pp_var_list (pretty *s, tree t);
134 : static void m2pp_bind_expr (pretty *s, tree t);
135 : static void m2pp_return_expr (pretty *s, tree t);
136 : static void m2pp_result_decl (pretty *s, tree t);
137 : static void m2pp_try_block (pretty *s, tree t);
138 : static void m2pp_cleanup_point_expr (pretty *s, tree t);
139 : static void m2pp_handler (pretty *s, tree t);
140 : static void m2pp_component_ref (pretty *s, tree t);
141 : static void m2pp_array_ref (pretty *s, tree t);
142 : static void m2pp_begin (pretty *s);
143 : static void m2pp_var (pretty *s);
144 : static void m2pp_types (pretty *s);
145 : static void m2pp_decl_expr (pretty *s, tree t);
146 : static void m2pp_var_type_decl (pretty *s, tree t);
147 : static void m2pp_non_lvalue_expr (pretty *s, tree t);
148 : static void m2pp_procedure_type (pretty *s, tree t);
149 : static void m2pp_param_type (pretty *s, tree t);
150 : static void m2pp_type_lowlevel (pretty *s, tree t);
151 : static void m2pp_try_catch_expr (pretty *s, tree t);
152 : static void m2pp_throw (pretty *s, tree t);
153 : static void m2pp_catch_expr (pretty *s, tree t);
154 : static void m2pp_try_finally_expr (pretty *s, tree t);
155 : static void m2pp_complex (pretty *s, tree t);
156 : static void killPretty (pretty *s);
157 : static void m2pp_compound_expression (pretty *s, tree t);
158 : static void m2pp_target_expression (pretty *s, tree t);
159 : static void m2pp_constructor (pretty *s, tree t);
160 : static void m2pp_translation (pretty *s, tree t);
161 : static void m2pp_module_block (pretty *s, tree t);
162 : static void push (tree t);
163 : static void pop (void);
164 : static bool begin_printed (tree t);
165 : static void m2pp_decl_list (pretty *s, tree t);
166 : static void m2pp_loc (pretty *s, tree t);
167 : static FILE *getoutput (pretty *s);
168 :
169 :
170 : void pet (tree t);
171 : void m2pp_integer (pretty *s, tree t);
172 :
173 : extern void stop (void);
174 :
175 : static stack *stackPtr = NULL;
176 : static FILE *m2pp_output_file[M2PP_DUMP_END];
177 :
178 : /* do_pf helper function for pf. */
179 :
180 : void
181 0 : do_pf (tree t, int bits)
182 : {
183 0 : pretty *state = initPretty (M2PP_DUMP_STDOUT, bits);
184 :
185 0 : if (TREE_CODE (t) == TRANSLATION_UNIT_DECL)
186 0 : m2pp_translation (state, t);
187 0 : else if (TREE_CODE (t) == BLOCK)
188 0 : m2pp_module_block (state, t);
189 0 : else if (TREE_CODE (t) == FUNCTION_DECL)
190 0 : m2pp_function (state, t);
191 : else
192 0 : m2pp_statement_sequence (state, t);
193 0 : killPretty (state);
194 0 : }
195 :
196 : /* pf print function. Expected to be printed interactively from
197 : the debugger: print modula2::pf(func), or to be called from code. */
198 :
199 : void
200 0 : pf (tree t)
201 : {
202 0 : do_pf (t, false);
203 0 : }
204 :
205 : /* pe print expression. Expected to be printed interactively from
206 : the debugger: print modula2::pe(expr), or to be called from code. */
207 :
208 : void
209 0 : pe (tree t)
210 : {
211 0 : pretty *state = initPretty (M2PP_DUMP_STDOUT, 0);
212 :
213 0 : m2pp_expression (state, t);
214 0 : m2pp_needspace (state);
215 0 : m2pp_print (state, ";\n");
216 0 : killPretty (state);
217 0 : }
218 :
219 : /* pet print expression and its type. Expected to be printed
220 : interactively from the debugger: print modula2::pet(expr), or to
221 : be called from code. */
222 :
223 : void
224 0 : pet (tree t)
225 : {
226 0 : pretty *state = initPretty (M2PP_DUMP_STDOUT, 0);
227 :
228 0 : m2pp_expression (state, t);
229 0 : m2pp_needspace (state);
230 0 : m2pp_print (state, ":");
231 0 : m2pp_type (state, TREE_TYPE (t));
232 0 : m2pp_print (state, ";\n");
233 0 : killPretty (state);
234 0 : }
235 :
236 : /* pt print type. Expected to be printed interactively from the
237 : debugger: print pt(expr), or to be called from code. */
238 :
239 : void
240 0 : pt (tree t)
241 : {
242 0 : pretty *state = initPretty (M2PP_DUMP_STDOUT, 0);
243 0 : m2pp_type (state, t);
244 0 : m2pp_needspace (state);
245 0 : m2pp_print (state, ";\n");
246 0 : killPretty (state);
247 0 : }
248 :
249 : /* ptl print type low level. Expected to be printed interactively
250 : from the debugger: print ptl(type), or to be called from code. */
251 :
252 : void
253 0 : ptl (tree t)
254 : {
255 0 : pretty *state = initPretty (M2PP_DUMP_STDOUT, 0);
256 0 : m2pp_type_lowlevel (state, t);
257 0 : m2pp_needspace (state);
258 0 : m2pp_print (state, ";\n");
259 0 : killPretty (state);
260 0 : }
261 :
262 : /* ptcl print TREE_CHAINed list. */
263 :
264 : void
265 0 : ptcl (tree t)
266 : {
267 0 : pretty *state = initPretty (M2PP_DUMP_STDOUT, 0);
268 :
269 0 : m2pp_decl_list (state, t);
270 0 : m2pp_print (state, "\n");
271 0 : killPretty (state);
272 0 : }
273 :
274 : /* loc if tree has a location then display it within a comment. */
275 :
276 : static void
277 0 : m2pp_loc (pretty *s, tree t)
278 : {
279 0 : if (CAN_HAVE_LOCATION_P (t))
280 : {
281 0 : if (EXPR_HAS_LOCATION (t))
282 : {
283 0 : if (EXPR_LOCATION (t) == UNKNOWN_LOCATION)
284 0 : m2pp_print (s, "(* missing location1 *)\n");
285 : else
286 : {
287 0 : expanded_location l = expand_location (EXPR_LOCATION (t));
288 :
289 0 : m2pp_print (s, "(* ");
290 0 : m2pp_print (s, l.file);
291 0 : m2pp_print (s, ":");
292 0 : fprintf (getoutput (s), "%d", l.line);
293 0 : m2pp_print (s, " *)");
294 0 : m2pp_print (s, "\n");
295 : }
296 : }
297 : else
298 : {
299 0 : m2pp_print (s, "(* missing location2 *)\n");
300 : }
301 : }
302 0 : }
303 :
304 : /* m2pp_decl_list prints a TREE_CHAINed list for a decl node. */
305 :
306 : static void
307 0 : m2pp_decl_list (pretty *s, tree t)
308 : {
309 0 : tree u = t;
310 :
311 0 : m2pp_print (s, "(");
312 0 : m2pp_needspace (s);
313 0 : while (t != NULL_TREE)
314 : {
315 0 : m2pp_identifier (s, t);
316 0 : t = TREE_CHAIN (t);
317 0 : if (t == u || t == NULL_TREE)
318 : break;
319 0 : m2pp_print (s, ",");
320 0 : m2pp_needspace (s);
321 : }
322 0 : m2pp_needspace (s);
323 0 : m2pp_print (s, ")");
324 0 : }
325 :
326 : static void
327 0 : m2pp_decl_bool (pretty *s, tree t)
328 : {
329 0 : if (TREE_STATIC (t))
330 0 : m2pp_print (s, "static, ");
331 0 : if (DECL_EXTERNAL (t))
332 0 : m2pp_print (s, "external, ");
333 0 : if (DECL_SEEN_IN_BIND_EXPR_P (t))
334 0 : m2pp_print (s, "in bind expr, ");
335 0 : }
336 :
337 : /* Print statement stmt. */
338 :
339 : void
340 0 : ps (tree stmt)
341 : {
342 0 : if (stmt)
343 : {
344 0 : pretty *state = initPretty (M2PP_DUMP_STDOUT, 0);
345 0 : m2pp_statement (state, stmt);
346 0 : killPretty (state);
347 : }
348 0 : }
349 :
350 : void
351 0 : pv (tree t)
352 : {
353 0 : if (t)
354 : {
355 0 : enum tree_code code = TREE_CODE (t);
356 :
357 0 : if (code == PARM_DECL)
358 : {
359 0 : pretty *state = initPretty (M2PP_DUMP_STDOUT, 0);
360 0 : m2pp_identifier (state, t);
361 0 : m2pp_needspace (state);
362 0 : m2pp_print (state, "<parm_decl context = ");
363 0 : m2pp_identifier (state, DECL_CONTEXT (t));
364 0 : if (DECL_ABSTRACT_ORIGIN (t) == t)
365 0 : m2pp_print (state, ">\n");
366 : else
367 : {
368 0 : m2pp_print (state, ", abstract origin = ");
369 0 : m2pp_identifier (state, DECL_ABSTRACT_ORIGIN (t));
370 0 : m2pp_print (state, ">\n");
371 0 : modula2::pv (DECL_ABSTRACT_ORIGIN (t));
372 : }
373 0 : killPretty (state);
374 : }
375 0 : if (code == VAR_DECL)
376 : {
377 0 : pretty *state = initPretty (M2PP_DUMP_STDOUT, 0);
378 0 : m2pp_identifier (state, t);
379 0 : m2pp_needspace (state);
380 0 : m2pp_print (state, "(* <var_decl context = ");
381 0 : m2pp_identifier (state, DECL_CONTEXT (t));
382 0 : m2pp_decl_bool (state, t);
383 0 : if (DECL_ABSTRACT_ORIGIN (t) == t)
384 0 : m2pp_print (state, "> *)\n");
385 : else
386 : {
387 0 : m2pp_print (state, ", abstract origin = ");
388 0 : m2pp_identifier (state, DECL_ABSTRACT_ORIGIN (t));
389 0 : m2pp_print (state, "> *)\n");
390 0 : modula2::pv (DECL_ABSTRACT_ORIGIN (t));
391 : }
392 0 : killPretty (state);
393 : }
394 : }
395 0 : }
396 :
397 : #if defined(GM2_MAINTAINER)
398 :
399 : /* remember an internal debugging hook. */
400 : static tree rememberF = NULL;
401 :
402 : static void
403 : remember (tree t)
404 : {
405 : rememberF = t;
406 : printf ("type: watch *((tree *) %p) != %p\n", (void *)&DECL_SAVED_TREE (t),
407 : (void *)DECL_SAVED_TREE (t));
408 : }
409 : #endif
410 :
411 : /* push pushes tree t onto stack. */
412 :
413 : static void
414 0 : push (tree t)
415 : {
416 0 : stack *s = (stack *)xmalloc (sizeof (stack));
417 :
418 0 : s->value = t;
419 0 : s->next = stackPtr;
420 0 : stackPtr = s;
421 0 : }
422 :
423 : /* pop pops a tree, from the stack. */
424 :
425 : static void
426 0 : pop (void)
427 : {
428 0 : stack *s = stackPtr;
429 :
430 0 : stackPtr = stackPtr->next;
431 0 : free (s);
432 0 : }
433 :
434 : /* being_printed returns true if t is held on the stack. */
435 :
436 : static bool
437 0 : begin_printed (tree t)
438 : {
439 0 : stack *s = stackPtr;
440 :
441 0 : while (s != NULL)
442 : {
443 0 : if (s->value == t)
444 : return true;
445 : else
446 0 : s = s->next;
447 : }
448 : return false;
449 : }
450 :
451 : /* dupPretty duplicate and return a copy of state s. */
452 :
453 : static pretty *
454 0 : dupPretty (pretty *s)
455 : {
456 0 : pretty *p = initPretty (s->output, s->bits);
457 0 : *p = *s;
458 0 : return p;
459 : }
460 :
461 : /* initPretty initialise the state of the pretty printer. */
462 :
463 : static pretty *
464 0 : initPretty (m2pp_dump_kind kind, int bits)
465 : {
466 0 : pretty *state = (pretty *)xmalloc (sizeof (pretty));
467 0 : state->output = kind;
468 0 : state->needs_space = false;
469 0 : state->needs_indent = false;
470 0 : state->curpos = 0;
471 0 : state->indent = 0;
472 0 : state->issued_begin = false;
473 0 : state->in_vars = false;
474 0 : state->in_types = false;
475 0 : state->block = NULL_TREE;
476 0 : state->bits = bits;
477 0 : return state;
478 : }
479 :
480 : /* killPretty cleans up the state. */
481 :
482 : static void
483 0 : killPretty (pretty *s)
484 : {
485 0 : fflush (getoutput (s));
486 0 : free (s);
487 0 : }
488 :
489 : /* getindent returns the current indent value. */
490 :
491 : static int
492 0 : getindent (pretty *s)
493 : {
494 0 : return s->indent;
495 : }
496 :
497 : /* setindent sets the current indent to, n. */
498 :
499 : static void
500 0 : setindent (pretty *s, int n)
501 : {
502 0 : s->indent = n;
503 0 : }
504 :
505 : /* getcurpos returns the current cursor position. */
506 :
507 : static int
508 0 : getcurpos (pretty *s)
509 : {
510 0 : if (s->needs_space)
511 0 : return s->curpos + 1;
512 : else
513 0 : return s->curpos;
514 : }
515 :
516 : static FILE *
517 0 : getoutput (pretty *s)
518 : {
519 0 : return m2pp_output_file[s->output];
520 : }
521 :
522 : /* m2pp_type_lowlevel prints out the low level details of a
523 : fundamental type. */
524 :
525 : static void
526 0 : m2pp_type_lowlevel (pretty *s, tree t)
527 : {
528 0 : if (TREE_CODE (t) == INTEGER_TYPE)
529 : {
530 0 : m2pp_print (s, "min");
531 0 : m2pp_needspace (s);
532 0 : m2pp_integer_cst (s, TYPE_MIN_VALUE (t));
533 0 : m2pp_print (s, ", max");
534 0 : m2pp_needspace (s);
535 0 : m2pp_integer_cst (s, TYPE_MAX_VALUE (t));
536 0 : m2pp_print (s, ", type size unit");
537 0 : m2pp_needspace (s);
538 0 : m2pp_integer_cst (s, TYPE_SIZE_UNIT (t));
539 0 : m2pp_print (s, ", type size");
540 0 : m2pp_needspace (s);
541 0 : m2pp_integer_cst (s, TYPE_SIZE (t));
542 :
543 0 : fprintf (getoutput (s),
544 : ", precision %d, mode %d, align %d, user align %d",
545 0 : TYPE_PRECISION (t), TYPE_MODE (t), TYPE_ALIGN (t),
546 0 : TYPE_USER_ALIGN (t));
547 :
548 0 : m2pp_needspace (s);
549 0 : if (TYPE_UNSIGNED (t))
550 0 : m2pp_print (s, "unsigned");
551 : else
552 0 : m2pp_print (s, "signed");
553 : }
554 0 : }
555 :
556 : /* m2pp_var emit a VAR if necessary. */
557 :
558 : static void
559 0 : m2pp_var (pretty *s)
560 : {
561 0 : if (!s->in_vars)
562 : {
563 0 : s->in_vars = true;
564 0 : m2pp_print (s, "VAR\n");
565 0 : setindent (s, getindent (s) + 3);
566 : }
567 0 : }
568 :
569 : /* m2pp_types emit a TYPE if necessary. */
570 :
571 : static void
572 0 : m2pp_types (pretty *s)
573 : {
574 0 : if (!s->in_types)
575 : {
576 0 : s->in_types = true;
577 0 : m2pp_print (s, "TYPE\n");
578 0 : setindent (s, getindent (s) + 3);
579 : }
580 0 : }
581 :
582 : #ifdef DEBUGGING
583 : /* hextree displays the critical fields for function, block and
584 : bind_expr trees in raw hex. */
585 :
586 : static void
587 : hextree (tree t)
588 : {
589 : if (t == NULL_TREE)
590 : return;
591 :
592 : if (TREE_CODE (t) == BLOCK)
593 : {
594 : printf ("(* BLOCK %p *)\n", (void *)t);
595 : printf ("BLOCK_VARS (t) = %p\n", (void *)BLOCK_VARS (t));
596 : printf ("BLOCK_SUPERCONTEXT (t) = %p\n",
597 : (void *)BLOCK_SUPERCONTEXT (t));
598 : }
599 : if (TREE_CODE (t) == BIND_EXPR)
600 : {
601 : printf ("(* BIND_EXPR %p *)\n", (void *)t);
602 : printf ("BIND_EXPR_VARS (t) = %p\n", (void *)BIND_EXPR_VARS (t));
603 : printf ("BIND_EXPR_BLOCK (t) = %p\n", (void *)BIND_EXPR_BLOCK (t));
604 : printf ("BIND_EXPR_BODY (t) = %p\n", (void *)BIND_EXPR_BODY (t));
605 : }
606 : if (TREE_CODE (t) == FUNCTION_DECL)
607 : {
608 : printf ("(* FUNCTION_DECL %p *)\n", (void *)t);
609 : printf ("DECL_INITIAL (t) = %p\n", (void *)DECL_INITIAL (t));
610 : printf ("DECL_SAVED_TREE (t) = %p\n", (void *)DECL_SAVED_TREE (t));
611 : hextree (DECL_INITIAL (t));
612 : hextree (DECL_SAVED_TREE (t));
613 : }
614 : if (VAR_P (t))
615 : {
616 : pretty *state = initPretty (M2PP_DUMP_STDOUT, 0);
617 :
618 : printf ("(* VAR_DECL %p <", (void *)t);
619 : if (DECL_SEEN_IN_BIND_EXPR_P (t))
620 : printf ("b");
621 : if (DECL_EXTERNAL (t))
622 : printf ("e");
623 : if (TREE_STATIC (t))
624 : printf ("s");
625 : printf ("> context = %p*)\n", (void *)decl_function_context (t));
626 : m2pp_type (state, TREE_TYPE (t));
627 : m2pp_needspace (state);
628 : m2pp_print (state, ";\n");
629 : killPretty (state);
630 : }
631 : if (TREE_CODE (t) == PARM_DECL)
632 : {
633 : pretty *state = initPretty (M2PP_DUMP_STDOUT, 0);
634 :
635 : printf ("(* PARM_DECL %p <", (void *)t);
636 : printf ("> context = %p*)\n", (void *)decl_function_context (t));
637 : m2pp_type (state, TREE_TYPE (t));
638 : m2pp_needspace (state);
639 : m2pp_print (state, ";\n");
640 : killPretty (state);
641 : }
642 : }
643 : #endif
644 :
645 : /* translation produce a pseudo implementation module from the tree t. */
646 :
647 : static void
648 0 : m2pp_translation (pretty *s, tree t)
649 : {
650 0 : tree block = DECL_INITIAL (t);
651 :
652 0 : m2pp_print (s, "IMPLEMENTATION MODULE ");
653 0 : m2pp_identifier (s, t);
654 0 : m2pp_print (s, "\n\n");
655 :
656 0 : if (block != NULL)
657 : {
658 0 : m2pp_module_block (s, block);
659 0 : m2pp_print (s, "\n");
660 : }
661 :
662 0 : m2pp_print (s, "\n");
663 0 : m2pp_print (s, "END ");
664 0 : m2pp_identifier (s, t);
665 0 : m2pp_print (s, ".\n");
666 0 : }
667 :
668 : static void
669 0 : m2pp_module_block (pretty *s, tree t)
670 : {
671 0 : t = BLOCK_VARS (t);
672 :
673 0 : if (t != NULL_TREE)
674 0 : for (; t != NULL_TREE; t = TREE_CHAIN (t))
675 : {
676 0 : switch (TREE_CODE (t))
677 : {
678 0 : case FUNCTION_DECL:
679 0 : if (!DECL_EXTERNAL (t))
680 : {
681 0 : pretty *p = dupPretty (s);
682 0 : fprintf (getoutput (s), "\n");
683 0 : p->in_vars = false;
684 0 : p->in_types = false;
685 0 : m2pp_function (p, t);
686 0 : killPretty (p);
687 0 : fprintf (getoutput (s), "\n");
688 0 : s->in_vars = false;
689 0 : s->in_types = false;
690 : }
691 : break;
692 :
693 0 : case TYPE_DECL:
694 0 : {
695 0 : int o = getindent (s);
696 0 : int p;
697 :
698 0 : m2pp_print (s, "\n");
699 0 : m2pp_types (s);
700 0 : setindent (s, o + 3);
701 0 : m2pp_identifier (s, t);
702 0 : m2pp_print (s, " = ");
703 0 : p = getcurpos (s);
704 0 : setindent (s, p);
705 0 : m2pp_type (s, TREE_TYPE (t));
706 0 : setindent (s, o);
707 0 : m2pp_needspace (s);
708 0 : m2pp_print (s, ";\n");
709 0 : s->in_vars = false;
710 : }
711 0 : break;
712 :
713 0 : case VAR_DECL:
714 0 : m2pp_var (s);
715 0 : m2pp_identifier (s, t);
716 0 : m2pp_needspace (s);
717 0 : m2pp_print (s, ":");
718 0 : m2pp_needspace (s);
719 0 : m2pp_type (s, TREE_TYPE (t));
720 0 : m2pp_needspace (s);
721 0 : m2pp_print (s, ";\n");
722 0 : s->in_types = false;
723 0 : break;
724 :
725 0 : case DECL_EXPR:
726 0 : fprintf (getoutput (s), "is this node legal here? \n");
727 0 : m2pp_decl_expr (s, t);
728 0 : break;
729 :
730 0 : default:
731 0 : m2pp_unknown (s, __FUNCTION__, get_tree_code_name (TREE_CODE (t)));
732 : }
733 : }
734 0 : }
735 :
736 : /* m2pp_begin emit a BEGIN if necessary. */
737 :
738 : static void
739 0 : m2pp_begin (pretty *s)
740 : {
741 0 : if (!s->issued_begin)
742 : {
743 0 : if (s->in_vars || s->in_types)
744 : {
745 0 : setindent (s, getindent (s) - 3);
746 0 : m2pp_print (s, "BEGIN\n");
747 0 : setindent (s, getindent (s) + 3);
748 : }
749 : else
750 : {
751 0 : m2pp_print (s, "BEGIN\n");
752 0 : setindent (s, getindent (s) + 3);
753 : }
754 0 : s->issued_begin = true;
755 0 : s->in_vars = false;
756 0 : s->in_types = false;
757 : }
758 0 : }
759 :
760 : /* m2pp_function walk over the function. */
761 :
762 : static void
763 0 : m2pp_function (pretty *s, tree t)
764 : {
765 0 : m2pp_function_header (s, t);
766 0 : m2pp_function_vars (s, t);
767 0 : m2pp_statement_sequence (s, DECL_SAVED_TREE (t));
768 0 : if (TREE_CODE (t) == FUNCTION_DECL)
769 : {
770 0 : m2pp_begin (s);
771 0 : setindent (s, getindent (s) - 3);
772 0 : m2pp_print (s, "END");
773 0 : m2pp_needspace (s);
774 0 : m2pp_identifier (s, t);
775 0 : m2pp_needspace (s);
776 0 : m2pp_print (s, ";\n");
777 : }
778 0 : }
779 :
780 : /* m2pp_bind_expr displays the bind expr tree node. */
781 :
782 : static void
783 0 : m2pp_bind_expr (pretty *s, tree t)
784 : {
785 0 : if (TREE_CODE (t) == BIND_EXPR)
786 : {
787 0 : if (BIND_EXPR_VARS (t))
788 : {
789 0 : m2pp_print (s, "(* variables in bind_expr *)\n");
790 0 : m2pp_var (s);
791 0 : m2pp_var_list (s, BIND_EXPR_VARS (t));
792 : }
793 0 : if (BIND_EXPR_BLOCK (t))
794 : {
795 0 : m2pp_print (s, "(* bind_expr_block *)\n");
796 0 : m2pp_statement_sequence (s, BIND_EXPR_BLOCK (t));
797 0 : m2pp_needspace (s);
798 0 : m2pp_print (s, "; \n");
799 : }
800 0 : m2pp_statement_sequence (s, BIND_EXPR_BODY (t));
801 : }
802 0 : }
803 :
804 : /* m2pp_block_list iterates over the list of blocks. */
805 :
806 : static void
807 0 : m2pp_block_list (pretty *s, tree t)
808 : {
809 0 : for (; t; t = BLOCK_CHAIN (t))
810 0 : m2pp_block (s, t);
811 0 : }
812 :
813 : /* m2pp_block prints the VARiables and the TYPEs inside a block. */
814 :
815 : static void
816 0 : m2pp_block (pretty *s, tree t)
817 : {
818 0 : if ((BLOCK_VARS (t) != NULL_TREE) && (s->block != BLOCK_VARS (t)))
819 : {
820 0 : s->block = BLOCK_VARS (t);
821 0 : m2pp_print (s, "(* block variables *)\n");
822 0 : m2pp_var (s);
823 0 : m2pp_var_list (s, BLOCK_VARS (t));
824 : }
825 0 : }
826 :
827 : /* m2pp_var_type_decl displays the variable and type declaration. */
828 :
829 : static void
830 0 : m2pp_var_type_decl (pretty *s, tree t)
831 : {
832 0 : m2pp_identifier (s, t);
833 0 : m2pp_needspace (s);
834 0 : m2pp_print (s, ":");
835 0 : m2pp_needspace (s);
836 0 : m2pp_type (s, TREE_TYPE (t));
837 0 : m2pp_needspace (s);
838 0 : m2pp_print (s, ";\n");
839 0 : }
840 :
841 : /* m2pp_var_list print a variable list. */
842 :
843 : static void
844 0 : m2pp_var_list (pretty *s, tree t)
845 : {
846 0 : if (t != NULL_TREE)
847 0 : for (; t; t = TREE_CHAIN (t))
848 : {
849 0 : if (TREE_CODE (t) == FUNCTION_DECL)
850 : {
851 0 : pretty *p = dupPretty (s);
852 0 : fprintf (getoutput (s), "\n");
853 0 : p->in_vars = false;
854 0 : p->in_types = false;
855 0 : m2pp_function (p, t);
856 0 : killPretty (p);
857 0 : fprintf (getoutput (s), "\n");
858 : }
859 0 : else if (TREE_CODE (t) == TYPE_DECL)
860 0 : m2pp_identifier (s, t);
861 0 : else if (TREE_CODE (t) == DECL_EXPR)
862 : {
863 0 : fprintf (getoutput (s), "is this node legal here? \n");
864 : // is it legal to have a DECL_EXPR here ?
865 0 : m2pp_var_type_decl (s, DECL_EXPR_DECL (t));
866 : }
867 : else
868 0 : m2pp_var_type_decl (s, t);
869 : }
870 0 : }
871 :
872 : #if 0
873 : /* m2pp_type_list print a variable list. */
874 :
875 : static void
876 : m2pp_type_list (pretty *s, tree t)
877 : {
878 : if (t != NULL_TREE)
879 : for (; t; t = TREE_CHAIN (t))
880 : {
881 : m2pp_identifier (s, t);
882 : m2pp_needspace (s);
883 : m2pp_print (s, "=");
884 : m2pp_needspace (s);
885 : m2pp_type (s, TREE_TYPE (t));
886 : m2pp_needspace (s);
887 : m2pp_print (s, ";\n");
888 : }
889 : }
890 : #endif
891 :
892 : /* m2pp_needspace sets appropriate flag to true. */
893 :
894 : static void
895 0 : m2pp_needspace (pretty *s)
896 : {
897 0 : s->needs_space = true;
898 0 : }
899 :
900 : /* m2pp_identifer prints an identifier. */
901 :
902 : static void
903 0 : m2pp_identifier (pretty *s, tree t)
904 : {
905 0 : if (t)
906 : {
907 0 : if (TREE_CODE (t) == COMPONENT_REF)
908 0 : m2pp_component_ref (s, t);
909 0 : else if (DECL_NAME (t) && IDENTIFIER_POINTER (DECL_NAME (t)))
910 0 : m2pp_ident_pointer (s, DECL_NAME (t));
911 : else
912 : {
913 0 : char name[100];
914 :
915 0 : if (TREE_CODE (t) == CONST_DECL)
916 0 : snprintf (name, 100, "C_%u", DECL_UID (t));
917 : else
918 0 : snprintf (name, 100, "D_%u", DECL_UID (t));
919 0 : m2pp_print (s, name);
920 : #ifdef VERBOSE_TYPE_DESC
921 : if (TREE_TYPE (t) != NULL_TREE)
922 : {
923 : m2pp_needspace (s);
924 : m2pp_print (s, "(* type:");
925 : m2pp_needspace (s);
926 : m2pp_simple_type (s, TREE_TYPE (t));
927 : m2pp_needspace (s);
928 : m2pp_type_lowlevel (s, TREE_TYPE (t));
929 : m2pp_needspace (s);
930 : m2pp_print (s, "*)");
931 : }
932 : #endif
933 : }
934 : }
935 0 : }
936 :
937 : /* m2pp_ident_pointer displays an ident pointer. */
938 :
939 : static void
940 0 : m2pp_ident_pointer (pretty *s, tree t)
941 : {
942 0 : if (t)
943 0 : m2pp_print (s, IDENTIFIER_POINTER (t));
944 0 : }
945 :
946 : /* m2pp_parameter prints out a param decl tree. */
947 :
948 : static void
949 0 : m2pp_parameter (pretty *s, tree t)
950 : {
951 0 : if (TREE_CODE (t) == PARM_DECL)
952 : {
953 0 : if (TREE_TYPE (t) && (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE))
954 : {
955 0 : m2pp_print (s, "VAR");
956 0 : m2pp_needspace (s);
957 0 : m2pp_identifier (s, t);
958 0 : m2pp_print (s, ":");
959 0 : m2pp_needspace (s);
960 0 : m2pp_simple_type (s, TREE_TYPE (TREE_TYPE (t)));
961 : }
962 : else
963 : {
964 0 : m2pp_identifier (s, t);
965 0 : m2pp_print (s, ":");
966 0 : m2pp_needspace (s);
967 0 : m2pp_simple_type (s, TREE_TYPE (t));
968 : }
969 : }
970 0 : }
971 :
972 : /* m2pp_param_type prints out the type of parameter. */
973 :
974 : static void
975 0 : m2pp_param_type (pretty *s, tree t)
976 : {
977 0 : if (t && (TREE_CODE (t) == REFERENCE_TYPE))
978 : {
979 0 : m2pp_print (s, "VAR");
980 0 : m2pp_needspace (s);
981 0 : m2pp_simple_type (s, TREE_TYPE (t));
982 : }
983 : else
984 0 : m2pp_simple_type (s, t);
985 0 : }
986 :
987 : /* m2pp_procedure_type displays a procedure type. */
988 :
989 : static void
990 0 : m2pp_procedure_type (pretty *s, tree t)
991 : {
992 0 : push (t);
993 0 : if (TREE_CODE (t) == FUNCTION_TYPE)
994 : {
995 0 : tree i = TYPE_ARG_TYPES (t);
996 0 : tree returnType = TREE_TYPE (TREE_TYPE (t));
997 :
998 0 : m2pp_needspace (s);
999 0 : m2pp_print (s, "PROCEDURE");
1000 0 : m2pp_needspace (s);
1001 0 : if (i != NULL_TREE)
1002 : {
1003 0 : int o = getindent (s);
1004 0 : int p;
1005 0 : bool first = true;
1006 :
1007 0 : m2pp_print (s, "(");
1008 0 : p = getcurpos (s);
1009 0 : setindent (s, p);
1010 0 : while (i != NULL_TREE)
1011 : {
1012 0 : if (TREE_CHAIN (i) == NULL_TREE)
1013 : {
1014 0 : if (TREE_VALUE (i) == void_type_node)
1015 : /* Ignore void_type_node at the end. */
1016 : ;
1017 : else
1018 : {
1019 0 : m2pp_param_type (s, TREE_VALUE (i));
1020 0 : m2pp_print (s, ", ...");
1021 : }
1022 : break;
1023 : }
1024 : else
1025 : {
1026 0 : if (!first)
1027 : {
1028 0 : m2pp_print (s, ",");
1029 0 : m2pp_needspace (s);
1030 : }
1031 0 : m2pp_param_type (s, TREE_VALUE (i));
1032 : }
1033 0 : i = TREE_CHAIN (i);
1034 0 : first = false;
1035 : }
1036 0 : m2pp_print (s, ")");
1037 0 : setindent (s, o);
1038 : }
1039 0 : else if (returnType != NULL_TREE)
1040 : {
1041 0 : m2pp_needspace (s);
1042 0 : m2pp_print (s, "()");
1043 : }
1044 0 : if (returnType != NULL_TREE)
1045 : {
1046 0 : m2pp_needspace (s);
1047 0 : m2pp_print (s, ": ");
1048 0 : m2pp_simple_type (s, returnType);
1049 : }
1050 : }
1051 0 : pop ();
1052 0 : }
1053 :
1054 : /* m2pp_comment_header displays a simple header with some critical
1055 : tree info. */
1056 :
1057 : static void
1058 0 : m2pp_comment_header (pretty *s, tree t)
1059 : {
1060 0 : int o = getindent (s);
1061 :
1062 0 : m2pp_print (s, "(*\n");
1063 0 : setindent (s, o + 3);
1064 0 : m2pp_identifier (s, t);
1065 0 : m2pp_needspace (s);
1066 0 : m2pp_print (s, "-");
1067 0 : m2pp_needspace (s);
1068 0 : if (TREE_PUBLIC (t))
1069 : {
1070 0 : m2pp_needspace (s);
1071 0 : m2pp_print (s, "public,");
1072 : }
1073 0 : if (TREE_STATIC (t))
1074 : {
1075 0 : m2pp_needspace (s);
1076 0 : m2pp_print (s, "static,");
1077 : }
1078 0 : if (DECL_EXTERNAL (t))
1079 : {
1080 0 : m2pp_needspace (s);
1081 0 : m2pp_print (s, "extern");
1082 : }
1083 0 : m2pp_print (s, "\n");
1084 0 : setindent (s, o);
1085 0 : m2pp_print (s, "*)\n\n");
1086 0 : }
1087 :
1088 : /* m2pp_function_header displays the function header. */
1089 :
1090 : static void
1091 0 : m2pp_function_header (pretty *s, tree t)
1092 : {
1093 0 : push (t);
1094 0 : if (TREE_CODE (t) == FUNCTION_DECL)
1095 : {
1096 0 : tree i = DECL_ARGUMENTS (t);
1097 0 : tree returnType = TREE_TYPE (TREE_TYPE (t));
1098 :
1099 0 : m2pp_comment_header (s, t);
1100 0 : m2pp_print (s, "PROCEDURE ");
1101 0 : m2pp_identifier (s, t);
1102 0 : m2pp_needspace (s);
1103 0 : if (i != NULL_TREE)
1104 : {
1105 0 : int o = getindent (s);
1106 0 : int p;
1107 :
1108 0 : m2pp_print (s, "(");
1109 0 : p = getcurpos (s);
1110 0 : setindent (s, p);
1111 0 : while (i != NULL_TREE)
1112 : {
1113 0 : m2pp_parameter (s, i);
1114 0 : i = TREE_CHAIN (i);
1115 0 : if (i != NULL_TREE)
1116 0 : m2pp_print (s, ";\n");
1117 : }
1118 0 : m2pp_print (s, ")");
1119 0 : m2pp_needspace (s);
1120 0 : setindent (s, o);
1121 : }
1122 0 : else if (returnType != void_type_node)
1123 : {
1124 0 : m2pp_print (s, "()");
1125 0 : m2pp_needspace (s);
1126 : }
1127 0 : if (returnType != void_type_node)
1128 : {
1129 0 : m2pp_print (s, ": ");
1130 0 : m2pp_simple_type (s, returnType);
1131 0 : m2pp_needspace (s);
1132 : }
1133 0 : m2pp_print (s, "; ");
1134 0 : m2pp_loc (s, t);
1135 0 : m2pp_print (s, "\n");
1136 : }
1137 0 : pop ();
1138 0 : }
1139 :
1140 : /* m2pp_add_var adds a variable into a list as defined by, data. */
1141 :
1142 : static tree
1143 0 : m2pp_add_var (tree *tp, int *walk_subtrees, void *data)
1144 : {
1145 0 : tree t = *tp;
1146 0 : pretty *s = (pretty *)data;
1147 0 : enum tree_code code = TREE_CODE (t);
1148 :
1149 0 : if (code == VAR_DECL)
1150 : {
1151 0 : m2pp_var (s);
1152 0 : m2pp_identifier (s, t);
1153 0 : m2pp_needspace (s);
1154 0 : m2pp_print (s, ":");
1155 0 : m2pp_needspace (s);
1156 0 : m2pp_type (s, TREE_TYPE (t));
1157 0 : m2pp_needspace (s);
1158 0 : m2pp_print (s, ";\n");
1159 : }
1160 0 : if (code == SSA_NAME)
1161 : {
1162 0 : m2pp_var (s);
1163 0 : m2pp_ssa (s, t);
1164 0 : m2pp_identifier (s, SSA_NAME_VAR (t));
1165 0 : m2pp_needspace (s);
1166 0 : m2pp_print (s, ":");
1167 0 : m2pp_needspace (s);
1168 0 : m2pp_type (s, TREE_TYPE (t));
1169 0 : m2pp_needspace (s);
1170 0 : m2pp_print (s, ";\n");
1171 : }
1172 :
1173 0 : *walk_subtrees = 1;
1174 0 : return NULL_TREE;
1175 : }
1176 :
1177 : /* m2pp_function_vars displays variables as defined by the function
1178 : tree. */
1179 :
1180 : static void
1181 0 : m2pp_function_vars (pretty *s, tree t)
1182 : {
1183 0 : walk_tree_without_duplicates (&t, m2pp_add_var, s);
1184 :
1185 0 : if (TREE_CODE (t) == FUNCTION_DECL && DECL_INITIAL (t))
1186 : {
1187 0 : m2pp_print (s, "(* variables in function_decl (decl_initial) *)\n");
1188 0 : m2pp_var (s);
1189 0 : m2pp_statement_sequence (s, DECL_INITIAL (t));
1190 : }
1191 0 : }
1192 :
1193 : /* m2pp_print print out a string p interpreting '\n' and
1194 : adjusting the fields within state s. */
1195 :
1196 : static void
1197 0 : m2pp_print (pretty *s, const char *p)
1198 : {
1199 0 : if (p)
1200 : {
1201 0 : int l = strlen (p);
1202 0 : int i = 0;
1203 :
1204 0 : if (s->needs_space)
1205 : {
1206 0 : fprintf (getoutput (s), " ");
1207 0 : s->needs_space = false;
1208 0 : s->curpos++;
1209 : }
1210 :
1211 0 : while (i < l)
1212 : {
1213 0 : if (p[i] == '\n')
1214 : {
1215 0 : s->needs_indent = true;
1216 0 : s->curpos = 0;
1217 0 : fprintf (getoutput (s), "\n");
1218 : }
1219 : else
1220 : {
1221 0 : if (s->needs_indent)
1222 : {
1223 0 : if (s->indent > 0)
1224 0 : fprintf (getoutput (s), "%*c", s->indent, ' ');
1225 0 : s->needs_indent = false;
1226 0 : s->curpos += s->indent;
1227 : }
1228 0 : s->curpos++;
1229 0 : fputc (p[i], getoutput (s));
1230 : }
1231 0 : i++;
1232 : }
1233 : }
1234 0 : }
1235 :
1236 : /* m2pp_print_char prints out a character ch obeying needs_space
1237 : and needs_indent. */
1238 :
1239 : static void
1240 0 : m2pp_print_char (pretty *s, char ch)
1241 : {
1242 0 : if (s->needs_space)
1243 : {
1244 0 : fprintf (getoutput (s), " ");
1245 0 : s->needs_space = false;
1246 0 : s->curpos++;
1247 : }
1248 0 : if (s->needs_indent)
1249 : {
1250 0 : if (s->indent > 0)
1251 0 : fprintf (getoutput (s), "%*c", s->indent, ' ');
1252 0 : s->needs_indent = false;
1253 0 : s->curpos += s->indent;
1254 : }
1255 0 : if (ch == '\n')
1256 : {
1257 0 : s->curpos++;
1258 0 : fputc ('\\', getoutput (s));
1259 0 : fputc ('n', getoutput (s));
1260 : }
1261 : else
1262 0 : fputc (ch, getoutput (s));
1263 0 : s->curpos++;
1264 0 : }
1265 :
1266 : /* m2pp_integer display the appropriate integer type. */
1267 :
1268 : #if defined(GM2)
1269 : void
1270 0 : m2pp_integer (pretty *s, tree t)
1271 : {
1272 0 : if (t == m2type_GetM2ZType ())
1273 0 : m2pp_print (s, "M2ZTYPE");
1274 0 : else if (t == m2type_GetM2LongIntType ())
1275 0 : m2pp_print (s, "LONGINT");
1276 0 : else if (t == m2type_GetM2IntegerType ())
1277 0 : m2pp_print (s, "INTEGER");
1278 0 : else if (t == m2type_GetM2ShortIntType ())
1279 0 : m2pp_print (s, "SHORTINT");
1280 0 : else if (t == m2type_GetLongIntType ())
1281 0 : m2pp_print (s, "long int");
1282 0 : else if (t == m2type_GetIntegerType ())
1283 0 : m2pp_print (s, "int");
1284 0 : else if (t == m2type_GetShortIntType ())
1285 0 : m2pp_print (s, "short");
1286 0 : else if (t == m2type_GetM2LongCardType ())
1287 0 : m2pp_print (s, "LONGCARD");
1288 0 : else if (t == m2type_GetM2CardinalType ())
1289 0 : m2pp_print (s, "CARDINAL");
1290 0 : else if (t == m2type_GetM2ShortCardType ())
1291 0 : m2pp_print (s, "SHORTCARD");
1292 0 : else if (t == m2type_GetCardinalType ())
1293 0 : m2pp_print (s, "CARDINAL");
1294 0 : else if (t == m2type_GetPointerType ())
1295 0 : m2pp_print (s, "ADDRESS");
1296 0 : else if (t == m2type_GetByteType ())
1297 0 : m2pp_print (s, "BYTE");
1298 0 : else if (t == m2type_GetCharType ())
1299 0 : m2pp_print (s, "CHAR");
1300 0 : else if (t == m2type_GetBitsetType ())
1301 0 : m2pp_print (s, "BITSET");
1302 0 : else if (t == m2type_GetBitnumType ())
1303 0 : m2pp_print (s, "BITNUM");
1304 : else
1305 : {
1306 0 : if (TYPE_UNSIGNED (t))
1307 0 : m2pp_print (s, "CARDINAL");
1308 : else
1309 0 : m2pp_print (s, "INTEGER");
1310 0 : m2pp_integer_cst (s, TYPE_SIZE (t));
1311 : }
1312 0 : }
1313 : #else
1314 : void
1315 : m2pp_integer (pretty *s, tree t ATTRIBUTE_UNUSED)
1316 : {
1317 : m2pp_print (s, "INTEGER");
1318 : }
1319 : #endif
1320 :
1321 : /* m2pp_complex display the actual complex type. */
1322 :
1323 : #if defined(GM2)
1324 : static void
1325 0 : m2pp_complex (pretty *s, tree t)
1326 : {
1327 0 : if (t == m2type_GetM2ComplexType ())
1328 0 : m2pp_print (s, "COMPLEX");
1329 0 : else if (t == m2type_GetM2LongComplexType ())
1330 0 : m2pp_print (s, "LONGCOMPLEX");
1331 0 : else if (t == m2type_GetM2ShortComplexType ())
1332 0 : m2pp_print (s, "SHORTCOMPLEX");
1333 0 : else if (t == m2type_GetM2CType ())
1334 0 : m2pp_print (s, "C'omplex' type");
1335 0 : else if (t == m2type_GetM2Complex32 ())
1336 0 : m2pp_print (s, "COMPLEX32");
1337 0 : else if (t == m2type_GetM2Complex64 ())
1338 0 : m2pp_print (s, "COMPLEX64");
1339 0 : else if (t == m2type_GetM2Complex96 ())
1340 0 : m2pp_print (s, "COMPLEX96");
1341 0 : else if (t == m2type_GetM2Complex128 ())
1342 0 : m2pp_print (s, "COMPLEX128");
1343 : else
1344 0 : m2pp_print (s, "unknown COMPLEX type");
1345 0 : }
1346 :
1347 : #else
1348 :
1349 : static void
1350 : m2pp_complex (pretty *s, tree t ATTRIBUTE_UNUSED)
1351 : {
1352 : m2pp_print (s, "a COMPLEX type");
1353 : }
1354 : #endif
1355 :
1356 : void
1357 0 : m2pp_real_type (pretty *s, tree t)
1358 : {
1359 0 : if (t == m2type_GetRealType ())
1360 0 : m2pp_print (s, "C double");
1361 0 : else if (t == m2type_GetShortRealType ())
1362 0 : m2pp_print (s, "C float");
1363 0 : else if (t == m2type_GetLongRealType ())
1364 0 : m2pp_print (s, "C long double");
1365 0 : else if (t == m2type_GetM2RealType ())
1366 0 : m2pp_print (s, "REAL");
1367 0 : else if (t == m2type_GetM2ShortRealType ())
1368 0 : m2pp_print (s, "SHORTREAL");
1369 0 : else if (t == m2type_GetM2LongRealType ())
1370 0 : m2pp_print (s, "LONGREAL");
1371 0 : else if (t == m2type_GetM2Real128 ())
1372 0 : m2pp_print (s, "REAL128");
1373 0 : else if (t == m2type_GetM2Real64 ())
1374 0 : m2pp_print (s, "REAL64");
1375 0 : else if (t == m2type_GetM2Real32 ())
1376 0 : m2pp_print (s, "REAL32");
1377 0 : else if (t == m2type_GetM2RType ())
1378 0 : m2pp_print (s, "R Type");
1379 : else
1380 0 : m2pp_print (s, "unknown REAL");
1381 0 : }
1382 :
1383 : /* m2pp_type prints a full type. */
1384 :
1385 : void
1386 0 : m2pp_type (pretty *s, tree t)
1387 : {
1388 0 : if (begin_printed (t))
1389 : {
1390 0 : m2pp_print (s, "<...>");
1391 0 : return;
1392 : }
1393 0 : if ((TREE_CODE (t) != FIELD_DECL) && (TREE_CODE (t) != TYPE_DECL))
1394 0 : m2pp_gimpified (s, t);
1395 0 : switch (TREE_CODE (t))
1396 : {
1397 0 : case INTEGER_TYPE:
1398 0 : m2pp_integer (s, t);
1399 0 : break;
1400 0 : case REAL_TYPE:
1401 0 : m2pp_real_type (s, t);
1402 0 : break;
1403 0 : case ENUMERAL_TYPE:
1404 0 : m2pp_enum (s, t);
1405 0 : break;
1406 0 : case UNION_TYPE:
1407 0 : m2pp_union_type (s, t);
1408 0 : break;
1409 0 : case RECORD_TYPE:
1410 0 : m2pp_record_type (s, t);
1411 0 : break;
1412 0 : case ARRAY_TYPE:
1413 0 : m2pp_array (s, t);
1414 0 : break;
1415 : #if 0
1416 : case FUNCTION_TYPE:
1417 : m2pp_function_type (s, t);
1418 : break;
1419 : #endif
1420 0 : case TYPE_DECL:
1421 0 : m2pp_identifier (s, t);
1422 0 : break;
1423 0 : case POINTER_TYPE:
1424 0 : m2pp_pointer_type (s, t);
1425 0 : break;
1426 : #if defined(GM2)
1427 0 : case SET_TYPE:
1428 0 : m2pp_set_type (s, t);
1429 0 : break;
1430 : #endif
1431 0 : case VOID_TYPE:
1432 0 : m2pp_print (s, "ADDRESS");
1433 0 : break;
1434 0 : case COMPLEX_TYPE:
1435 0 : m2pp_complex (s, t);
1436 0 : break;
1437 0 : default:
1438 0 : m2pp_unknown (s, __FUNCTION__, get_tree_code_name (TREE_CODE (t)));
1439 : }
1440 : }
1441 :
1442 : /* m2pp_set_type prints out the set type. */
1443 :
1444 : static void
1445 0 : m2pp_set_type (pretty *s, tree t)
1446 : {
1447 0 : push (t);
1448 0 : m2pp_print (s, "SET OF");
1449 0 : m2pp_needspace (s);
1450 0 : m2pp_type (s, TREE_TYPE (t));
1451 0 : pop ();
1452 0 : }
1453 :
1454 : /* m2pp_enum print out the enumeration type. */
1455 :
1456 : static void
1457 0 : m2pp_enum (pretty *s, tree t)
1458 : {
1459 0 : tree chain_p = TYPE_VALUES (t);
1460 :
1461 0 : push (t);
1462 0 : m2pp_print (s, "(");
1463 0 : while (chain_p)
1464 : {
1465 0 : m2pp_ident_pointer (s, TREE_PURPOSE (chain_p));
1466 0 : chain_p = TREE_CHAIN (chain_p);
1467 0 : if (chain_p)
1468 0 : m2pp_print (s, ", ");
1469 : }
1470 0 : m2pp_print (s, ")");
1471 0 : pop ();
1472 0 : }
1473 :
1474 : /* m2pp_array prints out the array type. */
1475 :
1476 : static void
1477 0 : m2pp_array (pretty *s, tree t)
1478 : {
1479 0 : push (t);
1480 0 : m2pp_print (s, "ARRAY");
1481 0 : m2pp_needspace (s);
1482 0 : m2pp_subrange (s, TYPE_DOMAIN (t));
1483 0 : m2pp_needspace (s);
1484 0 : m2pp_print (s, "OF");
1485 0 : m2pp_needspace (s);
1486 0 : m2pp_type (s, TREE_TYPE (t));
1487 0 : pop ();
1488 0 : }
1489 :
1490 : /* m2pp_subrange prints out the subrange, but probably the lower
1491 : bound will always be zero. */
1492 :
1493 : static void
1494 0 : m2pp_subrange (pretty *s, tree t)
1495 : {
1496 0 : tree min = TYPE_MIN_VALUE (t);
1497 0 : tree max = TYPE_MAX_VALUE (t);
1498 :
1499 0 : m2pp_print (s, "[");
1500 0 : m2pp_expression (s, min);
1501 0 : m2pp_print (s, "..");
1502 0 : m2pp_expression (s, max);
1503 0 : m2pp_print (s, "]");
1504 0 : }
1505 :
1506 : /* m2pp_gimplified print out a gimplified comment. */
1507 :
1508 : static void
1509 0 : m2pp_gimpified (pretty *s, tree t)
1510 : {
1511 0 : if (!TYPE_SIZES_GIMPLIFIED (t))
1512 : {
1513 0 : m2pp_print (s, "(* <!g> *)");
1514 0 : m2pp_needspace (s);
1515 : }
1516 0 : }
1517 :
1518 : /* m2pp_printer_type display the pointer type. */
1519 :
1520 : static void
1521 0 : m2pp_pointer_type (pretty *s, tree t)
1522 : {
1523 0 : push (t);
1524 0 : if (TREE_CODE (t) == POINTER_TYPE)
1525 : {
1526 0 : if (TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE)
1527 0 : m2pp_procedure_type (s, TREE_TYPE (t));
1528 0 : else if (t == ptr_type_node)
1529 0 : m2pp_print (s, "ADDRESS");
1530 : else
1531 : {
1532 0 : m2pp_print (s, "POINTER TO");
1533 0 : m2pp_needspace (s);
1534 0 : m2pp_type (s, TREE_TYPE (t));
1535 : }
1536 : }
1537 0 : pop ();
1538 0 : }
1539 :
1540 : /* m2pp_record_alignment prints out whether this record is aligned
1541 : (packed). */
1542 :
1543 : static void
1544 0 : m2pp_record_alignment (pretty *s, tree t)
1545 : {
1546 0 : if (TYPE_PACKED (t))
1547 0 : m2pp_print (s, "<* bytealignment (0) *>\n");
1548 0 : }
1549 :
1550 : static unsigned int
1551 0 : m2pp_getaligned (tree t)
1552 : {
1553 0 : if (DECL_P (t))
1554 : {
1555 0 : if (DECL_USER_ALIGN (t))
1556 0 : return DECL_ALIGN (t);
1557 : }
1558 0 : else if (TYPE_P (t))
1559 : {
1560 0 : if (TYPE_USER_ALIGN (t))
1561 0 : return TYPE_ALIGN (t);
1562 : }
1563 : return 0;
1564 : }
1565 :
1566 : static void
1567 0 : m2pp_recordfield_alignment (pretty *s, tree t)
1568 : {
1569 0 : unsigned int aligned = m2pp_getaligned (t);
1570 :
1571 0 : if (aligned != 0)
1572 : {
1573 0 : int o = getindent (s);
1574 0 : int p = getcurpos (s);
1575 0 : m2pp_needspace (s);
1576 0 : m2pp_print (s, "<* bytealignment (");
1577 0 : setindent (s, p + 18);
1578 :
1579 0 : fprintf (getoutput (s), "%d", aligned / BITS_PER_UNIT);
1580 :
1581 0 : m2pp_print (s, ")");
1582 0 : m2pp_needspace (s);
1583 0 : setindent (s, p);
1584 0 : m2pp_print (s, "*>");
1585 0 : setindent (s, o);
1586 : }
1587 0 : }
1588 :
1589 : static void
1590 0 : m2pp_recordfield_bitfield (pretty *s, tree t)
1591 : {
1592 0 : if ((TREE_CODE (t) == FIELD_DECL) && DECL_PACKED (t))
1593 : {
1594 0 : m2pp_print (s, " (* packed");
1595 0 : if (DECL_NONADDRESSABLE_P (t))
1596 0 : m2pp_print (s, ", non-addressible");
1597 0 : if (DECL_BIT_FIELD (t))
1598 0 : m2pp_print (s, ", bit-field");
1599 0 : m2pp_print (s, ", offset: ");
1600 0 : m2pp_expression (s, DECL_FIELD_OFFSET (t));
1601 0 : m2pp_print (s, ", bit offset:");
1602 0 : m2pp_expression (s, DECL_FIELD_BIT_OFFSET (t));
1603 0 : m2pp_print (s, " *) ");
1604 : }
1605 0 : }
1606 :
1607 : /* m2pp_record_type displays the record type. */
1608 :
1609 : static void
1610 0 : m2pp_record_type (pretty *s, tree t)
1611 : {
1612 0 : push (t);
1613 0 : if (TREE_CODE (t) == RECORD_TYPE)
1614 : {
1615 0 : tree i;
1616 0 : int o = getindent (s);
1617 0 : int p = getcurpos (s);
1618 :
1619 0 : m2pp_print (s, "RECORD\n");
1620 0 : setindent (s, p + 3);
1621 0 : m2pp_record_alignment (s, t);
1622 0 : for (i = TYPE_FIELDS (t); i != NULL_TREE; i = TREE_CHAIN (i))
1623 : {
1624 0 : m2pp_identifier (s, i);
1625 0 : m2pp_print (s, " : ");
1626 0 : m2pp_type (s, TREE_TYPE (i));
1627 0 : m2pp_recordfield_bitfield (s, i);
1628 0 : m2pp_recordfield_alignment (s, i);
1629 0 : m2pp_print (s, ";\n");
1630 : }
1631 0 : setindent (s, p);
1632 0 : m2pp_print (s, "END");
1633 0 : setindent (s, o);
1634 : }
1635 0 : pop ();
1636 0 : }
1637 :
1638 : /* m2pp_record_type displays the record type. */
1639 :
1640 : static void
1641 0 : m2pp_union_type (pretty *s, tree t)
1642 : {
1643 0 : push (t);
1644 0 : if (TREE_CODE (t) == UNION_TYPE)
1645 : {
1646 0 : tree i;
1647 0 : int o = getindent (s);
1648 0 : int p = getcurpos (s);
1649 :
1650 0 : m2pp_print (s, "CASE .. OF\n");
1651 0 : setindent (s, p + 3);
1652 0 : m2pp_record_alignment (s, t);
1653 0 : for (i = TYPE_FIELDS (t); i != NULL_TREE; i = TREE_CHAIN (i))
1654 : {
1655 0 : m2pp_identifier (s, i);
1656 0 : m2pp_print (s, " : ");
1657 0 : m2pp_type (s, TREE_TYPE (i));
1658 0 : m2pp_recordfield_bitfield (s, i);
1659 0 : m2pp_print (s, ";\n");
1660 : }
1661 0 : setindent (s, p);
1662 0 : m2pp_print (s, "END");
1663 0 : setindent (s, o);
1664 : }
1665 0 : pop ();
1666 0 : }
1667 :
1668 : /* m2pp_print_mode. */
1669 :
1670 : static void
1671 0 : m2pp_print_mode (pretty *s, tree t)
1672 : {
1673 0 : int mode = SCALAR_FLOAT_TYPE_MODE (t);
1674 0 : char buf[100];
1675 :
1676 0 : snprintf (buf, sizeof (buf), "%d", mode);
1677 0 : m2pp_print (s, "<*");
1678 0 : m2pp_needspace (s);
1679 0 : m2pp_print (s, buf);
1680 0 : m2pp_needspace (s);
1681 0 : m2pp_print (s, "*>");
1682 0 : }
1683 :
1684 : /* m2pp_simple_type. */
1685 :
1686 : static void
1687 0 : m2pp_simple_type (pretty *s, tree t)
1688 : {
1689 0 : if (begin_printed (t))
1690 : {
1691 0 : m2pp_print (s, "<...>");
1692 0 : return;
1693 : }
1694 :
1695 0 : m2pp_gimpified (s, t);
1696 0 : switch (TREE_CODE (t))
1697 : {
1698 0 : case INTEGER_TYPE:
1699 0 : m2pp_integer (s, t);
1700 0 : break;
1701 0 : case REAL_TYPE:
1702 0 : m2pp_real_type (s, t);
1703 0 : m2pp_print_mode (s, t);
1704 0 : break;
1705 0 : case BOOLEAN_TYPE:
1706 0 : m2pp_print (s, "BOOLEAN");
1707 0 : break;
1708 0 : case VOID_TYPE:
1709 0 : m2pp_print (s, "ADDRESS");
1710 0 : break;
1711 0 : case TYPE_DECL:
1712 0 : m2pp_identifier (s, t);
1713 0 : break;
1714 0 : case POINTER_TYPE:
1715 0 : m2pp_pointer_type (s, t);
1716 0 : break;
1717 0 : case RECORD_TYPE:
1718 0 : m2pp_record_type (s, t);
1719 0 : break;
1720 0 : case UNION_TYPE:
1721 0 : m2pp_union_type (s, t);
1722 0 : break;
1723 0 : case ENUMERAL_TYPE:
1724 0 : m2pp_enum (s, t);
1725 0 : break;
1726 0 : case COMPLEX_TYPE:
1727 0 : m2pp_complex (s, t);
1728 0 : break;
1729 0 : default:
1730 0 : m2pp_unknown (s, __FUNCTION__, get_tree_code_name (TREE_CODE (t)));
1731 : }
1732 : }
1733 :
1734 : /* m2pp_float issue a VAL (type, expr) expression. */
1735 :
1736 : static void
1737 0 : m2pp_float (pretty *s, tree t)
1738 : {
1739 0 : m2pp_needspace (s);
1740 0 : m2pp_print (s, "VAL (");
1741 0 : m2pp_simple_type (s, TREE_TYPE (t));
1742 0 : m2pp_print (s, ", ");
1743 0 : m2pp_expression (s, TREE_OPERAND (t, 0));
1744 0 : m2pp_print (s, ")");
1745 0 : }
1746 :
1747 : /* m2pp_expression display an expression. */
1748 :
1749 : static void
1750 0 : m2pp_expression (pretty *s, tree t)
1751 : {
1752 0 : enum tree_code code = TREE_CODE (t);
1753 :
1754 0 : switch (code)
1755 : {
1756 0 : case EQ_EXPR:
1757 0 : m2pp_relop (s, t, "=");
1758 0 : break;
1759 0 : case NE_EXPR:
1760 0 : m2pp_relop (s, t, "#");
1761 0 : break;
1762 0 : case LE_EXPR:
1763 0 : m2pp_relop (s, t, "<=");
1764 0 : break;
1765 0 : case GE_EXPR:
1766 0 : m2pp_relop (s, t, ">=");
1767 0 : break;
1768 0 : case LT_EXPR:
1769 0 : m2pp_relop (s, t, "<");
1770 0 : break;
1771 0 : case GT_EXPR:
1772 0 : m2pp_relop (s, t, ">");
1773 0 : break;
1774 0 : case FLOAT_EXPR:
1775 0 : m2pp_float (s, t);
1776 0 : break;
1777 0 : default:
1778 0 : m2pp_simple_expression (s, t);
1779 : }
1780 0 : }
1781 :
1782 : /* m2pp_relop displays the lhs relop rhs. */
1783 :
1784 : static void
1785 0 : m2pp_relop (pretty *s, tree t, const char *p)
1786 : {
1787 0 : m2pp_expression (s, TREE_OPERAND (t, 0));
1788 0 : m2pp_needspace (s);
1789 0 : m2pp_print (s, p);
1790 0 : m2pp_needspace (s);
1791 0 : m2pp_expression (s, TREE_OPERAND (t, 1));
1792 0 : }
1793 :
1794 : /* m2pp_compound_expression handle compound expression tree. */
1795 :
1796 : static void
1797 0 : m2pp_compound_expression (pretty *s, tree t)
1798 : {
1799 0 : m2pp_print (s, "compound expression {");
1800 0 : m2pp_expression (s, TREE_OPERAND (t, 0));
1801 0 : m2pp_print (s, " (* result ignored *), ");
1802 0 : m2pp_expression (s, TREE_OPERAND (t, 1));
1803 0 : m2pp_print (s, "}");
1804 0 : m2pp_needspace (s);
1805 0 : }
1806 :
1807 : /* m2pp_target_expression handle target expression tree. */
1808 :
1809 : static void
1810 0 : m2pp_target_expression (pretty *s, tree t)
1811 : {
1812 0 : m2pp_print (s, "{");
1813 0 : m2pp_needspace (s);
1814 0 : if (TREE_OPERAND (t, 0) != NULL_TREE)
1815 : {
1816 0 : m2pp_print (s, "(* target *) ");
1817 0 : m2pp_expression (s, TREE_OPERAND (t, 0));
1818 0 : m2pp_print (s, ",");
1819 0 : m2pp_needspace (s);
1820 : }
1821 0 : if (TREE_OPERAND (t, 1) != NULL_TREE)
1822 : {
1823 0 : m2pp_print (s, "(* initializer *) ");
1824 0 : m2pp_expression (s, TREE_OPERAND (t, 1));
1825 0 : m2pp_print (s, ",");
1826 0 : m2pp_needspace (s);
1827 : }
1828 0 : if (TREE_OPERAND (t, 2) != NULL_TREE)
1829 : {
1830 0 : m2pp_print (s, "(* cleanup *) ");
1831 0 : m2pp_expression (s, TREE_OPERAND (t, 2));
1832 0 : m2pp_print (s, ",");
1833 0 : m2pp_needspace (s);
1834 : }
1835 0 : if (TREE_OPERAND (t, 3) != NULL_TREE)
1836 : {
1837 0 : m2pp_print (s, "(* saved initializer *) ");
1838 0 : m2pp_expression (s, TREE_OPERAND (t, 3));
1839 0 : m2pp_print (s, ",");
1840 0 : m2pp_needspace (s);
1841 : }
1842 0 : m2pp_print (s, "}");
1843 0 : m2pp_needspace (s);
1844 0 : }
1845 :
1846 : /* m2pp_constructor print out a constructor. */
1847 :
1848 : static void
1849 0 : m2pp_constructor (pretty *s, tree t)
1850 : {
1851 0 : tree purpose, value;
1852 0 : unsigned HOST_WIDE_INT ix;
1853 :
1854 0 : m2pp_print (s, "{ ");
1855 0 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t), ix, purpose, value)
1856 : {
1857 0 : m2pp_print (s, "(index: ");
1858 0 : m2pp_simple_expression (s, purpose);
1859 0 : m2pp_print (s, ") ");
1860 0 : m2pp_simple_expression (s, value);
1861 0 : m2pp_print (s, ", ");
1862 : }
1863 0 : m2pp_print (s, "}");
1864 : #ifdef VERBOSE_TYPE_DESC
1865 : m2pp_print (s, "(* type: ");
1866 : setindent (s, getindent (s) + 8);
1867 : m2pp_type (s, TREE_TYPE (t));
1868 : setindent (s, getindent (s) - 8);
1869 : m2pp_print (s, " *)\n");
1870 : #endif
1871 0 : }
1872 :
1873 : /* m2pp_complex_expr handle GCC complex_expr tree. */
1874 :
1875 : static void
1876 0 : m2pp_complex_expr (pretty *s, tree t)
1877 : {
1878 0 : if (TREE_CODE (t) == COMPLEX_CST)
1879 : {
1880 0 : m2pp_print (s, "CMPLX(");
1881 0 : m2pp_needspace (s);
1882 0 : m2pp_expression (s, TREE_REALPART (t));
1883 0 : m2pp_print (s, ",");
1884 0 : m2pp_needspace (s);
1885 0 : m2pp_expression (s, TREE_IMAGPART (t));
1886 0 : m2pp_print (s, ")");
1887 : }
1888 : else
1889 : {
1890 0 : m2pp_print (s, "CMPLX(");
1891 0 : m2pp_needspace (s);
1892 0 : m2pp_expression (s, TREE_OPERAND (t, 0));
1893 0 : m2pp_print (s, ",");
1894 0 : m2pp_needspace (s);
1895 0 : m2pp_expression (s, TREE_OPERAND (t, 1));
1896 0 : m2pp_print (s, ")");
1897 : }
1898 0 : }
1899 :
1900 : /* m2pp_imagpart_expr handle imagpart_expr tree. */
1901 :
1902 : static void
1903 0 : m2pp_imagpart_expr (pretty *s, tree t)
1904 : {
1905 0 : m2pp_print (s, "IM(");
1906 0 : m2pp_needspace (s);
1907 0 : if (TREE_CODE (t) == IMAGPART_EXPR)
1908 0 : m2pp_expression (s, TREE_OPERAND (t, 0));
1909 0 : else if (TREE_CODE (t) == COMPLEX_CST)
1910 0 : m2pp_expression (s, TREE_IMAGPART (t));
1911 0 : m2pp_needspace (s);
1912 0 : m2pp_print (s, ")");
1913 0 : }
1914 :
1915 : /* m2pp_realpart_expr handle imagpart_expr tree. */
1916 :
1917 : static void
1918 0 : m2pp_realpart_expr (pretty *s, tree t)
1919 : {
1920 0 : m2pp_print (s, "RE(");
1921 0 : m2pp_needspace (s);
1922 0 : if (TREE_CODE (t) == REALPART_EXPR)
1923 0 : m2pp_expression (s, TREE_OPERAND (t, 0));
1924 0 : else if (TREE_CODE (t) == COMPLEX_CST)
1925 0 : m2pp_expression (s, TREE_REALPART (t));
1926 0 : m2pp_needspace (s);
1927 0 : m2pp_print (s, ")");
1928 0 : }
1929 :
1930 : /* m2pp_bit_ior_expr generate a C style bit or. */
1931 :
1932 : static void
1933 0 : m2pp_bit_ior_expr (pretty *s, tree t)
1934 : {
1935 0 : m2pp_binary (s, t, "|");
1936 0 : }
1937 :
1938 : /* m2pp_bit_and_expr generate a C style bit and. */
1939 :
1940 : static void
1941 0 : m2pp_bit_and_expr (pretty *s, tree t)
1942 : {
1943 0 : m2pp_binary (s, t, "&");
1944 0 : }
1945 :
1946 : /* m2pp_truth_expr. */
1947 :
1948 : static void
1949 0 : m2pp_truth_expr (pretty *s, tree t, const char *op)
1950 : {
1951 0 : m2pp_print (s, "(");
1952 0 : m2pp_expression (s, TREE_OPERAND (t, 0));
1953 0 : m2pp_print (s, ")");
1954 0 : m2pp_needspace (s);
1955 0 : m2pp_print (s, op);
1956 0 : m2pp_needspace (s);
1957 0 : m2pp_print (s, "(");
1958 0 : m2pp_expression (s, TREE_OPERAND (t, 1));
1959 0 : m2pp_print (s, ")");
1960 0 : }
1961 :
1962 : /* m2pp_binary_function handle GCC expression tree as a function. */
1963 :
1964 : static void
1965 0 : m2pp_binary_function (pretty *s, tree t, const char *funcname)
1966 : {
1967 0 : m2pp_print (s, funcname);
1968 0 : m2pp_needspace (s);
1969 0 : m2pp_print (s, "(");
1970 0 : m2pp_expression (s, TREE_OPERAND (t, 0));
1971 0 : m2pp_print (s, ",");
1972 0 : m2pp_needspace (s);
1973 0 : m2pp_expression (s, TREE_OPERAND (t, 1));
1974 0 : m2pp_print (s, ")");
1975 0 : }
1976 :
1977 : static void
1978 0 : m2pp_shiftrotate_expr (pretty *s, tree t, const char *op)
1979 : {
1980 0 : tree left = TREE_OPERAND (t, 0);
1981 0 : tree right = TREE_OPERAND (t, 1);
1982 0 : m2pp_print (s, "(");
1983 0 : m2pp_expression (s, left);
1984 0 : m2pp_print (s, ")");
1985 0 : m2pp_needspace (s);
1986 0 : m2pp_print (s, op);
1987 0 : m2pp_needspace (s);
1988 0 : m2pp_print (s, "(");
1989 0 : m2pp_expression (s, right);
1990 0 : m2pp_print (s, ")");
1991 0 : }
1992 :
1993 : /* m2pp_simple_expression handle GCC expression tree. */
1994 :
1995 : static void
1996 0 : m2pp_simple_expression (pretty *s, tree t)
1997 : {
1998 0 : enum tree_code code = TREE_CODE (t);
1999 :
2000 0 : switch (code)
2001 : {
2002 0 : case ERROR_MARK:
2003 0 : m2pp_print (s, "(* !!! ERROR NODE !!! *)");
2004 0 : break;
2005 0 : case CONSTRUCTOR:
2006 0 : m2pp_constructor (s, t);
2007 0 : break;
2008 0 : case IDENTIFIER_NODE:
2009 0 : m2pp_ident_pointer (s, t);
2010 0 : break;
2011 0 : case PARM_DECL:
2012 0 : m2pp_identifier (s, t);
2013 0 : break;
2014 0 : case FIELD_DECL:
2015 0 : m2pp_identifier (s, t);
2016 0 : break;
2017 0 : case TREE_LIST:
2018 0 : m2pp_list (s, t);
2019 0 : break;
2020 0 : case BLOCK:
2021 0 : m2pp_print (s, "(* BLOCK NODE *)");
2022 0 : break;
2023 0 : case OFFSET_TYPE:
2024 0 : m2pp_offset (s, t);
2025 0 : break;
2026 0 : case INTEGER_CST:
2027 0 : m2pp_integer_cst (s, t);
2028 0 : break;
2029 0 : case REAL_CST:
2030 0 : m2pp_real_cst (s, t);
2031 0 : break;
2032 0 : case STRING_CST:
2033 0 : m2pp_string_cst (s, t);
2034 0 : break;
2035 0 : case INDIRECT_REF:
2036 0 : m2pp_indirect_ref (s, t);
2037 0 : break;
2038 0 : case ADDR_EXPR:
2039 0 : m2pp_addr_expr (s, t);
2040 0 : break;
2041 0 : case NOP_EXPR:
2042 0 : m2pp_nop (s, t);
2043 0 : break;
2044 0 : case CONVERT_EXPR:
2045 0 : m2pp_convert (s, t);
2046 0 : break;
2047 0 : case VAR_DECL:
2048 0 : m2pp_var_decl (s, t);
2049 0 : break;
2050 0 : case RESULT_DECL:
2051 0 : m2pp_result_decl (s, t);
2052 0 : break;
2053 0 : case PLUS_EXPR:
2054 0 : m2pp_binary (s, t, "+");
2055 0 : break;
2056 0 : case MINUS_EXPR:
2057 0 : m2pp_binary (s, t, "-");
2058 0 : break;
2059 0 : case MULT_EXPR:
2060 0 : m2pp_binary (s, t, "*");
2061 0 : break;
2062 0 : case FLOOR_DIV_EXPR:
2063 0 : case CEIL_DIV_EXPR:
2064 0 : case TRUNC_DIV_EXPR:
2065 0 : case ROUND_DIV_EXPR:
2066 0 : m2pp_binary (s, t, "DIV");
2067 0 : break;
2068 0 : case FLOOR_MOD_EXPR:
2069 0 : case CEIL_MOD_EXPR:
2070 0 : case TRUNC_MOD_EXPR:
2071 0 : case ROUND_MOD_EXPR:
2072 0 : m2pp_binary (s, t, "MOD");
2073 0 : break;
2074 0 : case NEGATE_EXPR:
2075 0 : m2pp_unary (s, t, "-");
2076 0 : break;
2077 0 : case CALL_EXPR:
2078 0 : m2pp_call_expr (s, t);
2079 0 : break;
2080 0 : case SSA_NAME:
2081 0 : m2pp_ssa (s, t);
2082 0 : break;
2083 0 : case COMPONENT_REF:
2084 0 : m2pp_component_ref (s, t);
2085 0 : break;
2086 0 : case RETURN_EXPR:
2087 0 : m2pp_return_expr (s, t);
2088 0 : break;
2089 0 : case ARRAY_REF:
2090 0 : m2pp_array_ref (s, t);
2091 0 : break;
2092 0 : case NON_LVALUE_EXPR:
2093 0 : m2pp_non_lvalue_expr (s, t);
2094 0 : break;
2095 0 : case EXPR_STMT:
2096 0 : m2pp_expression (s, EXPR_STMT_EXPR (t));
2097 0 : break;
2098 : #if 0
2099 : case EXC_PTR_EXPR:
2100 : m2pp_print (s, "GCC_EXCEPTION_OBJECT");
2101 : break;
2102 : #endif
2103 0 : case INIT_EXPR:
2104 0 : case MODIFY_EXPR:
2105 0 : m2pp_assignment (s, t);
2106 0 : break;
2107 0 : case COMPOUND_EXPR:
2108 0 : m2pp_compound_expression (s, t);
2109 0 : break;
2110 0 : case TARGET_EXPR:
2111 0 : m2pp_target_expression (s, t);
2112 0 : break;
2113 0 : case THROW_EXPR:
2114 0 : m2pp_throw (s, t);
2115 0 : break;
2116 0 : case FUNCTION_DECL:
2117 0 : m2pp_identifier (s, t);
2118 0 : break;
2119 0 : case COMPLEX_EXPR:
2120 0 : m2pp_complex_expr (s, t);
2121 0 : break;
2122 0 : case REALPART_EXPR:
2123 0 : m2pp_realpart_expr (s, t);
2124 0 : break;
2125 0 : case IMAGPART_EXPR:
2126 0 : m2pp_imagpart_expr (s, t);
2127 0 : break;
2128 0 : case CONST_DECL:
2129 0 : m2pp_identifier (s, t);
2130 0 : break;
2131 0 : case POINTER_PLUS_EXPR:
2132 0 : m2pp_binary (s, t, "+");
2133 0 : break;
2134 0 : case CLEANUP_POINT_EXPR:
2135 0 : m2pp_cleanup_point_expr (s, t);
2136 0 : break;
2137 0 : case BIT_IOR_EXPR:
2138 0 : m2pp_bit_ior_expr (s, t);
2139 0 : break;
2140 0 : case BIT_AND_EXPR:
2141 0 : m2pp_bit_and_expr (s, t);
2142 0 : break;
2143 0 : case TRUTH_ANDIF_EXPR:
2144 0 : m2pp_truth_expr (s, t, "AND");
2145 0 : break;
2146 0 : case TRUTH_ORIF_EXPR:
2147 0 : m2pp_truth_expr (s, t, "OR");
2148 0 : break;
2149 0 : case LSHIFT_EXPR:
2150 0 : m2pp_shiftrotate_expr (s, t, "<<");
2151 0 : break;
2152 0 : case RSHIFT_EXPR:
2153 0 : m2pp_shiftrotate_expr (s, t, ">>");
2154 0 : break;
2155 0 : case LROTATE_EXPR:
2156 0 : m2pp_binary_function (s, t, "LROTATE");
2157 0 : break;
2158 0 : case RROTATE_EXPR:
2159 0 : m2pp_binary_function (s, t, "RROTATE");
2160 0 : break;
2161 0 : default:
2162 0 : m2pp_unknown (s, __FUNCTION__, get_tree_code_name (code));
2163 : }
2164 0 : }
2165 :
2166 : /* non_lvalue_expr indicates that operand 0 is not an lvalue. */
2167 :
2168 : static void
2169 0 : m2pp_non_lvalue_expr (pretty *s, tree t)
2170 : {
2171 0 : m2pp_needspace (s);
2172 0 : m2pp_print (s, "assert_non_lvalue(");
2173 0 : m2pp_needspace (s);
2174 0 : m2pp_expression (s, TREE_OPERAND (t, 0));
2175 0 : m2pp_needspace (s);
2176 0 : m2pp_print (s, ")");
2177 0 : }
2178 :
2179 : /* m2pp_array_ref prints out the array reference. */
2180 :
2181 : static void
2182 0 : m2pp_array_ref (pretty *s, tree t)
2183 : {
2184 0 : m2pp_expression (s, TREE_OPERAND (t, 0));
2185 0 : m2pp_print (s, "[");
2186 0 : m2pp_expression (s, TREE_OPERAND (t, 1));
2187 0 : m2pp_print (s, "]");
2188 0 : }
2189 :
2190 : /* m2pp_ssa prints out the ssa variable name. */
2191 :
2192 : static void
2193 0 : m2pp_ssa (pretty *s, tree t)
2194 : {
2195 0 : m2pp_identifier (s, SSA_NAME_VAR (t));
2196 0 : }
2197 :
2198 : /* m2pp_binary print the binary operator, p, and lhs, rhs. */
2199 :
2200 : static void
2201 0 : m2pp_binary (pretty *s, tree t, const char *p)
2202 : {
2203 0 : tree left = TREE_OPERAND (t, 0);
2204 0 : tree right = TREE_OPERAND (t, 1);
2205 :
2206 0 : m2pp_expression (s, left);
2207 0 : m2pp_needspace (s);
2208 0 : m2pp_print (s, p);
2209 0 : m2pp_needspace (s);
2210 0 : m2pp_expression (s, right);
2211 0 : }
2212 :
2213 : /* m2pp_unary print the unary operator, p, and expression. */
2214 :
2215 : static void
2216 0 : m2pp_unary (pretty *s, tree t, const char *p)
2217 : {
2218 0 : tree expr = TREE_OPERAND (t, 0);
2219 :
2220 0 : m2pp_needspace (s);
2221 0 : m2pp_print (s, p);
2222 0 : m2pp_expression (s, expr);
2223 0 : }
2224 :
2225 : /* m2pp_integer_cst displays the integer constant. */
2226 :
2227 : static void
2228 0 : m2pp_integer_cst (pretty *s, tree t)
2229 : {
2230 0 : char val[100];
2231 :
2232 0 : snprintf (val, 100, HOST_WIDE_INT_PRINT_UNSIGNED, TREE_INT_CST_LOW (t));
2233 0 : m2pp_print (s, val);
2234 0 : }
2235 :
2236 : /* m2pp_real_cst displays the real constant. */
2237 :
2238 : static void
2239 0 : m2pp_real_cst (pretty *s, tree t ATTRIBUTE_UNUSED)
2240 : {
2241 0 : m2pp_print (s, "<unknown real>");
2242 0 : }
2243 :
2244 : /* m2pp_string_cst displays the real constant. */
2245 :
2246 : static void
2247 0 : m2pp_string_cst (pretty *s, tree t)
2248 : {
2249 0 : const char *p = TREE_STRING_POINTER (t);
2250 0 : int i = 0;
2251 :
2252 0 : m2pp_print (s, "\"");
2253 0 : while (p[i] != '\0')
2254 : {
2255 0 : m2pp_print_char (s, p[i]);
2256 0 : i++;
2257 : }
2258 0 : m2pp_print (s, "\"");
2259 0 : }
2260 :
2261 : /* m2pp_statement_sequence iterates over a statement list
2262 : displaying each statement in turn. */
2263 :
2264 : static void
2265 0 : m2pp_statement_sequence (pretty *s, tree t)
2266 : {
2267 0 : if (t != NULL_TREE)
2268 : {
2269 0 : if (TREE_CODE (t) == STATEMENT_LIST)
2270 : {
2271 0 : tree_stmt_iterator i;
2272 0 : m2pp_print (s, "(* statement list *)\n");
2273 :
2274 0 : for (i = tsi_start (t); !tsi_end_p (i); tsi_next (&i))
2275 0 : m2pp_statement (s, *tsi_stmt_ptr (i));
2276 : }
2277 : else
2278 0 : m2pp_statement (s, t);
2279 : }
2280 0 : }
2281 :
2282 : /* m2pp_unknown displays an error message. */
2283 :
2284 : static void
2285 0 : m2pp_unknown (pretty *s, const char *s1, const char *s2)
2286 : {
2287 0 : m2pp_begin (s);
2288 0 : m2pp_print (s, s1);
2289 0 : m2pp_needspace (s);
2290 0 : m2pp_print (s, s2);
2291 0 : m2pp_needspace (s);
2292 0 : }
2293 :
2294 : /* m2pp_throw displays a throw statement. */
2295 :
2296 : static void
2297 0 : m2pp_throw (pretty *s, tree t)
2298 : {
2299 0 : tree expr = TREE_OPERAND (t, 0);
2300 :
2301 0 : m2pp_begin (s);
2302 0 : if (expr == NULL_TREE)
2303 0 : m2pp_print (s, "THROW ;\n");
2304 : else
2305 : {
2306 0 : m2pp_print (s, "THROW (");
2307 0 : m2pp_expression (s, TREE_OPERAND (t, 0));
2308 0 : m2pp_print (s, ")\n");
2309 : }
2310 0 : }
2311 :
2312 : /* m2pp_catch_expr attempts to reconstruct a catch expr. */
2313 :
2314 : static void
2315 0 : m2pp_catch_expr (pretty *s, tree t)
2316 : {
2317 0 : tree types = CATCH_TYPES (t);
2318 0 : tree body = CATCH_BODY (t);
2319 :
2320 0 : m2pp_print (s, "(* CATCH expression ");
2321 0 : if (types != NULL_TREE)
2322 : {
2323 0 : m2pp_print (s, "(");
2324 0 : m2pp_expression (s, types);
2325 0 : m2pp_print (s, ")");
2326 : }
2327 0 : m2pp_print (s, "*)\n");
2328 0 : m2pp_print (s, "(* catch body *)\n");
2329 0 : m2pp_statement_sequence (s, body);
2330 0 : m2pp_print (s, "(* end catch body *)\n");
2331 0 : }
2332 :
2333 : /* m2pp_try_finally_expr attemts to reconstruct a try finally expr. */
2334 :
2335 : static void
2336 0 : m2pp_try_finally_expr (pretty *s, tree t)
2337 : {
2338 0 : m2pp_begin (s);
2339 0 : m2pp_print (s, "(* try_finally_expr *)\n");
2340 0 : setindent (s, getindent (s) + 3);
2341 0 : m2pp_statement_sequence (s, TREE_OPERAND (t, 0));
2342 0 : setindent (s, getindent (s) - 3);
2343 0 : m2pp_print (s,
2344 : "(* finally (cleanup which is executed after the above) *)\n");
2345 0 : setindent (s, getindent (s) + 3);
2346 0 : m2pp_statement_sequence (s, TREE_OPERAND (t, 1));
2347 0 : setindent (s, getindent (s) - 3);
2348 0 : m2pp_print (s, "(* end try_finally_expr *)\n");
2349 0 : }
2350 :
2351 : /* m2pp_if_stmt pretty print a if_stmt tree. Modula-2 does not use this to
2352 : generate IF THEN ELSE END statements, instead it uses labels and gotos. */
2353 :
2354 : static void
2355 0 : m2pp_if_stmt (pretty *s, tree t)
2356 : {
2357 0 : m2pp_print (s, "(* An if_stmt node. *)\n");
2358 0 : m2pp_print (s, "IF ");
2359 0 : m2pp_expression (s, TREE_OPERAND (t, 0));
2360 0 : m2pp_print (s, "\n");
2361 0 : m2pp_print (s, "THEN\n");
2362 0 : setindent (s, getindent (s) + 3);
2363 0 : m2pp_statement_sequence (s, TREE_OPERAND (t, 1));
2364 0 : setindent (s, getindent (s) - 3);
2365 0 : m2pp_print (s, "ELSE\n");
2366 0 : setindent (s, getindent (s) + 3);
2367 0 : m2pp_statement_sequence (s, TREE_OPERAND (t, 2));
2368 0 : setindent (s, getindent (s) - 3);
2369 0 : m2pp_print (s, "END\n");
2370 0 : }
2371 :
2372 : static void
2373 0 : m2pp_asm_expr (pretty *state, tree node)
2374 : {
2375 0 : m2pp_begin (state);
2376 0 : m2pp_print (state, "ASM");
2377 0 : m2pp_needspace (state);
2378 0 : if (ASM_VOLATILE_P (node))
2379 : {
2380 0 : m2pp_print (state, "VOLATILE");
2381 0 : m2pp_needspace (state);
2382 : }
2383 0 : m2pp_print (state, "(");
2384 0 : m2pp_expression (state, ASM_STRING (node));
2385 0 : m2pp_print (state, ":");
2386 0 : m2pp_needspace (state);
2387 0 : m2pp_expression (state, ASM_OUTPUTS (node));
2388 0 : m2pp_print (state, ":");
2389 0 : m2pp_needspace (state);
2390 0 : m2pp_expression (state, ASM_INPUTS (node));
2391 0 : if (ASM_CLOBBERS (node) != NULL)
2392 : {
2393 0 : m2pp_print (state, ":");
2394 0 : m2pp_needspace (state);
2395 0 : m2pp_expression (state, ASM_CLOBBERS (node));
2396 : }
2397 0 : m2pp_print (state, ");\n");
2398 0 : }
2399 :
2400 : /* m2pp_nop_expr display the nop_expr node. */
2401 :
2402 : static void
2403 0 : m2pp_nop_expr (pretty *state, tree t)
2404 : {
2405 0 : m2pp_begin (state);
2406 0 : m2pp_print (state, "(* NOP for debug location *)");
2407 0 : m2pp_needspace (state);
2408 0 : m2pp_loc (state, t);
2409 0 : }
2410 :
2411 : /* m2pp_statement attempts to reconstruct a statement. */
2412 :
2413 : static void
2414 0 : m2pp_statement (pretty *s, tree t)
2415 : {
2416 0 : enum tree_code code = TREE_CODE (t);
2417 :
2418 0 : m2pp_loc (s, t);
2419 0 : switch (code)
2420 : {
2421 0 : case COND_EXPR:
2422 0 : m2pp_conditional (s, t);
2423 0 : break;
2424 0 : case LABEL_EXPR:
2425 0 : m2pp_label_expr (s, t);
2426 0 : break;
2427 0 : case LABEL_DECL:
2428 0 : m2pp_label_decl (s, t);
2429 0 : break;
2430 0 : case GOTO_EXPR:
2431 0 : m2pp_goto (s, t);
2432 0 : break;
2433 0 : case INIT_EXPR:
2434 0 : case MODIFY_EXPR:
2435 0 : m2pp_assignment (s, t);
2436 0 : break;
2437 0 : case CALL_EXPR:
2438 0 : m2pp_procedure_call (s, t);
2439 0 : break;
2440 0 : case BLOCK:
2441 0 : m2pp_block_list (s, t);
2442 0 : break;
2443 0 : case BIND_EXPR:
2444 0 : m2pp_bind_expr (s, t);
2445 0 : break;
2446 0 : case RETURN_EXPR:
2447 0 : m2pp_return_expr (s, t);
2448 0 : break;
2449 0 : case DECL_EXPR:
2450 0 : m2pp_decl_expr (s, t);
2451 0 : break;
2452 0 : case TRY_BLOCK:
2453 0 : m2pp_try_block (s, t);
2454 0 : break;
2455 0 : case HANDLER:
2456 0 : m2pp_handler (s, t);
2457 0 : break;
2458 0 : case CLEANUP_POINT_EXPR:
2459 0 : m2pp_cleanup_point_expr (s, t);
2460 0 : break;
2461 0 : case THROW_EXPR:
2462 0 : m2pp_throw (s, t);
2463 0 : break;
2464 0 : case TRY_CATCH_EXPR:
2465 0 : m2pp_try_catch_expr (s, t);
2466 0 : break;
2467 0 : case TRY_FINALLY_EXPR:
2468 0 : m2pp_try_finally_expr (s, t);
2469 0 : break;
2470 0 : case CATCH_EXPR:
2471 0 : m2pp_catch_expr (s, t);
2472 0 : break;
2473 0 : case ASM_EXPR:
2474 0 : m2pp_asm_expr (s, t);
2475 0 : break;
2476 0 : case IF_STMT:
2477 0 : m2pp_if_stmt (s, t);
2478 0 : break;
2479 0 : case NOP_EXPR:
2480 0 : m2pp_nop_expr (s, t);
2481 0 : break;
2482 0 : case ERROR_MARK:
2483 0 : m2pp_print (s, "<ERROR CODE>\n");
2484 0 : break;
2485 0 : default:
2486 0 : m2pp_unknown (s, __FUNCTION__, get_tree_code_name (TREE_CODE (t)));
2487 : }
2488 0 : }
2489 :
2490 : /* m2pp_try_catch_expr is used after gimplification. */
2491 :
2492 : static void
2493 0 : m2pp_try_catch_expr (pretty *s, tree t)
2494 : {
2495 0 : m2pp_print (s, "(* try_catch_expr begins *)\n");
2496 0 : m2pp_statement_sequence (s, TREE_OPERAND (t, 0));
2497 0 : setindent (s, 0);
2498 0 : m2pp_print (s, "EXCEPT\n");
2499 0 : setindent (s, 3);
2500 0 : m2pp_statement_sequence (s, TREE_OPERAND (t, 1));
2501 0 : m2pp_print (s, "(* try_catch_expr ends *)\n");
2502 0 : }
2503 :
2504 : /* m2pp_cleanup_point_expr emits a comment indicating a GCC
2505 : cleanup_point_expr is present. */
2506 :
2507 : static void
2508 0 : m2pp_cleanup_point_expr (pretty *s, tree t)
2509 : {
2510 0 : m2pp_begin (s);
2511 0 : m2pp_print (s, "(* Cleanup point begins. *)\n");
2512 0 : m2pp_expression (s, TREE_OPERAND (t, 0));
2513 0 : m2pp_print (s, "(* Cleanup point ends. *)\n");
2514 0 : }
2515 :
2516 : /* m2pp_decl_expr displays a local declaration. */
2517 :
2518 : static void
2519 0 : m2pp_decl_expr (pretty *s, tree t)
2520 : {
2521 0 : m2pp_var (s);
2522 0 : m2pp_print (s, "(* Variable in decl_expr. *)\n");
2523 0 : m2pp_var_type_decl (s, DECL_EXPR_DECL (t));
2524 0 : }
2525 :
2526 : /* m2pp_procedure_call print a call to a procedure. */
2527 :
2528 : static void
2529 0 : m2pp_procedure_call (pretty *s, tree t)
2530 : {
2531 0 : m2pp_begin (s);
2532 0 : m2pp_call_expr (s, t);
2533 0 : m2pp_needspace (s);
2534 0 : m2pp_print (s, ";\n");
2535 0 : }
2536 :
2537 : /* args displays each argument in an iter list by calling expression. */
2538 :
2539 : static void
2540 0 : m2pp_args (pretty *s, tree e)
2541 : {
2542 0 : call_expr_arg_iterator iter;
2543 0 : tree arg;
2544 :
2545 0 : m2pp_print (s, "(");
2546 0 : m2pp_needspace (s);
2547 0 : FOR_EACH_CALL_EXPR_ARG (arg, iter, e)
2548 : {
2549 0 : m2pp_expression (s, arg);
2550 0 : if (more_call_expr_args_p (&iter))
2551 : {
2552 0 : m2pp_print (s, ",");
2553 0 : m2pp_needspace (s);
2554 : }
2555 : }
2556 0 : m2pp_print (s, ")");
2557 0 : }
2558 :
2559 : /* m2pp_call_expr print a call to a procedure or function. */
2560 :
2561 : static void
2562 0 : m2pp_call_expr (pretty *s, tree t)
2563 : {
2564 0 : tree call = CALL_EXPR_FN (t);
2565 0 : tree args = TREE_OPERAND (t, 1);
2566 0 : tree type = TREE_TYPE (t);
2567 0 : bool has_return_type = true;
2568 0 : tree proc;
2569 :
2570 0 : if (type && VOID_TYPE_P (type))
2571 0 : has_return_type = false;
2572 :
2573 0 : if (TREE_CODE (call) == ADDR_EXPR || TREE_CODE (call) == NON_LVALUE_EXPR)
2574 0 : proc = TREE_OPERAND (call, 0);
2575 : else
2576 : proc = call;
2577 :
2578 0 : m2pp_expression (s, proc);
2579 0 : if (args || has_return_type)
2580 0 : m2pp_args (s, t);
2581 0 : }
2582 :
2583 : /* m2pp_return_expr displays the return statement. */
2584 :
2585 : static void
2586 0 : m2pp_return_expr (pretty *s, tree t)
2587 : {
2588 0 : tree e = TREE_OPERAND (t, 0);
2589 :
2590 0 : m2pp_begin (s);
2591 0 : if (e == NULL_TREE)
2592 : {
2593 0 : m2pp_print (s, "RETURN");
2594 : }
2595 0 : else if (TREE_CODE (e) == MODIFY_EXPR || (TREE_CODE (e) == INIT_EXPR))
2596 : {
2597 0 : m2pp_assignment (s, e);
2598 0 : m2pp_print (s, "RETURN");
2599 0 : m2pp_needspace (s);
2600 0 : m2pp_expression (s, TREE_OPERAND (e, 0));
2601 : }
2602 : else
2603 : {
2604 0 : m2pp_print (s, "RETURN");
2605 0 : m2pp_needspace (s);
2606 0 : m2pp_expression (s, e);
2607 : }
2608 0 : m2pp_needspace (s);
2609 0 : m2pp_print (s, ";\n");
2610 0 : }
2611 :
2612 : /* m2pp_try_block displays the try block. */
2613 :
2614 : static void
2615 0 : m2pp_try_block (pretty *s, tree t)
2616 : {
2617 0 : tree stmts = TRY_STMTS (t);
2618 0 : tree handlers = TRY_HANDLERS (t);
2619 :
2620 0 : m2pp_begin (s);
2621 0 : m2pp_print (s, "(* TRY *)\n");
2622 0 : m2pp_statement_sequence (s, stmts);
2623 0 : setindent (s, 0);
2624 0 : m2pp_print (s, "EXCEPT\n");
2625 0 : setindent (s, 3);
2626 0 : m2pp_statement_sequence (s, handlers);
2627 0 : m2pp_print (s, "(* END TRY *)\n");
2628 0 : }
2629 :
2630 : /* m2pp_try_block displays the handler block. */
2631 :
2632 : static void
2633 0 : m2pp_handler (pretty *s, tree t)
2634 : {
2635 0 : tree parms = HANDLER_PARMS (t);
2636 0 : tree body = HANDLER_BODY (t);
2637 0 : tree type = HANDLER_TYPE (t);
2638 :
2639 0 : m2pp_print (s, "(* handler *)\n");
2640 0 : if (parms != NULL_TREE)
2641 : {
2642 0 : m2pp_print (s, "(* handler parameter has a type (should be NULL_TREE) "
2643 : "in Modula-2 *)\n");
2644 0 : m2pp_print (s, "CATCH (");
2645 0 : m2pp_expression (s, parms);
2646 0 : m2pp_print (s, ")\n");
2647 : }
2648 0 : if (type != NULL_TREE)
2649 0 : m2pp_print (s, "(* handler type (should be NULL_TREE) in Modula-2 *)\n");
2650 0 : m2pp_statement_sequence (s, body);
2651 0 : }
2652 :
2653 : /* m2pp_assignment prints out the assignment statement. */
2654 :
2655 : static void
2656 0 : m2pp_assignment (pretty *s, tree t)
2657 : {
2658 0 : int o;
2659 :
2660 0 : m2pp_begin (s);
2661 : #ifdef VERBOSE_TYPE_DESC
2662 : /* Print the types of des and expr. */
2663 : m2pp_print (s, "(*");
2664 : m2pp_needspace (s);
2665 : m2pp_type (s, TREE_TYPE (TREE_OPERAND (t, 0)));
2666 : m2pp_needspace (s);
2667 : m2pp_print (s, ":=");
2668 : m2pp_needspace (s);
2669 : m2pp_type (s, TREE_TYPE (TREE_OPERAND (t, 1)));
2670 : m2pp_needspace (s);
2671 : m2pp_print (s, ";");
2672 : m2pp_needspace (s);
2673 : m2pp_print (s, "*)\n");
2674 : #endif
2675 : /* Print the assignment statement. */
2676 0 : m2pp_designator (s, TREE_OPERAND (t, 0));
2677 0 : m2pp_needspace (s);
2678 0 : m2pp_print (s, ":=");
2679 0 : m2pp_needspace (s);
2680 0 : o = getindent (s);
2681 0 : setindent (s, getcurpos (s) + 1);
2682 0 : m2pp_expression (s, TREE_OPERAND (t, 1));
2683 0 : m2pp_needspace (s);
2684 0 : m2pp_print (s, ";\n");
2685 0 : setindent (s, o);
2686 0 : }
2687 :
2688 : /* m2pp_designator displays the lhs of an assignment. */
2689 :
2690 : static void
2691 0 : m2pp_designator (pretty *s, tree t)
2692 : {
2693 0 : m2pp_expression (s, t);
2694 0 : }
2695 :
2696 : /* m2pp_indirect_ref displays the indirect operator. */
2697 :
2698 : static void
2699 0 : m2pp_indirect_ref (pretty *s, tree t)
2700 : {
2701 0 : m2pp_print (s, "(");
2702 0 : m2pp_expression (s, TREE_OPERAND (t, 0));
2703 0 : m2pp_print (s, ")^");
2704 0 : }
2705 :
2706 : /* m2pp_conditional builds an IF THEN ELSE END. With more work
2707 : this should be moved into statement sequence which could look for
2708 : repeat and while loops. */
2709 :
2710 : static void
2711 0 : m2pp_conditional (pretty *s, tree t)
2712 : {
2713 0 : int o;
2714 :
2715 0 : m2pp_begin (s);
2716 0 : m2pp_print (s, "IF");
2717 0 : m2pp_needspace (s);
2718 0 : m2pp_expression (s, TREE_OPERAND (t, 0));
2719 0 : m2pp_print (s, "\nTHEN\n");
2720 0 : o = getindent (s);
2721 0 : setindent (s, o + 3);
2722 0 : m2pp_statement_sequence (s, TREE_OPERAND (t, 1));
2723 0 : setindent (s, o);
2724 0 : if (TREE_OPERAND (t, 2) != NULL_TREE)
2725 : {
2726 0 : m2pp_print (s, "ELSE\n");
2727 0 : setindent (s, o + 3);
2728 0 : m2pp_statement_sequence (s, TREE_OPERAND (t, 2));
2729 0 : setindent (s, o);
2730 : }
2731 0 : m2pp_print (s, "END ;\n");
2732 0 : }
2733 :
2734 : /* m2pp_label_decl displays a label. Again should be moved into
2735 : statement sequence to determine proper loop constructs. */
2736 :
2737 : static void
2738 0 : m2pp_label_decl (pretty *s, tree t)
2739 : {
2740 0 : m2pp_begin (s);
2741 0 : m2pp_print (s, "(* label ");
2742 0 : m2pp_identifier (s, t);
2743 0 : m2pp_print (s, ": *)\n");
2744 0 : }
2745 :
2746 : /* m2pp_label_expr skips the LABEL_EXPR to find the LABEL_DECL. */
2747 :
2748 : static void
2749 0 : m2pp_label_expr (pretty *s, tree t)
2750 : {
2751 0 : m2pp_begin (s);
2752 0 : m2pp_statement (s, TREE_OPERAND (t, 0));
2753 0 : }
2754 :
2755 : /* m2pp_goto displays a goto statement. Again should be moved into
2756 : statement sequence to determine proper loop constructs. */
2757 :
2758 : static void
2759 0 : m2pp_goto (pretty *s, tree t)
2760 : {
2761 0 : m2pp_begin (s);
2762 0 : m2pp_print (s, "(* goto ");
2763 0 : m2pp_identifier (s, TREE_OPERAND (t, 0));
2764 0 : m2pp_print (s, " *)\n");
2765 0 : }
2766 :
2767 : /* m2pp_list prints a TREE_CHAINed list. */
2768 :
2769 : static void
2770 0 : m2pp_list (pretty *s, tree t)
2771 : {
2772 0 : tree u = t;
2773 :
2774 0 : m2pp_print (s, "(");
2775 0 : m2pp_needspace (s);
2776 0 : while (t != NULL_TREE)
2777 : {
2778 0 : m2pp_expression (s, TREE_VALUE (t));
2779 0 : t = TREE_CHAIN (t);
2780 0 : if (t == u || t == NULL_TREE)
2781 : break;
2782 0 : m2pp_print (s, ",");
2783 0 : m2pp_needspace (s);
2784 : }
2785 0 : m2pp_needspace (s);
2786 0 : m2pp_print (s, ")");
2787 0 : }
2788 :
2789 : /* m2pp_offset displays the offset operator. */
2790 :
2791 : static void
2792 0 : m2pp_offset (pretty *s, tree t)
2793 : {
2794 0 : tree type = TREE_TYPE (t);
2795 0 : tree base = TYPE_OFFSET_BASETYPE (t);
2796 :
2797 0 : m2pp_print (s, "OFFSET (");
2798 0 : m2pp_type (s, base);
2799 0 : m2pp_print (s, ".");
2800 0 : m2pp_type (s, type);
2801 0 : m2pp_print (s, ")");
2802 0 : }
2803 :
2804 : /* m2pp_addr_expr create an ADR expression. */
2805 :
2806 : static void
2807 0 : m2pp_addr_expr (pretty *s, tree t)
2808 : {
2809 0 : m2pp_needspace (s);
2810 0 : m2pp_print (s, "ADR (");
2811 0 : m2pp_expression (s, TREE_OPERAND (t, 0));
2812 0 : m2pp_print (s, ")");
2813 0 : }
2814 :
2815 : /* m2pp_nop generate a CAST expression. */
2816 :
2817 : static void
2818 0 : m2pp_nop (pretty *s, tree t)
2819 : {
2820 0 : m2pp_needspace (s);
2821 0 : m2pp_print (s, "CAST (");
2822 0 : m2pp_simple_type (s, TREE_TYPE (t));
2823 0 : m2pp_print (s, ", ");
2824 0 : m2pp_expression (s, TREE_OPERAND (t, 0));
2825 0 : m2pp_print (s, ")");
2826 0 : }
2827 :
2828 : /* m2pp_convert generate a CONVERT expression. */
2829 :
2830 : static void
2831 0 : m2pp_convert (pretty *s, tree t)
2832 : {
2833 0 : m2pp_needspace (s);
2834 0 : m2pp_print (s, "CONVERT (");
2835 0 : m2pp_simple_type (s, TREE_TYPE (t));
2836 0 : m2pp_print (s, ", ");
2837 0 : m2pp_expression (s, TREE_OPERAND (t, 0));
2838 0 : m2pp_print (s, ")");
2839 0 : }
2840 :
2841 : /* m2pp_var_decl generate a variable. */
2842 :
2843 : static void
2844 0 : m2pp_var_decl (pretty *s, tree t)
2845 : {
2846 0 : m2pp_identifier (s, t);
2847 0 : }
2848 :
2849 : /* m2pp_result_decl generate a result declaration (variable). */
2850 :
2851 : static void
2852 0 : m2pp_result_decl (pretty *s, tree t)
2853 : {
2854 0 : m2pp_identifier (s, t);
2855 0 : }
2856 :
2857 : /* m2pp_component_ref generate a record field access. */
2858 :
2859 : static void
2860 0 : m2pp_component_ref (pretty *s, tree t)
2861 : {
2862 0 : m2pp_simple_expression (s, TREE_OPERAND (t, 0));
2863 0 : m2pp_print (s, ".");
2864 0 : m2pp_simple_expression (s, TREE_OPERAND (t, 1));
2865 0 : }
2866 :
2867 : }
2868 :
2869 : /* Code interface to this module. */
2870 :
2871 : /* CreateDumpGimple creates the dump files using the template name. */
2872 :
2873 : void
2874 0 : m2pp_CreateDumpGimple (char *template_name, int template_len)
2875 : {
2876 0 : int kind = M2PP_DUMP_STDOUT;
2877 0 : modula2::m2pp_output_file[kind] = stdout;
2878 0 : kind++;
2879 0 : for (; kind < M2PP_DUMP_END; kind++)
2880 : {
2881 0 : if (kind == M2PP_DUMP_FD)
2882 0 : modula2::m2pp_output_file[kind] = NULL;
2883 : else
2884 : {
2885 0 : char *name = (char *)alloca (template_len);
2886 :
2887 0 : snprintf (name, template_len, template_name, kind);
2888 0 : modula2::m2pp_output_file[kind] = fopen (name, "w");
2889 0 : if (modula2::m2pp_output_file[kind] == NULL)
2890 : {
2891 0 : fprintf (stderr, "unable to create dump file %s: %s\n",
2892 0 : name, xstrerror (errno));
2893 0 : exit (1);
2894 : }
2895 0 : fprintf (modula2::m2pp_output_file[kind], "%s\n\n",
2896 : m2pp_dump_description[kind]);
2897 : }
2898 : }
2899 0 : }
2900 :
2901 : /* Close all dump files and fflush stdout. */
2902 :
2903 : void
2904 0 : m2pp_CloseDumpGimple (void)
2905 : {
2906 0 : int kind = M2PP_DUMP_STDOUT;
2907 0 : fflush (modula2::m2pp_output_file[kind]);
2908 0 : kind++;
2909 0 : for (; kind < M2PP_DUMP_END; kind++)
2910 0 : if (kind != M2PP_DUMP_FD)
2911 0 : fclose (modula2::m2pp_output_file[kind]);
2912 0 : }
2913 :
2914 : /* m2pp_dump_gimple_pretty create an initPretty object and print
2915 : fndecl to kind output. */
2916 :
2917 : void
2918 0 : m2pp_dump_gimple_pretty (m2pp_dump_kind kind, tree fndecl)
2919 : {
2920 0 : modula2::pretty *state = modula2::initPretty (kind, 0);
2921 :
2922 0 : modula2::m2pp_print (state, "\n");
2923 0 : if (TREE_CODE (fndecl) == TRANSLATION_UNIT_DECL)
2924 0 : modula2::m2pp_translation (state, fndecl);
2925 0 : else if (TREE_CODE (fndecl) == BLOCK)
2926 0 : modula2::m2pp_module_block (state, fndecl);
2927 0 : else if (TREE_CODE (fndecl) == FUNCTION_DECL)
2928 0 : modula2::m2pp_function (state, fndecl);
2929 : else
2930 0 : modula2::m2pp_statement_sequence (state, fndecl);
2931 0 : modula2::killPretty (state);
2932 0 : }
2933 :
2934 :
2935 : /* Generate modula-2 style gimple for fndecl. */
2936 :
2937 : void
2938 219750 : m2pp_dump_gimple (m2pp_dump_kind kind, tree fndecl)
2939 : {
2940 219750 : if (M2Options_GetDumpGimple ()
2941 219750 : && M2LangDump_IsDumpRequiredTree (fndecl, true))
2942 0 : m2pp_dump_gimple_pretty (kind, fndecl);
2943 219750 : }
2944 :
2945 :
2946 : /* Dump fndecl to a file descriptor. */
2947 :
2948 : void
2949 0 : m2pp_DumpGimpleFd (int fd, tree fndecl)
2950 : {
2951 0 : FILE *f = fdopen (fd, "a");
2952 0 : if (f != NULL)
2953 : {
2954 : #if 0
2955 : modula2::m2pp_output_file[M2PP_DUMP_FD] = f;
2956 : m2pp_dump_gimple_pretty (M2PP_DUMP_FD, fndecl);
2957 : fprintf (f, "\n");
2958 : #endif
2959 0 : print_node (f, "m2 tree", fndecl, 1);
2960 0 : fprintf (f, "\n\n");
2961 0 : fflush (f);
2962 : #if 0
2963 : modula2::m2pp_output_file[M2PP_DUMP_FD] = NULL;
2964 : #endif
2965 : }
2966 0 : }
|