Esempio n. 1
0
        public CILProgram Parse(string filename)
        {
            program = new CILProgram();
            fin = new StreamReader(filename);
            string str, s1;
            while(true)
            {
                str = GetNextLine();
                if(str == null)
                    break;

                s1 = str.Substring(0, str.IndexOf(" "));
                switch(s1)
                {
                    case ".assembly":
                        ParseAssembly(str);
                        break;
                    case ".stackreserve":
                        ParseStackReserve(str);
                        break;
                    case ".module":
                        ParseModule(str);
                        break;
                    case ".imagebase":
                        ParseImageBase(str);
                        break;
                    case ".subsystem":
                        ParseSubsystem(str);
                        break;
                    case ".file":
                        ParseFile(str);
                        break;
                    case ".corflags":
                        ParseCorflags(str);
                        break;
                    case ".class":
                        ParseClass(str);
                        break;
                    default:
                        Console.WriteLine("Unknown symbol {0}", s1);
                        break;
                }
            }
            fin.Close();
            return program;
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            //			TestMaxFlow.Test();
            //			return;
            if(args.Length < 1)
            {
                Console.WriteLine("mmchecker test");
                return;
            }

            if(args[0].Equals("maketest"))
            {
                MakeTest(args[1]);
                return;
            }

            CheckerConfiguration.LoadCheckerConfiguration("general.conf");
            CheckerConfiguration.LoadCheckerConfiguration(args);
            OrderingTable.LoadTable(CheckerConfiguration.GetProperty("memorymodel"));

            string programname = CheckerConfiguration.GetProperty("program");
            CILParser Parser = new CILParser();
            program = Parser.Parse(programname + ".il");
            StreamWriter st = new StreamWriter(programname + ".parse");
            st.Write(program.Print());
            st.Close();

            // catch -trace option
            if(CheckerConfiguration.GetNumericProperty("trace") == 1)
            {
                Tracer.GoTrace(program);
                return;
            }

            State st0 = State.MakeInitialState(program);

            Observer ob;

            switch(CheckerConfiguration.GetProperty("observer"))
            {
                case "SimpleObserver":
                    ob = new SimpleObserver();
                    break;
                case "SimpleCumulativeObserver":
                    ob = new SimpleCumulativeObserver();
                    break;
                default:
                    throw new Exception("Unknown observer " + CheckerConfiguration.GetProperty("observer") + " to create");
            }
            st0.AddObserver(ob);

            Random r;
            switch(CheckerConfiguration.GetProperty("search"))
            {
                case "left":
                    while(st0.GetForwardStateCount() > 0)
                    {
                        st0 = st0.Duplicate();
                        st0.Forward(0);
                    }
                    break;
                case "random":
                    r = new Random();
                    while(st0.GetForwardStateCount() > 0)
                    {
                        st0 = st0.Duplicate();
                        st0.Forward(r.Next(st0.GetForwardStateCount()));
                    }
                    break;
                case "repeated_random":
                    r = new Random();
                    while(true)
                    {
                        st0 = State.MakeInitialState(program);
                        st0.AddObserver(ob);
                        while(st0.GetForwardStateCount() > 0)
                        {
                            st0 = st0.Duplicate();
                            st0.Forward(r.Next(st0.GetForwardStateCount()));
                        }
                    }
                case "guided":
                    GuidedSearch(st0);
                    break;
                case "checkoptimality":
                case "co":
                    CheckOptimality(st0);
                    break;
                case "full":
                    Search(st0);
                    break;
                case "maxflow":
                    if(CheckerConfiguration.NumThreads > 1)
                    {
                        FindBarrierMaxflowParallel f = new FindBarrierMaxflowParallel();
                        f.Execute();
                    }else
                        FindBarrierByMaxflow(st0);
                    break;
                default:
                    throw new Exception("Unknown search algorithm " + CheckerConfiguration.GetProperty("search_algorithm"));
            }
            ob.PrintReport();
            Console.WriteLine("Bytecodes: {0}", program.GetInstructionCount());
            Console.WriteLine("State count: {0}", stateSet.Count);
            if(CheckerConfiguration.DoTiming)
            {
                Console.WriteLine("Time used: {0}", Process.GetCurrentProcess().TotalProcessorTime);
                Console.WriteLine("Maxflow time: {0}", maxflowTime);
            }
        }