예제 #1
0
파일: Program.cs 프로젝트: nikki161/b8
        static void Main(string[] args)
        {
            string inp  = File.ReadAllText("a.txt");
            var    root = Parser.ParseString(inp);

            // Генерация и получение трёхзначного кода
            var linearCode = new LinearCodeVisitor();

            root?.AcceptVisit(linearCode);
            var code = linearCode.code;


            // Get blocks and print it
            var blocks = LinearToBaseBlock.Build(code);

            foreach (var block in blocks)
            {
                Console.WriteLine(block.ToString());
            }

            // Get graph and made DepthSpanningTree
            var    cfg     = new CFGraph(blocks);
            var    dst     = new DepthSpanningTree(cfg);
            string dst_viz = dst.ToString();

            Console.WriteLine(dst_viz);


            Console.ReadLine();
        }
예제 #2
0
파일: Demos.cs 프로젝트: koyre/b8
        public void DSTTest()
        {
            var root       = Parser.ParseString(Samples.SampleProgramText.sample2);
            var linearCode = new LinearCodeVisitor();

            root.AcceptVisit(linearCode);

            var code   = linearCode.code;
            var blocks = LinearToBaseBlock.Build(code);
            var cfg    = new CFGraph(blocks);
            var dst    = new DepthSpanningTree(cfg);

            cfg.ShowCompact = true;
            Console.WriteLine(cfg.ToString());
            Console.WriteLine(dst.ToString());
        }
예제 #3
0
파일: Program.cs 프로젝트: koyre/b8
        static void Main(string[] args)
        {
            var text = File.ReadAllText("a.txt");
            //text = "n = 0;" +
            //        "if n {" +
            //        "custom_label1:" +
            //        "goto custom_label2;" +
            //        "}" +
            //        "else {" +
            //        "custom_label2:" +
            //        "goto custom_label1;" +
            //        "}";
            var root = Parser.ParseString(text);

            if (root == null)
            {
                Console.WriteLine("Error");
                return;
            }

            // Генерация и получение трёхзначного кода
            var linearCode = new LinearCodeVisitor();

            root.AcceptVisit(linearCode);
            var code = linearCode.code;


            // Get blocks and print it
            var blocks = LinearToBaseBlock.Build(code);

            foreach (var block in blocks)
            {
                Console.WriteLine(block.ToString());
            }

            // Get graph and made DepthSpanningTree
            var cfg = new CFGraph(blocks);

            Console.WriteLine(cfg.ToString());


            var exprsAnalizer = new AvailableExprAnalyzer(cfg);

            exprsAnalizer.analyze();

            var    dst     = new DepthSpanningTree(cfg);
            string dst_viz = dst.ToString();

            Console.WriteLine(dst_viz);

            Console.WriteLine("");

            Console.WriteLine(cfg.EdgeTypes.ToString());


            var f  = cfg.allRetreatingEdgesAreBackwards();
            var r  = cfg.getNaturalCyclesForBackwardEdges();
            var rs = new RegionSequence(cfg);

            Console.ReadLine();
        }