PIPS
|
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "genC.h"
#include "linear.h"
#include "misc.h"
#include "properties.h"
#include "pipsdbm.h"
#include "ri-util.h"
#include "workspace-util.h"
#include "control.h"
#include "prettyprint.h"
#include "phases.h"
#include "pipsmake.h"
#include "syntax.h"
#include "parser_private.h"
#include "syn_yacc.h"
Go to the source code of this file.
Functions | |
void | init_ghost_variable_entities () |
procedure.c More... | |
void | substitute_ghost_variable_in_expression (expression expr, entity v, entity f) |
void | substitute_ghost_variable_in_statement (statement stmt, entity v, entity f) |
void | remove_ghost_variable_entities (bool substitute_p) |
void | add_ghost_variable_entity (entity e) |
void | reify_ghost_variable_entity (entity e) |
It is possible to change one's mind and effectively use an entity which was previously assumed useless. More... | |
bool | ghost_variable_entity_p (entity e) |
void | BeginingOfProcedure () |
this function is called each time a new procedure is encountered. More... | |
void | update_called_modules (entity e) |
void | remove_from_called_modules (entity e) |
macros are added, although they should not have been. More... | |
void | AbortOfProcedure () |
static bool | gather_implicit_indices (call c) |
static bool | fix_storage (reference r) |
static int | implied_do_reference_number (expression) |
forward declaration More... | |
static int | expression_reference_number (expression e) |
static list | find_target_position (list cvl, int ctp, int *pmin_cp, int *pmax_cp, expression *pcve) |
static void | store_initial_value (entity var, expression val) |
Integer and bool initial values are stored as int, float, string and maybe complex initial values are stored as entities. More... | |
static void | process_value_list (list vl, list isvs, list svps) |
static void | process_static_initialization (call c) |
static void | process_static_initializations () |
void | EndOfProcedure () |
This function is called when the parsing of a procedure is completed. More... | |
void | UpdateFunctionalType (entity f, list l) |
This function analyzes the CurrentFunction formal parameter list to determine the CurrentFunction functional type. More... | |
void | remove_module_entity (entity m) |
void | MakeCurrentFunction (type t, int msf, const char *cfn, list lfp) |
this function creates one entity cf that represents the Fortran function f being analyzed. More... | |
void | ResetEntries () |
void | AbortEntries () |
bool | EmptyEntryListsP () |
void | AddEntryLabel (entity l) |
void | AddEntryTarget (statement s) |
void | AddEntryEntity (entity e) |
void | AddEffectiveFormalParameter (entity f) |
Keep track of the formal parameters for the current module. More... | |
bool | IsEffectiveFormalParameterP (entity f) |
static list | TranslateEntryFormals (entity e, list lfp) |
list of formal parameters wrongly declared in current module More... | |
static void | MakeEntryCommon (entity m, entity a) |
Static variables in a module with entries must be redeclared as stored in a common in order to be accessible from all modules derived from the entries. More... | |
entity | SafeLocalToGlobal (entity e, type r) |
A local entity might have been created but found out later to be global, depending on the order of declaration statements (see MakeExternalFunction()). More... | |
type | MakeResultType (entity e, type r) |
The result type of a function may be carried by e, by r or be implicit. More... | |
entity | LocalToGlobal (entity e) |
instruction | MakeEntry (entity e, list lfp) |
An ENTRY statement is substituted by a labelled continue. More... | |
static statement | BuildStatementForEntry (entity cm, entity e, statement t) |
Build an entry version of the current module statement. More... | |
static void | ProcessEntry (entity cm, entity e, statement t) |
void | ProcessEntries () |
entity | NameToFunctionalEntity (string name) |
void | TypeFunctionalEntity (entity fe, type r) |
entity | MakeExternalFunction (entity e, type r) |
entity | DeclareExternalFunction (entity e) |
void | MakeFormalParameter (entity m, entity fp, int nfp) |
This function transforms an untyped entity into a formal parameter. More... | |
void | ScanFormalParameters (entity m, list l) |
this function scans the formal parameter list. More... | |
void | UpdateFormalStorages (entity m, list lfp) |
this function check and set if necessary the storage of formal parameters in lfp. More... | |
Variables | |
static list | called_modules = list_undefined |
list of called subroutines or functions More... | |
static statement | function_body = statement_undefined |
statement of current function More... | |
static list | ghost_variable_entities = list_undefined |
list of potential local or top-level variables that turned out to be useless. More... | |
static list | implicit_do_index_set = list_undefined |
static list | entry_labels = NIL |
Processing of entries: when an ENTRY statement is encountered, it is replaced by a labelled CONTINUE and the entry is declared as function or a subroutine, depending on its type. More... | |
static list | entry_targets = NIL |
static list | entry_entities = NIL |
static list | effective_formal_parameters = NIL |
void AbortEntries | ( | void | ) |
Useless entities should be reset
the current module statement is used when processing entries
Definition at line 1473 of file procedure.c.
References CleanLocalEntities(), effective_formal_parameters, ENTITY, entry_entities, entry_labels, entry_targets, error_reset_current_module_statement(), free_entity(), gen_free_list(), MAP, and NIL.
Referenced by ParserError().
void AbortOfProcedure | ( | void | ) |
get rid of ghost variable entities
Definition at line 386 of file procedure.c.
References ghost_variable_entities, list_undefined_p, remove_ghost_variable_entities(), and ResetBlockStack().
Referenced by ParserError().
void add_ghost_variable_entity | ( | entity | e | ) |
Definition at line 275 of file procedure.c.
References arguments_add_entity(), ghost_variable_entities, list_undefined_p, and pips_assert.
Referenced by SafeLocalToGlobal().
void AddEffectiveFormalParameter | ( | entity | f | ) |
Keep track of the formal parameters for the current module.
Definition at line 1529 of file procedure.c.
References arguments_add_entity(), effective_formal_parameters, and f().
Referenced by MakeEntry().
void AddEntryEntity | ( | entity | e | ) |
Definition at line 1523 of file procedure.c.
References arguments_add_entity(), and entry_entities.
Referenced by MakeEntry().
void AddEntryLabel | ( | entity | l | ) |
Definition at line 1513 of file procedure.c.
References arguments_add_entity(), and entry_labels.
Referenced by MakeEntry().
void AddEntryTarget | ( | statement | s | ) |
Definition at line 1518 of file procedure.c.
References CONS, entry_targets, gen_nconc(), NIL, and STATEMENT.
Referenced by MakeEntry().
void BeginingOfProcedure | ( | void | ) |
this function is called each time a new procedure is encountered.
reset_current_module_entity();
Definition at line 301 of file procedure.c.
References called_modules, InitImplicit(), and NIL.
Build an entry version of the current module statement.
The copy_statement() is not consistent with the use of statement t. You have to free s in a very careful way
current module statement
statement for entry e
temporary statement list
Let's get rid of s without destroying cms: do not forget the goto t!
Definition at line 1989 of file procedure.c.
References CAR, CDR, CONS, copy_statement(), entity_name, free_statement(), get_current_module_statement(), instruction_block, instruction_goto, instruction_to_statement(), is_instruction_goto, make_block_statement(), make_instruction(), NIL, pips_assert, pips_debug, STATEMENT, STATEMENT_, statement_consistent_p(), statement_instruction, and statement_undefined.
Referenced by ProcessEntry().
It might be better to declare an unknown type as result type but I decided to fix the problem later. When a call is later encountered, the result type is set to void.
e | entity to be turned into external function or subroutine, except if it is a formal functional parameter. |
Definition at line 2426 of file procedure.c.
References entity_initial, entity_storage, entity_type, entity_undefined, MakeExternalFunction(), module_local_name(), ParserError(), pips_user_warning, storage_defined_p(), storage_formal_p, type_functional_p, type_undefined, type_undefined_p, and value_intrinsic_p.
bool EmptyEntryListsP | ( | void | ) |
Definition at line 1506 of file procedure.c.
References empty, entry_entities, entry_labels, and NIL.
Referenced by EndOfProcedure(), MakeEntry(), and the_actual_parser().
void EndOfProcedure | ( | void | ) |
This function is called when the parsing of a procedure is completed.
It performs a few calculations which cannot be done on the fly such as address computations for static and dynamic areas and commons.
And it writes the internal representation of the CurrentFunction with a call to gen_free (?).
get rid of ghost variable entities and substitute them if necessary
we generate the last statement to carry a label or a comment
|| iPrevComm != 0
we generate statement last+1 to eliminate returns
Check the block stack
are there undefined gotos ?
The following calls could be located in check_first_statement() which is called when the first executable statement is encountered. At that point, many declaration related problems should be fixed or fixeable. But additional undeclared variables will be added to the dynamic area and their addresses must be computed. At least, ComputeAddresses() must stay here.. so I keep all these calls together.
Must be performed before equivalence resolution, for user declared commons whose declarations are stronger than equivalences
Use equivalence chains to update storages of equivalenced and of variables implicitly declared in DynamicArea, or implicitly thru DATA or explicitly thru SAVE declared in StaticArea
Initialize the shared field in ram storage
Now that retyping and equivalences have been taken into account:
Why keep it in (apparent) declaration order rather than alphabetical order? Because some later processing may be based on this assumption. Sort can be performed before printouts.
remove hpfc special routines if required.
done here. affects callees and code. FC.
the current package is re-initialized
Definition at line 979 of file procedure.c.
References called_modules, callees_consistent_p(), CAR, CheckAndInitializeStmt(), code_declarations, ComputeAddresses(), ComputeEquivalences(), CONS, CurrentPackage, DB_PUT_MEMORY_RESOURCE, dump_arguments(), DynamicArea, EmptyEntryListsP(), entity_declarations, entity_name, entity_undefined, EntityCode(), FormalParameters, fprint_environment(), fprintf(), function_body, gen_free_list(), gen_nreverse(), GenerateReturn(), get_bool_property(), get_current_module_entity(), hpf_directive_string_p(), ifdebug, IsBlockStackEmpty(), keep_directive_in_code_p(), lab_I, LinkInstToCurrentBlock(), make_callees(), make_continue_instruction(), MAPL, module_local_name(), NIL, parser_close_macros_support(), parser_substitute_all_macros(), ParserError(), pips_debug, PopBlock(), process_static_initializations(), ProcessEntries(), remove_ghost_variable_entities(), reset_common_size_map(), reset_current_module_entity(), reset_current_module_statement(), ResetChains(), ResetReturnCodeVariable(), SaveChains(), set_current_module_statement(), statement_consistent_p(), StaticArea, STRING, SubstituteAlternateReturns(), TOP_LEVEL_MODULE_NAME, update_common_sizes(), update_user_common_layouts(), UpdateFunctionalType(), and uses_alternate_return().
|
static |
Number of Value Positions
A scalar is referenced
An array element is referenced
A whole array is initialized
substring is equivalent to one reference
substring is equivalent to one reference
Definition at line 494 of file procedure.c.
References call_function, ENDP, entity_local_name(), entity_module_name(), entity_name, entity_scalar_p(), entity_type, expression_call_p(), expression_reference(), expression_reference_p(), expression_syntax, f(), IMPLIED_DO_NAME, implied_do_reference_number(), IO_LIST_STRING_NAME, NumberOfElements(), ParserError(), pips_debug, pips_user_warning, reference_indices, reference_variable, SUBSTRING_FUNCTION_NAME, syntax_call, type_variable, variable_basic, and variable_dimensions.
Referenced by implied_do_reference_number(), and process_static_initialization().
|
static |
Local Current Value expression List
Value Set
Value Set
Find the repeat factor
Repeat Factor Expression
Constant Value Expression
Default repeat factor
pips_assert("The repeat function is called", ENTITY_REPEAT_VALUE_P(rf));
Definition at line 613 of file procedure.c.
References call_arguments, call_function, CAR, CDR, ENDP, ENTITY_REPEAT_VALUE_P, EXPRESSION, expression_call_p(), expression_syntax, expression_to_int(), expression_undefined, gen_length(), ParserError(), pips_assert, pips_debug, pips_internal_error, pips_user_warning, POP, and syntax_call.
Referenced by process_value_list().
Variable is in static area or in a user declared common
Variable must be in a user declared common
Variable must be in static area
No need to go down
Definition at line 409 of file procedure.c.
References dynamic_area_p(), entity_blockdata_p(), entity_local_name(), entity_name, entity_storage, gen_in_list_p(), get_bool_property(), get_current_module_entity(), implicit_do_index_set, is_storage_ram, make_ram(), make_storage(), module_local_name(), NIL, ParserError(), pips_debug, pips_user_warning, ram_section, reference_variable, SaveEntity(), static_area_p(), StaticArea, storage_ram, storage_ram_p, storage_tag, storage_undefined_p, and UNKNOWN_RAM_OFFSET.
Referenced by process_static_initializations().
Definition at line 397 of file procedure.c.
References call_arguments, call_function, CAR, ENTITY_IMPLIEDDO_P, EXPRESSION, expression_syntax, gen_once(), implicit_do_index_set, reference_variable, and syntax_reference.
Referenced by process_static_initializations().
Definition at line 292 of file procedure.c.
References entity_is_argument_p(), ghost_variable_entities, list_undefined_p, and pips_assert.
Referenced by NameToFunctionalEntity(), and SafeFindOrCreateEntity().
|
static |
forward declaration
Must be an implied DO
local value position
Definition at line 561 of file procedure.c.
References call_arguments, call_function, CAR, CDR, entity_local_name(), EXPRESSION, expression_reference_number(), expression_syntax, f(), gen_length(), ifdebug, IMPLIED_DO_NAME, intptr_t, line_b_I, line_e_I, MAP, pips_assert, pips_debug, pips_user_warning, range_count(), syntax_call, syntax_range, and syntax_range_p.
Referenced by expression_reference_number().
void init_ghost_variable_entities | ( | void | ) |
Definition at line 69 of file procedure.c.
References ghost_variable_entities, list_undefined_p, NIL, and pips_assert.
Definition at line 1534 of file procedure.c.
References effective_formal_parameters, entity_is_argument_p(), and f().
Referenced by MakeEntry().
Definition at line 1801 of file procedure.c.
References SafeLocalToGlobal(), and type_undefined.
Referenced by MakeEntry(), and MakeExternalFunction().
this function creates one entity cf that represents the Fortran function f being analyzed.
if f is a Fortran FUNCTION, a second entity is created; this entity represents the variable that is used in the function body to return a value. both entities share the same name and the type of the result entity is equal to the type of cf's result.
t is the type of the function result if it has been given by the programmer as in INTEGER FUNCTION F(A,B,C)
msf indicates if f is a main, a subroutine or a function.
cf is the current function
lfp is the list of formal parameters
current function
the body of the current function
the second entity, used to store the function result
to split the entity name space between mains, commons, blockdatas and regular modules
full current function name
global entity with conflicting name
Check that there is no such common: This test is obsolete because the standard does not prohibit the use of the same name for a common and a function. However, it is not a good programming practice
if(!type_undefined_p(entity_type(cf)) || ! storage_undefined_p(entity_storage(cf)) || !value_undefined_p(entity_initial(cf)))
Clean up existing local entities in case of a recompilation.
A block data may be declared in an EXTERNAL statement, see Standard 8-9
remove_variable_entity(ce);
Let's hope cf is not an intrinsic
Unfortunately, an intrinsics cannot be redefined, just like a user function or subroutine after editing because intrinsics are not handled like user functions or subroutines. They are not added to the called_modules list of other modules, unless the redefining module is parsed FIRST. There is not mechanism in PIPS to control the parsing order.
set ghost variable entities to NIL
This procedure is called when the whole module declaration statement has been parsed. The formal parameters have already been declared and the ghost variables checked. The call was moved in gram.y, reduction rule for psf_keyword.
init_ghost_variable_entities();
initialize equivalence chain lists to NIL
the intended result type t for a main or a subroutine should be undefined
The parameters part of cf's functional type is not created because the types of formal parameters are not known yet. This is performed later by UpdateFunctionalType().
If a call to the function has been encountered before, it's already typed. However, this information is discarded.
a function has a rom storage
a function has an initial value 'code' that contains an empty block
FI: This NULL string is a catastrophy for the strcmp used later to check the content of the stack. Any string, including the empty string "", would be better. icf is used to link new instructions/statement to the current block. Only the first block is not pushed for syntactic reasons. The later blocks will be pushed for DO's and IF's.
PushBlock(icf, (string) NULL);
No common has yet been declared
Generic areas are created for memory allocation.
Formal parameters are created. Alternate returns can be ignored or substituted.
a result entity is created
esult = FindOrCreateEntity(CurrentPackage, entity_local_name(cf));
CleanLocalEntities() does not remove any entity
msf | sf |
cfn | fn |
lfp | fp |
Definition at line 1239 of file procedure.c.
References add_formal_return_code(), AddEntityToDeclarations(), BLOCKDATA_PREFIX, CleanLocalEntities(), code_declarations, code_undefined_p, COMMON_PREFIX, concatenate(), CurrentPackage, DeclareVariable(), ENDP, entity_domain, entity_initial, entity_local_name(), entity_name, entity_storage, entity_type, entity_undefined, entity_undefined_p, FatalError, FindEntity(), FindOrCreateEntity(), free(), free_type(), function_body, gen_find_tabulated(), get_string_property(), ImplicitType(), InitAreas(), initialize_common_size_map(), instruction_to_statement(), intrinsic_entity_p(), is_storage_return, is_type_functional, is_type_void, is_value_code, MAIN_PREFIX, make_code(), make_functional(), make_language_fortran(), make_sequence(), make_storage(), make_storage_rom(), make_type(), make_value(), MakeEmptyInstructionBlock(), module_local_name(), MODULE_SEP_STRING, NIL, ParserError(), pips_debug, pips_user_warning, prefix, PushBlock(), remove_module_entity(), ScanFormalParameters(), set_current_module_entity(), SetChains(), strdup(), string_undefined, SubstituteAlternateReturns(), TK_BLOCKDATA, TK_FUNCTION, TK_PROGRAM, TOP_LEVEL_MODULE_NAME, type_undefined, type_undefined_p, user_warning, UU, value_code, value_code_p, value_undefined, and value_undefined_p.
instruction MakeEntry | ( | entity | e, |
list | lfp | ||
) |
An ENTRY statement is substituted by a labelled continue.
The ENTRY entity is created as in MakeExternalFunction() and MakeCurrentFunction(). list of formal parameters
current module cm
The parser expects an instruction and not a statement. I use a block wrapping to avoid tampering with lab_I.
entity e = FindOrCreateEntity(cmn, en);
result type
current chunk (temporary)
list of effective formal parameters
Name conflicts could be checked here as in MakeCurrentFunction()
Keep track of the effective formal parameters of the current module cm at the first call to MakeEntry and reallocate static variables.
Check if the static area is empty and define a specific common if not.
Too early: StaticArea is not defined yet. Postpone to ProcessEntry. if(area_size(type_area(entity_type(StaticArea)))!=0) { MakeEntryCommon(cm, StaticArea); }
Compute the result type and make sure a functional entity is being used.
In case of previous declaration in the current module
Entity e must not be destroyed if fe is a function because e must carry the result.
In case of previous declaration in the current module
Entry fe may have been encountered earlier and typed from the parameter list
This depends on what has been done in LocalToGlobal and SafeLocalToGlobal
This depends on what has been done in LocalToGlobal and SafeLocalToGlobal
A call site for fe has been encountered in another module
Should now be the normal case...
The entry formal parameters should be removed if they are not formal parameters of the current module... but they are referenced. They cannot be preserved although useless because they may be dimensionned by expressions legal for this entry but not for the current module. They should be removed later when dead code elimination let us know which variables are used by each entry.
Temporarily, the formal parameters of entry fe are declared in cm to keep the code consistent but they are supposedly not added to cm's declarations... because FindOrCreateEntity() does not update declarations. MakeAtom() does not redeclare formal parameters.
Let's assume it works for undefined storages..
Should it really be officially declared?
Remove it from the declaration list
fp may appear in a type statement and/or an executable statement: the information is now lost.
Request some post-processing
lfp | entry, local to retrieve potential explicit typing |
Definition at line 1810 of file procedure.c.
References AddEffectiveFormalParameter(), AddEntryEntity(), AddEntryLabel(), AddEntryTarget(), CAR, code_declarations, code_undefined, code_undefined_p, CONS, dump_arguments(), EmptyEntryListsP(), ENDP, ENTITY, entity_declarations, entity_function_p(), entity_initial, entity_is_argument_p(), entity_local_name(), entity_name, entity_storage, entity_type, entity_undefined, fprintf(), free_storage(), free_type(), gen_remove(), get_current_module_entity(), ifdebug, is_storage_formal, is_type_void, is_value_code, IsEffectiveFormalParameterP(), list_undefined, LocalToGlobal(), make_code(), make_continue_statement(), make_formal(), make_instruction_block(), make_language_fortran(), make_new_label(), make_sequence(), make_storage(), make_storage_rom(), make_type(), make_value(), MakeResultType(), MAP, module_local_name(), NIL, pips_assert, pips_debug, pips_internal_error, pips_user_warning, POP, SafeLocalToGlobal(), STATEMENT, storage_formal_p, storage_rom_p, storage_undefined_p, strdup(), TranslateEntryFormals(), type_undefined, type_undefined_p, TypeFunctionalEntity(), UpdateFormalStorages(), UpdateFunctionalType(), UU, value_code, value_code_p, value_undefined_p, and value_unknown_p.
Static variables in a module with entries must be redeclared as stored in a common in order to be accessible from all modules derived from the entries.
This may create a problem for variables initialized with a DATA for compilers that do not accept multiple initializations of a common variable.
FI: the prefix used to be "_ENTRY_" but this seems to be refused by f77 3.3.5
Make sure that no static variables are aliased because this special cases has not been implemented
Process all variables in a's layout and declare them stored in c
A variable in a common cannot be initialized more than once
Copy a's area in c's area
Do not sort by name or the offset increasing implicit rule is broken: sort_list_of_entities(area_layout(ac));
Reset a's area
Definition at line 1573 of file procedure.c.
References area_layout, area_size, area_undefined, common_members_of_module(), COMMON_PREFIX, concatenate(), ENDP, ENTITY, entity_initial, entity_local_name(), entity_name, entity_storage, entity_type, entity_undefined_p, FindOrCreateEntity(), free(), gen_free_list(), ifdebug, list_undefined, local_name_to_top_level_entity(), MakeCommon(), MAP, module_local_name(), NIL, ParserError(), pips_assert, pips_debug, pips_internal_error, pips_user_warning, print_arguments(), print_common_layout(), ram_section, ram_shared, storage_ram, storage_ram_p, strdup(), TOP_LEVEL_MODULE_NAME, type_area, and value_constant.
Referenced by ProcessEntry().
Assertion: fe is a (functional) global entity and the type of its result is new_r, or it is a formal functional parameter
a function has a rom storage, except for formal functions
an external function has an unknown initial value, else code would be temporarily undefined which is avoided (theoretically forbidden) in PIPS.
fe is added to CurrentFunction's entities
r | entity to be turned into external function type of result |
Definition at line 2372 of file procedure.c.
References AddEntityToDeclarations(), entity_blockdata_p(), entity_initial, entity_name, entity_storage, entity_undefined, get_current_module_entity(), LocalToGlobal(), make_storage_rom(), make_value_unknown(), MakeResultType(), pips_debug, pips_user_warning, storage_formal_p, storage_undefined, type_undefined, TypeFunctionalEntity(), and value_undefined.
Referenced by DeclareExternalFunction(), MakeAtom(), and MakeCallInst().
This function transforms an untyped entity into a formal parameter.
fp is an entity generated by FindOrCreateEntity() for instance, and nfp is its rank in the formal parameter list.
A specific type is used for the return code variable which may be adde by the parser to handle alternate returns. See return.c offset (i.e. rank) of formal parameter
fp | module of formal parameter |
nfp | formal parameter |
Definition at line 2466 of file procedure.c.
References entity_initial, entity_local_name(), entity_storage, entity_type, formal_label_replacement_p(), ImplicitType(), is_basic_int, is_basic_string, is_storage_formal, is_type_variable, make_basic(), make_formal(), make_storage(), make_type(), make_value_unknown(), make_variable(), MakeTypeVariable(), NIL, ParserError(), pips_user_warning, ReturnCodeVariableP(), SubstituteAlternateReturnsP(), and type_undefined_p.
Referenced by ScanFormalParameters().
The result type of a function may be carried by e, by r or be implicit.
A new type structure is allocated, unless r is used as new result type.
e is a function that was implicitly declared as a variable. this may happen in Fortran.
pips_assert("undefined type", r == type_undefined);
The variable may have been typed, for instance implicitly, but then it appears in a CALL statement and its new type is void. Added for formal parameters.
Well... this should be useless because e is already typed. FI: I do not believe copy_type() is necessary in spite of the non orthogonality...
Definition at line 1754 of file procedure.c.
References copy_type(), entity_name, entity_type, functional_result, ImplicitType(), pips_assert, pips_debug, pips_internal_error, type_functional, type_functional_p, type_to_string(), type_undefined, type_undefined_p, type_variable_p, and type_void_p.
Referenced by MakeEntry(), and MakeExternalFunction().
Ignore ghost variables, they are not in the current scope
The functional entity must be a formal parameter
The current declaration is wrong and should be fixed later, i.e. by MakeExternalFunction() or MakeCallInst()
It is the name of a blockdata
name | ame |
Definition at line 2217 of file procedure.c.
References BLOCKDATA_PREFIX, concatenate(), CurrentPackage, entity_domain, entity_storage, entity_undefined, entity_undefined_p, f(), FindOrCreateEntity(), gen_find_tabulated(), ghost_variable_entity_p(), MODULE_SEP_STRING, pips_assert, storage_formal_p, storage_undefined_p, and TOP_LEVEL_MODULE_NAME.
|
static |
Initialized Scalar VariableS
Scalar Value PositionS
Current Variable Position
Value list from the second element on
Reference list, hanging from call to DATA LIST function
DATA LIST function
reference list expression, with call to DATA LIST
Value List, with repeat operator
Look for initialized scalar variables and for their positions in the reference list
Move al to the first value, passing the reference list
A scalar is referenced
0 is returned for call to IO LIST
Process the value list
Definition at line 852 of file procedure.c.
References call_arguments, call_function, CAR, CDR, CONS, ENDP, ENTITY, ENTITY_DATA_LIST_P, entity_local_name(), entity_scalar_p(), ENTITY_STATIC_INITIALIZATION_P, entity_undefined, EXPRESSION, expression_call_p(), expression_reference(), expression_reference_number(), expression_reference_p(), expression_syntax, expression_undefined, fprintf(), gen_in_list_p(), gen_length(), gen_nconc(), ifdebug, INT, list_undefined, MAP, NIL, ParserError(), pips_assert, pips_debug, pips_user_warning, POP, process_value_list(), reference_variable, and syntax_call.
Referenced by process_static_initializations().
|
static |
Variables appearing in a static initialization cannot be in the dynamic area, nor in the heap_area nor in the stack_area. They must be moved to the static area if this happens unless they are implied do indices.
Definition at line 945 of file procedure.c.
References call_domain, code_initializations, entity_initial, fix_storage(), gather_implicit_indices(), gen_free_list(), gen_null(), gen_recurse, get_current_module_entity(), implicit_do_index_set, list_undefined, MAP, NIL, pips_internal_error, process_static_initialization(), reference_domain, sequence_statements, STATEMENT, statement_call(), statement_call_p(), and value_code.
Referenced by EndOfProcedure().
Find a value in vl at the monotonically increasing position given in svps for the variable in isvs. All lists are assumed non-empty.
current target position
The current position is a window because of the repeat operator
minimal current position
maximal current position
Current Value List
Current Initialized Variable List
Current Value Expression
Store value
Not enough values in vl
reuse the same value cve
Store value
Definition at line 809 of file procedure.c.
References CAR, ENDP, ENTITY, entity_local_name(), expression_undefined, find_target_position(), INT, list_undefined, ParserError(), pips_assert, pips_internal_error, pips_user_warning, POP, and store_initial_value().
Referenced by process_static_initialization().
void ProcessEntries | ( | void | ) |
To avoid an include of the prettyprint library and/or a compiler warning.
The declarations for cm are likely to be incorrect. They must be synthesized by the prettyprinter.
Regenerate a SOURCE_FILE .f without entries for the module itself
To avoid warnings about column 73 when the code is parsed again
Not ot duplicate DATA statements for static variables and common variables in every entry
Process each entry
Postponed to the_actual_parser() which needs to know entries were encountered
Definition at line 2171 of file procedure.c.
References CAR, code_decls_text, ENDP, ENTITY, entity_code(), entry_entities, entry_labels, entry_targets, free(), get_bool_property(), get_current_module_entity(), get_current_module_statement(), make_text_resource_and_free(), module_local_name(), NIL, pips_assert, POP, ProcessEntry(), set_bool_property(), STATEMENT, statement_label, strdup(), text_named_module(), and text_undefined.
Referenced by EndOfProcedure().
so as not to compute anything before the debugging message is printed out
Compute the proper declaration list, without formal parameters from cm and with formal parameters from e
Collect local and global variables of cm that may be visible from entry e
Try to get rid of unreachable statements which may contain references to formal parameters undeclared in the current entry an obtain a clean entry statement (ces).
By default we use the controlizer that is activated according to pipsmake...
...but we can change it according to special environment variables if they are defined:
Compute an external representation of entry statement es for entry e. Cheat with the declarations because of text_named_module().
DATA statements should not be replicated in each entry code
give the entry a user file.
Definition at line 2036 of file procedure.c.
References active_phase_p(), area_size, arguments_add_entity(), BuildStatementForEntry(), code_initializations, control_graph(), db_get_memory_resource(), DB_PUT_MEMORY_RESOURCE, dump_arguments(), empty_comments, empty_extensions(), ENTITY, entity_declarations, entity_empty_label(), entity_initial, entity_name, entity_storage, entity_type, fprint_environment(), fprintf(), free_statement(), gen_nconc(), get_bool_property(), get_current_module_statement(), hcfg(), ifdebug, init_stmt, is_instruction_unstructured, list_undefined, make_instruction(), MAKE_ORDERING, make_statement(), make_synchronization_none(), make_text_resource_and_free(), MakeEntryCommon(), MAP, module_local_name(), NIL, pips_assert, pips_debug, sequence_statements, set_bool_property(), statement_consistent_p(), STATEMENT_NUMBER_UNDEFINED, statement_undefined, StaticArea, storage_formal_p, strdup(), text_named_module(), text_undefined, type_area, unspaghettify_statement(), USE_NEW_CONTROLIZER_ENV_VAR_NAME, USE_OLD_CONTROLIZER_ENV_VAR_NAME, and value_code.
Referenced by ProcessEntries().
void reify_ghost_variable_entity | ( | entity | e | ) |
It is possible to change one's mind and effectively use an entity which was previously assumed useless.
Definition at line 284 of file procedure.c.
References arguments_rm_entity(), entity_is_argument_p(), ghost_variable_entities, list_undefined_p, and pips_assert.
Referenced by CheckLeftHandSide().
void remove_from_called_modules | ( | entity | e | ) |
macros are added, although they should not have been.
Definition at line 354 of file procedure.c.
References called_modules, CAR, CDR, ENDP, entity_name, free(), gen_free_list(), module_local_name(), NIL, pips_debug, POP, same_string_p, and STRING.
Referenced by parser_close_macros_support().
void remove_ghost_variable_entities | ( | bool | substitute_p | ) |
The debugging message must use the variable name before it is freed
We already are in ParserError()! Too bad for the memory leak
substitute_p | ubstitute_p |
Definition at line 206 of file procedure.c.
References ENTITY, entity_in_equivalence_chains_p(), entity_local_name(), entity_name, entity_type, entity_undefined_p, function_body, ghost_variable_entities, list_undefined, list_undefined_p, local_name_to_top_level_entity(), MAP, ParserError(), pips_assert, pips_debug, remove_variable_entity(), substitute_ghost_variable_in_statement(), type_functional_p, type_undefined_p, type_variable_p, and user_warning.
Referenced by AbortOfProcedure(), and EndOfProcedure().
void remove_module_entity | ( | entity | m | ) |
It is assumed that neither variables nor areas have been declared in m but that m may have been declared by EXTERNAL in other modules.
Definition at line 1188 of file procedure.c.
References code_declarations, code_undefined_p, db_get_module_list(), entity_initial, entity_name, entity_undefined_p, free_entity(), gen_array_full_free(), gen_array_item(), gen_array_nitems(), gen_in_list_p(), gen_remove(), ifdebug, local_name_to_top_level_entity(), pips_debug, value_code, value_undefined_p, and value_unknown_p.
Referenced by MakeCurrentFunction().
void ResetEntries | ( | void | ) |
Definition at line 1458 of file procedure.c.
References effective_formal_parameters, entry_entities, entry_labels, entry_targets, gen_free_list(), and NIL.
Referenced by the_actual_parser().
A local entity might have been created but found out later to be global, depending on the order of declaration statements (see MakeExternalFunction()).
The local entity e is (marked as) destroyed and replaced by functional entity fe.
Should we anticipate the value code, since we know it has to be a value code for a function and it may be tested later after the parsing phase of the caller but before the parsing phase of the callee, or should we wait till the code is really known?
entity_initial(fe) = make_value(is_value_unknown, UU);
FI: I need to destroy a virtual entity which does not appear in the program and wich was temporarily created by the parser when it recognized a name; however, I've no way to know if the same entity does not appear for good somewhere else in the code; does the Fortran standard let you write: LOG = LOG(3.) If yes, PIPS will core dump... PIPS also core dumps with ALOG(ALOG(X))... (8 July 1993)
remove_variable_entity(e);
ParserError("LocalToGlobal", "Formal functional parameters are not supported " "by PIPS.\n");
Definition at line 1681 of file procedure.c.
References add_ghost_variable_entity(), entity_initial, entity_local_name(), entity_name, entity_storage, entity_undefined, FatalError, FindOrCreateEntity(), is_storage_rom, is_value_code, make_code(), make_language_fortran(), make_sequence(), make_storage(), make_value(), NIL, pips_assert, pips_debug, pips_internal_error, pips_user_warning, storage_formal_p, storage_ram_p, storage_rom_p, storage_tag, storage_undefined, storage_undefined_p, strdup(), top_level_entity_p(), TOP_LEVEL_MODULE_NAME, type_undefined_p, UU, and value_undefined_p.
Referenced by LocalToGlobal(), and MakeEntry().
this function scans the formal parameter list.
each formal parameter is created with an implicit type, and then is added to CurrentFunction's declarations.
le parametre formel
son rang dans la liste
Definition at line 2503 of file procedure.c.
References AddEntityToDeclarations(), CAR, CDR, ENTITY, FormalParameters, and MakeFormalParameter().
Referenced by MakeCurrentFunction().
|
static |
Integer and bool initial values are stored as int, float, string and maybe complex initial values are stored as entities.
Type coercion should be implemented as required in the Fortran standard.
type val_t = type_of_expression(val);
variable val_vt = type_variable(val_t);
to be freed
The semantics of expression_constant_p() is a call to a constant entity and not a constant expression(), i.e. an expression whose terms are all recursively constant
pips_assert("val is a constant expression", expression_constant_p(val));
return;
Type coercion
Voir avec Fabien les procedures de Son, type_this_chunk() et typing_of_expressions()
Has an initialization already been defined for var?
An evaluation function should evaluate any well-typed expression and return a value. Find below a very limited evaluation procedure for backward compatibility with PIPS previous implementation for integer expressions
Storage if a proper initial value has been found
Is there a leading unary minus?
For real and complex, I should allocate "-f" and forget about calls to unary minus
Definition at line 675 of file procedure.c.
References basic_equal_p(), basic_of_expression(), basic_tag, call_arguments, call_function, CAR, constant_call, constant_call_p, constant_int, constant_int_p, ENTITY_FALSE_P, entity_initial, entity_local_name(), entity_scalar_p(), ENTITY_TRUE_P, entity_type, ENTITY_UNARY_MINUS_P, EXPRESSION, expression_call_p(), expression_syntax, expression_undefined, expression_undefined_p, f(), free_basic(), free_value(), i2a(), ifdebug, is_basic_complex, is_basic_float, is_basic_int, is_basic_logical, is_basic_overloaded, is_basic_string, is_constant_call, is_constant_int, is_value_constant, is_value_unknown, make_constant(), make_value(), ParserError(), pips_assert, pips_debug, pips_internal_error, pips_user_warning, print_expression(), syntax_call, type_variable, UU, value_constant, value_constant_p, value_undefined, value_unknown_p, and variable_basic.
Referenced by process_value_list().
void substitute_ghost_variable_in_expression | ( | expression | expr, |
entity | v, | ||
entity | f | ||
) |
It is assumed that v and f are defined entities and that v is of type variable and f of type functional.
ParserError() is going to request ghost variable substitution recursively and we do not want this to happen because it is going to fail again. Well, substitution won't be tried from AbortOfProcedure()...
ghost_variable_entities = NIL;
ParserError("substitute_ghost_variable_in_expression", "Functional parameters are not (yet) supported by PIPS\n");
expr | xpr |
Definition at line 75 of file procedure.c.
References call_arguments, call_function, call_undefined, entity_name, EXPRESSION, expression_syntax, f(), ifdebug, is_syntax_call, is_syntax_range, is_syntax_reference, MAP, module_local_name(), pips_assert, pips_debug, pips_user_warning, print_expression(), range_increment, range_lower, range_undefined, range_upper, ref, reference_indices, reference_undefined, reference_variable, syntax_call, syntax_range, syntax_reference, and syntax_tag.
Referenced by substitute_ghost_variable_in_statement().
It is assumed that v and f are defined entities and that v is of type variable and f of type functional.
gen_recurse() is not used to control the context better
unstructured u = unstructured_undefined;
Local variables should also be checked
Local variables should also be checked
nothing to do
stmt | tmt |
Definition at line 139 of file procedure.c.
References call_arguments, call_function, call_undefined, EXPRESSION, f(), FatalError, instruction_block, instruction_call, instruction_loop, instruction_tag, instruction_test, instruction_whileloop, is_instruction_call, is_instruction_goto, is_instruction_loop, is_instruction_sequence, is_instruction_test, is_instruction_unstructured, is_instruction_whileloop, loop_body, loop_index, loop_label, loop_range, loop_undefined, MAP, pips_assert, range_increment, range_lower, range_upper, STATEMENT, statement_instruction, statement_label, substitute_ghost_variable_in_expression(), test_condition, test_false, test_true, test_undefined, whileloop_body, whileloop_condition, whileloop_label, and whileloop_undefined.
Referenced by remove_ghost_variable_entities().
list of formal parameters wrongly declared in current module
list of effective formal parameters lefp for entry e
the storage is not recoverable
lfp | entry e |
Definition at line 1539 of file procedure.c.
References CONS, copy_type(), copy_value(), dump_arguments(), ENTITY, entity_initial, entity_local_name(), entity_type, FindOrCreateEntity(), gen_nconc(), ifdebug, MAP, module_local_name(), NIL, and pips_debug.
Referenced by MakeEntry().
this is wrong, because we do not know if we are handling an EXTERNAL declaration, in which case the result type is type_undefined, or a function call appearing somewhere, in which case the ImplicitType should be used; maybe the unknown type should be used?
a bug is detected here: MakeExternalFunction, as its name implies, always makes a FUNCTION, even when the symbol appears in an EXTERNAL statement; the result type is infered from ImplicitType() - see just above -; let's use implicit_type_p() again, whereas the unknown type should have been used
ignore r
someone used a subroutine as a function. this happens in hpfc for declaring "pure" routines. thus I make this case being ignored. warning? FC.
memory leak of tr
This may be an undeclared formal functional argument, initially assumed to be a variable. Since it is not declared as an array but appears with arguments, it must be a functional entity.
I do not know how to get the argument types. Let's hope it's performed later...
fe | e |
Definition at line 2257 of file procedure.c.
References basic_to_string(), entity_name, entity_storage, entity_type, free_type(), functional_result, implicit_type_p(), ImplicitType(), intrinsic_entity_p(), is_type_functional, make_functional(), make_type(), NIL, overloaded_type_p(), ParserError(), pips_internal_error, storage_formal_p, type_equal_p(), type_functional, type_functional_p, type_undefined, type_variable, type_variable_p, type_void_p, user_warning, and variable_basic.
Referenced by MakeEntry(), and MakeExternalFunction().
void update_called_modules | ( | entity | e | ) |
Self recursive calls are not allowed
do not count intrinsics; user function should not be named like intrinsics
FI, 20/01/92: maybe, initializations of global entities should be more precise (storage, initial value, etc...); for the time being, I choose to ignore the potential problems with other executions of the parser and the linker
pips_internal_error("unexpected case");
Definition at line 308 of file procedure.c.
References called_modules, CAR, concatenate(), CONS, entity_domain, entity_initial, entity_local_name(), entity_undefined, gen_find_tabulated(), get_current_module_entity(), MAPL, MODULE_SEP_STRING, ParserError(), pips_debug, pips_user_warning, strdup(), STRING, TOP_LEVEL_MODULE_NAME, value_intrinsic_p, and value_undefined.
Referenced by make_get_rc_statement(), MakeAtom(), MakeCallInst(), and set_rc_function().
this function check and set if necessary the storage of formal parameters in lfp.
formal parameter chunk
formal parameter offset
Oupss... the associated area should be cleaned up... but it should ony occur in EndOfProcedure() when all implictly declared variables have been encountered...
lfp | fp |
Definition at line 2522 of file procedure.c.
References CAR, ENDP, ENTITY, entity_module_name(), entity_name, entity_storage, formal_offset, free_storage(), is_storage_formal, local_name_to_top_level_entity(), make_formal(), make_storage(), pips_assert, pips_internal_error, POP, storage_formal, storage_formal_p, storage_ram_p, and storage_undefined_p.
Referenced by MakeEntry().
This function analyzes the CurrentFunction formal parameter list to determine the CurrentFunction functional type.
l is this list.
It is called by EndOfProcedure().
FI: I do not understand this assert... at least now that functions may be typed at call sites. I do not understand why this assert has not made more damage. Only OVL in APSI (Spec-cfp95) generates a core dump. To be studied more!
This assert is guaranteed by MakeCurrentFunction() but not by retype_formal_parameters() which is called in case an intrinsic statement is encountered. It is not guaranteed by MakeExternalFunction() which uses the actual parameter list to estimate a functional type
Definition at line 1131 of file procedure.c.
References CAR, CDR, CONS, ENDP, ENTITY, entity_type, f(), fprint_functional(), fprintf(), functional_parameters, gen_nconc(), ifdebug, ImplicitType(), make_dummy_identifier(), make_parameter(), MakeModeReference(), module_local_name(), NIL, PARAMETER, pips_assert, pips_debug, type_functional, type_functional_p, and type_undefined_p.
Referenced by EndOfProcedure(), gfc2pips_namespace(), gfc2pips_parameters(), and MakeEntry().
|
static |
list of called subroutines or functions
Definition at line 57 of file procedure.c.
Referenced by BeginingOfProcedure(), build_real_resources(), callgraph(), EndOfProcedure(), remove_from_called_modules(), and update_called_modules().
Definition at line 1456 of file procedure.c.
Referenced by AbortEntries(), AddEffectiveFormalParameter(), IsEffectiveFormalParameterP(), and ResetEntries().
Definition at line 1455 of file procedure.c.
Referenced by AbortEntries(), AddEntryEntity(), EmptyEntryListsP(), ProcessEntries(), and ResetEntries().
Processing of entries: when an ENTRY statement is encountered, it is replaced by a labelled CONTINUE and the entry is declared as function or a subroutine, depending on its type.
The label and the module entity which are created are stored in two static lists, entry_labels and entry_entities, for later processing. When the current module has been fully parsed, the two entry lists are scanned together. The current module code is duplicated for each entry, a GOTO the proper entry label is added, the code is controlized to get rid of the unwanted pieces of code, and:
The second approach was selected. The current .f file is overwritten when the parser is called for the code of an entry.
Further problems are created by entries in fsplit which creates a .f_initial file for each entry and in the parser which may not produce the expected PARSED_CODE when it is called for an ENTRY. A recursive call to the parser is executed to parse the .f file just produced by the first call. This scheme was designed to make entries unvisible from pipsmake.
Definition at line 1453 of file procedure.c.
Referenced by AbortEntries(), AddEntryLabel(), EmptyEntryListsP(), ProcessEntries(), and ResetEntries().
Definition at line 1454 of file procedure.c.
Referenced by AbortEntries(), AddEntryTarget(), ProcessEntries(), and ResetEntries().
|
static |
statement of current function
Definition at line 60 of file procedure.c.
Referenced by EndOfProcedure(), MakeCurrentFunction(), and remove_ghost_variable_entities().
|
static |
list of potential local or top-level variables that turned out to be useless.
Definition at line 67 of file procedure.c.
Referenced by AbortOfProcedure(), add_ghost_variable_entity(), ghost_variable_entity_p(), init_ghost_variable_entities(), reify_ghost_variable_entity(), and remove_ghost_variable_entities().
|
static |
Definition at line 395 of file procedure.c.
Referenced by fix_storage(), gather_implicit_indices(), and process_static_initializations().