Chromium Code Reviews| Index: pkg/front_end/lib/src/fasta/outline.dart |
| diff --git a/pkg/front_end/lib/src/fasta/outline.dart b/pkg/front_end/lib/src/fasta/outline.dart |
| index 08b924bea0e4c155c4d1423aaa4bf9db0afba22e..003b68ecdbe5eede78a644a73225275864e75c60 100644 |
| --- a/pkg/front_end/lib/src/fasta/outline.dart |
| +++ b/pkg/front_end/lib/src/fasta/outline.dart |
| @@ -8,7 +8,15 @@ import 'dart:async' show Future; |
| import 'dart:convert' show JSON; |
| -import 'dart:io' show exitCode; |
| +import 'dart:io' show BytesBuilder, FileSystemEntity, exitCode; |
| + |
| +import 'package:kernel/binary/ast_to_binary.dart' show BinaryPrinter; |
| + |
| +import 'package:kernel/kernel.dart' show Program; |
| + |
| +import 'package:kernel/target/targets.dart' show Target, TargetFlags, getTarget; |
| + |
| +import '../vm.dart' show CompilationResult; |
| import 'kernel/verifier.dart' show verifyProgram; |
| @@ -155,3 +163,58 @@ class CompileTask { |
| return uri; |
| } |
| } |
| + |
| +Future<CompilationResult> parseScript( |
| + Uri fileName, Uri packages, Uri patchedSdk, bool verbose) async { |
| + if (!FileSystemEntity.isFileSync(fileName.toFilePath())) { |
| + throw "Input file '${fileName.toFilePath()}' does not exist."; |
| + } |
| + |
| + if (!FileSystemEntity.isDirectorySync(patchedSdk.toFilePath())) { |
| + throw "Patched sdk directory not found at ${patchedSdk.toFilePath()}"; |
| + } |
| + |
| + Target target = getTarget("vm", new TargetFlags(strongMode: false)); |
| + |
| + Program program; |
| + final uriTranslator = await TranslateUri.parse(null, packages); |
| + final Ticker ticker = new Ticker(isVerbose: verbose); |
| + final DillTarget dillTarget = new DillTarget(ticker, uriTranslator); |
| + dillTarget.read(patchedSdk.resolve('platform.dill')); |
| + final KernelTarget kernelTarget = new KernelTarget(dillTarget, uriTranslator); |
| + try { |
| + kernelTarget.read(fileName); |
| + await dillTarget.writeOutline(null); |
| + program = await kernelTarget.writeOutline(null); |
| + program = await kernelTarget.writeProgram(null); |
| + if (kernelTarget.errors.isNotEmpty) { |
| + return new CompilationResult.error(kernelTarget.errors |
| + .map((err) => err.toString()) |
| + .toList(growable: false)); |
| + } |
| + } on InputError catch (e) { |
| + return new CompilationResult.error(<String>[e.format()]); |
| + } |
| + |
| + // Perform target-specific transformations. |
| + target.performModularTransformations(program); |
| + target.performGlobalTransformations(program); |
| + |
| + // Write the program to a list of bytes and return it. |
| + var sink = new ByteSink(); |
| + new BinaryPrinter(sink).writeProgramFile(program); |
| + return new CompilationResult.ok(sink.builder.takeBytes()); |
| +} |
| + |
| +// TODO(ahe): https://github.com/dart-lang/sdk/issues/29027 |
|
Vyacheslav Egorov (Google)
2017/03/10 09:58:15
I have filed this issue before as #28316
ahe
2017/03/10 12:05:49
Done.
|
| +class ByteSink implements Sink<List<int>> { |
| + final BytesBuilder builder = new BytesBuilder(); |
| + |
| + void add(List<int> data) { |
| + builder.add(data); |
| + } |
| + |
| + void close() { |
| + // Nothing to do. |
| + } |
| +} |