Пример #1
0
        public void CreateWithCfgNode()
        {
            StructureNode node = CreateNode("foo", 1);
            Interval i = new Interval(1, node);
//            Assert.AreSame(node, i.Header);
            Assert.AreEqual(1, i.Nodes.Count);
        }
Пример #2
0
        public void BuildIntervals(DerivedGraph derGraph)
        {
            if (derGraph == null)
                throw new ArgumentNullException("derGraph");
            if (derGraph.Entry == null)
                throw new ArgumentException("cfg graph must be non-null.", "derGraph");

            var intSeq = derGraph.Intervals;	// The sequence of intervals in this graph
            var headerSeq = new WorkList<StructureNode>();	// The sequence of interval header nodes
            var beenInH = new List<StructureNode>();	// The set of nodes that have been in the above sequence at some stage

            headerSeq.Add(derGraph.Entry);

            beenInH.Add(derGraph.Entry);

            StructureNode header;
            while (headerSeq.GetWorkItem(out header))
            {
                var newInt = new Interval(intervalID++, header);

                // Process each succesive node in the interval until no more nodes can be added to the interval.
                for (int i = 0; i < newInt.Nodes.Count; i++)
                {
                    var curNode = newInt.Nodes[i];

                    // Process each child of the current node
                    for (int j = 0; j < curNode.OutEdges.Count; j++)
                    {
                        var succ = curNode.OutEdges[j];

                        // Only further consider the current child if it isn't already in the interval
                        if (!newInt.Nodes.Contains(succ))
                        {
                            // If the current child has all its parents
                            // inside the interval, then add it to the interval. Remove it from the header
                            // sequence if it is on it.
                            if (IsSubSetOf(succ.InEdges, newInt))
                            {
                                newInt.AddNode(succ);
                                headerSeq.Remove(succ);
                            }

                            // Otherwise, add it to the header sequence if it hasn't already been in it.
                            else if (!beenInH.Contains(succ))
                            {
                                headerSeq.Add(succ);
                                beenInH.Add(succ);
                            }
                        }
                    }
                }

                // Add the new interval to the sequence of intervals
                intSeq.Add(newInt);
            }
        }
Пример #3
0
        public void CreateWithIntervalNode()
        {
            StructureNode node1 = CreateNode("node1", 1);
            StructureNode node2 = CreateNode("node2", 2);
            Interval i1 = new Interval(1, node1);
            Interval i2 = new Interval(2, node2);
            StructureNode node3 = CreateNode("node3", 3);
            i2.AddNode(node3);

            Interval i = new Interval(3, i1);
            i.AddNode(i2);
            Assert.AreEqual(2, i.Nodes.Count);
        }
Пример #4
0
        public void FindNoLoopInInterval()
        {
            ProcedureBuilder m = new ProcedureBuilder();
            m.Return();

            StructureNode node = new StructureNode(m.Procedure.ControlGraph.Blocks[1], 3);
            node.Order = 0;
            Interval interval = new Interval(1, node);

            var nodesInInterval = interval.FindIntervalNodes(0);
            SccLoopFinder finder = new SccLoopFinder(interval, nodesInInterval);
            var loopNodes = finder.FindLoop();
            Assert.AreEqual(0, loopNodes.Count);
        }
Пример #5
0
        public List<Interval> BuildIntervals(DirectedGraph<StructureNode> graph, StructureNode entry)
        {
            if (graph == null)
                throw new ArgumentNullException("graph");
            if (entry == null)
                throw new ArgumentNullException("entry");

            var intervalsInGraph = new List<Interval>();	// The sequence of intervals in this graph
            var headers = new WorkList<StructureNode>();	// The sequence of interval header nodes
            var beenInH = new HashSet<StructureNode>();	    // The set of nodes that have been in the above sequence at some stage

            headers.Add(entry);
            beenInH.Add(entry);

            StructureNode header;
            while (headers.GetWorkItem(out header))
            {
                Interval newInt = new Interval(intervalID++, header);

                // Process each succesive node in the interval until no more nodes can be added to the interval.
                for (int i = 0; i < newInt.Nodes.Count; i++)
                {
                    StructureNode curNode = newInt.Nodes[i];

                    foreach (StructureNode succ in graph.Successors(curNode))
                    {
                        // Only further consider the current child if it isn't already in the interval
                        if (!newInt.Nodes.Contains(succ))
                        {
                            // If the current child has all its parents
                            // inside the interval, then add it to the interval. Remove it from the header
                            // sequence if it is on it.
                            if (IsSubSetOf(graph.Predecessors(succ), newInt))
                            {
                                newInt.AddNode(succ);
                                headers.Remove(succ);
                            }

                            // Otherwise, add it to the header sequence if it hasn't already been in it.
                            else if (!beenInH.Contains(succ))
                            {
                                headers.Add(succ);
                                beenInH.Add(succ);
                            }
                        }
                    }
                }

                // Add the new interval to the sequence of intervals
                intervalsInGraph.Add(newInt);
            }
            return intervalsInGraph;
        }
Пример #6
0
 private bool IsSubSetOf(IEnumerable<StructureNode> inEdges, Interval newInt)
 {
     foreach (StructureNode inEdge in inEdges)
         if (inEdge.Interval != newInt)
             return false;
     return true;
 }
Пример #7
0
 private StructureNode IntervalHeaderNode(Interval interval)
 {
     var headNode = interval.Header as Interval;
     while (headNode != null)
     {
         interval = headNode;
         headNode = interval.Header as Interval;
     }
     return interval.Header;
 }
Пример #8
0
 private SccLoopFinder CreateSccLoopFinder(ProcedureStructure proc, Interval intNode, int graphLevel)
 {
     var nodesInInterval = intNode.FindIntervalNodes(graphLevel);
     return new SccLoopFinder(intNode, nodesInInterval);
 }