From b320d02e1dbfa255ac0c919e37f89aa0108edaa5 Mon Sep 17 00:00:00 2001 From: bd-912 Date: Sat, 20 Apr 2024 13:23:01 -0600 Subject: Implement partial reachable tracking in CFG --- vaporize/library/CFGNode.java | 24 ++++++++++++++++++++---- vaporize/library/CFGSimp.java | 18 ++++++++++++++++-- vaporize/library/ControlFlowGraph.java | 6 +++++- 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/vaporize/library/CFGNode.java b/vaporize/library/CFGNode.java index b79ee6b..9d627a0 100644 --- a/vaporize/library/CFGNode.java +++ b/vaporize/library/CFGNode.java @@ -4,18 +4,22 @@ import misc.*; import cs132.vapor.ast.*; import java.util.ArrayList; +import java.util.HashSet; class CFGNode { private Node instruction; private ArrayList sources; private ArrayList dests; + private HashSet reaching; + private ArrayList liveness; private int line; protected CFGNode(Node instruction) { this.instruction = instruction; this.sources = new ArrayList<>(); this.dests = new ArrayList<>(); + this.reaching = new HashSet<>(); this.line = this.instruction.sourcePos.line; } @@ -23,10 +27,6 @@ class CFGNode { return this.instruction.toString(); } - public int hashCode() { - return this.line; - } - /** * For if we only have a line * number. (VBranch issues) @@ -52,6 +52,13 @@ class CFGNode { this.dests.add(node); } + protected void addReaching(String add) { + MinimalLogger.info(String.format("Def %s at %s", + add, + this.line)); + this.reaching.add(add); + } + protected Node getInstruction() { return this.instruction; } @@ -64,4 +71,13 @@ class CFGNode { return this.dests; } + protected HashSet getReaching() { + return this.reaching; + } + + protected int getLine() { + return this.line; + } + + } diff --git a/vaporize/library/CFGSimp.java b/vaporize/library/CFGSimp.java index f85c198..4456d39 100644 --- a/vaporize/library/CFGSimp.java +++ b/vaporize/library/CFGSimp.java @@ -52,6 +52,12 @@ public class CFGSimp extends VInstr.VisitorPR