Esempio n. 1
0
        public static void Initialize(Configs config)
        {
            // Program
            progVerifyOptions = new BoogieVerifyOptions();
            progVerifyOptions.NonUniformUnfolding       = config.NonUniformUnfolding;
            progVerifyOptions.newStratifiedInlining     = config.newStratifiedInlining;
            progVerifyOptions.newStratifiedInliningAlgo = config.newStratifiedInliningAlgo;
            progVerifyOptions.CallTree          = config.noCallTreeReuse ? null : new HashSet <string>();
            progVerifyOptions.UseProverEvaluate = config.useProverEvaluate;
            progVerifyOptions.StratifiedInliningWithoutModels = progVerifyOptions.UseProverEvaluate ? true : false;
            progVerifyOptions.useFwdBck = config.FwdBckSearch == 1;
            progVerifyOptions.useDI     = config.useDI;
            progVerifyOptions.extraFlags.UnionWith(config.extraFlags);
            if (config.staticInlining > 0)
            {
                progVerifyOptions.StratifiedInlining = 100;
            }

            // Path
            pathVerifyOptions = new BoogieVerifyOptions();
            pathVerifyOptions.StratifiedInlining              = 100;
            pathVerifyOptions.newStratifiedInlining           = config.newStratifiedInlining;
            pathVerifyOptions.newStratifiedInliningAlgo       = config.newStratifiedInliningAlgo;
            pathVerifyOptions.UseProverEvaluate               = config.useProverEvaluate;
            pathVerifyOptions.StratifiedInliningWithoutModels = pathVerifyOptions.UseProverEvaluate ? true : false;;
            pathVerifyOptions.useFwdBck = false;
            pathVerifyOptions.useDI     = false;
            if (config.printData == 2)
            {
                pathVerifyOptions.StratifiedInliningWithoutModels = false;
                pathVerifyOptions.ModelViewFile = "corral_model";
            }

            if (config.printVerify)
            {
                progVerifyOptions.printProg    = true;
                progVerifyOptions.progFileName = "last_query.bpl";
                pathVerifyOptions.printProg    = true;
                pathVerifyOptions.progFileName = "last_query.bpl";
            }

            if (config.printFinalProg != null)
            {
                progVerifyOptions.printProg    = true;
                progVerifyOptions.progFileName = config.printFinalProg;
            }

            // Refinement
            refinementVerifyOptions = pathVerifyOptions.Copy();
            //refinementVerifyOptions.UseProverEvaluate = false;
            refinementVerifyOptions.UseProverEvaluate = config.newStratifiedInlining;
            refinementVerifyOptions.StratifiedInliningWithoutModels = true;
            refinementVerifyOptions.ModelViewFile = null;
            refinementVerifyOptions.useFwdBck     = false;
            refinementVerifyOptions.useDI         = false;
        }
Esempio n. 2
0
        public static void AbsorbPrevState(Configs config, BoogieVerifyOptions progVerifyOptions)
        {
            var cs = GetCorralState(config.prevCorralState);

            if (cs != null)
            {
                progVerifyOptions.CallTree = cs.CallTree;
                config.trackedVars.UnionWith(cs.TrackedVariables);
            }
        }
        public static Dictionary <string, int> Compute(CBAProgram program, int max, List <string> Annotations, BoogieVerifyOptions options)
        {
            var loopBounds = new Dictionary <string, int>();

            Initialize(Annotations);
            maxBound = max;
            var start = DateTime.Now;

            // remove non-free ensures and requires
            program.TopLevelDeclarations.OfType <Procedure>()
            .Iter(proc => proc.Ensures = proc.Ensures.Filter(en => en.Free));
            program.TopLevelDeclarations.OfType <Procedure>()
            .Iter(proc => proc.Requires = proc.Requires.Filter(en => en.Free));
            // remove assertions
            program.TopLevelDeclarations.OfType <Implementation>()
            .Iter(impl => impl.Blocks
                  .Iter(blk => blk.Cmds = blk.Cmds.Map(c =>
            {
                var ac = c as AssertCmd;
                if (ac == null)
                {
                    return(c);
                }
                return(new AssumeCmd(ac.tok, /*ac.Expr*/ Expr.True, ac.Attributes));
            })));
            // delete yield
            program.TopLevelDeclarations.OfType <Implementation>()
            .Iter(impl => impl.Blocks
                  .Iter(blk => blk.Cmds.RemoveAll(c => c is YieldCmd)));

            // Call graph
            ComputeCallGraph(program);

            // Gather the set of implementations with "loop" inside their name
            var allLoopImpls = new List <Implementation>();

            program.TopLevelDeclarations.OfType <Implementation>()
            .Iter(impl => { if (impl.Name.Contains("loop"))
                            {
                                allLoopImpls.Add(impl);
                            }
                  });

            // Prune to the right form
            var loopImpls = allLoopImpls.Filter(CheckImpl);

            #region Process user annotations

            // Include user anntations
            var allLoops = new HashSet <string>();
            loopImpls.Iter(impl => allLoops.Add(impl.Name));
            foreach (var sp in UserAnnotations
                     .Where(s => s.StartsWith("LB:"))
                     .Select(s => s.Split(':'))
                     .Where(sp => sp.Length == 3))
            {
                // grab bound
                var bound = 0;
                if (!Int32.TryParse(sp[2], out bound))
                {
                    continue;
                }

                // grab proc
                if (!allLoops.Contains(sp[1]))
                {
                    continue;
                }

                loopBounds[sp[1]] = bound;
                Console.WriteLine("LB: Loop {0} requires minimum {1} iterations (annotated)", sp[1], bound);
            }
            loopImpls = loopImpls.Filter(impl => !loopBounds.ContainsKey(impl.Name));
            #endregion

            if (loopImpls.Count == 0)
            {
                return(loopBounds);
            }

            // Prepare query
            var query = PrepareQuery(loopImpls, program);

            // Set general options
            BoogieVerify.options = options;

            // Set rec. bound
            var oldBound = CommandLineOptions.Clo.RecursionBound;
            CommandLineOptions.Clo.RecursionBound = maxBound;

            // Query
            var allErrors = new List <BoogieErrorTrace>();
            BoogieVerify.Verify(query, out allErrors);
            foreach (var trace in allErrors)
            {
                var loopName = QKeyValue.FindStringAttribute(trace.impl.Attributes, "LB_Mapping");
                var bound    = RecBound(loopName, trace.cex, trace.impl.Name);
                if (bound <= 1)
                {
                    continue;
                }
                loopBounds.Add(loopName, bound);
                Console.WriteLine("LB: Loop {0} requires minimum {1} iterations", loopName, bound);
            }

            CommandLineOptions.Clo.RecursionBound = oldBound;
            timeTaken = (DateTime.Now - start);

            return(loopBounds);
        }