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

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

Issue 9599026: Generate code for some switch statements. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Update status files and work around a failed assertion Created 8 years, 10 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
« no previous file with comments | « no previous file | dart/frog/leg/ssa/closure.dart » ('j') | dart/frog/leg/ssa/optimize.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dart/frog/leg/ssa/builder.dart
diff --git a/dart/frog/leg/ssa/builder.dart b/dart/frog/leg/ssa/builder.dart
index c75d86b755013ebb3f999eddf7680a956565e96c..ef263dec1cb9d53d47f8d9a61877ef069a9d7457 100644
--- a/dart/frog/leg/ssa/builder.dart
+++ b/dart/frog/leg/ssa/builder.dart
@@ -452,7 +452,7 @@ class LocalsHandler {
* goto loop-entry;
* loop-exit:
*/
- void startLoop(Loop node) {
+ void startLoop(Node node) {
ClosureScope scopeData = closureData.capturingScopes[node];
if (scopeData == null) return;
if (scopeData.hasBoxedLoopVariables()) {
@@ -1957,7 +1957,11 @@ class SsaBuilder implements Visitor {
visitNodeList(NodeList node) {
for (Link<Node> link = node.nodes; !link.isEmpty(); link = link.tail) {
- visit(link.head);
+ if (isAborted()) {
ahe 2012/03/05 22:58:35 Not sure about this.
Lasse Reichstein Nielsen 2012/03/06 08:57:14 Seems like a reasonable warning. Maybe break the l
ahe 2012/03/06 09:16:50 I think an IDE wants multiple warnings. Otherwise
+ compiler.reportWarning(link.head, 'dead code');
+ } else {
+ visit(link.head);
+ }
}
}
@@ -2281,7 +2285,62 @@ class SsaBuilder implements Visitor {
}
visitSwitchStatement(SwitchStatement node) {
- generateUnimplemented('switch statement not implemented');
+ work.allowSpeculativeOptimization = false;
+ visit(node.expression);
+ HInstruction expression = pop();
+ Link cases = node.cases.nodes;
+ int count = 0;
+ handleThen() {
+ if (cases.head.statements.nodes.isEmpty()) {
+ compiler.unimplemented('fall-through', node: cases.head);
+ }
+ visit(cases.head.statements);
+ cases = cases.tail;
+ }
+ handleElse() {
+ if (cases.isEmpty()) return;
+ if (cases.head is DefaultCase) {
+ stack.add(graph.addNewLiteralBool(true));
+ if (!cases.tail.isEmpty()) {
+ compiler.unimplemented('default case not last', node: cases.head);
+ }
+ } else {
+ SwitchCase switchCase = cases.head;
+ visit(switchCase.expression);
+ HInstruction caseExpression = pop();
+ Element equalsHelper = compiler.findHelper(const SourceString('eq'));
+ HInstruction target = new HStatic(equalsHelper);
+ add(target);
+ push(new HEquals(target, caseExpression, expression));
+ }
Lasse Reichstein Nielsen 2012/03/06 08:57:14 Am I right that this only handles one case express
ahe 2012/03/06 09:16:50 Yes. I called this fall-through and report it as u
+ handleIf(handleThen, handleElse);
+ }
+
+ localsHandler.startLoop(node);
Lasse Reichstein Nielsen 2012/03/06 08:57:14 Is this loop just to give a target for unnamed bre
ahe 2012/03/06 09:16:50 It serves that purpose right now. However, it'll s
+ BreakHandler breakHandler = beginLoopHeader(node);
+ HBasicBlock loopEntryBlock = current;
+ localsHandler.enterLoopBody(node);
+
+ handleElse();
+
+ if (isAborted()) {
+ compiler.unimplemented("SsaBuilder for loop with aborting body",
+ node: node);
+ }
+
+ HBasicBlock bodyExitBlock = close(new HGoto());
+ HBasicBlock conditionBlock = addNewBlock();
+ bodyExitBlock.addSuccessor(conditionBlock);
+ open(conditionBlock);
+ stack.add(graph.addNewLiteralBool(false));
+
+ conditionBlock = close(new HLoopBranch(popBoolified(),
+ HLoopBranch.DO_WHILE_LOOP));
+
+ conditionBlock.addSuccessor(loopEntryBlock); // The back-edge.
+ loopEntryBlock.postProcessLoopHeader();
+
+ endLoop(loopEntryBlock, conditionBlock, breakHandler);
}
visitTryStatement(TryStatement node) {
« no previous file with comments | « no previous file | dart/frog/leg/ssa/closure.dart » ('j') | dart/frog/leg/ssa/optimize.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698