| 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 library kernel.treeshaker_dump; | 4 library kernel.treeshaker_dump; |
| 5 | 5 |
| 6 import 'dart:io'; | 6 import 'dart:io'; |
| 7 import 'package:kernel/core_types.dart'; |
| 7 import 'package:kernel/kernel.dart'; | 8 import 'package:kernel/kernel.dart'; |
| 8 import 'package:kernel/transformations/treeshaker.dart'; | 9 import 'package:kernel/transformations/treeshaker.dart'; |
| 9 import 'package:args/args.dart'; | 10 import 'package:args/args.dart'; |
| 10 import 'package:path/path.dart' as pathlib; | 11 import 'package:path/path.dart' as pathlib; |
| 11 import 'package:kernel/text/ast_to_text.dart'; | 12 import 'package:kernel/text/ast_to_text.dart'; |
| 12 | 13 |
| 13 ArgParser parser = new ArgParser(allowTrailingOptions: true) | 14 ArgParser parser = new ArgParser(allowTrailingOptions: true) |
| 14 ..addFlag('used', help: 'Print used members', negatable: false) | 15 ..addFlag('used', help: 'Print used members', negatable: false) |
| 15 ..addFlag('unused', help: 'Print unused members', negatable: false) | 16 ..addFlag('unused', help: 'Print unused members', negatable: false) |
| 16 ..addFlag('instantiated', | 17 ..addFlag('instantiated', |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 String filename = options.rest.single; | 58 String filename = options.rest.single; |
| 58 | 59 |
| 59 if (options['output'] != null && !options['diff']) { | 60 if (options['output'] != null && !options['diff']) { |
| 60 print('--output must be used with --diff'); | 61 print('--output must be used with --diff'); |
| 61 exit(1); | 62 exit(1); |
| 62 } | 63 } |
| 63 | 64 |
| 64 bool strong = options['strong']; | 65 bool strong = options['strong']; |
| 65 | 66 |
| 66 Program program = loadProgramFromBinary(filename); | 67 Program program = loadProgramFromBinary(filename); |
| 67 TreeShaker shaker = new TreeShaker(program, strongMode: strong); | 68 CoreTypes coreTypes = new CoreTypes(program); |
| 69 TreeShaker shaker = new TreeShaker(coreTypes, program, strongMode: strong); |
| 68 int totalClasses = 0; | 70 int totalClasses = 0; |
| 69 int totalInstantiationCandidates = 0; | 71 int totalInstantiationCandidates = 0; |
| 70 int totalMembers = 0; | 72 int totalMembers = 0; |
| 71 int usedClasses = 0; | 73 int usedClasses = 0; |
| 72 int instantiatedClasses = 0; | 74 int instantiatedClasses = 0; |
| 73 int usedMembers = 0; | 75 int usedMembers = 0; |
| 74 | 76 |
| 75 void visitMember(Member member) { | 77 void visitMember(Member member) { |
| 76 if (member.isAbstract) return; // Abstract members are not relevant. | 78 if (member.isAbstract) return; // Abstract members are not relevant. |
| 77 ++totalMembers; | 79 ++totalMembers; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 | 122 |
| 121 if (options['diff']) { | 123 if (options['diff']) { |
| 122 String name = pathlib.basenameWithoutExtension(filename); | 124 String name = pathlib.basenameWithoutExtension(filename); |
| 123 String outputDir = options['output'] ?? ''; | 125 String outputDir = options['output'] ?? ''; |
| 124 String beforeFile = pathlib.join(outputDir, '$name.before.txt'); | 126 String beforeFile = pathlib.join(outputDir, '$name.before.txt'); |
| 125 String afterFile = pathlib.join(outputDir, '$name.after.txt'); | 127 String afterFile = pathlib.join(outputDir, '$name.after.txt'); |
| 126 NameSystem names = new NameSystem(); | 128 NameSystem names = new NameSystem(); |
| 127 StringBuffer before = new StringBuffer(); | 129 StringBuffer before = new StringBuffer(); |
| 128 new Printer(before, syntheticNames: names).writeProgramFile(program); | 130 new Printer(before, syntheticNames: names).writeProgramFile(program); |
| 129 new File(beforeFile).writeAsStringSync('$before'); | 131 new File(beforeFile).writeAsStringSync('$before'); |
| 130 new TreeShaker(program, strongMode: strong).transform(program); | 132 new TreeShaker(coreTypes, program, strongMode: strong).transform(program); |
| 131 StringBuffer after = new StringBuffer(); | 133 StringBuffer after = new StringBuffer(); |
| 132 new Printer(after, syntheticNames: names).writeProgramFile(program); | 134 new Printer(after, syntheticNames: names).writeProgramFile(program); |
| 133 new File(afterFile).writeAsStringSync('$after'); | 135 new File(afterFile).writeAsStringSync('$after'); |
| 134 print('Text written to $beforeFile and $afterFile'); | 136 print('Text written to $beforeFile and $afterFile'); |
| 135 } | 137 } |
| 136 } | 138 } |
| 137 | 139 |
| 138 String ratio(num x, num total) { | 140 String ratio(num x, num total) { |
| 139 return '$x / $total (${percent(x, total)})'; | 141 return '$x / $total (${percent(x, total)})'; |
| 140 } | 142 } |
| 141 | 143 |
| 142 String percent(num x, num total) { | 144 String percent(num x, num total) { |
| 143 return total == 0 ? '0%' : ((100 * x / total).toStringAsFixed(0) + '%'); | 145 return total == 0 ? '0%' : ((100 * x / total).toStringAsFixed(0) + '%'); |
| 144 } | 146 } |
| OLD | NEW |