Local Analysis complete?

git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@33 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent 002f53017a
commit 145fd3359d
  1. 21
      jode/jode/flow/FlowBlock.java
  2. 3
      jode/jode/flow/InstructionContainer.java
  3. 68
      jode/jode/flow/StructuredBlock.java
  4. 44
      jode/jode/flow/VariableSet.java

@ -380,7 +380,7 @@ public class FlowBlock {
* by this blocks
*/
VariableSet defineHere = successor.in.merge(allOuts);
defineHere.subtractIdentical(in);
defineHere.subtractExact(in);
System.err.println(" defineHere : "+defineHere);
if (t1Transformation) {
@ -889,10 +889,6 @@ public class FlowBlock {
return true;
}
public void makeDeclaration() {
block.makeDeclaration();
}
/**
* Resolves the destinations of all jumps.
*/
@ -922,6 +918,11 @@ public class FlowBlock {
successors.setElementAt(null, successors.indexOf(jump));
}
public void makeDeclaration(VariableSet param) {
in.merge(param);
in.subtract(param);
block.makeDeclaration(param);
}
/**
* Print the source code for this structured block. This handles
@ -939,14 +940,8 @@ public class FlowBlock {
writer.tab();
}
if (jode.Decompiler.isDebugging) {
writer.print("in: ");
java.util.Enumeration enum = in.elements();
while(enum.hasMoreElements()) {
writer.print(((jode.LocalInfo)enum.nextElement()).getName()
+ " ");
}
writer.println("");
if (!in.isEmpty()) {
writer.print("in: "+in);
}
block.dumpSource(writer);

@ -27,12 +27,15 @@ public abstract class InstructionContainer extends StructuredBlock {
public InstructionContainer(Instruction instr) {
this.instr = instr;
if (instr instanceof LocalVarOperator)
used.addElement(((LocalVarOperator)instr).getLocalInfo());
}
public InstructionContainer(Instruction instr, Jump jump) {
this.instr = instr;
if (instr instanceof LocalVarOperator) {
LocalVarOperator varOp = (LocalVarOperator) instr;
used.addElement(varOp.getLocalInfo());
jump.out.addElement(varOp.getLocalInfo());
}
setJump(jump);

@ -61,11 +61,16 @@ public abstract class StructuredBlock {
*/
/**
* The variable set containing all variables that must be defined
* in this block (or maybe an outer block, this changes as the
* blocks are put together).
* The variable set containing all variables that are used in
* this block.
*/
VariableSet defineHere = new VariableSet();
VariableSet used = new VariableSet();
/**
* The variable set containing all variables we must declare.
* The analyzation is done in makeDeclaration
*/
VariableSet declare = new VariableSet();
/**
* The surrounding structured block. If this is the outermost
@ -202,14 +207,14 @@ public abstract class StructuredBlock {
/* define(...) will not move from blocks, that are not sub blocks,
* so we do it by hand.
*/
java.util.Enumeration enum = from.defineHere.elements();
java.util.Enumeration enum = from.used.elements();
while (enum.hasMoreElements()) {
LocalInfo var =
((LocalInfo) enum.nextElement()).getLocalInfo();
defineHere.addElement(var);
used.addElement(var);
var.setDefining(this);
}
from.defineHere.removeAllElements();
from.used.removeAllElements();
StructuredBlock[] subs = from.getSubBlocks();
for (int i=0; i<subs.length; i++)
moveDefinitions(subs[i], sub);
@ -266,22 +271,24 @@ public abstract class StructuredBlock {
java.util.Enumeration enum = vars.elements();
while (enum.hasMoreElements()) {
LocalInfo var = ((LocalInfo) enum.nextElement()).getLocalInfo();
StructuredBlock previous = var.getDefining();
if (previous != null) {
if (previous == this || !contains(previous))
continue;
previous.defineHere.removeElement(var);
}
defineHere.addElement(var);
var.setDefining(this);
used.addElement(var);
}
}
public void makeDeclaration() {
/**
* Make the declarations, i.e. initialize the declare variable
* to correct values. This will declare every variable that
* is marked as used, but not done.
* @param done The set of the already declare variables.
*/
public void makeDeclaration(VariableSet done) {
declare.addExact(used);
declare.subtractExact(done);
done.addExact(declare);
StructuredBlock[] subs = getSubBlocks();
for (int i=0; i<subs.length; i++) {
subs[i].makeDeclaration();
}
for (int i=0; i<subs.length; i++)
subs[i].makeDeclaration(done);
}
public void checkConsistent() {
@ -346,15 +353,32 @@ public abstract class StructuredBlock {
public void dumpSource(jode.TabbedPrintWriter writer)
throws java.io.IOException
{
if (!defineHere.isEmpty() || jode.Decompiler.isDebugging)
writer.println("defining: "+defineHere);
/* XXX declare variables needed in this block */
if (jode.Decompiler.isDebugging)
writer.println("declaring: "+declare);
java.util.Enumeration enum = declare.elements();
while (enum.hasMoreElements()) {
LocalInfo local = (LocalInfo) enum.nextElement();
dumpDeclaration(writer, local);
}
dumpInstruction(writer);
if (jump != null)
jump.dumpSource(writer);
}
/**
* Print the code for the declaration of a local variable.
* @param writer The tabbed print writer, where we print to.
* @param local The local that should be declared.
*/
public void dumpDeclaration(jode.TabbedPrintWriter writer, LocalInfo local)
throws java.io.IOException
{
writer.println(local.getType().typeString(local.getName().toString())
+ ";");
}
/**
* Print the instruction expressing this structured block.
* @param writer The tabbed print writer, where we print to.

@ -91,6 +91,28 @@ public class VariableSet extends java.util.Vector {
return intersection;
}
/**
* Intersects the current VariableSet with another and returns the
* intersection. The existing VariableSet are not changed.
* @param vs the other variable set.
*/
public VariableSet intersectExact(VariableSet vs) {
VariableSet intersection = new VariableSet();
for (int i=0; i<elementCount; i++) {
LocalInfo li1 = ((LocalInfo) elementData[i]).getLocalInfo();
for (int j=0; j<vs.elementCount; j++) {
LocalInfo li2 = ((LocalInfo) vs.elementData[j]).getLocalInfo();
if (li1.getLocalInfo() == li2.getLocalInfo()) {
if (!intersection.contains(li1))
intersection.addElement(li1);
if (!intersection.contains(li2))
intersection.addElement(li2);
}
}
}
return intersection;
}
/**
* Union the other variable set to the current.
*/
@ -130,6 +152,26 @@ public class VariableSet extends java.util.Vector {
}
}
/**
* Add the other variable set to the current, except when the slot
* is already in the current set.
*/
public void addExact(VariableSet vs) {
int oldSize = elementCount;
iloop:
for (int i=0; i< vs.elementCount; i++) {
LocalInfo li2 = ((LocalInfo) vs.elementData[i]).getLocalInfo();
/* check if this slot was already overwritten by this block */
for (int j=0; j< oldSize; j++) {
LocalInfo li1 = (LocalInfo) elementData[j];
if (li1.getLocalInfo() == li2)
/* Yes it was, take next variable */
continue iloop;
}
addElement(li2);
}
}
/**
* Subtract the other variable set from this one. This removes
* every variable from this set, that uses a slot in the other
@ -164,7 +206,7 @@ public class VariableSet extends java.util.Vector {
* variable set.
* @param vs The other variable set.
*/
public void subtractIdentical(VariableSet vs) {
public void subtractExact(VariableSet vs) {
/* We count from top to bottom to have easier reorganization.
* Note, that the variables have not to be in any particular
* order. */

Loading…
Cancel
Save