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

Side by Side Diff: pkg/compiler/lib/src/ssa/builder_kernel.dart

Issue 2280133002: implement kernel -> ssa for literals (Closed)
Patch Set: put ast accesses in separate class 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'package:compiler/src/ssa/kernel_ast_adapter.dart';
Siggi Cherem (dart-lang) 2016/08/26 20:27:11 nit: use relative import? (just to be homogeneous
5 import 'package:kernel/ast.dart' as ir; 6 import 'package:kernel/ast.dart' as ir;
6 7
7 import '../common/codegen.dart' show CodegenWorkItem; 8 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem;
8 import '../common/tasks.dart' show CompilerTask; 9 import '../common/tasks.dart' show CompilerTask;
9 import '../compiler.dart'; 10 import '../compiler.dart';
10 import '../diagnostics/spannable.dart'; 11 import '../diagnostics/spannable.dart';
11 import '../elements/elements.dart'; 12 import '../elements/elements.dart';
12 import '../io/source_information.dart'; 13 import '../io/source_information.dart';
13 import '../js_backend/backend.dart' show JavaScriptBackend; 14 import '../js_backend/backend.dart' show JavaScriptBackend;
14 import '../kernel/kernel.dart'; 15 import '../kernel/kernel.dart';
15 import '../kernel/kernel_visitor.dart'; 16 import '../kernel/kernel_visitor.dart';
16 import '../resolution/tree_elements.dart'; 17 import '../resolution/tree_elements.dart';
18 import '../tree/dartstring.dart';
17 import 'graph_builder.dart'; 19 import 'graph_builder.dart';
18 import 'locals_handler.dart'; 20 import 'locals_handler.dart';
19 import 'nodes.dart'; 21 import 'nodes.dart';
20 22
21 class SsaKernelBuilderTask extends CompilerTask { 23 class SsaKernelBuilderTask extends CompilerTask {
22 final JavaScriptBackend backend; 24 final JavaScriptBackend backend;
23 final SourceInformationStrategy sourceInformationFactory; 25 final SourceInformationStrategy sourceInformationFactory;
24 26
25 String get name => 'SSA kernel builder'; 27 String get name => 'SSA kernel builder';
26 28
(...skipping 11 matching lines...) Expand all
38 try { 40 try {
39 function = visitor.buildFunction(); 41 function = visitor.buildFunction();
40 } catch (e) { 42 } catch (e) {
41 throw "Failed to convert to Kernel IR: $e"; 43 throw "Failed to convert to Kernel IR: $e";
42 } 44 }
43 KernelSsaBuilder builder = new KernelSsaBuilder( 45 KernelSsaBuilder builder = new KernelSsaBuilder(
44 function, 46 function,
45 element, 47 element,
46 work.resolvedAst, 48 work.resolvedAst,
47 backend.compiler, 49 backend.compiler,
50 work.registry,
48 sourceInformationFactory, 51 sourceInformationFactory,
49 visitor.nodeToElement); 52 visitor);
50 return builder.build(); 53 return builder.build();
51 }); 54 });
52 } 55 }
53 } 56 }
54 57
55 class KernelSsaBuilder extends ir.Visitor with GraphBuilder { 58 class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
56 final IrFunction function; 59 final IrFunction function;
57 final FunctionElement functionElement; 60 final FunctionElement functionElement;
58 final ResolvedAst resolvedAst; 61 final ResolvedAst resolvedAst;
59 final Compiler compiler; 62 final Compiler compiler;
60 final Map<ir.Node, Element> nodeToElement; 63 final CodegenRegistry registry;
61 64
62 JavaScriptBackend get backend => compiler.backend; 65 JavaScriptBackend get backend => compiler.backend;
63 66
64 LocalsHandler localsHandler; 67 LocalsHandler localsHandler;
65 SourceInformationBuilder sourceInformationBuilder; 68 SourceInformationBuilder sourceInformationBuilder;
69 KernelAstAdapter astAdapter;
66 70
67 KernelSsaBuilder( 71 KernelSsaBuilder(
68 this.function, 72 this.function,
69 this.functionElement, 73 this.functionElement,
70 this.resolvedAst, 74 this.resolvedAst,
71 this.compiler, 75 this.compiler,
76 this.registry,
72 SourceInformationStrategy sourceInformationFactory, 77 SourceInformationStrategy sourceInformationFactory,
73 this.nodeToElement) { 78 KernelVisitor visitor) {
74 graph.element = functionElement; 79 graph.element = functionElement;
75 // TODO(het): Should sourceInformationBuilder be in GraphBuilder? 80 // TODO(het): Should sourceInformationBuilder be in GraphBuilder?
76 this.sourceInformationBuilder = 81 this.sourceInformationBuilder =
77 sourceInformationFactory.createBuilderForContext(resolvedAst); 82 sourceInformationFactory.createBuilderForContext(resolvedAst);
78 graph.sourceInformation = 83 graph.sourceInformation =
79 sourceInformationBuilder.buildVariableDeclaration(); 84 sourceInformationBuilder.buildVariableDeclaration();
80 this.localsHandler = 85 this.localsHandler =
81 new LocalsHandler(this, functionElement, null, compiler); 86 new LocalsHandler(this, functionElement, null, compiler);
87 this.astAdapter =
88 new KernelAstAdapter(compiler.backend, resolvedAst, visitor.nodeToAst);
82 } 89 }
83 90
84 HGraph build() { 91 HGraph build() {
85 // TODO(het): no reason to do this here... 92 // TODO(het): no reason to do this here...
86 HInstruction.idCounter = 0; 93 HInstruction.idCounter = 0;
87 if (function.kind == ir.ProcedureKind.Method) { 94 if (function.kind == ir.ProcedureKind.Method) {
88 buildMethod(function, functionElement); 95 buildMethod(function, functionElement);
89 } else { 96 } else {
90 compiler.reporter.internalError( 97 compiler.reporter.internalError(
91 functionElement, 98 functionElement,
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 // TODO(het): Add source information 159 // TODO(het): Add source information
153 // TODO(het): Set a return value instead of closing the function when we 160 // TODO(het): Set a return value instead of closing the function when we
154 // support inlining. 161 // support inlining.
155 closeAndGotoExit(new HReturn(value, null)); 162 closeAndGotoExit(new HReturn(value, null));
156 } 163 }
157 164
158 @override 165 @override
159 void visitIntLiteral(ir.IntLiteral intLiteral) { 166 void visitIntLiteral(ir.IntLiteral intLiteral) {
160 stack.add(graph.addConstantInt(intLiteral.value, compiler)); 167 stack.add(graph.addConstantInt(intLiteral.value, compiler));
161 } 168 }
169
170 @override
171 visitDoubleLiteral(ir.DoubleLiteral doubleLiteral) {
172 stack.add(graph.addConstantDouble(doubleLiteral.value, compiler));
173 }
174
175 @override
176 visitBoolLiteral(ir.BoolLiteral boolLiteral) {
177 stack.add(graph.addConstantBool(boolLiteral.value, compiler));
178 }
179
180 @override
181 visitStringLiteral(ir.StringLiteral stringLiteral) {
182 stack.add(graph.addConstantString(
183 new DartString.literal(stringLiteral.value), compiler));
184 }
185
186 @override
187 visitSymbolLiteral(ir.SymbolLiteral symbolLiteral) {
188 stack.add(
189 graph.addConstant(astAdapter.getConstantFor(symbolLiteral), compiler));
190 registry?.registerConstSymbol(symbolLiteral.value);
191 }
192
193 @override
194 visitNullLiteral(ir.NullLiteral nullLiteral) {
195 stack.add(graph.addConstantNull(compiler));
196 }
162 } 197 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698