| 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 void traceGraph(String title, var irObject) { | 87 void traceGraph(String title, var irObject) { |
| 88 if (tracer != null) { | 88 if (tracer != null) { |
| 89 tracer.traceGraph(title, irObject); | 89 tracer.traceGraph(title, irObject); |
| 90 } | 90 } |
| 91 } | 91 } |
| 92 | 92 |
| 93 cps.FunctionDefinition compileToCpsIR(AstElement element) { | 93 cps.FunctionDefinition compileToCpsIR(AstElement element) { |
| 94 // TODO(sigurdm): Support these constructs. | 94 // TODO(sigurdm): Support these constructs. |
| 95 if (element.isGenerativeConstructorBody || | 95 if (element.isGenerativeConstructorBody || |
| 96 element.enclosingClass is ClosureClassElement || | 96 element.enclosingClass is ClosureClassElement || |
| 97 element.isNative) { | 97 element.isNative || |
| 98 element.isField) { |
| 98 giveUp('unsupported element kind: ${element.name}:${element.kind}'); | 99 giveUp('unsupported element kind: ${element.name}:${element.kind}'); |
| 99 } | 100 } |
| 100 | 101 |
| 101 cps.FunctionDefinition cpsNode = irBuilderTask.buildNode(element); | 102 cps.FunctionDefinition cpsNode = irBuilderTask.buildNode(element); |
| 102 if (cpsNode == null) { | 103 if (cpsNode == null) { |
| 103 giveUp('unable to build cps definition of $element'); | 104 giveUp('unable to build cps definition of $element'); |
| 104 } | 105 } |
| 105 const UnsugarVisitor().rewrite(cpsNode); | 106 const UnsugarVisitor().rewrite(cpsNode); |
| 106 return cpsNode; | 107 return cpsNode; |
| 107 } | 108 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 119 | 120 |
| 120 // Do not rewrite the IR after variable allocation. Allocation | 121 // Do not rewrite the IR after variable allocation. Allocation |
| 121 // makes decisions based on an approximation of IR variable live | 122 // makes decisions based on an approximation of IR variable live |
| 122 // ranges that can be invalidated by transforming the IR. | 123 // ranges that can be invalidated by transforming the IR. |
| 123 new cps.RegisterAllocator().visit(cpsNode); | 124 new cps.RegisterAllocator().visit(cpsNode); |
| 124 return cpsNode; | 125 return cpsNode; |
| 125 } | 126 } |
| 126 | 127 |
| 127 tree_ir.FunctionDefinition compileToTreeIR(cps.FunctionDefinition cpsNode) { | 128 tree_ir.FunctionDefinition compileToTreeIR(cps.FunctionDefinition cpsNode) { |
| 128 tree_builder.Builder builder = new tree_builder.Builder(compiler); | 129 tree_builder.Builder builder = new tree_builder.Builder(compiler); |
| 129 tree_ir.FunctionDefinition treeNode = builder.build(cpsNode); | 130 tree_ir.FunctionDefinition treeNode = builder.buildFunction(cpsNode); |
| 130 assert(treeNode != null); | 131 assert(treeNode != null); |
| 131 traceGraph('Tree builder', treeNode); | 132 traceGraph('Tree builder', treeNode); |
| 132 return treeNode; | 133 return treeNode; |
| 133 } | 134 } |
| 134 | 135 |
| 135 tree_ir.FunctionDefinition optimizeTreeIR( | 136 tree_ir.FunctionDefinition optimizeTreeIR( |
| 136 tree_ir.FunctionDefinition treeNode) { | 137 tree_ir.FunctionDefinition treeNode) { |
| 137 // Transformations on the Tree IR. | 138 // Transformations on the Tree IR. |
| 138 new StatementRewriter().rewrite(treeNode); | 139 new StatementRewriter().rewrite(treeNode); |
| 139 traceGraph('Statement rewriter', treeNode); | 140 traceGraph('Statement rewriter', treeNode); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 new TokenSourceFileLocation(sourceFile, endToken, name); | 189 new TokenSourceFileLocation(sourceFile, endToken, name); |
| 189 } | 190 } |
| 190 return node.withPosition(sourcePosition, endSourcePosition); | 191 return node.withPosition(sourcePosition, endSourcePosition); |
| 191 } | 192 } |
| 192 | 193 |
| 193 SourceFile sourceFileOfElement(Element element) { | 194 SourceFile sourceFileOfElement(Element element) { |
| 194 return element.implementation.compilationUnit.script.file; | 195 return element.implementation.compilationUnit.script.file; |
| 195 } | 196 } |
| 196 | 197 |
| 197 } | 198 } |
| OLD | NEW |