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:kernel/binary/ast_to_binary.dart' show BinaryPrinter; | 13 import 'package:kernel/binary/ast_to_binary.dart' show BinaryPrinter; |
14 | 14 |
15 import 'package:kernel/binary/tag.dart' show Tag; | |
16 | |
15 import 'package:kernel/kernel.dart' show Program; | 17 import 'package:kernel/kernel.dart' show Program; |
16 | 18 |
17 import 'package:kernel/target/targets.dart' show Target, TargetFlags, getTarget; | 19 import 'package:kernel/target/targets.dart' show Target, TargetFlags, getTarget; |
18 | 20 |
19 import 'compiler_command_line.dart' show CompilerCommandLine; | 21 import 'compiler_command_line.dart' show CompilerCommandLine; |
20 | 22 |
21 import 'compiler_context.dart' show CompilerContext; | 23 import 'compiler_context.dart' show CompilerContext; |
22 | 24 |
23 import 'errors.dart' show InputError, formatUnexpected, inputError, reportCrash; | 25 import 'errors.dart' show InputError, formatUnexpected, inputError, reportCrash; |
24 | 26 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 Future<Uri> compile() async { | 145 Future<Uri> compile() async { |
144 KernelTarget kernelTarget = await buildOutline(); | 146 KernelTarget kernelTarget = await buildOutline(); |
145 if (exitCode != 0) return null; | 147 if (exitCode != 0) return null; |
146 Uri uri = c.options.output; | 148 Uri uri = c.options.output; |
147 await kernelTarget.writeProgram(uri, | 149 await kernelTarget.writeProgram(uri, |
148 dumpIr: c.options.dumpIr, verify: c.options.verify); | 150 dumpIr: c.options.dumpIr, verify: c.options.verify); |
149 return uri; | 151 return uri; |
150 } | 152 } |
151 } | 153 } |
152 | 154 |
155 class FrontEndBinaryPrinter extends BinaryPrinter { | |
Kevin Millikin (Google)
2017/03/31 10:05:42
This is hacky and I'm sure there is a better way.
ahe
2017/03/31 10:13:09
I think this would be a better fit for the "kernel
ahe
2017/03/31 10:13:09
How about renaming this FilteringBinaryPrinter and
| |
156 FrontEndBinaryPrinter(Sink<List<int>> sink) : super(sink); | |
157 | |
158 void writeProgramFile(Program program) { | |
159 program.computeCanonicalNames(); | |
160 writeMagicWord(Tag.ProgramFile); | |
161 stringIndexer.scanProgram(program); | |
162 writeStringTable(stringIndexer); | |
163 writeUriToSource(program); | |
164 writeLinkTable(program); | |
165 writeList(program.libraries.where((lib) => !lib.importUri.isScheme('dart')), | |
166 writeNode); | |
167 writeMemberReference(program.mainMethod, allowNull: true); | |
168 flush(); | |
169 } | |
170 } | |
171 | |
153 Future<CompilationResult> parseScript( | 172 Future<CompilationResult> parseScript( |
154 Uri fileName, Uri packages, Uri patchedSdk, bool verbose) async { | 173 Uri fileName, Uri packages, Uri patchedSdk, bool verbose) async { |
155 try { | 174 try { |
156 if (!await new File.fromUri(fileName).exists()) { | 175 if (!await new File.fromUri(fileName).exists()) { |
157 return new CompilationResult.error( | 176 return new CompilationResult.error( |
158 formatUnexpected(fileName, -1, "No such file.")); | 177 formatUnexpected(fileName, -1, "No such file.")); |
159 } | 178 } |
160 if (!await new Directory.fromUri(patchedSdk).exists()) { | 179 if (!await new Directory.fromUri(patchedSdk).exists()) { |
161 return new CompilationResult.error( | 180 return new CompilationResult.error( |
162 formatUnexpected(patchedSdk, -1, "Patched sdk directory not found.")); | 181 formatUnexpected(patchedSdk, -1, "Patched sdk directory not found.")); |
(...skipping 21 matching lines...) Expand all Loading... | |
184 } on InputError catch (e) { | 203 } on InputError catch (e) { |
185 return new CompilationResult.error(e.format()); | 204 return new CompilationResult.error(e.format()); |
186 } | 205 } |
187 | 206 |
188 // Perform target-specific transformations. | 207 // Perform target-specific transformations. |
189 target.performModularTransformations(program); | 208 target.performModularTransformations(program); |
190 target.performGlobalTransformations(program); | 209 target.performGlobalTransformations(program); |
191 | 210 |
192 // Write the program to a list of bytes and return it. | 211 // Write the program to a list of bytes and return it. |
193 var sink = new ByteSink(); | 212 var sink = new ByteSink(); |
194 new BinaryPrinter(sink).writeProgramFile(program); | 213 new FrontEndBinaryPrinter(sink).writeProgramFile(program); |
195 return new CompilationResult.ok(sink.builder.takeBytes()); | 214 return new CompilationResult.ok(sink.builder.takeBytes()); |
196 } catch (e, s) { | 215 } catch (e, s) { |
197 return reportCrash(e, s, fileName); | 216 return reportCrash(e, s, fileName); |
198 } | 217 } |
199 } | 218 } |
200 | 219 |
201 Future compilePlatform(Uri patchedSdk, Uri output, | 220 Future compilePlatform(Uri patchedSdk, Uri output, |
202 {Uri packages, bool verbose: false}) async { | 221 {Uri packages, bool verbose: false}) async { |
203 Ticker ticker = new Ticker(isVerbose: verbose); | 222 Ticker ticker = new Ticker(isVerbose: verbose); |
204 await CompilerCommandLine.withGlobalOptions("", [""], (CompilerContext c) { | 223 await CompilerCommandLine.withGlobalOptions("", [""], (CompilerContext c) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
244 final BytesBuilder builder = new BytesBuilder(); | 263 final BytesBuilder builder = new BytesBuilder(); |
245 | 264 |
246 void add(List<int> data) { | 265 void add(List<int> data) { |
247 builder.add(data); | 266 builder.add(data); |
248 } | 267 } |
249 | 268 |
250 void close() { | 269 void close() { |
251 // Nothing to do. | 270 // Nothing to do. |
252 } | 271 } |
253 } | 272 } |
OLD | NEW |