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.target.targets; | 4 library kernel.target.targets; |
5 | 5 |
6 import '../ast.dart'; | 6 import '../ast.dart'; |
7 import '../core_types.dart'; | 7 import '../core_types.dart'; |
8 import '../transformations/treeshaker.dart' show ProgramRoot; | 8 import '../transformations/treeshaker.dart' show ProgramRoot; |
9 import 'flutter.dart'; | 9 import 'flutter.dart' show FlutterTarget; |
10 import 'vm.dart'; | 10 import 'vm.dart' show VmTarget; |
11 import 'vmcc.dart'; | 11 import 'vm_fasta.dart' show VmFastaTarget; |
12 import 'vmreify.dart'; | 12 import 'vmcc.dart' show VmClosureConvertedTarget; |
| 13 import 'vmreify.dart' show VmGenericTypesReifiedTarget; |
13 | 14 |
14 final List<String> targetNames = targets.keys.toList(); | 15 final List<String> targetNames = targets.keys.toList(); |
15 | 16 |
16 class TargetFlags { | 17 class TargetFlags { |
17 bool strongMode; | 18 bool strongMode; |
18 bool treeShake; | 19 bool treeShake; |
19 List<ProgramRoot> programRoots; | 20 List<ProgramRoot> programRoots; |
20 Uri kernelRuntime; | 21 Uri kernelRuntime; |
21 | 22 |
22 TargetFlags( | 23 TargetFlags( |
23 {this.strongMode: false, | 24 {this.strongMode: false, |
24 this.treeShake: false, | 25 this.treeShake: false, |
25 this.programRoots: const <ProgramRoot>[], | 26 this.programRoots: const <ProgramRoot>[], |
26 this.kernelRuntime}); | 27 this.kernelRuntime}); |
27 } | 28 } |
28 | 29 |
29 typedef Target _TargetBuilder(TargetFlags flags); | 30 typedef Target _TargetBuilder(TargetFlags flags); |
30 | 31 |
31 final Map<String, _TargetBuilder> targets = <String, _TargetBuilder>{ | 32 final Map<String, _TargetBuilder> targets = <String, _TargetBuilder>{ |
32 'none': (TargetFlags flags) => new NoneTarget(flags), | 33 'none': (TargetFlags flags) => new NoneTarget(flags), |
33 'vm': (TargetFlags flags) => new VmTarget(flags), | 34 'vm': (TargetFlags flags) => new VmTarget(flags), |
| 35 'vm_fasta': (TargetFlags flags) => new VmFastaTarget(flags), |
34 'vmcc': (TargetFlags flags) => new VmClosureConvertedTarget(flags), | 36 'vmcc': (TargetFlags flags) => new VmClosureConvertedTarget(flags), |
35 'vmreify': (TargetFlags flags) => new VmGenericTypesReifiedTarget(flags), | 37 'vmreify': (TargetFlags flags) => new VmGenericTypesReifiedTarget(flags), |
36 'flutter': (TargetFlags flags) => new FlutterTarget(flags), | 38 'flutter': (TargetFlags flags) => new FlutterTarget(flags), |
37 }; | 39 }; |
38 | 40 |
39 Target getTarget(String name, TargetFlags flags) { | 41 Target getTarget(String name, TargetFlags flags) { |
40 var builder = targets[name]; | 42 var builder = targets[name]; |
41 if (builder == null) return null; | 43 if (builder == null) return null; |
42 return builder(flags); | 44 return builder(flags); |
43 } | 45 } |
(...skipping 16 matching lines...) Expand all Loading... |
60 | 62 |
61 /// Classes from the SDK whose interface is required for the modular | 63 /// Classes from the SDK whose interface is required for the modular |
62 /// transformations. | 64 /// transformations. |
63 Map<String, List<String>> get requiredSdkClasses => CoreTypes.requiredClasses; | 65 Map<String, List<String>> get requiredSdkClasses => CoreTypes.requiredClasses; |
64 | 66 |
65 bool get strongMode; | 67 bool get strongMode; |
66 | 68 |
67 /// If true, the SDK should be loaded in strong mode. | 69 /// If true, the SDK should be loaded in strong mode. |
68 bool get strongModeSdk => strongMode; | 70 bool get strongModeSdk => strongMode; |
69 | 71 |
70 /// Perform target-specific modular transformations. | 72 /// Perform target-specific modular transformations on the given program. |
71 /// | 73 /// |
72 /// These transformations should not be whole-program transformations. They | 74 /// These transformations should not be whole-program transformations. They |
73 /// should expect that the program will contain external libraries. | 75 /// should expect that the program will contain external libraries. |
74 void performModularTransformations(CoreTypes coreTypes, Program program); | 76 void performModularTransformationsOnProgram( |
| 77 CoreTypes coreTypes, Program program, |
| 78 {void logger(String msg)}) { |
| 79 performModularTransformationsOnLibraries(coreTypes, program.libraries, |
| 80 logger: logger); |
| 81 } |
| 82 |
| 83 /// Perform target-specific modular transformations on the given libraries. |
| 84 /// |
| 85 /// The intent of this method is to perform the transformations only on some |
| 86 /// subset of the program libraries and avoid packing them into a temporary |
| 87 /// [Program] instance to pass into [performModularTransformationsOnProgram]. |
| 88 /// |
| 89 /// Note that the following should be equivalent: |
| 90 /// |
| 91 /// target.performModularTransformationsOnProgram(coreTypes, program); |
| 92 /// |
| 93 /// and |
| 94 /// |
| 95 /// target.performModularTransformationsOnLibraries( |
| 96 /// coreTypes, program.libraries); |
| 97 void performModularTransformationsOnLibraries( |
| 98 CoreTypes coreTypes, List<Library> libraries, |
| 99 {void logger(String msg)}); |
75 | 100 |
76 /// Perform target-specific whole-program transformations. | 101 /// Perform target-specific whole-program transformations. |
77 /// | 102 /// |
78 /// These transformations should be optimizations and not required for | 103 /// These transformations should be optimizations and not required for |
79 /// correctness. Everything should work if a simple and fast linker chooses | 104 /// correctness. Everything should work if a simple and fast linker chooses |
80 /// not to apply these transformations. | 105 /// not to apply these transformations. |
81 void performGlobalTransformations(CoreTypes coreTypes, Program program); | 106 /// |
| 107 /// Note that [performGlobalTransformations] doesn't have -OnProgram and |
| 108 /// -OnLibraries alternatives, because the global knowledge required by the |
| 109 /// transformations is assumed to be retrieved from a [Program] instance. |
| 110 void performGlobalTransformations(CoreTypes coreTypes, Program program, |
| 111 {void logger(String msg)}); |
82 | 112 |
83 /// Builds an expression that instantiates an [Invocation] that can be passed | 113 /// Builds an expression that instantiates an [Invocation] that can be passed |
84 /// to [noSuchMethod]. | 114 /// to [noSuchMethod]. |
85 Expression instantiateInvocation(Member target, Expression receiver, | 115 Expression instantiateInvocation(Member target, Expression receiver, |
86 String name, Arguments arguments, int offset, bool isSuper); | 116 String name, Arguments arguments, int offset, bool isSuper); |
87 | 117 |
88 String toString() => 'Target($name)'; | 118 String toString() => 'Target($name)'; |
89 } | 119 } |
90 | 120 |
91 class NoneTarget extends Target { | 121 class NoneTarget extends Target { |
92 final TargetFlags flags; | 122 final TargetFlags flags; |
93 | 123 |
94 NoneTarget(this.flags); | 124 NoneTarget(this.flags); |
95 | 125 |
96 bool get strongMode => flags.strongMode; | 126 bool get strongMode => flags.strongMode; |
97 String get name => 'none'; | 127 String get name => 'none'; |
98 List<String> get extraRequiredLibraries => <String>[]; | 128 List<String> get extraRequiredLibraries => <String>[]; |
99 void performModularTransformations(CoreTypes coreTypes, Program program) {} | 129 void performModularTransformationsOnLibraries( |
100 void performGlobalTransformations(CoreTypes coreTypes, Program program) {} | 130 CoreTypes coreTypes, List<Library> libraries, |
| 131 {void logger(String msg)}) {} |
| 132 void performGlobalTransformations(CoreTypes coreTypes, Program program, |
| 133 {void logger(String msg)}) {} |
101 | 134 |
102 @override | 135 @override |
103 Expression instantiateInvocation(Member target, Expression receiver, | 136 Expression instantiateInvocation(Member target, Expression receiver, |
104 String name, Arguments arguments, int offset, bool isSuper) { | 137 String name, Arguments arguments, int offset, bool isSuper) { |
105 return new InvalidExpression(); | 138 return new InvalidExpression(); |
106 } | 139 } |
107 } | 140 } |
OLD | NEW |