add graphviz caller utility

This commit is contained in:
ChUrl
2021-01-31 17:46:36 +01:00
parent bdf1376675
commit 91e26d0a9d
3 changed files with 33 additions and 39 deletions

View File

@ -3,11 +3,8 @@ package codegen.analysis.dataflow;
import codegen.flowgraph.FlowBasicBlock;
import codegen.flowgraph.FlowGraph;
import codegen.flowgraph.FlowInstruction;
import util.GraphvizCaller;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
@ -128,21 +125,7 @@ public final class DataFlowGraph implements Iterable<DataFlowNode> {
dot.append("}");
final String dotOut = dot.toString();
final Path dotFile = Paths.get(System.getProperty("user.dir") + "/DataFlowGraph.dot");
try {
Files.writeString(dotFile, dotOut);
} catch (IOException e) {
e.printStackTrace();
}
final ProcessBuilder dotCompile = new ProcessBuilder("dot", "-Tsvg", "-oDataFlowGraph.svg", "DataFlowGraph.dot");
try {
dotCompile.start();
} catch (IOException e) {
e.printStackTrace();
}
GraphvizCaller.callGraphviz(dot, "DataFlowGraph");
return "Finished.";
}

View File

@ -2,12 +2,9 @@ package codegen.analysis.liveness;
import codegen.analysis.dataflow.DataFlowGraph;
import codegen.analysis.dataflow.DataFlowNode;
import util.GraphvizCaller;
import util.Logger;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@ -89,7 +86,7 @@ public final class InterferenceGraph implements Iterable<InterferenceNode> {
for (InterferenceNode neigh : node.getNeighbourSet()) {
if (!dot.toString().contains(neigh.getSymbol() + " -> " + node.getSymbol())) {
// No double lines
dot.append(node.getSymbol()).append(" -> ").append(neigh.getSymbol()).append(" [arrowhead=\"none\"];\n");
}
}
@ -97,21 +94,7 @@ public final class InterferenceGraph implements Iterable<InterferenceNode> {
dot.append("}");
final String dotOut = dot.toString();
final Path dotFile = Paths.get(System.getProperty("user.dir") + "/InterferenceGraph.dot");
try {
Files.writeString(dotFile, dotOut);
} catch (IOException e) {
e.printStackTrace();
}
final ProcessBuilder dotCompile = new ProcessBuilder("dot", "-Tsvg", "-oInterferenceGraph.svg", "InterferenceGraph.dot");
try {
dotCompile.start();
} catch (IOException e) {
e.printStackTrace();
}
GraphvizCaller.callGraphviz(dot, "InterferenceGraph");
return "Finished.";
}

View File

@ -0,0 +1,28 @@
package util;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public final class GraphvizCaller {
private GraphvizCaller() {}
public static void callGraphviz(CharSequence dot, String filename) {
final Path dotFile = Paths.get(System.getProperty("user.dir") + "/" + filename + ".dot");
try {
Files.writeString(dotFile, dot);
} catch (IOException e) {
e.printStackTrace();
}
final ProcessBuilder dotCompile = new ProcessBuilder("dot", "-Tsvg", "-o" + filename + ".svg", filename + ".dot");
try {
dotCompile.start();
} catch (IOException e) {
e.printStackTrace();
}
}
}