25 #include "pips_config.h"
41 if (s2 ==
context->searched_statement)
43 context->found_sequence_statement = s;
57 context.searched_statement = searched_stat;
58 context.found_sequence_statement = NULL;
62 return context.found_sequence_statement;
87 if (strstr(comments,
context->searched_string) != NULL)
105 pips_debug(5,
"Comment portion: %s\n", comment_portion);
112 percent = strstr(
context.searched_string,
"%s");
117 pips_user_error(
"Malformed statement comment to search. Should be of the form 'BLAH_%%s'\n");
126 pips_debug(5,
"Searching statements with comments: %s\n",
context.searched_string);
135 return context.list_of_statements;
144 string comments = NULL;
145 string searched_string;
147 char* function_name = NULL;
151 pips_debug(5,
"BEGIN get_function_name_by_searching_tag [%s] on \n",
tag);
165 searched_string =
strdup(comment_portion);
166 searched_string[strcspn(comment_portion,
"%s")] =
'\0';
168 next_line = strtok(comments,
"\n");
170 if (next_line != NULL)
174 string first_occurence = strstr(next_line, searched_string);
176 if (first_occurence != NULL)
178 function_name =
malloc(256);
179 sscanf(first_occurence, comment_portion, function_name);
180 pips_debug(5,
"Found function: [%s]\n", function_name);
183 next_line = strtok(NULL,
"\n");
185 while (next_line != NULL);
189 free(comment_portion);
193 pips_debug(5,
"END get_function_name_by_searching_tag [%s] on \n",
tag);
195 return function_name;
206 string new_comments = NULL;
208 string searched_string =
strdup(comment_portion);
209 searched_string[strcspn(comment_portion,
"%s")] =
'\0';
211 char * next_line = strtok(comments,
"\n");
213 if (next_line != NULL)
217 if (strstr(next_line, searched_string) == NULL)
219 if (new_comments != NULL)
229 next_line = strtok(NULL,
"\n");
231 while (next_line != NULL);
234 if (new_comments != NULL)
243 free(searched_string);
254 char* removed_tag =
malloc(256);
257 pips_debug(2,
"REMOVE %s from\n", removed_tag);
268 char* removed_tag =
malloc(256);
271 pips_debug(2,
"REMOVE %s from\n", removed_tag);
286 bool statement_to_isolate =
false;
287 int nb_of_statements_to_isolate = 0;
291 pips_assert(
"function_name is not NULL", function_name != NULL);
295 if ((statement_to_isolate && (s != end_tag_statement)) || ((!statement_to_isolate) && (s == begin_tag_statement)))
297 nb_of_statements_to_isolate++;
301 if (statement_to_isolate && (s == end_tag_statement))
303 statement_to_isolate =
false;
306 if ((!statement_to_isolate) && (s == begin_tag_statement))
308 statement_to_isolate =
true;
317 char *new_tag =
malloc(256);
323 pips_debug(5,
"Found %d statement to isolate\n", nb_of_statements_to_isolate);
325 if (nb_of_statements_to_isolate > 1)
334 sequence_instruction,
338 bool isolated_seq_stats_is_inserted =
false;
342 if ((statement_to_isolate && (s != end_tag_statement)) || ((!statement_to_isolate) && (s == begin_tag_statement)))
344 if (!isolated_seq_stats_is_inserted)
346 new_seq_stats =
CONS(
STATEMENT, returned_statement, new_seq_stats);
347 isolated_seq_stats_is_inserted =
true;
355 if (statement_to_isolate && (s == end_tag_statement))
357 statement_to_isolate =
false;
360 if ((!statement_to_isolate) && (s == begin_tag_statement))
362 statement_to_isolate =
true;
371 pips_debug(5,
"Isolating and returning statement:\n");
375 return returned_statement;
377 else if (nb_of_statements_to_isolate == 1)
382 pips_debug(5,
"Isolating and returning statement:\n");
386 return begin_tag_statement;
390 pips_user_warning(
"Malformed externalized code portion identified. No operation to do. Ignored.\n");
401 list statements_containing_begin_tag;
402 list statements_contained_in_a_sequence =
NIL;
403 list statements_to_distribute =
NIL;
415 pips_debug(5,
"Potential externalizable statement:\n");
421 statements_contained_in_a_sequence =
CONS(
STATEMENT, s, statements_contained_in_a_sequence);
427 }, statements_containing_begin_tag);
432 string function_name;
433 list potential_end_statement =
NIL;
437 pips_debug(5,
"Potential externalizable statement contained in a sequence \n");
442 if (function_name != NULL)
444 pips_debug(5,
"Name: [%s] \n", function_name);
454 if (container_of_end_tag_statement == sequence_statement)
458 statements_to_distribute =
CONS(
STATEMENT, externalized_code, statements_to_distribute);
462 pips_user_warning(
"Malformed externalized code portion identified [%s]. End tag found at a bad place!!!. Ignored.\n", function_name);
467 pips_user_warning(
"Malformed externalized code portion identified [%s]. %d end tags found!!!. Ignored.\n", function_name,
gen_length(potential_end_statement));
472 pips_user_warning(
"Malformed externalized code portion identified [Unnamed]!!!. Ignored.\n");
474 }, statements_contained_in_a_sequence);
476 return statements_to_distribute;
492 debug_on(
"SAFESCALE_DISTRIBUTOR_DEBUG_LEVEL");
495 pips_debug(2,
"BEGIN of SAFESCALE_DISTRIBUTOR_INIT\n");
497 pips_debug(2,
"END of SAFESCALE_DISTRIBUTOR_INIT\n");
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)
instruction make_instruction(enum instruction_utype tag, void *val)
synchronization make_synchronization_none(void)
sequence make_sequence(list a)
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.
const char * module_name(const char *s)
Return the module part of an entity name.
#define gen_context_recurse(start, ctxt, domain_number, flt, rwt)
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.
statement set_current_module_statement(statement)
Set the current module statement.
entity set_current_module_entity(entity)
static.c
bool gen_true2(__attribute__((unused)) gen_chunk *u1, __attribute__((unused)) void *u2)
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)
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:
static void check_if_statement_contains_comment(statement s, void *a_context)
Add in the statement containing comments in the list of statements.
static void remove_end_tag(statement stat, string function_name)
Remove end tag for given statement and function.
static list get_statements_with_comments_containing(string comment_portion, statement stat)
Build a list with statements containing comments.
static void clean_statement_from_tags(string comment_portion, statement stat)
static string get_function_name_by_searching_tag(statement stat, string tag)
Return the identified function name of the externalized portion of code by searching comment matching...
static list identify_statements_to_distribute(statement module_stat)
Return a list of statements that are marked for externalization.
static bool statement_is_contained_in_a_sequence_p(statement root_statement, statement searched_stat)
bool safescale_distributor_init(const char *module_name)
Main phase for block code detection.
static void search_sequence_containing(statement s, void *a_context)
static void remove_begin_tag(statement stat, string function_name)
Remove begin tag for a given statement and function.
static statement isolate_code_portion(statement begin_tag_statement, statement end_tag_statement, statement sequence_statement)
Transform a statement in a sequence statement with a single statement which is the embedded statement...
static statement sequence_statement_containing(statement root_statement, statement searched_stat)
#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
string concatenate(const char *,...)
Return the concatenation of the given strings.
#define EXTERNALIZED_CODE_PRAGMA_BEGIN
#define EXTERNALIZED_CODE_PRAGMA_END
void print_statement(statement)
Print a statement on stderr.
bool module_reorder(statement body)
Reorder a module and recompute order to statement if any.
#define empty_comments
Empty comments (i.e.
entity module_name_to_entity(const char *mn)
This is an alias for local_name_to_top_level_entity.
entity entity_empty_label(void)
#define statement_ordering(x)
#define statement_domain
newgen_sizeofexpression_domain_defined
@ is_instruction_sequence
#define instruction_tag(x)
#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 STATEMENT(x)
STATEMENT.
#define EXTERNALIZED_CODE_PRAGMA_ANALYZED_PREFIX_TOP
#define EXTERNALIZED_CODE_PRAGMA_ANALYZED_TOP
The structure used to build lists in NewGen.
A gen_chunk is used to store every object.