Commit 3705ffac authored by Carlos Galindo's avatar Carlos Galindo
Browse files

Add support for ACFG and APDG

parent 5c2a63ac
Loading
Loading
Loading
Loading
+13 −7
Original line number Diff line number Diff line
@@ -12,10 +12,16 @@ public abstract class Arc<D extends ArcData> extends edg.graphlib.Arrow<String,
        super((edg.graphlib.Vertex<String, D>) from, (edg.graphlib.Vertex<String, D>) to);
    }

    /** @see tfm.arcs.cfg.ControlFlowArc */
    public abstract boolean isControlFlowArrow();

    /** @see tfm.arcs.cfg.ControlFlowArc.NonExecutable */
    public abstract boolean isExecutableControlFlowArrow();

    /** @see tfm.arcs.pdg.ControlDependencyArc */
    public abstract boolean isControlDependencyArrow();

    /** @see tfm.arcs.pdg.DataDependencyArc */
    public abstract boolean isDataDependencyArrow();

    @Override
@@ -28,8 +34,8 @@ public abstract class Arc<D extends ArcData> extends edg.graphlib.Arrow<String,
    }

    public String toGraphvizRepresentation() {
        GraphNode from = (GraphNode) getFrom();
        GraphNode to = (GraphNode) getTo();
        GraphNode<?> from = (GraphNode<?>) getFrom();
        GraphNode<?> to = (GraphNode<?>) getTo();

        return String.format("%s -> %s",
                from.getId(),
@@ -58,12 +64,12 @@ public abstract class Arc<D extends ArcData> extends edg.graphlib.Arrow<String,
        if (!(o instanceof Arc))
            return false;

        Arc arc = (Arc) o;
        Arc<?> arc = (Arc<?>) o;

        GraphNode from = (GraphNode) arc.getFrom();
        GraphNode from2 = (GraphNode) getFrom();
        GraphNode to = (GraphNode) getTo();
        GraphNode to2 = (GraphNode) arc.getTo();
        GraphNode<?> from = (GraphNode<?>) arc.getFrom();
        GraphNode<?> from2 = (GraphNode<?>) getFrom();
        GraphNode<?> to = (GraphNode<?>) getTo();
        GraphNode<?> to2 = (GraphNode<?>) arc.getTo();

        return Objects.equals(arc.getData(), getData()) &&
                Objects.equals(from.getId(), from2.getId()) &&
+44 −1
Original line number Diff line number Diff line
@@ -4,9 +4,14 @@ import tfm.arcs.Arc;
import tfm.arcs.data.VoidArcData;
import tfm.nodes.GraphNode;

/**
 * An edge of the {@link tfm.graphs.CFGGraph}, representing the direct
 * flow of control. It connects two instructions if, when the source
 * is executed, one of the possible next instructions is the destination.
 */
public class ControlFlowArc extends Arc<VoidArcData> {

    public ControlFlowArc(GraphNode from, GraphNode to) {
    public ControlFlowArc(GraphNode<?> from, GraphNode<?> to) {
        super(from, to);
    }

@@ -15,6 +20,11 @@ public class ControlFlowArc extends Arc<VoidArcData> {
        return true;
    }

    @Override
    public boolean isExecutableControlFlowArrow() {
        return true;
    }

    @Override
    public boolean isControlDependencyArrow() {
        return false;
@@ -33,4 +43,37 @@ public class ControlFlowArc extends Arc<VoidArcData> {
        );
    }

    /**
     * Represents a non-executable control flow arc, used within the {@link tfm.exec.Config#ACFG}.
     * Initially it had the following meaning: connecting a statement with
     * the following one as if the source was a {@code nop} command (no operation).
     * <br/>
     * It is used to improve control dependence, and it should be skipped when
     * computing data dependence and other analyses.
     */
    public final static class NonExecutable extends ControlFlowArc {
        public NonExecutable(GraphNode<?> from, GraphNode<?> to) {
            super(from, to);
        }

        @Override
        public String toString() {
            return "NonExecutable" + super.toString();
        }

        @Override
        public boolean isExecutableControlFlowArrow() {
            return false;
        }

        @Override
        public String toGraphvizRepresentation() {
            return super.toGraphvizRepresentation() + "[style = dashed]";
        }

        @Override
        public boolean equals(Object o) {
            return o instanceof NonExecutable && super.equals(o);
        }
    }
}
+14 −3
Original line number Diff line number Diff line
@@ -4,9 +4,15 @@ import tfm.arcs.Arc;
import tfm.arcs.data.ArcData;
import tfm.nodes.GraphNode;

/**
 * An arc used in the {@link tfm.graphs.PDGGraph} and {@link tfm.graphs.SDGGraph}
 * used to represent control dependence between two nodes. The traditional definition of
 * control dependence is: a node {@code a} is <it>control dependent</it> on node
 * {@code b} if and only if {@code b} alters the number of times {@code a} is executed.
 */
public class ControlDependencyArc extends Arc<ArcData> {

    public ControlDependencyArc(GraphNode from, GraphNode to) {
    public ControlDependencyArc(GraphNode<?> from, GraphNode<?> to) {
        super(from, to);
    }

@@ -15,6 +21,11 @@ public class ControlDependencyArc extends Arc<ArcData> {
        return false;
    }

    @Override
    public boolean isExecutableControlFlowArrow() {
        return false;
    }

    @Override
    public boolean isControlDependencyArrow() {
        return true;
@@ -28,8 +39,8 @@ public class ControlDependencyArc extends Arc<ArcData> {
    @Override
    public String toString() {
        return String.format("ControlDependencyArc{%s -> %s}",
                ((GraphNode) getFrom()).getId(),
                ((GraphNode) getTo()).getId()
                ((GraphNode<?>) getFrom()).getId(),
                ((GraphNode<?>) getTo()).getId()
        );
    }
}
+13 −1
Original line number Diff line number Diff line
@@ -8,9 +8,16 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * An arc used in the {@link tfm.graphs.PDGGraph} and {@link tfm.graphs.SDGGraph},
 * representing the declaration of some data linked to its usage (of that value).
 * There is data dependency between two nodes if and only if (1) the source <it>may</it>
 * declare a variable, (2) the destination <it>may</it> use it, and (3) there is a
 * path between the nodes where the variable is not redefined.
 */
public class DataDependencyArc extends Arc<VariableArcData> {

    public DataDependencyArc(GraphNode from, GraphNode to, String variable, String... variables) {
    public DataDependencyArc(GraphNode<?> from, GraphNode<?> to, String variable, String... variables) {
        super(from, to);

        List<String> variablesList = new ArrayList<>(variables.length + 1);
@@ -28,6 +35,11 @@ public class DataDependencyArc extends Arc<VariableArcData> {
        return false;
    }

    @Override
    public boolean isExecutableControlFlowArrow() {
        return false;
    }

    @Override
    public boolean isControlDependencyArrow() {
        return false;
+16 −0
Original line number Diff line number Diff line
package tfm.exec;

/**
 * Configuration for the different graphs created in the process of program slicing.
 * <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.
 * </ul>
 */
public class Config {
    public static final int CFG = 0, ACFG = 1;
    public static int CFG_TYPE = CFG;
}
Loading