Ejemplo n.º 1
0
 public void ConnectNodes(CFGNode predecessor, CFGNode successor)
 {
     successor.Predecessors.Add(predecessor);
     predecessor.Successors.Add(successor);
     this.Nodes.Add(predecessor);
     this.Nodes.Add(successor);
 }
Ejemplo n.º 2
0
        private static ISet <CFGNode> ComputeDominators(CFGNode node)
        {
            var result = new HashSet <CFGNode>();

            do
            {
                result.Add(node);
                node = node.ImmediateDominator;
            }while (node != null);

            return(result);
        }
Ejemplo n.º 3
0
        // Tarjan's topological sort recursive algorithm
        private CFGNode[] ComputeBackwardTopologicalSort()
        {
            var result  = new CFGNode[this.Nodes.Count];
            var visited = new bool[this.Nodes.Count];
            var index   = this.Nodes.Count - 1;

            foreach (var node in this.Exits)
            {
                BackwardDFS(result, visited, node, ref index);
            }

            return(result);
        }
Ejemplo n.º 4
0
        // Depth First Search algorithm
        private static void BackwardDFS(CFGNode[] result, bool[] visited, CFGNode node, ref int index)
        {
            var alreadyVisited = visited[node.Id];

            if (!alreadyVisited)
            {
                visited[node.Id] = true;

                foreach (var pred in node.Predecessors)
                {
                    BackwardDFS(result, visited, pred, ref index);
                }

                node.BackwardIndex = index;
                result[index]      = node;
                index--;
            }
        }
Ejemplo n.º 5
0
        // Depth First Search algorithm
        private static void ForwardDFS(CFGNode[] result, bool[] visited, CFGNode node, ref int index)
        {
            var alreadyVisited = visited[node.Id];

            if (!alreadyVisited)
            {
                visited[node.Id] = true;

                foreach (var succ in node.Successors)
                {
                    ForwardDFS(result, visited, succ, ref index);
                }

                node.ForwardIndex = index;
                result[index]     = node;
                index--;
            }
        }
Ejemplo n.º 6
0
 public CFGEdge(CFGNode source, CFGNode target)
 {
     this.Source = source;
     this.Target = target;
 }
Ejemplo n.º 7
0
        //public IExpression Condition { get; set; }

        public CFGLoop(CFGNode header)
        {
            this.Header = header;
            this.Body   = new HashSet <CFGNode>();
            this.Body.Add(header);
        }