f6af8ccba8
As number of bytecode generation options grows, it becomes cumbersome to add them and propagate from the place where they are parsed to the place where they are used. In order to make it easier to change and add new bytecode generation options, this CL introduces BytecodeOptions class which consolidates all options for bytecode generation. Also, command line options --emit-bytecode-*** are gathered into a single multi-option --bytecode-options=opt1,opt2,... Also, unused --use-future-bytecode-format option is cleaned up. If needed, it could be easily re-introduced in the new BytecodeOptions. Change-Id: I637bf28ceb4233ead2562afe7ad51c69a99f2d60 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/106965 Reviewed-by: Ryan Macnak <rmacnak@google.com> Commit-Queue: Alexander Markov <alexmarkov@google.com>
64 lines
2.2 KiB
Dart
64 lines
2.2 KiB
Dart
// Copyright (c) 2018, 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:io';
|
|
|
|
import 'package:front_end/src/api_unstable/vm.dart'
|
|
show CompilerOptions, DiagnosticMessage;
|
|
import 'package:kernel/ast.dart';
|
|
import 'package:kernel/kernel.dart';
|
|
import 'package:test/test.dart';
|
|
import 'package:vm/bytecode/gen_bytecode.dart' show generateBytecode;
|
|
import 'package:vm/bytecode/options.dart' show BytecodeOptions;
|
|
import 'package:vm/kernel_front_end.dart' show runWithFrontEndCompilerContext;
|
|
|
|
import '../common_test_utils.dart';
|
|
|
|
final String pkgVmDir = Platform.script.resolve('../..').toFilePath();
|
|
|
|
runTestCase(Uri source) async {
|
|
// Certain tests require super-mixin semantics which is used in Flutter.
|
|
bool enableSuperMixins = source.pathSegments.last == 'super_calls.dart';
|
|
|
|
Component component = await compileTestCaseToKernelProgram(source,
|
|
enableSuperMixins: enableSuperMixins);
|
|
|
|
final options = new CompilerOptions()
|
|
..onDiagnostic = (DiagnosticMessage message) {
|
|
fail("Compilation error: ${message.plainTextFormatted.join('\n')}");
|
|
};
|
|
|
|
final mainLibrary = component.mainMethod.enclosingLibrary;
|
|
|
|
await runWithFrontEndCompilerContext(source, options, component, () {
|
|
// Need to omit source positions from bytecode as they are different on
|
|
// Linux and Windows (due to differences in newline characters).
|
|
generateBytecode(component,
|
|
options: new BytecodeOptions(
|
|
enableAsserts: true, omitAssertSourcePositions: true),
|
|
libraries: [mainLibrary]);
|
|
});
|
|
|
|
component.libraries.removeWhere((lib) => lib != mainLibrary);
|
|
String actual = kernelComponentToString(component);
|
|
|
|
// Remove absolute library URIs.
|
|
actual = actual.replaceAll(new Uri.file(pkgVmDir).toString(), '#pkg/vm');
|
|
|
|
compareResultWithExpectationsFile(source, actual);
|
|
}
|
|
|
|
main() {
|
|
group('gen-bytecode', () {
|
|
final testCasesDir = new Directory(pkgVmDir + '/testcases/bytecode');
|
|
|
|
for (var entry
|
|
in testCasesDir.listSync(recursive: true, followLinks: false)) {
|
|
if (entry.path.endsWith(".dart")) {
|
|
test(entry.path, () => runTestCase(entry.uri));
|
|
}
|
|
}
|
|
});
|
|
}
|