22 #License along with this library; if not, write to the Free Software |
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 |
23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
24 |
24 |
25 """ |
25 """ |
26 |
26 |
27 THIS CODE GENARATES C++ CODE FOR IEC2CC COMPILER |
27 THIS CODE GENARATES C++ CODE FOR IEC2C COMPILER |
28 GENERATED CODE IS : |
28 GENERATED CODE IS : |
29 |
29 |
30 function_type_decl.h - the long enumeration of std function types |
30 function_type_decl.h - the long enumeration of std function types |
31 get_function_type_decl.c - the funct that return enumerated according function name |
31 get_function_type_decl.c - the funct that return enumerated according function name |
32 st_code_gen.c - part of generate_cc_st_c::visit(function_invocation) |
32 st_code_gen.c - part of generate_c_st_c::visit(function_invocation) |
33 responsible to generate C code for std lib calls |
33 responsible to generate C code for std lib calls |
34 il_code_gen.c - part of generate_cc_il_c::visit(il_function_call) |
34 il_code_gen.c - part of generate_c_il_c::visit(il_function_call) |
35 responsible to generate C code for std lib calls |
35 responsible to generate C code for std lib calls |
36 search_type_code.c - called by search_expression_type_c::visit(function_invocation) |
36 search_type_code.c - called by search_expression_type_c::visit(function_invocation) |
37 return type symbol for std function invocation |
37 return type symbol for std function invocation |
38 |
38 |
39 """ |
39 """ |
96 |
96 |
97 """ |
97 """ |
98 |
98 |
99 def ANY_to_compiler_test_type_GEN(typename, paramname): |
99 def ANY_to_compiler_test_type_GEN(typename, paramname): |
100 """ |
100 """ |
101 Convert ANY_XXX IEC type declaration into IEC2CC's generated type test. |
101 Convert ANY_XXX IEC type declaration into IEC2C's generated type test. |
102 This tests are defined in search_expression_type.cc |
102 This tests are defined in search_expression_type.cc |
103 """ |
103 """ |
104 return {"ANY" : "", |
104 return {"ANY" : "", |
105 "ANY_BIT" : "if(search_expression_type->is_binary_type(%(paramname)s_type_symbol))", |
105 "ANY_BIT" : "if(search_expression_type->is_binary_type(%(paramname)s_type_symbol))", |
106 "ANY_NBIT" : "if(search_expression_type->is_nbinary_type(%(paramname)s_type_symbol))", |
106 "ANY_NBIT" : "if(search_expression_type->is_nbinary_type(%(paramname)s_type_symbol))", |
312 } |
312 } |
313 |
313 |
314 """ |
314 """ |
315 ################################################################### |
315 ################################################################### |
316 """ |
316 """ |
317 Generate the part of generate_cc_st_c::visit(function_invocation) |
317 Generate the part of generate_c_st_c::visit(function_invocation) |
318 that is responsible to generate C code for std lib calls. |
318 that is responsible to generate C code for std lib calls. |
319 """ |
319 """ |
320 st_code_gen = matiec_header + """ |
320 st_code_gen = matiec_header + """ |
321 /**** |
321 /**** |
322 * IEC 61131-3 standard function lib |
322 * IEC 61131-3 standard function lib |
349 return NULL; |
349 return NULL; |
350 """ |
350 """ |
351 |
351 |
352 ################################################################### |
352 ################################################################### |
353 """ |
353 """ |
354 Generate the part of generate_cc_il_c::visit(il_function_call) |
354 Generate the part of generate_c_il_c::visit(il_function_call) |
355 that is responsible to generate C code for std lib calls. |
355 that is responsible to generate C code for std lib calls. |
356 """ |
356 """ |
357 il_code_gen = matiec_header + """ |
357 il_code_gen = matiec_header + """ |
358 /**** |
358 /**** |
359 * IEC 61131-3 standard function lib |
359 * IEC 61131-3 standard function lib |
518 print "Usage: " + sys.argv[0] + "path_name\n -> create files in path_name" |
518 print "Usage: " + sys.argv[0] + "path_name\n -> create files in path_name" |
519 sys.exit(0) |
519 sys.exit(0) |
520 |
520 |
521 # Now, print that out, or write to files from sys.argv |
521 # Now, print that out, or write to files from sys.argv |
522 for path, name, ext in [ |
522 for path, name, ext in [ |
523 ('stage4/generate_cc','function_type_decl','h'), |
523 ('stage4/generate_c','function_type_decl','h'), |
524 ('stage4/generate_cc','get_function_type_decl','c'), |
524 ('stage4/generate_c','get_function_type_decl','c'), |
525 ('stage4/generate_cc','st_code_gen','c'), |
525 ('stage4/generate_c','st_code_gen','c'), |
526 ('stage4/generate_cc','il_code_gen','c'), |
526 ('stage4/generate_c','il_code_gen','c'), |
527 ('stage4/generate_cc','search_type_code','c'), |
527 ('stage4/generate_c','search_type_code','c'), |
528 ('stage1_2','standard_function_names','c'), |
528 ('stage1_2','standard_function_names','c'), |
529 ('lib', 'iec_std_lib_generated','h') |
529 ('lib', 'iec_std_lib_generated','h') |
530 ]: |
530 ]: |
531 fd = open(os.path.join(sys.argv[1], path, name+'.'+ext),'w') |
531 fd = open(os.path.join(sys.argv[1], path, name+'.'+ext),'w') |
532 fd.write(eval(name)) |
532 fd.write(eval(name)) |