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()); }
public void OutpReplacePhi() { var m = new ProcedureBuilder(); var foo = new Identifier("foo", PrimitiveType.Word32, null); var foo1 = new Identifier("foo1", PrimitiveType.Word32, null); var foo2 = new Identifier("foo2", PrimitiveType.Word32, null); var foo3 = new Identifier("foo3", PrimitiveType.Word32, null); var pfoo = new Identifier("pfoo", PrimitiveType.Pointer32, null); Block block1 = m.Label("block1"); m.Assign(foo1, Constant.Word32(1)); Statement stmFoo1 = m.Block.Statements.Last; Block block2 = m.Label("block2"); m.Assign(foo2, Constant.Word32(2)); Statement stmFoo2 = m.Block.Statements.Last; Block block3 = m.Label("block3"); Statement stmFoo3 = m.Phi(foo3, foo1, foo2); SsaIdentifierCollection ssaIds = new SsaIdentifierCollection(); ssaIds.Add(foo1, new SsaIdentifier(foo1, foo, stmFoo1, null, false)); ssaIds.Add(foo2, new SsaIdentifier(foo2, foo, stmFoo2, null, false)); ssaIds.Add(foo3, new SsaIdentifier(foo3, foo, stmFoo3, null, false)); OutParameterTransformer opt = new OutParameterTransformer(null, ssaIds); opt.ReplaceDefinitionsWithOutParameter(foo3, pfoo); Assert.AreEqual("*pfoo = 0x00000001", stmFoo1.Instruction.ToString()); Assert.AreEqual("*pfoo = 0x00000002", stmFoo2.Instruction.ToString()); Assert.AreEqual("foo3 = PHI(foo1, foo2)", stmFoo3.Instruction.ToString()); }