PIPS
test_spaghettify.c
Go to the documentation of this file.
1 /*
2 
3  $Id: test_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 creating
29  * "Finite State Machine"-like code portions in order to synthetise them
30  * in reconfigurables units.
31  *
32  * This file contains the code used for spaghettify tests.
33  */
34 
35 #include <stdio.h>
36 #include <ctype.h>
37 
38 #include "genC.h"
39 #include "linear.h"
40 #include "ri.h"
41 #include "effects.h"
42 
43 #include "resources.h"
44 
45 #include "misc.h"
46 #include "ri-util.h"
47 #include "effects-util.h"
48 
49 #include "text-util.h"
50 
51 #include "dg.h"
52 
53 
54 #include "phrase_tools.h"
55 #include "spaghettify.h"
56 
57 
58 /**
59  * Build and return a new control containing condition statement
60  * of the "destructured" test
61  */
63  statement stat)
64 {
65  statement condition_statement;
66  test condition_test
67  = make_test (test_condition(the_test),
70 
71 
72  condition_statement = make_statement(entity_empty_label(),
73  statement_number(stat),
74  statement_ordering(stat),
77  condition_test),
78  NIL,NULL,
80  return make_control (condition_statement, NIL, NIL);
81 }
82 
83 /**
84  * Build and return a new control containing "if true" statement
85  * of the "destructured" test
86  */
88  const char* module_name)
89 {
91  module_name),
92  NIL, NIL);
93 }
94 
95 /**
96  * Build and return a new control containing "if false" statement
97  * of the "destructured" test
98  */
100  const char* module_name)
101 {
103  module_name),
104  NIL, NIL);
105 }
106 
107 /**
108  * Build and return a new control containing exit statement
109  * of the "destructured" test (this is a continue statement)
110  */
112 {
114 }
115 /**
116  * Build and return a new unstructured coding the
117  * "destructured" test
118  */
120  statement stat,
121  const char* module_name)
122 {
123  control condition = make_condition_from_test (the_test,stat);
125  control if_true = make_if_true_from_test (the_test,module_name);
126  control if_false = make_if_false_from_test (the_test,module_name);
127 
128  /* The first connexion is the false one */
129  //link_2_control_nodes (condition, if_false);
130  //link_2_control_nodes (condition, if_true);
131  link_3_control_nodes (condition, if_true, if_false);
132  link_2_control_nodes (if_true, exit);
133  link_2_control_nodes (if_false, 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 TEST statement
141  */
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 }
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
void link_2_control_nodes(control source, control target)
Add an edge between 2 control nodes.
Definition: control.c:1193
#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
#define test_false(x)
Definition: ri.h:2837
@ is_instruction_unstructured
Definition: ri.h:1475
@ is_instruction_test
Definition: ri.h:1470
#define instruction_tag(x)
Definition: ri.h:1511
#define test_true(x)
Definition: ri.h:2835
#define statement_extensions(x)
Definition: ri.h:2464
#define test_condition(x)
Definition: ri.h:2833
#define statement_instruction(x)
Definition: ri.h:2458
#define instruction_test(x)
Definition: ri.h:1517
#define statement_number(x)
Definition: ri.h:2452
static control make_exit_from_test()
Build and return a new control containing exit statement of the "destructured" test (this is a contin...
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.
statement spaghettify_test(statement stat, const char *module_name)
test_spaghettify.c
static control make_if_true_from_test(test the_test, const char *module_name)
Build and return a new control containing "if true" statement of the "destructured" test.
static control make_condition_from_test(test the_test, statement stat)
The spaghettifier is used in context of PHRASE project while creating "Finite State Machine"-like cod...
static control make_if_false_from_test(test the_test, const char *module_name)
Build and return a new control containing "if false" statement of the "destructured" test.