Commit f02c0088 authored by Carlos Galindo's avatar Carlos Galindo
Browse files

Support for the PPDG (building only)

parent 65be4201
Loading
Loading
Loading
Loading
+11 −7
Original line number Diff line number Diff line
@@ -5,20 +5,24 @@ package tfm.exec;
 * <br/>
 * The <b>Control Flow Graph</b> has different variations, each with its own name or code.
 * <ul>
 *     <li>CFG</li>: the original proposal. It works well with statements, loops and branch instructions.
 *     <li>ACFG</li>: the <it>augmented</it> CFG; adds non-executable edges to represent unconditional
 *     jumps such as {@code break}, {@code return}, {@code switch} and much more.
 *     <li><b>CFG</b>: the original proposal. It works well with statements, loops and branch instructions.</li>
 *     <li><b>ACFG</b>: the <it>augmented</it> CFG; adds non-executable edges to represent unconditional
 *     jumps such as {@code break}, {@code return}, {@code switch} and much more.</li>
 * </ul>
 * The <b>Program Dependence Graph</b> has variations in a similar fashion.
 * <ul>
 *     <li>PDG</li>: based on the CFG, it computes control and data dependence to connect the nodes.
 *     <li>APDG</li>: similar to the PDG, but based on the ACFG. The non-executable edges are ignored
 *     when computing data dependencies.
 *     <li><b>PDG</b>: based on the CFG, it computes control and data dependence to connect the nodes.</li>
 *     <li><b>APDG</b>: similar to the PDG, but based on the ACFG. The non-executable edges are ignored
 *     when computing data dependencies.</li>
 *     <li><b>PPDG</b>: combines the PDG and the APDG; (1) when computing control dependencies it uses the ACFG
 *     to find a node's successors, but the CFG for computing the postdominance, and (2) modifies the traversal
 *     of the graph, disallowing the traversal of edges that reach a pseudo-predicate (those that are the source
 *     of non-executable edges) if the pseudo-predicate is not the slicing criterion.</li>
 * </ul>
 */
public class Config {
    public static final int CFG = 0, ACFG = 1;
    public static final int PDG = 0, APDG = 1;
    public static final int PDG = 0, APDG = 1, PPDG = 2;

    public static int CFG_TYPE = CFG;
    public static int PDG_TYPE = PDG;
+0 −7
Original line number Diff line number Diff line
@@ -46,13 +46,6 @@ public class PDGGraph extends Graph {
        return "Entry";
    }

    public GraphNode<?> addNode(GraphNode<?> node) {
        GraphNode<?> vertex = new GraphNode<>(node);
        super.addVertex(vertex);

        return vertex;
    }

    @Override
    public <ASTNode extends Node> GraphNode<ASTNode> addNode(String instruction, ASTNode node) {
        return addNode(getNextVertexId(), instruction, node);
+6 −1
Original line number Diff line number Diff line
@@ -2,11 +2,13 @@ package tfm.visitors.pdg;

import tfm.arcs.Arc;
import tfm.arcs.data.ArcData;
import tfm.exec.Config;
import tfm.graphs.CFGGraph;
import tfm.graphs.PDGGraph;
import tfm.nodes.GraphNode;

import java.util.*;
import java.util.stream.Collectors;

/**
 * A simple but slow finder of control dependencies.
@@ -65,7 +67,7 @@ public class ControlDependencyBuilder {
            return;
        GraphNode<?> clone = new GraphNode<>(node.getId(), node.getData(), node.getAstNode());
        nodeMap.put(node, clone);
        pdg.addNode(clone);
        pdg.addVertex(clone);
    }

    public static boolean hasControlDependence(GraphNode<?> a, GraphNode<?> b) {
@@ -92,6 +94,9 @@ public class ControlDependencyBuilder {
        if (a.equals(b) || visited.contains(a))
            return true;
        List<Arc<ArcData>> outgoing = a.getOutgoingArcs();
        // Limit the traversal if it is a PPDG
        if (Config.PDG_TYPE == Config.PPDG)
            outgoing = outgoing.stream().filter(Arc::isExecutableControlFlowArrow).collect(Collectors.toList());
        // Stop w/ failure if there are no edges to traverse from a
        if (outgoing.size() == 0)
            return false;