Chromium Code Reviews| 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 traceGraph("IR Builder", cpsNode); | 119 traceGraph("IR Builder", cpsNode); |
| 120 // Eliminating redundant phis before the unsugaring pass will make it | 120 // Eliminating redundant phis before the unsugaring pass will make it |
| 121 // insert fewer getInterceptor calls. | 121 // insert fewer getInterceptor calls. |
| 122 new RedundantPhiEliminator().rewrite(cpsNode); | 122 new RedundantPhiEliminator().rewrite(cpsNode); |
| 123 traceGraph("Redundant phi elimination", cpsNode); | 123 traceGraph("Redundant phi elimination", cpsNode); |
| 124 new UnsugarVisitor(glue).rewrite(cpsNode); | 124 new UnsugarVisitor(glue).rewrite(cpsNode); |
| 125 traceGraph("Unsugaring", cpsNode); | 125 traceGraph("Unsugaring", cpsNode); |
| 126 return cpsNode; | 126 return cpsNode; |
| 127 } | 127 } |
| 128 | 128 |
| 129 static const Pattern PRINT_TYPED_IR_FILTER = null; | 129 static const Pattern PRINT_TYPED_IR_FILTER = ''; |
|
Kevin Millikin (Google)
2015/09/18 09:00:58
I won't commit this change.
| |
| 130 | 130 |
| 131 String formatTypeMask(TypeMask type) { | 131 String formatTypeMask(TypeMask type) { |
| 132 if (type is UnionTypeMask) { | 132 if (type is UnionTypeMask) { |
| 133 return '[${type.disjointMasks.map(formatTypeMask).join(', ')}]'; | 133 return '[${type.disjointMasks.map(formatTypeMask).join(', ')}]'; |
| 134 } else if (type is FlatTypeMask) { | 134 } else if (type is FlatTypeMask) { |
| 135 if (type.isEmpty) { | 135 if (type.isEmpty) { |
| 136 return "null"; | 136 return "null"; |
| 137 } | 137 } |
| 138 String suffix = (type.isExact ? "" : "+") + (type.isNullable ? "?" : "!"); | 138 String suffix = (type.isExact ? "" : "+") + (type.isNullable ? "?" : "!"); |
| 139 return '${type.base.name}$suffix'; | 139 return '${type.base.name}$suffix'; |
| 140 } else if (type is ForwardingTypeMask) { | 140 } else if (type is ForwardingTypeMask) { |
| 141 return formatTypeMask(type.forwardTo); | 141 return formatTypeMask(type.forwardTo); |
| 142 } | 142 } |
| 143 throw 'unsupported: $type'; | 143 throw 'unsupported: $type'; |
| 144 } | 144 } |
| 145 | 145 |
| 146 void dumpTypedIR(cps.FunctionDefinition cpsNode, | 146 void dumpTypedIR(cps.FunctionDefinition cpsNode, |
| 147 TypePropagator typePropagator) { | 147 TypePropagator typePropagator) { |
| 148 if (PRINT_TYPED_IR_FILTER != null && | 148 if (PRINT_TYPED_IR_FILTER != null && |
| 149 PRINT_TYPED_IR_FILTER.matchAsPrefix(cpsNode.element.name) != null) { | 149 PRINT_TYPED_IR_FILTER.matchAsPrefix(cpsNode.element.name) != null) { |
| 150 String printType(nodeOrRef, String s) { | 150 String printType(nodeOrRef, String s) { |
| 151 cps.Node node = nodeOrRef is cps.Reference | 151 cps.Node node = nodeOrRef is cps.Reference |
| 152 ? nodeOrRef.definition | 152 ? nodeOrRef.definition |
| 153 : nodeOrRef; | 153 : nodeOrRef; |
| 154 var type = typePropagator.getType(node); | 154 return node is cps.Variable && node.type != null |
| 155 return type == null ? s : "$s:${formatTypeMask(type.type)}"; | 155 ? '$s:${formatTypeMask(node.type)}' |
| 156 : s; | |
| 156 } | 157 } |
| 157 DEBUG_MODE = true; | 158 DEBUG_MODE = true; |
| 158 print(new SExpressionStringifier(printType).visit(cpsNode)); | 159 print(new SExpressionStringifier(printType).visit(cpsNode)); |
| 159 } | 160 } |
| 160 } | 161 } |
| 161 | 162 |
| 162 static bool checkCpsIntegrity(cps.FunctionDefinition node) { | 163 static bool checkCpsIntegrity(cps.FunctionDefinition node) { |
| 163 new CheckCpsIntegrity().check(node); | 164 new CheckCpsIntegrity().check(node); |
| 164 return true; // So this can be used from assert(). | 165 return true; // So this can be used from assert(). |
| 165 } | 166 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 242 // TODO(sigurdm): Make a better list of tasks. | 243 // TODO(sigurdm): Make a better list of tasks. |
| 243 return <CompilerTask>[irBuilderTask]..addAll(fallbackCompiler.tasks); | 244 return <CompilerTask>[irBuilderTask]..addAll(fallbackCompiler.tasks); |
| 244 } | 245 } |
| 245 | 246 |
| 246 js.Node attachPosition(js.Node node, AstElement element) { | 247 js.Node attachPosition(js.Node node, AstElement element) { |
| 247 return node.withSourceInformation( | 248 return node.withSourceInformation( |
| 248 sourceInformationFactory.createBuilderForContext(element) | 249 sourceInformationFactory.createBuilderForContext(element) |
| 249 .buildDeclaration(element)); | 250 .buildDeclaration(element)); |
| 250 } | 251 } |
| 251 } | 252 } |
| OLD | NEW |