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<>(); } @Override 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); } }