use of soot.jimple.GotoStmt in project soot by Sable.
the class OutFlow method processTargetFixup.
/**
* Runs through the given bbq contents performing the target fix-up pass;
* Requires all reachable blocks to have their done flags set to true, and
* this resets them all back to false;
* @param bbq queue of BasicBlocks to process.
* @see jimpleTargetFixup
*/
private void processTargetFixup(BBQ bbq) {
BasicBlock b, p;
Stmt s;
while (!bbq.isEmpty()) {
try {
b = bbq.pull();
} catch (NoSuchElementException e) {
break;
}
s = b.getTailJStmt();
if (s instanceof GotoStmt) {
if (b.succ.size() == 1) {
// Regular goto
((GotoStmt) s).setTarget(b.succ.firstElement().getHeadJStmt());
} else {
// Goto derived from a jsr bytecode
/*
if((BasicBlock)(b.succ.firstElement())==b.next)
((GotoStmt)s).setTarget(((BasicBlock) b.succ.elementAt(1)).getHeadJStmt());
else
((GotoStmt)s).setTarget(((BasicBlock) b.succ.firstElement()).getHeadJStmt());
*/
logger.debug("Error :");
for (int i = 0; i < b.statements.size(); i++) logger.debug("" + b.statements.get(i));
throw new RuntimeException(b + " has " + b.succ.size() + " successors.");
}
} else if (s instanceof IfStmt) {
if (b.succ.size() != 2)
logger.debug("How can an if not have 2 successors?");
if ((b.succ.firstElement()) == b.next) {
((IfStmt) s).setTarget(b.succ.elementAt(1).getHeadJStmt());
} else {
((IfStmt) s).setTarget(b.succ.firstElement().getHeadJStmt());
}
} else if (s instanceof TableSwitchStmt) {
int count = 0;
TableSwitchStmt sts = (TableSwitchStmt) s;
for (BasicBlock basicBlock : b.succ) {
p = (basicBlock);
if (count == 0) {
sts.setDefaultTarget(p.getHeadJStmt());
} else {
sts.setTarget(count - 1, p.getHeadJStmt());
}
count++;
}
} else if (s instanceof LookupSwitchStmt) {
int count = 0;
LookupSwitchStmt sls = (LookupSwitchStmt) s;
for (BasicBlock basicBlock : b.succ) {
p = (basicBlock);
if (count == 0) {
sls.setDefaultTarget(p.getHeadJStmt());
} else {
sls.setTarget(count - 1, p.getHeadJStmt());
}
count++;
}
}
b.done = false;
for (BasicBlock basicBlock : b.succ) {
p = (basicBlock);
if (p.done)
bbq.push(p);
}
}
}
use of soot.jimple.GotoStmt in project soot by Sable.
the class GotoInstruction method gotoStatement.
private GotoStmt gotoStatement() {
GotoStmt go = Jimple.v().newGotoStmt(targetInstruction.getUnit());
setUnit(go);
addTags(go);
return go;
}
use of soot.jimple.GotoStmt in project soot by Sable.
the class DalvikTyper method typeUntypedConstrantInDiv.
// this is needed because UnuesedStatementTransformer checks types in the div expressions
public void typeUntypedConstrantInDiv(final Body b) {
for (Unit u : b.getUnits()) {
StmtSwitch sw = new StmtSwitch() {
@Override
public void caseBreakpointStmt(BreakpointStmt stmt) {
// TODO Auto-generated method stub
}
@Override
public void caseInvokeStmt(InvokeStmt stmt) {
changeUntypedConstantsInInvoke(stmt.getInvokeExpr());
}
@Override
public void caseAssignStmt(AssignStmt stmt) {
if (stmt.getRightOp() instanceof NewArrayExpr) {
NewArrayExpr nae = (NewArrayExpr) stmt.getRightOp();
if (nae.getSize() instanceof UntypedConstant) {
UntypedIntOrFloatConstant uc = (UntypedIntOrFloatConstant) nae.getSize();
nae.setSize(uc.defineType(IntType.v()));
}
} else if (stmt.getRightOp() instanceof InvokeExpr) {
changeUntypedConstantsInInvoke((InvokeExpr) stmt.getRightOp());
} else if (stmt.getRightOp() instanceof CastExpr) {
CastExpr ce = (CastExpr) stmt.getRightOp();
if (ce.getOp() instanceof UntypedConstant) {
UntypedConstant uc = (UntypedConstant) ce.getOp();
// check incoming primitive type
for (Tag t : stmt.getTags()) {
// Debug.printDbg("assign primitive type from stmt tag: ", stmt, t);
if (t instanceof IntOpTag) {
ce.setOp(uc.defineType(IntType.v()));
return;
} else if (t instanceof FloatOpTag) {
ce.setOp(uc.defineType(FloatType.v()));
return;
} else if (t instanceof DoubleOpTag) {
ce.setOp(uc.defineType(DoubleType.v()));
return;
} else if (t instanceof LongOpTag) {
ce.setOp(uc.defineType(LongType.v()));
return;
}
}
// 0 -> null
ce.setOp(uc.defineType(RefType.v("java.lang.Object")));
}
}
if (stmt.containsArrayRef()) {
ArrayRef ar = stmt.getArrayRef();
if ((ar.getIndex() instanceof UntypedConstant)) {
UntypedIntOrFloatConstant uc = (UntypedIntOrFloatConstant) ar.getIndex();
ar.setIndex(uc.toIntConstant());
}
}
Value r = stmt.getRightOp();
if (r instanceof DivExpr || r instanceof RemExpr) {
// DivExpr de = (DivExpr) r;
for (Tag t : stmt.getTags()) {
// Debug.printDbg("div stmt tag: ", stmt, t);
if (t instanceof IntOpTag) {
checkExpr(r, IntType.v());
return;
} else if (t instanceof FloatOpTag) {
checkExpr(r, FloatType.v());
return;
} else if (t instanceof DoubleOpTag) {
checkExpr(r, DoubleType.v());
return;
} else if (t instanceof LongOpTag) {
checkExpr(r, LongType.v());
return;
}
}
}
}
@Override
public void caseIdentityStmt(IdentityStmt stmt) {
// TODO Auto-generated method stub
}
@Override
public void caseEnterMonitorStmt(EnterMonitorStmt stmt) {
// TODO Auto-generated method stub
}
@Override
public void caseExitMonitorStmt(ExitMonitorStmt stmt) {
// TODO Auto-generated method stub
}
@Override
public void caseGotoStmt(GotoStmt stmt) {
// TODO Auto-generated method stub
}
@Override
public void caseIfStmt(IfStmt stmt) {
// TODO Auto-generated method stub
}
@Override
public void caseLookupSwitchStmt(LookupSwitchStmt stmt) {
// TODO Auto-generated method stub
}
@Override
public void caseNopStmt(NopStmt stmt) {
// TODO Auto-generated method stub
}
@Override
public void caseRetStmt(RetStmt stmt) {
// TODO Auto-generated method stub
}
@Override
public void caseReturnStmt(ReturnStmt stmt) {
if (stmt.getOp() instanceof UntypedConstant) {
UntypedConstant uc = (UntypedConstant) stmt.getOp();
Type type = b.getMethod().getReturnType();
stmt.setOp(uc.defineType(type));
}
}
@Override
public void caseReturnVoidStmt(ReturnVoidStmt stmt) {
// TODO Auto-generated method stub
}
@Override
public void caseTableSwitchStmt(TableSwitchStmt stmt) {
// TODO Auto-generated method stub
}
@Override
public void caseThrowStmt(ThrowStmt stmt) {
if (stmt.getOp() instanceof UntypedConstant) {
UntypedConstant uc = (UntypedConstant) stmt.getOp();
stmt.setOp(uc.defineType(RefType.v("java.lang.Object")));
}
}
@Override
public void defaultCase(Object obj) {
// TODO Auto-generated method stub
}
};
u.apply(sw);
}
}
Aggregations