Esempio n. 1
0
        static int Main(string[] args)
        {
            CommandLineOptions.Install(new CommandLineOptions());
            int argc = args.Length;

            if (argc < 4)
            {
                System.Console.WriteLine("Boogiewrapper.exe a.bpl EQ LEFT RIGHT [v1name] [v2name] [bvdfriendly]");
                System.Console.WriteLine("\t   EQ: name of the combined procedure to be verified");
                System.Console.WriteLine("\t   RIGHT: name of the right procedure");
                System.Console.WriteLine("\t   RIGHT: name of the right procedure");
                System.Console.WriteLine("\t   viname: optional prefix of the left/right procedure (when not checking EQ_v1.foo__xx__v2.foo)");
                System.Console.WriteLine("\t   bvdfriendly: optional instrument the input file to add some captureStates for bvd to display (no checking)");
                return(-1);
            }
            string fileName = args[0];
            string funcName = args[1];

            //TODO: Make it aware of the other Boogie options
            var boogieOptions = " -doModSetAnalysis -printInstrumented -z3multipleErrors -typeEncoding:m -timeLimit:" + Options.Timeout + " -removeEmptyBlocks:0 -printModel:1 -printModelToFile:model.dmp " + Options.BoogieUserOpts;

            SDiff.Boogie.Process.InitializeBoogie(boogieOptions);

            Program prog = BoogieUtils.ParseProgram(args[0]);

            if (prog == null)
            {
                Log.Out(Log.Verifier, "Parse Error!!! in   " + args[1]);
                return(-1);
            }
            if (BoogieUtils.ResolveAndTypeCheckThrow(prog, args[0]))
            {
                return(-1);
            }
            //code duplication

            //Not having "-printInstrumented" just prints the old version of hte program!!!!
            if (args.Length == 7 && args[6] == "/bvdfriendly")
            {
                //System.Diagnostics.Debugger.Break();
                var     bvdI  = new BvdInstrument();
                Program prog1 = bvdI.VisitProgram(prog);
                if (BoogieUtils.ResolveAndTypeCheckThrow(prog, fileName))
                {
                    return(-1);
                }
                Util.DumpBplAST(prog, "merged_bvd.bpl");
                return(-1);
            }

            var newProg = prog;

            VC.ConditionGeneration vcgen = BoogieVerify.InitializeVC(newProg);
            var newDict = SDiff.Boogie.Process.BuildProgramDictionary(newProg.TopLevelDeclarations.ToList());

            //RS: Uncomment this
            var newEq = (Implementation)newDict.Get(funcName + "$IMPL");
            SDiffCounterexamples SErrors;
            List <Model>         errModelList;

            var Result = BoogieVerify.VerifyImplementation(vcgen, newEq, newProg, out SErrors, out errModelList);

            switch (Result)
            {
            case VerificationResult.Error:
                Log.Out(Log.Verifier, "Result: Error");
                break;

            case VerificationResult.Verified:
                Log.Out(Log.Verifier, "Result: Verified");
                break;

            case VerificationResult.OutOfMemory:
                Log.Out(Log.Verifier, "Result: OutOfMemory");
                return(-2);

            //break;
            case VerificationResult.TimeOut:
                Log.Out(Log.Verifier, "Result: TimeOut");
                return(-3);

            // break;
            default:
                Log.Out(Log.Verifier, "Result: Unhandled");
                return(-4);
            }
            Implementation n1, n2;

            GetImplementations(newDict, funcName, out n1, out n2, args[2], args[3]);

            var outputVars = new List <Variable>();

            foreach (Variable v in n1.OutParams)
            {
                outputVars.Add(newDict.Get(v.Name + "$VAR") as Variable);
            }
            foreach (Variable v in n2.OutParams)
            {
                outputVars.Add(newDict.Get(v.Name + "$VAR") as Variable);
            }


            var globals = new List <Variable>();

            foreach (IdentifierExpr ie in newEq.Proc.Modifies)
            {
                globals.Add(ie.Decl);
            }


            if (SErrors != null)
            {
                //somewhat misnamed...
                if (Options.DumpBeforeVerifying)
                {
                    Log.Out(Log.SymEx, "Dumping procedure under verification");
                    newEq.Emit(Log.LogWriter, 0);
                }
                if (Options.DoSymEx)
                {
                    if (Options.PreciseDifferentialInline)
                    {
                        IEnumerable <Declaration> consts = prog.TopLevelDeclarations.Where(x => x is Constant);
                        if (args.Length < 6)
                        {
                            BoogieVerify.ProcessCounterexamplesWOSymbolicOut(SErrors, globals, newEq.LocVars, null, null, consts.ToList(), errModelList);
                        }
                        else
                        {
                            BoogieVerify.ProcessCounterexamplesWOSymbolicOut(SErrors, globals, newEq.LocVars, null, null, consts.ToList(), errModelList, args[4], args[5]);
                        }
                    }
                    else
                    {
                        BoogieVerify.ProcessCounterexamples(SErrors, globals, outputVars, newProg, null, null);
                    }
                }
            }

            return(SErrors == null ? 0 : SErrors.Count);
        }
Esempio n. 2
0
        public static int RVTRunVerificationTask(SDiff.VerificationTask vt, VC.ConditionGeneration vcgen, Program prog,
                                                 HashSet <int> inlinedFns1, HashSet <int> inlinedFns2, out bool crashed)
        {
            Log.Out(Log.Verifier, "Verifying " + vt.Eq.Name);

            crashed = false;


            var attList = new List <Object>(1);

            attList.Add(Expr.Literal(1));

            //save attributes
            var sqkLeft   = vt.Left.Attributes;
            var sqkpLeft  = vt.Left.Proc.Attributes;
            var sqkRight  = vt.Right.Attributes;
            var sqkpRight = vt.Right.Proc.Attributes;

            //save postconditions
            var leftPosts  = vt.Left.Proc.Ensures;
            var rightPosts = vt.Right.Proc.Ensures;

            //Keep the postconditions correpsonding to the
            //free ensures (out == uf_Foo(inp))
            //vt.Left.Proc.Ensures = new List<Ensures>();
            //vt.Right.Proc.Ensures = new List<Ensures>();

            //inline procedures under analysis
            vt.Left.Attributes
                = Util.MkInlinedAttribute(attList);
            vt.Left.Proc.Attributes = vt.Left.Attributes;

            vt.Right.Attributes
                = Util.MkInlinedAttribute(attList);
            vt.Right.Proc.Attributes = vt.Right.Attributes;

            vt.Left.OriginalBlocks   = vt.Left.Blocks;
            vt.Left.OriginalLocVars  = vt.Left.LocVars;
            vt.Right.OriginalBlocks  = vt.Right.Blocks;
            vt.Right.OriginalLocVars = vt.Right.LocVars;


            IEnumerable <Declaration> procImplPIter = prog.TopLevelDeclarations.Where(x => x is Implementation);

            List <Implementation> inlinedImpls = new List <Implementation>();

            foreach (Implementation currentProcImpl in procImplPIter)
            {
                bool match = false;
                int  indx  = -1;
                if (fnNameToIndex1.ContainsKey(currentProcImpl.Proc.Name))
                {
                    match = true;
                    indx  = fnNameToIndex1[currentProcImpl.Proc.Name];
                }
                else if (fnNameToIndex2.ContainsKey(currentProcImpl.Proc.Name))
                {
                    match = true;
                    indx  = fnNameToIndex2[currentProcImpl.Proc.Name];
                }

                //Inline if present in
                if (match && (inlinedFns1.Contains(indx) || inlinedFns2.Contains(indx)))
                {
                    inlinedImpls.Add(currentProcImpl);
                    currentProcImpl.Attributes      = Util.MkInlinedAttribute(attList);
                    currentProcImpl.Proc.Attributes = Util.MkInlinedAttribute(attList);

                    //RUN INLINER OVER EQ FUNCTION
                    currentProcImpl.OriginalBlocks  = currentProcImpl.Blocks;
                    currentProcImpl.OriginalLocVars = currentProcImpl.LocVars;
                }
            }

            //RUN INLINER OVER EQ FUNCTION
            // prog = EQ program
            // vt.Eq = EQ_f_f' procedure with f, f' having {inline} tags
            Inliner.ProcessImplementation(prog, vt.Eq);

            if (Options.TraceVerify)
            {
                Log.Out(Log.Normal, "Ready to verify:");
                Log.LogEmit(Log.Normal, prog.Emit);
            }

            // To print the EQ files in

            Util.DumpBplAST(prog, vt.Eq.Name + "_out.bpl");
            // prog = SDiff.Boogie.Process.ParseProgram(vt.Eq.Name + "_out.bpl");

            if (BoogieUtils.ResolveAndTypeCheckThrow(prog, Options.MergedProgramOutputFile))
            {
                return(1);
            }

            Implementation newEq   = vt.Eq;
            var            newProg = prog;

            vcgen = BoogieVerify.InitializeVC(newProg);
            //SDiff.Boogie.Process.ResolveAndTypeCheck(newProg, "");
            var newDict = SDiff.Boogie.Process.BuildProgramDictionary(newProg.TopLevelDeclarations.ToList());
            //newEq = (Implementation)newDict.Get(vt.Eq.Name + "$IMPL");



            SDiffCounterexamples SErrors;
            List <Model>         errModelList;


            //Clear up the state since it might call the same procedure twice



            vt.Result = BoogieVerify.VerifyImplementation(vcgen, newEq, newProg, out SErrors, out errModelList);

            switch (vt.Result)
            {
            case SDiff.VerificationResult.Error:
                Log.Out(Log.Verifier, "Result: Error");
                break;

            case SDiff.VerificationResult.Verified:
                Log.Out(Log.Verifier, "Result: Verified");
                break;

            default:
                Log.Out(Log.Verifier, "Result: Unhandled");
                crashed = true;
                break;
            }

            //restore postconditions IN THE OLD IN-MEMORY PROGRAM
            vt.Left.Proc.Ensures  = leftPosts;
            vt.Right.Proc.Ensures = rightPosts;

            //remove the inline annotation IN THE OLD IN-MEMORY PROGRAM
            vt.Left.Attributes       = sqkLeft;
            vt.Left.Proc.Attributes  = sqkpLeft;
            vt.Right.Attributes      = sqkRight;
            vt.Right.Proc.Attributes = sqkpRight;

            //remove the inline annotation in the Inlined Procedures
            foreach (Implementation currentProcImpl in procImplPIter)
            {
                if (inlinedImpls.Contains(currentProcImpl))
                {
                    currentProcImpl.Attributes      = null;
                    currentProcImpl.Proc.Attributes = null;
                }
            }

            if (vt.Result == SDiff.VerificationResult.Verified)
            {
                return(1);
            }
            else
            {
                return(0);
            }
        }