Пример #1
0
        private void GenVC(Implementation impl)
        {
            ModelViewInfo          mvInfo;
            Dictionary <int, Absy> label2absy;

            vcgen.ConvertCFG2DAG(impl);
            vcgen.PassifyImpl(impl, out mvInfo);

            var gen    = prover.VCExprGen;
            var vcexpr = vcgen.GenerateVC(impl, null, out label2absy, prover.Context);

            // Create a macro so that the VC can sit with the theorem prover
            Macro macro = new Macro(Token.NoToken, impl.Name + "Macro", new List <Variable>(), new Formal(Token.NoToken, new TypedIdent(Token.NoToken, "", Bpl.Type.Bool), false));

            prover.DefineMacro(macro, vcexpr);

            // Store VC
            impl2VC.Add(impl.Name, gen.Function(macro));

            //Console.WriteLine("VC of {0}: {1}", impl.Name, vcexpr);

            // Find the assert
            impl2EndStateVars.Add(impl.Name, new List <VCExpr>());
            var found = false;

            foreach (var blk in impl.Blocks)
            {
                foreach (var cmd in blk.Cmds.OfType <AssertCmd>())
                {
                    if (BoogieUtil.isAssertTrue(cmd))
                    {
                        continue;
                    }
                    var nary = cmd.Expr as NAryExpr;
                    if (nary == null)
                    {
                        continue;
                    }
                    var pred = nary.Fun as FunctionCall;
                    if (pred == null || pred.FunctionName != (impl.Name + (AbstractHoudini.summaryPredSuffix)))
                    {
                        continue;
                    }

                    Debug.Assert(!found);
                    found = true;
                    nary.Args.OfType <Expr>()
                    .Iter(expr => impl2EndStateVars[impl.Name].Add(prover.Context.BoogieExprTranslator.Translate(expr)));
                }
            }
            Debug.Assert(found);

            // Grab summary predicates
            var visitor = new FindSummaryPred(prover.VCExprGen);

            visitor.Mutate(vcexpr, true);

            impl2CalleeSummaries.Add(impl.Name, new List <Tuple <string, VCExprNAry> >());
            visitor.summaryPreds.Iter(tup => impl2CalleeSummaries[impl.Name].Add(tup));
        }
Пример #2
0
        public HoudiniVC(StratifiedInliningInfo siInfo, HashSet <string> procCalls, HashSet <string> currentAssignment)
            : base(siInfo, procCalls)
        {
            var gen = siInfo.vcgen.prover.VCExprGen;
            // Remove CandiateFunc
            var fsp = new FindSummaryPred(gen);

            vcexpr = fsp.Apply(vcexpr);
            this.constantToAssumedExpr  = fsp.constantToAssumedExpr;
            this.constantToAssertedExpr = fsp.constantToAssertedExpr;


            if (!HoudiniInlining.DualHoudini)
            {
                // Assume current summaries of callees
                foreach (var tup in constantToAssumedExpr)
                {
                    if (!currentAssignment.Contains(tup.Item1))
                    {
                        continue;
                    }
                    vcexpr = gen.And(vcexpr, gen.Implies(tup.Item2, tup.Item3));
                }
            }
            else
            {
                // Assert current post
                foreach (var tup in constantToAssertedExpr)
                {
                    if (!currentAssignment.Contains(tup.Key))
                    {
                        continue;
                    }
                    vcexpr = gen.And(vcexpr, gen.Not(tup.Value));
                }
            }
        }