| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 /// Generate code using the cps-based IR pipeline. | 5 /// Generate code using the cps-based IR pipeline. |
| 6 library code_generator_task; | 6 library code_generator_task; |
| 7 | 7 |
| 8 import 'glue.dart'; | 8 import 'glue.dart'; |
| 9 import 'codegen.dart'; | 9 import 'codegen.dart'; |
| 10 import 'unsugar.dart'; | 10 import 'unsugar.dart'; |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 TypePropagator typePropagator = new TypePropagator<TypeMask>( | 172 TypePropagator typePropagator = new TypePropagator<TypeMask>( |
| 173 compiler.types, | 173 compiler.types, |
| 174 constantSystem, | 174 constantSystem, |
| 175 new TypeMaskSystem(compiler), | 175 new TypeMaskSystem(compiler), |
| 176 compiler.internalError); | 176 compiler.internalError); |
| 177 applyCpsPass(typePropagator); | 177 applyCpsPass(typePropagator); |
| 178 dumpTypedIR(cpsNode, typePropagator); | 178 dumpTypedIR(cpsNode, typePropagator); |
| 179 applyCpsPass(new RedundantPhiEliminator()); | 179 applyCpsPass(new RedundantPhiEliminator()); |
| 180 applyCpsPass(new ShrinkingReducer()); | 180 applyCpsPass(new ShrinkingReducer()); |
| 181 | 181 |
| 182 // Do not rewrite the IR after variable allocation. Allocation | |
| 183 // makes decisions based on an approximation of IR variable live | |
| 184 // ranges that can be invalidated by transforming the IR. | |
| 185 new cps.RegisterAllocator(compiler.internalError).visit(cpsNode); | |
| 186 return cpsNode; | 182 return cpsNode; |
| 187 } | 183 } |
| 188 | 184 |
| 189 tree_ir.FunctionDefinition compileToTreeIR(cps.FunctionDefinition cpsNode) { | 185 tree_ir.FunctionDefinition compileToTreeIR(cps.FunctionDefinition cpsNode) { |
| 190 tree_builder.Builder builder = new JsTreeBuilder( | 186 tree_builder.Builder builder = new JsTreeBuilder( |
| 191 compiler.internalError, compiler.identicalFunction, glue); | 187 compiler.internalError, compiler.identicalFunction, glue); |
| 192 tree_ir.FunctionDefinition treeNode = builder.buildFunction(cpsNode); | 188 tree_ir.FunctionDefinition treeNode = builder.buildFunction(cpsNode); |
| 193 assert(treeNode != null); | 189 assert(treeNode != null); |
| 194 traceGraph('Tree builder', treeNode); | 190 traceGraph('Tree builder', treeNode); |
| 195 assert(checkTreeIntegrity(treeNode)); | 191 assert(checkTreeIntegrity(treeNode)); |
| 196 return treeNode; | 192 return treeNode; |
| 197 } | 193 } |
| 198 | 194 |
| 199 static bool checkTreeIntegrity(tree_ir.ExecutableDefinition node) { | 195 static bool checkTreeIntegrity(tree_ir.ExecutableDefinition node) { |
| 200 new CheckTreeIntegrity().check(node); | 196 new CheckTreeIntegrity().check(node); |
| 201 return true; // So this can be used from assert(). | 197 return true; // So this can be used from assert(). |
| 202 } | 198 } |
| 203 | 199 |
| 204 tree_ir.FunctionDefinition optimizeTreeIR(tree_ir.FunctionDefinition node) { | 200 tree_ir.FunctionDefinition optimizeTreeIR(tree_ir.FunctionDefinition node) { |
| 205 void applyTreePass(tree_opt.Pass pass) { | 201 void applyTreePass(tree_opt.Pass pass) { |
| 206 pass.rewrite(node); | 202 pass.rewrite(node); |
| 207 traceGraph(pass.passName, node); | 203 traceGraph(pass.passName, node); |
| 208 assert(checkTreeIntegrity(node)); | 204 assert(checkTreeIntegrity(node)); |
| 209 } | 205 } |
| 210 | 206 |
| 211 applyTreePass(new StatementRewriter()); | 207 applyTreePass(new StatementRewriter()); |
| 212 applyTreePass(new CopyPropagator()); | 208 applyTreePass(new VariableMerger()); |
| 213 applyTreePass(new LoopRewriter()); | 209 applyTreePass(new LoopRewriter()); |
| 214 applyTreePass(new LogicalRewriter()); | 210 applyTreePass(new LogicalRewriter()); |
| 215 | 211 |
| 216 return node; | 212 return node; |
| 217 } | 213 } |
| 218 | 214 |
| 219 js.Fun compileToJavaScript(CodegenWorkItem work, | 215 js.Fun compileToJavaScript(CodegenWorkItem work, |
| 220 tree_ir.FunctionDefinition definition) { | 216 tree_ir.FunctionDefinition definition) { |
| 221 CodeGenerator codeGen = new CodeGenerator(glue, work.registry); | 217 CodeGenerator codeGen = new CodeGenerator(glue, work.registry); |
| 222 | 218 |
| 223 return attachPosition(codeGen.buildFunction(definition), work.element); | 219 return attachPosition(codeGen.buildFunction(definition), work.element); |
| 224 } | 220 } |
| 225 | 221 |
| 226 Iterable<CompilerTask> get tasks { | 222 Iterable<CompilerTask> get tasks { |
| 227 // TODO(sigurdm): Make a better list of tasks. | 223 // TODO(sigurdm): Make a better list of tasks. |
| 228 return <CompilerTask>[irBuilderTask]..addAll(fallbackCompiler.tasks); | 224 return <CompilerTask>[irBuilderTask]..addAll(fallbackCompiler.tasks); |
| 229 } | 225 } |
| 230 | 226 |
| 231 js.Node attachPosition(js.Node node, AstElement element) { | 227 js.Node attachPosition(js.Node node, AstElement element) { |
| 232 return node.withSourceInformation( | 228 return node.withSourceInformation( |
| 233 StartEndSourceInformation.computeSourceInformation(element)); | 229 StartEndSourceInformation.computeSourceInformation(element)); |
| 234 } | 230 } |
| 235 } | 231 } |
| OLD | NEW |