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