Files
sdk/pkg/vm/bin/gen_kernel.dart
T
Alexander Markov 170d5578c7 [vm/kernel] Move functionality of Fuchsia's compiler.dart into pkg/vm
This includes:
* Selecting front-end target.
* Support for multi-root virtual file system.
* Not linking platform into resulting kernel file.
* Specifying input as URI (instead of file path) on command line.
* Automatically converting input script URI to package URI.
* Writing ninja dependencies file.
* Writing package-split kernel binaries.

After this change Fuchsia's compiler.dart will become a small wrapper
over pkg/vm, sharing most logic and even most command line options
with pkg/vm gen_kernel tool.

Also, this CL attempts to share some pieces of code between frontend
server and gen_kernel.

In addition, seperate bytecode generation for package-split binaries
is implemented (needed for https://dart-review.googlesource.com/c/sdk/+/85469).

Corresponding Fuchsia CL: https://fuchsia-review.googlesource.com/c/topaz/+/229964

Change-Id: I12d7b2f6401357b3c9df2e31bc736af5a9dc5fd2
Reviewed-on: https://dart-review.googlesource.com/c/85721
Reviewed-by: Alexander Aprelev <aam@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2018-12-04 01:08:03 +00:00

73 lines
2.3 KiB
Dart

// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
import 'dart:io' show exit;
import 'package:args/args.dart' show ArgParser;
import 'package:kernel/text/ast_to_text.dart'
show globalDebuggingNames, NameSystem;
import 'package:kernel/src/tool/batch_util.dart' as batch_util;
import 'package:vm/kernel_front_end.dart'
show
createCompilerArgParser,
runCompiler,
successExitCode,
compileTimeErrorExitCode,
badUsageExitCode;
final ArgParser _argParser = createCompilerArgParser();
final String _usage = '''
Usage: dart pkg/vm/bin/gen_kernel.dart --platform vm_platform_strong.dill [options] input.dart
Compiles Dart sources to a kernel binary file for Dart VM.
Options:
${_argParser.usage}
''';
main(List<String> arguments) async {
if (arguments.isNotEmpty && arguments.last == '--batch') {
await runBatchModeCompiler();
} else {
exit(await compile(arguments));
}
}
Future<int> compile(List<String> arguments) async {
return runCompiler(_argParser.parse(arguments), _usage);
}
Future runBatchModeCompiler() async {
await batch_util.runBatch((List<String> arguments) async {
// TODO(kustermann): Once we know where the new IKG api is and how to use
// it, we should take advantage of it.
//
// Important things to note:
//
// * Our global transformations must never alter the AST structures which
// the statefull IKG generator keeps across compilations.
// => We need to make our own copy.
//
// * We must ensure the stateful IKG generator keeps giving us all the
// compile-time errors, warnings, hints for every compilation and we
// report the compilation result accordingly.
//
final exitCode = await compile(arguments);
// Re-create global NameSystem to avoid accumulating garbage.
globalDebuggingNames = new NameSystem();
switch (exitCode) {
case successExitCode:
return batch_util.CompilerOutcome.Ok;
case compileTimeErrorExitCode:
case badUsageExitCode:
return batch_util.CompilerOutcome.Fail;
default:
throw 'Could not obtain correct exit code from compiler.';
}
});
}