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 part of dart2js.js_emitter; | 5 part of dart2js.js_emitter; |
6 | 6 |
7 const USE_LAZY_EMITTER = const bool.fromEnvironment("dart2js.use.lazy.emitter"); | 7 const USE_LAZY_EMITTER = const bool.fromEnvironment("dart2js.use.lazy.emitter"); |
8 | 8 |
9 /** | 9 /** |
10 * Generates the code for all used classes in the program. Static fields (even | 10 * Generates the code for all used classes in the program. Static fields (even |
(...skipping 16 matching lines...) Expand all Loading... |
27 JavaScriptBackend get backend => compiler.backend; | 27 JavaScriptBackend get backend => compiler.backend; |
28 | 28 |
29 @deprecated | 29 @deprecated |
30 // This field should be removed. It's currently only needed for dump-info and | 30 // This field should be removed. It's currently only needed for dump-info and |
31 // tests. | 31 // tests. |
32 // The field is set after the program has been emitted. | 32 // The field is set after the program has been emitted. |
33 /// Contains a list of all classes that are emitted. | 33 /// Contains a list of all classes that are emitted. |
34 Set<ClassElement> neededClasses; | 34 Set<ClassElement> neededClasses; |
35 | 35 |
36 CodeEmitterTask(Compiler compiler, Namer namer, bool generateSourceMap, | 36 CodeEmitterTask(Compiler compiler, Namer namer, bool generateSourceMap, |
37 bool useStartupEmitter) | 37 bool useStartupEmitter) |
38 : super(compiler), | 38 : super(compiler), |
39 this.namer = namer, | 39 this.namer = namer, |
40 this.typeTestRegistry = new TypeTestRegistry(compiler) { | 40 this.typeTestRegistry = new TypeTestRegistry(compiler) { |
41 nativeEmitter = new NativeEmitter(this); | 41 nativeEmitter = new NativeEmitter(this); |
42 if (USE_LAZY_EMITTER) { | 42 if (USE_LAZY_EMITTER) { |
43 emitter = new lazy_js_emitter.Emitter(compiler, namer, nativeEmitter); | 43 emitter = new lazy_js_emitter.Emitter(compiler, namer, nativeEmitter); |
44 } else if (useStartupEmitter) { | 44 } else if (useStartupEmitter) { |
45 emitter = new startup_js_emitter.Emitter( | 45 emitter = new startup_js_emitter.Emitter( |
46 compiler, namer, nativeEmitter, generateSourceMap); | 46 compiler, namer, nativeEmitter, generateSourceMap); |
47 } else { | 47 } else { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 | 91 |
92 /// Returns the JS constructor of the given element. | 92 /// Returns the JS constructor of the given element. |
93 /// | 93 /// |
94 /// The returned expression must only be used in a JS `new` expression. | 94 /// The returned expression must only be used in a JS `new` expression. |
95 jsAst.Expression constructorAccess(ClassElement e) { | 95 jsAst.Expression constructorAccess(ClassElement e) { |
96 return emitter.constructorAccess(e); | 96 return emitter.constructorAccess(e); |
97 } | 97 } |
98 | 98 |
99 /// Returns the JS prototype of the given class [e]. | 99 /// Returns the JS prototype of the given class [e]. |
100 jsAst.Expression prototypeAccess(ClassElement e, | 100 jsAst.Expression prototypeAccess(ClassElement e, |
101 {bool hasBeenInstantiated: false}) { | 101 {bool hasBeenInstantiated: false}) { |
102 return emitter.prototypeAccess(e, hasBeenInstantiated); | 102 return emitter.prototypeAccess(e, hasBeenInstantiated); |
103 } | 103 } |
104 | 104 |
105 /// Returns the JS prototype of the given interceptor class [e]. | 105 /// Returns the JS prototype of the given interceptor class [e]. |
106 jsAst.Expression interceptorPrototypeAccess(ClassElement e) { | 106 jsAst.Expression interceptorPrototypeAccess(ClassElement e) { |
107 return jsAst.js('#.prototype', interceptorClassAccess(e)); | 107 return jsAst.js('#.prototype', interceptorClassAccess(e)); |
108 } | 108 } |
109 | 109 |
110 /// Returns the JS constructor of the given interceptor class [e]. | 110 /// Returns the JS constructor of the given interceptor class [e]. |
111 jsAst.Expression interceptorClassAccess(ClassElement e) { | 111 jsAst.Expression interceptorClassAccess(ClassElement e) { |
(...skipping 22 matching lines...) Expand all Loading... |
134 typeTestRegistry.computeRequiredTypeChecks(); | 134 typeTestRegistry.computeRequiredTypeChecks(); |
135 // Compute the classes needed by RTI. | 135 // Compute the classes needed by RTI. |
136 return typeTestRegistry.computeRtiNeededClasses(); | 136 return typeTestRegistry.computeRtiNeededClasses(); |
137 } | 137 } |
138 | 138 |
139 int assembleProgram() { | 139 int assembleProgram() { |
140 return measure(() { | 140 return measure(() { |
141 emitter.invalidateCaches(); | 141 emitter.invalidateCaches(); |
142 | 142 |
143 Set<ClassElement> rtiNeededClasses = _finalizeRti(); | 143 Set<ClassElement> rtiNeededClasses = _finalizeRti(); |
144 ProgramBuilder programBuilder = new ProgramBuilder( | 144 ProgramBuilder programBuilder = |
145 compiler, namer, this, emitter, rtiNeededClasses); | 145 new ProgramBuilder(compiler, namer, this, emitter, rtiNeededClasses); |
146 int size = emitter.emitProgram(programBuilder); | 146 int size = emitter.emitProgram(programBuilder); |
147 // TODO(floitsch): we shouldn't need the `neededClasses` anymore. | 147 // TODO(floitsch): we shouldn't need the `neededClasses` anymore. |
148 neededClasses = programBuilder.collector.neededClasses; | 148 neededClasses = programBuilder.collector.neededClasses; |
149 return size; | 149 return size; |
150 }); | 150 }); |
151 } | 151 } |
152 } | 152 } |
153 | 153 |
154 abstract class Emitter { | 154 abstract class Emitter { |
155 /// Returns the string that is used to find library patches that are | 155 /// Returns the string that is used to find library patches that are |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 bool isConstantInlinedOrAlreadyEmitted(ConstantValue constant); | 201 bool isConstantInlinedOrAlreadyEmitted(ConstantValue constant); |
202 | 202 |
203 /// Returns the JS code for accessing the given [constant]. | 203 /// Returns the JS code for accessing the given [constant]. |
204 jsAst.Expression constantReference(ConstantValue constant); | 204 jsAst.Expression constantReference(ConstantValue constant); |
205 | 205 |
206 /// Returns the JS template for the given [builtin]. | 206 /// Returns the JS template for the given [builtin]. |
207 jsAst.Template templateForBuiltin(JsBuiltin builtin); | 207 jsAst.Template templateForBuiltin(JsBuiltin builtin); |
208 | 208 |
209 void invalidateCaches(); | 209 void invalidateCaches(); |
210 } | 210 } |
OLD | NEW |