| 1 |
/* m2statement.cc provides an interface to GCC statement trees. |
| 2 |
|
| 3 |
Copyright (C) 2012-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 "../gm2-lang.h" |
| 25 |
#include "../m2-tree.h" |
| 26 |
|
| 27 |
/* Prototypes. */ |
| 28 |
|
| 29 |
#define m2statement_c |
| 30 |
#include "m2assert.h" |
| 31 |
#include "m2block.h" |
| 32 |
#include "m2decl.h" |
| 33 |
#include "m2expr.h" |
| 34 |
#include "m2statement.h" |
| 35 |
#include "m2tree.h" |
| 36 |
#include "m2treelib.h" |
| 37 |
#include "m2type.h" |
| 38 |
#include "m2convert.h" |
| 39 |
#include "m2builtins.h" |
| 40 |
#include "m2pp.h" |
| 41 |
|
| 42 |
static GTY (()) tree param_list = NULL_TREE; /* Ready for the next time we |
| 43 |
call/define a function. */ |
| 44 |
static GTY (()) tree last_function = NULL_TREE; |
| 45 |
|
| 46 |
|
| 47 |
/* BuildStartFunctionCode - generate function entry code. */ |
| 48 |
|
| 49 |
void |
| 50 |
m2statement_BuildStartFunctionCode (location_t location, tree fndecl, |
| 51 |
bool isexported, bool isinline) |
| 52 |
{ |
| 53 |
tree param_decl; |
| 54 |
|
| 55 |
ASSERT_BOOL (isexported); |
| 56 |
ASSERT_BOOL (isinline); |
| 57 |
/* Announce we are compiling this function. */ |
| 58 |
announce_function (fndecl); |
| 59 |
|
| 60 |
/* Set up to compile the function and enter it. */ |
| 61 |
|
| 62 |
DECL_INITIAL (fndecl) = NULL_TREE; |
| 63 |
|
| 64 |
current_function_decl = fndecl; |
| 65 |
m2block_pushFunctionScope (fndecl); |
| 66 |
m2statement_SetBeginLocation (location); |
| 67 |
|
| 68 |
ASSERT_BOOL ((cfun != NULL)); |
| 69 |
/* Initialize the RTL code for the function. */ |
| 70 |
allocate_struct_function (fndecl, false); |
| 71 |
/* Begin the statement tree for this function. */ |
| 72 |
DECL_SAVED_TREE (fndecl) = NULL_TREE; |
| 73 |
|
| 74 |
/* Set the context of these parameters to this function. */ |
| 75 |
for (param_decl = DECL_ARGUMENTS (fndecl); param_decl; |
| 76 |
param_decl = TREE_CHAIN (param_decl)) |
| 77 |
DECL_CONTEXT (param_decl) = fndecl; |
| 78 |
|
| 79 |
/* This function exists in static storage. (This does not mean |
| 80 |
`static' in the C sense!) */ |
| 81 |
TREE_STATIC (fndecl) = 1; |
| 82 |
TREE_PUBLIC (fndecl) = isexported; |
| 83 |
/* We could do better here by detecting ADR |
| 84 |
or type PROC used on this function. --fixme-- */ |
| 85 |
TREE_ADDRESSABLE (fndecl) = 1; |
| 86 |
DECL_DECLARED_INLINE_P (fndecl) = 0; /* isinline; */ |
| 87 |
} |
| 88 |
|
| 89 |
/* BuildEndFunctionCode - generates the function epilogue. */ |
| 90 |
|
| 91 |
void |
| 92 |
m2statement_BuildEndFunctionCode (location_t location, tree fndecl, bool nested) |
| 93 |
{ |
| 94 |
tree block = DECL_INITIAL (fndecl); |
| 95 |
|
| 96 |
BLOCK_SUPERCONTEXT (block) = fndecl; |
| 97 |
|
| 98 |
/* Must mark the RESULT_DECL as being in this function. */ |
| 99 |
DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl; |
| 100 |
|
| 101 |
/* And attach it to the function. */ |
| 102 |
DECL_INITIAL (fndecl) = block; |
| 103 |
|
| 104 |
m2block_finishFunctionCode (fndecl); |
| 105 |
m2statement_SetEndLocation (location); |
| 106 |
|
| 107 |
m2pp_dump_gimple (M2PP_DUMP_PRE_GENERICIZE, fndecl); |
| 108 |
gm2_genericize (fndecl); |
| 109 |
if (nested) |
| 110 |
(void)cgraph_node::get_create (fndecl); |
| 111 |
else |
| 112 |
{ |
| 113 |
m2pp_dump_gimple (M2PP_DUMP_POST_GENERICIZE, fndecl); |
| 114 |
cgraph_node::finalize_function (fndecl, false); |
| 115 |
} |
| 116 |
|
| 117 |
m2block_popFunctionScope (); |
| 118 |
|
| 119 |
/* We're leaving the context of this function, so zap cfun. It's |
| 120 |
still in DECL_STRUCT_FUNCTION, and we'll restore it in |
| 121 |
tree_rest_of_compilation. */ |
| 122 |
set_cfun (NULL); |
| 123 |
current_function_decl = NULL; |
| 124 |
} |
| 125 |
|
| 126 |
/* BuildPushFunctionContext - pushes the current function context. |
| 127 |
Maps onto push_function_context in ../function.cc. */ |
| 128 |
|
| 129 |
void |
| 130 |
m2statement_BuildPushFunctionContext (void) |
| 131 |
{ |
| 132 |
push_function_context (); |
| 133 |
} |
| 134 |
|
| 135 |
/* BuildPopFunctionContext - pops the current function context. Maps |
| 136 |
onto pop_function_context in ../function.cc. */ |
| 137 |
|
| 138 |
void |
| 139 |
m2statement_BuildPopFunctionContext (void) |
| 140 |
{ |
| 141 |
pop_function_context (); |
| 142 |
} |
| 143 |
|
| 144 |
void |
| 145 |
m2statement_SetBeginLocation (location_t location) |
| 146 |
{ |
| 147 |
if (cfun != NULL) |
| 148 |
cfun->function_start_locus = location; |
| 149 |
} |
| 150 |
|
| 151 |
void |
| 152 |
m2statement_SetEndLocation (location_t location) |
| 153 |
{ |
| 154 |
if (cfun != NULL) |
| 155 |
cfun->function_end_locus = location; |
| 156 |
} |
| 157 |
|
| 158 |
/* copy_record_fields copy each record field from right to left. */ |
| 159 |
|
| 160 |
static |
| 161 |
void |
| 162 |
copy_record_fields (location_t location, tree left, tree right) |
| 163 |
{ |
| 164 |
unsigned int i; |
| 165 |
tree right_value; |
| 166 |
tree left_type = TREE_TYPE (left); |
| 167 |
vec<constructor_elt, va_gc> *values = CONSTRUCTOR_ELTS (right); |
| 168 |
FOR_EACH_CONSTRUCTOR_VALUE (values, i, right_value) |
| 169 |
{ |
| 170 |
tree left_field = m2treelib_get_field_no (left_type, NULL_TREE, false, i); |
| 171 |
tree left_ref = m2expr_BuildComponentRef (location, left, left_field); |
| 172 |
m2statement_CopyByField (location, left_ref, right_value); |
| 173 |
} |
| 174 |
} |
| 175 |
|
| 176 |
/* copy_array copy each element of an array from array right to array left. */ |
| 177 |
|
| 178 |
static |
| 179 |
void |
| 180 |
copy_array (location_t location, tree left, tree right) |
| 181 |
{ |
| 182 |
unsigned int i; |
| 183 |
tree value; |
| 184 |
vec<constructor_elt, va_gc> *values = CONSTRUCTOR_ELTS (right); |
| 185 |
tree array_type = TREE_TYPE (left); |
| 186 |
tree index_type = TYPE_DOMAIN (array_type); |
| 187 |
tree elt_type = TREE_TYPE (array_type); |
| 188 |
tree low_indice = TYPE_MIN_VALUE (index_type); |
| 189 |
low_indice |
| 190 |
= m2convert_BuildConvert (location, index_type, low_indice, false); |
| 191 |
FOR_EACH_CONSTRUCTOR_VALUE (values, i, value) |
| 192 |
{ |
| 193 |
tree idx = m2decl_BuildIntegerConstant (i); |
| 194 |
idx = m2convert_BuildConvert (location, index_type, idx, false); |
| 195 |
tree array_ref = build4_loc (location, ARRAY_REF, elt_type, left, |
| 196 |
idx, low_indice, NULL_TREE); |
| 197 |
m2statement_CopyByField (location, array_ref, value); |
| 198 |
} |
| 199 |
} |
| 200 |
|
| 201 |
/* copy_array cst into left using strncpy. */ |
| 202 |
|
| 203 |
static |
| 204 |
void |
| 205 |
copy_strncpy (location_t location, tree left, tree cst) |
| 206 |
{ |
| 207 |
tree result = m2builtins_BuiltinStrNCopy (location, |
| 208 |
m2expr_BuildAddr (location, left, false), |
| 209 |
m2expr_BuildAddr (location, cst, false), |
| 210 |
m2decl_BuildIntegerConstant (m2expr_StringLength (cst))); |
| 211 |
TREE_SIDE_EFFECTS (result) = true; |
| 212 |
TREE_USED (left) = true; |
| 213 |
TREE_USED (cst) = true; |
| 214 |
add_stmt (location, result); |
| 215 |
} |
| 216 |
|
| 217 |
/* copy_memcpy copy right into left using builtin_memcpy. */ |
| 218 |
|
| 219 |
static |
| 220 |
void |
| 221 |
copy_memcpy (location_t location, tree left, tree right) |
| 222 |
{ |
| 223 |
tree result = m2builtins_BuiltinMemCopy (location, |
| 224 |
m2expr_BuildAddr (location, left, false), |
| 225 |
m2expr_BuildAddr (location, right, false), |
| 226 |
m2expr_GetSizeOf (location, left)); |
| 227 |
TREE_SIDE_EFFECTS (result) = true; |
| 228 |
TREE_USED (left) = true; |
| 229 |
TREE_USED (right) = true; |
| 230 |
add_stmt (location, result); |
| 231 |
} |
| 232 |
|
| 233 |
/* CopyByField_Lower copy right to left using memcpy for unions, |
| 234 |
strncpy for string cst, field assignment for records, |
| 235 |
array element assignment for array constructors. For all |
| 236 |
other types it uses BuildAssignmentStatement. */ |
| 237 |
|
| 238 |
static |
| 239 |
void |
| 240 |
CopyByField_Lower (location_t location, |
| 241 |
tree left, tree right) |
| 242 |
{ |
| 243 |
tree left_type = TREE_TYPE (left); |
| 244 |
enum tree_code right_code = TREE_CODE (right); |
| 245 |
enum tree_code left_code = TREE_CODE (left_type); |
| 246 |
|
| 247 |
if (left_code == RECORD_TYPE && right_code == CONSTRUCTOR) |
| 248 |
copy_record_fields (location, left, right); |
| 249 |
else if (left_code == ARRAY_TYPE && right_code == CONSTRUCTOR) |
| 250 |
copy_array (location, left, right); |
| 251 |
else if (left_code == UNION_TYPE && right_code == CONSTRUCTOR) |
| 252 |
copy_memcpy (location, left, right); |
| 253 |
else if (right_code == STRING_CST) |
| 254 |
copy_strncpy (location, left, right); |
| 255 |
else |
| 256 |
m2statement_BuildAssignmentStatement (location, left, right); |
| 257 |
} |
| 258 |
|
| 259 |
/* CopyByField recursively checks each field to ensure GCC |
| 260 |
type equivalence and if so it uses assignment. |
| 261 |
Otherwise use strncpy or memcpy depending upon type. */ |
| 262 |
|
| 263 |
void |
| 264 |
m2statement_CopyByField (location_t location, tree des, tree expr) |
| 265 |
{ |
| 266 |
if (m2type_IsGccStrictTypeEquivalent (des, expr)) |
| 267 |
m2statement_BuildAssignmentStatement (location, des, expr); |
| 268 |
else |
| 269 |
CopyByField_Lower (location, des, expr); |
| 270 |
} |
| 271 |
|
| 272 |
/* BuildAssignmentTree builds the assignment of, des, and, expr. |
| 273 |
It returns, des. */ |
| 274 |
|
| 275 |
tree |
| 276 |
m2statement_BuildAssignmentTree (location_t location, tree des, tree expr) |
| 277 |
{ |
| 278 |
tree result; |
| 279 |
|
| 280 |
m2assert_AssertLocation (location); |
| 281 |
STRIP_TYPE_NOPS (expr); |
| 282 |
|
| 283 |
if (TREE_CODE (expr) == FUNCTION_DECL) |
| 284 |
result = build2 (MODIFY_EXPR, TREE_TYPE (des), des, |
| 285 |
m2expr_BuildAddr (location, expr, false)); |
| 286 |
else |
| 287 |
{ |
| 288 |
gcc_assert (TREE_CODE (TREE_TYPE (des)) != TYPE_DECL); |
| 289 |
if (TREE_TYPE (expr) == TREE_TYPE (des)) |
| 290 |
result = build2 (MODIFY_EXPR, TREE_TYPE (des), des, expr); |
| 291 |
else |
| 292 |
result = build2 ( |
| 293 |
MODIFY_EXPR, TREE_TYPE (des), des, |
| 294 |
m2convert_BuildConvert (location, TREE_TYPE (des), expr, false)); |
| 295 |
} |
| 296 |
|
| 297 |
TREE_SIDE_EFFECTS (result) = true; |
| 298 |
TREE_USED (des) = true; |
| 299 |
TREE_USED (expr) = true; |
| 300 |
add_stmt (location, result); |
| 301 |
return des; |
| 302 |
} |
| 303 |
|
| 304 |
/* BuildAssignmentStatement builds the assignment of, des, and, expr. */ |
| 305 |
|
| 306 |
void |
| 307 |
m2statement_BuildAssignmentStatement (location_t location, tree des, tree expr) |
| 308 |
{ |
| 309 |
m2statement_BuildAssignmentTree (location, des, expr); |
| 310 |
} |
| 311 |
|
| 312 |
/* BuildGoto builds a goto operation. */ |
| 313 |
|
| 314 |
void |
| 315 |
m2statement_BuildGoto (location_t location, char *name) |
| 316 |
{ |
| 317 |
tree label = m2block_getLabel (location, name); |
| 318 |
|
| 319 |
m2assert_AssertLocation (location); |
| 320 |
TREE_USED (label) = true; |
| 321 |
add_stmt (location, build1 (GOTO_EXPR, void_type_node, label)); |
| 322 |
} |
| 323 |
|
| 324 |
/* DeclareLabel - create a label, name. */ |
| 325 |
|
| 326 |
void |
| 327 |
m2statement_DeclareLabel (location_t location, char *name) |
| 328 |
{ |
| 329 |
tree label = m2block_getLabel (location, name); |
| 330 |
|
| 331 |
m2assert_AssertLocation (location); |
| 332 |
add_stmt (location, build1 (LABEL_EXPR, void_type_node, label)); |
| 333 |
} |
| 334 |
|
| 335 |
/* BuildParam - build a list of parameters, ready for a subsequent |
| 336 |
procedure call. */ |
| 337 |
|
| 338 |
void |
| 339 |
m2statement_BuildParam (location_t location, tree param) |
| 340 |
{ |
| 341 |
m2assert_AssertLocation (location); |
| 342 |
|
| 343 |
TREE_USED (param) = true; |
| 344 |
if (TREE_CODE (param) == FUNCTION_DECL) |
| 345 |
param = m2expr_BuildAddr (location, param, false); |
| 346 |
|
| 347 |
param_list = chainon (build_tree_list (NULL_TREE, param), param_list); |
| 348 |
} |
| 349 |
|
| 350 |
/* nCount - return the number of chained tree nodes in list, t. */ |
| 351 |
|
| 352 |
static int |
| 353 |
nCount (tree t) |
| 354 |
{ |
| 355 |
int i = 0; |
| 356 |
|
| 357 |
while (t != NULL) |
| 358 |
{ |
| 359 |
i++; |
| 360 |
t = TREE_CHAIN (t); |
| 361 |
} |
| 362 |
return i; |
| 363 |
} |
| 364 |
|
| 365 |
/* BuildProcedureCallTree - creates a procedure call from a procedure |
| 366 |
and parameter list and the return type, rettype. */ |
| 367 |
|
| 368 |
tree |
| 369 |
m2statement_BuildProcedureCallTree (location_t location, tree procedure, |
| 370 |
tree rettype) |
| 371 |
{ |
| 372 |
tree functype = TREE_TYPE (procedure); |
| 373 |
tree funcptr = build1 (ADDR_EXPR, build_pointer_type (functype), procedure); |
| 374 |
tree call; |
| 375 |
int n = nCount (param_list); |
| 376 |
tree *argarray = XALLOCAVEC (tree, n); |
| 377 |
tree t = param_list; |
| 378 |
int i; |
| 379 |
|
| 380 |
m2assert_AssertLocation (location); |
| 381 |
ASSERT_CONDITION ( |
| 382 |
last_function |
| 383 |
== NULL_TREE); /* Previous function value has not been collected. */ |
| 384 |
TREE_USED (procedure) = true; |
| 385 |
|
| 386 |
for (i = 0; i < n; i++) |
| 387 |
{ |
| 388 |
argarray[i] = TREE_VALUE (t); |
| 389 |
t = TREE_CHAIN (t); |
| 390 |
} |
| 391 |
|
| 392 |
if (rettype == NULL_TREE) |
| 393 |
{ |
| 394 |
rettype = void_type_node; |
| 395 |
call = build_call_array_loc (location, rettype, funcptr, n, argarray); |
| 396 |
TREE_USED (call) = true; |
| 397 |
TREE_SIDE_EFFECTS (call) = true; |
| 398 |
|
| 399 |
#if defined(DEBUG_PROCEDURE_CALLS) |
| 400 |
fprintf (stderr, "built the modula-2 call, here is the tree\n"); |
| 401 |
fflush (stderr); |
| 402 |
debug_tree (call); |
| 403 |
#endif |
| 404 |
|
| 405 |
param_list |
| 406 |
= NULL_TREE; /* Ready for the next time we call a procedure. */ |
| 407 |
last_function = NULL_TREE; |
| 408 |
return call; |
| 409 |
} |
| 410 |
else |
| 411 |
{ |
| 412 |
last_function = build_call_array_loc ( |
| 413 |
location, m2tree_skip_type_decl (rettype), funcptr, n, argarray); |
| 414 |
TREE_USED (last_function) = true; |
| 415 |
TREE_SIDE_EFFECTS (last_function) = true; |
| 416 |
param_list |
| 417 |
= NULL_TREE; /* Ready for the next time we call a procedure. */ |
| 418 |
return last_function; |
| 419 |
} |
| 420 |
} |
| 421 |
|
| 422 |
/* BuildIndirectProcedureCallTree - creates a procedure call from a |
| 423 |
procedure and parameter list and the return type, rettype. */ |
| 424 |
|
| 425 |
tree |
| 426 |
m2statement_BuildIndirectProcedureCallTree (location_t location, |
| 427 |
tree procedure, tree rettype) |
| 428 |
{ |
| 429 |
tree call; |
| 430 |
int n = nCount (param_list); |
| 431 |
tree *argarray = XALLOCAVEC (tree, n); |
| 432 |
tree t = param_list; |
| 433 |
int i; |
| 434 |
|
| 435 |
m2assert_AssertLocation (location); |
| 436 |
TREE_USED (procedure) = true; |
| 437 |
TREE_SIDE_EFFECTS (procedure) = true; |
| 438 |
|
| 439 |
for (i = 0; i < n; i++) |
| 440 |
{ |
| 441 |
argarray[i] = TREE_VALUE (t); |
| 442 |
t = TREE_CHAIN (t); |
| 443 |
} |
| 444 |
|
| 445 |
if (rettype == NULL_TREE) |
| 446 |
{ |
| 447 |
rettype = void_type_node; |
| 448 |
call = build_call_array_loc (location, rettype, procedure, n, argarray); |
| 449 |
TREE_USED (call) = true; |
| 450 |
TREE_SIDE_EFFECTS (call) = true; |
| 451 |
|
| 452 |
#if defined(DEBUG_PROCEDURE_CALLS) |
| 453 |
fprintf (stderr, "built the modula-2 call, here is the tree\n"); |
| 454 |
fflush (stderr); |
| 455 |
debug_tree (call); |
| 456 |
#endif |
| 457 |
|
| 458 |
last_function = NULL_TREE; |
| 459 |
param_list |
| 460 |
= NULL_TREE; /* Ready for the next time we call a procedure. */ |
| 461 |
return call; |
| 462 |
} |
| 463 |
else |
| 464 |
{ |
| 465 |
last_function = build_call_array_loc ( |
| 466 |
location, m2tree_skip_type_decl (rettype), procedure, n, argarray); |
| 467 |
TREE_USED (last_function) = true; |
| 468 |
TREE_SIDE_EFFECTS (last_function) = true; |
| 469 |
param_list |
| 470 |
= NULL_TREE; /* Ready for the next time we call a procedure. */ |
| 471 |
return last_function; |
| 472 |
} |
| 473 |
} |
| 474 |
|
| 475 |
|
| 476 |
/* BuildBuiltinCallTree calls the builtin procedure. */ |
| 477 |
|
| 478 |
tree |
| 479 |
m2statement_BuildBuiltinCallTree (tree func) |
| 480 |
{ |
| 481 |
TREE_USED (func) = true; |
| 482 |
TREE_SIDE_EFFECTS (func) = true; |
| 483 |
param_list |
| 484 |
= NULL_TREE; /* Ready for the next time we call a procedure. */ |
| 485 |
return func; |
| 486 |
} |
| 487 |
|
| 488 |
|
| 489 |
/* BuildFunctValue - generates code for value := |
| 490 |
last_function(foobar); */ |
| 491 |
|
| 492 |
tree |
| 493 |
m2statement_BuildFunctValue (location_t location, tree value) |
| 494 |
{ |
| 495 |
tree assign |
| 496 |
= m2treelib_build_modify_expr (location, value, NOP_EXPR, last_function); |
| 497 |
|
| 498 |
m2assert_AssertLocation (location); |
| 499 |
ASSERT_CONDITION ( |
| 500 |
last_function |
| 501 |
!= NULL_TREE); /* No value available, possible used before. */ |
| 502 |
|
| 503 |
TREE_SIDE_EFFECTS (assign) = true; |
| 504 |
TREE_USED (assign) = true; |
| 505 |
TREE_USED (value) = true; |
| 506 |
last_function = NULL_TREE; |
| 507 |
return assign; |
| 508 |
// return m2statement_BuildAssignmentTree (location, value, assign); |
| 509 |
} |
| 510 |
|
| 511 |
/* BuildCall2 - builds a tree representing: function (arg1, arg2). */ |
| 512 |
|
| 513 |
tree |
| 514 |
m2statement_BuildCall2 (location_t location, tree function, tree rettype, |
| 515 |
tree arg1, tree arg2) |
| 516 |
{ |
| 517 |
m2assert_AssertLocation (location); |
| 518 |
ASSERT_CONDITION (param_list == NULL_TREE); |
| 519 |
|
| 520 |
param_list = chainon (build_tree_list (NULL_TREE, arg2), param_list); |
| 521 |
param_list = chainon (build_tree_list (NULL_TREE, arg1), param_list); |
| 522 |
return m2statement_BuildProcedureCallTree (location, function, rettype); |
| 523 |
} |
| 524 |
|
| 525 |
/* BuildCall3 - builds a tree representing: function (arg1, arg2, |
| 526 |
arg3). */ |
| 527 |
|
| 528 |
tree |
| 529 |
m2statement_BuildCall3 (location_t location, tree function, tree rettype, |
| 530 |
tree arg1, tree arg2, tree arg3) |
| 531 |
{ |
| 532 |
m2assert_AssertLocation (location); |
| 533 |
ASSERT_CONDITION (param_list == NULL_TREE); |
| 534 |
|
| 535 |
param_list = chainon (build_tree_list (NULL_TREE, arg3), param_list); |
| 536 |
param_list = chainon (build_tree_list (NULL_TREE, arg2), param_list); |
| 537 |
param_list = chainon (build_tree_list (NULL_TREE, arg1), param_list); |
| 538 |
return m2statement_BuildProcedureCallTree (location, function, rettype); |
| 539 |
} |
| 540 |
|
| 541 |
/* BuildFunctionCallTree - creates a procedure function call from |
| 542 |
a procedure and parameter list and the return type, rettype. |
| 543 |
No tree is returned as the tree is held in the last_function global |
| 544 |
variable. It is expected the BuildFunctValue is to be called after |
| 545 |
a call to BuildFunctionCallTree. */ |
| 546 |
|
| 547 |
void |
| 548 |
m2statement_BuildFunctionCallTree (location_t location, tree procedure, |
| 549 |
tree rettype) |
| 550 |
{ |
| 551 |
m2statement_BuildProcedureCallTree (location, procedure, rettype); |
| 552 |
} |
| 553 |
|
| 554 |
/* SetLastFunction - assigns last_function to, t. */ |
| 555 |
|
| 556 |
void |
| 557 |
m2statement_SetLastFunction (tree t) |
| 558 |
{ |
| 559 |
last_function = t; |
| 560 |
} |
| 561 |
|
| 562 |
/* SetParamList - assigns param_list to, t. */ |
| 563 |
|
| 564 |
void |
| 565 |
m2statement_SetParamList (tree t) |
| 566 |
{ |
| 567 |
param_list = t; |
| 568 |
} |
| 569 |
|
| 570 |
/* GetLastFunction - returns, last_function. */ |
| 571 |
|
| 572 |
tree |
| 573 |
m2statement_GetLastFunction (void) |
| 574 |
{ |
| 575 |
return last_function; |
| 576 |
} |
| 577 |
|
| 578 |
/* GetParamList - returns, param_list. */ |
| 579 |
|
| 580 |
tree |
| 581 |
m2statement_GetParamList (void) |
| 582 |
{ |
| 583 |
return param_list; |
| 584 |
} |
| 585 |
|
| 586 |
/* GetCurrentFunction - returns the current_function. */ |
| 587 |
|
| 588 |
tree |
| 589 |
m2statement_GetCurrentFunction (void) |
| 590 |
{ |
| 591 |
return current_function_decl; |
| 592 |
} |
| 593 |
|
| 594 |
/* GetParamTree - return parameter, i. */ |
| 595 |
|
| 596 |
tree |
| 597 |
m2statement_GetParamTree (tree call, unsigned int i) |
| 598 |
{ |
| 599 |
return CALL_EXPR_ARG (call, i); |
| 600 |
} |
| 601 |
|
| 602 |
/* BuildTryFinally - returns a TRY_FINALL_EXPR with the call and |
| 603 |
cleanups attached. */ |
| 604 |
|
| 605 |
tree |
| 606 |
m2statement_BuildTryFinally (location_t location, tree call, tree cleanups) |
| 607 |
{ |
| 608 |
return build_stmt (location, TRY_FINALLY_EXPR, call, cleanups); |
| 609 |
} |
| 610 |
|
| 611 |
/* BuildCleanUp - return a CLEANUP_POINT_EXPR which will clobber, |
| 612 |
param. */ |
| 613 |
|
| 614 |
tree |
| 615 |
m2statement_BuildCleanUp (tree param) |
| 616 |
{ |
| 617 |
tree clobber = build_constructor (TREE_TYPE (param), NULL); |
| 618 |
TREE_THIS_VOLATILE (clobber) = 1; |
| 619 |
return build2 (MODIFY_EXPR, TREE_TYPE (param), param, clobber); |
| 620 |
} |
| 621 |
|
| 622 |
/* BuildAsm - generates an inline assembler instruction. */ |
| 623 |
|
| 624 |
void |
| 625 |
m2statement_BuildAsm (location_t location, tree instr, bool isVolatile, |
| 626 |
bool isSimple, tree inputs, tree outputs, tree trash, |
| 627 |
tree labels) |
| 628 |
{ |
| 629 |
tree string = resolve_asm_operand_names (instr, outputs, inputs, labels); |
| 630 |
tree args = build_stmt (location, ASM_EXPR, string, outputs, inputs, trash, |
| 631 |
labels); |
| 632 |
|
| 633 |
m2assert_AssertLocation (location); |
| 634 |
|
| 635 |
/* ASM statements without outputs, including simple ones, are treated |
| 636 |
as volatile. */ |
| 637 |
ASM_BASIC_P (args) = isSimple; |
| 638 |
ASM_VOLATILE_P (args) = isVolatile; |
| 639 |
|
| 640 |
add_stmt (location, args); |
| 641 |
} |
| 642 |
|
| 643 |
/* BuildUnaryForeachWordDo - provides the large set operators. Each |
| 644 |
word (or less) of the set can be calculated by unop. This |
| 645 |
procedure runs along each word of the large set invoking the unop. */ |
| 646 |
|
| 647 |
void |
| 648 |
m2statement_BuildUnaryForeachWordDo (location_t location, tree type, tree op1, |
| 649 |
tree op2, |
| 650 |
tree (*unop) (location_t, tree, bool), |
| 651 |
bool is_op1lvalue, bool is_op2lvalue, |
| 652 |
bool is_op1const, bool is_op2const) |
| 653 |
{ |
| 654 |
tree size = m2expr_GetSizeOf (location, type); |
| 655 |
|
| 656 |
m2assert_AssertLocation (location); |
| 657 |
ASSERT_BOOL (is_op1lvalue); |
| 658 |
ASSERT_BOOL (is_op2lvalue); |
| 659 |
ASSERT_BOOL (is_op1const); |
| 660 |
ASSERT_BOOL (is_op2const); |
| 661 |
if (m2expr_CompareTrees ( |
| 662 |
size, m2decl_BuildIntegerConstant (SET_WORD_SIZE / BITS_PER_UNIT)) |
| 663 |
<= 0) |
| 664 |
/* Small set size <= TSIZE(WORD). */ |
| 665 |
m2statement_BuildAssignmentTree ( |
| 666 |
location, m2treelib_get_rvalue (location, op1, type, is_op1lvalue), |
| 667 |
(*unop) (location, |
| 668 |
m2treelib_get_rvalue (location, op2, type, is_op2lvalue), |
| 669 |
false)); |
| 670 |
else |
| 671 |
{ |
| 672 |
/* Large set size > TSIZE(WORD). */ |
| 673 |
unsigned int fieldNo = 0; |
| 674 |
tree field1 = m2treelib_get_field_no (type, op1, is_op1const, fieldNo); |
| 675 |
tree field2 = m2treelib_get_field_no (type, op2, is_op2const, fieldNo); |
| 676 |
|
| 677 |
if (is_op1const) |
| 678 |
error ("internal error: not expecting operand1 to be a constant set"); |
| 679 |
|
| 680 |
while (field1 != NULL && field2 != NULL) |
| 681 |
{ |
| 682 |
m2statement_BuildAssignmentTree ( |
| 683 |
location, m2treelib_get_set_field_des (location, op1, field1), |
| 684 |
(*unop) (location, |
| 685 |
m2treelib_get_set_field_rhs (location, op2, field2), |
| 686 |
false)); |
| 687 |
fieldNo++; |
| 688 |
field1 = m2treelib_get_field_no (type, op1, is_op1const, fieldNo); |
| 689 |
field2 = m2treelib_get_field_no (type, op2, is_op2const, fieldNo); |
| 690 |
} |
| 691 |
} |
| 692 |
} |
| 693 |
|
| 694 |
/* BuildExcludeVarConst - builds the EXCL(op1, 1<<op2) operation for |
| 695 |
a small sets. Large sets call this routine to exclude the bit in |
| 696 |
the particular word. op2 is a constant. */ |
| 697 |
|
| 698 |
void |
| 699 |
m2statement_BuildExcludeVarConst (location_t location, tree type, tree op1, |
| 700 |
tree op2, bool is_lvalue, int fieldno) |
| 701 |
{ |
| 702 |
tree size = m2expr_GetSizeOf (location, type); |
| 703 |
|
| 704 |
m2assert_AssertLocation (location); |
| 705 |
ASSERT_BOOL (is_lvalue); |
| 706 |
if (m2expr_CompareTrees ( |
| 707 |
size, m2decl_BuildIntegerConstant (SET_WORD_SIZE / BITS_PER_UNIT)) |
| 708 |
<= 0) |
| 709 |
{ |
| 710 |
/* Small set size <= TSIZE(WORD). */ |
| 711 |
m2statement_BuildAssignmentTree ( |
| 712 |
location, m2treelib_get_rvalue (location, op1, type, is_lvalue), |
| 713 |
m2expr_BuildLogicalAnd ( |
| 714 |
location, m2treelib_get_rvalue (location, op1, type, is_lvalue), |
| 715 |
m2expr_BuildSetNegate ( |
| 716 |
location, |
| 717 |
m2expr_BuildLSL (location, m2expr_GetWordOne (location), op2, |
| 718 |
false), |
| 719 |
false), |
| 720 |
false)); |
| 721 |
} |
| 722 |
else |
| 723 |
{ |
| 724 |
tree fieldlist = TYPE_FIELDS (type); |
| 725 |
tree field; |
| 726 |
|
| 727 |
for (field = fieldlist; (field != NULL) && (fieldno > 0); |
| 728 |
field = TREE_CHAIN (field)) |
| 729 |
fieldno--; |
| 730 |
|
| 731 |
m2statement_BuildAssignmentTree ( |
| 732 |
location, m2treelib_get_set_field_des (location, op1, field), |
| 733 |
m2expr_BuildLogicalAnd ( |
| 734 |
location, m2treelib_get_set_field_rhs (location, op1, field), |
| 735 |
m2expr_BuildSetNegate ( |
| 736 |
location, |
| 737 |
m2expr_BuildLSL (location, m2expr_GetWordOne (location), op2, |
| 738 |
false), |
| 739 |
false), |
| 740 |
false)); |
| 741 |
} |
| 742 |
} |
| 743 |
|
| 744 |
/* BuildExcludeVarVar - builds the EXCL(varset, 1<<varel) operation |
| 745 |
for a small and large sets. varel is a variable. */ |
| 746 |
|
| 747 |
void |
| 748 |
m2statement_BuildExcludeVarVar (location_t location, tree type, tree varset, |
| 749 |
tree varel, bool is_lvalue, tree low) |
| 750 |
{ |
| 751 |
tree size = m2expr_GetSizeOf (location, type); |
| 752 |
|
| 753 |
m2assert_AssertLocation (location); |
| 754 |
ASSERT_BOOL (is_lvalue); |
| 755 |
/* Calculate the index from the first bit, ie bit 0 represents low value. */ |
| 756 |
tree index |
| 757 |
= m2expr_BuildSub (location, m2convert_ToInteger (location, varel), |
| 758 |
m2convert_ToInteger (location, low), false); |
| 759 |
|
| 760 |
if (m2expr_CompareTrees ( |
| 761 |
size, m2decl_BuildIntegerConstant (SET_WORD_SIZE / BITS_PER_UNIT)) |
| 762 |
<= 0) |
| 763 |
/* Small set size <= TSIZE(WORD). */ |
| 764 |
m2statement_BuildAssignmentTree ( |
| 765 |
location, m2treelib_get_rvalue (location, varset, type, is_lvalue), |
| 766 |
m2expr_BuildLogicalAnd ( |
| 767 |
location, m2treelib_get_rvalue (location, varset, type, is_lvalue), |
| 768 |
m2expr_BuildSetNegate ( |
| 769 |
location, |
| 770 |
m2expr_BuildLSL (location, m2expr_GetWordOne (location), |
| 771 |
m2convert_ToWord (location, index), false), |
| 772 |
false), |
| 773 |
false)); |
| 774 |
else |
| 775 |
{ |
| 776 |
tree p1 = m2treelib_get_set_address (location, varset, is_lvalue); |
| 777 |
/* Calculate the index from the first bit. */ |
| 778 |
|
| 779 |
/* Which word do we need to fetch? */ |
| 780 |
tree word_index = m2expr_BuildDivTrunc ( |
| 781 |
location, index, m2decl_BuildIntegerConstant (SET_WORD_SIZE), false); |
| 782 |
/* Calculate the bit in this word. */ |
| 783 |
tree offset_into_word = m2expr_BuildModTrunc ( |
| 784 |
location, index, m2decl_BuildIntegerConstant (SET_WORD_SIZE), false); |
| 785 |
|
| 786 |
tree v1; |
| 787 |
|
| 788 |
/* Calculate the address of the word we are interested in. */ |
| 789 |
p1 = m2expr_BuildAddAddress ( |
| 790 |
location, m2convert_convertToPtr (location, p1), |
| 791 |
m2expr_BuildMult ( |
| 792 |
location, word_index, |
| 793 |
m2decl_BuildIntegerConstant (SET_WORD_SIZE / BITS_PER_UNIT), |
| 794 |
false)); |
| 795 |
|
| 796 |
v1 = m2expr_BuildLogicalAnd ( |
| 797 |
location, |
| 798 |
m2expr_BuildIndirect (location, p1, m2type_GetBitsetType ()), |
| 799 |
m2expr_BuildSetNegate ( |
| 800 |
location, |
| 801 |
m2expr_BuildLSL (location, m2expr_GetWordOne (location), |
| 802 |
m2convert_ToWord (location, offset_into_word), |
| 803 |
false), |
| 804 |
false), |
| 805 |
false); |
| 806 |
|
| 807 |
/* Set bit offset_into_word within the word pointer at by p1. */ |
| 808 |
m2statement_BuildAssignmentTree ( |
| 809 |
location, |
| 810 |
m2expr_BuildIndirect (location, p1, m2type_GetBitsetType ()), |
| 811 |
m2convert_ToBitset (location, v1)); |
| 812 |
} |
| 813 |
} |
| 814 |
|
| 815 |
/* BuildIncludeVarConst - builds the INCL(op1, 1<<op2) operation for |
| 816 |
a small sets. Large sets call this routine to include the bit in |
| 817 |
the particular word. op2 is a constant. */ |
| 818 |
|
| 819 |
void |
| 820 |
m2statement_BuildIncludeVarConst (location_t location, tree type, tree op1, |
| 821 |
tree op2, bool is_lvalue, int fieldno) |
| 822 |
{ |
| 823 |
tree size = m2expr_GetSizeOf (location, type); |
| 824 |
|
| 825 |
m2assert_AssertLocation (location); |
| 826 |
ASSERT_BOOL (is_lvalue); |
| 827 |
if (m2expr_CompareTrees ( |
| 828 |
size, m2decl_BuildIntegerConstant (SET_WORD_SIZE / BITS_PER_UNIT)) |
| 829 |
<= 0) |
| 830 |
{ |
| 831 |
/* Small set size <= TSIZE(WORD). */ |
| 832 |
m2statement_BuildAssignmentTree ( |
| 833 |
location, m2treelib_get_rvalue (location, op1, type, is_lvalue), |
| 834 |
m2expr_BuildLogicalOr ( |
| 835 |
location, m2treelib_get_rvalue (location, op1, type, is_lvalue), |
| 836 |
m2expr_BuildLSL (location, m2expr_GetWordOne (location), |
| 837 |
m2convert_ToWord (location, op2), false), |
| 838 |
false)); |
| 839 |
} |
| 840 |
else |
| 841 |
{ |
| 842 |
tree fieldlist = TYPE_FIELDS (type); |
| 843 |
tree field; |
| 844 |
|
| 845 |
for (field = fieldlist; (field != NULL) && (fieldno > 0); |
| 846 |
field = TREE_CHAIN (field)) |
| 847 |
fieldno--; |
| 848 |
|
| 849 |
m2statement_BuildAssignmentTree ( |
| 850 |
location, |
| 851 |
/* Would like to use: m2expr_BuildComponentRef (location, p, field) |
| 852 |
but strangely we have to take the address of the field and |
| 853 |
dereference it to satify the gimplifier. See |
| 854 |
testsuite/gm2/pim/pass/timeio?.mod for testcases. */ |
| 855 |
m2treelib_get_set_field_des (location, op1, field), |
| 856 |
m2expr_BuildLogicalOr ( |
| 857 |
location, m2treelib_get_set_field_rhs (location, op1, field), |
| 858 |
m2expr_BuildLSL (location, m2expr_GetWordOne (location), |
| 859 |
m2convert_ToWord (location, op2), false), |
| 860 |
false)); |
| 861 |
} |
| 862 |
} |
| 863 |
|
| 864 |
/* BuildIncludeVarVar - builds the INCL(varset, 1<<varel) operation |
| 865 |
for a small and large sets. op2 is a variable. */ |
| 866 |
|
| 867 |
void |
| 868 |
m2statement_BuildIncludeVarVar (location_t location, tree type, tree varset, |
| 869 |
tree varel, bool is_lvalue, tree low) |
| 870 |
{ |
| 871 |
tree size = m2expr_GetSizeOf (location, type); |
| 872 |
|
| 873 |
m2assert_AssertLocation (location); |
| 874 |
ASSERT_BOOL (is_lvalue); |
| 875 |
/* Calculate the index from the first bit, ie bit 0 represents low value. */ |
| 876 |
tree index |
| 877 |
= m2expr_BuildSub (location, m2convert_ToInteger (location, varel), |
| 878 |
m2convert_ToInteger (location, low), false); |
| 879 |
tree indexw = m2convert_ToWord (location, index); |
| 880 |
|
| 881 |
if (m2expr_CompareTrees ( |
| 882 |
size, m2decl_BuildIntegerConstant (SET_WORD_SIZE / BITS_PER_UNIT)) |
| 883 |
<= 0) |
| 884 |
/* Small set size <= TSIZE(WORD). */ |
| 885 |
m2statement_BuildAssignmentTree ( |
| 886 |
location, m2treelib_get_rvalue (location, varset, type, is_lvalue), |
| 887 |
m2convert_ToBitset ( |
| 888 |
location, |
| 889 |
m2expr_BuildLogicalOr ( |
| 890 |
location, |
| 891 |
m2treelib_get_rvalue (location, varset, type, is_lvalue), |
| 892 |
m2expr_BuildLSL (location, m2expr_GetWordOne (location), |
| 893 |
indexw, false), |
| 894 |
false))); |
| 895 |
else |
| 896 |
{ |
| 897 |
tree p1 = m2treelib_get_set_address (location, varset, is_lvalue); |
| 898 |
/* Which word do we need to fetch? */ |
| 899 |
tree word_index = m2expr_BuildDivTrunc ( |
| 900 |
location, index, m2decl_BuildIntegerConstant (SET_WORD_SIZE), false); |
| 901 |
/* Calculate the bit in this word. */ |
| 902 |
tree offset_into_word = m2convert_BuildConvert ( |
| 903 |
location, m2type_GetWordType (), |
| 904 |
m2expr_BuildModTrunc (location, index, |
| 905 |
m2decl_BuildIntegerConstant (SET_WORD_SIZE), |
| 906 |
false), |
| 907 |
false); |
| 908 |
tree v1; |
| 909 |
|
| 910 |
/* Calculate the address of the word we are interested in. */ |
| 911 |
p1 = m2expr_BuildAddAddress ( |
| 912 |
location, m2convert_convertToPtr (location, p1), |
| 913 |
m2expr_BuildMult ( |
| 914 |
location, word_index, |
| 915 |
m2decl_BuildIntegerConstant (SET_WORD_SIZE / BITS_PER_UNIT), |
| 916 |
false)); |
| 917 |
v1 = m2expr_BuildLogicalOr ( |
| 918 |
location, |
| 919 |
m2expr_BuildIndirect (location, p1, m2type_GetBitsetType ()), |
| 920 |
m2convert_ToBitset (location, |
| 921 |
m2expr_BuildLSL (location, |
| 922 |
m2expr_GetWordOne (location), |
| 923 |
offset_into_word, false)), |
| 924 |
false); |
| 925 |
|
| 926 |
/* Set bit offset_into_word within the word pointer at by p1. */ |
| 927 |
m2statement_BuildAssignmentTree ( |
| 928 |
location, |
| 929 |
m2expr_BuildIndirect (location, p1, m2type_GetBitsetType ()), |
| 930 |
m2convert_ToBitset (location, v1)); |
| 931 |
} |
| 932 |
} |
| 933 |
|
| 934 |
/* BuildStart - creates a module initialization function. We make |
| 935 |
this function public if it is not an inner module. The linker |
| 936 |
will create a call list for all linked modules which determines |
| 937 |
the initialization sequence for all modules. */ |
| 938 |
|
| 939 |
tree |
| 940 |
m2statement_BuildStart (location_t location, char *name, bool inner_module) |
| 941 |
{ |
| 942 |
tree fntype; |
| 943 |
tree fndecl; |
| 944 |
|
| 945 |
m2assert_AssertLocation (location); |
| 946 |
/* The function type depends on the return type and type of args. */ |
| 947 |
fntype = build_function_type (integer_type_node, NULL_TREE); |
| 948 |
fndecl = build_decl (location, FUNCTION_DECL, get_identifier (name), fntype); |
| 949 |
|
| 950 |
DECL_EXTERNAL (fndecl) = 0; |
| 951 |
if (inner_module) |
| 952 |
TREE_PUBLIC (fndecl) = 0; |
| 953 |
else |
| 954 |
TREE_PUBLIC (fndecl) = 1; |
| 955 |
|
| 956 |
TREE_STATIC (fndecl) = 1; |
| 957 |
DECL_RESULT (fndecl) |
| 958 |
= build_decl (location, RESULT_DECL, NULL_TREE, integer_type_node); |
| 959 |
DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl; |
| 960 |
|
| 961 |
/* Prevent the optimizer from removing it if it is public. */ |
| 962 |
if (TREE_PUBLIC (fndecl)) |
| 963 |
gm2_mark_addressable (fndecl); |
| 964 |
|
| 965 |
m2statement_BuildStartFunctionCode (location, fndecl, !inner_module, |
| 966 |
inner_module); |
| 967 |
return fndecl; |
| 968 |
} |
| 969 |
|
| 970 |
/* BuildEnd - complete the initialization function for this module. */ |
| 971 |
|
| 972 |
void |
| 973 |
m2statement_BuildEnd (location_t location, tree fndecl, bool nested) |
| 974 |
{ |
| 975 |
m2statement_BuildEndFunctionCode (location, fndecl, nested); |
| 976 |
current_function_decl = NULL; |
| 977 |
set_cfun (NULL); |
| 978 |
} |
| 979 |
|
| 980 |
/* BuildCallInner - call the inner module function. It has no |
| 981 |
parameters and no return value. */ |
| 982 |
|
| 983 |
void |
| 984 |
m2statement_BuildCallInner (location_t location, tree fndecl) |
| 985 |
{ |
| 986 |
m2assert_AssertLocation (location); |
| 987 |
param_list = NULL_TREE; |
| 988 |
add_stmt (location, |
| 989 |
m2statement_BuildProcedureCallTree (location, fndecl, NULL_TREE)); |
| 990 |
} |
| 991 |
|
| 992 |
|
| 993 |
/* BuildIfThenDoEnd - returns a tree which will only execute |
| 994 |
statement, s, if, condition, is true. */ |
| 995 |
|
| 996 |
tree |
| 997 |
m2statement_BuildIfThenDoEnd (tree condition, tree then_block) |
| 998 |
{ |
| 999 |
if (then_block == NULL_TREE) |
| 1000 |
return NULL_TREE; |
| 1001 |
else |
| 1002 |
return fold_build3 (COND_EXPR, void_type_node, condition, then_block, |
| 1003 |
alloc_stmt_list ()); |
| 1004 |
} |
| 1005 |
|
| 1006 |
/* BuildIfThenElseEnd - returns a tree which will execute then_block |
| 1007 |
or else_block depending upon, condition. */ |
| 1008 |
|
| 1009 |
tree |
| 1010 |
m2statement_BuildIfThenElseEnd (tree condition, tree then_block, |
| 1011 |
tree else_block) |
| 1012 |
{ |
| 1013 |
if (then_block == NULL_TREE) |
| 1014 |
return NULL_TREE; |
| 1015 |
else |
| 1016 |
return fold_build3 (COND_EXPR, void_type_node, condition, then_block, |
| 1017 |
else_block); |
| 1018 |
} |
| 1019 |
|
| 1020 |
/* BuildReturnValueCode - generates the code associated with: RETURN( |
| 1021 |
value ) */ |
| 1022 |
|
| 1023 |
void |
| 1024 |
m2statement_BuildReturnValueCode (location_t location, tree fndecl, tree value) |
| 1025 |
{ |
| 1026 |
tree ret_stmt; |
| 1027 |
tree t; |
| 1028 |
|
| 1029 |
m2assert_AssertLocation (location); |
| 1030 |
t = build2 ( |
| 1031 |
MODIFY_EXPR, TREE_TYPE (DECL_RESULT (fndecl)), DECL_RESULT (fndecl), |
| 1032 |
m2convert_BuildConvert ( |
| 1033 |
location, m2tree_skip_type_decl (TREE_TYPE (DECL_RESULT (fndecl))), |
| 1034 |
value, false)); |
| 1035 |
|
| 1036 |
ret_stmt = build_stmt (location, RETURN_EXPR, t); |
| 1037 |
add_stmt (location, ret_stmt); |
| 1038 |
} |
| 1039 |
|
| 1040 |
/* DoJump - jump to the appropriate label depending whether result of |
| 1041 |
the expression is true or false. */ |
| 1042 |
|
| 1043 |
void |
| 1044 |
m2statement_DoJump (location_t location, tree exp, char *falselabel, |
| 1045 |
char *truelabel) |
| 1046 |
{ |
| 1047 |
tree c = NULL_TREE; |
| 1048 |
|
| 1049 |
m2assert_AssertLocation (location); |
| 1050 |
if (TREE_CODE (TREE_TYPE (exp)) != BOOLEAN_TYPE) |
| 1051 |
exp = convert_loc (location, m2type_GetBooleanType (), exp); |
| 1052 |
|
| 1053 |
if ((falselabel != NULL) && (truelabel == NULL)) |
| 1054 |
{ |
| 1055 |
m2block_push_statement_list (m2block_begin_statement_list ()); |
| 1056 |
|
| 1057 |
m2statement_BuildGoto (location, falselabel); |
| 1058 |
c = build3 (COND_EXPR, void_type_node, exp, |
| 1059 |
m2block_pop_statement_list (), |
| 1060 |
alloc_stmt_list ()); |
| 1061 |
} |
| 1062 |
else if ((falselabel == NULL) && (truelabel != NULL)) |
| 1063 |
{ |
| 1064 |
m2block_push_statement_list (m2block_begin_statement_list ()); |
| 1065 |
|
| 1066 |
m2statement_BuildGoto (location, truelabel); |
| 1067 |
c = build3 (COND_EXPR, void_type_node, exp, |
| 1068 |
m2block_pop_statement_list (), |
| 1069 |
alloc_stmt_list ()); |
| 1070 |
} |
| 1071 |
else |
| 1072 |
error_at (location, "expecting one and only one label to be declared"); |
| 1073 |
if (c != NULL_TREE) |
| 1074 |
add_stmt (location, c); |
| 1075 |
} |
| 1076 |
|
| 1077 |
#include "gt-m2-m2statement.h" |