| 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:kernel/ast.dart' as ir; | 5 import 'package:kernel/ast.dart' as ir; |
| 6 | 6 |
| 7 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; | 7 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; |
| 8 import '../common/tasks.dart' show CompilerTask; | 8 import '../common/tasks.dart' show CompilerTask; |
| 9 import '../compiler.dart'; | 9 import '../compiler.dart'; |
| 10 import '../diagnostics/spannable.dart'; | 10 import '../diagnostics/spannable.dart'; |
| 11 import '../elements/elements.dart'; | 11 import '../elements/elements.dart'; |
| 12 import '../io/source_information.dart'; | 12 import '../io/source_information.dart'; |
| 13 import '../js_backend/backend.dart' show JavaScriptBackend; | 13 import '../js_backend/backend.dart' show JavaScriptBackend; |
| 14 import '../kernel/kernel.dart'; | 14 import '../kernel/kernel.dart'; |
| 15 import '../kernel/kernel_visitor.dart'; | 15 import '../kernel/kernel_visitor.dart'; |
| 16 import '../resolution/tree_elements.dart'; | 16 import '../resolution/tree_elements.dart'; |
| 17 import '../tree/dartstring.dart'; | 17 import '../tree/dartstring.dart'; |
| 18 import '../types/masks.dart'; |
| 18 | 19 |
| 19 import 'graph_builder.dart'; | 20 import 'graph_builder.dart'; |
| 20 import 'kernel_ast_adapter.dart'; | 21 import 'kernel_ast_adapter.dart'; |
| 21 import 'locals_handler.dart'; | 22 import 'locals_handler.dart'; |
| 22 import 'nodes.dart'; | 23 import 'nodes.dart'; |
| 23 | 24 |
| 24 class SsaKernelBuilderTask extends CompilerTask { | 25 class SsaKernelBuilderTask extends CompilerTask { |
| 25 final JavaScriptBackend backend; | 26 final JavaScriptBackend backend; |
| 26 final SourceInformationStrategy sourceInformationFactory; | 27 final SourceInformationStrategy sourceInformationFactory; |
| 27 | 28 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 43 } catch (e) { | 44 } catch (e) { |
| 44 throw "Failed to convert to Kernel IR: $e"; | 45 throw "Failed to convert to Kernel IR: $e"; |
| 45 } | 46 } |
| 46 KernelSsaBuilder builder = new KernelSsaBuilder( | 47 KernelSsaBuilder builder = new KernelSsaBuilder( |
| 47 function, | 48 function, |
| 48 element, | 49 element, |
| 49 work.resolvedAst, | 50 work.resolvedAst, |
| 50 backend.compiler, | 51 backend.compiler, |
| 51 work.registry, | 52 work.registry, |
| 52 sourceInformationFactory, | 53 sourceInformationFactory, |
| 53 visitor); | 54 visitor, |
| 55 kernel); |
| 54 return builder.build(); | 56 return builder.build(); |
| 55 }); | 57 }); |
| 56 } | 58 } |
| 57 } | 59 } |
| 58 | 60 |
| 59 class KernelSsaBuilder extends ir.Visitor with GraphBuilder { | 61 class KernelSsaBuilder extends ir.Visitor with GraphBuilder { |
| 60 final IrFunction function; | 62 final IrFunction function; |
| 61 final FunctionElement functionElement; | 63 final FunctionElement functionElement; |
| 62 final ResolvedAst resolvedAst; | 64 final ResolvedAst resolvedAst; |
| 63 final Compiler compiler; | 65 final Compiler compiler; |
| 64 final CodegenRegistry registry; | 66 final CodegenRegistry registry; |
| 65 | 67 |
| 66 JavaScriptBackend get backend => compiler.backend; | 68 JavaScriptBackend get backend => compiler.backend; |
| 67 | 69 |
| 68 LocalsHandler localsHandler; | 70 LocalsHandler localsHandler; |
| 69 SourceInformationBuilder sourceInformationBuilder; | 71 SourceInformationBuilder sourceInformationBuilder; |
| 70 KernelAstAdapter astAdapter; | 72 KernelAstAdapter astAdapter; |
| 71 | 73 |
| 72 KernelSsaBuilder( | 74 KernelSsaBuilder( |
| 73 this.function, | 75 this.function, |
| 74 this.functionElement, | 76 this.functionElement, |
| 75 this.resolvedAst, | 77 this.resolvedAst, |
| 76 this.compiler, | 78 this.compiler, |
| 77 this.registry, | 79 this.registry, |
| 78 SourceInformationStrategy sourceInformationFactory, | 80 SourceInformationStrategy sourceInformationFactory, |
| 79 KernelVisitor visitor) { | 81 KernelVisitor visitor, |
| 82 Kernel kernel) { |
| 80 graph.element = functionElement; | 83 graph.element = functionElement; |
| 81 // TODO(het): Should sourceInformationBuilder be in GraphBuilder? | 84 // TODO(het): Should sourceInformationBuilder be in GraphBuilder? |
| 82 this.sourceInformationBuilder = | 85 this.sourceInformationBuilder = |
| 83 sourceInformationFactory.createBuilderForContext(resolvedAst); | 86 sourceInformationFactory.createBuilderForContext(resolvedAst); |
| 84 graph.sourceInformation = | 87 graph.sourceInformation = |
| 85 sourceInformationBuilder.buildVariableDeclaration(); | 88 sourceInformationBuilder.buildVariableDeclaration(); |
| 86 this.localsHandler = | 89 this.localsHandler = |
| 87 new LocalsHandler(this, functionElement, null, compiler); | 90 new LocalsHandler(this, functionElement, null, compiler); |
| 88 this.astAdapter = | 91 this.astAdapter = new KernelAstAdapter(compiler.backend, resolvedAst, |
| 89 new KernelAstAdapter(compiler.backend, resolvedAst, visitor.nodeToAst); | 92 visitor.nodeToAst, visitor.nodeToElement, kernel.functions); |
| 90 } | 93 } |
| 91 | 94 |
| 92 HGraph build() { | 95 HGraph build() { |
| 93 // TODO(het): no reason to do this here... | 96 // TODO(het): no reason to do this here... |
| 94 HInstruction.idCounter = 0; | 97 HInstruction.idCounter = 0; |
| 95 if (function.kind == ir.ProcedureKind.Method) { | 98 if (function.kind == ir.ProcedureKind.Method) { |
| 96 buildMethod(function, functionElement); | 99 buildMethod(function, functionElement); |
| 97 } else { | 100 } else { |
| 98 compiler.reporter.internalError( | 101 compiler.reporter.internalError( |
| 99 functionElement, | 102 functionElement, |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 } | 182 } |
| 180 | 183 |
| 181 @override | 184 @override |
| 182 visitStringLiteral(ir.StringLiteral stringLiteral) { | 185 visitStringLiteral(ir.StringLiteral stringLiteral) { |
| 183 stack.add(graph.addConstantString( | 186 stack.add(graph.addConstantString( |
| 184 new DartString.literal(stringLiteral.value), compiler)); | 187 new DartString.literal(stringLiteral.value), compiler)); |
| 185 } | 188 } |
| 186 | 189 |
| 187 @override | 190 @override |
| 188 visitSymbolLiteral(ir.SymbolLiteral symbolLiteral) { | 191 visitSymbolLiteral(ir.SymbolLiteral symbolLiteral) { |
| 189 stack.add( | 192 stack.add(graph.addConstant( |
| 190 graph.addConstant(astAdapter.getConstantFor(symbolLiteral), compiler)); | 193 astAdapter.getConstantForSymbol(symbolLiteral), compiler)); |
| 191 registry?.registerConstSymbol(symbolLiteral.value); | 194 registry?.registerConstSymbol(symbolLiteral.value); |
| 192 } | 195 } |
| 193 | 196 |
| 194 @override | 197 @override |
| 195 visitNullLiteral(ir.NullLiteral nullLiteral) { | 198 visitNullLiteral(ir.NullLiteral nullLiteral) { |
| 196 stack.add(graph.addConstantNull(compiler)); | 199 stack.add(graph.addConstantNull(compiler)); |
| 197 } | 200 } |
| 201 |
| 202 @override |
| 203 visitVariableGet(ir.VariableGet variableGet) { |
| 204 LocalElement local = astAdapter.getElement(variableGet.variable); |
| 205 stack.add(localsHandler.readLocal(local)); |
| 206 } |
| 207 |
| 208 @override |
| 209 visitStaticInvocation(ir.StaticInvocation invocation) { |
| 210 List<HInstruction> inputs = <HInstruction>[]; |
| 211 |
| 212 for (ir.Expression argument in invocation.arguments.positional) { |
| 213 argument.accept(this); |
| 214 inputs.add(pop()); |
| 215 } |
| 216 for (ir.NamedExpression argument in invocation.arguments.named) { |
| 217 argument.value.accept(this); |
| 218 inputs.add(pop()); |
| 219 } |
| 220 |
| 221 ir.Procedure target = invocation.target; |
| 222 bool targetCanThrow = astAdapter.getCanThrow(target); |
| 223 TypeMask typeMask = astAdapter.returnTypeOf(target); |
| 224 |
| 225 HInstruction instruction = new HInvokeStatic( |
| 226 astAdapter.getElement(target).declaration, inputs, typeMask, |
| 227 targetCanThrow: targetCanThrow); |
| 228 instruction.sideEffects = astAdapter.getSideEffects(target); |
| 229 |
| 230 push(instruction); |
| 231 } |
| 232 |
| 233 @override |
| 234 visitExpressionStatement(ir.ExpressionStatement exprStatement) { |
| 235 exprStatement.expression.accept(this); |
| 236 pop(); |
| 237 } |
| 198 } | 238 } |
| OLD | NEW |