public static ProverInterface CreateProver(Program prog, string/*?*/ logFilePath, bool appendLogFile, int timeout, int taskID = -1) { Contract.Requires(prog != null); ProverOptions options = cce.NonNull(CommandLineOptions.Clo.TheProverFactory).BlankProverOptions(); if (logFilePath != null) { options.LogFilename = logFilePath; if (appendLogFile) options.AppendLogFile = appendLogFile; } if (timeout > 0) { options.TimeLimit = timeout * 1000; } if (taskID >= 0) { options.Parse(CommandLineOptions.Clo.Cho[taskID].ProverOptions); } else { options.Parse(CommandLineOptions.Clo.ProverOptions); } ProverContext ctx = (ProverContext)CommandLineOptions.Clo.TheProverFactory.NewProverContext(options); // set up the context foreach (Declaration decl in prog.TopLevelDeclarations) { Contract.Assert(decl != null); TypeCtorDecl t = decl as TypeCtorDecl; if (t != null) { ctx.DeclareType(t, null); } } foreach (Declaration decl in prog.TopLevelDeclarations) { Contract.Assert(decl != null); Constant c = decl as Constant; if (c != null) { ctx.DeclareConstant(c, c.Unique, null); } else { Function f = decl as Function; if (f != null) { ctx.DeclareFunction(f, null); } } } foreach (var ax in prog.Axioms) { ctx.AddAxiom(ax, null); } foreach (Declaration decl in prog.TopLevelDeclarations) { Contract.Assert(decl != null); GlobalVariable v = decl as GlobalVariable; if (v != null) { ctx.DeclareGlobalVariable(v, null); } } return (ProverInterface)CommandLineOptions.Clo.TheProverFactory.SpawnProver(options, ctx); }
/// <summary> /// Set up the context. /// </summary> private void Setup(Program prog, ProverContext ctx, Split s = null) { Program = prog; // TODO(wuestholz): Is this lock necessary? lock (Program.TopLevelDeclarations) { var decls = s == null ? prog.TopLevelDeclarations : s.TopLevelDeclarations; foreach (Declaration decl in decls) { Contract.Assert(decl != null); var typeDecl = decl as TypeCtorDecl; var constDecl = decl as Constant; var funDecl = decl as Function; var axiomDecl = decl as Axiom; var glVarDecl = decl as GlobalVariable; if (typeDecl != null) { ctx.DeclareType(typeDecl, null); } else if (constDecl != null) { ctx.DeclareConstant(constDecl, constDecl.Unique, null); } else if (funDecl != null) { ctx.DeclareFunction(funDecl, null); } else if (axiomDecl != null) { ctx.AddAxiom(axiomDecl, null); } else if (glVarDecl != null) { ctx.DeclareGlobalVariable(glVarDecl, null); } } } }
/// <summary> /// Set up the context. /// </summary> private void Setup(Program prog, ProverContext ctx, Implementation impl = null) { Program = prog; // TODO(wuestholz): Is this lock necessary? lock (Program.TopLevelDeclarations) { foreach (Declaration decl in Prune.GetSuccinctDecl(prog, impl)) { Contract.Assert(decl != null); var typeDecl = decl as TypeCtorDecl; var constDecl = decl as Constant; var funDecl = decl as Function; var axiomDecl = decl as Axiom; var glVarDecl = decl as GlobalVariable; if (typeDecl != null) { ctx.DeclareType(typeDecl, null); } else if (constDecl != null) { ctx.DeclareConstant(constDecl, constDecl.Unique, null); } else if (funDecl != null) { ctx.DeclareFunction(funDecl, null); } else if (axiomDecl != null) { ctx.AddAxiom(axiomDecl, null); } else if (glVarDecl != null) { ctx.DeclareGlobalVariable(glVarDecl, null); } } } }
/// <summary> /// Set up the context. /// </summary> private void Setup(Program prog, ProverContext ctx) { Program = prog; lock (Program.TopLevelDeclarations) { foreach (Declaration decl in Program.TopLevelDeclarations) { Contract.Assert(decl != null); var typeDecl = decl as TypeCtorDecl; var constDecl = decl as Constant; var funDecl = decl as Function; var axiomDecl = decl as Axiom; var glVarDecl = decl as GlobalVariable; if (typeDecl != null) { ctx.DeclareType(typeDecl, null); } else if (constDecl != null) { ctx.DeclareConstant(constDecl, constDecl.Unique, null); } else if (funDecl != null) { ctx.DeclareFunction(funDecl, null); } else if (axiomDecl != null) { ctx.AddAxiom(axiomDecl, null); } else if (glVarDecl != null) { ctx.DeclareGlobalVariable(glVarDecl, null); } } } }
/// <summary> /// Set up the context. /// </summary> private void Setup(Program prog, ProverContext ctx) { Program = prog; // TODO(wuestholz): Is this lock necessary? lock (Program.TopLevelDeclarations) { foreach (Declaration decl in Program.TopLevelDeclarations) { Contract.Assert(decl != null); var typeDecl = decl as TypeCtorDecl; var constDecl = decl as Constant; var funDecl = decl as Function; var axiomDecl = decl as Axiom; var glVarDecl = decl as GlobalVariable; if (typeDecl != null) { ctx.DeclareType(typeDecl, null); } else if (constDecl != null) { ctx.DeclareConstant(constDecl, constDecl.Unique, null); } else if (funDecl != null) { ctx.DeclareFunction(funDecl, null); } else if (axiomDecl != null) { ctx.AddAxiom(axiomDecl, null); } else if (glVarDecl != null) { ctx.DeclareGlobalVariable(glVarDecl, null); } } } }
private void AnnotateBlock(Implementation impl, ProverContext ctxt, Block header) { Contract.Assert(header != null); string name = impl.Name + "_" + header.Label + "_invar"; if (annotationInfo.ContainsKey(name)) return; // collect the variables needed in the invariant List<Expr> exprs = new List<Expr>(); List<Variable> vars = new List<Variable>(); List<string> names = new List<string>(); if (style == AnnotationStyle.Flat) { // in flat mode, all live globals should be in live set #if false foreach (Variable v in program.GlobalVariables()) { vars.Add(v); names.Add(v.ToString()); exprs.Add(new IdentifierExpr(Token.NoToken, v)); } #endif foreach (Variable v in /* impl.LocVars */ header.liveVarsBefore) { if (!(v is BoundVariable)) { vars.Add(v); names.Add(v.ToString()); exprs.Add(new IdentifierExpr(Token.NoToken, v)); } } } else { foreach (Variable v in program.GlobalVariables()) { vars.Add(v); names.Add("@old_" + v.ToString()); exprs.Add(new OldExpr(Token.NoToken, new IdentifierExpr(Token.NoToken, v))); } foreach (IdentifierExpr ie in impl.Proc.Modifies) { if (ie.Decl == null) continue; vars.Add(ie.Decl); names.Add(ie.Decl.ToString()); exprs.Add(ie); } foreach (Variable v in impl.Proc.InParams) { Contract.Assert(v != null); vars.Add(v); names.Add("@old_" + v.ToString()); exprs.Add(new OldExpr(Token.NoToken, new IdentifierExpr(Token.NoToken, v))); } foreach (Variable v in impl.LocVars) { vars.Add(v); names.Add(v.ToString()); exprs.Add(new IdentifierExpr(Token.NoToken, v)); } } TypedIdent ti = new TypedIdent(Token.NoToken, "", Microsoft.Boogie.Type.Bool); Contract.Assert(ti != null); Formal returnVar = new Formal(Token.NoToken, ti, false); Contract.Assert(returnVar != null); var function = new Function(Token.NoToken, name, vars, returnVar); ctxt.DeclareFunction(function, ""); Expr invarExpr = new NAryExpr(Token.NoToken, new FunctionCall(function), exprs); var invarAssertion = new AssertCmd(Token.NoToken, invarExpr); List<Cmd> newCmds = new List<Cmd>(); newCmds.Add(invarAssertion); // make a record in annotationInfo; var info = new AnnotationInfo(); info.filename = header.tok.filename; info.lineno = header.Line; info.argnames = names.ToArray(); info.type = AnnotationInfo.AnnotationType.LoopInvariant; annotationInfo.Add(name, info); // get file and line info from havoc, if there is... if (header.Cmds.Count > 0) { PredicateCmd bif = header.Cmds[0] as PredicateCmd; if (bif != null) { string foo = QKeyValue.FindStringAttribute(bif.Attributes, "sourcefile"); if (foo != null) info.filename = foo; int bar = QKeyValue.FindIntAttribute(bif.Attributes, "sourceline", -1); if (bar != -1) info.lineno = bar; } } var thing = header; foreach (Cmd c in header.Cmds) { newCmds.Add(c); } header.Cmds = newCmds; }
public void AnnotateProcEnsures(Procedure proc, Implementation impl, ProverContext ctxt) { Contract.Requires(impl != null); CurrentLocalVariables = impl.LocVars; // collect the variables needed in the invariant List<Expr> exprs = new List<Expr>(); List<Variable> vars = new List<Variable>(); List<string> names = new List<string>(); foreach (Variable v in program.GlobalVariables()) { vars.Add(v); exprs.Add(new OldExpr(Token.NoToken,new IdentifierExpr(Token.NoToken, v))); names.Add(v.Name); } foreach (IdentifierExpr ie in proc.Modifies) { if (ie.Decl == null) continue; vars.Add(ie.Decl); exprs.Add(ie); names.Add(ie.Decl.Name + "_out"); } foreach (Variable v in proc.InParams) { Contract.Assert(v != null); vars.Add(v); exprs.Add(new OldExpr(Token.NoToken, new IdentifierExpr(Token.NoToken, v))); names.Add(v.Name); } foreach (Variable v in proc.OutParams) { Contract.Assert(v != null); vars.Add(v); exprs.Add(new IdentifierExpr(Token.NoToken, v)); names.Add(v.Name); } string name = impl.Name + "_summary"; summaries.Add(name, true); TypedIdent ti = new TypedIdent(Token.NoToken, "", Microsoft.Boogie.Type.Bool); Contract.Assert(ti != null); Formal returnVar = new Formal(Token.NoToken, ti, false); Contract.Assert(returnVar != null); var function = new Function(Token.NoToken, name, vars, returnVar); ctxt.DeclareFunction(function, ""); Expr invarExpr = new NAryExpr(Token.NoToken, new FunctionCall(function), exprs); proc.Ensures.Add(new Ensures(Token.NoToken, false, invarExpr, "", null)); var info = new AnnotationInfo(); info.filename = proc.tok.filename; info.lineno = proc.Line; info.argnames = names.ToArray(); info.type = AnnotationInfo.AnnotationType.ProcedureSummary; annotationInfo.Add(name, info); }
public LazyInliningInfo(Implementation impl, Program program, ProverContext ctxt, int uniqueId, GlobalVariable errorVariable) { Contract.Requires(impl != null); Contract.Requires(program != null); Procedure proc = cce.NonNull(impl.Proc); this.impl = impl; this.uniqueId = uniqueId; this.controlFlowVariable = new LocalVariable(Token.NoToken, new TypedIdent(Token.NoToken, "cfc", Microsoft.Boogie.Type.Int)); impl.LocVars.Add(controlFlowVariable); List<Variable> interfaceVars = new List<Variable>(); Expr assertExpr = new LiteralExpr(Token.NoToken, true); Contract.Assert(assertExpr != null); foreach (Variable v in program.GlobalVariables()) { Contract.Assert(v != null); interfaceVars.Add(v); if (v.Name == "error") inputErrorVariable = v; } // InParams must be obtained from impl and not proc foreach (Variable v in impl.InParams) { Contract.Assert(v != null); interfaceVars.Add(v); } // OutParams must be obtained from impl and not proc foreach (Variable v in impl.OutParams) { Contract.Assert(v != null); Constant c = new Constant(Token.NoToken, new TypedIdent(Token.NoToken, impl.Name + "_" + v.Name, v.TypedIdent.Type)); interfaceVars.Add(c); Expr eqExpr = Expr.Eq(new IdentifierExpr(Token.NoToken, c), new IdentifierExpr(Token.NoToken, v)); assertExpr = Expr.And(assertExpr, eqExpr); } if (errorVariable != null) { proc.Modifies.Add(new IdentifierExpr(Token.NoToken, errorVariable)); } foreach (IdentifierExpr e in proc.Modifies) { Contract.Assert(e != null); if (e.Decl == null) continue; Variable v = e.Decl; Constant c = new Constant(Token.NoToken, new TypedIdent(Token.NoToken, impl.Name + "_" + v.Name, v.TypedIdent.Type)); interfaceVars.Add(c); if (v.Name == "error") { outputErrorVariable = c; continue; } Expr eqExpr = Expr.Eq(new IdentifierExpr(Token.NoToken, c), new IdentifierExpr(Token.NoToken, v)); assertExpr = Expr.And(assertExpr, eqExpr); } this.interfaceVars = interfaceVars; this.assertExpr = Expr.Not(assertExpr); List<Variable> functionInterfaceVars = new List<Variable>(); foreach (Variable v in interfaceVars) { Contract.Assert(v != null); functionInterfaceVars.Add(new Formal(Token.NoToken, new TypedIdent(Token.NoToken, v.Name, v.TypedIdent.Type), true)); } TypedIdent ti = new TypedIdent(Token.NoToken, "", Microsoft.Boogie.Type.Bool); Contract.Assert(ti != null); Formal returnVar = new Formal(Token.NoToken, ti, false); Contract.Assert(returnVar != null); this.function = new Function(Token.NoToken, proc.Name, functionInterfaceVars, returnVar); ctxt.DeclareFunction(this.function, ""); interfaceVarCopies = new List<List<Variable>>(); int temp = 0; for (int i = 0; i < /* CommandLineOptions.Clo.ProcedureCopyBound */ 0; i++) { interfaceVarCopies.Add(new List<Variable>()); foreach (Variable v in interfaceVars) { Constant constant = new Constant(Token.NoToken, new TypedIdent(Token.NoToken, v.Name + temp++, v.TypedIdent.Type)); interfaceVarCopies[i].Add(constant); //program.TopLevelDeclarations.Add(constant); } } }