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

Side by Side Diff: pkg/compiler/lib/src/common/codegen.dart

Issue 2531303002: Decouple WorkItem from Compiler (Closed)
Patch Set: Created 4 years 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 library dart2js.common.codegen; 5 library dart2js.common.codegen;
6 6
7 import '../common.dart'; 7 import '../common.dart';
8 import '../compiler.dart' show Compiler; 8 import '../common/backend_api.dart' show Backend;
9 import '../constants/values.dart' show ConstantValue; 9 import '../constants/values.dart' show ConstantValue;
10 import '../dart_types.dart' show DartType, InterfaceType; 10 import '../dart_types.dart' show DartType, InterfaceType;
11 import '../elements/elements.dart' 11 import '../elements/elements.dart'
12 show 12 show
13 AstElement, 13 AstElement,
14 ClassElement, 14 ClassElement,
15 Element, 15 Element,
16 FunctionElement, 16 FunctionElement,
17 LocalFunctionElement, 17 LocalFunctionElement,
18 ResolvedAst; 18 ResolvedAst;
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 } 139 }
140 140
141 Iterable<Element> get asyncMarkers { 141 Iterable<Element> get asyncMarkers {
142 return _asyncMarkers != null ? _asyncMarkers : const <FunctionElement>[]; 142 return _asyncMarkers != null ? _asyncMarkers : const <FunctionElement>[];
143 } 143 }
144 } 144 }
145 145
146 // TODO(johnniwinther): Split this class into interface and implementation. 146 // TODO(johnniwinther): Split this class into interface and implementation.
147 // TODO(johnniwinther): Move this implementation to the JS backend. 147 // TODO(johnniwinther): Move this implementation to the JS backend.
148 class CodegenRegistry { 148 class CodegenRegistry {
149 final Compiler compiler;
150 final Element currentElement; 149 final Element currentElement;
151 final _CodegenImpact worldImpact; 150 final _CodegenImpact worldImpact;
152 151
153 CodegenRegistry(Compiler compiler, AstElement currentElement) 152 CodegenRegistry(AstElement currentElement)
154 : this.compiler = compiler, 153 : this.currentElement = currentElement,
155 this.currentElement = currentElement,
156 this.worldImpact = new _CodegenImpact(); 154 this.worldImpact = new _CodegenImpact();
157 155
158 bool get isForResolution => false; 156 bool get isForResolution => false;
159 157
160 String toString() => 'CodegenRegistry for $currentElement'; 158 String toString() => 'CodegenRegistry for $currentElement';
161 159
162 /// Add the uses in [impact] to the impact of this registry. 160 /// Add the uses in [impact] to the impact of this registry.
163 void addImpact(WorldImpact impact) { 161 void addImpact(WorldImpact impact) {
164 worldImpact.addImpact(impact); 162 worldImpact.addImpact(impact);
165 } 163 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 214
217 void registerAsyncMarker(FunctionElement element) { 215 void registerAsyncMarker(FunctionElement element) {
218 worldImpact.registerAsyncMarker(element); 216 worldImpact.registerAsyncMarker(element);
219 } 217 }
220 } 218 }
221 219
222 /// [WorkItem] used exclusively by the [CodegenEnqueuer]. 220 /// [WorkItem] used exclusively by the [CodegenEnqueuer].
223 class CodegenWorkItem extends WorkItem { 221 class CodegenWorkItem extends WorkItem {
224 CodegenRegistry registry; 222 CodegenRegistry registry;
225 final ResolvedAst resolvedAst; 223 final ResolvedAst resolvedAst;
224 final Backend backend;
226 225
227 factory CodegenWorkItem(Compiler compiler, AstElement element) { 226 factory CodegenWorkItem(Backend backend, AstElement element) {
228 // If this assertion fails, the resolution callbacks of the backend may be 227 // If this assertion fails, the resolution callbacks of the backend may be
229 // missing call of form registry.registerXXX. Alternatively, the code 228 // missing call of form registry.registerXXX. Alternatively, the code
230 // generation could spuriously be adding dependencies on things we know we 229 // generation could spuriously be adding dependencies on things we know we
231 // don't need. 230 // don't need.
232 assert(invariant(element, element.hasResolvedAst, 231 assert(invariant(element, element.hasResolvedAst,
233 message: "$element has no resolved ast.")); 232 message: "$element has no resolved ast."));
234 ResolvedAst resolvedAst = element.resolvedAst; 233 ResolvedAst resolvedAst = element.resolvedAst;
235 return new CodegenWorkItem.internal(resolvedAst); 234 return new CodegenWorkItem.internal(resolvedAst, backend);
236 } 235 }
237 236
238 CodegenWorkItem.internal(ResolvedAst resolvedAst) 237 CodegenWorkItem.internal(ResolvedAst resolvedAst, this.backend)
239 : this.resolvedAst = resolvedAst, 238 : this.resolvedAst = resolvedAst,
240 super(resolvedAst.element); 239 super(resolvedAst.element);
241 240
242 WorldImpact run(Compiler compiler, Enqueuer world) { 241 WorldImpact run() {
243 if (world.isProcessed(element)) return const WorldImpact(); 242 registry = new CodegenRegistry(element);
244 243 return backend.codegen(this);
245 registry = new CodegenRegistry(compiler, element);
246 return compiler.codegen(this, world);
247 } 244 }
248 245
249 String toString() => 'CodegenWorkItem(${resolvedAst.element})'; 246 String toString() => 'CodegenWorkItem(${resolvedAst.element})';
250 } 247 }
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/common/resolution.dart » ('j') | pkg/compiler/lib/src/compiler.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698