static void runGenerator() { var filename = ""; var corralflags = flags.Concat(" "); if (mode == MODE.GENERATE_CANDIDATES) { var prog = BoogieUtil.ParseProgram(bplfile); addAtomsToBoogieFile(prog, "train.bpl"); corralflags += " /trainSummaries /runHoudini:2"; filename = "train.bpl"; } else if (mode == MODE.RUN_CANDIDATES) { var prog = BoogieUtil.ParseProgram(bplfile); addPredicatesToBoogieFile(prog, "test.bpl"); filename = "test.bpl"; corralflags += @" /useDuality "; corralflags += " /bopt:z3exe:" + iz3exe + " "; } else if (mode == MODE.GENERATE_ATOMS) { var prog = BoogieUtil.ParseProgram(bplfile); DeleteNonFreeTemplates(prog); BoogieUtil.PrintProgram(prog, "basic.bpl"); filename = "basic.bpl"; corralflags += @" /useDuality /z3opt:Fixedpoint.no_conj=true /z3opt:Fixedpoint.mbqi=false /z3opt:SMT.QI.max_instances=10000 /z3opt:SMT.QI.EAGER_THRESHOLD=10 /bopt:printFixedPoint:fp.bpl /bopt:printConjectures:cp /recursionBound:100 "; corralflags += " /bopt:z3exe:" + iz3exe + " "; } if (debugging) { Console.WriteLine("Running corral with flags: {0}", corralflags); } var corralout = CommonLib.Util.run(Environment.CurrentDirectory, wlimitexe, string.Format("/w {0} {1} {2}", timeout, corralexe, filename + " " + corralflags)); if (mode == MODE.GENERATE_ATOMS) { addAtomsFromDualityOutput(filename); Console.WriteLine("Done"); } else if (mode == MODE.GENERATE_CANDIDATES) { addSummaryPredicate(); Console.WriteLine("Done"); } else { File.WriteAllLines(CommonLib.GlobalConfig.util_result_file, corralout); string output1 = CommonLib.Util.parseOutput(corralout, false); // Run vanilla Corral without Houdini inference string corralFlagsNoHoudini = ""; corralflags.Split(' ').Iter <string>(n => { if (!n.StartsWith("/runHoudini")) { corralFlagsNoHoudini += n + " "; } }); if (debugging) { Console.WriteLine("Running corral with flags: {0}", corralflags); } var corralout2 = CommonLib.Util.run(Environment.CurrentDirectory, wlimitexe, string.Format("/w {0} {1} {2}", timeout, corralexe, filename + " " + corralFlagsNoHoudini)); File.AppendAllLines(CommonLib.GlobalConfig.util_result_file, corralout2); string output2 = CommonLib.Util.parseOutput(corralout2, false); Console.WriteLine("{0} {1}", output1, output2); } }
private static void addAtomsFromDualityOutput(string filename) { var pwd = Environment.CurrentDirectory; var dualityOutputFiles = System.IO.Directory.GetFiles(pwd, "cp.*").ToList(); dualityOutputFiles.RemoveAll(fname => fname == System.IO.Path.Combine(pwd, "cp.tmp")); if (System.IO.File.Exists("fp.bpl")) { dualityOutputFiles.Add("fp.bpl"); } //foreach (var file in dualityOutputFiles) // Console.WriteLine("file: {0}", file); if (!dualityOutputFiles.Any()) { return; } // Get the set of variables with annotation {:environment}. var slicVars = new HashSet <string>(); var testBpl = BoogieUtil.ParseProgram(filename); testBpl.TopLevelDeclarations.OfType <Variable>() .Where(g => QKeyValue.FindBoolAttribute(g.Attributes, "environment")) .Iter(g => slicVars.Add(g.Name)); var outatoms = new HashSet <string>(); var summaries = new AtomDictionary(); foreach (var file in dualityOutputFiles) { // Parse the procedure summary file fp.bpl generated by Duality. var program = BoogieUtil.ParseProgram(file); // Collect atomic propositions that talk about slic variables. var literalVisitor = new LiteralVisitor(); foreach (var proc in program.TopLevelDeclarations.OfType <Procedure>()) { foreach (var ens in proc.Ensures) { literalVisitor.VisitEnsures(ens); } } // Filter literals that talk about SLIC variables only. var literals = new HashSet <Expr>(); foreach (var lit in literalVisitor.literals) { var fv = new VarsInExpr(); fv.VisitExpr(lit); bool allVarsAreSlicVars = true; foreach (var v in fv.Vars) { if (!slicVars.Contains(v)) { allVarsAreSlicVars = false; } } if (allVarsAreSlicVars) { literals.Add(lit); } } // Get pre/post annotation var GetAtomFromLiteral = new Func <Expr, Tuple <string, Expr> >(e => { if (HasNonOldExpr.Process(e)) { return(Tuple.Create("{:post}", e)); } else { return(Tuple.Create("{:pre}", e)); } }); literals.Select(l => GetAtomFromLiteral(l)) .Iter(t => { summaries.Add(t.Item1, t.Item2); outatoms.Add(t.Item1 + " " + t.Item2); }); } var atomDatabasePath = CommonLib.GlobalConfig.util_result_file; Debug.Assert(!System.IO.File.Exists(atomDatabasePath)); TrainerDB.Driver.WriteDB(summaries, atomDatabasePath); if (debugging) { foreach (var atom in outatoms) { Console.WriteLine("Dumped atom: {0}", atom); } Console.WriteLine("Dumped atoms to db."); } }
static void runGenerator() { var filename = ""; var corralflags = flags.Concat(" "); if (mode == MODE.GENERATE_CANDIDATES) { var prog = BoogieUtil.ParseProgram(bplfile); loadTemplates(prog, "train.bpl"); //corralflags += " /trainSummaries /runHoudini:2"; // "trainSummaries" runs AbstractHoudini and generates "candidates.txt" filename = "train.bpl"; // Corral just needs to be run to generate the final bpl file //corralflags += @" /useDuality /z3opt:Fixedpoint.no_conj=true /z3opt:Fixedpoint.mbqi=false /z3opt:SMT.QI.max_instances=10000 /z3opt:SMT.QI.EAGER_THRESHOLD=10 /bopt:printFixedPoint:fp.bpl /bopt:printConjectures:cp /recursionBound:100 "; corralflags += @" /useDuality /z3opt:Fixedpoint.no_conj=true /z3opt:Fixedpoint.mbqi=false /z3opt:SMT.QI.max_instances=10000 /z3opt:SMT.QI.EAGER_THRESHOLD=10 /recursionBound:100 "; //corralflags += @" /useDuality /bopt:printFixedPoint:fp.bpl /bopt:printConjectures:cp /recursionBound:100 "; corralflags += " /bopt:z3exe:" + iz3exe + " "; corralflags += " /printFinalProg:f.bpl "; } else if (mode == MODE.RUN_CANDIDATES) { var prog = BoogieUtil.ParseProgram(bplfile); addPredicatesToBoogieFile(prog, "test0.bpl", "candidates0.db"); addPredicatesToBoogieFile(prog, "test1.bpl", "candidates1.db"); addPredicatesToBoogieFile(prog, "test2.bpl", "candidates2.db"); addPredicatesToBoogieFile(prog, "test3.bpl", "candidates3.db"); //filename = "test.bpl"; filename = null; //corralflags += " /timeLimit:3000 /memLimit:4096 "; } else if (mode == MODE.GENERATE_TEMPLATES) { var prog = BoogieUtil.ParseProgram(bplfile); DeleteNonFreeTemplates(prog); BoogieUtil.PrintProgram(prog, "basic.bpl"); filename = "basic.bpl"; corralflags += @" /useDuality /z3opt:Fixedpoint.no_conj=true /z3opt:Fixedpoint.mbqi=false /z3opt:SMT.QI.max_instances=10000 /z3opt:SMT.QI.EAGER_THRESHOLD=10 /bopt:printFixedPoint:fp.bpl /bopt:printConjectures:cp /recursionBound:100 "; corralflags += " /bopt:z3exe:" + iz3exe + " "; } if (mode == MODE.GENERATE_TEMPLATES) { if (debugging) { Console.WriteLine("Running corral with flags: {0}", corralflags); } var corralout = CommonLib.Util.run(Environment.CurrentDirectory, wlimitexe, string.Format("/w {0} {1} {2}", timeout, corralexe, filename + " " + corralflags)); if (!System.IO.File.Exists("fp.bpl")) { Console.WriteLine("Summary file is not found!"); return; } CommandLineOptions.Clo.ApplyDefaultOptions(); // needed for creating prover CommandLineOptions.Clo.StratifiedInlining = 1; addTemplatesFromDualityOutput(filename); Console.WriteLine("Done"); } else if (mode == MODE.GENERATE_CANDIDATES) { if (debugging) { Console.WriteLine("Running corral with flags: {0}", corralflags); } var corralout = CommonLib.Util.run(Environment.CurrentDirectory, wlimitexe, string.Format("/w {0} {1} {2}", timeout, corralexe, filename + " " + corralflags)); CommandLineOptions.Clo.ApplyDefaultOptions(); // needed for creating prover CommandLineOptions.Clo.StratifiedInlining = 1; addSummaryTemplate("train.bpl"); Console.WriteLine("Done"); } else { File.WriteAllText(CommonLib.GlobalConfig.util_result_file, "Starting Run"); // clear out the file #if false // (1) Run vanilla Corral+SI WITH manual summaries string output1 = runCorral(bplfile, corralflags, false); // (2) Run vanilla Corral+SI WITHOUT manual summaries string corralFlagsNoHoudini = ""; corralflags.Split(' ').Iter <string>(n => { if (!n.StartsWith("/runHoudini")) { corralFlagsNoHoudini += n + " "; } }); string output2 = runCorral(bplfile, corralFlagsNoHoudini, false); // (3) Run vanilla Corral+Duality WITH manual summaries string output3 = runCorral(bplfile, corralflags, true); // (4) Run vanilla Corral+Duality WITHOUT manual summaries string output4 = runCorral(bplfile, corralFlagsNoHoudini, true); #endif string output = ""; if (runCandidatesMode == 0) { // (5) Run Corral+SI WITH predicate summaries output = runCorral("test0.bpl", corralflags, false); } if (runCandidatesMode == 1) { // (6) Run Corral+SI WITH template(Clauses) summaries output = runCorral("test1.bpl", corralflags, false); } if (runCandidatesMode == 2) { // (7) Run Corral+SI WITH template(BoundedTail) summaries output = runCorral("test2.bpl", corralflags, false); } if (runCandidatesMode == 3) { // (8) Run Corral+SI WITH template(FreeTail) summaries output = runCorral("test3.bpl", corralflags, false); } Console.WriteLine("{0}", output); } }