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

Unified Diff: pkg/compiler/lib/src/ssa/builder_kernel.dart

Issue 2335203005: kernel -> ssa: implement literal maps (Closed)
Patch Set: Created 4 years, 3 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 | « pkg/compiler/lib/src/kernel/kernel_visitor.dart ('k') | pkg/compiler/lib/src/ssa/kernel_ast_adapter.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/ssa/builder_kernel.dart
diff --git a/pkg/compiler/lib/src/ssa/builder_kernel.dart b/pkg/compiler/lib/src/ssa/builder_kernel.dart
index b670e6451868f0e1434d7aae31b8f74f9f30e8cb..93eae3dfe7c785696090bf79cc61fc33a1ca2864 100644
--- a/pkg/compiler/lib/src/ssa/builder_kernel.dart
+++ b/pkg/compiler/lib/src/ssa/builder_kernel.dart
@@ -70,15 +70,8 @@ class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
graph.sourceInformation =
sourceInformationBuilder.buildVariableDeclaration();
this.localsHandler = new LocalsHandler(this, targetElement, null, compiler);
- this.astAdapter = new KernelAstAdapter(
- compiler.backend,
- resolvedAst,
- kernel.nodeToAst,
- kernel.nodeToElement,
- kernel.fields,
- kernel.functions,
- kernel.classes,
- kernel.libraries);
+ this.astAdapter = new KernelAstAdapter(kernel, compiler.backend,
+ resolvedAst, kernel.nodeToAst, kernel.nodeToElement);
Element originTarget = targetElement;
if (originTarget.isPatch) {
originTarget = originTarget.origin;
@@ -300,6 +293,47 @@ class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
}
@override
+ void visitMapLiteral(ir.MapLiteral mapLiteral) {
+ if (mapLiteral.isConst) {
+ stack.add(
+ graph.addConstant(astAdapter.getConstantFor(mapLiteral), compiler));
+ return;
+ }
+
+ // The map literal constructors take the key-value pairs as a List
+ List<HInstruction> constructorArgs = <HInstruction>[];
+ for (ir.MapEntry mapEntry in mapLiteral.entries) {
+ mapEntry.accept(this);
+ constructorArgs.add(pop());
+ constructorArgs.add(pop());
+ }
+
+ // The constructor is a procedure because it's a factory.
+ ir.Procedure constructor;
+ List<HInstruction> inputs = <HInstruction>[];
+ if (constructorArgs.isEmpty) {
+ constructor = astAdapter.mapLiteralConstructorEmpty;
+ } else {
+ constructor = astAdapter.mapLiteralConstructor;
+ HLiteralList argList =
+ new HLiteralList(constructorArgs, backend.extendableArrayType);
+ add(argList);
+ inputs.add(argList);
+ }
+
+ // TODO(het): Add type information
+ _pushStaticInvocation(constructor, inputs, backend.dynamicType);
+ }
+
+ @override
+ void visitMapEntry(ir.MapEntry mapEntry) {
+ // Visit value before the key because each will push an expression to the
+ // stack, so when we pop them off, the key is popped first, then the value.
+ mapEntry.value.accept(this);
+ mapEntry.key.accept(this);
+ }
+
+ @override
void visitStaticGet(ir.StaticGet staticGet) {
var staticTarget = staticGet.target;
Element element = astAdapter.getElement(staticTarget).declaration;
@@ -415,11 +449,9 @@ class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
void _pushStaticInvocation(
ir.Node target, List<HInstruction> arguments, TypeMask typeMask) {
- bool targetCanThrow = astAdapter.getCanThrow(target);
-
HInstruction instruction = new HInvokeStatic(
astAdapter.getElement(target).declaration, arguments, typeMask,
- targetCanThrow: targetCanThrow);
+ targetCanThrow: astAdapter.getCanThrow(target));
instruction.sideEffects = astAdapter.getSideEffects(target);
push(instruction);
« no previous file with comments | « pkg/compiler/lib/src/kernel/kernel_visitor.dart ('k') | pkg/compiler/lib/src/ssa/kernel_ast_adapter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698