use of org.mapleir.dot4j.model.DotGraph in project maple-ir by LLVM-but-worse.
the class GraphUtils method makeDotSkeleton.
public static <N extends FastGraphVertex, E extends FastGraphEdge<N>> DotGraph makeDotSkeleton(FastGraph<N, E> fastGraph, BiPredicate<N, Node> nodePredicate, BiPredicate<E, Edge> edgePredicate) {
Attrs font = GraphUtils.getDefaultFont();
DotGraph graph = Factory.graph().getGraphAttr().with(font).getNodeAttr().with(font).getEdgeAttr().with(font);
return Context.use(graph, ctx -> {
for (N vertex : fastGraph.vertices()) {
Node sourceNode = Factory.node(vertex.getDisplayName());
boolean addNode = true;
if (nodePredicate != null) {
addNode = nodePredicate.test(vertex, sourceNode);
}
if (addNode) {
graph.addSource(sourceNode);
}
for (E e : fastGraph.getEdges(vertex)) {
Node target = Factory.node(e.dst().getDisplayName());
Edge edge = Factory.to(target);
boolean addEdge = true;
if (edgePredicate != null) {
addEdge = edgePredicate.test(e, edge);
}
if (addEdge) {
sourceNode.addEdge(edge);
}
}
}
return graph;
});
}
use of org.mapleir.dot4j.model.DotGraph in project maple-ir by LLVM-but-worse.
the class CFGExporterUtils method makeDotGraph.
public static DotGraph makeDotGraph(ControlFlowGraph cfg, IPropertyDictionary properties) {
boolean showStmts = PropertyHelper.isSet(properties, OPT_STMTS);
boolean labelEdges = PropertyHelper.isSet(properties, OPT_EDGES);
boolean simplifyEdges = PropertyHelper.isSet(properties, OPT_SIMPLE_EDGES);
boolean hideHandlerEdges = PropertyHelper.isSet(properties, OPT_HIDE_HANDLER_EDGES);
DotGraph sourceGraph = Factory.graph().getGraphAttr().with(Rank.SOURCE);
DotGraph sinkGraph = Factory.graph().getGraphAttr().with(Rank.SINK);
DotGraph g = GraphUtils.makeDotSkeleton(cfg, (block, node) -> {
StringBuilder sb = new StringBuilder();
sb.append("<table>");
{
sb.append("<tr><td><font point-size=\"12\">").append(block.getDisplayName()).append("</font></td></tr>");
}
{
sb.append("<tr><td>");
if (showStmts) {
StringBuilder stmtsStr = new StringBuilder();
outputBlock(block, stmtsStr);
sb.append(stmtsStr.toString());
}
sb.append("</td></tr>");
}
sb.append("</table>");
Attrs colour;
DotGraph rankGraph;
if (cfg.getEntries().contains(block)) {
colour = Colour.RED.fill();
rankGraph = sourceGraph;
} else if (cfg.getEdges(block).isEmpty()) {
colour = Colour.GREEN.fill();
rankGraph = sinkGraph;
} else {
colour = Attrs.attrs();
rankGraph = null;
}
if (rankGraph != null) {
Context.use(rankGraph, (ctx) -> {
return rankGraph.addSource(Factory.node(node.getName()));
});
}
node.with(Shape.BOX, Style.FILLED, colour, ComplexLabel.html(sb.toString()).justify(Justification.LEFT));
return true;
}, (e, dotE) -> {
if (hideHandlerEdges && e instanceof TryCatchEdge) {
// dotE.with(Style.INVIS);
return false;
}
if (labelEdges) {
dotE.with(ComplexLabel.of(simplifyEdges ? e.getClass().getSimpleName().replace("Edge", "") : e.toGraphString()));
}
return true;
}).setDirected(true);
g.addSource(sourceGraph);
g.addSource(sinkGraph);
return g;
}
Aggregations