Ejemplo n.º 1
0
        public void ConstPropagationTest()
        {
            var program   = @"
var a, x, c;
input(c);
if c > 5
    x = 10;
else
    input(c);
if c > 5
    x = 20;
a = x;";
            var graph     = GenCFG(program);
            var algorithm = new ConstPropagation();

            algorithm.Execute(graph);
            var iterationsFast = algorithm.Iterations;

            algorithm.Execute(graph, false);
            var iterationsSlow = algorithm.Iterations;

            Assert.LessOrEqual(iterationsFast, iterationsSlow);
        }
Ejemplo n.º 2
0
        public void ConstPropagationIterativeTest()
        {
            var TAC       = GenTAC(@"
var a, x, c;
if c > 5
    x = 10;
else
    input(c);
if c > 5
    a = x;
");
            var cfg       = new ControlFlowGraph(BasicBlockLeader.DivideLeaderToLeader(TAC));
            var constProp = new ConstPropagation();
            var result    = constProp.Execute(cfg);

            var blocks = cfg.GetCurrentBasicBlocks();

            Assert.AreEqual(LatticeTypeData.CONST, result[blocks[6]].Out["x"].Type);
            Assert.AreEqual("10", result[blocks[6]].Out["x"].ConstValue);
            Assert.AreEqual(LatticeTypeData.CONST, result[blocks[6]].Out["a"].Type);
            Assert.AreEqual("10", result[blocks[6]].Out["a"].ConstValue);
            Assert.AreEqual(LatticeTypeData.NAC, result[blocks[6]].Out["c"].Type);
        }
Ejemplo n.º 3
0
        public void ConstPropagationIterativeTest()
        {
            var program   = @"
var a, x, c;
if c > 5
    x = 10;
else
    input(c);
if c > 5
    a = x;
";
            var cfg       = GenCFG(program);
            var constProp = new ConstPropagation();
            var result    = constProp.Execute(cfg);
            var blocks    = cfg.GetCurrentBasicBlocks();
            var actual    = result[blocks.Last()];

            Assert.AreEqual(LatticeTypeData.NAC, actual.Out["c"].Type);
            Assert.AreEqual(LatticeTypeData.CONST, actual.Out["x"].Type);
            Assert.AreEqual(LatticeTypeData.CONST, actual.Out["a"].Type);

            Assert.AreEqual("10", actual.Out["x"].ConstValue);
            Assert.AreEqual("10", actual.Out["a"].ConstValue);
        }