PIPS
spaghettify.h File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define INDEX_VARIABLE_NAME   "DO%d_INDEX"
 
#define BEGIN_VARIABLE_NAME   "DO%d_BEGIN"
 
#define END_VARIABLE_NAME   "DO%d_END"
 
#define INCREMENT_VARIABLE_NAME   "DO%d_INCREMENT"
 

Functions

statement spaghettify_loop (statement stat, const char *module_name)
 This function takes the statement stat as parameter and return a new spaghettized statement, asserting stat is a LOOP statement. More...
 
statement spaghettify_whileloop (statement stat, const char *module_name)
 whileloop_spaghettify.c More...
 
statement spaghettify_forloop (statement stat, const char *module_name)
 This function takes the statement stat as parameter and return a new spaghettized statement, asserting stat is a FORLOOP statement. More...
 
statement spaghettify_test (statement stat, const char *module_name)
 test_spaghettify.c More...
 
statement spaghettify_statement (statement stat, const char *module_name)
 The spaghettifier is used in context of PHRASE project while creating "Finite State Machine"-like code portions in order to synthetise them in reconfigurables units. More...
 

Macro Definition Documentation

◆ BEGIN_VARIABLE_NAME

#define BEGIN_VARIABLE_NAME   "DO%d_BEGIN"

Definition at line 28 of file spaghettify.h.

◆ END_VARIABLE_NAME

#define END_VARIABLE_NAME   "DO%d_END"

Definition at line 29 of file spaghettify.h.

◆ INCREMENT_VARIABLE_NAME

#define INCREMENT_VARIABLE_NAME   "DO%d_INCREMENT"

Definition at line 30 of file spaghettify.h.

◆ INDEX_VARIABLE_NAME

#define INDEX_VARIABLE_NAME   "DO%d_INDEX"

Definition at line 27 of file spaghettify.h.

Function Documentation

◆ spaghettify_forloop()

statement spaghettify_forloop ( statement  stat,
const char *  module_name 
)

This function takes the statement stat as parameter and return a new spaghettized statement, asserting stat is a FORLOOP statement.

forloop_spaghettify.c

Parameters
stattat
module_nameodule_name

Definition at line 135 of file forloop_spaghettify.c.

136 {
137  statement returned_statement = stat;
138  instruction unstructured_instruction;
139  unstructured new_unstructured;
140 
141  pips_assert("Statement is FORLOOP in FSM_GENERATION",
144 
145  pips_debug(2, "spaghettify_forloop, module %s\n", module_name);
146 
147  new_unstructured
150  stat,
151  module_name);
152 
153  unstructured_instruction = make_instruction(is_instruction_unstructured,
154  new_unstructured);
155 
156  statement_instruction(returned_statement) = unstructured_instruction;
157 
158  return returned_statement;
159 }
instruction make_instruction(enum instruction_utype tag, void *val)
Definition: ri.c:1166
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
static unstructured make_unstructured_from_forloop(forloop curLoop, statement stat, const char *module_name)
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
Definition: misc-local.h:145
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
@ is_instruction_unstructured
Definition: ri.h:1475
@ is_instruction_forloop
Definition: ri.h:1477
#define instruction_tag(x)
Definition: ri.h:1511
#define instruction_forloop(x)
Definition: ri.h:1538
#define statement_instruction(x)
Definition: ri.h:2458

References instruction_forloop, instruction_tag, is_instruction_forloop, is_instruction_unstructured, make_instruction(), make_unstructured_from_forloop(), module_name(), pips_assert, pips_debug, and statement_instruction.

Referenced by full_spaghettify_statement(), and spaghettify_statement().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ spaghettify_loop()

statement spaghettify_loop ( statement  stat,
const char *  module_name 
)

This function takes the statement stat as parameter and return a new spaghettized statement, asserting stat is a LOOP statement.

loop_spaghettify.c

Parameters
stattat
module_nameodule_name

Definition at line 391 of file loop_spaghettify.c.

392 {
393  statement returned_statement = stat;
394  instruction unstructured_instruction;
395  unstructured new_unstructured;
396 
397  pips_assert("Statement is LOOP in FSM_GENERATION",
400 
401  pips_debug(2, "spaghettify_loop, module %s\n", module_name);
402  new_unstructured = make_unstructured_from_loop (statement_loop(stat),
403  stat,
404  module_name);
405 
406  unstructured_instruction = make_instruction(is_instruction_unstructured,
407  new_unstructured);
408 
409  statement_instruction(returned_statement) = unstructured_instruction;
410 
411  return returned_statement;
412 }
loop statement_loop(statement)
Get the loop of a statement.
Definition: statement.c:1374
static unstructured make_unstructured_from_loop(loop the_loop, statement stat, const char *module_name)
Build and return a new unstructured coding the "destructured" loop.
@ is_instruction_loop
Definition: ri.h:1471

References instruction_tag, is_instruction_loop, is_instruction_unstructured, make_instruction(), make_unstructured_from_loop(), module_name(), pips_assert, pips_debug, statement_instruction, and statement_loop().

Referenced by full_spaghettify_statement(), and spaghettify_statement().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ spaghettify_statement()

statement spaghettify_statement ( statement  stat,
const char *  module_name 
)

The spaghettifier is used in context of PHRASE project while creating "Finite State Machine"-like code portions in order to synthetise them in reconfigurables units.

spaghettify.c

This phase transforms structured code portions (eg. loops) in unstructured statements.

To add flexibility, the behavior of \texttt{spaghettifier} is controlled by the properties

  • DESTRUCTURE_TESTS
  • DESTRUCTURE_LOOPS
  • DESTRUCTURE_WHILELOOPS
  • DESTRUCTURE_FORLOOPS to allow more or less destruction power !

spaghettify > MODULE.code < PROGRAM.entities < MODULE.code This function is recursively called during spaghettization. It takes the statement stat as parameter and return a new spaghettized statement (or the same if nothing has been done). Spaguettization is done:

  • on Tests (if property DESTRUCTURE_TESTS set to true)
  • on Loops (if property DESTRUCTURE_LOOPS set to true)
  • on WhileLoops (if property DESTRUCTURE_WHILELOOPS set to true)
  • on ForLoops (if property DESTRUCTURE_FORLOOPS set to true)
Parameters
stattat
module_nameodule_name

Definition at line 85 of file spaghettify.c.

86 {
87  // Defaut behaviour is to return parameter statement stat
88  statement returned_statement = stat;
90 
91  pips_debug(2,"\nSPAGHETTIFY: Module statement: =====================================\n");
92  ifdebug(2) {
93  print_statement(stat);
94  }
95  pips_debug(2,"domain number = %"PRIdPTR"\n", statement_domain_number(stat));
96  pips_debug(2,"entity = UNDEFINED\n");
97  pips_debug(2,"statement number = %"PRIdPTR"\n", statement_number(stat));
98  pips_debug(2,"statement ordering = %"PRIdPTR"\n", statement_ordering(stat));
100  pips_debug(2,"statement comments = EMPTY\n");
101  }
102  else {
103  pips_debug(2,"statement comments = %s\n", statement_comments(stat));
104  }
105  pips_debug(2,"statement instruction = %s\n", statement_type_as_string(stat));
106  switch (instruction_tag(i)) {
107  case is_instruction_test:
108  {
109  pips_debug(2, "TEST\n");
110  if (get_bool_property("DESTRUCTURE_TESTS")) {
111  returned_statement = spaghettify_test (stat, module_name);
112  }
113  break;
114  }
116  {
118  pips_debug(2, "SEQUENCE\n");
119  MAP(STATEMENT, current_stat,
120  {
121  statement new_stat = spaghettify_statement(current_stat, module_name);
122  if (new_stat != NULL) {
123  gen_list_patch (sequence_statements(seq), current_stat, new_stat);
124  }
125  }, sequence_statements(seq));
126  break;
127  }
128  case is_instruction_loop: {
129  pips_debug(2, "LOOP\n");
130  if (get_bool_property("DESTRUCTURE_LOOPS")) {
131  returned_statement = spaghettify_loop (stat, module_name);
132  }
133  break;
134  }
136  pips_debug(2, "WHILELOOP\n");
137  if (get_bool_property("DESTRUCTURE_WHILELOOPS")) {
138  returned_statement = spaghettify_whileloop (stat, module_name);
139  }
140  break;
141  }
142  case is_instruction_forloop: {
143  pips_debug(2, "FORLOOP\n");
144  if (get_bool_property("DESTRUCTURE_FORLOOPS")) {
145  returned_statement = spaghettify_forloop (stat, module_name);
146  }
147  break;
148  }
149  case is_instruction_call: {
150  pips_debug(2, "CALL\n");
151  break;
152  }
154  pips_debug(2, "UNSTRUCTURED\n");
155  break;
156  }
157  case is_instruction_goto: {
158  pips_debug(2, "GOTO\n");
159  break;
160  }
161  default:
162  pips_debug(2, "UNDEFINED\n");
163  break;
164  }
165 
166  return returned_statement;
167 }
bool get_bool_property(const string)
FC 2015-07-20: yuk, moved out to prevent an include cycle dependency include "properties....
statement spaghettify_forloop(statement stat, const char *module_name)
This function takes the statement stat as parameter and return a new spaghettized statement,...
void gen_list_patch(list l, const void *x, const void *y)
Replace all the reference to x in list l by a reference to y:
Definition: list.c:985
#define MAP(_map_CASTER, _map_item, _map_code, _map_list)
Apply/map an instruction block on all the elements of a list (old fashioned)
Definition: newgen_list.h:226
bool statement_with_empty_comment_p(statement)
Return true if the statement has an empty statement:
Definition: statement.c:126
statement spaghettify_loop(statement stat, const char *module_name)
This function takes the statement stat as parameter and return a new spaghettized statement,...
statement spaghettify_test(statement, const char *)
test_spaghettify.c
string statement_type_as_string(statement)
phrase_tools.c
Definition: phrase_tools.c:65
statement spaghettify_whileloop(statement, const char *)
whileloop_spaghettify.c
void print_statement(statement)
Print a statement on stderr.
Definition: statement.c:98
#define statement_ordering(x)
Definition: ri.h:2454
@ is_instruction_goto
Definition: ri.h:1473
@ is_instruction_whileloop
Definition: ri.h:1472
@ is_instruction_test
Definition: ri.h:1470
@ is_instruction_call
Definition: ri.h:1474
@ is_instruction_sequence
Definition: ri.h:1469
#define statement_domain_number(x)
Definition: ri.h:2448
#define sequence_statements(x)
Definition: ri.h:2360
#define instruction_sequence(x)
Definition: ri.h:1514
#define statement_comments(x)
Definition: ri.h:2456
#define statement_number(x)
Definition: ri.h:2452
#define STATEMENT(x)
STATEMENT.
Definition: ri.h:2413
#define ifdebug(n)
Definition: sg.c:47
statement spaghettify_statement(statement stat, const char *module_name)
The spaghettifier is used in context of PHRASE project while creating "Finite State Machine"-like cod...
Definition: spaghettify.c:85

Referenced by spaghettify(), and spaghettify_statement().

+ Here is the caller graph for this function:

◆ spaghettify_test()

statement spaghettify_test ( statement  stat,
const char *  module_name 
)

test_spaghettify.c

Parameters
stattat
module_nameodule_name

Definition at line 142 of file test_spaghettify.c.

143 {
144  statement returned_statement = stat;
145  instruction unstructured_instruction;
146  unstructured new_unstructured;
147 
148  pips_assert("Statement is TEST in FSM_GENERATION",
151 
152  pips_debug(2, "spaghettify_test, module %s\n", module_name);
153 
154  new_unstructured
157  stat,
158  module_name);
159 
160  unstructured_instruction = make_instruction(is_instruction_unstructured,
161  new_unstructured);
162 
163  statement_instruction(returned_statement) = unstructured_instruction;
164  return returned_statement;
165 }
#define instruction_test(x)
Definition: ri.h:1517
static unstructured make_unstructured_from_test(test the_test, statement stat, const char *module_name)
Build and return a new unstructured coding the "destructured" test.

◆ spaghettify_whileloop()

statement spaghettify_whileloop ( statement  stat,
const char *  module_name 
)

whileloop_spaghettify.c

Parameters
stattat
module_nameodule_name

Definition at line 142 of file whileloop_spaghettify.c.

143 {
144  statement returned_statement = stat;
145  instruction unstructured_instruction;
146  unstructured new_unstructured;
147 
148  pips_assert("Statement is WHILELOOP in FSM_GENERATION",
151 
152  pips_debug(2, "spaghettify_whileloop, module %s\n", module_name);
153  new_unstructured
156  stat,
157  module_name);
158 
159  unstructured_instruction = make_instruction(is_instruction_unstructured,
160  new_unstructured);
161 
162  statement_instruction(returned_statement) = unstructured_instruction;
163 
164  return returned_statement;
165 }
#define instruction_whileloop(x)
Definition: ri.h:1523
static unstructured make_unstructured_from_whileloop(whileloop the_whileloop, statement stat, const char *module_name)
Build and return a new unstructured coding the "destructured" whileloop.