Skip to content
CFGLog.java 1.08 KiB
Newer Older
package tfm.exec;

import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.Node;
import guru.nidi.graphviz.engine.Format;
import guru.nidi.graphviz.engine.Graphviz;
import tfm.graphs.CFGGraph;
import tfm.graphs.Graph;
Javier Costa's avatar
Javier Costa committed
import tfm.graphs.PDGGraph;
import tfm.visitors.CFGVisitor;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;

public class CFGLog extends GraphLog<CFGGraph, CFGVisitor> {

Javier Costa's avatar
Javier Costa committed
    public CFGLog() {

    }

    public CFGLog(CFGGraph graph) {
        this.graph = graph;
    }

    @Override
    public void visit(Node node) {
Javier Costa's avatar
Javier Costa committed
        this.graph = new CFGGraph();

        this.visitor = new CFGVisitor(graph);

        node.accept(visitor, null);
    }

    @Override
    public void generatePNGs() throws IOException {
        Graphviz.fromString(graph.toGraphvizRepresentation())
                .render(Format.PNG)
                .toFile(new File("./out/cfg.png"));
    }

    @Override
    public void openVisualRepresentation() throws IOException {
        new ProcessBuilder(Arrays.asList("xdg-open", "./out/cfg.png")).start();
    }
}