OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 library ssa; | 5 library ssa; |
6 | 6 |
7 export 'builder.dart' show SsaFunctionCompiler; | 7 import '../common/codegen.dart' show CodegenWorkItem; |
| 8 import '../common/tasks.dart' show CompilerTask; |
| 9 import '../elements/elements.dart' show Element, FunctionElement; |
| 10 import '../io/source_information.dart'; |
| 11 import '../js/js.dart' as js; |
| 12 import '../js_backend/backend.dart' show JavaScriptBackend, FunctionCompiler; |
| 13 |
| 14 import 'builder.dart'; |
| 15 import 'builder_kernel.dart'; |
| 16 import 'codegen.dart'; |
| 17 import 'nodes.dart'; |
| 18 import 'optimize.dart'; |
| 19 import 'types.dart'; |
| 20 |
| 21 class SsaFunctionCompiler implements FunctionCompiler { |
| 22 final SsaCodeGeneratorTask generator; |
| 23 final SsaBuilderTask builder; |
| 24 final SsaKernelBuilderTask builderKernel; |
| 25 final SsaOptimizerTask optimizer; |
| 26 final JavaScriptBackend backend; |
| 27 final bool useKernel; |
| 28 |
| 29 SsaFunctionCompiler(JavaScriptBackend backend, |
| 30 SourceInformationStrategy sourceInformationFactory, this.useKernel) |
| 31 : generator = new SsaCodeGeneratorTask(backend, sourceInformationFactory), |
| 32 builder = new SsaBuilderTask(backend, sourceInformationFactory), |
| 33 builderKernel = |
| 34 new SsaKernelBuilderTask(backend, sourceInformationFactory), |
| 35 optimizer = new SsaOptimizerTask(backend), |
| 36 backend = backend; |
| 37 |
| 38 /// Generates JavaScript code for `work.element`. |
| 39 /// Using the ssa builder, optimizer and codegenerator. |
| 40 js.Fun compile(CodegenWorkItem work) { |
| 41 HGraph graph = useKernel ? builderKernel.build(work) : builder.build(work); |
| 42 optimizer.optimize(work, graph); |
| 43 Element element = work.element; |
| 44 js.Expression result = generator.generateCode(work, graph); |
| 45 if (element is FunctionElement) { |
| 46 // TODO(sigmund): replace by kernel transformer when `useKernel` is true. |
| 47 result = backend.rewriteAsync(element, result); |
| 48 } |
| 49 return result; |
| 50 } |
| 51 |
| 52 Iterable<CompilerTask> get tasks { |
| 53 return <CompilerTask>[ |
| 54 useKernel ? builderKernel : builder, |
| 55 optimizer, |
| 56 generator |
| 57 ]; |
| 58 } |
| 59 } |
OLD | NEW |