Exemple #1
0
        private DerivedGraph BuildNextOrderGraph(DerivedGraph gr)
        {
            DirectedGraph <StructureNode> newGraph = new DirectedGraphImpl <StructureNode>();
            StructureNode newEntry = gr.Intervals[0];

            foreach (Interval interval in gr.Intervals)
            {
                newGraph.Nodes.Add(interval);
            }

            foreach (Interval interval in gr.Intervals)
            {
                foreach (StructureNode node in interval.Nodes)
                {
                    foreach (StructureNode succ in gr.Graph.Successors(node))
                    {
                        if (succ.Interval != interval && !newGraph.ContainsEdge(interval, succ.Interval))
                        {
                            newGraph.AddEdge(interval, succ.Interval);
                        }
                    }
                }
            }
            return(new DerivedGraph(newGraph, newEntry, ib.BuildIntervals(newGraph, newEntry)));
        }
Exemple #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);
            }
        }
Exemple #3
0
        public DerivedSequenceBuilder(ProcedureStructure proc)
        {
            this.graphs = proc.DerivedGraphs;
            this.ib     = new IntervalBuilder();
            var gr = BuildDerivedGraph(proc.Nodes, proc.EntryNode);

            graphs.Add(gr);
            while (gr.Graph.Nodes.Count > 1)
            {
                DerivedGraph newGr = BuildNextOrderGraph(gr);
                if (newGr.Graph.Nodes.Count == gr.Graph.Nodes.Count)
                {
                    return;
                }
                graphs.Add(newGr);
                gr = newGr;
            }
        }
Exemple #4
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);
            }
        }