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 file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library fasta; | 5 library fasta; |
6 | 6 |
7 import 'dart:async' show Future; | 7 import 'dart:async' show Future; |
8 | 8 |
9 import 'dart:convert' show JSON; | 9 import 'dart:convert' show JSON; |
10 | 10 |
11 import 'dart:io' show BytesBuilder, Directory, File, exitCode; | 11 import 'dart:io' show BytesBuilder, Directory, File, exitCode; |
12 | 12 |
13 import 'package:front_end/physical_file_system.dart'; | 13 import 'package:front_end/physical_file_system.dart'; |
14 import 'package:kernel/binary/ast_to_binary.dart' | 14 import 'package:kernel/binary/ast_to_binary.dart' |
15 show LibraryFilteringBinaryPrinter; | 15 show LibraryFilteringBinaryPrinter; |
16 | 16 |
17 import 'package:kernel/kernel.dart' show Program, Library; | 17 import 'package:kernel/kernel.dart' show Library, Program, loadProgramFromBytes; |
18 | 18 |
19 import 'package:kernel/target/targets.dart' show Target, TargetFlags, getTarget; | 19 import 'package:kernel/target/targets.dart' show Target, TargetFlags, getTarget; |
20 | 20 |
21 import 'compiler_command_line.dart' show CompilerCommandLine; | 21 import 'compiler_command_line.dart' show CompilerCommandLine; |
22 | 22 |
23 import 'compiler_context.dart' show CompilerContext; | 23 import 'compiler_context.dart' show CompilerContext; |
24 | 24 |
25 import 'errors.dart' show InputError, formatUnexpected, inputError, reportCrash; | 25 import 'errors.dart' show InputError, formatUnexpected, inputError, reportCrash; |
26 | 26 |
27 import 'kernel/kernel_target.dart' show KernelTarget; | 27 import 'kernel/kernel_target.dart' show KernelTarget; |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 return new CompilationResult.error( | 173 return new CompilationResult.error( |
174 formatUnexpected(patchedSdk, -1, "Patched sdk directory not found.")); | 174 formatUnexpected(patchedSdk, -1, "Patched sdk directory not found.")); |
175 } | 175 } |
176 | 176 |
177 Program program; | 177 Program program; |
178 try { | 178 try { |
179 TranslateUri uriTranslator = | 179 TranslateUri uriTranslator = |
180 await TranslateUri.parse(PhysicalFileSystem.instance, null, packages); | 180 await TranslateUri.parse(PhysicalFileSystem.instance, null, packages); |
181 final Ticker ticker = new Ticker(isVerbose: verbose); | 181 final Ticker ticker = new Ticker(isVerbose: verbose); |
182 final DillTarget dillTarget = new DillTarget(ticker, uriTranslator); | 182 final DillTarget dillTarget = new DillTarget(ticker, uriTranslator); |
183 dillTarget.read(patchedSdk.resolve('platform.dill')); | 183 _appendDillForUri(dillTarget, patchedSdk.resolve('platform.dill')); |
184 final KernelTarget kernelTarget = new KernelTarget( | 184 final KernelTarget kernelTarget = new KernelTarget( |
185 PhysicalFileSystem.instance, dillTarget, uriTranslator, strongMode); | 185 PhysicalFileSystem.instance, dillTarget, uriTranslator, strongMode); |
186 kernelTarget.read(fileName); | 186 kernelTarget.read(fileName); |
187 await dillTarget.writeOutline(null); | 187 await dillTarget.writeOutline(null); |
188 program = await kernelTarget.writeOutline(null); | 188 program = await kernelTarget.writeOutline(null); |
189 program = await kernelTarget.writeProgram(null); | 189 program = await kernelTarget.writeProgram(null); |
190 if (kernelTarget.errors.isNotEmpty) { | 190 if (kernelTarget.errors.isNotEmpty) { |
191 return new CompilationResult.errors(kernelTarget.errors | 191 return new CompilationResult.errors(kernelTarget.errors |
192 .map((err) => err.toString()) | 192 .map((err) => err.toString()) |
193 .toList(growable: false)); | 193 .toList(growable: false)); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 await CompilerCommandLine.withGlobalOptions("", [""], | 243 await CompilerCommandLine.withGlobalOptions("", [""], |
244 (CompilerContext c) async { | 244 (CompilerContext c) async { |
245 c.options.options["--packages"] = packages; | 245 c.options.options["--packages"] = packages; |
246 if (verbose) { | 246 if (verbose) { |
247 c.options.options["--verbose"] = true; | 247 c.options.options["--verbose"] = true; |
248 } | 248 } |
249 | 249 |
250 TranslateUri uriTranslator = await TranslateUri.parse( | 250 TranslateUri uriTranslator = await TranslateUri.parse( |
251 c.fileSystem, c.options.sdk, c.options.packages); | 251 c.fileSystem, c.options.sdk, c.options.packages); |
252 ticker.logMs("Read packages file"); | 252 ticker.logMs("Read packages file"); |
253 DillTarget dillTarget = new DillTarget(ticker, uriTranslator) | 253 DillTarget dillTarget = new DillTarget(ticker, uriTranslator); |
254 ..read(platform); | 254 _appendDillForUri(dillTarget, platform); |
255 KernelTarget kernelTarget = new KernelTarget(PhysicalFileSystem.instance, | 255 KernelTarget kernelTarget = new KernelTarget(PhysicalFileSystem.instance, |
256 dillTarget, uriTranslator, false, c.uriToSource); | 256 dillTarget, uriTranslator, false, c.uriToSource); |
257 | 257 |
258 kernelTarget.read(script); | 258 kernelTarget.read(script); |
259 await dillTarget.writeOutline(null); | 259 await dillTarget.writeOutline(null); |
260 await kernelTarget.loader.buildOutlines(); | 260 await kernelTarget.loader.buildOutlines(); |
261 await kernelTarget.writeDepsFile(output, depsFile, | 261 await kernelTarget.writeDepsFile(output, depsFile, |
262 extraDependencies: extraDependencies); | 262 extraDependencies: extraDependencies); |
263 }); | 263 }); |
264 } | 264 } |
265 | 265 |
| 266 /// Load the [Program] from the given [uri] and append its libraries |
| 267 /// to the [dillTarget]. |
| 268 void _appendDillForUri(DillTarget dillTarget, Uri uri) { |
| 269 var bytes = new File.fromUri(uri).readAsBytesSync(); |
| 270 var platformProgram = loadProgramFromBytes(bytes); |
| 271 dillTarget.loader.appendLibraries(platformProgram); |
| 272 } |
| 273 |
266 // TODO(ahe): https://github.com/dart-lang/sdk/issues/28316 | 274 // TODO(ahe): https://github.com/dart-lang/sdk/issues/28316 |
267 class ByteSink implements Sink<List<int>> { | 275 class ByteSink implements Sink<List<int>> { |
268 final BytesBuilder builder = new BytesBuilder(); | 276 final BytesBuilder builder = new BytesBuilder(); |
269 | 277 |
270 void add(List<int> data) { | 278 void add(List<int> data) { |
271 builder.add(data); | 279 builder.add(data); |
272 } | 280 } |
273 | 281 |
274 void close() { | 282 void close() { |
275 // Nothing to do. | 283 // Nothing to do. |
276 } | 284 } |
277 } | 285 } |
OLD | NEW |