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