author | laurent |
Sun, 29 Nov 2009 16:38:11 +0100 | |
changeset 217 | f5dfadf5de54 |
parent 155 | e094c92cf197 |
child 221 | c6aed7e5f070 |
permissions | -rw-r--r-- |
70 | 1 |
/* |
2 |
* (c) 2007 Mario de Sousa, Laurent Bessard |
|
3 |
* |
|
4 |
* Offered to the public under the terms of the GNU General Public License |
|
5 |
* as published by the Free Software Foundation; either version 2 of the |
|
6 |
* License, or (at your option) any later version. |
|
7 |
* |
|
8 |
* This program is distributed in the hope that it will be useful, but |
|
9 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
|
11 |
* Public License for more details. |
|
12 |
* |
|
13 |
* This code is made available on the understanding that it will not be |
|
14 |
* used in safety-critical situations without a full and competent review. |
|
15 |
*/ |
|
16 |
||
17 |
/* |
|
18 |
* An IEC 61131-3 IL and ST compiler. |
|
19 |
* |
|
20 |
* Based on the |
|
21 |
* FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
25 |
||
26 |
/* |
|
27 |
* Conversion of sfc networks (i.e. SFC code). |
|
28 |
* |
|
29 |
* This is part of the 4th stage that generates |
|
30 |
* a c++ source program equivalent to the SFC, IL and ST |
|
31 |
* code. |
|
32 |
*/ |
|
33 |
||
34 |
typedef struct |
|
35 |
{ |
|
36 |
transition_c *symbol; |
|
37 |
int priority; |
|
38 |
int index; |
|
39 |
} TRANSITION; |
|
40 |
||
41 |
||
42 |
||
43 |
||
44 |
||
45 |
/***********************************************************************/ |
|
46 |
/***********************************************************************/ |
|
47 |
/***********************************************************************/ |
|
48 |
/***********************************************************************/ |
|
49 |
||
50 |
class generate_c_sfc_elements_c: public generate_c_base_c { |
|
51 |
||
52 |
public: |
|
53 |
typedef enum { |
|
54 |
transitionlist_sg, |
|
55 |
transitiontest_sg, |
|
141 | 56 |
transitiontestdebug_sg, |
70 | 57 |
stepset_sg, |
58 |
stepreset_sg, |
|
59 |
actionassociation_sg, |
|
60 |
actionbody_sg |
|
61 |
} sfcgeneration_t; |
|
62 |
||
63 |
private: |
|
64 |
generate_c_il_c *generate_c_il; |
|
65 |
generate_c_st_c *generate_c_st; |
|
66 |
generate_c_SFC_IL_ST_c *generate_c_code; |
|
67 |
search_var_instance_decl_c *search_var_instance_decl; |
|
68 |
||
69 |
int transition_number; |
|
70 |
std::list<TRANSITION> transition_list; |
|
71 |
||
72 |
symbol_c *current_step; |
|
73 |
symbol_c *current_action; |
|
74 |
||
75 |
sfcgeneration_t wanted_sfcgeneration; |
|
76 |
||
77 |
public: |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
78 |
generate_c_sfc_elements_c(stage4out_c *s4o_ptr, symbol_c *name, symbol_c *scope, const char *variable_prefix = NULL) |
70 | 79 |
: generate_c_base_c(s4o_ptr) { |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
80 |
generate_c_il = new generate_c_il_c(s4o_ptr, name, scope, variable_prefix); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
81 |
generate_c_st = new generate_c_st_c(s4o_ptr, name, scope, variable_prefix); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
82 |
generate_c_code = new generate_c_SFC_IL_ST_c(s4o_ptr, name, scope, variable_prefix); |
70 | 83 |
search_var_instance_decl = new search_var_instance_decl_c(scope); |
84 |
this->set_variable_prefix(variable_prefix); |
|
85 |
} |
|
86 |
||
87 |
~generate_c_sfc_elements_c(void) { |
|
149 | 88 |
transition_list.clear(); |
70 | 89 |
delete generate_c_il; |
90 |
delete generate_c_st; |
|
91 |
delete generate_c_code; |
|
92 |
delete search_var_instance_decl; |
|
93 |
} |
|
94 |
||
95 |
void reset_transition_number(void) {transition_number = 0;} |
|
96 |
||
97 |
void generate(symbol_c *symbol, sfcgeneration_t generation_type) { |
|
98 |
wanted_sfcgeneration = generation_type; |
|
99 |
switch (wanted_sfcgeneration) { |
|
100 |
case transitiontest_sg: |
|
101 |
{ |
|
102 |
std::list<TRANSITION>::iterator pt; |
|
103 |
for(pt = transition_list.begin(); pt != transition_list.end(); pt++) { |
|
104 |
transition_number = pt->index; |
|
105 |
pt->symbol->accept(*this); |
|
106 |
} |
|
107 |
} |
|
108 |
break; |
|
109 |
default: |
|
110 |
symbol->accept(*this); |
|
111 |
break; |
|
112 |
} |
|
113 |
} |
|
114 |
||
115 |
void print_step_argument(symbol_c *step_name, const char* argument) { |
|
116 |
print_variable_prefix(); |
|
141 | 117 |
s4o.print("__step_list["); |
70 | 118 |
s4o.print(SFC_STEP_ACTION_PREFIX); |
119 |
step_name->accept(*this); |
|
120 |
s4o.print("]."); |
|
121 |
s4o.print(argument); |
|
122 |
} |
|
123 |
||
124 |
void print_action_argument(symbol_c *action_name, const char* argument) { |
|
125 |
print_variable_prefix(); |
|
141 | 126 |
s4o.print("__action_list["); |
70 | 127 |
s4o.print(SFC_STEP_ACTION_PREFIX); |
128 |
action_name->accept(*this); |
|
129 |
s4o.print("]."); |
|
130 |
s4o.print(argument); |
|
131 |
} |
|
132 |
||
133 |
void print_transition_number(void) { |
|
134 |
char str[10]; |
|
135 |
sprintf(str, "%d", transition_number); |
|
136 |
s4o.print(str); |
|
137 |
} |
|
138 |
||
139 |
void print_reset_step(symbol_c *step_name) { |
|
140 |
s4o.print(s4o.indent_spaces); |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
141 |
s4o.print(SET_VAR); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
142 |
s4o.print("("); |
70 | 143 |
print_step_argument(step_name, "state"); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
144 |
s4o.print(",0);\n"); |
70 | 145 |
} |
146 |
||
147 |
void print_set_step(symbol_c *step_name) { |
|
148 |
s4o.print(s4o.indent_spaces); |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
149 |
s4o.print(SET_VAR); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
150 |
s4o.print("("); |
70 | 151 |
print_step_argument(step_name, "state"); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
152 |
s4o.print(",1);\n" + s4o.indent_spaces); |
70 | 153 |
print_step_argument(step_name, "elapsed_time"); |
154 |
s4o.print(" = __time_to_timespec(1, 0, 0, 0, 0, 0);\n"); |
|
155 |
} |
|
156 |
||
157 |
bool is_variable(symbol_c *symbol) { |
|
158 |
/* we try to find the variable instance declaration, to determine its type... */ |
|
159 |
symbol_c *var_decl = search_var_instance_decl->get_decl(symbol); |
|
160 |
||
161 |
return var_decl != NULL; |
|
162 |
} |
|
163 |
||
164 |
/*********************************************/ |
|
165 |
/* B.1.6 Sequential function chart elements */ |
|
166 |
/*********************************************/ |
|
167 |
||
168 |
void *visit(initial_step_c *symbol) { |
|
169 |
switch (wanted_sfcgeneration) { |
|
170 |
case actionassociation_sg: |
|
171 |
if (((list_c*)symbol->action_association_list)->n > 0) { |
|
172 |
s4o.print(s4o.indent_spaces + "// "); |
|
173 |
symbol->step_name->accept(*this); |
|
174 |
s4o.print(" action associations\n"); |
|
175 |
current_step = symbol->step_name; |
|
176 |
s4o.print(s4o.indent_spaces + "{\n"); |
|
177 |
s4o.indent_right(); |
|
178 |
s4o.print(s4o.indent_spaces + "char activated = "); |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
179 |
s4o.print(GET_VAR); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
180 |
s4o.print("("); |
70 | 181 |
print_step_argument(current_step, "state"); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
182 |
s4o.print(") && !"); |
70 | 183 |
print_step_argument(current_step, "prev_state"); |
184 |
s4o.print(";\n"); |
|
185 |
s4o.print(s4o.indent_spaces + "char desactivated = !"); |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
186 |
s4o.print(GET_VAR); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
187 |
s4o.print("("); |
70 | 188 |
print_step_argument(current_step, "state"); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
189 |
s4o.print(") && "); |
70 | 190 |
print_step_argument(current_step, "prev_state"); |
191 |
s4o.print(";\n"); |
|
192 |
s4o.print(s4o.indent_spaces + "char active = "); |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
193 |
s4o.print(GET_VAR); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
194 |
s4o.print("("); |
70 | 195 |
print_step_argument(current_step, "state"); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
196 |
s4o.print(");\n"); |
70 | 197 |
symbol->action_association_list->accept(*this); |
198 |
s4o.indent_left(); |
|
199 |
s4o.print(s4o.indent_spaces + "}\n\n"); |
|
200 |
} |
|
201 |
break; |
|
202 |
default: |
|
203 |
break; |
|
204 |
} |
|
205 |
return NULL; |
|
206 |
} |
|
207 |
||
208 |
void *visit(step_c *symbol) { |
|
209 |
switch (wanted_sfcgeneration) { |
|
210 |
case actionassociation_sg: |
|
211 |
if (((list_c*)symbol->action_association_list)->n > 0) { |
|
212 |
s4o.print(s4o.indent_spaces + "// "); |
|
213 |
symbol->step_name->accept(*this); |
|
214 |
s4o.print(" action associations\n"); |
|
215 |
current_step = symbol->step_name; |
|
216 |
s4o.print(s4o.indent_spaces + "{\n"); |
|
217 |
s4o.indent_right(); |
|
218 |
s4o.print(s4o.indent_spaces + "char activated = "); |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
219 |
s4o.print(GET_VAR); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
220 |
s4o.print("("); |
70 | 221 |
print_step_argument(current_step, "state"); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
222 |
s4o.print(") && !"); |
70 | 223 |
print_step_argument(current_step, "prev_state"); |
224 |
s4o.print(";\n"); |
|
225 |
s4o.print(s4o.indent_spaces + "char desactivated = !"); |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
226 |
s4o.print(GET_VAR); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
227 |
s4o.print("("); |
70 | 228 |
print_step_argument(current_step, "state"); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
229 |
s4o.print(") && "); |
70 | 230 |
print_step_argument(current_step, "prev_state"); |
231 |
s4o.print(";\n"); |
|
232 |
s4o.print(s4o.indent_spaces + "char active = "); |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
233 |
s4o.print(GET_VAR); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
234 |
s4o.print("("); |
70 | 235 |
print_step_argument(current_step, "state"); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
236 |
s4o.print(");\n"); |
70 | 237 |
symbol->action_association_list->accept(*this); |
238 |
s4o.indent_left(); |
|
239 |
s4o.print(s4o.indent_spaces + "}\n\n"); |
|
240 |
} |
|
241 |
break; |
|
242 |
default: |
|
243 |
break; |
|
244 |
} |
|
245 |
return NULL; |
|
246 |
} |
|
247 |
||
248 |
void *visit(transition_c *symbol) { |
|
249 |
switch (wanted_sfcgeneration) { |
|
250 |
case transitionlist_sg: |
|
251 |
{ |
|
252 |
TRANSITION *transition; |
|
253 |
transition = new TRANSITION; |
|
254 |
transition->symbol = symbol; |
|
255 |
transition->index = transition_number; |
|
256 |
if (symbol->integer != NULL) { |
|
257 |
transition->priority = atoi(((token_c *)symbol->integer)->value); |
|
258 |
std::list<TRANSITION>::iterator pt = transition_list.begin(); |
|
259 |
while (pt != transition_list.end() && pt->priority <= transition->priority) { |
|
260 |
pt++; |
|
261 |
} |
|
262 |
transition_list.insert(pt, *transition); |
|
263 |
} |
|
264 |
else { |
|
265 |
transition->priority = 0; |
|
266 |
transition_list.push_back(*transition); |
|
267 |
} |
|
268 |
transition_number++; |
|
269 |
} |
|
270 |
break; |
|
271 |
case transitiontest_sg: |
|
272 |
s4o.print(s4o.indent_spaces + "if ("); |
|
273 |
symbol->from_steps->accept(*this); |
|
274 |
s4o.print(") {\n"); |
|
275 |
s4o.indent_right(); |
|
276 |
||
277 |
// Calculate transition value |
|
87 | 278 |
symbol->transition_condition->accept(*this); |
279 |
||
70 | 280 |
if (symbol->integer != NULL) { |
281 |
s4o.print(s4o.indent_spaces + "if ("); |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
282 |
s4o.print(GET_VAR); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
283 |
s4o.print("("); |
70 | 284 |
print_variable_prefix(); |
141 | 285 |
s4o.print("__transition_list["); |
70 | 286 |
print_transition_number(); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
287 |
s4o.print("])) {\n"); |
70 | 288 |
s4o.indent_right(); |
289 |
wanted_sfcgeneration = stepreset_sg; |
|
290 |
symbol->from_steps->accept(*this); |
|
291 |
wanted_sfcgeneration = transitiontest_sg; |
|
292 |
s4o.indent_left(); |
|
293 |
s4o.print(s4o.indent_spaces + "}\n"); |
|
294 |
} |
|
295 |
s4o.indent_left(); |
|
141 | 296 |
s4o.print(s4o.indent_spaces + "}\n"); |
297 |
s4o.print(s4o.indent_spaces + "else {\n"); |
|
70 | 298 |
s4o.indent_right(); |
141 | 299 |
// Calculate transition value for debug |
300 |
s4o.print(s4o.indent_spaces + "if (__DEBUG) {\n"); |
|
301 |
s4o.indent_right(); |
|
302 |
wanted_sfcgeneration = transitiontestdebug_sg; |
|
303 |
symbol->transition_condition->accept(*this); |
|
304 |
wanted_sfcgeneration = transitiontest_sg; |
|
305 |
s4o.indent_left(); |
|
306 |
s4o.print(s4o.indent_spaces + "}\n"); |
|
70 | 307 |
s4o.print(s4o.indent_spaces); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
308 |
s4o.print(SET_VAR); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
309 |
s4o.print("("); |
70 | 310 |
print_variable_prefix(); |
141 | 311 |
s4o.print("__transition_list["); |
70 | 312 |
print_transition_number(); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
313 |
s4o.print("],0);\n"); |
70 | 314 |
s4o.indent_left(); |
315 |
s4o.print(s4o.indent_spaces + "}\n"); |
|
316 |
break; |
|
317 |
case stepset_sg: |
|
318 |
s4o.print(s4o.indent_spaces + "if ("); |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
319 |
s4o.print(GET_VAR); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
320 |
s4o.print("("); |
70 | 321 |
print_variable_prefix(); |
141 | 322 |
s4o.print("__transition_list["); |
70 | 323 |
print_transition_number(); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
324 |
s4o.print("])) {\n"); |
70 | 325 |
s4o.indent_right(); |
326 |
symbol->to_steps->accept(*this); |
|
327 |
s4o.indent_left(); |
|
328 |
s4o.print(s4o.indent_spaces + "}\n"); |
|
329 |
transition_number++; |
|
330 |
break; |
|
331 |
case stepreset_sg: |
|
332 |
if (symbol->integer == NULL) { |
|
333 |
s4o.print(s4o.indent_spaces + "if ("); |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
334 |
s4o.print(GET_VAR); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
335 |
s4o.print("("); |
70 | 336 |
print_variable_prefix(); |
141 | 337 |
s4o.print("__transition_list["); |
70 | 338 |
print_transition_number(); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
339 |
s4o.print("])) {\n"); |
70 | 340 |
s4o.indent_right(); |
341 |
symbol->from_steps->accept(*this); |
|
342 |
s4o.indent_left(); |
|
343 |
s4o.print(s4o.indent_spaces + "}\n"); |
|
344 |
} |
|
345 |
transition_number++; |
|
346 |
break; |
|
347 |
default: |
|
348 |
break; |
|
349 |
} |
|
350 |
return NULL; |
|
351 |
} |
|
352 |
||
87 | 353 |
void *visit(transition_condition_c *symbol) { |
354 |
switch (wanted_sfcgeneration) { |
|
355 |
case transitiontest_sg: |
|
141 | 356 |
case transitiontestdebug_sg: |
87 | 357 |
// Transition condition is in IL |
358 |
if (symbol->transition_condition_il != NULL) { |
|
359 |
generate_c_il->declare_backup_variable(); |
|
360 |
s4o.print(s4o.indent_spaces); |
|
361 |
symbol->transition_condition_il->accept(*generate_c_il); |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
362 |
s4o.print(SET_VAR); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
363 |
s4o.print("("); |
87 | 364 |
print_variable_prefix(); |
141 | 365 |
if (wanted_sfcgeneration == transitiontestdebug_sg) |
366 |
s4o.print("__debug_"); |
|
367 |
else |
|
368 |
s4o.print("__"); |
|
87 | 369 |
s4o.print("transition_list["); |
370 |
print_transition_number(); |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
371 |
s4o.print("],"); |
87 | 372 |
generate_c_il->print_backup_variable(); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
373 |
s4o.print(");\n"); |
87 | 374 |
} |
375 |
// Transition condition is in ST |
|
376 |
if (symbol->transition_condition_st != NULL) { |
|
377 |
s4o.print(s4o.indent_spaces); |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
378 |
s4o.print(SET_VAR); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
379 |
s4o.print("("); |
87 | 380 |
print_variable_prefix(); |
141 | 381 |
if (wanted_sfcgeneration == transitiontestdebug_sg) |
382 |
s4o.print("__debug_"); |
|
383 |
else |
|
384 |
s4o.print("__"); |
|
87 | 385 |
s4o.print("transition_list["); |
386 |
print_transition_number(); |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
387 |
s4o.print("],"); |
87 | 388 |
symbol->transition_condition_st->accept(*generate_c_st); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
389 |
s4o.print(");\n"); |
87 | 390 |
} |
141 | 391 |
if (wanted_sfcgeneration == transitiontest_sg) { |
392 |
s4o.print(s4o.indent_spaces + "if (__DEBUG) {\n"); |
|
393 |
s4o.indent_right(); |
|
394 |
s4o.print(s4o.indent_spaces); |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
395 |
s4o.print(SET_VAR); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
396 |
s4o.print("("); |
141 | 397 |
print_variable_prefix(); |
398 |
s4o.print("__debug_transition_list["); |
|
399 |
print_transition_number(); |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
400 |
s4o.print("],"); |
141 | 401 |
print_variable_prefix(); |
402 |
s4o.print("__transition_list["); |
|
403 |
print_transition_number(); |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
404 |
s4o.print("]);\n"); |
141 | 405 |
s4o.indent_left(); |
406 |
s4o.print(s4o.indent_spaces + "}\n"); |
|
407 |
} |
|
87 | 408 |
break; |
409 |
default: |
|
410 |
break; |
|
411 |
} |
|
412 |
return NULL; |
|
413 |
} |
|
414 |
||
70 | 415 |
void *visit(action_c *symbol) { |
416 |
switch (wanted_sfcgeneration) { |
|
417 |
case actionbody_sg: |
|
418 |
s4o.print(s4o.indent_spaces + "if("); |
|
419 |
print_variable_prefix(); |
|
141 | 420 |
s4o.print("__action_list["); |
70 | 421 |
s4o.print(SFC_STEP_ACTION_PREFIX); |
422 |
symbol->action_name->accept(*this); |
|
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
423 |
s4o.print("].state) {\n"); |
70 | 424 |
s4o.indent_right(); |
425 |
||
426 |
// generate action code |
|
427 |
symbol->function_block_body->accept(*generate_c_code); |
|
428 |
||
429 |
s4o.indent_left(); |
|
430 |
s4o.print(s4o.indent_spaces + "}\n\n"); |
|
431 |
break; |
|
432 |
default: |
|
433 |
break; |
|
434 |
} |
|
435 |
return NULL; |
|
436 |
} |
|
437 |
||
438 |
void *visit(steps_c *symbol) { |
|
439 |
if (symbol->step_name != NULL) { |
|
440 |
switch (wanted_sfcgeneration) { |
|
441 |
case transitiontest_sg: |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
442 |
s4o.print(GET_VAR); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
443 |
s4o.print("("); |
70 | 444 |
print_step_argument(symbol->step_name, "state"); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
445 |
s4o.print(")"); |
70 | 446 |
break; |
447 |
case stepset_sg: |
|
448 |
print_set_step(symbol->step_name); |
|
449 |
break; |
|
450 |
case stepreset_sg: |
|
451 |
print_reset_step(symbol->step_name); |
|
452 |
break; |
|
453 |
default: |
|
454 |
break; |
|
455 |
} |
|
456 |
} |
|
457 |
else if (symbol->step_name_list != NULL) { |
|
458 |
symbol->step_name_list->accept(*this); |
|
459 |
} |
|
460 |
return NULL; |
|
461 |
} |
|
462 |
||
463 |
void *visit(step_name_list_c *symbol) { |
|
464 |
switch (wanted_sfcgeneration) { |
|
465 |
case transitiontest_sg: |
|
466 |
for(int i = 0; i < symbol->n; i++) { |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
467 |
s4o.print(GET_VAR); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
468 |
s4o.print("("); |
70 | 469 |
print_step_argument(symbol->elements[i], "state"); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
470 |
s4o.print(")"); |
70 | 471 |
if (i < symbol->n - 1) { |
472 |
s4o.print(" && "); |
|
473 |
} |
|
474 |
} |
|
475 |
break; |
|
476 |
case stepset_sg: |
|
477 |
for(int i = 0; i < symbol->n; i++) { |
|
478 |
print_set_step(symbol->elements[i]); |
|
479 |
} |
|
480 |
break; |
|
481 |
case stepreset_sg: |
|
482 |
for(int i = 0; i < symbol->n; i++) { |
|
483 |
print_reset_step(symbol->elements[i]); |
|
484 |
} |
|
485 |
break; |
|
486 |
default: |
|
487 |
break; |
|
488 |
} |
|
489 |
return NULL; |
|
490 |
} |
|
491 |
||
492 |
void *visit(action_association_list_c* symbol) { |
|
493 |
switch (wanted_sfcgeneration) { |
|
494 |
case actionassociation_sg: |
|
495 |
print_list(symbol, "", "\n", "\n"); |
|
496 |
break; |
|
497 |
default: |
|
498 |
break; |
|
499 |
} |
|
500 |
return NULL; |
|
501 |
} |
|
502 |
||
503 |
void *visit(action_association_c *symbol) { |
|
504 |
switch (wanted_sfcgeneration) { |
|
505 |
case actionassociation_sg: |
|
506 |
if (symbol->action_qualifier != NULL) { |
|
507 |
current_action = symbol->action_name; |
|
508 |
symbol->action_qualifier->accept(*this); |
|
509 |
} |
|
510 |
else { |
|
511 |
s4o.print(s4o.indent_spaces + "if ("); |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
512 |
s4o.print(GET_VAR); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
513 |
s4o.print("("); |
70 | 514 |
print_step_argument(current_step, "state"); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
515 |
s4o.print(")) {\n"); |
70 | 516 |
s4o.indent_right(); |
517 |
s4o.print(s4o.indent_spaces); |
|
518 |
print_action_argument(symbol->action_name, "state"); |
|
519 |
s4o.print(" = 1;\n"); |
|
520 |
s4o.indent_left(); |
|
521 |
s4o.print(s4o.indent_spaces + "}"); |
|
522 |
} |
|
523 |
break; |
|
524 |
default: |
|
525 |
break; |
|
526 |
} |
|
527 |
return NULL; |
|
528 |
} |
|
529 |
||
530 |
void *visit(action_qualifier_c *symbol) { |
|
531 |
switch (wanted_sfcgeneration) { |
|
532 |
case actionassociation_sg: |
|
533 |
{ |
|
534 |
char *qualifier = (char *)symbol->action_qualifier->accept(*this); |
|
535 |
s4o.print(s4o.indent_spaces + "if ("); |
|
155 | 536 |
if (strcmp(qualifier, "N") == 0 || strcmp(qualifier, "S") == 0 || |
537 |
strcmp(qualifier, "R") == 0) { |
|
70 | 538 |
s4o.print("active"); |
539 |
} |
|
540 |
if (strcmp(qualifier, "P") == 0 || strcmp(qualifier, "SD") == 0 || |
|
155 | 541 |
strcmp(qualifier, "DS") == 0 || strcmp(qualifier, "SL") == 0) { |
70 | 542 |
s4o.print("activated"); |
543 |
} |
|
544 |
if (strcmp(qualifier, "D") == 0 || strcmp(qualifier, "L") == 0) { |
|
120
74640e3c7f53
Bug with D and L action qualifier and timing management in SFC generated fixed
lbessard
parents:
119
diff
changeset
|
545 |
s4o.print("active && __TIME_CMP("); |
70 | 546 |
print_step_argument(current_step, "elapsed_time"); |
120
74640e3c7f53
Bug with D and L action qualifier and timing management in SFC generated fixed
lbessard
parents:
119
diff
changeset
|
547 |
s4o.print(", "); |
74640e3c7f53
Bug with D and L action qualifier and timing management in SFC generated fixed
lbessard
parents:
119
diff
changeset
|
548 |
symbol->action_time->accept(*this); |
70 | 549 |
if (strcmp(qualifier, "D") == 0) { |
120
74640e3c7f53
Bug with D and L action qualifier and timing management in SFC generated fixed
lbessard
parents:
119
diff
changeset
|
550 |
s4o.print(") >= 0"); |
70 | 551 |
} |
552 |
else { |
|
120
74640e3c7f53
Bug with D and L action qualifier and timing management in SFC generated fixed
lbessard
parents:
119
diff
changeset
|
553 |
s4o.print(") < 0"); |
70 | 554 |
} |
555 |
} |
|
556 |
s4o.print(") {\n"); |
|
557 |
s4o.indent_right(); |
|
558 |
s4o.print(s4o.indent_spaces); |
|
559 |
if (strcmp(qualifier, "N") == 0 || strcmp(qualifier, "P") == 0 || |
|
560 |
strcmp(qualifier, "D") == 0 || strcmp(qualifier, "L") == 0) { |
|
561 |
print_action_argument(current_action, "state"); |
|
562 |
s4o.print(" = 1;\n"); |
|
563 |
} |
|
564 |
if (strcmp(qualifier, "S") == 0) { |
|
565 |
if (is_variable(current_action)) { |
|
566 |
print_variable_prefix(); |
|
567 |
current_action->accept(*this); |
|
568 |
} |
|
569 |
else |
|
570 |
print_action_argument(current_action, "set"); |
|
571 |
s4o.print(" = 1;\n"); |
|
572 |
} |
|
573 |
if (strcmp(qualifier, "R") == 0) { |
|
574 |
if (is_variable(current_action)) { |
|
575 |
print_variable_prefix(); |
|
576 |
current_action->accept(*this); |
|
577 |
s4o.print(" = 0;\n"); |
|
578 |
} |
|
579 |
else { |
|
580 |
print_action_argument(current_action, "reset"); |
|
581 |
s4o.print(" = 1;\n"); |
|
582 |
} |
|
583 |
} |
|
584 |
if (strcmp(qualifier, "SD") == 0 || strcmp(qualifier, "DS") == 0 || |
|
585 |
strcmp(qualifier, "SL") == 0) { |
|
586 |
if (strcmp(qualifier, "SL") == 0) { |
|
587 |
print_action_argument(current_action, "reset_remaining_time"); |
|
588 |
} |
|
589 |
else { |
|
590 |
print_action_argument(current_action, "set_remaining_time"); |
|
591 |
} |
|
592 |
s4o.print(" = "); |
|
593 |
symbol->action_time->accept(*this); |
|
594 |
s4o.print(";\n"); |
|
595 |
} |
|
596 |
s4o.indent_left(); |
|
597 |
s4o.print(s4o.indent_spaces + "}"); |
|
598 |
if (strcmp(qualifier, "DS") == 0) { |
|
599 |
s4o.print("desactivated"); |
|
600 |
s4o.indent_right(); |
|
601 |
s4o.print(s4o.indent_spaces); |
|
602 |
print_action_argument(current_action, "set_remaining_time"); |
|
603 |
s4o.print(" = __time_to_timespec(1, 0, 0, 0, 0, 0);\n"); |
|
604 |
} |
|
605 |
} |
|
606 |
break; |
|
607 |
default: |
|
608 |
break; |
|
609 |
} |
|
610 |
return NULL; |
|
611 |
} |
|
612 |
||
613 |
void *visit(qualifier_c *symbol) { |
|
614 |
return (void *)symbol->value; |
|
615 |
} |
|
616 |
||
617 |
void *visit(timed_qualifier_c *symbol) { |
|
618 |
return (void *)symbol->value; |
|
619 |
} |
|
620 |
||
621 |
}; /* generate_c_sfc_actiondecl_c */ |
|
622 |
||
623 |
||
624 |
||
625 |
/***********************************************************************/ |
|
626 |
/***********************************************************************/ |
|
627 |
/***********************************************************************/ |
|
628 |
/***********************************************************************/ |
|
629 |
||
630 |
class generate_c_sfc_c: public generate_c_typedecl_c { |
|
631 |
||
632 |
private: |
|
633 |
generate_c_sfc_elements_c *generate_c_sfc_elements; |
|
634 |
||
635 |
public: |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
636 |
generate_c_sfc_c(stage4out_c *s4o_ptr, symbol_c *name, symbol_c *scope, const char *variable_prefix = NULL) |
70 | 637 |
: generate_c_typedecl_c(s4o_ptr) { |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
638 |
generate_c_sfc_elements = new generate_c_sfc_elements_c(s4o_ptr, name, scope, variable_prefix); |
70 | 639 |
this->set_variable_prefix(variable_prefix); |
640 |
} |
|
641 |
||
642 |
virtual ~generate_c_sfc_c(void) { |
|
643 |
delete generate_c_sfc_elements; |
|
644 |
} |
|
645 |
||
646 |
/*********************************************/ |
|
647 |
/* B.1.6 Sequential function chart elements */ |
|
648 |
/*********************************************/ |
|
119
4cbf71106b66
Bug with C code generation for SFC when more than one sfc_network in one sequential_function_chart fixed
lbessard
parents:
111
diff
changeset
|
649 |
|
4cbf71106b66
Bug with C code generation for SFC when more than one sfc_network in one sequential_function_chart fixed
lbessard
parents:
111
diff
changeset
|
650 |
void *visit(sequential_function_chart_c *symbol) { |
4cbf71106b66
Bug with C code generation for SFC when more than one sfc_network in one sequential_function_chart fixed
lbessard
parents:
111
diff
changeset
|
651 |
int i; |
4cbf71106b66
Bug with C code generation for SFC when more than one sfc_network in one sequential_function_chart fixed
lbessard
parents:
111
diff
changeset
|
652 |
|
4cbf71106b66
Bug with C code generation for SFC when more than one sfc_network in one sequential_function_chart fixed
lbessard
parents:
111
diff
changeset
|
653 |
generate_c_sfc_elements->reset_transition_number(); |
4cbf71106b66
Bug with C code generation for SFC when more than one sfc_network in one sequential_function_chart fixed
lbessard
parents:
111
diff
changeset
|
654 |
for(i = 0; i < symbol->n; i++) { |
4cbf71106b66
Bug with C code generation for SFC when more than one sfc_network in one sequential_function_chart fixed
lbessard
parents:
111
diff
changeset
|
655 |
generate_c_sfc_elements->generate(symbol->elements[i], generate_c_sfc_elements_c::transitionlist_sg); |
4cbf71106b66
Bug with C code generation for SFC when more than one sfc_network in one sequential_function_chart fixed
lbessard
parents:
111
diff
changeset
|
656 |
} |
4cbf71106b66
Bug with C code generation for SFC when more than one sfc_network in one sequential_function_chart fixed
lbessard
parents:
111
diff
changeset
|
657 |
|
4cbf71106b66
Bug with C code generation for SFC when more than one sfc_network in one sequential_function_chart fixed
lbessard
parents:
111
diff
changeset
|
658 |
s4o.print(s4o.indent_spaces +"INT i;\n"); |
125
7ec16536bc87
Modifying time qualifier in SFC to take real time enlapsed instead of theoric period time
lbessard
parents:
121
diff
changeset
|
659 |
s4o.print(s4o.indent_spaces +"BOOL transition;\n"); |
7ec16536bc87
Modifying time qualifier in SFC to take real time enlapsed instead of theoric period time
lbessard
parents:
121
diff
changeset
|
660 |
s4o.print(s4o.indent_spaces +"TIME elapsed_time, current_time;\n\n"); |
7ec16536bc87
Modifying time qualifier in SFC to take real time enlapsed instead of theoric period time
lbessard
parents:
121
diff
changeset
|
661 |
|
7ec16536bc87
Modifying time qualifier in SFC to take real time enlapsed instead of theoric period time
lbessard
parents:
121
diff
changeset
|
662 |
/* generate elapsed_time initialisations */ |
7ec16536bc87
Modifying time qualifier in SFC to take real time enlapsed instead of theoric period time
lbessard
parents:
121
diff
changeset
|
663 |
s4o.print(s4o.indent_spaces + "// Calculate elapsed_time\n"); |
7ec16536bc87
Modifying time qualifier in SFC to take real time enlapsed instead of theoric period time
lbessard
parents:
121
diff
changeset
|
664 |
s4o.print(s4o.indent_spaces +"current_time = __CURRENT_TIME;\n"); |
149 | 665 |
s4o.print(s4o.indent_spaces +"elapsed_time = __time_sub(__BOOL_LITERAL(TRUE), NULL, current_time, "); |
125
7ec16536bc87
Modifying time qualifier in SFC to take real time enlapsed instead of theoric period time
lbessard
parents:
121
diff
changeset
|
666 |
print_variable_prefix(); |
141 | 667 |
s4o.print("__lasttick_time);\n"); |
668 |
s4o.print(s4o.indent_spaces); |
|
669 |
print_variable_prefix(); |
|
670 |
s4o.print("__lasttick_time = current_time;\n"); |
|
119
4cbf71106b66
Bug with C code generation for SFC when more than one sfc_network in one sequential_function_chart fixed
lbessard
parents:
111
diff
changeset
|
671 |
|
4cbf71106b66
Bug with C code generation for SFC when more than one sfc_network in one sequential_function_chart fixed
lbessard
parents:
111
diff
changeset
|
672 |
/* generate step initialisations */ |
70 | 673 |
s4o.print(s4o.indent_spaces + "// Steps initialisation\n"); |
674 |
s4o.print(s4o.indent_spaces + "for (i = 0; i < "); |
|
675 |
print_variable_prefix(); |
|
141 | 676 |
s4o.print("__nb_steps; i++) {\n"); |
677 |
s4o.indent_right(); |
|
678 |
s4o.print(s4o.indent_spaces); |
|
679 |
print_variable_prefix(); |
|
680 |
s4o.print("__step_list[i].prev_state = "); |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
681 |
s4o.print(GET_VAR); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
682 |
s4o.print("("); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
683 |
print_variable_prefix(); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
684 |
s4o.print("__step_list[i].state);\n"); |
70 | 685 |
s4o.print(s4o.indent_spaces + "if ("); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
686 |
s4o.print(GET_VAR); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
687 |
s4o.print("("); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
688 |
print_variable_prefix(); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
155
diff
changeset
|
689 |
s4o.print("__step_list[i].state)) {\n"); |
141 | 690 |
s4o.indent_right(); |
691 |
s4o.print(s4o.indent_spaces); |
|
692 |
print_variable_prefix(); |
|
149 | 693 |
s4o.print("__step_list[i].elapsed_time = __time_add(__BOOL_LITERAL(TRUE), NULL, "); |
141 | 694 |
print_variable_prefix(); |
695 |
s4o.print("__step_list[i].elapsed_time, elapsed_time);\n"); |
|
70 | 696 |
s4o.indent_left(); |
697 |
s4o.print(s4o.indent_spaces + "}\n"); |
|
698 |
s4o.indent_left(); |
|
699 |
s4o.print(s4o.indent_spaces + "}\n"); |
|
700 |
||
701 |
/* generate action initilizations */ |
|
702 |
s4o.print(s4o.indent_spaces + "// Actions initialisation\n"); |
|
703 |
s4o.print(s4o.indent_spaces + "for (i = 0; i < "); |
|
704 |
print_variable_prefix(); |
|
141 | 705 |
s4o.print("__nb_actions; i++) {\n"); |
706 |
s4o.indent_right(); |
|
707 |
s4o.print(s4o.indent_spaces); |
|
708 |
print_variable_prefix(); |
|
709 |
s4o.print("__action_list[i].state = 0;\n"); |
|
710 |
s4o.print(s4o.indent_spaces); |
|
711 |
print_variable_prefix(); |
|
712 |
s4o.print("__action_list[i].set = 0;\n"); |
|
713 |
s4o.print(s4o.indent_spaces); |
|
714 |
print_variable_prefix(); |
|
715 |
s4o.print("__action_list[i].reset = 0;\n"); |
|
70 | 716 |
s4o.print(s4o.indent_spaces + "if ("); |
149 | 717 |
s4o.print("__TIME_CMP("); |
718 |
print_variable_prefix(); |
|
719 |
s4o.print("__action_list[i].set_remaining_time, __time_to_timespec(1, 0, 0, 0, 0, 0)) > 0) {\n"); |
|
720 |
s4o.indent_right(); |
|
721 |
s4o.print(s4o.indent_spaces); |
|
722 |
print_variable_prefix(); |
|
723 |
s4o.print("__action_list[i].set_remaining_time = __time_sub(__BOOL_LITERAL(TRUE), NULL, "); |
|
141 | 724 |
print_variable_prefix(); |
725 |
s4o.print("__action_list[i].set_remaining_time, elapsed_time);\n"); |
|
70 | 726 |
s4o.print(s4o.indent_spaces + "if ("); |
149 | 727 |
s4o.print("__TIME_CMP("); |
728 |
print_variable_prefix(); |
|
729 |
s4o.print("__action_list[i].set_remaining_time, __time_to_timespec(1, 0, 0, 0, 0, 0)) <= 0) {\n"); |
|
141 | 730 |
s4o.indent_right(); |
731 |
s4o.print(s4o.indent_spaces); |
|
732 |
print_variable_prefix(); |
|
733 |
s4o.print("__action_list[i].set_remaining_time = __time_to_timespec(1, 0, 0, 0, 0, 0);\n"); |
|
734 |
s4o.print(s4o.indent_spaces); |
|
735 |
print_variable_prefix(); |
|
736 |
s4o.print("__action_list[i].set = 1;\n"); |
|
70 | 737 |
s4o.indent_left(); |
738 |
s4o.print(s4o.indent_spaces + "}\n"); |
|
739 |
s4o.indent_left(); |
|
740 |
s4o.print(s4o.indent_spaces + "}\n"); |
|
741 |
s4o.print(s4o.indent_spaces + "if ("); |
|
149 | 742 |
s4o.print("__TIME_CMP("); |
743 |
print_variable_prefix(); |
|
744 |
s4o.print("__action_list[i].reset_remaining_time, __time_to_timespec(1, 0, 0, 0, 0, 0)) > 0) {\n"); |
|
745 |
s4o.indent_right(); |
|
746 |
s4o.print(s4o.indent_spaces); |
|
747 |
print_variable_prefix(); |
|
748 |
s4o.print("__action_list[i].reset_remaining_time = __time_sub(__BOOL_LITERAL(TRUE), NULL, "); |
|
141 | 749 |
print_variable_prefix(); |
750 |
s4o.print("__action_list[i].reset_remaining_time, elapsed_time);\n"); |
|
70 | 751 |
s4o.print(s4o.indent_spaces + "if ("); |
149 | 752 |
s4o.print("__TIME_CMP("); |
753 |
print_variable_prefix(); |
|
754 |
s4o.print("__action_list[i].reset_remaining_time, __time_to_timespec(1, 0, 0, 0, 0, 0)) <= 0) {\n"); |
|
141 | 755 |
s4o.indent_right(); |
756 |
s4o.print(s4o.indent_spaces); |
|
757 |
print_variable_prefix(); |
|
758 |
s4o.print("__action_list[i].reset_remaining_time = __time_to_timespec(1, 0, 0, 0, 0, 0);\n"); |
|
759 |
s4o.print(s4o.indent_spaces); |
|
760 |
print_variable_prefix(); |
|
761 |
s4o.print("__action_list[i].reset = 1;\n"); |
|
70 | 762 |
s4o.indent_left(); |
763 |
s4o.print(s4o.indent_spaces + "}\n"); |
|
764 |
s4o.indent_left(); |
|
765 |
s4o.print(s4o.indent_spaces + "}\n"); |
|
766 |
s4o.indent_left(); |
|
767 |
s4o.print(s4o.indent_spaces + "}\n\n"); |
|
768 |
||
769 |
/* generate transition tests */ |
|
770 |
s4o.print(s4o.indent_spaces + "// Transitions fire test\n"); |
|
119
4cbf71106b66
Bug with C code generation for SFC when more than one sfc_network in one sequential_function_chart fixed
lbessard
parents:
111
diff
changeset
|
771 |
generate_c_sfc_elements->generate((symbol_c *)symbol, generate_c_sfc_elements_c::transitiontest_sg); |
70 | 772 |
s4o.print("\n"); |
773 |
||
774 |
/* generate transition reset steps */ |
|
775 |
s4o.print(s4o.indent_spaces + "// Transitions reset steps\n"); |
|
776 |
generate_c_sfc_elements->reset_transition_number(); |
|
119
4cbf71106b66
Bug with C code generation for SFC when more than one sfc_network in one sequential_function_chart fixed
lbessard
parents:
111
diff
changeset
|
777 |
for(i = 0; i < symbol->n; i++) { |
4cbf71106b66
Bug with C code generation for SFC when more than one sfc_network in one sequential_function_chart fixed
lbessard
parents:
111
diff
changeset
|
778 |
generate_c_sfc_elements->generate(symbol->elements[i], generate_c_sfc_elements_c::stepreset_sg); |
4cbf71106b66
Bug with C code generation for SFC when more than one sfc_network in one sequential_function_chart fixed
lbessard
parents:
111
diff
changeset
|
779 |
} |
70 | 780 |
s4o.print("\n"); |
781 |
||
782 |
/* generate transition set steps */ |
|
783 |
s4o.print(s4o.indent_spaces + "// Transitions set steps\n"); |
|
784 |
generate_c_sfc_elements->reset_transition_number(); |
|
119
4cbf71106b66
Bug with C code generation for SFC when more than one sfc_network in one sequential_function_chart fixed
lbessard
parents:
111
diff
changeset
|
785 |
for(i = 0; i < symbol->n; i++) { |
4cbf71106b66
Bug with C code generation for SFC when more than one sfc_network in one sequential_function_chart fixed
lbessard
parents:
111
diff
changeset
|
786 |
generate_c_sfc_elements->generate(symbol->elements[i], generate_c_sfc_elements_c::stepset_sg); |
4cbf71106b66
Bug with C code generation for SFC when more than one sfc_network in one sequential_function_chart fixed
lbessard
parents:
111
diff
changeset
|
787 |
} |
70 | 788 |
s4o.print("\n"); |
789 |
||
119
4cbf71106b66
Bug with C code generation for SFC when more than one sfc_network in one sequential_function_chart fixed
lbessard
parents:
111
diff
changeset
|
790 |
/* generate step association */ |
70 | 791 |
s4o.print(s4o.indent_spaces + "// Steps association\n"); |
119
4cbf71106b66
Bug with C code generation for SFC when more than one sfc_network in one sequential_function_chart fixed
lbessard
parents:
111
diff
changeset
|
792 |
for(i = 0; i < symbol->n; i++) { |
4cbf71106b66
Bug with C code generation for SFC when more than one sfc_network in one sequential_function_chart fixed
lbessard
parents:
111
diff
changeset
|
793 |
generate_c_sfc_elements->generate(symbol->elements[i], generate_c_sfc_elements_c::actionassociation_sg); |
4cbf71106b66
Bug with C code generation for SFC when more than one sfc_network in one sequential_function_chart fixed
lbessard
parents:
111
diff
changeset
|
794 |
} |
70 | 795 |
s4o.print("\n"); |
796 |
||
797 |
/* generate action state evaluation */ |
|
798 |
s4o.print(s4o.indent_spaces + "// Actions state evaluation\n"); |
|
799 |
s4o.print(s4o.indent_spaces + "for (i = 0; i < "); |
|
800 |
print_variable_prefix(); |
|
141 | 801 |
s4o.print("__nb_actions; i++) {\n"); |
70 | 802 |
s4o.indent_right(); |
803 |
s4o.print(s4o.indent_spaces + "if ("); |
|
804 |
print_variable_prefix(); |
|
141 | 805 |
s4o.print("__action_list[i].set) {\n"); |
806 |
s4o.indent_right(); |
|
807 |
s4o.print(s4o.indent_spaces); |
|
808 |
print_variable_prefix(); |
|
809 |
s4o.print("__action_list[i].stored = 1;\n"); |
|
70 | 810 |
s4o.indent_left(); |
811 |
s4o.print(s4o.indent_spaces + "}\n" + s4o.indent_spaces + "if ("); |
|
812 |
print_variable_prefix(); |
|
141 | 813 |
s4o.print("__action_list[i].reset) {\n"); |
814 |
s4o.indent_right(); |
|
815 |
s4o.print(s4o.indent_spaces); |
|
816 |
print_variable_prefix(); |
|
817 |
s4o.print("__action_list[i].set_remaining_time = __time_to_timespec(1, 0, 0, 0, 0, 0);\n" + s4o.indent_spaces); |
|
818 |
print_variable_prefix(); |
|
819 |
s4o.print("__action_list[i].reset_remaining_time = __time_to_timespec(1, 0, 0, 0, 0, 0);\n" + s4o.indent_spaces); |
|
820 |
print_variable_prefix(); |
|
821 |
s4o.print("__action_list[i].stored = 0;\n"); |
|
70 | 822 |
s4o.indent_left(); |
823 |
s4o.print(s4o.indent_spaces + "}\n" + s4o.indent_spaces); |
|
824 |
print_variable_prefix(); |
|
141 | 825 |
s4o.print("__action_list[i].state |= "); |
826 |
print_variable_prefix(); |
|
827 |
s4o.print("__action_list[i].stored;\n"); |
|
70 | 828 |
s4o.indent_left(); |
829 |
s4o.print(s4o.indent_spaces + "}\n\n"); |
|
830 |
||
831 |
/* generate action execution */ |
|
832 |
s4o.print(s4o.indent_spaces + "// Actions execution\n"); |
|
119
4cbf71106b66
Bug with C code generation for SFC when more than one sfc_network in one sequential_function_chart fixed
lbessard
parents:
111
diff
changeset
|
833 |
for(i = 0; i < symbol->n; i++) { |
4cbf71106b66
Bug with C code generation for SFC when more than one sfc_network in one sequential_function_chart fixed
lbessard
parents:
111
diff
changeset
|
834 |
generate_c_sfc_elements->generate(symbol->elements[i], generate_c_sfc_elements_c::actionbody_sg); |
4cbf71106b66
Bug with C code generation for SFC when more than one sfc_network in one sequential_function_chart fixed
lbessard
parents:
111
diff
changeset
|
835 |
} |
70 | 836 |
s4o.print("\n"); |
837 |
||
838 |
return NULL; |
|
839 |
} |
|
119
4cbf71106b66
Bug with C code generation for SFC when more than one sfc_network in one sequential_function_chart fixed
lbessard
parents:
111
diff
changeset
|
840 |
|
70 | 841 |
void generate(sequential_function_chart_c *sfc) { |
842 |
sfc->accept(*this); |
|
843 |
} |
|
844 |
||
845 |
}; /* generate_c_sfc_c */ |