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.library_loader; | 5 library dart2js.library_loader; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:io' show Platform; | |
9 | 8 |
10 import 'package:front_end/front_end.dart' as fe; | 9 import 'package:front_end/front_end.dart' as fe; |
11 import 'package:kernel/ast.dart' as ir; | 10 import 'package:kernel/ast.dart' as ir; |
12 import 'package:kernel/binary/ast_from_binary.dart' show BinaryBuilder; | 11 import 'package:kernel/binary/ast_from_binary.dart' show BinaryBuilder; |
13 import 'package:kernel/kernel.dart' hide LibraryDependency, Combinator; | 12 import 'package:kernel/kernel.dart' hide LibraryDependency, Combinator; |
14 import 'package:kernel/target/targets.dart'; | 13 import 'package:kernel/target/targets.dart'; |
15 | 14 |
16 import '../compiler_new.dart' as api; | 15 import '../compiler_new.dart' as api; |
17 import 'kernel/front_end_adapter.dart'; | 16 import 'kernel/front_end_adapter.dart'; |
18 import 'kernel/dart2js_target.dart' show Dart2jsTarget; | 17 import 'kernel/dart2js_target.dart' show Dart2jsTarget; |
(...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
817 | 816 |
818 /// A loader that builds a kernel IR representation of the program (or set of | 817 /// A loader that builds a kernel IR representation of the program (or set of |
819 /// libraries). | 818 /// libraries). |
820 /// | 819 /// |
821 /// It supports loading both .dart source files or pre-compiled .dill files. | 820 /// It supports loading both .dart source files or pre-compiled .dill files. |
822 /// When given .dart source files, it invokes the shared frontend | 821 /// When given .dart source files, it invokes the shared frontend |
823 /// (`package:front_end`) to produce the corresponding kernel IR representation. | 822 /// (`package:front_end`) to produce the corresponding kernel IR representation. |
824 // TODO(sigmund): move this class to a new file under src/kernel/. | 823 // TODO(sigmund): move this class to a new file under src/kernel/. |
825 class KernelLibraryLoaderTask extends CompilerTask | 824 class KernelLibraryLoaderTask extends CompilerTask |
826 implements LibraryLoaderTask { | 825 implements LibraryLoaderTask { |
| 826 final Uri sdkRoot; |
| 827 |
827 final DiagnosticReporter reporter; | 828 final DiagnosticReporter reporter; |
828 | 829 |
829 final api.CompilerInput compilerInput; | 830 final api.CompilerInput compilerInput; |
830 | 831 |
831 /// Holds the mapping of Kernel IR to KElements that is constructed as a | 832 /// Holds the mapping of Kernel IR to KElements that is constructed as a |
832 /// result of loading a program. | 833 /// result of loading a program. |
833 final KernelToElementMapForImpactImpl _elementMap; | 834 final KernelToElementMapForImpactImpl _elementMap; |
834 | 835 |
835 List<LibraryEntity> _allLoadedLibraries; | 836 List<LibraryEntity> _allLoadedLibraries; |
836 | 837 |
837 KernelLibraryLoaderTask( | 838 KernelLibraryLoaderTask(this.sdkRoot, this._elementMap, this.compilerInput, |
838 this._elementMap, this.compilerInput, this.reporter, Measurer measurer) | 839 this.reporter, Measurer measurer) |
839 : _allLoadedLibraries = new List<LibraryEntity>(), | 840 : _allLoadedLibraries = new List<LibraryEntity>(), |
840 super(measurer); | 841 super(measurer); |
841 | 842 |
842 /// Loads an entire Kernel [Program] from a file on disk (note, not just a | 843 /// Loads an entire Kernel [Program] from a file on disk (note, not just a |
843 /// library, so this name is actually a bit of a misnomer). | 844 /// library, so this name is actually a bit of a misnomer). |
844 // TODO(efortuna): Rename this once the Element library loader class goes | 845 // TODO(efortuna): Rename this once the Element library loader class goes |
845 // away. | 846 // away. |
846 Future<LoadedLibraries> loadLibrary(Uri resolvedUri, | 847 Future<LoadedLibraries> loadLibrary(Uri resolvedUri, |
847 {bool skipFileWithPartOfTag: false}) { | 848 {bool skipFileWithPartOfTag: false}) { |
848 return measure(() async { | 849 return measure(() async { |
849 var isDill = resolvedUri.path.endsWith('.dill'); | 850 var isDill = resolvedUri.path.endsWith('.dill'); |
850 ir.Program program; | 851 ir.Program program; |
851 if (isDill) { | 852 if (isDill) { |
852 api.Input input = await compilerInput.readFromUri(resolvedUri, | 853 api.Input input = await compilerInput.readFromUri(resolvedUri, |
853 inputKind: api.InputKind.binary); | 854 inputKind: api.InputKind.binary); |
854 program = new ir.Program(); | 855 program = new ir.Program(); |
855 new BinaryBuilder(input.data).readProgram(program); | 856 new BinaryBuilder(input.data).readProgram(program); |
856 } else { | 857 } else { |
857 // TODO(sigmund): remove this hack. Ship platform.dill with the SDK | |
858 // instead. | |
859 // Note: this logic only works on development and bot configurations, | |
860 // but will not work when using dart2js outside the repo. | |
861 var executableUri = new Uri.file(Platform.resolvedExecutable); | |
862 Uri platformFile = executableUri.path.endsWith('dart-sdk/bin/dart') | |
863 ? executableUri.resolve('../../patched_dart2js_sdk/platform.dill') | |
864 : executableUri.resolve('patched_dart2js_sdk/platform.dill'); | |
865 var options = new fe.CompilerOptions() | 858 var options = new fe.CompilerOptions() |
866 ..fileSystem = new CompilerFileSystem(compilerInput) | 859 ..fileSystem = new CompilerFileSystem(compilerInput) |
867 ..target = new Dart2jsTarget(new TargetFlags()) | 860 ..target = new Dart2jsTarget(new TargetFlags()) |
868 ..compileSdk = true | 861 ..compileSdk = true |
869 ..linkedDependencies = [platformFile] | 862 ..linkedDependencies = [ |
| 863 sdkRoot.resolve('_internal/dart2js_platform.dill') |
| 864 ] |
870 ..onError = (e) => reportFrontEndMessage(reporter, e); | 865 ..onError = (e) => reportFrontEndMessage(reporter, e); |
871 | 866 |
872 program = await fe.kernelForProgram(resolvedUri, options); | 867 program = await fe.kernelForProgram(resolvedUri, options); |
873 } | 868 } |
874 if (program == null) return null; | 869 if (program == null) return null; |
875 return createLoadedLibraries(program); | 870 return createLoadedLibraries(program); |
876 }); | 871 }); |
877 } | 872 } |
878 | 873 |
879 // Only visible for unit testing. | 874 // Only visible for unit testing. |
(...skipping 815 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1695 } | 1690 } |
1696 | 1691 |
1697 /// API used by the library loader to synchronously scan a library or | 1692 /// API used by the library loader to synchronously scan a library or |
1698 /// compilation unit and ensure that their library tags are computed. | 1693 /// compilation unit and ensure that their library tags are computed. |
1699 abstract class ElementScanner { | 1694 abstract class ElementScanner { |
1700 void scanLibrary(LibraryElement library); | 1695 void scanLibrary(LibraryElement library); |
1701 void scanUnit(CompilationUnitElement unit); | 1696 void scanUnit(CompilationUnitElement unit); |
1702 } | 1697 } |
1703 | 1698 |
1704 const _reuseLibrarySubtaskName = "Reuse library"; | 1699 const _reuseLibrarySubtaskName = "Reuse library"; |
OLD | NEW |