Add IExplodedBasicBlock.getOriginalNumber()

This method is useful when reasoning about SSAPiStatements, as their
successor block number refers to original basic blocks, not exploded
blocks.
This commit is contained in:
Manu Sridharan 2016-08-10 11:51:13 -07:00
parent 2c9eec0cff
commit e4101510a2
2 changed files with 19 additions and 8 deletions

View File

@ -40,7 +40,7 @@ import com.ibm.wala.util.intset.MutableSparseIntSet;
/** /**
* A view of a control flow graph where each basic block corresponds to exactly one SSA instruction index. * A view of a control flow graph where each basic block corresponds to exactly one SSA instruction index.
* *
* Prototype: Not terribly efficient. * Prototype: Not terribly efficient.
*/ */
public class ExplodedControlFlowGraph implements ControlFlowGraph<SSAInstruction, IExplodedBasicBlock> { public class ExplodedControlFlowGraph implements ControlFlowGraph<SSAInstruction, IExplodedBasicBlock> {
@ -140,7 +140,7 @@ public class ExplodedControlFlowGraph implements ControlFlowGraph<SSAInstruction
@Override @Override
public List<IExplodedBasicBlock> getExceptionalSuccessors(IExplodedBasicBlock bb) { public List<IExplodedBasicBlock> getExceptionalSuccessors(IExplodedBasicBlock bb) {
ExplodedBasicBlock eb = (ExplodedBasicBlock) bb; ExplodedBasicBlock eb = (ExplodedBasicBlock) bb;
assert eb != null; assert eb != null;
if (eb.equals(exit)) { if (eb.equals(exit)) {
return Collections.emptyList(); return Collections.emptyList();
@ -151,7 +151,7 @@ public class ExplodedControlFlowGraph implements ControlFlowGraph<SSAInstruction
if (eb.isEntryBlock() && orig == null) { if (eb.isEntryBlock() && orig == null) {
orig = ir.getControlFlowGraph().entry(); orig = ir.getControlFlowGraph().entry();
} }
for (ISSABasicBlock s : ir.getControlFlowGraph().getExceptionalSuccessors(orig)) { for (ISSABasicBlock s : ir.getControlFlowGraph().getExceptionalSuccessors(orig)) {
if (s.equals(ir.getControlFlowGraph().exit())) { if (s.equals(ir.getControlFlowGraph().exit())) {
result.add(exit()); result.add(exit());
@ -277,7 +277,7 @@ public class ExplodedControlFlowGraph implements ControlFlowGraph<SSAInstruction
@Override @Override
public int getPredNodeCount(IExplodedBasicBlock bb) throws IllegalArgumentException { public int getPredNodeCount(IExplodedBasicBlock bb) throws IllegalArgumentException {
ExplodedBasicBlock eb = (ExplodedBasicBlock) bb; ExplodedBasicBlock eb = (ExplodedBasicBlock) bb;
if (eb == null) { if (eb == null) {
throw new IllegalArgumentException("eb == null"); throw new IllegalArgumentException("eb == null");
} }
@ -385,7 +385,7 @@ public class ExplodedControlFlowGraph implements ControlFlowGraph<SSAInstruction
return true; return true;
} }
} }
return false; return false;
} }
@ -458,7 +458,7 @@ public class ExplodedControlFlowGraph implements ControlFlowGraph<SSAInstruction
/** /**
* A basic block with exactly one normal instruction (which may be null), corresponding to a single instruction index in the SSA * A basic block with exactly one normal instruction (which may be null), corresponding to a single instruction index in the SSA
* instruction array. * instruction array.
* *
* The block may also have phis. * The block may also have phis.
*/ */
private class ExplodedBasicBlock implements IExplodedBasicBlock { private class ExplodedBasicBlock implements IExplodedBasicBlock {
@ -634,6 +634,11 @@ public class ExplodedControlFlowGraph implements ControlFlowGraph<SSAInstruction
} }
return "ExplodedBlock[" + getNumber() + "](original:" + original + ")"; return "ExplodedBlock[" + getNumber() + "](original:" + original + ")";
} }
@Override
public int getOriginalNumber() {
return original.getNumber();
}
} }
@Override @Override

View File

@ -17,7 +17,7 @@ import com.ibm.wala.ssa.SSAInstruction;
/** /**
* A basic block with exactly one normal instruction (which may be null), corresponding to a single instruction index in the SSA * A basic block with exactly one normal instruction (which may be null), corresponding to a single instruction index in the SSA
* instruction array. * instruction array.
* *
* The block may also have phis. * The block may also have phis.
*/ */
public interface IExplodedBasicBlock extends ISSABasicBlock { public interface IExplodedBasicBlock extends ISSABasicBlock {
@ -29,9 +29,15 @@ public interface IExplodedBasicBlock extends ISSABasicBlock {
/** /**
* if this represents an exception handler block, return the corresponding {@link SSAGetCaughtExceptionInstruction} * if this represents an exception handler block, return the corresponding {@link SSAGetCaughtExceptionInstruction}
* *
* @throws IllegalArgumentException if this does not represent an exception handler block * @throws IllegalArgumentException if this does not represent an exception handler block
*/ */
public SSAGetCaughtExceptionInstruction getCatchInstruction(); public SSAGetCaughtExceptionInstruction getCatchInstruction();
/**
* get the number of the original basic block containing the instruction of
* this exploded block
*/
public int getOriginalNumber();
} }