summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbd-912 <bdunahu@colostate.edu>2024-04-15 01:30:48 -0600
committerbd-912 <bdunahu@colostate.edu>2024-04-15 01:30:48 -0600
commit664e7846c0ca942dc94029010b94dcc41d78f492 (patch)
treeb106996ed7add062b233b4e267873d5b4e2a40f7
parent4907f4ed2f471f2ca23dd7ab30f602c1baed84c6 (diff)
Correctly call Vapor visitor
-rw-r--r--V2VM.java11
-rw-r--r--vaporize/library/TotalSpill.java55
2 files changed, 63 insertions, 3 deletions
diff --git a/V2VM.java b/V2VM.java
index 0f745f0..155c239 100644
--- a/V2VM.java
+++ b/V2VM.java
@@ -3,6 +3,7 @@ import cs132.util.ProblemException;
import cs132.vapor.parser.VaporParser;
import cs132.vapor.ast.VaporProgram;
import cs132.vapor.ast.VBuiltIn.Op;
+import cs132.vapor.ast.VFunction;
import java.io.InputStreamReader;
import java.io.IOException;
@@ -16,10 +17,14 @@ public class V2VM {
public static void main(String[] args) {
try {
- VaporProgram pgrm = parseVapor(System.in, System.out);
- System.out.println(pgrm);
+ VFunction[] funts = parseVapor(System.in, System.out).functions;
- ControlFlowGraph vp = new ControlFlowGraph<Void, Void>();
+ ControlFlowGraph cfg = new ControlFlowGraph<Void, Void>();
+
+ TotalSpill<String, Void> ts = new TotalSpill<String, Void>();
+ for (VFunction f : funts) {
+ f.body[0].accept("", ts);
+ }
} catch (IOException e) {
System.out.println(e.toString());
diff --git a/vaporize/library/TotalSpill.java b/vaporize/library/TotalSpill.java
new file mode 100644
index 0000000..9af45ea
--- /dev/null
+++ b/vaporize/library/TotalSpill.java
@@ -0,0 +1,55 @@
+package vaporize.library;
+
+import cs132.vapor.ast.*;
+import st.*;
+import misc.*;
+import java.util.*;
+
+public class TotalSpill<P, R> extends VInstr.VisitorPR<P, R, RuntimeException> {
+
+
+ private void printNode(P p, Node n) {
+ PrintFilter.print(n.getClass().getSimpleName(), true);
+ }
+
+ public R visit(P p, VMemRead n) throws RuntimeException {
+ this.printNode(p, n);
+ return null;
+ }
+
+ public R visit(P p, VMemWrite n) throws RuntimeException {
+ this.printNode(p, n);
+ return null;
+ }
+
+ public R visit(P p, VAssign n) throws RuntimeException {
+ this.printNode(p, n);
+ return null;
+ }
+
+ public R visit(P p, VBranch n) throws RuntimeException {
+ this.printNode(p, n);
+ return null;
+ }
+
+ public R visit(P p, VGoto n) throws RuntimeException {
+ this.printNode(p, n);
+ return null;
+ }
+
+ public R visit(P p, VCall n) throws RuntimeException {
+ this.printNode(p, n);
+ return null;
+ }
+
+ public R visit(P p, VBuiltIn n) throws RuntimeException {
+ this.printNode(p, n);
+ return null;
+ }
+
+ public R visit(P p, VReturn n) throws RuntimeException {
+ this.printNode(p, n);
+ return null;
+ }
+
+}