use uuids for graphviz printing
This commit is contained in:
@ -107,8 +107,9 @@ public final class DataFlowGraph implements Iterable<DataFlowNode> {
|
|||||||
.append("node[shape=Mrecord]\n");
|
.append("node[shape=Mrecord]\n");
|
||||||
|
|
||||||
for (DataFlowNode node : this.dataFlowNodes) {
|
for (DataFlowNode node : this.dataFlowNodes) {
|
||||||
dot.append(node.getId())
|
dot.append("\"")
|
||||||
.append(" [label=\"{<f0> ")
|
.append(node.getId())
|
||||||
|
.append("\" [label=\"{<f0> ")
|
||||||
.append(this.dataFlowNodes.indexOf(node))
|
.append(this.dataFlowNodes.indexOf(node))
|
||||||
.append("|<f1> ")
|
.append("|<f1> ")
|
||||||
.append(node.getInst())
|
.append(node.getInst())
|
||||||
@ -118,13 +119,13 @@ public final class DataFlowGraph implements Iterable<DataFlowNode> {
|
|||||||
dot.append("START[label=\"START\"];\n")
|
dot.append("START[label=\"START\"];\n")
|
||||||
.append("END[label=\"END\"];\n");
|
.append("END[label=\"END\"];\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(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");
|
||||||
|
|
||||||
for (DataFlowNode node : this.dataFlowNodes) {
|
for (DataFlowNode node : this.dataFlowNodes) {
|
||||||
for (DataFlowNode successor : node.getSuccessorSet()) {
|
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import java.util.Collections;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -15,7 +16,7 @@ import java.util.stream.Collectors;
|
|||||||
public final class DataFlowNode {
|
public final class DataFlowNode {
|
||||||
|
|
||||||
// General graph structure information
|
// General graph structure information
|
||||||
private final String id;
|
private final UUID id;
|
||||||
private final Set<DataFlowNode> predecessors;
|
private final Set<DataFlowNode> predecessors;
|
||||||
private final Set<DataFlowNode> successors;
|
private final Set<DataFlowNode> successors;
|
||||||
|
|
||||||
@ -46,7 +47,7 @@ public final class DataFlowNode {
|
|||||||
*/
|
*/
|
||||||
private final Set<String> out;
|
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.id = id;
|
||||||
this.inst = inst;
|
this.inst = inst;
|
||||||
this.use = use;
|
this.use = use;
|
||||||
@ -80,7 +81,7 @@ public final class DataFlowNode {
|
|||||||
|
|
||||||
// Getters, Setters
|
// Getters, Setters
|
||||||
|
|
||||||
public String getId() {
|
public UUID getId() {
|
||||||
return this.id;
|
return this.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,8 +78,9 @@ public final class InterferenceGraph implements Iterable<InterferenceNode> {
|
|||||||
.append("node[shape=Mrecord]\n");
|
.append("node[shape=Mrecord]\n");
|
||||||
|
|
||||||
for (InterferenceNode node : this.interferenceNodes) {
|
for (InterferenceNode node : this.interferenceNodes) {
|
||||||
dot.append(node.getSymbol())
|
dot.append("\"")
|
||||||
.append(" [label=\"{<f0> Symbol: ")
|
.append(node.getId())
|
||||||
|
.append("\" [label=\"{<f0> Symbol: ")
|
||||||
.append(node.getSymbol())
|
.append(node.getSymbol())
|
||||||
.append("|<f1> Color: ")
|
.append("|<f1> Color: ")
|
||||||
.append(node.getColor())
|
.append(node.getColor())
|
||||||
@ -88,10 +89,10 @@ public final class InterferenceGraph implements Iterable<InterferenceNode> {
|
|||||||
|
|
||||||
for (InterferenceNode node : this.interferenceNodes) {
|
for (InterferenceNode node : this.interferenceNodes) {
|
||||||
for (InterferenceNode neigh : node.getNeighbourSet()) {
|
for (InterferenceNode neigh : node.getNeighbourSet()) {
|
||||||
if (!dot.toString().contains(neigh.getSymbol() + " -> " + node.getSymbol())) {
|
if (!dot.toString().contains(neigh.getId() + "\" -> \"" + node.getId())) {
|
||||||
// No double lines
|
// 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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,15 @@ import java.util.Collections;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Repräsentiert eine Variable und ihre Farbe im Interferenzgraph.
|
* Repräsentiert eine Variable und ihre Farbe im Interferenzgraph.
|
||||||
*/
|
*/
|
||||||
public class InterferenceNode {
|
public class InterferenceNode {
|
||||||
|
|
||||||
|
private final UUID id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Der Name der Variable.
|
* Der Name der Variable.
|
||||||
*/
|
*/
|
||||||
@ -26,6 +29,7 @@ public class InterferenceNode {
|
|||||||
private int color;
|
private int color;
|
||||||
|
|
||||||
public InterferenceNode(String symbol) {
|
public InterferenceNode(String symbol) {
|
||||||
|
this.id = UUID.randomUUID();
|
||||||
this.symbol = symbol;
|
this.symbol = symbol;
|
||||||
this.color = 0;
|
this.color = 0;
|
||||||
this.neighbours = new HashSet<>();
|
this.neighbours = new HashSet<>();
|
||||||
@ -37,6 +41,10 @@ public class InterferenceNode {
|
|||||||
|
|
||||||
// Getters, Setters
|
// Getters, Setters
|
||||||
|
|
||||||
|
public UUID getId() {
|
||||||
|
return this.id;
|
||||||
|
}
|
||||||
|
|
||||||
public String getSymbol() {
|
public String getSymbol() {
|
||||||
return this.symbol;
|
return this.symbol;
|
||||||
}
|
}
|
||||||
|
@ -8,12 +8,13 @@ import java.util.List;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class FlowBasicBlock implements Iterable<FlowInstruction> {
|
public class FlowBasicBlock implements Iterable<FlowInstruction> {
|
||||||
|
|
||||||
// Graph structure information
|
// Graph structure information
|
||||||
private final String id;
|
private final UUID id;
|
||||||
private final Set<FlowBasicBlock> predecessors;
|
private final Set<FlowBasicBlock> predecessors;
|
||||||
private final Set<FlowBasicBlock> successors;
|
private final Set<FlowBasicBlock> successors;
|
||||||
|
|
||||||
@ -35,7 +36,7 @@ public class FlowBasicBlock implements Iterable<FlowInstruction> {
|
|||||||
|
|
||||||
public FlowBasicBlock(String label) {
|
public FlowBasicBlock(String label) {
|
||||||
this.label = label;
|
this.label = label;
|
||||||
this.id = String.valueOf(System.nanoTime());
|
this.id = UUID.randomUUID();
|
||||||
this.instructions = new ArrayList<>();
|
this.instructions = new ArrayList<>();
|
||||||
this.predecessors = new HashSet<>();
|
this.predecessors = new HashSet<>();
|
||||||
this.successors = new HashSet<>();
|
this.successors = new HashSet<>();
|
||||||
@ -55,7 +56,7 @@ public class FlowBasicBlock implements Iterable<FlowInstruction> {
|
|||||||
|
|
||||||
// Geteter, Setter
|
// Geteter, Setter
|
||||||
|
|
||||||
public String getId() {
|
public UUID getId() {
|
||||||
return this.id;
|
return this.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,8 +66,7 @@ public class FlowBasicBlock implements Iterable<FlowInstruction> {
|
|||||||
|
|
||||||
public void addInstruction(String instruction, String... args) {
|
public void addInstruction(String instruction, String... args) {
|
||||||
this.instNr++;
|
this.instNr++;
|
||||||
this.instructions.add(new FlowInstruction(String.valueOf(Long.parseLong(this.id) + this.instNr),
|
this.instructions.add(new FlowInstruction(instruction, args));
|
||||||
instruction, args));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<FlowBasicBlock> getBlockSuccessorSet() {
|
public Set<FlowBasicBlock> getBlockSuccessorSet() {
|
||||||
|
@ -214,8 +214,9 @@ public class FlowGraph implements Iterable<FlowBasicBlock> {
|
|||||||
.append("node[shape=Mrecord]\n");
|
.append("node[shape=Mrecord]\n");
|
||||||
|
|
||||||
for (FlowBasicBlock block : this.basicBlocks) {
|
for (FlowBasicBlock block : this.basicBlocks) {
|
||||||
dot.append(block.getId())
|
dot.append("\"")
|
||||||
.append(" [label=\"{<f0> ")
|
.append(block.getId())
|
||||||
|
.append("\" [label=\"{<f0> ")
|
||||||
.append(this.basicBlocks.indexOf(block))
|
.append(this.basicBlocks.indexOf(block))
|
||||||
.append(": ")
|
.append(": ")
|
||||||
.append(block.getLabel())
|
.append(block.getLabel())
|
||||||
@ -227,14 +228,14 @@ public class FlowGraph implements Iterable<FlowBasicBlock> {
|
|||||||
dot.append("START[label=\"START\"];\n")
|
dot.append("START[label=\"START\"];\n")
|
||||||
.append("END[label=\"END\"];\n");
|
.append("END[label=\"END\"];\n");
|
||||||
|
|
||||||
dot.append("START -> ").append(this.basicBlocks.get(0).getId()).append(";\n");
|
dot.append("START -> \"").append(this.basicBlocks.get(0).getId()).append("\";\n");
|
||||||
dot.append(currentBlock.get().getId()).append(" -> END;\n");
|
dot.append("\"").append(currentBlock.get().getId()).append("\" -> END;\n");
|
||||||
|
|
||||||
for (FlowBasicBlock block : this.basicBlocks) {
|
for (FlowBasicBlock block : this.basicBlocks) {
|
||||||
// Successors
|
// Successors
|
||||||
|
|
||||||
for (FlowBasicBlock successor : block.getBlockSuccessorSet()) {
|
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
package codegen.flowgraph;
|
package codegen.flowgraph;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Repräsentiert eine Instruction im {@link FlowGraph}.
|
* Repräsentiert eine Instruction im {@link FlowGraph}.
|
||||||
*/
|
*/
|
||||||
public class FlowInstruction {
|
public class FlowInstruction {
|
||||||
|
|
||||||
private final String id;
|
private final UUID id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Die Instruction ist der Jasmin-Assembler Befehl.
|
* Die Instruction ist der Jasmin-Assembler Befehl.
|
||||||
@ -13,13 +15,13 @@ public class FlowInstruction {
|
|||||||
private final String instruction;
|
private final String instruction;
|
||||||
private final String[] args;
|
private final String[] args;
|
||||||
|
|
||||||
public FlowInstruction(String id, String instruction, String... args) {
|
public FlowInstruction(String instruction, String... args) {
|
||||||
this.id = id;
|
this.id = UUID.randomUUID();
|
||||||
this.instruction = instruction;
|
this.instruction = instruction;
|
||||||
this.args = args;
|
this.args = args;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId() {
|
public UUID getId() {
|
||||||
return this.id;
|
return this.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user