|
1 /* |
|
2 * (c) 2003 Mario de Sousa |
|
3 * |
|
4 * Offered to the public under the terms of the GNU General Public License |
|
5 * as published by the Free Software Foundation; either version 2 of the |
|
6 * License, or (at your option) any later version. |
|
7 * |
|
8 * This program is distributed in the hope that it will be useful, but |
|
9 * WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
|
11 * Public License for more details. |
|
12 * |
|
13 * This code is made available on the understanding that it will not be |
|
14 * used in safety-critical situations without a full and competent review. |
|
15 */ |
|
16 |
|
17 /* |
|
18 * An IEC 61131-3 IL and ST compiler. |
|
19 * |
|
20 * Based on the |
|
21 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
|
22 * |
|
23 */ |
|
24 |
|
25 |
|
26 /* |
|
27 * Build the body of the main function (currently named run() ) |
|
28 * of the class onto which is mapped a specific CONFIGURATION. |
|
29 * |
|
30 * This is part of the 4th stage that generates |
|
31 * a c++ source program equivalent to the IL and ST |
|
32 * code. |
|
33 */ |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 // #include <stdio.h> /* required for NULL */ |
|
41 /* |
|
42 #include <string> |
|
43 #include <iostream> |
|
44 |
|
45 #include "../../util/symtable.hh" |
|
46 |
|
47 #include "../stage4.hh" |
|
48 */ |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 class generate_cc_configbody_c: public generate_cc_base_c { |
|
55 |
|
56 public: |
|
57 generate_cc_configbody_c(stage4out_c *s4o_ptr) |
|
58 : generate_cc_base_c(s4o_ptr) { |
|
59 current_resource_name = NULL; |
|
60 } |
|
61 |
|
62 virtual ~generate_cc_configbody_c(void) {} |
|
63 |
|
64 |
|
65 private: |
|
66 /* The name of the resource curretnly being processed... */ |
|
67 symbol_c *current_resource_name; |
|
68 |
|
69 |
|
70 /********************************/ |
|
71 /* B 1.7 Configuration elements */ |
|
72 /********************************/ |
|
73 |
|
74 |
|
75 public: |
|
76 /* |
|
77 CONFIGURATION configuration_name |
|
78 optional_global_var_declarations |
|
79 (resource_declaration_list | single_resource_declaration) |
|
80 optional_access_declarations |
|
81 optional_instance_specific_initializations |
|
82 END_CONFIGURATION |
|
83 */ |
|
84 /* |
|
85 SYM_REF6(configuration_declaration_c, configuration_name, global_var_declarations, resource_declarations, access_declarations, instance_specific_initializations, unused) |
|
86 */ |
|
87 void *visit(configuration_declaration_c *symbol) { |
|
88 TRACE("configuration_declaration_c"); |
|
89 |
|
90 symbol->resource_declarations->accept(*this); |
|
91 return NULL; |
|
92 } |
|
93 |
|
94 |
|
95 |
|
96 /* helper symbol for configuration_declaration */ |
|
97 // SYM_LIST(resource_declaration_list_c) |
|
98 void *visit(resource_declaration_list_c *symbol) { |
|
99 TRACE("resource_declaration_list_c"); |
|
100 |
|
101 return print_list(symbol); |
|
102 } |
|
103 |
|
104 /* |
|
105 RESOURCE resource_name ON resource_type_name |
|
106 optional_global_var_declarations |
|
107 single_resource_declaration |
|
108 END_RESOURCE |
|
109 */ |
|
110 // SYM_REF4(resource_declaration_c, resource_name, resource_type_name, global_var_declarations, resource_declaration) |
|
111 void *visit(resource_declaration_c *symbol) { |
|
112 TRACE("resource_declaration_c"); |
|
113 |
|
114 current_resource_name = symbol->resource_name; |
|
115 symbol->resource_declaration->accept(*this); |
|
116 current_resource_name = NULL; |
|
117 return NULL; |
|
118 } |
|
119 |
|
120 |
|
121 |
|
122 /* task_configuration_list program_configuration_list */ |
|
123 // SYM_REF2(single_resource_declaration_c, task_configuration_list, program_configuration_list) |
|
124 void *visit(single_resource_declaration_c *symbol) { |
|
125 TRACE("single_resource_declaration_c"); |
|
126 |
|
127 symbol->program_configuration_list->accept(*this); |
|
128 return NULL; |
|
129 } |
|
130 |
|
131 |
|
132 |
|
133 /* helper symbol for single_resource_declaration */ |
|
134 //SYM_LIST(task_configuration_list_c) |
|
135 |
|
136 |
|
137 /* helper symbol for single_resource_declaration */ |
|
138 //SYM_LIST(program_configuration_list_c) |
|
139 void *visit(program_configuration_list_c *symbol) { |
|
140 TRACE("program_configuration_list_c"); |
|
141 |
|
142 return print_list(symbol); |
|
143 } |
|
144 |
|
145 |
|
146 /* helper symbol for |
|
147 * - access_path |
|
148 * - instance_specific_init |
|
149 */ |
|
150 //SYM_LIST(any_fb_name_list_c) |
|
151 |
|
152 /* [resource_name '.'] global_var_name ['.' structure_element_name] */ |
|
153 //SYM_REF4(global_var_reference_c, resource_name, global_var_name, structure_element_name, unused) |
|
154 |
|
155 /* prev_declared_program_name '.' symbolic_variable */ |
|
156 //SYM_REF2(program_output_reference_c, program_name, symbolic_variable) |
|
157 |
|
158 /* TASK task_name task_initialization */ |
|
159 //SYM_REF2(task_configuration_c, task_name, task_initialization) |
|
160 |
|
161 /* '(' [SINGLE ASSIGN data_source ','] [INTERVAL ASSIGN data_source ','] PRIORITY ASSIGN integer ')' */ |
|
162 //SYM_REF4(task_initialization_c, single_data_source, interval_data_source, priority_data_source, unused) |
|
163 |
|
164 /* PROGRAM [RETAIN | NON_RETAIN] program_name [WITH task_name] ':' program_type_name ['(' prog_conf_elements ')'] */ |
|
165 //SYM_REF6(program_configuration_c, retain_option, program_name, task_name, program_type_name, prog_conf_elements, unused) |
|
166 void *visit(program_configuration_c *symbol) { |
|
167 TRACE("program_configuration_c"); |
|
168 |
|
169 s4o.print(s4o.indent_spaces); |
|
170 if (NULL != current_resource_name) { |
|
171 current_resource_name->accept(*this); |
|
172 s4o.print("."); |
|
173 } |
|
174 symbol->program_name->accept(*this); |
|
175 s4o.print(".f();\n"); |
|
176 return NULL; |
|
177 } |
|
178 |
|
179 /* prog_conf_elements ',' prog_conf_element */ |
|
180 //SYM_LIST(prog_conf_elements_c) |
|
181 |
|
182 /* fb_name WITH task_name */ |
|
183 //SYM_REF2(fb_task_c, fb_name, task_name) |
|
184 // TODO... |
|
185 |
|
186 /* any_symbolic_variable ASSIGN prog_data_source */ |
|
187 //SYM_REF2(prog_cnxn_assign_c, symbolic_variable, prog_data_source) |
|
188 |
|
189 /* any_symbolic_variable SENDTO data_sink */ |
|
190 //SYM_REF2(prog_cnxn_sendto_c, symbolic_variable, prog_data_source) |
|
191 |
|
192 /* VAR_CONFIG instance_specific_init_list END_VAR */ |
|
193 //SYM_REF2(instance_specific_initializations_c, instance_specific_init_list, unused) |
|
194 |
|
195 /* helper symbol for instance_specific_initializations */ |
|
196 //SYM_LIST(instance_specific_init_list_c) |
|
197 |
|
198 /* resource_name '.' program_name '.' {fb_name '.'} |
|
199 ((variable_name [location] ':' located_var_spec_init) | (fb_name ':' fb_initialization)) |
|
200 */ |
|
201 //SYM_REF6(instance_specific_init_c, resource_name, program_name, any_fb_name_list, variable_name, location, initialization) |
|
202 |
|
203 /* helper symbol for instance_specific_init */ |
|
204 /* function_block_type_name ':=' structure_initialization */ |
|
205 //SYM_REF2(fb_initialization_c, function_block_type_name, structure_initialization) |
|
206 |
|
207 |
|
208 |
|
209 }; /* generate_cc_configbody_c */ |
|
210 |
|
211 |