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

Side by Side Diff: pkg/front_end/tool/perf.dart

Issue 2856223003: Implement the kernel_generator API using fasta (Closed)
Patch Set: Created 3 years, 7 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 /// An entrypoint used to run portions of front_end and measure its performance. 5 /// An entrypoint used to run portions of front_end and measure its performance.
6 library front_end.tool.perf; 6 library front_end.tool.perf;
7 7
8 import 'dart:async'; 8 import 'dart:async';
9 import 'dart:io' show Directory, File, Platform, exit; 9 import 'dart:io' show Directory, File, Platform, exit;
10 10
11 import 'package:analyzer/dart/ast/ast.dart'; 11 import 'package:analyzer/dart/ast/ast.dart';
12 import 'package:analyzer/error/listener.dart'; 12 import 'package:analyzer/error/listener.dart';
13 import 'package:analyzer/file_system/file_system.dart' show ResourceUriResolver; 13 import 'package:analyzer/file_system/file_system.dart' show ResourceUriResolver;
14 import 'package:analyzer/file_system/physical_file_system.dart' 14 import 'package:analyzer/file_system/physical_file_system.dart'
15 show PhysicalResourceProvider; 15 show PhysicalResourceProvider;
16 import 'package:analyzer/source/package_map_resolver.dart'; 16 import 'package:analyzer/source/package_map_resolver.dart';
17 import 'package:analyzer/src/context/builder.dart'; 17 import 'package:analyzer/src/context/builder.dart';
18 import 'package:analyzer/src/dart/sdk/sdk.dart' show FolderBasedDartSdk; 18 import 'package:analyzer/src/dart/sdk/sdk.dart' show FolderBasedDartSdk;
19 import 'package:analyzer/src/generated/engine.dart' show AnalysisOptionsImpl;
19 import 'package:analyzer/src/generated/parser.dart'; 20 import 'package:analyzer/src/generated/parser.dart';
20 import 'package:analyzer/src/generated/source.dart'; 21 import 'package:analyzer/src/generated/source.dart';
21 import 'package:analyzer/src/generated/source_io.dart'; 22 import 'package:analyzer/src/generated/source_io.dart';
23 import 'package:analyzer/src/kernel/loader.dart';
22 import 'package:analyzer/src/summary/format.dart'; 24 import 'package:analyzer/src/summary/format.dart';
23 import 'package:analyzer/src/summary/idl.dart'; 25 import 'package:analyzer/src/summary/idl.dart';
24 import 'package:analyzer/src/summary/link.dart'; 26 import 'package:analyzer/src/summary/link.dart';
25 import 'package:analyzer/src/summary/summarize_ast.dart'; 27 import 'package:analyzer/src/summary/summarize_ast.dart';
28 import 'package:front_end/compilation_error.dart';
26 import 'package:front_end/compiler_options.dart'; 29 import 'package:front_end/compiler_options.dart';
27 import 'package:front_end/kernel_generator.dart';
28 import 'package:front_end/src/scanner/reader.dart'; 30 import 'package:front_end/src/scanner/reader.dart';
29 import 'package:front_end/src/scanner/scanner.dart'; 31 import 'package:front_end/src/scanner/scanner.dart';
30 import 'package:front_end/src/scanner/token.dart'; 32 import 'package:front_end/src/scanner/token.dart';
31 import 'package:kernel/kernel.dart' hide Source; 33 import 'package:kernel/kernel.dart' hide Source;
32 import 'package:package_config/discovery.dart'; 34 import 'package:package_config/discovery.dart';
33 import 'package:path/path.dart' as path; 35 import 'package:path/path.dart' as path;
36 import 'package:source_span/source_span.dart' show SourceSpan;
34 37
35 main(List<String> args) async { 38 main(List<String> args) async {
36 // TODO(sigmund): provide sdk folder as well. 39 // TODO(sigmund): provide sdk folder as well.
37 if (args.length < 2) { 40 if (args.length < 2) {
38 print('usage: perf.dart <bench-id> <entry.dart>'); 41 print('usage: perf.dart <bench-id> <entry.dart>');
39 exit(1); 42 exit(1);
40 } 43 }
41 44
42 var bench = args[0]; 45 var bench = args[0];
43 var entryUri = Uri.base.resolve(args[1]); 46 var entryUri = Uri.base.resolve(args[1]);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 var options = new CompilerOptions() 129 var options = new CompilerOptions()
127 ..strongMode = false 130 ..strongMode = false
128 ..compileSdk = compileSdk 131 ..compileSdk = compileSdk
129 ..packagesFileUri = _repoUri.resolve('.packages') 132 ..packagesFileUri = _repoUri.resolve('.packages')
130 ..onError = ((e) => print('${e.message}')); 133 ..onError = ((e) => print('${e.message}'));
131 if (useSdkSummary) { 134 if (useSdkSummary) {
132 options.sdkSummary = _sdkUri.resolve('lib/_internal/spec.sum'); 135 options.sdkSummary = _sdkUri.resolve('lib/_internal/spec.sum');
133 } else { 136 } else {
134 options.sdkRoot = _sdkUri; 137 options.sdkRoot = _sdkUri;
135 } 138 }
136 Program program = await kernelForProgram(entryUri, options); 139 Program program = await _kernelForProgramViaDartk(entryUri, options);
137 dartkTimer.stop(); 140 dartkTimer.stop();
138 var suffix = useSdkSummary ? '_sum' : ''; 141 var suffix = useSdkSummary ? '_sum' : '';
139 report('kernel_gen_e2e${suffix}', dartkTimer.elapsedMicroseconds); 142 report('kernel_gen_e2e${suffix}', dartkTimer.elapsedMicroseconds);
140 return program; 143 return program;
141 } 144 }
142 145
146 _kernelForProgramViaDartk(Uri source, CompilerOptions options) async {
147 var loader = await _createLoader(options, entry: source);
148 if (options.compileSdk) {
149 options.additionalLibraries.forEach(loader.loadLibrary);
150 }
151 loader.loadProgram(source, compileSdk: options.compileSdk);
152 _reportErrors(loader.errors, options.onError);
153 return loader.program;
154 }
155
156 /// Create a [DartLoader] using the provided [options].
157 ///
158 /// If [options] contain no configuration to resolve `.packages`, the [entry]
159 /// file will be used to search for a `.packages` file.
160 Future<DartLoader> _createLoader(CompilerOptions options,
161 {Program program, Uri entry}) async {
162 var kernelOptions = _convertOptions(options);
163 var packages = await createPackages(_uriToPath(options.packagesFileUri),
164 discoveryPath: entry?.path);
165 var loader =
166 new DartLoader(program ?? new Program(), kernelOptions, packages);
167 var patchPaths = <String, List<String>>{};
168
169 // TODO(sigmund,paulberry): use ProcessedOptions so that we can resolve the
170 // URIs correctly even if sdkRoot is inferred and not specified explicitly.
171 String resolve(Uri patch) => _uriToPath(options.sdkRoot.resolveUri(patch));
172
173 options.targetPatches.forEach((uri, patches) {
174 patchPaths['$uri'] = patches.map(resolve).toList();
175 });
176 AnalysisOptionsImpl analysisOptions = loader.context.analysisOptions;
177 analysisOptions.patchPaths = patchPaths;
178 return loader;
179 }
180
181 DartOptions _convertOptions(CompilerOptions options) {
182 return new DartOptions(
183 strongMode: options.strongMode,
184 sdk: _uriToPath(options.sdkRoot),
185 // TODO(sigmund): make it possible to use summaries and still compile the
186 // sdk sources.
187 sdkSummary: options.compileSdk ? null : _uriToPath(options.sdkSummary),
188 packagePath: _uriToPath(options.packagesFileUri),
189 customUriMappings: options.uriOverride,
190 declaredVariables: options.declaredVariables);
191 }
192
193 String _uriToPath(Uri uri) {
194 if (uri == null) return null;
195 if (uri.scheme != 'file') {
196 throw new StateError('Only file URIs are supported: $uri');
197 }
198 return uri.toFilePath();
199 }
200
201 void _reportErrors(List errors, ErrorHandler onError) {
202 if (onError == null) return;
203 for (var error in errors) {
204 onError(new _DartkError(error));
205 }
206 }
207
208 class _DartkError implements CompilationError {
209 String get correction => null;
210 SourceSpan get span => null;
211 final String message;
212 _DartkError(this.message);
213 }
214
143 /// Generates unlinkmed summaries for all files in [files], and returns them in 215 /// Generates unlinkmed summaries for all files in [files], and returns them in
144 /// an [_UnlinkedSummaries] container. 216 /// an [_UnlinkedSummaries] container.
145 _UnlinkedSummaries generateUnlinkedSummaries(Set<Source> files) { 217 _UnlinkedSummaries generateUnlinkedSummaries(Set<Source> files) {
146 var unlinkedSummaries = new _UnlinkedSummaries(); 218 var unlinkedSummaries = new _UnlinkedSummaries();
147 for (var source in files) { 219 for (var source in files) {
148 unlinkedSummaries.summariesByUri[source.uri.toString()] = 220 unlinkedSummaries.summariesByUri[source.uri.toString()] =
149 unlinkedSummarize(source); 221 unlinkedSummarize(source);
150 } 222 }
151 return unlinkedSummaries; 223 return unlinkedSummaries;
152 } 224 }
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 class _Scanner extends Scanner { 435 class _Scanner extends Scanner {
364 _Scanner(String contents) : super.create(new CharSequenceReader(contents)) { 436 _Scanner(String contents) : super.create(new CharSequenceReader(contents)) {
365 preserveComments = false; 437 preserveComments = false;
366 } 438 }
367 439
368 @override 440 @override
369 void reportError(errorCode, int offset, List<Object> arguments) { 441 void reportError(errorCode, int offset, List<Object> arguments) {
370 // ignore errors. 442 // ignore errors.
371 } 443 }
372 } 444 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698