Files
sdk/pkg/vm/bin/gen_kernel.dart
T
Ryan Macnak ab4f9351b1 Rename vm_platform_strong.dill to vm_platform.dill.
The name has always been annoying because it did not add strong typing. And now there aren't variants of the VM platform to distinguish.

Leave a copy at the old name to not immediately break illegal uses.

TEST=ci
Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,flutter-frontend-try,flutter-linux-try
Change-Id: Ie76fa7f16940aa1ba8d582eb5197f0ae55dc8938
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/429828
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-06-16 18:33:38 -07: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' as io;
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.dill [options] input.dart
Compiles Dart sources to a kernel binary file for Dart VM.
Options:
${_argParser.usage}
''';
void main(List<String> arguments) async {
if (arguments.isNotEmpty && arguments.last == '--batch') {
await runBatchModeCompiler();
} else {
io.exitCode = 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 stateful 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.';
}
});
}