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 dart2js.compiler_base; | 5 library dart2js.compiler_base; |
6 | 6 |
7 import 'dart:async' show Future; | 7 import 'dart:async' show Future; |
8 | 8 |
9 import '../compiler_new.dart' as api; | 9 import '../compiler_new.dart' as api; |
| 10 import 'backend_strategy.dart'; |
10 import 'closure.dart' as closureMapping show ClosureTask; | 11 import 'closure.dart' as closureMapping show ClosureTask; |
11 import 'common/names.dart' show Selectors; | 12 import 'common/names.dart' show Selectors; |
12 import 'common/names.dart' show Uris; | 13 import 'common/names.dart' show Uris; |
13 import 'common/resolution.dart' | 14 import 'common/resolution.dart' |
14 show | 15 show |
15 ParsingContext, | 16 ParsingContext, |
16 Resolution, | 17 Resolution, |
17 ResolutionWorkItem, | 18 ResolutionWorkItem, |
18 ResolutionImpact, | 19 ResolutionImpact, |
19 Target; | 20 Target; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 import 'tree/tree.dart' show Node, TypeAnnotation; | 66 import 'tree/tree.dart' show Node, TypeAnnotation; |
66 import 'typechecker.dart' show TypeCheckerTask; | 67 import 'typechecker.dart' show TypeCheckerTask; |
67 import 'types/types.dart' show GlobalTypeInferenceTask; | 68 import 'types/types.dart' show GlobalTypeInferenceTask; |
68 import 'universe/selector.dart' show Selector; | 69 import 'universe/selector.dart' show Selector; |
69 import 'universe/world_builder.dart' | 70 import 'universe/world_builder.dart' |
70 show ResolutionWorldBuilder, CodegenWorldBuilder; | 71 show ResolutionWorldBuilder, CodegenWorldBuilder; |
71 import 'universe/use.dart' show StaticUse, TypeUse; | 72 import 'universe/use.dart' show StaticUse, TypeUse; |
72 import 'universe/world_impact.dart' | 73 import 'universe/world_impact.dart' |
73 show ImpactStrategy, WorldImpact, WorldImpactBuilderImpl; | 74 show ImpactStrategy, WorldImpact, WorldImpactBuilderImpl; |
74 import 'util/util.dart' show Link; | 75 import 'util/util.dart' show Link; |
75 import 'world.dart' show ClosedWorld, ClosedWorldRefiner, ClosedWorldImpl; | 76 import 'world.dart' show ClosedWorld, ClosedWorldRefiner; |
76 | 77 |
77 typedef CompilerDiagnosticReporter MakeReporterFunction( | 78 typedef CompilerDiagnosticReporter MakeReporterFunction( |
78 Compiler compiler, CompilerOptions options); | 79 Compiler compiler, CompilerOptions options); |
79 | 80 |
80 abstract class Compiler { | 81 abstract class Compiler { |
81 Measurer get measurer; | 82 Measurer get measurer; |
82 | 83 |
83 final IdGenerator idGenerator = new IdGenerator(); | 84 final IdGenerator idGenerator = new IdGenerator(); |
84 DartTypes types; | 85 DartTypes types; |
85 FrontEndStrategy frontEndStrategy; | 86 FrontEndStrategy frontEndStrategy; |
| 87 BackendStrategy backendStrategy; |
86 CommonElements _commonElements; | 88 CommonElements _commonElements; |
87 ElementEnvironment _elementEnvironment; | 89 ElementEnvironment _elementEnvironment; |
88 CompilerDiagnosticReporter _reporter; | 90 CompilerDiagnosticReporter _reporter; |
89 CompilerResolution _resolution; | 91 CompilerResolution _resolution; |
90 ParsingContext _parsingContext; | 92 ParsingContext _parsingContext; |
91 | 93 |
92 ImpactStrategy impactStrategy = const ImpactStrategy(); | 94 ImpactStrategy impactStrategy = const ImpactStrategy(); |
93 | 95 |
94 /** | 96 /** |
95 * Map from token to the first preceding comment token. | 97 * Map from token to the first preceding comment token. |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 ? const NullCompilerOutput() | 188 ? const NullCompilerOutput() |
187 : outputProvider { | 189 : outputProvider { |
188 if (makeReporter != null) { | 190 if (makeReporter != null) { |
189 _reporter = makeReporter(this, options); | 191 _reporter = makeReporter(this, options); |
190 } else { | 192 } else { |
191 _reporter = new CompilerDiagnosticReporter(this, options); | 193 _reporter = new CompilerDiagnosticReporter(this, options); |
192 } | 194 } |
193 frontEndStrategy = options.loadFromDill | 195 frontEndStrategy = options.loadFromDill |
194 ? new KernelFrontEndStrategy(reporter) | 196 ? new KernelFrontEndStrategy(reporter) |
195 : new ResolutionFrontEndStrategy(this); | 197 : new ResolutionFrontEndStrategy(this); |
| 198 backendStrategy = options.loadFromDill |
| 199 ? new KernelBackendStrategy() |
| 200 : new ElementBackendStrategy(this); |
196 _resolution = createResolution(); | 201 _resolution = createResolution(); |
197 _elementEnvironment = frontEndStrategy.elementEnvironment; | 202 _elementEnvironment = frontEndStrategy.elementEnvironment; |
198 _commonElements = new CommonElements(_elementEnvironment); | 203 _commonElements = new CommonElements(_elementEnvironment); |
199 types = new Types(_resolution); | 204 types = new Types(_resolution); |
200 | 205 |
201 if (options.verbose) { | 206 if (options.verbose) { |
202 progress = new Stopwatch()..start(); | 207 progress = new Stopwatch()..start(); |
203 } | 208 } |
204 | 209 |
205 backend = createBackend(); | 210 backend = createBackend(); |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 | 624 |
620 backend.onCodegenEnd(); | 625 backend.onCodegenEnd(); |
621 | 626 |
622 checkQueues(resolutionEnqueuer, codegenEnqueuer); | 627 checkQueues(resolutionEnqueuer, codegenEnqueuer); |
623 }); | 628 }); |
624 | 629 |
625 /// Perform the steps needed to fully end the resolution phase. | 630 /// Perform the steps needed to fully end the resolution phase. |
626 ClosedWorldRefiner closeResolution() { | 631 ClosedWorldRefiner closeResolution() { |
627 phase = PHASE_DONE_RESOLVING; | 632 phase = PHASE_DONE_RESOLVING; |
628 | 633 |
629 ClosedWorldImpl world = resolutionWorldBuilder.closeWorld(); | 634 ClosedWorld closedWorld = resolutionWorldBuilder.closeWorld(); |
| 635 ClosedWorldRefiner closedWorldRefiner = |
| 636 backendStrategy.createClosedWorldRefiner(closedWorld); |
630 // Compute whole-program-knowledge that the backend needs. (This might | 637 // Compute whole-program-knowledge that the backend needs. (This might |
631 // require the information computed in [world.closeWorld].) | 638 // require the information computed in [world.closeWorld].) |
632 backend.onResolutionClosedWorld(world, world); | 639 backend.onResolutionClosedWorld(closedWorld, closedWorldRefiner); |
633 | 640 |
634 deferredLoadTask.onResolutionComplete(mainFunction); | 641 deferredLoadTask.onResolutionComplete(mainFunction); |
635 | 642 |
636 // TODO(johnniwinther): Move this after rti computation but before | 643 // TODO(johnniwinther): Move this after rti computation but before |
637 // reflection members computation, and (re-)close the world afterwards. | 644 // reflection members computation, and (re-)close the world afterwards. |
638 closureToClassMapper.createClosureClasses(world); | 645 backendStrategy.convertClosures(closedWorldRefiner); |
639 return world; | 646 return closedWorldRefiner; |
640 } | 647 } |
641 | 648 |
642 /// Compute the [WorldImpact] for accessing all elements in [library]. | 649 /// Compute the [WorldImpact] for accessing all elements in [library]. |
643 WorldImpact computeImpactForLibrary(LibraryElement library) { | 650 WorldImpact computeImpactForLibrary(LibraryElement library) { |
644 WorldImpactBuilderImpl impactBuilder = new WorldImpactBuilderImpl(); | 651 WorldImpactBuilderImpl impactBuilder = new WorldImpactBuilderImpl(); |
645 | 652 |
646 void registerStaticUse(Element element) { | 653 void registerStaticUse(Element element) { |
647 impactBuilder.registerStaticUse(new StaticUse.directUse(element)); | 654 impactBuilder.registerStaticUse(new StaticUse.directUse(element)); |
648 } | 655 } |
649 | 656 |
(...skipping 1026 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1676 _ElementScanner(this.scanner); | 1683 _ElementScanner(this.scanner); |
1677 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); | 1684 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); |
1678 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); | 1685 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); |
1679 } | 1686 } |
1680 | 1687 |
1681 class _EmptyEnvironment implements Environment { | 1688 class _EmptyEnvironment implements Environment { |
1682 const _EmptyEnvironment(); | 1689 const _EmptyEnvironment(); |
1683 | 1690 |
1684 String valueOf(String key) => null; | 1691 String valueOf(String key) => null; |
1685 } | 1692 } |
OLD | NEW |