Example #1
0
File: Demos.cs Project: koyre/b8
        public void CFGraphTest()
        {
            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);

            Console.WriteLine(cfg.ToString());
        }
Example #2
0
File: Demos.cs Project: koyre/b8
        public void SsaConstructionTest()
        {
            var root   = Parser.ParseString(Samples.SampleProgramText.ssaoptimizationSample2);
            var code   = ProgramTreeToLinear.Build(root);
            var blocks = LinearToBaseBlock.Build(code);
            var cfg    = new CFGraph(blocks);

            Console.WriteLine("###--------- Input CF Graph ---------###");
            Console.WriteLine(cfg.ToString());
            SsaConstruction ssa = new SsaConstruction(cfg);

            Console.WriteLine("###--------- Output SSA Graph ---------###");
            Console.WriteLine(ssa.SsaForm.ToString());
        }
Example #3
0
File: Demos.cs Project: 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());
        }
Example #4
0
File: Demos.cs Project: koyre/b8
        public void SsaCopyPropagationTest()
        {
            var root   = Parser.ParseString(Samples.SampleProgramText.ssaoptimizationSample3);
            var code   = ProgramTreeToLinear.Build(root);
            var blocks = LinearToBaseBlock.Build(code);
            var cfg    = new CFGraph(blocks);

            Console.WriteLine("###--------- Input CF Graph ---------###");
            Console.WriteLine(cfg.ToString());
            SsaConstruction ssa      = new SsaConstruction(cfg);
            CFGraph         ssaGraph = ssa.SsaForm;

            Console.WriteLine("###--------- Constructed SSA Graph ---------###");
            Console.WriteLine(ssaGraph.ToString());

            SsaCopyPropagation ssaCopyPropagation = new SsaCopyPropagation(ssaGraph);

            ssaCopyPropagation.Launch();
            Console.WriteLine("###--------- Output SSA Graph after copy propagation ---------###");
            Console.WriteLine(ssaCopyPropagation.OptimizedSsaGraph);
        }
Example #5
0
File: Program.cs Project: 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();
        }