Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: frog/leg/ssa/validate.dart

Issue 8513004: Throw and a small fix to If. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « frog/leg/ssa/tracer.dart ('k') | frog/tests/leg_only/src/Throw1Test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 graph) {
10 this.graph = graph; 10 this.graph = graph;
11 visitDominatorTree(graph); 11 visitDominatorTree(graph);
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) {
22 if (!isValid) return; // Don't need to continue if we are already invalid. 22 if (!isValid) return; // Don't need to continue if we are already invalid.
23 23
24 // Test that the last instruction is a branching instruction and that the 24 // Test that the last instruction is a branching instruction and that the
25 // basic block contains the branch-target. 25 // basic block contains the branch-target.
26 if (block.first === null || block.last === null) { 26 if (block.first === null || block.last === null) {
27 markInvalid("empty block"); 27 markInvalid("empty block");
28 } 28 }
29 if (block.last is !HIf && 29 if (block.last is !HControlFlow) {
30 block.last is !HGoto &&
31 block.last is !HReturn &&
32 block.last is !HExit) {
33 markInvalid("block ends with non-tail node."); 30 markInvalid("block ends with non-tail node.");
34 } 31 }
35 if (block.last is HIf && block.successors.length != 2) { 32 if (block.last is HIf && block.successors.length != 2) {
36 markInvalid("If node without two successors"); 33 markInvalid("If node without two successors");
37 } 34 }
38 if (block.last is HGoto && block.successors.length != 1) { 35 if (block.last is HGoto && block.successors.length != 1) {
39 markInvalid("Goto node without one successor"); 36 markInvalid("Goto node without one successor");
40 } 37 }
41 if (block.last is HReturn && 38 if (block.last is HReturn &&
42 (block.successors.length != 1 || !block.successors[0].isExitBlock())) { 39 (block.successors.length != 1 || !block.successors[0].isExitBlock())) {
43 markInvalid("Return node with > 1 succesor or not going to exit-block"); 40 markInvalid("Return node with > 1 succesor or not going to exit-block");
44 } 41 }
45 if (block.last is HExit && !block.successors.isEmpty()) { 42 if (block.last is HExit && !block.successors.isEmpty()) {
46 markInvalid("Exit block with successor"); 43 markInvalid("Exit block with successor");
47 } 44 }
45 if (block.last is HThrow && !block.successors.isEmpty()) {
46 markInvalid("Throw block with successor");
47 }
48 48
49 if (block.successors.isEmpty() && !block.isExitBlock()) { 49 if (block.successors.isEmpty() &&
50 markInvalid("Non-exit block without successor"); 50 block.last is !HThrow &&
51 !block.isExitBlock()) {
52 markInvalid("Non-exit or throw block without successor");
51 } 53 }
52 54
53 // Make sure that successors ids are always higher than the current one. 55 // Make sure that successors ids are always higher than the current one.
54 // TODO(floitsch): this is, of course, not true for back-branches. 56 // TODO(floitsch): this is, of course, not true for back-branches.
55 if (block.id === null) markInvalid("block without id"); 57 if (block.id === null) markInvalid("block without id");
56 for (HBasicBlock successor in block.successors) { 58 for (HBasicBlock successor in block.successors) {
57 if (!isValid) break; 59 if (!isValid) break;
58 if (successor.id === null) markInvalid("successor without id"); 60 if (successor.id === null) markInvalid("successor without id");
59 if (successor.id <= block.id) { 61 if (successor.id <= block.id) {
60 markInvalid("successor with lower id"); 62 markInvalid("successor with lower id");
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 if (!instruction.isInBasicBlock()) return true; 132 if (!instruction.isInBasicBlock()) return true;
131 return everyInstruction(instruction.usedBy, (use, count) { 133 return everyInstruction(instruction.usedBy, (use, count) {
132 return countInstruction(use.inputs, instruction) == count; 134 return countInstruction(use.inputs, instruction) == count;
133 }); 135 });
134 } 136 }
135 137
136 isValid = isValid && 138 isValid = isValid &&
137 hasCorrectInputs(instruction) && hasCorrectUses(instruction); 139 hasCorrectInputs(instruction) && hasCorrectUses(instruction);
138 } 140 }
139 } 141 }
OLDNEW
« no previous file with comments | « frog/leg/ssa/tracer.dart ('k') | frog/tests/leg_only/src/Throw1Test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698