| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 js_backend.backend; | 5 library js_backend.backend; |
| 6 | 6 |
| 7 import 'dart:async' show Future; | 7 import 'dart:async' show Future; |
| 8 | 8 |
| 9 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames; | 9 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames; |
| 10 | 10 |
| 11 import '../common.dart'; | 11 import '../common.dart'; |
| 12 import '../common/backend_api.dart' | 12 import '../common/backend_api.dart' |
| 13 show BackendClasses, ForeignResolver, NativeRegistry; | 13 show BackendClasses, ForeignResolver, NativeRegistry, ImpactTransformer; |
| 14 import '../common/codegen.dart' show CodegenImpact, CodegenWorkItem; | 14 import '../common/codegen.dart' show CodegenImpact, CodegenWorkItem; |
| 15 import '../common/names.dart' show Uris; | 15 import '../common/names.dart' show Uris; |
| 16 import '../common/resolution.dart' | 16 import '../common/resolution.dart' |
| 17 show Frontend, Resolution, ResolutionImpact, Target; | 17 show Frontend, Resolution, ResolutionImpact, Target; |
| 18 import '../common/tasks.dart' show CompilerTask; | 18 import '../common/tasks.dart' show CompilerTask; |
| 19 import '../compiler.dart' show Compiler; | 19 import '../compiler.dart' show Compiler; |
| 20 import '../constants/constant_system.dart'; | 20 import '../constants/constant_system.dart'; |
| 21 import '../constants/expressions.dart'; | 21 import '../constants/expressions.dart'; |
| 22 import '../constants/values.dart'; | 22 import '../constants/values.dart'; |
| 23 import '../common_elements.dart' show CommonElements, ElementEnvironment; | 23 import '../common_elements.dart' show CommonElements, ElementEnvironment; |
| 24 import '../deferred_load.dart' show DeferredLoadTask; | 24 import '../deferred_load.dart' show DeferredLoadTask; |
| 25 import '../dump_info.dart' show DumpInfoTask; | 25 import '../dump_info.dart' show DumpInfoTask; |
| 26 import '../elements/elements.dart'; | 26 import '../elements/elements.dart'; |
| 27 import '../elements/entities.dart'; | 27 import '../elements/entities.dart'; |
| 28 import '../elements/resolution_types.dart'; | 28 import '../elements/resolution_types.dart'; |
| 29 import '../elements/types.dart'; | 29 import '../elements/types.dart'; |
| 30 import '../enqueue.dart' | 30 import '../enqueue.dart' |
| 31 show | 31 show |
| 32 DirectEnqueuerStrategy, | 32 DirectEnqueuerStrategy, |
| 33 Enqueuer, | 33 Enqueuer, |
| 34 EnqueuerListener, | |
| 35 EnqueueTask, | 34 EnqueueTask, |
| 36 ResolutionEnqueuer, | 35 ResolutionEnqueuer, |
| 37 ResolutionWorkItemBuilder, | 36 ResolutionWorkItemBuilder, |
| 38 TreeShakingEnqueuerStrategy; | 37 TreeShakingEnqueuerStrategy; |
| 39 import '../io/multi_information.dart' show MultiSourceInformationStrategy; | 38 import '../io/multi_information.dart' show MultiSourceInformationStrategy; |
| 40 import '../io/position_information.dart' show PositionSourceInformationStrategy; | 39 import '../io/position_information.dart' show PositionSourceInformationStrategy; |
| 41 import '../io/source_information.dart' show SourceInformationStrategy; | 40 import '../io/source_information.dart' show SourceInformationStrategy; |
| 42 import '../io/start_end_information.dart' | 41 import '../io/start_end_information.dart' |
| 43 show StartEndSourceInformationStrategy; | 42 show StartEndSourceInformationStrategy; |
| 44 import '../js/js.dart' as jsAst; | 43 import '../js/js.dart' as jsAst; |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 MirrorsAnalysis mirrorsAnalysis; | 414 MirrorsAnalysis mirrorsAnalysis; |
| 416 | 415 |
| 417 /// Builds kernel representation for the program. | 416 /// Builds kernel representation for the program. |
| 418 KernelTask kernelTask; | 417 KernelTask kernelTask; |
| 419 | 418 |
| 420 /// The compiler task responsible for the compilation of constants for both | 419 /// The compiler task responsible for the compilation of constants for both |
| 421 /// the frontend and the backend. | 420 /// the frontend and the backend. |
| 422 final JavaScriptConstantTask constantCompilerTask; | 421 final JavaScriptConstantTask constantCompilerTask; |
| 423 | 422 |
| 424 /// Backend transformation methods for the world impacts. | 423 /// Backend transformation methods for the world impacts. |
| 425 JavaScriptImpactTransformer impactTransformer; | 424 ImpactTransformer impactTransformer; |
| 425 |
| 426 CodegenImpactTransformer _codegenImpactTransformer; |
| 426 | 427 |
| 427 PatchResolverTask patchResolverTask; | 428 PatchResolverTask patchResolverTask; |
| 428 | 429 |
| 429 /// The strategy used for collecting and emitting source information. | 430 /// The strategy used for collecting and emitting source information. |
| 430 SourceInformationStrategy sourceInformationStrategy; | 431 SourceInformationStrategy sourceInformationStrategy; |
| 431 | 432 |
| 432 /// Interface for serialization of backend specific data. | 433 /// Interface for serialization of backend specific data. |
| 433 JavaScriptBackendSerialization serialization; | 434 JavaScriptBackendSerialization serialization; |
| 434 | 435 |
| 435 NativeDataImpl _nativeData; | 436 NativeDataImpl _nativeData; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 nativeClassData); | 540 nativeClassData); |
| 540 jsInteropAnalysis = new JsInteropAnalysis(this); | 541 jsInteropAnalysis = new JsInteropAnalysis(this); |
| 541 mirrorsAnalysis = new MirrorsAnalysis(this, compiler.resolution); | 542 mirrorsAnalysis = new MirrorsAnalysis(this, compiler.resolution); |
| 542 lookupMapLibraryAccess = | 543 lookupMapLibraryAccess = |
| 543 new LookupMapLibraryAccess(reporter, compiler.elementEnvironment); | 544 new LookupMapLibraryAccess(reporter, compiler.elementEnvironment); |
| 544 lookupMapAnalysis = new LookupMapAnalysis(this, compiler.options, reporter, | 545 lookupMapAnalysis = new LookupMapAnalysis(this, compiler.options, reporter, |
| 545 compiler.elementEnvironment, commonElements, backendClasses); | 546 compiler.elementEnvironment, commonElements, backendClasses); |
| 546 | 547 |
| 547 noSuchMethodRegistry = new NoSuchMethodRegistry(this); | 548 noSuchMethodRegistry = new NoSuchMethodRegistry(this); |
| 548 kernelTask = new KernelTask(compiler); | 549 kernelTask = new KernelTask(compiler); |
| 549 impactTransformer = new JavaScriptImpactTransformer(this); | 550 impactTransformer = new JavaScriptImpactTransformer( |
| 551 compiler.options, |
| 552 compiler.resolution, |
| 553 compiler.elementEnvironment, |
| 554 commonElements, |
| 555 impacts, |
| 556 nativeClassData, |
| 557 nativeResolutionEnqueuer, |
| 558 backendUsageBuilder, |
| 559 mirrorsData, |
| 560 customElementsResolutionAnalysis, |
| 561 rtiNeedBuilder); |
| 550 patchResolverTask = new PatchResolverTask(compiler); | 562 patchResolverTask = new PatchResolverTask(compiler); |
| 551 functionCompiler = | 563 functionCompiler = |
| 552 new SsaFunctionCompiler(this, sourceInformationStrategy, useKernel); | 564 new SsaFunctionCompiler(this, sourceInformationStrategy, useKernel); |
| 553 serialization = | 565 serialization = |
| 554 new JavaScriptBackendSerialization(nativeClassData, nativeData); | 566 new JavaScriptBackendSerialization(nativeClassData, nativeData); |
| 555 _interceptorDataBuilder = new InterceptorDataBuilderImpl( | 567 _interceptorDataBuilder = new InterceptorDataBuilderImpl( |
| 556 nativeClassData, helpers, commonElements, compiler.resolution); | 568 nativeClassData, helpers, commonElements, compiler.resolution); |
| 557 } | 569 } |
| 558 | 570 |
| 559 /// The [ConstantSystem] used to interpret compile-time constants for this | 571 /// The [ConstantSystem] used to interpret compile-time constants for this |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1008 ConstantValue initialValue = constants.getConstantValue(constant); | 1020 ConstantValue initialValue = constants.getConstantValue(constant); |
| 1009 if (initialValue != null) { | 1021 if (initialValue != null) { |
| 1010 computeImpactForCompileTimeConstant( | 1022 computeImpactForCompileTimeConstant( |
| 1011 initialValue, work.registry.worldImpact, | 1023 initialValue, work.registry.worldImpact, |
| 1012 forResolution: false); | 1024 forResolution: false); |
| 1013 addCompileTimeConstantForEmission(initialValue); | 1025 addCompileTimeConstantForEmission(initialValue); |
| 1014 // We don't need to generate code for static or top-level | 1026 // We don't need to generate code for static or top-level |
| 1015 // variables. For instance variables, we may need to generate | 1027 // variables. For instance variables, we may need to generate |
| 1016 // the checked setter. | 1028 // the checked setter. |
| 1017 if (Elements.isStaticOrTopLevel(element)) { | 1029 if (Elements.isStaticOrTopLevel(element)) { |
| 1018 return impactTransformer | 1030 return _codegenImpactTransformer |
| 1019 .transformCodegenImpact(work.registry.worldImpact); | 1031 .transformCodegenImpact(work.registry.worldImpact); |
| 1020 } | 1032 } |
| 1021 } else { | 1033 } else { |
| 1022 assert(invariant( | 1034 assert(invariant( |
| 1023 variableElement, | 1035 variableElement, |
| 1024 variableElement.isInstanceMember || | 1036 variableElement.isInstanceMember || |
| 1025 constant.isImplicit || | 1037 constant.isImplicit || |
| 1026 constant.isPotential, | 1038 constant.isPotential, |
| 1027 message: "Constant expression without value: " | 1039 message: "Constant expression without value: " |
| 1028 "${constant.toStructuredText()}.")); | 1040 "${constant.toStructuredText()}.")); |
| 1029 } | 1041 } |
| 1030 } else { | 1042 } else { |
| 1031 // If the constant-handler was not able to produce a result we have to | 1043 // If the constant-handler was not able to produce a result we have to |
| 1032 // go through the builder (below) to generate the lazy initializer for | 1044 // go through the builder (below) to generate the lazy initializer for |
| 1033 // the static variable. | 1045 // the static variable. |
| 1034 // We also need to register the use of the cyclic-error helper. | 1046 // We also need to register the use of the cyclic-error helper. |
| 1035 work.registry.worldImpact.registerStaticUse(new StaticUse.staticInvoke( | 1047 work.registry.worldImpact.registerStaticUse(new StaticUse.staticInvoke( |
| 1036 helpers.cyclicThrowHelper, CallStructure.ONE_ARG)); | 1048 helpers.cyclicThrowHelper, CallStructure.ONE_ARG)); |
| 1037 } | 1049 } |
| 1038 } | 1050 } |
| 1039 | 1051 |
| 1040 jsAst.Fun function = functionCompiler.compile(work, _closedWorld); | 1052 jsAst.Fun function = functionCompiler.compile(work, _closedWorld); |
| 1041 if (function.sourceInformation == null) { | 1053 if (function.sourceInformation == null) { |
| 1042 function = function.withSourceInformation( | 1054 function = function.withSourceInformation( |
| 1043 sourceInformationStrategy.buildSourceMappedMarker()); | 1055 sourceInformationStrategy.buildSourceMappedMarker()); |
| 1044 } | 1056 } |
| 1045 generatedCode[element] = function; | 1057 generatedCode[element] = function; |
| 1046 WorldImpact worldImpact = | 1058 WorldImpact worldImpact = _codegenImpactTransformer |
| 1047 impactTransformer.transformCodegenImpact(work.registry.worldImpact); | 1059 .transformCodegenImpact(work.registry.worldImpact); |
| 1048 compiler.dumpInfoTask.registerImpact(element, worldImpact); | 1060 compiler.dumpInfoTask.registerImpact(element, worldImpact); |
| 1049 return worldImpact; | 1061 return worldImpact; |
| 1050 } | 1062 } |
| 1051 | 1063 |
| 1052 native.NativeEnqueuer get nativeResolutionEnqueuer => | 1064 native.NativeEnqueuer get nativeResolutionEnqueuer => |
| 1053 _nativeResolutionEnqueuer; | 1065 _nativeResolutionEnqueuer; |
| 1054 | 1066 |
| 1055 native.NativeEnqueuer get nativeCodegenEnqueuer => _nativeCodegenEnqueuer; | 1067 native.NativeEnqueuer get nativeCodegenEnqueuer => _nativeCodegenEnqueuer; |
| 1056 | 1068 |
| 1057 ClassElement defaultSuperclass(ClassElement element) { | 1069 ClassElement defaultSuperclass(ClassElement element) { |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1229 _closedWorldCache = value; | 1241 _closedWorldCache = value; |
| 1230 } | 1242 } |
| 1231 | 1243 |
| 1232 /// Called when the compiler starts running the codegen enqueuer. The | 1244 /// Called when the compiler starts running the codegen enqueuer. The |
| 1233 /// [WorldImpact] of enabled backend features is returned. | 1245 /// [WorldImpact] of enabled backend features is returned. |
| 1234 WorldImpact onCodegenStart( | 1246 WorldImpact onCodegenStart( |
| 1235 ClosedWorld closedWorld, CodegenWorldBuilder codegenWorldBuilder) { | 1247 ClosedWorld closedWorld, CodegenWorldBuilder codegenWorldBuilder) { |
| 1236 _closedWorld = closedWorld; | 1248 _closedWorld = closedWorld; |
| 1237 _namer = determineNamer(closedWorld, codegenWorldBuilder); | 1249 _namer = determineNamer(closedWorld, codegenWorldBuilder); |
| 1238 tracer = new Tracer(closedWorld, namer, compiler); | 1250 tracer = new Tracer(closedWorld, namer, compiler); |
| 1239 emitter.createEmitter(_namer, closedWorld); | 1251 emitter.createEmitter(namer, closedWorld); |
| 1240 _rtiEncoder = | 1252 _rtiEncoder = |
| 1241 _namer.rtiEncoder = new _RuntimeTypesEncoder(_namer, emitter, helpers); | 1253 _namer.rtiEncoder = new _RuntimeTypesEncoder(namer, emitter, helpers); |
| 1242 | 1254 _codegenImpactTransformer = new CodegenImpactTransformer( |
| 1255 this, |
| 1256 compiler.options, |
| 1257 compiler.elementEnvironment, |
| 1258 helpers, |
| 1259 impacts, |
| 1260 checkedModeHelpers, |
| 1261 nativeData, |
| 1262 rtiNeed, |
| 1263 nativeCodegenEnqueuer, |
| 1264 namer, |
| 1265 mirrorsData, |
| 1266 oneShotInterceptorData, |
| 1267 lookupMapAnalysis, |
| 1268 customElementsCodegenAnalysis); |
| 1243 lookupMapAnalysis.onCodegenStart(lookupMapLibraryAccess); | 1269 lookupMapAnalysis.onCodegenStart(lookupMapLibraryAccess); |
| 1244 return const WorldImpact(); | 1270 return const WorldImpact(); |
| 1245 } | 1271 } |
| 1246 | 1272 |
| 1247 /// Called when code generation has been completed. | 1273 /// Called when code generation has been completed. |
| 1248 void onCodegenEnd() { | 1274 void onCodegenEnd() { |
| 1249 sourceInformationStrategy.onComplete(); | 1275 sourceInformationStrategy.onComplete(); |
| 1250 tracer.close(); | 1276 tracer.close(); |
| 1251 } | 1277 } |
| 1252 | 1278 |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1630 return _backend.defaultSuperclass(element); | 1656 return _backend.defaultSuperclass(element); |
| 1631 } | 1657 } |
| 1632 | 1658 |
| 1633 @override | 1659 @override |
| 1634 bool isNativeClass(ClassEntity element) => | 1660 bool isNativeClass(ClassEntity element) => |
| 1635 _backend.nativeClassData.isNativeClass(element); | 1661 _backend.nativeClassData.isNativeClass(element); |
| 1636 | 1662 |
| 1637 @override | 1663 @override |
| 1638 bool isForeign(Element element) => _backend.isForeign(element); | 1664 bool isForeign(Element element) => _backend.isForeign(element); |
| 1639 } | 1665 } |
| OLD | NEW |