public void TestCase()
        {
            Prog = SymbooglixTest.LoadProgramFrom("Transforms/programs/AnnotationPass.bpl");

            var pm = new PassManager();

            pm.Add(new Symbooglix.Annotation.InstructionStatisticsAnnotater());
            pm.Run(Prog);

            // Check Axioms
            foreach (var axiom in Prog.TopLevelDeclarations.OfType <Axiom>())
            {
                DoSomethingWithInstructionStatistics(axiom.GetInstructionStatistics());
            }


            // Check Procedures
            foreach (var proc in Prog.TopLevelDeclarations.OfType <Procedure>())
            {
                foreach (var requires in proc.Requires)
                {
                    DoSomethingWithInstructionStatistics(requires.GetInstructionStatistics());
                }

                foreach (var ensures in proc.Ensures)
                {
                    DoSomethingWithInstructionStatistics(ensures.GetInstructionStatistics());
                }
            }

            // Check basic blocks
            foreach (var bb in Prog.Blocks())
            {
                foreach (var cmd in bb.Cmds)
                {
                    DoSomethingWithInstructionStatistics(cmd.GetInstructionStatistics());
                }

                if (bb.TransferCmd is GotoCmd)
                {
                    var gotoCmd    = bb.TransferCmd as GotoCmd;
                    var instrStats = gotoCmd.GetInstructionStatistics() as GotoInstructionStatistics;
                    Assert.AreEqual(0, instrStats.Covered);
                    Assert.AreEqual(0, instrStats.TotalJumps);

                    foreach (var target in gotoCmd.labelTargets)
                    {
                        Assert.AreEqual(0, instrStats.GetJumpsTo(target));
                    }
                }
                else
                {
                    DoSomethingWithInstructionStatistics((bb.TransferCmd as ReturnCmd).GetInstructionStatistics());
                }
            }
        }
예제 #2
0
        public void TestCase()
        {
            Program program = SymbooglixTest.LoadProgramFrom("Transforms/programs/NestedFunctionsToInline.bpl");

            var PM = new PassManager();

            PM.Add(new FunctionInliningPass());
            PM.Run(program);

            // Check the Expression on the AssertCmd was inlined as expected
            var assert = SymbooglixTest.GetMain(program).Blocks[0].Cmds[0] as AssertCmd;

            Assert.AreEqual("v + 1 + v + 1 + 1 == 12", assert.Expr.ToString());
        }
예제 #3
0
        public void InlineExistsWithFreeVariable()
        {
            Program program = SymbooglixTest.LoadProgramFrom("Transforms/programs/InlineExists.bpl");

            var PM = new PassManager();

            PM.Add(new FunctionInliningPass());
            PM.Run(program);

            // Check the requires on strLen
            var strLenProc = program.TopLevelDeclarations.OfType <Procedure>().Where(proc => proc.Name == "strLen").First();

            Assert.AreEqual("(exists x: int :: x >= 0 && s[x] == 0bv8)", strLenProc.Requires[0].Condition.ToString());
        }
예제 #4
0
        public void TestCase()
        {
            Program program = SymbooglixTest.LoadProgramFrom("Transforms/programs/simple_function_inline.bpl");

            var PM = new PassManager();

            PM.Add(new FunctionInliningPass());
            PM.Run(program);

            // Now check what we expected to be inlined was inlined

            // Another function that uses foo
            var barFunction = program.TopLevelDeclarations.OfType <Function>().Where(f => f.Name == "bar").First();

            Assert.AreEqual("(if x > 0 then x == 0 else x - 1 == 0)", barFunction.Body.ToString());

            // Axiom
            var axiom = program.TopLevelDeclarations.OfType <Axiom>().First();

            Assert.AreEqual("v == 0", axiom.Expr.ToString());


            var procedure = program.TopLevelDeclarations.OfType <Procedure>().First();

            // Requires
            Assert.AreEqual(1, procedure.Requires.Count);
            Assert.AreEqual("x == 0 && false <==> x == 0", procedure.Requires[0].Condition.ToString());

            // Ensures
            Assert.AreEqual(1, procedure.Ensures.Count);
            Assert.AreEqual("x == 0 <==> x == 0", procedure.Ensures[0].Condition.ToString());

            // Assert statement
            var assertCmd = program.TopLevelDeclarations.OfType <Implementation>().SelectMany(i => i.Blocks).SelectMany(cmd => cmd.Cmds).OfType <AssertCmd>().First();

            Assert.AreEqual("x == 0", assertCmd.Expr.ToString());
        }
예제 #5
0
 private void LoadProgram()
 {
     prog = SymbooglixTest.LoadProgramFrom("Transforms/programs/OldExprCanonicalise.bpl");
 }
예제 #6
0
        public void TestCase()
        {
            Prog = SymbooglixTest.LoadProgramFrom("Transforms/programs/AnnotationPass.bpl");

            var pm = new PassManager();

            pm.Add(new Symbooglix.Annotation.ProgramLocationAnnotater());
            pm.Run(Prog);

            // Check Variables (Global and constant)
            foreach (var variable in Prog.TopLevelDeclarations.OfType <Variable>())
            {
                CheckIsNotNullAndString(variable.GetProgramLocation());
                Assert.IsTrue(variable.GetProgramLocation().IsVariable);
            }

            // Check Procedures
            foreach (var proc in Prog.TopLevelDeclarations.OfType <Procedure>())
            {
                // TODO: Should Procedures have an associated ProgramLocation?
                //DoSomethingWithProgramLocation(proc.GetProgramLocation());

                foreach (var requires in proc.Requires)
                {
                    CheckIsNotNullAndString(requires.GetProgramLocation());
                    Assert.IsTrue(requires.GetProgramLocation().IsRequires);
                }

                foreach (var ensures in proc.Ensures)
                {
                    CheckIsNotNullAndString(ensures.GetProgramLocation());
                    Assert.IsTrue(ensures.GetProgramLocation().IsEnsures);
                }

                foreach (var inParam in proc.InParams)
                {
                    CheckIsNotNullAndString(inParam.GetProgramLocation());
                    Assert.IsTrue(inParam.GetProgramLocation().IsVariable);
                }

                foreach (var outParam in proc.OutParams)
                {
                    CheckIsNotNullAndString(outParam.GetProgramLocation());
                    Assert.IsTrue(outParam.GetProgramLocation().IsVariable);
                }

                CheckIsNotNullAndString(proc.GetModSetProgramLocation());
                Assert.IsTrue(proc.GetModSetProgramLocation().IsModifiesSet);
            }

            // Check Implementations
            foreach (var impl in Prog.TopLevelDeclarations.OfType <Implementation>())
            {
                // TODO: Should Implementations have an associated ProgramLocation?
                //DoSomethingWithProgramLocation(impl.GetProgramLocation());

                foreach (var inParam in impl.InParams)
                {
                    CheckIsNotNullAndString(inParam.GetProgramLocation());
                    Assert.IsTrue(inParam.GetProgramLocation().IsVariable);
                }

                foreach (var outParam in impl.OutParams)
                {
                    CheckIsNotNullAndString(outParam.GetProgramLocation());
                    Assert.IsTrue(outParam.GetProgramLocation().IsVariable);
                }

                foreach (var localVariable in impl.LocVars)
                {
                    CheckIsNotNullAndString(localVariable.GetProgramLocation());
                    Assert.IsTrue(localVariable.GetProgramLocation().IsVariable);
                }
            }

            // Check basic blocks
            foreach (var bb in Prog.Blocks())
            {
                foreach (var cmd in bb.Cmds)
                {
                    CheckIsNotNullAndString(cmd.GetProgramLocation());
                    Assert.IsTrue(cmd.GetProgramLocation().IsCmd);
                }

                CheckIsNotNullAndString(bb.TransferCmd.GetProgramLocation());
                Assert.IsTrue(bb.TransferCmd.GetProgramLocation().IsTransferCmd);
            }
        }