use of soot.Unit in project soot by Sable.
the class AsmMethodSource method mergeUnits.
void mergeUnits(AbstractInsnNode insn, Unit u) {
Unit prev = units.put(insn, u);
if (prev != null) {
Unit merged = new UnitContainer(prev, u);
units.put(insn, merged);
}
}
use of soot.Unit in project soot by Sable.
the class AsmMethodSource method emitUnits.
private void emitUnits() {
AbstractInsnNode insn = instructions.getFirst();
ArrayDeque<LabelNode> labls = new ArrayDeque<LabelNode>();
while (insn != null) {
// Save the label to assign it to the next real unit
if (insn instanceof LabelNode)
labls.add((LabelNode) insn);
// Get the unit associated with the current instruction
Unit u = units.get(insn);
if (u == null) {
insn = insn.getNext();
continue;
}
emitUnits(u);
// If this is an exception handler, register the starting unit for it
{
IdentityStmt caughtEx = null;
if (u instanceof IdentityStmt)
caughtEx = (IdentityStmt) u;
else if (u instanceof UnitContainer)
caughtEx = getIdentityRefFromContrainer((UnitContainer) u);
if (insn instanceof LabelNode && caughtEx != null && caughtEx.getRightOp() instanceof CaughtExceptionRef) {
// We directly place this label
Collection<UnitBox> traps = trapHandlers.get((LabelNode) insn);
for (UnitBox ub : traps) ub.setUnit(caughtEx);
}
}
// Register this unit for all targets of the labels ending up at it
while (!labls.isEmpty()) {
LabelNode ln = labls.poll();
Collection<UnitBox> boxes = labels.get(ln);
if (boxes != null) {
for (UnitBox box : boxes) {
box.setUnit(u instanceof UnitContainer ? ((UnitContainer) u).getFirstUnit() : u);
}
}
}
insn = insn.getNext();
}
// Emit the inline exception handlers
for (LabelNode ln : this.inlineExceptionHandlers.keySet()) {
Unit handler = this.inlineExceptionHandlers.get(ln);
emitUnits(handler);
Collection<UnitBox> traps = trapHandlers.get(ln);
for (UnitBox ub : traps) ub.setUnit(handler);
// We need to jump to the original implementation
Unit targetUnit = units.get(ln);
GotoStmt gotoImpl = Jimple.v().newGotoStmt(targetUnit);
body.getUnits().add(gotoImpl);
}
/* set remaining labels & boxes to last unit of chain */
if (labls.isEmpty())
return;
Unit end = Jimple.v().newNopStmt();
body.getUnits().add(end);
while (!labls.isEmpty()) {
LabelNode ln = labls.poll();
Collection<UnitBox> boxes = labels.get(ln);
if (boxes != null) {
for (UnitBox box : boxes) box.setUnit(end);
}
}
}
use of soot.Unit in project soot by Sable.
the class AsmMethodSource method setUnit.
void setUnit(AbstractInsnNode insn, Unit u) {
if (Options.v().keep_line_number() && lastLineNumber >= 0) {
Tag lineTag = u.getTag("LineNumberTag");
if (lineTag == null) {
lineTag = new LineNumberTag(lastLineNumber);
u.addTag(lineTag);
} else if (((LineNumberTag) lineTag).getLineNumber() != lastLineNumber)
throw new RuntimeException("Line tag mismatch");
}
Unit o = units.put(insn, u);
if (o != null)
throw new AssertionError(insn.getOpcode() + " already has a unit, " + o);
}
use of soot.Unit in project soot by Sable.
the class AsmMethodSource method emitLocals.
private void emitLocals() {
JimpleBody jb = body;
SootMethod m = jb.getMethod();
Collection<Local> jbl = jb.getLocals();
Collection<Unit> jbu = jb.getUnits();
int iloc = 0;
if (!m.isStatic()) {
Local l = getLocal(iloc++);
jbu.add(Jimple.v().newIdentityStmt(l, Jimple.v().newThisRef(m.getDeclaringClass().getType())));
}
int nrp = 0;
for (Object ot : m.getParameterTypes()) {
Type t = (Type) ot;
Local l = getLocal(iloc);
jbu.add(Jimple.v().newIdentityStmt(l, Jimple.v().newParameterRef(t, nrp++)));
if (AsmUtil.isDWord(t))
iloc += 2;
else
iloc++;
}
for (Local l : locals.values()) {
jbl.add(l);
}
}
use of soot.Unit in project soot by Sable.
the class Walker method outAIdentityNoTypeStatement.
public void outAIdentityNoTypeStatement(AIdentityNoTypeStatement node) {
// get rid of @caughtexception string
mProductions.removeLast();
// presently on top of the stack
// the local ref
Value local = mLocals.get(mProductions.removeLast());
// from it's
// identifier
Unit u = Jimple.v().newIdentityStmt(local, Jimple.v().newCaughtExceptionRef());
mProductions.addLast(u);
}
Aggregations