public static NumeratedGraph StraightOrder(this TACode code) { var graph = new NumeratedGraph(code, null); graph.Numerator = GraphNumerator.BackOrder(graph).Reverse(graph); return(graph); }
public static GraphNumerator BackOrder(ControlFlowGraph graph) { var root = graph.CFGNodes.ElementAt(0); var num = new GraphNumerator(); var index = graph.CFGNodes.Count; var openSet = new HashSet <BasicBlock>(); void Iter(BasicBlock node) { openSet.Add(node); var children = node.Children; foreach (var c in children.Where(x => !openSet.Contains(x))) { Iter(c); } num._num[node] = --index; } Iter(root); return(num); }
public static IGraphNumerator Reverse(this GraphNumerator n, ControlFlowGraph g) => new ReverseNum(g, n);