removeOnetimeLocals

git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@432 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent 7c30104a69
commit aec2d9ac5e
  1. 6
      jode/jode/flow/FlowBlock.java
  2. 15
      jode/jode/flow/InstructionContainer.java
  3. 19
      jode/jode/flow/LoopBlock.java
  4. 50
      jode/jode/flow/SequentialBlock.java
  5. 15
      jode/jode/flow/StructuredBlock.java

@ -1468,6 +1468,12 @@ public class FlowBlock {
}
}
public void removeOnetimeLocals() {
block.removeOnetimeLocals();
if (nextByAddr != null)
nextByAddr.removeOnetimeLocals();
}
public void makeDeclaration(VariableSet param) {
in.merge(param);
in.subtract(param);

@ -46,6 +46,21 @@ public abstract class InstructionContainer extends StructuredBlock {
setJump(jump);
}
/**
* This method should remove local variables that are only written
* and read one time directly after another. <br>
*
* This is especially important for stack locals, that are created
* when there are unusual swap or dup instructions, but also makes
* inlined functions more pretty (but not that close to the
* bytecode).
*/
public void removeOnetimeLocals() {
if (instr != null)
instr = instr.removeOnetimeLocals();
super.removeOnetimeLocals();
}
/**
* Fill all in variables into the given VariableSet.
* @param in The VariableSet, the in variables should be stored to.

@ -387,6 +387,25 @@ public class LoopBlock extends StructuredBlock implements BreakableBlock {
bodyBlock.removePush();
}
/**
* This method should remove local variables that are only written
* and read one time directly after another. <br>
*
* This is especially important for stack locals, that are created
* when there are unusual swap or dup instructions, but also makes
* inlined functions more pretty (but not that close to the
* bytecode).
*/
public void removeOnetimeLocals() {
cond = cond.removeOnetimeLocals();
if (type == FOR) {
if (init != null)
init.removeOnetimeLocals();
incr.removeOnetimeLocals();
}
super.removeOnetimeLocals();
}
/**
* Replace all breaks to block with a continue to this.
* @param block the breakable block where the breaks originally

@ -17,6 +17,7 @@
*/
package jode.flow;
import jode.decompiler.TabbedPrintWriter;
import jode.expr.LocalStoreOperator;
/**
* A sequential block combines exactly two structured blocks to a new
@ -67,6 +68,55 @@ public class SequentialBlock extends StructuredBlock {
return null;
}
/**
* This method should remove local variables that are only written
* and read one time directly after another. <br>
*
* This is especially important for stack locals, that are created
* when there are unusual swap or dup instructions, but also makes
* inlined functions more pretty (but not that close to the
* bytecode).
*/
public void removeOnetimeLocals() {
StructuredBlock secondBlock = subBlocks[1];
if (secondBlock instanceof SequentialBlock)
secondBlock = ((SequentialBlock)secondBlock).subBlocks[0];
if (subBlocks[0] instanceof InstructionBlock
&& secondBlock instanceof InstructionContainer) {
InstructionBlock first = (InstructionBlock) subBlocks[0];
InstructionContainer second = (InstructionContainer) secondBlock;
/* check if subBlocks[0] writes to a local, second reads
* that local, the local is only used by this two blocks,
* and there are no side effects. In that case replace
* the LoadLocal with the righthandside of subBlocks[0]
* and replace subBlocks[1] with this block. Call
* removeOnetimelLocals on subBlocks[1] afterwards and
* return.
*/
if (first.getInstruction().getOperator()
instanceof LocalStoreOperator) {
LocalStoreOperator store = (LocalStoreOperator)
first.getInstruction().getOperator();
if (store.getLocalInfo().getUseCount() == 2
&& (second.getInstruction().canCombine
(first.getInstruction()) > 0)) {
System.err.println("before: "+first+second);
second.setInstruction(second.getInstruction()
.combine(first.getInstruction()));
System.err.println("after: "+second);
StructuredBlock sb = subBlocks[1];
sb.moveDefinitions(this, sb);
sb.replace(this);
sb.removeOnetimeLocals();
return;
}
}
}
super.removeOnetimeLocals();
}
/**
* Returns the block where the control will normally flow to, when
* the given sub block is finished (<em>not</em> ignoring the jump

@ -390,6 +390,21 @@ public abstract class StructuredBlock {
subBlocks[i].removePush();
}
/**
* This method should remove local variables that are only written
* and read one time directly after another. <br>
*
* This is especially important for stack locals, that are created
* when there are unusual swap or dup instructions, but also makes
* inlined functions more pretty (but not that close to the
* bytecode).
*/
public void removeOnetimeLocals() {
StructuredBlock[] subBlocks = getSubBlocks();
for (int i=0; i< subBlocks.length; i++)
subBlocks[i].removeOnetimeLocals();
}
/**
* Make the declarations, i.e. initialize the declare variable
* to correct values. This will declare every variable that

Loading…
Cancel
Save