author | etisserant |
Sat, 21 Jul 2007 01:17:02 +0200 | |
changeset 52 | 35b54852c533 |
parent 43 | 4a7e80513edd |
child 58 | 39cd981ff242 |
permissions | -rw-r--r-- |
36
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
1 |
""" |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
2 |
|
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
3 |
THIS CODE GENARATES C++ CODE FOR IEC2CC COMPILER |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
4 |
GENERATED CODE IS : |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
5 |
|
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
6 |
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
|
7 |
get_function_type_decl.c - the funct that return enumerated according function name |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
8 |
st_code_gen.c - part of generate_cc_st_c::visit(function_invocation) |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
9 |
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
|
10 |
il_code_gen.c - part of generate_cc_il_c::visit(il_function_call) |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
11 |
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
|
12 |
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
|
13 |
return type symbol for std function invocation |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
14 |
|
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
15 |
""" |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
16 |
|
25 | 17 |
# Get definitions |
18 |
from plcopen.structures import * |
|
19 |
||
20 |
#import pprint |
|
21 |
#pp = pprint.PrettyPrinter(indent=4) |
|
22 |
||
23 |
def ANY_to_compiler_test_type_GEN(typename, paramname): |
|
24 |
""" |
|
25 |
Convert ANY_XXX IEC type declaration into IEC2CC's generated type test. |
|
26 |
This tests are defined in search_expression_type.cc |
|
27 |
""" |
|
28 |
return {"ANY" : "", |
|
29 |
"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
|
30 |
"ANY_NBIT" : "if(search_expression_type->is_nbinary_type(%(paramname)s_type_symbol))", |
25 | 31 |
"ANY_NUM" : "if(search_expression_type->is_num_type(%(paramname)s_type_symbol))", |
32 |
"ANY_REAL" : "if(search_expression_type->is_real_type(%(paramname)s_type_symbol))", |
|
33 |
"ANY_INT" : "if(search_expression_type->is_integer_type(%(paramname)s_type_symbol))" |
|
34 |
}.get(typename, |
|
40 | 35 |
#"if (typeid(*last_type_symbol) == typeid(%(typename)s_type_name_c))")%{ |
36 |
"if(search_expression_type->is_same_type(&search_constant_type_c::%(typename)s_type_name, last_type_symbol))")%{ |
|
25 | 37 |
"paramname" : paramname, "typename": typename.lower()} |
38 |
||
39 |
def recurse_and_indent(fdecls, indent, do_type_search_only = False, do_il = False): |
|
40 |
""" |
|
41 |
This function generate visit(function_invocation) code for |
|
42 |
- ST code generator |
|
43 |
- IL code generator |
|
44 |
- search_expression_type class for ST |
|
45 |
- search_expression_type class for IL |
|
46 |
||
47 |
Input data is a |
|
48 |
"{fname : {IN[0]paramname : {IN[0]paramtype : {IN[1]paraname : {IN[1]paramtype : {... : {IN[N]paraname : {IN[N]paramtype : (fdecl,)}}}}}}" |
|
49 |
nested dictionary structure. |
|
50 |
""" |
|
51 |
if type(fdecls) != type(tuple()): |
|
52 |
res = "" |
|
53 |
for Paramname, ParamTypes in fdecls.iteritems(): |
|
54 |
if do_il: |
|
55 |
res += """ |
|
56 |
{""" |
|
57 |
if not do_type_search_only: |
|
58 |
res += """ |
|
59 |
/* Get the value from a foo(<param_name> = <param_value>) style call */ |
|
60 |
symbol_c *%(input_name)s_param_value = &this->default_variable_name; |
|
61 |
"""%{"input_name":Paramname} |
|
62 |
res += """ |
|
63 |
symbol_c *%(input_name)s_type_symbol = param_data_type; |
|
64 |
last_type_symbol = param_data_type; |
|
65 |
"""%{"input_name":Paramname} |
|
66 |
else: |
|
67 |
res += """ |
|
68 |
{ |
|
69 |
identifier_c param_name("%(input_name)s"); |
|
70 |
/* Get the value from a foo(<param_name> = <param_value>) style call */ |
|
71 |
symbol_c *%(input_name)s_param_value = function_call_param_iterator.search(¶m_name); |
|
72 |
||
73 |
/* Get the value from a foo(<param_value>) style call */ |
|
74 |
if (%(input_name)s_param_value == NULL) |
|
75 |
%(input_name)s_param_value = function_call_param_iterator.next(); |
|
76 |
symbol_c *%(input_name)s_type_symbol = search_expression_type->get_type(%(input_name)s_param_value); |
|
77 |
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 ; |
|
78 |
"""%{"input_name":Paramname} |
|
79 |
||
80 |
for ParamType,NextParamDecl in ParamTypes.iteritems(): |
|
81 |
||
82 |
res += """ |
|
83 |
%(type_test)s |
|
84 |
{ |
|
85 |
%(if_good_type_code)s |
|
86 |
} |
|
87 |
"""%{ |
|
88 |
"type_test":ANY_to_compiler_test_type_GEN(ParamType,Paramname), |
|
89 |
"if_good_type_code":recurse_and_indent(NextParamDecl,indent,do_type_search_only).replace('\n','\n ')} |
|
90 |
||
91 |
res += """ |
|
92 |
ERROR; |
|
93 |
} |
|
94 |
""" |
|
95 |
||
96 |
return res.replace('\n','\n'+indent) |
|
97 |
else: |
|
98 |
res = "\n" |
|
99 |
fdecl=fdecls[0] |
|
100 |
||
101 |
result_type_rule = fdecl["return_type_rule"] |
|
102 |
res += { |
|
103 |
"copy_input" : "symbol_c * return_type_symbol = last_type_symbol;\n", |
|
104 |
"defined" : "symbol_c * return_type_symbol = &search_constant_type_c::%s_type_name;\n"%fdecl["outputs"][0][1].lower(), |
|
105 |
}.get(result_type_rule, "symbol_c * return_type_symbol = %s;\n"%result_type_rule) |
|
106 |
||
107 |
if not do_type_search_only: |
|
108 |
code_gen = eval(fdecl["python_eval_c_code_format"]) |
|
109 |
||
110 |
code_gen_dic_decl = {} |
|
111 |
for paramname,paramtype,unused in fdecl["inputs"]: |
|
112 |
code_gen_dic_decl[paramname+"_value"] = '");\n%s_param_value->accept(*this);\ns4o.print("'%(paramname) |
|
113 |
code_gen_dic_decl[paramname+"_type"] = '");\n%s_type_symbol->accept(*this);\ns4o.print("'%(paramname) |
|
114 |
code_gen_dic_decl["return_type"] = '");\nreturn_type_symbol->accept(*this);\ns4o.print("' |
|
115 |
code_gen_dic_decl["param_count"] = '");\ns4o.print_integer(nb_param);\ns4o.print("' |
|
43 | 116 |
code_gen_dic_decl["common_type"] = '");\nlast_type_symbol->accept(*this);\ns4o.print("' |
25 | 117 |
code_gen_dic_decl["start_bool_filter"] = '");\nif (search_expression_type->is_bool_type(last_type_symbol))\n s4o.print("(' |
118 |
code_gen_dic_decl["end_bool_filter"] = '");\nif (search_expression_type->is_bool_type(last_type_symbol)) {\n s4o.print("&1");\n s4o.print(")");\n}\ns4o.print("' |
|
119 |
||
120 |
if type(code_gen) == type(tuple()): |
|
40 | 121 |
res += 's4o.indent_right();\n' |
122 |
res += 's4o.print("%s\\n" + s4o.indent_spaces);\n'%(code_gen[0]%code_gen_dic_decl) |
|
25 | 123 |
static_param_accept_list = [] |
124 |
for paramname,paramtype,unused in fdecl["inputs"]: |
|
125 |
static_param_accept_list.append("%s_param_value->accept(*this);\n"%(paramname)) |
|
40 | 126 |
res += ('s4o.print("%s\\n" + s4o.indent_spaces);\n'%(code_gen[1])).join(static_param_accept_list) |
127 |
code = 's4o.print("%s\\n" + s4o.indent_spaces);\nparam_value->accept(*this);\n'%(code_gen[1]) |
|
128 |
end_code = 's4o.print("%s");\ns4o.indent_left();\nreturn NULL;\n'%(code_gen[2]%code_gen_dic_decl) |
|
25 | 129 |
else: |
130 |
code = '' |
|
131 |
end_code = ('s4o.print("' + code_gen%code_gen_dic_decl + '");\nreturn NULL;\n').replace('s4o.print("");\n','') |
|
132 |
||
133 |
if fdecl["extensible"]: |
|
134 |
res += (""" |
|
135 |
int base_num = %d; |
|
136 |
symbol_c *param_value = NULL; |
|
137 |
do{ |
|
138 |
char my_name[10]; |
|
139 |
sprintf(my_name, "IN%%d", base_num++); |
|
140 |
identifier_c param_name(my_name); |
|
141 |
||
142 |
/* Get the value from a foo(<param_name> = <param_value>) style call */ |
|
143 |
param_value = function_call_param_iterator.search(¶m_name); |
|
144 |
||
145 |
/* Get the value from a foo(<param_value>) style call */ |
|
146 |
if (param_value == NULL) |
|
147 |
param_value = function_call_param_iterator.next(); |
|
148 |
if (param_value != NULL){ |
|
149 |
symbol_c *current_type_symbol = search_expression_type->get_type(param_value); |
|
150 |
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 ; |
|
151 |
||
152 |
/*Function specific CODE */ |
|
153 |
%s |
|
154 |
} |
|
155 |
||
156 |
}while(param_value != NULL); |
|
157 |
%s |
|
158 |
"""%(fdecl["baseinputnumber"]+2, code.replace('\n','\n '), end_code)) |
|
159 |
else: |
|
160 |
#res += code + end_code |
|
161 |
res += end_code |
|
162 |
else: |
|
163 |
res += "return return_type_symbol;\n" |
|
164 |
||
165 |
||
166 |
return res.replace('\n','\n'+indent) |
|
167 |
||
168 |
################################################################### |
|
169 |
### ### |
|
170 |
### MAIN ### |
|
171 |
### ### |
|
172 |
################################################################### |
|
173 |
||
174 |
""" |
|
175 |
Reorganize std_decl from structure.py |
|
176 |
into a nested dictionnary structure (i.e. a tree): |
|
177 |
"{fname : {IN[0]paramname : {IN[0]paramtype : {IN[1]paraname : {IN[1]paramtype : {... : {IN[N]paraname : {IN[N]paramtype : (fdecl,)}}}}}}" |
|
178 |
Keep ptrack of original declaration order in a |
|
179 |
separated list called official_order |
|
180 |
""" |
|
181 |
std_fdecls = {} |
|
182 |
official_order = [] |
|
183 |
for section in std_decl: |
|
184 |
for fdecl in section["list"]: |
|
185 |
if len(official_order)==0 or official_order[-1] != fdecl["name"]: |
|
186 |
official_order.append(fdecl["name"]) |
|
187 |
# store all func by name in a dict |
|
188 |
std_fdecls_fdecl_name = std_fdecls.get(fdecl["name"], {}) |
|
189 |
current = std_fdecls_fdecl_name |
|
190 |
for i in fdecl["inputs"]: |
|
191 |
current[i[0]] = current.get(i[0], {}) |
|
192 |
current = current[i[0]] |
|
193 |
last = current |
|
194 |
current[i[1]] = current.get(i[1], {}) |
|
195 |
current = current[i[1]] |
|
196 |
last[i[1]]=(fdecl,) |
|
197 |
std_fdecls[fdecl["name"]] = std_fdecls_fdecl_name |
|
198 |
||
199 |
################################################################### |
|
200 |
||
201 |
""" |
|
202 |
Generate the long enumeration of std function types |
|
203 |
""" |
|
204 |
function_type_decl = """ |
|
205 |
/**** |
|
206 |
* IEC 61131-3 standard function lib |
|
207 |
* generated code, do not edit by hand |
|
208 |
*/ |
|
209 |
typedef enum { |
|
210 |
""" |
|
211 |
for fname, fdecls in [ (fname,std_fdecls[fname]) for fname in official_order ]: |
|
212 |
function_type_decl += " function_"+fname.lower()+",\n" |
|
213 |
||
214 |
function_type_decl += """ function_none |
|
215 |
} function_type_t; |
|
216 |
""" |
|
217 |
################################################################### |
|
218 |
""" |
|
219 |
Generate the funct that return enumerated according function name |
|
220 |
""" |
|
221 |
get_function_type_decl = """ |
|
222 |
/**** |
|
223 |
* IEC 61131-3 standard function lib |
|
224 |
* generated code, do not edit by hand |
|
225 |
*/ |
|
226 |
function_type_t get_function_type(identifier_c *function_name) { |
|
227 |
""" |
|
228 |
for fname, fdecls in [ (fname,std_fdecls[fname]) for fname in official_order ]: |
|
229 |
get_function_type_decl += """ |
|
230 |
if (!strcasecmp(function_name->value, "%s")) |
|
231 |
return function_%s; |
|
232 |
"""%(fname,fname.lower()) |
|
233 |
||
234 |
get_function_type_decl += """ |
|
235 |
else return function_none; |
|
236 |
} |
|
237 |
||
238 |
""" |
|
239 |
################################################################### |
|
240 |
""" |
|
241 |
Generate the part of generate_cc_st_c::visit(function_invocation) |
|
242 |
that is responsible to generate C code for std lib calls. |
|
243 |
""" |
|
244 |
st_code_gen = """ |
|
245 |
/**** |
|
246 |
* IEC 61131-3 standard function lib |
|
247 |
* generated code, do not edit by hand |
|
248 |
*/ |
|
249 |
switch(current_function_type){ |
|
250 |
""" |
|
251 |
||
252 |
for fname, fdecls in [ (fname,std_fdecls[fname]) for fname in official_order ]: |
|
253 |
st_code_gen += """ |
|
254 |
/**** |
|
255 |
*%s |
|
256 |
*/ |
|
257 |
case function_%s : |
|
258 |
{ |
|
259 |
symbol_c *last_type_symbol = NULL; |
|
260 |
""" %(fname, fname.lower()) |
|
261 |
indent = " " |
|
262 |
||
263 |
st_code_gen += recurse_and_indent(fdecls, indent).replace('\n','\n ') |
|
264 |
||
265 |
st_code_gen += """ |
|
266 |
}/*function_%s*/ |
|
267 |
break; |
|
268 |
""" %(fname.lower()) |
|
269 |
st_code_gen += """ |
|
270 |
case function_none : |
|
271 |
ERROR; |
|
272 |
} |
|
273 |
return NULL; |
|
274 |
""" |
|
275 |
||
276 |
################################################################### |
|
277 |
""" |
|
278 |
Generate the part of generate_cc_il_c::visit(il_function_call) |
|
279 |
that is responsible to generate C code for std lib calls. |
|
280 |
""" |
|
281 |
il_code_gen = """ |
|
282 |
/**** |
|
283 |
* IEC 61131-3 standard function lib |
|
284 |
* generated code, do not edit by hand |
|
285 |
*/ |
|
286 |
switch(current_function_type){ |
|
287 |
""" |
|
288 |
||
289 |
for fname, fdecls in [ (fname,std_fdecls[fname]) for fname in official_order ]: |
|
290 |
il_code_gen += """ |
|
291 |
/**** |
|
292 |
*%s |
|
293 |
*/ |
|
294 |
case function_%s : |
|
295 |
{ |
|
296 |
symbol_c *last_type_symbol = NULL; |
|
297 |
""" %(fname, fname.lower()) |
|
298 |
indent = " " |
|
299 |
||
300 |
il_code_gen += recurse_and_indent(fdecls, indent, do_il=True).replace('\n','\n ') |
|
301 |
||
302 |
il_code_gen += """ |
|
303 |
}/*function_%s*/ |
|
304 |
break; |
|
305 |
""" %(fname.lower()) |
|
306 |
il_code_gen += """ |
|
307 |
case function_none : |
|
308 |
ERROR; |
|
309 |
} |
|
310 |
return NULL; |
|
311 |
""" |
|
312 |
||
313 |
################################################################### |
|
314 |
""" |
|
315 |
Generate the part of search_expression_type_c::visit(function_invocation) |
|
316 |
that is responsible of returning type symbol for function invocation. |
|
317 |
""" |
|
318 |
search_type_code = """ |
|
319 |
/**** |
|
320 |
* IEC 61131-3 standard function lib |
|
321 |
* generated code, do not edit by hand |
|
322 |
*/ |
|
323 |
||
324 |
void *compute_standard_function_st(function_invocation_c *symbol) { |
|
325 |
||
326 |
function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name); |
|
327 |
function_call_param_iterator_c function_call_param_iterator(symbol); |
|
328 |
search_expression_type_c* search_expression_type = this; |
|
329 |
||
330 |
switch(current_function_type){ |
|
331 |
""" |
|
332 |
||
333 |
for fname, fdecls in [ (fname,std_fdecls[fname]) for fname in official_order ]: |
|
334 |
search_type_code += """ |
|
335 |
/**** |
|
336 |
*%s |
|
337 |
*/ |
|
338 |
case function_%s : |
|
339 |
{ |
|
340 |
symbol_c *last_type_symbol = NULL; |
|
341 |
""" %(fname, fname.lower()) |
|
342 |
indent = " " |
|
343 |
||
344 |
search_type_code += recurse_and_indent(fdecls, indent, True).replace('\n','\n ') |
|
345 |
||
346 |
search_type_code += """ |
|
347 |
}/*function_%s*/ |
|
348 |
break; |
|
349 |
""" %(fname.lower()) |
|
350 |
search_type_code += """ |
|
351 |
case function_none : |
|
352 |
ERROR; |
|
353 |
} |
|
354 |
return NULL; |
|
355 |
} |
|
356 |
||
357 |
void *compute_standard_function_il(il_function_call_c *symbol, symbol_c *param_data_type) { |
|
358 |
||
359 |
function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name); |
|
360 |
function_call_param_iterator_c function_call_param_iterator(symbol); |
|
361 |
search_expression_type_c* search_expression_type = this; |
|
362 |
||
363 |
switch(current_function_type){ |
|
364 |
""" |
|
365 |
||
366 |
for fname, fdecls in [ (fname,std_fdecls[fname]) for fname in official_order ]: |
|
367 |
search_type_code += """ |
|
368 |
/**** |
|
369 |
*%s |
|
370 |
*/ |
|
371 |
case function_%s : |
|
372 |
{ |
|
373 |
symbol_c *last_type_symbol = NULL; |
|
374 |
""" %(fname, fname.lower()) |
|
375 |
indent = " " |
|
376 |
||
377 |
search_type_code += recurse_and_indent(fdecls, indent, True, True).replace('\n','\n ') |
|
378 |
||
379 |
search_type_code += """ |
|
380 |
}/*function_%s*/ |
|
381 |
break; |
|
382 |
""" %(fname.lower()) |
|
383 |
search_type_code += """ |
|
384 |
case function_none : |
|
385 |
ERROR; |
|
386 |
} |
|
387 |
return NULL; |
|
388 |
} |
|
389 |
""" |
|
390 |
||
391 |
################################################################### |
|
392 |
################################################################### |
|
393 |
################################################################### |
|
394 |
""" |
|
36
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
395 |
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
|
396 |
""" |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
397 |
standard_function_names = """ |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
398 |
/**** |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
399 |
* IEC 61131-3 standard function lib |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
400 |
* generated code, do not edit by hand |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
401 |
*/ |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
402 |
|
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
403 |
const char *standard_function_names[] = { |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
404 |
""" |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
405 |
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
|
406 |
standard_function_names += "\""+fname+"\",\n" |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
407 |
standard_function_names += """ |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
408 |
/* end of array marker! Do not remove! */ |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
409 |
NULL |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
410 |
}; |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
411 |
|
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
412 |
""" |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
413 |
|
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
414 |
################################################################### |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
415 |
################################################################### |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
416 |
################################################################### |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
417 |
""" |
25 | 418 |
Generate the C implementation of the IEC standard function library. |
419 |
""" |
|
420 |
iec_std_lib_generated = """ |
|
421 |
/**** |
|
422 |
* IEC 61131-3 standard function lib |
|
423 |
* generated code, do not edit by hand |
|
424 |
*/ |
|
425 |
||
426 |
/* Macro that expand to subtypes */ |
|
427 |
""" |
|
428 |
for typename, parenttypename in TypeHierarchy_list: |
|
429 |
if (typename.startswith("ANY")): |
|
430 |
iec_std_lib_generated += "#define " + typename + "(DO)" |
|
431 |
for typename2, parenttypename2 in TypeHierarchy_list: |
|
432 |
if(parenttypename2 == typename): |
|
433 |
if(typename2.startswith("ANY")): |
|
434 |
iec_std_lib_generated += " " + typename2 + "(DO)" |
|
435 |
else: |
|
436 |
iec_std_lib_generated += " DO(" + typename2 + ")" |
|
437 |
iec_std_lib_generated += "\n" |
|
438 |
else: |
|
439 |
break |
|
440 |
||
441 |
if len(sys.argv) != 2 : |
|
442 |
print "Usage: " + sys.argv[0] + "path_name\n -> create files in path_name" |
|
443 |
sys.exit(0) |
|
444 |
||
445 |
# 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
|
446 |
for path, name, ext in [ |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
447 |
('stage4/generate_cc','function_type_decl','h'), |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
448 |
('stage4/generate_cc','get_function_type_decl','c'), |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
449 |
('stage4/generate_cc','st_code_gen','c'), |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
450 |
('stage4/generate_cc','il_code_gen','c'), |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
451 |
('stage4/generate_cc','search_type_code','c'), |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
452 |
('stage1_2','standard_function_names','c'), |
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
453 |
('lib', 'iec_std_lib_generated','h') |
26
36d378bd852e
Stage4 changes according to new STD lib implementation
etisserant
parents:
25
diff
changeset
|
454 |
]: |
36
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
455 |
fd = open(os.path.join(sys.argv[1], path, name+'.'+ext),'w') |
25 | 456 |
fd.write(eval(name)) |
457 |
fd.close() |
|
36
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
458 |
|
e7d67b27877f
Changes in the std library + std lib PLCOpen test (broken)
etisserant
parents:
26
diff
changeset
|
459 |
#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
|
460 |
#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
|
461 |
#print iec_std_lib_generated |