예제 #1
0
파일: Configs.cs 프로젝트: dongshen/corral
        public static Configs parseCommandLine(string[] args)
        {
            var inputFlags = FlagReader.read(args);

            // Go through flags and find the bpl file and
            // other flags

            string inputFile = null;

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

            foreach (var str in inputFlags)
            {
                if (FlagReader.isFlag(str))
                {
                    flags.Add(str);
                    continue;
                }

                if (str.EndsWith(".bpl"))
                {
                    if (inputFile != null)
                    {
                        throw new UsageError(string.Format("Multiple input files given: {0} and {1}", inputFile, str));
                    }

                    inputFile = str;
                    continue;
                }

                throw new UsageError("Unknown argument: " + str);
            }

            if (inputFile == null)
            {
                throw new UsageError("Input file not given");
            }

            Configs config = new Configs();

            config.inputFile = inputFile;

            foreach (var flag in flags)
            {
                config.parseFlag(flag);
            }

            // Concatenate include files
            if (config.includeFiles.Count != 0)
            {
                var          newfilePrefix = "CorralTmpConcatFile";
                var          newfile       = newfilePrefix + ".bpl";
                StreamWriter w             = null;
                try
                {
                    w = new StreamWriter(newfile);
                }
                catch (Exception e)
                {
                    throw new UsageError(string.Format("Error opening file {0}. {1}", newfile, e.Message));
                }
                config.includeFiles.Add(config.inputFile);
                foreach (var infile in config.includeFiles)
                {
                    StreamReader r = null;
                    try
                    {
                        r = new StreamReader(infile);
                    }
                    catch (Exception e)
                    {
                        throw new UsageError(string.Format("Error opening file {0}. {1}", newfile, e.Message));
                    }
                    w.Write(r.ReadToEnd() + Environment.NewLine);
                    r.Close();
                }
                w.Close();
                config.inputFile = newfile;
            }


            if (config.contextBound <= 0)
            {
                throw new UsageError("Context bound invalid");
            }

            if (config.recursionBound < 1)
            {
                Console.WriteLine("Warning: Using default recursion bound of 1");
                config.recursionBound = 1;
            }

            return(config);
        }
예제 #2
0
 public static void DumpCorralState(Configs config, HashSet <string> CallTree, HashSet <string> Vars)
 {
     DumpCorralState(config.dumpCorralState, CallTree, Vars);
 }