private SsaIdentifier AddSid(string name) { Identifier id = new Identifier(name, null, null); SsaIdentifier sid = sids.Add(id, new Statement(0, new DefInstruction(id), null), null, false); return(sid); }
public void SltSimple() { Build(new SimpleMock().Procedure, new FakeArchitecture()); using (FileUnitTester fut = new FileUnitTester("Analysis/SltSimple.txt")) { ssa.Write(fut.TextWriter); sla.Write(proc, fut.TextWriter); fut.TextWriter.WriteLine(); fut.AssertFilesEqual(); } Block block = proc.EntryBlock.Succ[0]; block.Write(Console.Out); Assert.AreEqual("Mem3[0x10000000:word32] = a + b", block.Statements[0].Instruction.ToString()); Assert.AreEqual("Mem4[0x10000004:word32] = a", block.Statements[1].Instruction.ToString()); SsaIdentifier a = ssa.Identifiers.Where(s => s.Identifier.Name == "a").Single(); SsaIdentifier b = ssa.Identifiers.Where(s => s.Identifier.Name == "b").Single(); SsaIdentifier c_2 = ssa.Identifiers.Where(s => s.Identifier.Name == "c_2").Single(); Assert.IsFalse(sla.IsLiveOut(a.Identifier, block.Statements[1]), "a should be dead after its last use"); Assert.IsTrue(sla.IsLiveOut(a.Identifier, block.Statements[0]), "a should be live after the first use"); Assert.IsFalse(sla.IsDefinedAtStatement(c_2, block.Statements[0])); Assert.IsFalse(sla.IsDefinedAtStatement(b, block.Statements[0])); }
public void OutpReplaceManyUses() { ProcedureBuilder m = new ProcedureBuilder(); Identifier foo = new Identifier("foo", PrimitiveType.Word32, null); Identifier bar = new Identifier("bar", PrimitiveType.Word32, null); Identifier pfoo = new Identifier("pfoo", PrimitiveType.Pointer32, null); Block block = m.Label("block"); m.Assign(foo, 1); Statement stmFoo = m.Block.Statements.Last; m.Assign(bar, foo); Statement stmBar = m.Block.Statements.Last; SsaIdentifier ssaFoo = new SsaIdentifier(foo, foo, stmFoo, ((Assignment)stmFoo.Instruction).Src, false); ssaFoo.Uses.Add(stmBar); SsaIdentifier ssaBar = new SsaIdentifier(bar, bar, stmBar, ((Assignment)stmBar.Instruction).Src, false); SsaIdentifierCollection ssaIds = new SsaIdentifierCollection(); ssaIds.Add(foo, ssaFoo); ssaIds.Add(bar, ssaBar); OutParameterTransformer opt = new OutParameterTransformer(m.Procedure, ssaIds); opt.ReplaceDefinitionsWithOutParameter(foo, pfoo); Assert.AreEqual(3, block.Statements.Count); Assert.AreEqual("foo = 0x00000001", block.Statements[0].Instruction.ToString()); Assert.AreEqual("*pfoo = foo", block.Statements[1].Instruction.ToString()); Assert.AreEqual("bar = foo", block.Statements[2].Instruction.ToString()); }
public Identifier Reg(string name, RegisterStorage r) { var id = new Identifier(name, r.DataType, r); var sid = new SsaIdentifier(id, id, null, null, false); Ssa.Identifiers.Add(id, sid); return(sid.Identifier); }
private Identifier MakeSsaIdentifier(Identifier id, string name) { var idNew = new Identifier(name, id.DataType, id.Storage); var sid = new SsaIdentifier(idNew, id, null, null, false); Ssa.Identifiers.Add(idNew, sid); return(sid.Identifier); }
public Identifier Temp(string name, TemporaryStorage stg) { var id = new Identifier(stg.Name, stg.DataType, stg); var sid = new SsaIdentifier(id, id, null, null, false); Ssa.Identifiers.Add(id, sid); return(sid.Identifier); }
public Identifier Flags(string name, FlagGroupStorage flags) { var id = new Identifier(name, flags.DataType, flags); var sid = new SsaIdentifier(id, id, null, null, false); Ssa.Identifiers.Add(id, sid); return(sid.Identifier); }
public override Identifier Local32(string name, int offset) { var local = base.Local32(name, offset); var sid = new SsaIdentifier(local, local, null, null, false); Ssa.Identifiers.Add(local, sid); return(sid.Identifier); }
private Identifier Reg8(string name) { var mr = new RegisterStorage(name, ssaIds.Count, 0, PrimitiveType.Byte); Identifier id = new Identifier(mr.Name, mr.DataType, mr); SsaIdentifier sid = new SsaIdentifier(id, id, null, null, false); ssaIds.Add(id, sid); return(sid.Identifier); }
private Identifier Reg(string name, PrimitiveType pt) { var r = new RegisterStorage(name, Ssa.Identifiers.Count, 0, pt); var id = new Identifier(r.Name, r.DataType, r); var sid = new SsaIdentifier(id, id, null, null, false); Ssa.Identifiers.Add(id, sid); return(sid.Identifier); }
private void AddMemIdToSsa(MemoryAccess access) { var idOld = access.MemoryId; var idNew = new MemoryIdentifier(Ssa.Identifiers.Count, idOld.DataType); access.MemoryId = idNew; var sid = new SsaIdentifier(idNew, idOld, null, null, false); Ssa.Identifiers.Add(idNew, sid); }
private MemoryIdentifier AddMemIdToSsa(MemoryIdentifier idOld) { if (Ssa.Identifiers.Contains(idOld)) { return(idOld); } var idNew = new MemoryIdentifier(Ssa.Identifiers.Count, idOld.DataType); var sid = new SsaIdentifier(idNew, idOld, null, null, false); Ssa.Identifiers.Add(idNew, sid); return(idNew); }
private SegmentedAccess SegMem(DataType dt, Expression basePtr, Expression ptr) { var segMem = m.SegMem(dt, basePtr, ptr); var idOld = segMem.MemoryId; var idNew = new MemoryIdentifier(ssaIds.Count, idOld.DataType); segMem.MemoryId = idNew; var sid = new SsaIdentifier(idNew, idOld, null, null, false); ssaIds.Add(idNew, sid); return(segMem); }
public void DeciWeb() { Build(new DiamondMock().Procedure); DeclarationInserter deci = new DeclarationInserter(ssaIds, doms); Web web = new Web(); SsaIdentifier r_1 = ssaIds.Where(s => s.Identifier.Name == "r_1").Single(); SsaIdentifier r_3 = ssaIds.Where(s => s.Identifier.Name == "r_3").Single(); SsaIdentifier r_4 = ssaIds.Where(s => s.Identifier.Name == "r_4").Single(); web.Add(r_1); web.Add(r_3); web.Add(r_4); deci.InsertDeclaration(web); Assert.AreEqual("word32 r_1", proc.ControlGraph.Blocks[2].Statements[0].Instruction.ToString()); }
public void OutpReplaceSimple() { var m = new ProcedureBuilder(); var block = m.Label("block"); var foo = new Identifier("foo", PrimitiveType.Word32, null); var pfoo = new Identifier("pfoo", PrimitiveType.Pointer32, null); m.Assign(foo, 3); var sid = new SsaIdentifier(foo, foo, m.Block.Statements.Last, null, false); var ssaIds = new SsaIdentifierCollection { { foo, sid } }; var opt = new OutParameterTransformer(null, ssaIds); opt.ReplaceDefinitionsWithOutParameter(foo, pfoo); Assert.AreEqual("*pfoo = 0x00000003", m.Block.Statements[0].ToString()); }
public void SltLiveLoop() { Build(new LiveLoopMock().Procedure, new FakeArchitecture()); using (FileUnitTester fut = new FileUnitTester("Analysis/SltLiveLoop.txt")) { sla.Write(proc, fut.TextWriter); fut.TextWriter.WriteLine("======================="); fut.AssertFilesEqual(); } SsaIdentifier i = ssa.Identifiers.Where(s => s.Identifier.Name == "i").Single(); SsaIdentifier i_1 = ssa.Identifiers.Where(s => s.Identifier.Name == "i_1").Single(); SsaIdentifier i_3 = ssa.Identifiers.Where(s => s.Identifier.Name == "i_3").Single(); Assert.IsFalse(sla.IsLiveOut(i.Identifier, i_1.DefStatement)); var block1 = proc.ControlGraph.Blocks.Where(b => b.Name == "loop").Single(); Assert.AreEqual("branch Mem0[i_3:byte] != 0 loop", block1.Statements[2].Instruction.ToString()); Assert.IsTrue(sla.IsLiveOut(i_1.Identifier, block1.Statements[2]), "i_1 should be live at the end of block 1"); Assert.IsTrue(sla.IsLiveOut(i_3.Identifier, block1.Statements[2]), "i_3 should be live at the end of block 1"); Assert.AreEqual("i_1 = PHI(i, i_3)", block1.Statements[0].Instruction.ToString()); Assert.IsFalse(sla.IsLiveOut(i_3.Identifier, block1.Statements[0]), "i_3 is dead after the phi function"); }
public void Idc_ConstantPropagate() { Identifier ds = m.Frame.EnsureRegister(Registers.ds); var c = Constant.Word16(0x1234); m.Assign(ds, c); m.SideEffect(ds); var def = m.Block.Statements[0]; var use = m.Block.Statements[1]; SsaIdentifier sid_ds = ssa.Add(ds, def, c, false); var ass = (Assignment)def.Instruction; ass.Dst = sid_ds.Identifier; ((SideEffect)use.Instruction).Expression = sid_ds.Identifier; sid_ds.Uses.Add(use); IdConstant ic = new IdConstant(new SsaEvaluationContext(null, ssa), new Unifier(null), listener); Assert.IsTrue(ic.Match(sid_ds.Identifier)); Expression e = ic.Transform(); Assert.AreEqual("selector", e.DataType.ToString()); }