Index: pkg/compiler/lib/src/library_loader.dart |
diff --git a/pkg/compiler/lib/src/library_loader.dart b/pkg/compiler/lib/src/library_loader.dart |
index e471c1f1f8c226f40f52ee201d9c83de3398fd1d..0c2adf2378fe03e8f3c1347ebcb71e3aae54f1a1 100644 |
--- a/pkg/compiler/lib/src/library_loader.dart |
+++ b/pkg/compiler/lib/src/library_loader.dart |
@@ -5,6 +5,17 @@ |
library dart2js.library_loader; |
import 'dart:async'; |
+import 'dart:io' show Platform; |
+ |
+import 'package:front_end/front_end.dart' as fe; |
+import 'package:kernel/ast.dart' as ir; |
+import 'package:kernel/binary/ast_from_binary.dart' show BinaryBuilder; |
+import 'package:kernel/kernel.dart' hide LibraryDependency, Combinator; |
+import 'package:kernel/target/targets.dart'; |
+ |
+import '../compiler_new.dart' as api; |
+import 'kernel/front_end_adapter.dart'; |
+import 'kernel/dart2js_target.dart' show Dart2jsTarget; |
import 'common/names.dart' show Uris; |
import 'common/tasks.dart' show CompilerTask, Measurer; |
@@ -39,9 +50,6 @@ import 'serialization/serialization.dart' show LibraryDeserializer; |
import 'tree/tree.dart'; |
import 'util/util.dart' show Link, LinkBuilder; |
-import 'package:kernel/ast.dart' as ir; |
-import 'package:kernel/binary/ast_from_binary.dart' show BinaryBuilder; |
- |
typedef Future<Iterable<LibraryElement>> ReuseLibrariesFunction( |
Iterable<LibraryElement> libraries); |
@@ -807,17 +815,18 @@ class ResolutionLibraryLoaderTask extends CompilerTask |
} |
} |
-/// A task for loading a pre-processed .dill file into memory rather than |
-/// parsing Dart source. Use of this task only makes sense when used in |
-/// conjunction with --use-kernel. |
-class DillLibraryLoaderTask extends CompilerTask implements LibraryLoaderTask { |
+/// A loader that builds a kernel IR representation of the program (or set of |
+/// libraries). |
+/// |
+/// It supports loading both .dart source files or pre-compiled .dill files. |
+/// When given .dart source files, it invokes the shared frontend |
+/// (`package:front_end`) to produce the corresponding kernel IR representation. |
+// TODO(sigmund): move this class to a new file under src/kernel/. |
+class KernelLibraryLoaderTask extends CompilerTask |
+ implements LibraryLoaderTask { |
final DiagnosticReporter reporter; |
- final ResolvedUriTranslator uriTranslator; |
- |
- /// Loads the contents of a script file (a .dart file). Used when loading |
- /// libraries from source. |
- final ScriptLoader scriptLoader; |
+ final api.CompilerInput compilerInput; |
/// Holds the mapping of Kernel IR to KElements that is constructed as a |
/// result of loading a program. |
@@ -825,8 +834,8 @@ class DillLibraryLoaderTask extends CompilerTask implements LibraryLoaderTask { |
List<LibraryEntity> _allLoadedLibraries; |
- DillLibraryLoaderTask(this._elementMap, this.uriTranslator, this.scriptLoader, |
- this.reporter, Measurer measurer) |
+ KernelLibraryLoaderTask( |
+ this._elementMap, this.compilerInput, this.reporter, Measurer measurer) |
: _allLoadedLibraries = new List<LibraryEntity>(), |
super(measurer); |
@@ -836,19 +845,35 @@ class DillLibraryLoaderTask extends CompilerTask implements LibraryLoaderTask { |
// away. |
Future<LoadedLibraries> loadLibrary(Uri resolvedUri, |
{bool skipFileWithPartOfTag: false}) { |
- assert(resolvedUri.pathSegments.last.endsWith('.dill'), |
- 'Invalid uri: $resolvedUri'); |
- Uri readableUri = uriTranslator.translate(null, resolvedUri, null); |
return measure(() async { |
- Binary binary = await scriptLoader.readBinary(readableUri, null); |
- ir.Program program = new ir.Program(); |
- new BinaryBuilder(binary.data).readProgram(program); |
- return measure(() { |
- return createLoadedLibraries(program); |
- }); |
+ var isDill = resolvedUri.path.endsWith('.dill'); |
+ ir.Program program; |
+ if (isDill) { |
+ api.Input input = await compilerInput.readFromUri(resolvedUri, |
+ inputKind: api.InputKind.binary); |
+ program = new ir.Program(); |
+ new BinaryBuilder(input.data).readProgram(program); |
+ } else { |
+ var options = new fe.CompilerOptions() |
+ ..fileSystem = new CompilerFileSystem(compilerInput) |
+ ..target = new Dart2jsTarget(new TargetFlags()) |
+ ..compileSdk = true |
+ ..linkedDependencies = [ |
+ // TODO(sigmund): infer the location of platform.dill |
+ // once it is shipped as part of the sdk. |
+ new Uri.file(Platform.resolvedExecutable) |
+ .resolve('patched_dart2js_sdk/platform.dill') |
+ ] |
+ ..onError = (e) => reportFrontEndMessage(reporter, e); |
+ |
+ program = await fe.kernelForProgram(resolvedUri, options); |
+ } |
+ if (program == null) return null; |
+ return createLoadedLibraries(program); |
}); |
} |
+ // Only visible for unit testing. |
LoadedLibraries createLoadedLibraries(ir.Program program) { |
_elementMap.addProgram(program); |
program.libraries.forEach((ir.Library library) => |
@@ -865,11 +890,11 @@ class DillLibraryLoaderTask extends CompilerTask implements LibraryLoaderTask { |
KernelToElementMapForImpactImpl get elementMap => _elementMap; |
void reset({bool reuseLibrary(LibraryElement library)}) { |
- throw new UnimplementedError('DillLibraryLoaderTask.reset'); |
+ throw new UnimplementedError('KernelLibraryLoaderTask.reset'); |
} |
Future resetAsync(Future<bool> reuseLibrary(LibraryElement library)) { |
- throw new UnimplementedError('DillLibraryLoaderTask.resetAsync'); |
+ throw new UnimplementedError('KernelLibraryLoaderTask.resetAsync'); |
} |
Iterable<LibraryEntity> get libraries => _allLoadedLibraries; |
@@ -879,12 +904,12 @@ class DillLibraryLoaderTask extends CompilerTask implements LibraryLoaderTask { |
} |
Future<Null> resetLibraries(ReuseLibrariesFunction reuseLibraries) { |
- throw new UnimplementedError('DillLibraryLoaderTask.reuseLibraries'); |
+ throw new UnimplementedError('KernelLibraryLoaderTask.reuseLibraries'); |
} |
void registerDeferredAction(DeferredAction action) { |
throw new UnimplementedError( |
- 'DillLibraryLoaderTask.registerDeferredAction'); |
+ 'KernelLibraryLoaderTask.registerDeferredAction'); |
} |
Iterable<DeferredAction> pullDeferredActions() => const <DeferredAction>[]; |