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

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

Issue 9718034: Continue for simple loops (while/for). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 957f323e3b23d09d2cf2a6b85a1e072f17fd657f..d089e1612fde49d4bfae17a1c7b57bc3425b53d3 100644
--- a/frog/leg/ssa/codegen.dart
+++ b/frog/leg/ssa/codegen.dart
@@ -247,14 +247,22 @@ class SsaCodeGenerator implements HVisitor {
void handleLabeledBlock(HLabeledBlockInformation labeledBlockInfo) {
addIndentation();
for (LabelElement label in labeledBlockInfo.labels) {
- addLabel(label);
+ if (labeledBlockInfo.isContinue) {
+ addContinueLabel(label);
+ } else {
+ addBreakLabel(label);
+ }
buffer.add(':');
}
ngeoffray 2012/03/19 11:42:06 Shouldn't you do: if !(labeledBlockInfo.labels.isE
Lasse Reichstein Nielsen 2012/03/19 12:13:58 It's never empty, so no.
TargetElement target = labeledBlockInfo.target;
if (target.isSwitch) {
- addImplicitLabel(target);
+ addImplicitBreakLabel(target);
buffer.add(@':');
}
+ if (labeledBlockInfo.isContinue) {
+ addImplicitContinueLabel(target);
+ buffer.add(':');
+ }
buffer.add('{\n');
indent++;
@@ -433,15 +441,24 @@ class SsaCodeGenerator implements HVisitor {
}
// Used to write the name of labels.
- // The default implementation uses the unmodified Dart label name.
- // Specializations might change this.
- void addLabel(LabelElement label) {
+ void addBreakLabel(LabelElement label) {
buffer.add(@'$');
buffer.add(label.labelName);
}
- void addImplicitLabel(TargetElement target) {
- buffer.add('\$${target.nestingLevel}');
+ void addContinueLabel(LabelElement label) {
+ buffer.add(@'c$');
+ buffer.add(label.labelName);
+ }
+
+ void addImplicitBreakLabel(TargetElement target) {
+ buffer.add(@'$');
+ buffer.add('${target.nestingLevel}');
+ }
+
+ void addImplicitContinueLabel(TargetElement target) {
+ buffer.add(@'c$');
+ buffer.add('${target.nestingLevel}');
}
visitBreak(HBreak node) {
@@ -450,15 +467,33 @@ class SsaCodeGenerator implements HVisitor {
buffer.add("break");
if (node.label !== null) {
buffer.add(" ");
- addLabel(node.label);
+ addBreakLabel(node.label);
} else {
TargetElement target = node.target;
if (target.isSwitch) {
ngeoffray 2012/03/19 11:42:06 Please add a comment that since we're generating s
Lasse Reichstein Nielsen 2012/03/19 12:13:58 Done.
buffer.add(@' ');
- addImplicitLabel(target);
+ addImplicitBreakLabel(target);
}
}
buffer.add(";\n");
+ }
+
+ visitContinue(HContinue node) {
+ assert(currentBlock.successors.length == 1);
+ // No block finishing with a 'break' can have more than
ngeoffray 2012/03/19 11:42:06 break -> continue
+ // one dominated block (since it has only one successor).
ngeoffray 2012/03/19 11:42:06 more than one -> a ? You're checking that dominate
+ // If the successor is dominated by another block, then the other block
+ // is responsible for visiting the successor.
+ assert(currentBlock.dominatedBlocks.isEmpty());
+ // Otherwise we would have bailed out in the builder.
ngeoffray 2012/03/19 11:42:06 Should that comment be one line above?
Lasse Reichstein Nielsen 2012/03/19 12:13:58 These comments should all go away, just as they di
+ addIndentation();
+ buffer.add("break ");
ngeoffray 2012/03/19 11:42:06 Please add a comment on why this isn't 'continue'.
Lasse Reichstein Nielsen 2012/03/19 12:13:58 Done.
+ if (node.label !== null) {
+ addContinueLabel(node.label);
+ } else {
+ addImplicitContinueLabel(node.target);
+ }
+ buffer.add(";\n");
// We never follow the break to its target, even if it dominates the
// break target block. That block is always handled by the structure
// that introduced the break.
@@ -1179,7 +1214,7 @@ class SsaOptimizedCodeGenerator extends SsaCodeGenerator {
void beginLoop(HBasicBlock block) {
addIndentation();
for (LabelElement label in block.loopInformation.labels) {
- addLabel(label);
+ addBreakLabel(label);
ngeoffray 2012/03/19 11:42:06 What about continue labels here?
Lasse Reichstein Nielsen 2012/03/19 12:13:58 Continue labels are put as labels on a block surro
buffer.add(":");
}
buffer.add('while (true) {\n');
@@ -1343,12 +1378,6 @@ class SsaUnoptimizedCodeGenerator extends SsaCodeGenerator {
buffer.add('}\n'); // Close 'switch'.
}
- // Adds a "$" in front of names of labels from the original source.
- // This avoids conflicts with labels introduced by bailouts, which
- // starts with a non-"$" character.
- void addLabel(LabelElement label) {
- buffer.add("\$${label.labelName}");
- }
void beginLoop(HBasicBlock block) {
// TODO(ngeoffray): Don't put labels on loops that don't bailout.
@@ -1358,8 +1387,8 @@ class SsaUnoptimizedCodeGenerator extends SsaCodeGenerator {
}
addIndentation();
- for (LabelElement label in block.loopInformation.labels) {
- addLabel(label);
+ for (SourceString label in block.loopInformation.labels) {
+ addBreakLabel(label);
buffer.add(":");
}
buffer.add('$newLabel: while (true) {\n');

Powered by Google App Engine
This is Rietveld 408576698