public StratifiedInliningInfo(Implementation implementation, StratifiedVCGenBase stratifiedVcGen, Action<Implementation> PassiveImplInstrumentation) { vcgen = stratifiedVcGen; impl = implementation; this.PassiveImplInstrumentation = PassiveImplInstrumentation; List<Variable> functionInterfaceVars = new List<Variable>(); foreach (Variable v in vcgen.program.GlobalVariables) { functionInterfaceVars.Add(new Formal(Token.NoToken, new TypedIdent(Token.NoToken, "", v.TypedIdent.Type), true)); } foreach (Variable v in impl.InParams) { functionInterfaceVars.Add(new Formal(Token.NoToken, new TypedIdent(Token.NoToken, "", v.TypedIdent.Type), true)); } foreach (Variable v in impl.OutParams) { functionInterfaceVars.Add(new Formal(Token.NoToken, new TypedIdent(Token.NoToken, "", v.TypedIdent.Type), true)); } foreach (IdentifierExpr e in impl.Proc.Modifies) { if (e.Decl == null) continue; functionInterfaceVars.Add(new Formal(Token.NoToken, new TypedIdent(Token.NoToken, "", e.Decl.TypedIdent.Type), true)); } Formal returnVar = new Formal(Token.NoToken, new TypedIdent(Token.NoToken, "", Bpl.Type.Bool), false); function = new Function(Token.NoToken, impl.Name, functionInterfaceVars, returnVar); vcgen.prover.Context.DeclareFunction(function, ""); List<Expr> exprs = new List<Expr>(); foreach (Variable v in vcgen.program.GlobalVariables) { Contract.Assert(v != null); exprs.Add(new OldExpr(Token.NoToken, new IdentifierExpr(Token.NoToken, v))); } foreach (Variable v in impl.Proc.InParams) { Contract.Assert(v != null); exprs.Add(new IdentifierExpr(Token.NoToken, v)); } foreach (Variable v in impl.Proc.OutParams) { Contract.Assert(v != null); exprs.Add(new IdentifierExpr(Token.NoToken, v)); } foreach (IdentifierExpr ie in impl.Proc.Modifies) { Contract.Assert(ie != null); if (ie.Decl == null) continue; exprs.Add(ie); } Expr freePostExpr = new NAryExpr(Token.NoToken, new FunctionCall(function), exprs); impl.Proc.Ensures.Add(new Ensures(Token.NoToken, true, freePostExpr, "", new QKeyValue(Token.NoToken, "si_fcall", new List<object>(), null))); initialized = false; }
// Assumptions: // - Program has no recursion public static HashSet <string> FindLeastToVerify(Program program, HashSet <string> boolVars) { Debug.Assert(program != null); RemoveAsserts(program); if (options.printProg) { BoogieUtil.PrintProgram(program, options.progFileName); } //// ---------- Verify ---------------------------------------------------------------- Debug.Assert(CommandLineOptions.Clo.StratifiedInlining > 0); VC.StratifiedVCGenBase vcgen = null; try { if (options.newStratifiedInlining) { vcgen = new CoreLib.StratifiedInlining(program, CommandLineOptions.Clo.ProverLogFilePath, CommandLineOptions.Clo.ProverLogFileAppend, null); } else { vcgen = new VC.StratifiedVCGen(program, CommandLineOptions.Clo.ProverLogFilePath, CommandLineOptions.Clo.ProverLogFileAppend, new List <Checker>()); } } catch (ProverException) { Log.WriteLine(Log.Error, "ProverException: {0}"); return(new HashSet <string>()); } var mains = program.TopLevelDeclarations .OfType <Implementation>() .Where(impl => QKeyValue.FindBoolAttribute(impl.Attributes, "entrypoint")); if (mains.Count() != 1) { throw new InternalError("Wrong number of entrypoints for FindLeastToverify"); } var main = mains.First(); VC.VCGen.Outcome outcome; //HashSet<string> minVars = new HashSet<string>(); try { var start = DateTime.Now; outcome = vcgen.FindLeastToVerify(main, ref boolVars); var end = DateTime.Now; TimeSpan elapsed = end - start; Log.WriteLine(Log.Debug, string.Format(" [{0} s] ", elapsed.TotalSeconds)); verificationTime += elapsed; if (recordTempTime) { tempTime += elapsed; } } catch (VC.VCGenException e) { throw new InternalError("VCGenException: " + e.Message); //errors = null; //outcome = VC.VCGen.Outcome.Inconclusive; } catch (UnexpectedProverOutputException upo) { throw new InternalError("Unexpected prover output: " + upo.Message); //errors = null; //outcome = VC.VCGen.Outcome.Inconclusive; } switch (outcome) { case VC.VCGen.Outcome.Correct: break; case VC.VCGen.Outcome.Errors: Debug.Assert(false); break; case VC.VCGen.Outcome.ReachedBound: Debug.Assert(false); break; case VC.VCGen.Outcome.Inconclusive: throw new InternalError("z3 says inconclusive"); case VC.VCGen.Outcome.OutOfMemory: throw new InternalError("z3 out of memory"); case VC.VCGen.Outcome.OutOfResource: case VC.VCGen.Outcome.TimedOut: throw new InternalError("z3 timed out"); default: throw new InternalError("z3 unknown response"); } Debug.Assert(outcome == VC.VCGen.Outcome.Correct); vcgen.Close(); CommandLineOptions.Clo.TheProverFactory.Close(); return(boolVars); }