当前位置: 首页>>代码示例>>C#>>正文


C# FlowAnalysis.ControlFlowNode类代码示例

本文整理汇总了C#中ICSharpCode.Decompiler.FlowAnalysis.ControlFlowNode的典型用法代码示例。如果您正苦于以下问题:C# ControlFlowNode类的具体用法?C# ControlFlowNode怎么用?C# ControlFlowNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ControlFlowNode类属于ICSharpCode.Decompiler.FlowAnalysis命名空间,在下文中一共展示了ControlFlowNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ControlFlowGraph

 internal ControlFlowGraph(ControlFlowNode[] nodes)
 {
     this.nodes = new ReadOnlyCollection<ControlFlowNode>(nodes);
     Debug.Assert(EntryPoint.NodeType == ControlFlowNodeType.EntryPoint);
     Debug.Assert(RegularExit.NodeType == ControlFlowNodeType.RegularExit);
     Debug.Assert(ExceptionalExit.NodeType == ControlFlowNodeType.ExceptionalExit);
 }
开发者ID:richardschneider,项目名称:ILSpy,代码行数:7,代码来源:ControlFlowGraph.cs

示例2: FindLoopContents

 static void FindLoopContents(HashSet<ControlFlowNode> nodes, HashSet<ControlFlowNode> loopContents, ControlFlowNode loopHead, ControlFlowNode addNode)
 {
     if (nodes.Contains(addNode) && loopHead.Dominates(addNode) && loopContents.Add(addNode)) {
         foreach (var edge in addNode.Incoming) {
             FindLoopContents(nodes, loopContents, loopHead, edge.Source);
         }
     }
 }
开发者ID:FriedWishes,项目名称:ILSpy,代码行数:8,代码来源:ILAstOptimizer.cs

示例3: BuildGraph

		ControlFlowGraph BuildGraph(List<ILNode> nodes, ILLabel entryLabel)
		{
			cached_ControlFlowGraph.Nodes.Clear();
			int index = 0;
			var cfNodes = cached_ControlFlowGraph.Nodes;
			ControlFlowNode entryPoint = new ControlFlowNode(index++, 0, ControlFlowNodeType.EntryPoint);
			cfNodes.Add(entryPoint);
			ControlFlowNode regularExit = new ControlFlowNode(index++, null, ControlFlowNodeType.RegularExit);
			cfNodes.Add(regularExit);
			ControlFlowNode exceptionalExit = new ControlFlowNode(index++, null, ControlFlowNodeType.ExceptionalExit);
			cfNodes.Add(exceptionalExit);

			// Create graph nodes
			labelToCfNode.Clear();
			Dictionary<ILNode, ControlFlowNode> astNodeToCfNode = new Dictionary<ILNode, ControlFlowNode>();
			List<ILLabel> listLabels = null;
			foreach(ILBasicBlock node in nodes) {
				ControlFlowNode cfNode = new ControlFlowNode(index++, null, ControlFlowNodeType.Normal);
				cfNodes.Add(cfNode);
				astNodeToCfNode[node] = cfNode;
				cfNode.UserData = node;
				
				// Find all contained labels
				foreach(ILLabel label in node.GetSelfAndChildrenRecursive<ILLabel>(listLabels ?? (listLabels = new List<ILLabel>()))) {
					labelToCfNode[label] = cfNode;
				}
			}
			
			// Entry endge
			ControlFlowNode entryNode = labelToCfNode[entryLabel];
			ControlFlowEdge entryEdge = new ControlFlowEdge(entryPoint, entryNode, JumpType.Normal);
			entryPoint.Outgoing.Add(entryEdge);
			entryNode.Incoming.Add(entryEdge);

			// Create edges
			List<ILExpression> listExpressions = null;
			foreach(ILBasicBlock node in nodes) {
				ControlFlowNode source = astNodeToCfNode[node];
				
				// Find all branches
				foreach(ILLabel target in node.GetSelfAndChildrenRecursive<ILExpression>(listExpressions ?? (listExpressions = new List<ILExpression>()), e => e.IsBranch()).SelectMany(e => e.GetBranchTargets())) {
					ControlFlowNode destination;
					// Labels which are out of out scope will not be in the collection
					// Insert self edge only if we are sure we are a loop
					if (labelToCfNode.TryGetValue(target, out destination) && (destination != source || target == node.Body.FirstOrDefault())) {
						ControlFlowEdge edge = new ControlFlowEdge(source, destination, JumpType.Normal);
						source.Outgoing.Add(edge);
						destination.Incoming.Add(edge);
					}
				}
			}

			return cached_ControlFlowGraph;
		}
开发者ID:levisre,项目名称:dnSpy,代码行数:54,代码来源:LoopsAndConditions.cs

示例4: ControlFlowGraphBuilder

		private ControlFlowGraphBuilder(MethodBody methodBody)
		{
			this.methodBody = methodBody;
			offsets = methodBody.Instructions.Select(i => i.Offset).ToArray();
			hasIncomingJumps = new bool[methodBody.Instructions.Count];
			
			entryPoint = new ControlFlowNode(0, 0, ControlFlowNodeType.EntryPoint);
			nodes.Add(entryPoint);
			regularExit = new ControlFlowNode(1, -1, ControlFlowNodeType.RegularExit);
			nodes.Add(regularExit);
			exceptionalExit = new ControlFlowNode(2, -1, ControlFlowNodeType.ExceptionalExit);
			nodes.Add(exceptionalExit);
			Debug.Assert(nodes.Count == 3);
		}
开发者ID:Gobiner,项目名称:ILSpy,代码行数:14,代码来源:ControlFlowGraphBuilder.cs

示例5: FindDominatedNodes

        static HashSet<ControlFlowNode> FindDominatedNodes(HashSet<ControlFlowNode> scope, ControlFlowNode head)
        {
            HashSet<ControlFlowNode> agenda = new HashSet<ControlFlowNode>();
            HashSet<ControlFlowNode> result = new HashSet<ControlFlowNode>();
            agenda.Add(head);

            while(agenda.Count > 0) {
                ControlFlowNode addNode = agenda.First();
                agenda.Remove(addNode);

                if (scope.Contains(addNode) && head.Dominates(addNode) && result.Add(addNode)) {
                    for (int i = 0; i < addNode.Outgoing.Count; i++) {
                        agenda.Add(addNode.Outgoing[i].Target);
                    }
                }
            }

            return result;
        }
开发者ID:n017,项目名称:dnSpy,代码行数:19,代码来源:LoopsAndConditions.cs

示例6: FindDominatedNodes

        static HashSet<ControlFlowNode> FindDominatedNodes(HashSet<ControlFlowNode> nodes, ControlFlowNode head)
        {
            var exitNodes = head.DominanceFrontier.SelectMany(n => n.Predecessors);
            HashSet<ControlFlowNode> agenda = new HashSet<ControlFlowNode>(exitNodes);
            HashSet<ControlFlowNode> result = new HashSet<ControlFlowNode>();

            while(agenda.Count > 0) {
                ControlFlowNode addNode = agenda.First();
                agenda.Remove(addNode);

                if (nodes.Contains(addNode) && head.Dominates(addNode) && result.Add(addNode)) {
                    foreach (var predecessor in addNode.Predecessors) {
                        agenda.Add(predecessor);
                    }
                }
            }
            if (nodes.Contains(head))
                result.Add(head);

            return result;
        }
开发者ID:FriedWishes,项目名称:ILSpy,代码行数:21,代码来源:ILAstOptimizer.cs

示例7: Dominates

		/// <summary>
		/// Gets whether <c>this</c> dominates <paramref name="node"/>.
		/// </summary>
		public bool Dominates(ControlFlowNode node)
		{
			// TODO: this can be made O(1) by numbering the dominator tree
			ControlFlowNode tmp = node;
			while (tmp != null) {
				if (tmp == this)
					return true;
				tmp = tmp.ImmediateDominator;
			}
			return false;
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:14,代码来源:ControlFlowNode.cs

示例8: ControlFlowNode

		internal ControlFlowNode(int blockIndex, ExceptionHandler exceptionHandler, ControlFlowNode endFinallyOrFaultNode)
		{
			BlockIndex = blockIndex;
			NodeType = endFinallyOrFaultNode != null ? ControlFlowNodeType.FinallyOrFaultHandler : ControlFlowNodeType.CatchHandler;
			ExceptionHandler = exceptionHandler;
			EndFinallyOrFaultNode = endFinallyOrFaultNode;
			Debug.Assert((exceptionHandler.HandlerType == ExceptionHandlerType.Finally || exceptionHandler.HandlerType == ExceptionHandlerType.Fault) == (endFinallyOrFaultNode != null));
			Offset = exceptionHandler.HandlerStart.Offset;
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:9,代码来源:ControlFlowNode.cs

示例9: FindCommonDominator

		ControlFlowNode FindCommonDominator(ControlFlowNode b1, ControlFlowNode b2)
		{
			// Here we could use the postorder numbers to get rid of the hashset, see "A Simple, Fast Dominance Algorithm"
			FindCommonDominator_path1.Clear();
			while (b1 != null && FindCommonDominator_path1.Add(b1))
				b1 = b1.ImmediateDominator;
			while (b2 != null) {
				if (FindCommonDominator_path1.Contains(b2))
					return b2;
				else
					b2 = b2.ImmediateDominator;
			}
			throw new Exception("No common dominator found!");
		}
开发者ID:GreenDamTan,项目名称:dnSpy,代码行数:14,代码来源:ControlFlowGraph.cs

示例10: CreateEdge

		void CreateEdge(ControlFlowNode fromNode, ControlFlowNode toNode, JumpType type)
		{
			ControlFlowEdge edge = new ControlFlowEdge(fromNode, toNode, type);
			fromNode.Outgoing.Add(edge);
			toNode.Incoming.Add(edge);
		}
开发者ID:Gobiner,项目名称:ILSpy,代码行数:6,代码来源:ControlFlowGraphBuilder.cs

示例11: GetNew

			ControlFlowNode GetNew(ControlFlowNode oldNode)
			{
				if (oldNode == end)
					return newEnd;
				ControlFlowNode newNode;
				if (oldToNew.TryGetValue(oldNode, out newNode))
					return newNode;
				return oldNode;
			}
开发者ID:Gobiner,项目名称:ILSpy,代码行数:9,代码来源:ControlFlowGraphBuilder.cs

示例12: CollectNodes

			void CollectNodes(ControlFlowNode node)
			{
				if (node == end || node == newEnd)
					throw new InvalidOperationException("unexpected cycle involving finally construct");
				if (!oldToNew.ContainsKey(node)) {
					int newBlockIndex = builder.nodes.Count;
					ControlFlowNode copy;
					switch (node.NodeType) {
						case ControlFlowNodeType.Normal:
							copy = new ControlFlowNode(newBlockIndex, node.Start, node.End);
							break;
						case ControlFlowNodeType.FinallyOrFaultHandler:
							copy = new ControlFlowNode(newBlockIndex, node.ExceptionHandler, node.EndFinallyOrFaultNode);
							break;
						default:
							// other nodes shouldn't occur when copying finally blocks
							throw new NotSupportedException(node.NodeType.ToString());
					}
					copy.CopyFrom = node;
					builder.nodes.Add(copy);
					oldToNew.Add(node, copy);
					
					if (node != start) {
						foreach (ControlFlowNode n in node.Predecessors) {
							CollectNodes(n);
						}
					}
				}
			}
开发者ID:Gobiner,项目名称:ILSpy,代码行数:29,代码来源:ControlFlowGraphBuilder.cs

示例13: CopyFinallySubGraph

		/// <summary>
		/// Creates a copy of all nodes pointing to 'end' and replaces those references with references to 'newEnd'.
		/// Nodes pointing to the copied node are copied recursively to update those references, too.
		/// This recursion stops at 'start'. The modified version of start is returned.
		/// </summary>
		ControlFlowNode CopyFinallySubGraph(ControlFlowNode start, ControlFlowNode end, ControlFlowNode newEnd)
		{
			return new CopyFinallySubGraphLogic(this, start, end, newEnd).CopyFinallySubGraph();
		}
开发者ID:Gobiner,项目名称:ILSpy,代码行数:9,代码来源:ControlFlowGraphBuilder.cs

示例14: BuildGraph

        ControlFlowGraph BuildGraph(List<ILNode> nodes, ILLabel entryLabel)
        {
            int index = 0;
            List<ControlFlowNode> cfNodes = new List<ControlFlowNode>();
            ControlFlowNode entryPoint = new ControlFlowNode(index++, 0, ControlFlowNodeType.EntryPoint);
            cfNodes.Add(entryPoint);
            ControlFlowNode regularExit = new ControlFlowNode(index++, -1, ControlFlowNodeType.RegularExit);
            cfNodes.Add(regularExit);
            ControlFlowNode exceptionalExit = new ControlFlowNode(index++, -1, ControlFlowNodeType.ExceptionalExit);
            cfNodes.Add(exceptionalExit);

            // Create graph nodes
            labelToCfNode = new Dictionary<ILLabel, ControlFlowNode>();
            Dictionary<ILNode, ControlFlowNode>  astNodeToCfNode = new Dictionary<ILNode, ControlFlowNode>();
            foreach(ILNode node in nodes) {
                ControlFlowNode cfNode = new ControlFlowNode(index++, -1, ControlFlowNodeType.Normal);
                cfNodes.Add(cfNode);
                astNodeToCfNode[node] = cfNode;
                cfNode.UserData = node;

                // Find all contained labels
                foreach(ILLabel label in node.GetSelfAndChildrenRecursive<ILLabel>()) {
                    labelToCfNode[label] = cfNode;
                }
            }

            // Entry endge
            ControlFlowNode entryNode = labelToCfNode[entryLabel];
            ControlFlowEdge entryEdge = new ControlFlowEdge(entryPoint, entryNode, JumpType.Normal);
            entryPoint.Outgoing.Add(entryEdge);
            entryNode.Incoming.Add(entryEdge);

            // Create edges
            foreach(ILNode node in nodes) {
                ControlFlowNode source = astNodeToCfNode[node];

                // Find all branches
                foreach(ILExpression child in node.GetSelfAndChildrenRecursive<ILExpression>()) {
                    IEnumerable<ILLabel> targets = child.GetBranchTargets();
                    if (targets != null) {
                        foreach(ILLabel target in targets) {
                            ControlFlowNode destination;
                            // Labels which are out of out scope will not be int the collection
                            if (labelToCfNode.TryGetValue(target, out destination) && destination != source) {
                                ControlFlowEdge edge = new ControlFlowEdge(source, destination, JumpType.Normal);
                                source.Outgoing.Add(edge);
                                destination.Incoming.Add(edge);
                            }
                        }
                    }
                }
            }

            return new ControlFlowGraph(cfNodes.ToArray());
        }
开发者ID:FriedWishes,项目名称:ILSpy,代码行数:55,代码来源:ILAstOptimizer.cs

示例15: FindLoops

        List<ILNode> FindLoops(HashSet<ControlFlowNode> scope, ControlFlowNode entryPoint, bool excludeEntryPoint)
        {
            List<ILNode> result = new List<ILNode>();

            Queue<ControlFlowNode> agenda  = new Queue<ControlFlowNode>();
            agenda.Enqueue(entryPoint);
            while(agenda.Count > 0) {
                ControlFlowNode node = agenda.Dequeue();

                if (scope.Contains(node)
                        && node.DominanceFrontier.Contains(node)
                        && (node != entryPoint || !excludeEntryPoint))
                {
                    HashSet<ControlFlowNode> loopContents = FindDominatedNodes(scope, node);

                    ILWhileLoop loop = new ILWhileLoop();

                    ILCondition cond;
                    HashSet<ControlFlowNode> condNodes;
                    ILLabel condLabel;
                    if (TryMatchCondition(loopContents, new ControlFlowNode[]{}, node, out cond, out condNodes, out condLabel)) {
                        loopContents.ExceptWith(condNodes);
                        scope.ExceptWith(condNodes);
                        // Use loop to implement condition
                        loop.Condition      = cond.Condition;
                        loop.PreLoopLabel   = condLabel;
                        loop.PostLoopGoto   = cond.FalseBlock.EntryGoto;
                        loop.BodyBlock      = new ILBlock() { EntryGoto = cond.TrueBlock.EntryGoto };
                    } else {
                        // Give the block some explicit entry point
                        ILLabel entryLabel  = new ILLabel() { Name = "Loop_" + (nextBlockIndex++) };
                        loop.BodyBlock      = new ILBlock() { EntryGoto = new ILExpression(ILCode.Br, entryLabel) };
                        ((ILBasicBlock)node.UserData).Body.Insert(0, entryLabel);
                    }
                    loop.BodyBlock.Body = FindLoops(loopContents, node, true);

                    // Move the content into loop block
                    scope.ExceptWith(loopContents);
                    result.Add(loop);
                }

                // Using the dominator tree should ensure we find the the widest loop first
                foreach(var child in node.DominatorTreeChildren) {
                    agenda.Enqueue(child);
                }
            }

            // Add whatever is left
            foreach(var node in scope) {
                result.Add((ILNode)node.UserData);
            }

            return result;
        }
开发者ID:petr-k,项目名称:ILSpy,代码行数:54,代码来源:ILAstOptimizer.cs


注:本文中的ICSharpCode.Decompiler.FlowAnalysis.ControlFlowNode类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。