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

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

Issue 2918923003: Revert "Use backend targets to run Kernel transformations in Fasta" (Closed)
Patch Set: 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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 Uri fileName, Uri packages, Uri patchedSdk, 179 Uri fileName, Uri packages, Uri patchedSdk,
180 {bool verbose: false, bool strongMode: false}) async { 180 {bool verbose: false, bool strongMode: false}) async {
181 return parseScriptInFileSystem( 181 return parseScriptInFileSystem(
182 fileName, PhysicalFileSystem.instance, packages, patchedSdk, 182 fileName, PhysicalFileSystem.instance, packages, patchedSdk,
183 verbose: verbose, strongMode: strongMode); 183 verbose: verbose, strongMode: strongMode);
184 } 184 }
185 185
186 Future<CompilationResult> parseScriptInFileSystem( 186 Future<CompilationResult> parseScriptInFileSystem(
187 Uri fileName, FileSystem fileSystem, Uri packages, Uri patchedSdk, 187 Uri fileName, FileSystem fileSystem, Uri packages, Uri patchedSdk,
188 {bool verbose: false, bool strongMode: false, String backendTarget}) async { 188 {bool verbose: false, bool strongMode: false, String backendTarget}) async {
189 backendTarget ??= "vm_fasta"; 189 backendTarget ??= "vm";
190 try { 190 try {
191 if (!await fileSystem.entityForUri(fileName).exists()) { 191 if (!await fileSystem.entityForUri(fileName).exists()) {
192 return new CompilationResult.error( 192 return new CompilationResult.error(
193 formatUnexpected(fileName, -1, "No such file.")); 193 formatUnexpected(fileName, -1, "No such file."));
194 } 194 }
195 if (!await new Directory.fromUri(patchedSdk).exists()) { 195 if (!await new Directory.fromUri(patchedSdk).exists()) {
196 return new CompilationResult.error( 196 return new CompilationResult.error(
197 formatUnexpected(patchedSdk, -1, "Patched sdk directory not found.")); 197 formatUnexpected(patchedSdk, -1, "Patched sdk directory not found."));
198 } 198 }
199 199
200 CoreTypes coreTypes; 200 CoreTypes coreTypes;
201 ClassHierarchy hierarchy; 201 ClassHierarchy hierarchy;
202 Program program; 202 Program program;
203 try { 203 try {
204 TranslateUri uriTranslator = 204 TranslateUri uriTranslator =
205 await TranslateUri.parse(fileSystem, patchedSdk, packages: packages); 205 await TranslateUri.parse(fileSystem, patchedSdk, packages: packages);
206 final Ticker ticker = new Ticker(isVerbose: verbose); 206 final Ticker ticker = new Ticker(isVerbose: verbose);
207 final DillTarget dillTarget = new DillTarget( 207 final DillTarget dillTarget =
208 ticker, uriTranslator, backendTarget, 208 new DillTarget(ticker, uriTranslator, backendTarget);
209 flags: new TargetFlags(strongMode: strongMode));
210 _appendDillForUri(dillTarget, patchedSdk.resolve('platform.dill')); 209 _appendDillForUri(dillTarget, patchedSdk.resolve('platform.dill'));
211 final KernelTarget kernelTarget = 210 final KernelTarget kernelTarget =
212 new KernelTarget(fileSystem, dillTarget, uriTranslator, strongMode); 211 new KernelTarget(fileSystem, dillTarget, uriTranslator, strongMode);
213 kernelTarget.read(fileName); 212 kernelTarget.read(fileName);
214 await dillTarget.buildOutlines(); 213 await dillTarget.buildOutlines();
215 await kernelTarget.buildOutlines(); 214 await kernelTarget.buildOutlines();
216 coreTypes = kernelTarget.loader.coreTypes; 215 coreTypes = kernelTarget.loader.coreTypes;
217 hierarchy = kernelTarget.loader.hierarchy; 216 hierarchy = kernelTarget.loader.hierarchy;
218 program = await kernelTarget.buildProgram(); 217 program = await kernelTarget.buildProgram();
219 if (kernelTarget.errors.isNotEmpty) { 218 if (kernelTarget.errors.isNotEmpty) {
220 return new CompilationResult.errors(kernelTarget.errors); 219 return new CompilationResult.errors(kernelTarget.errors);
221 } 220 }
222 } on InputError catch (e) { 221 } on InputError catch (e) {
223 return new CompilationResult.error(e.format()); 222 return new CompilationResult.error(e.format());
224 } 223 }
225 224
226 if (program.mainMethod == null) { 225 if (program.mainMethod == null) {
227 return new CompilationResult.error("No 'main' method found."); 226 return new CompilationResult.error("No 'main' method found.");
228 } 227 }
229 228
229 // Perform target-specific transformations.
230 Target target = getTarget("vm", new TargetFlags(strongMode: false));
231 target.performModularTransformations(coreTypes, hierarchy, program);
232 target.performGlobalTransformations(coreTypes, program);
233
230 // Write the program to a list of bytes and return it. Do not include 234 // Write the program to a list of bytes and return it. Do not include
231 // libraries that have a dart: import URI. 235 // libraries that have a dart: import URI.
232 // 236 //
233 // TODO(kmillikin): This is intended to exclude platform libraries that are 237 // TODO(kmillikin): This is intended to exclude platform libraries that are
234 // included in the Kernel binary platform platform.dill. It does not 238 // included in the Kernel binary platform platform.dill. It does not
235 // necessarily exclude exactly the platform libraries. Use a better 239 // necessarily exclude exactly the platform libraries. Use a better
236 // predicate that knows what is included in platform.dill. 240 // predicate that knows what is included in platform.dill.
237 var sink = new ByteSink(); 241 var sink = new ByteSink();
238 bool predicate(Library library) => !library.importUri.isScheme('dart'); 242 bool predicate(Library library) => !library.importUri.isScheme('dart');
239 new LibraryFilteringBinaryPrinter(sink, predicate) 243 new LibraryFilteringBinaryPrinter(sink, predicate)
240 .writeProgramFile(program); 244 .writeProgramFile(program);
241 return new CompilationResult.ok(sink.builder.takeBytes()); 245 return new CompilationResult.ok(sink.builder.takeBytes());
242 } catch (e, s) { 246 } catch (e, s) {
243 return reportCrash(e, s, fileName); 247 return reportCrash(e, s, fileName);
244 } 248 }
245 } 249 }
246 250
247 Future compilePlatform(Uri patchedSdk, Uri fullOutput, 251 Future compilePlatform(Uri patchedSdk, Uri fullOutput,
248 {Uri outlineOutput, 252 {Uri outlineOutput, Uri packages, bool verbose: false}) async {
249 Uri packages,
250 bool verbose: false,
251 String backendTarget}) async {
252 backendTarget ??= "vm_fasta";
253 Ticker ticker = new Ticker(isVerbose: verbose); 253 Ticker ticker = new Ticker(isVerbose: verbose);
254 await CompilerCommandLine.withGlobalOptions("", [""], (CompilerContext c) { 254 await CompilerCommandLine.withGlobalOptions("", [""], (CompilerContext c) {
255 c.options.options["--target"] = backendTarget;
256 c.options.options["--packages"] = packages; 255 c.options.options["--packages"] = packages;
257 if (verbose) { 256 if (verbose) {
258 c.options.options["--verbose"] = true; 257 c.options.options["--verbose"] = true;
259 } 258 }
260 return compilePlatformInternal( 259 return compilePlatformInternal(
261 c, ticker, patchedSdk, fullOutput, outlineOutput); 260 c, ticker, patchedSdk, fullOutput, outlineOutput);
262 }); 261 });
263 } 262 }
264 263
265 Future writeDepsFile(Uri script, Uri depsFile, Uri output, 264 Future writeDepsFile(Uri script, Uri depsFile, Uri output,
266 {Uri sdk, 265 {Uri sdk,
267 Uri packages, 266 Uri packages,
268 Uri platform, 267 Uri platform,
269 Iterable<Uri> extraDependencies, 268 Iterable<Uri> extraDependencies,
270 bool verbose: false, 269 bool verbose: false,
271 String backendTarget}) async { 270 String backendTarget}) async {
272 backendTarget ??= "vm_fasta"; 271 backendTarget ??= "vm";
273 Ticker ticker = new Ticker(isVerbose: verbose); 272 Ticker ticker = new Ticker(isVerbose: verbose);
274 await CompilerCommandLine.withGlobalOptions("", [""], 273 await CompilerCommandLine.withGlobalOptions("", [""],
275 (CompilerContext c) async { 274 (CompilerContext c) async {
276 c.options.options["--packages"] = packages; 275 c.options.options["--packages"] = packages;
277 if (verbose) { 276 if (verbose) {
278 c.options.options["--verbose"] = true; 277 c.options.options["--verbose"] = true;
279 } 278 }
280 sdk ??= c.options.sdk; 279 sdk ??= c.options.sdk;
281 280
282 TranslateUri uriTranslator = await TranslateUri.parse(c.fileSystem, sdk, 281 TranslateUri uriTranslator = await TranslateUri.parse(c.fileSystem, sdk,
283 packages: c.options.packages); 282 packages: c.options.packages);
284 ticker.logMs("Read packages file"); 283 ticker.logMs("Read packages file");
285 DillTarget dillTarget = new DillTarget(ticker, uriTranslator, backendTarget, 284 DillTarget dillTarget =
286 flags: new TargetFlags(strongMode: false)); 285 new DillTarget(ticker, uriTranslator, backendTarget);
287 _appendDillForUri(dillTarget, platform); 286 _appendDillForUri(dillTarget, platform);
288 KernelTarget kernelTarget = new KernelTarget(PhysicalFileSystem.instance, 287 KernelTarget kernelTarget = new KernelTarget(PhysicalFileSystem.instance,
289 dillTarget, uriTranslator, false, c.uriToSource); 288 dillTarget, uriTranslator, false, c.uriToSource);
290 289
291 kernelTarget.read(script); 290 kernelTarget.read(script);
292 await dillTarget.buildOutlines(); 291 await dillTarget.buildOutlines();
293 await kernelTarget.loader.buildOutlines(); 292 await kernelTarget.loader.buildOutlines();
294 await kernelTarget.writeDepsFile(output, depsFile, 293 await kernelTarget.writeDepsFile(output, depsFile,
295 extraDependencies: extraDependencies); 294 extraDependencies: extraDependencies);
296 }); 295 });
(...skipping 13 matching lines...) Expand all
310 final BytesBuilder builder = new BytesBuilder(); 309 final BytesBuilder builder = new BytesBuilder();
311 310
312 void add(List<int> data) { 311 void add(List<int> data) {
313 builder.add(data); 312 builder.add(data);
314 } 313 }
315 314
316 void close() { 315 void close() {
317 // Nothing to do. 316 // Nothing to do.
318 } 317 }
319 } 318 }
OLDNEW
« no previous file with comments | « pkg/front_end/lib/src/fasta/dill/dill_target.dart ('k') | pkg/front_end/lib/src/fasta/kernel/kernel_target.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698