private static void ConnectControlFlow(CFGNode from, CFGNode to) { Debug.Assert(from != null); Debug.Assert(to != null); to.Entries.Add(from); from.Exits.Add(to); }
private CFGNode CreateControlFlow(CFGNode entry, ASTNode astNode) { CFGNode temp = currentNode; currentNode = entry; AppendControlFlow(astNode); CFGNode exit = currentNode; currentNode = temp; return(exit); }
private List <CFGNode> SplitControlFlow(int num) { Debug.Assert(num > 0, $"Invalid split number: {num}"); List <CFGNode> nodes = new List <CFGNode>(); for (int i = 0; i < num; ++i) { CFGNode node = factory.MakeNode(); nodes.Add(node); ConnectControlFlow(currentNode, node); } // set to null because we don't know what is the current node at this point currentNode = null; return(nodes); }
private void MergeControlFlow(List <CFGNode> nodes, CFGNode destination = null) { Debug.Assert(nodes.Count > 1, $"Invalid merge number: {nodes.Count}"); if (destination == null) { destination = factory.MakeNode(); } foreach (CFGNode node in nodes) { if (node != destination) { ConnectControlFlow(node, destination); } } currentNode = destination; }
private static void PrintCFG(CFGNode root) { HashSet <CFGNode> visited = new HashSet <CFGNode>(); Queue <CFGNode> queue = new Queue <CFGNode>(); queue.Enqueue(root); while (queue.Count != 0) { CFGNode node = queue.Dequeue(); if (!visited.Contains(node)) { visited.Add(node); Console.WriteLine(node); foreach (CFGNode exit in node.Exits) { queue.Enqueue(exit); } } } }
private CFGBuilder(CFGNodeFactory factory, FunctionCFG currentCFG) { this.factory = factory; this.currentCFG = currentCFG; this.currentNode = currentCFG.Entry; }
public FunctionCFG() { Entry = null; Exit = null; }