| 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 Target; | 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 'deprecated_problems.dart' |
| 28 show |
| 29 deprecated_InputError, |
| 30 deprecated_formatUnexpected, |
| 31 deprecated_inputError, |
| 32 reportCrash; |
| 28 | 33 |
| 29 import 'kernel/kernel_target.dart' show KernelTarget; | 34 import 'kernel/kernel_target.dart' show KernelTarget; |
| 30 | 35 |
| 31 import 'dill/dill_target.dart' show DillTarget; | 36 import 'dill/dill_target.dart' show DillTarget; |
| 32 | 37 |
| 33 import 'compile_platform.dart' show compilePlatformInternal; | 38 import 'compile_platform.dart' show compilePlatformInternal; |
| 34 | 39 |
| 35 import 'ticker.dart' show Ticker; | 40 import 'ticker.dart' show Ticker; |
| 36 | 41 |
| 37 import 'translate_uri.dart' show TranslateUri; | 42 import 'translate_uri.dart' show TranslateUri; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 try { | 80 try { |
| 76 return await CompilerCommandLine.withGlobalOptions("outline", arguments, | 81 return await CompilerCommandLine.withGlobalOptions("outline", arguments, |
| 77 (CompilerContext c) async { | 82 (CompilerContext c) async { |
| 78 if (c.options.verbose) { | 83 if (c.options.verbose) { |
| 79 print("Building outlines for ${arguments.join(' ')}"); | 84 print("Building outlines for ${arguments.join(' ')}"); |
| 80 } | 85 } |
| 81 CompileTask task = | 86 CompileTask task = |
| 82 new CompileTask(c, new Ticker(isVerbose: c.options.verbose)); | 87 new CompileTask(c, new Ticker(isVerbose: c.options.verbose)); |
| 83 return await task.buildOutline(c.options.output); | 88 return await task.buildOutline(c.options.output); |
| 84 }); | 89 }); |
| 85 } on InputError catch (e) { | 90 } on deprecated_InputError catch (e) { |
| 86 exitCode = 1; | 91 exitCode = 1; |
| 87 print(e.format()); | 92 print(e.deprecated_format()); |
| 88 return null; | 93 return null; |
| 89 } | 94 } |
| 90 } | 95 } |
| 91 | 96 |
| 92 Future<Uri> compile(List<String> arguments) async { | 97 Future<Uri> compile(List<String> arguments) async { |
| 93 try { | 98 try { |
| 94 return await CompilerCommandLine.withGlobalOptions("compile", arguments, | 99 return await CompilerCommandLine.withGlobalOptions("compile", arguments, |
| 95 (CompilerContext c) async { | 100 (CompilerContext c) async { |
| 96 if (c.options.verbose) { | 101 if (c.options.verbose) { |
| 97 print("Compiling directly to Kernel: ${arguments.join(' ')}"); | 102 print("Compiling directly to Kernel: ${arguments.join(' ')}"); |
| 98 } | 103 } |
| 99 CompileTask task = | 104 CompileTask task = |
| 100 new CompileTask(c, new Ticker(isVerbose: c.options.verbose)); | 105 new CompileTask(c, new Ticker(isVerbose: c.options.verbose)); |
| 101 return await task.compile(); | 106 return await task.compile(); |
| 102 }); | 107 }); |
| 103 } on InputError catch (e) { | 108 } on deprecated_InputError catch (e) { |
| 104 exitCode = 1; | 109 exitCode = 1; |
| 105 print(e.format()); | 110 print(e.deprecated_format()); |
| 106 return null; | 111 return null; |
| 107 } | 112 } |
| 108 } | 113 } |
| 109 | 114 |
| 110 class CompileTask { | 115 class CompileTask { |
| 111 final CompilerContext c; | 116 final CompilerContext c; |
| 112 final Ticker ticker; | 117 final Ticker ticker; |
| 113 | 118 |
| 114 CompileTask(this.c, this.ticker); | 119 CompileTask(this.c, this.ticker); |
| 115 | 120 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 136 Uri platform = c.options.platform; | 141 Uri platform = c.options.platform; |
| 137 if (platform != null) { | 142 if (platform != null) { |
| 138 _appendDillForUri(dillTarget, platform); | 143 _appendDillForUri(dillTarget, platform); |
| 139 } | 144 } |
| 140 String argument = c.options.arguments.first; | 145 String argument = c.options.arguments.first; |
| 141 Uri uri = Uri.base.resolve(argument); | 146 Uri uri = Uri.base.resolve(argument); |
| 142 String path = uriTranslator.translate(uri)?.path ?? argument; | 147 String path = uriTranslator.translate(uri)?.path ?? argument; |
| 143 if (path.endsWith(".dart")) { | 148 if (path.endsWith(".dart")) { |
| 144 kernelTarget.read(uri); | 149 kernelTarget.read(uri); |
| 145 } else { | 150 } else { |
| 146 inputError(uri, -1, "Unexpected input: $uri"); | 151 deprecated_inputError(uri, -1, "Unexpected input: $uri"); |
| 147 } | 152 } |
| 148 await dillTarget.buildOutlines(); | 153 await dillTarget.buildOutlines(); |
| 149 var outline = await kernelTarget.buildOutlines(); | 154 var outline = await kernelTarget.buildOutlines(); |
| 150 if (c.options.dumpIr && output != null) { | 155 if (c.options.dumpIr && output != null) { |
| 151 printProgramText(outline, libraryFilter: kernelTarget.isSourceLibrary); | 156 printProgramText(outline, libraryFilter: kernelTarget.isSourceLibrary); |
| 152 } | 157 } |
| 153 if (output != null) { | 158 if (output != null) { |
| 154 await writeProgramToFile(outline, output); | 159 await writeProgramToFile(outline, output); |
| 155 ticker.logMs("Wrote outline to ${output.toFilePath()}"); | 160 ticker.logMs("Wrote outline to ${output.toFilePath()}"); |
| 156 } | 161 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 178 packages, patchedSdk, backendTarget, | 183 packages, patchedSdk, backendTarget, |
| 179 verbose: verbose); | 184 verbose: verbose); |
| 180 } | 185 } |
| 181 | 186 |
| 182 Future<CompilationResult> parseScriptInFileSystem(Uri fileName, | 187 Future<CompilationResult> parseScriptInFileSystem(Uri fileName, |
| 183 FileSystem fileSystem, Uri packages, Uri patchedSdk, Target backendTarget, | 188 FileSystem fileSystem, Uri packages, Uri patchedSdk, Target backendTarget, |
| 184 {bool verbose: false}) async { | 189 {bool verbose: false}) async { |
| 185 try { | 190 try { |
| 186 if (!await fileSystem.entityForUri(fileName).exists()) { | 191 if (!await fileSystem.entityForUri(fileName).exists()) { |
| 187 return new CompilationResult.error( | 192 return new CompilationResult.error( |
| 188 formatUnexpected(fileName, -1, "No such file.")); | 193 deprecated_formatUnexpected(fileName, -1, "No such file.")); |
| 189 } | 194 } |
| 190 if (!await new Directory.fromUri(patchedSdk).exists()) { | 195 if (!await new Directory.fromUri(patchedSdk).exists()) { |
| 191 return new CompilationResult.error( | 196 return new CompilationResult.error(deprecated_formatUnexpected( |
| 192 formatUnexpected(patchedSdk, -1, "Patched sdk directory not found.")); | 197 patchedSdk, -1, "Patched sdk directory not found.")); |
| 193 } | 198 } |
| 194 | 199 |
| 195 Program program; | 200 Program program; |
| 196 try { | 201 try { |
| 197 TranslateUri uriTranslator = | 202 TranslateUri uriTranslator = |
| 198 await TranslateUri.parse(fileSystem, patchedSdk, packages: packages); | 203 await TranslateUri.parse(fileSystem, patchedSdk, packages: packages); |
| 199 final Ticker ticker = new Ticker(isVerbose: verbose); | 204 final Ticker ticker = new Ticker(isVerbose: verbose); |
| 200 final DillTarget dillTarget = | 205 final DillTarget dillTarget = |
| 201 new DillTarget(ticker, uriTranslator, backendTarget); | 206 new DillTarget(ticker, uriTranslator, backendTarget); |
| 202 _appendDillForUri(dillTarget, patchedSdk.resolve('platform.dill')); | 207 _appendDillForUri(dillTarget, patchedSdk.resolve('platform.dill')); |
| 203 final KernelTarget kernelTarget = | 208 final KernelTarget kernelTarget = |
| 204 new KernelTarget(fileSystem, dillTarget, uriTranslator); | 209 new KernelTarget(fileSystem, dillTarget, uriTranslator); |
| 205 kernelTarget.read(fileName); | 210 kernelTarget.read(fileName); |
| 206 await dillTarget.buildOutlines(); | 211 await dillTarget.buildOutlines(); |
| 207 await kernelTarget.buildOutlines(); | 212 await kernelTarget.buildOutlines(); |
| 208 program = await kernelTarget.buildProgram(); | 213 program = await kernelTarget.buildProgram(); |
| 209 if (kernelTarget.errors.isNotEmpty) { | 214 if (kernelTarget.errors.isNotEmpty) { |
| 210 return new CompilationResult.errors(kernelTarget.errors); | 215 return new CompilationResult.errors(kernelTarget.errors); |
| 211 } | 216 } |
| 212 } on InputError catch (e) { | 217 } on deprecated_InputError catch (e) { |
| 213 return new CompilationResult.error(e.format()); | 218 return new CompilationResult.error(e.deprecated_format()); |
| 214 } | 219 } |
| 215 | 220 |
| 216 if (program.mainMethod == null) { | 221 if (program.mainMethod == null) { |
| 217 return new CompilationResult.error("No 'main' method found."); | 222 return new CompilationResult.error("No 'main' method found."); |
| 218 } | 223 } |
| 219 | 224 |
| 220 // Write the program to a list of bytes and return it. Do not include | 225 // Write the program to a list of bytes and return it. Do not include |
| 221 // libraries that have a dart: import URI. | 226 // libraries that have a dart: import URI. |
| 222 // | 227 // |
| 223 // TODO(kmillikin): This is intended to exclude platform libraries that are | 228 // TODO(kmillikin): This is intended to exclude platform libraries that are |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 final BytesBuilder builder = new BytesBuilder(); | 309 final BytesBuilder builder = new BytesBuilder(); |
| 305 | 310 |
| 306 void add(List<int> data) { | 311 void add(List<int> data) { |
| 307 builder.add(data); | 312 builder.add(data); |
| 308 } | 313 } |
| 309 | 314 |
| 310 void close() { | 315 void close() { |
| 311 // Nothing to do. | 316 // Nothing to do. |
| 312 } | 317 } |
| 313 } | 318 } |
| OLD | NEW |