Search in sources :

Example 1 with DominatorNode

use of soot.toolkits.graph.DominatorNode in project soot by Sable.

the class RegionAnalysis method weakRegionDFS2.

/**
 * This algorithm starts from a head node in the CFG and is exactly the same as the above
 * with the difference that post dominator and dominator trees switch positions.
 * @param v
 * @param r
 */
private void weakRegionDFS2(Block v, int r) {
    // regions keep an implicit order of the contained blocks so it matters where blocks are added
    // below.
    this.m_regions.get(r).add2Back(v);
    DominatorNode<Block> parentOfV = this.m_pdom.getParentOf(this.m_pdom.getDode(v));
    Block u2 = (parentOfV == null) ? null : parentOfV.getGode();
    List<DominatorNode<Block>> children = this.m_dom.getChildrenOf(this.m_dom.getDode(v));
    for (int i = 0; i < children.size(); i++) {
        DominatorNode<Block> w = children.get(i);
        Block u1 = w.getGode();
        if (u2 != null && u1.equals(u2)) {
            this.weakRegionDFS2(w.getGode(), r);
        } else {
            this.m_regCount++;
            this.m_regions.put(this.m_regCount, this.createRegion(this.m_regCount));
            this.weakRegionDFS2(w.getGode(), this.m_regCount);
        }
    }
}
Also used : Block(soot.toolkits.graph.Block) DominatorNode(soot.toolkits.graph.DominatorNode)

Example 2 with DominatorNode

use of soot.toolkits.graph.DominatorNode in project soot by Sable.

the class RegionAnalysis method weakRegionDFS.

/**
 * This algorithms assumes that the first time it's called with a tail of the CFG. Then for each
 * child node w of v in the post-dominator tree, it compares the parent of v in the dominator tree
 * with w and if they are the same, that means w belongs to the same region as v, so  weakRegionDFS
 * is recursively called with w and the same region id as v.
 * If the comparison fails, then a new region is created and weakRegionDFS is called recursively with
 * w but this time with the newly created region id.
 *
 * @param v
 * @param r
 */
private void weakRegionDFS(Block v, int r) {
    try {
        // System.out.println("##entered weakRegionDFS for region " + r);
        this.m_regions.get(r).add(v);
        DominatorNode<Block> parentOfV = this.m_dom.getParentOf(this.m_dom.getDode(v));
        Block u2 = (parentOfV == null) ? null : parentOfV.getGode();
        List<DominatorNode<Block>> children = this.m_pdom.getChildrenOf(this.m_pdom.getDode(v));
        for (int i = 0; i < children.size(); i++) {
            DominatorNode<Block> w = children.get(i);
            Block u1 = w.getGode();
            if (u2 != null && u1.equals(u2)) {
                this.weakRegionDFS(w.getGode(), r);
            } else {
                this.m_regCount++;
                this.m_regions.put(this.m_regCount, this.createRegion(this.m_regCount));
                this.weakRegionDFS(w.getGode(), this.m_regCount);
            }
        }
    } catch (RuntimeException e) {
        logger.debug("[RegionAnalysis] Exception in weakRegionDFS: ", e);
        logger.debug("v is  " + v.toShortString() + " in region " + r);
        G.v().out.flush();
    }
}
Also used : Block(soot.toolkits.graph.Block) DominatorNode(soot.toolkits.graph.DominatorNode)

Example 3 with DominatorNode

use of soot.toolkits.graph.DominatorNode in project soot by Sable.

the class CFGToDotGraph method formatNodeText.

/**
 * A utility method which formats the text for each node in
 * a <code>DotGraph</code> representing a CFG.
 *
 * @param body the <code>Body</code> whose control flow is visualized in
 *             <code>canvas</code>.
 *
 * @param canvas the <code>DotGraph</code> for visualizing the CFG.
 *
 * @param namer provides a mapping from CFG objects to identifiers in
 *              generated dot source.
 */
private <N> void formatNodeText(Body body, DotGraph canvas, DotNamer<N> namer) {
    LabeledUnitPrinter printer = null;
    if (body != null) {
        printer = new BriefUnitPrinter(body);
        printer.noIndent();
    }
    for (Iterator<N> nodesIt = namer.keySet().iterator(); nodesIt.hasNext(); ) {
        N node = nodesIt.next();
        DotGraphNode dotnode = canvas.getNode(namer.getName(node));
        String nodeLabel = null;
        if (node instanceof DominatorNode) {
            node = ((DominatorNode<N>) node).getGode();
        }
        if (printer == null) {
            nodeLabel = node.toString();
        } else {
            if (node instanceof Unit) {
                ((Unit) node).toString(printer);
                String targetLabel = printer.labels().get(node);
                if (targetLabel == null) {
                    nodeLabel = printer.toString();
                } else {
                    nodeLabel = targetLabel + ": " + printer.toString();
                }
            } else if (node instanceof Block) {
                Iterator<Unit> units = ((Block) node).iterator();
                StringBuffer buffer = new StringBuffer();
                while (units.hasNext()) {
                    Unit unit = units.next();
                    String targetLabel = (String) printer.labels().get(unit);
                    if (targetLabel != null) {
                        buffer.append(targetLabel).append(":\\n");
                    }
                    unit.toString(printer);
                    buffer.append(printer.toString()).append("\\l");
                }
                nodeLabel = buffer.toString();
            } else {
                nodeLabel = node.toString();
            }
        }
        dotnode.setLabel(nodeLabel);
    }
}
Also used : DominatorNode(soot.toolkits.graph.DominatorNode) Block(soot.toolkits.graph.Block) DotGraphNode(soot.util.dot.DotGraphNode)

Aggregations

Block (soot.toolkits.graph.Block)3 DominatorNode (soot.toolkits.graph.DominatorNode)3 DotGraphNode (soot.util.dot.DotGraphNode)1