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