Ejemplo n.º 1
0
 public static void Install(CommandLineOptionsBoomble options)
 {
     Contract.Requires(options != null);
     clo_boomble = options;
 }
Ejemplo n.º 2
0
        static int Main(string[] args)
        {
            Contract.Requires(cce.NonNullElements(args));

            ExecutionEngine.printer = new ConsolePrinter();

            CommandLineOptionsBoomble.Install(new CommandLineOptionsBoomble());
            CommandLineOptions.Install(new CommandLineOptions());

            var boogie_args = CommandLineOptionsBoomble.Clo_Boomble.Parse(args);

            if (boogie_args.Length == 0)
            {
                ExecutionEngine.printer.ErrorWriteLine(Console.Out, "*** Error: No input files were specified.");
                goto END;
            }

            if (!CommandLineOptions.Clo.Parse(boogie_args))
            {
                goto END;
            }

            CommandLineOptions.Clo.RunningBoogieFromCommandLine = true;

            if (CommandLineOptions.Clo.Files.Count == 0)
            {
                ExecutionEngine.printer.ErrorWriteLine(Console.Out, "*** Error: No input files were specified.");
                goto END;
            }

            if (CommandLineOptions.Clo.XmlSink != null)
            {
                string errMsg = CommandLineOptions.Clo.XmlSink.Open();
                if (errMsg != null)
                {
                    ExecutionEngine.printer.ErrorWriteLine(Console.Out, "*** Error: " + errMsg);
                    goto END;
                }
            }

            if (!CommandLineOptions.Clo.DontShowLogo)
            {
                //Console.WriteLine(CommandLineOptions.Clo.Version);
                Console.WriteLine(CommandLineOptionsBoomble.Clo_Boomble.Version);
            }

            if (CommandLineOptions.Clo.ShowEnv == CommandLineOptions.ShowEnvironment.Always)
            {
                Console.WriteLine("---Command arguments");
                foreach (string arg in boogie_args)
                {
                    Contract.Assert(arg != null);
                    Console.WriteLine(arg);
                }

                Console.WriteLine("--------------------");
            }

            Helpers.ExtraTraceInformation("Becoming sentient");

            List <string> fileList = new List <string>();

            foreach (string file in CommandLineOptions.Clo.Files)
            {
                string extension = Path.GetExtension(file);
                if (extension != null)
                {
                    extension = extension.ToLower();
                }

                if (extension == ".txt")
                {
                    StreamReader stream = new StreamReader(file);
                    string       s      = stream.ReadToEnd();
                    fileList.AddRange(s.Split(new char[3] {
                        ' ', '\n', '\r'
                    }, StringSplitOptions.RemoveEmptyEntries));
                }
                else
                {
                    fileList.Add(file);
                }
            }

            foreach (string file in fileList)
            {
                Contract.Assert(file != null);
                string extension = Path.GetExtension(file);
                if (extension != null)
                {
                    extension = extension.ToLower();
                }

                if (extension != ".bpl")
                {
                    ExecutionEngine.printer.ErrorWriteLine(Console.Out,
                                                           "*** Error: '{0}': Filename extension '{1}' is not supported. Input files must be BoogiePL programs (.bpl).",
                                                           file,
                                                           extension == null ? "" : extension);
                    goto END;
                }
            }

            Program program         = ExecutionEngine.ParseBoogieProgram(fileList, false);
            var     tuple           = Shuffler.Get_N_Permutations_of_Program(program, CommandLineOptionsBoomble.Clo_Boomble.N, CommandLineOptionsBoomble.Clo_Boomble.NoMutation);
            var     list_of_program = tuple.Item1.ToList();
            var     list_of_order   = tuple.Item2.ToList();

            var outputpath = Environment.CurrentDirectory + "/results/";

            if (Directory.Exists(outputpath))
            {
                Console.WriteLine("Result folder is not empty!");
                goto END;
            }

            //Directory.Delete(outputpath, true);

            Directory.CreateDirectory(outputpath);

            for (int i = 0; i < list_of_program.Count; i++)
            {
                var file_name = "shuffle" + i + ".bpl";
                ExecutionEngine.PrintBplFile(outputpath + file_name, list_of_program[i], false);
            }

            Console.WriteLine("Shuffles dumped in folder results.");


            return(0);

END:
            if (CommandLineOptions.Clo.XmlSink != null)
            {
                CommandLineOptions.Clo.XmlSink.Close();
            }

            if (CommandLineOptions.Clo.Wait)
            {
                Console.WriteLine("Press Enter to exit.");
                Console.ReadLine();
            }

            return(1);
        }