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 part of js_backend; | 5 part of js_backend; |
6 | 6 |
7 const VERBOSE_OPTIMIZER_HINTS = false; | 7 const VERBOSE_OPTIMIZER_HINTS = false; |
8 | 8 |
9 class JavaScriptItemCompilationContext extends ItemCompilationContext { | 9 class JavaScriptItemCompilationContext extends ItemCompilationContext { |
10 final Set<HInstruction> boundsChecked = new Set<HInstruction>(); | 10 final Set<HInstruction> boundsChecked = new Set<HInstruction>(); |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 NoSuchMethodRegistry noSuchMethodRegistry; | 495 NoSuchMethodRegistry noSuchMethodRegistry; |
496 | 496 |
497 JavaScriptConstantTask constantCompilerTask; | 497 JavaScriptConstantTask constantCompilerTask; |
498 | 498 |
499 JavaScriptImpactTransformer impactTransformer; | 499 JavaScriptImpactTransformer impactTransformer; |
500 | 500 |
501 PatchResolverTask patchResolverTask; | 501 PatchResolverTask patchResolverTask; |
502 | 502 |
503 bool enabledNoSuchMethod = false; | 503 bool enabledNoSuchMethod = false; |
504 | 504 |
505 final SourceInformationStrategy sourceInformationStrategy; | 505 SourceInformationStrategy sourceInformationStrategy; |
506 | 506 |
507 final BackendHelpers helpers; | 507 final BackendHelpers helpers; |
508 final BackendImpacts impacts; | 508 final BackendImpacts impacts; |
509 | 509 |
510 JavaScriptBackend(Compiler compiler, | 510 JavaScriptBackend(Compiler compiler, |
511 {bool generateSourceMap: true, | 511 {bool generateSourceMap: true, |
512 bool useStartupEmitter: false}) | 512 bool useStartupEmitter: false}) |
513 : namer = determineNamer(compiler), | 513 : namer = determineNamer(compiler), |
514 oneShotInterceptors = new Map<jsAst.Name, Selector>(), | 514 oneShotInterceptors = new Map<jsAst.Name, Selector>(), |
515 interceptedElements = new Map<String, Set<Element>>(), | 515 interceptedElements = new Map<String, Set<Element>>(), |
516 rti = new _RuntimeTypes(compiler), | 516 rti = new _RuntimeTypes(compiler), |
517 rtiEncoder = new _RuntimeTypesEncoder(compiler), | 517 rtiEncoder = new _RuntimeTypesEncoder(compiler), |
518 specializedGetInterceptors = new Map<jsAst.Name, Set<ClassElement>>(), | 518 specializedGetInterceptors = new Map<jsAst.Name, Set<ClassElement>>(), |
519 annotations = new Annotations(compiler), | 519 annotations = new Annotations(compiler), |
520 this.sourceInformationStrategy = | 520 this.sourceInformationStrategy = |
521 generateSourceMap | 521 generateSourceMap |
522 ? (useNewSourceInfo | 522 ? (useNewSourceInfo |
523 ? const PositionSourceInformationStrategy() | 523 ? new PositionSourceInformationStrategy() |
524 : const StartEndSourceInformationStrategy()) | 524 : const StartEndSourceInformationStrategy()) |
525 : const JavaScriptSourceInformationStrategy(), | 525 : const JavaScriptSourceInformationStrategy(), |
526 helpers = new BackendHelpers(compiler), | 526 helpers = new BackendHelpers(compiler), |
527 impacts = new BackendImpacts(compiler), | 527 impacts = new BackendImpacts(compiler), |
528 super(compiler) { | 528 super(compiler) { |
529 emitter = new CodeEmitterTask( | 529 emitter = new CodeEmitterTask( |
530 compiler, namer, generateSourceMap, useStartupEmitter); | 530 compiler, namer, generateSourceMap, useStartupEmitter); |
531 typeVariableHandler = new TypeVariableHandler(compiler); | 531 typeVariableHandler = new TypeVariableHandler(compiler); |
532 customElementsAnalysis = new CustomElementsAnalysis(this); | 532 customElementsAnalysis = new CustomElementsAnalysis(this); |
533 lookupMapAnalysis = new LookupMapAnalysis(this, reporter); | 533 lookupMapAnalysis = new LookupMapAnalysis(this, reporter); |
(...skipping 1089 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1623 // If the constant-handler was not able to produce a result we have to | 1623 // If the constant-handler was not able to produce a result we have to |
1624 // go through the builder (below) to generate the lazy initializer for | 1624 // go through the builder (below) to generate the lazy initializer for |
1625 // the static variable. | 1625 // the static variable. |
1626 // We also need to register the use of the cyclic-error helper. | 1626 // We also need to register the use of the cyclic-error helper. |
1627 compiler.enqueuer.codegen.registerStaticUse( | 1627 compiler.enqueuer.codegen.registerStaticUse( |
1628 new StaticUse.staticInvoke( | 1628 new StaticUse.staticInvoke( |
1629 helpers.cyclicThrowHelper, CallStructure.ONE_ARG)); | 1629 helpers.cyclicThrowHelper, CallStructure.ONE_ARG)); |
1630 } | 1630 } |
1631 } | 1631 } |
1632 | 1632 |
1633 generatedCode[element] = functionCompiler.compile(work); | 1633 jsAst.Fun function = functionCompiler.compile(work); |
| 1634 if (function.sourceInformation == null) { |
| 1635 function = function.withSourceInformation( |
| 1636 sourceInformationStrategy.buildSourceMappedMarker()); |
| 1637 } |
| 1638 generatedCode[element] = function; |
1634 WorldImpact worldImpact = | 1639 WorldImpact worldImpact = |
1635 impactTransformer.transformCodegenImpact(work.registry.worldImpact); | 1640 impactTransformer.transformCodegenImpact(work.registry.worldImpact); |
1636 compiler.dumpInfoTask.registerImpact(element, worldImpact); | 1641 compiler.dumpInfoTask.registerImpact(element, worldImpact); |
1637 return worldImpact; | 1642 return worldImpact; |
1638 } | 1643 } |
1639 | 1644 |
1640 native.NativeEnqueuer nativeResolutionEnqueuer(Enqueuer world) { | 1645 native.NativeEnqueuer nativeResolutionEnqueuer(Enqueuer world) { |
1641 return new native.NativeResolutionEnqueuer(world, compiler); | 1646 return new native.NativeResolutionEnqueuer(world, compiler); |
1642 } | 1647 } |
1643 | 1648 |
(...skipping 10 matching lines...) Expand all Loading... |
1654 ? helpers.jsInterceptorClass : coreClasses.objectClass; | 1659 ? helpers.jsInterceptorClass : coreClasses.objectClass; |
1655 } | 1660 } |
1656 | 1661 |
1657 /** | 1662 /** |
1658 * Unit test hook that returns code of an element as a String. | 1663 * Unit test hook that returns code of an element as a String. |
1659 * | 1664 * |
1660 * Invariant: [element] must be a declaration element. | 1665 * Invariant: [element] must be a declaration element. |
1661 */ | 1666 */ |
1662 String getGeneratedCode(Element element) { | 1667 String getGeneratedCode(Element element) { |
1663 assert(invariant(element, element.isDeclaration)); | 1668 assert(invariant(element, element.isDeclaration)); |
1664 return jsAst.prettyPrint(generatedCode[element], compiler).getText(); | 1669 return jsAst.prettyPrint(generatedCode[element], compiler); |
1665 } | 1670 } |
1666 | 1671 |
1667 int assembleProgram() { | 1672 int assembleProgram() { |
1668 int programSize = emitter.assembleProgram(); | 1673 int programSize = emitter.assembleProgram(); |
1669 noSuchMethodRegistry.emitDiagnostic(); | 1674 noSuchMethodRegistry.emitDiagnostic(); |
1670 int totalMethodCount = generatedCode.length; | 1675 int totalMethodCount = generatedCode.length; |
1671 if (totalMethodCount != preMirrorsMethodCount) { | 1676 if (totalMethodCount != preMirrorsMethodCount) { |
1672 int mirrorCount = totalMethodCount - preMirrorsMethodCount; | 1677 int mirrorCount = totalMethodCount - preMirrorsMethodCount; |
1673 double percentage = (mirrorCount / totalMethodCount) * 100; | 1678 double percentage = (mirrorCount / totalMethodCount) * 100; |
1674 DiagnosticMessage hint = reporter.createMessage( | 1679 DiagnosticMessage hint = reporter.createMessage( |
(...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2502 "@NoThrows() should always be combined with @NoInline."); | 2507 "@NoThrows() should always be combined with @NoInline."); |
2503 } | 2508 } |
2504 if (hasNoSideEffects && !hasNoInline) { | 2509 if (hasNoSideEffects && !hasNoInline) { |
2505 reporter.internalError(element, | 2510 reporter.internalError(element, |
2506 "@NoSideEffects() should always be combined with @NoInline."); | 2511 "@NoSideEffects() should always be combined with @NoInline."); |
2507 } | 2512 } |
2508 if (element == helpers.invokeOnMethod) { | 2513 if (element == helpers.invokeOnMethod) { |
2509 compiler.enabledInvokeOn = true; | 2514 compiler.enabledInvokeOn = true; |
2510 } | 2515 } |
2511 } | 2516 } |
2512 | 2517 /* |
2513 CodeBuffer codeOf(Element element) { | 2518 CodeBuffer codeOf(Element element) { |
2514 return generatedCode.containsKey(element) | 2519 return generatedCode.containsKey(element) |
2515 ? jsAst.prettyPrint(generatedCode[element], compiler) | 2520 ? jsAst.prettyPrint(generatedCode[element], compiler) |
2516 : null; | 2521 : null; |
2517 } | 2522 } |
2518 | 2523 */ |
2519 FunctionElement helperForBadMain() => helpers.badMain; | 2524 FunctionElement helperForBadMain() => helpers.badMain; |
2520 | 2525 |
2521 FunctionElement helperForMissingMain() => helpers.missingMain; | 2526 FunctionElement helperForMissingMain() => helpers.missingMain; |
2522 | 2527 |
2523 FunctionElement helperForMainArity() => helpers.mainHasTooManyParameters; | 2528 FunctionElement helperForMainArity() => helpers.mainHasTooManyParameters; |
2524 | 2529 |
2525 void forgetElement(Element element) { | 2530 void forgetElement(Element element) { |
2526 constants.forgetElement(element); | 2531 constants.forgetElement(element); |
2527 constantCompilerTask.dartConstantCompiler.forgetElement(element); | 2532 constantCompilerTask.dartConstantCompiler.forgetElement(element); |
2528 aliasedSuperMembers.remove(element); | 2533 aliasedSuperMembers.remove(element); |
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3164 } | 3169 } |
3165 } | 3170 } |
3166 | 3171 |
3167 @override | 3172 @override |
3168 void onImpactUsed(ImpactUseCase impactUse) { | 3173 void onImpactUsed(ImpactUseCase impactUse) { |
3169 if (impactUse == DeferredLoadTask.IMPACT_USE) { | 3174 if (impactUse == DeferredLoadTask.IMPACT_USE) { |
3170 resolution.emptyCache(); | 3175 resolution.emptyCache(); |
3171 } | 3176 } |
3172 } | 3177 } |
3173 } | 3178 } |
OLD | NEW |