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 dart_backend; | 5 part of dart_backend; |
6 | 6 |
7 // TODO(ahe): This class is simply wrong. This backend should use | 7 // TODO(ahe): This class is simply wrong. This backend should use |
8 // elements when it can, not AST nodes. Perhaps a [Map<Element, | 8 // elements when it can, not AST nodes. Perhaps a [Map<Element, |
9 // TreeElements>] is what is needed. | 9 // TreeElements>] is what is needed. |
10 class ElementAst { | 10 class ElementAst { |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 world.registerInvocation(new Selector.call("toString", null, 0)); | 127 world.registerInvocation(new Selector.call("toString", null, 0)); |
128 world.registerInvokedGetter(new Selector.getter("hashCode", null)); | 128 world.registerInvokedGetter(new Selector.getter("hashCode", null)); |
129 world.registerInvocation(new Selector.binaryOperator("==")); | 129 world.registerInvocation(new Selector.binaryOperator("==")); |
130 world.registerInvocation(new Selector.call("compareTo", null, 1)); | 130 world.registerInvocation(new Selector.call("compareTo", null, 1)); |
131 } | 131 } |
132 | 132 |
133 void codegen(CodegenWorkItem work) { } | 133 void codegen(CodegenWorkItem work) { } |
134 | 134 |
135 /// Create an [ElementAst] from the CPS IR. | 135 /// Create an [ElementAst] from the CPS IR. |
136 static ElementAst createElementAst(Compiler compiler, | 136 static ElementAst createElementAst(Compiler compiler, |
137 Tracer tracer, | 137 Tracer tracer, |
138 ConstantSystem constantSystem, | 138 ConstantSystem constantSystem, |
139 Element element, | 139 Element element, |
140 cps_ir.FunctionDefinition function) { | 140 cps_ir.ExecutableDefinition cpsDefinition) { |
141 // Transformations on the CPS IR. | 141 // Transformations on the CPS IR. |
142 if (tracer != null) { | 142 if (tracer != null) { |
143 tracer.traceCompilation(element.name, null); | 143 tracer.traceCompilation(element.name, null); |
144 } | 144 } |
145 | 145 |
146 void traceGraph(String title, var irObject) { | 146 void traceGraph(String title, var irObject) { |
147 if (tracer != null) { | 147 if (tracer != null) { |
148 tracer.traceGraph(title, irObject); | 148 tracer.traceGraph(title, irObject); |
149 } | 149 } |
150 } | 150 } |
151 | 151 |
152 new ConstantPropagator(compiler, constantSystem).rewrite(function); | 152 new ConstantPropagator(compiler, constantSystem).rewrite(cpsDefinition); |
153 traceGraph("Sparse constant propagation", function); | 153 traceGraph("Sparse constant propagation", cpsDefinition); |
154 new RedundantPhiEliminator().rewrite(function); | 154 new RedundantPhiEliminator().rewrite(cpsDefinition); |
155 traceGraph("Redundant phi elimination", function); | 155 traceGraph("Redundant phi elimination", cpsDefinition); |
156 new ShrinkingReducer().rewrite(function); | 156 new ShrinkingReducer().rewrite(cpsDefinition); |
157 traceGraph("Shrinking reductions", function); | 157 traceGraph("Shrinking reductions", cpsDefinition); |
158 | 158 |
159 // Do not rewrite the IR after variable allocation. Allocation | 159 // Do not rewrite the IR after variable allocation. Allocation |
160 // makes decisions based on an approximation of IR variable live | 160 // makes decisions based on an approximation of IR variable live |
161 // ranges that can be invalidated by transforming the IR. | 161 // ranges that can be invalidated by transforming the IR. |
162 new cps_ir.RegisterAllocator().visit(function); | 162 new cps_ir.RegisterAllocator().visit(cpsDefinition); |
163 | 163 |
164 tree_builder.Builder builder = new tree_builder.Builder(compiler); | 164 tree_builder.Builder builder = new tree_builder.Builder(compiler); |
165 tree_ir.FunctionDefinition definition = builder.build(function); | 165 tree_ir.ExecutableDefinition treeDefinition = builder.build(cpsDefinition); |
166 assert(definition != null); | 166 assert(treeDefinition != null); |
167 traceGraph('Tree builder', definition); | 167 traceGraph('Tree builder', treeDefinition); |
168 | 168 |
169 // Transformations on the Tree IR. | 169 // Transformations on the Tree IR. |
170 new StatementRewriter().rewrite(definition); | 170 new StatementRewriter().rewrite(treeDefinition); |
171 traceGraph('Statement rewriter', definition); | 171 traceGraph('Statement rewriter', treeDefinition); |
172 new CopyPropagator().rewrite(definition); | 172 new CopyPropagator().rewrite(treeDefinition); |
173 traceGraph('Copy propagation', definition); | 173 traceGraph('Copy propagation', treeDefinition); |
174 new LoopRewriter().rewrite(definition); | 174 new LoopRewriter().rewrite(treeDefinition); |
175 traceGraph('Loop rewriter', definition); | 175 traceGraph('Loop rewriter', treeDefinition); |
176 new LogicalRewriter().rewrite(definition); | 176 new LogicalRewriter().rewrite(treeDefinition); |
177 traceGraph('Logical rewriter', definition); | 177 traceGraph('Logical rewriter', treeDefinition); |
178 new backend_ast_emitter.UnshadowParameters().unshadow(definition); | 178 new backend_ast_emitter.UnshadowParameters().unshadow(treeDefinition); |
179 traceGraph('Unshadow parameters', definition); | 179 traceGraph('Unshadow parameters', treeDefinition); |
180 | 180 |
181 TreeElementMapping treeElements = new TreeElementMapping(element); | 181 TreeElementMapping treeElements = new TreeElementMapping(element); |
182 backend_ast.Node backendAst = | 182 backend_ast.ExecutableDefinition backendAst = |
183 backend_ast_emitter.emit(definition); | 183 backend_ast_emitter.emit(treeDefinition); |
184 Node frontend_ast = backend2frontend.emit(treeElements, backendAst); | 184 Node frontend_ast = backend2frontend.emit(treeElements, backendAst); |
185 return new ElementAst.internal(frontend_ast, treeElements); | 185 return new ElementAst.internal(frontend_ast, treeElements); |
186 | 186 |
187 } | 187 } |
188 | 188 |
189 /** | 189 /** |
190 * Tells whether we should output given element. Corelib classes like | 190 * Tells whether we should output given element. Corelib classes like |
191 * Object should not be in the resulting code. | 191 * Object should not be in the resulting code. |
192 */ | 192 */ |
193 @override | 193 @override |
194 bool shouldOutput(Element element) { | 194 bool shouldOutput(Element element) { |
195 return (!element.library.isPlatformLibrary && | 195 return (!element.library.isPlatformLibrary && |
196 !element.isSynthesized && | 196 !element.isSynthesized && |
197 element is! AbstractFieldElement) | 197 element is! AbstractFieldElement) |
198 || mirrorRenamer.isMirrorHelperLibrary(element.library); | 198 || mirrorRenamer.isMirrorHelperLibrary(element.library); |
199 } | 199 } |
200 | 200 |
201 void assembleProgram() { | 201 void assembleProgram() { |
202 | 202 |
203 ElementAst computeElementAst(AstElement element) { | 203 ElementAst computeElementAst(AstElement element) { |
204 if (!compiler.irBuilder.hasIr(element)) { | 204 if (!compiler.irBuilder.hasIr(element)) { |
205 return new ElementAst(element); | 205 return new ElementAst(element); |
206 } else { | 206 } else { |
207 cps_ir.FunctionDefinition function = compiler.irBuilder.getIr(element); | 207 cps_ir.ExecutableDefinition definition = |
| 208 compiler.irBuilder.getIr(element); |
208 return createElementAst(compiler, | 209 return createElementAst(compiler, |
209 compiler.tracer, constantSystem, element, function); | 210 compiler.tracer, constantSystem, element, definition); |
210 } | 211 } |
211 } | 212 } |
212 | 213 |
213 // TODO(johnniwinther): Remove the need for this method. | 214 // TODO(johnniwinther): Remove the need for this method. |
214 void postProcessElementAst( | 215 void postProcessElementAst( |
215 AstElement element, ElementAst elementAst, | 216 AstElement element, ElementAst elementAst, |
216 newTypedefElementCallback, | 217 newTypedefElementCallback, |
217 newClassElementCallback) { | 218 newClassElementCallback) { |
218 ReferencedElementCollector collector = | 219 ReferencedElementCollector collector = |
219 new ReferencedElementCollector(compiler, | 220 new ReferencedElementCollector(compiler, |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 } | 518 } |
518 | 519 |
519 ConstantExpression compileMetadata(MetadataAnnotation metadata, | 520 ConstantExpression compileMetadata(MetadataAnnotation metadata, |
520 Node node, | 521 Node node, |
521 TreeElements elements) { | 522 TreeElements elements) { |
522 return measure(() { | 523 return measure(() { |
523 return constantCompiler.compileMetadata(metadata, node, elements); | 524 return constantCompiler.compileMetadata(metadata, node, elements); |
524 }); | 525 }); |
525 } | 526 } |
526 } | 527 } |
OLD | NEW |