Move the cb swapping to the front, this sometimes make better trafos possible

git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@110 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent df4c4560bb
commit 209b219442
  1. 39
      jode/jode/flow/FlowBlock.java

@ -134,6 +134,21 @@ public class FlowBlock {
remainingJumps = lastJump; remainingJumps = lastJump;
} }
for (Jump jump = jumps; jump != null; jump = jump.next) {
/* First swap all conditional blocks, that have two jumps,
* so that the jump to succ will be on the outside.
*/
if (jump.prev.outer instanceof ConditionalBlock
&& jump.prev.outer.jump != null) {
StructuredBlock prev = jump.prev;
ConditionalBlock cb = (ConditionalBlock) prev.outer;
Expression instr = cb.getInstruction();
cb.setInstruction(instr.negate());
cb.swapJump(prev);
}
}
next_jump: next_jump:
while (jumps != null) { while (jumps != null) {
Jump jump = jumps; Jump jump = jumps;
@ -161,14 +176,13 @@ public class FlowBlock {
if (jump.prev.outer instanceof ConditionalBlock) { if (jump.prev.outer instanceof ConditionalBlock) {
if (jump.prev.outer.jump != null) {
StructuredBlock prev = jump.prev; StructuredBlock prev = jump.prev;
ConditionalBlock cb = (ConditionalBlock) prev.outer; ConditionalBlock cb = (ConditionalBlock) prev.outer;
Expression instr = cb.getInstruction(); Expression instr = cb.getInstruction();
if (cb.jump.destination == jump.destination) { if (cb.jump != null) {
/* This is a weired "if (cond) empty"-block. We /* This can only happen if cb also jumps to succ.
* This is a weired "if (cond) empty"-block. We
* transform it by hand. * transform it by hand.
*/ */
prev.removeJump(); prev.removeJump();
@ -180,25 +194,9 @@ public class FlowBlock {
continue; continue;
} }
/* Swap conditional blocks, that have two jumps, and where
* this jump is the inner jump.
*/
cb.setInstruction(instr.negate());
cb.swapJump(jump.prev);
/* Consider this jump again
*/
jumps = jump;
continue;
}
/* Now cb.jump is null, so cb.outer is not null, /* Now cb.jump is null, so cb.outer is not null,
* since otherwise it would have no successor. */ * since otherwise it would have no successor. */
ConditionalBlock cb = (ConditionalBlock) jump.prev.outer;
Expression instr = cb.getInstruction();
/* If this is the first instruction of a /* If this is the first instruction of a
* while/for(true) block, make this the loop condition * while/for(true) block, make this the loop condition
* (negated of course). * (negated of course).
@ -317,7 +315,6 @@ public class FlowBlock {
while (sb instanceof SequentialBlock) while (sb instanceof SequentialBlock)
sb = sb.outer; sb = sb.outer;
/* if this is a jump at the end of a then block belonging /* if this is a jump at the end of a then block belonging
* to a if-then block without else part, and the if-then * to a if-then block without else part, and the if-then
* block is followed by a single block, then replace the * block is followed by a single block, then replace the

Loading…
Cancel
Save