Пример #1
0
 private static void ConnectControlFlow(CFGNode from, CFGNode to)
 {
     Debug.Assert(from != null);
     Debug.Assert(to != null);
     to.Entries.Add(from);
     from.Exits.Add(to);
 }
Пример #2
0
        private CFGNode CreateControlFlow(CFGNode entry, ASTNode astNode)
        {
            CFGNode temp = currentNode;

            currentNode = entry;
            AppendControlFlow(astNode);
            CFGNode exit = currentNode;

            currentNode = temp;
            return(exit);
        }
Пример #3
0
        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);
        }
Пример #4
0
 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;
 }
Пример #5
0
        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);
                    }
                }
            }
        }
Пример #6
0
 private CFGBuilder(CFGNodeFactory factory, FunctionCFG currentCFG)
 {
     this.factory     = factory;
     this.currentCFG  = currentCFG;
     this.currentNode = currentCFG.Entry;
 }
Пример #7
0
 public FunctionCFG()
 {
     Entry = null;
     Exit  = null;
 }