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'; |
11 | 11 |
12 import '../js_backend.dart'; | 12 import '../js_backend.dart'; |
13 import '../../common/codegen.dart' show | 13 import '../../common/codegen.dart' show |
14 CodegenWorkItem; | 14 CodegenWorkItem; |
15 import '../../common/tasks.dart' show | 15 import '../../common/tasks.dart' show |
16 CompilerTask; | 16 CompilerTask; |
17 import '../../compiler.dart' show | 17 import '../../compiler.dart' show |
18 Compiler; | 18 Compiler; |
19 import '../../constants/constant_system.dart'; | 19 import '../../constants/constant_system.dart'; |
20 import '../../cps_ir/cps_ir_nodes.dart' as cps; | 20 import '../../cps_ir/cps_ir_nodes.dart' as cps; |
21 import '../../cps_ir/cps_ir_integrity.dart'; | 21 import '../../cps_ir/cps_ir_integrity.dart'; |
22 import '../../cps_ir/cps_ir_builder_task.dart'; | 22 import '../../cps_ir/cps_ir_builder_task.dart'; |
| 23 import '../../diagnostics/diagnostic_listener.dart' show |
| 24 DiagnosticReporter; |
23 import '../../diagnostics/invariant.dart' show | 25 import '../../diagnostics/invariant.dart' show |
24 DEBUG_MODE; | 26 DEBUG_MODE; |
25 import '../../tree_ir/tree_ir_nodes.dart' as tree_ir; | 27 import '../../tree_ir/tree_ir_nodes.dart' as tree_ir; |
26 import '../../types/types.dart' show TypeMask, UnionTypeMask, FlatTypeMask, | 28 import '../../types/types.dart' show TypeMask, UnionTypeMask, FlatTypeMask, |
27 ForwardingTypeMask; | 29 ForwardingTypeMask; |
28 import '../../elements/elements.dart'; | 30 import '../../elements/elements.dart'; |
29 import '../../js/js.dart' as js; | 31 import '../../js/js.dart' as js; |
30 import '../../io/source_information.dart' show SourceInformationStrategy; | 32 import '../../io/source_information.dart' show SourceInformationStrategy; |
31 import '../../tree_ir/tree_ir_builder.dart' as tree_builder; | 33 import '../../tree_ir/tree_ir_builder.dart' as tree_builder; |
32 import '../../cps_ir/optimizers.dart'; | 34 import '../../cps_ir/optimizers.dart'; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 compiler = compiler, | 71 compiler = compiler, |
70 glue = new Glue(compiler), | 72 glue = new Glue(compiler), |
71 cpsOptimizationTask = new GenericTask('CPS optimization', compiler), | 73 cpsOptimizationTask = new GenericTask('CPS optimization', compiler), |
72 treeBuilderTask = new GenericTask('Tree builder', compiler), | 74 treeBuilderTask = new GenericTask('Tree builder', compiler), |
73 treeOptimizationTask = new GenericTask('Tree optimization', compiler); | 75 treeOptimizationTask = new GenericTask('Tree optimization', compiler); |
74 | 76 |
75 String get name => 'CPS Ir pipeline'; | 77 String get name => 'CPS Ir pipeline'; |
76 | 78 |
77 JavaScriptBackend get backend => compiler.backend; | 79 JavaScriptBackend get backend => compiler.backend; |
78 | 80 |
| 81 DiagnosticReporter get reporter => compiler.reporter; |
| 82 |
79 /// Generates JavaScript code for `work.element`. | 83 /// Generates JavaScript code for `work.element`. |
80 js.Fun compile(CodegenWorkItem work) { | 84 js.Fun compile(CodegenWorkItem work) { |
81 AstElement element = work.element; | 85 AstElement element = work.element; |
82 return compiler.withCurrentElement(element, () { | 86 return reporter.withCurrentElement(element, () { |
83 typeSystem = new TypeMaskSystem(compiler); | 87 typeSystem = new TypeMaskSystem(compiler); |
84 try { | 88 try { |
85 // TODO(karlklose): remove this fallback when we do not need it for | 89 // TODO(karlklose): remove this fallback when we do not need it for |
86 // testing anymore. | 90 // testing anymore. |
87 if (false) { | 91 if (false) { |
88 compiler.log('Using SSA compiler for platform element $element'); | 92 reporter.log('Using SSA compiler for platform element $element'); |
89 return fallbackCompiler.compile(work); | 93 return fallbackCompiler.compile(work); |
90 } | 94 } |
91 | 95 |
92 if (tracer != null) { | 96 if (tracer != null) { |
93 tracer.traceCompilation(element.name, null); | 97 tracer.traceCompilation(element.name, null); |
94 } | 98 } |
95 cps.FunctionDefinition cpsFunction = compileToCpsIr(element); | 99 cps.FunctionDefinition cpsFunction = compileToCpsIr(element); |
96 cpsFunction = optimizeCpsIr(cpsFunction); | 100 cpsFunction = optimizeCpsIr(cpsFunction); |
97 tree_ir.FunctionDefinition treeFunction = compileToTreeIr(cpsFunction); | 101 tree_ir.FunctionDefinition treeFunction = compileToTreeIr(cpsFunction); |
98 treeFunction = optimizeTreeIr(treeFunction); | 102 treeFunction = optimizeTreeIr(treeFunction); |
99 return compileToJavaScript(work, treeFunction); | 103 return compileToJavaScript(work, treeFunction); |
100 } on CodegenBailout catch (e) { | 104 } on CodegenBailout catch (e) { |
101 String message = "Unable to compile $element with the new compiler.\n" | 105 String message = "Unable to compile $element with the new compiler.\n" |
102 " Reason: ${e.message}"; | 106 " Reason: ${e.message}"; |
103 compiler.internalError(element, message); | 107 reporter.internalError(element, message); |
104 } | 108 } |
105 }); | 109 }); |
106 } | 110 } |
107 | 111 |
108 void giveUp(String reason) { | 112 void giveUp(String reason) { |
109 throw new CodegenBailout(null, reason); | 113 throw new CodegenBailout(null, reason); |
110 } | 114 } |
111 | 115 |
112 void traceGraph(String title, var irObject) { | 116 void traceGraph(String title, var irObject) { |
113 if (tracer != null) { | 117 if (tracer != null) { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 applyCpsPass(new RedundantPhiEliminator(), cpsFunction); | 200 applyCpsPass(new RedundantPhiEliminator(), cpsFunction); |
197 applyCpsPass(new ShrinkingReducer(), cpsFunction); | 201 applyCpsPass(new ShrinkingReducer(), cpsFunction); |
198 applyCpsPass(new ShareInterceptors(), cpsFunction); | 202 applyCpsPass(new ShareInterceptors(), cpsFunction); |
199 applyCpsPass(new ShrinkingReducer(), cpsFunction); | 203 applyCpsPass(new ShrinkingReducer(), cpsFunction); |
200 | 204 |
201 return cpsFunction; | 205 return cpsFunction; |
202 } | 206 } |
203 | 207 |
204 tree_ir.FunctionDefinition compileToTreeIr(cps.FunctionDefinition cpsNode) { | 208 tree_ir.FunctionDefinition compileToTreeIr(cps.FunctionDefinition cpsNode) { |
205 tree_builder.Builder builder = new tree_builder.Builder( | 209 tree_builder.Builder builder = new tree_builder.Builder( |
206 compiler.internalError); | 210 reporter.internalError); |
207 tree_ir.FunctionDefinition treeNode = | 211 tree_ir.FunctionDefinition treeNode = |
208 treeBuilderTask.measure(() => builder.buildFunction(cpsNode)); | 212 treeBuilderTask.measure(() => builder.buildFunction(cpsNode)); |
209 assert(treeNode != null); | 213 assert(treeNode != null); |
210 traceGraph('Tree builder', treeNode); | 214 traceGraph('Tree builder', treeNode); |
211 assert(checkTreeIntegrity(treeNode)); | 215 assert(checkTreeIntegrity(treeNode)); |
212 return treeNode; | 216 return treeNode; |
213 } | 217 } |
214 | 218 |
215 static bool checkTreeIntegrity(tree_ir.FunctionDefinition node) { | 219 static bool checkTreeIntegrity(tree_ir.FunctionDefinition node) { |
216 new CheckTreeIntegrity().check(node); | 220 new CheckTreeIntegrity().check(node); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 treeOptimizationTask] | 259 treeOptimizationTask] |
256 ..addAll(fallbackCompiler.tasks); | 260 ..addAll(fallbackCompiler.tasks); |
257 } | 261 } |
258 | 262 |
259 js.Node attachPosition(js.Node node, AstElement element) { | 263 js.Node attachPosition(js.Node node, AstElement element) { |
260 return node.withSourceInformation( | 264 return node.withSourceInformation( |
261 sourceInformationFactory.createBuilderForContext(element) | 265 sourceInformationFactory.createBuilderForContext(element) |
262 .buildDeclaration(element)); | 266 .buildDeclaration(element)); |
263 } | 267 } |
264 } | 268 } |
OLD | NEW |