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

Side by Side Diff: pkg/front_end/lib/kernel_generator.dart

Issue 2919003003: Reapply "Use backend targets to run Kernel transformations in Fasta" (Closed)
Patch Set: Follow dartanalyzer suggestions 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 /// Defines the front-end API for converting source code to Dart Kernel objects. 5 /// Defines the front-end API for converting source code to Dart Kernel objects.
6 library front_end.kernel_generator; 6 library front_end.kernel_generator;
7 7
8 import 'compiler_options.dart'; 8 import 'compiler_options.dart';
9 import 'dart:async' show Future; 9 import 'dart:async' show Future;
10 import 'dart:async'; 10 import 'dart:async';
11 import 'package:front_end/src/base/processed_options.dart'; 11 import 'package:front_end/src/base/processed_options.dart';
12 import 'src/fasta/dill/dill_target.dart' show DillTarget; 12 import 'src/fasta/dill/dill_target.dart' show DillTarget;
13 import 'src/fasta/errors.dart' show InputError; 13 import 'src/fasta/errors.dart' show InputError;
14 import 'src/fasta/kernel/kernel_target.dart' show KernelTarget; 14 import 'src/fasta/kernel/kernel_target.dart' show KernelTarget;
15 import 'package:kernel/kernel.dart' show Program; 15 import 'package:kernel/kernel.dart' show Program;
16 import 'package:kernel/target/targets.dart' show TargetFlags;
16 import 'src/fasta/ticker.dart' show Ticker; 17 import 'src/fasta/ticker.dart' show Ticker;
17 import 'src/fasta/translate_uri.dart' show TranslateUri; 18 import 'src/fasta/translate_uri.dart' show TranslateUri;
18 import 'src/simple_error.dart'; 19 import 'src/simple_error.dart';
19 20
20 /// Generates a kernel representation of the program whose main library is in 21 /// Generates a kernel representation of the program whose main library is in
21 /// the given [source]. 22 /// the given [source].
22 /// 23 ///
23 /// Intended for whole program (non-modular) compilation. 24 /// Intended for whole program (non-modular) compilation.
24 /// 25 ///
25 /// Given the Uri of a file containing a program's `main` method, this function 26 /// Given the Uri of a file containing a program's `main` method, this function
(...skipping 19 matching lines...) Expand all
45 return report("Entry-point file not found: $source"); 46 return report("Entry-point file not found: $source");
46 } 47 }
47 48
48 var pOptions = new ProcessedOptions(options); 49 var pOptions = new ProcessedOptions(options);
49 50
50 if (!await pOptions.validateOptions()) return null; 51 if (!await pOptions.validateOptions()) return null;
51 52
52 try { 53 try {
53 TranslateUri uriTranslator = await pOptions.getUriTranslator(); 54 TranslateUri uriTranslator = await pOptions.getUriTranslator();
54 55
55 var dillTarget = 56 var dillTarget = new DillTarget(
56 new DillTarget(new Ticker(isVerbose: false), uriTranslator, "vm"); 57 new Ticker(isVerbose: false), uriTranslator, "vm_fasta",
58 flags: new TargetFlags(strongMode: options.strongMode));
57 var summary = await pOptions.sdkSummaryProgram; 59 var summary = await pOptions.sdkSummaryProgram;
58 if (summary != null) { 60 if (summary != null) {
59 dillTarget.loader.appendLibraries(summary); 61 dillTarget.loader.appendLibraries(summary);
60 } 62 }
61 63
62 var kernelTarget = new KernelTarget( 64 var kernelTarget =
63 options.fileSystem, dillTarget, uriTranslator, options.strongMode); 65 new KernelTarget(options.fileSystem, dillTarget, uriTranslator);
64 kernelTarget.read(source); 66 kernelTarget.read(source);
65 67
66 await dillTarget.buildOutlines(); 68 await dillTarget.buildOutlines();
67 await kernelTarget.buildOutlines(); 69 await kernelTarget.buildOutlines();
68 Program program = await kernelTarget.buildProgram(trimDependencies: true); 70 Program program = await kernelTarget.buildProgram(trimDependencies: true);
69 71
70 if (kernelTarget.errors.isNotEmpty) { 72 if (kernelTarget.errors.isNotEmpty) {
71 kernelTarget.errors.forEach(report); 73 kernelTarget.errors.forEach(report);
72 return null; 74 return null;
73 } 75 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 } 143 }
142 } 144 }
143 145
144 var pOptions = new ProcessedOptions(options); 146 var pOptions = new ProcessedOptions(options);
145 147
146 if (!await pOptions.validateOptions()) return null; 148 if (!await pOptions.validateOptions()) return null;
147 149
148 try { 150 try {
149 TranslateUri uriTranslator = await pOptions.getUriTranslator(); 151 TranslateUri uriTranslator = await pOptions.getUriTranslator();
150 152
151 var dillTarget = 153 var dillTarget = new DillTarget(
152 new DillTarget(new Ticker(isVerbose: false), uriTranslator, "vm"); 154 new Ticker(isVerbose: false), uriTranslator, "vm_fasta",
155 flags: new TargetFlags(strongMode: options.strongMode));
153 var summary = await pOptions.sdkSummaryProgram; 156 var summary = await pOptions.sdkSummaryProgram;
154 if (summary != null) { 157 if (summary != null) {
155 dillTarget.loader.appendLibraries(summary); 158 dillTarget.loader.appendLibraries(summary);
156 } 159 }
157 160
158 // TODO(sigmund): this is likely not going to work if done naively: if 161 // TODO(sigmund): this is likely not going to work if done naively: if
159 // summaries contain external references we need to ensure they are loaded 162 // summaries contain external references we need to ensure they are loaded
160 // in a specific order. 163 // in a specific order.
161 for (var inputSummary in await pOptions.inputSummariesPrograms) { 164 for (var inputSummary in await pOptions.inputSummariesPrograms) {
162 dillTarget.loader.appendLibraries(inputSummary); 165 dillTarget.loader.appendLibraries(inputSummary);
163 } 166 }
164 167
165 await dillTarget.buildOutlines(); 168 await dillTarget.buildOutlines();
166 169
167 var kernelTarget = new KernelTarget( 170 var kernelTarget =
168 options.fileSystem, dillTarget, uriTranslator, options.strongMode); 171 new KernelTarget(options.fileSystem, dillTarget, uriTranslator);
169 sources.forEach(kernelTarget.read); 172 sources.forEach(kernelTarget.read);
170 await kernelTarget.buildOutlines(); 173 await kernelTarget.buildOutlines();
171 174
172 Program program = await kernelTarget.buildProgram(trimDependencies: true); 175 Program program = await kernelTarget.buildProgram(trimDependencies: true);
173 176
174 if (kernelTarget.errors.isNotEmpty) { 177 if (kernelTarget.errors.isNotEmpty) {
175 kernelTarget.errors.forEach(report); 178 kernelTarget.errors.forEach(report);
176 return null; 179 return null;
177 } 180 }
178 181
179 return program; 182 return program;
180 } on InputError catch (e) { 183 } on InputError catch (e) {
181 options.onError(new SimpleError(e.format())); 184 options.onError(new SimpleError(e.format()));
182 return null; 185 return null;
183 } 186 }
184 } 187 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698