From 35eae1492c94e353ba8a1a52bfbae9313808b357 Mon Sep 17 00:00:00 2001 From: bd-912 Date: Sat, 20 Apr 2024 18:22:49 -0600 Subject: CFG Class cleanup/reordering --- cfg/CFGNode.java | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 cfg/CFGNode.java (limited to 'cfg/CFGNode.java') diff --git a/cfg/CFGNode.java b/cfg/CFGNode.java new file mode 100644 index 0000000..e604753 --- /dev/null +++ b/cfg/CFGNode.java @@ -0,0 +1,73 @@ +package cfg; + +import misc.*; +import cs132.vapor.ast.*; + +import java.util.*; + +public class CFGNode { + + private Node instruction; + private ArrayList sources; + private ArrayList dests; + protected Set reaching; + protected Set liveness; + + public CFGNode(Node instruction) { + this.instruction = instruction; + this.sources = new ArrayList<>(); + this.dests = new ArrayList<>(); + this.reaching = new HashSet<>(); + this.liveness = new HashSet<>(); + } + + public String toString() { + return String.format("L%d", + this.instruction.sourcePos.line); + } + + /** + * For if we only have a line + * number. (VBranch issues) + */ + public boolean equals(Object other) { + return (other instanceof CFGNode && + (((CFGNode) other).instruction == + this.instruction)) || + (other instanceof Node && + (((Node) other).sourcePos == + this.instruction.sourcePos)) || + (other instanceof Integer && + (((Integer) other) + .equals(this.instruction.sourcePos.line))); + } + + protected void addSource(CFGNode node) { + this.sources.add(node); + } + + protected void addDest(CFGNode node) { + this.dests.add(node); + } + + public Node getInstruction() { + return this.instruction; + } + + public List getSources() { + return Collections.unmodifiableList(this.sources); + } + + public List getDests() { + return Collections.unmodifiableList(this.dests); + } + + public Set getReaching() { + return Collections.unmodifiableSet(this.reaching); + } + + public Set getLiveness() { + return Collections.unmodifiableSet(this.liveness); + } + +} -- cgit v1.2.3