Search in sources :

Example 16 with Stmt

use of com.googlecode.dex2jar.ir.stmt.Stmt in project dex2jar by pxb1988.

the class DeadCodeTrnasformerTest method test09DeadCode.

@Test
public void test09DeadCode() {
    Stmt ret = addStmt(Stmts.nReturnVoid());
    Stmt lb = addStmt(newLabel());
    addStmt(Stmts.nReturnVoid());
    transform();
    Assert.assertSame(ret, method.stmts.getFirst());
    Assert.assertSame(ret, method.stmts.getLast());
}
Also used : Stmt(com.googlecode.dex2jar.ir.stmt.Stmt) Test(org.junit.Test)

Example 17 with Stmt

use of com.googlecode.dex2jar.ir.stmt.Stmt 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);
}
Also used : LabelStmt(com.googlecode.dex2jar.ir.stmt.LabelStmt) Local(com.googlecode.dex2jar.ir.expr.Local) LabelStmt(com.googlecode.dex2jar.ir.stmt.LabelStmt) Stmt(com.googlecode.dex2jar.ir.stmt.Stmt) Test(org.junit.Test)

Example 18 with Stmt

use of com.googlecode.dex2jar.ir.stmt.Stmt 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));
}
Also used : LabelStmt(com.googlecode.dex2jar.ir.stmt.LabelStmt) Local(com.googlecode.dex2jar.ir.expr.Local) LabelStmt(com.googlecode.dex2jar.ir.stmt.LabelStmt) Stmt(com.googlecode.dex2jar.ir.stmt.Stmt) Test(org.junit.Test)

Example 19 with Stmt

use of com.googlecode.dex2jar.ir.stmt.Stmt in project dex2jar by pxb1988.

the class RemoveLocalFromSSATest method t001.

@Test
public void t001() {
    Local a = addLocal("a");
    Local b = addLocal("b");
    Local c = addLocal("c");
    Stmt sa = addStmt(nAssign(a, nInt(0)));
    addStmt(nAssign(b, a));
    addStmt(nAssign(c, b));
    Stmt sb = addStmt(nReturn(c));
    transform();
    Assert.assertEquals(sa.getOp1(), sb.getOp());
    Assert.assertEquals("1 local should left", 1, locals.size());
}
Also used : Local(com.googlecode.dex2jar.ir.expr.Local) Stmt(com.googlecode.dex2jar.ir.stmt.Stmt) Test(org.junit.Test)

Example 20 with Stmt

use of com.googlecode.dex2jar.ir.stmt.Stmt in project dex2jar by pxb1988.

the class UnSSATransformerTransformerTest method test00Base.

@Test
public void test00Base() {
    initMethod(true, "V");
    Local a = addLocal("a");
    Local b = addLocal("b");
    Local phi = addLocal("p");
    LabelStmt L1 = newLabel();
    Stmt s1 = addStmt(nAssign(a, nString("123")));
    addStmt(nIf(niGt(nInt(100), nInt(0)), L1));
    Stmt s2 = addStmt(nAssign(b, nString("456")));
    addStmt(L1);
    attachPhi(L1, nAssign(phi, nPhi(a, b)));
    addStmt(nReturn(phi));
    transform();
    Assert.assertEquals("insert assign after s1", ST.ASSIGN, s1.getNext().st);
    Assert.assertEquals("insert assign after s1", ST.ASSIGN, s2.getNext().st);
// Assert.assertEquals("local should index to 0", 0, b._ls_index);
}
Also used : LabelStmt(com.googlecode.dex2jar.ir.stmt.LabelStmt) Local(com.googlecode.dex2jar.ir.expr.Local) LabelStmt(com.googlecode.dex2jar.ir.stmt.LabelStmt) Stmt(com.googlecode.dex2jar.ir.stmt.Stmt) Test(org.junit.Test)

Aggregations

Stmt (com.googlecode.dex2jar.ir.stmt.Stmt)41 LabelStmt (com.googlecode.dex2jar.ir.stmt.LabelStmt)31 Local (com.googlecode.dex2jar.ir.expr.Local)23 AssignStmt (com.googlecode.dex2jar.ir.stmt.AssignStmt)22 Test (org.junit.Test)10 Value (com.googlecode.dex2jar.ir.expr.Value)8 ArrayList (java.util.ArrayList)7 JumpStmt (com.googlecode.dex2jar.ir.stmt.JumpStmt)4 Cfg (com.googlecode.dex2jar.ir.ts.Cfg)4 Trap (com.googlecode.dex2jar.ir.Trap)3 StmtList (com.googlecode.dex2jar.ir.stmt.StmtList)3 List (java.util.List)3 StmtTraveler (com.googlecode.dex2jar.ir.StmtTraveler)2 Constant (com.googlecode.dex2jar.ir.expr.Constant)2 PhiExpr (com.googlecode.dex2jar.ir.expr.PhiExpr)2 E2Stmt (com.googlecode.dex2jar.ir.stmt.Stmt.E2Stmt)2 HashSet (java.util.HashSet)2 IR2JConverter (com.googlecode.d2j.converter.IR2JConverter)1 DexFileNode (com.googlecode.d2j.node.DexFileNode)1 DexMethodNode (com.googlecode.d2j.node.DexMethodNode)1