| 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/kernel/task.dart'; | 14 import 'package:compiler/src/kernel/task.dart'; |
| 15 import 'package:compiler/src/elements/elements.dart'; | 15 import 'package:compiler/src/elements/elements.dart'; |
| 16 import 'package:compiler/src/common.dart'; | 16 import 'package:compiler/src/common.dart'; |
| 17 import 'package:compiler/src/diagnostics/diagnostic_listener.dart'; | 17 import 'package:compiler/src/diagnostics/diagnostic_listener.dart'; |
| 18 import 'package:compiler/src/diagnostics/messages.dart' | 18 import 'package:compiler/src/diagnostics/messages.dart' |
| 19 show Message, MessageTemplate; | 19 show Message, MessageTemplate; |
| 20 import 'package:compiler/src/io/source_file.dart'; | 20 import 'package:compiler/src/io/source_file.dart'; |
| 21 import 'package:compiler/src/options.dart' show ParserOptions; | |
| 22 import 'package:compiler/src/options.dart'; | 21 import 'package:compiler/src/options.dart'; |
| 23 import 'package:compiler/src/parser/element_listener.dart' show ScannerOptions; | 22 import 'package:compiler/src/parser/element_listener.dart' show ScannerOptions; |
| 24 import 'package:compiler/src/parser/listener.dart'; | 23 import 'package:compiler/src/parser/listener.dart'; |
| 25 import 'package:compiler/src/parser/node_listener.dart' show NodeListener; | 24 import 'package:compiler/src/parser/node_listener.dart' show NodeListener; |
| 26 import 'package:compiler/src/parser/parser.dart' show Parser; | 25 import 'package:compiler/src/parser/parser.dart' show Parser; |
| 27 import 'package:compiler/src/parser/partial_parser.dart'; | 26 import 'package:compiler/src/parser/partial_parser.dart'; |
| 28 import 'package:compiler/src/platform_configuration.dart' as platform; | 27 import 'package:compiler/src/platform_configuration.dart' as platform; |
| 29 import 'package:compiler/src/scanner/scanner.dart'; | 28 import 'package:compiler/src/scanner/scanner.dart'; |
| 30 import 'package:compiler/src/source_file_provider.dart'; | 29 import 'package:compiler/src/source_file_provider.dart'; |
| 31 import 'package:compiler/src/tokens/token.dart' show Token; | 30 import 'package:compiler/src/tokens/token.dart' show Token; |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 var next = await loader.loadFile(start.uri.resolve(directive)); | 174 var next = await loader.loadFile(start.uri.resolve(directive)); |
| 176 await collectSources(next, files); | 175 await collectSources(next, files); |
| 177 } | 176 } |
| 178 } | 177 } |
| 179 | 178 |
| 180 /// Uses the diet-parser to parse only directives in [source], returns the | 179 /// Uses the diet-parser to parse only directives in [source], returns the |
| 181 /// URIs seen in import/export/part directives in the file. | 180 /// URIs seen in import/export/part directives in the file. |
| 182 Set<String> parseDirectives(SourceFile source) { | 181 Set<String> parseDirectives(SourceFile source) { |
| 183 var tokens = tokenize(source); | 182 var tokens = tokenize(source); |
| 184 var listener = new DirectiveListener(); | 183 var listener = new DirectiveListener(); |
| 185 new PartialParser(listener, const _ParserOptions()).parseUnit(tokens); | 184 new PartialParser(listener).parseUnit(tokens); |
| 186 return listener.targets; | 185 return listener.targets; |
| 187 } | 186 } |
| 188 | 187 |
| 189 /// Parse the full body of [source]. | 188 /// Parse the full body of [source]. |
| 190 parseFull(SourceFile source) { | 189 parseFull(SourceFile source) { |
| 191 var tokens = tokenize(source); | 190 var tokens = tokenize(source); |
| 192 NodeListener listener = new NodeListener( | 191 NodeListener listener = new NodeListener( |
| 193 const ScannerOptions(canUseNative: true), new FakeReporter(), null); | 192 const ScannerOptions(canUseNative: true), new FakeReporter(), null); |
| 194 Parser parser = new Parser(listener, const _ParserOptions()); | 193 Parser parser = new Parser(listener); |
| 195 parser.parseUnit(tokens); | 194 parser.parseUnit(tokens); |
| 196 return listener.popNode(); | 195 return listener.popNode(); |
| 197 } | 196 } |
| 198 | 197 |
| 199 /// Scan [source] and return the first token produced by the scanner. | 198 /// Scan [source] and return the first token produced by the scanner. |
| 200 Token tokenize(SourceFile source) { | 199 Token tokenize(SourceFile source) { |
| 201 scanTimer.start(); | 200 scanTimer.start(); |
| 202 scanTotalChars += source.length; | 201 scanTotalChars += source.length; |
| 203 var token = new Scanner(source).tokenize(); | 202 var token = new Scanner(source).tokenize(); |
| 204 scanTimer.stop(); | 203 scanTimer.stop(); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 } | 325 } |
| 327 | 326 |
| 328 Uri _translatePackageUri(Uri uri) { | 327 Uri _translatePackageUri(Uri uri) { |
| 329 checkValidPackageUri(uri); | 328 checkValidPackageUri(uri); |
| 330 return packages.resolve(uri, notFound: (_) { | 329 return packages.resolve(uri, notFound: (_) { |
| 331 print('$uri not found'); | 330 print('$uri not found'); |
| 332 }); | 331 }); |
| 333 } | 332 } |
| 334 } | 333 } |
| 335 | 334 |
| 336 class _ParserOptions implements ParserOptions { | |
| 337 const _ParserOptions(); | |
| 338 bool get enableGenericMethodSyntax => true; | |
| 339 } | |
| 340 | |
| 341 generateKernel(Uri entryUri) async { | 335 generateKernel(Uri entryUri) async { |
| 342 var timer = new Stopwatch()..start(); | 336 var timer = new Stopwatch()..start(); |
| 343 var options = new CompilerOptions( | 337 var options = new CompilerOptions( |
| 344 entryPoint: entryUri, | 338 entryPoint: entryUri, |
| 345 libraryRoot: _libraryRoot, | 339 libraryRoot: _libraryRoot, |
| 346 packagesDiscoveryProvider: findPackages, | 340 packagesDiscoveryProvider: findPackages, |
| 347 platformConfigUri: _platformConfigUri, | 341 platformConfigUri: _platformConfigUri, |
| 348 useKernel: true, | 342 useKernel: true, |
| 349 verbose: false); // set to true to debug internal timings | 343 verbose: false); // set to true to debug internal timings |
| 350 var inputProvider = new CompilerSourceFileProvider(); | 344 var inputProvider = new CompilerSourceFileProvider(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 // TODO(sigmund): more diagnostics? | 389 // TODO(sigmund): more diagnostics? |
| 396 print("compilation failed!"); | 390 print("compilation failed!"); |
| 397 exit(1); | 391 exit(1); |
| 398 } | 392 } |
| 399 | 393 |
| 400 closeResolution(); | 394 closeResolution(); |
| 401 var program = (backend as dynamic).kernelTask.program; | 395 var program = (backend as dynamic).kernelTask.program; |
| 402 print('total libraries: ${program.libraries.length}'); | 396 print('total libraries: ${program.libraries.length}'); |
| 403 }); | 397 }); |
| 404 } | 398 } |
| OLD | NEW |