| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 /// Generate code using the cps-based IR pipeline. | 5 /// Generate code using the cps-based IR pipeline. |
| 6 library code_generator_task; | 6 library code_generator_task; |
| 7 | 7 |
| 8 import 'glue.dart'; | 8 import 'glue.dart'; |
| 9 import 'codegen.dart'; | 9 import 'codegen.dart'; |
| 10 import 'unsugar.dart'; | 10 import 'unsugar.dart'; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 import '../../tracer.dart'; | 27 import '../../tracer.dart'; |
| 28 import '../../js_backend/codegen/codegen.dart'; | 28 import '../../js_backend/codegen/codegen.dart'; |
| 29 import '../../ssa/ssa.dart' as ssa; | 29 import '../../ssa/ssa.dart' as ssa; |
| 30 import '../../tree_ir/optimization/optimization.dart'; | 30 import '../../tree_ir/optimization/optimization.dart'; |
| 31 import '../../tree_ir/optimization/optimization.dart' as tree_opt; | 31 import '../../tree_ir/optimization/optimization.dart' as tree_opt; |
| 32 import '../../tree_ir/tree_ir_integrity.dart'; | 32 import '../../tree_ir/tree_ir_integrity.dart'; |
| 33 import '../../cps_ir/cps_ir_nodes_sexpr.dart'; | 33 import '../../cps_ir/cps_ir_nodes_sexpr.dart'; |
| 34 | 34 |
| 35 class CpsFunctionCompiler implements FunctionCompiler { | 35 class CpsFunctionCompiler implements FunctionCompiler { |
| 36 final ConstantSystem constantSystem; | 36 final ConstantSystem constantSystem; |
| 37 // TODO(karlklose): remove the compiler. |
| 37 final Compiler compiler; | 38 final Compiler compiler; |
| 38 final Glue glue; | 39 final Glue glue; |
| 39 final SourceInformationStrategy sourceInformationFactory; | 40 final SourceInformationStrategy sourceInformationFactory; |
| 40 | 41 |
| 41 // TODO(karlklose,sigurm): remove and update dart-doc of [compile]. | 42 // TODO(karlklose,sigurm): remove and update dart-doc of [compile]. |
| 42 final FunctionCompiler fallbackCompiler; | 43 final FunctionCompiler fallbackCompiler; |
| 43 | 44 |
| 44 Tracer get tracer => compiler.tracer; | 45 Tracer get tracer => compiler.tracer; |
| 45 | 46 |
| 46 IrBuilderTask get irBuilderTask => compiler.irBuilder; | 47 IrBuilderTask get irBuilderTask => compiler.irBuilder; |
| 47 | 48 |
| 48 CpsFunctionCompiler(Compiler compiler, JavaScriptBackend backend, | 49 CpsFunctionCompiler(Compiler compiler, JavaScriptBackend backend, |
| 49 SourceInformationStrategy sourceInformationFactory) | 50 SourceInformationStrategy sourceInformationFactory) |
| 50 : fallbackCompiler = | 51 : fallbackCompiler = |
| 51 new ssa.SsaFunctionCompiler(backend, sourceInformationFactory), | 52 new ssa.SsaFunctionCompiler(backend, sourceInformationFactory), |
| 52 this.sourceInformationFactory = sourceInformationFactory, | 53 this.sourceInformationFactory = sourceInformationFactory, |
| 53 constantSystem = backend.constantSystem, | 54 constantSystem = backend.constantSystem, |
| 54 compiler = compiler, | 55 compiler = compiler, |
| 55 glue = new Glue(compiler); | 56 glue = new Glue(compiler); |
| 56 | 57 |
| 57 String get name => 'CPS Ir pipeline'; | 58 String get name => 'CPS Ir pipeline'; |
| 58 | 59 |
| 60 JavaScriptBackend get backend => compiler.backend; |
| 61 |
| 59 /// Generates JavaScript code for `work.element`. | 62 /// Generates JavaScript code for `work.element`. |
| 60 js.Fun compile(CodegenWorkItem work) { | 63 js.Fun compile(CodegenWorkItem work) { |
| 61 AstElement element = work.element; | 64 AstElement element = work.element; |
| 62 JavaScriptBackend backend = compiler.backend; | 65 JavaScriptBackend backend = compiler.backend; |
| 63 return compiler.withCurrentElement(element, () { | 66 return compiler.withCurrentElement(element, () { |
| 64 try { | 67 try { |
| 65 // TODO(karlklose): remove this fallback. | 68 // TODO(karlklose): remove this fallback. |
| 66 // Fallback for a few functions that we know require try-finally and | 69 // Fallback for a few functions that we know require try-finally and |
| 67 // switch. | 70 // switch. |
| 68 if (element.isNative) { | 71 if (element.isNative) { |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 applyTreePass(new LoopRewriter()); | 209 applyTreePass(new LoopRewriter()); |
| 207 applyTreePass(new LogicalRewriter()); | 210 applyTreePass(new LogicalRewriter()); |
| 208 applyTreePass(new PullIntoInitializers()); | 211 applyTreePass(new PullIntoInitializers()); |
| 209 | 212 |
| 210 return node; | 213 return node; |
| 211 } | 214 } |
| 212 | 215 |
| 213 js.Fun compileToJavaScript(CodegenWorkItem work, | 216 js.Fun compileToJavaScript(CodegenWorkItem work, |
| 214 tree_ir.FunctionDefinition definition) { | 217 tree_ir.FunctionDefinition definition) { |
| 215 CodeGenerator codeGen = new CodeGenerator(glue, work.registry); | 218 CodeGenerator codeGen = new CodeGenerator(glue, work.registry); |
| 216 return attachPosition(codeGen.buildFunction(definition), work.element); | 219 Element element = work.element; |
| 220 js.Fun code = codeGen.buildFunction(definition); |
| 221 if (element is FunctionElement && element.asyncMarker != AsyncMarker.SYNC) { |
| 222 code = backend.rewriteAsync(element, code); |
| 223 work.registry.registerAsyncMarker(element); |
| 224 } |
| 225 return attachPosition(code, element); |
| 217 } | 226 } |
| 218 | 227 |
| 219 Iterable<CompilerTask> get tasks { | 228 Iterable<CompilerTask> get tasks { |
| 220 // TODO(sigurdm): Make a better list of tasks. | 229 // TODO(sigurdm): Make a better list of tasks. |
| 221 return <CompilerTask>[irBuilderTask]..addAll(fallbackCompiler.tasks); | 230 return <CompilerTask>[irBuilderTask]..addAll(fallbackCompiler.tasks); |
| 222 } | 231 } |
| 223 | 232 |
| 224 js.Node attachPosition(js.Node node, AstElement element) { | 233 js.Node attachPosition(js.Node node, AstElement element) { |
| 225 return node.withSourceInformation( | 234 return node.withSourceInformation( |
| 226 sourceInformationFactory.createBuilderForContext(element) | 235 sourceInformationFactory.createBuilderForContext(element) |
| 227 .buildDeclaration(element)); | 236 .buildDeclaration(element)); |
| 228 } | 237 } |
| 229 } | 238 } |
| OLD | NEW |