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