OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 dart2js.kernel.backend_strategy; | 5 library dart2js.kernel.backend_strategy; |
6 | 6 |
7 import 'package:kernel/ast.dart' as ir; | 7 import 'package:kernel/ast.dart' as ir; |
8 | 8 |
9 import '../backend_strategy.dart'; | 9 import '../backend_strategy.dart'; |
10 import '../closure.dart'; | 10 import '../closure.dart'; |
11 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; | 11 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; |
12 import '../common/tasks.dart'; | 12 import '../common/tasks.dart'; |
13 import '../compiler.dart'; | 13 import '../compiler.dart'; |
14 import '../elements/entities.dart'; | 14 import '../elements/entities.dart'; |
15 import '../elements/entity_utils.dart' as utils; | 15 import '../elements/entity_utils.dart' as utils; |
16 import '../enqueue.dart'; | 16 import '../enqueue.dart'; |
17 import '../io/source_information.dart'; | 17 import '../io/source_information.dart'; |
18 import '../js/js_source_mapping.dart'; | 18 import '../js/js_source_mapping.dart'; |
19 import '../js_backend/backend.dart'; | 19 import '../js_backend/backend.dart'; |
20 import '../js_backend/native_data.dart'; | 20 import '../js_backend/native_data.dart'; |
21 import '../js_emitter/sorter.dart'; | 21 import '../js_emitter/sorter.dart'; |
22 import '../js_model/closure.dart'; | 22 import '../js_model/closure.dart'; |
| 23 import '../js_model/js_strategy.dart'; |
23 import '../js_model/locals.dart'; | 24 import '../js_model/locals.dart'; |
24 import '../kernel/element_map.dart'; | 25 import '../kernel/element_map.dart'; |
25 import '../kernel/element_map_impl.dart'; | 26 import '../kernel/element_map_impl.dart'; |
26 import '../native/behavior.dart'; | 27 import '../native/behavior.dart'; |
27 import '../options.dart'; | 28 import '../options.dart'; |
28 import '../ssa/builder_kernel.dart'; | 29 import '../ssa/builder_kernel.dart'; |
29 import '../ssa/nodes.dart'; | 30 import '../ssa/nodes.dart'; |
30 import '../ssa/ssa.dart'; | 31 import '../ssa/ssa.dart'; |
31 import '../ssa/types.dart'; | 32 import '../ssa/types.dart'; |
32 import '../types/types.dart'; | 33 import '../types/types.dart'; |
33 import '../universe/selector.dart'; | 34 import '../universe/selector.dart'; |
34 import '../universe/world_builder.dart'; | 35 import '../universe/world_builder.dart'; |
35 import '../universe/world_impact.dart'; | 36 import '../universe/world_impact.dart'; |
36 import '../world.dart'; | 37 import '../world.dart'; |
37 import 'element_map_impl.dart'; | 38 import 'element_map_impl.dart'; |
38 import 'kernel_strategy.dart'; | 39 import 'kernel_strategy.dart'; |
39 | 40 |
| 41 /// If `true` the [JsStrategy] is used as the backend strategy. |
| 42 bool useJsStrategyForTesting = false; |
| 43 |
40 /// A backend strategy based on Kernel IR nodes. | 44 /// A backend strategy based on Kernel IR nodes. |
41 abstract class KernelBackendStrategy implements BackendStrategy { | 45 abstract class KernelBackendStrategy implements BackendStrategy { |
42 KernelToElementMapForBuilding get elementMap; | 46 KernelToElementMapForBuilding get elementMap; |
43 GlobalLocalsMap get globalLocalsMapForTesting; | 47 GlobalLocalsMap get globalLocalsMapForTesting; |
| 48 |
| 49 factory KernelBackendStrategy(Compiler compiler) { |
| 50 return useJsStrategyForTesting |
| 51 ? new JsBackendStrategy(compiler) |
| 52 : new KernelBackendStrategyImpl(compiler); |
| 53 } |
44 } | 54 } |
45 | 55 |
46 /// Backend strategy that uses the kernel elements as the backend model. | 56 /// Backend strategy that uses the kernel elements as the backend model. |
47 // TODO(redemption): Replace this with a strategy based on the J-element | 57 // TODO(redemption): Replace this with a strategy based on the J-element |
48 // model. | 58 // model. |
49 class KernelBackendStrategyImpl implements KernelBackendStrategy { | 59 class KernelBackendStrategyImpl implements KernelBackendStrategy { |
50 final Compiler _compiler; | 60 final Compiler _compiler; |
51 Sorter _sorter; | 61 Sorter _sorter; |
52 ClosureConversionTask _closureDataLookup; | 62 ClosureConversionTask _closureDataLookup; |
53 final GlobalLocalsMap _globalLocalsMap = new GlobalLocalsMap(); | 63 final GlobalLocalsMap _globalLocalsMap = new GlobalLocalsMap(); |
54 | 64 |
55 KernelBackendStrategyImpl(this._compiler); | 65 KernelBackendStrategyImpl(this._compiler); |
56 | 66 |
57 KernelToElementMapForBuilding get elementMap { | 67 KernelToElementMapForBuilding get elementMap { |
58 KernelFrontEndStrategy frontendStrategy = _compiler.frontendStrategy; | 68 KernelFrontEndStrategy frontendStrategy = _compiler.frontendStrategy; |
59 return frontendStrategy.elementMap; | 69 KernelToElementMapImpl elementMap = frontendStrategy.elementMap; |
| 70 return elementMap; |
60 } | 71 } |
61 | 72 |
62 GlobalLocalsMap get globalLocalsMapForTesting => _globalLocalsMap; | 73 GlobalLocalsMap get globalLocalsMapForTesting => _globalLocalsMap; |
63 | 74 |
64 @override | 75 @override |
65 ClosedWorldRefiner createClosedWorldRefiner( | 76 ClosedWorldRefiner createClosedWorldRefiner( |
66 covariant KernelClosedWorld closedWorld) { | 77 covariant KernelClosedWorld closedWorld) { |
67 return closedWorld; | 78 return closedWorld; |
68 } | 79 } |
69 | 80 |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 return _closedWorld.commonMasks.dynamicType; | 271 return _closedWorld.commonMasks.dynamicType; |
261 } | 272 } |
262 | 273 |
263 @override | 274 @override |
264 TypeMask getReturnTypeOf(FunctionEntity function) { | 275 TypeMask getReturnTypeOf(FunctionEntity function) { |
265 return _closedWorld.commonMasks.dynamicType; | 276 return _closedWorld.commonMasks.dynamicType; |
266 } | 277 } |
267 } | 278 } |
268 | 279 |
269 class KernelSorter implements Sorter { | 280 class KernelSorter implements Sorter { |
270 final KernelToElementMapImpl elementMap; | 281 final KernelToElementMapForBuilding elementMap; |
271 | 282 |
272 KernelSorter(this.elementMap); | 283 KernelSorter(this.elementMap); |
273 | 284 |
274 int _compareLibraries(LibraryEntity a, LibraryEntity b) { | 285 int _compareLibraries(LibraryEntity a, LibraryEntity b) { |
275 return utils.compareLibrariesUris(a.canonicalUri, b.canonicalUri); | 286 return utils.compareLibrariesUris(a.canonicalUri, b.canonicalUri); |
276 } | 287 } |
277 | 288 |
278 int _compareNodes( | 289 int _compareNodes( |
279 Entity entity1, ir.TreeNode node1, Entity entity2, ir.TreeNode node2) { | 290 Entity entity1, ir.TreeNode node1, Entity entity2, ir.TreeNode node2) { |
280 ir.Location location1 = node1.location; | 291 ir.Location location1 = node1.location; |
(...skipping 25 matching lines...) Expand all Loading... |
306 Iterable<ClassEntity> sortClasses(Iterable<ClassEntity> classes) { | 317 Iterable<ClassEntity> sortClasses(Iterable<ClassEntity> classes) { |
307 return classes.toList() | 318 return classes.toList() |
308 ..sort((ClassEntity a, ClassEntity b) { | 319 ..sort((ClassEntity a, ClassEntity b) { |
309 int r = _compareLibraries(a.library, b.library); | 320 int r = _compareLibraries(a.library, b.library); |
310 if (r != 0) return r; | 321 if (r != 0) return r; |
311 return _compareNodes( | 322 return _compareNodes( |
312 a, elementMap.getClassNode(a), b, elementMap.getClassNode(b)); | 323 a, elementMap.getClassNode(a), b, elementMap.getClassNode(b)); |
313 }); | 324 }); |
314 } | 325 } |
315 } | 326 } |
OLD | NEW |