| 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/file_system.dart'; | 13 import 'package:front_end/file_system.dart'; |
| 14 import 'package:front_end/physical_file_system.dart'; | 14 import 'package:front_end/physical_file_system.dart'; |
| 15 import 'package:front_end/src/fasta/kernel/utils.dart'; | 15 import 'package:front_end/src/fasta/kernel/utils.dart'; |
| 16 import 'package:kernel/binary/ast_to_binary.dart' | 16 import 'package:kernel/binary/ast_to_binary.dart' |
| 17 show LibraryFilteringBinaryPrinter; | 17 show LibraryFilteringBinaryPrinter; |
| 18 | 18 |
| 19 import 'package:kernel/kernel.dart' show Library, Program, loadProgramFromBytes; | 19 import 'package:kernel/kernel.dart' show Library, Program, loadProgramFromBytes; |
| 20 | 20 |
| 21 import 'package:kernel/target/targets.dart' show getTarget, TargetFlags; | 21 import 'package:kernel/target/targets.dart' show Target; |
| 22 | 22 |
| 23 import 'compiler_command_line.dart' show CompilerCommandLine; | 23 import 'compiler_command_line.dart' show CompilerCommandLine; |
| 24 | 24 |
| 25 import 'compiler_context.dart' show CompilerContext; | 25 import 'compiler_context.dart' show CompilerContext; |
| 26 | 26 |
| 27 import 'errors.dart' show InputError, formatUnexpected, inputError, reportCrash; | 27 import 'errors.dart' show InputError, formatUnexpected, inputError, reportCrash; |
| 28 | 28 |
| 29 import 'kernel/kernel_target.dart' show KernelTarget; | 29 import 'kernel/kernel_target.dart' show KernelTarget; |
| 30 | 30 |
| 31 import 'dill/dill_target.dart' show DillTarget; | 31 import 'dill/dill_target.dart' show DillTarget; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 } | 107 } |
| 108 } | 108 } |
| 109 | 109 |
| 110 class CompileTask { | 110 class CompileTask { |
| 111 final CompilerContext c; | 111 final CompilerContext c; |
| 112 final Ticker ticker; | 112 final Ticker ticker; |
| 113 | 113 |
| 114 CompileTask(this.c, this.ticker); | 114 CompileTask(this.c, this.ticker); |
| 115 | 115 |
| 116 DillTarget createDillTarget(TranslateUri uriTranslator) { | 116 DillTarget createDillTarget(TranslateUri uriTranslator) { |
| 117 return new DillTarget( | 117 return new DillTarget(ticker, uriTranslator, c.options.target); |
| 118 ticker, | |
| 119 uriTranslator, | |
| 120 getTarget(c.options.target, | |
| 121 new TargetFlags(strongMode: c.options.strongMode))); | |
| 122 } | 118 } |
| 123 | 119 |
| 124 KernelTarget createKernelTarget( | 120 KernelTarget createKernelTarget( |
| 125 DillTarget dillTarget, TranslateUri uriTranslator, bool strongMode) { | 121 DillTarget dillTarget, TranslateUri uriTranslator, bool strongMode) { |
| 126 return new KernelTarget( | 122 return new KernelTarget( |
| 127 c.fileSystem, dillTarget, uriTranslator, c.uriToSource); | 123 c.fileSystem, dillTarget, uriTranslator, c.uriToSource); |
| 128 } | 124 } |
| 129 | 125 |
| 130 Future<KernelTarget> buildOutline([Uri output]) async { | 126 Future<KernelTarget> buildOutline([Uri output]) async { |
| 131 TranslateUri uriTranslator = await TranslateUri | 127 TranslateUri uriTranslator = await TranslateUri |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 if (c.options.dumpIr) { | 165 if (c.options.dumpIr) { |
| 170 printProgramText(program, libraryFilter: kernelTarget.isSourceLibrary); | 166 printProgramText(program, libraryFilter: kernelTarget.isSourceLibrary); |
| 171 } | 167 } |
| 172 await writeProgramToFile(program, uri); | 168 await writeProgramToFile(program, uri); |
| 173 ticker.logMs("Wrote program to ${uri.toFilePath()}"); | 169 ticker.logMs("Wrote program to ${uri.toFilePath()}"); |
| 174 return uri; | 170 return uri; |
| 175 } | 171 } |
| 176 } | 172 } |
| 177 | 173 |
| 178 Future<CompilationResult> parseScript( | 174 Future<CompilationResult> parseScript( |
| 179 Uri fileName, Uri packages, Uri patchedSdk, | 175 Uri fileName, Uri packages, Uri patchedSdk, Target backendTarget, |
| 180 {bool verbose: false, bool strongMode: false}) async { | 176 {bool verbose: false}) async { |
| 181 return parseScriptInFileSystem( | 177 return parseScriptInFileSystem(fileName, PhysicalFileSystem.instance, |
| 182 fileName, PhysicalFileSystem.instance, packages, patchedSdk, | 178 packages, patchedSdk, backendTarget, |
| 183 verbose: verbose, strongMode: strongMode); | 179 verbose: verbose); |
| 184 } | 180 } |
| 185 | 181 |
| 186 Future<CompilationResult> parseScriptInFileSystem( | 182 Future<CompilationResult> parseScriptInFileSystem(Uri fileName, |
| 187 Uri fileName, FileSystem fileSystem, Uri packages, Uri patchedSdk, | 183 FileSystem fileSystem, Uri packages, Uri patchedSdk, Target backendTarget, |
| 188 {bool verbose: false, bool strongMode: false, String backendTarget}) async { | 184 {bool verbose: false}) async { |
| 189 backendTarget ??= "vm_fasta"; | |
| 190 try { | 185 try { |
| 191 if (!await fileSystem.entityForUri(fileName).exists()) { | 186 if (!await fileSystem.entityForUri(fileName).exists()) { |
| 192 return new CompilationResult.error( | 187 return new CompilationResult.error( |
| 193 formatUnexpected(fileName, -1, "No such file.")); | 188 formatUnexpected(fileName, -1, "No such file.")); |
| 194 } | 189 } |
| 195 if (!await new Directory.fromUri(patchedSdk).exists()) { | 190 if (!await new Directory.fromUri(patchedSdk).exists()) { |
| 196 return new CompilationResult.error( | 191 return new CompilationResult.error( |
| 197 formatUnexpected(patchedSdk, -1, "Patched sdk directory not found.")); | 192 formatUnexpected(patchedSdk, -1, "Patched sdk directory not found.")); |
| 198 } | 193 } |
| 199 | 194 |
| 200 Program program; | 195 Program program; |
| 201 try { | 196 try { |
| 202 TranslateUri uriTranslator = | 197 TranslateUri uriTranslator = |
| 203 await TranslateUri.parse(fileSystem, patchedSdk, packages: packages); | 198 await TranslateUri.parse(fileSystem, patchedSdk, packages: packages); |
| 204 final Ticker ticker = new Ticker(isVerbose: verbose); | 199 final Ticker ticker = new Ticker(isVerbose: verbose); |
| 205 final DillTarget dillTarget = new DillTarget(ticker, uriTranslator, | 200 final DillTarget dillTarget = |
| 206 getTarget(backendTarget, new TargetFlags(strongMode: strongMode))); | 201 new DillTarget(ticker, uriTranslator, backendTarget); |
| 207 _appendDillForUri(dillTarget, patchedSdk.resolve('platform.dill')); | 202 _appendDillForUri(dillTarget, patchedSdk.resolve('platform.dill')); |
| 208 final KernelTarget kernelTarget = | 203 final KernelTarget kernelTarget = |
| 209 new KernelTarget(fileSystem, dillTarget, uriTranslator); | 204 new KernelTarget(fileSystem, dillTarget, uriTranslator); |
| 210 kernelTarget.read(fileName); | 205 kernelTarget.read(fileName); |
| 211 await dillTarget.buildOutlines(); | 206 await dillTarget.buildOutlines(); |
| 212 await kernelTarget.buildOutlines(); | 207 await kernelTarget.buildOutlines(); |
| 213 program = await kernelTarget.buildProgram(); | 208 program = await kernelTarget.buildProgram(); |
| 214 if (kernelTarget.errors.isNotEmpty) { | 209 if (kernelTarget.errors.isNotEmpty) { |
| 215 return new CompilationResult.errors(kernelTarget.errors); | 210 return new CompilationResult.errors(kernelTarget.errors); |
| 216 } | 211 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 {Uri sdk, | 256 {Uri sdk, |
| 262 Uri packages, | 257 Uri packages, |
| 263 Uri platform, | 258 Uri platform, |
| 264 Iterable<Uri> extraDependencies, | 259 Iterable<Uri> extraDependencies, |
| 265 bool verbose: false, | 260 bool verbose: false, |
| 266 String backendTarget}) async { | 261 String backendTarget}) async { |
| 267 backendTarget ??= "vm_fasta"; | 262 backendTarget ??= "vm_fasta"; |
| 268 Ticker ticker = new Ticker(isVerbose: verbose); | 263 Ticker ticker = new Ticker(isVerbose: verbose); |
| 269 await CompilerCommandLine.withGlobalOptions("", [""], | 264 await CompilerCommandLine.withGlobalOptions("", [""], |
| 270 (CompilerContext c) async { | 265 (CompilerContext c) async { |
| 266 c.options.options["--target"] = backendTarget; |
| 267 c.options.options["--strong-mode"] = false; |
| 271 c.options.options["--packages"] = packages; | 268 c.options.options["--packages"] = packages; |
| 272 if (verbose) { | 269 if (verbose) { |
| 273 c.options.options["--verbose"] = true; | 270 c.options.options["--verbose"] = true; |
| 274 } | 271 } |
| 275 sdk ??= c.options.sdk; | 272 sdk ??= c.options.sdk; |
| 276 | 273 |
| 277 TranslateUri uriTranslator = await TranslateUri.parse(c.fileSystem, sdk, | 274 TranslateUri uriTranslator = await TranslateUri.parse(c.fileSystem, sdk, |
| 278 packages: c.options.packages); | 275 packages: c.options.packages); |
| 279 ticker.logMs("Read packages file"); | 276 ticker.logMs("Read packages file"); |
| 280 DillTarget dillTarget = new DillTarget(ticker, uriTranslator, | 277 DillTarget dillTarget = |
| 281 getTarget(backendTarget, new TargetFlags(strongMode: false))); | 278 new DillTarget(ticker, uriTranslator, c.options.target); |
| 282 _appendDillForUri(dillTarget, platform); | 279 _appendDillForUri(dillTarget, platform); |
| 283 KernelTarget kernelTarget = new KernelTarget( | 280 KernelTarget kernelTarget = new KernelTarget( |
| 284 PhysicalFileSystem.instance, dillTarget, uriTranslator, c.uriToSource); | 281 PhysicalFileSystem.instance, dillTarget, uriTranslator, c.uriToSource); |
| 285 | 282 |
| 286 kernelTarget.read(script); | 283 kernelTarget.read(script); |
| 287 await dillTarget.buildOutlines(); | 284 await dillTarget.buildOutlines(); |
| 288 await kernelTarget.loader.buildOutlines(); | 285 await kernelTarget.loader.buildOutlines(); |
| 289 await kernelTarget.writeDepsFile(output, depsFile, | 286 await kernelTarget.writeDepsFile(output, depsFile, |
| 290 extraDependencies: extraDependencies); | 287 extraDependencies: extraDependencies); |
| 291 }); | 288 }); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 305 final BytesBuilder builder = new BytesBuilder(); | 302 final BytesBuilder builder = new BytesBuilder(); |
| 306 | 303 |
| 307 void add(List<int> data) { | 304 void add(List<int> data) { |
| 308 builder.add(data); | 305 builder.add(data); |
| 309 } | 306 } |
| 310 | 307 |
| 311 void close() { | 308 void close() { |
| 312 // Nothing to do. | 309 // Nothing to do. |
| 313 } | 310 } |
| 314 } | 311 } |
| OLD | NEW |