summaryrefslogtreecommitdiff
path: root/vaporize/library/LIRDict.java
diff options
context:
space:
mode:
Diffstat (limited to 'vaporize/library/LIRDict.java')
-rw-r--r--vaporize/library/LIRDict.java49
1 files changed, 49 insertions, 0 deletions
diff --git a/vaporize/library/LIRDict.java b/vaporize/library/LIRDict.java
new file mode 100644
index 0000000..b32647c
--- /dev/null
+++ b/vaporize/library/LIRDict.java
@@ -0,0 +1,49 @@
+package vaporize.library;
+
+import misc.*;
+import cfg.*;
+import java.util.*;
+
+public class LIRDict {
+
+ private TreeSet<LIRVar> intervals;
+
+ public LIRDict(ControlFlowGraph cfg) {
+ this.intervals = new TreeSet<LIRVar>();
+
+ for (CFGNode n : cfg.getNodes()) {
+ int line = n.getInstruction().sourcePos.line;
+
+ for (String var : n.getReaching())
+ if (!this.contains(var))
+ this.intervals.add(new LIRVar(var, line, line));
+ for (String var : n.getLiveness()) {
+ if (!this.contains(var))
+ MinimalLogger.severe(String.format("%s was used before defined!",
+ var));
+ this.getInterval(var).trySetLastUse(line);
+ }
+ }
+ }
+
+ public LIRVar getInterval(String s) {
+ LIRVar ret = null;
+ for (LIRVar v : this.intervals) {
+ if (v.equals(s)) {
+ ret = v;
+ break;
+ }
+ }
+
+ return ret;
+ }
+
+ public boolean contains(String s) {
+ return this.getInterval(s) != null;
+ }
+
+ public SortedSet<LIRVar> getIntervals() {
+ return Collections.unmodifiableSortedSet(this.intervals);
+ }
+
+}