summaryrefslogtreecommitdiff
path: root/cfg
diff options
context:
space:
mode:
Diffstat (limited to 'cfg')
-rw-r--r--cfg/CFGNode.java10
-rw-r--r--cfg/ControlFlowGraph.java23
2 files changed, 22 insertions, 11 deletions
diff --git a/cfg/CFGNode.java b/cfg/CFGNode.java
index 5ce39b5..41f2c9c 100644
--- a/cfg/CFGNode.java
+++ b/cfg/CFGNode.java
@@ -10,13 +10,15 @@ public class CFGNode {
private Node instruction;
private ArrayList<CFGNode> sources;
private ArrayList<CFGNode> dests;
- protected Set<String> reaching;
- protected Set<String> liveness;
+ public Set<String> defs;
+ public Set<String> reaching;
+ public Set<String> liveness;
public CFGNode(Node instruction) {
this.instruction = instruction;
this.sources = new ArrayList<>();
this.dests = new ArrayList<>();
+ this.defs = new HashSet<>();
this.reaching = new HashSet<>();
this.liveness = new HashSet<>();
}
@@ -70,4 +72,8 @@ public class CFGNode {
return Collections.unmodifiableSet(this.liveness);
}
+ public Set<String> getDefinitions() {
+ return Collections.unmodifiableSet(this.defs);
+ }
+
}
diff --git a/cfg/ControlFlowGraph.java b/cfg/ControlFlowGraph.java
index c3943a0..49cd2fc 100644
--- a/cfg/ControlFlowGraph.java
+++ b/cfg/ControlFlowGraph.java
@@ -80,6 +80,14 @@ public class ControlFlowGraph {
source.addDest(dest);
dest.addSource(source);
+ for (String var : source.getReaching()) {
+ dest.reaching.add(var);
+ }
+ for (String var : dest.getLiveness()) {
+ if (!source.getDefinitions().contains(var))
+ source.liveness.add(var);
+ }
+
ret += ";";
} else {
MinimalLogger.info(String.format("Skipping duplicate edge for %s",
@@ -89,22 +97,19 @@ public class ControlFlowGraph {
return ret;
}
- public void addReaching(CFGNode n, String s) {
- MinimalLogger.info(String.format("Def \"%s\" at %s",
- s,
- n.toString()));
+ public void addDefinition(CFGNode n, String s) {
+ n.defs.add(s);
n.reaching.add(s);
}
- public void addLiveness(CFGNode n, String s) {
+ public void addReference(CFGNode n, String s) {
if (this.isKnownVar(s)) {
- MinimalLogger.info(String.format("Use \"%s\" at %s",
+ MinimalLogger.info(String.format("\"%s\" referenced at %s",
s,
n.toString()));
+ n.reaching.add(s);
n.liveness.add(s);
- } else
- MinimalLogger.info(String.format("Use \"%s\" not a known variable!",
- s));
+ }
}
public ArrayList<CFGNode> getNodes() {