author | 'Gr?gory Tr?lat <gregory.trelat@lolitech.fr>' |
Fri, 10 Jul 2009 11:41:29 +0200 | |
changeset 198 | f68ef6f05e17 |
parent 189 | 7ca02034c4f6 |
child 202 | da1a8186f86f |
permissions | -rwxr-xr-x |
70 | 1 |
/* |
2 |
* (c) 2003 Mario de Sousa |
|
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 |
* This is one of the versions available for the 4th stage. |
|
28 |
* |
|
29 |
* This 4th stage generates a c++ source program equivalent |
|
30 |
* to the IL and ST code. |
|
31 |
*/ |
|
32 |
||
33 |
||
34 |
||
35 |
||
36 |
||
37 |
||
38 |
// #include <stdio.h> /* required for NULL */ |
|
39 |
#include <string> |
|
40 |
#include <iostream> |
|
41 |
#include <sstream> |
|
42 |
#include <typeinfo> |
|
111 | 43 |
#include <list> |
139
668a54686827
added missing includes on some platform (gentoo/gcc-4.3.1)
etisserant
parents:
138
diff
changeset
|
44 |
#include <strings.h> |
70 | 45 |
|
46 |
#include "../../util/symtable.hh" |
|
47 |
#include "../../util/dsymtable.hh" |
|
48 |
#include "../../absyntax/visitor.hh" |
|
181
38d6eb056260
Moving absyntax utility files out from stage4/generate_c
mario
parents:
178
diff
changeset
|
49 |
#include "../../absyntax_utils/absyntax_utils.hh" |
70 | 50 |
|
51 |
#include "../stage4.hh" |
|
52 |
||
53 |
||
54 |
||
55 |
||
56 |
||
57 |
||
58 |
||
59 |
//#define DEBUG |
|
60 |
#ifdef DEBUG |
|
61 |
#define TRACE(classname) printf("\n____%s____\n",classname); |
|
62 |
#else |
|
63 |
#define TRACE(classname) |
|
64 |
#endif |
|
65 |
||
66 |
||
67 |
||
68 |
#define ERROR error_exit(__FILE__,__LINE__) |
|
69 |
/* function defined in main.cc */ |
|
70 |
extern void error_exit(const char *file_name, int line_no); |
|
71 |
||
72 |
||
73 |
||
74 |
||
75 |
/***********************************************************************/ |
|
76 |
/***********************************************************************/ |
|
77 |
/***********************************************************************/ |
|
78 |
/***********************************************************************/ |
|
79 |
||
80 |
/* Unlike Programs and Configurations which get mapped onto C++ classes, |
|
81 |
* Function Blocks are mapped onto a C structure containing the variables, and |
|
82 |
* a C function containing the code in the FB's body. This is to allow direct allocation |
|
83 |
* of a FB variable (which is really an instance of the C data structure) to |
|
84 |
* a member of a union variable (note that classes with constructors cannot |
|
85 |
* be mebers of a union), which is done in IL when loading a FB onto IL's |
|
86 |
* default variable. |
|
87 |
* |
|
88 |
* So as not to clash the names of the C data structure and the C function, |
|
89 |
* the C structure is given a name identical to that of the FB name, whereas |
|
90 |
* the name of the function is the FB name with a constant string appended. |
|
91 |
* The value of that constant string which is appended is defined in the following |
|
92 |
* constant. |
|
93 |
* In order not to clash with any variable in the IL and ST source codem the |
|
94 |
* following constant should contain a double underscore, which is not allowed |
|
95 |
* in IL and ST. |
|
96 |
* |
|
97 |
* e.g.: FUNTION_BLOCK TEST |
|
98 |
* is mapped onto a TEST data structure, and a TEST_body__ function. |
|
99 |
*/ |
|
100 |
||
101 |
#define FB_FUNCTION_SUFFIX "_body__" |
|
102 |
||
103 |
/* Idem as body, but for initializer FB function */ |
|
104 |
#define FB_INIT_SUFFIX "_init__" |
|
105 |
||
106 |
/* Idem as body, but for run CONFIG and RESOURCE function */ |
|
107 |
#define FB_RUN_SUFFIX "_run__" |
|
108 |
||
109 |
/* The FB body function is passed as the only parameter a pointer to the FB data |
|
110 |
* structure instance. The name of this parameter is given by the following constant. |
|
111 |
* In order not to clash with any variable in the IL and ST source codem the |
|
112 |
* following constant should contain a double underscore, which is not allowed |
|
113 |
* in IL and ST. |
|
114 |
* |
|
115 |
* e.g.: the body of FUNTION_BLOCK TEST |
|
116 |
* is mapped onto the C function |
|
117 |
* TEST_body__(TEST *data__) |
|
118 |
*/ |
|
119 |
||
120 |
#define FB_FUNCTION_PARAM "data__" |
|
121 |
||
122 |
||
123 |
#define SFC_STEP_ACTION_PREFIX "__SFC_" |
|
124 |
||
125 |
/***********************************************************************/ |
|
126 |
/***********************************************************************/ |
|
127 |
/***********************************************************************/ |
|
128 |
/***********************************************************************/ |
|
129 |
||
130 |
#include "generate_c_base.cc" |
|
131 |
#include "generate_c_typedecl.cc" |
|
132 |
#include "generate_c_sfcdecl.cc" |
|
133 |
#include "generate_c_vardecl.cc" |
|
134 |
#include "generate_c_configbody.cc" |
|
135 |
#include "generate_location_list.cc" |
|
111 | 136 |
#include "generate_var_list.cc" |
70 | 137 |
|
138 |
/***********************************************************************/ |
|
139 |
/***********************************************************************/ |
|
140 |
/***********************************************************************/ |
|
141 |
/***********************************************************************/ |
|
142 |
||
143 |
/* Generate a name for a temporary variable. |
|
144 |
* Each new name generated is appended a different number, |
|
145 |
* starting off from 0. |
|
146 |
* After calling reset(), the names will start off again from 0. |
|
147 |
*/ |
|
148 |
#define VAR_LEADER "__" |
|
149 |
#define TEMP_VAR VAR_LEADER "TMP_" |
|
150 |
#define SOURCE_VAR VAR_LEADER "SRC_" |
|
151 |
||
152 |
#include "generate_c_tempvardecl.cc" |
|
153 |
||
154 |
#include "generate_c_st.cc" |
|
155 |
#include "generate_c_il.cc" |
|
156 |
||
157 |
#include "generate_c.hh" |
|
158 |
||
159 |
/***********************************************************************/ |
|
160 |
/***********************************************************************/ |
|
161 |
/***********************************************************************/ |
|
162 |
/***********************************************************************/ |
|
163 |
||
164 |
#define MILLISECOND 1000000 |
|
165 |
#define SECOND 1000 * MILLISECOND |
|
166 |
||
167 |
/* A helper class that knows how to generate code for both the IL and ST languages... */ |
|
168 |
class calculate_time_c: public iterator_visitor_c { |
|
169 |
private: |
|
170 |
unsigned long time; |
|
171 |
float current_value; |
|
172 |
||
173 |
public: |
|
174 |
calculate_time_c(void){time = 0;}; |
|
175 |
||
176 |
unsigned long get_time(void) {return time;}; |
|
177 |
||
178 |
void *get_integer_value(token_c *token) { |
|
179 |
std::string str = ""; |
|
180 |
for (unsigned int i = 0; i < strlen(token->value); i++) |
|
181 |
if (token->value[i] != '_') |
|
182 |
str += token->value[i]; |
|
183 |
current_value = atof(str.c_str()); |
|
184 |
return NULL; |
|
185 |
} |
|
186 |
||
187 |
void *get_float_value(token_c *token) { |
|
188 |
current_value = atof(token->value); |
|
189 |
return NULL; |
|
190 |
} |
|
191 |
||
192 |
/******************************/ |
|
193 |
/* B 1.2.1 - Numeric Literals */ |
|
194 |
/******************************/ |
|
195 |
||
196 |
void *visit(integer_c *symbol) {return get_integer_value(symbol);} |
|
197 |
||
198 |
/************************/ |
|
199 |
/* B 1.2.3.1 - Duration */ |
|
200 |
/************************/ |
|
201 |
||
202 |
/* SYM_REF2(duration_c, neg, interval) */ |
|
203 |
void *visit(duration_c *symbol) { |
|
204 |
if (symbol->neg != NULL) |
|
205 |
ERROR; |
|
206 |
symbol->interval->accept(*this); |
|
207 |
return NULL; |
|
208 |
} |
|
209 |
||
210 |
/* SYM_TOKEN(fixed_point_c) */ |
|
211 |
void *visit(fixed_point_c *symbol) {return get_float_value(symbol);} |
|
212 |
||
213 |
/* SYM_REF2(days_c, days, hours) */ |
|
214 |
void *visit(days_c *symbol) { |
|
215 |
if (symbol->hours) |
|
216 |
symbol->hours->accept(*this); |
|
217 |
symbol->days->accept(*this); |
|
218 |
time += (unsigned long)(current_value * 24 * 3600 * SECOND); |
|
219 |
return NULL; |
|
220 |
} |
|
221 |
||
222 |
/* SYM_REF2(hours_c, hours, minutes) */ |
|
223 |
void *visit(hours_c *symbol) { |
|
224 |
if (symbol->minutes) |
|
225 |
symbol->minutes->accept(*this); |
|
226 |
symbol->hours->accept(*this); |
|
227 |
time += (unsigned long)(current_value * 3600 * SECOND); |
|
228 |
return NULL; |
|
229 |
} |
|
230 |
||
231 |
/* SYM_REF2(minutes_c, minutes, seconds) */ |
|
232 |
void *visit(minutes_c *symbol) { |
|
233 |
if (symbol->seconds) |
|
234 |
symbol->seconds->accept(*this); |
|
235 |
symbol->minutes->accept(*this); |
|
236 |
time += (unsigned long)(current_value * 60 * SECOND); |
|
237 |
return NULL; |
|
238 |
} |
|
239 |
||
240 |
/* SYM_REF2(seconds_c, seconds, milliseconds) */ |
|
241 |
void *visit(seconds_c *symbol) { |
|
242 |
if (symbol->milliseconds) |
|
243 |
symbol->milliseconds->accept(*this); |
|
244 |
symbol->seconds->accept(*this); |
|
245 |
time += (unsigned long)(current_value * SECOND); |
|
246 |
return NULL; |
|
247 |
} |
|
248 |
||
249 |
/* SYM_REF2(milliseconds_c, milliseconds, unused) */ |
|
250 |
void *visit(milliseconds_c *symbol) { |
|
251 |
symbol->milliseconds->accept(*this); |
|
252 |
time += (unsigned long)(current_value * MILLISECOND); |
|
253 |
return NULL; |
|
254 |
} |
|
255 |
}; |
|
256 |
||
257 |
/***********************************************************************/ |
|
258 |
/***********************************************************************/ |
|
259 |
/***********************************************************************/ |
|
260 |
/***********************************************************************/ |
|
261 |
||
262 |
class calculate_common_ticktime_c: public iterator_visitor_c { |
|
263 |
private: |
|
264 |
unsigned long common_ticktime; |
|
265 |
||
266 |
public: |
|
267 |
calculate_common_ticktime_c(void){common_ticktime = 0;} |
|
268 |
||
269 |
unsigned long euclide(unsigned long a, unsigned long b) { |
|
270 |
unsigned long c = a % b; |
|
271 |
if (c == 0) |
|
272 |
return b; |
|
273 |
else |
|
274 |
return euclide(b, c); |
|
275 |
} |
|
276 |
||
277 |
void update_ticktime(unsigned long time) { |
|
278 |
if (common_ticktime == 0) |
|
279 |
common_ticktime = time; |
|
280 |
else if (time > common_ticktime) |
|
281 |
common_ticktime = euclide(time, common_ticktime); |
|
282 |
else |
|
283 |
common_ticktime = euclide(common_ticktime, time); |
|
284 |
} |
|
285 |
||
286 |
unsigned long get_ticktime(void) { |
|
287 |
return common_ticktime; |
|
288 |
} |
|
289 |
||
290 |
/* TASK task_name task_initialization */ |
|
291 |
//SYM_REF2(task_configuration_c, task_name, task_initialization) |
|
292 |
void *visit(task_initialization_c *symbol) { |
|
293 |
calculate_time_c calculate_time; |
|
294 |
unsigned long time = 0; |
|
295 |
if (symbol->interval_data_source != NULL) { |
|
296 |
symbol->interval_data_source->accept(calculate_time); |
|
297 |
time = calculate_time.get_time(); |
|
298 |
} |
|
299 |
if (time > 0) |
|
300 |
update_ticktime(time); |
|
301 |
return NULL; |
|
302 |
} |
|
303 |
}; |
|
304 |
||
305 |
/***********************************************************************/ |
|
306 |
/***********************************************************************/ |
|
307 |
/***********************************************************************/ |
|
308 |
/***********************************************************************/ |
|
309 |
||
310 |
/* A helper class that knows how to generate code for both the IL and ST languages... */ |
|
311 |
class generate_c_SFC_IL_ST_c: public null_visitor_c { |
|
312 |
private: |
|
313 |
stage4out_c *s4o_ptr; |
|
314 |
symbol_c *scope; |
|
315 |
const char *variable_prefix; |
|
316 |
||
317 |
public: |
|
318 |
generate_c_SFC_IL_ST_c(stage4out_c *s4o_ptr, symbol_c *scope, const char *variable_prefix = NULL); |
|
319 |
/*********************************************/ |
|
320 |
/* B.1.6 Sequential function chart elements */ |
|
321 |
/*********************************************/ |
|
322 |
||
323 |
/*| sequential_function_chart sfc_network*/ |
|
324 |
void *visit(sequential_function_chart_c * symbol); |
|
325 |
||
326 |
/****************************************/ |
|
327 |
/* B.2 - Language IL (Instruction List) */ |
|
328 |
/****************************************/ |
|
329 |
||
330 |
/***********************************/ |
|
331 |
/* B 2.1 Instructions and Operands */ |
|
332 |
/***********************************/ |
|
333 |
/*| instruction_list il_instruction */ |
|
334 |
void *visit(instruction_list_c *symbol); |
|
335 |
||
336 |
/* Remainder implemented in generate_c_il_c... */ |
|
337 |
||
338 |
/***************************************/ |
|
339 |
/* B.3 - Language ST (Structured Text) */ |
|
340 |
/***************************************/ |
|
341 |
/***********************/ |
|
342 |
/* B 3.1 - Expressions */ |
|
343 |
/***********************/ |
|
344 |
/* Implemented in generate_c_st_c */ |
|
345 |
||
346 |
/********************/ |
|
347 |
/* B 3.2 Statements */ |
|
348 |
/********************/ |
|
349 |
void *visit(statement_list_c *symbol); |
|
350 |
||
351 |
/* Remainder implemented in generate_c_st_c... */ |
|
352 |
}; |
|
353 |
||
354 |
#include "generate_c_sfc.cc" |
|
355 |
||
356 |
generate_c_SFC_IL_ST_c::generate_c_SFC_IL_ST_c(stage4out_c *s4o_ptr, symbol_c *scope, const char *variable_prefix) { |
|
357 |
if (NULL == scope) ERROR; |
|
358 |
this->s4o_ptr = s4o_ptr; |
|
359 |
this->scope = scope; |
|
360 |
this->variable_prefix = variable_prefix; |
|
361 |
} |
|
362 |
||
363 |
void *generate_c_SFC_IL_ST_c::visit(sequential_function_chart_c * symbol) { |
|
364 |
generate_c_sfc_c generate_c_sfc(s4o_ptr, scope, variable_prefix); |
|
365 |
generate_c_sfc.generate(symbol); |
|
366 |
return NULL; |
|
367 |
} |
|
368 |
||
369 |
void *generate_c_SFC_IL_ST_c::visit(instruction_list_c *symbol) { |
|
370 |
generate_c_il_c generate_c_il(s4o_ptr, scope, variable_prefix); |
|
371 |
generate_c_il.generate(symbol); |
|
372 |
return NULL; |
|
373 |
} |
|
374 |
||
375 |
void *generate_c_SFC_IL_ST_c::visit(statement_list_c *symbol) { |
|
376 |
generate_c_st_c generate_c_st(s4o_ptr, scope, variable_prefix); |
|
377 |
generate_c_st.generate(symbol); |
|
378 |
return NULL; |
|
379 |
} |
|
380 |
||
381 |
||
382 |
||
383 |
||
384 |
/***********************************************************************/ |
|
385 |
/***********************************************************************/ |
|
386 |
/***********************************************************************/ |
|
387 |
/***********************************************************************/ |
|
388 |
/***********************************************************************/ |
|
389 |
||
390 |
||
391 |
class generate_c_pous_c: public generate_c_typedecl_c { |
|
392 |
||
393 |
public: |
|
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
394 |
generate_c_pous_c(stage4out_c *s4o_ptr, stage4out_c *s4o_incl_ptr) |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
395 |
: generate_c_typedecl_c(s4o_ptr, s4o_incl_ptr) {}; |
70 | 396 |
virtual ~generate_c_pous_c(void) {} |
397 |
||
398 |
||
399 |
public: |
|
400 |
||
401 |
/*************************/ |
|
402 |
/* B.1 - Common elements */ |
|
403 |
/*************************/ |
|
404 |
/*******************************************/ |
|
405 |
/* B 1.1 - Letters, digits and identifiers */ |
|
406 |
/*******************************************/ |
|
407 |
/* done in base class(es) */ |
|
408 |
||
409 |
/*********************/ |
|
410 |
/* B 1.2 - Constants */ |
|
411 |
/*********************/ |
|
412 |
/* originally empty... */ |
|
413 |
||
414 |
/******************************/ |
|
415 |
/* B 1.2.1 - Numeric Literals */ |
|
416 |
/******************************/ |
|
417 |
/* done in base class(es) */ |
|
418 |
||
419 |
/*******************************/ |
|
420 |
/* B.1.2.2 Character Strings */ |
|
421 |
/*******************************/ |
|
422 |
/* done in base class(es) */ |
|
423 |
||
424 |
/***************************/ |
|
425 |
/* B 1.2.3 - Time Literals */ |
|
426 |
/***************************/ |
|
427 |
/************************/ |
|
428 |
/* B 1.2.3.1 - Duration */ |
|
429 |
/************************/ |
|
430 |
/* done in base class(es) */ |
|
431 |
||
432 |
/************************************/ |
|
433 |
/* B 1.2.3.2 - Time of day and Date */ |
|
434 |
/************************************/ |
|
435 |
/* done in base class(es) */ |
|
436 |
||
437 |
/**********************/ |
|
438 |
/* B.1.3 - Data types */ |
|
439 |
/**********************/ |
|
440 |
/***********************************/ |
|
441 |
/* B 1.3.1 - Elementary Data Types */ |
|
442 |
/***********************************/ |
|
443 |
/* done in base class(es) */ |
|
444 |
||
445 |
/********************************/ |
|
446 |
/* B.1.3.2 - Generic data types */ |
|
447 |
/********************************/ |
|
448 |
/* originally empty... */ |
|
449 |
||
450 |
/********************************/ |
|
451 |
/* B 1.3.3 - Derived data types */ |
|
452 |
/********************************/ |
|
453 |
/* done in base class(es) */ |
|
454 |
||
455 |
/*********************/ |
|
456 |
/* B 1.4 - Variables */ |
|
457 |
/*********************/ |
|
458 |
/* done in base class(es) */ |
|
459 |
||
460 |
/********************************************/ |
|
461 |
/* B.1.4.1 Directly Represented Variables */ |
|
462 |
/********************************************/ |
|
463 |
/* done in base class(es) */ |
|
464 |
||
465 |
/*************************************/ |
|
466 |
/* B.1.4.2 Multi-element Variables */ |
|
467 |
/*************************************/ |
|
468 |
/* done in base class(es) */ |
|
469 |
||
470 |
/******************************************/ |
|
471 |
/* B 1.4.3 - Declaration & Initialisation */ |
|
472 |
/******************************************/ |
|
473 |
/* done in base class(es) */ |
|
474 |
||
475 |
/**************************************/ |
|
476 |
/* B.1.5 - Program organization units */ |
|
477 |
/**************************************/ |
|
478 |
/***********************/ |
|
479 |
/* B 1.5.1 - Functions */ |
|
480 |
/***********************/ |
|
481 |
||
482 |
public: |
|
483 |
/* FUNCTION derived_function_name ':' elementary_type_name io_OR_function_var_declarations_list function_body END_FUNCTION */ |
|
484 |
/* | FUNCTION derived_function_name ':' derived_type_name io_OR_function_var_declarations_list function_body END_FUNCTION */ |
|
485 |
void *visit(function_declaration_c *symbol) { |
|
486 |
generate_c_vardecl_c *vardecl; |
|
487 |
TRACE("function_declaration_c"); |
|
488 |
||
489 |
/* (A) Function declaration... */ |
|
490 |
/* (A.1) Function return type */ |
|
491 |
s4o.print("// FUNCTION\n"); |
|
492 |
symbol->type_name->accept(*this); /* return type */ |
|
493 |
s4o.print(" "); |
|
494 |
/* (A.2) Function name */ |
|
495 |
symbol->derived_function_name->accept(*this); |
|
496 |
s4o.print("("); |
|
497 |
||
498 |
/* (A.3) Function parameters */ |
|
499 |
s4o.indent_right(); |
|
500 |
vardecl = new generate_c_vardecl_c(&s4o, |
|
501 |
generate_c_vardecl_c::finterface_vf, |
|
502 |
generate_c_vardecl_c::input_vt | |
|
145 | 503 |
generate_c_vardecl_c::output_vt | |
146
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
504 |
generate_c_vardecl_c::inoutput_vt | |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
505 |
generate_c_vardecl_c::eneno_vt); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
506 |
vardecl->print(symbol->var_declarations_list); |
189 | 507 |
vardecl->print_eneno(); |
146
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
508 |
delete vardecl; |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
509 |
|
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
510 |
s4o.indent_left(); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
511 |
|
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
512 |
s4o.print(")\n" + s4o.indent_spaces + "{\n"); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
513 |
|
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
514 |
/* (B) Function local variable declaration */ |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
515 |
/* (B.1) Variables declared in ST source code */ |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
516 |
s4o.indent_right(); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
517 |
|
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
518 |
vardecl = new generate_c_vardecl_c(&s4o, |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
519 |
generate_c_vardecl_c::localinit_vf, |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
520 |
generate_c_vardecl_c::output_vt | |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
521 |
generate_c_vardecl_c::inoutput_vt | |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
522 |
generate_c_vardecl_c::private_vt); |
70 | 523 |
vardecl->print(symbol->var_declarations_list); |
524 |
delete vardecl; |
|
146
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
525 |
|
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
526 |
/* (B.2) Temporary variable for function's return value */ |
70 | 527 |
/* It will have the same name as the function itself! */ |
528 |
s4o.print(s4o.indent_spaces); |
|
529 |
symbol->type_name->accept(*this); /* return type */ |
|
530 |
s4o.print(" "); |
|
531 |
symbol->derived_function_name->accept(*this); |
|
532 |
s4o.print(" = "); |
|
533 |
{ |
|
534 |
/* get the default value of this variable's type */ |
|
535 |
symbol_c *default_value = (symbol_c *)symbol->type_name->accept(*type_initial_value_c::instance()); |
|
536 |
if (default_value == NULL) ERROR; |
|
537 |
default_value->accept(*this); |
|
538 |
} |
|
539 |
s4o.print(";\n\n"); |
|
146
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
540 |
|
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
541 |
s4o.print(s4o.indent_spaces + "// Control execution\n"); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
542 |
s4o.print(s4o.indent_spaces + "if (!EN) {\n"); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
543 |
s4o.indent_right(); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
544 |
s4o.print(s4o.indent_spaces + "if (ENO != NULL) {\n"); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
545 |
s4o.indent_right(); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
546 |
s4o.print(s4o.indent_spaces + "*ENO = __BOOL_LITERAL(FALSE);\n"); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
547 |
s4o.indent_left(); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
548 |
s4o.print(s4o.indent_spaces + "}\n"); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
549 |
s4o.print(s4o.indent_spaces + "return "); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
550 |
symbol->derived_function_name->accept(*this); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
551 |
s4o.print(";\n"); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
552 |
s4o.indent_left(); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
553 |
s4o.print(s4o.indent_spaces + "}\n"); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
554 |
s4o.print(s4o.indent_spaces + "else {\n"); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
555 |
s4o.indent_right(); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
556 |
s4o.print(s4o.indent_spaces + "if (ENO != NULL) {\n"); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
557 |
s4o.indent_right(); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
558 |
s4o.print(s4o.indent_spaces + "*ENO = __BOOL_LITERAL(TRUE);\n"); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
559 |
s4o.indent_left(); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
560 |
s4o.print(s4o.indent_spaces + "}\n"); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
561 |
s4o.indent_left(); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
562 |
s4o.print(s4o.indent_spaces + "}\n"); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
563 |
|
70 | 564 |
/* (C) Function body */ |
565 |
generate_c_SFC_IL_ST_c generate_c_code(&s4o, symbol); |
|
566 |
symbol->function_body->accept(generate_c_code); |
|
145 | 567 |
|
568 |
vardecl = new generate_c_vardecl_c(&s4o, |
|
569 |
generate_c_vardecl_c::foutputassign_vf, |
|
570 |
generate_c_vardecl_c::output_vt | |
|
571 |
generate_c_vardecl_c::inoutput_vt); |
|
572 |
vardecl->print(symbol->var_declarations_list); |
|
573 |
delete vardecl; |
|
574 |
||
70 | 575 |
s4o.print(s4o.indent_spaces + "return "); |
576 |
symbol->derived_function_name->accept(*this); |
|
577 |
s4o.print(";\n"); |
|
578 |
s4o.indent_left(); |
|
579 |
s4o.print(s4o.indent_spaces + "}\n\n\n"); |
|
580 |
||
581 |
return NULL; |
|
582 |
} |
|
583 |
||
584 |
||
585 |
/* The remaining var_declarations_list_c, function_var_decls_c |
|
586 |
* and var2_init_decl_list_c are handled in the generate_c_vardecl_c class |
|
587 |
*/ |
|
588 |
||
589 |
||
590 |
/*****************************/ |
|
591 |
/* B 1.5.2 - Function Blocks */ |
|
592 |
/*****************************/ |
|
593 |
public: |
|
594 |
/* FUNCTION_BLOCK derived_function_block_name io_OR_other_var_declarations function_block_body END_FUNCTION_BLOCK */ |
|
595 |
//SYM_REF4(function_block_declaration_c, fblock_name, var_declarations, fblock_body, unused) |
|
596 |
void *visit(function_block_declaration_c *symbol) { |
|
597 |
generate_c_vardecl_c *vardecl; |
|
598 |
generate_c_sfcdecl_c *sfcdecl; |
|
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
599 |
generate_c_typedecl_c *typedecl; |
70 | 600 |
TRACE("function_block_declaration_c"); |
601 |
||
602 |
/* (A) Function Block data structure declaration... */ |
|
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
603 |
typedecl = new generate_c_typedecl_c(&s4o_incl); |
70 | 604 |
/* (A.1) Data structure declaration */ |
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
605 |
s4o_incl.print("// FUNCTION_BLOCK "); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
606 |
symbol->fblock_name->accept(*typedecl); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
607 |
s4o_incl.print("\n// Data part\n"); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
608 |
s4o_incl.print("typedef struct {\n"); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
609 |
s4o_incl.indent_right(); |
70 | 610 |
/* (A.2) Public variables: i.e. the function parameters... */ |
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
611 |
s4o_incl.print(s4o_incl.indent_spaces + "// FB Interface - IN, OUT, IN_OUT variables\n"); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
612 |
vardecl = new generate_c_vardecl_c(&s4o_incl, |
70 | 613 |
generate_c_vardecl_c::local_vf, |
614 |
generate_c_vardecl_c::input_vt | |
|
615 |
generate_c_vardecl_c::output_vt | |
|
146
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
616 |
generate_c_vardecl_c::inoutput_vt | |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
617 |
generate_c_vardecl_c::eneno_vt); |
70 | 618 |
vardecl->print(symbol->var_declarations); |
189 | 619 |
vardecl->print_eneno(); |
70 | 620 |
delete vardecl; |
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
621 |
s4o_incl.print("\n"); |
70 | 622 |
/* (A.3) Private internal variables */ |
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
623 |
s4o_incl.print(s4o_incl.indent_spaces + "// FB private variables - TEMP, private and located variables\n"); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
624 |
vardecl = new generate_c_vardecl_c(&s4o_incl, |
70 | 625 |
generate_c_vardecl_c::local_vf, |
626 |
generate_c_vardecl_c::temp_vt | |
|
627 |
generate_c_vardecl_c::private_vt | |
|
628 |
generate_c_vardecl_c::located_vt | |
|
629 |
generate_c_vardecl_c::external_vt); |
|
630 |
vardecl->print(symbol->var_declarations); |
|
631 |
delete vardecl; |
|
146
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
632 |
|
70 | 633 |
/* (A.4) Generate private internal variables for SFC */ |
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
634 |
sfcdecl = new generate_c_sfcdecl_c(&s4o_incl, generate_c_sfcdecl_c::sfcdecl_sd); |
70 | 635 |
sfcdecl->print(symbol->fblock_body); |
636 |
delete sfcdecl; |
|
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
637 |
s4o_incl.print("\n"); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
638 |
|
70 | 639 |
/* (A.5) Function Block data structure type name. */ |
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
640 |
s4o_incl.indent_left(); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
641 |
s4o_incl.print("} "); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
642 |
symbol->fblock_name->accept(*typedecl); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
643 |
s4o_incl.print(";\n\n"); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
644 |
delete typedecl; |
70 | 645 |
|
646 |
/* (B) Constructor */ |
|
647 |
/* (B.1) Constructor name... */ |
|
648 |
s4o.print(s4o.indent_spaces + "void "); |
|
649 |
symbol->fblock_name->accept(*this); |
|
650 |
s4o.print(FB_INIT_SUFFIX); |
|
651 |
s4o.print("("); |
|
652 |
||
653 |
/* first and only parameter is a pointer to the data */ |
|
654 |
symbol->fblock_name->accept(*this); |
|
655 |
s4o.print(" *"); |
|
656 |
s4o.print(FB_FUNCTION_PARAM); |
|
657 |
s4o.print(") {\n"); |
|
658 |
s4o.indent_right(); |
|
659 |
||
660 |
/* (B.2) Member initializations... */ |
|
661 |
s4o.print(s4o.indent_spaces); |
|
662 |
vardecl = new generate_c_vardecl_c(&s4o, |
|
663 |
generate_c_vardecl_c::constructorinit_vf, |
|
664 |
generate_c_vardecl_c::input_vt | |
|
665 |
generate_c_vardecl_c::output_vt | |
|
666 |
generate_c_vardecl_c::inoutput_vt | |
|
667 |
generate_c_vardecl_c::private_vt | |
|
668 |
generate_c_vardecl_c::located_vt | |
|
146
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
669 |
generate_c_vardecl_c::external_vt | |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
670 |
generate_c_vardecl_c::eneno_vt); |
70 | 671 |
vardecl->print(symbol->var_declarations, NULL, FB_FUNCTION_PARAM"->"); |
146
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
672 |
if (!vardecl->is_en_declared()) { |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
673 |
s4o.print("\n" + s4o.indent_spaces); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
674 |
s4o.print(FB_FUNCTION_PARAM); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
675 |
s4o.print("->EN = __BOOL_LITERAL(TRUE);"); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
676 |
} |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
677 |
if (!vardecl->is_eno_declared()) { |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
678 |
s4o.print("\n" + s4o.indent_spaces); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
679 |
s4o.print(FB_FUNCTION_PARAM); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
680 |
s4o.print("->ENO = __BOOL_LITERAL(TRUE);"); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
681 |
} |
70 | 682 |
delete vardecl; |
683 |
s4o.print("\n"); |
|
684 |
/* (B.3) Generate private internal variables for SFC */ |
|
685 |
sfcdecl = new generate_c_sfcdecl_c(&s4o, generate_c_sfcdecl_c::sfcinit_sd); |
|
686 |
sfcdecl->print(symbol->fblock_body, FB_FUNCTION_PARAM"->"); |
|
687 |
delete sfcdecl; |
|
688 |
s4o.indent_left(); |
|
689 |
s4o.print(s4o.indent_spaces + "}\n\n"); |
|
690 |
||
691 |
||
692 |
/* (C) Function with FB body */ |
|
693 |
/* (C.1) Step definitions */ |
|
694 |
sfcdecl = new generate_c_sfcdecl_c(&s4o, generate_c_sfcdecl_c::stepdef_sd); |
|
695 |
sfcdecl->print(symbol->fblock_body); |
|
696 |
delete sfcdecl; |
|
697 |
||
698 |
/* (C.2) Action definitions */ |
|
699 |
sfcdecl = new generate_c_sfcdecl_c(&s4o, generate_c_sfcdecl_c::actiondef_sd); |
|
700 |
sfcdecl->print(symbol->fblock_body); |
|
701 |
delete sfcdecl; |
|
702 |
||
703 |
/* (C.3) Function declaration */ |
|
704 |
s4o.print("// Code part\n"); |
|
705 |
/* function interface */ |
|
706 |
s4o.print("void "); |
|
707 |
symbol->fblock_name->accept(*this); |
|
708 |
s4o.print(FB_FUNCTION_SUFFIX); |
|
709 |
s4o.print("("); |
|
710 |
/* first and only parameter is a pointer to the data */ |
|
711 |
symbol->fblock_name->accept(*this); |
|
712 |
s4o.print(" *"); |
|
713 |
s4o.print(FB_FUNCTION_PARAM); |
|
714 |
s4o.print(") {\n"); |
|
715 |
s4o.indent_right(); |
|
716 |
||
146
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
717 |
s4o.print(s4o.indent_spaces + "// Control execution\n"); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
718 |
s4o.print(s4o.indent_spaces + "if (!"); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
719 |
s4o.print(FB_FUNCTION_PARAM); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
720 |
s4o.print("->EN) {\n"); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
721 |
s4o.indent_right(); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
722 |
s4o.print(s4o.indent_spaces); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
723 |
s4o.print(FB_FUNCTION_PARAM); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
724 |
s4o.print("->ENO = __BOOL_LITERAL(FALSE);\n"); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
725 |
s4o.print(s4o.indent_spaces + "return;\n"); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
726 |
s4o.indent_left(); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
727 |
s4o.print(s4o.indent_spaces + "}\n"); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
728 |
s4o.print(s4o.indent_spaces + "else {\n"); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
729 |
s4o.indent_right(); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
730 |
s4o.print(s4o.indent_spaces); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
731 |
s4o.print(FB_FUNCTION_PARAM); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
732 |
s4o.print("->ENO = __BOOL_LITERAL(TRUE);\n"); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
733 |
s4o.indent_left(); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
734 |
s4o.print(s4o.indent_spaces + "}\n"); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
735 |
|
70 | 736 |
/* (C.4) Initialize TEMP variables */ |
737 |
/* function body */ |
|
738 |
s4o.print(s4o.indent_spaces + "// Initialise TEMP variables\n"); |
|
739 |
vardecl = new generate_c_vardecl_c(&s4o, |
|
740 |
generate_c_vardecl_c::init_vf, |
|
741 |
generate_c_vardecl_c::temp_vt); |
|
742 |
vardecl->print(symbol->var_declarations, NULL, FB_FUNCTION_PARAM"->"); |
|
743 |
delete vardecl; |
|
744 |
s4o.print("\n"); |
|
745 |
||
746 |
/* (C.5) Function code */ |
|
747 |
generate_c_SFC_IL_ST_c generate_c_code(&s4o, symbol, FB_FUNCTION_PARAM"->"); |
|
748 |
symbol->fblock_body->accept(generate_c_code); |
|
749 |
s4o.indent_left(); |
|
750 |
s4o.print(s4o.indent_spaces + "} // "); |
|
751 |
symbol->fblock_name->accept(*this); |
|
752 |
s4o.print(FB_FUNCTION_SUFFIX); |
|
753 |
s4o.print(s4o.indent_spaces + "() \n\n"); |
|
754 |
||
755 |
/* (C.6) Step undefinitions */ |
|
756 |
sfcdecl = new generate_c_sfcdecl_c(&s4o, generate_c_sfcdecl_c::stepundef_sd); |
|
757 |
sfcdecl->print(symbol->fblock_body); |
|
758 |
delete sfcdecl; |
|
759 |
||
760 |
/* (C.7) Action undefinitions */ |
|
761 |
sfcdecl = new generate_c_sfcdecl_c(&s4o, generate_c_sfcdecl_c::actionundef_sd); |
|
762 |
sfcdecl->print(symbol->fblock_body); |
|
763 |
delete sfcdecl; |
|
764 |
||
765 |
s4o.indent_left(); |
|
766 |
s4o.print("\n\n\n\n"); |
|
767 |
||
768 |
return NULL; |
|
769 |
} |
|
770 |
||
771 |
||
772 |
/* The remaining temp_var_decls_c, temp_var_decls_list_c |
|
773 |
* and non_retentive_var_decls_c are handled in the generate_c_vardecl_c class |
|
774 |
*/ |
|
775 |
||
776 |
||
777 |
/**********************/ |
|
778 |
/* B 1.5.3 - Programs */ |
|
779 |
/**********************/ |
|
780 |
||
781 |
||
782 |
||
783 |
public: |
|
784 |
/* PROGRAM program_type_name program_var_declarations_list function_block_body END_PROGRAM */ |
|
785 |
//SYM_REF4(program_declaration_c, program_type_name, var_declarations, function_block_body, unused) |
|
786 |
void *visit(program_declaration_c *symbol) { |
|
787 |
generate_c_vardecl_c *vardecl; |
|
788 |
generate_c_sfcdecl_c *sfcdecl; |
|
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
789 |
generate_c_typedecl_c *typedecl; |
70 | 790 |
TRACE("program_declaration_c"); |
791 |
||
792 |
/* (A) Program data structure declaration... */ |
|
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
793 |
typedecl = new generate_c_typedecl_c(&s4o_incl); |
70 | 794 |
/* (A.1) Data structure declaration */ |
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
795 |
s4o_incl.print("// PROGRAM "); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
796 |
symbol->program_type_name->accept(*typedecl); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
797 |
s4o_incl.print("\n// Data part\n"); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
798 |
s4o_incl.print("typedef struct {\n"); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
799 |
s4o_incl.indent_right(); |
70 | 800 |
|
801 |
/* (A.2) Public variables: i.e. the program parameters... */ |
|
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
802 |
s4o_incl.print(s4o_incl.indent_spaces + "// PROGRAM Interface - IN, OUT, IN_OUT variables\n"); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
803 |
vardecl = new generate_c_vardecl_c(&s4o_incl, |
70 | 804 |
generate_c_vardecl_c::local_vf, |
805 |
generate_c_vardecl_c::input_vt | |
|
806 |
generate_c_vardecl_c::output_vt | |
|
807 |
generate_c_vardecl_c::inoutput_vt); |
|
808 |
vardecl->print(symbol->var_declarations); |
|
809 |
delete vardecl; |
|
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
810 |
s4o_incl.print("\n"); |
70 | 811 |
/* (A.3) Private internal variables */ |
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
812 |
s4o_incl.print(s4o_incl.indent_spaces + "// PROGRAM private variables - TEMP, private and located variables\n"); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
813 |
vardecl = new generate_c_vardecl_c(&s4o_incl, |
70 | 814 |
generate_c_vardecl_c::local_vf, |
815 |
generate_c_vardecl_c::temp_vt | |
|
816 |
generate_c_vardecl_c::private_vt | |
|
817 |
generate_c_vardecl_c::located_vt | |
|
818 |
generate_c_vardecl_c::external_vt); |
|
819 |
vardecl->print(symbol->var_declarations); |
|
820 |
delete vardecl; |
|
821 |
/* (A.4) Generate private internal variables for SFC */ |
|
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
822 |
sfcdecl = new generate_c_sfcdecl_c(&s4o_incl, generate_c_sfcdecl_c::sfcdecl_sd); |
70 | 823 |
sfcdecl->print(symbol->function_block_body); |
824 |
delete sfcdecl; |
|
825 |
||
826 |
/* (A.5) Program data structure type name. */ |
|
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
827 |
s4o_incl.indent_left(); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
828 |
s4o_incl.print("} "); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
829 |
symbol->program_type_name->accept(*typedecl); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
830 |
s4o_incl.print(";\n\n"); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
831 |
delete typedecl; |
70 | 832 |
|
833 |
/* (B) Constructor */ |
|
834 |
/* (B.1) Constructor name... */ |
|
835 |
s4o.print(s4o.indent_spaces + "void "); |
|
836 |
symbol->program_type_name->accept(*this); |
|
837 |
s4o.print(FB_INIT_SUFFIX); |
|
838 |
s4o.print("("); |
|
839 |
||
840 |
/* first and only parameter is a pointer to the data */ |
|
841 |
symbol->program_type_name->accept(*this); |
|
842 |
s4o.print(" *"); |
|
843 |
s4o.print(FB_FUNCTION_PARAM); |
|
844 |
s4o.print(") {\n"); |
|
845 |
s4o.indent_right(); |
|
846 |
||
847 |
/* (B.2) Member initializations... */ |
|
848 |
s4o.print(s4o.indent_spaces); |
|
849 |
vardecl = new generate_c_vardecl_c(&s4o, |
|
850 |
generate_c_vardecl_c::constructorinit_vf, |
|
851 |
generate_c_vardecl_c::input_vt | |
|
852 |
generate_c_vardecl_c::output_vt | |
|
853 |
generate_c_vardecl_c::inoutput_vt | |
|
854 |
generate_c_vardecl_c::private_vt | |
|
855 |
generate_c_vardecl_c::located_vt | |
|
856 |
generate_c_vardecl_c::external_vt); |
|
857 |
vardecl->print(symbol->var_declarations, NULL, FB_FUNCTION_PARAM"->"); |
|
858 |
delete vardecl; |
|
859 |
s4o.print("\n"); |
|
860 |
/* (B.3) Generate private internal variables for SFC */ |
|
861 |
sfcdecl = new generate_c_sfcdecl_c(&s4o, generate_c_sfcdecl_c::sfcinit_sd); |
|
862 |
sfcdecl->print(symbol->function_block_body,FB_FUNCTION_PARAM"->"); |
|
863 |
delete sfcdecl; |
|
864 |
||
865 |
s4o.indent_left(); |
|
866 |
s4o.print(s4o.indent_spaces + "}\n\n"); |
|
867 |
||
868 |
/* (C) Function with PROGRAM body */ |
|
869 |
/* (C.1) Step definitions */ |
|
870 |
sfcdecl = new generate_c_sfcdecl_c(&s4o, generate_c_sfcdecl_c::stepdef_sd); |
|
871 |
sfcdecl->print(symbol->function_block_body); |
|
872 |
delete sfcdecl; |
|
873 |
||
874 |
/* (C.2) Action definitions */ |
|
875 |
sfcdecl = new generate_c_sfcdecl_c(&s4o, generate_c_sfcdecl_c::actiondef_sd); |
|
876 |
sfcdecl->print(symbol->function_block_body); |
|
877 |
delete sfcdecl; |
|
878 |
||
879 |
/* (C.3) Function declaration */ |
|
880 |
s4o.print("// Code part\n"); |
|
881 |
/* function interface */ |
|
882 |
s4o.print("void "); |
|
883 |
symbol->program_type_name->accept(*this); |
|
884 |
s4o.print(FB_FUNCTION_SUFFIX); |
|
885 |
s4o.print("("); |
|
886 |
/* first and only parameter is a pointer to the data */ |
|
887 |
symbol->program_type_name->accept(*this); |
|
888 |
s4o.print(" *"); |
|
889 |
s4o.print(FB_FUNCTION_PARAM); |
|
890 |
s4o.print(") {\n"); |
|
891 |
s4o.indent_right(); |
|
892 |
||
893 |
/* (C.4) Initialize TEMP variables */ |
|
894 |
/* function body */ |
|
895 |
s4o.print(s4o.indent_spaces + "// Initialise TEMP variables\n"); |
|
896 |
vardecl = new generate_c_vardecl_c(&s4o, |
|
897 |
generate_c_vardecl_c::init_vf, |
|
898 |
generate_c_vardecl_c::temp_vt); |
|
899 |
vardecl->print(symbol->var_declarations, NULL, FB_FUNCTION_PARAM"->"); |
|
900 |
delete vardecl; |
|
901 |
s4o.print("\n"); |
|
902 |
||
903 |
/* (C.5) Function code */ |
|
904 |
generate_c_SFC_IL_ST_c generate_c_code(&s4o, symbol, FB_FUNCTION_PARAM"->"); |
|
905 |
symbol->function_block_body->accept(generate_c_code); |
|
906 |
s4o.indent_left(); |
|
907 |
s4o.print(s4o.indent_spaces + "} // "); |
|
908 |
symbol->program_type_name->accept(*this); |
|
909 |
s4o.print(FB_FUNCTION_SUFFIX); |
|
910 |
s4o.print(s4o.indent_spaces + "() \n\n"); |
|
911 |
||
912 |
/* (C.6) Step undefinitions */ |
|
913 |
sfcdecl = new generate_c_sfcdecl_c(&s4o, generate_c_sfcdecl_c::stepundef_sd); |
|
914 |
sfcdecl->print(symbol->function_block_body); |
|
915 |
delete sfcdecl; |
|
916 |
||
917 |
/* (C.7) Action undefinitions */ |
|
918 |
sfcdecl = new generate_c_sfcdecl_c(&s4o, generate_c_sfcdecl_c::actionundef_sd); |
|
919 |
sfcdecl->print(symbol->function_block_body); |
|
920 |
delete sfcdecl; |
|
921 |
||
922 |
s4o.indent_left(); |
|
923 |
s4o.print("\n\n\n\n"); |
|
924 |
||
925 |
return NULL; |
|
926 |
} |
|
927 |
||
928 |
}; /* generate_c_pous_c */ |
|
929 |
||
930 |
/***********************************************************************/ |
|
931 |
/***********************************************************************/ |
|
932 |
/***********************************************************************/ |
|
933 |
/***********************************************************************/ |
|
934 |
/***********************************************************************/ |
|
935 |
/***********************************************************************/ |
|
936 |
/***********************************************************************/ |
|
937 |
/***********************************************************************/ |
|
938 |
||
939 |
class generate_c_config_c: public generate_c_typedecl_c { |
|
940 |
||
941 |
public: |
|
942 |
generate_c_config_c(stage4out_c *s4o_ptr) |
|
943 |
: generate_c_typedecl_c(s4o_ptr) {}; |
|
944 |
virtual ~generate_c_config_c(void) {} |
|
945 |
||
946 |
typedef enum { |
|
947 |
initprotos_dt, |
|
948 |
initdeclare_dt, |
|
949 |
runprotos_dt, |
|
950 |
rundeclare_dt |
|
951 |
} declaretype_t; |
|
952 |
||
953 |
declaretype_t wanted_declaretype; |
|
954 |
||
955 |
/********************************/ |
|
956 |
/* B 1.7 Configuration elements */ |
|
957 |
/********************************/ |
|
958 |
||
959 |
||
960 |
public: |
|
961 |
/* |
|
962 |
CONFIGURATION configuration_name |
|
963 |
optional_global_var_declarations |
|
964 |
(resource_declaration_list | single_resource_declaration) |
|
965 |
optional_access_declarations |
|
966 |
optional_instance_specific_initializations |
|
967 |
END_CONFIGURATION |
|
968 |
*/ |
|
969 |
/* |
|
970 |
SYM_REF6(configuration_declaration_c, configuration_name, global_var_declarations, resource_declarations, access_declarations, instance_specific_initializations, unused) |
|
971 |
*/ |
|
972 |
void *visit(configuration_declaration_c *symbol) { |
|
973 |
generate_c_vardecl_c *vardecl; |
|
974 |
||
975 |
/* Insert the header... */ |
|
976 |
s4o.print("/*******************************************/\n"); |
|
977 |
s4o.print("/* FILE GENERATED BY iec2c */\n"); |
|
978 |
s4o.print("/* Editing this file is not recommended... */\n"); |
|
979 |
s4o.print("/*******************************************/\n\n"); |
|
980 |
s4o.print("#include \"iec_std_lib.h\"\n\n"); |
|
981 |
||
982 |
/* (A) configuration declaration... */ |
|
983 |
/* (A.1) configuration name in comment */ |
|
984 |
s4o.print("// CONFIGURATION "); |
|
985 |
symbol->configuration_name->accept(*this); |
|
986 |
s4o.print("\n"); |
|
987 |
||
988 |
/* (A.2) Global variables */ |
|
989 |
vardecl = new generate_c_vardecl_c(&s4o, |
|
990 |
generate_c_vardecl_c::local_vf, |
|
991 |
generate_c_vardecl_c::global_vt); |
|
992 |
vardecl->print(symbol); |
|
993 |
delete vardecl; |
|
994 |
s4o.print("\n"); |
|
995 |
||
996 |
/* (B) Initialisation Function */ |
|
997 |
/* (B.1) Ressources initialisation protos... */ |
|
998 |
wanted_declaretype = initprotos_dt; |
|
999 |
symbol->resource_declarations->accept(*this); |
|
1000 |
s4o.print("\n"); |
|
1001 |
||
1002 |
/* (B.2) Initialisation function name... */ |
|
1003 |
s4o.print(s4o.indent_spaces + "void config"); |
|
1004 |
s4o.print(FB_INIT_SUFFIX); |
|
1005 |
s4o.print("(void) {\n"); |
|
1006 |
s4o.indent_right(); |
|
1007 |
||
1008 |
/* (B.3) Global variables initializations... */ |
|
1009 |
s4o.print(s4o.indent_spaces); |
|
1010 |
vardecl = new generate_c_vardecl_c(&s4o, |
|
1011 |
generate_c_vardecl_c::constructorinit_vf, |
|
1012 |
generate_c_vardecl_c::global_vt); |
|
1013 |
vardecl->print(symbol); |
|
1014 |
delete vardecl; |
|
1015 |
s4o.print("\n"); |
|
1016 |
||
1017 |
/* (B.3) Resources initializations... */ |
|
1018 |
wanted_declaretype = initdeclare_dt; |
|
1019 |
symbol->resource_declarations->accept(*this); |
|
1020 |
||
1021 |
s4o.indent_left(); |
|
1022 |
s4o.print(s4o.indent_spaces + "}\n\n"); |
|
1023 |
||
1024 |
||
1025 |
/* (C) Run Function*/ |
|
1026 |
/* (C.1) Resources run functions protos... */ |
|
1027 |
wanted_declaretype = runprotos_dt; |
|
1028 |
symbol->resource_declarations->accept(*this); |
|
1029 |
s4o.print("\n"); |
|
1030 |
||
1031 |
/* (C.2) Run function name... */ |
|
1032 |
s4o.print(s4o.indent_spaces + "void config"); |
|
1033 |
s4o.print(FB_RUN_SUFFIX); |
|
1034 |
s4o.print("(int tick) {\n"); |
|
1035 |
s4o.indent_right(); |
|
1036 |
||
1037 |
/* (C.3) Resources initializations... */ |
|
1038 |
wanted_declaretype = rundeclare_dt; |
|
1039 |
symbol->resource_declarations->accept(*this); |
|
1040 |
||
1041 |
/* (C.3) Close Public Function body */ |
|
1042 |
s4o.indent_left(); |
|
1043 |
s4o.print(s4o.indent_spaces + "}\n"); |
|
1044 |
||
1045 |
return NULL; |
|
1046 |
} |
|
1047 |
||
1048 |
void *visit(resource_declaration_c *symbol) { |
|
1049 |
if (wanted_declaretype == initprotos_dt || wanted_declaretype == runprotos_dt) { |
|
1050 |
s4o.print(s4o.indent_spaces + "void "); |
|
1051 |
symbol->resource_name->accept(*this); |
|
1052 |
if (wanted_declaretype == initprotos_dt) { |
|
1053 |
s4o.print(FB_INIT_SUFFIX); |
|
1054 |
s4o.print("(void);\n"); |
|
1055 |
} |
|
1056 |
else { |
|
1057 |
s4o.print(FB_RUN_SUFFIX); |
|
1058 |
s4o.print("(int tick);\n"); |
|
1059 |
} |
|
1060 |
} |
|
1061 |
if (wanted_declaretype == initdeclare_dt || wanted_declaretype == rundeclare_dt) { |
|
1062 |
s4o.print(s4o.indent_spaces); |
|
1063 |
symbol->resource_name->accept(*this); |
|
1064 |
if (wanted_declaretype == initdeclare_dt) { |
|
1065 |
s4o.print(FB_INIT_SUFFIX); |
|
1066 |
s4o.print("();\n"); |
|
1067 |
} |
|
1068 |
else { |
|
1069 |
s4o.print(FB_RUN_SUFFIX); |
|
1070 |
s4o.print("(tick);\n"); |
|
1071 |
} |
|
1072 |
} |
|
1073 |
return NULL; |
|
1074 |
} |
|
1075 |
||
1076 |
void *visit(single_resource_declaration_c *symbol) { |
|
1077 |
if (wanted_declaretype == initprotos_dt || wanted_declaretype == runprotos_dt) { |
|
1078 |
s4o.print(s4o.indent_spaces + "void RESOURCE"); |
|
1079 |
if (wanted_declaretype == initprotos_dt) { |
|
1080 |
s4o.print(FB_INIT_SUFFIX); |
|
1081 |
s4o.print("(void);\n"); |
|
1082 |
} |
|
1083 |
else { |
|
1084 |
s4o.print(FB_RUN_SUFFIX); |
|
1085 |
s4o.print("(int tick);\n"); |
|
1086 |
} |
|
1087 |
} |
|
1088 |
if (wanted_declaretype == initdeclare_dt || wanted_declaretype == rundeclare_dt) { |
|
1089 |
s4o.print(s4o.indent_spaces + "RESOURCE"); |
|
1090 |
if (wanted_declaretype == initdeclare_dt) { |
|
1091 |
s4o.print(FB_INIT_SUFFIX); |
|
1092 |
s4o.print("();\n"); |
|
1093 |
} |
|
1094 |
else { |
|
1095 |
s4o.print(FB_RUN_SUFFIX); |
|
1096 |
s4o.print("(tick);\n"); |
|
1097 |
} |
|
1098 |
} |
|
1099 |
return NULL; |
|
1100 |
} |
|
1101 |
||
1102 |
}; |
|
1103 |
||
1104 |
/***********************************************************************/ |
|
1105 |
/***********************************************************************/ |
|
1106 |
/***********************************************************************/ |
|
1107 |
/***********************************************************************/ |
|
1108 |
/***********************************************************************/ |
|
1109 |
/***********************************************************************/ |
|
1110 |
/***********************************************************************/ |
|
1111 |
/***********************************************************************/ |
|
1112 |
||
1113 |
||
1114 |
class generate_c_resources_c: public generate_c_typedecl_c { |
|
1115 |
||
1116 |
search_var_instance_decl_c *search_config_instance; |
|
1117 |
search_var_instance_decl_c *search_resource_instance; |
|
1118 |
||
1119 |
private: |
|
1120 |
/* The name of the resource curretnly being processed... */ |
|
1121 |
symbol_c *current_resource_name; |
|
184 | 1122 |
symbol_c *current_task_name; |
70 | 1123 |
symbol_c *current_global_vars; |
1124 |
||
1125 |
public: |
|
1126 |
generate_c_resources_c(stage4out_c *s4o_ptr, symbol_c *config_scope, symbol_c *resource_scope, unsigned long time) |
|
1127 |
: generate_c_typedecl_c(s4o_ptr) { |
|
1128 |
search_config_instance = new search_var_instance_decl_c(config_scope); |
|
1129 |
search_resource_instance = new search_var_instance_decl_c(resource_scope); |
|
1130 |
common_ticktime = time; |
|
1131 |
current_resource_name = NULL; |
|
184 | 1132 |
current_task_name = NULL; |
70 | 1133 |
current_global_vars = NULL; |
1134 |
}; |
|
1135 |
virtual ~generate_c_resources_c(void) { |
|
1136 |
delete search_config_instance; |
|
1137 |
delete search_resource_instance; |
|
1138 |
} |
|
1139 |
||
1140 |
typedef enum { |
|
1141 |
declare_dt, |
|
1142 |
init_dt, |
|
1143 |
run_dt |
|
1144 |
} declaretype_t; |
|
1145 |
||
1146 |
declaretype_t wanted_declaretype; |
|
1147 |
||
1148 |
unsigned long common_ticktime; |
|
1149 |
||
1150 |
const char *current_program_name; |
|
1151 |
||
1152 |
typedef enum { |
|
1153 |
assign_at, |
|
1154 |
send_at |
|
1155 |
} assigntype_t; |
|
1156 |
||
1157 |
assigntype_t wanted_assigntype; |
|
1158 |
||
1159 |
/********************************/ |
|
1160 |
/* B 1.7 Configuration elements */ |
|
1161 |
/********************************/ |
|
1162 |
||
1163 |
/* |
|
1164 |
RESOURCE resource_name ON resource_type_name |
|
1165 |
optional_global_var_declarations |
|
1166 |
single_resource_declaration |
|
1167 |
END_RESOURCE |
|
1168 |
*/ |
|
1169 |
// SYM_REF4(resource_declaration_c, resource_name, resource_type_name, global_var_declarations, resource_declaration) |
|
1170 |
void *visit(resource_declaration_c *symbol) { |
|
1171 |
current_resource_name = symbol->resource_name; |
|
1172 |
current_global_vars = symbol->global_var_declarations; |
|
1173 |
||
1174 |
symbol->resource_declaration->accept(*this); |
|
1175 |
||
1176 |
current_resource_name = NULL; |
|
1177 |
current_global_vars = NULL; |
|
1178 |
return NULL; |
|
1179 |
} |
|
1180 |
||
1181 |
/* task_configuration_list program_configuration_list */ |
|
1182 |
// SYM_REF2(single_resource_declaration_c, task_configuration_list, program_configuration_list) |
|
1183 |
void *visit(single_resource_declaration_c *symbol) { |
|
1184 |
bool single_resource = current_resource_name == NULL; |
|
1185 |
if (single_resource) |
|
1186 |
current_resource_name = new identifier_c("RESOURCE"); |
|
1187 |
generate_c_vardecl_c *vardecl; |
|
1188 |
||
1189 |
/* Insert the header... */ |
|
1190 |
s4o.print("/*******************************************/\n"); |
|
1191 |
s4o.print("/* FILE GENERATED BY iec2c */\n"); |
|
1192 |
s4o.print("/* Editing this file is not recommended... */\n"); |
|
1193 |
s4o.print("/*******************************************/\n\n"); |
|
1194 |
s4o.print("#include \"iec_std_lib.h\"\n\n"); |
|
1195 |
||
1196 |
/* (A) resource declaration... */ |
|
1197 |
/* (A.1) resource name in comment */ |
|
1198 |
s4o.print("// RESOURCE "); |
|
1199 |
current_resource_name->accept(*this); |
|
120
74640e3c7f53
Bug with D and L action qualifier and timing management in SFC generated fixed
lbessard
parents:
112
diff
changeset
|
1200 |
s4o.print("\n\n"); |
74640e3c7f53
Bug with D and L action qualifier and timing management in SFC generated fixed
lbessard
parents:
112
diff
changeset
|
1201 |
|
74640e3c7f53
Bug with D and L action qualifier and timing management in SFC generated fixed
lbessard
parents:
112
diff
changeset
|
1202 |
s4o.print("extern int common_ticktime__;\n\n"); |
70 | 1203 |
|
1204 |
/* (A.2) Global variables... */ |
|
1205 |
if (current_global_vars != NULL) { |
|
1206 |
vardecl = new generate_c_vardecl_c(&s4o, |
|
1207 |
generate_c_vardecl_c::local_vf, |
|
138
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
121
diff
changeset
|
1208 |
generate_c_vardecl_c::global_vt, |
8b32fd4d0194
Some miscelanous static, extern and pointer status variable changes in C generated code for configuration and resources
etisserant
parents:
121
diff
changeset
|
1209 |
current_resource_name); |
70 | 1210 |
vardecl->print(current_global_vars); |
1211 |
delete vardecl; |
|
120
74640e3c7f53
Bug with D and L action qualifier and timing management in SFC generated fixed
lbessard
parents:
112
diff
changeset
|
1212 |
s4o.print("\n"); |
70 | 1213 |
} |
1214 |
||
1215 |
/* (A.3) POUs inclusion */ |
|
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
1216 |
s4o.print("#include \"POUS.h\"\n\n"); |
70 | 1217 |
s4o.print("#include \"POUS.c\"\n\n"); |
1218 |
||
184 | 1219 |
wanted_declaretype = declare_dt; |
1220 |
||
70 | 1221 |
/* (A.4) Resource programs declaration... */ |
184 | 1222 |
symbol->task_configuration_list->accept(*this); |
1223 |
||
1224 |
/* (A.5) Resource programs declaration... */ |
|
70 | 1225 |
symbol->program_configuration_list->accept(*this); |
184 | 1226 |
|
70 | 1227 |
s4o.print("\n"); |
1228 |
||
1229 |
/* (B) resource initialisation function... */ |
|
1230 |
/* (B.1) initialisation function name... */ |
|
1231 |
s4o.print("void "); |
|
1232 |
current_resource_name->accept(*this); |
|
1233 |
s4o.print(FB_INIT_SUFFIX); |
|
1234 |
s4o.print("(void) {\n"); |
|
1235 |
s4o.indent_right(); |
|
1236 |
||
1237 |
/* (B.2) Global variables initialisations... */ |
|
1238 |
if (current_global_vars != NULL) { |
|
1239 |
s4o.print(s4o.indent_spaces); |
|
1240 |
vardecl = new generate_c_vardecl_c(&s4o, |
|
1241 |
generate_c_vardecl_c::constructorinit_vf, |
|
1242 |
generate_c_vardecl_c::global_vt); |
|
1243 |
vardecl->print(current_global_vars); |
|
1244 |
delete vardecl; |
|
1245 |
} |
|
1246 |
s4o.print("\n"); |
|
1247 |
||
1248 |
wanted_declaretype = init_dt; |
|
184 | 1249 |
|
1250 |
/* (B.3) Tasks initialisations... */ |
|
1251 |
symbol->task_configuration_list->accept(*this); |
|
1252 |
||
1253 |
/* (B.4) Resource programs initialisations... */ |
|
70 | 1254 |
symbol->program_configuration_list->accept(*this); |
1255 |
||
1256 |
s4o.indent_left(); |
|
1257 |
s4o.print("}\n\n"); |
|
1258 |
||
1259 |
/* (C) Resource run function... */ |
|
1260 |
/* (C.1) Run function name... */ |
|
1261 |
s4o.print("void "); |
|
1262 |
current_resource_name->accept(*this); |
|
1263 |
s4o.print(FB_RUN_SUFFIX); |
|
1264 |
s4o.print("(int tick) {\n"); |
|
1265 |
s4o.indent_right(); |
|
1266 |
||
184 | 1267 |
wanted_declaretype = run_dt; |
1268 |
||
70 | 1269 |
/* (C.2) Task management... */ |
1270 |
symbol->task_configuration_list->accept(*this); |
|
1271 |
||
1272 |
/* (C.3) Program run declaration... */ |
|
1273 |
symbol->program_configuration_list->accept(*this); |
|
1274 |
||
1275 |
s4o.indent_left(); |
|
1276 |
s4o.print("}\n\n"); |
|
1277 |
||
1278 |
if (single_resource) { |
|
1279 |
delete current_resource_name; |
|
1280 |
current_resource_name = NULL; |
|
1281 |
} |
|
1282 |
return NULL; |
|
1283 |
} |
|
1284 |
||
1285 |
/* PROGRAM [RETAIN | NON_RETAIN] program_name [WITH task_name] ':' program_type_name ['(' prog_conf_elements ')'] */ |
|
1286 |
//SYM_REF6(program_configuration_c, retain_option, program_name, task_name, program_type_name, prog_conf_elements, unused) |
|
1287 |
void *visit(program_configuration_c *symbol) { |
|
184 | 1288 |
switch (wanted_declaretype) { |
1289 |
case declare_dt: |
|
70 | 1290 |
s4o.print(s4o.indent_spaces); |
184 | 1291 |
symbol->program_type_name->accept(*this); |
1292 |
s4o.print(" "); |
|
1293 |
current_resource_name->accept(*this); |
|
1294 |
s4o.print("__"); |
|
1295 |
symbol->program_name->accept(*this); |
|
1296 |
s4o.print(";\n#define "); |
|
1297 |
symbol->program_name->accept(*this); |
|
1298 |
s4o.print(" "); |
|
1299 |
current_resource_name->accept(*this); |
|
1300 |
s4o.print("__"); |
|
1301 |
symbol->program_name->accept(*this); |
|
1302 |
s4o.print("\n"); |
|
1303 |
break; |
|
1304 |
case init_dt: |
|
1305 |
s4o.print(s4o.indent_spaces); |
|
1306 |
symbol->program_type_name->accept(*this); |
|
1307 |
s4o.print(FB_INIT_SUFFIX); |
|
1308 |
s4o.print("(&"); |
|
1309 |
symbol->program_name->accept(*this); |
|
1310 |
s4o.print(");\n"); |
|
1311 |
break; |
|
1312 |
case run_dt: |
|
1313 |
current_program_name = ((identifier_c*)(symbol->program_name))->value; |
|
1314 |
if (symbol->task_name != NULL) { |
|
1315 |
s4o.print(s4o.indent_spaces); |
|
1316 |
s4o.print("if ("); |
|
1317 |
symbol->task_name->accept(*this); |
|
1318 |
s4o.print(") {\n"); |
|
1319 |
s4o.indent_right(); |
|
1320 |
} |
|
70 | 1321 |
|
184 | 1322 |
wanted_assigntype = assign_at; |
1323 |
if (symbol->prog_conf_elements != NULL) |
|
1324 |
symbol->prog_conf_elements->accept(*this); |
|
1325 |
||
1326 |
s4o.print(s4o.indent_spaces); |
|
1327 |
symbol->program_type_name->accept(*this); |
|
1328 |
s4o.print(FB_FUNCTION_SUFFIX); |
|
1329 |
s4o.print("(&"); |
|
1330 |
symbol->program_name->accept(*this); |
|
1331 |
s4o.print(");\n"); |
|
1332 |
||
1333 |
wanted_assigntype = send_at; |
|
1334 |
if (symbol->prog_conf_elements != NULL) |
|
1335 |
symbol->prog_conf_elements->accept(*this); |
|
1336 |
||
1337 |
if (symbol->task_name != NULL) { |
|
1338 |
s4o.indent_left(); |
|
1339 |
s4o.print(s4o.indent_spaces + "}\n"); |
|
1340 |
} |
|
1341 |
break; |
|
1342 |
default: |
|
1343 |
break; |
|
70 | 1344 |
} |
1345 |
return NULL; |
|
1346 |
} |
|
1347 |
||
1348 |
/* TASK task_name task_initialization */ |
|
1349 |
//SYM_REF2(task_configuration_c, task_name, task_initialization) |
|
1350 |
void *visit(task_configuration_c *symbol) { |
|
184 | 1351 |
current_task_name = symbol->task_name; |
1352 |
switch (wanted_declaretype) { |
|
1353 |
case declare_dt: |
|
1354 |
s4o.print(s4o.indent_spaces + "BOOL "); |
|
1355 |
current_task_name->accept(*this); |
|
1356 |
s4o.print(";\n"); |
|
1357 |
symbol->task_initialization->accept(*this); |
|
1358 |
break; |
|
1359 |
case init_dt: |
|
1360 |
s4o.print(s4o.indent_spaces); |
|
1361 |
current_task_name->accept(*this); |
|
1362 |
s4o.print(" = __BOOL_LITERAL(FALSE);\n"); |
|
1363 |
symbol->task_initialization->accept(*this); |
|
1364 |
break; |
|
1365 |
case run_dt: |
|
1366 |
symbol->task_initialization->accept(*this); |
|
1367 |
break; |
|
1368 |
default: |
|
1369 |
break; |
|
1370 |
} |
|
1371 |
current_task_name = NULL; |
|
70 | 1372 |
return NULL; |
1373 |
} |
|
1374 |
||
1375 |
/* '(' [SINGLE ASSIGN data_source ','] [INTERVAL ASSIGN data_source ','] PRIORITY ASSIGN integer ')' */ |
|
1376 |
//SYM_REF4(task_initialization_c, single_data_source, interval_data_source, priority_data_source, unused) |
|
1377 |
void *visit(task_initialization_c *symbol) { |
|
184 | 1378 |
switch (wanted_declaretype) { |
1379 |
case declare_dt: |
|
1380 |
if (symbol->single_data_source != NULL) { |
|
1381 |
s4o.print(s4o.indent_spaces + "R_TRIG "); |
|
1382 |
current_task_name->accept(*this); |
|
1383 |
s4o.print("_R_TRIG;\n"); |
|
1384 |
} |
|
1385 |
break; |
|
1386 |
case init_dt: |
|
1387 |
if (symbol->single_data_source != NULL) { |
|
1388 |
s4o.print(s4o.indent_spaces + "R_TRIG"); |
|
1389 |
s4o.print(FB_INIT_SUFFIX); |
|
1390 |
s4o.print("(&"); |
|
1391 |
current_task_name->accept(*this); |
|
1392 |
s4o.print("_R_TRIG);\n"); |
|
1393 |
} |
|
1394 |
break; |
|
1395 |
case run_dt: |
|
1396 |
if (symbol->single_data_source != NULL) { |
|
1397 |
symbol_c *config_var_decl = NULL; |
|
1398 |
symbol_c *res_var_decl = NULL; |
|
1399 |
symbol_c *current_var_reference = ((global_var_reference_c *)(symbol->single_data_source))->global_var_name; |
|
1400 |
res_var_decl = search_resource_instance->get_decl(current_var_reference); |
|
1401 |
if (res_var_decl == NULL) { |
|
1402 |
config_var_decl = search_config_instance->get_decl(current_var_reference); |
|
1403 |
if (config_var_decl == NULL) |
|
1404 |
ERROR; |
|
1405 |
s4o.print(s4o.indent_spaces + "{extern "); |
|
1406 |
config_var_decl->accept(*this); |
|
1407 |
s4o.print(" *"); |
|
1408 |
symbol->single_data_source->accept(*this); |
|
1409 |
s4o.print("; "); |
|
1410 |
} |
|
1411 |
else |
|
1412 |
s4o.print(s4o.indent_spaces); |
|
1413 |
current_task_name->accept(*this); |
|
1414 |
s4o.print("_R_TRIG.CLK = *"); |
|
1415 |
symbol->single_data_source->accept(*this); |
|
1416 |
s4o.print(";"); |
|
1417 |
if (config_var_decl != NULL) |
|
1418 |
s4o.print("}"); |
|
1419 |
s4o.print("\n"); |
|
1420 |
s4o.print(s4o.indent_spaces + "R_TRIG"); |
|
1421 |
s4o.print(FB_FUNCTION_SUFFIX); |
|
1422 |
s4o.print("(&"); |
|
1423 |
current_task_name->accept(*this); |
|
1424 |
s4o.print("_R_TRIG);\n"); |
|
1425 |
s4o.print(s4o.indent_spaces); |
|
1426 |
current_task_name->accept(*this); |
|
1427 |
s4o.print(" = "); |
|
1428 |
current_task_name->accept(*this); |
|
1429 |
s4o.print("_R_TRIG.Q"); |
|
1430 |
} |
|
1431 |
else { |
|
1432 |
s4o.print(s4o.indent_spaces); |
|
1433 |
current_task_name->accept(*this); |
|
1434 |
s4o.print(" = "); |
|
1435 |
if (symbol->interval_data_source != NULL) { |
|
1436 |
calculate_time_c calculate_time; |
|
1437 |
symbol->interval_data_source->accept(calculate_time); |
|
1438 |
unsigned long time = calculate_time.get_time(); |
|
1439 |
if (time != 0) { |
|
1440 |
s4o.print("!(tick % "); |
|
1441 |
s4o.print_integer((int)(time / common_ticktime)); |
|
1442 |
s4o.print(")"); |
|
1443 |
} |
|
1444 |
else |
|
1445 |
s4o.print("1"); |
|
1446 |
} |
|
1447 |
else |
|
1448 |
s4o.print("1"); |
|
1449 |
} |
|
1450 |
s4o.print(";\n"); |
|
1451 |
break; |
|
1452 |
default: |
|
1453 |
break; |
|
70 | 1454 |
} |
1455 |
return NULL; |
|
1456 |
} |
|
1457 |
||
1458 |
/* any_symbolic_variable ASSIGN prog_data_source */ |
|
1459 |
//SYM_REF2(prog_cnxn_assign_c, symbolic_variable, prog_data_source) |
|
1460 |
void *visit(prog_cnxn_assign_c *symbol) { |
|
1461 |
if (wanted_assigntype == assign_at) { |
|
1462 |
symbol_c *var_decl; |
|
1463 |
unsigned int vartype = 0; |
|
1464 |
symbol_c *current_var_reference = ((global_var_reference_c *)(symbol->prog_data_source))->global_var_name; |
|
1465 |
var_decl = search_resource_instance->get_decl(current_var_reference); |
|
1466 |
if (var_decl == NULL) { |
|
1467 |
var_decl = search_config_instance->get_decl(current_var_reference); |
|
1468 |
if (var_decl == NULL) |
|
1469 |
ERROR; |
|
1470 |
else |
|
1471 |
vartype = search_config_instance->get_vartype(); |
|
1472 |
} |
|
1473 |
else |
|
1474 |
vartype = search_resource_instance->get_vartype(); |
|
1475 |
||
1476 |
s4o.print(s4o.indent_spaces + "{extern "); |
|
1477 |
var_decl->accept(*this); |
|
1478 |
s4o.print(" "); |
|
1479 |
symbol->prog_data_source->accept(*this); |
|
1480 |
s4o.print("; "); |
|
1481 |
s4o.print(current_program_name); |
|
1482 |
s4o.print("."); |
|
1483 |
symbol->symbolic_variable->accept(*this); |
|
1484 |
s4o.print(" = "); |
|
1485 |
if (vartype || search_var_instance_decl_c::global_vt) |
|
1486 |
s4o.print("*"); |
|
1487 |
symbol->prog_data_source->accept(*this); |
|
1488 |
s4o.print(";}\n"); |
|
1489 |
} |
|
1490 |
return NULL; |
|
1491 |
} |
|
1492 |
||
1493 |
/* any_symbolic_variable SENDTO data_sink */ |
|
1494 |
//SYM_REF2(prog_cnxn_sendto_c, symbolic_variable, data_sink) |
|
1495 |
void *visit(prog_cnxn_sendto_c *symbol) { |
|
1496 |
if (wanted_assigntype == send_at) { |
|
1497 |
symbol_c *var_decl; |
|
1498 |
unsigned int vartype = 0; |
|
1499 |
symbol_c *current_var_reference = ((global_var_reference_c *)(symbol->data_sink))->global_var_name; |
|
1500 |
var_decl = search_resource_instance->get_decl(current_var_reference); |
|
1501 |
if (var_decl == NULL) { |
|
1502 |
var_decl = search_config_instance->get_decl(current_var_reference); |
|
1503 |
if (var_decl == NULL) |
|
1504 |
ERROR; |
|
1505 |
else |
|
1506 |
vartype = search_config_instance->get_vartype(); |
|
1507 |
} |
|
1508 |
else |
|
1509 |
vartype = search_resource_instance->get_vartype(); |
|
1510 |
||
1511 |
s4o.print(s4o.indent_spaces); |
|
1512 |
s4o.print(s4o.indent_spaces + "{extern "); |
|
1513 |
var_decl->accept(*this); |
|
1514 |
s4o.print(" "); |
|
1515 |
symbol->data_sink->accept(*this); |
|
1516 |
s4o.print("; "); |
|
1517 |
if (vartype || search_var_instance_decl_c::global_vt) |
|
1518 |
s4o.print("*"); |
|
1519 |
symbol->data_sink->accept(*this); |
|
1520 |
s4o.print(" = "); |
|
1521 |
s4o.print(current_program_name); |
|
1522 |
s4o.print("."); |
|
1523 |
symbol->symbolic_variable->accept(*this); |
|
1524 |
s4o.print("};\n"); |
|
1525 |
} |
|
1526 |
return NULL; |
|
1527 |
} |
|
1528 |
||
1529 |
}; |
|
1530 |
||
1531 |
/***********************************************************************/ |
|
1532 |
/***********************************************************************/ |
|
1533 |
/***********************************************************************/ |
|
1534 |
/***********************************************************************/ |
|
1535 |
/***********************************************************************/ |
|
1536 |
/***********************************************************************/ |
|
1537 |
/***********************************************************************/ |
|
1538 |
/***********************************************************************/ |
|
1539 |
||
1540 |
class generate_c_c: public iterator_visitor_c { |
|
1541 |
protected: |
|
1542 |
stage4out_c &s4o; |
|
1543 |
stage4out_c pous_s4o; |
|
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
1544 |
stage4out_c pous_incl_s4o; |
70 | 1545 |
stage4out_c located_variables_s4o; |
111 | 1546 |
stage4out_c variables_s4o; |
70 | 1547 |
generate_c_pous_c generate_c_pous; |
111 | 1548 |
|
70 | 1549 |
symbol_c *current_configuration; |
1550 |
||
1551 |
const char *current_name; |
|
1552 |
const char *current_builddir; |
|
1553 |
||
1554 |
unsigned long common_ticktime; |
|
1555 |
||
1556 |
public: |
|
1557 |
generate_c_c(stage4out_c *s4o_ptr, const char *builddir): |
|
1558 |
s4o(*s4o_ptr), |
|
1559 |
pous_s4o(builddir, "POUS", "c"), |
|
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
1560 |
pous_incl_s4o(builddir, "POUS", "h"), |
70 | 1561 |
located_variables_s4o(builddir, "LOCATED_VARIABLES","h"), |
112 | 1562 |
variables_s4o(builddir, "VARIABLES","csv"), |
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
1563 |
generate_c_pous(&pous_s4o, &pous_incl_s4o) { |
70 | 1564 |
current_builddir = builddir; |
1565 |
current_configuration = NULL; |
|
1566 |
} |
|
1567 |
||
1568 |
~generate_c_c(void) {} |
|
1569 |
||
1570 |
/***************************/ |
|
1571 |
/* B 0 - Programming Model */ |
|
1572 |
/***************************/ |
|
1573 |
void *visit(library_c *symbol) { |
|
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
1574 |
pous_incl_s4o.print("#ifndef __POUS_H\n#define __POUS_H\n\n"); |
70 | 1575 |
for(int i = 0; i < symbol->n; i++) { |
1576 |
symbol->elements[i]->accept(*this); |
|
1577 |
} |
|
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
1578 |
pous_incl_s4o.print("#endif //__POUS_H\n"); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
1579 |
|
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
1580 |
generate_var_list_c generate_var_list(&variables_s4o, symbol); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
1581 |
generate_var_list.generate_programs(symbol); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
1582 |
generate_var_list.generate_variables(symbol); |
111 | 1583 |
|
98 | 1584 |
generate_location_list_c generate_location_list(&located_variables_s4o); |
1585 |
symbol->accept(generate_location_list); |
|
70 | 1586 |
return NULL; |
1587 |
} |
|
1588 |
||
1589 |
/*************************/ |
|
1590 |
/* B.1 - Common elements */ |
|
1591 |
/*************************/ |
|
1592 |
/*******************************************/ |
|
1593 |
/* B 1.1 - Letters, digits and identifiers */ |
|
1594 |
/*******************************************/ |
|
1595 |
void *visit(identifier_c *symbol) { |
|
1596 |
current_name = symbol->value; |
|
1597 |
return NULL; |
|
1598 |
} |
|
1599 |
||
98 | 1600 |
/********************************/ |
1601 |
/* B 1.3.3 - Derived data types */ |
|
1602 |
/********************************/ |
|
1603 |
/* TYPE type_declaration_list END_TYPE */ |
|
1604 |
void *visit(data_type_declaration_c *symbol) { |
|
1605 |
symbol->accept(generate_c_pous); |
|
1606 |
return NULL; |
|
1607 |
} |
|
1608 |
||
70 | 1609 |
/**************************************/ |
1610 |
/* B.1.5 - Program organization units */ |
|
1611 |
/**************************************/ |
|
1612 |
/***********************/ |
|
1613 |
/* B 1.5.1 - Functions */ |
|
1614 |
/***********************/ |
|
1615 |
void *visit(function_declaration_c *symbol) { |
|
1616 |
symbol->accept(generate_c_pous); |
|
1617 |
return NULL; |
|
1618 |
} |
|
1619 |
||
1620 |
/*****************************/ |
|
1621 |
/* B 1.5.2 - Function Blocks */ |
|
1622 |
/*****************************/ |
|
1623 |
void *visit(function_block_declaration_c *symbol) { |
|
1624 |
symbol->accept(generate_c_pous); |
|
1625 |
return NULL; |
|
1626 |
} |
|
1627 |
||
1628 |
/**********************/ |
|
1629 |
/* B 1.5.3 - Programs */ |
|
1630 |
/**********************/ |
|
1631 |
void *visit(program_declaration_c *symbol) { |
|
1632 |
symbol->accept(generate_c_pous); |
|
1633 |
return NULL; |
|
1634 |
} |
|
1635 |
||
1636 |
||
1637 |
/********************************/ |
|
1638 |
/* B 1.7 Configuration elements */ |
|
1639 |
/********************************/ |
|
1640 |
void *visit(configuration_declaration_c *symbol) { |
|
1641 |
static int configuration_count = 0; |
|
1642 |
||
1643 |
if (configuration_count++) { |
|
1644 |
/* the first configuration is the one we will use!! */ |
|
1645 |
ERROR; |
|
1646 |
} |
|
1647 |
||
1648 |
current_configuration = symbol; |
|
1649 |
||
1650 |
calculate_common_ticktime_c calculate_common_ticktime; |
|
1651 |
symbol->accept(calculate_common_ticktime); |
|
1652 |
common_ticktime = calculate_common_ticktime.get_ticktime(); |
|
1653 |
||
1654 |
symbol->configuration_name->accept(*this); |
|
1655 |
stage4out_c config_s4o(current_builddir, current_name, "c"); |
|
1656 |
generate_c_config_c generate_c_config(&config_s4o); |
|
1657 |
symbol->accept(generate_c_config); |
|
1658 |
||
1659 |
config_s4o.print("int common_ticktime__ = "); |
|
1660 |
config_s4o.print_integer((int)(common_ticktime / 1000000)); |
|
1661 |
config_s4o.print("; /*ms*/\n"); |
|
1662 |
||
1663 |
symbol->resource_declarations->accept(*this); |
|
1664 |
||
1665 |
current_configuration = NULL; |
|
1666 |
||
1667 |
return NULL; |
|
1668 |
} |
|
1669 |
||
1670 |
void *visit(resource_declaration_c *symbol) { |
|
1671 |
symbol->resource_name->accept(*this); |
|
1672 |
stage4out_c resources_s4o(current_builddir, current_name, "c"); |
|
1673 |
generate_c_resources_c generate_c_resources(&resources_s4o, current_configuration, symbol, common_ticktime); |
|
1674 |
symbol->accept(generate_c_resources); |
|
1675 |
return NULL; |
|
1676 |
} |
|
1677 |
||
1678 |
void *visit(single_resource_declaration_c *symbol) { |
|
1679 |
stage4out_c resources_s4o(current_builddir, "RESOURCE", "c"); |
|
1680 |
generate_c_resources_c generate_c_resources(&resources_s4o, current_configuration, symbol, common_ticktime); |
|
1681 |
symbol->accept(generate_c_resources); |
|
1682 |
return NULL; |
|
1683 |
} |
|
1684 |
||
1685 |
}; |
|
1686 |
||
1687 |
/***********************************************************************/ |
|
1688 |
/***********************************************************************/ |
|
1689 |
/***********************************************************************/ |
|
1690 |
/***********************************************************************/ |
|
1691 |
/***********************************************************************/ |
|
1692 |
/***********************************************************************/ |
|
1693 |
/***********************************************************************/ |
|
1694 |
/***********************************************************************/ |
|
1695 |
||
1696 |
||
1697 |
||
1698 |
||
1699 |
visitor_c *new_code_generator(stage4out_c *s4o, const char *builddir) {return new generate_c_c(s4o, builddir);} |
|
1700 |
void delete_code_generator(visitor_c *code_generator) {delete code_generator;} |
|
1701 |
||
1702 |