author | lbessard |
Tue, 09 Dec 2008 10:01:12 +0100 | |
changeset 292 | 800e100038ae |
parent 291 | e580c945c62a |
child 307 | fd1f6ae26d4f |
permissions | -rw-r--r-- |
58 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
4 |
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor |
|
5 |
#based on the plcopen standard. |
|
6 |
# |
|
7 |
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
|
8 |
# |
|
9 |
#See COPYING file for copyrights details. |
|
10 |
# |
|
11 |
#This library is free software; you can redistribute it and/or |
|
12 |
#modify it under the terms of the GNU General Public |
|
13 |
#License as published by the Free Software Foundation; either |
|
14 |
#version 2.1 of the License, or (at your option) any later version. |
|
15 |
# |
|
16 |
#This library is distributed in the hope that it will be useful, |
|
17 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
19 |
#General Public License for more details. |
|
20 |
# |
|
21 |
#You should have received a copy of the GNU General Public |
|
22 |
#License along with this library; if not, write to the Free Software |
|
23 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
24 |
||
36
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
25 |
""" |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
26 |
|
115 | 27 |
THIS CODE GENARATES C++ CODE FOR IEC2C COMPILER |
36
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
28 |
GENERATED CODE IS : |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
29 |
|
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
30 |
function_type_decl.h - the long enumeration of std function types |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
31 |
get_function_type_decl.c - the funct that return enumerated according function name |
115 | 32 |
st_code_gen.c - part of generate_c_st_c::visit(function_invocation) |
36
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
33 |
responsible to generate C code for std lib calls |
115 | 34 |
il_code_gen.c - part of generate_c_il_c::visit(il_function_call) |
36
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
35 |
responsible to generate C code for std lib calls |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
36 |
search_type_code.c - called by search_expression_type_c::visit(function_invocation) |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
37 |
return type symbol for std function invocation |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
38 |
|
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
39 |
""" |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
40 |
|
25 | 41 |
# Get definitions |
42 |
from plcopen.structures import * |
|
43 |
||
284 | 44 |
if len(sys.argv) != 2 : |
45 |
print "Usage: " + sys.argv[0] + " path_name\n -> create files in path_name" |
|
46 |
sys.exit(0) |
|
47 |
||
25 | 48 |
#import pprint |
49 |
#pp = pprint.PrettyPrinter(indent=4) |
|
50 |
||
58 | 51 |
matiec_header = """/* |
167 | 52 |
* (c) 2008 Edouard TISSERANT |
58 | 53 |
* |
54 |
* Offered to the public under the terms of the GNU General Public License |
|
55 |
* as published by the Free Software Foundation; either version 2 of the |
|
56 |
* License, or (at your option) any later version. |
|
57 |
* |
|
58 |
* This program is distributed in the hope that it will be useful, but |
|
59 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|
60 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
|
61 |
* Public License for more details. |
|
62 |
* |
|
63 |
* This code is made available on the understanding that it will not be |
|
64 |
* used in safety-critical situations without a full and competent review. |
|
65 |
*/ |
|
66 |
||
67 |
/* |
|
68 |
* An IEC 61131-3 IL and ST compiler. |
|
69 |
* |
|
70 |
* Based on the |
|
71 |
* FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
|
72 |
* |
|
73 |
*/ |
|
167 | 74 |
|
75 |
/**** |
|
76 |
* IEC 61131-3 standard function library |
|
77 |
* generated code, do not edit by hand |
|
78 |
*/ |
|
58 | 79 |
|
80 |
""" |
|
81 |
||
59 | 82 |
matiec_lesser_header = """/* |
167 | 83 |
* (c) 2008 Edouard TISSERANT |
59 | 84 |
* |
85 |
* Offered to the public under the terms of the GNU Lesser General Public |
|
86 |
* License as published by the Free Software Foundation; either version 2 |
|
87 |
* of the License, or (at your option) any later version. |
|
88 |
* |
|
89 |
* This program is distributed in the hope that it will be useful, but |
|
90 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|
91 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser |
|
92 |
* General Public License for more details. |
|
93 |
* |
|
94 |
* This code is made available on the understanding that it will not be |
|
95 |
* used in safety-critical situations without a full and competent review. |
|
96 |
*/ |
|
97 |
||
167 | 98 |
/**** |
99 |
* IEC 61131-3 standard function library |
|
100 |
* generated code, do not edit by hand |
|
101 |
*/ |
|
102 |
||
59 | 103 |
""" |
104 |
||
25 | 105 |
def ANY_to_compiler_test_type_GEN(typename, paramname): |
106 |
""" |
|
115 | 107 |
Convert ANY_XXX IEC type declaration into IEC2C's generated type test. |
25 | 108 |
This tests are defined in search_expression_type.cc |
109 |
""" |
|
110 |
return {"ANY" : "", |
|
111 |
"ANY_BIT" : "if(search_expression_type->is_binary_type(%(paramname)s_type_symbol))", |
|
26
36d378bd852e
Stage4 changes according to new STD lib implementation
etisserant
parents:
25
diff
changeset
|
112 |
"ANY_NBIT" : "if(search_expression_type->is_nbinary_type(%(paramname)s_type_symbol))", |
25 | 113 |
"ANY_NUM" : "if(search_expression_type->is_num_type(%(paramname)s_type_symbol))", |
114 |
"ANY_REAL" : "if(search_expression_type->is_real_type(%(paramname)s_type_symbol))", |
|
115 |
"ANY_INT" : "if(search_expression_type->is_integer_type(%(paramname)s_type_symbol))" |
|
116 |
}.get(typename, |
|
40 | 117 |
#"if (typeid(*last_type_symbol) == typeid(%(typename)s_type_name_c))")%{ |
118 |
"if(search_expression_type->is_same_type(&search_constant_type_c::%(typename)s_type_name, last_type_symbol))")%{ |
|
25 | 119 |
"paramname" : paramname, "typename": typename.lower()} |
120 |
||
121 |
def recurse_and_indent(fdecls, indent, do_type_search_only = False, do_il = False): |
|
122 |
""" |
|
123 |
This function generate visit(function_invocation) code for |
|
124 |
- ST code generator |
|
125 |
- IL code generator |
|
126 |
- search_expression_type class for ST |
|
127 |
- search_expression_type class for IL |
|
128 |
||
129 |
Input data is a |
|
130 |
"{fname : {IN[0]paramname : {IN[0]paramtype : {IN[1]paraname : {IN[1]paramtype : {... : {IN[N]paraname : {IN[N]paramtype : (fdecl,)}}}}}}" |
|
131 |
nested dictionary structure. |
|
132 |
""" |
|
133 |
if type(fdecls) != type(tuple()): |
|
134 |
res = "" |
|
135 |
for Paramname, ParamTypes in fdecls.iteritems(): |
|
136 |
if do_il: |
|
137 |
res += """ |
|
138 |
{""" |
|
139 |
if not do_type_search_only: |
|
140 |
res += """ |
|
141 |
/* Get the value from a foo(<param_name> = <param_value>) style call */ |
|
142 |
symbol_c *%(input_name)s_param_value = &this->default_variable_name; |
|
143 |
"""%{"input_name":Paramname} |
|
144 |
res += """ |
|
145 |
symbol_c *%(input_name)s_type_symbol = param_data_type; |
|
146 |
last_type_symbol = param_data_type; |
|
147 |
"""%{"input_name":Paramname} |
|
148 |
else: |
|
149 |
res += """ |
|
150 |
{ |
|
151 |
identifier_c param_name("%(input_name)s"); |
|
152 |
/* Get the value from a foo(<param_name> = <param_value>) style call */ |
|
153 |
symbol_c *%(input_name)s_param_value = function_call_param_iterator.search(¶m_name); |
|
154 |
||
155 |
/* Get the value from a foo(<param_value>) style call */ |
|
156 |
if (%(input_name)s_param_value == NULL) |
|
157 |
%(input_name)s_param_value = function_call_param_iterator.next(); |
|
158 |
symbol_c *%(input_name)s_type_symbol = search_expression_type->get_type(%(input_name)s_param_value); |
|
159 |
last_type_symbol = last_type_symbol && search_expression_type->is_same_type(%(input_name)s_type_symbol, last_type_symbol) ? search_expression_type->common_type(%(input_name)s_type_symbol, last_type_symbol) : %(input_name)s_type_symbol ; |
|
160 |
"""%{"input_name":Paramname} |
|
284 | 161 |
|
25 | 162 |
for ParamType,NextParamDecl in ParamTypes.iteritems(): |
163 |
||
164 |
res += """ |
|
165 |
%(type_test)s |
|
166 |
{ |
|
167 |
%(if_good_type_code)s |
|
168 |
} |
|
169 |
"""%{ |
|
170 |
"type_test":ANY_to_compiler_test_type_GEN(ParamType,Paramname), |
|
171 |
"if_good_type_code":recurse_and_indent(NextParamDecl,indent,do_type_search_only).replace('\n','\n ')} |
|
172 |
||
173 |
res += """ |
|
284 | 174 |
|
25 | 175 |
ERROR; |
176 |
} |
|
177 |
""" |
|
178 |
||
179 |
return res.replace('\n','\n'+indent) |
|
180 |
else: |
|
181 |
res = "\n" |
|
182 |
fdecl=fdecls[0] |
|
183 |
||
284 | 184 |
if not do_type_search_only: |
185 |
code_gen = eval(fdecl["python_eval_c_code_format"]) |
|
186 |
||
187 |
if code_gen[1] is not None: |
|
188 |
res += "function_name = (symbol_c*)(new pragma_c(\"%s\"));\n"%code_gen[1] |
|
189 |
if fdecl["extensible"]: |
|
190 |
res += """ |
|
291
e580c945c62a
Bug with standard functions nb_params count on Windows fixed
lbessard
parents:
284
diff
changeset
|
191 |
char* nb_param_str = new char[10]; |
284 | 192 |
sprintf(nb_param_str, "%d", nb_param); |
291
e580c945c62a
Bug with standard functions nb_params count on Windows fixed
lbessard
parents:
284
diff
changeset
|
193 |
ADD_PARAM_LIST((symbol_c*)(new integer_c((const char *)nb_param_str)), (symbol_c*)(new int_type_name_c()), function_param_iterator_c::direction_in) |
284 | 194 |
""" |
195 |
for paramname,paramtype,unused in fdecl["inputs"]: |
|
196 |
res += "ADD_PARAM_LIST(%(input_name)s_param_value, %(input_name)s_type_symbol, function_param_iterator_c::direction_in)\n"%{"input_name" : paramname} |
|
197 |
||
198 |
if fdecl["extensible"]: |
|
199 |
res += """ |
|
200 |
int base_num = %d; |
|
201 |
symbol_c *param_value = NULL; |
|
202 |
do{ |
|
203 |
char my_name[10]; |
|
204 |
sprintf(my_name, "IN%%d", base_num++); |
|
205 |
identifier_c param_name(my_name); |
|
206 |
||
207 |
/* Get the value from a foo(<param_name> = <param_value>) style call */ |
|
208 |
param_value = function_call_param_iterator.search(¶m_name); |
|
209 |
||
210 |
/* Get the value from a foo(<param_value>) style call */ |
|
211 |
if (param_value == NULL) |
|
212 |
param_value = function_call_param_iterator.next(); |
|
213 |
if (param_value != NULL){ |
|
214 |
symbol_c *current_type_symbol = search_expression_type->get_type(param_value); |
|
215 |
last_type_symbol = last_type_symbol && search_expression_type->is_same_type(current_type_symbol, last_type_symbol) ? search_expression_type->common_type(current_type_symbol, last_type_symbol) : current_type_symbol ; |
|
216 |
||
217 |
/*Function specific CODE */ |
|
218 |
ADD_PARAM_LIST(param_value, current_type_symbol, function_param_iterator_c::direction_in) |
|
219 |
} |
|
220 |
||
221 |
}while(param_value != NULL); |
|
222 |
"""%(fdecl["baseinputnumber"] + 2) |
|
223 |
||
25 | 224 |
result_type_rule = fdecl["return_type_rule"] |
225 |
res += { |
|
226 |
"copy_input" : "symbol_c * return_type_symbol = last_type_symbol;\n", |
|
227 |
"defined" : "symbol_c * return_type_symbol = &search_constant_type_c::%s_type_name;\n"%fdecl["outputs"][0][1].lower(), |
|
228 |
}.get(result_type_rule, "symbol_c * return_type_symbol = %s;\n"%result_type_rule) |
|
229 |
||
230 |
if not do_type_search_only: |
|
284 | 231 |
if code_gen[0] is not None: |
232 |
res += "function_type_prefix = %s;\n"%{"return_type" : "return_type_symbol"}.get(code_gen[0], "(symbol_c*)(new pragma_c(\"%s\"))"%code_gen[0]) |
|
233 |
if code_gen[2] is not None: |
|
234 |
res += "function_type_suffix = %s_symbol;\n"%{"common_type" : "last_type"}.get(code_gen[2], code_gen[2]) |
|
235 |
res += "break;\n" |
|
25 | 236 |
else: |
237 |
res += "return return_type_symbol;\n" |
|
238 |
||
239 |
return res.replace('\n','\n'+indent) |
|
240 |
||
241 |
################################################################### |
|
242 |
### ### |
|
243 |
### MAIN ### |
|
244 |
### ### |
|
245 |
################################################################### |
|
246 |
||
247 |
""" |
|
248 |
Reorganize std_decl from structure.py |
|
249 |
into a nested dictionnary structure (i.e. a tree): |
|
250 |
"{fname : {IN[0]paramname : {IN[0]paramtype : {IN[1]paraname : {IN[1]paramtype : {... : {IN[N]paraname : {IN[N]paramtype : (fdecl,)}}}}}}" |
|
251 |
Keep ptrack of original declaration order in a |
|
252 |
separated list called official_order |
|
253 |
""" |
|
254 |
std_fdecls = {} |
|
255 |
official_order = [] |
|
256 |
for section in std_decl: |
|
257 |
for fdecl in section["list"]: |
|
258 |
if len(official_order)==0 or official_order[-1] != fdecl["name"]: |
|
259 |
official_order.append(fdecl["name"]) |
|
260 |
# store all func by name in a dict |
|
261 |
std_fdecls_fdecl_name = std_fdecls.get(fdecl["name"], {}) |
|
262 |
current = std_fdecls_fdecl_name |
|
263 |
for i in fdecl["inputs"]: |
|
264 |
current[i[0]] = current.get(i[0], {}) |
|
265 |
current = current[i[0]] |
|
266 |
last = current |
|
267 |
current[i[1]] = current.get(i[1], {}) |
|
268 |
current = current[i[1]] |
|
269 |
last[i[1]]=(fdecl,) |
|
270 |
std_fdecls[fdecl["name"]] = std_fdecls_fdecl_name |
|
271 |
||
272 |
################################################################### |
|
273 |
||
274 |
""" |
|
275 |
Generate the long enumeration of std function types |
|
276 |
""" |
|
58 | 277 |
function_type_decl = matiec_header + """ |
25 | 278 |
typedef enum { |
279 |
""" |
|
280 |
for fname, fdecls in [ (fname,std_fdecls[fname]) for fname in official_order ]: |
|
281 |
function_type_decl += " function_"+fname.lower()+",\n" |
|
282 |
||
283 |
function_type_decl += """ function_none |
|
284 |
} function_type_t; |
|
285 |
""" |
|
286 |
################################################################### |
|
287 |
""" |
|
288 |
Generate the funct that return enumerated according function name |
|
289 |
""" |
|
58 | 290 |
get_function_type_decl = matiec_header + """ |
25 | 291 |
function_type_t get_function_type(identifier_c *function_name) { |
292 |
""" |
|
293 |
for fname, fdecls in [ (fname,std_fdecls[fname]) for fname in official_order ]: |
|
294 |
get_function_type_decl += """ |
|
295 |
if (!strcasecmp(function_name->value, "%s")) |
|
296 |
return function_%s; |
|
297 |
"""%(fname,fname.lower()) |
|
298 |
||
299 |
get_function_type_decl += """ |
|
300 |
else return function_none; |
|
301 |
} |
|
302 |
||
303 |
""" |
|
304 |
################################################################### |
|
305 |
""" |
|
115 | 306 |
Generate the part of generate_c_st_c::visit(function_invocation) |
25 | 307 |
that is responsible to generate C code for std lib calls. |
308 |
""" |
|
58 | 309 |
st_code_gen = matiec_header + """ |
25 | 310 |
switch(current_function_type){ |
311 |
""" |
|
312 |
||
313 |
for fname, fdecls in [ (fname,std_fdecls[fname]) for fname in official_order ]: |
|
314 |
st_code_gen += """ |
|
315 |
/**** |
|
316 |
*%s |
|
317 |
*/ |
|
318 |
case function_%s : |
|
319 |
{ |
|
320 |
symbol_c *last_type_symbol = NULL; |
|
321 |
""" %(fname, fname.lower()) |
|
322 |
indent = " " |
|
323 |
||
324 |
st_code_gen += recurse_and_indent(fdecls, indent).replace('\n','\n ') |
|
325 |
||
326 |
st_code_gen += """ |
|
327 |
}/*function_%s*/ |
|
328 |
break; |
|
329 |
""" %(fname.lower()) |
|
330 |
st_code_gen += """ |
|
331 |
case function_none : |
|
332 |
ERROR; |
|
333 |
} |
|
334 |
""" |
|
335 |
||
336 |
################################################################### |
|
337 |
""" |
|
115 | 338 |
Generate the part of generate_c_il_c::visit(il_function_call) |
25 | 339 |
that is responsible to generate C code for std lib calls. |
340 |
""" |
|
58 | 341 |
il_code_gen = matiec_header + """ |
25 | 342 |
switch(current_function_type){ |
343 |
""" |
|
344 |
||
345 |
for fname, fdecls in [ (fname,std_fdecls[fname]) for fname in official_order ]: |
|
346 |
il_code_gen += """ |
|
347 |
/**** |
|
348 |
*%s |
|
349 |
*/ |
|
350 |
case function_%s : |
|
351 |
{ |
|
352 |
symbol_c *last_type_symbol = NULL; |
|
353 |
""" %(fname, fname.lower()) |
|
354 |
indent = " " |
|
355 |
||
356 |
il_code_gen += recurse_and_indent(fdecls, indent, do_il=True).replace('\n','\n ') |
|
357 |
||
358 |
il_code_gen += """ |
|
359 |
}/*function_%s*/ |
|
360 |
break; |
|
361 |
""" %(fname.lower()) |
|
362 |
il_code_gen += """ |
|
363 |
case function_none : |
|
364 |
ERROR; |
|
365 |
} |
|
366 |
""" |
|
367 |
||
368 |
################################################################### |
|
369 |
""" |
|
370 |
Generate the part of search_expression_type_c::visit(function_invocation) |
|
371 |
that is responsible of returning type symbol for function invocation. |
|
372 |
""" |
|
59 | 373 |
search_type_code = matiec_header + """ |
25 | 374 |
|
284 | 375 |
void *compute_standard_function_default(function_invocation_c *st_symbol = NULL, il_formal_funct_call_c *il_symbol = NULL) { |
376 |
function_type_t current_function_type; |
|
377 |
function_call_param_iterator_c *tmp_function_call_param_iterator; |
|
378 |
if (st_symbol != NULL && il_symbol == NULL) { |
|
379 |
current_function_type = get_function_type((identifier_c *)st_symbol->function_name); |
|
380 |
tmp_function_call_param_iterator = new function_call_param_iterator_c(st_symbol); |
|
381 |
} |
|
382 |
else if (st_symbol == NULL && il_symbol != NULL) { |
|
383 |
current_function_type = get_function_type((identifier_c *)il_symbol->function_name); |
|
384 |
tmp_function_call_param_iterator = new function_call_param_iterator_c(il_symbol); |
|
385 |
} |
|
386 |
else |
|
387 |
ERROR; |
|
388 |
function_call_param_iterator_c function_call_param_iterator(*tmp_function_call_param_iterator); |
|
25 | 389 |
search_expression_type_c* search_expression_type = this; |
390 |
||
391 |
switch(current_function_type){ |
|
392 |
""" |
|
393 |
||
394 |
for fname, fdecls in [ (fname,std_fdecls[fname]) for fname in official_order ]: |
|
395 |
search_type_code += """ |
|
396 |
/**** |
|
397 |
*%s |
|
398 |
*/ |
|
399 |
case function_%s : |
|
400 |
{ |
|
401 |
symbol_c *last_type_symbol = NULL; |
|
402 |
""" %(fname, fname.lower()) |
|
403 |
indent = " " |
|
404 |
||
405 |
search_type_code += recurse_and_indent(fdecls, indent, True).replace('\n','\n ') |
|
406 |
||
407 |
search_type_code += """ |
|
408 |
}/*function_%s*/ |
|
409 |
break; |
|
410 |
""" %(fname.lower()) |
|
411 |
search_type_code += """ |
|
412 |
case function_none : |
|
413 |
ERROR; |
|
414 |
} |
|
415 |
return NULL; |
|
416 |
} |
|
417 |
||
418 |
void *compute_standard_function_il(il_function_call_c *symbol, symbol_c *param_data_type) { |
|
419 |
||
420 |
function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name); |
|
421 |
function_call_param_iterator_c function_call_param_iterator(symbol); |
|
422 |
search_expression_type_c* search_expression_type = this; |
|
423 |
||
424 |
switch(current_function_type){ |
|
425 |
""" |
|
426 |
||
427 |
for fname, fdecls in [ (fname,std_fdecls[fname]) for fname in official_order ]: |
|
428 |
search_type_code += """ |
|
429 |
/**** |
|
430 |
*%s |
|
431 |
*/ |
|
432 |
case function_%s : |
|
433 |
{ |
|
434 |
symbol_c *last_type_symbol = NULL; |
|
435 |
""" %(fname, fname.lower()) |
|
436 |
indent = " " |
|
437 |
||
438 |
search_type_code += recurse_and_indent(fdecls, indent, True, True).replace('\n','\n ') |
|
439 |
||
440 |
search_type_code += """ |
|
441 |
}/*function_%s*/ |
|
442 |
break; |
|
443 |
""" %(fname.lower()) |
|
444 |
search_type_code += """ |
|
445 |
case function_none : |
|
446 |
ERROR; |
|
447 |
} |
|
448 |
return NULL; |
|
449 |
} |
|
450 |
""" |
|
451 |
||
452 |
################################################################### |
|
453 |
################################################################### |
|
454 |
################################################################### |
|
455 |
""" |
|
36
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
456 |
Generate the standard_function_names[] for inclusion in bizon generated code |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
457 |
""" |
59 | 458 |
standard_function_names = matiec_header + """ |
36
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
459 |
const char *standard_function_names[] = { |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
460 |
""" |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
461 |
for fname, fdecls in [ (fname,std_fdecls[fname]) for fname in official_order ]: |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
462 |
standard_function_names += "\""+fname+"\",\n" |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
463 |
standard_function_names += """ |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
464 |
/* end of array marker! Do not remove! */ |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
465 |
NULL |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
466 |
}; |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
467 |
|
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
468 |
""" |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
469 |
|
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
470 |
################################################################### |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
471 |
################################################################### |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
472 |
################################################################### |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
473 |
""" |
25 | 474 |
Generate the C implementation of the IEC standard function library. |
475 |
""" |
|
59 | 476 |
iec_std_lib_generated = matiec_lesser_header + """ |
25 | 477 |
|
478 |
/* Macro that expand to subtypes */ |
|
479 |
""" |
|
480 |
for typename, parenttypename in TypeHierarchy_list: |
|
481 |
if (typename.startswith("ANY")): |
|
482 |
iec_std_lib_generated += "#define " + typename + "(DO)" |
|
483 |
for typename2, parenttypename2 in TypeHierarchy_list: |
|
484 |
if(parenttypename2 == typename): |
|
485 |
if(typename2.startswith("ANY")): |
|
486 |
iec_std_lib_generated += " " + typename2 + "(DO)" |
|
487 |
else: |
|
488 |
iec_std_lib_generated += " DO(" + typename2 + ")" |
|
489 |
iec_std_lib_generated += "\n" |
|
490 |
else: |
|
491 |
break |
|
492 |
||
493 |
# Now, print that out, or write to files from sys.argv |
|
36
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
494 |
for path, name, ext in [ |
115 | 495 |
('stage4/generate_c','function_type_decl','h'), |
496 |
('stage4/generate_c','get_function_type_decl','c'), |
|
497 |
('stage4/generate_c','st_code_gen','c'), |
|
498 |
('stage4/generate_c','il_code_gen','c'), |
|
499 |
('stage4/generate_c','search_type_code','c'), |
|
36
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
500 |
('stage1_2','standard_function_names','c'), |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
501 |
('lib', 'iec_std_lib_generated','h') |
26
36d378bd852e
Stage4 changes according to new STD lib implementation
etisserant
parents:
25
diff
changeset
|
502 |
]: |
36
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
503 |
fd = open(os.path.join(sys.argv[1], path, name+'.'+ext),'w') |
25 | 504 |
fd.write(eval(name)) |
505 |
fd.close() |
|
36
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
506 |
|
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
507 |
#print "/* Code to eventually paste in iec_std_lib.h if type hierarchy changed */" |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
508 |
#print "/* you also have to change iec_std_lib.h according to new types */\n\n" |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
509 |
#print iec_std_lib_generated |