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; | 31 show ChainContext, Result, StdioProcess, Step, TestDescription; |
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 |
35 class Print extends Step<Program, Program, ChainContext> { | 39 class Print extends Step<Program, Program, ChainContext> { |
36 const Print(); | 40 const Print(); |
37 | 41 |
38 String get name => "print"; | 42 String get name => "print"; |
39 | 43 |
40 Future<Result<Program>> run(Program program, _) async { | 44 Future<Result<Program>> run(Program program, _) async { |
41 StringBuffer sb = new StringBuffer(); | 45 StringBuffer sb = new StringBuffer(); |
42 for (Library library in program.libraries) { | 46 for (Library library in program.libraries) { |
43 Printer printer = new Printer(sb); | 47 Printer printer = new Printer(sb); |
44 if (library.importUri.scheme != "dart" && | 48 if (library.importUri.scheme != "dart" && |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 Future<Result<Program>> run(Program program, _) async { | 167 Future<Result<Program>> run(Program program, _) async { |
164 BytesCollector sink = new BytesCollector(); | 168 BytesCollector sink = new BytesCollector(); |
165 new BinaryPrinter(sink).writeProgramFile(program); | 169 new BinaryPrinter(sink).writeProgramFile(program); |
166 program.unbindCanonicalNames(); | 170 program.unbindCanonicalNames(); |
167 Uint8List bytes = sink.collect(); | 171 Uint8List bytes = sink.collect(); |
168 new BinaryBuilder(bytes).readProgram(program); | 172 new BinaryBuilder(bytes).readProgram(program); |
169 return pass(program); | 173 return pass(program); |
170 } | 174 } |
171 } | 175 } |
172 | 176 |
| 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 |
173 class BytesCollector implements Sink<List<int>> { | 211 class BytesCollector implements Sink<List<int>> { |
174 final List<List<int>> lists = <List<int>>[]; | 212 final List<List<int>> lists = <List<int>>[]; |
175 | 213 |
176 int length = 0; | 214 int length = 0; |
177 | 215 |
178 void add(List<int> data) { | 216 void add(List<int> data) { |
179 lists.add(data); | 217 lists.add(data); |
180 length += data.length; | 218 length += data.length; |
181 } | 219 } |
182 | 220 |
(...skipping 20 matching lines...) Expand all Loading... |
203 | 241 |
204 Future openWrite(Uri uri, f(IOSink sink)) async { | 242 Future openWrite(Uri uri, f(IOSink sink)) async { |
205 IOSink sink = new File.fromUri(uri).openWrite(); | 243 IOSink sink = new File.fromUri(uri).openWrite(); |
206 try { | 244 try { |
207 await f(sink); | 245 await f(sink); |
208 } finally { | 246 } finally { |
209 await sink.close(); | 247 await sink.close(); |
210 } | 248 } |
211 print("Wrote $uri"); | 249 print("Wrote $uri"); |
212 } | 250 } |
OLD | NEW |