public void ConnectNodes(CFGNode predecessor, CFGNode successor) { successor.Predecessors.Add(predecessor); predecessor.Successors.Add(successor); this.Nodes.Add(predecessor); this.Nodes.Add(successor); }
private static ISet <CFGNode> ComputeDominators(CFGNode node) { var result = new HashSet <CFGNode>(); do { result.Add(node); node = node.ImmediateDominator; }while (node != null); return(result); }
// Tarjan's topological sort recursive algorithm private CFGNode[] ComputeBackwardTopologicalSort() { var result = new CFGNode[this.Nodes.Count]; var visited = new bool[this.Nodes.Count]; var index = this.Nodes.Count - 1; foreach (var node in this.Exits) { BackwardDFS(result, visited, node, ref index); } return(result); }
// Depth First Search algorithm private static void BackwardDFS(CFGNode[] result, bool[] visited, CFGNode node, ref int index) { var alreadyVisited = visited[node.Id]; if (!alreadyVisited) { visited[node.Id] = true; foreach (var pred in node.Predecessors) { BackwardDFS(result, visited, pred, ref index); } node.BackwardIndex = index; result[index] = node; index--; } }
// Depth First Search algorithm private static void ForwardDFS(CFGNode[] result, bool[] visited, CFGNode node, ref int index) { var alreadyVisited = visited[node.Id]; if (!alreadyVisited) { visited[node.Id] = true; foreach (var succ in node.Successors) { ForwardDFS(result, visited, succ, ref index); } node.ForwardIndex = index; result[index] = node; index--; } }
public CFGEdge(CFGNode source, CFGNode target) { this.Source = source; this.Target = target; }
//public IExpression Condition { get; set; } public CFGLoop(CFGNode header) { this.Header = header; this.Body = new HashSet <CFGNode>(); this.Body.Add(header); }