|
1 """ |
|
2 |
|
3 THIS CODE GENARATES C++ CODE FOR IEC2CC COMPILER |
|
4 GENERATED CODE IS : |
|
5 |
|
6 function_type_decl.h - the long enumeration of std function types |
|
7 get_function_type_decl.c - the funct that return enumerated according function name |
|
8 st_code_gen.c - part of generate_cc_st_c::visit(function_invocation) |
|
9 responsible to generate C code for std lib calls |
|
10 il_code_gen.c - part of generate_cc_il_c::visit(il_function_call) |
|
11 responsible to generate C code for std lib calls |
|
12 search_type_code.c - called by search_expression_type_c::visit(function_invocation) |
|
13 return type symbol for std function invocation |
|
14 |
|
15 """ |
|
16 |
1 # Get definitions |
17 # Get definitions |
2 from plcopen.structures import * |
18 from plcopen.structures import * |
3 |
19 |
4 #import pprint |
20 #import pprint |
5 #pp = pprint.PrettyPrinter(indent=4) |
21 #pp = pprint.PrettyPrinter(indent=4) |
371 |
387 |
372 ################################################################### |
388 ################################################################### |
373 ################################################################### |
389 ################################################################### |
374 ################################################################### |
390 ################################################################### |
375 """ |
391 """ |
|
392 Generate the standard_function_names[] for inclusion in bizon generated code |
|
393 """ |
|
394 standard_function_names = """ |
|
395 /**** |
|
396 * IEC 61131-3 standard function lib |
|
397 * generated code, do not edit by hand |
|
398 */ |
|
399 |
|
400 const char *standard_function_names[] = { |
|
401 """ |
|
402 for fname, fdecls in [ (fname,std_fdecls[fname]) for fname in official_order ]: |
|
403 standard_function_names += "\""+fname+"\",\n" |
|
404 standard_function_names += """ |
|
405 /* end of array marker! Do not remove! */ |
|
406 NULL |
|
407 }; |
|
408 |
|
409 """ |
|
410 |
|
411 ################################################################### |
|
412 ################################################################### |
|
413 ################################################################### |
|
414 """ |
376 Generate the C implementation of the IEC standard function library. |
415 Generate the C implementation of the IEC standard function library. |
377 """ |
416 """ |
378 iec_std_lib_generated = """ |
417 iec_std_lib_generated = """ |
379 /**** |
418 /**** |
380 * IEC 61131-3 standard function lib |
419 * IEC 61131-3 standard function lib |
399 if len(sys.argv) != 2 : |
438 if len(sys.argv) != 2 : |
400 print "Usage: " + sys.argv[0] + "path_name\n -> create files in path_name" |
439 print "Usage: " + sys.argv[0] + "path_name\n -> create files in path_name" |
401 sys.exit(0) |
440 sys.exit(0) |
402 |
441 |
403 # Now, print that out, or write to files from sys.argv |
442 # Now, print that out, or write to files from sys.argv |
404 for name, ext in [ |
443 for path, name, ext in [ |
405 ('function_type_decl','h'), |
444 ('stage4/generate_cc','function_type_decl','h'), |
406 ('get_function_type_decl','c'), |
445 ('stage4/generate_cc','get_function_type_decl','c'), |
407 ('st_code_gen','c'), |
446 ('stage4/generate_cc','st_code_gen','c'), |
408 ('il_code_gen','c'), |
447 ('stage4/generate_cc','il_code_gen','c'), |
409 ('search_type_code','c')#, |
448 ('stage4/generate_cc','search_type_code','c'), |
410 #('iec_std_lib_generated','h') |
449 ('stage1_2','standard_function_names','c'), |
|
450 ('lib', 'iec_std_lib_generated','h') |
411 ]: |
451 ]: |
412 fd = open(os.path.join(sys.argv[1],name+'.'+ext),'w') |
452 fd = open(os.path.join(sys.argv[1], path, name+'.'+ext),'w') |
413 fd.write(eval(name)) |
453 fd.write(eval(name)) |
414 fd.close() |
454 fd.close() |
|
455 |
|
456 #print "/* Code to eventually paste in iec_std_lib.h if type hierarchy changed */" |
|
457 #print "/* you also have to change iec_std_lib.h according to new types */\n\n" |
|
458 #print iec_std_lib_generated |