use of com.googlecode.dex2jar.ir.expr.Local in project dex2jar by pxb1988.
the class ConstTransformerTest method test01.
@Test
public void test01() {
// local in phi
IrMethod jm = new IrMethod();
Local a = nLocal("a");
Local p = nLocal("p");
jm.locals.add(a);
jm.locals.add(p);
jm.stmts.add(nAssign(a, nString("a String")));
jm.stmts.add(nAssign(p, Exprs.nPhi(a)));
UnopStmt retStmt = nReturn(p);
jm.stmts.add(retStmt);
new ConstTransformer().transform(jm);
Assert.assertTrue(jm.locals.size() == 2);
Assert.assertTrue(jm.stmts.getSize() == 3);
Assert.assertEquals("a String", ((Constant) retStmt.op.trim()).value);
}
use of com.googlecode.dex2jar.ir.expr.Local in project dex2jar by pxb1988.
the class RemoveConstantFromSSATest method t005PhiValueEqual.
@Test
public void t005PhiValueEqual() {
Local a0 = addLocal("a0");
Local a1 = addLocal("a1");
Local ax = addLocal("aX");
LabelStmt L1 = newLabel();
LabelStmt L2 = newLabel();
addStmt(nIf(niGt(nInt(100), nInt(0)), L1));
addStmt(nAssign(a0, nString("123")));
addStmt(nGoto(L2));
addStmt(L1);
addStmt(nAssign(a1, nString("123")));
addStmt(L2);
attachPhi(L2, nAssign(ax, Exprs.nPhi(a0, a1)));
Stmt ret = addStmt(nReturn(ax));
transform();
Assert.assertTrue("should return '123'", ret.getOp().vt == Value.VT.CONSTANT);
}
use of com.googlecode.dex2jar.ir.expr.Local in project dex2jar by pxb1988.
the class RemoveConstantFromSSATest method t003.
@Test
public void t003() {
Local a = addLocal("a");
Local b = addLocal("b");
Local c = addLocal("c");
addStmt(nAssign(a, nNewIntArray(nInt(5))));
addStmt(nAssign(b, nInt(2)));
addStmt(nAssign(c, nArray(a, b, "I")));
addStmt(nReturn(c));
transform();
Assert.assertTrue("local b should removed", !locals.contains(b));
Assert.assertTrue(locals.size() == 2);
}
use of com.googlecode.dex2jar.ir.expr.Local in project dex2jar by pxb1988.
the class RemoveConstantFromSSATest method t004.
@Test
public void t004() {
Local a0 = addLocal("a0");
Local a1 = addLocal("a1");
Local ax = addLocal("aX");
LabelStmt L1 = newLabel();
LabelStmt L2 = newLabel();
addStmt(nIf(niGt(nInt(100), nInt(0)), L1));
addStmt(nAssign(a0, nString("123")));
addStmt(nGoto(L2));
addStmt(L1);
addStmt(nAssign(a1, nNull()));
addStmt(L2);
attachPhi(L2, nAssign(ax, Exprs.nPhi(a0, a1)));
addStmt(nReturn(ax));
transform();
Assert.assertEquals("all local should kept", 3, locals.size());
}
use of com.googlecode.dex2jar.ir.expr.Local in project dex2jar by pxb1988.
the class RemoveConstantFromSSATest method t001.
@Test
public void t001() {
Local a = addLocal("a");
Local b = addLocal("b");
Local c1 = addLocal("c1");
Local c2 = addLocal("c2");
Local cphi = addLocal("cphi");
LabelStmt L1 = newLabel();
LabelStmt L2 = newLabel();
Stmt sa = addStmt(nAssign(a, nInt(5)));
Stmt sb = addStmt(nAssign(b, nInt(6)));
addStmt(nIf(niGt(a, b), L1));
addStmt(nAssign(c1, a));
addStmt(nGoto(L2));
addStmt(L1);
addStmt(nAssign(c2, b));
addStmt(L2);
attachPhi(L2, nAssign(cphi, Exprs.nPhi(c1, c2)));
addStmt(nReturn(cphi));
transform();
Assert.assertFalse("SA should remove from method", method.stmts.contains(sa));
Assert.assertFalse("SB should remove from method", method.stmts.contains(sb));
}
Aggregations