| 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 26 matching lines...) Expand all Loading... |
| 37 final IrBuilderTask irBuilderTask; | 37 final IrBuilderTask irBuilderTask; |
| 38 final ConstantSystem constantSystem; | 38 final ConstantSystem constantSystem; |
| 39 final Compiler compiler; | 39 final Compiler compiler; |
| 40 final Glue glue; | 40 final Glue glue; |
| 41 | 41 |
| 42 TypeSystem types; | 42 TypeSystem types; |
| 43 | 43 |
| 44 // TODO(karlklose,sigurm): remove and update dart-doc of [compile]. | 44 // TODO(karlklose,sigurm): remove and update dart-doc of [compile]. |
| 45 final FunctionCompiler fallbackCompiler; | 45 final FunctionCompiler fallbackCompiler; |
| 46 | 46 |
| 47 // TODO(sigurdm): Assign this. | 47 Tracer get tracer => compiler.tracer; |
| 48 Tracer tracer; | |
| 49 | 48 |
| 50 CspFunctionCompiler(Compiler compiler, JavaScriptBackend backend) | 49 CspFunctionCompiler(Compiler compiler, JavaScriptBackend backend) |
| 51 : irBuilderTask = new IrBuilderTask(compiler), | 50 : irBuilderTask = new IrBuilderTask(compiler), |
| 52 fallbackCompiler = new ssa.SsaFunctionCompiler(backend, true), | 51 fallbackCompiler = new ssa.SsaFunctionCompiler(backend, true), |
| 53 constantSystem = backend.constantSystem, | 52 constantSystem = backend.constantSystem, |
| 54 compiler = compiler, | 53 compiler = compiler, |
| 55 glue = new Glue(compiler); | 54 glue = new Glue(compiler); |
| 56 | 55 |
| 57 String get name => 'CPS Ir pipeline'; | 56 String get name => 'CPS Ir pipeline'; |
| 58 | 57 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 | 90 |
| 92 void traceGraph(String title, var irObject) { | 91 void traceGraph(String title, var irObject) { |
| 93 if (tracer != null) { | 92 if (tracer != null) { |
| 94 tracer.traceGraph(title, irObject); | 93 tracer.traceGraph(title, irObject); |
| 95 } | 94 } |
| 96 } | 95 } |
| 97 | 96 |
| 98 cps.FunctionDefinition compileToCpsIR(AstElement element) { | 97 cps.FunctionDefinition compileToCpsIR(AstElement element) { |
| 99 // TODO(sigurdm): Support these constructs. | 98 // TODO(sigurdm): Support these constructs. |
| 100 if (element.isGenerativeConstructorBody || | 99 if (element.isGenerativeConstructorBody || |
| 101 element.enclosingClass is ClosureClassElement || | |
| 102 element.isNative || | 100 element.isNative || |
| 103 element.isField) { | 101 element.isField) { |
| 104 giveUp('unsupported element kind: ${element.name}:${element.kind}'); | 102 giveUp('unsupported element kind: ${element.name}:${element.kind}'); |
| 105 } | 103 } |
| 106 | 104 |
| 107 cps.FunctionDefinition cpsNode = irBuilderTask.buildNode(element); | 105 cps.FunctionDefinition cpsNode = irBuilderTask.buildNode(element); |
| 108 if (cpsNode == null) { | 106 if (cpsNode == null) { |
| 109 giveUp('unable to build cps definition of $element'); | 107 giveUp('unable to build cps definition of $element'); |
| 110 } | 108 } |
| 109 traceGraph("IR Builder", cpsNode); |
| 111 new UnsugarVisitor(glue).rewrite(cpsNode); | 110 new UnsugarVisitor(glue).rewrite(cpsNode); |
| 111 traceGraph("Unsugaring", cpsNode); |
| 112 return cpsNode; | 112 return cpsNode; |
| 113 } | 113 } |
| 114 | 114 |
| 115 static const Pattern PRINT_TYPED_IR_FILTER = null; | 115 static const Pattern PRINT_TYPED_IR_FILTER = null; |
| 116 | 116 |
| 117 String formatTypeMask(TypeMask type) { | 117 String formatTypeMask(TypeMask type) { |
| 118 if (type is UnionTypeMask) { | 118 if (type is UnionTypeMask) { |
| 119 return '[${type.disjointMasks.map(formatTypeMask).join(', ')}]'; | 119 return '[${type.disjointMasks.map(formatTypeMask).join(', ')}]'; |
| 120 } else if (type is FlatTypeMask) { | 120 } else if (type is FlatTypeMask) { |
| 121 if (type.isEmpty) { | 121 if (type.isEmpty) { |
| 122 return "null"; | 122 return "null"; |
| 123 } | 123 } |
| 124 String suffix = (type.isExact ? "" : "+") + (type.isNullable ? "?" : "!"); | 124 String suffix = (type.isExact ? "" : "+") + (type.isNullable ? "?" : "!"); |
| 125 return '${type.base.name}$suffix'; | 125 return '${type.base.name}$suffix'; |
| 126 } else if (type is ForwardingTypeMask) { | 126 } else if (type is ForwardingTypeMask) { |
| 127 return formatTypeMask(type.forwardTo); | 127 return formatTypeMask(type.forwardTo); |
| 128 } | 128 } |
| 129 throw 'unsupported: $type'; | 129 throw 'unsupported: $type'; |
| 130 } | 130 } |
| 131 | 131 |
| 132 cps.FunctionDefinition optimizeCpsIR(cps.FunctionDefinition cpsNode) { | 132 cps.FunctionDefinition optimizeCpsIR(cps.FunctionDefinition cpsNode) { |
| 133 // Transformations on the CPS IR. | 133 // Transformations on the CPS IR. |
| 134 traceGraph("IR Builder", cpsNode); | |
| 135 | 134 |
| 136 TypePropagator typePropagator = new TypePropagator<TypeMask>( | 135 TypePropagator typePropagator = new TypePropagator<TypeMask>( |
| 137 compiler.types, | 136 compiler.types, |
| 138 constantSystem, | 137 constantSystem, |
| 139 new TypeMaskSystem(compiler), | 138 new TypeMaskSystem(compiler), |
| 140 compiler.internalError); | 139 compiler.internalError); |
| 141 typePropagator.rewrite(cpsNode); | 140 typePropagator.rewrite(cpsNode); |
| 142 traceGraph("Sparse constant propagation", cpsNode); | 141 traceGraph("Sparse constant propagation", cpsNode); |
| 143 | 142 |
| 144 if (PRINT_TYPED_IR_FILTER != null && | 143 if (PRINT_TYPED_IR_FILTER != null && |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 endSourcePosition = | 226 endSourcePosition = |
| 228 new TokenSourceFileLocation(sourceFile, endToken, name); | 227 new TokenSourceFileLocation(sourceFile, endToken, name); |
| 229 } | 228 } |
| 230 return node.withPosition(sourcePosition, endSourcePosition); | 229 return node.withPosition(sourcePosition, endSourcePosition); |
| 231 } | 230 } |
| 232 | 231 |
| 233 SourceFile sourceFileOfElement(Element element) { | 232 SourceFile sourceFileOfElement(Element element) { |
| 234 return element.implementation.compilationUnit.script.file; | 233 return element.implementation.compilationUnit.script.file; |
| 235 } | 234 } |
| 236 } | 235 } |
| OLD | NEW |