Skip to content
CFGGraph.java 731 B
Newer Older
Javier Costa's avatar
Javier Costa committed
package tfm.graphs;
Javier Costa's avatar
Javier Costa committed

import edg.graphlib.Arrow;
Javier Costa's avatar
Javier Costa committed
import tfm.arcs.cfg.ControlFlowArc;
import tfm.nodes.CFGVertex;
Javier Costa's avatar
Javier Costa committed

public abstract class CFGGraph extends Graph<CFGVertex> {

    public CFGGraph() {
        super();
        setRootVertex(new CFGVertex(VertexId.getVertexId(), getRootNodeData()));
    }

    @Override
    public CFGVertex addVertex(String instruction) {
        CFGVertex vertex = new CFGVertex(VertexId.getVertexId(), instruction);
        this.addVertex(vertex);

        return vertex;
    }

    protected abstract String getRootNodeData();

    @SuppressWarnings("unchecked")
    public void addControlFlowEdge(CFGVertex from, CFGVertex to) {
        super.addEdge((Arrow) new ControlFlowArc(from, to));
    }
}