PIPS
|
#include <stdio.h>
#include "genC.h"
#include "linear.h"
#include "ri.h"
#include "ri-util.h"
#include "misc.h"
#include "properties.h"
#include "prettyprint.h"
#include "c_syntax.h"
Go to the source code of this file.
Functions | |
entity | Generate_C_ReturnLabel (entity m) |
Handling of C return statements. More... | |
statement | Generate_C_ReturnStatement () |
void | Reset_C_ReturnStatement () |
The return statement must be reset when it is used by the parser to add the return statement to the function body or when a parser error is encountered. More... | |
statement | Get_C_ReturnStatement () |
This function is used to generate all goto's towards the unique return used to C replace return statement and to insert this unique return at the end of the current function's body. More... | |
statement | C_MakeReturnStatement (list el, int ln, string c) |
This function creates a goto instruction to label end_label. More... | |
int | GetReturnNumber () |
void | FixCReturnStatements (statement ms) |
When return statements have been encountered, each of them has been replaced by a goto to a unique return statement. More... | |
Variables | |
static statement | C_return_statement = statement_undefined |
Generate a unique call statement to RETURN per module. More... | |
static int | number_of_return_statements = -1 |
Saved to optimize the internal representation instead of relying on the parser and/or on control_restructure: is it possible to optimize? what is the last expression list returned? Which statement becomes redundant? More... | |
static list | last_returned_value = list_undefined |
static statement | last_return_value_assignment = statement_undefined |
static entity | return_value_entity = entity_undefined |
It is saved because it is hard to retrieve from within actual_c_parser() once the aprsing is over. More... | |
static entity | return_current_module = entity_undefined |
get_current_module_entity() is reset too early by the parser More... | |
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. Generates the internal representation of a C return statement. If e is an undefined expression, a goto returnlabel is generated. Else, e is assigned to the return value of the current function, a goto is generated and both are returned within a block.
Assign the expression to the return value of the current function
el | l |
ln | n |
Definition at line 155 of file return.c.
References CAR, CDR, CONS, empty_extensions(), ENDP, entity_empty_label(), entity_to_expression(), EXPRESSION, f(), function_to_return_value(), Get_C_ReturnStatement(), get_current_module_entity(), instruction_consistent_p(), instruction_to_statement(), instruction_undefined, instruction_undefined_p, last_return_value_assignment, last_returned_value, make_assign_instruction(), make_instruction_block(), make_instruction_goto(), make_statement(), make_synchronization_none(), NIL, pips_assert, pips_internal_error, STATEMENT, statement_consistent_p(), STATEMENT_ORDERING_UNDEFINED, statement_undefined, and string_undefined.
void FixCReturnStatements | ( | statement | ms | ) |
When return statements have been encountered, each of them has been replaced by a goto to a unique return statement.
This unique return statement may have to be added to the function body.
How many return statements have been encountered?
nothing to be done
If the return statement is the last statement of the module statement, the goto and the assignment can be replaced by a call to return. Otherwise, a return statement with the proper label must be added at the end of the module statement ms
The goto instruction and, possibly, the return value assignment can be removed: just remove the label?
Do not forget to declare the return variable...
ms | s |
Definition at line 223 of file return.c.
References AddLocalEntityToDeclarations(), C_RETURN_FUNCTION_NAME, C_return_statement, call_to_instruction, CreateIntrinsic(), entity_undefined_p, free_instruction(), get_bool_property(), GetReturnNumber(), insert_statement(), instruction_goto, instruction_goto_p, last_return_value_assignment, last_returned_value, last_statement(), make_call(), make_continue_instruction(), pips_assert, pips_internal_error, Reset_C_ReturnStatement(), reset_current_module_entity(), return_current_module, return_value_entity, set_current_module_entity(), statement_block_p, statement_instruction, and statement_undefined_p.
Referenced by actual_c_parser().
Handling of C return statements.
return.c
Unlike Fortran return statements, C return statements carry the value returned by functions. In some sense, they have a continuation since they return to the caller, but there is no local continuation. So C return cannot be simply replaced by goto statements. This only preserves the control semantics. An additional variable, the return value, must be declared and used to collect information about the different values that are returned. This translation can be removed when there is only one return at the end of the function body. Note that pass restructure_control may be useful for procedure with several returns because unspaghettify, called by the controlizer, is not strong enough.
Francois Irigoin
Definition at line 58 of file return.c.
References entity_module_name(), LABEL_PREFIX, make_label(), and RETURN_LABEL_NAME.
Referenced by Generate_C_ReturnStatement().
statement Generate_C_ReturnStatement | ( | void | ) |
Definition at line 84 of file return.c.
References C_RETURN_FUNCTION_NAME, CONS, entity_intrinsic(), entity_to_expression(), entity_type, EXPRESSION, f(), function_to_return_value(), functional_result, Generate_C_ReturnLabel(), get_current_module_entity(), instruction_to_statement(), instruction_undefined, make_call_instruction(), NIL, return_current_module, return_value_entity, statement_label, statement_undefined, type_functional, and type_void_p.
Referenced by Get_C_ReturnStatement().
statement Get_C_ReturnStatement | ( | void | ) |
This function is used to generate all goto's towards the unique return used to C replace return statement and to insert this unique return at the end of the current function's body.
Definition at line 130 of file return.c.
References C_return_statement, Generate_C_ReturnStatement(), number_of_return_statements, pips_assert, and statement_undefined_p.
Referenced by C_MakeReturnStatement().
int GetReturnNumber | ( | void | ) |
Definition at line 214 of file return.c.
References number_of_return_statements.
Referenced by FixCReturnStatements().
void Reset_C_ReturnStatement | ( | void | ) |
The return statement must be reset when it is used by the parser to add the return statement to the function body or when a parser error is encountered.
Definition at line 115 of file return.c.
References C_return_statement, entity_undefined, last_return_value_assignment, last_returned_value, list_undefined, number_of_return_statements, return_current_module, return_value_entity, and statement_undefined.
Referenced by c_parser_error(), and FixCReturnStatements().
|
static |
Generate a unique call statement to RETURN per module.
Saved to be reused each time a return must be converted into a goto b ythe parser
Definition at line 68 of file return.c.
Referenced by FixCReturnStatements(), Get_C_ReturnStatement(), and Reset_C_ReturnStatement().
|
static |
Definition at line 75 of file return.c.
Referenced by C_MakeReturnStatement(), FixCReturnStatements(), and Reset_C_ReturnStatement().
|
static |
Definition at line 74 of file return.c.
Referenced by C_MakeReturnStatement(), FixCReturnStatements(), and Reset_C_ReturnStatement().
|
static |
Saved to optimize the internal representation instead of relying on the parser and/or on control_restructure: is it possible to optimize? what is the last expression list returned? Which statement becomes redundant?
Definition at line 73 of file return.c.
Referenced by Get_C_ReturnStatement(), GetReturnNumber(), and Reset_C_ReturnStatement().
|
static |
get_current_module_entity() is reset too early by the parser
Definition at line 82 of file return.c.
Referenced by FixCReturnStatements(), Generate_C_ReturnStatement(), and Reset_C_ReturnStatement().
|
static |
It is saved because it is hard to retrieve from within actual_c_parser() once the aprsing is over.
get_current_module_entity() seems to return an undefined entity
Definition at line 80 of file return.c.
Referenced by FixCReturnStatements(), Generate_C_ReturnStatement(), and Reset_C_ReturnStatement().