Search in sources :

Example 1 with Colour

use of org.mapleir.dot4j.attr.builtin.Colour 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;
}
Also used : Colour(org.mapleir.dot4j.attr.builtin.Colour) DotGraph(org.mapleir.dot4j.model.DotGraph) Shape(org.mapleir.dot4j.attr.builtin.Shape) Justification(org.mapleir.dot4j.attr.builtin.ComplexLabel.Justification) Iterator(java.util.Iterator) ComplexLabel(org.mapleir.dot4j.attr.builtin.ComplexLabel) Rank(org.mapleir.dot4j.attr.builtin.Rank) ControlFlowGraph(org.mapleir.ir.cfg.ControlFlowGraph) Context(org.mapleir.dot4j.model.Context) Stmt(org.mapleir.ir.code.Stmt) Attrs(org.mapleir.dot4j.attr.Attrs) TabbedStringWriter(org.mapleir.stdlib.util.TabbedStringWriter) IPropertyDictionary(org.mapleir.propertyframework.api.IPropertyDictionary) GraphUtils(org.mapleir.stdlib.collections.graph.GraphUtils) Style(org.mapleir.dot4j.attr.builtin.Style) Factory(org.mapleir.dot4j.model.Factory) BasicBlock(org.mapleir.ir.cfg.BasicBlock) PropertyHelper(org.mapleir.propertyframework.util.PropertyHelper) TryCatchEdge(org.mapleir.flowgraph.edges.TryCatchEdge) DotGraph(org.mapleir.dot4j.model.DotGraph) Attrs(org.mapleir.dot4j.attr.Attrs) TryCatchEdge(org.mapleir.flowgraph.edges.TryCatchEdge)

Aggregations

Iterator (java.util.Iterator)1 Attrs (org.mapleir.dot4j.attr.Attrs)1 Colour (org.mapleir.dot4j.attr.builtin.Colour)1 ComplexLabel (org.mapleir.dot4j.attr.builtin.ComplexLabel)1 Justification (org.mapleir.dot4j.attr.builtin.ComplexLabel.Justification)1 Rank (org.mapleir.dot4j.attr.builtin.Rank)1 Shape (org.mapleir.dot4j.attr.builtin.Shape)1 Style (org.mapleir.dot4j.attr.builtin.Style)1 Context (org.mapleir.dot4j.model.Context)1 DotGraph (org.mapleir.dot4j.model.DotGraph)1 Factory (org.mapleir.dot4j.model.Factory)1 TryCatchEdge (org.mapleir.flowgraph.edges.TryCatchEdge)1 BasicBlock (org.mapleir.ir.cfg.BasicBlock)1 ControlFlowGraph (org.mapleir.ir.cfg.ControlFlowGraph)1 Stmt (org.mapleir.ir.code.Stmt)1 IPropertyDictionary (org.mapleir.propertyframework.api.IPropertyDictionary)1 PropertyHelper (org.mapleir.propertyframework.util.PropertyHelper)1 GraphUtils (org.mapleir.stdlib.collections.graph.GraphUtils)1 TabbedStringWriter (org.mapleir.stdlib.util.TabbedStringWriter)1