| 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 | 10 |
| 11 import '../js_backend.dart'; | 11 import '../js_backend.dart'; |
| 12 import '../../dart2jslib.dart'; | 12 import '../../dart2jslib.dart'; |
| 13 import '../../source_file.dart'; | 13 import '../../source_file.dart'; |
| 14 import '../../cps_ir/cps_ir_nodes.dart' as cps; | 14 import '../../cps_ir/cps_ir_nodes.dart' as cps; |
| 15 import '../../cps_ir/cps_ir_builder.dart'; | 15 import '../../cps_ir/cps_ir_builder.dart'; |
| 16 import '../../tree_ir/tree_ir_nodes.dart' as tree_ir; | 16 import '../../tree_ir/tree_ir_nodes.dart' as tree_ir; |
| 17 import '../../tree/tree.dart' as ast; | 17 import '../../tree/tree.dart' as ast; |
| 18 import '../../scanner/scannerlib.dart' as scanner; | 18 import '../../scanner/scannerlib.dart' as scanner; |
| 19 import '../../elements/elements.dart'; | 19 import '../../elements/elements.dart'; |
| 20 import '../../closure.dart'; | 20 import '../../closure.dart'; |
| 21 import '../../js/js.dart' as js; | 21 import '../../js/js.dart' as js; |
| 22 import '../../source_map_builder.dart'; | 22 import '../../source_map_builder.dart'; |
| 23 import '../../tree_ir/tree_ir_builder.dart' as tree_builder; | 23 import '../../tree_ir/tree_ir_builder.dart' as tree_builder; |
| 24 import '../../dart_backend/backend_ast_emitter.dart' as backend_ast_emitter; | 24 import '../../dart_backend/backend_ast_emitter.dart' as backend_ast_emitter; |
| 25 import '../../cps_ir/optimizers.dart'; | 25 import '../../cps_ir/optimizers.dart'; |
| 26 import '../../tracer.dart'; | 26 import '../../tracer.dart'; |
| 27 import '../../js_backend/codegen/codegen.dart'; | 27 import '../../js_backend/codegen/codegen.dart'; |
| 28 import '../../ssa/ssa.dart' as ssa; | 28 import '../../ssa/ssa.dart' as ssa; |
| 29 import '../../tree_ir/optimization/optimization.dart'; | 29 import '../../tree_ir/optimization/optimization.dart'; |
| 30 import '../../common.dart' show SelectorKind; |
| 31 import '../../constants/expressions.dart'; |
| 32 import '../../constants/values.dart'; |
| 33 |
| 34 class JsBackendTreeBuilder extends tree_builder.Builder { |
| 35 JsBackendTreeBuilder(Compiler compiler) : super(compiler); |
| 36 |
| 37 Selector get identicalSelector { |
| 38 return new Selector( SelectorKind.CALL, 'identical', null, 2); |
| 39 } |
| 40 |
| 41 /// TOOD(karlklose): cache this? |
| 42 tree_ir.Constant get constantTrue { |
| 43 ConstantExpression trueValue = |
| 44 new PrimitiveConstantExpression(new TrueConstantValue()); |
| 45 return new tree_ir.Constant(trueValue); |
| 46 } |
| 47 |
| 48 /** |
| 49 * Boolean conversion maps any object o into a boolean. Boolean conversion is |
| 50 * defined by the function application |
| 51 * (bool v){ |
| 52 * assert(v != null); |
| 53 * return identical(v, true); |
| 54 * }(o) |
| 55 */ |
| 56 tree_ir.Expression visitIsTrue(cps.IsTrue node) { |
| 57 tree_ir.Expression value = getVariableReference(node.value); |
| 58 /// TODO(karlklose): implement the assert(v != null) check. |
| 59 return new tree_ir.InvokeStatic( |
| 60 compiler.identicalFunction, |
| 61 identicalSelector, |
| 62 <tree_ir.Expression>[value, constantTrue]); |
| 63 } |
| 64 |
| 65 } |
| 30 | 66 |
| 31 class CspFunctionCompiler implements FunctionCompiler { | 67 class CspFunctionCompiler implements FunctionCompiler { |
| 32 final IrBuilderTask irBuilderTask; | 68 final IrBuilderTask irBuilderTask; |
| 33 final ConstantSystem constantSystem; | 69 final ConstantSystem constantSystem; |
| 34 final Compiler compiler; | 70 final Compiler compiler; |
| 35 | 71 |
| 36 // TODO(karlklose,sigurm): remove and update dart-doc of [compile]. | 72 // TODO(karlklose,sigurm): remove and update dart-doc of [compile]. |
| 37 final FunctionCompiler fallbackCompiler; | 73 final FunctionCompiler fallbackCompiler; |
| 38 | 74 |
| 39 // TODO(sigurdm): Assign this. | 75 // TODO(sigurdm): Assign this. |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 traceGraph("Shrinking reductions", cpsNode); | 150 traceGraph("Shrinking reductions", cpsNode); |
| 115 | 151 |
| 116 // Do not rewrite the IR after variable allocation. Allocation | 152 // Do not rewrite the IR after variable allocation. Allocation |
| 117 // makes decisions based on an approximation of IR variable live | 153 // makes decisions based on an approximation of IR variable live |
| 118 // ranges that can be invalidated by transforming the IR. | 154 // ranges that can be invalidated by transforming the IR. |
| 119 new cps.RegisterAllocator().visit(cpsNode); | 155 new cps.RegisterAllocator().visit(cpsNode); |
| 120 return cpsNode; | 156 return cpsNode; |
| 121 } | 157 } |
| 122 | 158 |
| 123 tree_ir.FunctionDefinition compileToTreeIR(cps.FunctionDefinition cpsNode) { | 159 tree_ir.FunctionDefinition compileToTreeIR(cps.FunctionDefinition cpsNode) { |
| 124 tree_builder.Builder builder = new tree_builder.Builder(compiler); | 160 tree_builder.Builder builder = new JsBackendTreeBuilder(compiler); |
| 125 tree_ir.FunctionDefinition treeNode = builder.build(cpsNode); | 161 tree_ir.FunctionDefinition treeNode = builder.build(cpsNode); |
| 126 assert(treeNode != null); | 162 assert(treeNode != null); |
| 127 traceGraph('Tree builder', treeNode); | 163 traceGraph('Tree builder', treeNode); |
| 128 return treeNode; | 164 return treeNode; |
| 129 } | 165 } |
| 130 | 166 |
| 131 tree_ir.FunctionDefinition optimizeTreeIR( | 167 tree_ir.FunctionDefinition optimizeTreeIR( |
| 132 tree_ir.FunctionDefinition treeNode) { | 168 tree_ir.FunctionDefinition treeNode) { |
| 133 // Transformations on the Tree IR. | 169 // Transformations on the Tree IR. |
| 134 new StatementRewriter().rewrite(treeNode); | 170 new StatementRewriter().rewrite(treeNode); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 SourceFile sourceFileOfElement(Element element) { | 229 SourceFile sourceFileOfElement(Element element) { |
| 194 return element.implementation.compilationUnit.script.file; | 230 return element.implementation.compilationUnit.script.file; |
| 195 } | 231 } |
| 196 | 232 |
| 197 js.Fun buildJavaScriptFunction(FunctionElement element, | 233 js.Fun buildJavaScriptFunction(FunctionElement element, |
| 198 List<js.Parameter> parameters, | 234 List<js.Parameter> parameters, |
| 199 js.Block body) { | 235 js.Block body) { |
| 200 return attachPosition(new js.Fun(parameters, body), element); | 236 return attachPosition(new js.Fun(parameters, body), element); |
| 201 } | 237 } |
| 202 } | 238 } |
| OLD | NEW |