| 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 library tree_ir_builder; | 5 library tree_ir_builder; |
| 6 | 6 |
| 7 import '../dart2jslib.dart' as dart2js; | 7 import '../dart2jslib.dart' as dart2js; |
| 8 import '../dart_types.dart'; | 8 import '../dart_types.dart'; |
| 9 import '../elements/elements.dart'; | 9 import '../elements/elements.dart'; |
| 10 import '../cps_ir/cps_ir_nodes.dart' as cps_ir; | 10 import '../cps_ir/cps_ir_nodes.dart' as cps_ir; |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 returnContinuation = node.body.returnContinuation; | 182 returnContinuation = node.body.returnContinuation; |
| 183 | 183 |
| 184 phiTempVar = new Variable(node.element, null); | 184 phiTempVar = new Variable(node.element, null); |
| 185 body = visit(node.body); | 185 body = visit(node.body); |
| 186 } | 186 } |
| 187 | 187 |
| 188 return new ConstructorDefinition(node.element, parameters, | 188 return new ConstructorDefinition(node.element, parameters, |
| 189 body, initializers, node.localConstants, node.defaultParameterValues); | 189 body, initializers, node.localConstants, node.defaultParameterValues); |
| 190 } | 190 } |
| 191 | 191 |
| 192 | 192 /// Returns a list of variables corresponding to the arguments to a method |
| 193 /// call or similar construct. |
| 194 /// |
| 195 /// The `readCount` for these variables will be incremented. |
| 196 /// |
| 197 /// The list will be typed as a list of [Expression] to allow inplace updates |
| 198 /// on the list during the rewrite phases. |
| 193 List<Expression> translateArguments(List<cps_ir.Reference> args) { | 199 List<Expression> translateArguments(List<cps_ir.Reference> args) { |
| 194 return new List<Expression>.generate(args.length, | 200 return new List<Expression>.generate(args.length, |
| 195 (int index) => getVariableReference(args[index]), | 201 (int index) => getVariableReference(args[index]), |
| 196 growable: false); | 202 growable: false); |
| 197 } | 203 } |
| 198 | 204 |
| 205 /// Returns the list of variables corresponding to the arguments to a join |
| 206 /// continuation. |
| 207 /// |
| 208 /// The `readCount` of these variables will not be incremented. Instead, |
| 209 /// [buildPhiAssignments] will handle the increment, if necessary. |
| 199 List<Variable> translatePhiArguments(List<cps_ir.Reference> args) { | 210 List<Variable> translatePhiArguments(List<cps_ir.Reference> args) { |
| 200 return new List<Variable>.generate(args.length, | 211 return new List<Variable>.generate(args.length, |
| 201 (int index) => getVariableReference(args[index])); | 212 (int index) => getVariable(args[index].definition), |
| 213 growable: false); |
| 202 } | 214 } |
| 203 | 215 |
| 204 Statement buildContinuationAssignment( | 216 Statement buildContinuationAssignment( |
| 205 cps_ir.Parameter parameter, | 217 cps_ir.Parameter parameter, |
| 206 Expression argument, | 218 Expression argument, |
| 207 Statement buildRest()) { | 219 Statement buildRest()) { |
| 208 Variable variable = getVariable(parameter); | 220 Variable variable = getVariable(parameter); |
| 209 Statement assignment; | 221 Statement assignment; |
| 210 if (variable == null) { | 222 if (variable == null) { |
| 211 assignment = new ExpressionStatement(argument, null); | 223 assignment = new ExpressionStatement(argument, null); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 240 } | 252 } |
| 241 List<int> list = rightHand[arg]; | 253 List<int> list = rightHand[arg]; |
| 242 if (list == null) { | 254 if (list == null) { |
| 243 rightHand[arg] = list = <int>[]; | 255 rightHand[arg] = list = <int>[]; |
| 244 } | 256 } |
| 245 list.add(i); | 257 list.add(i); |
| 246 } | 258 } |
| 247 | 259 |
| 248 Statement first, current; | 260 Statement first, current; |
| 249 void addAssignment(Variable dst, Variable src) { | 261 void addAssignment(Variable dst, Variable src) { |
| 262 ++src.readCount; |
| 263 // `dst.writeCount` will be updated by the Assign constructor. |
| 250 if (first == null) { | 264 if (first == null) { |
| 251 first = current = new Assign(dst, src, null); | 265 first = current = new Assign(dst, src, null); |
| 252 } else { | 266 } else { |
| 253 current = current.next = new Assign(dst, src, null); | 267 current = current.next = new Assign(dst, src, null); |
| 254 } | 268 } |
| 255 } | 269 } |
| 256 | 270 |
| 257 List<Variable> assignmentSrc = new List<Variable>(parameters.length); | 271 List<Variable> assignmentSrc = new List<Variable>(parameters.length); |
| 258 List<bool> done = new List<bool>(parameters.length); | 272 List<bool> done = new List<bool>(parameters.length); |
| 259 void visitAssignment(int i) { | 273 void visitAssignment(int i) { |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 // visited. | 558 // visited. |
| 545 internalError(CURRENT_ELEMENT_SPANNABLE, 'Unexpected IR node: $node.'); | 559 internalError(CURRENT_ELEMENT_SPANNABLE, 'Unexpected IR node: $node.'); |
| 546 return null; | 560 return null; |
| 547 } | 561 } |
| 548 | 562 |
| 549 Expression visitIsTrue(cps_ir.IsTrue node) { | 563 Expression visitIsTrue(cps_ir.IsTrue node) { |
| 550 return getVariableReference(node.value); | 564 return getVariableReference(node.value); |
| 551 } | 565 } |
| 552 } | 566 } |
| 553 | 567 |
| OLD | NEW |