msousa@443: /* msousa@443: * matiec - a compiler for the programming languages defined in IEC 61131-3 msousa@443: * msousa@443: * Copyright (C) 2012 Mario de Sousa (msousa@fe.up.pt) msousa@443: * msousa@443: * msousa@443: * This program is free software: you can redistribute it and/or modify msousa@443: * it under the terms of the GNU General Public License as published by msousa@443: * the Free Software Foundation, either version 3 of the License, or msousa@443: * (at your option) any later version. msousa@443: * msousa@443: * This program is distributed in the hope that it will be useful, msousa@443: * but WITHOUT ANY WARRANTY; without even the implied warranty of msousa@443: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the msousa@443: * GNU General Public License for more details. msousa@443: * msousa@443: * You should have received a copy of the GNU General Public License msousa@443: * along with this program. If not, see . msousa@443: * msousa@443: * msousa@443: * This code is made available on the understanding that it will not be msousa@443: * used in safety-critical situations without a full and competent review. msousa@443: */ msousa@443: msousa@443: /* msousa@443: * An IEC 61131-3 compiler. msousa@443: * msousa@443: * Based on the msousa@443: * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) msousa@443: * msousa@443: */ msousa@443: msousa@443: msousa@443: /* msousa@443: * Do flow control analysis of the IEC 61131-3 code. msousa@443: * msousa@443: * We currently only do this for IL code. msousa@443: * This class will annotate the abstract syntax tree, by filling in the msousa@443: * prev_il_instruction variable in the il_instruction_c, so it points to msousa@443: * the previous il_instruction_c object in the instruction list instruction_list_c. msousa@443: */ msousa@443: msousa@443: msousa@443: msousa@443: #include "../absyntax_utils/absyntax_utils.hh" msousa@443: msousa@443: msousa@443: class flow_control_analysis_c: public iterator_visitor_c { msousa@443: msousa@443: private: msousa@459: search_il_label_c *search_il_label; msousa@443: symbol_c *prev_il_instruction; msousa@459: symbol_c *curr_il_instruction; msousa@463: bool prev_il_instruction_is_JMP_or_RET; msousa@443: msousa@443: public: msousa@443: flow_control_analysis_c(symbol_c *ignore); msousa@443: virtual ~flow_control_analysis_c(void); msousa@443: msousa@443: /**************************************/ msousa@443: /* B 1.5 - Program organization units */ msousa@443: /**************************************/ msousa@443: /***********************/ msousa@443: /* B 1.5.1 - Functions */ msousa@443: /***********************/ msousa@443: void *visit(function_declaration_c *symbol); msousa@443: msousa@443: /*****************************/ msousa@443: /* B 1.5.2 - Function blocks */ msousa@443: /*****************************/ msousa@443: void *visit(function_block_declaration_c *symbol); msousa@443: msousa@443: /**********************/ msousa@443: /* B 1.5.3 - Programs */ msousa@443: /**********************/ msousa@443: void *visit(program_declaration_c *symbol); msousa@443: msousa@443: /********************************/ msousa@443: /* B 1.7 Configuration elements */ msousa@443: /********************************/ msousa@443: void *visit(configuration_declaration_c *symbol); msousa@443: msousa@443: /****************************************/ msousa@443: /* B.2 - Language IL (Instruction List) */ msousa@443: /****************************************/ msousa@443: /***********************************/ msousa@443: /* B 2.1 Instructions and Operands */ msousa@443: /***********************************/ msousa@443: void *visit(instruction_list_c *symbol); msousa@443: void *visit(il_instruction_c *symbol); msousa@443: // void *visit(il_simple_operation_c *symbol); msousa@443: // void *visit(il_function_call_c *symbol); msousa@453: void *visit(il_expression_c *symbol); msousa@459: void *visit(il_jump_operation_c *symbol); msousa@443: // void *visit(il_fb_call_c *symbol); msousa@443: // void *visit(il_formal_funct_call_c *symbol); msousa@452: // void *visit(il_operand_list_c *symbol); msousa@452: void *visit(simple_instr_list_c *symbol); msousa@453: void *visit(il_simple_instruction_c*symbol); msousa@452: // void *visit(il_param_list_c *symbol); msousa@452: // void *visit(il_param_assignment_c *symbol); msousa@452: // void *visit(il_param_out_assignment_c *symbol); msousa@443: msousa@443: /*******************/ msousa@443: /* B 2.2 Operators */ msousa@443: /*******************/ msousa@459: // void *visit( LD_operator_c *symbol); msousa@459: // void *visit( LDN_operator_c *symbol); msousa@459: // void *visit( ST_operator_c *symbol); msousa@459: // void *visit( STN_operator_c *symbol); msousa@459: // void *visit( NOT_operator_c *symbol); msousa@459: // void *visit( S_operator_c *symbol); msousa@459: // void *visit( R_operator_c *symbol); msousa@459: // void *visit( S1_operator_c *symbol); msousa@459: // void *visit( R1_operator_c *symbol); msousa@459: // void *visit( CLK_operator_c *symbol); msousa@459: // void *visit( CU_operator_c *symbol); msousa@459: // void *visit( CD_operator_c *symbol); msousa@459: // void *visit( PV_operator_c *symbol); msousa@459: // void *visit( IN_operator_c *symbol); msousa@459: // void *visit( PT_operator_c *symbol); msousa@459: // void *visit( AND_operator_c *symbol); msousa@459: // void *visit( OR_operator_c *symbol); msousa@459: // void *visit( XOR_operator_c *symbol); msousa@459: // void *visit( ANDN_operator_c *symbol); msousa@459: // void *visit( ORN_operator_c *symbol); msousa@459: // void *visit( XORN_operator_c *symbol); msousa@459: // void *visit( ADD_operator_c *symbol); msousa@459: // void *visit( SUB_operator_c *symbol); msousa@459: // void *visit( MUL_operator_c *symbol); msousa@459: // void *visit( DIV_operator_c *symbol); msousa@459: // void *visit( MOD_operator_c *symbol); msousa@459: // void *visit( GT_operator_c *symbol); msousa@459: // void *visit( GE_operator_c *symbol); msousa@459: // void *visit( EQ_operator_c *symbol); msousa@459: // void *visit( LT_operator_c *symbol); msousa@459: // void *visit( LE_operator_c *symbol); msousa@459: // void *visit( NE_operator_c *symbol); msousa@459: // void *visit( CAL_operator_c *symbol); msousa@459: // void *visit( CALC_operator_c *symbol); msousa@459: // void *visit(CALCN_operator_c *symbol); msousa@463: void *visit( RET_operator_c *symbol); msousa@459: // void *visit( RETC_operator_c *symbol); msousa@459: // void *visit(RETCN_operator_c *symbol); msousa@463: void *visit( JMP_operator_c *symbol); msousa@459: // void *visit( JMPC_operator_c *symbol); msousa@459: // void *visit(JMPCN_operator_c *symbol); msousa@459: msousa@443: /* Symbol class handled together with function call checks */ msousa@443: // void *visit(il_assign_operator_c *symbol, variable_name); msousa@443: /* Symbol class handled together with function call checks */ msousa@443: // void *visit(il_assign_operator_c *symbol, option, variable_name); msousa@443: msousa@443: }; // flow_control_analysis_c msousa@443: msousa@443: msousa@443: msousa@443: msousa@443: msousa@443: msousa@443: msousa@443: