public void DominatorTree() { var program = @" var a; input(a); 1: if a == 0 goto 2; if a == 1 goto 2; a = 2; 2: a = 3; "; var graph = GenCFG(program); var algorithm = new DominatorTree(); _ = algorithm.Execute(graph); var iterationsFast = algorithm.Iterations; _ = algorithm.Execute(graph, false); var iterationsSlow = algorithm.Iterations; Assert.LessOrEqual(iterationsFast, iterationsSlow); }
private void TestInternal(ControlFlowGraph graph, DominatorDictionary expectedDoms, ParentsDictionary expectedParents, ChildrenDictionary expectedChildren) { var dt = new DominatorTree(); var dominators = dt.GetDominators(graph); var tree = dt.Execute(graph); var blocks = graph.GetCurrentBasicBlocks(); Assert.AreEqual(blocks.Count, dominators.Count(), "Dominators count and blocks count are different"); for (var i = 0; i < blocks.Count(); ++i) { CollectionAssert.AreEquivalent(expectedDoms[i], dominators[blocks[i]], $"Check dominators: error for block #{i}"); } for (var i = 0; i < blocks.Count(); ++i) { Assert.AreEqual(expectedParents[i], tree.Parent(blocks[i]), $"Check parents: error for block #{i}"); CollectionAssert.AreEquivalent(expectedChildren[i], tree.Children(blocks[i]), $"Check children: error for block #{i}"); } }