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

Unified Diff: lib/compiler/implementation/ssa/codegen.dart

Issue 10544024: Implement constant switch as JS switch. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments. Added to Tracer. Created 8 years, 6 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 | « lib/compiler/implementation/ssa/builder.dart ('k') | lib/compiler/implementation/ssa/nodes.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/compiler/implementation/ssa/codegen.dart
diff --git a/lib/compiler/implementation/ssa/codegen.dart b/lib/compiler/implementation/ssa/codegen.dart
index 9cc988411b3e3f105236564871650d7325532a1d..7e8337c9963558331560c477cf0f63b6b68a4b2e 100644
--- a/lib/compiler/implementation/ssa/codegen.dart
+++ b/lib/compiler/implementation/ssa/codegen.dart
@@ -633,6 +633,45 @@ class SsaCodeGenerator implements HVisitor, HBlockInformationVisitor {
return true;
}
+ bool visitSwitchInfo(HSwitchBlockInformation info) {
+ bool isExpression = isJSExpression(info.expression);
+ if (!isExpression) {
+ generateStatements(info.expression);
+ }
+ addIndentation();
+ for (LabelElement label in info.labels) {
+ if (label.isTarget) {
+ writeLabel(label);
+ buffer.add(":");
+ }
+ }
+ addIndented("switch (");
+ if (isExpression) {
+ generateExpression(info.expression);
+ } else {
+ use(info.expression.conditionExpression,
+ JSPrecedence.EXPRESSION_PRECEDENCE);
+ }
+ buffer.add(") {\n");
+ indent++;
+ for (int i = 0; i < info.matchExpressions.length; i++) {
+ for (Constant constant in info.matchExpressions[i]) {
+ addIndented("case ");
+ generateConstant(constant);
+ buffer.add(":\n");
+ }
+ if (i == info.matchExpressions.length - 1 && info.hasDefault) {
+ addIndented("default:\n");
+ }
+ indent++;
+ generateStatements(info.statements[i]);
+ indent--;
+ }
+ indent--;
+ addIndented("}\n");
+ return true;
+ }
+
bool visitSequenceInfo(HStatementSequenceInformation info) {
return false;
}
@@ -1565,28 +1604,33 @@ class SsaCodeGenerator implements HVisitor, HBlockInformationVisitor {
endExpression(JSPrecedence.MEMBER_PRECEDENCE);
}
- visitConstant(HConstant node) {
- assert(isGenerateAtUseSite(node));
+ void generateConstant(Constant constant) {
// TODO(floitsch): the compile-time constant handler and the codegen
// need to work together to avoid the parenthesis. See r4928 for an
// implementation that still dealt with precedence.
ConstantHandler handler = compiler.constantHandler;
- String name = handler.getNameForConstant(node.constant);
+ String name = handler.getNameForConstant(constant);
if (name === null) {
- assert(!node.constant.isObject());
- if (node.constant.isNum()
+ assert(!constant.isObject());
+ if (constant.isNum()
&& expectedPrecedence == JSPrecedence.MEMBER_PRECEDENCE) {
buffer.add('(');
- handler.writeConstant(buffer, node.constant);
+ handler.writeConstant(buffer, constant);
buffer.add(')');
} else {
- handler.writeConstant(buffer, node.constant);
+ handler.writeConstant(buffer, constant);
}
} else {
buffer.add(compiler.namer.CURRENT_ISOLATE);
buffer.add(".");
buffer.add(name);
}
+
+ }
+
+ visitConstant(HConstant node) {
+ assert(isGenerateAtUseSite(node));
+ generateConstant(node.constant);
}
visitLoopBranch(HLoopBranch node) {
@@ -1794,6 +1838,10 @@ class SsaCodeGenerator implements HVisitor, HBlockInformationVisitor {
buffer.add(text);
}
+ void visitSwitch(HSwitch node) {
+ // Switches are handled using [visitSwitchInfo].
+ }
+
void visitStatic(HStatic node) {
world.registerStaticUse(node.element);
buffer.add(compiler.namer.isolateAccess(node.element));
« no previous file with comments | « lib/compiler/implementation/ssa/builder.dart ('k') | lib/compiler/implementation/ssa/nodes.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698