OLD | NEW |
---|---|
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/ssa_branch_builder.dart'; | |
5 import 'package:kernel/ast.dart' as ir; | 6 import 'package:kernel/ast.dart' as ir; |
6 | 7 |
7 import '../common/codegen.dart' show CodegenRegistry, 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'; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 | 61 |
61 class KernelSsaBuilder extends ir.Visitor with GraphBuilder { | 62 class KernelSsaBuilder extends ir.Visitor with GraphBuilder { |
62 final IrFunction function; | 63 final IrFunction function; |
63 final FunctionElement functionElement; | 64 final FunctionElement functionElement; |
64 final ResolvedAst resolvedAst; | 65 final ResolvedAst resolvedAst; |
65 final Compiler compiler; | 66 final Compiler compiler; |
66 final CodegenRegistry registry; | 67 final CodegenRegistry registry; |
67 | 68 |
68 JavaScriptBackend get backend => compiler.backend; | 69 JavaScriptBackend get backend => compiler.backend; |
69 | 70 |
70 LocalsHandler localsHandler; | |
71 SourceInformationBuilder sourceInformationBuilder; | 71 SourceInformationBuilder sourceInformationBuilder; |
72 KernelAstAdapter astAdapter; | 72 KernelAstAdapter astAdapter; |
73 | 73 |
74 KernelSsaBuilder( | 74 KernelSsaBuilder( |
75 this.function, | 75 this.function, |
76 this.functionElement, | 76 this.functionElement, |
77 this.resolvedAst, | 77 this.resolvedAst, |
78 this.compiler, | 78 this.compiler, |
79 this.registry, | 79 this.registry, |
80 SourceInformationStrategy sourceInformationFactory, | 80 SourceInformationStrategy sourceInformationFactory, |
(...skipping 25 matching lines...) Expand all Loading... | |
106 } else { | 106 } else { |
107 compiler.reporter.internalError( | 107 compiler.reporter.internalError( |
108 functionElement, | 108 functionElement, |
109 "Unable to convert this kind of Kernel " | 109 "Unable to convert this kind of Kernel " |
110 "procedure to SSA: ${function.kind}"); | 110 "procedure to SSA: ${function.kind}"); |
111 } | 111 } |
112 assert(graph.isValid()); | 112 assert(graph.isValid()); |
113 return graph; | 113 return graph; |
114 } | 114 } |
115 | 115 |
116 @override | |
117 HBoolify popBoolified() { | |
118 HInstruction value = pop(); | |
119 // TODO(het): add boolean conversion type check | |
Siggi Cherem (dart-lang)
2016/09/01 23:51:21
once you do, would this method move to GraphBuilde
Harry Terkelsen
2016/09/02 17:52:27
Yes, if we also pass in the boolType
| |
120 HInstruction result = new HBoolify(value, backend.boolType); | |
121 add(result); | |
122 return result; | |
123 } | |
124 | |
125 // TODO(het): This implementation is shared with [SsaBuilder]. Should we just | |
126 // allow [GraphBuilder] to access `compiler`? | |
Siggi Cherem (dart-lang)
2016/09/01 23:51:22
seems ok, is it only for boolType? We could also j
Harry Terkelsen
2016/09/02 17:52:27
It's for boolType and for the 'compiler' argument
| |
127 @override | |
128 pushCheckNull(HInstruction expression) { | |
129 push(new HIdentity( | |
130 expression, graph.addConstantNull(compiler), null, backend.boolType)); | |
131 } | |
132 | |
116 /// Builds a SSA graph for [method]. | 133 /// Builds a SSA graph for [method]. |
117 void buildMethod(IrFunction method, FunctionElement functionElement) { | 134 void buildMethod(IrFunction method, FunctionElement functionElement) { |
118 openFunction(method, functionElement); | 135 openFunction(method, functionElement); |
119 method.node.body.accept(this); | 136 method.node.body.accept(this); |
120 closeFunction(); | 137 closeFunction(); |
121 } | 138 } |
122 | 139 |
123 void openFunction(IrFunction method, FunctionElement functionElement) { | 140 void openFunction(IrFunction method, FunctionElement functionElement) { |
124 HBasicBlock block = graph.addNewBlock(); | 141 HBasicBlock block = graph.addNewBlock(); |
125 open(graph.entry); | 142 open(graph.entry); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
165 value = pop(); | 182 value = pop(); |
166 // TODO(het): Check or trust the type of value | 183 // TODO(het): Check or trust the type of value |
167 } | 184 } |
168 // TODO(het): Add source information | 185 // TODO(het): Add source information |
169 // TODO(het): Set a return value instead of closing the function when we | 186 // TODO(het): Set a return value instead of closing the function when we |
170 // support inlining. | 187 // support inlining. |
171 closeAndGotoExit(new HReturn(value, null)); | 188 closeAndGotoExit(new HReturn(value, null)); |
172 } | 189 } |
173 | 190 |
174 @override | 191 @override |
192 void visitIfStatement(ir.IfStatement ifStatement) { | |
193 SsaBranchBuilder branchBuilder = new SsaBranchBuilder(this, compiler); | |
194 branchBuilder.handleIf( | |
195 () => ifStatement.condition.accept(this), | |
196 () => ifStatement.then.accept(this), | |
197 () => ifStatement.otherwise?.accept(this)); | |
198 } | |
199 | |
200 @override | |
175 void visitIntLiteral(ir.IntLiteral intLiteral) { | 201 void visitIntLiteral(ir.IntLiteral intLiteral) { |
176 stack.add(graph.addConstantInt(intLiteral.value, compiler)); | 202 stack.add(graph.addConstantInt(intLiteral.value, compiler)); |
177 } | 203 } |
178 | 204 |
179 @override | 205 @override |
180 visitDoubleLiteral(ir.DoubleLiteral doubleLiteral) { | 206 visitDoubleLiteral(ir.DoubleLiteral doubleLiteral) { |
181 stack.add(graph.addConstantDouble(doubleLiteral.value, compiler)); | 207 stack.add(graph.addConstantDouble(doubleLiteral.value, compiler)); |
182 } | 208 } |
183 | 209 |
184 @override | 210 @override |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
273 visitThisExpression(ir.ThisExpression thisExpression) { | 299 visitThisExpression(ir.ThisExpression thisExpression) { |
274 stack.add(localsHandler.readThis()); | 300 stack.add(localsHandler.readThis()); |
275 } | 301 } |
276 | 302 |
277 @override | 303 @override |
278 visitExpressionStatement(ir.ExpressionStatement exprStatement) { | 304 visitExpressionStatement(ir.ExpressionStatement exprStatement) { |
279 exprStatement.expression.accept(this); | 305 exprStatement.expression.accept(this); |
280 pop(); | 306 pop(); |
281 } | 307 } |
282 } | 308 } |
OLD | NEW |