コード例 #1
0
ファイル: ControlFlowGraph.cs プロジェクト: GreenDamTan/dnSpy
		public GraphVizGraph ExportGraph()
		{
			GraphVizGraph graph = new GraphVizGraph();
			foreach (ControlFlowNode node in nodes) {
				graph.AddNode(new GraphVizNode(node.BlockIndex) { label = node.ToString(), shape = "box" });
			}
			foreach (ControlFlowNode node in nodes) {
				foreach (ControlFlowEdge edge in node.Outgoing) {
					GraphVizEdge e = new GraphVizEdge(edge.Source.BlockIndex, edge.Target.BlockIndex);
					switch (edge.Type) {
						case JumpType.Normal:
							break;
						case JumpType.LeaveTry:
						case JumpType.EndFinally:
							e.color = "red";
							break;
						default:
							e.color = "gray";
							//e.constraint = false;
							break;
					}
					graph.AddEdge(e);
				}
				if (node.ImmediateDominator != null) {
					graph.AddEdge(new GraphVizEdge(node.ImmediateDominator.BlockIndex, node.BlockIndex) { color = "green", constraint = false });
				}
			}
			return graph;
		}
コード例 #2
0
		public GraphVizGraph ExportBlockGraph(Func<SsaBlock, string> labelProvider = null)
		{
			if (labelProvider == null)
				labelProvider = b => b.ToString();
			GraphVizGraph graph = new GraphVizGraph();
			foreach (SsaBlock block in this.Blocks) {
				graph.AddNode(new GraphVizNode(block.BlockIndex) { label = labelProvider(block), shape = "box" });
			}
			foreach (SsaBlock block in this.Blocks) {
				foreach (SsaBlock s in block.Successors) {
					graph.AddEdge(new GraphVizEdge(block.BlockIndex, s.BlockIndex));
				}
			}
			return graph;
		}
コード例 #3
0
		public GraphVizGraph ExportVariableGraph(Func<SsaVariable, string> labelProvider = null)
		{
			if (labelProvider == null)
				labelProvider = v => v.ToString();
			GraphVizGraph graph = new GraphVizGraph();
			foreach (SsaVariable v in this.AllVariables) {
				graph.AddNode(new GraphVizNode(v.Name) { label = labelProvider(v) });
			}
			int instructionIndex = 0;
			foreach (SsaBlock block in this.Blocks) {
				foreach (SsaInstruction inst in block.Instructions) {
					if (inst.Operands.Length == 0 && inst.Target == null)
						continue;
					string id = "instruction" + (++instructionIndex);
					graph.AddNode(new GraphVizNode(id) { label = inst.ToString(), shape = "box" });
					foreach (SsaVariable op in inst.Operands)
						graph.AddEdge(new GraphVizEdge(op.Name, id));
					if (inst.Target != null)
						graph.AddEdge(new GraphVizEdge(id, inst.Target.Name));
				}
			}
			return graph;
		}