| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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('tracer'); | 5 #library('tracer'); |
| 6 | 6 |
| 7 #import('dart:io'); | 7 #import('dart:io'); |
| 8 #import('ssa.dart'); | 8 #import('ssa.dart'); |
| 9 #import('../leg.dart'); | 9 #import('../leg.dart'); |
| 10 | 10 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 } | 154 } |
| 155 } | 155 } |
| 156 | 156 |
| 157 class HInstructionStringifier implements HVisitor<String> { | 157 class HInstructionStringifier implements HVisitor<String> { |
| 158 HBasicBlock currentBlock; | 158 HBasicBlock currentBlock; |
| 159 | 159 |
| 160 HInstructionStringifier(this.currentBlock); | 160 HInstructionStringifier(this.currentBlock); |
| 161 | 161 |
| 162 visit(HInstruction node) => node.accept(this); | 162 visit(HInstruction node) => node.accept(this); |
| 163 | 163 |
| 164 visitBasicBlock(HBasicBlock node) { | |
| 165 // TODO(floitsch): Need a compiler object. | |
| 166 compiler.internalError('conditionExpression should not be called', | |
| 167 instruction: node); | |
| 168 } | |
| 169 | |
| 170 String temporaryId(HInstruction instruction) { | 164 String temporaryId(HInstruction instruction) { |
| 171 String prefix; | 165 String prefix; |
| 172 HType type = instruction.propagatedType; | 166 HType type = instruction.propagatedType; |
| 173 if (!type.isPrimitive()) { | 167 if (!type.isPrimitive()) { |
| 174 prefix = 'U'; | 168 prefix = 'U'; |
| 175 } else { | 169 } else { |
| 176 switch (type) { | 170 if (type == HType.MUTABLE_ARRAY) { |
| 177 case HType.MUTABLE_ARRAY: prefix = 'm'; break; | 171 prefix = 'm'; |
| 178 case HType.READABLE_ARRAY: prefix = 'a'; break; | 172 } else if (type == HType.READABLE_ARRAY) { |
| 179 case HType.EXTENDABLE_ARRAY: prefix = 'e'; break; | 173 prefix = 'a'; |
| 180 case HType.BOOLEAN: prefix = 'b'; break; | 174 } else if (type == HType.EXTENDABLE_ARRAY) { |
| 181 case HType.INTEGER: prefix = 'i'; break; | 175 prefix = 'e'; |
| 182 case HType.DOUBLE: prefix = 'd'; break; | 176 } else if (type == HType.BOOLEAN) { |
| 183 case HType.NUMBER: prefix = 'n'; break; | 177 prefix = 'b'; |
| 184 case HType.STRING: prefix = 's'; break; | 178 } else if (type == HType.INTEGER) { |
| 185 case HType.UNKNOWN: prefix = 'v'; break; | 179 prefix = 'i'; |
| 186 case HType.CONFLICTING: prefix = 'c'; break; | 180 } else if (type == HType.DOUBLE) { |
| 187 case HType.INDEXABLE_PRIMITIVE: prefix = 'r'; break; | 181 prefix = 'd'; |
| 188 case HType.NULL: prefix = 'u'; break; | 182 } else if (type == HType.NUMBER) { |
| 189 default: prefix = 'x'; | 183 prefix = 'n'; |
| 184 } else if (type == HType.STRING) { |
| 185 prefix = 's'; |
| 186 } else if (type == HType.UNKNOWN) { |
| 187 prefix = 'v'; |
| 188 } else if (type == HType.CONFLICTING) { |
| 189 prefix = 'c'; |
| 190 } else if (type == HType.INDEXABLE_PRIMITIVE) { |
| 191 prefix = 'r'; |
| 192 } else if (type == HType.NULL) { |
| 193 prefix = 'u'; |
| 194 } else { |
| 195 prefix = 'x'; |
| 190 } | 196 } |
| 191 } | 197 } |
| 192 return "$prefix${instruction.id}"; | 198 return "$prefix${instruction.id}"; |
| 193 } | 199 } |
| 194 | 200 |
| 195 String visitBoolify(HBoolify node) { | 201 String visitBoolify(HBoolify node) { |
| 196 return "Boolify: ${temporaryId(node.inputs[0])}"; | 202 return "Boolify: ${temporaryId(node.inputs[0])}"; |
| 197 } | 203 } |
| 198 | 204 |
| 199 String visitAdd(HAdd node) => visitInvokeStatic(node); | 205 String visitAdd(HAdd node) => visitInvokeStatic(node); |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 if (node.finallyBlock != null) { | 433 if (node.finallyBlock != null) { |
| 428 finallyBlock = 'B${node.finallyBlock.id}'; | 434 finallyBlock = 'B${node.finallyBlock.id}'; |
| 429 } | 435 } |
| 430 | 436 |
| 431 return "Try: $tryBlock, Catch: $catchBlock, Finally: $finallyBlock, " | 437 return "Try: $tryBlock, Catch: $catchBlock, Finally: $finallyBlock, " |
| 432 "Join: B${successors.last().id}"; | 438 "Join: B${successors.last().id}"; |
| 433 } | 439 } |
| 434 | 440 |
| 435 String visitTypeGuard(HTypeGuard node) { | 441 String visitTypeGuard(HTypeGuard node) { |
| 436 String type; | 442 String type; |
| 437 switch (node.guardedType) { | 443 HType guardedType = node.guardedType; |
| 438 case HType.MUTABLE_ARRAY: type = "mutable_array"; break; | 444 if (guardedType == HType.MUTABLE_ARRAY) { |
| 439 case HType.READABLE_ARRAY: type = "readable_array"; break; | 445 type = "mutable_array"; |
| 440 case HType.EXTENDABLE_ARRAY: type = "extendable_array"; break; | 446 } else if (guardedType == HType.READABLE_ARRAY) { |
| 441 case HType.BOOLEAN: type = "bool"; break; | 447 type = "readable_array"; |
| 442 case HType.INTEGER: type = "integer"; break; | 448 } else if (guardedType == HType.EXTENDABLE_ARRAY) { |
| 443 case HType.DOUBLE: type = "double"; break; | 449 type = "extendable_array"; |
| 444 case HType.NUMBER: type = "number"; break; | 450 } else if (guardedType == HType.BOOLEAN) { |
| 445 case HType.STRING: type = "string"; break; | 451 type = "bool"; |
| 446 case HType.INDEXABLE_PRIMITIVE: type = "string_or_array"; break; | 452 } else if (guardedType == HType.INTEGER) { |
| 447 case HType.UNKNOWN: type = 'unknown'; break; | 453 type = "integer"; |
| 448 default: | 454 } else if (guardedType == HType.DOUBLE) { |
| 449 // TODO(floitsch): Need a compiler object. | 455 type = "double"; |
| 450 compiler.internalError('Unexpected type guard.', | 456 } else if (guardedType == HType.NUMBER) { |
| 451 instruction: node.guardedType); | 457 type = "number"; |
| 452 break; | 458 } else if (guardedType == HType.STRING) { |
| 459 type = "string"; |
| 460 } else if (guardedType == HType.INDEXABLE_PRIMITIVE) { |
| 461 type = "string_or_array"; |
| 462 } else if (guardedType == HType.UNKNOWN) { |
| 463 type = 'unknown'; |
| 464 } else { |
| 465 throw new CompilerCancelledException('Unexpected type guard: $type'); |
| 453 } | 466 } |
| 454 StringBuffer envBuffer = new StringBuffer(); | 467 StringBuffer envBuffer = new StringBuffer(); |
| 455 List<HInstruction> inputs = node.inputs; | 468 List<HInstruction> inputs = node.inputs; |
| 456 for (int i = 0; i < inputs.length; i++) { | 469 for (int i = 0; i < inputs.length; i++) { |
| 457 if (inputs[i] !== node.guarded) { | 470 if (inputs[i] !== node.guarded) { |
| 458 envBuffer.add(" ${temporaryId(inputs[i])}"); | 471 envBuffer.add(" ${temporaryId(inputs[i])}"); |
| 459 } | 472 } |
| 460 } | 473 } |
| 461 String on = node.isOn ? "on" : "off"; | 474 String on = node.isOn ? "on" : "off"; |
| 462 String id = temporaryId(node.guarded); | 475 String id = temporaryId(node.guarded); |
| 463 return "TypeGuard($on): $id is $type env: $envBuffer"; | 476 return "TypeGuard($on): $id is $type env: $envBuffer"; |
| 464 } | 477 } |
| 465 | 478 |
| 466 String visitIs(HIs node) { | 479 String visitIs(HIs node) { |
| 467 String type = node.typeExpression.toString(); | 480 String type = node.typeExpression.toString(); |
| 468 return "TypeTest: ${temporaryId(node.expression)} is $type"; | 481 return "TypeTest: ${temporaryId(node.expression)} is $type"; |
| 469 } | 482 } |
| 470 | 483 |
| 471 String visitTypeConversion(HTypeConversion node) { | 484 String visitTypeConversion(HTypeConversion node) { |
| 472 String type = node.propagatedType.toString(); | 485 String type = node.propagatedType.toString(); |
| 473 return "TypeConversion: ${temporaryId(node.inputs[0])} to $type"; | 486 return "TypeConversion: ${temporaryId(node.inputs[0])} to $type"; |
| 474 } | 487 } |
| 475 } | 488 } |
| OLD | NEW |