Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library fasta.outline; | |
| 6 | |
| 7 import 'dart:async' show | |
| 8 Future; | |
| 9 | |
| 10 import 'dart:io' show | |
| 11 exitCode; | |
| 12 | |
| 13 import 'package:kernel/verifier.dart' show | |
| 14 verifyProgram; | |
| 15 | |
| 16 import 'compiler_command_line.dart' show | |
| 17 CompilerCommandLine; | |
| 18 | |
| 19 import 'errors.dart' show | |
| 20 InputError, | |
| 21 inputError; | |
| 22 | |
| 23 import 'kernel/kernel_target.dart' show | |
| 24 KernelSourceTarget; | |
| 25 | |
| 26 import 'dill/dill_target.dart' show | |
| 27 DillTarget; | |
| 28 | |
| 29 import 'ticker.dart' show | |
| 30 Ticker; | |
| 31 | |
| 32 import 'translate_uri.dart' show | |
| 33 TranslateUri; | |
| 34 | |
| 35 import 'ast_kind.dart' show | |
| 36 AstKind; | |
| 37 | |
| 38 CompilerCommandLine parseArguments(String programName, List<String> arguments) { | |
| 39 return new CompilerCommandLine(programName, arguments); | |
| 40 } | |
| 41 | |
| 42 Future<KernelSourceTarget> outline(List<String> arguments) async { | |
| 43 try { | |
| 44 CompilerCommandLine cl = parseArguments("outline", arguments); | |
| 45 if (cl.verbose) print("Building outlines for ${arguments.join(' ')}"); | |
| 46 return await doOutline(cl, new Ticker(isVerbose:cl.verbose), cl.output); | |
|
Johnni Winther
2017/01/16 09:47:46
`isVerbose:cl.verbose` -> `isVerbose: cl.verbose`
ahe
2017/01/16 12:07:04
Done.
| |
| 47 } on InputError catch (e) { | |
| 48 exitCode = 1; | |
| 49 print(e.format()); | |
| 50 return null; | |
| 51 } | |
| 52 } | |
| 53 | |
| 54 Future<Uri> compile(List<String> arguments) async { | |
| 55 try { | |
| 56 CompilerCommandLine cl = parseArguments("compile", arguments); | |
| 57 if (cl.verbose) { | |
| 58 print("Compiling directly to Kernel: ${arguments.join(' ')}"); | |
| 59 } | |
| 60 return | |
| 61 await doCompile(cl, new Ticker(isVerbose:cl.verbose), AstKind.Kernel); | |
| 62 } on InputError catch (e) { | |
| 63 exitCode = 1; | |
| 64 print(e.format()); | |
| 65 return null; | |
| 66 } | |
| 67 } | |
| 68 | |
| 69 Future<Uri> kompile(List<String> arguments) async { | |
| 70 try { | |
| 71 CompilerCommandLine cl = parseArguments("kompile", arguments); | |
| 72 if (cl.verbose) print("Compiling via analyzer: ${arguments.join(' ')}"); | |
| 73 return | |
| 74 await doCompile(cl, new Ticker(isVerbose:cl.verbose), AstKind.Analyzer); | |
| 75 } on InputError catch (e) { | |
| 76 exitCode = 1; | |
| 77 print(e.format()); | |
| 78 return null; | |
| 79 } | |
| 80 } | |
| 81 | |
| 82 Future<KernelSourceTarget> doOutline(CompilerCommandLine cl, Ticker ticker, | |
| 83 [Uri output]) async { | |
| 84 TranslateUri uriTranslator = await TranslateUri.parse(); | |
| 85 ticker.logMs("Read packages file"); | |
| 86 DillTarget dillTarget = new DillTarget(ticker, uriTranslator); | |
| 87 KernelSourceTarget sourceTarget = | |
| 88 new KernelSourceTarget(dillTarget, uriTranslator); | |
| 89 dillTarget.read(cl.platform); | |
| 90 String argument = cl.arguments.first; | |
| 91 Uri uri = Uri.base.resolve(argument); | |
| 92 String path = uriTranslator.translate(uri)?.path ?? argument; | |
| 93 if (path.endsWith(".dart")) { | |
| 94 sourceTarget.read(uri); | |
| 95 } else { | |
| 96 inputError(uri, -1, "Unexpected input: $uri"); | |
| 97 } | |
| 98 await dillTarget.writeOutline(null); | |
| 99 await sourceTarget.writeOutline(output); | |
| 100 if (cl.dumpIr && output != null) { | |
| 101 sourceTarget.dumpIr(); | |
| 102 } | |
| 103 return sourceTarget; | |
| 104 } | |
| 105 | |
| 106 Future<Uri> doCompile(CompilerCommandLine cl, Ticker ticker, | |
| 107 AstKind kind) async { | |
| 108 KernelSourceTarget sourceTarget = await doOutline(cl, ticker); | |
| 109 if (exitCode != 0) return null; | |
| 110 Uri uri = cl.output; | |
| 111 await sourceTarget.writeProgram(uri, kind); | |
| 112 if (cl.dumpIr) { | |
| 113 sourceTarget.dumpIr(); | |
| 114 } | |
| 115 if (cl.verify) { | |
| 116 try { | |
| 117 verifyProgram(sourceTarget.program); | |
| 118 ticker.logMs("Verified program"); | |
| 119 } catch (e, s) { | |
| 120 exitCode = 1; | |
| 121 print("Verification of program failed: $e"); | |
| 122 if (s != null && cl.verbose) { | |
| 123 print(s); | |
| 124 } | |
| 125 } | |
| 126 } | |
| 127 return uri; | |
| 128 } | |
| OLD | NEW |