PIPS
whileloop_spaghettify.c File Reference
#include <stdio.h>
#include <ctype.h>
#include "genC.h"
#include "linear.h"
#include "ri.h"
#include "effects.h"
#include "resources.h"
#include "misc.h"
#include "ri-util.h"
#include "effects-util.h"
#include "text-util.h"
#include "dg.h"
#include "phrase_tools.h"
#include "spaghettify.h"
+ Include dependency graph for whileloop_spaghettify.c:

Go to the source code of this file.

Functions

static control make_condition_from_whileloop (whileloop the_whileloop, statement stat)
 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...
 
static control make_exit_from_whileloop ()
 Build and return a new control containing exit statement of the unstructured whileloop (this is a continue statement) More...
 
static control make_body_from_whileloop (whileloop the_whileloop, const char *module_name)
 Build and return a new control containing body statement of the unstructured whileloop. More...
 
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. More...
 
statement spaghettify_whileloop (statement stat, const char *module_name)
 whileloop_spaghettify.c More...
 

Function Documentation

◆ make_body_from_whileloop()

static control make_body_from_whileloop ( whileloop  the_whileloop,
const char *  module_name 
)
static

Build and return a new control containing body statement of the unstructured whileloop.

Definition at line 110 of file whileloop_spaghettify.c.

112 {
113  return make_control
114  (spaghettify_statement(whileloop_body(the_whileloop),
115  module_name), NIL, NIL);
116 }
control make_control(statement a1, list a2, list a3)
Definition: ri.c:523
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
statement spaghettify_statement(statement, const char *)
spaghettify.c
Definition: spaghettify.c:85
#define whileloop_body(x)
Definition: ri.h:3162

References make_control(), module_name(), NIL, spaghettify_statement(), and whileloop_body.

Referenced by make_unstructured_from_whileloop().

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

◆ make_condition_from_whileloop()

static control make_condition_from_whileloop ( whileloop  the_whileloop,
statement  stat 
)
static

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.

This file contains the code used for spaghettify whileloops.

General syntax of whileloop in Fortran are:

DO WHILE CONDITION STATEMENT END DO

Following code is generated:

10 IF (CONDITION) THEN STATEMENT GOTO 10 20 CONTINUE Build and return a new control containing condition statement of the unstructured whileloop

Definition at line 76 of file whileloop_spaghettify.c.

78 {
79  statement condition_statement;
80  test condition_test
81  = make_test (whileloop_condition(the_whileloop),
84 
85 
86  condition_statement = make_statement(entity_empty_label(),
87  statement_number(stat),
88  statement_ordering(stat),
91  condition_test),
92  NIL,NULL,
94  return make_control (condition_statement, NIL, NIL);
95 }
test make_test(expression a1, statement a2, statement a3)
Definition: ri.c:2607
statement make_statement(entity a1, intptr_t a2, intptr_t a3, string a4, instruction a5, list a6, string a7, extensions a8, synchronization a9)
Definition: ri.c:2222
instruction make_instruction(enum instruction_utype tag, void *val)
Definition: ri.c:1166
synchronization make_synchronization_none(void)
Definition: ri.c:2424
statement make_continue_statement(entity)
Definition: statement.c:953
#define empty_comments
Empty comments (i.e.
entity entity_empty_label(void)
Definition: entity.c:1105
#define statement_ordering(x)
Definition: ri.h:2454
@ is_instruction_test
Definition: ri.h:1470
#define statement_extensions(x)
Definition: ri.h:2464
#define whileloop_condition(x)
Definition: ri.h:3160
#define statement_number(x)
Definition: ri.h:2452

References empty_comments, entity_empty_label(), is_instruction_test, make_continue_statement(), make_control(), make_instruction(), make_statement(), make_synchronization_none(), make_test(), NIL, statement_extensions, statement_number, statement_ordering, and whileloop_condition.

Referenced by make_unstructured_from_whileloop().

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

◆ make_exit_from_whileloop()

static control make_exit_from_whileloop ( )
static

Build and return a new control containing exit statement of the unstructured whileloop (this is a continue statement)

Definition at line 101 of file whileloop_spaghettify.c.

102 {
104 }

References entity_empty_label(), make_continue_statement(), make_control(), and NIL.

Referenced by make_unstructured_from_whileloop().

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

◆ make_unstructured_from_whileloop()

static unstructured make_unstructured_from_whileloop ( whileloop  the_whileloop,
statement  stat,
const char *  module_name 
)
static

Build and return a new unstructured coding the "destructured" whileloop.

The first connexion is the false one

Definition at line 122 of file whileloop_spaghettify.c.

125 {
126  control condition = make_condition_from_whileloop (the_whileloop,stat);
128  control body = make_body_from_whileloop(the_whileloop,module_name);
129 
130  /* The first connexion is the false one */
131  //link_2_control_nodes (condition, exit); /* false condition, we exit from whileloop */
132  //link_2_control_nodes (condition, body); /* true condition, we go to body */
133  link_3_control_nodes (condition, body, exit);
134 
135  return make_unstructured (condition, exit);
136 }
unstructured make_unstructured(control a1, control a2)
Definition: ri.c:2778
void link_3_control_nodes(control c_test, control c_then, control c_else)
Add an edge between 2 control nodes.
Definition: control.c:1249
#define exit(code)
Definition: misc-local.h:54
static control make_exit_from_whileloop()
Build and return a new control containing exit statement of the unstructured whileloop (this is a con...
static control make_condition_from_whileloop(whileloop the_whileloop, statement stat)
The spaghettifier is used in context of PHRASE project while creating "Finite State Machine"-like cod...
static control make_body_from_whileloop(whileloop the_whileloop, const char *module_name)
Build and return a new control containing body statement of the unstructured whileloop.

References exit, link_3_control_nodes(), make_body_from_whileloop(), make_condition_from_whileloop(), make_exit_from_whileloop(), make_unstructured(), and module_name().

Referenced by spaghettify_whileloop().

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

◆ 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 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_whileloop
Definition: ri.h:1472
#define instruction_tag(x)
Definition: ri.h:1511
#define instruction_whileloop(x)
Definition: ri.h:1523
#define statement_instruction(x)
Definition: ri.h:2458
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.

References instruction_tag, instruction_whileloop, is_instruction_unstructured, is_instruction_whileloop, make_instruction(), make_unstructured_from_whileloop(), 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: