| 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 '../enqueue.dart'; | 16 import '../enqueue.dart'; |
| 16 import '../io/source_information.dart'; | 17 import '../io/source_information.dart'; |
| 17 import '../js/js_source_mapping.dart'; | 18 import '../js/js_source_mapping.dart'; |
| 18 import '../js_backend/backend.dart'; | 19 import '../js_backend/backend.dart'; |
| 19 import '../js_backend/native_data.dart'; | 20 import '../js_backend/native_data.dart'; |
| 20 import '../js_emitter/sorter.dart'; | 21 import '../js_emitter/sorter.dart'; |
| 21 import '../kernel/element_map.dart'; | 22 import '../kernel/element_map.dart'; |
| 22 import '../kernel/element_map_impl.dart'; | 23 import '../kernel/element_map_impl.dart'; |
| 23 import '../native/behavior.dart'; | 24 import '../native/behavior.dart'; |
| 24 import '../ssa/builder_kernel.dart'; | 25 import '../ssa/builder_kernel.dart'; |
| 25 import '../ssa/nodes.dart'; | 26 import '../ssa/nodes.dart'; |
| 26 import '../ssa/ssa.dart'; | 27 import '../ssa/ssa.dart'; |
| 27 import '../ssa/types.dart'; | 28 import '../ssa/types.dart'; |
| 28 import '../types/types.dart'; | 29 import '../types/types.dart'; |
| 29 import '../universe/selector.dart'; | 30 import '../universe/selector.dart'; |
| 30 import '../universe/world_builder.dart'; | 31 import '../universe/world_builder.dart'; |
| 31 import '../universe/world_impact.dart'; | 32 import '../universe/world_impact.dart'; |
| 32 import '../world.dart'; | 33 import '../world.dart'; |
| 34 import 'element_map_impl.dart'; |
| 33 import 'kernel_strategy.dart'; | 35 import 'kernel_strategy.dart'; |
| 34 | 36 |
| 35 /// Backend strategy that uses the kernel elements as the backend model. | 37 /// Backend strategy that uses the kernel elements as the backend model. |
| 36 // TODO(johnniwinther): Replace this with a strategy based on the J-element | 38 // TODO(johnniwinther): Replace this with a strategy based on the J-element |
| 37 // model. | 39 // model. |
| 38 class KernelBackendStrategy implements BackendStrategy { | 40 class KernelBackendStrategy implements BackendStrategy { |
| 39 final Compiler _compiler; | 41 final Compiler _compiler; |
| 42 Sorter _sorter; |
| 40 | 43 |
| 41 KernelBackendStrategy(this._compiler); | 44 KernelBackendStrategy(this._compiler); |
| 42 | 45 |
| 43 @override | 46 @override |
| 44 ClosedWorldRefiner createClosedWorldRefiner(KernelClosedWorld closedWorld) { | 47 ClosedWorldRefiner createClosedWorldRefiner(KernelClosedWorld closedWorld) { |
| 45 return closedWorld; | 48 return closedWorld; |
| 46 } | 49 } |
| 47 | 50 |
| 48 @override | 51 @override |
| 49 Sorter get sorter => | 52 Sorter get sorter { |
| 50 throw new UnimplementedError('KernelBackendStrategy.sorter'); | 53 if (_sorter == null) { |
| 54 KernelFrontEndStrategy frontEndStrategy = _compiler.frontEndStrategy; |
| 55 _sorter = new KernelSorter(frontEndStrategy.elementMap); |
| 56 } |
| 57 return _sorter; |
| 58 } |
| 51 | 59 |
| 52 @override | 60 @override |
| 53 void convertClosures(ClosedWorldRefiner closedWorldRefiner) { | 61 void convertClosures(ClosedWorldRefiner closedWorldRefiner) { |
| 54 // TODO(johnniwinther,efortuna): Compute closure classes for kernel based | 62 // TODO(johnniwinther,efortuna): Compute closure classes for kernel based |
| 55 // elements. | 63 // elements. |
| 56 } | 64 } |
| 57 | 65 |
| 58 @override | 66 @override |
| 59 WorkItemBuilder createCodegenWorkItemBuilder(ClosedWorld closedWorld) { | 67 WorkItemBuilder createCodegenWorkItemBuilder(ClosedWorld closedWorld) { |
| 60 return new KernelCodegenWorkItemBuilder(_compiler.backend, closedWorld); | 68 return new KernelCodegenWorkItemBuilder(_compiler.backend, closedWorld); |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 @override | 228 @override |
| 221 ClosureClassMap getLocalFunctionMap(Local localFunction) { | 229 ClosureClassMap getLocalFunctionMap(Local localFunction) { |
| 222 return new ClosureClassMap(null, null, null, null); | 230 return new ClosureClassMap(null, null, null, null); |
| 223 } | 231 } |
| 224 | 232 |
| 225 @override | 233 @override |
| 226 ClosureClassMap getMemberMap(MemberEntity member) { | 234 ClosureClassMap getMemberMap(MemberEntity member) { |
| 227 return new ClosureClassMap(null, null, null, null); | 235 return new ClosureClassMap(null, null, null, null); |
| 228 } | 236 } |
| 229 } | 237 } |
| 238 |
| 239 class KernelSorter implements Sorter { |
| 240 final KernelToElementMapImpl elementMap; |
| 241 |
| 242 KernelSorter(this.elementMap); |
| 243 |
| 244 int _compareLibraries(LibraryEntity a, LibraryEntity b) { |
| 245 return utils.compareLibrariesUris(a.canonicalUri, b.canonicalUri); |
| 246 } |
| 247 |
| 248 int _compareNodes( |
| 249 Entity entity1, ir.TreeNode node1, Entity entity2, ir.TreeNode node2) { |
| 250 ir.Location location1 = node1.location; |
| 251 ir.Location location2 = node2.location; |
| 252 int r = utils.compareSourceUris( |
| 253 Uri.parse(location1.file), Uri.parse(location2.file)); |
| 254 if (r != 0) return r; |
| 255 return utils.compareEntities(entity1, location1.line, location1.column, |
| 256 entity2, location2.line, location2.column); |
| 257 } |
| 258 |
| 259 @override |
| 260 Iterable<LibraryEntity> sortLibraries(Iterable<LibraryEntity> libraries) { |
| 261 return libraries.toList()..sort(_compareLibraries); |
| 262 } |
| 263 |
| 264 @override |
| 265 Iterable<MemberEntity> sortMembers(Iterable<MemberEntity> members) { |
| 266 return members.toList() |
| 267 ..sort((MemberEntity a, MemberEntity b) { |
| 268 int r = _compareLibraries(a.library, b.library); |
| 269 if (r != 0) return r; |
| 270 return _compareNodes( |
| 271 a, elementMap.getMemberNode(a), b, elementMap.getMemberNode(b)); |
| 272 }); |
| 273 } |
| 274 |
| 275 @override |
| 276 Iterable<ClassEntity> sortClasses(Iterable<ClassEntity> classes) { |
| 277 return classes.toList() |
| 278 ..sort((ClassEntity a, ClassEntity b) { |
| 279 int r = _compareLibraries(a.library, b.library); |
| 280 if (r != 0) return r; |
| 281 return _compareNodes( |
| 282 a, elementMap.getClassNode(a), b, elementMap.getClassNode(b)); |
| 283 }); |
| 284 } |
| 285 } |
| OLD | NEW |