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

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

Issue 2280133002: implement kernel -> ssa for literals (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 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/constants/values.dart';
6 import 'package:compiler/src/diagnostics/invariant.dart';
5 import 'package:kernel/ast.dart' as ir; 7 import 'package:kernel/ast.dart' as ir;
6 8
7 import '../common/codegen.dart' show CodegenWorkItem; 9 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem;
8 import '../common/tasks.dart' show CompilerTask; 10 import '../common/tasks.dart' show CompilerTask;
9 import '../compiler.dart'; 11 import '../compiler.dart';
10 import '../diagnostics/spannable.dart'; 12 import '../diagnostics/spannable.dart';
11 import '../elements/elements.dart'; 13 import '../elements/elements.dart';
12 import '../io/source_information.dart'; 14 import '../io/source_information.dart';
13 import '../js_backend/backend.dart' show JavaScriptBackend; 15 import '../js_backend/backend.dart' show JavaScriptBackend;
14 import '../kernel/kernel.dart'; 16 import '../kernel/kernel.dart';
15 import '../kernel/kernel_visitor.dart'; 17 import '../kernel/kernel_visitor.dart';
16 import '../resolution/tree_elements.dart'; 18 import '../resolution/tree_elements.dart';
19 import '../tree/tree.dart' as ast;
17 import 'graph_builder.dart'; 20 import 'graph_builder.dart';
18 import 'locals_handler.dart'; 21 import 'locals_handler.dart';
19 import 'nodes.dart'; 22 import 'nodes.dart';
20 23
21 class SsaKernelBuilderTask extends CompilerTask { 24 class SsaKernelBuilderTask extends CompilerTask {
22 final JavaScriptBackend backend; 25 final JavaScriptBackend backend;
23 final SourceInformationStrategy sourceInformationFactory; 26 final SourceInformationStrategy sourceInformationFactory;
24 27
25 String get name => 'SSA kernel builder'; 28 String get name => 'SSA kernel builder';
26 29
(...skipping 11 matching lines...) Expand all
38 try { 41 try {
39 function = visitor.buildFunction(); 42 function = visitor.buildFunction();
40 } catch (e) { 43 } catch (e) {
41 throw "Failed to convert to Kernel IR: $e"; 44 throw "Failed to convert to Kernel IR: $e";
42 } 45 }
43 KernelSsaBuilder builder = new KernelSsaBuilder( 46 KernelSsaBuilder builder = new KernelSsaBuilder(
44 function, 47 function,
45 element, 48 element,
46 work.resolvedAst, 49 work.resolvedAst,
47 backend.compiler, 50 backend.compiler,
51 work.registry,
48 sourceInformationFactory, 52 sourceInformationFactory,
49 visitor.nodeToElement); 53 visitor.nodeToElement,
54 visitor.nodeToAst);
50 return builder.build(); 55 return builder.build();
51 }); 56 });
52 } 57 }
53 } 58 }
54 59
55 class KernelSsaBuilder extends ir.Visitor with GraphBuilder { 60 class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
56 final IrFunction function; 61 final IrFunction function;
57 final FunctionElement functionElement; 62 final FunctionElement functionElement;
58 final ResolvedAst resolvedAst; 63 final ResolvedAst resolvedAst;
59 final Compiler compiler; 64 final Compiler compiler;
65 final CodegenRegistry registry;
60 final Map<ir.Node, Element> nodeToElement; 66 final Map<ir.Node, Element> nodeToElement;
67 final Map<ir.Node, ast.Node> nodeToAst;
61 68
62 JavaScriptBackend get backend => compiler.backend; 69 JavaScriptBackend get backend => compiler.backend;
63 70
64 LocalsHandler localsHandler; 71 LocalsHandler localsHandler;
65 SourceInformationBuilder sourceInformationBuilder; 72 SourceInformationBuilder sourceInformationBuilder;
66 73
67 KernelSsaBuilder( 74 KernelSsaBuilder(
68 this.function, 75 this.function,
69 this.functionElement, 76 this.functionElement,
70 this.resolvedAst, 77 this.resolvedAst,
71 this.compiler, 78 this.compiler,
79 this.registry,
72 SourceInformationStrategy sourceInformationFactory, 80 SourceInformationStrategy sourceInformationFactory,
73 this.nodeToElement) { 81 this.nodeToElement,
82 this.nodeToAst) {
74 graph.element = functionElement; 83 graph.element = functionElement;
75 // TODO(het): Should sourceInformationBuilder be in GraphBuilder? 84 // TODO(het): Should sourceInformationBuilder be in GraphBuilder?
76 this.sourceInformationBuilder = 85 this.sourceInformationBuilder =
77 sourceInformationFactory.createBuilderForContext(resolvedAst); 86 sourceInformationFactory.createBuilderForContext(resolvedAst);
78 graph.sourceInformation = 87 graph.sourceInformation =
79 sourceInformationBuilder.buildVariableDeclaration(); 88 sourceInformationBuilder.buildVariableDeclaration();
80 this.localsHandler = 89 this.localsHandler =
81 new LocalsHandler(this, functionElement, null, compiler); 90 new LocalsHandler(this, functionElement, null, compiler);
82 } 91 }
83 92
(...skipping 27 matching lines...) Expand all
111 close(new HGoto()).addSuccessor(block); 120 close(new HGoto()).addSuccessor(block);
112 121
113 open(block); 122 open(block);
114 } 123 }
115 124
116 void closeFunction() { 125 void closeFunction() {
117 if (!isAborted()) closeAndGotoExit(new HGoto()); 126 if (!isAborted()) closeAndGotoExit(new HGoto());
118 graph.finalize(); 127 graph.finalize();
119 } 128 }
120 129
130 ConstantValue getConstantForNode(ast.Node node) {
Siggi Cherem (dart-lang) 2016/08/26 18:15:57 Let's create a library and a class with the ir->as
Harry Terkelsen 2016/08/26 19:52:57 Done.
131 ConstantValue constantValue =
132 backend.constants.getConstantValueForNode(node, resolvedAst.elements);
133 assert(invariant(node, constantValue != null,
134 message: 'No constant computed for $node'));
135 return constantValue;
136 }
137
121 @override 138 @override
122 void visitBlock(ir.Block block) { 139 void visitBlock(ir.Block block) {
123 assert(!isAborted()); 140 assert(!isAborted());
124 for (ir.Statement statement in block.statements) { 141 for (ir.Statement statement in block.statements) {
125 statement.accept(this); 142 statement.accept(this);
126 if (!isReachable) { 143 if (!isReachable) {
127 // The block has been aborted by a return or a throw. 144 // The block has been aborted by a return or a throw.
128 if (stack.isNotEmpty) { 145 if (stack.isNotEmpty) {
129 compiler.reporter.internalError( 146 compiler.reporter.internalError(
130 NO_LOCATION_SPANNABLE, 'Non-empty instruction stack.'); 147 NO_LOCATION_SPANNABLE, 'Non-empty instruction stack.');
(...skipping 21 matching lines...) Expand all
152 // TODO(het): Add source information 169 // TODO(het): Add source information
153 // TODO(het): Set a return value instead of closing the function when we 170 // TODO(het): Set a return value instead of closing the function when we
154 // support inlining. 171 // support inlining.
155 closeAndGotoExit(new HReturn(value, null)); 172 closeAndGotoExit(new HReturn(value, null));
156 } 173 }
157 174
158 @override 175 @override
159 void visitIntLiteral(ir.IntLiteral intLiteral) { 176 void visitIntLiteral(ir.IntLiteral intLiteral) {
160 stack.add(graph.addConstantInt(intLiteral.value, compiler)); 177 stack.add(graph.addConstantInt(intLiteral.value, compiler));
161 } 178 }
179
180 @override
181 visitDoubleLiteral(ir.DoubleLiteral doubleLiteral) {
182 stack.add(graph.addConstantDouble(doubleLiteral.value, compiler));
183 }
184
185 @override
186 visitBoolLiteral(ir.BoolLiteral boolLiteral) {
187 stack.add(graph.addConstantBool(boolLiteral.value, compiler));
188 }
189
190 @override
191 visitStringLiteral(ir.StringLiteral stringLiteral) {
192 stack.add(graph.addConstantString(
193 new ast.DartString.literal(stringLiteral.value), compiler));
Siggi Cherem (dart-lang) 2016/08/26 18:15:57 for now because DartString is pretty independent o
Harry Terkelsen 2016/08/26 19:52:58 Done.
194 }
195
196 @override
197 visitSymbolLiteral(ir.SymbolLiteral symbolLiteral) {
198 stack.add(graph.addConstant(
199 getConstantForNode(nodeToAst[symbolLiteral]), compiler));
200 registry?.registerConstSymbol(symbolLiteral.value);
201 }
202
203 @override
204 visitNullLiteral(ir.NullLiteral nullLiteral) {
205 stack.add(graph.addConstantNull(compiler));
206 }
162 } 207 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/kernel/kernel_visitor.dart ('k') | tests/compiler/dart2js/kernel/simple_function_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698