OLD | NEW |
---|---|
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 interface HVisitor<R> { | 5 interface HVisitor<R> { |
6 R visitAdd(HAdd node); | 6 R visitAdd(HAdd node); |
7 R visitBitAnd(HBitAnd node); | 7 R visitBitAnd(HBitAnd node); |
8 R visitBitNot(HBitNot node); | 8 R visitBitNot(HBitNot node); |
9 R visitBitOr(HBitOr node); | 9 R visitBitOr(HBitOr node); |
10 R visitBitXor(HBitXor node); | 10 R visitBitXor(HBitXor node); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
45 R visitNegate(HNegate node); | 45 R visitNegate(HNegate node); |
46 R visitNot(HNot node); | 46 R visitNot(HNot node); |
47 R visitParameterValue(HParameterValue node); | 47 R visitParameterValue(HParameterValue node); |
48 R visitPhi(HPhi node); | 48 R visitPhi(HPhi node); |
49 R visitReturn(HReturn node); | 49 R visitReturn(HReturn node); |
50 R visitShiftLeft(HShiftLeft node); | 50 R visitShiftLeft(HShiftLeft node); |
51 R visitShiftRight(HShiftRight node); | 51 R visitShiftRight(HShiftRight node); |
52 R visitStatic(HStatic node); | 52 R visitStatic(HStatic node); |
53 R visitStaticStore(HStaticStore node); | 53 R visitStaticStore(HStaticStore node); |
54 R visitSubtract(HSubtract node); | 54 R visitSubtract(HSubtract node); |
55 R visitSwitch(HSwitch node); | |
55 R visitThis(HThis node); | 56 R visitThis(HThis node); |
56 R visitThrow(HThrow node); | 57 R visitThrow(HThrow node); |
57 R visitTruncatingDivide(HTruncatingDivide node); | 58 R visitTruncatingDivide(HTruncatingDivide node); |
58 R visitTry(HTry node); | 59 R visitTry(HTry node); |
59 R visitTypeGuard(HTypeGuard node); | 60 R visitTypeGuard(HTypeGuard node); |
60 R visitTypeConversion(HTypeConversion node); | 61 R visitTypeConversion(HTypeConversion node); |
61 } | 62 } |
62 | 63 |
63 class HGraphVisitor { | 64 class HGraphVisitor { |
64 visitDominatorTree(HGraph graph) { | 65 visitDominatorTree(HGraph graph) { |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
292 visitModulo(HModulo node) => visitBinaryArithmetic(node); | 293 visitModulo(HModulo node) => visitBinaryArithmetic(node); |
293 visitNegate(HNegate node) => visitInvokeUnary(node); | 294 visitNegate(HNegate node) => visitInvokeUnary(node); |
294 visitNot(HNot node) => visitInstruction(node); | 295 visitNot(HNot node) => visitInstruction(node); |
295 visitPhi(HPhi node) => visitInstruction(node); | 296 visitPhi(HPhi node) => visitInstruction(node); |
296 visitMultiply(HMultiply node) => visitBinaryArithmetic(node); | 297 visitMultiply(HMultiply node) => visitBinaryArithmetic(node); |
297 visitParameterValue(HParameterValue node) => visitInstruction(node); | 298 visitParameterValue(HParameterValue node) => visitInstruction(node); |
298 visitReturn(HReturn node) => visitControlFlow(node); | 299 visitReturn(HReturn node) => visitControlFlow(node); |
299 visitShiftRight(HShiftRight node) => visitBinaryBitOp(node); | 300 visitShiftRight(HShiftRight node) => visitBinaryBitOp(node); |
300 visitShiftLeft(HShiftLeft node) => visitBinaryBitOp(node); | 301 visitShiftLeft(HShiftLeft node) => visitBinaryBitOp(node); |
301 visitSubtract(HSubtract node) => visitBinaryArithmetic(node); | 302 visitSubtract(HSubtract node) => visitBinaryArithmetic(node); |
303 visitSwitch(HSwitch node) => visitControlFlow(node); | |
302 visitStatic(HStatic node) => visitInstruction(node); | 304 visitStatic(HStatic node) => visitInstruction(node); |
303 visitStaticStore(HStaticStore node) => visitInstruction(node); | 305 visitStaticStore(HStaticStore node) => visitInstruction(node); |
304 visitThis(HThis node) => visitParameterValue(node); | 306 visitThis(HThis node) => visitParameterValue(node); |
305 visitThrow(HThrow node) => visitControlFlow(node); | 307 visitThrow(HThrow node) => visitControlFlow(node); |
306 visitTry(HTry node) => visitControlFlow(node); | 308 visitTry(HTry node) => visitControlFlow(node); |
307 visitTruncatingDivide(HTruncatingDivide node) => visitBinaryArithmetic(node); | 309 visitTruncatingDivide(HTruncatingDivide node) => visitBinaryArithmetic(node); |
308 visitTypeGuard(HTypeGuard node) => visitCheck(node); | 310 visitTypeGuard(HTypeGuard node) => visitCheck(node); |
309 visitIs(HIs node) => visitInstruction(node); | 311 visitIs(HIs node) => visitInstruction(node); |
310 visitTypeConversion(HTypeConversion node) => visitCheck(node); | 312 visitTypeConversion(HTypeConversion node) => visitCheck(node); |
311 } | 313 } |
(...skipping 13 matching lines...) Expand all Loading... | |
325 } | 327 } |
326 } | 328 } |
327 | 329 |
328 class SubExpression extends SubGraph { | 330 class SubExpression extends SubGraph { |
329 const SubExpression(HBasicBlock start, HBasicBlock end) | 331 const SubExpression(HBasicBlock start, HBasicBlock end) |
330 : super(start, end); | 332 : super(start, end); |
331 | 333 |
332 /** Find the condition expression if this sub-expression is a condition. */ | 334 /** Find the condition expression if this sub-expression is a condition. */ |
333 HInstruction get conditionExpression() { | 335 HInstruction get conditionExpression() { |
334 HInstruction last = end.last; | 336 HInstruction last = end.last; |
335 if (last is HConditionalBranch) return last.inputs[0]; | 337 if (last is HConditionalBranch || last is HSwitch) return last.inputs[0]; |
336 return null; | 338 return null; |
337 } | 339 } |
338 } | 340 } |
339 | 341 |
340 class HInstructionList { | 342 class HInstructionList { |
341 HInstruction first = null; | 343 HInstruction first = null; |
342 HInstruction last = null; | 344 HInstruction last = null; |
343 | 345 |
344 bool isEmpty() { | 346 bool isEmpty() { |
345 return first === null; | 347 return first === null; |
(...skipping 1124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1470 HSubtract(HStatic target, HInstruction left, HInstruction right) | 1472 HSubtract(HStatic target, HInstruction left, HInstruction right) |
1471 : super(target, left, right); | 1473 : super(target, left, right); |
1472 accept(HVisitor visitor) => visitor.visitSubtract(this); | 1474 accept(HVisitor visitor) => visitor.visitSubtract(this); |
1473 | 1475 |
1474 SubtractOperation get operation() => const SubtractOperation(); | 1476 SubtractOperation get operation() => const SubtractOperation(); |
1475 int typeCode() => 9; | 1477 int typeCode() => 9; |
1476 bool typeEquals(other) => other is HSubtract; | 1478 bool typeEquals(other) => other is HSubtract; |
1477 bool dataEquals(HInstruction other) => true; | 1479 bool dataEquals(HInstruction other) => true; |
1478 } | 1480 } |
1479 | 1481 |
1482 /** | |
1483 * An [HSwitch] instruction has one input for the incoming | |
1484 * value, and one input per constant that it can switch on. | |
1485 * Its block has one succeessor per constant, and one for the default. | |
floitsch
2012/06/06 11:50:26
successor.
Lasse Reichstein Nielsen
2012/06/06 13:01:21
Done.
| |
1486 */ | |
1487 class HSwitch extends HControlFlow { | |
1488 HSwitch(List<HInstruction> inputs) : super(inputs); | |
1489 | |
1490 HConstant constant(int index) => inputs[index + 1]; | |
1491 HInstruction get expression() => inputs[0]; | |
1492 | |
1493 HBasicBlock get defaultTarget() => block.successors.last(); | |
ngeoffray
2012/06/06 12:03:46
What if the switch does not have a default? Is tha
Lasse Reichstein Nielsen
2012/06/06 13:01:21
It is. Comment added.
| |
1494 | |
1495 accept(HVisitor visitor) => visitor.visitSwitch(this); | |
1496 | |
1497 String toString() => "HSwitch cases = $inputs"; | |
1498 } | |
1499 | |
1480 class HTruncatingDivide extends HBinaryArithmetic { | 1500 class HTruncatingDivide extends HBinaryArithmetic { |
1481 HTruncatingDivide(HStatic target, HInstruction left, HInstruction right) | 1501 HTruncatingDivide(HStatic target, HInstruction left, HInstruction right) |
1482 : super(target, left, right); | 1502 : super(target, left, right); |
1483 accept(HVisitor visitor) => visitor.visitTruncatingDivide(this); | 1503 accept(HVisitor visitor) => visitor.visitTruncatingDivide(this); |
1484 | 1504 |
1485 TruncatingDivideOperation get operation() | 1505 TruncatingDivideOperation get operation() |
1486 => const TruncatingDivideOperation(); | 1506 => const TruncatingDivideOperation(); |
1487 int typeCode() => 10; | 1507 int typeCode() => 10; |
1488 bool typeEquals(other) => other is HTruncatingDivide; | 1508 bool typeEquals(other) => other is HTruncatingDivide; |
1489 bool dataEquals(HInstruction other) => true; | 1509 bool dataEquals(HInstruction other) => true; |
(...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2296 bool accept(HExpressionInformationVisitor visitor); | 2316 bool accept(HExpressionInformationVisitor visitor); |
2297 HInstruction get conditionExpression(); | 2317 HInstruction get conditionExpression(); |
2298 } | 2318 } |
2299 | 2319 |
2300 | 2320 |
2301 interface HStatementInformationVisitor { | 2321 interface HStatementInformationVisitor { |
2302 bool visitLabeledBlockInfo(HLabeledBlockInformation info); | 2322 bool visitLabeledBlockInfo(HLabeledBlockInformation info); |
2303 bool visitLoopInfo(HLoopBlockInformation info); | 2323 bool visitLoopInfo(HLoopBlockInformation info); |
2304 bool visitIfInfo(HIfBlockInformation info); | 2324 bool visitIfInfo(HIfBlockInformation info); |
2305 bool visitTryInfo(HTryBlockInformation info); | 2325 bool visitTryInfo(HTryBlockInformation info); |
2326 bool visitSwitchInfo(HSwitchBlockInformation info); | |
2306 bool visitSequenceInfo(HStatementSequenceInformation info); | 2327 bool visitSequenceInfo(HStatementSequenceInformation info); |
2307 // Pseudo-structure embedding a dominator-based traversal into | 2328 // Pseudo-structure embedding a dominator-based traversal into |
2308 // the block-structure traversal. This will eventually go away. | 2329 // the block-structure traversal. This will eventually go away. |
2309 bool visitSubGraphInfo(HSubGraphBlockInformation info); | 2330 bool visitSubGraphInfo(HSubGraphBlockInformation info); |
2310 } | 2331 } |
2311 | 2332 |
2312 | 2333 |
2313 interface HExpressionInformationVisitor { | 2334 interface HExpressionInformationVisitor { |
2314 bool visitAndOrInfo(HAndOrBlockInformation info); | 2335 bool visitAndOrInfo(HAndOrBlockInformation info); |
2315 bool visitSubExpressionInfo(HSubExpressionBlockInformation info); | 2336 bool visitSubExpressionInfo(HSubExpressionBlockInformation info); |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2491 this.catchBlock, | 2512 this.catchBlock, |
2492 this.finallyBlock); | 2513 this.finallyBlock); |
2493 | 2514 |
2494 HBasicBlock get start() => body.start; | 2515 HBasicBlock get start() => body.start; |
2495 HBasicBlock get end() => | 2516 HBasicBlock get end() => |
2496 finallyBlock === null ? catchBlock.end : finallyBlock.end; | 2517 finallyBlock === null ? catchBlock.end : finallyBlock.end; |
2497 | 2518 |
2498 bool accept(HStatementInformationVisitor visitor) => | 2519 bool accept(HStatementInformationVisitor visitor) => |
2499 visitor.visitTryInfo(this); | 2520 visitor.visitTryInfo(this); |
2500 } | 2521 } |
2522 | |
2523 | |
2524 | |
2525 class HSwitchBlockInformation implements HStatementInformation { | |
2526 final HExpressionInformation expression; | |
2527 final List<List<Constant>> matchExpressions; | |
2528 final List<HStatementInformation> statements; | |
2529 // If the switch has a default, it's the last statement block, which | |
2530 // may or may not have other expresions. | |
2531 final bool hasDefault; | |
2532 final TargetElement target; | |
2533 final List<LabelElement> labels; | |
2534 | |
2535 HSwitchBlockInformation(this.expression, | |
2536 this.matchExpressions, | |
2537 this.statements, | |
2538 this.hasDefault, | |
2539 this.target, | |
2540 this.labels); | |
2541 | |
2542 HBasicBlock get start() => expression.start; | |
2543 HBasicBlock get end() { | |
2544 // We don't create a switch block if there are no cases. | |
2545 assert(!statements.isEmpty()); | |
2546 return statements.last().end; | |
2547 } | |
2548 | |
2549 bool accept(HStatementInformationVisitor visitor) => | |
2550 visitor.visitSwitchInfo(this); | |
2551 } | |
OLD | NEW |