use of com.jopdesign.common.graphutils.AdvancedDOTExporter in project jop by jop-devel.
the class Template method exportDOT.
public void exportDOT(File dbgFile) throws IOException {
DirectedGraph<Location, DefaultEdge> locGraph = new DefaultDirectedGraph<Location, DefaultEdge>(DefaultEdge.class);
for (Location l : this.locations.values()) locGraph.addVertex(l);
Map<DefaultEdge, String> edgeMap = new HashMap<DefaultEdge, String>();
for (Transition t : this.transitions) {
DefaultEdge e = locGraph.addEdge(t.getSource(), t.getTarget());
edgeMap.put(e, t.getAttrs().toString());
}
FileWriter fw = new FileWriter(dbgFile);
AdvancedDOTExporter.DOTNodeLabeller<Location> nodeLabeller = new AdvancedDOTExporter.DefaultNodeLabeller<Location>() {
public int getID(Location node) {
return node.getId();
}
public String getLabel(Location node) {
return node.getName();
}
};
AdvancedDOTExporter.DOTLabeller<DefaultEdge> edgeLabeller = new AdvancedDOTExporter.MapLabeller<DefaultEdge>(edgeMap);
AdvancedDOTExporter<Location, DefaultEdge> dotExport = new AdvancedDOTExporter<Location, DefaultEdge>(nodeLabeller, edgeLabeller);
dotExport.exportDOT(fw, locGraph);
fw.close();
}
use of com.jopdesign.common.graphutils.AdvancedDOTExporter in project jop by jop-devel.
the class Segment method exportDOT.
/**
* Export to DOT file
* @param dotFile
* @throws IOException
*/
public void exportDOT(File dotFile) throws IOException {
FileWriter dotWriter = new FileWriter(dotFile);
AdvancedDOTExporter.DOTNodeLabeller<SuperGraphNode> nodeLabeller = new AdvancedDOTExporter.DefaultNodeLabeller<SuperGraphNode>() {
@Override
public String getLabel(SuperGraphNode node) {
StringBuilder sb = new StringBuilder();
/* for entry nodes: method + call string */
if (node.getCFGNode().getId() == 0) {
sb.append(node.getContextCFG().getCfg().getMethodInfo().getFQMethodName() + "\n");
int i = 1;
for (InvokeSite is : node.getContextCFG().getCallString()) {
sb.append(" #" + i + " " + is.getInvoker().getFQMethodName() + " / " + is.getInstructionHandle().getPosition() + "\n");
i += 1;
}
} else /* for other nodes: basic block export */
{
sb.append(node.getCFGNode().toString());
}
return sb.toString();
}
};
DOTLabeller<SuperGraphEdge> edgeLabeller = new AdvancedDOTExporter.DefaultDOTLabeller<SuperGraphEdge>() {
@Override
public String getLabel(SuperGraphEdge edge) {
return "";
}
@Override
public boolean setAttributes(SuperGraphEdge edge, Map<String, String> ht) {
super.setAttributes(edge, ht);
if (edge instanceof SuperReturnEdge) {
ht.put("style", "dotted");
ht.put("arrowhead", "empty");
} else if (edge instanceof SuperInvokeEdge) {
ht.put("style", "dotted");
}
return true;
}
};
AdvancedDOTExporter<SuperGraphNode, SuperGraphEdge> de = new AdvancedDOTExporter<SuperGraphNode, SuperGraphEdge>(nodeLabeller, edgeLabeller);
de.exportDOTDiGraph(dotWriter, this.getNodes(), this.getEdges(), new AdvancedDOTExporter.GraphAdapter<SuperGraphNode, SuperGraphEdge>() {
@Override
public SuperGraphNode getEdgeSource(SuperGraphEdge e) {
return e.getSource();
}
@Override
public SuperGraphNode getEdgeTarget(SuperGraphEdge e) {
return e.getTarget();
}
});
dotWriter.close();
}
use of com.jopdesign.common.graphutils.AdvancedDOTExporter in project jop by jop-devel.
the class SuperGraph method exportDOT.
public void exportDOT(File dotFile) throws IOException {
FileWriter dotWriter = new FileWriter(dotFile);
AdvancedDOTExporter.DOTNodeLabeller<ContextCFG> nodeLabeller = new AdvancedDOTExporter.DefaultNodeLabeller<ContextCFG>() {
@Override
public String getLabel(ContextCFG node) {
StringBuilder sb = new StringBuilder();
sb.append(node.getCfg().getMethodInfo().getFQMethodName() + "\n");
int i = 1;
for (InvokeSite is : node.getContext().getCallString()) {
sb.append(" #" + i + " " + is.getInvoker().getFQMethodName() + " / " + is.getInstructionHandle().getPosition() + "\n");
i += 1;
}
return sb.toString();
}
};
DOTLabeller<SuperEdge> edgeLabeller = new AdvancedDOTExporter.DefaultDOTLabeller<SuperEdge>() {
@Override
public String getLabel(SuperEdge edge) {
return "";
}
@Override
public boolean setAttributes(SuperEdge edge, Map<String, String> ht) {
super.setAttributes(edge, ht);
if (edge instanceof SuperReturnEdge) {
ht.put("style", "dotted");
ht.put("arrowhead", "empty");
}
return true;
}
};
AdvancedDOTExporter<ContextCFG, SuperEdge> de = new AdvancedDOTExporter<ContextCFG, SuperEdge>(nodeLabeller, edgeLabeller);
de.exportDOT(dotWriter, this.superGraph);
dotWriter.close();
}
Aggregations