Exemplo n.º 1
0
        public static VCExpr GenerateVC(Program prog, Implementation impl)
        {
            VC.vcgen.ConvertCFG2DAG(impl);
            ModelViewInfo mvInfo;
            Dictionary <TransferCmd, ReturnCmd> gotoCmdOrigins = VC.vcgen.PassifyImpl(impl, out mvInfo);
            //Hashtable/*TransferCmd->ReturnCmd*/ gotoCmdOrigins = VC.vcgen.PassifyImpl(impl, out mvInfo);

            var exprGen = VC.proverInterface.Context.ExprGen;
            //VCExpr controlFlowVariableExpr = null;
            VCExpr controlFlowVariableExpr = CommandLineOptions.Clo.UseLabels ? null : VC.exprGen.Integer(BigNum.ZERO);


            //Hashtable/*<int, Absy!>*/ label2absy;
            Dictionary <int, Absy> label2absy;
            var vc = VC.vcgen.GenerateVC(impl, controlFlowVariableExpr, out label2absy, VC.proverInterface.Context);

            if (!CommandLineOptions.Clo.UseLabels)
            {
                VCExpr controlFlowFunctionAppl = VC.exprGen.ControlFlowFunctionApplication(VC.exprGen.Integer(BigNum.ZERO), VC.exprGen.Integer(BigNum.ZERO));
                VCExpr eqExpr = VC.exprGen.Eq(controlFlowFunctionAppl, VC.exprGen.Integer(BigNum.FromInt(impl.Blocks[0].UniqueId)));
                vc = VC.exprGen.Implies(eqExpr, vc);
            }

            if (CommandLineOptions.Clo.vcVariety == CommandLineOptions.VCVariety.Local)
            {
                VC.handler = new VCGen.ErrorReporterLocal(gotoCmdOrigins, label2absy, impl.Blocks, VC.vcgen.incarnationOriginMap, VC.collector, mvInfo, VC.proverInterface.Context, prog);
            }
            else
            {
                VC.handler = new VCGen.ErrorReporter(gotoCmdOrigins, label2absy, impl.Blocks, VC.vcgen.incarnationOriginMap, VC.collector, mvInfo, VC.proverInterface.Context, prog);
            }
            return(vc);
        }
Exemplo n.º 2
0
        public HoudiniSession(Houdini houdini, VCGen vcgen, ProverInterface proverInterface, Program program, Implementation impl, HoudiniStatistics stats, int taskID = -1)
        {
            this.descriptiveName = impl.Name;
            this.stats           = stats;
            collector            = new ConditionGeneration.CounterexampleCollector();
            collector.OnProgress("HdnVCGen", 0, 0, 0.0);

            vcgen.ConvertCFG2DAG(impl, taskID: taskID);
            ModelViewInfo mvInfo;
            var           gotoCmdOrigins = vcgen.PassifyImpl(impl, out mvInfo);

            ExistentialConstantCollector ecollector;

            ExistentialConstantCollector.CollectHoudiniConstants(houdini, impl, out ecollector);
            this.houdiniAssertConstants   = ecollector.houdiniAssertConstants;
            this.houdiniAssumeConstants   = ecollector.houdiniAssumeConstants;
            this.explainConstantsNegative = ecollector.explainNegative;
            this.explainConstantsPositive = ecollector.explainPositive;
            this.constantToControl        = ecollector.constToControl;

            houdiniConstants = new HashSet <Variable>();
            houdiniConstants.UnionWith(houdiniAssertConstants);
            houdiniConstants.UnionWith(houdiniAssumeConstants);

            var    exprGen = proverInterface.Context.ExprGen;
            VCExpr controlFlowVariableExpr = CommandLineOptions.Clo.UseLabels ? null : exprGen.Integer(BigNum.ZERO);

            Dictionary <int, Absy> label2absy;

            conjecture = vcgen.GenerateVC(impl, controlFlowVariableExpr, out label2absy, proverInterface.Context);
            if (!CommandLineOptions.Clo.UseLabels)
            {
                VCExpr controlFlowFunctionAppl = exprGen.ControlFlowFunctionApplication(exprGen.Integer(BigNum.ZERO), exprGen.Integer(BigNum.ZERO));
                VCExpr eqExpr = exprGen.Eq(controlFlowFunctionAppl, exprGen.Integer(BigNum.FromInt(impl.Blocks[0].UniqueId)));
                conjecture = exprGen.Implies(eqExpr, conjecture);
            }

            Macro macro = new Macro(Token.NoToken, descriptiveName, new List <Variable>(), new Formal(Token.NoToken, new TypedIdent(Token.NoToken, "", Type.Bool), false));

            proverInterface.DefineMacro(macro, conjecture);
            conjecture = exprGen.Function(macro);

            if (CommandLineOptions.Clo.vcVariety == CommandLineOptions.VCVariety.Local)
            {
                handler = new VCGen.ErrorReporterLocal(gotoCmdOrigins, label2absy, impl.Blocks, vcgen.incarnationOriginMap, collector, mvInfo, proverInterface.Context, program);
            }
            else
            {
                handler = new VCGen.ErrorReporter(gotoCmdOrigins, label2absy, impl.Blocks, vcgen.incarnationOriginMap, collector, mvInfo, proverInterface.Context, program);
            }
        }
Exemplo n.º 3
0
        public void NewProblem(string descriptiveName, VCExpr vc, ProverInterface.ErrorHandler handler)
        {
            Contract.Requires(descriptiveName != null);
            Contract.Requires(vc != null);
            Contract.Requires(handler != null);
            HashSet <string /*!*/> /*!*/ labels = FindLabelsVisitor.FindLabels(vc);

            Contract.Assert(labels != null);
            toInspector.WriteLine("PROBLEM " + descriptiveName);
            toInspector.WriteLine("TOKEN BEGIN");
            foreach (string lab in labels)
            {
                Contract.Assert(lab != null);
                string no   = lab.Substring(1);
                Absy   absy = handler.Label2Absy(no);

                IToken    tok   = absy.tok;
                AssertCmd assrt = absy as AssertCmd;
                Block     blk   = absy as Block;
                string    val   = tok.val; // might require computation, so cache it
                if (val == "foo" || tok.filename == null)
                {
                    continue;                               // no token
                }
                toInspector.Write("TOKEN ");
                toInspector.Write(lab);
                toInspector.Write(" ");

                if (assrt != null)
                {
                    toInspector.Write("ASSERT");
                    string errData = assrt.ErrorData as string;
                    if (errData != null)
                    {
                        val = errData;
                    }
                    else if (assrt.ErrorMessage != null)
                    {
                        val = assrt.ErrorMessage;
                    }
                }
                else if (blk != null)
                {
                    toInspector.Write("BLOCK ");
                    toInspector.Write(blk.Label);
                }
                else
                {
                    Contract.Assume(false);
                }
                if (val == null || val == "assert" || val == "ensures")
                {
                    val = "";
                }

                if (absy is LoopInitAssertCmd)
                {
                    val += " (loop entry)";
                }
                else if (absy is LoopInvMaintainedAssertCmd)
                {
                    val += " (loop body)";
                }
                else if (val.IndexOf("#VCCERR") >= 0)
                {
                    // skip further transformations
                }
                else if (absy is AssertRequiresCmd)
                {
                    AssertRequiresCmd req  = (AssertRequiresCmd)absy;
                    IToken            t2   = req.Requires.tok;
                    string            tval = t2.val;
                    if (tval == "requires")
                    {
                        tval = string.Format("{0}({1},{2}))", t2.filename, t2.line, t2.col);
                    }
                    string call = "";
                    if (val != "call")
                    {
                        call = " in call to " + val;
                    }
                    val = string.Format("precondition {0}{1}", tval, call);
                }

                val = val.Replace("\r", "").Replace("\n", " ");

                toInspector.WriteLine(string.Format(" {0} {1} :@:{2}:@:{3}", tok.line, tok.col, tok.filename, val));
            }
            toInspector.WriteLine("TOKEN END");
        }
Exemplo n.º 4
0
        public static ProverInterface.Outcome MyBeginCheck(string descriptiveName, VCExpr vc, ProverInterface.ErrorHandler handler)
        {
            VC.proverInterface.Push();
            VC.proverInterface.Assert(vc, true);
            VC.proverInterface.Check();
            var outcome = VC.proverInterface.CheckOutcomeCore(VC.handler);

            VC.proverInterface.Pop();
            return(outcome);
        }