summaryrefslogtreecommitdiff
path: root/cfg/CFGNode.java
diff options
context:
space:
mode:
authorbd-912 <bdunahu@colostate.edu>2024-04-20 18:22:49 -0600
committerbd-912 <bdunahu@colostate.edu>2024-04-20 18:22:49 -0600
commit35eae1492c94e353ba8a1a52bfbae9313808b357 (patch)
treeeb30b12ae142a23a9837cfd097c1556828c95c44 /cfg/CFGNode.java
parent38ef4ec52804876ba0a3daef3a2d1817f17bc1e5 (diff)
CFG Class cleanup/reordering
Diffstat (limited to 'cfg/CFGNode.java')
-rw-r--r--cfg/CFGNode.java73
1 files changed, 73 insertions, 0 deletions
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<CFGNode> sources;
+ private ArrayList<CFGNode> dests;
+ protected Set<String> reaching;
+ protected Set<String> 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<CFGNode> getSources() {
+ return Collections.unmodifiableList(this.sources);
+ }
+
+ public List<CFGNode> getDests() {
+ return Collections.unmodifiableList(this.dests);
+ }
+
+ public Set<String> getReaching() {
+ return Collections.unmodifiableSet(this.reaching);
+ }
+
+ public Set<String> getLiveness() {
+ return Collections.unmodifiableSet(this.liveness);
+ }
+
+}