Exemplo n.º 1
0
        private static void addTemplatesFromDualityOutput(string filename)
        {
            var pwd = Environment.CurrentDirectory;
            var dualityOutputFiles = new List <string>();

            //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");
            }

            Contract.Assert(dualityOutputFiles.Count == 1);

            // create Rule database
            EnvironmentalSummaries envSummaries = new EnvironmentalSummaries(new List <string> {
                filename
            }, dualityOutputFiles[0], false);                                                                                              // TODO: Later set to FALSE

            //envSummaries.EmitBplWithSummaries(EnvironmentalSummaries.InsertedSummaryType.LearntTemplates, "EnvVarsPredAbsInductiveTemplates.bpl");
            envSummaries.CreateRuleTemplateDB(EnvironmentalSummaries.InsertedSummaryType.LearntTemplates);

            // Store to file
            TemplateDictionarySerializable tds = new TemplateDictionarySerializable();

            tds.LoadFromDB();
            var atomDatabasePath = CommonLib.GlobalConfig.util_result_file;

            if (System.IO.File.Exists(atomDatabasePath))
            {
                Console.WriteLine("{0} is already present. Aborting!", atomDatabasePath);
                Debug.Assert(!System.IO.File.Exists(atomDatabasePath));
            }
            TemplateDictionarySerializable.WriteTemplateDictionary(tds, atomDatabasePath);
        }
Exemplo n.º 2
0
        private static void addSummaryTemplate(string inferFile)
        {
            EnvironmentalSummaries envSummaries = new EnvironmentalSummaries(new List <string>(), null, true);

            envSummaries.RunAbstractHoudini();  // generates the file "corralPredicates.txt"

            if (!System.IO.File.Exists("corralPredicates.txt"))
            {
                return;
            }

            // stubs is always [] in the current version.
            var predWithStubs = new HashSet <Tuple <string, string> >();

            using (var file = new System.IO.StreamReader("corralPredicates.txt"))
            {
                string pred;
                string stubs = "";
                while ((pred = file.ReadLine()) != null)
                {
                    if (useStubs)
                    {
                        stubs = file.ReadLine();
                        if (stubs == "[]")
                        {
                            stubs = "";
                        }
                        else
                        {
                            stubs = string.Format("{{:stubs \"{0}\"}}", stubs);
                        }
                    }
                    predWithStubs.Add(Tuple.Create(stubs, pred));
                }
            }

            string database = CommonLib.GlobalConfig.util_result_file;

            Debug.Assert(!System.IO.File.Exists(database));
            var summaries = new StubAnnotatedSummaryDictionary();

            StubAnnotatedSummaryDictionary.CreateProver(z3exe);
            if (useStubs)
            {
                predWithStubs.Iter(tup => summaries.Add(tup.Item1, tup.Item2));
            }
            else
            {
                predWithStubs.Iter(tup => summaries.Add("", tup.Item2));
            }
            //predicates.Iter(pred => summaries.Add(property, pred));
            //summaries.Print(databaseTxt);
            StubAnnotatedSummaryDictionary.CloseProver();
            summaries.Marshall();

            while (true)
            {
                try
                {
                    using (var fs = new System.IO.FileStream(database, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.None))
                    {
                        var serializer = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                        serializer.Serialize(fs, summaries);
                        break;
                    }
                }
                catch (System.IO.IOException)
                {
                    Random rnd = new Random();
                    Thread.Sleep(rnd.Next(300, 501));
                }
            }
            if (debugging)
            {
                Console.WriteLine("Dumped summaries to db.");
            }
        }