public void VpShiftSum() { Constant c = Constant.Word32(1); ProcedureBuilder m = new ProcedureBuilder(); Expression e = m.Shl(1, m.ISub(Constant.Byte(32), 1)); var vp = new ExpressionSimplifier(new SsaEvaluationContext(ssaIds)); e = e.Accept(vp); Assert.AreEqual("0x80000000", e.ToString()); }
public void SsaPushAndPop() { // Mirrors the pattern of stack accesses used by x86 compilers. var m = new ProcedureBuilder("SsaPushAndPop"); var esp = EnsureRegister32(m, "esp"); var ebp = EnsureRegister32(m, "ebp"); var eax = EnsureRegister32(m, "eax"); m.Assign(esp, m.ISub(esp, 4)); m.Store(esp, ebp); m.Assign(ebp, esp); m.Assign(eax, m.LoadDw(m.IAdd(ebp, 8))); // dwArg04 m.Assign(ebp, m.LoadDw(esp)); m.Assign(esp, m.IAdd(esp,4)); m.Return(); RunUnitTest(m, "Analysis/SsaPushAndPop.txt"); }
public void VpEquality2() { // Makes sure that // y = x - 2 // if (y == 0) ... // doesn't get munged into // y = x - 2 // if (x == 2) Identifier x = Reg32("x"); Identifier y = Reg32("y"); ProcedureBuilder m = new ProcedureBuilder(); var stmX = m.Assign(x, m.LoadDw(Constant.Word32(0x1000300))); ssaIds[x].DefStatement = m.Block.Statements.Last; var stmY = m.Assign(y, m.ISub(x, 2)); ssaIds[y].DefStatement = m.Block.Statements.Last; var stm = m.BranchIf(m.Eq(y, 0), "test"); Assert.AreEqual("x = Mem0[0x01000300:word32]", stmX.ToString()); Assert.AreEqual("y = x - 0x00000002", stmY.ToString()); Assert.AreEqual("branch y == 0x00000000 test", stm.ToString()); var vp = new ValuePropagator(ssaIds, null); vp.Transform(stm); Assert.AreEqual("branch x == 0x00000002 test", stm.Instruction.ToString()); }