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

Side by Side Diff: tests/compiler/dart2js/kernel/helper.dart

Issue 2997413002: Support --use-kernel in memory_compiler (Closed)
Patch Set: Remove hack in source_loader Created 3 years, 4 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:async'; 5 import 'dart:async';
6 6
7 import 'package:compiler/src/common_elements.dart';
7 import 'package:compiler/src/compiler.dart' show Compiler; 8 import 'package:compiler/src/compiler.dart' show Compiler;
8 import 'package:compiler/src/elements/elements.dart' 9 import 'package:compiler/src/elements/entities.dart';
9 show Element, LibraryElement;
10 import 'package:compiler/src/js_backend/backend.dart' as js 10 import 'package:compiler/src/js_backend/backend.dart' as js
11 show JavaScriptBackend; 11 show JavaScriptBackend;
12 import 'package:compiler/src/commandline_options.dart' show Flags; 12 import 'package:compiler/src/commandline_options.dart' show Flags;
13 import 'package:test/test.dart'; 13 import 'package:test/test.dart';
14 14
15 import '../memory_compiler.dart'; 15 import '../memory_compiler.dart';
16 16
17 Future<String> compile(String code, 17 Future<String> compile(String code,
18 {dynamic lookup: 'main', 18 {dynamic lookup: 'main',
19 bool useKernelInSsa: true, 19 bool useKernel: false,
20 bool useKernelInSsa: false,
20 bool disableTypeInference: true, 21 bool disableTypeInference: true,
21 List<String> extraOptions: const <String>[]}) async { 22 List<String> extraOptions: const <String>[]}) async {
22 List<String> options = <String>[ 23 List<String> options = <String>[
23 Flags.disableInlining, 24 Flags.disableInlining,
24 ]; 25 ];
25 if (disableTypeInference) options.add(Flags.disableTypeInference); 26 if (disableTypeInference) options.add(Flags.disableTypeInference);
27 if (useKernel) options.add(Flags.useKernel);
26 if (useKernelInSsa) options.add(Flags.useKernelInSsa); 28 if (useKernelInSsa) options.add(Flags.useKernelInSsa);
27 options.addAll(extraOptions); 29 options.addAll(extraOptions);
28 30
29 if (lookup is String && lookup != 'main' && !code.contains('main')) { 31 if (lookup is String && lookup != 'main' && !code.contains('main')) {
30 code = "$code\n\nmain() => $lookup;"; 32 code = "$code\n\nmain() => $lookup;";
31 } 33 }
32 CompilationResult result = await runCompiler( 34 CompilationResult result = await runCompiler(
33 memorySourceFiles: {'main.dart': code}, options: options); 35 memorySourceFiles: {'main.dart': code}, options: options);
34 expect(result.isSuccess, isTrue); 36 expect(result.isSuccess, isTrue);
35 Compiler compiler = result.compiler; 37 Compiler compiler = result.compiler;
36 LibraryElement mainApp = 38 ElementEnvironment elementEnvironment =
37 compiler.frontendStrategy.elementEnvironment.mainLibrary; 39 compiler.backendClosedWorldForTesting.elementEnvironment;
38 Element element; 40 MemberEntity element;
39 if (lookup is String) { 41 if (lookup is String) {
40 element = mainApp.find(lookup); 42 LibraryEntity mainLibrary = elementEnvironment.mainLibrary;
43 element = elementEnvironment.lookupLibraryMember(mainLibrary, lookup);
41 } else { 44 } else {
42 element = lookup(compiler); 45 element = lookup(compiler);
43 } 46 }
44 js.JavaScriptBackend backend = compiler.backend; 47 js.JavaScriptBackend backend = compiler.backend;
45 return backend.getGeneratedCode(element); 48 return backend.getGeneratedCode(element);
46 } 49 }
47 50
48 /// Checks that the given Dart [code] compiles to the same JS in kernel and 51 /// Checks that the given Dart [code] compiles to the same JS in kernel and
49 /// normal mode. 52 /// normal mode.
50 /// 53 ///
51 /// The function to check at the end is given by [lookup]. If [lookup] is a 54 /// The function to check at the end is given by [lookup]. If [lookup] is a
52 /// String, then the generated code for a top-level element named [lookup] is 55 /// String, then the generated code for a top-level element named [lookup] is
53 /// checked. Otherwise, [lookup] is a function that takes a [Compiler] and 56 /// checked. Otherwise, [lookup] is a function that takes a [Compiler] and
54 /// returns an [Element], and the returned [Element] is checked. 57 /// returns an [MemberEntity], and the returned [MemberEntity] is checked.
55 Future check(String code, 58 Future check(String code,
56 {dynamic lookup: 'main', 59 {dynamic lookup: 'main',
57 bool disableTypeInference: true, 60 bool disableTypeInference: true,
58 List<String> extraOptions: const <String>[]}) async { 61 List<String> extraOptions: const <String>[],
62 // TODO(redemption): Remove the need for this.
63 bool useKernelInSsa: false}) async {
59 var original = await compile(code, 64 var original = await compile(code,
60 lookup: lookup, 65 lookup: lookup,
61 useKernelInSsa: false, 66 useKernelInSsa: false,
62 disableTypeInference: disableTypeInference, 67 disableTypeInference: disableTypeInference,
63 extraOptions: extraOptions); 68 extraOptions: extraOptions);
64 var kernel = await compile(code, 69 var kernel = await compile(code,
65 lookup: lookup, 70 lookup: lookup,
66 useKernelInSsa: true, 71 useKernel: !useKernelInSsa,
72 useKernelInSsa: useKernelInSsa,
67 disableTypeInference: disableTypeInference, 73 disableTypeInference: disableTypeInference,
68 extraOptions: extraOptions); 74 extraOptions: extraOptions);
69 expect(kernel, original); 75 expect(kernel, original);
70 } 76 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/kernel/getters_setters_test.dart ('k') | tests/compiler/dart2js/kernel/literals_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698