equal
deleted
inserted
replaced
43 |
43 |
44 #import pprint |
44 #import pprint |
45 #pp = pprint.PrettyPrinter(indent=4) |
45 #pp = pprint.PrettyPrinter(indent=4) |
46 |
46 |
47 matiec_header = """/* |
47 matiec_header = """/* |
48 * (c) 2003 Mario de Sousa |
48 * (c) 2008 Edouard TISSERANT |
49 * |
49 * |
50 * Offered to the public under the terms of the GNU General Public License |
50 * Offered to the public under the terms of the GNU General Public License |
51 * as published by the Free Software Foundation; either version 2 of the |
51 * as published by the Free Software Foundation; either version 2 of the |
52 * License, or (at your option) any later version. |
52 * License, or (at your option) any later version. |
53 * |
53 * |
65 * |
65 * |
66 * Based on the |
66 * Based on the |
67 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
67 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
68 * |
68 * |
69 */ |
69 */ |
|
70 |
|
71 /**** |
|
72 * IEC 61131-3 standard function library |
|
73 * generated code, do not edit by hand |
|
74 */ |
70 |
75 |
71 """ |
76 """ |
72 |
77 |
73 matiec_lesser_header = """/* |
78 matiec_lesser_header = """/* |
74 * (c) 2003 Mario de Sousa |
79 * (c) 2008 Edouard TISSERANT |
75 * |
80 * |
76 * Offered to the public under the terms of the GNU Lesser General Public |
81 * Offered to the public under the terms of the GNU Lesser General Public |
77 * License as published by the Free Software Foundation; either version 2 |
82 * License as published by the Free Software Foundation; either version 2 |
78 * of the License, or (at your option) any later version. |
83 * of the License, or (at your option) any later version. |
79 * |
84 * |
84 * |
89 * |
85 * This code is made available on the understanding that it will not be |
90 * This code is made available on the understanding that it will not be |
86 * used in safety-critical situations without a full and competent review. |
91 * used in safety-critical situations without a full and competent review. |
87 */ |
92 */ |
88 |
93 |
89 /* |
94 /**** |
90 * An IEC 61131-3 IL and ST compiler. |
95 * IEC 61131-3 standard function library |
91 * |
96 * generated code, do not edit by hand |
92 * Based on the |
97 */ |
93 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
98 |
94 * |
|
95 */ |
|
96 |
|
97 """ |
99 """ |
98 |
100 |
99 def ANY_to_compiler_test_type_GEN(typename, paramname): |
101 def ANY_to_compiler_test_type_GEN(typename, paramname): |
100 """ |
102 """ |
101 Convert ANY_XXX IEC type declaration into IEC2C's generated type test. |
103 Convert ANY_XXX IEC type declaration into IEC2C's generated type test. |
276 |
278 |
277 """ |
279 """ |
278 Generate the long enumeration of std function types |
280 Generate the long enumeration of std function types |
279 """ |
281 """ |
280 function_type_decl = matiec_header + """ |
282 function_type_decl = matiec_header + """ |
281 /**** |
|
282 * IEC 61131-3 standard function lib |
|
283 * generated code, do not edit by hand |
|
284 */ |
|
285 typedef enum { |
283 typedef enum { |
286 """ |
284 """ |
287 for fname, fdecls in [ (fname,std_fdecls[fname]) for fname in official_order ]: |
285 for fname, fdecls in [ (fname,std_fdecls[fname]) for fname in official_order ]: |
288 function_type_decl += " function_"+fname.lower()+",\n" |
286 function_type_decl += " function_"+fname.lower()+",\n" |
289 |
287 |
293 ################################################################### |
291 ################################################################### |
294 """ |
292 """ |
295 Generate the funct that return enumerated according function name |
293 Generate the funct that return enumerated according function name |
296 """ |
294 """ |
297 get_function_type_decl = matiec_header + """ |
295 get_function_type_decl = matiec_header + """ |
298 /**** |
|
299 * IEC 61131-3 standard function lib |
|
300 * generated code, do not edit by hand |
|
301 */ |
|
302 function_type_t get_function_type(identifier_c *function_name) { |
296 function_type_t get_function_type(identifier_c *function_name) { |
303 """ |
297 """ |
304 for fname, fdecls in [ (fname,std_fdecls[fname]) for fname in official_order ]: |
298 for fname, fdecls in [ (fname,std_fdecls[fname]) for fname in official_order ]: |
305 get_function_type_decl += """ |
299 get_function_type_decl += """ |
306 if (!strcasecmp(function_name->value, "%s")) |
300 if (!strcasecmp(function_name->value, "%s")) |
316 """ |
310 """ |
317 Generate the part of generate_c_st_c::visit(function_invocation) |
311 Generate the part of generate_c_st_c::visit(function_invocation) |
318 that is responsible to generate C code for std lib calls. |
312 that is responsible to generate C code for std lib calls. |
319 """ |
313 """ |
320 st_code_gen = matiec_header + """ |
314 st_code_gen = matiec_header + """ |
321 /**** |
|
322 * IEC 61131-3 standard function lib |
|
323 * generated code, do not edit by hand |
|
324 */ |
|
325 switch(current_function_type){ |
315 switch(current_function_type){ |
326 """ |
316 """ |
327 |
317 |
328 for fname, fdecls in [ (fname,std_fdecls[fname]) for fname in official_order ]: |
318 for fname, fdecls in [ (fname,std_fdecls[fname]) for fname in official_order ]: |
329 st_code_gen += """ |
319 st_code_gen += """ |
353 """ |
343 """ |
354 Generate the part of generate_c_il_c::visit(il_function_call) |
344 Generate the part of generate_c_il_c::visit(il_function_call) |
355 that is responsible to generate C code for std lib calls. |
345 that is responsible to generate C code for std lib calls. |
356 """ |
346 """ |
357 il_code_gen = matiec_header + """ |
347 il_code_gen = matiec_header + """ |
358 /**** |
|
359 * IEC 61131-3 standard function lib |
|
360 * generated code, do not edit by hand |
|
361 */ |
|
362 switch(current_function_type){ |
348 switch(current_function_type){ |
363 """ |
349 """ |
364 |
350 |
365 for fname, fdecls in [ (fname,std_fdecls[fname]) for fname in official_order ]: |
351 for fname, fdecls in [ (fname,std_fdecls[fname]) for fname in official_order ]: |
366 il_code_gen += """ |
352 il_code_gen += """ |
390 """ |
376 """ |
391 Generate the part of search_expression_type_c::visit(function_invocation) |
377 Generate the part of search_expression_type_c::visit(function_invocation) |
392 that is responsible of returning type symbol for function invocation. |
378 that is responsible of returning type symbol for function invocation. |
393 """ |
379 """ |
394 search_type_code = matiec_header + """ |
380 search_type_code = matiec_header + """ |
395 /**** |
|
396 * IEC 61131-3 standard function lib |
|
397 * generated code, do not edit by hand |
|
398 */ |
|
399 |
381 |
400 void *compute_standard_function_st(function_invocation_c *symbol) { |
382 void *compute_standard_function_st(function_invocation_c *symbol) { |
401 |
383 |
402 function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name); |
384 function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name); |
403 function_call_param_iterator_c function_call_param_iterator(symbol); |
385 function_call_param_iterator_c function_call_param_iterator(symbol); |
469 ################################################################### |
451 ################################################################### |
470 """ |
452 """ |
471 Generate the standard_function_names[] for inclusion in bizon generated code |
453 Generate the standard_function_names[] for inclusion in bizon generated code |
472 """ |
454 """ |
473 standard_function_names = matiec_header + """ |
455 standard_function_names = matiec_header + """ |
474 /**** |
|
475 * IEC 61131-3 standard function lib |
|
476 * generated code, do not edit by hand |
|
477 */ |
|
478 |
|
479 const char *standard_function_names[] = { |
456 const char *standard_function_names[] = { |
480 """ |
457 """ |
481 for fname, fdecls in [ (fname,std_fdecls[fname]) for fname in official_order ]: |
458 for fname, fdecls in [ (fname,std_fdecls[fname]) for fname in official_order ]: |
482 standard_function_names += "\""+fname+"\",\n" |
459 standard_function_names += "\""+fname+"\",\n" |
483 standard_function_names += """ |
460 standard_function_names += """ |
492 ################################################################### |
469 ################################################################### |
493 """ |
470 """ |
494 Generate the C implementation of the IEC standard function library. |
471 Generate the C implementation of the IEC standard function library. |
495 """ |
472 """ |
496 iec_std_lib_generated = matiec_lesser_header + """ |
473 iec_std_lib_generated = matiec_lesser_header + """ |
497 /**** |
|
498 * IEC 61131-3 standard function lib |
|
499 * generated code, do not edit by hand |
|
500 */ |
|
501 |
474 |
502 /* Macro that expand to subtypes */ |
475 /* Macro that expand to subtypes */ |
503 """ |
476 """ |
504 for typename, parenttypename in TypeHierarchy_list: |
477 for typename, parenttypename in TypeHierarchy_list: |
505 if (typename.startswith("ANY")): |
478 if (typename.startswith("ANY")): |