Beispiel #1
0
        public static TemplateDictionarySerializable Merge(IEnumerable <TemplateDictionarySerializable> atoms)
        {
            var ret = new HashSet <RuleAsString>();

            atoms.Iter(atom => ret.UnionWith(atom.table));
            var merged = new TemplateDictionarySerializable();

            merged.table.AddRange(ret);
            return(merged);
        }
Beispiel #2
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);
        }
Beispiel #3
0
        public static void loadTemplates(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);
            }

            TemplateDictionarySerializable 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 TemplateDictionarySerializable;
                        break;
                    }
                }
                catch (System.IO.IOException ex)
                {
                    Thread.Sleep(300);
                    Console.WriteLine("-- {0}: {1}", ex.GetType().Name, ex.ToString());
                }
            }


            #endregion

            // Load out database from the deserialized object
            summaries.DumpToDB();


#if false
            var numPreds = 0;

            string s = @"procedure {:trainingPredicates} summaryTrainingtemplate();";
            //string s = @"procedure {:XXX} YYY();";
            s += summaries.DumpPredicates(out numPreds);


            // 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");
                }
            }
#endif
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Usage: generator file.[c|bpl]");
                return;
            }

            for (int i = 0; i < args.Count(); i++)
            {
                ProcessArg(args[i]);
            }

            var files = CommonLib.Util.GetFilesForUnion(args);

            if (files != null)
            {
                if (mode == MODE.GENERATE_TEMPLATES)
                {
                    // merge atoms.db
                    var dbs = new List <TemplateDictionarySerializable>();
                    files.Iter(f => dbs.Add(TemplateDictionarySerializable.ReadTemplateDictionary(f)));
                    TemplateDictionarySerializable.WriteTemplateDictionary(
                        TemplateDictionarySerializable.Merge(dbs), CommonLib.GlobalConfig.util_result_file);
                }
                else if (mode == MODE.GENERATE_CANDIDATES)
                {
                    // merge candidates db
                    var dbs = new List <StubAnnotatedSummaryDictionary>();
                    files.Iter(f => dbs.Add(TrainerDB.Driver.ReadCandidateDB(f)));
                    TrainerDB.Driver.WriteDB(
                        StubAnnotatedSummaryDictionary.Merge(dbs), CommonLib.GlobalConfig.util_result_file);
                }
                else
                {
                    // merge corral output
                    var cat = new List <string>();
                    foreach (var file in files)
                    {
                        cat.AddRange(System.IO.File.ReadAllLines(file));
                        cat.Add("=========");
                    }
                    System.IO.File.WriteAllLines(CommonLib.GlobalConfig.util_result_file, cat);
                }

                return;
            }

            try
            {
                // Set up Boogie
                CommandLineOptions.Install(new CommandLineOptions());
                CommandLineOptions.Clo.PrintInstrumented = true;

                // Set up corral, duality
                var root = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
                wlimitexe = Path.Combine(root, "wlimit.exe");
                corralexe = Path.Combine(root, "..", "corral", "corral.exe");
                z3exe     = Path.Combine(root, "..", "corral", "z3.exe");
                iz3exe    = Path.Combine(root, "..", "iz3", "z3.exe");
                CommandLineOptions.Clo.Z3ExecutablePath = z3exe;

                runGenerator();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }