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

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

Issue 2785883005: Make top-level scope implicit. (Closed)
Patch Set: Created 3 years, 8 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
« no previous file with comments | « pkg/front_end/lib/src/fasta/source/scope_listener.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 fasta and measure its performance. 5 /// An entrypoint used to run portions of fasta and measure its performance.
6 library front_end.tool.fasta_perf; 6 library front_end.tool.fasta_perf;
7 7
8 import 'dart:async'; 8 import 'dart:async';
9 import 'dart:io'; 9 import 'dart:io';
10 10
11 import 'package:analyzer/src/fasta/ast_builder.dart'; 11 import 'package:analyzer/src/fasta/ast_builder.dart';
12 import 'package:front_end/src/fasta/dill/dill_target.dart' show DillTarget; 12 import 'package:front_end/src/fasta/dill/dill_target.dart' show DillTarget;
13 import 'package:front_end/src/fasta/kernel/kernel_target.dart' 13 import 'package:front_end/src/fasta/kernel/kernel_target.dart'
14 show KernelTarget; 14 show KernelTarget;
15 import 'package:front_end/src/fasta/parser.dart'; 15 import 'package:front_end/src/fasta/parser.dart';
16 import 'package:front_end/src/fasta/scanner.dart'; 16 import 'package:front_end/src/fasta/scanner.dart';
17 import 'package:front_end/src/fasta/scanner/io.dart' show readBytesFromFileSync; 17 import 'package:front_end/src/fasta/scanner/io.dart' show readBytesFromFileSync;
18 import 'package:front_end/src/fasta/scope.dart' show Scope;
19 import 'package:front_end/src/fasta/ticker.dart' show Ticker; 18 import 'package:front_end/src/fasta/ticker.dart' show Ticker;
20 import 'package:front_end/src/fasta/translate_uri.dart' show TranslateUri; 19 import 'package:front_end/src/fasta/translate_uri.dart' show TranslateUri;
21 import 'package:front_end/src/fasta/translate_uri.dart'; 20 import 'package:front_end/src/fasta/translate_uri.dart';
22 21
23 /// Cumulative total number of chars scanned. 22 /// Cumulative total number of chars scanned.
24 int inputSize = 0; 23 int inputSize = 0;
25 24
26 /// Cumulative time spent scanning. 25 /// Cumulative time spent scanning.
27 Stopwatch scanTimer = new Stopwatch(); 26 Stopwatch scanTimer = new Stopwatch();
28 27
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 'parse', parseTimer.elapsedMicroseconds - scanTimer.elapsedMicroseconds); 217 'parse', parseTimer.elapsedMicroseconds - scanTimer.elapsedMicroseconds);
219 } 218 }
220 219
221 /// Parse the full body of [source]. 220 /// Parse the full body of [source].
222 parseFull(Uri uri, List<int> source) { 221 parseFull(Uri uri, List<int> source) {
223 var tokens = tokenize(source); 222 var tokens = tokenize(source);
224 Parser parser = new Parser(new _PartialAstBuilder(uri)); 223 Parser parser = new Parser(new _PartialAstBuilder(uri));
225 parser.parseUnit(tokens); 224 parser.parseUnit(tokens);
226 } 225 }
227 226
228 class _EmptyScope extends Scope {
229 _EmptyScope() : super({}, null);
230 }
231
232 // Note: AstBuilder doesn't build compilation-units or classes, only method 227 // Note: AstBuilder doesn't build compilation-units or classes, only method
233 // bodies. So this listener is not feature complete. 228 // bodies. So this listener is not feature complete.
234 class _PartialAstBuilder extends AstBuilder { 229 class _PartialAstBuilder extends AstBuilder {
235 _PartialAstBuilder(Uri uri) 230 _PartialAstBuilder(Uri uri) : super(null, null, null, null, null, uri);
236 : super(null, null, null, null, new _EmptyScope(), uri);
237 231
238 // Note: this method converts the body to kernel, so we skip that here. 232 // Note: this method converts the body to kernel, so we skip that here.
239 @override 233 @override
240 finishFunction(formals, asyncModifier, body) {} 234 finishFunction(formals, asyncModifier, body) {}
241 } 235 }
242 236
243 // Invoke the fasta kernel generator for the program starting in [entryUri] 237 // Invoke the fasta kernel generator for the program starting in [entryUri]
244 // TODO(sigmund): update to uyse the frontend api once fasta is beind hit. 238 // TODO(sigmund): update to uyse the frontend api once fasta is beind hit.
245 generateKernel(Uri entryUri, {bool compileSdk: true}) async { 239 generateKernel(Uri entryUri, {bool compileSdk: true}) async {
246 // TODO(sigmund): this is here only to compute the input size, 240 // TODO(sigmund): this is here only to compute the input size,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 /// Report that metric [name] took [time] micro-seconds to process 281 /// Report that metric [name] took [time] micro-seconds to process
288 /// [inputSize] characters. 282 /// [inputSize] characters.
289 void report(String name, int time) { 283 void report(String name, int time) {
290 var sb = new StringBuffer(); 284 var sb = new StringBuffer();
291 var padding = ' ' * (20 - name.length); 285 var padding = ' ' * (20 - name.length);
292 sb.write('$name:$padding $time us, ${time ~/ 1000} ms'); 286 sb.write('$name:$padding $time us, ${time ~/ 1000} ms');
293 var invSpeed = (time * 1000 / inputSize).toStringAsFixed(2); 287 var invSpeed = (time * 1000 / inputSize).toStringAsFixed(2);
294 sb.write(', $invSpeed ns/char'); 288 sb.write(', $invSpeed ns/char');
295 print('$sb'); 289 print('$sb');
296 } 290 }
OLDNEW
« no previous file with comments | « pkg/front_end/lib/src/fasta/source/scope_listener.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698