improve graphviz printing
This commit is contained in:
@ -116,8 +116,8 @@ public final class DataFlowGraph implements Iterable<DataFlowNode> {
|
|||||||
.append("}\"];\n");
|
.append("}\"];\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
dot.append("START[label=\"START\"];\n")
|
dot.append("START[label=\"START\" shape=box];\n")
|
||||||
.append("END[label=\"END\"];\n");
|
.append("END[label=\"END\" shape=box];\n");
|
||||||
|
|
||||||
dot.append("START -> \"").append(this.dataFlowNodes.get(0).getId()).append("\";\n");
|
dot.append("START -> \"").append(this.dataFlowNodes.get(0).getId()).append("\";\n");
|
||||||
dot.append("\"").append(this.dataFlowNodes.get(this.dataFlowNodes.size() - 1).getId()).append("\" -> END;\n");
|
dot.append("\"").append(this.dataFlowNodes.get(this.dataFlowNodes.size() - 1).getId()).append("\" -> END;\n");
|
||||||
@ -129,6 +129,16 @@ public final class DataFlowGraph implements Iterable<DataFlowNode> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (DataFlowNode node : this.dataFlowNodes) {
|
||||||
|
dot.append("{ rank=same; ");
|
||||||
|
for (DataFlowNode successor : node.getSuccessorSet()) {
|
||||||
|
|
||||||
|
dot.append("\"").append(successor.getId()).append("\", ");
|
||||||
|
}
|
||||||
|
dot.deleteCharAt(dot.lastIndexOf(","));
|
||||||
|
dot.append("}\n");
|
||||||
|
}
|
||||||
|
|
||||||
dot.append("}");
|
dot.append("}");
|
||||||
|
|
||||||
GraphvizCaller.callGraphviz(dot, "DataFlowGraph");
|
GraphvizCaller.callGraphviz(dot, "DataFlowGraph");
|
||||||
|
@ -204,10 +204,6 @@ public class FlowGraph implements Iterable<FlowBasicBlock> {
|
|||||||
public String printToImage() {
|
public String printToImage() {
|
||||||
final Optional<FlowBasicBlock> currentBlock = this.getCurrentBlock();
|
final Optional<FlowBasicBlock> currentBlock = this.getCurrentBlock();
|
||||||
|
|
||||||
if (this.basicBlocks.isEmpty() || currentBlock.isEmpty()) {
|
|
||||||
return "Can't export empty graph: FlowGraph.svg";
|
|
||||||
}
|
|
||||||
|
|
||||||
final StringBuilder dot = new StringBuilder();
|
final StringBuilder dot = new StringBuilder();
|
||||||
|
|
||||||
dot.append("digraph dfd {\n")
|
dot.append("digraph dfd {\n")
|
||||||
@ -225,18 +221,36 @@ public class FlowGraph implements Iterable<FlowBasicBlock> {
|
|||||||
.append("}\"];\n");
|
.append("}\"];\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
dot.append("START[label=\"START\"];\n")
|
dot.append("START[label=\"START\" shape=box];\n")
|
||||||
.append("END[label=\"END\"];\n");
|
.append("END[label=\"END\" shape=box];\n");
|
||||||
|
|
||||||
dot.append("START -> \"").append(this.basicBlocks.get(0).getId()).append("\";\n");
|
|
||||||
dot.append("\"").append(currentBlock.get().getId()).append("\" -> END;\n");
|
|
||||||
|
|
||||||
for (FlowBasicBlock block : this.basicBlocks) {
|
if (!this.basicBlocks.isEmpty() && currentBlock.isPresent()) {
|
||||||
// Successors
|
|
||||||
|
|
||||||
for (FlowBasicBlock successor : block.getBlockSuccessorSet()) {
|
dot.append("START -> \"").append(this.basicBlocks.get(0).getId()).append("\";\n");
|
||||||
dot.append("\"").append(block.getId()).append("\" -> \"").append(successor.getId()).append("\";\n");
|
dot.append("\"").append(currentBlock.get().getId()).append("\" -> END;\n");
|
||||||
|
|
||||||
|
for (FlowBasicBlock block : this.basicBlocks) {
|
||||||
|
// Successors
|
||||||
|
|
||||||
|
for (FlowBasicBlock successor : block.getBlockSuccessorSet()) {
|
||||||
|
dot.append("\"").append(block.getId()).append("\" -> \"").append(successor.getId()).append("\";\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (FlowBasicBlock block : this.basicBlocks) {
|
||||||
|
dot.append("{ rank=same; ");
|
||||||
|
for (FlowBasicBlock successor : block.getBlockSuccessorSet()) {
|
||||||
|
|
||||||
|
dot.append("\"").append(successor.getId()).append("\", ");
|
||||||
|
}
|
||||||
|
dot.deleteCharAt(dot.lastIndexOf(","));
|
||||||
|
dot.append("}\n");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Main-method is empty
|
||||||
|
|
||||||
|
dot.append("START -> END");
|
||||||
}
|
}
|
||||||
|
|
||||||
dot.append("}");
|
dot.append("}");
|
||||||
|
@ -67,9 +67,15 @@ public class SyntaxTree {
|
|||||||
|
|
||||||
dot.append("\"").append(current.getId()).append("\"")
|
dot.append("\"").append(current.getId()).append("\"")
|
||||||
.append(" [label=\"{<f0> ")
|
.append(" [label=\"{<f0> ")
|
||||||
.append(current.getName())
|
.append(current.getName()
|
||||||
|
.replace("\"", "\\\"")
|
||||||
|
.replace("<", "less")
|
||||||
|
.replace(">", "greater"))
|
||||||
.append("|<f1> ")
|
.append("|<f1> ")
|
||||||
.append(current.getValue())
|
.append(current.getValue()
|
||||||
|
.replace("\"", "\\\"")
|
||||||
|
.replace("<", "less")
|
||||||
|
.replace(">", "greater"))
|
||||||
.append("}\"];\n");
|
.append("}\"];\n");
|
||||||
|
|
||||||
current.getChildren().forEach(stack::push);
|
current.getChildren().forEach(stack::push);
|
||||||
|
Reference in New Issue
Block a user