Chromium Code Reviews| 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 /// An entrypoint used to run portions of dart2js and measure its performance. | 5 /// An entrypoint used to run portions of dart2js and measure its performance. |
| 6 library compiler.tool.perf; | 6 library compiler.tool.perf; |
| 7 | 7 |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import 'dart:io'; | 9 import 'dart:io'; |
| 10 | 10 |
| 11 import 'package:compiler/compiler_new.dart'; | 11 import 'package:compiler/compiler_new.dart'; |
| 12 import 'package:compiler/src/apiimpl.dart'; | 12 import 'package:compiler/src/apiimpl.dart'; |
| 13 import 'package:compiler/src/compiler.dart'; | 13 import 'package:compiler/src/compiler.dart'; |
| 14 import 'package:compiler/src/elements/elements.dart'; | 14 import 'package:compiler/src/elements/elements.dart'; |
| 15 import 'package:compiler/src/common.dart'; | 15 import 'package:compiler/src/common.dart'; |
| 16 import 'package:compiler/src/diagnostics/diagnostic_listener.dart'; | 16 import 'package:compiler/src/diagnostics/diagnostic_listener.dart'; |
| 17 import 'package:compiler/src/diagnostics/messages.dart' | 17 import 'package:compiler/src/diagnostics/messages.dart' |
| 18 show Message, MessageTemplate; | 18 show Message, MessageTemplate; |
| 19 import 'package:compiler/src/io/source_file.dart'; | 19 import 'package:compiler/src/io/source_file.dart'; |
| 20 import 'package:compiler/src/options.dart'; | 20 import 'package:compiler/src/options.dart'; |
| 21 import 'package:compiler/src/parser/element_listener.dart' show ScannerOptions; | 21 import 'package:compiler/src/parser/element_listener.dart' show ScannerOptions; |
| 22 import 'package:compiler/src/parser/listener.dart'; | |
| 23 import 'package:compiler/src/parser/node_listener.dart' show NodeListener; | 22 import 'package:compiler/src/parser/node_listener.dart' show NodeListener; |
| 24 import 'package:compiler/src/parser/parser.dart' show Parser; | 23 import 'package:compiler/src/parser/diet_parser_task.dart' show PartialParser; |
| 25 import 'package:compiler/src/parser/partial_parser.dart'; | |
| 26 import 'package:compiler/src/platform_configuration.dart' as platform; | 24 import 'package:compiler/src/platform_configuration.dart' as platform; |
| 27 import 'package:compiler/src/scanner/scanner.dart'; | |
| 28 import 'package:compiler/src/source_file_provider.dart'; | 25 import 'package:compiler/src/source_file_provider.dart'; |
| 29 import 'package:compiler/src/tokens/token.dart' show Token; | |
| 30 import 'package:compiler/src/universe/world_impact.dart' show WorldImpact; | 26 import 'package:compiler/src/universe/world_impact.dart' show WorldImpact; |
| 27 import 'package:front_end/src/fasta/parser.dart' show Listener, Parser; | |
| 28 import 'package:front_end/src/fasta/scanner.dart' show Token, scan; | |
| 31 import 'package:package_config/discovery.dart' show findPackages; | 29 import 'package:package_config/discovery.dart' show findPackages; |
| 32 import 'package:package_config/packages.dart' show Packages; | 30 import 'package:package_config/packages.dart' show Packages; |
| 33 import 'package:package_config/src/util.dart' show checkValidPackageUri; | 31 import 'package:package_config/src/util.dart' show checkValidPackageUri; |
| 34 | 32 |
| 35 /// Cumulative total number of chars scanned. | 33 /// Cumulative total number of chars scanned. |
| 36 int inputSize = 0; | 34 int inputSize = 0; |
| 37 | 35 |
| 38 /// Cumulative time spent scanning. | 36 /// Cumulative time spent scanning. |
| 39 Stopwatch scanTimer = new Stopwatch(); | 37 Stopwatch scanTimer = new Stopwatch(); |
| 40 | 38 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 var next = await loader.loadFile(start.uri.resolve(directive)); | 149 var next = await loader.loadFile(start.uri.resolve(directive)); |
| 152 await collectSources(next, files); | 150 await collectSources(next, files); |
| 153 } | 151 } |
| 154 } | 152 } |
| 155 | 153 |
| 156 /// Uses the diet-parser to parse only directives in [source], returns the | 154 /// Uses the diet-parser to parse only directives in [source], returns the |
| 157 /// URIs seen in import/export/part directives in the file. | 155 /// URIs seen in import/export/part directives in the file. |
| 158 Set<String> parseDirectives(SourceFile source) { | 156 Set<String> parseDirectives(SourceFile source) { |
| 159 var tokens = tokenize(source); | 157 var tokens = tokenize(source); |
| 160 var listener = new DirectiveListener(); | 158 var listener = new DirectiveListener(); |
| 161 new PartialParser(listener).parseUnit(tokens); | 159 new PartialParser(listener).parseUnit(tokens); |
|
Siggi Cherem (dart-lang)
2017/02/01 15:30:35
fwiw - I think we can now switch to the top-level
ahe
2017/02/01 15:34:06
OK, I'll let you decide what to do.
| |
| 162 return listener.targets; | 160 return listener.targets; |
| 163 } | 161 } |
| 164 | 162 |
| 165 /// Parse the full body of [source]. | 163 /// Parse the full body of [source]. |
| 166 parseFull(SourceFile source) { | 164 parseFull(SourceFile source) { |
| 167 var tokens = tokenize(source); | 165 var tokens = tokenize(source); |
| 168 NodeListener listener = new NodeListener( | 166 NodeListener listener = new NodeListener( |
| 169 const ScannerOptions(canUseNative: true), new FakeReporter(), null); | 167 const ScannerOptions(canUseNative: true), new FakeReporter(), null); |
| 170 Parser parser = new Parser(listener); | 168 Parser parser = new Parser(listener); |
| 171 parser.parseUnit(tokens); | 169 parser.parseUnit(tokens); |
| 172 return listener.popNode(); | 170 return listener.popNode(); |
| 173 } | 171 } |
| 174 | 172 |
| 175 /// Scan [source] and return the first token produced by the scanner. | 173 /// Scan [source] and return the first token produced by the scanner. |
| 176 Token tokenize(SourceFile source) { | 174 Token tokenize(SourceFile source) { |
| 177 scanTimer.start(); | 175 scanTimer.start(); |
| 178 var token = new Scanner(source).tokenize(); | 176 var token = scan(source.slowUtf8ZeroTerminatedBytes()).tokens; |
| 179 scanTimer.stop(); | 177 scanTimer.stop(); |
| 180 return token; | 178 return token; |
| 181 } | 179 } |
| 182 | 180 |
| 183 /// Report that metric [name] took [time] micro-seconds to process | 181 /// Report that metric [name] took [time] micro-seconds to process |
| 184 /// [inputSize] characters. | 182 /// [inputSize] characters. |
| 185 void report(String name, int time) { | 183 void report(String name, int time) { |
| 186 var sb = new StringBuffer(); | 184 var sb = new StringBuffer(); |
| 187 var padding = ' ' * (20 - name.length); | 185 var padding = ' ' * (20 - name.length); |
| 188 sb.write('$name:$padding $time us, ${time ~/ 1000} ms'); | 186 sb.write('$name:$padding $time us, ${time ~/ 1000} ms'); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 227 Uri _platformConfigUri = _libraryRoot.resolve('lib/dart_server.platform'); | 225 Uri _platformConfigUri = _libraryRoot.resolve('lib/dart_server.platform'); |
| 228 | 226 |
| 229 class FakeReporter extends DiagnosticReporter { | 227 class FakeReporter extends DiagnosticReporter { |
| 230 final hasReportedError = false; | 228 final hasReportedError = false; |
| 231 final options = new FakeReporterOptions(); | 229 final options = new FakeReporterOptions(); |
| 232 | 230 |
| 233 withCurrentElement(e, f) => f(); | 231 withCurrentElement(e, f) => f(); |
| 234 log(m) => print(m); | 232 log(m) => print(m); |
| 235 internalError(_, m) => print(m); | 233 internalError(_, m) => print(m); |
| 236 spanFromSpannable(_) => null; | 234 spanFromSpannable(_) => null; |
| 235 spanFromToken(_) => null; | |
| 237 | 236 |
| 238 void reportError(DiagnosticMessage message, | 237 void reportError(DiagnosticMessage message, |
| 239 [List<DiagnosticMessage> infos = const <DiagnosticMessage>[]]) { | 238 [List<DiagnosticMessage> infos = const <DiagnosticMessage>[]]) { |
| 240 print('error: ${message.message}'); | 239 print('error: ${message.message}'); |
| 241 } | 240 } |
| 242 | 241 |
| 243 void reportWarning(DiagnosticMessage message, | 242 void reportWarning(DiagnosticMessage message, |
| 244 [List<DiagnosticMessage> infos = const <DiagnosticMessage>[]]) { | 243 [List<DiagnosticMessage> infos = const <DiagnosticMessage>[]]) { |
| 245 print('warning: ${message.message}'); | 244 print('warning: ${message.message}'); |
| 246 } | 245 } |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 381 // TODO(sigmund): more diagnostics? | 380 // TODO(sigmund): more diagnostics? |
| 382 print('compilation failed!'); | 381 print('compilation failed!'); |
| 383 exit(1); | 382 exit(1); |
| 384 } | 383 } |
| 385 | 384 |
| 386 closeResolution(); | 385 closeResolution(); |
| 387 var program = (backend as dynamic).kernelTask.program; | 386 var program = (backend as dynamic).kernelTask.program; |
| 388 print('total libraries: ${program.libraries.length}'); | 387 print('total libraries: ${program.libraries.length}'); |
| 389 }); | 388 }); |
| 390 } | 389 } |
| OLD | NEW |