use of soot.util.dot.DotGraphEdge in project soot by Sable.
the class CFGToDotGraph method drawCFG.
/**
* Create a <code>DotGraph</code> whose nodes and edges depict the
* control flow in a <code>ExceptionalGraph</code>, with
* distinguished edges for exceptional control flow.
*
* @param graph the control flow graph
*
* @return a visualization of <code>graph</code>.
*/
public <N> DotGraph drawCFG(ExceptionalGraph<N> graph) {
Body body = graph.getBody();
DotGraph canvas = initDotGraph(body);
DotNamer namer = new DotNamer((int) (graph.size() / 0.7f), 0.7f);
NodeComparator nodeComparator = new NodeComparator(namer);
// comparisons between graphs of a given method.
for (Iterator<N> nodesIt = graph.iterator(); nodesIt.hasNext(); ) {
namer.getName(nodesIt.next());
}
for (Iterator<N> nodesIt = graph.iterator(); nodesIt.hasNext(); ) {
N node = nodesIt.next();
canvas.drawNode(namer.getName(node));
for (Iterator<N> succsIt = sortedIterator(graph.getUnexceptionalSuccsOf(node), nodeComparator); succsIt.hasNext(); ) {
N succ = succsIt.next();
DotGraphEdge edge = canvas.drawEdge(namer.getName(node), namer.getName(succ));
edge.setAttribute(unexceptionalControlFlowAttr);
}
for (Iterator<N> succsIt = sortedIterator(graph.getExceptionalSuccsOf(node), nodeComparator); succsIt.hasNext(); ) {
N succ = succsIt.next();
DotGraphEdge edge = canvas.drawEdge(namer.getName(node), namer.getName(succ));
edge.setAttribute(exceptionalControlFlowAttr);
}
if (showExceptions) {
for (Iterator<ExceptionDest<N>> destsIt = sortedIterator(graph.getExceptionDests(node), new ExceptionDestComparator(namer)); destsIt.hasNext(); ) {
ExceptionDest<N> dest = destsIt.next();
Object handlerStart = dest.getHandlerNode();
if (handlerStart == null) {
// Giving each escaping exception its own, invisible
// exceptional exit node produces a less cluttered
// graph.
handlerStart = new Object() {
public String toString() {
return "Esc";
}
};
DotGraphNode escapeNode = canvas.drawNode(namer.getName(handlerStart));
escapeNode.setStyle(DotGraphConstants.NODE_STYLE_INVISIBLE);
}
DotGraphEdge edge = canvas.drawEdge(namer.getName(node), namer.getName(handlerStart));
edge.setAttribute(exceptionEdgeAttr);
edge.setLabel(formatThrowableSet(dest.getThrowables()));
}
}
}
setStyle(graph.getHeads(), canvas, namer, DotGraphConstants.NODE_STYLE_FILLED, headAttr);
setStyle(graph.getTails(), canvas, namer, DotGraphConstants.NODE_STYLE_FILLED, tailAttr);
if (!isBrief) {
formatNodeText(graph.getBody(), canvas, namer);
}
return canvas;
}
use of soot.util.dot.DotGraphEdge in project soot by Sable.
the class AbstractInterproceduralAnalysis method drawAsOneDot.
/**
* Dump the interprocedural analysis result as a graph. One node / subgraph
* for each analysed method that contains the method summary, and call-to
* edges.
*
* Note: this graph does not show filtered-out methods for which a
* conservative summary was asked via summaryOfUnanalysedMethod.
*
* @param name output filename
*
* @see fillDotGraph
*/
public void drawAsOneDot(String name) {
DotGraph dot = new DotGraph(name);
dot.setGraphLabel(name);
dot.setGraphAttribute("compound", "true");
// dot.setGraphAttribute("rankdir","LR");
int id = 0;
Map<SootMethod, Integer> idmap = new HashMap<SootMethod, Integer>();
// draw sub-graph cluster
for (SootMethod m : dg) {
DotGraph sub = dot.createSubGraph("cluster" + id);
DotGraphNode label = sub.drawNode("head" + id);
idmap.put(m, id);
sub.setGraphLabel("");
label.setLabel("(" + order.get(m) + ") " + m.toString());
label.setAttribute("fontsize", "18");
label.setShape("box");
if (data.containsKey(m)) {
fillDotGraph("X" + id, data.get(m), sub);
}
id++;
}
// connect edges
for (SootMethod m : dg) {
for (SootMethod mm : dg.getSuccsOf(m)) {
DotGraphEdge edge = dot.drawEdge("head" + idmap.get(m), "head" + idmap.get(mm));
edge.setAttribute("ltail", "cluster" + idmap.get(m));
edge.setAttribute("lhead", "cluster" + idmap.get(mm));
}
}
File f = new File(SourceLocator.v().getOutputDir(), name + DotGraph.DOT_EXTENSION);
dot.plot(f.getPath());
}
use of soot.util.dot.DotGraphEdge in project soot by Sable.
the class PurityIntraproceduralAnalysis method drawAsOneDot.
/**
* Draw the result of the intra-procedural analysis as one big dot file,
* named className.methodName.dot, containing one purity graph for each
* statement in the method.
*
* @param prefix
* @param name
*/
public void drawAsOneDot(String prefix, String name) {
DotGraph dot = new DotGraph(name);
dot.setGraphLabel(name);
dot.setGraphAttribute("compound", "true");
dot.setGraphAttribute("rankdir", "LR");
Map<Unit, Integer> node = new HashMap<Unit, Integer>();
int id = 0;
for (Unit stmt : graph) {
PurityGraphBox ref = getFlowAfter(stmt);
DotGraph sub = dot.createSubGraph("cluster" + id);
DotGraphNode label = sub.drawNode("head" + id);
String lbl = stmt.toString();
if (lbl.startsWith("lookupswitch")) {
lbl = "lookupswitch...";
}
if (lbl.startsWith("tableswitch")) {
lbl = "tableswitch...";
}
sub.setGraphLabel(" ");
label.setLabel(lbl);
label.setAttribute("fontsize", "18");
label.setShape("box");
ref.g.fillDotGraph("X" + id, sub);
node.put(stmt, id);
id++;
}
for (Unit src : graph) {
for (Unit dst : graph.getSuccsOf(src)) {
DotGraphEdge edge = dot.drawEdge("head" + node.get(src), "head" + node.get(dst));
edge.setAttribute("ltail", "cluster" + node.get(src));
edge.setAttribute("lhead", "cluster" + node.get(dst));
}
}
File f = new File(SourceLocator.v().getOutputDir(), prefix + name + DotGraph.DOT_EXTENSION);
dot.plot(f.getPath());
}
Aggregations