public void Liv_CreateIncInitialValue()
        {
            ssaIds = new SsaIdentifierCollection();
            LinearInductionVariableFinder liv = new LinearInductionVariableFinder(null, ssaIds, null);

            liv.Context.InitialValue  = Constant.Word32(0);
            liv.Context.PhiStatement  = new Statement(0, null, null);
            liv.Context.PhiIdentifier = new Identifier("foo_0", PrimitiveType.Word32, null);
            ssaIds.Add(liv.Context.PhiIdentifier, new SsaIdentifier(liv.Context.PhiIdentifier, liv.Context.PhiIdentifier, liv.Context.PhiStatement, null, false));
            liv.Context.DeltaValue     = Constant.Word32(1);
            liv.Context.DeltaStatement = new Statement(0, new Assignment(new Identifier("foo_1", PrimitiveType.Word32, null),
                                                                         new BinaryExpression(Operator.IAdd, PrimitiveType.Word32, liv.Context.PhiIdentifier, liv.Context.DeltaValue)), null);
            ssaIds[liv.Context.PhiIdentifier].Uses.Add(liv.Context.DeltaStatement);

            LinearInductionVariable iv = liv.CreateInductionVariable();

            Assert.AreEqual("(0x00000001 0x00000001 ?)", iv.ToString());
        }
        public void Liv_CreateBareMinimum()
        {
            ssaIds = new SsaIdentifierCollection();
            Identifier id0 = new Identifier("foo", PrimitiveType.Word32, new TemporaryStorage("foo", 1, PrimitiveType.Word32));
            Identifier id1 = new Identifier("bar", PrimitiveType.Word32, new TemporaryStorage("bar", 1, PrimitiveType.Word32));
            Identifier phi = new Identifier("i_3", PrimitiveType.Word32, null);

            ssaIds.Add(id0, new SsaIdentifier(id0, id0, null, null, false));
            ssaIds.Add(id1, new SsaIdentifier(id1, id1, null, null, false));
            ssaIds.Add(phi, new SsaIdentifier(phi, phi, null, null, false));
            LinearInductionVariableFinder liv = new LinearInductionVariableFinder(null, ssaIds, null);

            liv.Context.PhiStatement  = new Statement(0, null, null);
            liv.Context.PhiIdentifier = phi;
            liv.Context.DeltaValue    = Constant.Word32(1);
            LinearInductionVariable iv = liv.CreateInductionVariable();

            Assert.AreEqual("(? 0x00000001 ?)", iv.ToString());
        }
        public void Liv_CreateIncInitialValue()
        {
            var pb = new ProcedureBuilder();

            ssa = new SsaState(pb.Procedure);
            LinearInductionVariableFinder liv = new LinearInductionVariableFinder(ssa, null);

            liv.Context.InitialValue  = Constant.Word32(0);
            liv.Context.PhiStatement  = new Statement(0, null, null);
            liv.Context.PhiIdentifier = new Identifier("foo_0", PrimitiveType.Word32, null);
            ssa.Identifiers.Add(liv.Context.PhiIdentifier, new SsaIdentifier(liv.Context.PhiIdentifier, liv.Context.PhiIdentifier, liv.Context.PhiStatement, null, false));
            liv.Context.DeltaValue     = Constant.Word32(1);
            liv.Context.DeltaStatement = new Statement(0, new Assignment(new Identifier("foo_1", PrimitiveType.Word32, null),
                                                                         new BinaryExpression(Operator.IAdd, PrimitiveType.Word32, liv.Context.PhiIdentifier, liv.Context.DeltaValue)), null);
            ssa.Identifiers[liv.Context.PhiIdentifier].Uses.Add(liv.Context.DeltaStatement);

            LinearInductionVariable iv = liv.CreateInductionVariable();

            Assert.AreEqual("(1<32> 1<32> ?)", iv.ToString());
        }
        public void Liv_CreateBareMinimum()
        {
            var pb = new ProcedureBuilder();

            ssa = new SsaState(pb.Procedure);
            Identifier id0 = new Identifier("foo", PrimitiveType.Word32, new TemporaryStorage("foo", 1, PrimitiveType.Word32));
            Identifier id1 = new Identifier("bar", PrimitiveType.Word32, new TemporaryStorage("bar", 1, PrimitiveType.Word32));
            Identifier phi = new Identifier("i_3", PrimitiveType.Word32, null);

            ssa.Identifiers.Add(id0, new SsaIdentifier(id0, id0, null, null, false));
            ssa.Identifiers.Add(id1, new SsaIdentifier(id1, id1, null, null, false));
            ssa.Identifiers.Add(phi, new SsaIdentifier(phi, phi, null, null, false));
            var liv = new LinearInductionVariableFinder(ssa, null);

            liv.Context.PhiStatement  = new Statement(0, null, null);
            liv.Context.PhiIdentifier = phi;
            liv.Context.DeltaValue    = Constant.Word32(1);
            LinearInductionVariable iv = liv.CreateInductionVariable();

            Assert.AreEqual("(? 1<32> ?)", iv.ToString());
        }
        public void CreateNoincInitialValue()
        {
            ProcedureBuilder m = new ProcedureBuilder();

            ssa = new SsaState(m.Procedure);
            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(ssa, 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, ssa.Identifiers.Count);

            Identifier id3 = m.Local32("id_3");
            Identifier id4 = m.Local32("id_4");

            liv.Context.PhiStatement  = m.Phi(id3, (id2, "block2"), (id4, "block4"));
            liv.Context.PhiIdentifier = id3;
            SsaId(id3, liv.Context.PhiStatement, ((PhiAssignment)liv.Context.PhiStatement.Instruction).Src, false);
            Assert.AreEqual(4, ssa.Identifiers.Count);

            Statement use = new Statement(0, null, null);

            ssa.Identifiers[id3].Uses.Add(use);

            liv.Context.DeltaValue = m.Word32(1);
            m.Assign(id4, m.IAdd(id3, liv.Context.DeltaValue));
            liv.Context.DeltaStatement = m.Block.Statements.Last;
            ssa.Identifiers[id3].Uses.Add(liv.Context.DeltaStatement);

            LinearInductionVariable iv = liv.CreateInductionVariable();

            Assert.AreEqual("(0<32> 1<32> ?)", iv.ToString());
        }
        public void Liv_CreateNo()
        {
            var liv = new LinearInductionVariableFinder(null, null);

            Assert.IsNull(liv.CreateInductionVariable());
        }
		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 Liv_CreateIncInitialValue()
		{
			ssaIds = new SsaIdentifierCollection();
			LinearInductionVariableFinder liv = new LinearInductionVariableFinder(null, ssaIds, null);
			liv.Context.InitialValue = Constant.Word32(0);
			liv.Context.PhiStatement = new Statement(0, null, null);
			liv.Context.PhiIdentifier = new Identifier("foo_0", PrimitiveType.Word32, null);
            ssaIds.Add(liv.Context.PhiIdentifier, new SsaIdentifier(liv.Context.PhiIdentifier, liv.Context.PhiIdentifier, liv.Context.PhiStatement, null, false));
			liv.Context.DeltaValue = Constant.Word32(1);
			liv.Context.DeltaStatement = new Statement(0, new Assignment(new Identifier("foo_1", PrimitiveType.Word32, null), 
				new BinaryExpression(Operator.IAdd, PrimitiveType.Word32, liv.Context.PhiIdentifier, liv.Context.DeltaValue)), null);
			ssaIds[liv.Context.PhiIdentifier].Uses.Add(liv.Context.DeltaStatement);

			LinearInductionVariable iv = liv.CreateInductionVariable();
			Assert.AreEqual("(0x00000001 0x00000001 ?)", iv.ToString());
		}
		public void Liv_CreateBareMinimum()
		{
			ssaIds = new SsaIdentifierCollection();
            Identifier id0 = new Identifier("foo", PrimitiveType.Word32, new TemporaryStorage("foo", 1, PrimitiveType.Word32));
            Identifier id1 = new Identifier("bar", PrimitiveType.Word32, new TemporaryStorage("bar", 1, PrimitiveType.Word32));
            Identifier phi = new Identifier("i_3", PrimitiveType.Word32, null);
			ssaIds.Add(id0, new SsaIdentifier(id0, id0, null, null, false));
			ssaIds.Add(id1, new SsaIdentifier(id1, id1, null, null, false));
            ssaIds.Add(phi, new SsaIdentifier(phi, phi, null, null, false));
			LinearInductionVariableFinder liv = new LinearInductionVariableFinder(null, ssaIds, null);
			liv.Context.PhiStatement = new Statement(0, null, null);
            liv.Context.PhiIdentifier = phi;
			liv.Context.DeltaValue = Constant.Word32(1);
			LinearInductionVariable iv = liv.CreateInductionVariable();
			Assert.AreEqual("(? 0x00000001 ?)", iv.ToString());
		}
		public void Liv_CreateNo()
		{
			LinearInductionVariableFinder liv = new LinearInductionVariableFinder(null, null, null);
			Assert.IsNull(liv.CreateInductionVariable());
		}