Search in sources :

Example 21 with Local

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);
}
Also used : ConstTransformer(com.googlecode.dex2jar.ir.ts.ConstTransformer) Exprs.nLocal(com.googlecode.dex2jar.ir.expr.Exprs.nLocal) Local(com.googlecode.dex2jar.ir.expr.Local) IrMethod(com.googlecode.dex2jar.ir.IrMethod) UnopStmt(com.googlecode.dex2jar.ir.stmt.UnopStmt) Test(org.junit.Test)

Example 22 with Local

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);
}
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 23 with Local

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

Example 24 with Local

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

Example 25 with Local

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));
}
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

Local (com.googlecode.dex2jar.ir.expr.Local)86 Test (org.junit.Test)44 LabelStmt (com.googlecode.dex2jar.ir.stmt.LabelStmt)28 Stmt (com.googlecode.dex2jar.ir.stmt.Stmt)23 Value (com.googlecode.dex2jar.ir.expr.Value)19 AssignStmt (com.googlecode.dex2jar.ir.stmt.AssignStmt)15 ArrayList (java.util.ArrayList)8 IrMethod (com.googlecode.dex2jar.ir.IrMethod)6 Exprs.nLocal (com.googlecode.dex2jar.ir.expr.Exprs.nLocal)6 UnopStmt (com.googlecode.dex2jar.ir.stmt.UnopStmt)6 JumpStmt (com.googlecode.dex2jar.ir.stmt.JumpStmt)5 ConstTransformer (com.googlecode.dex2jar.ir.ts.ConstTransformer)5 Exprs.nString (com.googlecode.dex2jar.ir.expr.Exprs.nString)4 StmtList (com.googlecode.dex2jar.ir.stmt.StmtList)4 Trap (com.googlecode.dex2jar.ir.Trap)3 Exprs.nArrayValue (com.googlecode.dex2jar.ir.expr.Exprs.nArrayValue)3 AnalyzeValue (com.googlecode.dex2jar.ir.ts.an.AnalyzeValue)3 List (java.util.List)3 DexLabel (com.googlecode.d2j.DexLabel)2 Op (com.googlecode.d2j.reader.Op)2