Example #1
0
 public CFGEdge AddEdge(CFGNode source, CFGNode target, BranchConditionType conditionType)
 {
     return AddEdge(source, target, new BranchCondition(conditionType));
 }
Example #2
0
 public CFGEdge AddEdge(CFGNodeCluster sourceCluster, CFGNode target)
 {
     return AddEdge(sourceCluster.End, target);
 }
Example #3
0
 public CFGEdge AddEdge(CFGNode source, CFGNode target)
 {
     return (CFGEdge)base.AddEdge(source, target);
 }
Example #4
0
 public CFGEdge AddEdge(CFGNode source, CFGNodeCluster targetCluster, BranchConditionType conditionType)
 {
     return AddEdge(source, targetCluster.Start, conditionType);
 }
Example #5
0
 public CFGEdge AddEdge(CFGNode source, CFGNodeCluster targetCluster)
 {
     return AddEdge(source, targetCluster.Start);
 }
Example #6
0
        public virtual bool Match(CFGNode node, CFGPatternMatchFlags flags)
        {
            CFGPatternMatchFlags currentFlags = SpecialFlags == null ? SpecialFlags.Value : flags;
            if (FlowControl != null)
            {
                if (FlowControl.Value != node.FlowControl)
                {
                    return false;
                }
            }
            foreach (Predicate<CFGNode> predicate in Predicates)
            {
                if (!predicate(node))
                {
                    return false;
                }
            }
            if ((currentFlags & CFGPatternMatchFlags.PerfectMatch) > 0)
            {

                if (Pattern.OutDegree(this) != node.Graph.OutDegree(node))
                {
                    return false;
                }
            }

            // find a match for each edge
            List<CFGPatternEdge> patternEdges = new List<CFGPatternEdge>();
            foreach (QuickGraph.Concepts.IEdge edge in this.Pattern.OutEdges(this))
            {
                patternEdges.Add((CFGPatternEdge)edge);
            }
            List<CFGEdge> edges = new List<CFGEdge>();
            foreach (QuickGraph.Concepts.IEdge edge in node.Graph.OutEdges(node))
            {
                edges.Add((CFGEdge)edge);
            }
            while (patternEdges.Count > 0)
            {
                foreach (CFGPatternEdge patternEdge in patternEdges)
                {
                    bool foundMatch = false;
                    foreach (CFGEdge edge in edges)
                    {
                        if (patternEdge.Match(edge, flags))
                        {
                            foundMatch = true;
                            patternEdges.Remove(patternEdge);
                            edges.Remove(edge);
                            break;
                        }
                    }
                    if (!foundMatch)
                    {
                        return false;
                    }
                }
            }

            return true;
        }
Example #7
0
 public CFGNodeCluster(CFGNodeCluster start, CFGNodeCluster end)
 {
     _start = start.Start;
     _end = end.End;
 }
Example #8
0
 public CFGEdge(int id, CFGNode from, CFGNode to)
     : base(id, from, to)
 {
 }
Example #9
0
 public CFGEdge AddEdge(CFGNodeCluster sourceCluster, CFGNode target, BranchConditionType conditionType)
 {
     return AddEdge(sourceCluster.End, target, conditionType);
 }
Example #10
0
 public CFGNode[] Successors(CFGNode node)
 {
     List<CFGNode> nodes = new List<CFGNode>();
     EdgeCollection edges = this.OutEdges(node);
     foreach (IEdge edge in edges)
     {
         CFGNode targetNode = (CFGNode)edge.Target;
         if (!nodes.Contains(targetNode))
         {
             nodes.Add(targetNode);
         }
     }
     return nodes.ToArray();
 }
Example #11
0
 public InEdgePredicate(CFGNode target)
 {
     Target = target;
 }
Example #12
0
 public CFGNode[] Predecessors(CFGNode node)
 {
     List<CFGNode> nodes = new List<CFGNode>();
     EdgeCollection edges = InEdges(node);
     foreach (IEdge edge in edges)
     {
         CFGNode sourceNode = (CFGNode)edge.Source;
         if (!nodes.Contains(sourceNode))
         {
             nodes.Add(sourceNode);
         }
     }
     return nodes.ToArray();
 }
Example #13
0
        public void InsertAfter(CFGNode node, CFGNode insertAfterMe)
        {
            // all out edges of insertAfterMe become out edges of node
            List<CFGEdge> edgesToRemove = new List<CFGEdge>();
            foreach (CFGEdge outEdge in OutEdges(insertAfterMe))
            {
                AddEdge(node, outEdge.Target, outEdge.BranchCondition);
                edgesToRemove.Add(outEdge);
            }
            foreach (CFGEdge edgeToRemove in edgesToRemove)
            {
                RemoveEdge(edgeToRemove);
            }

            // now add an edge from insertAfterme to node
            AddEdge(insertAfterMe, node, BranchConditionType.Unconditional);
        }
Example #14
0
 // TODO: Cache data in CFG (cache is cleared when an edge or node is added or removed)
 public EdgeCollection InEdges(CFGNode node)
 {
     FilteredEdgeEnumerable edges = this.SelectEdges(new InEdgePredicate(node));
     return new EdgeCollection(edges);
 }
Example #15
0
 public CFGEdge AddEdge(CFGNode source, CFGNode target, BranchCondition condition)
 {
     CFGEdge edge = (CFGEdge)base.AddEdge(source, target);
     edge.BranchCondition = condition;
     return edge;
 }
Example #16
0
 public CFGNodeCluster(CFGNode start, CFGNode end)
 {
     _start = start;
     _end = end;
 }
Example #17
0
 public CFGNode AddNode()
 {
     CFGNode newNode = (CFGNode)base.AddVertex();
     if (_root == null)
     {
         _root = newNode;
     }
     return newNode;
 }
Example #18
0
 // TODO: Move ReplaceRoot into BasicMiddleEnd - MethodCompileInfo should only contain state information, and compiler tiers should manipulate that state
 public void ReplaceRoot(CFGNode root, CFGNode replacement)
 {
     if (_cfg.Root == root)
     {
         _cfg.Root = replacement;
     }
     else
     {
         foreach (TryBlockInfo tryBlockInfo in _tryBlockInfos)
         {
             foreach (CFGNodeCluster handlerCluster in tryBlockInfo.Handlers.Keys)
             {
                 if (handlerCluster.Start == root)
                 {
                     handlerCluster.Start = replacement;
                 }
             }
         }
     }
 }