| OLD | NEW |
| 1 #!/usr/bin/env dart | 1 #!/usr/bin/env dart |
| 2 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 2 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 3 // for details. All rights reserved. Use of this source code is governed by a | 3 // for details. All rights reserved. Use of this source code is governed by a |
| 4 // BSD-style license that can be found in the LICENSE file. | 4 // BSD-style license that can be found in the LICENSE file. |
| 5 | 5 |
| 6 import 'dart:async'; | 6 import 'dart:async'; |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 | 8 |
| 9 import 'package:args/args.dart'; | 9 import 'package:args/args.dart'; |
| 10 import 'package:kernel/verifier.dart'; | 10 import 'package:kernel/verifier.dart'; |
| 11 import 'package:kernel/kernel.dart'; | 11 import 'package:kernel/kernel.dart'; |
| 12 import 'package:kernel/transformations/continuation.dart' as cont; | 12 import 'package:kernel/transformations/continuation.dart' as cont; |
| 13 import 'package:kernel/transformations/infer_values.dart' as infer_values; | 13 import 'package:kernel/transformations/infer_values.dart' as infer_values; |
| 14 import 'package:kernel/transformations/mixin_full_resolution.dart' as mix; | 14 import 'package:kernel/transformations/mixin_full_resolution.dart' as mix; |
| 15 import 'package:kernel/transformations/closure_conversion.dart' as closures; | 15 import 'package:kernel/transformations/closure_conversion.dart' as closures; |
| 16 import 'package:kernel/transformations/treeshaker.dart' as treeshaker; | 16 import 'package:kernel/transformations/treeshaker.dart' as treeshaker; |
| 17 | 17 |
| 18 import 'util.dart'; |
| 18 import 'batch_util.dart'; | 19 import 'batch_util.dart'; |
| 19 | 20 |
| 20 ArgParser parser = new ArgParser() | 21 ArgParser parser = new ArgParser() |
| 21 ..addOption('format', | 22 ..addOption('format', |
| 22 abbr: 'f', | 23 abbr: 'f', |
| 23 allowed: ['text', 'bin'], | 24 allowed: ['text', 'bin'], |
| 24 defaultsTo: 'bin', | 25 defaultsTo: 'bin', |
| 25 help: 'Output format.') | 26 help: 'Output format.') |
| 26 ..addOption('out', abbr: 'o', help: 'Output file.', defaultsTo: null) | 27 ..addOption('out', abbr: 'o', help: 'Output file.', defaultsTo: null) |
| 27 ..addFlag('verbose', | 28 ..addFlag('verbose', |
| 28 abbr: 'v', | 29 abbr: 'v', |
| 29 negatable: false, | 30 negatable: false, |
| 30 help: 'Be verbose (e.g. prints transformed main library).', | 31 help: 'Be verbose (e.g. prints transformed main library).', |
| 31 defaultsTo: false) | 32 defaultsTo: false) |
| 33 ..addOption('embedder-entry-points-manifest', |
| 34 allowMultiple: true, |
| 35 help: 'A path to a file describing entrypoints ' |
| 36 '(lines of the form `<library>,<class>,<member>`).') |
| 32 ..addOption('transformation', | 37 ..addOption('transformation', |
| 33 abbr: 't', | 38 abbr: 't', |
| 34 help: 'The transformation to apply.', | 39 help: 'The transformation to apply.', |
| 35 defaultsTo: 'continuation'); | 40 defaultsTo: 'continuation'); |
| 36 | 41 |
| 37 main(List<String> arguments) async { | 42 main(List<String> arguments) async { |
| 38 if (arguments.isNotEmpty && arguments[0] == '--batch') { | 43 if (arguments.isNotEmpty && arguments[0] == '--batch') { |
| 39 if (arguments.length != 1) { | 44 if (arguments.length != 1) { |
| 40 throw '--batch cannot be used with other arguments'; | 45 throw '--batch cannot be used with other arguments'; |
| 41 } | 46 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 55 | 60 |
| 56 var input = options.rest.first; | 61 var input = options.rest.first; |
| 57 var output = options['out']; | 62 var output = options['out']; |
| 58 var format = options['format']; | 63 var format = options['format']; |
| 59 var verbose = options['verbose']; | 64 var verbose = options['verbose']; |
| 60 | 65 |
| 61 if (output == null) { | 66 if (output == null) { |
| 62 output = '${input.substring(0, input.lastIndexOf('.'))}.transformed.dill'; | 67 output = '${input.substring(0, input.lastIndexOf('.'))}.transformed.dill'; |
| 63 } | 68 } |
| 64 | 69 |
| 70 List<String> embedderEntryPointManifests = |
| 71 options['embedder-entry-points-manifest'] as List<String>; |
| 72 List<treeshaker.ProgramRoot> programRoots = |
| 73 parseProgramRoots(embedderEntryPointManifests); |
| 74 |
| 65 var program = loadProgramFromBinary(input); | 75 var program = loadProgramFromBinary(input); |
| 66 switch (options['transformation']) { | 76 switch (options['transformation']) { |
| 67 case 'continuation': | 77 case 'continuation': |
| 68 program = cont.transformProgram(program); | 78 program = cont.transformProgram(program); |
| 69 break; | 79 break; |
| 70 case 'infervalues': | 80 case 'infervalues': |
| 71 program = infer_values.transformProgram(program); | 81 program = infer_values.transformProgram(program); |
| 72 break; | 82 break; |
| 73 case 'resolve-mixins': | 83 case 'resolve-mixins': |
| 74 program = mix.transformProgram(program); | 84 program = mix.transformProgram(program); |
| 75 break; | 85 break; |
| 76 case 'closures': | 86 case 'closures': |
| 77 program = closures.transformProgram(program); | 87 program = closures.transformProgram(program); |
| 78 break; | 88 break; |
| 79 case 'treeshake': | 89 case 'treeshake': |
| 80 program = treeshaker.transformProgram(program); | 90 program = |
| 91 treeshaker.transformProgram(program, programRoots: programRoots); |
| 81 break; | 92 break; |
| 82 default: | 93 default: |
| 83 throw 'Unknown transformation'; | 94 throw 'Unknown transformation'; |
| 84 } | 95 } |
| 85 | 96 |
| 86 verifyProgram(program); | 97 verifyProgram(program); |
| 87 | 98 |
| 88 if (format == 'text') { | 99 if (format == 'text') { |
| 89 writeProgramToText(program, path: output); | 100 writeProgramToText(program, path: output); |
| 90 } else { | 101 } else { |
| 91 assert(format == 'bin'); | 102 assert(format == 'bin'); |
| 92 await writeProgramToBinary(program, output); | 103 await writeProgramToBinary(program, output); |
| 93 } | 104 } |
| 94 | 105 |
| 95 if (verbose) { | 106 if (verbose) { |
| 96 writeLibraryToText(program.mainMethod.parent as Library); | 107 writeLibraryToText(program.mainMethod.parent as Library); |
| 97 } | 108 } |
| 98 | 109 |
| 99 return CompilerOutcome.Ok; | 110 return CompilerOutcome.Ok; |
| 100 } | 111 } |
| OLD | NEW |