| 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 18 matching lines...) Expand all Loading... |
| 29 const USE_LAZY_EMITTER = const bool.fromEnvironment("dart2js.use.lazy.emitter"); | 29 const USE_LAZY_EMITTER = const bool.fromEnvironment("dart2js.use.lazy.emitter"); |
| 30 | 30 |
| 31 /** | 31 /** |
| 32 * Generates the code for all used classes in the program. Static fields (even | 32 * Generates the code for all used classes in the program. Static fields (even |
| 33 * in classes) are ignored, since they can be treated as non-class elements. | 33 * in classes) are ignored, since they can be treated as non-class elements. |
| 34 * | 34 * |
| 35 * The code for the containing (used) methods must exist in the `universe`. | 35 * The code for the containing (used) methods must exist in the `universe`. |
| 36 */ | 36 */ |
| 37 class CodeEmitterTask extends CompilerTask { | 37 class CodeEmitterTask extends CompilerTask { |
| 38 TypeTestRegistry typeTestRegistry; | 38 TypeTestRegistry typeTestRegistry; |
| 39 NativeEmitter nativeEmitter; | 39 NativeEmitter _nativeEmitter; |
| 40 MetadataCollector metadataCollector; | 40 MetadataCollector metadataCollector; |
| 41 EmitterFactory _emitterFactory; | 41 EmitterFactory _emitterFactory; |
| 42 Emitter _emitter; | 42 Emitter _emitter; |
| 43 final Compiler compiler; | 43 final Compiler compiler; |
| 44 | 44 |
| 45 JavaScriptBackend get backend => compiler.backend; | 45 JavaScriptBackend get backend => compiler.backend; |
| 46 | 46 |
| 47 @deprecated | 47 @deprecated |
| 48 // This field should be removed. It's currently only needed for dump-info and | 48 // This field should be removed. It's currently only needed for dump-info and |
| 49 // tests. | 49 // tests. |
| 50 // The field is set after the program has been emitted. | 50 // The field is set after the program has been emitted. |
| 51 /// Contains a list of all classes that are emitted. | 51 /// Contains a list of all classes that are emitted. |
| 52 Set<ClassEntity> neededClasses; | 52 Set<ClassEntity> neededClasses; |
| 53 | 53 |
| 54 CodeEmitterTask( | 54 CodeEmitterTask( |
| 55 Compiler compiler, bool generateSourceMap, bool useStartupEmitter) | 55 Compiler compiler, bool generateSourceMap, bool useStartupEmitter) |
| 56 : compiler = compiler, | 56 : compiler = compiler, |
| 57 super(compiler.measurer) { | 57 super(compiler.measurer) { |
| 58 nativeEmitter = new NativeEmitter(this); | |
| 59 if (USE_LAZY_EMITTER) { | 58 if (USE_LAZY_EMITTER) { |
| 60 _emitterFactory = new lazy_js_emitter.EmitterFactory(); | 59 _emitterFactory = new lazy_js_emitter.EmitterFactory(); |
| 61 } else if (useStartupEmitter) { | 60 } else if (useStartupEmitter) { |
| 62 _emitterFactory = new startup_js_emitter.EmitterFactory( | 61 _emitterFactory = new startup_js_emitter.EmitterFactory( |
| 63 generateSourceMap: generateSourceMap); | 62 generateSourceMap: generateSourceMap); |
| 64 } else { | 63 } else { |
| 65 _emitterFactory = new full_js_emitter.EmitterFactory( | 64 _emitterFactory = new full_js_emitter.EmitterFactory( |
| 66 generateSourceMap: generateSourceMap); | 65 generateSourceMap: generateSourceMap); |
| 67 } | 66 } |
| 68 } | 67 } |
| 69 | 68 |
| 69 NativeEmitter get nativeEmitter { |
| 70 assert(invariant(NO_LOCATION_SPANNABLE, _nativeEmitter != null, |
| 71 message: "NativeEmitter has not been created yet.")); |
| 72 return _nativeEmitter; |
| 73 } |
| 74 |
| 70 Emitter get emitter { | 75 Emitter get emitter { |
| 71 assert(invariant(NO_LOCATION_SPANNABLE, _emitter != null, | 76 assert(invariant(NO_LOCATION_SPANNABLE, _emitter != null, |
| 72 message: "Emitter has not been created yet.")); | 77 message: "Emitter has not been created yet.")); |
| 73 return _emitter; | 78 return _emitter; |
| 74 } | 79 } |
| 75 | 80 |
| 76 /// Returns the [Sorter] use for ordering elements in the generated | 81 /// Returns the [Sorter] use for ordering elements in the generated |
| 77 /// JavaScript. | 82 /// JavaScript. |
| 78 // TODO(johnniwinther): Switch this based on the used entity model. | 83 // TODO(johnniwinther): Switch this based on the used entity model. |
| 79 Sorter get sorter => const ElementSorter(); | 84 Sorter get sorter => const ElementSorter(); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 typeTestRegistry.computeRequiredTypeChecks(backend.rtiChecksBuilder); | 161 typeTestRegistry.computeRequiredTypeChecks(backend.rtiChecksBuilder); |
| 157 // Compute the classes needed by RTI. | 162 // Compute the classes needed by RTI. |
| 158 typeTestRegistry.computeRtiNeededClasses(backend.rtiSubstitutions, | 163 typeTestRegistry.computeRtiNeededClasses(backend.rtiSubstitutions, |
| 159 backend.mirrorsData, backend.generatedCode.keys); | 164 backend.mirrorsData, backend.generatedCode.keys); |
| 160 } | 165 } |
| 161 | 166 |
| 162 /// Creates the [Emitter] for this task. | 167 /// Creates the [Emitter] for this task. |
| 163 void createEmitter(Namer namer, ClosedWorld closedWorld, | 168 void createEmitter(Namer namer, ClosedWorld closedWorld, |
| 164 CodegenWorldBuilder codegenWorldBuilder) { | 169 CodegenWorldBuilder codegenWorldBuilder) { |
| 165 measure(() { | 170 measure(() { |
| 171 _nativeEmitter = new NativeEmitter(this, closedWorld.nativeData); |
| 166 _emitter = _emitterFactory.createEmitter(this, namer, closedWorld); | 172 _emitter = _emitterFactory.createEmitter(this, namer, closedWorld); |
| 167 metadataCollector = new MetadataCollector( | 173 metadataCollector = new MetadataCollector( |
| 168 compiler.options, | 174 compiler.options, |
| 169 compiler.reporter, | 175 compiler.reporter, |
| 170 compiler.deferredLoadTask, | 176 compiler.deferredLoadTask, |
| 171 _emitter, | 177 _emitter, |
| 172 backend.constants, | 178 backend.constants, |
| 173 backend.typeVariableCodegenAnalysis, | 179 backend.typeVariableCodegenAnalysis, |
| 174 backend.mirrorsData, | 180 backend.mirrorsData, |
| 175 backend.rtiEncoder); | 181 backend.rtiEncoder); |
| 176 typeTestRegistry = new TypeTestRegistry(codegenWorldBuilder, closedWorld); | 182 typeTestRegistry = new TypeTestRegistry(codegenWorldBuilder, closedWorld); |
| 177 }); | 183 }); |
| 178 } | 184 } |
| 179 | 185 |
| 180 int assembleProgram(Namer namer, ClosedWorld closedWorld) { | 186 int assembleProgram(Namer namer, ClosedWorld closedWorld) { |
| 181 return measure(() { | 187 return measure(() { |
| 182 _finalizeRti(); | 188 _finalizeRti(); |
| 183 ProgramBuilder programBuilder = new ProgramBuilder( | 189 ProgramBuilder programBuilder = new ProgramBuilder( |
| 184 compiler.options, | 190 compiler.options, |
| 185 compiler.elementEnvironment, | 191 compiler.elementEnvironment, |
| 186 compiler.commonElements, | 192 compiler.commonElements, |
| 187 compiler.types, | 193 compiler.types, |
| 188 compiler.deferredLoadTask, | 194 compiler.deferredLoadTask, |
| 189 compiler.closureToClassMapper, | 195 compiler.closureToClassMapper, |
| 190 compiler.codegenWorldBuilder, | 196 compiler.codegenWorldBuilder, |
| 191 backend.nativeCodegenEnqueuer, | 197 backend.nativeCodegenEnqueuer, |
| 192 backend.backendUsage, | 198 backend.backendUsage, |
| 193 backend.constants, | 199 backend.constants, |
| 194 backend.nativeData, | 200 closedWorld.nativeData, |
| 195 backend.rtiNeed, | 201 backend.rtiNeed, |
| 196 backend.mirrorsData, | 202 backend.mirrorsData, |
| 197 backend.interceptorData, | 203 backend.interceptorData, |
| 198 backend.superMemberData, | 204 backend.superMemberData, |
| 199 typeTestRegistry.rtiChecks, | 205 typeTestRegistry.rtiChecks, |
| 200 backend.rtiEncoder, | 206 backend.rtiEncoder, |
| 201 backend.rtiSubstitutions, | 207 backend.rtiSubstitutions, |
| 202 backend.jsInteropAnalysis, | 208 backend.jsInteropAnalysis, |
| 203 backend.oneShotInterceptorData, | 209 backend.oneShotInterceptorData, |
| 204 backend.customElementsCodegenAnalysis, | 210 backend.customElementsCodegenAnalysis, |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 | 276 |
| 271 /// Returns the JS code for accessing the given [constant]. | 277 /// Returns the JS code for accessing the given [constant]. |
| 272 jsAst.Expression constantReference(ConstantValue constant); | 278 jsAst.Expression constantReference(ConstantValue constant); |
| 273 | 279 |
| 274 /// Returns the JS template for the given [builtin]. | 280 /// Returns the JS template for the given [builtin]. |
| 275 jsAst.Template templateForBuiltin(JsBuiltin builtin); | 281 jsAst.Template templateForBuiltin(JsBuiltin builtin); |
| 276 | 282 |
| 277 /// Returns the size of the code generated for a given output [unit]. | 283 /// Returns the size of the code generated for a given output [unit]. |
| 278 int generatedSize(OutputUnit unit); | 284 int generatedSize(OutputUnit unit); |
| 279 } | 285 } |
| OLD | NEW |