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 /// 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 'package:kernel/target/targets.dart' show TargetFlags; |
| 17 import 'package:kernel/target/vm_fasta.dart' show VmFastaTarget; |
17 import 'src/fasta/ticker.dart' show Ticker; | 18 import 'src/fasta/ticker.dart' show Ticker; |
18 import 'src/fasta/translate_uri.dart' show TranslateUri; | 19 import 'src/fasta/translate_uri.dart' show TranslateUri; |
19 import 'src/simple_error.dart'; | 20 import 'src/simple_error.dart'; |
20 | 21 |
21 /// Generates a kernel representation of the program whose main library is in | 22 /// Generates a kernel representation of the program whose main library is in |
22 /// the given [source]. | 23 /// the given [source]. |
23 /// | 24 /// |
24 /// Intended for whole program (non-modular) compilation. | 25 /// Intended for whole program (non-modular) compilation. |
25 /// | 26 /// |
26 /// Given the Uri of a file containing a program's `main` method, this function | 27 /// Given the Uri of a file containing a program's `main` method, this function |
(...skipping 19 matching lines...) Expand all Loading... |
46 return report("Entry-point file not found: $source"); | 47 return report("Entry-point file not found: $source"); |
47 } | 48 } |
48 | 49 |
49 var pOptions = new ProcessedOptions(options); | 50 var pOptions = new ProcessedOptions(options); |
50 | 51 |
51 if (!await pOptions.validateOptions()) return null; | 52 if (!await pOptions.validateOptions()) return null; |
52 | 53 |
53 try { | 54 try { |
54 TranslateUri uriTranslator = await pOptions.getUriTranslator(); | 55 TranslateUri uriTranslator = await pOptions.getUriTranslator(); |
55 | 56 |
56 var dillTarget = new DillTarget( | 57 var dillTarget = new DillTarget(new Ticker(isVerbose: false), uriTranslator, |
57 new Ticker(isVerbose: false), uriTranslator, "vm_fasta", | 58 new VmFastaTarget(new TargetFlags(strongMode: options.strongMode))); |
58 flags: new TargetFlags(strongMode: options.strongMode)); | |
59 var summary = await pOptions.sdkSummaryProgram; | 59 var summary = await pOptions.sdkSummaryProgram; |
60 if (summary != null) { | 60 if (summary != null) { |
61 dillTarget.loader.appendLibraries(summary); | 61 dillTarget.loader.appendLibraries(summary); |
62 } | 62 } |
63 | 63 |
64 var kernelTarget = | 64 var kernelTarget = |
65 new KernelTarget(options.fileSystem, dillTarget, uriTranslator); | 65 new KernelTarget(options.fileSystem, dillTarget, uriTranslator); |
66 kernelTarget.read(source); | 66 kernelTarget.read(source); |
67 | 67 |
68 await dillTarget.buildOutlines(); | 68 await dillTarget.buildOutlines(); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 } | 143 } |
144 } | 144 } |
145 | 145 |
146 var pOptions = new ProcessedOptions(options); | 146 var pOptions = new ProcessedOptions(options); |
147 | 147 |
148 if (!await pOptions.validateOptions()) return null; | 148 if (!await pOptions.validateOptions()) return null; |
149 | 149 |
150 try { | 150 try { |
151 TranslateUri uriTranslator = await pOptions.getUriTranslator(); | 151 TranslateUri uriTranslator = await pOptions.getUriTranslator(); |
152 | 152 |
153 var dillTarget = new DillTarget( | 153 var dillTarget = new DillTarget(new Ticker(isVerbose: false), uriTranslator, |
154 new Ticker(isVerbose: false), uriTranslator, "vm_fasta", | 154 new VmFastaTarget(new TargetFlags(strongMode: options.strongMode))); |
155 flags: new TargetFlags(strongMode: options.strongMode)); | |
156 var summary = await pOptions.sdkSummaryProgram; | 155 var summary = await pOptions.sdkSummaryProgram; |
157 if (summary != null) { | 156 if (summary != null) { |
158 dillTarget.loader.appendLibraries(summary); | 157 dillTarget.loader.appendLibraries(summary); |
159 } | 158 } |
160 | 159 |
161 // TODO(sigmund): this is likely not going to work if done naively: if | 160 // TODO(sigmund): this is likely not going to work if done naively: if |
162 // summaries contain external references we need to ensure they are loaded | 161 // summaries contain external references we need to ensure they are loaded |
163 // in a specific order. | 162 // in a specific order. |
164 for (var inputSummary in await pOptions.inputSummariesPrograms) { | 163 for (var inputSummary in await pOptions.inputSummariesPrograms) { |
165 dillTarget.loader.appendLibraries(inputSummary); | 164 dillTarget.loader.appendLibraries(inputSummary); |
(...skipping 12 matching lines...) Expand all Loading... |
178 kernelTarget.errors.forEach(report); | 177 kernelTarget.errors.forEach(report); |
179 return null; | 178 return null; |
180 } | 179 } |
181 | 180 |
182 return program; | 181 return program; |
183 } on InputError catch (e) { | 182 } on InputError catch (e) { |
184 options.onError(new SimpleError(e.format())); | 183 options.onError(new SimpleError(e.format())); |
185 return null; | 184 return null; |
186 } | 185 } |
187 } | 186 } |
OLD | NEW |