*** empty log message ***

git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@22 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent 58973855f5
commit b6eb6a495b
  1. 299
      jode/jode/flow/FlowBlock.java
  2. 15
      jode/jode/flow/StructuredBlock.java
  3. 3
      jode/jode/flow/jode.ppl

@ -217,7 +217,7 @@ public class FlowBlock {
elseBlock.outer instanceof SequentialBlock && elseBlock.outer instanceof SequentialBlock &&
elseBlock.outer.getSubBlocks()[0] instanceof IfThenElseBlock && elseBlock.outer.getSubBlocks()[0] instanceof IfThenElseBlock &&
(elseBlock.outer.getNextFlowBlock() == successor || (elseBlock.outer.getNextFlowBlock() == successor ||
elseBlock.outer.jumpMayBeChanged()) { elseBlock.outer.jumpMayBeChanged())) {
IfThenElseBlock ifBlock = IfThenElseBlock ifBlock =
(IfThenElseBlock)elseBlock.outer.getSubBlocks()[0]; (IfThenElseBlock)elseBlock.outer.getSubBlocks()[0];
if (ifBlock.getElseBlock() == null) { if (ifBlock.getElseBlock() == null) {
@ -228,7 +228,7 @@ public class FlowBlock {
} else { } else {
jump.parent.removeJump(); jump.parent.removeJump();
} }
ifBlock.replace(elseBlock.outer) ifBlock.replace(elseBlock.outer);
ifBlock.setElseBlock(elseBlock); ifBlock.setElseBlock(elseBlock);
if (appendBlock = elseBlock.outer) if (appendBlock = elseBlock.outer)
appendBlock = ifBlock; appendBlock = ifBlock;
@ -238,55 +238,55 @@ public class FlowBlock {
return appendBlock; return appendBlock;
} }
/** /**
* Updates the in/out-Vectors of the structured block of the * Updates the in/out-Vectors of the structured block of the
* successing flow block simultanous to a T1 transformation. * successing flow block simultanous to a T1 transformation.
* @param successor The flow block which is unified with this flow * @param successor The flow block which is unified with this flow
* block. * block.
*/ */
void updateInOut (FlowBlock successor, boolean t1Transformation) { void updateInOut (FlowBlock successor, boolean t1Transformation) {
/* First get the out vectors of all jumps to successor and /* First get the out vectors of all jumps to successor and
* calculate the intersection. * calculate the intersection.
*/ */
VariableSet allOuts = new VariableSet(); VariableSet allOuts = new VariableSet();
VariableSet intersectOut = null; VariableSet intersectOut = null;
Enumeration enum = successors; Enumeration enum = successors;
while (enum.hasMoreElement()) { while (enum.hasMoreElement()) {
Jump jump = (Jump) enum.nextElement(); Jump jump = (Jump) enum.nextElement();
if (jump == null || jump.destination != successor) if (jump == null || jump.destination != successor)
continue; continue;
allOuts.union(jump.parent.out); allOuts.union(jump.parent.out);
if (intersectOut == null) if (intersectOut == null)
intersectOut = jump.parent.out; intersectOut = jump.parent.out;
else else
intersectOut = intersectOut.intersect(jump.parent.out); intersectOut = intersectOut.intersect(jump.parent.out);
} }
/* Now work on each block of the successor */ /* Now work on each block of the successor */
Stack todo = new Stack(); Stack todo = new Stack();
todo.push(successor.block); todo.push(successor.block);
while (!todo.empty()) { while (!todo.empty()) {
StructuredBlock block = (StructuredBlock) todo.pop(); StructuredBlock block = (StructuredBlock) todo.pop();
StructuredBlock[] subBlocks = block.getSubBlocks(); StructuredBlock[] subBlocks = block.getSubBlocks();
for (int i=0; i<subBlocks.length; i++) for (int i=0; i<subBlocks.length; i++)
todo.push(subBlocks[i]); todo.push(subBlocks[i]);
/* Merge the locals used in successing block with those written /* Merge the locals used in successing block with those written
* by this blocks * by this blocks
*/ */
block.in.merge(allOuts); block.in.merge(allOuts);
if (t1Transformation) { if (t1Transformation) {
/* Now update in and out set of successing block */ /* Now update in and out set of successing block */
block.in.subtract(intersectOut); block.in.subtract(intersectOut);
block.out.add(intersectOut); block.out.add(intersectOut);
} }
} }
} }
/* Special cases: /* Special cases:
* *
* try-header * try-header
* |- first instruction * |- first instruction
@ -350,116 +350,123 @@ public class FlowBlock {
* return_n * return_n
*/ */
public boolean doT1 { public boolean doT1 {
/* search successor with smallest addr. */ /* search successor with smallest addr. */
Enumeration enum = successors.elements(); Enumeration enum = successors.elements();
FlowBlock succ = null; FlowBlock succ = null;
while (enum.hasMoreElements()) { while (enum.hasMoreElements()) {
Jump jump = (Jump) enum.nextElement(); Jump jump = (Jump) enum.nextElement();
if (jump == null) if (jump == null)
continue; continue;
FlowBlock fb = jump.destination; FlowBlock fb = jump.destination;
if (succ == null || fb.addr < succ.addr) { if (succ == null || fb.addr < succ.addr) {
succ = fb; succ = fb;
} }
} }
if (succ == null) { if (succ == null) {
/* There are no successors at all */ /* There are no successors at all */
return false; return false;
} }
/* check if this successor has only this block as predecessor. */ /* check if this successor has only this block as predecessor. */
/* if not, return false. */ /* if not, return false. */
if (succ.predecessors.size() != 1) if (succ.predecessors.size() != 1)
return false; return false;
/* First find the innermost block that contains all jumps to this /* First find the innermost block that contains all jumps to this
* successor and the last modified block. * successor and the last modified block.
*/ */
Enumeration enum = successors.elements(); Enumeration enum = successors.elements();
StructuredBlock appendBlock = lastModified; StructuredBlock appendBlock = lastModified;
while(enum.hasMoreElements()) { while(enum.hasMoreElements()) {
Jump jump = (Jump) enum.nextElement(); Jump jump = (Jump) enum.nextElement();
if (jump == null || jump.destination != successors) if (jump == null || jump.destination != successors)
continue; continue;
while (!appendBlock.contains(jump.parent)) while (!appendBlock.contains(jump.parent))
appendBlock = appendBlock.outer; appendBlock = appendBlock.outer;
/* appendBlock can't be null now, because the /* appendBlock can't be null now, because the
* outermost block contains every structured block. * outermost block contains every structured block.
*/ */
} }
/* Update the in/out-Vectors now */ /* Update the in/out-Vectors now */
updateInOut(successor, true); updateInOut(successor, true);
/* The switch "fall through" case: if the appendBlock is a /* The switch "fall through" case: if the appendBlock is a
* switch, and the successor is the address of a case, and all * switch, and the successor is the address of a case, and all
* other successors are inside the block preceding that case. * other successors are inside the block preceding that case.
*/ */
if (case != null) { if (case != null) {
SwitchBlock switchBlock = (StructuredBlock) appendBlock; SwitchBlock switchBlock = (StructuredBlock) appendBlock;
/* Now put the succ.block into the next case.
*/
switchBlock.replaceSubBlock(nextcase,succ.block);
succ.block.outer = switchBlock;
/* nextcase is not referenced any more */
/* Do the following modifications on the struct block. */
appendBlock = precedingcase;
} else {
/* Prepare the unification of the blocks: Make sure that
* appendBlock has a successor outside of this block. This is
* always possible, because it contains lastModified.
*/
if (appendBlock.jump == null) {
/* assert(appendBlock.jump.getNextFlowBlock() != null) */
appendBlock.setJump(appendBlock.getNextFlowBlock());
}
/* Now unify the blocks: Create a new SequentialBlock
* containing appendBlock and successor.block. Then replace
* appendBlock with the new sequential block.
*/
StructuredBlock outer = appendBlock.outer;
StructuredBlock sequBlock =
new SequentialBlock(appendBlock, switchBlock);
outer.replaceSubBlock(appendBlock, sequBlock);
sequBlock.outer = outer;
}
/* Try to eliminate as many jumps as possible.
*/
optimizeJumps(succ, appendBlock); /* Now put the succ.block into the next case.
*/
switchBlock.replaceSubBlock(nextcase,succ.block);
succ.block.outer = switchBlock;
/* nextcase is not referenced any more */
/* Now remove the jump of the appendBlock if it points to successor. /* Do the following modifications on the struct block. */
*/ appendBlock = precedingcase;
if (appendBlock.jump == succ) } else {
appendBlock.removeJump();
/* If there are further jumps, put a do/while(0) block around /* Prepare the unification of the blocks: Make sure that
* appendBlock and replace every remaining jump with a break * appendBlock has a successor outside of this block. This is
* to the do/while block. * always possible, because it contains lastModified.
*/ */
if (appendBlock.jump == null) {
/* assert(appendBlock.jump.getNextFlowBlock() != null) */
appendBlock.setJump(appendBlock.getNextFlowBlock());
}
/* Believe it or not: Now the rule, that the first part of a /* Now unify the blocks: Create a new SequentialBlock
* SequentialBlock shouldn't be another SequentialBlock is * containing appendBlock and successor.block. Then replace
* fulfilled. <p> * appendBlock with the new sequential block.
* */
* This isn't easy to prove, it has a lot to do with the StructuredBlock outer = appendBlock.outer;
* transformation in optimizeJump and the fact that StructuredBlock sequBlock =
* appendBlock was the innermost Block containing all jumps new SequentialBlock(appendBlock, switchBlock);
* and lastModified. outer.replaceSubBlock(appendBlock, sequBlock);
*/ sequBlock.outer = outer;
}
/* Try to eliminate as many jumps as possible.
*/
optimizeJumps(succ, appendBlock);
/* Now remove the jump of the appendBlock if it points to successor.
*/
if (appendBlock.jump == succ)
appendBlock.removeJump();
/* Set last modified to correct value. */ /* If there are further jumps, put a do/while(0) block around
lastModified = succ.lastModified; * appendBlock and replace every remaining jump with a break
} * to the do/while block.
*/
/* Merge the sucessors from the successing flow block
*/
enum = succ.successors.elements();
while (enum.hasMoreElements()) {
successors.addElement(enum.nextElement());
}
/* Believe it or not: Now the rule, that the first part of a
* SequentialBlock shouldn't be another SequentialBlock is
* fulfilled. <p>
*
* This isn't easy to prove, it has a lot to do with the
* transformation in optimizeJump and the fact that
* appendBlock was the innermost Block containing all jumps
* and lastModified.
*/
/* Set last modified to correct value. */
lastModified = succ.lastModified;
}
public boolean doT2() { public boolean doT2() {
/* If there are no jumps to the beginning of this flow block /* If there are no jumps to the beginning of this flow block
@ -501,7 +508,3 @@ public class FlowBlock {
successors.setElementAt(null, successors.indexOf(jump)); successors.setElementAt(null, successors.indexOf(jump));
} }
} }

@ -236,6 +236,21 @@ public abstract class StructuredBlock {
return false; return false;
} }
/**
* Get the unique predecessor which mustn't be a conditional jump
* @return the predecessor or null if there isn't a such a thing
*/
public StructuredBlock getSimpleUniquePredecessor() {
SequentialBlock sequ;
if (outer instanceof SequentialBlock) {
if (outer.getSubBlocks()[1] == this)
return outer.getSubBlocks()[0];
else if (outer.outer instanceof SequentialBlock)
return outer.outer.getSubBlocks[0];
}
return null;
}
/** /**
* Print the source code for this structured block. This may be * Print the source code for this structured block. This may be
* called only once, because it remembers which local variables * called only once, because it remembers which local variables

@ -35,4 +35,5 @@
auf klo auf klo
1998-09-17 17:11:45 ei 1998-09-17 17:11:45 ei
1998-09-17 17:49:35 ecd 1998-09-17 17:49:35 ecd
1998-09-19 10:46:01 bcd
1998-09-19 11:00:08 ecd
Loading…
Cancel
Save