Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1053)

Side by Side Diff: pkg/kernel/lib/target/targets.dart

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

Powered by Google App Engine
This is Rietveld 408576698