author | mjsousa |
Fri, 26 Dec 2014 10:09:27 +0000 | |
changeset 972 | bc90dd4bbf4f |
parent 690 | 6156ee2b4e32 |
child 1041 | 56ebe2a31b5b |
permissions | -rw-r--r-- |
443
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1 |
/* |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
2 |
* matiec - a compiler for the programming languages defined in IEC 61131-3 |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
3 |
* |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
4 |
* Copyright (C) 2012 Mario de Sousa (msousa@fe.up.pt) |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
5 |
* |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
6 |
* This program is free software: you can redistribute it and/or modify |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
7 |
* it under the terms of the GNU General Public License as published by |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
8 |
* the Free Software Foundation, either version 3 of the License, or |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
9 |
* (at your option) any later version. |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
10 |
* |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
11 |
* This program is distributed in the hope that it will be useful, |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
14 |
* GNU General Public License for more details. |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
15 |
* |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
16 |
* You should have received a copy of the GNU General Public License |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
17 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
18 |
* |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
19 |
* |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
20 |
* This code is made available on the understanding that it will not be |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
21 |
* used in safety-critical situations without a full and competent review. |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
22 |
*/ |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
23 |
|
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
24 |
/* |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
25 |
* An IEC 61131-3 compiler. |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
26 |
* |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
27 |
* Based on the |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
28 |
* FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
29 |
* |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
30 |
*/ |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
31 |
|
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
32 |
|
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
33 |
/* |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
34 |
* Do flow control analysis of the IEC 61131-3 code. |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
35 |
* |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
36 |
* We currently only do this for IL code. |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
37 |
* This class will annotate the abstract syntax tree, by filling in the |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
38 |
* prev_il_instruction variable in the il_instruction_c, so it points to |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
39 |
* the previous il_instruction_c object in the instruction list instruction_list_c. |
453
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
40 |
* |
486
e22150ad75fd
Fix error messages of il function calls - it now prints out location info of first parameter.
Mario de Sousa <msousa@fe.up.pt>
parents:
463
diff
changeset
|
41 |
* Since IL code can contain jumps (JMP), the same il_instruction may effectively have |
e22150ad75fd
Fix error messages of il function calls - it now prints out location info of first parameter.
Mario de Sousa <msousa@fe.up.pt>
parents:
463
diff
changeset
|
42 |
* several previous il_instructions. In order to accommodate this, each il_instruction |
e22150ad75fd
Fix error messages of il function calls - it now prints out location info of first parameter.
Mario de Sousa <msousa@fe.up.pt>
parents:
463
diff
changeset
|
43 |
* will maintain a vector (i..e an array) of pointers to all the previous il_instructions. |
e22150ad75fd
Fix error messages of il function calls - it now prints out location info of first parameter.
Mario de Sousa <msousa@fe.up.pt>
parents:
463
diff
changeset
|
44 |
* We do however attempt to guarantee that the first element in the vector (array) will preferentially |
e22150ad75fd
Fix error messages of il function calls - it now prints out location info of first parameter.
Mario de Sousa <msousa@fe.up.pt>
parents:
463
diff
changeset
|
45 |
* point to the il instruction that is right before / imediately preceding the current il instructions, |
e22150ad75fd
Fix error messages of il function calls - it now prints out location info of first parameter.
Mario de Sousa <msousa@fe.up.pt>
parents:
463
diff
changeset
|
46 |
* i.e. the first element in the array will tend to point to the previous il_instruction |
e22150ad75fd
Fix error messages of il function calls - it now prints out location info of first parameter.
Mario de Sousa <msousa@fe.up.pt>
parents:
463
diff
changeset
|
47 |
* that is not a jump JMP IL instruction! |
e22150ad75fd
Fix error messages of il function calls - it now prints out location info of first parameter.
Mario de Sousa <msousa@fe.up.pt>
parents:
463
diff
changeset
|
48 |
* |
e22150ad75fd
Fix error messages of il function calls - it now prints out location info of first parameter.
Mario de Sousa <msousa@fe.up.pt>
parents:
463
diff
changeset
|
49 |
* The result will essentially be a graph of il_instruction_c objects, each |
453
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
50 |
* pointing to the previous il_instruction_c object. |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
51 |
* |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
52 |
* The reality is we will get several independent and isolated linked lists |
486
e22150ad75fd
Fix error messages of il function calls - it now prints out location info of first parameter.
Mario de Sousa <msousa@fe.up.pt>
parents:
463
diff
changeset
|
53 |
* (actually, since we now process labels correctly, this is really a graph): |
453
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
54 |
* one for each block of IL code (e.g. inside a Function, FB or Program). |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
55 |
* Additionally, when the IL code has an expression (expression_c object), we will actually |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
56 |
* have one more isolated linked list for the IL code inside that expression. |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
57 |
* |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
58 |
* e.g. |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
59 |
* line_1: LD 1 |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
60 |
* line_2: ADD (42 |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
61 |
* line_3: ADD B |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
62 |
* line_4: ADD C |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
63 |
* line_5: ) |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
64 |
* line_6: ADD D |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
65 |
* line_7: ST E |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
66 |
* |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
67 |
* will result in two independent linked lists: |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
68 |
* main list: line_7 -> line_6 -> line2 -> line_1 |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
69 |
* expr list: lin4_4 -> line_3 -> (operand of line_2, i.e. '42') |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
70 |
* |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
71 |
* |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
72 |
* In the main list, each: |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
73 |
* line_x: IL_operation IL_operand |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
74 |
* is encoded as |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
75 |
* il_instruction_c(label, il_incomplete_instruction) |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
76 |
* these il_instruction_c objects will point back to the previous il_instruction_c object. |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
77 |
* |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
78 |
* In the expr list, each |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
79 |
* line_x: IL_operation IL_operand |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
80 |
* is encoded as |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
81 |
* il_simple_instruction_c(il_simple_instruction) |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
82 |
* these il_simple_instruction_c objects will point back to the previous il_simple_instruction_c object, |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
83 |
* except the for the first il_simple_instruction_c object in the list, which will point back to |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
84 |
* the first il_operand (in the above example, '42'), or NULL is it does not exist. |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
85 |
* |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
86 |
* |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
87 |
* label: |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
88 |
* identifier_c |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
89 |
* |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
90 |
* il_incomplete_instruction: |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
91 |
* il_simple_operation (il_simple_operation_c, il_function_call_c) |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
92 |
* | il_expression (il_expression_c) |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
93 |
* | il_jump_operation (il_jump_operation_c) |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
94 |
* | il_fb_call (il_fb_call_c) |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
95 |
* | il_formal_funct_call (il_formal_funct_call_c) |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
96 |
* | il_return_operator (RET_operator_c, RETC_operator_c, RETCN_operator_c) |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
97 |
* |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
98 |
* |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
99 |
* il_expression_c(il_expr_operator, il_operand, simple_instr_list) |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
100 |
* |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
101 |
* il_operand: |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
102 |
* variable (symbolic_variable_c, direct_variable_c, array_variable_c, structured_variable_c) |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
103 |
* | enumerated_value (enumerated_value_c) |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
104 |
* | constant (lots of literal classes _c) |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
105 |
* |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
106 |
* simple_instr_list: |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
107 |
* list of il_simple_instruction |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
108 |
* |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
109 |
* il_simple_instruction: |
454
099aa5d655de
Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents:
453
diff
changeset
|
110 |
* il_simple_operation (il_simple_operation_c, il_function_call_c) |
453
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
111 |
* | il_expression (il_expression_c) |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
112 |
* | il_formal_funct_call (il_formal_funct_call_c) |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
113 |
* |
443
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
114 |
*/ |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
115 |
|
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
116 |
#include "flow_control_analysis.hh" |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
117 |
|
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
118 |
|
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
119 |
|
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
120 |
/* set to 1 to see debug info during execution */ |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
121 |
static int debug = 0; |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
122 |
|
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
123 |
flow_control_analysis_c::flow_control_analysis_c(symbol_c *ignore) { |
459
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
124 |
prev_il_instruction = NULL; |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
125 |
curr_il_instruction = NULL; |
661
f537c3315f83
Minor changes needed to build with pedantic flag.
Manuele Conti <conti.ma@alice.it>
parents:
486
diff
changeset
|
126 |
prev_il_instruction_is_JMP_or_RET = false; |
f537c3315f83
Minor changes needed to build with pedantic flag.
Manuele Conti <conti.ma@alice.it>
parents:
486
diff
changeset
|
127 |
search_il_label = NULL; |
443
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
128 |
} |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
129 |
|
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
130 |
flow_control_analysis_c::~flow_control_analysis_c(void) { |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
131 |
} |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
132 |
|
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
133 |
|
672
dee28c5bdc73
Use doubly linked connections for flow control graph (will be used later).
Mario de Sousa <msousa@fe.up.pt>
parents:
661
diff
changeset
|
134 |
void flow_control_analysis_c::link_insert(symbol_c *prev_instruction, symbol_c *next_instruction) { |
685
5b19e376cc94
Fix flow control analysis of IL simple instructions (i.e. IL instructions inside parenthises!)
Mario de Sousa <msousa@fe.up.pt>
parents:
672
diff
changeset
|
135 |
il_instruction_c *next_a = dynamic_cast<il_instruction_c *>(next_instruction); |
5b19e376cc94
Fix flow control analysis of IL simple instructions (i.e. IL instructions inside parenthises!)
Mario de Sousa <msousa@fe.up.pt>
parents:
672
diff
changeset
|
136 |
il_instruction_c *prev_a = dynamic_cast<il_instruction_c *>(prev_instruction); |
5b19e376cc94
Fix flow control analysis of IL simple instructions (i.e. IL instructions inside parenthises!)
Mario de Sousa <msousa@fe.up.pt>
parents:
672
diff
changeset
|
137 |
il_simple_instruction_c *next_b = dynamic_cast<il_simple_instruction_c *>(next_instruction); |
5b19e376cc94
Fix flow control analysis of IL simple instructions (i.e. IL instructions inside parenthises!)
Mario de Sousa <msousa@fe.up.pt>
parents:
672
diff
changeset
|
138 |
il_simple_instruction_c *prev_b = dynamic_cast<il_simple_instruction_c *>(prev_instruction); |
5b19e376cc94
Fix flow control analysis of IL simple instructions (i.e. IL instructions inside parenthises!)
Mario de Sousa <msousa@fe.up.pt>
parents:
672
diff
changeset
|
139 |
|
5b19e376cc94
Fix flow control analysis of IL simple instructions (i.e. IL instructions inside parenthises!)
Mario de Sousa <msousa@fe.up.pt>
parents:
672
diff
changeset
|
140 |
if (NULL != next_a) next_a->prev_il_instruction.insert(next_a->prev_il_instruction.begin(), prev_instruction); |
5b19e376cc94
Fix flow control analysis of IL simple instructions (i.e. IL instructions inside parenthises!)
Mario de Sousa <msousa@fe.up.pt>
parents:
672
diff
changeset
|
141 |
else if (NULL != next_b) next_b->prev_il_instruction.insert(next_b->prev_il_instruction.begin(), prev_instruction); |
5b19e376cc94
Fix flow control analysis of IL simple instructions (i.e. IL instructions inside parenthises!)
Mario de Sousa <msousa@fe.up.pt>
parents:
672
diff
changeset
|
142 |
else ERROR; |
5b19e376cc94
Fix flow control analysis of IL simple instructions (i.e. IL instructions inside parenthises!)
Mario de Sousa <msousa@fe.up.pt>
parents:
672
diff
changeset
|
143 |
|
5b19e376cc94
Fix flow control analysis of IL simple instructions (i.e. IL instructions inside parenthises!)
Mario de Sousa <msousa@fe.up.pt>
parents:
672
diff
changeset
|
144 |
if (NULL != prev_a) prev_a->next_il_instruction.insert(prev_a->next_il_instruction.begin(), next_instruction); |
5b19e376cc94
Fix flow control analysis of IL simple instructions (i.e. IL instructions inside parenthises!)
Mario de Sousa <msousa@fe.up.pt>
parents:
672
diff
changeset
|
145 |
else if (NULL != prev_b) prev_b->next_il_instruction.insert(prev_b->next_il_instruction.begin(), next_instruction); |
5b19e376cc94
Fix flow control analysis of IL simple instructions (i.e. IL instructions inside parenthises!)
Mario de Sousa <msousa@fe.up.pt>
parents:
672
diff
changeset
|
146 |
else ERROR; |
672
dee28c5bdc73
Use doubly linked connections for flow control graph (will be used later).
Mario de Sousa <msousa@fe.up.pt>
parents:
661
diff
changeset
|
147 |
} |
dee28c5bdc73
Use doubly linked connections for flow control graph (will be used later).
Mario de Sousa <msousa@fe.up.pt>
parents:
661
diff
changeset
|
148 |
|
dee28c5bdc73
Use doubly linked connections for flow control graph (will be used later).
Mario de Sousa <msousa@fe.up.pt>
parents:
661
diff
changeset
|
149 |
|
dee28c5bdc73
Use doubly linked connections for flow control graph (will be used later).
Mario de Sousa <msousa@fe.up.pt>
parents:
661
diff
changeset
|
150 |
void flow_control_analysis_c::link_pushback(symbol_c *prev_instruction, symbol_c *next_instruction) { |
dee28c5bdc73
Use doubly linked connections for flow control graph (will be used later).
Mario de Sousa <msousa@fe.up.pt>
parents:
661
diff
changeset
|
151 |
il_instruction_c *next = dynamic_cast<il_instruction_c *>(next_instruction); |
dee28c5bdc73
Use doubly linked connections for flow control graph (will be used later).
Mario de Sousa <msousa@fe.up.pt>
parents:
661
diff
changeset
|
152 |
il_instruction_c *prev = dynamic_cast<il_instruction_c *>(prev_instruction); |
dee28c5bdc73
Use doubly linked connections for flow control graph (will be used later).
Mario de Sousa <msousa@fe.up.pt>
parents:
661
diff
changeset
|
153 |
if ((NULL == next) || (NULL == prev)) ERROR; |
dee28c5bdc73
Use doubly linked connections for flow control graph (will be used later).
Mario de Sousa <msousa@fe.up.pt>
parents:
661
diff
changeset
|
154 |
|
dee28c5bdc73
Use doubly linked connections for flow control graph (will be used later).
Mario de Sousa <msousa@fe.up.pt>
parents:
661
diff
changeset
|
155 |
next->prev_il_instruction.push_back(prev); |
dee28c5bdc73
Use doubly linked connections for flow control graph (will be used later).
Mario de Sousa <msousa@fe.up.pt>
parents:
661
diff
changeset
|
156 |
prev->next_il_instruction.push_back(next); |
dee28c5bdc73
Use doubly linked connections for flow control graph (will be used later).
Mario de Sousa <msousa@fe.up.pt>
parents:
661
diff
changeset
|
157 |
} |
dee28c5bdc73
Use doubly linked connections for flow control graph (will be used later).
Mario de Sousa <msousa@fe.up.pt>
parents:
661
diff
changeset
|
158 |
|
443
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
159 |
|
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
160 |
/************************************/ |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
161 |
/* B 1.5 Program organization units */ |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
162 |
/************************************/ |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
163 |
/*********************/ |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
164 |
/* B 1.5.1 Functions */ |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
165 |
/*********************/ |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
166 |
void *flow_control_analysis_c::visit(function_declaration_c *symbol) { |
459
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
167 |
search_il_label = new search_il_label_c(symbol); |
443
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
168 |
if (debug) printf("Doing flow control analysis in body of function %s\n", ((token_c *)(symbol->derived_function_name))->value); |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
169 |
symbol->function_body->accept(*this); |
459
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
170 |
delete search_il_label; |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
171 |
search_il_label = NULL; |
443
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
172 |
return NULL; |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
173 |
} |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
174 |
|
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
175 |
/***************************/ |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
176 |
/* B 1.5.2 Function blocks */ |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
177 |
/***************************/ |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
178 |
void *flow_control_analysis_c::visit(function_block_declaration_c *symbol) { |
459
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
179 |
search_il_label = new search_il_label_c(symbol); |
443
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
180 |
if (debug) printf("Doing flow control analysis in body of FB %s\n", ((token_c *)(symbol->fblock_name))->value); |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
181 |
symbol->fblock_body->accept(*this); |
459
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
182 |
delete search_il_label; |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
183 |
search_il_label = NULL; |
443
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
184 |
return NULL; |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
185 |
} |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
186 |
|
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
187 |
/********************/ |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
188 |
/* B 1.5.3 Programs */ |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
189 |
/********************/ |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
190 |
void *flow_control_analysis_c::visit(program_declaration_c *symbol) { |
459
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
191 |
search_il_label = new search_il_label_c(symbol); |
443
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
192 |
if (debug) printf("Doing flow control analysis in body of program %s\n", ((token_c *)(symbol->program_type_name))->value); |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
193 |
symbol->function_block_body->accept(*this); |
459
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
194 |
delete search_il_label; |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
195 |
search_il_label = NULL; |
443
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
196 |
return NULL; |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
197 |
} |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
198 |
|
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
199 |
|
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
200 |
/********************************/ |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
201 |
/* B 1.7 Configuration elements */ |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
202 |
/********************************/ |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
203 |
void *flow_control_analysis_c::visit(configuration_declaration_c *symbol) { |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
204 |
return NULL; |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
205 |
} |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
206 |
|
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
207 |
|
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
208 |
/****************************************/ |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
209 |
/* B.2 - Language IL (Instruction List) */ |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
210 |
/****************************************/ |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
211 |
/***********************************/ |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
212 |
/* B 2.1 Instructions and Operands */ |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
213 |
/***********************************/ |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
214 |
|
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
215 |
/*| instruction_list il_instruction */ |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
216 |
// SYM_LIST(instruction_list_c) |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
217 |
void *flow_control_analysis_c::visit(instruction_list_c *symbol) { |
463
fafa9abc166e
Correctly handle JMP and RET IL operators in flow control analysis.
Mario de Sousa <msousa@fe.up.pt>
parents:
459
diff
changeset
|
218 |
prev_il_instruction_is_JMP_or_RET = false; |
448
1bd18fc06911
Add support for semantic verification for implict FB calls in IL (e.g. PV ton_var)
Mario de Sousa <msousa@fe.up.pt>
parents:
443
diff
changeset
|
219 |
for(int i = 0; i < symbol->n; i++) { |
1bd18fc06911
Add support for semantic verification for implict FB calls in IL (e.g. PV ton_var)
Mario de Sousa <msousa@fe.up.pt>
parents:
443
diff
changeset
|
220 |
prev_il_instruction = NULL; |
1bd18fc06911
Add support for semantic verification for implict FB calls in IL (e.g. PV ton_var)
Mario de Sousa <msousa@fe.up.pt>
parents:
443
diff
changeset
|
221 |
if (i > 0) prev_il_instruction = symbol->elements[i-1]; |
459
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
222 |
curr_il_instruction = symbol->elements[i]; |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
223 |
curr_il_instruction->accept(*this); |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
224 |
curr_il_instruction = NULL; |
443
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
225 |
} |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
226 |
return NULL; |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
227 |
} |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
228 |
|
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
229 |
/* | label ':' [il_incomplete_instruction] eol_list */ |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
230 |
// SYM_REF2(il_instruction_c, label, il_instruction) |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
231 |
// void *visit(instruction_list_c *symbol); |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
232 |
void *flow_control_analysis_c::visit(il_instruction_c *symbol) { |
463
fafa9abc166e
Correctly handle JMP and RET IL operators in flow control analysis.
Mario de Sousa <msousa@fe.up.pt>
parents:
459
diff
changeset
|
233 |
if ((NULL != prev_il_instruction) && (!prev_il_instruction_is_JMP_or_RET)) |
486
e22150ad75fd
Fix error messages of il function calls - it now prints out location info of first parameter.
Mario de Sousa <msousa@fe.up.pt>
parents:
463
diff
changeset
|
234 |
/* We try to guarantee that the previous il instruction that is in the previous line, will occupy the first element of the vector. |
e22150ad75fd
Fix error messages of il function calls - it now prints out location info of first parameter.
Mario de Sousa <msousa@fe.up.pt>
parents:
463
diff
changeset
|
235 |
* In order to do that, we use insert() instead of push_back() |
e22150ad75fd
Fix error messages of il function calls - it now prints out location info of first parameter.
Mario de Sousa <msousa@fe.up.pt>
parents:
463
diff
changeset
|
236 |
*/ |
672
dee28c5bdc73
Use doubly linked connections for flow control graph (will be used later).
Mario de Sousa <msousa@fe.up.pt>
parents:
661
diff
changeset
|
237 |
link_insert(prev_il_instruction, symbol); |
459
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
238 |
|
463
fafa9abc166e
Correctly handle JMP and RET IL operators in flow control analysis.
Mario de Sousa <msousa@fe.up.pt>
parents:
459
diff
changeset
|
239 |
/* check if it is an il_expression_c, a JMP[C[N]], or a RET, and if so, handle it correctly */ |
fafa9abc166e
Correctly handle JMP and RET IL operators in flow control analysis.
Mario de Sousa <msousa@fe.up.pt>
parents:
459
diff
changeset
|
240 |
prev_il_instruction_is_JMP_or_RET = false; |
452
79ac274d1cc4
Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents:
448
diff
changeset
|
241 |
if (NULL != symbol->il_instruction) |
79ac274d1cc4
Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents:
448
diff
changeset
|
242 |
symbol->il_instruction->accept(*this); |
453
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
243 |
return NULL; |
443
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
244 |
} |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
245 |
|
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
246 |
|
459
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
247 |
|
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
248 |
/* | il_simple_operator [il_operand] */ |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
249 |
// SYM_REF2(il_simple_operation_c, il_simple_operator, il_operand) |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
250 |
// void *flow_control_analysis_c::visit(il_simple_operation_c *symbol) |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
251 |
|
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
252 |
|
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
253 |
|
443
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
254 |
/* | function_name [il_operand_list] */ |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
255 |
/* NOTE: The parameters 'called_function_declaration' and 'extensible_param_count' are used to pass data between the stage 3 and stage 4. */ |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
256 |
// SYM_REF2(il_function_call_c, function_name, il_operand_list, symbol_c *called_function_declaration; int extensible_param_count;) |
459
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
257 |
// void *flow_control_analysis_c::visit(il_function_call_c *symbol) |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
258 |
|
443
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
259 |
|
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
260 |
/* | il_expr_operator '(' [il_operand] eol_list [simple_instr_list] ')' */ |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
261 |
// SYM_REF3(il_expression_c, il_expr_operator, il_operand, simple_instr_list); |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
262 |
void *flow_control_analysis_c::visit(il_expression_c *symbol) { |
453
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
263 |
if(NULL == symbol->simple_instr_list) |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
264 |
/* nothing to do... */ |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
265 |
return NULL; |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
266 |
|
459
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
267 |
symbol_c *save_prev_il_instruction = prev_il_instruction; |
690
6156ee2b4e32
Correctly generate C code for IL expressions, i.e. IL instructions inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents:
685
diff
changeset
|
268 |
/* Stage2 will insert an artificial (and equivalent) LD <il_operand> to the simple_instr_list if necessary. We can therefore ignore the 'il_operand' entry! */ |
6156ee2b4e32
Correctly generate C code for IL expressions, i.e. IL instructions inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents:
685
diff
changeset
|
269 |
// prev_il_instruction = symbol->il_operand; |
6156ee2b4e32
Correctly generate C code for IL expressions, i.e. IL instructions inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents:
685
diff
changeset
|
270 |
prev_il_instruction = NULL; |
453
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
271 |
symbol->simple_instr_list->accept(*this); |
459
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
272 |
prev_il_instruction = save_prev_il_instruction; |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
273 |
return NULL; |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
274 |
} |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
275 |
|
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
276 |
|
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
277 |
/* il_jump_operator label */ |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
278 |
// SYM_REF2(il_jump_operation_c, il_jump_operator, label) |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
279 |
void *flow_control_analysis_c::visit(il_jump_operation_c *symbol) { |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
280 |
/* search for the il_instruction_c containing the label */ |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
281 |
il_instruction_c *destination = search_il_label->find_label(symbol->label); |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
282 |
|
463
fafa9abc166e
Correctly handle JMP and RET IL operators in flow control analysis.
Mario de Sousa <msousa@fe.up.pt>
parents:
459
diff
changeset
|
283 |
/* give the visit(JMP_operator *) an oportunity to set the prev_il_instruction_is_JMP_or_RET flag! */ |
fafa9abc166e
Correctly handle JMP and RET IL operators in flow control analysis.
Mario de Sousa <msousa@fe.up.pt>
parents:
459
diff
changeset
|
284 |
symbol->il_jump_operator->accept(*this); |
459
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
285 |
if (NULL != destination) |
672
dee28c5bdc73
Use doubly linked connections for flow control graph (will be used later).
Mario de Sousa <msousa@fe.up.pt>
parents:
661
diff
changeset
|
286 |
link_pushback(curr_il_instruction, destination); |
459
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
287 |
return NULL; |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
288 |
} |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
289 |
|
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
290 |
|
443
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
291 |
/* il_call_operator prev_declared_fb_name |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
292 |
* | il_call_operator prev_declared_fb_name '(' ')' |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
293 |
* | il_call_operator prev_declared_fb_name '(' eol_list ')' |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
294 |
* | il_call_operator prev_declared_fb_name '(' il_operand_list ')' |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
295 |
* | il_call_operator prev_declared_fb_name '(' eol_list il_param_list ')' |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
296 |
*/ |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
297 |
/* NOTE: The parameter 'called_fb_declaration'is used to pass data between stage 3 and stage4 (although currently it is not used in stage 4 */ |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
298 |
// SYM_REF4(il_fb_call_c, il_call_operator, fb_name, il_operand_list, il_param_list, symbol_c *called_fb_declaration) |
459
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
299 |
// void *flow_control_analysis_c::visit(il_fb_call_c *symbol) |
443
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
300 |
|
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
301 |
|
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
302 |
/* | function_name '(' eol_list [il_param_list] ')' */ |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
303 |
/* NOTE: The parameter 'called_function_declaration' is used to pass data between the stage 3 and stage 4. */ |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
304 |
// SYM_REF2(il_formal_funct_call_c, function_name, il_param_list, symbol_c *called_function_declaration; int extensible_param_count;) |
459
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
305 |
// void *flow_control_analysis_c::visit(il_formal_funct_call_c *symbol) |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
306 |
|
443
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
307 |
|
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
308 |
|
452
79ac274d1cc4
Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents:
448
diff
changeset
|
309 |
// void *visit(il_operand_list_c *symbol); |
79ac274d1cc4
Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents:
448
diff
changeset
|
310 |
void *flow_control_analysis_c::visit(simple_instr_list_c *symbol) { |
454
099aa5d655de
Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents:
453
diff
changeset
|
311 |
for(int i = 0; i < symbol->n; i++) { |
453
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
312 |
/* The prev_il_instruction for element[0] was set in visit(il_expression_c *) */ |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
313 |
if (i>0) prev_il_instruction = symbol->elements[i-1]; |
452
79ac274d1cc4
Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents:
448
diff
changeset
|
314 |
symbol->elements[i]->accept(*this); |
79ac274d1cc4
Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents:
448
diff
changeset
|
315 |
} |
79ac274d1cc4
Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents:
448
diff
changeset
|
316 |
return NULL; |
79ac274d1cc4
Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents:
448
diff
changeset
|
317 |
} |
79ac274d1cc4
Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents:
448
diff
changeset
|
318 |
|
453
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
319 |
|
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
320 |
// SYM_REF1(il_simple_instruction_c, il_simple_instruction, symbol_c *prev_il_instruction;) |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
321 |
void *flow_control_analysis_c::visit(il_simple_instruction_c*symbol) { |
459
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
322 |
if (NULL != prev_il_instruction) |
486
e22150ad75fd
Fix error messages of il function calls - it now prints out location info of first parameter.
Mario de Sousa <msousa@fe.up.pt>
parents:
463
diff
changeset
|
323 |
/* We try to guarantee that the previous il instruction that is in the previous line, will occupy the first element of the vector. |
e22150ad75fd
Fix error messages of il function calls - it now prints out location info of first parameter.
Mario de Sousa <msousa@fe.up.pt>
parents:
463
diff
changeset
|
324 |
* In order to do that, we use insert() instead of push_back() |
e22150ad75fd
Fix error messages of il function calls - it now prints out location info of first parameter.
Mario de Sousa <msousa@fe.up.pt>
parents:
463
diff
changeset
|
325 |
*/ |
672
dee28c5bdc73
Use doubly linked connections for flow control graph (will be used later).
Mario de Sousa <msousa@fe.up.pt>
parents:
661
diff
changeset
|
326 |
link_insert(prev_il_instruction, symbol); |
dee28c5bdc73
Use doubly linked connections for flow control graph (will be used later).
Mario de Sousa <msousa@fe.up.pt>
parents:
661
diff
changeset
|
327 |
|
453
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
328 |
return NULL; |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
329 |
} |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
330 |
|
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
452
diff
changeset
|
331 |
|
443
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
332 |
/* |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
333 |
void *visit(il_param_list_c *symbol); |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
334 |
void *visit(il_param_assignment_c *symbol); |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
335 |
void *visit(il_param_out_assignment_c *symbol); |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
336 |
*/ |
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
337 |
|
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
338 |
|
ff4d26b7e51d
Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
339 |
|
459
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
340 |
|
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
341 |
/*******************/ |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
342 |
/* B 2.2 Operators */ |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
343 |
/*******************/ |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
344 |
// void *visit( LD_operator_c *symbol); |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
345 |
// void *visit( LDN_operator_c *symbol); |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
346 |
// void *visit( ST_operator_c *symbol); |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
347 |
// void *visit( STN_operator_c *symbol); |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
348 |
// void *visit( NOT_operator_c *symbol); |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
349 |
// void *visit( S_operator_c *symbol); |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
350 |
// void *visit( R_operator_c *symbol); |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
351 |
// void *visit( S1_operator_c *symbol); |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
352 |
// void *visit( R1_operator_c *symbol); |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
353 |
// void *visit( CLK_operator_c *symbol); |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
354 |
// void *visit( CU_operator_c *symbol); |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
355 |
// void *visit( CD_operator_c *symbol); |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
356 |
// void *visit( PV_operator_c *symbol); |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
357 |
// void *visit( IN_operator_c *symbol); |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
358 |
// void *visit( PT_operator_c *symbol); |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
359 |
// void *visit( AND_operator_c *symbol); |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
360 |
// void *visit( OR_operator_c *symbol); |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
361 |
// void *visit( XOR_operator_c *symbol); |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
362 |
// void *visit( ANDN_operator_c *symbol); |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
363 |
// void *visit( ORN_operator_c *symbol); |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
364 |
// void *visit( XORN_operator_c *symbol); |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
365 |
// void *visit( ADD_operator_c *symbol); |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
366 |
// void *visit( SUB_operator_c *symbol); |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
367 |
// void *visit( MUL_operator_c *symbol); |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
368 |
// void *visit( DIV_operator_c *symbol); |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
369 |
// void *visit( MOD_operator_c *symbol); |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
370 |
// void *visit( GT_operator_c *symbol); |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
371 |
// void *visit( GE_operator_c *symbol); |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
372 |
// void *visit( EQ_operator_c *symbol); |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
373 |
// void *visit( LT_operator_c *symbol); |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
374 |
// void *visit( LE_operator_c *symbol); |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
375 |
// void *visit( NE_operator_c *symbol); |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
376 |
// void *visit( CAL_operator_c *symbol); |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
377 |
// void *visit( CALC_operator_c *symbol); |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
378 |
// void *visit(CALCN_operator_c *symbol); |
463
fafa9abc166e
Correctly handle JMP and RET IL operators in flow control analysis.
Mario de Sousa <msousa@fe.up.pt>
parents:
459
diff
changeset
|
379 |
|
fafa9abc166e
Correctly handle JMP and RET IL operators in flow control analysis.
Mario de Sousa <msousa@fe.up.pt>
parents:
459
diff
changeset
|
380 |
/* this next visit function will be called directly from visit(il_instruction_c *) */ |
fafa9abc166e
Correctly handle JMP and RET IL operators in flow control analysis.
Mario de Sousa <msousa@fe.up.pt>
parents:
459
diff
changeset
|
381 |
void *flow_control_analysis_c::visit( RET_operator_c *symbol) { |
fafa9abc166e
Correctly handle JMP and RET IL operators in flow control analysis.
Mario de Sousa <msousa@fe.up.pt>
parents:
459
diff
changeset
|
382 |
prev_il_instruction_is_JMP_or_RET = true; |
fafa9abc166e
Correctly handle JMP and RET IL operators in flow control analysis.
Mario de Sousa <msousa@fe.up.pt>
parents:
459
diff
changeset
|
383 |
return NULL; |
fafa9abc166e
Correctly handle JMP and RET IL operators in flow control analysis.
Mario de Sousa <msousa@fe.up.pt>
parents:
459
diff
changeset
|
384 |
} |
fafa9abc166e
Correctly handle JMP and RET IL operators in flow control analysis.
Mario de Sousa <msousa@fe.up.pt>
parents:
459
diff
changeset
|
385 |
|
459
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
386 |
// void *visit( RETC_operator_c *symbol); |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
387 |
// void *visit(RETCN_operator_c *symbol); |
463
fafa9abc166e
Correctly handle JMP and RET IL operators in flow control analysis.
Mario de Sousa <msousa@fe.up.pt>
parents:
459
diff
changeset
|
388 |
|
fafa9abc166e
Correctly handle JMP and RET IL operators in flow control analysis.
Mario de Sousa <msousa@fe.up.pt>
parents:
459
diff
changeset
|
389 |
/* this next visit function will be called from visit(il_jump_operation_c *) */ |
fafa9abc166e
Correctly handle JMP and RET IL operators in flow control analysis.
Mario de Sousa <msousa@fe.up.pt>
parents:
459
diff
changeset
|
390 |
void *flow_control_analysis_c::visit( JMP_operator_c *symbol) { |
fafa9abc166e
Correctly handle JMP and RET IL operators in flow control analysis.
Mario de Sousa <msousa@fe.up.pt>
parents:
459
diff
changeset
|
391 |
prev_il_instruction_is_JMP_or_RET = true; |
fafa9abc166e
Correctly handle JMP and RET IL operators in flow control analysis.
Mario de Sousa <msousa@fe.up.pt>
parents:
459
diff
changeset
|
392 |
return NULL; |
fafa9abc166e
Correctly handle JMP and RET IL operators in flow control analysis.
Mario de Sousa <msousa@fe.up.pt>
parents:
459
diff
changeset
|
393 |
} |
fafa9abc166e
Correctly handle JMP and RET IL operators in flow control analysis.
Mario de Sousa <msousa@fe.up.pt>
parents:
459
diff
changeset
|
394 |
|
459
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
395 |
// void *visit( JMPC_operator_c *symbol); |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
396 |
// void *visit(JMPCN_operator_c *symbol); |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
397 |
|
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
398 |
/* Symbol class handled together with function call checks */ |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
399 |
// void *visit(il_assign_operator_c *symbol, variable_name); |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
400 |
/* Symbol class handled together with function call checks */ |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
401 |
// void *visit(il_assign_operator_c *symbol, option, variable_name); |
01f6664bf8c5
Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents:
457
diff
changeset
|
402 |