PIPS
|
#include <stdio.h>
#include "genC.h"
#include "parser_private.h"
#include "linear.h"
#include "ri.h"
#include "ri-util.h"
#include "misc.h"
#include "properties.h"
#include "syntax.h"
Go to the source code of this file.
Macros | |
#define | GET_RC_PREFIX "GET_" |
#define | SET_RC_PREFIX "SET_" |
Variables | |
static bool | substitute_rc_p = false |
Handling of RETURN statements and substitution of alternate returns. More... | |
static bool | substitute_stop_p = false |
static bool | hide_rc_p = false |
static entity | return_code_variable = entity_undefined |
Variable used to carry return code replacing the alternate returns. More... | |
static bool | current_module_uses_alternate_returns = false |
Remember if the current module uses alternate returns. More... | |
static int | current_number_of_alternate_returns = -1 |
The current number of alternate returns is used to process a module declaration. More... | |
static list | alternate_returns = list_undefined |
Keep track of the labels used as actual arguments for alternate returns and generate the tests to check the return code. More... | |
LOCAL entity | end_label = entity_undefined |
This function creates a goto instruction to label end_label. More... | |
LOCAL char * | end_label_local_name = RETURN_LABEL_NAME |
apl | pl |
Definition at line 222 of file return.c.
References CONS, ENDP, entity_to_expression(), EXPRESSION, gen_nconc(), get_alternate_returns(), GetFullyDefinedReturnCodeVariable(), hide_rc_p, NIL, and substitute_rc_p.
Referenced by MakeCallInst().
void add_alternate_return | ( | string | label_name | ) |
label_name | abel_name |
Definition at line 242 of file return.c.
References alternate_returns, arguments_add_entity(), entity_undefined, line_b_I, line_e_I, MakeLabel(), pips_user_warning, and substitute_rc_p.
Update the formal and actual parameter lists by adding the return code variable as last argument.
To avoid an explicit check in gram.y which is large enough, the additions are conditional to the alternate return substitution.
Type, storage and initial value are set up later in MakeFormalParameter()
fpl | pl |
Definition at line 209 of file return.c.
References CONS, ENTITY, gen_nconc(), GetReturnCodeVariable(), hide_rc_p, NIL, substitute_rc_p, and uses_alternate_return_p().
Referenced by MakeCurrentFunction().
instruction generate_return_code_checks | ( | list | labels | ) |
The reset is controlled from gram.y, as is the set
pips_debug(2, "Additional statement generated for hide_rc_p:\n");
print_statement(s_init_rcv);
}
labels | abels |
Definition at line 337 of file return.c.
References CONS, ENDP, ENTITY, entity_to_expression(), expression_undefined, FOREACH, gen_free_list(), GetFullyDefinedReturnCodeVariable(), hide_rc_p, instruction_block, instruction_block_p, instruction_consistent_p(), instruction_undefined, label_local_name(), make_get_rc_statement(), MakeComputedGotoInst(), NIL, pips_assert, STATEMENT, and STRING.
Referenced by MakeCallInst().
void GenerateReturn | ( | void | ) |
Generate a unique call to RETURN per module.
statement c = MakeStatement(l, make_continue_instruction());
Definition at line 499 of file return.c.
References CONS, end_label_local_name, expression_undefined, get_statement_number(), instruction_consistent_p(), instruction_undefined, int_to_expression(), lab_I, LinkInstToCurrentBlock(), make_instruction_block(), make_set_rc_statement(), MakeLabel(), MakeStatement(), MakeZeroOrOneArgCallInst(), NIL, src, STATEMENT, statement_number, statement_undefined, strdup(), substitute_rc_p, and uses_alternate_return_p().
Referenced by EndOfProcedure().
list get_alternate_returns | ( | void | ) |
Definition at line 258 of file return.c.
References alternate_returns.
Referenced by add_actual_return_code(), and MakeCallInst().
int get_current_number_of_alternate_returns | ( | void | ) |
Definition at line 197 of file return.c.
References current_number_of_alternate_returns.
|
static |
Type, storage and initial value may have been set up earlier in MakeFormalParameter().
We must be dealing with the actual variable, not with the formal variable.
Definition at line 115 of file return.c.
References add_variable_to_area(), DYNAMIC_AREA_LOCAL_NAME, entity_initial, entity_storage, entity_type, entity_undefined_p, f(), FindEntity(), get_current_module_name(), GetReturnCodeVariable(), is_basic_int, is_storage_ram, local_name_to_top_level_entity(), make_basic(), make_ram(), make_storage(), make_value_unknown(), MakeTypeVariable(), module_name(), NIL, pips_assert, and type_undefined_p.
Referenced by add_actual_return_code(), and generate_return_code_checks().
entity GetReturnCodeVariable | ( | void | ) |
Cannot be asserted because the return_code_variable may either be a formal parameter if the current module uses multiple return, or a dynamic variable if it does not and if it calls a subroutine using alternate returns
Definition at line 95 of file return.c.
References entity_undefined_p, FindEntity(), FindOrCreateEntity(), get_current_module_name(), get_string_property(), and return_code_variable.
Referenced by add_formal_return_code(), GetFullyDefinedReturnCodeVariable(), and make_set_rc_statement().
|
static |
get_rc takes an argument and returns void
Definition at line 291 of file return.c.
References code_undefined, concatenate(), CONS, entity_initial, entity_storage, entity_type, entity_undefined_p, EXPRESSION, FindEntity(), FindOrCreateEntity(), GET_RC_PREFIX, get_statement_number(), get_string_property(), instruction_to_statement(), instruction_undefined, is_basic_int, is_instruction_call, is_mode_reference, is_storage_rom, is_type_functional, is_type_variable, is_type_void, is_value_code, make_basic(), make_call(), make_dummy_unknown(), make_functional(), make_instruction(), make_mode(), make_parameter(), make_storage(), make_type(), make_value(), make_variable(), NIL, PARAMETER, pips_assert, statement_number, statement_undefined, strdup(), TOP_LEVEL_MODULE_NAME, update_called_modules(), and UU.
Referenced by generate_return_code_checks().
|
static |
The return code may be directly assigned or indirectly through a PIPS run-time function call.
pips_debug(2, "Statement generated: ");
print_statement(src);
}
Definition at line 421 of file return.c.
References CONS, entity_to_expression(), EXPRESSION, expression_undefined_p, GetReturnCodeVariable(), hide_rc_p, instruction_to_statement(), int_to_expression(), is_instruction_call, make_assign_statement(), make_call(), make_instruction(), NIL, set_rc_function(), src, and statement_undefined.
Referenced by GenerateReturn(), and MakeReturn().
instruction MakeReturn | ( | expression | e | ) |
Assign e to the return code variable, but be sure not to count this assignment as a user instruction. Wrap if with the Go To in a block and return the block instruction.
See how code is synthesized for computed goto's...
Let's try to provide more useful information to the user
inst = MakeZeroOrOneArgCallInst("STOP", e);
Definition at line 445 of file return.c.
References call_function, concatenate(), CONS, end_label, end_label_local_name, entity_local_name(), entity_undefined, expression_call_p(), expression_syntax, expression_undefined_p, get_current_module_name(), get_statement_number(), instruction_consistent_p(), instruction_to_statement(), instruction_undefined, line_b_I, line_e_I, make_instruction_block(), make_set_rc_statement(), MakeCharacterConstantExpression(), MakeGotoInst(), MakeLabel(), MakeZeroOrOneArgCallInst(), NIL, pips_internal_error, src, STATEMENT, statement_number, strdup(), substitute_rc_p, substitute_stop_p, syntax_call, user_error, and uses_alternate_return_p().
void reset_alternate_returns | ( | void | ) |
Definition at line 272 of file return.c.
References alternate_returns, current_number_of_alternate_returns, gen_free_list(), list_undefined, list_undefined_p, and pips_assert.
Referenced by soft_reset_alternate_returns().
void reset_current_number_of_alternate_returns | ( | void | ) |
Definition at line 192 of file return.c.
References current_number_of_alternate_returns.
void ResetReturnCodeVariable | ( | void | ) |
Definition at line 151 of file return.c.
References entity_undefined, and return_code_variable.
Referenced by EndOfProcedure(), and ParserError().
rcv | cv |
Definition at line 145 of file return.c.
References return_code_variable.
Referenced by MakeFormalParameter().
void set_alternate_returns | ( | void | ) |
Definition at line 264 of file return.c.
References alternate_returns, current_number_of_alternate_returns, list_undefined_p, NIL, and pips_assert.
void set_current_number_of_alternate_returns | ( | void | ) |
Definition at line 187 of file return.c.
References current_number_of_alternate_returns.
Referenced by gfc2pips_args().
|
static |
set_rc takes no argument and returns a scalar int
Definition at line 389 of file return.c.
References code_undefined, concatenate(), CONS, entity_initial, entity_storage, entity_type, entity_undefined_p, FindEntity(), FindOrCreateEntity(), get_string_property(), is_basic_int, is_mode_reference, is_storage_rom, is_type_functional, is_type_variable, is_type_void, is_value_code, make_basic(), make_dummy_unknown(), make_functional(), make_mode(), make_parameter(), make_storage(), make_type(), make_value(), make_variable(), NIL, PARAMETER, pips_assert, SET_RC_PREFIX, strdup(), TOP_LEVEL_MODULE_NAME, update_called_modules(), and UU.
Referenced by make_set_rc_statement().
void soft_reset_alternate_returns | ( | void | ) |
ParserError() cannot guess if it has been performed or not, because it is reinitialized before and after each call statement.
If the error occurs within a call, alternate returns must be reset. Else they should not be reset.
Definition at line 284 of file return.c.
References alternate_returns, list_undefined_p, and reset_alternate_returns().
Referenced by ParserError().
void SubstituteAlternateReturns | ( | const char * | option | ) |
return.c
option | ption |
Definition at line 59 of file return.c.
References get_bool_property(), hide_rc_p, ParserError(), substitute_rc_p, substitute_stop_p, user_log(), and user_warning.
Referenced by EndOfProcedure(), MakeCurrentFunction(), and ParserError().
bool SubstituteAlternateReturnsP | ( | void | ) |
Definition at line 81 of file return.c.
References substitute_rc_p.
Referenced by MakeCallInst(), and MakeFormalParameter().
void uses_alternate_return | ( | bool | use | ) |
use | se |
Definition at line 171 of file return.c.
References current_module_uses_alternate_returns, current_number_of_alternate_returns, get_string_property(), line_b_I, line_e_I, ParserError(), and pips_user_warning.
Referenced by EndOfProcedure(), and ParserError().
bool uses_alternate_return_p | ( | void | ) |
Definition at line 166 of file return.c.
References current_module_uses_alternate_returns.
Referenced by add_formal_return_code(), GenerateReturn(), and MakeReturn().
|
static |
Keep track of the labels used as actual arguments for alternate returns and generate the tests to check the return code.
Definition at line 239 of file return.c.
Referenced by add_alternate_return(), get_alternate_returns(), reset_alternate_returns(), set_alternate_returns(), and soft_reset_alternate_returns().
Remember if the current module uses alternate returns.
If yes, the RETURN statements must include an assignment to the return code variable.
Definition at line 161 of file return.c.
Referenced by uses_alternate_return(), and uses_alternate_return_p().
|
static |
The current number of alternate returns is used to process a module declaration.
Definition at line 164 of file return.c.
Referenced by get_current_number_of_alternate_returns(), reset_alternate_returns(), reset_current_number_of_alternate_returns(), set_alternate_returns(), set_current_number_of_alternate_returns(), and uses_alternate_return().
LOCAL entity end_label = entity_undefined |
This function creates a goto instruction to label end_label.
This is done to eliminate return statements.
Note: I was afraid the mouse trap would not work to analyze multiple procedures but there is no problem. I guess that MakeGotoInst() generates the proper label entity regardless of end_label. FI.
Definition at line 386 of file return.c.
Referenced by MakeReturn().
LOCAL char* end_label_local_name = RETURN_LABEL_NAME |
Definition at line 387 of file return.c.
Referenced by GenerateReturn(), and MakeReturn().
Definition at line 54 of file return.c.
Referenced by add_actual_return_code(), add_formal_return_code(), generate_return_code_checks(), make_set_rc_statement(), and SubstituteAlternateReturns().
|
static |
Variable used to carry return code replacing the alternate returns.
This variable may be either a formal parameter if the module uses alternate returns, or a dynamic variable if it uses such a module. When both conditions are true, the return code is a formal parameter.
Definition at line 93 of file return.c.
Referenced by GetReturnCodeVariable(), ResetReturnCodeVariable(), and ReturnCodeVariableP().
Handling of RETURN statements and substitution of alternate returns.
Most of the code deals with alternate returns. Functions GenerateReturn() and MakeReturn() are sufficient to process regular RETURN statements.
Francois Irigoin Should alternate returns be substituted or not ?
If alternate returns are substituted, the code declarations should be regenerated unless hide_rc_p is true and some PIPS run-time Fortran functions provided. The corresponding property should be checked.
Definition at line 52 of file return.c.
Referenced by add_actual_return_code(), add_alternate_return(), add_formal_return_code(), GenerateReturn(), MakeReturn(), SubstituteAlternateReturns(), and SubstituteAlternateReturnsP().
Definition at line 53 of file return.c.
Referenced by MakeReturn(), and SubstituteAlternateReturns().