2 # -*- coding: utf-8 -*- |
2 # -*- coding: utf-8 -*- |
3 |
3 |
4 #This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor |
4 #This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor |
5 #based on the plcopen standard. |
5 #based on the plcopen standard. |
6 # |
6 # |
7 #Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
7 #Copyright (C) 2007-2011: Edouard TISSERANT and Laurent BESSARD |
8 # |
8 # |
9 #See COPYING file for copyrights details. |
9 #See COPYING file for copyrights details. |
10 # |
10 # |
11 #This library is free software; you can redistribute it and/or |
11 #This library is free software; you can redistribute it and/or |
12 #modify it under the terms of the GNU General Public |
12 #modify it under the terms of the GNU General Public |
21 #You should have received a copy of the GNU General Public |
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 |
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 |
|
27 THIS CODE GENARATES C++ CODE FOR IEC2C COMPILER |
26 THIS CODE GENARATES C++ CODE FOR IEC2C COMPILER |
28 GENERATED CODE IS : |
27 """ |
29 |
28 |
30 function_type_decl.h - the long enumeration of std function types |
29 file_list = [ |
31 get_function_type_decl.c - the funct that return enumerated according function name |
30 ('absyntax_utils', 'function_type_decl','h' ), |
32 st_code_gen.c - part of generate_c_st_c::visit(function_invocation) |
31 ('absyntax_utils', 'get_function_type_decl','c' ), |
33 responsible to generate C code for std lib calls |
32 ('absyntax_utils', 'search_type_code','c' ), |
34 il_code_gen.c - part of generate_c_il_c::visit(il_function_call) |
33 ('stage4/generate_c', 'st_code_gen','c' ), |
35 responsible to generate C code for std lib calls |
34 ('stage4/generate_c', 'il_code_gen','c' ), |
36 search_type_code.c - called by search_expression_type_c::visit(function_invocation) |
35 ('stage1_2', 'standard_function_names','c' ), |
37 return type symbol for std function invocation |
36 ('lib', 'iec_std_lib_generated','h' ) |
38 |
37 ] |
39 """ |
|
40 |
38 |
41 # Get definitions |
39 # Get definitions |
42 from plcopen.structures import * |
40 from plcopen.structures import * |
43 |
41 |
44 if len(sys.argv) != 2 : |
42 if len(sys.argv) != 2 : |
47 |
45 |
48 #import pprint |
46 #import pprint |
49 #pp = pprint.PrettyPrinter(indent=4) |
47 #pp = pprint.PrettyPrinter(indent=4) |
50 |
48 |
51 matiec_header = """/* |
49 matiec_header = """/* |
52 * (c) 2008 Edouard TISSERANT |
50 * Copyright (C) 2007-2011: Edouard TISSERANT and Laurent BESSARD |
53 * |
51 * |
54 * Offered to the public under the terms of the GNU General Public License |
52 * See COPYING and COPYING.LESSER files for copyright details. |
55 * as published by the Free Software Foundation; either version 2 of the |
53 * |
56 * License, or (at your option) any later version. |
54 * This program is free software: you can redistribute it and/or modify |
57 * |
55 * it under the terms of the GNU General Public License as published by |
58 * This program is distributed in the hope that it will be useful, but |
56 * the Free Software Foundation, either version 3 of the License, or |
59 * WITHOUT ANY WARRANTY; without even the implied warranty of |
57 * (at your option) any later version. |
60 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
58 * |
61 * Public License for more details. |
59 * This program is distributed in the hope that it will be useful, |
62 * |
60 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
63 * This code is made available on the understanding that it will not be |
61 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
64 * used in safety-critical situations without a full and competent review. |
62 * GNU General Public License for more details. |
65 */ |
63 * |
66 |
64 * You should have received a copy of the GNU General Public License |
67 /* |
65 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
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 * |
66 * |
73 */ |
67 */ |
74 |
68 |
75 /**** |
69 /**** |
76 * IEC 61131-3 standard function library |
70 * IEC 61131-3 standard function library |
78 */ |
72 */ |
79 |
73 |
80 """ |
74 """ |
81 |
75 |
82 matiec_lesser_header = """/* |
76 matiec_lesser_header = """/* |
83 * (c) 2008 Edouard TISSERANT |
77 * Copyright (C) 2007-2011: Edouard TISSERANT and Laurent BESSARD |
84 * |
78 * |
85 * Offered to the public under the terms of the GNU Lesser General Public |
79 * See COPYING and COPYING.LESSER files for copyright details. |
86 * License as published by the Free Software Foundation; either version 2 |
80 * |
87 * of the License, or (at your option) any later version. |
81 * This library is free software; you can redistribute it and/or |
88 * |
82 * modify it under the terms of the GNU Lesser General Public |
89 * This program is distributed in the hope that it will be useful, but |
83 * License as published by the Free Software Foundation; either |
90 * WITHOUT ANY WARRANTY; without even the implied warranty of |
84 * version 3 of the License, or (at your option) any later version. |
91 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser |
85 * |
92 * General Public License for more details. |
86 * This library is distributed in the hope that it will be useful, |
93 * |
87 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
94 * This code is made available on the understanding that it will not be |
88 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
95 * used in safety-critical situations without a full and competent review. |
89 * Lesser General Public License for more details. |
|
90 * |
|
91 * You should have received a copy of the GNU Lesser General Public License |
|
92 * along with this library. If not, see <http://www.gnu.org/licenses/>. |
|
93 * |
96 */ |
94 */ |
97 |
95 |
98 /**** |
96 /**** |
99 * IEC 61131-3 standard function library |
97 * IEC 61131-3 standard function library |
100 * generated code, do not edit by hand |
98 * generated code, do not edit by hand |
284 """ |
282 """ |
285 std_fdecls = {} |
283 std_fdecls = {} |
286 official_order = [] |
284 official_order = [] |
287 for section in std_decl: |
285 for section in std_decl: |
288 for fdecl in section["list"]: |
286 for fdecl in section["list"]: |
289 if len(official_order)==0 or official_order[-1] != fdecl["name"]: |
287 if len(official_order)==0 or fdecl["name"] not in official_order: |
290 official_order.append(fdecl["name"]) |
288 official_order.append(fdecl["name"]) |
291 # store all func by name in a dict |
289 # store all func by name in a dict |
292 std_fdecls_fdecl_name = std_fdecls.get(fdecl["name"], {}) |
290 std_fdecls_fdecl_name = std_fdecls.get(fdecl["name"], {}) |
293 current = std_fdecls_fdecl_name |
291 current = std_fdecls_fdecl_name |
294 for i in fdecl["inputs"]: |
292 for i in fdecl["inputs"]: |
520 iec_std_lib_generated += "\n" |
518 iec_std_lib_generated += "\n" |
521 else: |
519 else: |
522 break |
520 break |
523 |
521 |
524 # Now, print that out, or write to files from sys.argv |
522 # Now, print that out, or write to files from sys.argv |
525 for path, name, ext in [ |
523 for path, name, ext in file_list : |
526 ('absyntax_utils','function_type_decl','h'), |
|
527 ('absyntax_utils','get_function_type_decl','c'), |
|
528 ('stage4/generate_c','st_code_gen','c'), |
|
529 ('stage4/generate_c','il_code_gen','c'), |
|
530 ('absyntax_utils','search_type_code','c'), |
|
531 ('stage1_2','standard_function_names','c'), |
|
532 ('lib', 'iec_std_lib_generated','h') |
|
533 ]: |
|
534 fd = open(os.path.join(sys.argv[1], path, name+'.'+ext),'w') |
524 fd = open(os.path.join(sys.argv[1], path, name+'.'+ext),'w') |
535 fd.write(eval(name)) |
525 fd.write(eval(name)) |
536 fd.close() |
526 fd.close() |
537 |
527 |
538 #print "/* Code to eventually paste in iec_std_lib.h if type hierarchy changed */" |
528 #print "/* Code to eventually paste in iec_std_lib.h if type hierarchy changed */" |