PIPS
whileloop_spaghettify.c
Go to the documentation of this file.
1 /*
2 
3  $Id: whileloop_spaghettify.c 23065 2016-03-02 09:05:50Z coelho $
4 
5  Copyright 1989-2016 MINES ParisTech
6 
7  This file is part of PIPS.
8 
9  PIPS is free software: you can redistribute it and/or modify it
10  under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  any later version.
13 
14  PIPS is distributed in the hope that it will be useful, but WITHOUT ANY
15  WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  FITNESS FOR A PARTICULAR PURPOSE.
17 
18  See the GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with PIPS. If not, see <http://www.gnu.org/licenses/>.
22 
23 */
24 #ifdef HAVE_CONFIG_H
25  #include "pips_config.h"
26 #endif
27 /**
28  * The spaghettifier is used in context of PHRASE project while
29  * creating "Finite State Machine"-like code portions in order to synthetise
30  * them in reconfigurables units.
31  *
32  * This file contains the code used for spaghettify whileloops.
33  *
34  * General syntax of whileloop in Fortran are:
35  *
36  * DO WHILE CONDITION
37  * STATEMENT
38  * END DO
39  *
40  * Following code is generated:
41  *
42  * 10 IF (CONDITION) THEN
43  * STATEMENT
44  * GOTO 10
45  * 20 CONTINUE
46  *
47  */
48 
49 #include <stdio.h>
50 #include <ctype.h>
51 
52 #include "genC.h"
53 #include "linear.h"
54 #include "ri.h"
55 #include "effects.h"
56 
57 #include "resources.h"
58 
59 #include "misc.h"
60 #include "ri-util.h"
61 #include "effects-util.h"
62 
63 #include "text-util.h"
64 
65 #include "dg.h"
66 
67 
68 #include "phrase_tools.h"
69 #include "spaghettify.h"
70 
71 
72 /**
73  * Build and return a new control containing condition statement
74  * of the unstructured whileloop
75  */
77  statement stat)
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 }
96 
97 /**
98  * Build and return a new control containing exit statement
99  * of the unstructured whileloop (this is a continue statement)
100  */
102 {
104 }
105 
106 /**
107  * Build and return a new control containing body statement
108  * of the unstructured whileloop
109  */
111  const char* module_name)
112 {
113  return make_control
114  (spaghettify_statement(whileloop_body(the_whileloop),
115  module_name), NIL, NIL);
116 }
117 
118 /**
119  * Build and return a new unstructured coding the
120  * "destructured" whileloop
121  */
123  statement stat,
124  const char* module_name)
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 }
137 
138 /*
139  * This function takes the statement stat as parameter and return a new
140  * spaghettized statement, asserting stat is a WHILELOOP statement
141  */
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 }
unstructured make_unstructured(control a1, control a2)
Definition: ri.c:2778
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
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
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 NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
statement make_continue_statement(entity)
Definition: statement.c:953
#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
#define exit(code)
Definition: misc-local.h:54
statement spaghettify_statement(statement, const char *)
spaghettify.c
Definition: spaghettify.c:85
#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_unstructured
Definition: ri.h:1475
@ is_instruction_whileloop
Definition: ri.h:1472
@ is_instruction_test
Definition: ri.h:1470
#define instruction_tag(x)
Definition: ri.h:1511
#define statement_extensions(x)
Definition: ri.h:2464
#define instruction_whileloop(x)
Definition: ri.h:1523
#define whileloop_body(x)
Definition: ri.h:3162
#define statement_instruction(x)
Definition: ri.h:2458
#define whileloop_condition(x)
Definition: ri.h:3160
#define statement_number(x)
Definition: ri.h:2452
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.
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.
statement spaghettify_whileloop(statement stat, const char *module_name)
whileloop_spaghettify.c