Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: pkg/front_end/lib/src/fasta/fasta.dart

Issue 2918623004: Use backend targets to run Kernel transformations in Fasta (Closed)
Patch Set: Remove some overrides of performModularTransformationsOnProgram Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 Uri fileName, Uri packages, Uri patchedSdk, 177 Uri fileName, Uri packages, Uri patchedSdk,
178 {bool verbose: false, bool strongMode: false}) async { 178 {bool verbose: false, bool strongMode: false}) async {
179 return parseScriptInFileSystem( 179 return parseScriptInFileSystem(
180 fileName, PhysicalFileSystem.instance, packages, patchedSdk, 180 fileName, PhysicalFileSystem.instance, packages, patchedSdk,
181 verbose: verbose, strongMode: strongMode); 181 verbose: verbose, strongMode: strongMode);
182 } 182 }
183 183
184 Future<CompilationResult> parseScriptInFileSystem( 184 Future<CompilationResult> parseScriptInFileSystem(
185 Uri fileName, FileSystem fileSystem, Uri packages, Uri patchedSdk, 185 Uri fileName, FileSystem fileSystem, Uri packages, Uri patchedSdk,
186 {bool verbose: false, bool strongMode: false, String backendTarget}) async { 186 {bool verbose: false, bool strongMode: false, String backendTarget}) async {
187 backendTarget ??= "vm"; 187 backendTarget ??= "vm_fasta";
188 try { 188 try {
189 if (!await fileSystem.entityForUri(fileName).exists()) { 189 if (!await fileSystem.entityForUri(fileName).exists()) {
190 return new CompilationResult.error( 190 return new CompilationResult.error(
191 formatUnexpected(fileName, -1, "No such file.")); 191 formatUnexpected(fileName, -1, "No such file."));
192 } 192 }
193 if (!await new Directory.fromUri(patchedSdk).exists()) { 193 if (!await new Directory.fromUri(patchedSdk).exists()) {
194 return new CompilationResult.error( 194 return new CompilationResult.error(
195 formatUnexpected(patchedSdk, -1, "Patched sdk directory not found.")); 195 formatUnexpected(patchedSdk, -1, "Patched sdk directory not found."));
196 } 196 }
197 197
198 CoreTypes coreTypes; 198 CoreTypes coreTypes;
199 Program program; 199 Program program;
200 try { 200 try {
201 TranslateUri uriTranslator = 201 TranslateUri uriTranslator =
202 await TranslateUri.parse(fileSystem, patchedSdk, packages: packages); 202 await TranslateUri.parse(fileSystem, patchedSdk, packages: packages);
203 final Ticker ticker = new Ticker(isVerbose: verbose); 203 final Ticker ticker = new Ticker(isVerbose: verbose);
204 final DillTarget dillTarget = 204 final DillTarget dillTarget = new DillTarget(
205 new DillTarget(ticker, uriTranslator, backendTarget); 205 ticker, uriTranslator, backendTarget,
206 flags: new TargetFlags(strongMode: strongMode));
206 _appendDillForUri(dillTarget, patchedSdk.resolve('platform.dill')); 207 _appendDillForUri(dillTarget, patchedSdk.resolve('platform.dill'));
207 final KernelTarget kernelTarget = 208 final KernelTarget kernelTarget =
208 new KernelTarget(fileSystem, dillTarget, uriTranslator, strongMode); 209 new KernelTarget(fileSystem, dillTarget, uriTranslator, strongMode);
209 kernelTarget.read(fileName); 210 kernelTarget.read(fileName);
210 await dillTarget.buildOutlines(); 211 await dillTarget.buildOutlines();
211 await kernelTarget.buildOutlines(); 212 await kernelTarget.buildOutlines();
212 coreTypes = kernelTarget.loader.coreTypes; 213 coreTypes = kernelTarget.loader.coreTypes;
213 program = await kernelTarget.buildProgram(); 214 program = await kernelTarget.buildProgram();
214 if (kernelTarget.errors.isNotEmpty) { 215 if (kernelTarget.errors.isNotEmpty) {
215 return new CompilationResult.errors(kernelTarget.errors); 216 return new CompilationResult.errors(kernelTarget.errors);
216 } 217 }
217 } on InputError catch (e) { 218 } on InputError catch (e) {
218 return new CompilationResult.error(e.format()); 219 return new CompilationResult.error(e.format());
219 } 220 }
220 221
221 if (program.mainMethod == null) { 222 if (program.mainMethod == null) {
222 return new CompilationResult.error("No 'main' method found."); 223 return new CompilationResult.error("No 'main' method found.");
223 } 224 }
224 225
225 // Perform target-specific transformations. 226 // Perform target-specific transformations.
226 Target target = getTarget("vm", new TargetFlags(strongMode: false)); 227 Target target = getTarget("vm_fasta", new TargetFlags(strongMode: false));
227 target.performModularTransformations(coreTypes, program); 228 target.performModularTransformationsOnProgram(coreTypes, program);
Siggi Cherem (dart-lang) 2017/06/01 18:29:31 dbc - do we still need this call? (I'm thinking th
Dmitry Stefantsov 2017/06/02 07:52:52 Good catch! I've added backendTarget.performGlobal
228 target.performGlobalTransformations(coreTypes, program); 229 target.performGlobalTransformations(coreTypes, program);
229 230
230 // Write the program to a list of bytes and return it. Do not include 231 // Write the program to a list of bytes and return it. Do not include
231 // libraries that have a dart: import URI. 232 // libraries that have a dart: import URI.
232 // 233 //
233 // TODO(kmillikin): This is intended to exclude platform libraries that are 234 // TODO(kmillikin): This is intended to exclude platform libraries that are
234 // included in the Kernel binary platform platform.dill. It does not 235 // included in the Kernel binary platform platform.dill. It does not
235 // necessarily exclude exactly the platform libraries. Use a better 236 // necessarily exclude exactly the platform libraries. Use a better
236 // predicate that knows what is included in platform.dill. 237 // predicate that knows what is included in platform.dill.
237 var sink = new ByteSink(); 238 var sink = new ByteSink();
238 bool predicate(Library library) => !library.importUri.isScheme('dart'); 239 bool predicate(Library library) => !library.importUri.isScheme('dart');
239 new LibraryFilteringBinaryPrinter(sink, predicate) 240 new LibraryFilteringBinaryPrinter(sink, predicate)
240 .writeProgramFile(program); 241 .writeProgramFile(program);
241 return new CompilationResult.ok(sink.builder.takeBytes()); 242 return new CompilationResult.ok(sink.builder.takeBytes());
242 } catch (e, s) { 243 } catch (e, s) {
243 return reportCrash(e, s, fileName); 244 return reportCrash(e, s, fileName);
244 } 245 }
245 } 246 }
246 247
247 Future compilePlatform(Uri patchedSdk, Uri fullOutput, 248 Future compilePlatform(Uri patchedSdk, Uri fullOutput,
248 {Uri outlineOutput, Uri packages, bool verbose: false}) async { 249 {Uri outlineOutput,
250 Uri packages,
251 bool verbose: false,
252 String backendTarget}) async {
253 backendTarget ??= "vm_fasta";
249 Ticker ticker = new Ticker(isVerbose: verbose); 254 Ticker ticker = new Ticker(isVerbose: verbose);
250 await CompilerCommandLine.withGlobalOptions("", [""], (CompilerContext c) { 255 await CompilerCommandLine.withGlobalOptions("", [""], (CompilerContext c) {
256 c.options.options["--target"] = backendTarget;
251 c.options.options["--packages"] = packages; 257 c.options.options["--packages"] = packages;
252 if (verbose) { 258 if (verbose) {
253 c.options.options["--verbose"] = true; 259 c.options.options["--verbose"] = true;
254 } 260 }
255 return compilePlatformInternal( 261 return compilePlatformInternal(
256 c, ticker, patchedSdk, fullOutput, outlineOutput); 262 c, ticker, patchedSdk, fullOutput, outlineOutput);
257 }); 263 });
258 } 264 }
259 265
260 Future writeDepsFile(Uri script, Uri depsFile, Uri output, 266 Future writeDepsFile(Uri script, Uri depsFile, Uri output,
261 {Uri sdk, 267 {Uri sdk,
262 Uri packages, 268 Uri packages,
263 Uri platform, 269 Uri platform,
264 Iterable<Uri> extraDependencies, 270 Iterable<Uri> extraDependencies,
265 bool verbose: false, 271 bool verbose: false,
266 String backendTarget}) async { 272 String backendTarget}) async {
267 backendTarget ??= "vm"; 273 backendTarget ??= "vm_fasta";
268 Ticker ticker = new Ticker(isVerbose: verbose); 274 Ticker ticker = new Ticker(isVerbose: verbose);
269 await CompilerCommandLine.withGlobalOptions("", [""], 275 await CompilerCommandLine.withGlobalOptions("", [""],
270 (CompilerContext c) async { 276 (CompilerContext c) async {
271 c.options.options["--packages"] = packages; 277 c.options.options["--packages"] = packages;
272 if (verbose) { 278 if (verbose) {
273 c.options.options["--verbose"] = true; 279 c.options.options["--verbose"] = true;
274 } 280 }
275 sdk ??= c.options.sdk; 281 sdk ??= c.options.sdk;
276 282
277 TranslateUri uriTranslator = await TranslateUri.parse(c.fileSystem, sdk, 283 TranslateUri uriTranslator = await TranslateUri.parse(c.fileSystem, sdk,
278 packages: c.options.packages); 284 packages: c.options.packages);
279 ticker.logMs("Read packages file"); 285 ticker.logMs("Read packages file");
280 DillTarget dillTarget = 286 DillTarget dillTarget = new DillTarget(ticker, uriTranslator, backendTarget,
281 new DillTarget(ticker, uriTranslator, backendTarget); 287 flags: new TargetFlags(strongMode: false));
282 _appendDillForUri(dillTarget, platform); 288 _appendDillForUri(dillTarget, platform);
283 KernelTarget kernelTarget = new KernelTarget(PhysicalFileSystem.instance, 289 KernelTarget kernelTarget = new KernelTarget(PhysicalFileSystem.instance,
284 dillTarget, uriTranslator, false, c.uriToSource); 290 dillTarget, uriTranslator, false, c.uriToSource);
285 291
286 kernelTarget.read(script); 292 kernelTarget.read(script);
287 await dillTarget.buildOutlines(); 293 await dillTarget.buildOutlines();
288 await kernelTarget.loader.buildOutlines(); 294 await kernelTarget.loader.buildOutlines();
289 await kernelTarget.writeDepsFile(output, depsFile, 295 await kernelTarget.writeDepsFile(output, depsFile,
290 extraDependencies: extraDependencies); 296 extraDependencies: extraDependencies);
291 }); 297 });
(...skipping 13 matching lines...) Expand all
305 final BytesBuilder builder = new BytesBuilder(); 311 final BytesBuilder builder = new BytesBuilder();
306 312
307 void add(List<int> data) { 313 void add(List<int> data) {
308 builder.add(data); 314 builder.add(data);
309 } 315 }
310 316
311 void close() { 317 void close() {
312 // Nothing to do. 318 // Nothing to do.
313 } 319 }
314 } 320 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698