diff options
Diffstat (limited to 'cfg/CFGNode.java')
-rw-r--r-- | cfg/CFGNode.java | 73 |
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); + } + +} |