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.js_model.strategy; | 5 library dart2js.js_model.strategy; |
6 | 6 |
7 import '../backend_strategy.dart'; | 7 import '../backend_strategy.dart'; |
| 8 import '../common/tasks.dart'; |
8 import '../common_elements.dart'; | 9 import '../common_elements.dart'; |
9 import '../compiler.dart'; | 10 import '../compiler.dart'; |
10 import '../elements/elements.dart' show TypedefElement; | 11 import '../elements/elements.dart' show TypedefElement; |
11 import '../elements/entities.dart'; | 12 import '../elements/entities.dart'; |
12 import '../enqueue.dart'; | 13 import '../enqueue.dart'; |
13 import '../io/source_information.dart'; | 14 import '../io/source_information.dart'; |
14 import '../js_emitter/sorter.dart'; | 15 import '../js_emitter/sorter.dart'; |
15 import '../js/js_source_mapping.dart'; | 16 import '../js/js_source_mapping.dart'; |
16 import '../js_backend/backend.dart'; | 17 import '../js_backend/backend.dart'; |
17 import '../js_backend/backend_usage.dart'; | 18 import '../js_backend/backend_usage.dart'; |
18 import '../js_backend/constant_system_javascript.dart'; | 19 import '../js_backend/constant_system_javascript.dart'; |
19 import '../js_backend/interceptor_data.dart'; | 20 import '../js_backend/interceptor_data.dart'; |
20 import '../js_backend/native_data.dart'; | 21 import '../js_backend/native_data.dart'; |
| 22 import '../kernel/element_map.dart'; |
| 23 import '../kernel/element_map_impl.dart'; |
21 import '../kernel/kernel_backend_strategy.dart'; | 24 import '../kernel/kernel_backend_strategy.dart'; |
| 25 import '../kernel/kernel_strategy.dart'; |
22 import '../ssa/ssa.dart'; | 26 import '../ssa/ssa.dart'; |
23 import '../universe/class_set.dart'; | 27 import '../universe/class_set.dart'; |
24 import '../universe/world_builder.dart'; | 28 import '../universe/world_builder.dart'; |
25 import '../util/emptyset.dart'; | 29 import '../util/emptyset.dart'; |
26 import '../world.dart'; | 30 import '../world.dart'; |
27 import 'elements.dart'; | 31 import 'elements.dart'; |
28 | 32 |
29 class JsBackendStrategy implements BackendStrategy { | 33 class JsBackendStrategy implements BackendStrategy { |
30 final Compiler _compiler; | 34 final Compiler _compiler; |
31 final JsToFrontendMap _map = new JsToFrontendMap(); | 35 final JsToFrontendMap _map = new JsToFrontendMapImpl(); |
| 36 ElementEnvironment _elementEnvironment; |
| 37 CommonElements _commonElements; |
32 | 38 |
33 JsBackendStrategy(this._compiler); | 39 JsBackendStrategy(this._compiler); |
34 | 40 |
35 @override | 41 @override |
36 ClosedWorldRefiner createClosedWorldRefiner(ClosedWorld closedWorld) { | 42 ClosedWorldRefiner createClosedWorldRefiner(ClosedWorld closedWorld) { |
37 CommonElements commonElements = | 43 _elementEnvironment = |
38 new JsCommonElements(_map, closedWorld.commonElements); | 44 new JsElementEnvironment(_map, closedWorld.elementEnvironment); |
| 45 _commonElements = new JsCommonElements(_map, closedWorld.commonElements); |
39 BackendUsage backendUsage = | 46 BackendUsage backendUsage = |
40 new JsBackendUsage(_map, closedWorld.backendUsage); | 47 new JsBackendUsage(_map, closedWorld.backendUsage); |
41 NativeData nativeData = new JsNativeData(_map, closedWorld.nativeData); | 48 NativeData nativeData = new JsNativeData(_map, closedWorld.nativeData); |
42 InterceptorData interceptorData = new InterceptorDataImpl( | 49 InterceptorData interceptorData = new InterceptorDataImpl( |
43 nativeData, | 50 nativeData, |
44 commonElements, | 51 _commonElements, |
45 // TODO(johnniwinther): Convert these. | 52 // TODO(johnniwinther): Convert these. |
46 const {}, | 53 const {}, |
47 new Set(), | 54 new Set(), |
48 new Set()); | 55 new Set()); |
49 | 56 |
50 Map<ClassEntity, ClassHierarchyNode> classHierarchyNodes = | 57 Map<ClassEntity, ClassHierarchyNode> classHierarchyNodes = |
51 <ClassEntity, ClassHierarchyNode>{}; | 58 <ClassEntity, ClassHierarchyNode>{}; |
52 Map<ClassEntity, ClassSet> classSets = <ClassEntity, ClassSet>{}; | 59 Map<ClassEntity, ClassSet> classSets = <ClassEntity, ClassSet>{}; |
53 Set<ClassEntity> implementedClasses = new Set<ClassEntity>(); | 60 Set<ClassEntity> implementedClasses = new Set<ClassEntity>(); |
54 | 61 |
(...skipping 27 matching lines...) Expand all Loading... |
82 }); | 89 }); |
83 } | 90 } |
84 | 91 |
85 closedWorld | 92 closedWorld |
86 .getClassHierarchyNode(closedWorld.commonElements.objectClass) | 93 .getClassHierarchyNode(closedWorld.commonElements.objectClass) |
87 .forEachSubclass((ClassEntity cls) { | 94 .forEachSubclass((ClassEntity cls) { |
88 convertClassSet(closedWorld.getClassSet(cls)); | 95 convertClassSet(closedWorld.getClassSet(cls)); |
89 }, ClassHierarchyNode.ALL); | 96 }, ClassHierarchyNode.ALL); |
90 | 97 |
91 return new JsClosedWorld( | 98 return new JsClosedWorld( |
92 // TODO(johnniwinther): Create a JsElementEnvironment. | 99 elementEnvironment: _elementEnvironment, |
93 elementEnvironment: closedWorld.elementEnvironment, | 100 commonElements: _commonElements, |
94 commonElements: commonElements, | |
95 constantSystem: const JavaScriptConstantSystem(), | 101 constantSystem: const JavaScriptConstantSystem(), |
96 backendUsage: backendUsage, | 102 backendUsage: backendUsage, |
97 nativeData: nativeData, | 103 nativeData: nativeData, |
98 interceptorData: interceptorData, | 104 interceptorData: interceptorData, |
99 classHierarchyNodes: classHierarchyNodes, | 105 classHierarchyNodes: classHierarchyNodes, |
100 classSets: classSets, | 106 classSets: classSets, |
101 implementedClasses: implementedClasses, | 107 implementedClasses: implementedClasses, |
102 // TODO(johnniwinther): Support this. | 108 // TODO(johnniwinther): Support this. |
103 allTypedefs: new ImmutableEmptySet<TypedefElement>()); | 109 allTypedefs: new ImmutableEmptySet<TypedefElement>()); |
104 } | 110 } |
105 | 111 |
106 @override | 112 @override |
107 Sorter get sorter { | 113 Sorter get sorter { |
108 throw new UnimplementedError('JsBackendStrategy.sorter'); | 114 throw new UnimplementedError('JsBackendStrategy.sorter'); |
109 } | 115 } |
110 | 116 |
111 @override | 117 @override |
112 void convertClosures(ClosedWorldRefiner closedWorldRefiner) {} | 118 void convertClosures(ClosedWorldRefiner closedWorldRefiner) {} |
113 | 119 |
114 @override | 120 @override |
115 SourceInformationStrategy get sourceInformationStrategy => | 121 SourceInformationStrategy get sourceInformationStrategy => |
116 const JavaScriptSourceInformationStrategy(); | 122 const JavaScriptSourceInformationStrategy(); |
117 | 123 |
118 @override | 124 @override |
119 SsaBuilderTask createSsaBuilderTask(JavaScriptBackend backend, | 125 SsaBuilder createSsaBuilder(CompilerTask task, JavaScriptBackend backend, |
120 SourceInformationStrategy sourceInformationStrategy) { | 126 SourceInformationStrategy sourceInformationStrategy) { |
121 return new KernelSsaBuilderTask(backend.compiler); | 127 KernelFrontEndStrategy strategy = backend.compiler.frontendStrategy; |
| 128 KernelToElementMap elementMap = strategy.elementMap; |
| 129 JsKernelToElementMap jsElementMap = new JsKernelToElementMap( |
| 130 _map, _elementEnvironment, _commonElements, elementMap); |
| 131 return new KernelSsaBuilder(task, backend.compiler, jsElementMap); |
122 } | 132 } |
123 | 133 |
124 @override | 134 @override |
125 WorkItemBuilder createCodegenWorkItemBuilder(ClosedWorld closedWorld) { | 135 WorkItemBuilder createCodegenWorkItemBuilder(ClosedWorld closedWorld) { |
126 return new KernelCodegenWorkItemBuilder(_compiler.backend, closedWorld); | 136 return new KernelCodegenWorkItemBuilder(_compiler.backend, closedWorld); |
127 } | 137 } |
128 | 138 |
129 @override | 139 @override |
130 CodegenWorldBuilder createCodegenWorldBuilder( | 140 CodegenWorldBuilder createCodegenWorldBuilder( |
131 NativeBasicData nativeBasicData, | 141 NativeBasicData nativeBasicData, |
132 ClosedWorld closedWorld, | 142 ClosedWorld closedWorld, |
133 SelectorConstraintsStrategy selectorConstraintsStrategy) { | 143 SelectorConstraintsStrategy selectorConstraintsStrategy) { |
134 return new KernelCodegenWorldBuilder(closedWorld.elementEnvironment, | 144 return new KernelCodegenWorldBuilder(closedWorld.elementEnvironment, |
135 nativeBasicData, closedWorld, selectorConstraintsStrategy); | 145 nativeBasicData, closedWorld, selectorConstraintsStrategy); |
136 } | 146 } |
137 } | 147 } |
OLD | NEW |