OLD | NEW |
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; |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 import 'package:kernel/ast.dart' show Library, Program; | 22 import 'package:kernel/ast.dart' show Library, Program; |
23 | 23 |
24 import '../kernel/verifier.dart' show verifyProgram; | 24 import '../kernel/verifier.dart' show verifyProgram; |
25 | 25 |
26 import 'package:kernel/binary/ast_to_binary.dart' show BinaryPrinter; | 26 import 'package:kernel/binary/ast_to_binary.dart' show BinaryPrinter; |
27 | 27 |
28 import 'package:kernel/binary/ast_from_binary.dart' show BinaryBuilder; | 28 import 'package:kernel/binary/ast_from_binary.dart' show BinaryBuilder; |
29 | 29 |
30 import 'package:testing/testing.dart' | 30 import 'package:testing/testing.dart' |
31 show ChainContext, Result, StdioProcess, Step, TestDescription; | 31 show ChainContext, Result, StdioProcess, Step; |
32 | 32 |
33 import 'package:kernel/ast.dart' show Program; | 33 import 'package:kernel/ast.dart' show Program; |
34 | 34 |
35 import 'package:front_end/front_end.dart'; | |
36 | |
37 import 'patched_sdk_location.dart' show computePatchedSdk; | |
38 | |
39 class Print extends Step<Program, Program, ChainContext> { | 35 class Print extends Step<Program, Program, ChainContext> { |
40 const Print(); | 36 const Print(); |
41 | 37 |
42 String get name => "print"; | 38 String get name => "print"; |
43 | 39 |
44 Future<Result<Program>> run(Program program, _) async { | 40 Future<Result<Program>> run(Program program, _) async { |
45 StringBuffer sb = new StringBuffer(); | 41 StringBuffer sb = new StringBuffer(); |
46 for (Library library in program.libraries) { | 42 for (Library library in program.libraries) { |
47 Printer printer = new Printer(sb); | 43 Printer printer = new Printer(sb); |
48 if (library.importUri.scheme != "dart" && | 44 if (library.importUri.scheme != "dart" && |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 Future<Result<Program>> run(Program program, _) async { | 163 Future<Result<Program>> run(Program program, _) async { |
168 BytesCollector sink = new BytesCollector(); | 164 BytesCollector sink = new BytesCollector(); |
169 new BinaryPrinter(sink).writeProgramFile(program); | 165 new BinaryPrinter(sink).writeProgramFile(program); |
170 program.unbindCanonicalNames(); | 166 program.unbindCanonicalNames(); |
171 Uint8List bytes = sink.collect(); | 167 Uint8List bytes = sink.collect(); |
172 new BinaryBuilder(bytes).readProgram(program); | 168 new BinaryBuilder(bytes).readProgram(program); |
173 return pass(program); | 169 return pass(program); |
174 } | 170 } |
175 } | 171 } |
176 | 172 |
177 /// A `package:testing` step that runs the `package:front_end` compiler to | |
178 /// generate a kernel program for an individual file. | |
179 /// | |
180 /// Most options are hard-coded, but if necessary they could be moved to the | |
181 /// [CompileContext] object in the future. | |
182 class Compile extends Step<TestDescription, Program, CompileContext> { | |
183 const Compile(); | |
184 | |
185 String get name => "fasta compilation"; | |
186 | |
187 Future<Result<Program>> run( | |
188 TestDescription description, CompileContext context) async { | |
189 Result<Program> result; | |
190 reportError(CompilationError error) { | |
191 result ??= fail(null, error.message); | |
192 } | |
193 | |
194 Uri sdk = await computePatchedSdk(); | |
195 Program p = await kernelForProgram( | |
196 description.uri, | |
197 new CompilerOptions() | |
198 ..sdkRoot = sdk | |
199 ..packagesFileUri = Uri.base.resolve('.packages') | |
200 ..strongMode = context.strongMode | |
201 ..linkedDependencies = [sdk.resolve('platform.dill')] | |
202 ..onError = reportError); | |
203 return result ??= pass(p); | |
204 } | |
205 } | |
206 | |
207 abstract class CompileContext implements ChainContext { | |
208 bool get strongMode; | |
209 } | |
210 | |
211 class BytesCollector implements Sink<List<int>> { | 173 class BytesCollector implements Sink<List<int>> { |
212 final List<List<int>> lists = <List<int>>[]; | 174 final List<List<int>> lists = <List<int>>[]; |
213 | 175 |
214 int length = 0; | 176 int length = 0; |
215 | 177 |
216 void add(List<int> data) { | 178 void add(List<int> data) { |
217 lists.add(data); | 179 lists.add(data); |
218 length += data.length; | 180 length += data.length; |
219 } | 181 } |
220 | 182 |
(...skipping 20 matching lines...) Expand all Loading... |
241 | 203 |
242 Future openWrite(Uri uri, f(IOSink sink)) async { | 204 Future openWrite(Uri uri, f(IOSink sink)) async { |
243 IOSink sink = new File.fromUri(uri).openWrite(); | 205 IOSink sink = new File.fromUri(uri).openWrite(); |
244 try { | 206 try { |
245 await f(sink); | 207 await f(sink); |
246 } finally { | 208 } finally { |
247 await sink.close(); | 209 await sink.close(); |
248 } | 210 } |
249 print("Wrote $uri"); | 211 print("Wrote $uri"); |
250 } | 212 } |
OLD | NEW |