Index: pkg/front_end/tool/perf.dart |
diff --git a/pkg/front_end/tool/perf.dart b/pkg/front_end/tool/perf.dart |
index 558ee3de50cd2a7cf17ff6493f5263ed6fe25590..d5bc9255b89fce189976f8753f367449782ff283 100644 |
--- a/pkg/front_end/tool/perf.dart |
+++ b/pkg/front_end/tool/perf.dart |
@@ -16,21 +16,24 @@ import 'package:analyzer/file_system/physical_file_system.dart' |
import 'package:analyzer/source/package_map_resolver.dart'; |
import 'package:analyzer/src/context/builder.dart'; |
import 'package:analyzer/src/dart/sdk/sdk.dart' show FolderBasedDartSdk; |
+import 'package:analyzer/src/generated/engine.dart' show AnalysisOptionsImpl; |
import 'package:analyzer/src/generated/parser.dart'; |
import 'package:analyzer/src/generated/source.dart'; |
import 'package:analyzer/src/generated/source_io.dart'; |
+import 'package:analyzer/src/kernel/loader.dart'; |
import 'package:analyzer/src/summary/format.dart'; |
import 'package:analyzer/src/summary/idl.dart'; |
import 'package:analyzer/src/summary/link.dart'; |
import 'package:analyzer/src/summary/summarize_ast.dart'; |
+import 'package:front_end/compilation_error.dart'; |
import 'package:front_end/compiler_options.dart'; |
-import 'package:front_end/kernel_generator.dart'; |
import 'package:front_end/src/scanner/reader.dart'; |
import 'package:front_end/src/scanner/scanner.dart'; |
import 'package:front_end/src/scanner/token.dart'; |
import 'package:kernel/kernel.dart' hide Source; |
import 'package:package_config/discovery.dart'; |
import 'package:path/path.dart' as path; |
+import 'package:source_span/source_span.dart' show SourceSpan; |
main(List<String> args) async { |
// TODO(sigmund): provide sdk folder as well. |
@@ -133,13 +136,82 @@ Future<Program> generateKernel(Uri entryUri, |
} else { |
options.sdkRoot = _sdkUri; |
} |
- Program program = await kernelForProgram(entryUri, options); |
+ Program program = await _kernelForProgramViaDartk(entryUri, options); |
dartkTimer.stop(); |
var suffix = useSdkSummary ? '_sum' : ''; |
report('kernel_gen_e2e${suffix}', dartkTimer.elapsedMicroseconds); |
return program; |
} |
+_kernelForProgramViaDartk(Uri source, CompilerOptions options) async { |
+ var loader = await _createLoader(options, entry: source); |
+ if (options.compileSdk) { |
+ options.additionalLibraries.forEach(loader.loadLibrary); |
+ } |
+ loader.loadProgram(source, compileSdk: options.compileSdk); |
+ _reportErrors(loader.errors, options.onError); |
+ return loader.program; |
+} |
+ |
+/// Create a [DartLoader] using the provided [options]. |
+/// |
+/// If [options] contain no configuration to resolve `.packages`, the [entry] |
+/// file will be used to search for a `.packages` file. |
+Future<DartLoader> _createLoader(CompilerOptions options, |
+ {Program program, Uri entry}) async { |
+ var kernelOptions = _convertOptions(options); |
+ var packages = await createPackages(_uriToPath(options.packagesFileUri), |
+ discoveryPath: entry?.path); |
+ var loader = |
+ new DartLoader(program ?? new Program(), kernelOptions, packages); |
+ var patchPaths = <String, List<String>>{}; |
+ |
+ // TODO(sigmund,paulberry): use ProcessedOptions so that we can resolve the |
+ // URIs correctly even if sdkRoot is inferred and not specified explicitly. |
+ String resolve(Uri patch) => _uriToPath(options.sdkRoot.resolveUri(patch)); |
+ |
+ options.targetPatches.forEach((uri, patches) { |
+ patchPaths['$uri'] = patches.map(resolve).toList(); |
+ }); |
+ AnalysisOptionsImpl analysisOptions = loader.context.analysisOptions; |
+ analysisOptions.patchPaths = patchPaths; |
+ return loader; |
+} |
+ |
+DartOptions _convertOptions(CompilerOptions options) { |
+ return new DartOptions( |
+ strongMode: options.strongMode, |
+ sdk: _uriToPath(options.sdkRoot), |
+ // TODO(sigmund): make it possible to use summaries and still compile the |
+ // sdk sources. |
+ sdkSummary: options.compileSdk ? null : _uriToPath(options.sdkSummary), |
+ packagePath: _uriToPath(options.packagesFileUri), |
+ customUriMappings: options.uriOverride, |
+ declaredVariables: options.declaredVariables); |
+} |
+ |
+String _uriToPath(Uri uri) { |
+ if (uri == null) return null; |
+ if (uri.scheme != 'file') { |
+ throw new StateError('Only file URIs are supported: $uri'); |
+ } |
+ return uri.toFilePath(); |
+} |
+ |
+void _reportErrors(List errors, ErrorHandler onError) { |
+ if (onError == null) return; |
+ for (var error in errors) { |
+ onError(new _DartkError(error)); |
+ } |
+} |
+ |
+class _DartkError implements CompilationError { |
+ String get correction => null; |
+ SourceSpan get span => null; |
+ final String message; |
+ _DartkError(this.message); |
+} |
+ |
/// Generates unlinkmed summaries for all files in [files], and returns them in |
/// an [_UnlinkedSummaries] container. |
_UnlinkedSummaries generateUnlinkedSummaries(Set<Source> files) { |