Example #1
0
        public void SpanTreesAddSimpleInterior()
        {
            var trees = new SpanTree <int>[]
            { new SpanTree <int>(Span.FromBounds(2, 4), 1),
              new SpanTree <int>(Span.FromBounds(7, 9), 2),
              new SpanTree <int>(Span.FromBounds(8, 10), 3) };
            var expected = new int[] { 1, -1, 2, 3 };

            var newTrees1 = SpanTree <int> .Add(trees, 100, Span.FromBounds(104, 107), -1);

            AssertExpected(expected, newTrees1);

            var newTrees2 = SpanTree <int> .Add(trees, 100, Span.FromBounds(105, 107), -1);

            AssertExpected(expected, newTrees2);

            var newTrees3 = SpanTree <int> .Add(trees, 100, Span.FromBounds(104, 106), -1);

            AssertExpected(expected, newTrees3);


            var newTrees4 = SpanTree <int> .Add(trees, 100, Span.FromBounds(105, 106), -1);

            AssertExpected(expected, newTrees4);
        }
Example #2
0
        public void SpanTreesAddSimpleContainedByExisting()
        {
            var trees = new SpanTree <int>[]
            { new SpanTree <int>(Span.FromBounds(2, 5), 1),
              new SpanTree <int>(Span.FromBounds(7, 9), 2),
              new SpanTree <int>(Span.FromBounds(8, 10), 3) };
            var expected          = new int[] { 1, 2, 3 };
            var expectedChildren1 = new SpanTree <int>[] { new SpanTree <int>(Span.FromBounds(1, 2), -1) };
            var expectedChildren2 = new SpanTree <int>[] { new SpanTree <int>(Span.FromBounds(1, 3), -1) };
            var expectedChildren3 = new SpanTree <int>[] { new SpanTree <int>(Span.FromBounds(0, 2), -1) };

            var newTrees1 = SpanTree <int> .Add(trees, 100, Span.FromBounds(103, 104), -1);

            AssertExpected(expected, newTrees1);
            AssertExpected(expectedChildren1, newTrees1[0].Children);

            var newTrees2 = SpanTree <int> .Add(trees, 100, Span.FromBounds(103, 105), -1);

            AssertExpected(expected, newTrees2);
            AssertExpected(expectedChildren2, newTrees2[0].Children);

            var newTrees3 = SpanTree <int> .Add(trees, 100, Span.FromBounds(102, 104), -1);

            AssertExpected(expected, newTrees3);
            AssertExpected(expectedChildren3, newTrees3[0].Children);
        }
Example #3
0
        //Конструктор
        public DetectReversibleEdges(ControlFlowGraph.ControlFlowGraph cfg)
        {
            var dom = new DominatorsFinder(cfg);

            dominators = dom.Find();

            var spt = new SpanTree(cfg);

            edges = spt.buildSpanTree();
        }
Example #4
0
        public void SpanTreesAddSimpleLeadingOverlap()
        {
            var trees = new SpanTree <int>[]
            { new SpanTree <int>(Span.FromBounds(2, 4), 1),
              new SpanTree <int>(Span.FromBounds(7, 9), 2) };
            var expected = new int[] { 1, -1, 2 };

            var newTrees = SpanTree <int> .Add(trees, 100, Span.FromBounds(106, 108), -1);

            AssertExpected(expected, newTrees);
        }
Example #5
0
        public void SpanTreesAddSimpleTrailingOverlap()
        {
            var trees = new SpanTree <int>[]
            { new SpanTree <int>(Span.FromBounds(2, 4), 1),
              new SpanTree <int>(Span.FromBounds(7, 9), 2),
              new SpanTree <int>(Span.FromBounds(8, 10), 3) };
            var expected = new int[] { 1, -1, 2, 3 };

            var newTrees = SpanTree <int> .Add(trees, 100, Span.FromBounds(103, 105), -1);

            AssertExpected(expected, newTrees);
        }
Example #6
0
        public void SpanTreesAddSimpleSuffix()
        {
            var trees = new SpanTree <int>[]
            { new SpanTree <int>(Span.FromBounds(2, 4), 1),
              new SpanTree <int>(Span.FromBounds(7, 9), 2),
              new SpanTree <int>(Span.FromBounds(8, 10), 3) };
            var expected = new int[] { 1, 2, 3, -1 };

            var newTrees1 = SpanTree <int> .Add(trees, 100, Span.FromBounds(110, 112), -1);

            AssertExpected(expected, newTrees1);

            var newTrees2 = SpanTree <int> .Add(trees, 100, Span.FromBounds(111, 112), -1);

            AssertExpected(expected, newTrees2);
        }
Example #7
0
        //Конструктор
        public DetectReversibleEdges(ControlFlowGraph.ControlFlowGraph cfg)
        {
            var dom = new DominatorsFinder(cfg);

            dominators = dom.Find();

            var spt = new SpanTree(cfg);

            edges = spt.buildSpanTree();

            foreach (var e in edges)
            {
                isReversible[e] = dominators.Keys.Contains(e.v1.num) &&
                                  dominators[e.v1.num].Contains(e.v2.num);
            }
        }
Example #8
0
        public void SpanTreesAddToLeadingStacked()
        {
            var trees = new SpanTree <int>[]
            { new SpanTree <int>(Span.FromBounds(2, 20), 1),
              new SpanTree <int>(Span.FromBounds(4, 22), 2),
              new SpanTree <int>(Span.FromBounds(6, 24), 3),
              new SpanTree <int>(Span.FromBounds(8, 26), 4) };

            var expected = new int[] { -1, 1, 2, 3, 4 };


            for (int end = 101; (end < 110); ++end)
            {
                var newTrees1 = SpanTree <int> .Add(trees, 100, Span.FromBounds(100, end), -1);

                AssertExpected(expected, newTrees1);
            }
        }
Example #9
0
        public void SpanTreesAddSimpleContainExisting()
        {
            var trees = new SpanTree <int>[]
            { new SpanTree <int>(Span.FromBounds(2, 5), 1),
              new SpanTree <int>(Span.FromBounds(7, 9), 2),
              new SpanTree <int>(Span.FromBounds(8, 10), 3) };
            var expected          = new int[] { -1, 2, 3 };
            var expectedChildren1 = new SpanTree <int>[] { new SpanTree <int>(Span.FromBounds(0, 3), 1) };
            var expectedChildren2 = new SpanTree <int>[] { new SpanTree <int>(Span.FromBounds(0, 3), 1) };
            var expectedChildren3 = new SpanTree <int>[] { new SpanTree <int>(Span.FromBounds(1, 4), 1) };
            var expectedChildren4 = new SpanTree <int>[] { new SpanTree <int>(Span.FromBounds(1, 4), 1) };
            var expectedChildren5 = new SpanTree <int>[] { new SpanTree <int>(Span.FromBounds(2, 5), 1) };

            var newTrees1 = SpanTree <int> .Add(trees, 100, Span.FromBounds(102, 105), -1);

            AssertExpected(expected, newTrees1);
            AssertExpected(expectedChildren1, newTrees1[0].Children);

            var newTrees2 = SpanTree <int> .Add(trees, 100, Span.FromBounds(102, 106), -1);

            AssertExpected(expected, newTrees2);
            AssertExpected(expectedChildren2, newTrees2[0].Children);

            var newTrees3 = SpanTree <int> .Add(trees, 100, Span.FromBounds(101, 105), -1);

            AssertExpected(expected, newTrees3);
            AssertExpected(expectedChildren3, newTrees3[0].Children);

            var newTrees4 = SpanTree <int> .Add(trees, 100, Span.FromBounds(101, 106), -1);

            AssertExpected(expected, newTrees3);
            AssertExpected(expectedChildren4, newTrees4[0].Children);

            var newTrees5 = SpanTree <int> .Add(trees, 100, Span.FromBounds(100, 106), -1);

            AssertExpected(expected, newTrees5);
            AssertExpected(expectedChildren5, newTrees5[0].Children);
            Assert.IsTrue(object.ReferenceEquals(trees[0], newTrees5[0].Children[0]));
        }
Example #10
0
        private void DrawMass(List <LinkedList <SimpleLang.Visitors.ThreeCode> > code, TextBox txt)
        {
            if (radioButton1.Checked)
            {
                SimpleLang.ControlFlowGraph.ControlFlowGraph gra    = new SimpleLang.ControlFlowGraph.ControlFlowGraph(code);
                SimpleLang.Dominators.DominatorsFinder       finder = new SimpleLang.Dominators.DominatorsFinder(gra);
                finder.Find();
                txt.Text = finder.ToString();
            }
            if (radioButton2.Checked)
            {
                SimpleLang.ThreeCodeOptimisations.ReachingDefsAnalysis defs = new SimpleLang.ThreeCodeOptimisations.ReachingDefsAnalysis();
                defs.IterativeAlgorithm(code);
                txt.Text = defs.GetOutput();
            }
            if (radioButton3.Checked)
            {
                var tmp = System.Console.Out;
                System.IO.MemoryStream stre = new System.IO.MemoryStream();
                System.IO.TextWriter   wr   = new System.IO.StreamWriter(stre);
                Console.SetOut(wr);

                SimpleLang.ControlFlowGraph.ControlFlowGraph gra  = new SimpleLang.ControlFlowGraph.ControlFlowGraph(code);
                SimpleLang.DetectReversibleEdges             find = new SimpleLang.DetectReversibleEdges(gra);
                find.PrintIsReverseDic();


                Console.SetOut(tmp);
                wr.Flush();
                stre.Flush();
                string res = Encoding.UTF8.GetString(stre.ToArray());
                txt.Text = res;
            }
            if (radioButton4.Checked)
            {
                var tmp = System.Console.Out;
                System.IO.MemoryStream stre = new System.IO.MemoryStream();
                System.IO.TextWriter   wr   = new System.IO.StreamWriter(stre);
                Console.SetOut(wr);

                SimpleLang.ControlFlowGraph.ControlFlowGraph gra  = new SimpleLang.ControlFlowGraph.ControlFlowGraph(code);
                SimpleLang.DetectReversibleEdges             find = new SimpleLang.DetectReversibleEdges(gra);
                find.PrintisReducible();


                Console.SetOut(tmp);
                wr.Flush();
                stre.Flush();
                string res = Encoding.UTF8.GetString(stre.ToArray());
                txt.Text = res;
            }
            if (radioButton5.Checked)
            {
                SimpleLang.ControlFlowGraph.ControlFlowGraph   gra = new SimpleLang.ControlFlowGraph.ControlFlowGraph(code);
                SimpleLang.ThreeCodeOptimisations.DefUseBlocks def = new SimpleLang.ThreeCodeOptimisations.DefUseBlocks(gra);
                var d1 = def.DefBs;
                var d2 = def.UseBs;

                string res = "";

                if (d1.Count == d2.Count)
                {
                    for (int i = 0; i < d1.Count; i++)
                    {
                        res = res + "----------------------" + Environment.NewLine + "Block " + i.ToString() + Environment.NewLine;
                        var a1 = d1[i];
                        var a2 = d2[i];
                        res = res + "\tDefB:" + Environment.NewLine;
                        foreach (string t in a1)
                        {
                            res = res + "\t\t" + t + Environment.NewLine;
                        }
                        res = res + "\tUseB:" + Environment.NewLine;
                        foreach (string t in a2)
                        {
                            res = res + "\t\t" + t + Environment.NewLine;
                        }
                    }
                }
                txt.Text = res;
            }
            if (radioButton6.Checked)
            {
                var tmp = System.Console.Out;
                System.IO.MemoryStream stre = new System.IO.MemoryStream();
                System.IO.TextWriter   wr   = new System.IO.StreamWriter(stre);
                Console.SetOut(wr);


                SimpleLang.ControlFlowGraph.ControlFlowGraph gra = new SimpleLang.ControlFlowGraph.ControlFlowGraph(code);
                SpanTree span = new SpanTree(gra);
                span.buildSpanTree();
                span.writeAllSpanTreeEdges();
                Console.WriteLine();
                Console.WriteLine("\t\tTypes:");
                span.writeAllEdgesWithTypes();

                Console.SetOut(tmp);
                wr.Flush();
                stre.Flush();
                string res = Encoding.UTF8.GetString(stre.ToArray());
                txt.Text = res;
            }
            if (radioButton7.Checked)
            {
                SimpleLang.ControlFlowGraph.ControlFlowGraph   gra = new SimpleLang.ControlFlowGraph.ControlFlowGraph(code);
                SimpleLang.ThreeCodeOptimisations.DefUseBlocks def = new SimpleLang.ThreeCodeOptimisations.DefUseBlocks(gra);
                var ou = new SimpleLang.ThreeCodeOptimisations.InOutActiveVariables(def, gra);
                List <HashSet <string> > _in  = ou.InBlocks;
                List <HashSet <string> > _out = ou.OutBlocks;
                string res = "";
                for (int i = 0; i < _in.Count; i++)
                {
                    res = res + "----------------------" + Environment.NewLine + "Block " + i.ToString() + Environment.NewLine;
                    res = res + "\tIN:" + Environment.NewLine;
                    foreach (string t in _in[i])
                    {
                        res = res + "\t\t" + t + Environment.NewLine;
                    }
                    res = res + "\tOUT:" + Environment.NewLine;
                    foreach (string t in _out[i])
                    {
                        res = res + "\t\t" + t + Environment.NewLine;
                    }
                }
                txt.Text = res;
            }
        }