OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 class HValidator extends HInstructionVisitor { | 5 class HValidator extends HInstructionVisitor { |
6 bool isValid = true; | 6 bool isValid = true; |
7 HGraph graph; | 7 HGraph graph; |
8 | 8 |
9 void visitGraph(HGraph graph) { | 9 void visitGraph(HGraph visitee) { |
10 this.graph = graph; | 10 graph = visitee; |
11 visitDominatorTree(graph); | 11 visitDominatorTree(visitee); |
12 } | 12 } |
13 | 13 |
14 void markInvalid(String reason) { | 14 void markInvalid(String reason) { |
15 print(reason); | 15 print(reason); |
16 isValid = false; | 16 isValid = false; |
17 } | 17 } |
18 | 18 |
19 // Note that during construction of the Ssa graph the basic blocks are | 19 // Note that during construction of the Ssa graph the basic blocks are |
20 // not required to be valid yet. | 20 // not required to be valid yet. |
21 void visitBasicBlock(HBasicBlock block) { | 21 void visitBasicBlock(HBasicBlock block) { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 count++; | 114 count++; |
115 } | 115 } |
116 } | 116 } |
117 if (!f(current, count)) return false; | 117 if (!f(current, count)) return false; |
118 } | 118 } |
119 return true; | 119 return true; |
120 } | 120 } |
121 | 121 |
122 void visitInstruction(HInstruction instruction) { | 122 void visitInstruction(HInstruction instruction) { |
123 // Verifies that we are in the use list of our inputs. | 123 // Verifies that we are in the use list of our inputs. |
124 bool hasCorrectInputs(instruction) { | 124 bool hasCorrectInputs() { |
125 bool inBasicBlock = instruction.isInBasicBlock(); | 125 bool inBasicBlock = instruction.isInBasicBlock(); |
126 return everyInstruction(instruction.inputs, (input, count) { | 126 return everyInstruction(instruction.inputs, (input, count) { |
127 if (inBasicBlock) { | 127 if (inBasicBlock) { |
128 return countInstruction(input.usedBy, instruction) == count; | 128 return countInstruction(input.usedBy, instruction) == count; |
129 } else { | 129 } else { |
130 return countInstruction(input.usedBy, instruction) == 0; | 130 return countInstruction(input.usedBy, instruction) == 0; |
131 } | 131 } |
132 }); | 132 }); |
133 } | 133 } |
134 | 134 |
135 // Verifies that all our uses have us in their inputs. | 135 // Verifies that all our uses have us in their inputs. |
136 bool hasCorrectUses(instruction) { | 136 bool hasCorrectUses() { |
137 if (!instruction.isInBasicBlock()) return true; | 137 if (!instruction.isInBasicBlock()) return true; |
138 return everyInstruction(instruction.usedBy, (use, count) { | 138 return everyInstruction(instruction.usedBy, (use, count) { |
139 return countInstruction(use.inputs, instruction) == count; | 139 return countInstruction(use.inputs, instruction) == count; |
140 }); | 140 }); |
141 } | 141 } |
142 | 142 |
143 if (instruction.block !== currentBlock) { | 143 if (instruction.block !== currentBlock) { |
144 markInvalid("Instruction in wrong block"); | 144 markInvalid("Instruction in wrong block"); |
145 } | 145 } |
146 if (!hasCorrectInputs(instruction)) { | 146 if (!hasCorrectInputs()) { |
147 markInvalid("Incorrect inputs"); | 147 markInvalid("Incorrect inputs"); |
148 } | 148 } |
149 if (!hasCorrectUses(instruction)) { | 149 if (!hasCorrectUses()) { |
150 markInvalid("Incorrect uses"); | 150 markInvalid("Incorrect uses"); |
151 } | 151 } |
152 } | 152 } |
153 } | 153 } |
OLD | NEW |