Search in sources :

Example 11 with LabelStmt

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

the class ZeroTransformerTest method t001.

@Test
public void t001() {
    Local a = addLocal("a");
    Local c = addLocal("c");
    Local p = addLocal("p");
    Local q = addLocal("q");
    addStmt(nAssign(a, nInt(0)));
    addStmt(nAssign(c, nInvokeStatic(new Value[0], "La;", "a", new String[0], "I")));
    LabelStmt L1 = newLabel();
    addStmt(L1);
    Stmt sa = attachPhi(L1, nAssign(q, nPhi(a, c)));
    Stmt sb = attachPhi(L1, nAssign(p, nPhi(a, c)));
    addStmt(nReturn(p));
    transform();
    Assert.assertNotEquals("a is split to 2 local", sb.getOp2().getOps()[0], sa.getOp2().getOps()[0]);
    Assert.assertEquals("c is keep same", sb.getOp2().getOps()[1], sa.getOp2().getOps()[1]);
}
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 12 with LabelStmt

use of com.googlecode.dex2jar.ir.stmt.LabelStmt 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 13 with LabelStmt

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

Example 14 with LabelStmt

use of com.googlecode.dex2jar.ir.stmt.LabelStmt 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 15 with LabelStmt

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

the class StmtListTest method toStringTest.

@Test
public void toStringTest() {
    StmtList list = new StmtList();
    Local a = nLocal("this");
    Local b = nLocal("b");
    Local c = nLocal("c");
    Local d = nLocal("d");
    LabelStmt L1 = Stmts.nLabel();
    list.add(Stmts.nIdentity(a, nThisRef("La/Some;")));
    list.add(Stmts.nIdentity(b, nParameterRef("I", 0)));
    list.add(Stmts.nIdentity(c, nParameterRef("J", 1)));
    list.add(Stmts.nIdentity(d, nParameterRef("F", 2)));
    list.add(Stmts.nIf(nGt(b, nInt(0), "I"), L1));
    list.add(Stmts.nAssign(c, nCast(d, "F", "J")));
    list.add(L1);
    list.toString();
}
Also used : LabelStmt(com.googlecode.dex2jar.ir.stmt.LabelStmt) Exprs.nLocal(com.googlecode.dex2jar.ir.expr.Exprs.nLocal) Local(com.googlecode.dex2jar.ir.expr.Local) StmtList(com.googlecode.dex2jar.ir.stmt.StmtList) Test(org.junit.Test)

Aggregations

LabelStmt (com.googlecode.dex2jar.ir.stmt.LabelStmt)39 Local (com.googlecode.dex2jar.ir.expr.Local)26 Stmt (com.googlecode.dex2jar.ir.stmt.Stmt)22 AssignStmt (com.googlecode.dex2jar.ir.stmt.AssignStmt)17 Test (org.junit.Test)14 Value (com.googlecode.dex2jar.ir.expr.Value)8 ArrayList (java.util.ArrayList)7 Trap (com.googlecode.dex2jar.ir.Trap)4 JumpStmt (com.googlecode.dex2jar.ir.stmt.JumpStmt)4 StmtList (com.googlecode.dex2jar.ir.stmt.StmtList)4 List (java.util.List)3 StmtTraveler (com.googlecode.dex2jar.ir.StmtTraveler)2 PhiExpr (com.googlecode.dex2jar.ir.expr.PhiExpr)2 Cfg (com.googlecode.dex2jar.ir.ts.Cfg)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 IrMethod (com.googlecode.dex2jar.ir.IrMethod)1 LabelAndLocalMapper (com.googlecode.dex2jar.ir.LabelAndLocalMapper)1