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; }
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); }
/// <summary> /// Debugging helper that exports a control flow graph. /// </summary> public static GraphVizGraph ExportGraph(IList <ControlFlowNode> nodes) { GraphVizGraph g = new GraphVizGraph(); GraphVizNode[] n = new GraphVizNode[nodes.Count]; Dictionary <ControlFlowNode, int> dict = new Dictionary <ControlFlowNode, int>(); for (int i = 0; i < n.Length; i++) { dict.Add(nodes[i], i); n[i] = new GraphVizNode(i); string name = "#" + i + " = "; switch (nodes[i].Type) { case ControlFlowNodeType.StartNode: case ControlFlowNodeType.BetweenStatements: name += nodes[i].NextStatement.DebugToString(); break; case ControlFlowNodeType.EndNode: name += "End of " + nodes[i].PreviousStatement.DebugToString(); break; case ControlFlowNodeType.LoopCondition: name += "Condition in " + nodes[i].NextStatement.DebugToString(); break; default: name += "?"; break; } n[i].label = name; g.AddNode(n[i]); } for (int i = 0; i < n.Length; i++) { foreach (ControlFlowEdge edge in nodes[i].Outgoing) { GraphVizEdge ge = new GraphVizEdge(i, dict[edge.To]); if (edge.IsLeavingTryFinally) { ge.style = "dashed"; } switch (edge.Type) { case ControlFlowEdgeType.ConditionTrue: ge.color = "green"; break; case ControlFlowEdgeType.ConditionFalse: ge.color = "red"; break; case ControlFlowEdgeType.Jump: ge.color = "blue"; break; } g.AddEdge(ge); } } return(g); }
/// <summary> /// Exports the CFG. This method is intended to help debugging issues related to definite assignment. /// </summary> public GraphVizGraph ExportGraph() { GraphVizGraph g = new GraphVizGraph(); g.Title = "DefiniteAssignment - " + variableName; for (int i = 0; i < allNodes.Count; i++) { string name = "#" + i + " = " + allNodes[i].NodeStatus.ToString() + Environment.NewLine; switch (allNodes[i].Type) { case ControlFlowNodeType.StartNode: case ControlFlowNodeType.BetweenStatements: name += allNodes[i].NextStatement.ToString(); break; case ControlFlowNodeType.EndNode: name += "End of " + allNodes[i].PreviousStatement.ToString(); break; case ControlFlowNodeType.LoopCondition: name += "Condition in " + allNodes[i].NextStatement.ToString(); break; default: name += allNodes[i].Type.ToString(); break; } g.AddNode(new GraphVizNode(i) { label = name }); foreach (ControlFlowEdge edge in allNodes[i].Outgoing) { GraphVizEdge ge = new GraphVizEdge(i, ((DefiniteAssignmentNode)edge.To).Index); if (edgeStatus.Count > 0) { ge.label = edgeStatus[edge].ToString(); } if (edge.IsLeavingTryFinally) { ge.style = "dashed"; } switch (edge.Type) { case ControlFlowEdgeType.ConditionTrue: ge.color = "green"; break; case ControlFlowEdgeType.ConditionFalse: ge.color = "red"; break; case ControlFlowEdgeType.Jump: ge.color = "blue"; break; } g.AddEdge(ge); } } return(g); }