| 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 15 matching lines...) Expand all Loading... |
| 26 import '../options.dart'; | 26 import '../options.dart'; |
| 27 import '../ssa/builder_kernel.dart'; | 27 import '../ssa/builder_kernel.dart'; |
| 28 import '../ssa/nodes.dart'; | 28 import '../ssa/nodes.dart'; |
| 29 import '../ssa/ssa.dart'; | 29 import '../ssa/ssa.dart'; |
| 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 'element_map_impl.dart'; | 37 import 'element_map_impl.dart'; |
| 37 import 'kernel_strategy.dart'; | 38 import 'kernel_strategy.dart'; |
| 38 | 39 |
| 39 /// Backend strategy that uses the kernel elements as the backend model. | 40 /// Backend strategy that uses the kernel elements as the backend model. |
| 40 // TODO(johnniwinther): Replace this with a strategy based on the J-element | 41 // TODO(johnniwinther): Replace this with a strategy based on the J-element |
| 41 // model. | 42 // model. |
| 42 class KernelBackendStrategy implements BackendStrategy { | 43 class KernelBackendStrategy implements BackendStrategy { |
| 43 final Compiler _compiler; | 44 final Compiler _compiler; |
| 44 Sorter _sorter; | 45 Sorter _sorter; |
| 45 | 46 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 | 140 |
| 140 KernelSsaBuilderTask(this._compiler) : super(_compiler.measurer); | 141 KernelSsaBuilderTask(this._compiler) : super(_compiler.measurer); |
| 141 | 142 |
| 142 KernelToElementMapImpl get _elementMap { | 143 KernelToElementMapImpl get _elementMap { |
| 143 KernelFrontEndStrategy frontendStrategy = _compiler.frontendStrategy; | 144 KernelFrontEndStrategy frontendStrategy = _compiler.frontendStrategy; |
| 144 return frontendStrategy.elementMap; | 145 return frontendStrategy.elementMap; |
| 145 } | 146 } |
| 146 | 147 |
| 147 @override | 148 @override |
| 148 HGraph build(CodegenWorkItem work, ClosedWorld closedWorld) { | 149 HGraph build(CodegenWorkItem work, ClosedWorld closedWorld) { |
| 150 KernelToLocalsMap localsMap = new KernelToLocalsMapImpl(work.element); |
| 149 KernelSsaBuilder builder = new KernelSsaBuilder( | 151 KernelSsaBuilder builder = new KernelSsaBuilder( |
| 150 work.element, | 152 work.element, |
| 151 work.element.enclosingClass, | 153 work.element.enclosingClass, |
| 152 _elementMap.getMemberNode(work.element), | 154 _elementMap.getMemberNode(work.element), |
| 153 _compiler, | 155 _compiler, |
| 154 _elementMap, | 156 _elementMap, |
| 155 new KernelToTypeInferenceMapImpl(closedWorld), | 157 new KernelToTypeInferenceMapImpl(closedWorld), |
| 156 new KernelToLocalsMapImpl(work.element), | 158 localsMap, |
| 157 closedWorld, | 159 closedWorld, |
| 158 _compiler.codegenWorldBuilder, | 160 _compiler.codegenWorldBuilder, |
| 159 work.registry, | 161 work.registry, |
| 162 new KernelClosureDataLookup(_elementMap, localsMap), |
| 160 // TODO(johnniwinther): Support these: | 163 // TODO(johnniwinther): Support these: |
| 161 const KernelClosureDataLookup(), | |
| 162 const SourceInformationBuilder(), | 164 const SourceInformationBuilder(), |
| 163 null, // Function node used as capture scope id. | 165 null, // Function node used as capture scope id. |
| 164 targetIsConstructorBody: false); | 166 targetIsConstructorBody: false); |
| 165 return builder.build(); | 167 return builder.build(); |
| 166 } | 168 } |
| 167 } | 169 } |
| 168 | 170 |
| 169 class KernelToTypeInferenceMapImpl implements KernelToTypeInferenceMap { | 171 class KernelToTypeInferenceMapImpl implements KernelToTypeInferenceMap { |
| 170 final ClosedWorld _closedWorld; | 172 final ClosedWorld _closedWorld; |
| 171 | 173 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 @override | 283 @override |
| 282 Local getLocal(ir.VariableDeclaration node) { | 284 Local getLocal(ir.VariableDeclaration node) { |
| 283 return _map.putIfAbsent(node, () { | 285 return _map.putIfAbsent(node, () { |
| 284 return new KLocal(node.name, currentMember); | 286 return new KLocal(node.name, currentMember); |
| 285 }); | 287 }); |
| 286 } | 288 } |
| 287 | 289 |
| 288 @override | 290 @override |
| 289 LoopClosureRepresentationInfo getClosureRepresentationInfoForLoop( | 291 LoopClosureRepresentationInfo getClosureRepresentationInfoForLoop( |
| 290 ClosureDataLookup closureLookup, ir.TreeNode node) { | 292 ClosureDataLookup closureLookup, ir.TreeNode node) { |
| 291 return const LoopClosureRepresentationInfo(); | 293 return closureLookup.getClosureRepresentationInfoForLoop(node); |
| 292 } | 294 } |
| 293 } | 295 } |
| 294 | 296 |
| 295 class KLocal implements Local { | 297 class KLocal implements Local { |
| 296 final String name; | 298 final String name; |
| 297 final MemberEntity memberContext; | 299 final MemberEntity memberContext; |
| 298 | 300 |
| 299 KLocal(this.name, this.memberContext); | 301 KLocal(this.name, this.memberContext); |
| 300 | 302 |
| 301 @override | 303 @override |
| 302 Entity get executableContext => memberContext; | 304 Entity get executableContext => memberContext; |
| 303 | 305 |
| 304 String toString() { | 306 String toString() { |
| 305 StringBuffer sb = new StringBuffer(); | 307 StringBuffer sb = new StringBuffer(); |
| 306 sb.write('local('); | 308 sb.write('local('); |
| 307 if (memberContext.enclosingClass != null) { | 309 if (memberContext.enclosingClass != null) { |
| 308 sb.write(memberContext.enclosingClass.name); | 310 sb.write(memberContext.enclosingClass.name); |
| 309 sb.write('.'); | 311 sb.write('.'); |
| 310 } | 312 } |
| 311 sb.write(memberContext.name); | 313 sb.write(memberContext.name); |
| 312 sb.write('#'); | 314 sb.write('#'); |
| 313 sb.write(name); | 315 sb.write(name); |
| 314 sb.write(')'); | 316 sb.write(')'); |
| 315 return sb.toString(); | 317 return sb.toString(); |
| 316 } | 318 } |
| 317 } | 319 } |
| 318 | 320 |
| 319 /// TODO(johnniwinther,efortuna): Implement this. | |
| 320 class KernelClosureDataLookup implements ClosureDataLookup<ir.Node> { | |
| 321 const KernelClosureDataLookup(); | |
| 322 | |
| 323 @override | |
| 324 ClosureAnalysisInfo getClosureAnalysisInfo(ir.Node node) { | |
| 325 return const ClosureAnalysisInfo(); | |
| 326 } | |
| 327 | |
| 328 @override | |
| 329 LoopClosureRepresentationInfo getClosureRepresentationInfoForLoop( | |
| 330 ir.Node loopNode) { | |
| 331 return const LoopClosureRepresentationInfo(); | |
| 332 } | |
| 333 | |
| 334 @override | |
| 335 ClosureRepresentationInfo getClosureRepresentationInfo(Entity entity) { | |
| 336 if (entity is MemberEntity) { | |
| 337 ThisLocal thisLocal; | |
| 338 if (entity.isInstanceMember) { | |
| 339 thisLocal = new ThisLocal(entity); | |
| 340 } | |
| 341 return new ClosureClassMap(null, null, null, thisLocal); | |
| 342 } | |
| 343 return const ClosureRepresentationInfo(); | |
| 344 } | |
| 345 } | |
| 346 | |
| 347 class KernelSorter implements Sorter { | 321 class KernelSorter implements Sorter { |
| 348 final KernelToElementMapImpl elementMap; | 322 final KernelToElementMapImpl elementMap; |
| 349 | 323 |
| 350 KernelSorter(this.elementMap); | 324 KernelSorter(this.elementMap); |
| 351 | 325 |
| 352 int _compareLibraries(LibraryEntity a, LibraryEntity b) { | 326 int _compareLibraries(LibraryEntity a, LibraryEntity b) { |
| 353 return utils.compareLibrariesUris(a.canonicalUri, b.canonicalUri); | 327 return utils.compareLibrariesUris(a.canonicalUri, b.canonicalUri); |
| 354 } | 328 } |
| 355 | 329 |
| 356 int _compareNodes( | 330 int _compareNodes( |
| (...skipping 27 matching lines...) Expand all Loading... |
| 384 Iterable<ClassEntity> sortClasses(Iterable<ClassEntity> classes) { | 358 Iterable<ClassEntity> sortClasses(Iterable<ClassEntity> classes) { |
| 385 return classes.toList() | 359 return classes.toList() |
| 386 ..sort((ClassEntity a, ClassEntity b) { | 360 ..sort((ClassEntity a, ClassEntity b) { |
| 387 int r = _compareLibraries(a.library, b.library); | 361 int r = _compareLibraries(a.library, b.library); |
| 388 if (r != 0) return r; | 362 if (r != 0) return r; |
| 389 return _compareNodes( | 363 return _compareNodes( |
| 390 a, elementMap.getClassNode(a), b, elementMap.getClassNode(b)); | 364 a, elementMap.getClassNode(a), b, elementMap.getClassNode(b)); |
| 391 }); | 365 }); |
| 392 } | 366 } |
| 393 } | 367 } |
| OLD | NEW |