25 #include "pips_config.h"
35 #include "resources.h"
74 string new_module_name,
86 string searched_string;
88 char* function_name = NULL;
93 pips_debug(5,
"BEGIN get_function_name_by_searching_tag [%s] on \n",
tag);
102 searched_string =
strdup(comment_portion);
103 searched_string[strcspn(comment_portion,
"%s")] =
'\0';
105 next_line = strtok (comments,
"\n");
106 if (next_line != NULL) {
108 string first_occurence = strstr(next_line,searched_string);
109 if (first_occurence != NULL) {
110 function_name =
malloc(256);
111 sscanf (first_occurence, comment_portion, function_name);
112 pips_debug(5,
"Found function: [%s]\n", function_name);
114 next_line = strtok(NULL,
"\n");
116 while (next_line != NULL);
120 pips_debug(5,
"END get_function_name_by_searching_tag [%s] on \n",
tag);
121 return function_name;
132 pips_debug(2,
"REMOVE %s from\n", removed_tag);
146 pips_debug(2,
"REMOVE %s from\n", removed_tag);
169 bool statement_to_isolate;
170 int nb_of_statements_to_isolate;
178 function_name != NULL);
181 statement_to_isolate =
false;
182 nb_of_statements_to_isolate = 0;
185 if ((statement_to_isolate && (s != end_tag_statement))
186 || ((!statement_to_isolate) && (s == begin_tag_statement))) {
187 nb_of_statements_to_isolate++;
190 if (statement_to_isolate && (s == end_tag_statement)) {
191 statement_to_isolate =
false;
193 if ((!statement_to_isolate) && (s == begin_tag_statement)) {
194 statement_to_isolate =
true;
211 nb_of_statements_to_isolate);
215 pips_debug(5,
"Found %d statement to isolate\n",
216 nb_of_statements_to_isolate);
218 if (nb_of_statements_to_isolate > 1) {
231 sequence_instruction,
NIL,NULL,
234 bool isolated_seq_stats_is_inserted =
false;
239 if ((statement_to_isolate && (s != end_tag_statement))
240 || ((!statement_to_isolate) && (s == begin_tag_statement))) {
241 if (!isolated_seq_stats_is_inserted) {
242 new_seq_stats =
CONS(
STATEMENT, returned_statement, new_seq_stats);
243 isolated_seq_stats_is_inserted =
true;
249 if (statement_to_isolate && (s == end_tag_statement)) {
250 statement_to_isolate =
false;
252 if ((!statement_to_isolate) && (s == begin_tag_statement)) {
253 statement_to_isolate =
true;
262 pips_debug(5,
"Isolating and returning statement:\n");
266 return returned_statement;
268 else if (nb_of_statements_to_isolate == 1) {
271 pips_debug(5,
"Isolating and returning statement:\n");
274 return begin_tag_statement;
277 pips_user_warning(
"Malformed externalized code portion identified. No operation to do. Ignored.\n");
306 list statements_containing_begin_tag =
NIL;
307 list statements_contained_in_a_sequence =
NIL;
308 list statements_to_distribute =
NIL;
311 statements_containing_begin_tag
316 if (
gen_length(statements_containing_begin_tag) > 0) {
322 statements_containing_begin_tag =
NIL;
323 statements_containing_begin_tag
330 pips_debug(5,
"Potential externalizable statement:\n");
334 statements_contained_in_a_sequence
337 statements_contained_in_a_sequence);
342 }, statements_containing_begin_tag);
347 string function_name;
349 list potential_end_statement =
NIL;
352 pips_debug(5,
"Potential externalizable statement contained in a sequence \n");
356 if (function_name != NULL) {
357 pips_debug(5,
"Name: [%s] \n", function_name);
359 potential_end_statement
362 if (
gen_length(potential_end_statement) == 1) {
368 if (container_of_end_tag_statement == sequence_statement) {
373 statements_to_distribute
376 statements_to_distribute);
379 pips_user_warning(
"Malformed externalized code portion identified [%s]. End tag found at a bad place!!!. Ignored.\n", function_name);
383 pips_user_warning(
"Malformed externalized code portion identified [%s]. %d end tags found!!!. Ignored.\n", function_name,
gen_length(potential_end_statement));
387 pips_user_warning(
"Malformed externalized code portion identified [Unnamed]!!!. Ignored.\n");
391 return statements_to_distribute;
407 string call_comments;
463 pips_assert(
"Module structure is consistent after DISTRIBUTE_CODE",
466 pips_assert(
"Statement structure is consistent after DISTRIBUTE_CODE",
469 pips_assert(
"Statement is consistent after DISTRIBUTE_CODE",
472 pips_debug(5,
"Code distribution for : [%s] is DONE\n", function_name);
504 hash_get(ht_private,function_name));
553 string new_module_name,
587 const char* new_name,
588 const char* new_module_name,
636 string new_module_name,
641 list module_parameters;
686 string new_module_name)
721 string new_module_name,
728 pips_debug(2,
"Creating new module: [%s]\n", new_module_name);
751 pips_debug(2,
"Making new module: [%s]\n", new_module_name);
780 debug_on(
"PHRASE_DISTRIBUTOR_DEBUG_LEVEL");
784 pips_debug(2,
"BEGIN of PHRASE_DISTRIBUTOR_INIT\n");
786 pips_debug(2,
"END of PHRASE_DISTRIBUTOR_INIT\n");
788 pips_assert(
"Statement structure is consistent after PHRASE_DISTRIBUTOR_INIT",
791 pips_assert(
"Statement is consistent after PHRASE_DISTRIBUTOR_INIT",
848 debug_on(
"PHRASE_DISTRIBUTOR_DEBUG_LEVEL");
861 pips_debug(2,
"BEGIN of PHRASE_DISTRIBUTOR\n");
867 pips_assert(
"Statement structure is consistent after PHRASE_DISTRIBUTOR",
870 pips_assert(
"Statement is consistent after PHRASE_DISTRIBUTOR",
dummy make_dummy_identifier(entity _field_)
call make_call(entity a1, list a2)
parameter make_parameter(type a1, mode a2, dummy a3)
mode make_mode_reference(void)
type copy_type(type p)
TYPE.
storage make_storage(enum storage_utype tag, void *val)
language make_language_unknown(void)
ram make_ram(entity a1, entity a2, intptr_t a3, list a4)
bool statement_consistent_p(statement p)
statement make_statement(entity a1, intptr_t a2, intptr_t a3, string a4, instruction a5, list a6, string a7, extensions a8, synchronization a9)
value copy_value(value p)
VALUE.
storage make_storage_formal(formal _field_)
instruction make_instruction(enum instruction_utype tag, void *val)
synchronization make_synchronization_none(void)
sequence make_sequence(list a)
formal make_formal(entity a1, intptr_t a2)
static reference ref
Current stmt (an integer)
bdt base
Current expression.
callees compute_callees(const statement stat)
Recompute the callees of a module statement.
struct _newgen_struct_statement_ * statement
void simple_restructure_statement(statement)
A simple cleaning of the control graph without major topological restructuring.
string compilation_unit_of_module(const char *)
The output is undefined if the module is referenced but not defined in the workspace,...
string get_externalizable_function_name(statement stat)
Return the identified function name of the externalized portion of code by searching comment matching...
bool compute_distribution_context(list l_stats, statement module_stat, entity module, hash_table *ht_stats, hash_table *ht_params, hash_table *ht_private, hash_table *ht_in_regions, hash_table *ht_out_regions)
This function is called during PHRASE distribution.
static entity new_variable
entity to be replaced, the primary?
void get_regions_properties(void)
void set_rw_effects(statement_effects)
void reset_out_effects(void)
void reset_proper_rw_effects(void)
void set_proper_rw_effects(statement_effects)
void set_cumulated_rw_effects(statement_effects)
void set_out_effects(statement_effects)
void set_in_effects(statement_effects)
void reset_in_effects(void)
void reset_cumulated_rw_effects(void)
void reset_rw_effects(void)
const char * module_name(const char *s)
Return the module part of an entity name.
int gen_consistent_p(gen_chunk *obj)
GEN_CONSISTENT_P dynamically checks the type correctness of OBJ.
void reset_current_module_entity(void)
Reset the current module entity.
void reset_current_module_statement(void)
Reset the current module statement.
const char * get_current_module_name(void)
Get the name of the current module.
statement set_current_module_statement(statement)
Set the current module statement.
entity set_current_module_entity(entity)
static.c
entity get_current_module_entity(void)
Get the entity of the current module.
void replace_reference(void *s, reference old, entity new)
Replace an old reference by a reference to a new entity in a statement.
list gen_nreverse(list cp)
reverse a list in place
#define NIL
The empty list (nil in Lisp)
size_t gen_length(const list l)
#define CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
#define FOREACH(_fe_CASTER, _fe_item, _fe_list)
Apply/map an instruction block on all the elements of a list.
gen_chunk gen_nth(int n, const list l)
to be used as ENTITY(gen_nth(3, l))...
#define MAP(_map_CASTER, _map_item, _map_code, _map_list)
Apply/map an instruction block on all the elements of a list (old fashioned)
string db_get_memory_resource(const char *rname, const char *oname, bool pure)
Return the pointer to the resource, whatever it is.
#define DB_PUT_MEMORY_RESOURCE(res_name, own_name, res_val)
conform to old interface.
void insert_comments_to_statement(statement, const char *)
Insert a comment string (if non empty) at the beginning of the comments of a statement.
bool statement_with_empty_comment_p(statement)
Return true if the statement has an empty statement:
void * hash_get(const hash_table htp, const void *key)
this function retrieves in the hash table pointed to by htp the couple whose key is equal to key.
void hash_table_free(hash_table htp)
this function deletes a hash table that is no longer useful.
bool add_new_module_from_text(const char *module_name, text code_text, bool is_fortran, const char *compilation_unit_name)
Add the new resource files associated to a module with its more-or-less correct code.
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
#define pips_user_warning
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
#define pips_internal_error
#define DYNAMIC_AREA_LOCAL_NAME
#define MODULE_SEP_STRING
string concatenate(const char *,...)
Return the concatenation of the given strings.
#define HASH_MAP(k, v, code, ht)
void * gen_find_tabulated(const char *, int)
list get_statements_with_comments_containing(const char *, statement)
statement sequence_statement_containing(statement, statement)
void clean_statement_from_tags(const char *, statement)
bool statement_is_contained_in_a_sequence_p(statement, statement)
void replace_in_sequence_statement_with(statement, statement, statement)
Replace statement old_stat by statement new_stat, asserting that this statement is contained in a seq...
list references_for_regions(list)
Return a list of references corresponding to a list of regions.
#define EXTERNALIZED_CODE_PRAGMA_BEGIN
#define EXTERNALIZED_CODE_PRAGMA_CALL
#define EXTERNALIZED_FUNCTION_PRIVATE_PARAM_NAME
#define EXTERNALIZED_CODE_PRAGMA_ANALYZED
#define EXTERNALIZED_CODE_PRAGMA_END
#define EXTERNALIZED_FUNCTION_PARAM_NAME
Stuff for distribution controlization.
bool phrase_distributor(const char *module_name)
static string get_externalized_function_param_name(entity variable, int param_nb)
static entity dynamic_area
list identify_analyzed_statements_to_distribute(statement stat)
This function return a list of statements that were previously marked for externalization during phas...
static entity create_module_with_statement(statement stat, string new_module_name, list l_params, list l_priv)
Dynamically build a new module with specified statement.
void add_private_variable_to_module(reference ref, entity module, statement stat, string new_module_name)
Declare in the newly created module a new variable (which will be a private to the module),...
static void remove_end_tag(statement stat, string function_name)
Remove end tag for statement stat and function function_name.
entity create_private_variable_for_new_module(entity a_variable, const char *new_name, const char *new_module_name, entity module)
Creates a private variable in specified module.
static string get_externalized_function_private_param_name(entity variable)
dg_vertex_label vertex_label
string get_function_name_by_searching_tag(statement stat, const char *tag)
Return the identified function name of the externalized portion of code by searching comment matching...
void add_parameter_variable_to_module(reference ref, entity module, statement stat, string new_module_name, int param_nb)
Declare in the newly created module a new variable (which will be a parameter of the module),...
static list identify_statements_to_distribute(statement module_stat)
This function return a list of statements that are marked for externalization.
static void distribute_code(string function_name, statement externalized_code, statement module_stat, list l_params, list l_priv)
This function is called after identification and isolation of a portion of code to externalize.
bool phrase_distributor_init(const char *module_name)
static void prepare_distribute(statement module_stat)
Main function for PHRASE_DISTRIBUTION_INIT: phrase distribution for module module_stat.
static void remove_begin_tag(statement stat, string function_name)
Remove begin tag for statement stat and function function_name.
static statement isolate_code_portion(statement begin_tag_statement, statement end_tag_statement, statement sequence_statement)
At this point, we have a sequence statement sequence_statement which contains a statement with a begi...
static void distribute(statement module_stat, entity module)
Main function for PHRASE_DISTRIBUTION: phrase distribution for main module module,...
static entity create_parameter_variable_for_new_module(entity a_variable, string new_name, string new_module_name, entity module, int param_nb)
Creates a variable declared as a parameter in specified module.
text text_named_module(entity, entity, statement)
void print_statement(statement)
Print a statement on stderr.
void set_bool_property(const char *, bool)
bool module_reorder(statement body)
Reorder a module and recompute order to statement if any.
#define make_entity(n, t, s, i)
#define empty_comments
Empty comments (i.e.
entity FindEntity(const char *package, const char *name)
Retrieve an entity from its package/module name and its local name.
const char * entity_local_name(entity e)
entity_local_name modified so that it does not core when used in vect_fprint, since someone thought t...
entity FindOrCreateEntity(const char *package, const char *local_name)
Problem: A functional global entity may be referenced without parenthesis or CALL keyword in a functi...
string entity_global_name(entity e)
Used instead of the macro to pass as formal argument.
entity module_name_to_entity(const char *mn)
This is an alias for local_name_to_top_level_entity.
entity make_empty_subroutine(const char *name, language l)
entity entity_empty_label(void)
const char * module_local_name(entity e)
Returns the module local user name.
bool fortran_module_p(entity m)
Test if a module is in Fortran.
bool entity_module_p(entity e)
expression entity_to_expression(entity e)
if v is a constant, returns a constant call.
int add_variable_to_area(entity, entity)
#define REFERENCE(x)
REFERENCE.
#define reference_variable(x)
#define statement_ordering(x)
#define type_functional(x)
#define entity_storage(x)
#define code_declarations(x)
#define EXPRESSION(x)
EXPRESSION.
#define entity_undefined_p(x)
@ is_instruction_sequence
#define instruction_tag(x)
#define functional_parameters(x)
#define PARAMETER(x)
PARAMETER.
#define sequence_statements(x)
#define statement_extensions(x)
#define instruction_sequence(x)
#define statement_instruction(x)
#define statement_comments(x)
#define statement_number(x)
#define entity_domain
newgen_syntax_domain_defined
#define variable_basic(x)
#define STATEMENT(x)
STATEMENT.
#define storage_undefined
#define entity_initial(x)
char * variable_name(Variable v)
polynome_ri.c
void module_to_value_mappings(entity m)
void module_to_value_mappings(entity m): build hash tables between variables and values (old,...
The structure used to build lists in NewGen.
A gen_chunk is used to store every object.
list module_declarations(entity m)
High-level functions about modules, using pipsdbm and ri-util and some global variables assumed prope...