diff options
Diffstat (limited to 'vaporize/library')
-rw-r--r-- | vaporize/library/Kettle.java | 43 | ||||
-rw-r--r-- | vaporize/library/SpillEverywhere.java | 61 |
2 files changed, 84 insertions, 20 deletions
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; } |