add graphviz caller utility
This commit is contained in:
@ -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.";
|
||||
}
|
||||
|
@ -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.";
|
||||
}
|
||||
|
28
src/main/java/util/GraphvizCaller.java
Normal file
28
src/main/java/util/GraphvizCaller.java
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user