author | Edouard Tisserant |
Mon, 04 Apr 2011 19:18:22 +0200 | |
changeset 278 | 050d31dd7c74 |
parent 272 | 579db02bebd9 |
child 279 | c0453b7f99df |
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); |
255
86ef2244aef1
Modify code generated for avoiding warning while compiling when configuration or resource don't have any global variable
laurent
parents:
250
diff
changeset
|
1086 |
s4o.print("BOOL retain;\n"); |
86ef2244aef1
Modify code generated for avoiding warning while compiling when configuration or resource don't have any global variable
laurent
parents:
250
diff
changeset
|
1087 |
s4o.print(s4o.indent_spaces); |
86ef2244aef1
Modify code generated for avoiding warning while compiling when configuration or resource don't have any global variable
laurent
parents:
250
diff
changeset
|
1088 |
s4o.print("retain = 0;\n"); |
70 | 1089 |
|
1090 |
/* (B.3) Global variables initializations... */ |
|
1091 |
s4o.print(s4o.indent_spaces); |
|
1092 |
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
|
1093 |
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
|
1094 |
generate_c_vardecl_c::global_vt); |
70 | 1095 |
vardecl->print(symbol); |
1096 |
delete vardecl; |
|
1097 |
s4o.print("\n"); |
|
1098 |
||
1099 |
/* (B.3) Resources initializations... */ |
|
1100 |
wanted_declaretype = initdeclare_dt; |
|
1101 |
symbol->resource_declarations->accept(*this); |
|
1102 |
||
1103 |
s4o.indent_left(); |
|
1104 |
s4o.print(s4o.indent_spaces + "}\n\n"); |
|
1105 |
||
1106 |
||
1107 |
/* (C) Run Function*/ |
|
1108 |
/* (C.1) Resources run functions protos... */ |
|
1109 |
wanted_declaretype = runprotos_dt; |
|
1110 |
symbol->resource_declarations->accept(*this); |
|
1111 |
s4o.print("\n"); |
|
1112 |
||
1113 |
/* (C.2) Run function name... */ |
|
1114 |
s4o.print(s4o.indent_spaces + "void config"); |
|
1115 |
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
|
1116 |
s4o.print("(unsigned long tick) {\n"); |
70 | 1117 |
s4o.indent_right(); |
1118 |
||
1119 |
/* (C.3) Resources initializations... */ |
|
1120 |
wanted_declaretype = rundeclare_dt; |
|
1121 |
symbol->resource_declarations->accept(*this); |
|
1122 |
||
1123 |
/* (C.3) Close Public Function body */ |
|
1124 |
s4o.indent_left(); |
|
1125 |
s4o.print(s4o.indent_spaces + "}\n"); |
|
1126 |
||
1127 |
return NULL; |
|
1128 |
} |
|
1129 |
||
1130 |
void *visit(resource_declaration_c *symbol) { |
|
1131 |
if (wanted_declaretype == initprotos_dt || wanted_declaretype == runprotos_dt) { |
|
1132 |
s4o.print(s4o.indent_spaces + "void "); |
|
1133 |
symbol->resource_name->accept(*this); |
|
1134 |
if (wanted_declaretype == initprotos_dt) { |
|
1135 |
s4o.print(FB_INIT_SUFFIX); |
|
1136 |
s4o.print("(void);\n"); |
|
1137 |
} |
|
1138 |
else { |
|
1139 |
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
|
1140 |
s4o.print("(unsigned long tick);\n"); |
70 | 1141 |
} |
1142 |
} |
|
1143 |
if (wanted_declaretype == initdeclare_dt || wanted_declaretype == rundeclare_dt) { |
|
1144 |
s4o.print(s4o.indent_spaces); |
|
1145 |
symbol->resource_name->accept(*this); |
|
1146 |
if (wanted_declaretype == initdeclare_dt) { |
|
1147 |
s4o.print(FB_INIT_SUFFIX); |
|
1148 |
s4o.print("();\n"); |
|
1149 |
} |
|
1150 |
else { |
|
1151 |
s4o.print(FB_RUN_SUFFIX); |
|
1152 |
s4o.print("(tick);\n"); |
|
1153 |
} |
|
1154 |
} |
|
1155 |
return NULL; |
|
1156 |
} |
|
1157 |
||
1158 |
void *visit(single_resource_declaration_c *symbol) { |
|
1159 |
if (wanted_declaretype == initprotos_dt || wanted_declaretype == runprotos_dt) { |
|
1160 |
s4o.print(s4o.indent_spaces + "void RESOURCE"); |
|
1161 |
if (wanted_declaretype == initprotos_dt) { |
|
1162 |
s4o.print(FB_INIT_SUFFIX); |
|
1163 |
s4o.print("(void);\n"); |
|
1164 |
} |
|
1165 |
else { |
|
1166 |
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
|
1167 |
s4o.print("(unsigned long tick);\n"); |
70 | 1168 |
} |
1169 |
} |
|
1170 |
if (wanted_declaretype == initdeclare_dt || wanted_declaretype == rundeclare_dt) { |
|
1171 |
s4o.print(s4o.indent_spaces + "RESOURCE"); |
|
1172 |
if (wanted_declaretype == initdeclare_dt) { |
|
1173 |
s4o.print(FB_INIT_SUFFIX); |
|
1174 |
s4o.print("();\n"); |
|
1175 |
} |
|
1176 |
else { |
|
1177 |
s4o.print(FB_RUN_SUFFIX); |
|
1178 |
s4o.print("(tick);\n"); |
|
1179 |
} |
|
1180 |
} |
|
1181 |
return NULL; |
|
1182 |
} |
|
1183 |
||
1184 |
}; |
|
1185 |
||
1186 |
/***********************************************************************/ |
|
1187 |
/***********************************************************************/ |
|
1188 |
/***********************************************************************/ |
|
1189 |
/***********************************************************************/ |
|
1190 |
/***********************************************************************/ |
|
1191 |
/***********************************************************************/ |
|
1192 |
/***********************************************************************/ |
|
1193 |
/***********************************************************************/ |
|
1194 |
||
1195 |
||
1196 |
class generate_c_resources_c: public generate_c_typedecl_c { |
|
1197 |
||
1198 |
search_var_instance_decl_c *search_config_instance; |
|
1199 |
search_var_instance_decl_c *search_resource_instance; |
|
1200 |
||
1201 |
private: |
|
1202 |
/* The name of the resource curretnly being processed... */ |
|
1203 |
symbol_c *current_resource_name; |
|
184 | 1204 |
symbol_c *current_task_name; |
70 | 1205 |
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
|
1206 |
stage4out_c *s4o_ptr; |
70 | 1207 |
|
1208 |
public: |
|
1209 |
generate_c_resources_c(stage4out_c *s4o_ptr, symbol_c *config_scope, symbol_c *resource_scope, unsigned long time) |
|
1210 |
: 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
|
1211 |
search_config_instance = new search_var_instance_decl_c(config_scope); |
70 | 1212 |
search_resource_instance = new search_var_instance_decl_c(resource_scope); |
1213 |
common_ticktime = time; |
|
1214 |
current_resource_name = NULL; |
|
184 | 1215 |
current_task_name = NULL; |
70 | 1216 |
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
|
1217 |
generate_c_resources_c::s4o_ptr = s4o_ptr; |
70 | 1218 |
}; |
267
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
262
diff
changeset
|
1219 |
|
70 | 1220 |
virtual ~generate_c_resources_c(void) { |
1221 |
delete search_config_instance; |
|
1222 |
delete search_resource_instance; |
|
1223 |
} |
|
1224 |
||
1225 |
typedef enum { |
|
1226 |
declare_dt, |
|
1227 |
init_dt, |
|
1228 |
run_dt |
|
1229 |
} declaretype_t; |
|
1230 |
||
1231 |
declaretype_t wanted_declaretype; |
|
1232 |
||
1233 |
unsigned long common_ticktime; |
|
1234 |
||
1235 |
const char *current_program_name; |
|
1236 |
||
1237 |
typedef enum { |
|
1238 |
assign_at, |
|
1239 |
send_at |
|
1240 |
} assigntype_t; |
|
1241 |
||
1242 |
assigntype_t wanted_assigntype; |
|
1243 |
||
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
|
1244 |
/* 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
|
1245 |
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
|
1246 |
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
|
1247 |
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
|
1248 |
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
|
1249 |
|
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 |
/* 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
|
1251 |
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
|
1252 |
|
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 |
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
|
1254 |
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
|
1255 |
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
|
1256 |
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
|
1257 |
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
|
1258 |
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
|
1259 |
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
|
1260 |
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
|
1261 |
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
|
1262 |
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
|
1263 |
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
|
1264 |
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
|
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 |
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
|
1267 |
} |
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
|
1268 |
|
267
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
262
diff
changeset
|
1269 |
|
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 |
/* 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
|
1272 |
/********************/ |
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
262
diff
changeset
|
1273 |
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
|
1274 |
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
|
1275 |
|
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
262
diff
changeset
|
1276 |
|
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
|
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 |
/* 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
|
1279 |
/******************************************/ |
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 |
|
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 |
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
|
1282 |
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
|
1283 |
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
|
1284 |
} |
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 |
|
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 |
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
|
1287 |
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
|
1288 |
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
|
1289 |
} |
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 |
|
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 |
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
|
1292 |
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
|
1293 |
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
|
1294 |
} |
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
|
1295 |
|
70 | 1296 |
/********************************/ |
1297 |
/* B 1.7 Configuration elements */ |
|
1298 |
/********************************/ |
|
1299 |
||
1300 |
/* |
|
1301 |
RESOURCE resource_name ON resource_type_name |
|
1302 |
optional_global_var_declarations |
|
1303 |
single_resource_declaration |
|
1304 |
END_RESOURCE |
|
1305 |
*/ |
|
1306 |
// SYM_REF4(resource_declaration_c, resource_name, resource_type_name, global_var_declarations, resource_declaration) |
|
1307 |
void *visit(resource_declaration_c *symbol) { |
|
1308 |
current_resource_name = symbol->resource_name; |
|
1309 |
current_global_vars = symbol->global_var_declarations; |
|
1310 |
||
1311 |
symbol->resource_declaration->accept(*this); |
|
1312 |
||
1313 |
current_resource_name = NULL; |
|
1314 |
current_global_vars = NULL; |
|
1315 |
return NULL; |
|
1316 |
} |
|
1317 |
||
1318 |
/* task_configuration_list program_configuration_list */ |
|
1319 |
// SYM_REF2(single_resource_declaration_c, task_configuration_list, program_configuration_list) |
|
1320 |
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
|
1321 |
bool single_resource = current_resource_name == NULL; |
70 | 1322 |
if (single_resource) |
1323 |
current_resource_name = new identifier_c("RESOURCE"); |
|
1324 |
generate_c_vardecl_c *vardecl; |
|
1325 |
||
1326 |
/* Insert the header... */ |
|
1327 |
s4o.print("/*******************************************/\n"); |
|
1328 |
s4o.print("/* FILE GENERATED BY iec2c */\n"); |
|
1329 |
s4o.print("/* Editing this file is not recommended... */\n"); |
|
1330 |
s4o.print("/*******************************************/\n\n"); |
|
1331 |
s4o.print("#include \"iec_std_lib.h\"\n\n"); |
|
1332 |
||
1333 |
/* (A) resource declaration... */ |
|
1334 |
/* (A.1) resource name in comment */ |
|
1335 |
s4o.print("// RESOURCE "); |
|
1336 |
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
|
1337 |
s4o.print("\n\n"); |
74640e3c7f53
Bug with D and L action qualifier and timing management in SFC generated fixed
lbessard
parents:
112
diff
changeset
|
1338 |
|
237 | 1339 |
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
|
1340 |
|
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
210
diff
changeset
|
1341 |
s4o.print("#include \"accessor.h\"\n\n"); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
210
diff
changeset
|
1342 |
|
70 | 1343 |
/* (A.2) Global variables... */ |
1344 |
if (current_global_vars != NULL) { |
|
1345 |
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
|
1346 |
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
|
1347 |
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
|
1348 |
current_resource_name); |
70 | 1349 |
vardecl->print(current_global_vars); |
1350 |
delete vardecl; |
|
120
74640e3c7f53
Bug with D and L action qualifier and timing management in SFC generated fixed
lbessard
parents:
112
diff
changeset
|
1351 |
s4o.print("\n"); |
70 | 1352 |
} |
1353 |
||
1354 |
/* (A.3) POUs inclusion */ |
|
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
1355 |
s4o.print("#include \"POUS.h\"\n\n"); |
70 | 1356 |
s4o.print("#include \"POUS.c\"\n\n"); |
1357 |
||
184 | 1358 |
wanted_declaretype = declare_dt; |
1359 |
||
70 | 1360 |
/* (A.4) Resource programs declaration... */ |
184 | 1361 |
symbol->task_configuration_list->accept(*this); |
1362 |
||
1363 |
/* (A.5) Resource programs declaration... */ |
|
70 | 1364 |
symbol->program_configuration_list->accept(*this); |
184 | 1365 |
|
70 | 1366 |
s4o.print("\n"); |
1367 |
||
1368 |
/* (B) resource initialisation function... */ |
|
1369 |
/* (B.1) initialisation function name... */ |
|
1370 |
s4o.print("void "); |
|
1371 |
current_resource_name->accept(*this); |
|
1372 |
s4o.print(FB_INIT_SUFFIX); |
|
1373 |
s4o.print("(void) {\n"); |
|
1374 |
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
|
1375 |
s4o.print(s4o.indent_spaces); |
255
86ef2244aef1
Modify code generated for avoiding warning while compiling when configuration or resource don't have any global variable
laurent
parents:
250
diff
changeset
|
1376 |
s4o.print("BOOL retain;\n"); |
86ef2244aef1
Modify code generated for avoiding warning while compiling when configuration or resource don't have any global variable
laurent
parents:
250
diff
changeset
|
1377 |
s4o.print(s4o.indent_spaces); |
86ef2244aef1
Modify code generated for avoiding warning while compiling when configuration or resource don't have any global variable
laurent
parents:
250
diff
changeset
|
1378 |
s4o.print("retain = 0;\n"); |
70 | 1379 |
|
1380 |
/* (B.2) Global variables initialisations... */ |
|
1381 |
if (current_global_vars != NULL) { |
|
1382 |
s4o.print(s4o.indent_spaces); |
|
1383 |
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
|
1384 |
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
|
1385 |
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
|
1386 |
current_resource_name); |
70 | 1387 |
vardecl->print(current_global_vars); |
1388 |
delete vardecl; |
|
1389 |
} |
|
1390 |
s4o.print("\n"); |
|
1391 |
||
1392 |
wanted_declaretype = init_dt; |
|
184 | 1393 |
|
1394 |
/* (B.3) Tasks initialisations... */ |
|
1395 |
symbol->task_configuration_list->accept(*this); |
|
1396 |
||
1397 |
/* (B.4) Resource programs initialisations... */ |
|
70 | 1398 |
symbol->program_configuration_list->accept(*this); |
1399 |
||
1400 |
s4o.indent_left(); |
|
1401 |
s4o.print("}\n\n"); |
|
1402 |
||
1403 |
/* (C) Resource run function... */ |
|
1404 |
/* (C.1) Run function name... */ |
|
1405 |
s4o.print("void "); |
|
1406 |
current_resource_name->accept(*this); |
|
1407 |
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
|
1408 |
s4o.print("(unsigned long tick) {\n"); |
70 | 1409 |
s4o.indent_right(); |
1410 |
||
184 | 1411 |
wanted_declaretype = run_dt; |
1412 |
||
70 | 1413 |
/* (C.2) Task management... */ |
1414 |
symbol->task_configuration_list->accept(*this); |
|
1415 |
||
1416 |
/* (C.3) Program run declaration... */ |
|
1417 |
symbol->program_configuration_list->accept(*this); |
|
1418 |
||
1419 |
s4o.indent_left(); |
|
1420 |
s4o.print("}\n\n"); |
|
1421 |
||
1422 |
if (single_resource) { |
|
1423 |
delete current_resource_name; |
|
1424 |
current_resource_name = NULL; |
|
1425 |
} |
|
1426 |
return NULL; |
|
1427 |
} |
|
1428 |
||
1429 |
/* PROGRAM [RETAIN | NON_RETAIN] program_name [WITH task_name] ':' program_type_name ['(' prog_conf_elements ')'] */ |
|
1430 |
//SYM_REF6(program_configuration_c, retain_option, program_name, task_name, program_type_name, prog_conf_elements, unused) |
|
1431 |
void *visit(program_configuration_c *symbol) { |
|
184 | 1432 |
switch (wanted_declaretype) { |
1433 |
case declare_dt: |
|
70 | 1434 |
s4o.print(s4o.indent_spaces); |
184 | 1435 |
symbol->program_type_name->accept(*this); |
1436 |
s4o.print(" "); |
|
1437 |
current_resource_name->accept(*this); |
|
1438 |
s4o.print("__"); |
|
1439 |
symbol->program_name->accept(*this); |
|
1440 |
s4o.print(";\n#define "); |
|
1441 |
symbol->program_name->accept(*this); |
|
1442 |
s4o.print(" "); |
|
1443 |
current_resource_name->accept(*this); |
|
1444 |
s4o.print("__"); |
|
1445 |
symbol->program_name->accept(*this); |
|
1446 |
s4o.print("\n"); |
|
1447 |
break; |
|
1448 |
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
|
1449 |
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
|
1450 |
symbol->retain_option->accept(*this); |
184 | 1451 |
s4o.print(s4o.indent_spaces); |
1452 |
symbol->program_type_name->accept(*this); |
|
1453 |
s4o.print(FB_INIT_SUFFIX); |
|
1454 |
s4o.print("(&"); |
|
1455 |
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
|
1456 |
print_retain(); |
184 | 1457 |
s4o.print(");\n"); |
1458 |
break; |
|
1459 |
case run_dt: |
|
1460 |
current_program_name = ((identifier_c*)(symbol->program_name))->value; |
|
1461 |
if (symbol->task_name != NULL) { |
|
1462 |
s4o.print(s4o.indent_spaces); |
|
1463 |
s4o.print("if ("); |
|
1464 |
symbol->task_name->accept(*this); |
|
1465 |
s4o.print(") {\n"); |
|
1466 |
s4o.indent_right(); |
|
1467 |
} |
|
70 | 1468 |
|
184 | 1469 |
wanted_assigntype = assign_at; |
1470 |
if (symbol->prog_conf_elements != NULL) |
|
1471 |
symbol->prog_conf_elements->accept(*this); |
|
1472 |
||
1473 |
s4o.print(s4o.indent_spaces); |
|
1474 |
symbol->program_type_name->accept(*this); |
|
1475 |
s4o.print(FB_FUNCTION_SUFFIX); |
|
1476 |
s4o.print("(&"); |
|
1477 |
symbol->program_name->accept(*this); |
|
1478 |
s4o.print(");\n"); |
|
1479 |
||
1480 |
wanted_assigntype = send_at; |
|
1481 |
if (symbol->prog_conf_elements != NULL) |
|
1482 |
symbol->prog_conf_elements->accept(*this); |
|
1483 |
||
1484 |
if (symbol->task_name != NULL) { |
|
1485 |
s4o.indent_left(); |
|
1486 |
s4o.print(s4o.indent_spaces + "}\n"); |
|
1487 |
} |
|
1488 |
break; |
|
1489 |
default: |
|
1490 |
break; |
|
70 | 1491 |
} |
1492 |
return NULL; |
|
1493 |
} |
|
1494 |
||
1495 |
/* TASK task_name task_initialization */ |
|
1496 |
//SYM_REF2(task_configuration_c, task_name, task_initialization) |
|
1497 |
void *visit(task_configuration_c *symbol) { |
|
184 | 1498 |
current_task_name = symbol->task_name; |
1499 |
switch (wanted_declaretype) { |
|
1500 |
case declare_dt: |
|
1501 |
s4o.print(s4o.indent_spaces + "BOOL "); |
|
1502 |
current_task_name->accept(*this); |
|
1503 |
s4o.print(";\n"); |
|
1504 |
symbol->task_initialization->accept(*this); |
|
1505 |
break; |
|
1506 |
case init_dt: |
|
1507 |
s4o.print(s4o.indent_spaces); |
|
1508 |
current_task_name->accept(*this); |
|
1509 |
s4o.print(" = __BOOL_LITERAL(FALSE);\n"); |
|
1510 |
symbol->task_initialization->accept(*this); |
|
1511 |
break; |
|
1512 |
case run_dt: |
|
1513 |
symbol->task_initialization->accept(*this); |
|
1514 |
break; |
|
1515 |
default: |
|
1516 |
break; |
|
1517 |
} |
|
1518 |
current_task_name = NULL; |
|
70 | 1519 |
return NULL; |
1520 |
} |
|
1521 |
||
1522 |
/* '(' [SINGLE ASSIGN data_source ','] [INTERVAL ASSIGN data_source ','] PRIORITY ASSIGN integer ')' */ |
|
1523 |
//SYM_REF4(task_initialization_c, single_data_source, interval_data_source, priority_data_source, unused) |
|
1524 |
void *visit(task_initialization_c *symbol) { |
|
184 | 1525 |
switch (wanted_declaretype) { |
1526 |
case declare_dt: |
|
1527 |
if (symbol->single_data_source != NULL) { |
|
1528 |
s4o.print(s4o.indent_spaces + "R_TRIG "); |
|
1529 |
current_task_name->accept(*this); |
|
1530 |
s4o.print("_R_TRIG;\n"); |
|
1531 |
} |
|
1532 |
break; |
|
1533 |
case init_dt: |
|
1534 |
if (symbol->single_data_source != NULL) { |
|
1535 |
s4o.print(s4o.indent_spaces + "R_TRIG"); |
|
1536 |
s4o.print(FB_INIT_SUFFIX); |
|
1537 |
s4o.print("(&"); |
|
1538 |
current_task_name->accept(*this); |
|
248
9cb18ec14fa2
Task single parameter code generation broken after addition of accessors fixed.
laurent
parents:
244
diff
changeset
|
1539 |
s4o.print("_R_TRIG, retain);\n"); |
184 | 1540 |
} |
1541 |
break; |
|
1542 |
case run_dt: |
|
1543 |
if (symbol->single_data_source != NULL) { |
|
1544 |
symbol_c *config_var_decl = NULL; |
|
1545 |
symbol_c *res_var_decl = NULL; |
|
248
9cb18ec14fa2
Task single parameter code generation broken after addition of accessors fixed.
laurent
parents:
244
diff
changeset
|
1546 |
unsigned int vartype; |
184 | 1547 |
symbol_c *current_var_reference = ((global_var_reference_c *)(symbol->single_data_source))->global_var_name; |
1548 |
res_var_decl = search_resource_instance->get_decl(current_var_reference); |
|
1549 |
if (res_var_decl == NULL) { |
|
1550 |
config_var_decl = search_config_instance->get_decl(current_var_reference); |
|
1551 |
if (config_var_decl == NULL) |
|
1552 |
ERROR; |
|
248
9cb18ec14fa2
Task single parameter code generation broken after addition of accessors fixed.
laurent
parents:
244
diff
changeset
|
1553 |
vartype = search_config_instance->get_vartype(); |
184 | 1554 |
s4o.print(s4o.indent_spaces + "{extern "); |
1555 |
config_var_decl->accept(*this); |
|
1556 |
s4o.print(" *"); |
|
1557 |
symbol->single_data_source->accept(*this); |
|
1558 |
s4o.print("; "); |
|
1559 |
} |
|
248
9cb18ec14fa2
Task single parameter code generation broken after addition of accessors fixed.
laurent
parents:
244
diff
changeset
|
1560 |
else { |
9cb18ec14fa2
Task single parameter code generation broken after addition of accessors fixed.
laurent
parents:
244
diff
changeset
|
1561 |
vartype = search_resource_instance->get_vartype(); |
184 | 1562 |
s4o.print(s4o.indent_spaces); |
248
9cb18ec14fa2
Task single parameter code generation broken after addition of accessors fixed.
laurent
parents:
244
diff
changeset
|
1563 |
} |
9cb18ec14fa2
Task single parameter code generation broken after addition of accessors fixed.
laurent
parents:
244
diff
changeset
|
1564 |
s4o.print(SET_VAR); |
9cb18ec14fa2
Task single parameter code generation broken after addition of accessors fixed.
laurent
parents:
244
diff
changeset
|
1565 |
s4o.print("("); |
184 | 1566 |
current_task_name->accept(*this); |
248
9cb18ec14fa2
Task single parameter code generation broken after addition of accessors fixed.
laurent
parents:
244
diff
changeset
|
1567 |
s4o.print("_R_TRIG.CLK, *__GET_GLOBAL_"); |
184 | 1568 |
symbol->single_data_source->accept(*this); |
248
9cb18ec14fa2
Task single parameter code generation broken after addition of accessors fixed.
laurent
parents:
244
diff
changeset
|
1569 |
s4o.print("());"); |
184 | 1570 |
if (config_var_decl != NULL) |
1571 |
s4o.print("}"); |
|
1572 |
s4o.print("\n"); |
|
1573 |
s4o.print(s4o.indent_spaces + "R_TRIG"); |
|
1574 |
s4o.print(FB_FUNCTION_SUFFIX); |
|
1575 |
s4o.print("(&"); |
|
1576 |
current_task_name->accept(*this); |
|
1577 |
s4o.print("_R_TRIG);\n"); |
|
1578 |
s4o.print(s4o.indent_spaces); |
|
1579 |
current_task_name->accept(*this); |
|
1580 |
s4o.print(" = "); |
|
248
9cb18ec14fa2
Task single parameter code generation broken after addition of accessors fixed.
laurent
parents:
244
diff
changeset
|
1581 |
s4o.print(GET_VAR); |
9cb18ec14fa2
Task single parameter code generation broken after addition of accessors fixed.
laurent
parents:
244
diff
changeset
|
1582 |
s4o.print("("); |
184 | 1583 |
current_task_name->accept(*this); |
248
9cb18ec14fa2
Task single parameter code generation broken after addition of accessors fixed.
laurent
parents:
244
diff
changeset
|
1584 |
s4o.print("_R_TRIG.Q)"); |
184 | 1585 |
} |
1586 |
else { |
|
1587 |
s4o.print(s4o.indent_spaces); |
|
1588 |
current_task_name->accept(*this); |
|
1589 |
s4o.print(" = "); |
|
1590 |
if (symbol->interval_data_source != NULL) { |
|
1591 |
calculate_time_c calculate_time; |
|
1592 |
symbol->interval_data_source->accept(calculate_time); |
|
1593 |
unsigned long time = calculate_time.get_time(); |
|
1594 |
if (time != 0) { |
|
1595 |
s4o.print("!(tick % "); |
|
1596 |
s4o.print_integer((int)(time / common_ticktime)); |
|
1597 |
s4o.print(")"); |
|
1598 |
} |
|
1599 |
else |
|
1600 |
s4o.print("1"); |
|
1601 |
} |
|
1602 |
else |
|
1603 |
s4o.print("1"); |
|
1604 |
} |
|
1605 |
s4o.print(";\n"); |
|
1606 |
break; |
|
1607 |
default: |
|
1608 |
break; |
|
70 | 1609 |
} |
1610 |
return NULL; |
|
1611 |
} |
|
1612 |
||
1613 |
/* any_symbolic_variable ASSIGN prog_data_source */ |
|
1614 |
//SYM_REF2(prog_cnxn_assign_c, symbolic_variable, prog_data_source) |
|
1615 |
void *visit(prog_cnxn_assign_c *symbol) { |
|
1616 |
if (wanted_assigntype == assign_at) { |
|
1617 |
symbol_c *var_decl; |
|
1618 |
unsigned int vartype = 0; |
|
1619 |
symbol_c *current_var_reference = ((global_var_reference_c *)(symbol->prog_data_source))->global_var_name; |
|
1620 |
var_decl = search_resource_instance->get_decl(current_var_reference); |
|
1621 |
if (var_decl == NULL) { |
|
1622 |
var_decl = search_config_instance->get_decl(current_var_reference); |
|
1623 |
if (var_decl == NULL) |
|
1624 |
ERROR; |
|
1625 |
else |
|
1626 |
vartype = search_config_instance->get_vartype(); |
|
1627 |
} |
|
1628 |
else |
|
1629 |
vartype = search_resource_instance->get_vartype(); |
|
1630 |
||
1631 |
s4o.print(s4o.indent_spaces + "{extern "); |
|
1632 |
var_decl->accept(*this); |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
189
diff
changeset
|
1633 |
s4o.print(" *"); |
70 | 1634 |
symbol->prog_data_source->accept(*this); |
1635 |
s4o.print("; "); |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
189
diff
changeset
|
1636 |
s4o.printupper(current_program_name); |
70 | 1637 |
s4o.print("."); |
1638 |
symbol->symbolic_variable->accept(*this); |
|
1639 |
s4o.print(" = "); |
|
1640 |
if (vartype || search_var_instance_decl_c::global_vt) |
|
1641 |
s4o.print("*"); |
|
1642 |
symbol->prog_data_source->accept(*this); |
|
1643 |
s4o.print(";}\n"); |
|
1644 |
} |
|
1645 |
return NULL; |
|
1646 |
} |
|
1647 |
||
1648 |
/* any_symbolic_variable SENDTO data_sink */ |
|
1649 |
//SYM_REF2(prog_cnxn_sendto_c, symbolic_variable, data_sink) |
|
1650 |
void *visit(prog_cnxn_sendto_c *symbol) { |
|
1651 |
if (wanted_assigntype == send_at) { |
|
1652 |
symbol_c *var_decl; |
|
1653 |
unsigned int vartype = 0; |
|
1654 |
symbol_c *current_var_reference = ((global_var_reference_c *)(symbol->data_sink))->global_var_name; |
|
1655 |
var_decl = search_resource_instance->get_decl(current_var_reference); |
|
1656 |
if (var_decl == NULL) { |
|
1657 |
var_decl = search_config_instance->get_decl(current_var_reference); |
|
1658 |
if (var_decl == NULL) |
|
1659 |
ERROR; |
|
1660 |
else |
|
1661 |
vartype = search_config_instance->get_vartype(); |
|
1662 |
} |
|
1663 |
else |
|
1664 |
vartype = search_resource_instance->get_vartype(); |
|
1665 |
||
1666 |
s4o.print(s4o.indent_spaces + "{extern "); |
|
1667 |
var_decl->accept(*this); |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
189
diff
changeset
|
1668 |
s4o.print(" *"); |
70 | 1669 |
symbol->data_sink->accept(*this); |
1670 |
s4o.print("; "); |
|
1671 |
if (vartype || search_var_instance_decl_c::global_vt) |
|
1672 |
s4o.print("*"); |
|
1673 |
symbol->data_sink->accept(*this); |
|
1674 |
s4o.print(" = "); |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
189
diff
changeset
|
1675 |
s4o.printupper(current_program_name); |
70 | 1676 |
s4o.print("."); |
1677 |
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
|
1678 |
s4o.print(";};\n"); |
70 | 1679 |
} |
1680 |
return NULL; |
|
1681 |
} |
|
1682 |
||
1683 |
}; |
|
1684 |
||
1685 |
/***********************************************************************/ |
|
1686 |
/***********************************************************************/ |
|
1687 |
/***********************************************************************/ |
|
1688 |
/***********************************************************************/ |
|
1689 |
/***********************************************************************/ |
|
1690 |
/***********************************************************************/ |
|
1691 |
/***********************************************************************/ |
|
1692 |
/***********************************************************************/ |
|
1693 |
||
1694 |
class generate_c_c: public iterator_visitor_c { |
|
1695 |
protected: |
|
1696 |
stage4out_c &s4o; |
|
1697 |
stage4out_c pous_s4o; |
|
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
1698 |
stage4out_c pous_incl_s4o; |
70 | 1699 |
stage4out_c located_variables_s4o; |
111 | 1700 |
stage4out_c variables_s4o; |
70 | 1701 |
generate_c_pous_c generate_c_pous; |
111 | 1702 |
|
70 | 1703 |
symbol_c *current_configuration; |
1704 |
||
1705 |
const char *current_name; |
|
1706 |
const char *current_builddir; |
|
1707 |
||
237 | 1708 |
unsigned long long common_ticktime; |
70 | 1709 |
|
1710 |
public: |
|
1711 |
generate_c_c(stage4out_c *s4o_ptr, const char *builddir): |
|
1712 |
s4o(*s4o_ptr), |
|
1713 |
pous_s4o(builddir, "POUS", "c"), |
|
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
1714 |
pous_incl_s4o(builddir, "POUS", "h"), |
70 | 1715 |
located_variables_s4o(builddir, "LOCATED_VARIABLES","h"), |
112 | 1716 |
variables_s4o(builddir, "VARIABLES","csv"), |
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
1717 |
generate_c_pous(&pous_s4o, &pous_incl_s4o) { |
70 | 1718 |
current_builddir = builddir; |
1719 |
current_configuration = NULL; |
|
1720 |
} |
|
1721 |
||
1722 |
~generate_c_c(void) {} |
|
1723 |
||
267
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 |
|
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
262
diff
changeset
|
1726 |
/********************/ |
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
262
diff
changeset
|
1727 |
/* 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
|
1728 |
/********************/ |
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
262
diff
changeset
|
1729 |
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
|
1730 |
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 |
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
|
1732 |
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
|
1733 |
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
|
1734 |
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
|
1735 |
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
|
1736 |
} |
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
262
diff
changeset
|
1737 |
|
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
262
diff
changeset
|
1738 |
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
|
1739 |
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 |
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
|
1741 |
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
|
1742 |
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
|
1743 |
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
|
1744 |
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
|
1745 |
} |
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
262
diff
changeset
|
1746 |
|
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
262
diff
changeset
|
1747 |
|
70 | 1748 |
/***************************/ |
1749 |
/* B 0 - Programming Model */ |
|
1750 |
/***************************/ |
|
1751 |
void *visit(library_c *symbol) { |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
210
diff
changeset
|
1752 |
pous_incl_s4o.print("#ifndef __POUS_H\n#define __POUS_H\n\n#include \"accessor.h\"\n\n"); |
70 | 1753 |
for(int i = 0; i < symbol->n; i++) { |
1754 |
symbol->elements[i]->accept(*this); |
|
1755 |
} |
|
121
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
1756 |
pous_incl_s4o.print("#endif //__POUS_H\n"); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
1757 |
|
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
1758 |
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
|
1759 |
generate_var_list.generate_programs(symbol); |
9e8ce092e169
Adding support for POU struct definition in POUS.h
lbessard
parents:
120
diff
changeset
|
1760 |
generate_var_list.generate_variables(symbol); |
111 | 1761 |
|
98 | 1762 |
generate_location_list_c generate_location_list(&located_variables_s4o); |
1763 |
symbol->accept(generate_location_list); |
|
70 | 1764 |
return NULL; |
1765 |
} |
|
1766 |
||
1767 |
/*************************/ |
|
1768 |
/* B.1 - Common elements */ |
|
1769 |
/*************************/ |
|
1770 |
/*******************************************/ |
|
1771 |
/* B 1.1 - Letters, digits and identifiers */ |
|
1772 |
/*******************************************/ |
|
1773 |
void *visit(identifier_c *symbol) { |
|
1774 |
current_name = symbol->value; |
|
1775 |
return NULL; |
|
1776 |
} |
|
1777 |
||
98 | 1778 |
/********************************/ |
1779 |
/* B 1.3.3 - Derived data types */ |
|
1780 |
/********************************/ |
|
1781 |
/* TYPE type_declaration_list END_TYPE */ |
|
1782 |
void *visit(data_type_declaration_c *symbol) { |
|
1783 |
symbol->accept(generate_c_pous); |
|
1784 |
return NULL; |
|
1785 |
} |
|
1786 |
||
70 | 1787 |
/**************************************/ |
1788 |
/* B.1.5 - Program organization units */ |
|
1789 |
/**************************************/ |
|
1790 |
/***********************/ |
|
1791 |
/* B 1.5.1 - Functions */ |
|
1792 |
/***********************/ |
|
1793 |
void *visit(function_declaration_c *symbol) { |
|
1794 |
symbol->accept(generate_c_pous); |
|
1795 |
return NULL; |
|
1796 |
} |
|
1797 |
||
1798 |
/*****************************/ |
|
1799 |
/* B 1.5.2 - Function Blocks */ |
|
1800 |
/*****************************/ |
|
1801 |
void *visit(function_block_declaration_c *symbol) { |
|
1802 |
symbol->accept(generate_c_pous); |
|
1803 |
return NULL; |
|
1804 |
} |
|
1805 |
||
1806 |
/**********************/ |
|
1807 |
/* B 1.5.3 - Programs */ |
|
1808 |
/**********************/ |
|
1809 |
void *visit(program_declaration_c *symbol) { |
|
1810 |
symbol->accept(generate_c_pous); |
|
1811 |
return NULL; |
|
1812 |
} |
|
1813 |
||
1814 |
||
1815 |
/********************************/ |
|
1816 |
/* B 1.7 Configuration elements */ |
|
1817 |
/********************************/ |
|
1818 |
void *visit(configuration_declaration_c *symbol) { |
|
1819 |
static int configuration_count = 0; |
|
1820 |
||
1821 |
if (configuration_count++) { |
|
1822 |
/* the first configuration is the one we will use!! */ |
|
1823 |
ERROR; |
|
1824 |
} |
|
1825 |
||
1826 |
current_configuration = symbol; |
|
1827 |
||
1828 |
calculate_common_ticktime_c calculate_common_ticktime; |
|
1829 |
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
|
1830 |
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
|
1831 |
if (common_ticktime == 0) { |
9cb18ec14fa2
Task single parameter code generation broken after addition of accessors fixed.
laurent
parents:
244
diff
changeset
|
1832 |
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
|
1833 |
ERROR; |
9cb18ec14fa2
Task single parameter code generation broken after addition of accessors fixed.
laurent
parents:
244
diff
changeset
|
1834 |
} |
70 | 1835 |
|
1836 |
symbol->configuration_name->accept(*this); |
|
1837 |
stage4out_c config_s4o(current_builddir, current_name, "c"); |
|
1838 |
generate_c_config_c generate_c_config(&config_s4o); |
|
1839 |
symbol->accept(generate_c_config); |
|
1840 |
||
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
|
1841 |
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
|
1842 |
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
|
1843 |
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
|
1844 |
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
|
1845 |
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
|
1846 |
config_s4o.print("; /*tick*/\n"); |
70 | 1847 |
|
1848 |
symbol->resource_declarations->accept(*this); |
|
1849 |
||
1850 |
current_configuration = NULL; |
|
1851 |
||
1852 |
return NULL; |
|
1853 |
} |
|
1854 |
||
1855 |
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
|
1856 |
symbol->resource_name->accept(*this); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
189
diff
changeset
|
1857 |
stage4out_c resources_s4o(current_builddir, current_name, "c"); |
70 | 1858 |
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
|
1859 |
symbol->accept(generate_c_resources); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
189
diff
changeset
|
1860 |
return NULL; |
70 | 1861 |
} |
1862 |
||
1863 |
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
|
1864 |
stage4out_c resources_s4o(current_builddir, "RESOURCE", "c"); |
70 | 1865 |
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
|
1866 |
symbol->accept(generate_c_resources); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
189
diff
changeset
|
1867 |
return NULL; |
70 | 1868 |
} |
1869 |
||
1870 |
}; |
|
1871 |
||
1872 |
/***********************************************************************/ |
|
1873 |
/***********************************************************************/ |
|
1874 |
/***********************************************************************/ |
|
1875 |
/***********************************************************************/ |
|
1876 |
/***********************************************************************/ |
|
1877 |
/***********************************************************************/ |
|
1878 |
/***********************************************************************/ |
|
1879 |
/***********************************************************************/ |
|
1880 |
||
1881 |
||
1882 |
||
1883 |
||
1884 |
visitor_c *new_code_generator(stage4out_c *s4o, const char *builddir) {return new generate_c_c(s4o, builddir);} |
|
1885 |
void delete_code_generator(visitor_c *code_generator) {delete code_generator;} |
|
1886 |
||
1887 |