Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Unified Diff: tests/compiler/dart2js/compiler_helper.dart

Issue 1322973007: Use memory compiler in compiler_helper.dart. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Update cf. comments. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/compiler/dart2js/codegen_helper.dart ('k') | tests/compiler/dart2js/dictionary_types_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/compiler/dart2js/compiler_helper.dart
diff --git a/tests/compiler/dart2js/compiler_helper.dart b/tests/compiler/dart2js/compiler_helper.dart
index 9c84a8c23b0b0debd5ec22e810aa0722de5d6f3c..2452af73198cdf503674724575b4d7c8a687ab37 100644
--- a/tests/compiler/dart2js/compiler_helper.dart
+++ b/tests/compiler/dart2js/compiler_helper.dart
@@ -16,6 +16,7 @@ export 'package:compiler/src/elements/elements.dart';
import 'package:compiler/src/js_backend/js_backend.dart'
as js;
+import 'package:compiler/src/commandline_options.dart';
import 'package:compiler/src/common/codegen.dart';
import 'package:compiler/src/common/resolution.dart';
@@ -39,24 +40,35 @@ export 'package:compiler/src/tree/tree.dart';
import 'mock_compiler.dart';
export 'mock_compiler.dart';
+import 'memory_compiler.dart';
+
import 'output_collector.dart';
export 'output_collector.dart';
+/// Compile [code] and returns the code for [entry].
+///
+/// If [check] is provided, it is executed on the code for [entry] before
+/// returning. If [useMock] is `true` the [MockCompiler] is used for
+/// compilation, otherwise the memory compiler is used.
Future<String> compile(String code,
{String entry: 'main',
bool enableTypeAssertions: false,
bool minify: false,
bool analyzeAll: false,
bool disableInlining: true,
- void check(String generated)}) {
- MockCompiler compiler = new MockCompiler.internal(
- enableTypeAssertions: enableTypeAssertions,
- // Type inference does not run when manually
- // compiling a method.
- disableTypeInference: true,
- enableMinification: minify,
- disableInlining: disableInlining);
- return compiler.init().then((_) {
+ bool useMock: false,
+ void check(String generated)}) async {
+ if (useMock) {
+ // TODO(johnniwinther): Remove this when no longer needed by
+ // `arithmetic_simplication_test.dart`.
+ MockCompiler compiler = new MockCompiler.internal(
+ enableTypeAssertions: enableTypeAssertions,
+ // Type inference does not run when manually
+ // compiling a method.
+ disableTypeInference: true,
+ enableMinification: minify,
+ disableInlining: disableInlining);
+ await compiler.init();
compiler.parseScript(code);
lego.Element element = compiler.mainApp.find(entry);
if (element == null) return null;
@@ -75,12 +87,49 @@ Future<String> compile(String code,
compiler.phase = Compiler.PHASE_COMPILING;
work.run(compiler, compiler.enqueuer.codegen);
js.JavaScriptBackend backend = compiler.backend;
- String generated = backend.assembleCode(element);
+ String generated = backend.getGeneratedCode(element);
if (check != null) {
check(generated);
}
return generated;
- });
+ } else {
+ List<String> options = <String>[
+ Flags.disableTypeInference];
+ if (enableTypeAssertions) {
+ options.add(Flags.enableCheckedMode);
+ }
+ if (minify) {
+ options.add(Flags.minify);
+ }
+ if (analyzeAll) {
+ options.add(Flags.analyzeAll);
+ }
+
+ Map<String, String> source;
+ if (entry != 'main') {
+ source = {'main.dart': "$code\n\nmain() => $entry;" };
+ } else {
+ source = {'main.dart': code};
+ }
+
+ CompilationResult result = await runCompiler(
+ memorySourceFiles: source,
+ options: options,
+ beforeRun: (compiler) {
+ if (disableInlining) {
+ compiler.disableInlining = true;
+ }
+ });
+ Expect.isTrue(result.isSuccess);
+ Compiler compiler = result.compiler;
+ lego.Element element = compiler.mainApp.find(entry);
+ js.JavaScriptBackend backend = compiler.backend;
+ String generated = backend.getGeneratedCode(element);
+ if (check != null) {
+ check(generated);
+ }
+ return generated;
+ }
}
// TODO(herhut): Disallow warnings and errors during compilation by default.
@@ -225,8 +274,11 @@ void checkNumberOfMatches(Iterator it, int nb) {
Expect.isFalse(hasNext, "Found more than $nb matches");
}
-Future compileAndMatch(String code, String entry, RegExp regexp) {
- return compile(code, entry: entry, check: (String generated) {
+Future compileAndMatch(String code, String entry, RegExp regexp,
+ {bool useMock: false}) {
+ return compile(code, entry: entry,
+ useMock: useMock,
+ check: (String generated) {
Expect.isTrue(regexp.hasMatch(generated),
'"$generated" does not match /$regexp/');
});
« no previous file with comments | « tests/compiler/dart2js/codegen_helper.dart ('k') | tests/compiler/dart2js/dictionary_types_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698