public static void addPredicatesToBoogieFile(Program inprog, string outfile, string candidateFile) { // delete {:template} and {:trainingPredicates} procedure DeleteNonFreeTemplates(inprog); BoogieUtil.PrintProgram(inprog, outfile); #region ZL: read summaries from dababase. //var database = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location), // "candidates.db"); var database = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location), candidateFile); if (!System.IO.File.Exists(database)) { throw new Exception("File does not exist: " + database); } StubAnnotatedSummaryDictionary summaries = null; while (true) { try { using (var fs = new System.IO.FileStream(database, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read)) { var serializer = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); summaries = StubAnnotatedSummaryDictionary.GetDictionary(serializer.Deserialize(fs)); break; } } catch (System.IO.IOException ex) { Thread.Sleep(300); Console.WriteLine("-- {0}: {1}", ex.GetType().Name, ex.ToString()); } } summaries.DeMarshall(z3exe); var numPreds = 0; string s = summaries.DumpPredicates(out numPreds); // TODO: 1. Add "free requires yogi_error == 0; free ensures alloc >= old(alloc);" // 2. Add the two long candidates for irql rules. // 3. Track Mem_T.int4. // 4. Add free ensures and free requires for type state variables. // 5. Add inline depth argument #endregion using (var file = new System.IO.StreamWriter(outfile, true)) { file.WriteLine("procedure {:template} summaryTemplates();"); file.WriteLine(s); if (debugging) { Console.WriteLine("Written summary tempaltes from cubes.db"); } } }
public static void addAtomsToBoogieFile(Program inprog, string outfile) { DeleteNonFreeTemplates(inprog); BoogieUtil.PrintProgram(inprog, outfile); #region ZL: read atoms from atoms.db. var database = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location), "atoms.db"); if (!System.IO.File.Exists(database)) { throw new Exception("File does not exist: " + database); } AtomDictionary summaries = null; while (true) { try { using (var fs = new System.IO.FileStream(database, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read)) { var serializer = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); summaries = serializer.Deserialize(fs) as AtomDictionary; break; } } catch (System.IO.IOException ex) { Thread.Sleep(300); Console.WriteLine("-- {0}: {1}", ex.GetType().Name, ex.ToString()); } } var numPreds = 0; string s = @"procedure {:trainingPredicates} summaryTrainingtemplate();"; //string s = @"procedure {:XXX} YYY();"; s += summaries.DumpPredicates(out numPreds); #endregion // Add procedure summaryTrainingtemplate() by reading summary.db. using (var file = new System.IO.StreamWriter(outfile, true)) { file.WriteLine(s); if (debugging) { Console.WriteLine("Read atoms from atoms.db"); } } }
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); } }
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); } }