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

Unified Diff: frog/leg/ssa/codegen.dart

Issue 9601009: Change labeled statement to use visitSubGraph for its body instead of marking its "exit block" spec… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comment. add more tests. Created 8 years, 9 months 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 side-by-side diff with in-line comments
Download patch
Index: frog/leg/ssa/codegen.dart
diff --git a/frog/leg/ssa/codegen.dart b/frog/leg/ssa/codegen.dart
index 80d3b6d3654504a44836b1147322b7590b3a8d7c..50b81773ea441245791cbc7781764b63b5acdf9b 100644
--- a/frog/leg/ssa/codegen.dart
+++ b/frog/leg/ssa/codegen.dart
@@ -101,6 +101,11 @@ class SsaCodeGenerator implements HVisitor {
HGraph currentGraph;
HBasicBlock currentBlock;
+ // Records a block-information that is being handled specially.
+ // Used to break bad recursion.
ngeoffray 2012/03/06 11:17:37 What's a bad recursion?
Lasse Reichstein Nielsen 2012/03/08 09:02:02 Infinite recursion, recursing on the same input ag
+ HLabeledBlockInformation currentBlockInformation;
+ // The subgraph is used to delimit traversal for some constructions, e.g.,
+ // if branches.
SubGraph subGraph;
SsaCodeGenerator(this.compiler,
@@ -233,47 +238,48 @@ class SsaCodeGenerator implements HVisitor {
this.expectedPrecedence = oldPrecedence;
}
- void handleLabeledBlock(HBasicBlock node) {
- HLabeledBlockInformation labeledBlockInfo = node.labeledBlockInformation;
- if (labeledBlockInfo.start === node) {
- addIndentation();
- for (SourceString label in labeledBlockInfo.labels) {
- addLabel(label);
- buffer.add(":");
- }
- buffer.add("{\n");
- indent++;
- } else {
- assert(labeledBlockInfo.end === node);
- assert((){
- // Check that this block is (transitively) dominated by the start block.
- HBasicBlock block = node;
- while (block.dominator !== null) {
- block = block.dominator;
- if (block === labeledBlockInfo.start) return true;
- }
- return false;
- });
- indent--;
- addIndentation();
- buffer.add("}\n");
+ void handleLabeledBlock(HLabeledBlockInformation labeledBlockInfo) {
+ addIndentation();
+ for (SourceString label in labeledBlockInfo.labels) {
+ addLabel(label);
+ buffer.add(":");
}
+ buffer.add("{\n");
+ indent++;
+
+ visitSubGraph(labeledBlockInfo.body);
+
+ indent--;
+ addIndentation();
+ buffer.add("}\n");
+
+ visitBasicBlock(labeledBlockInfo.joinBlock);
}
visitBasicBlock(HBasicBlock node) {
+ // Abort traversal if we are leaving the currently active sub-graph.
if (!subGraph.contains(node)) return;
- currentBlock = node;
+ // If this node has special behavior attached, handle it.
+ // If we reach here again while handling the attached information,
+ // e.g., because we call visitSubGraph on a subgraph starting here,
+ // don't handle it again.
ngeoffray 2012/03/06 11:17:37 How can you end up doing this? Should we re-design
Lasse Reichstein Nielsen 2012/03/08 09:02:02 For a labeled expression, the "HLabeledBlockInform
+ if (node.hasLabeledBlockInformation() &&
+ node.labeledBlockInformation !== currentBlockInformation) {
+ HLabeledBlockInformation oldBlockInformation = currentBlockInformation;
+ currentBlockInformation = node.labeledBlockInformation;
+ handleLabeledBlock(currentBlockInformation);
+ currentBlockInformation = oldBlockInformation;
+ return;
+ }
- if (node.hasLabeledBlockInformation()) {
- handleLabeledBlock(node);
- } else if (currentBlock.isLoopHeader()) {
+ currentBlock = node;
+ if (node.isLoopHeader()) {
// While loop will be closed by the conditional loop-branch.
// TODO(floitsch): HACK HACK HACK.
beginLoop(node);
}
-
HInstruction instruction = node.first;
while (instruction != null) {
if (instruction is HGoto || instruction is HExit || instruction is HTry) {

Powered by Google App Engine
This is Rietveld 408576698