|
1 /* |
|
2 * matiec - a compiler for the programming languages defined in IEC 61131-3 |
|
3 * |
|
4 * Copyright (C) 2012 Mario de Sousa (msousa@fe.up.pt) |
|
5 * |
|
6 * |
|
7 * This program is free software: you can redistribute it and/or modify |
|
8 * it under the terms of the GNU General Public License as published by |
|
9 * the Free Software Foundation, either version 3 of the License, or |
|
10 * (at your option) any later version. |
|
11 * |
|
12 * This program is distributed in the hope that it will be useful, |
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15 * GNU General Public License for more details. |
|
16 * |
|
17 * You should have received a copy of the GNU General Public License |
|
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
19 * |
|
20 * |
|
21 * This code is made available on the understanding that it will not be |
|
22 * used in safety-critical situations without a full and competent review. |
|
23 */ |
|
24 |
|
25 /* |
|
26 * An IEC 61131-3 compiler. |
|
27 * |
|
28 * Based on the |
|
29 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
|
30 * |
|
31 */ |
|
32 |
|
33 |
|
34 /* |
|
35 * Do flow control analysis of the IEC 61131-3 code. |
|
36 * |
|
37 * We currently only do this for IL code. |
|
38 * This class will annotate the abstract syntax tree, by filling in the |
|
39 * prev_il_instruction variable in the il_instruction_c, so it points to |
|
40 * the previous il_instruction_c object in the instruction list instruction_list_c. |
|
41 */ |
|
42 |
|
43 |
|
44 |
|
45 #include "../absyntax_utils/absyntax_utils.hh" |
|
46 |
|
47 |
|
48 class flow_control_analysis_c: public iterator_visitor_c { |
|
49 |
|
50 private: |
|
51 search_il_label_c *search_il_label; |
|
52 symbol_c *prev_il_instruction; |
|
53 symbol_c *curr_il_instruction; |
|
54 bool prev_il_instruction_is_JMP_or_RET; |
|
55 |
|
56 public: |
|
57 flow_control_analysis_c(symbol_c *ignore); |
|
58 virtual ~flow_control_analysis_c(void); |
|
59 |
|
60 /**************************************/ |
|
61 /* B 1.5 - Program organization units */ |
|
62 /**************************************/ |
|
63 /***********************/ |
|
64 /* B 1.5.1 - Functions */ |
|
65 /***********************/ |
|
66 void *visit(function_declaration_c *symbol); |
|
67 |
|
68 /*****************************/ |
|
69 /* B 1.5.2 - Function blocks */ |
|
70 /*****************************/ |
|
71 void *visit(function_block_declaration_c *symbol); |
|
72 |
|
73 /**********************/ |
|
74 /* B 1.5.3 - Programs */ |
|
75 /**********************/ |
|
76 void *visit(program_declaration_c *symbol); |
|
77 |
|
78 /********************************/ |
|
79 /* B 1.7 Configuration elements */ |
|
80 /********************************/ |
|
81 void *visit(configuration_declaration_c *symbol); |
|
82 |
|
83 /****************************************/ |
|
84 /* B.2 - Language IL (Instruction List) */ |
|
85 /****************************************/ |
|
86 /***********************************/ |
|
87 /* B 2.1 Instructions and Operands */ |
|
88 /***********************************/ |
|
89 void *visit(instruction_list_c *symbol); |
|
90 void *visit(il_instruction_c *symbol); |
|
91 // void *visit(il_simple_operation_c *symbol); |
|
92 // void *visit(il_function_call_c *symbol); |
|
93 void *visit(il_expression_c *symbol); |
|
94 void *visit(il_jump_operation_c *symbol); |
|
95 // void *visit(il_fb_call_c *symbol); |
|
96 // void *visit(il_formal_funct_call_c *symbol); |
|
97 // void *visit(il_operand_list_c *symbol); |
|
98 void *visit(simple_instr_list_c *symbol); |
|
99 void *visit(il_simple_instruction_c*symbol); |
|
100 // void *visit(il_param_list_c *symbol); |
|
101 // void *visit(il_param_assignment_c *symbol); |
|
102 // void *visit(il_param_out_assignment_c *symbol); |
|
103 |
|
104 /*******************/ |
|
105 /* B 2.2 Operators */ |
|
106 /*******************/ |
|
107 // void *visit( LD_operator_c *symbol); |
|
108 // void *visit( LDN_operator_c *symbol); |
|
109 // void *visit( ST_operator_c *symbol); |
|
110 // void *visit( STN_operator_c *symbol); |
|
111 // void *visit( NOT_operator_c *symbol); |
|
112 // void *visit( S_operator_c *symbol); |
|
113 // void *visit( R_operator_c *symbol); |
|
114 // void *visit( S1_operator_c *symbol); |
|
115 // void *visit( R1_operator_c *symbol); |
|
116 // void *visit( CLK_operator_c *symbol); |
|
117 // void *visit( CU_operator_c *symbol); |
|
118 // void *visit( CD_operator_c *symbol); |
|
119 // void *visit( PV_operator_c *symbol); |
|
120 // void *visit( IN_operator_c *symbol); |
|
121 // void *visit( PT_operator_c *symbol); |
|
122 // void *visit( AND_operator_c *symbol); |
|
123 // void *visit( OR_operator_c *symbol); |
|
124 // void *visit( XOR_operator_c *symbol); |
|
125 // void *visit( ANDN_operator_c *symbol); |
|
126 // void *visit( ORN_operator_c *symbol); |
|
127 // void *visit( XORN_operator_c *symbol); |
|
128 // void *visit( ADD_operator_c *symbol); |
|
129 // void *visit( SUB_operator_c *symbol); |
|
130 // void *visit( MUL_operator_c *symbol); |
|
131 // void *visit( DIV_operator_c *symbol); |
|
132 // void *visit( MOD_operator_c *symbol); |
|
133 // void *visit( GT_operator_c *symbol); |
|
134 // void *visit( GE_operator_c *symbol); |
|
135 // void *visit( EQ_operator_c *symbol); |
|
136 // void *visit( LT_operator_c *symbol); |
|
137 // void *visit( LE_operator_c *symbol); |
|
138 // void *visit( NE_operator_c *symbol); |
|
139 // void *visit( CAL_operator_c *symbol); |
|
140 // void *visit( CALC_operator_c *symbol); |
|
141 // void *visit(CALCN_operator_c *symbol); |
|
142 void *visit( RET_operator_c *symbol); |
|
143 // void *visit( RETC_operator_c *symbol); |
|
144 // void *visit(RETCN_operator_c *symbol); |
|
145 void *visit( JMP_operator_c *symbol); |
|
146 // void *visit( JMPC_operator_c *symbol); |
|
147 // void *visit(JMPCN_operator_c *symbol); |
|
148 |
|
149 /* Symbol class handled together with function call checks */ |
|
150 // void *visit(il_assign_operator_c *symbol, variable_name); |
|
151 /* Symbol class handled together with function call checks */ |
|
152 // void *visit(il_assign_operator_c *symbol, option, variable_name); |
|
153 |
|
154 }; // flow_control_analysis_c |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |