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

Side by Side Diff: pkg/compiler/lib/src/dart_backend/backend.dart

Issue 812333002: Fix analyzer2dart end2end. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 | Annotate | Revision Log
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 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 world.registerInvocation(new Selector.call("toString", null, 0)); 124 world.registerInvocation(new Selector.call("toString", null, 0));
125 world.registerInvokedGetter(new Selector.getter("hashCode", null)); 125 world.registerInvokedGetter(new Selector.getter("hashCode", null));
126 world.registerInvocation(new Selector.binaryOperator("==")); 126 world.registerInvocation(new Selector.binaryOperator("=="));
127 world.registerInvocation(new Selector.call("compareTo", null, 1)); 127 world.registerInvocation(new Selector.call("compareTo", null, 1));
128 } 128 }
129 129
130 void codegen(CodegenWorkItem work) { } 130 void codegen(CodegenWorkItem work) { }
131 131
132 /// Create an [ElementAst] from the CPS IR. 132 /// Create an [ElementAst] from the CPS IR.
133 static ElementAst createElementAst( 133 static ElementAst createElementAst(
134 Compiler compiler, 134 ElementAstCreationContext context,
135 Tracer tracer,
136 ConstantSystem constantSystem,
137 Element element, 135 Element element,
138 cps_ir.ExecutableDefinition cpsDefinition) { 136 cps_ir.ExecutableDefinition cpsDefinition) {
139 // Transformations on the CPS IR. 137 // Transformations on the CPS IR.
140 if (tracer != null) { 138 context.traceCompilation(element.name);
141 tracer.traceCompilation(element.name, null);
142 }
143
144 void traceGraph(String title, var irObject) {
145 if (tracer != null) {
146 tracer.traceGraph(title, irObject);
147 }
148 }
149 139
150 // TODO(karlklose): enable type propagation for dart2dart when constant 140 // TODO(karlklose): enable type propagation for dart2dart when constant
151 // types are correctly marked as instantiated (Issue 21880). 141 // types are correctly marked as instantiated (Issue 21880).
152 new TypePropagator(compiler.types, constantSystem, new UnitTypeSystem(), 142 new TypePropagator(context.dartTypes,
153 compiler.internalError).rewrite(cpsDefinition); 143 context.constantSystem,
154 traceGraph("Sparse constant propagation", cpsDefinition); 144 new UnitTypeSystem(),
145 context.internalError)
146 .rewrite(cpsDefinition);
147 context.traceGraph("Sparse constant propagation", cpsDefinition);
155 new RedundantPhiEliminator().rewrite(cpsDefinition); 148 new RedundantPhiEliminator().rewrite(cpsDefinition);
156 traceGraph("Redundant phi elimination", cpsDefinition); 149 context.traceGraph("Redundant phi elimination", cpsDefinition);
157 new ShrinkingReducer().rewrite(cpsDefinition); 150 new ShrinkingReducer().rewrite(cpsDefinition);
158 traceGraph("Shrinking reductions", cpsDefinition); 151 context.traceGraph("Shrinking reductions", cpsDefinition);
159 152
160 // Do not rewrite the IR after variable allocation. Allocation 153 // Do not rewrite the IR after variable allocation. Allocation
161 // makes decisions based on an approximation of IR variable live 154 // makes decisions based on an approximation of IR variable live
162 // ranges that can be invalidated by transforming the IR. 155 // ranges that can be invalidated by transforming the IR.
163 new cps_ir.RegisterAllocator().visit(cpsDefinition); 156 new cps_ir.RegisterAllocator().visit(cpsDefinition);
164 157
165 tree_builder.Builder builder = 158 tree_builder.Builder builder =
166 new tree_builder.Builder(compiler.internalError); 159 new tree_builder.Builder(context.internalError);
167 tree_ir.ExecutableDefinition treeDefinition = builder.build(cpsDefinition); 160 tree_ir.ExecutableDefinition treeDefinition = builder.build(cpsDefinition);
168 assert(treeDefinition != null); 161 assert(treeDefinition != null);
169 traceGraph('Tree builder', treeDefinition); 162 context.traceGraph('Tree builder', treeDefinition);
170 163
171 // Transformations on the Tree IR. 164 // Transformations on the Tree IR.
172 new StatementRewriter().rewrite(treeDefinition); 165 new StatementRewriter().rewrite(treeDefinition);
173 traceGraph('Statement rewriter', treeDefinition); 166 context.traceGraph('Statement rewriter', treeDefinition);
174 new CopyPropagator().rewrite(treeDefinition); 167 new CopyPropagator().rewrite(treeDefinition);
175 traceGraph('Copy propagation', treeDefinition); 168 context.traceGraph('Copy propagation', treeDefinition);
176 new LoopRewriter().rewrite(treeDefinition); 169 new LoopRewriter().rewrite(treeDefinition);
177 traceGraph('Loop rewriter', treeDefinition); 170 context.traceGraph('Loop rewriter', treeDefinition);
178 new LogicalRewriter().rewrite(treeDefinition); 171 new LogicalRewriter().rewrite(treeDefinition);
179 traceGraph('Logical rewriter', treeDefinition); 172 context.traceGraph('Logical rewriter', treeDefinition);
180 new backend_ast_emitter.UnshadowParameters().unshadow(treeDefinition); 173 new backend_ast_emitter.UnshadowParameters().unshadow(treeDefinition);
181 traceGraph('Unshadow parameters', treeDefinition); 174 context.traceGraph('Unshadow parameters', treeDefinition);
182 175
183 TreeElementMapping treeElements = new TreeElementMapping(element); 176 TreeElementMapping treeElements = new TreeElementMapping(element);
184 backend_ast.ExecutableDefinition backendAst = 177 backend_ast.ExecutableDefinition backendAst =
185 backend_ast_emitter.emit(treeDefinition); 178 backend_ast_emitter.emit(treeDefinition);
186 Node frontend_ast = backend2frontend.emit(treeElements, backendAst); 179 Node frontend_ast = backend2frontend.emit(treeElements, backendAst);
187 return new ElementAst(frontend_ast, treeElements); 180 return new ElementAst(frontend_ast, treeElements);
188 181
189 } 182 }
190 183
191 /** 184 /**
192 * Tells whether we should output given element. Corelib classes like 185 * Tells whether we should output given element. Corelib classes like
193 * Object should not be in the resulting code. 186 * Object should not be in the resulting code.
194 */ 187 */
195 @override 188 @override
196 bool shouldOutput(Element element) { 189 bool shouldOutput(Element element) {
197 return (!element.library.isPlatformLibrary && 190 return (!element.library.isPlatformLibrary &&
198 !element.isSynthesized && 191 !element.isSynthesized &&
199 element is! AbstractFieldElement) 192 element is! AbstractFieldElement)
200 || mirrorRenamer.isMirrorHelperLibrary(element.library); 193 || mirrorRenamer.isMirrorHelperLibrary(element.library);
201 } 194 }
202 195
203 void assembleProgram() { 196 void assembleProgram() {
197 ElementAstCreationContext context =
198 new _ElementAstCreationContext(compiler, constantSystem);
204 199
205 ElementAst computeElementAst(AstElement element) { 200 ElementAst computeElementAst(AstElement element) {
206 if (!compiler.irBuilder.hasIr(element)) { 201 if (!compiler.irBuilder.hasIr(element)) {
207 return new ElementAst(element.resolvedAst.node, 202 return new ElementAst(element.resolvedAst.node,
208 element.resolvedAst.elements); 203 element.resolvedAst.elements);
209 } else { 204 } else {
210 cps_ir.ExecutableDefinition definition = 205 cps_ir.ExecutableDefinition definition =
211 compiler.irBuilder.getIr(element); 206 compiler.irBuilder.getIr(element);
212 return createElementAst(compiler, 207 return createElementAst(context, element, definition);
213 compiler.tracer, constantSystem, element, definition);
214 } 208 }
215 } 209 }
216 210
217 // TODO(johnniwinther): Remove the need for this method. 211 // TODO(johnniwinther): Remove the need for this method.
218 void postProcessElementAst( 212 void postProcessElementAst(
219 AstElement element, ElementAst elementAst, 213 AstElement element, ElementAst elementAst,
220 newTypedefElementCallback, 214 newTypedefElementCallback,
221 newClassElementCallback) { 215 newClassElementCallback) {
222 ReferencedElementCollector collector = 216 ReferencedElementCollector collector =
223 new ReferencedElementCollector(compiler, 217 new ReferencedElementCollector(compiler,
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 } 515 }
522 516
523 ConstantExpression compileMetadata(MetadataAnnotation metadata, 517 ConstantExpression compileMetadata(MetadataAnnotation metadata,
524 Node node, 518 Node node,
525 TreeElements elements) { 519 TreeElements elements) {
526 return measure(() { 520 return measure(() {
527 return constantCompiler.compileMetadata(metadata, node, elements); 521 return constantCompiler.compileMetadata(metadata, node, elements);
528 }); 522 });
529 } 523 }
530 } 524 }
525
526 abstract class ElementAstCreationContext {
527 DartTypes get dartTypes;
528 ConstantSystem get constantSystem;
529 InternalErrorFunction get internalError;
530
531 void traceCompilation(String name) {}
karlklose 2014/12/18 09:49:34 Make these two functions abstract?
Johnni Winther 2014/12/18 10:05:38 Done.
532 void traceGraph(String title, var irObject) {}
533 }
534
535 class _ElementAstCreationContext implements ElementAstCreationContext {
536 final Compiler compiler;
537 final ConstantSystem constantSystem;
538
539 _ElementAstCreationContext(this.compiler, this.constantSystem);
540
541 void traceCompilation(String name) {
542 compiler.tracer.traceCompilation(name, null);
543 }
544
545 void traceGraph(String title, var irObject) {
546 compiler.tracer.traceGraph(title, irObject);
547 }
548
549 DartTypes get dartTypes => compiler.types;
550
551 InternalErrorFunction get internalError => compiler.internalError;
552 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698