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

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

Issue 1068243002: Overhaul tree IR visitor and rename IR classes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add dummy use for RootVisitor and InitializerVisitor without arguments Created 5 years, 8 months 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 // Enqueue the methods that the VM might invoke on user objects because 124 // Enqueue the methods that the VM might invoke on user objects because
125 // we don't trust the resolution to always get these included. 125 // we don't trust the resolution to always get these included.
126 world.registerInvocation(new Selector.call("toString", null, 0)); 126 world.registerInvocation(new Selector.call("toString", null, 0));
127 world.registerInvokedGetter(new Selector.getter("hashCode", null)); 127 world.registerInvokedGetter(new Selector.getter("hashCode", null));
128 world.registerInvocation(new Selector.binaryOperator("==")); 128 world.registerInvocation(new Selector.binaryOperator("=="));
129 world.registerInvocation(new Selector.call("compareTo", null, 1)); 129 world.registerInvocation(new Selector.call("compareTo", null, 1));
130 } 130 }
131 131
132 void codegen(CodegenWorkItem work) { } 132 void codegen(CodegenWorkItem work) { }
133 133
134 static bool checkTreeIntegrity(tree_ir.ExecutableDefinition node) { 134 static bool checkTreeIntegrity(tree_ir.RootNode node) {
135 new CheckTreeIntegrity().check(node); 135 new CheckTreeIntegrity().check(node);
136 return true; // So this can be used from assert(). 136 return true; // So this can be used from assert().
137 } 137 }
138 138
139 static bool checkCpsIntegrity(cps_ir.ExecutableDefinition node) { 139 static bool checkCpsIntegrity(cps_ir.RootNode node) {
140 new CheckCpsIntegrity().check(node); 140 new CheckCpsIntegrity().check(node);
141 return true; // So this can be used from assert(). 141 return true; // So this can be used from assert().
142 } 142 }
143 143
144 /// Create an [ElementAst] from the CPS IR. 144 /// Create an [ElementAst] from the CPS IR.
145 static ElementAst createElementAst( 145 static ElementAst createElementAst(
146 ElementAstCreationContext context, 146 ElementAstCreationContext context,
147 Element element, 147 Element element,
148 cps_ir.ExecutableDefinition cpsDefinition) { 148 cps_ir.RootNode cpsRoot) {
149 context.traceCompilation(element.name); 149 context.traceCompilation(element.name);
150 context.traceGraph('CPS builder', cpsDefinition); 150 context.traceGraph('CPS builder', cpsRoot);
151 assert(checkCpsIntegrity(cpsDefinition)); 151 assert(checkCpsIntegrity(cpsRoot));
152 152
153 // Transformations on the CPS IR. 153 // Transformations on the CPS IR.
154 void applyCpsPass(cps_opt.Pass pass) { 154 void applyCpsPass(cps_opt.Pass pass) {
155 pass.rewrite(cpsDefinition); 155 pass.rewrite(cpsRoot);
156 context.traceGraph(pass.passName, cpsDefinition); 156 context.traceGraph(pass.passName, cpsRoot);
157 assert(checkCpsIntegrity(cpsDefinition)); 157 assert(checkCpsIntegrity(cpsRoot));
158 } 158 }
159 159
160 // TODO(karlklose): enable type propagation for dart2dart when constant 160 // TODO(karlklose): enable type propagation for dart2dart when constant
161 // types are correctly marked as instantiated (Issue 21880). 161 // types are correctly marked as instantiated (Issue 21880).
162 TypePropagator typePropagator = new TypePropagator( 162 TypePropagator typePropagator = new TypePropagator(
163 context.dartTypes, 163 context.dartTypes,
164 context.constantSystem, 164 context.constantSystem,
165 new UnitTypeSystem(), 165 new UnitTypeSystem(),
166 context.internalError); 166 context.internalError);
167 applyCpsPass(typePropagator); 167 applyCpsPass(typePropagator);
168 applyCpsPass(new RedundantPhiEliminator()); 168 applyCpsPass(new RedundantPhiEliminator());
169 applyCpsPass(new ShrinkingReducer()); 169 applyCpsPass(new ShrinkingReducer());
170 170
171 tree_builder.Builder builder = 171 tree_builder.Builder builder =
172 new tree_builder.Builder(context.internalError); 172 new tree_builder.Builder(context.internalError);
173 tree_ir.ExecutableDefinition treeDefinition = builder.build(cpsDefinition); 173 tree_ir.RootNode treeRoot = builder.build(cpsRoot);
174 assert(treeDefinition != null); 174 assert(treeRoot != null);
175 context.traceGraph('Tree builder', treeDefinition); 175 context.traceGraph('Tree builder', treeRoot);
176 assert(checkTreeIntegrity(treeDefinition)); 176 assert(checkTreeIntegrity(treeRoot));
177 177
178 // Transformations on the Tree IR. 178 // Transformations on the Tree IR.
179 void applyTreePass(tree_opt.Pass pass) { 179 void applyTreePass(tree_opt.Pass pass) {
180 pass.rewrite(treeDefinition); 180 pass.rewrite(treeRoot);
181 context.traceGraph(pass.passName, treeDefinition); 181 context.traceGraph(pass.passName, treeRoot);
182 assert(checkTreeIntegrity(treeDefinition)); 182 assert(checkTreeIntegrity(treeRoot));
183 } 183 }
184 184
185 applyTreePass(new StatementRewriter()); 185 applyTreePass(new StatementRewriter());
186 applyTreePass(new VariableMerger()); 186 applyTreePass(new VariableMerger());
187 applyTreePass(new LoopRewriter()); 187 applyTreePass(new LoopRewriter());
188 applyTreePass(new LogicalRewriter()); 188 applyTreePass(new LogicalRewriter());
189 189
190 // Backend-specific transformations. 190 // Backend-specific transformations.
191 new backend_ast_emitter.UnshadowParameters().unshadow(treeDefinition); 191 new backend_ast_emitter.UnshadowParameters().unshadow(treeRoot);
192 context.traceGraph('Unshadow parameters', treeDefinition); 192 context.traceGraph('Unshadow parameters', treeRoot);
193 193
194 TreeElementMapping treeElements = new TreeElementMapping(element); 194 TreeElementMapping treeElements = new TreeElementMapping(element);
195 backend_ast.ExecutableDefinition backendAst = 195 backend_ast.RootNode backendAst =
196 backend_ast_emitter.emit(treeDefinition); 196 backend_ast_emitter.emit(treeRoot);
197 Node frontend_ast = backend2frontend.emit(treeElements, backendAst); 197 Node frontend_ast = backend2frontend.emit(treeElements, backendAst);
198 return new ElementAst(frontend_ast, treeElements); 198 return new ElementAst(frontend_ast, treeElements);
199 199
200 } 200 }
201 201
202 /** 202 /**
203 * Tells whether we should output given element. Corelib classes like 203 * Tells whether we should output given element. Corelib classes like
204 * Object should not be in the resulting code. 204 * Object should not be in the resulting code.
205 */ 205 */
206 @override 206 @override
207 bool shouldOutput(Element element) { 207 bool shouldOutput(Element element) {
208 return (!element.library.isPlatformLibrary && 208 return (!element.library.isPlatformLibrary &&
209 !element.isSynthesized && 209 !element.isSynthesized &&
210 element is! AbstractFieldElement) 210 element is! AbstractFieldElement)
211 || mirrorRenamer.isMirrorHelperLibrary(element.library); 211 || mirrorRenamer.isMirrorHelperLibrary(element.library);
212 } 212 }
213 213
214 int assembleProgram() { 214 int assembleProgram() {
215 ElementAstCreationContext context = 215 ElementAstCreationContext context =
216 new _ElementAstCreationContext(compiler, constantSystem); 216 new _ElementAstCreationContext(compiler, constantSystem);
217 217
218 ElementAst computeElementAst(AstElement element) { 218 ElementAst computeElementAst(AstElement element) {
219 if (!compiler.irBuilder.hasIr(element)) { 219 if (!compiler.irBuilder.hasIr(element)) {
220 return new ElementAst(element.resolvedAst.node, 220 return new ElementAst(element.resolvedAst.node,
221 element.resolvedAst.elements); 221 element.resolvedAst.elements);
222 } else { 222 } else {
223 cps_ir.ExecutableDefinition definition = 223 cps_ir.RootNode irNode = compiler.irBuilder.getIr(element);
224 compiler.irBuilder.getIr(element); 224 return createElementAst(context, element, irNode);
225 return createElementAst(context, element, definition);
226 } 225 }
227 } 226 }
228 227
229 // TODO(johnniwinther): Remove the need for this method. 228 // TODO(johnniwinther): Remove the need for this method.
230 void postProcessElementAst( 229 void postProcessElementAst(
231 AstElement element, ElementAst elementAst, 230 AstElement element, ElementAst elementAst,
232 newTypedefElementCallback, 231 newTypedefElementCallback,
233 newClassElementCallback) { 232 newClassElementCallback) {
234 ReferencedElementCollector collector = 233 ReferencedElementCollector collector =
235 new ReferencedElementCollector(compiler, 234 new ReferencedElementCollector(compiler,
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 } 556 }
558 557
559 void traceGraph(String title, var irObject) { 558 void traceGraph(String title, var irObject) {
560 compiler.tracer.traceGraph(title, irObject); 559 compiler.tracer.traceGraph(title, irObject);
561 } 560 }
562 561
563 DartTypes get dartTypes => compiler.types; 562 DartTypes get dartTypes => compiler.types;
564 563
565 InternalErrorFunction get internalError => compiler.internalError; 564 InternalErrorFunction get internalError => compiler.internalError;
566 } 565 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/type_propagation.dart ('k') | pkg/compiler/lib/src/dart_backend/backend_ast_emitter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698