OLD | NEW |
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.js_emitter.code_emitter_task; | 5 library dart2js.js_emitter.code_emitter_task; |
6 | 6 |
7 import 'package:js_runtime/shared/embedded_names.dart' show JsBuiltin; | 7 import 'package:js_runtime/shared/embedded_names.dart' show JsBuiltin; |
8 | 8 |
9 import '../common.dart'; | 9 import '../common.dart'; |
10 import '../common/tasks.dart' show CompilerTask; | 10 import '../common/tasks.dart' show CompilerTask; |
(...skipping 25 matching lines...) Expand all Loading... |
36 * The code for the containing (used) methods must exist in the `universe`. | 36 * The code for the containing (used) methods must exist in the `universe`. |
37 */ | 37 */ |
38 class CodeEmitterTask extends CompilerTask { | 38 class CodeEmitterTask extends CompilerTask { |
39 TypeTestRegistry typeTestRegistry; | 39 TypeTestRegistry typeTestRegistry; |
40 NativeEmitter _nativeEmitter; | 40 NativeEmitter _nativeEmitter; |
41 MetadataCollector metadataCollector; | 41 MetadataCollector metadataCollector; |
42 EmitterFactory _emitterFactory; | 42 EmitterFactory _emitterFactory; |
43 Emitter _emitter; | 43 Emitter _emitter; |
44 final Compiler compiler; | 44 final Compiler compiler; |
45 | 45 |
46 /// The [Sorter] use for ordering elements in the generated JavaScript. | |
47 final Sorter sorter; | |
48 | |
49 JavaScriptBackend get backend => compiler.backend; | 46 JavaScriptBackend get backend => compiler.backend; |
50 | 47 |
51 @deprecated | 48 @deprecated |
52 // This field should be removed. It's currently only needed for dump-info and | 49 // This field should be removed. It's currently only needed for dump-info and |
53 // tests. | 50 // tests. |
54 // The field is set after the program has been emitted. | 51 // The field is set after the program has been emitted. |
55 /// Contains a list of all classes that are emitted. | 52 /// Contains a list of all classes that are emitted. |
56 Set<ClassEntity> neededClasses; | 53 Set<ClassEntity> neededClasses; |
57 | 54 |
58 CodeEmitterTask( | 55 CodeEmitterTask( |
59 Compiler compiler, bool generateSourceMap, bool useStartupEmitter) | 56 Compiler compiler, bool generateSourceMap, bool useStartupEmitter) |
60 : compiler = compiler, | 57 : compiler = compiler, |
61 sorter = compiler.backendStrategy.sorter, | |
62 super(compiler.measurer) { | 58 super(compiler.measurer) { |
63 if (USE_LAZY_EMITTER) { | 59 if (USE_LAZY_EMITTER) { |
64 _emitterFactory = new lazy_js_emitter.EmitterFactory(); | 60 _emitterFactory = new lazy_js_emitter.EmitterFactory(); |
65 } else if (useStartupEmitter) { | 61 } else if (useStartupEmitter) { |
66 _emitterFactory = new startup_js_emitter.EmitterFactory( | 62 _emitterFactory = new startup_js_emitter.EmitterFactory( |
67 generateSourceMap: generateSourceMap); | 63 generateSourceMap: generateSourceMap); |
68 } else { | 64 } else { |
69 _emitterFactory = new full_js_emitter.EmitterFactory( | 65 _emitterFactory = new full_js_emitter.EmitterFactory( |
70 generateSourceMap: generateSourceMap); | 66 generateSourceMap: generateSourceMap); |
71 } | 67 } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 // Compute the required type checks to know which classes need a | 157 // Compute the required type checks to know which classes need a |
162 // 'is$' method. | 158 // 'is$' method. |
163 typeTestRegistry.computeRequiredTypeChecks(backend.rtiChecksBuilder); | 159 typeTestRegistry.computeRequiredTypeChecks(backend.rtiChecksBuilder); |
164 // Compute the classes needed by RTI. | 160 // Compute the classes needed by RTI. |
165 typeTestRegistry.computeRtiNeededClasses(backend.rtiSubstitutions, | 161 typeTestRegistry.computeRtiNeededClasses(backend.rtiSubstitutions, |
166 backend.mirrorsData, backend.generatedCode.keys); | 162 backend.mirrorsData, backend.generatedCode.keys); |
167 } | 163 } |
168 | 164 |
169 /// Creates the [Emitter] for this task. | 165 /// Creates the [Emitter] for this task. |
170 void createEmitter(Namer namer, ClosedWorld closedWorld, | 166 void createEmitter(Namer namer, ClosedWorld closedWorld, |
171 CodegenWorldBuilder codegenWorldBuilder) { | 167 CodegenWorldBuilder codegenWorldBuilder, Sorter sorter) { |
172 measure(() { | 168 measure(() { |
173 _nativeEmitter = new NativeEmitter(this, closedWorld, codegenWorldBuilder, | 169 _nativeEmitter = new NativeEmitter(this, closedWorld, codegenWorldBuilder, |
174 backend.nativeCodegenEnqueuer); | 170 backend.nativeCodegenEnqueuer); |
175 _emitter = _emitterFactory.createEmitter(this, namer, closedWorld); | 171 _emitter = |
| 172 _emitterFactory.createEmitter(this, namer, closedWorld, sorter); |
176 metadataCollector = new MetadataCollector( | 173 metadataCollector = new MetadataCollector( |
177 compiler.options, | 174 compiler.options, |
178 compiler.reporter, | 175 compiler.reporter, |
179 compiler.deferredLoadTask, | 176 compiler.deferredLoadTask, |
180 _emitter, | 177 _emitter, |
181 backend.constants, | 178 backend.constants, |
182 backend.typeVariableCodegenAnalysis, | 179 backend.typeVariableCodegenAnalysis, |
183 backend.mirrorsData, | 180 backend.mirrorsData, |
184 backend.rtiEncoder); | 181 backend.rtiEncoder); |
185 typeTestRegistry = new TypeTestRegistry( | 182 typeTestRegistry = new TypeTestRegistry( |
(...skipping 24 matching lines...) Expand all Loading... |
210 typeTestRegistry.rtiChecks, | 207 typeTestRegistry.rtiChecks, |
211 backend.rtiEncoder, | 208 backend.rtiEncoder, |
212 backend.rtiSubstitutions, | 209 backend.rtiSubstitutions, |
213 backend.jsInteropAnalysis, | 210 backend.jsInteropAnalysis, |
214 backend.oneShotInterceptorData, | 211 backend.oneShotInterceptorData, |
215 backend.customElementsCodegenAnalysis, | 212 backend.customElementsCodegenAnalysis, |
216 backend.generatedCode, | 213 backend.generatedCode, |
217 namer, | 214 namer, |
218 this, | 215 this, |
219 closedWorld, | 216 closedWorld, |
| 217 compiler.backendStrategy.sorter, |
220 typeTestRegistry.rtiNeededClasses, | 218 typeTestRegistry.rtiNeededClasses, |
221 closedWorld.elementEnvironment.mainFunction, | 219 closedWorld.elementEnvironment.mainFunction, |
222 isMockCompilation: compiler.isMockCompilation); | 220 isMockCompilation: compiler.isMockCompilation); |
223 int size = emitter.emitProgram(programBuilder); | 221 int size = emitter.emitProgram(programBuilder); |
224 // TODO(floitsch): we shouldn't need the `neededClasses` anymore. | 222 // TODO(floitsch): we shouldn't need the `neededClasses` anymore. |
225 neededClasses = programBuilder.collector.neededClasses; | 223 neededClasses = programBuilder.collector.neededClasses; |
226 return size; | 224 return size; |
227 }); | 225 }); |
228 } | 226 } |
229 } | 227 } |
230 | 228 |
231 abstract class EmitterFactory { | 229 abstract class EmitterFactory { |
232 /// Returns true, if the emitter supports reflection. | 230 /// Returns true, if the emitter supports reflection. |
233 bool get supportsReflection; | 231 bool get supportsReflection; |
234 | 232 |
235 /// Create the [Emitter] for the emitter [task] that uses the given [namer]. | 233 /// Create the [Emitter] for the emitter [task] that uses the given [namer]. |
236 Emitter createEmitter( | 234 Emitter createEmitter(CodeEmitterTask task, Namer namer, |
237 CodeEmitterTask task, Namer namer, ClosedWorld closedWorld); | 235 ClosedWorld closedWorld, Sorter sorter); |
238 } | 236 } |
239 | 237 |
240 abstract class Emitter { | 238 abstract class Emitter { |
241 Program get programForTesting; | 239 Program get programForTesting; |
242 | 240 |
243 /// Uses the [programBuilder] to generate a model of the program, emits | 241 /// Uses the [programBuilder] to generate a model of the program, emits |
244 /// the program, and returns the size of the generated output. | 242 /// the program, and returns the size of the generated output. |
245 int emitProgram(ProgramBuilder programBuilder); | 243 int emitProgram(ProgramBuilder programBuilder); |
246 | 244 |
247 /// Returns the JS function that must be invoked to get the value of the | 245 /// Returns the JS function that must be invoked to get the value of the |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 @override | 333 @override |
336 jsAst.Expression interceptorClassAccess(ClassEntity element) { | 334 jsAst.Expression interceptorClassAccess(ClassEntity element) { |
337 return globalPropertyAccessForClass(element); | 335 return globalPropertyAccessForClass(element); |
338 } | 336 } |
339 | 337 |
340 @override | 338 @override |
341 jsAst.Expression typeAccess(Entity element) { | 339 jsAst.Expression typeAccess(Entity element) { |
342 return globalPropertyAccessForType(element); | 340 return globalPropertyAccessForType(element); |
343 } | 341 } |
344 } | 342 } |
OLD | NEW |