summaryrefslogtreecommitdiff
path: root/vaporize
diff options
context:
space:
mode:
Diffstat (limited to 'vaporize')
-rw-r--r--vaporize/library/CFGSimp.java48
-rw-r--r--vaporize/library/ControlFlowGraph.java69
-rw-r--r--vaporize/library/Node.java38
-rw-r--r--vaporize/library/SpillEverywhere.java84
4 files changed, 184 insertions, 55 deletions
diff --git a/vaporize/library/CFGSimp.java b/vaporize/library/CFGSimp.java
new file mode 100644
index 0000000..372f926
--- /dev/null
+++ b/vaporize/library/CFGSimp.java
@@ -0,0 +1,48 @@
+package vaporize.library;
+
+import cs132.vapor.ast.*;
+import st.*;
+import misc.*;
+import java.util.*;
+
+public class CFGSimp<P, R> extends VInstr.VisitorPR<P, R, RuntimeException> {
+
+ ControlFlowGraph cfg;
+
+ public CFGSimp(ControlFlowGraph cfg) {
+ this.cfg = cfg;
+ }
+
+ public R visit(P p, VMemRead n) throws RuntimeException {
+ return null;
+ }
+
+ public R visit(P p, VMemWrite n) throws RuntimeException {
+ return null;
+ }
+
+ public R visit(P p, VAssign n) throws RuntimeException {
+ return null;
+ }
+
+ public R visit(P p, VBranch n) throws RuntimeException {
+ return null;
+ }
+
+ public R visit(P p, VGoto n) throws RuntimeException {
+ return null;
+ }
+
+ public R visit(P p, VCall n) throws RuntimeException {
+ return null;
+ }
+
+ public R visit(P p, VBuiltIn n) throws RuntimeException {
+ return null;
+ }
+
+ public R visit(P p, VReturn n) throws RuntimeException {
+ return null;
+ }
+
+}
diff --git a/vaporize/library/ControlFlowGraph.java b/vaporize/library/ControlFlowGraph.java
index 787ef8f..f181d36 100644
--- a/vaporize/library/ControlFlowGraph.java
+++ b/vaporize/library/ControlFlowGraph.java
@@ -1,68 +1,27 @@
package vaporize.library;
import cs132.vapor.ast.*;
-import st.*;
-import misc.*;
-import java.util.*;
+import java.util.ArrayList;
-public class ControlFlowGraph<P, R> extends VInstr.VisitorPR<P, R, RuntimeException> {
+public class ControlFlowGraph {
+ private ArrayList<Node> nodes;
+ private Node start;
+ private Node end;
- public R visit(P p, VMemRead n) throws RuntimeException {
- PrintFilter.print(String.format("%s (%s)",
- n.getClass().getSimpleName(),
- n.sourcePos.toString()), true);
- return null;
+ public ControlFlowGraph() {
+ this.nodes = new ArrayList<>();
+ this.start = null;
+ this.end = null;
}
- public R visit(P p, VMemWrite n) throws RuntimeException {
- PrintFilter.print(String.format("%s (%s)",
- n.getClass().getSimpleName(),
- n.sourcePos.toString()), true);
- return null;
+ protected void addNode(Node node) {
+ this.nodes.add(node);
}
- public R visit(P p, VAssign n) throws RuntimeException {
- PrintFilter.print(String.format("%s (%s)",
- n.getClass().getSimpleName(),
- n.sourcePos.toString()), true);
- return null;
- }
-
- public R visit(P p, VBranch n) throws RuntimeException {
- PrintFilter.print(String.format("%s (%s)",
- n.getClass().getSimpleName(),
- n.sourcePos.toString()), true);
- return null;
- }
-
- public R visit(P p, VGoto n) throws RuntimeException {
- PrintFilter.print(String.format("%s (%s)",
- n.getClass().getSimpleName(),
- n.sourcePos.toString()), true);
- return null;
- }
-
- public R visit(P p, VCall n) throws RuntimeException {
- PrintFilter.print(String.format("%s (%s)",
- n.getClass().getSimpleName(),
- n.sourcePos.toString()), true);
- return null;
- }
-
- public R visit(P p, VBuiltIn n) throws RuntimeException {
- PrintFilter.print(String.format("%s (%s:%s)",
- n.getClass().getSimpleName(),
- n.op.name,
- n.sourcePos.toString()), true);
- return null;
- }
-
- public R visit(P p, VReturn n) throws RuntimeException {
- PrintFilter.print(String.format("%s (%s)",
- n.getClass().getSimpleName(),
- n.sourcePos.toString()), true);
- return null;
+ protected void addEdge(Node source, Node dest) {
+ source.addDest(dest);
+ dest.addSource(source);
}
}
diff --git a/vaporize/library/Node.java b/vaporize/library/Node.java
new file mode 100644
index 0000000..203f931
--- /dev/null
+++ b/vaporize/library/Node.java
@@ -0,0 +1,38 @@
+package vaporize.library;
+
+import cs132.vapor.ast.*;
+import java.util.ArrayList;
+
+class Node {
+
+ private VInstr instruction;
+ private ArrayList<Node> sources;
+ private ArrayList<Node> dests;
+
+ protected Node(VInstr instruction) {
+ this.instruction = instruction;
+ this.sources = new ArrayList<>();
+ this.dests = new ArrayList<>();
+ }
+
+ protected void addSource(Node node) {
+ this.sources.add(node);
+ }
+
+ protected void addDest(Node node) {
+ this.dests.add(node);
+ }
+
+ protected VInstr getInstruction() {
+ return this.instruction;
+ }
+
+ protected ArrayList<Node> getSources() {
+ return this.sources;
+ }
+
+ protected ArrayList<Node> getDests() {
+ return this.dests;
+ }
+
+}
diff --git a/vaporize/library/SpillEverywhere.java b/vaporize/library/SpillEverywhere.java
new file mode 100644
index 0000000..aa8368f
--- /dev/null
+++ b/vaporize/library/SpillEverywhere.java
@@ -0,0 +1,84 @@
+package vaporize.library;
+
+import cs132.vapor.ast.*;
+import st.*;
+import misc.*;
+import java.util.*;
+
+public class SpillEverywhere<P, R> extends VInstr.VisitorPR<P, R, RuntimeException> {
+
+ ArrayList<String> vapor;
+ String vaporm;
+
+
+ public SpillEverywhere(ArrayList<String> vapor) {
+ this.vapor = vapor;
+ this.vaporm = "";
+ }
+
+ public R visit(P p, VMemRead n) throws RuntimeException {
+ PrintFilter.print(String.format("%s (%s:%s)",
+ n.getClass().getSimpleName(),
+ this.vapor.get(n.sourcePos.line-1),
+ n.sourcePos.toString()), true);
+ return null;
+ }
+
+ public R visit(P p, VMemWrite n) throws RuntimeException {
+ PrintFilter.print(String.format("%s (%s:%s)",
+ n.getClass().getSimpleName(),
+ this.vapor.get(n.sourcePos.line-1),
+ n.sourcePos.toString()), true);
+ return null;
+ }
+
+ public R visit(P p, VAssign n) throws RuntimeException {
+ PrintFilter.print(String.format("%s (%s:%s)",
+ n.getClass().getSimpleName(),
+ this.vapor.get(n.sourcePos.line-1),
+ n.sourcePos.toString()), true);
+ return null;
+ }
+
+ public R visit(P p, VBranch n) throws RuntimeException {
+ PrintFilter.print(String.format("%s (%s:%s)",
+ n.getClass().getSimpleName(),
+ this.vapor.get(n.sourcePos.line-1),
+ n.sourcePos.toString()), true);
+ System.out.println("NEXT: " +
+ return null;
+ }
+
+ public R visit(P p, VGoto n) throws RuntimeException {
+ PrintFilter.print(String.format("%s (%s:%s)",
+ n.getClass().getSimpleName(),
+ this.vapor.get(n.sourcePos.line-1),
+ n.sourcePos.toString()), true);
+ return null;
+ }
+
+ public R visit(P p, VCall n) throws RuntimeException {
+ PrintFilter.print(String.format("%s (%s:%s)",
+ n.getClass().getSimpleName(),
+ this.vapor.get(n.sourcePos.line-1),
+ n.sourcePos.toString()), true);
+ return null;
+ }
+
+ public R visit(P p, VBuiltIn n) throws RuntimeException {
+ PrintFilter.print(String.format("%s (%s:%s)",
+ n.op.name,
+ this.vapor.get(n.sourcePos.line-1),
+ n.sourcePos.toString()), true);
+ return null;
+ }
+
+ public R visit(P p, VReturn n) throws RuntimeException {
+ PrintFilter.print(String.format("%s (%s:%s)",
+ n.getClass().getSimpleName(),
+ this.vapor.get(n.sourcePos.line-1),
+ n.sourcePos.toString()), true);
+ return null;
+ }
+
+ }