diff options
-rw-r--r-- | V2VM.java | 8 | ||||
-rw-r--r-- | misc/PrintFilter.java | 2 | ||||
-rw-r--r-- | vaporize/library/Kettle.java | 43 | ||||
-rw-r--r-- | vaporize/library/SpillEverywhere.java | 61 | ||||
-rw-r--r-- | vaporize/tests/ex30.vapor | 3 | ||||
-rw-r--r-- | vaporize/tests/ex32.vapor | 15 | ||||
-rw-r--r-- | vaporize/tests/ex32.vaporm | 22 |
7 files changed, 124 insertions, 30 deletions
@@ -27,18 +27,14 @@ public class V2VM { VaporProgram prog = parseVapor(System.in, System.out); + SpillEverywhere spill = new SpillEverywhere(prog, strProg); + ArrayList<ControlFlowGraph> cfgs = new ArrayList<ControlFlowGraph>(); for (VFunction f : prog.functions) { CFGSimp cfg = new CFGSimp(f); cfgs.add(cfg.getCFG()); } - SpillEverywhere<String, Void> se = new SpillEverywhere<String, Void>(strProg); - - // for (VFunction f : prog.functions) - // for (VInstr s : f.body) - // s.accept("", se); - } catch (IOException e) { System.out.println(e.toString()); System.exit(1); diff --git a/misc/PrintFilter.java b/misc/PrintFilter.java index e3be310..971ef04 100644 --- a/misc/PrintFilter.java +++ b/misc/PrintFilter.java @@ -4,7 +4,7 @@ package misc; public class PrintFilter { public static void print(String message, boolean newline) { - boolean debug = false; + boolean debug = true; if (debug) { System.out.print(message); if (newline) diff --git a/vaporize/library/Kettle.java b/vaporize/library/Kettle.java new file mode 100644 index 0000000..2590d4b --- /dev/null +++ b/vaporize/library/Kettle.java @@ -0,0 +1,43 @@ +package vaporize.library; + +import cs132.vapor.ast.*; +import java.util.ArrayList; + +/** + * This class contains various generic methods for + * assembling common-use vaporm strings. + * + * Robert Martin cries + */ +class Kettle { + + ArrayList<String> vapor; + + protected Kettle(ArrayList<String> vapor) { + this.vapor = vapor; + } + + protected String indexOriginal(Node n) { + /** + * Given the source position of a Node, returns the original line. + */ + return this.vapor.get(n.sourcePos.line-1); + } + + protected String functionParameters(VFunction prev, int in, + int out, int local) { + return String.format("func %s [in %d, out %d, local %d]", + this.indexOriginal(prev).split(" ")[1], + in, + out, + local); + } + + protected String spill() { + return null; + } + + protected String backup() { + return null; + } +} diff --git a/vaporize/library/SpillEverywhere.java b/vaporize/library/SpillEverywhere.java index 5edbbfc..b910270 100644 --- a/vaporize/library/SpillEverywhere.java +++ b/vaporize/library/SpillEverywhere.java @@ -5,77 +5,98 @@ import st.*; import misc.*; import java.util.*; -public class SpillEverywhere<P, R> extends VInstr.VisitorPR<P, R, RuntimeException> { +public class SpillEverywhere extends VInstr.VisitorPR<String, String, RuntimeException> { - ArrayList<String> vapor; + VaporProgram vp; + Kettle kettle; String vaporm; + // public CFGSimp(VaporProgram v) { - public SpillEverywhere(ArrayList<String> vapor) { - this.vapor = vapor; + // // nodes + // for (VInstr s : n.body) + // this.cfg.addNode(new CFGNode(s)); + + // // edges + // for (VInstr s : n.body) + // s.accept("", this); + + // System.out.println(this.cfg.getNodes().toString()); + // } + + public SpillEverywhere(VaporProgram vp, ArrayList<String> vapor) { + this.vp = vp; + this.kettle = new Kettle(vapor); this.vaporm = ""; + + for (VFunction f : vp.functions) { + for (VInstr s : f.body) { + // s.accept("", this); + } + PrintFilter.print(this.kettle.indexOriginal(f), true); + } } - public R visit(P p, VMemRead n) throws RuntimeException { + public String visit(String p, VMemRead n) throws RuntimeException { PrintFilter.print(String.format("%s (%s:%s)", n.getClass().getSimpleName(), - this.vapor.get(n.sourcePos.line-1), + this.kettle.indexOriginal(n), n.sourcePos.toString()), true); return null; } - public R visit(P p, VMemWrite n) throws RuntimeException { + public String visit(String p, VMemWrite n) throws RuntimeException { PrintFilter.print(String.format("%s (%s:%s)", n.getClass().getSimpleName(), - this.vapor.get(n.sourcePos.line-1), + this.kettle.indexOriginal(n), n.sourcePos.toString()), true); return null; } - public R visit(P p, VAssign n) throws RuntimeException { + public String visit(String p, VAssign n) throws RuntimeException { PrintFilter.print(String.format("%s (%s:%s)", n.getClass().getSimpleName(), - this.vapor.get(n.sourcePos.line-1), + this.kettle.indexOriginal(n), n.sourcePos.toString()), true); return null; } - public R visit(P p, VBranch n) throws RuntimeException { + public String visit(String p, VBranch n) throws RuntimeException { PrintFilter.print(String.format("%s (%s:%s)", n.getClass().getSimpleName(), - this.vapor.get(n.sourcePos.line-1), + this.kettle.indexOriginal(n), n.sourcePos.toString()), true); return null; } - public R visit(P p, VGoto n) throws RuntimeException { + public String visit(String p, VGoto n) throws RuntimeException { PrintFilter.print(String.format("%s (%s:%s)", n.getClass().getSimpleName(), - this.vapor.get(n.sourcePos.line-1), + this.kettle.indexOriginal(n), n.sourcePos.toString()), true); return null; } - public R visit(P p, VCall n) throws RuntimeException { + public String visit(String p, VCall n) throws RuntimeException { PrintFilter.print(String.format("%s (%s:%s)", n.getClass().getSimpleName(), - this.vapor.get(n.sourcePos.line-1), + this.kettle.indexOriginal(n), n.sourcePos.toString()), true); return null; } - public R visit(P p, VBuiltIn n) throws RuntimeException { + public String visit(String p, VBuiltIn n) throws RuntimeException { PrintFilter.print(String.format("%s (%s:%s)", n.op.name, - this.vapor.get(n.sourcePos.line-1), + this.kettle.indexOriginal(n), n.sourcePos.toString()), true); return null; } - public R visit(P p, VReturn n) throws RuntimeException { + public String visit(String p, VReturn n) throws RuntimeException { PrintFilter.print(String.format("%s (%s:%s)", n.getClass().getSimpleName(), - this.vapor.get(n.sourcePos.line-1), + this.kettle.indexOriginal(n), n.sourcePos.toString()), true); return null; } diff --git a/vaporize/tests/ex30.vapor b/vaporize/tests/ex30.vapor deleted file mode 100644 index 200baee..0000000 --- a/vaporize/tests/ex30.vapor +++ /dev/null @@ -1,3 +0,0 @@ -func Main() - - ret
\ No newline at end of file diff --git a/vaporize/tests/ex32.vapor b/vaporize/tests/ex32.vapor new file mode 100644 index 0000000..8a8dc62 --- /dev/null +++ b/vaporize/tests/ex32.vapor @@ -0,0 +1,15 @@ +func Main() + t.3 = HeapAllocZ(4) + [t.3+0] = :functable_A + t.4 = [t.3+0] + t.5 = [t.4+0] + t.6 = 12 + t.10 = call t.5(t.3 t.6) + PrintIntS(t.10) + ret + +const functable_A + :A_foo + +func A_foo(this t.1) + ret t.1 diff --git a/vaporize/tests/ex32.vaporm b/vaporize/tests/ex32.vaporm new file mode 100644 index 0000000..85ecf13 --- /dev/null +++ b/vaporize/tests/ex32.vaporm @@ -0,0 +1,22 @@ +func Main [in 0, out 0, local 0] + $t0 = HeapAllocZ(4) + [$t0] = :functable_A + $t1 = [$t0] + $t2 = [$t1] + $a0 = $t0 + $a1 = 12 + call $t2 + $t1 = $v0 + PrintIntS($t1) + ret + +const functable_A + :A_foo + +func A_foo [in 0, out 0, local 1] + local[0] = $s0 + $t0 = $a0 + $s0 = $a1 + $v0 = $s0 + $s0 = local[0] + ret |