Ejemplo n.º 1
0
        private static ISet <CFGEdge> IdentifyBackEdges(ControlFlowGraph cfg)
        {
            var back_edges = new HashSet <CFGEdge>();

            foreach (var node in cfg.Nodes)
            {
                foreach (var succ in node.Successors)
                {
                    if (node.Dominators.Contains(succ))
                    {
                        var edge = new CFGEdge(node, succ);
                        back_edges.Add(edge);
                    }
                }
            }

            return(back_edges);
        }
Ejemplo n.º 2
0
        private static CFGLoop IdentifyLoop(CFGEdge back_edge)
        {
            var loop  = new CFGLoop(back_edge.Target);
            var nodes = new Stack <CFGNode>();

            nodes.Push(back_edge.Source);

            do
            {
                var node     = nodes.Pop();
                var new_node = loop.Body.Add(node);

                if (new_node)
                {
                    foreach (var pred in node.Predecessors)
                    {
                        nodes.Push(pred);
                    }
                }
            }while (nodes.Count > 0);

            return(loop);
        }