public void Test1() { var m = new ProcedureBuilder(); var id = m.Local32("id"); var x = m.Local32("x"); var stm = m.Assign(x, m.IAdd(m.SMul(id, 4), id)); }
public void Setup() { m = new ProcedureBuilder(); i = m.Local32("i"); c = m.Int32(16); off = m.Int32(42); r = m.Local32("r"); aem = new ArrayExpressionMatcher(PrimitiveType.Pointer32); }
public void SetUp() { m = new ProcedureBuilder(); id = m.Local32("id"); x = m.Local32("x"); ssaIds = new SsaIdentifierCollection(); foreach (Identifier i in m.Procedure.Frame.Identifiers) { ssaIds.Add(i, null, null, false); } }
public void Pdg_PostDominateIfElse() { ProcedureBuilder m = new ProcedureBuilder(); m.BranchIf(m.Local32("a"), "then"); m.Assign(m.Local32("b"), m.Int32(0)); m.Jump("join"); m.Label("then"); m.Assign(m.Local32("c"), m.Int32(0)); m.Label("join"); m.Return(); FindPostDominators(m); }
public void DeadFnReturn() { ProcedureBuilder m = new ProcedureBuilder("foo"); Identifier unused = m.Local32("unused"); m.Assign(unused, m.Fn("foo", Constant.Word32(1))); m.Return(); RunTest(m, "Analysis/DeadFnReturn.txt"); }
private Procedure BuildSimpleLoop() { ProcedureBuilder m = new ProcedureBuilder(); Identifier p = m.Local32("p"); m.Assign(p, 0); m.Label("loop"); m.BranchIf(m.Eq(p, 0x4000), "done"); m.Store(m.IAdd(p, 0x3000), m.Int32(0)); m.Assign(p, m.IAdd(p, 4)); m.Goto("loop"); m.Label("done"); m.Return(); return m.Procedure; }
public void TrcoCallFunctionWithArraySize() { var m = new ProcedureBuilder(); var sig = new ProcedureSignature(null, m.Frame.EnsureStackArgument(0, PrimitiveType.Word32)); var ex = new ExternalProcedure("malloc", sig, new ProcedureCharacteristics { Allocator = true, ArraySize = new ArraySizeCharacteristic { Argument = "r", Factors = new ArraySizeFactor[] { new ArraySizeFactor { Constant = "1" } } } }); Identifier eax = m.Local32("eax"); var call = m.Assign(eax, m.Fn(new ProcedureConstant(PrimitiveType.Word32, ex), m.Word32(3))); coll = CreateCollector(); call.Accept(eqb); call.Accept(coll); StringWriter sw = new StringWriter(); handler.Traits.Write(sw); string sExp = "T_1 (in malloc : word32)" + nl + "\ttrait_func(T_4 -> T_5)" + nl + "T_3 (in dwArg00 : word32)" + nl + "\ttrait_primitive(word32)" + nl + "T_4 (in 0x00000003 : word32)" + nl + "\ttrait_primitive(word32)" + nl + "\ttrait_equal(T_3)" + nl + "T_5 (in malloc(0x00000003) : word32)" + nl + "\ttrait_primitive(word32)"; Console.WriteLine(sw.ToString()); Assert.AreEqual(sExp, sw.ToString()); }
public void TrcoDbp() { ProcedureBuilder m = new ProcedureBuilder(); Identifier a = m.Local32("a"); Identifier b = m.LocalByte("b"); var s = m.Assign(a, m.Dpb(a, b, 0)); coll = CreateCollector(); s.Accept(eqb); s.Accept(coll); StringWriter sb = new StringWriter(); handler.Traits.Write(sb); Console.WriteLine(sb); string exp = "T_1 (in a : word32)" + nl + "\ttrait_primitive(word32)" + nl + "\ttrait_primitive(word32)" + nl + "\ttrait_primitive(word32)" + nl + "\ttrait_equal(T_3)" + nl + "T_2 (in b : byte)" + nl + "\ttrait_primitive(byte)" + nl + "T_3 (in DPB(a, b, 0) : word32)" + nl + "\ttrait_primitive(word32)" + nl; Assert.AreEqual(exp, sb.ToString()); }
public void TrcoIcall() { ProcedureBuilder m = new ProcedureBuilder(); Identifier pfn = m.Local32("pfn"); Expression l = m.Load(PrimitiveType.Word32, pfn); CallInstruction icall = new CallInstruction(l, new CallSite(0, 0)); coll = CreateCollector(); icall.Accept(eqb); icall.Accept(coll); StringWriter sw = new StringWriter(); handler.Traits.Write(sw); string exp = "T_1 (in pfn : word32)" + nl + "\ttrait_primitive(word32)" + nl + "\ttrait_mem(T_2, 0)" + nl + "T_2 (in Mem0[pfn:word32] : word32)" + nl + "\ttrait_primitive((ptr code))" + nl + "\ttrait_primitive(word32)" + nl; Console.WriteLine(sw.ToString()); Assert.AreEqual(exp, sw.ToString()); }
public void TrcoMultiplication() { var prog = CreateProgram(); var m = new ProcedureBuilder(); var id = m.Local32("id"); var e = m.IMul(id, id); coll = CreateCollector(prog); e = e.Accept(en); e.Accept(eqb); e.Accept(coll); Verify(null, "Typing/TrcoMultiplication.txt"); }
public void TrcoGlobalArray() { Program prog = CreateProgram(); ProcedureBuilder m = new ProcedureBuilder(); Identifier i = m.Local32("i"); Expression ea = m.IAdd(prog.Globals, m.IAdd(m.Shl(i, 2), 0x3000)); Expression e = m.Load(PrimitiveType.Int32, ea); coll = CreateCollector(prog); e = e.Accept(en); e.Accept(eqb); e.Accept(coll); Verify(null, "Typing/TrcoGlobalArray.txt"); }
public void DtbSignedCompare() { ProcedureBuilder m = new ProcedureBuilder(); Identifier p = m.Local32("p"); Identifier ds = m.Local16("ds"); ds.DataType = PrimitiveType.SegmentSelector; Identifier ds2 = m.Local16("ds2"); ds.DataType = PrimitiveType.SegmentSelector; m.Assign(ds2, ds); m.Store( m.SegMem(PrimitiveType.Bool, ds, m.Word16(0x5400)), m.Lt(m.SegMemW(ds, m.Word16(0x5404)), m.Word16(20))); m.Store(m.SegMemW(ds2, m.Word16(0x5404)), m.Word16(0)); ProgramBuilder prog = new ProgramBuilder(); prog.Add(m); RunTest(prog.BuildProgram(), "Typing/DtbSignedCompare.txt"); }
public void CreateNoincInitialValue() { ProcedureBuilder m = new ProcedureBuilder(); ssaIds = new SsaIdentifierCollection(); SsaId(new Identifier("id0", PrimitiveType.Word32, new TemporaryStorage("id0", 0, PrimitiveType.Word32)), null, null, false); SsaId(new Identifier("id1", PrimitiveType.Word32, new TemporaryStorage("id1", 1, PrimitiveType.Word32)), null, null, false); LinearInductionVariableFinder liv = new LinearInductionVariableFinder(null, ssaIds, null); liv.Context.InitialValue = Constant.Word32(0); Identifier id2 = m.Local32("id_2"); SsaId(id2, new Statement(0, null, null), null, false); Assert.AreEqual(3, ssaIds.Count); Identifier id3 = m.Local32("id_3"); Identifier id4 = m.Local32("id_4"); liv.Context.PhiStatement = m.Phi(id3, id2, id4); liv.Context.PhiIdentifier = id3; SsaId(id3, liv.Context.PhiStatement, ((PhiAssignment)liv.Context.PhiStatement.Instruction).Src, false); Assert.AreEqual(4, ssaIds.Count); Statement use = new Statement(0, null, null); ssaIds[id3].Uses.Add(use); liv.Context.DeltaValue = m.Int32(1); m.Assign(id4, m.IAdd(id3, liv.Context.DeltaValue)); liv.Context.DeltaStatement = m.Block.Statements.Last; ssaIds[id3].Uses.Add(liv.Context.DeltaStatement); LinearInductionVariable iv = liv.CreateInductionVariable(); Assert.AreEqual("(0x00000000 0x00000001 ?)", iv.ToString()); }