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

Side by Side Diff: pkg/front_end/lib/src/fasta/testing/kernel_chain.dart

Issue 2982093003: Unifying compiler context (Closed)
Patch Set: revert change to kernel-service.dart Created 3 years, 5 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.md file. 3 // BSD-style license that can be found in the LICENSE.md file.
4 4
5 // TODO(ahe): Copied from closure_conversion branch of kernel, remove this file 5 // TODO(ahe): Copied from closure_conversion branch of kernel, remove this file
6 // when closure_conversion is merged with master. 6 // when closure_conversion is merged with master.
7 7
8 library fasta.testing.kernel_chain; 8 library fasta.testing.kernel_chain;
9 9
10 import 'dart:async' show Future; 10 import 'dart:async' show Future;
11 11
12 import 'dart:io' show Directory, File, IOSink; 12 import 'dart:io' show Directory, File, IOSink;
13 13
14 import 'dart:typed_data' show Uint8List; 14 import 'dart:typed_data' show Uint8List;
15 15
16 import 'package:kernel/kernel.dart' show loadProgramFromBinary; 16 import 'package:kernel/kernel.dart' show loadProgramFromBinary;
17 17
18 import 'package:kernel/target/targets.dart' show Target; 18 import 'package:kernel/target/targets.dart' show Target;
19 19
20 import 'package:kernel/text/ast_to_text.dart' show Printer; 20 import 'package:kernel/text/ast_to_text.dart' show Printer;
21 21
22 import 'package:testing/testing.dart' show Result, StdioProcess, Step; 22 import 'package:testing/testing.dart' show Result, StdioProcess, Step;
23 23
24 import 'package:kernel/ast.dart' show Library, Program; 24 import 'package:kernel/ast.dart' show Library, Program;
25 25
26 import '../kernel/verifier.dart' show verifyProgram; 26 import '../kernel/verifier.dart' show verifyProgram;
27 27
28 import '../compiler_command_line.dart'; 28 import '../compiler_context.dart';
29 29
30 import 'package:kernel/binary/ast_to_binary.dart' show BinaryPrinter; 30 import 'package:kernel/binary/ast_to_binary.dart' show BinaryPrinter;
31 31
32 import 'package:kernel/binary/ast_from_binary.dart' show BinaryBuilder; 32 import 'package:kernel/binary/ast_from_binary.dart' show BinaryBuilder;
33 33
34 import 'package:testing/testing.dart' 34 import 'package:testing/testing.dart'
35 show ChainContext, Result, StdioProcess, Step, TestDescription; 35 show ChainContext, Result, StdioProcess, Step, TestDescription;
36 36
37 import 'package:kernel/ast.dart' show Program; 37 import 'package:kernel/ast.dart' show Program;
38 38
39 import 'package:front_end/front_end.dart'; 39 import 'package:front_end/front_end.dart';
40 40
41 import 'package:front_end/src/base/processed_options.dart'
42 show ProcessedOptions;
43
41 import 'patched_sdk_location.dart' show computePatchedSdk; 44 import 'patched_sdk_location.dart' show computePatchedSdk;
42 45
43 class Print extends Step<Program, Program, ChainContext> { 46 class Print extends Step<Program, Program, ChainContext> {
44 const Print(); 47 const Print();
45 48
46 String get name => "print"; 49 String get name => "print";
47 50
48 Future<Result<Program>> run(Program program, _) async { 51 Future<Result<Program>> run(Program program, _) async {
49 StringBuffer sb = new StringBuffer(); 52 StringBuffer sb = new StringBuffer();
50 for (Library library in program.libraries) { 53 for (Library library in program.libraries) {
51 Printer printer = new Printer(sb); 54 Printer printer = new Printer(sb);
52 if (library.importUri.scheme != "dart" && 55 if (library.importUri.scheme != "dart" &&
53 library.importUri.scheme != "package") { 56 library.importUri.scheme != "package") {
54 printer.writeLibraryFile(library); 57 printer.writeLibraryFile(library);
55 } 58 }
56 } 59 }
57 print("$sb"); 60 print("$sb");
58 return pass(program); 61 return pass(program);
59 } 62 }
60 } 63 }
61 64
62 class Verify extends Step<Program, Program, ChainContext> { 65 class Verify extends Step<Program, Program, ChainContext> {
63 final bool fullCompile; 66 final bool fullCompile;
64 67
65 const Verify(this.fullCompile); 68 const Verify(this.fullCompile);
66 69
67 String get name => "verify"; 70 String get name => "verify";
68 71
69 Future<Result<Program>> run(Program program, ChainContext context) async { 72 Future<Result<Program>> run(Program program, ChainContext context) async {
70 return await CompilerCommandLine.withGlobalOptions("", [""], (_) async { 73 var options =
74 new ProcessedOptions(new CompilerOptions()..throwOnErrors = false);
75 return await CompilerContext.runWithOptions(options, (_) async {
71 var errors = verifyProgram(program, isOutline: !fullCompile); 76 var errors = verifyProgram(program, isOutline: !fullCompile);
72 if (errors.isEmpty) { 77 if (errors.isEmpty) {
73 return pass(program); 78 return pass(program);
74 } else { 79 } else {
75 return new Result<Program>( 80 return new Result<Program>(
76 null, context.expectationSet["VerificationError"], errors, null); 81 null, context.expectationSet["VerificationError"], errors, null);
77 } 82 }
78 }); 83 });
79 } 84 }
80 } 85 }
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 /// Most options are hard-coded, but if necessary they could be moved to the 189 /// Most options are hard-coded, but if necessary they could be moved to the
185 /// [CompileContext] object in the future. 190 /// [CompileContext] object in the future.
186 class Compile extends Step<TestDescription, Program, CompileContext> { 191 class Compile extends Step<TestDescription, Program, CompileContext> {
187 const Compile(); 192 const Compile();
188 193
189 String get name => "fasta compilation"; 194 String get name => "fasta compilation";
190 195
191 Future<Result<Program>> run( 196 Future<Result<Program>> run(
192 TestDescription description, CompileContext context) async { 197 TestDescription description, CompileContext context) async {
193 Result<Program> result; 198 Result<Program> result;
194 reportError(CompilationError error) { 199 reportError(CompilationMessage error) {
195 result ??= fail(null, error.message); 200 result ??= fail(null, error.message);
196 } 201 }
197 202
198 Uri sdk = await computePatchedSdk(); 203 Uri sdk = await computePatchedSdk();
199 var options = new CompilerOptions() 204 var options = new CompilerOptions()
200 ..sdkRoot = sdk 205 ..sdkRoot = sdk
201 ..compileSdk = true 206 ..compileSdk = true
202 ..packagesFileUri = Uri.base.resolve('.packages') 207 ..packagesFileUri = Uri.base.resolve('.packages')
203 ..strongMode = context.strongMode 208 ..strongMode = context.strongMode
204 ..onError = reportError; 209 ..onError = reportError;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 258
254 Future openWrite(Uri uri, f(IOSink sink)) async { 259 Future openWrite(Uri uri, f(IOSink sink)) async {
255 IOSink sink = new File.fromUri(uri).openWrite(); 260 IOSink sink = new File.fromUri(uri).openWrite();
256 try { 261 try {
257 await f(sink); 262 await f(sink);
258 } finally { 263 } finally {
259 await sink.close(); 264 await sink.close();
260 } 265 }
261 print("Wrote $uri"); 266 print("Wrote $uri");
262 } 267 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698