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'; |
(...skipping 19 matching lines...) Expand all Loading... |
30 import '../ssa/types.dart'; | 30 import '../ssa/types.dart'; |
31 import '../types/types.dart'; | 31 import '../types/types.dart'; |
32 import '../universe/selector.dart'; | 32 import '../universe/selector.dart'; |
33 import '../universe/world_builder.dart'; | 33 import '../universe/world_builder.dart'; |
34 import '../universe/world_impact.dart'; | 34 import '../universe/world_impact.dart'; |
35 import '../world.dart'; | 35 import '../world.dart'; |
36 import 'closure.dart'; | 36 import 'closure.dart'; |
37 import 'element_map_impl.dart'; | 37 import 'element_map_impl.dart'; |
38 import 'kernel_strategy.dart'; | 38 import 'kernel_strategy.dart'; |
39 | 39 |
| 40 /// A backend strategy based on Kernel IR nodes. |
| 41 abstract class KernelBackendStrategy implements BackendStrategy { |
| 42 KernelToElementMap get elementMap; |
| 43 GlobalLocalsMap get globalLocalsMapForTesting; |
| 44 } |
| 45 |
40 /// Backend strategy that uses the kernel elements as the backend model. | 46 /// Backend strategy that uses the kernel elements as the backend model. |
41 // TODO(johnniwinther): Replace this with a strategy based on the J-element | 47 // TODO(johnniwinther): Replace this with a strategy based on the J-element |
42 // model. | 48 // model. |
43 class KernelBackendStrategy implements BackendStrategy { | 49 class KernelBackendStrategyImpl implements KernelBackendStrategy { |
44 final Compiler _compiler; | 50 final Compiler _compiler; |
45 Sorter _sorter; | 51 Sorter _sorter; |
46 ClosureConversionTask _closureDataLookup; | 52 ClosureConversionTask _closureDataLookup; |
47 GlobalLocalsMap _globalLocalsMap = new GlobalLocalsMap(); | 53 final GlobalLocalsMap _globalLocalsMap = new GlobalLocalsMap(); |
48 | 54 |
49 KernelBackendStrategy(this._compiler); | 55 KernelBackendStrategyImpl(this._compiler); |
50 | 56 |
51 KernelToElementMap get _elementMap { | 57 KernelToElementMap get elementMap { |
52 KernelFrontEndStrategy frontendStrategy = _compiler.frontendStrategy; | 58 KernelFrontEndStrategy frontendStrategy = _compiler.frontendStrategy; |
53 return frontendStrategy.elementMap; | 59 return frontendStrategy.elementMap; |
54 } | 60 } |
55 | 61 |
| 62 GlobalLocalsMap get globalLocalsMapForTesting => _globalLocalsMap; |
| 63 |
56 @override | 64 @override |
57 ClosedWorldRefiner createClosedWorldRefiner( | 65 ClosedWorldRefiner createClosedWorldRefiner( |
58 covariant KernelClosedWorld closedWorld) { | 66 covariant KernelClosedWorld closedWorld) { |
59 return closedWorld; | 67 return closedWorld; |
60 } | 68 } |
61 | 69 |
62 @override | 70 @override |
63 Sorter get sorter { | 71 Sorter get sorter { |
64 if (_sorter == null) { | 72 if (_sorter == null) { |
65 KernelFrontEndStrategy frontendStrategy = _compiler.frontendStrategy; | 73 _sorter = new KernelSorter(elementMap); |
66 _sorter = new KernelSorter(frontendStrategy.elementMap); | |
67 } | 74 } |
68 return _sorter; | 75 return _sorter; |
69 } | 76 } |
70 | 77 |
71 @override | 78 @override |
72 ClosureConversionTask get closureDataLookup => | 79 ClosureConversionTask get closureDataLookup => |
73 _closureDataLookup ??= new KernelClosureConversionTask( | 80 _closureDataLookup ??= new KernelClosureConversionTask( |
74 _compiler.measurer, _elementMap, _globalLocalsMap); | 81 _compiler.measurer, elementMap, _globalLocalsMap); |
75 | 82 |
76 @override | 83 @override |
77 WorkItemBuilder createCodegenWorkItemBuilder(ClosedWorld closedWorld) { | 84 WorkItemBuilder createCodegenWorkItemBuilder(ClosedWorld closedWorld) { |
78 return new KernelCodegenWorkItemBuilder(_compiler.backend, closedWorld); | 85 return new KernelCodegenWorkItemBuilder(_compiler.backend, closedWorld); |
79 } | 86 } |
80 | 87 |
81 @override | 88 @override |
82 CodegenWorldBuilder createCodegenWorldBuilder( | 89 CodegenWorldBuilder createCodegenWorldBuilder( |
83 NativeBasicData nativeBasicData, | 90 NativeBasicData nativeBasicData, |
84 ClosedWorld closedWorld, | 91 ClosedWorld closedWorld, |
85 SelectorConstraintsStrategy selectorConstraintsStrategy) { | 92 SelectorConstraintsStrategy selectorConstraintsStrategy) { |
86 return new KernelCodegenWorldBuilder( | 93 return new KernelCodegenWorldBuilder( |
87 _elementMap, | 94 elementMap, |
88 closedWorld.elementEnvironment, | 95 closedWorld.elementEnvironment, |
89 nativeBasicData, | 96 nativeBasicData, |
90 closedWorld, | 97 closedWorld, |
91 selectorConstraintsStrategy); | 98 selectorConstraintsStrategy); |
92 } | 99 } |
93 | 100 |
94 @override | 101 @override |
95 SsaBuilder createSsaBuilder(CompilerTask task, JavaScriptBackend backend, | 102 SsaBuilder createSsaBuilder(CompilerTask task, JavaScriptBackend backend, |
96 SourceInformationStrategy sourceInformationStrategy) { | 103 SourceInformationStrategy sourceInformationStrategy) { |
97 return new KernelSsaBuilder( | 104 return new KernelSsaBuilder( |
98 task, backend.compiler, _elementMap, _globalLocalsMap); | 105 task, backend.compiler, elementMap, _globalLocalsMap); |
99 } | 106 } |
100 | 107 |
101 @override | 108 @override |
102 SourceInformationStrategy get sourceInformationStrategy => | 109 SourceInformationStrategy get sourceInformationStrategy => |
103 const JavaScriptSourceInformationStrategy(); | 110 const JavaScriptSourceInformationStrategy(); |
104 } | 111 } |
105 | 112 |
106 class KernelCodegenWorkItemBuilder implements WorkItemBuilder { | 113 class KernelCodegenWorkItemBuilder implements WorkItemBuilder { |
107 final JavaScriptBackend _backend; | 114 final JavaScriptBackend _backend; |
108 final ClosedWorld _closedWorld; | 115 final ClosedWorld _closedWorld; |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 Iterable<ClassEntity> sortClasses(Iterable<ClassEntity> classes) { | 381 Iterable<ClassEntity> sortClasses(Iterable<ClassEntity> classes) { |
375 return classes.toList() | 382 return classes.toList() |
376 ..sort((ClassEntity a, ClassEntity b) { | 383 ..sort((ClassEntity a, ClassEntity b) { |
377 int r = _compareLibraries(a.library, b.library); | 384 int r = _compareLibraries(a.library, b.library); |
378 if (r != 0) return r; | 385 if (r != 0) return r; |
379 return _compareNodes( | 386 return _compareNodes( |
380 a, elementMap.getClassNode(a), b, elementMap.getClassNode(b)); | 387 a, elementMap.getClassNode(a), b, elementMap.getClassNode(b)); |
381 }); | 388 }); |
382 } | 389 } |
383 } | 390 } |
OLD | NEW |