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.outline; | 5 library fasta.outline; |
6 | 6 |
7 import 'dart:async' show | 7 import 'dart:async' show |
8 Future; | 8 Future; |
9 | 9 |
10 import 'dart:io' show | 10 import 'dart:io' show |
11 exitCode; | 11 exitCode; |
12 | 12 |
13 import 'package:kernel/verifier.dart' show | 13 import 'package:kernel/verifier.dart' show |
14 verifyProgram; | 14 verifyProgram; |
15 | 15 |
16 import 'compiler_command_line.dart' show | 16 import 'compiler_command_line.dart' show |
17 CompilerCommandLine; | 17 CompilerCommandLine; |
18 | 18 |
19 import 'errors.dart' show | 19 import 'errors.dart' show |
20 InputError, | 20 InputError, |
21 inputError; | 21 inputError; |
22 | 22 |
23 import 'kernel/kernel_target.dart' show | 23 import 'kernel/kernel_target.dart' show |
24 KernelSourceTarget; | 24 KernelTarget; |
25 | 25 |
26 import 'dill/dill_target.dart' show | 26 import 'dill/dill_target.dart' show |
27 DillTarget; | 27 DillTarget; |
28 | 28 |
29 import 'ticker.dart' show | 29 import 'ticker.dart' show |
30 Ticker; | 30 Ticker; |
31 | 31 |
32 import 'translate_uri.dart' show | 32 import 'translate_uri.dart' show |
33 TranslateUri; | 33 TranslateUri; |
34 | 34 |
35 import 'ast_kind.dart' show | 35 import 'ast_kind.dart' show |
36 AstKind; | 36 AstKind; |
37 | 37 |
38 // TODO(ahe): Remove this import. Instead make the SDK available as resource in | 38 // TODO(ahe): Remove this import. Instead make the SDK available as resource in |
39 // the executable, or something similar. | 39 // the executable, or something similar. |
40 import 'testing/kernel_chain.dart' show | 40 import 'testing/kernel_chain.dart' show |
41 computePatchedSdk; | 41 computePatchedSdk; |
42 | 42 |
43 CompilerCommandLine parseArguments(String programName, List<String> arguments) { | 43 CompilerCommandLine parseArguments(String programName, List<String> arguments) { |
44 return new CompilerCommandLine(programName, arguments); | 44 return new CompilerCommandLine(programName, arguments); |
45 } | 45 } |
46 | 46 |
47 Future<KernelSourceTarget> outline(List<String> arguments) async { | 47 Future<KernelTarget> outline(List<String> arguments) async { |
48 try { | 48 try { |
49 CompilerCommandLine cl = parseArguments("outline", arguments); | 49 CompilerCommandLine cl = parseArguments("outline", arguments); |
50 if (cl.verbose) print("Building outlines for ${arguments.join(' ')}"); | 50 if (cl.verbose) print("Building outlines for ${arguments.join(' ')}"); |
51 return await doOutline(cl, new Ticker(isVerbose: cl.verbose), cl.output); | 51 return await doOutline(cl, new Ticker(isVerbose: cl.verbose), cl.output); |
52 } on InputError catch (e) { | 52 } on InputError catch (e) { |
53 exitCode = 1; | 53 exitCode = 1; |
54 print(e.format()); | 54 print(e.format()); |
55 return null; | 55 return null; |
56 } | 56 } |
57 } | 57 } |
(...skipping 19 matching lines...) Expand all Loading... |
77 if (cl.verbose) print("Compiling via analyzer: ${arguments.join(' ')}"); | 77 if (cl.verbose) print("Compiling via analyzer: ${arguments.join(' ')}"); |
78 return await doCompile( | 78 return await doCompile( |
79 cl, new Ticker(isVerbose: cl.verbose), AstKind.Analyzer); | 79 cl, new Ticker(isVerbose: cl.verbose), AstKind.Analyzer); |
80 } on InputError catch (e) { | 80 } on InputError catch (e) { |
81 exitCode = 1; | 81 exitCode = 1; |
82 print(e.format()); | 82 print(e.format()); |
83 return null; | 83 return null; |
84 } | 84 } |
85 } | 85 } |
86 | 86 |
87 Future<KernelSourceTarget> doOutline(CompilerCommandLine cl, Ticker ticker, | 87 Future<KernelTarget> doOutline(CompilerCommandLine cl, Ticker ticker, |
88 [Uri output]) async { | 88 [Uri output]) async { |
89 Uri sdk = await computePatchedSdk(); | 89 Uri sdk = await computePatchedSdk(); |
90 ticker.logMs("Found patched SDK"); | 90 ticker.logMs("Found patched SDK"); |
91 TranslateUri uriTranslator = await TranslateUri.parse(sdk); | 91 TranslateUri uriTranslator = await TranslateUri.parse(sdk); |
92 ticker.logMs("Read packages file"); | 92 ticker.logMs("Read packages file"); |
93 DillTarget dillTarget = new DillTarget(ticker, uriTranslator); | 93 DillTarget dillTarget = new DillTarget(ticker, uriTranslator); |
94 KernelSourceTarget sourceTarget = | 94 KernelTarget kernelTarget = new KernelTarget(dillTarget, uriTranslator); |
95 new KernelSourceTarget(dillTarget, uriTranslator); | |
96 Uri platform = cl.platform; | 95 Uri platform = cl.platform; |
97 if (platform != null) { | 96 if (platform != null) { |
98 dillTarget.read(platform); | 97 dillTarget.read(platform); |
99 } | 98 } |
100 String argument = cl.arguments.first; | 99 String argument = cl.arguments.first; |
101 Uri uri = Uri.base.resolve(argument); | 100 Uri uri = Uri.base.resolve(argument); |
102 String path = uriTranslator.translate(uri)?.path ?? argument; | 101 String path = uriTranslator.translate(uri)?.path ?? argument; |
103 if (path.endsWith(".dart")) { | 102 if (path.endsWith(".dart")) { |
104 sourceTarget.read(uri); | 103 kernelTarget.read(uri); |
105 } else { | 104 } else { |
106 inputError(uri, -1, "Unexpected input: $uri"); | 105 inputError(uri, -1, "Unexpected input: $uri"); |
107 } | 106 } |
108 await dillTarget.writeOutline(null); | 107 await dillTarget.writeOutline(null); |
109 await sourceTarget.writeOutline(output); | 108 await kernelTarget.writeOutline(output); |
110 if (cl.dumpIr && output != null) { | 109 if (cl.dumpIr && output != null) { |
111 sourceTarget.dumpIr(); | 110 kernelTarget.dumpIr(); |
112 } | 111 } |
113 return sourceTarget; | 112 return kernelTarget; |
114 } | 113 } |
115 | 114 |
116 Future<Uri> doCompile(CompilerCommandLine cl, Ticker ticker, | 115 Future<Uri> doCompile(CompilerCommandLine cl, Ticker ticker, |
117 AstKind kind) async { | 116 AstKind kind) async { |
118 KernelSourceTarget sourceTarget = await doOutline(cl, ticker); | 117 KernelTarget kernelTarget = await doOutline(cl, ticker); |
119 if (exitCode != 0) return null; | 118 if (exitCode != 0) return null; |
120 Uri uri = cl.output; | 119 Uri uri = cl.output; |
121 await sourceTarget.writeProgram(uri, kind); | 120 await kernelTarget.writeProgram(uri, kind); |
122 if (cl.dumpIr) { | 121 if (cl.dumpIr) { |
123 sourceTarget.dumpIr(); | 122 kernelTarget.dumpIr(); |
124 } | 123 } |
125 if (cl.verify) { | 124 if (cl.verify) { |
126 try { | 125 try { |
127 verifyProgram(sourceTarget.program); | 126 verifyProgram(kernelTarget.program); |
128 ticker.logMs("Verified program"); | 127 ticker.logMs("Verified program"); |
129 } catch (e, s) { | 128 } catch (e, s) { |
130 exitCode = 1; | 129 exitCode = 1; |
131 print("Verification of program failed: $e"); | 130 print("Verification of program failed: $e"); |
132 if (s != null && cl.verbose) { | 131 if (s != null && cl.verbose) { |
133 print(s); | 132 print(s); |
134 } | 133 } |
135 } | 134 } |
136 } | 135 } |
137 return uri; | 136 return uri; |
138 } | 137 } |
OLD | NEW |