use uuids for graphviz printing

This commit is contained in:
ChUrl
2021-02-04 20:16:54 +01:00
parent 5c27fe4cb6
commit 3810785ae7
7 changed files with 40 additions and 26 deletions

View File

@ -107,8 +107,9 @@ public final class DataFlowGraph implements Iterable<DataFlowNode> {
.append("node[shape=Mrecord]\n");
for (DataFlowNode node : this.dataFlowNodes) {
dot.append(node.getId())
.append(" [label=\"{<f0> ")
dot.append("\"")
.append(node.getId())
.append("\" [label=\"{<f0> ")
.append(this.dataFlowNodes.indexOf(node))
.append("|<f1> ")
.append(node.getInst())
@ -118,13 +119,13 @@ public final class DataFlowGraph implements Iterable<DataFlowNode> {
dot.append("START[label=\"START\"];\n")
.append("END[label=\"END\"];\n");
dot.append("START -> ").append(this.dataFlowNodes.get(0).getId()).append(";\n");
dot.append(this.dataFlowNodes.get(this.dataFlowNodes.size() - 1).getId()).append(" -> END;\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");
for (DataFlowNode node : this.dataFlowNodes) {
for (DataFlowNode successor : node.getSuccessorSet()) {
dot.append(node.getId()).append(" -> ").append(successor.getId()).append(";\n");
dot.append("\"").append(node.getId()).append("\" -> \"").append(successor.getId()).append("\";\n");
}
}

View File

@ -7,6 +7,7 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
/**
@ -15,7 +16,7 @@ import java.util.stream.Collectors;
public final class DataFlowNode {
// General graph structure information
private final String id;
private final UUID id;
private final Set<DataFlowNode> predecessors;
private final Set<DataFlowNode> successors;
@ -46,7 +47,7 @@ public final class DataFlowNode {
*/
private final Set<String> out;
private DataFlowNode(String id, String inst, String use, String def) {
private DataFlowNode(UUID id, String inst, String use, String def) {
this.id = id;
this.inst = inst;
this.use = use;
@ -80,7 +81,7 @@ public final class DataFlowNode {
// Getters, Setters
public String getId() {
public UUID getId() {
return this.id;
}

View File

@ -78,8 +78,9 @@ public final class InterferenceGraph implements Iterable<InterferenceNode> {
.append("node[shape=Mrecord]\n");
for (InterferenceNode node : this.interferenceNodes) {
dot.append(node.getSymbol())
.append(" [label=\"{<f0> Symbol: ")
dot.append("\"")
.append(node.getId())
.append("\" [label=\"{<f0> Symbol: ")
.append(node.getSymbol())
.append("|<f1> Color: ")
.append(node.getColor())
@ -88,10 +89,10 @@ public final class InterferenceGraph implements Iterable<InterferenceNode> {
for (InterferenceNode node : this.interferenceNodes) {
for (InterferenceNode neigh : node.getNeighbourSet()) {
if (!dot.toString().contains(neigh.getSymbol() + " -> " + node.getSymbol())) {
if (!dot.toString().contains(neigh.getId() + "\" -> \"" + node.getId())) {
// No double lines
dot.append(node.getSymbol()).append(" -> ").append(neigh.getSymbol()).append(" [arrowhead=\"none\"];\n");
dot.append("\"").append(node.getId()).append("\" -> \"").append(neigh.getId()).append("\" [arrowhead=\"none\"];\n");
}
}
}

View File

@ -4,12 +4,15 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
/**
* Repräsentiert eine Variable und ihre Farbe im Interferenzgraph.
*/
public class InterferenceNode {
private final UUID id;
/**
* Der Name der Variable.
*/
@ -26,6 +29,7 @@ public class InterferenceNode {
private int color;
public InterferenceNode(String symbol) {
this.id = UUID.randomUUID();
this.symbol = symbol;
this.color = 0;
this.neighbours = new HashSet<>();
@ -37,6 +41,10 @@ public class InterferenceNode {
// Getters, Setters
public UUID getId() {
return this.id;
}
public String getSymbol() {
return this.symbol;
}

View File

@ -8,12 +8,13 @@ import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
public class FlowBasicBlock implements Iterable<FlowInstruction> {
// Graph structure information
private final String id;
private final UUID id;
private final Set<FlowBasicBlock> predecessors;
private final Set<FlowBasicBlock> successors;
@ -35,7 +36,7 @@ public class FlowBasicBlock implements Iterable<FlowInstruction> {
public FlowBasicBlock(String label) {
this.label = label;
this.id = String.valueOf(System.nanoTime());
this.id = UUID.randomUUID();
this.instructions = new ArrayList<>();
this.predecessors = new HashSet<>();
this.successors = new HashSet<>();
@ -55,7 +56,7 @@ public class FlowBasicBlock implements Iterable<FlowInstruction> {
// Geteter, Setter
public String getId() {
public UUID getId() {
return this.id;
}
@ -65,8 +66,7 @@ public class FlowBasicBlock implements Iterable<FlowInstruction> {
public void addInstruction(String instruction, String... args) {
this.instNr++;
this.instructions.add(new FlowInstruction(String.valueOf(Long.parseLong(this.id) + this.instNr),
instruction, args));
this.instructions.add(new FlowInstruction(instruction, args));
}
public Set<FlowBasicBlock> getBlockSuccessorSet() {

View File

@ -214,8 +214,9 @@ public class FlowGraph implements Iterable<FlowBasicBlock> {
.append("node[shape=Mrecord]\n");
for (FlowBasicBlock block : this.basicBlocks) {
dot.append(block.getId())
.append(" [label=\"{<f0> ")
dot.append("\"")
.append(block.getId())
.append("\" [label=\"{<f0> ")
.append(this.basicBlocks.indexOf(block))
.append(": ")
.append(block.getLabel())
@ -227,14 +228,14 @@ public class FlowGraph implements Iterable<FlowBasicBlock> {
dot.append("START[label=\"START\"];\n")
.append("END[label=\"END\"];\n");
dot.append("START -> ").append(this.basicBlocks.get(0).getId()).append(";\n");
dot.append(currentBlock.get().getId()).append(" -> END;\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) {
// Successors
for (FlowBasicBlock successor : block.getBlockSuccessorSet()) {
dot.append(block.getId()).append(" -> ").append(successor.getId()).append(";\n");
dot.append("\"").append(block.getId()).append("\" -> \"").append(successor.getId()).append("\";\n");
}
}

View File

@ -1,11 +1,13 @@
package codegen.flowgraph;
import java.util.UUID;
/**
* Repräsentiert eine Instruction im {@link FlowGraph}.
*/
public class FlowInstruction {
private final String id;
private final UUID id;
/**
* Die Instruction ist der Jasmin-Assembler Befehl.
@ -13,13 +15,13 @@ public class FlowInstruction {
private final String instruction;
private final String[] args;
public FlowInstruction(String id, String instruction, String... args) {
this.id = id;
public FlowInstruction(String instruction, String... args) {
this.id = UUID.randomUUID();
this.instruction = instruction;
this.args = args;
}
public String getId() {
public UUID getId() {
return this.id;
}