ff99a0ce59
This is the result of: - taking the diff of the branch closure_conversion to master in the kernel repository - updating the file paths - applying the diff to the Dart SDK - fixing conflicts between the changes to pkg/kernel in the Dart SDK and the master branch in the kernel repository R=asgerf@google.com Review-Url: https://codereview.chromium.org/2561723003 .
101 lines
3.0 KiB
Dart
Executable File
101 lines
3.0 KiB
Dart
Executable File
#!/usr/bin/env dart
|
|
// Copyright (c) 2016, 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';
|
|
|
|
import 'package:args/args.dart';
|
|
import 'package:kernel/verifier.dart';
|
|
import 'package:kernel/kernel.dart';
|
|
import 'package:kernel/transformations/continuation.dart' as cont;
|
|
import 'package:kernel/transformations/infer_values.dart' as infer_values;
|
|
import 'package:kernel/transformations/mixin_full_resolution.dart' as mix;
|
|
import 'package:kernel/transformations/closure_conversion.dart' as closures;
|
|
import 'package:kernel/transformations/treeshaker.dart' as treeshaker;
|
|
|
|
import 'batch_util.dart';
|
|
|
|
ArgParser parser = new ArgParser()
|
|
..addOption('format',
|
|
abbr: 'f',
|
|
allowed: ['text', 'bin'],
|
|
defaultsTo: 'bin',
|
|
help: 'Output format.')
|
|
..addOption('out', abbr: 'o', help: 'Output file.', defaultsTo: null)
|
|
..addFlag('verbose',
|
|
abbr: 'v',
|
|
negatable: false,
|
|
help: 'Be verbose (e.g. prints transformed main library).',
|
|
defaultsTo: false)
|
|
..addOption('transformation',
|
|
abbr: 't',
|
|
help: 'The transformation to apply.',
|
|
defaultsTo: 'continuation');
|
|
|
|
main(List<String> arguments) async {
|
|
if (arguments.isNotEmpty && arguments[0] == '--batch') {
|
|
if (arguments.length != 1) {
|
|
throw '--batch cannot be used with other arguments';
|
|
}
|
|
await runBatch((arguments) => runTransformation(arguments));
|
|
} else {
|
|
CompilerOutcome outcome = await runTransformation(arguments);
|
|
exit(outcome == CompilerOutcome.Ok ? 0 : 1);
|
|
}
|
|
}
|
|
|
|
Future<CompilerOutcome> runTransformation(List<String> arguments) async {
|
|
ArgResults options = parser.parse(arguments);
|
|
|
|
if (options.rest.length != 1) {
|
|
throw 'Usage:\n${parser.usage}';
|
|
}
|
|
|
|
var input = options.rest.first;
|
|
var output = options['out'];
|
|
var format = options['format'];
|
|
var verbose = options['verbose'];
|
|
|
|
if (output == null) {
|
|
output = '${input.substring(0, input.lastIndexOf('.'))}.transformed.dill';
|
|
}
|
|
|
|
var program = loadProgramFromBinary(input);
|
|
switch (options['transformation']) {
|
|
case 'continuation':
|
|
program = cont.transformProgram(program);
|
|
break;
|
|
case 'infervalues':
|
|
program = infer_values.transformProgram(program);
|
|
break;
|
|
case 'resolve-mixins':
|
|
program = mix.transformProgram(program);
|
|
break;
|
|
case 'closures':
|
|
program = closures.transformProgram(program);
|
|
break;
|
|
case 'treeshake':
|
|
program = treeshaker.transformProgram(program);
|
|
break;
|
|
default:
|
|
throw 'Unknown transformation';
|
|
}
|
|
|
|
verifyProgram(program);
|
|
|
|
if (format == 'text') {
|
|
writeProgramToText(program, path: output);
|
|
} else {
|
|
assert(format == 'bin');
|
|
await writeProgramToBinary(program, output);
|
|
}
|
|
|
|
if (verbose) {
|
|
writeLibraryToText(program.mainMethod.parent as Library);
|
|
}
|
|
|
|
return CompilerOutcome.Ok;
|
|
}
|