diff options
-rw-r--r-- | J2V.java | 3 | ||||
-rw-r--r-- | V2VM.java | 5 | ||||
-rw-r--r-- | boil/library/BoilSimp.java | 443 | ||||
-rw-r--r-- | vaporize/library/ControlFlowGraph.java | 42 | ||||
-rw-r--r-- | vaporize/library/TotalSpill.java | 68 |
5 files changed, 262 insertions, 299 deletions
@@ -25,7 +25,8 @@ public class J2V { root.accept(new SymTableTopDown<Void>(), symt); BoilSimp vp = new BoilSimp(); - root.accept(vp, symt); + vp.setSymbolTable(symt); + root.accept(vp, ""); PrintFilter.print("===================================================", true); System.out.println(vp.getVapor()); @@ -19,11 +19,10 @@ public class V2VM { try { VFunction[] funts = parseVapor(System.in, System.out).functions; - ControlFlowGraph cfg = new ControlFlowGraph<Void, Void>(); + ControlFlowGraph<String, Void> cfg = new ControlFlowGraph<String, Void>(); - TotalSpill<String, Void> ts = new TotalSpill<String, Void>(); for (VFunction f : funts) { - f.body[0].accept("", ts); + f.body[0].accept("", cfg); } } catch (IOException e) { diff --git a/boil/library/BoilSimp.java b/boil/library/BoilSimp.java index 081b205..0c391db 100644 --- a/boil/library/BoilSimp.java +++ b/boil/library/BoilSimp.java @@ -6,10 +6,15 @@ import st.*; import misc.*; import java.util.*; -public class BoilSimp extends GJDepthFirst<String,SymbolTable> { +public class BoilSimp extends GJDepthFirst<String,String> { private String vapor; // the collected vapor program private TypeFactory tf = new TypeFactory(); // the shared type generator + private SymbolTable symt; + + public void setSymbolTable(SymbolTable symt) { + this.symt = symt; + } public String getVapor() { return this.vapor; @@ -18,22 +23,22 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { // // Auto class visitors--probably don't need to be overridden. // - public String visit(NodeList n, SymbolTable symt) { + public String visit(NodeList n, String args) { String mod = ""; int _count=0; for ( Enumeration<Node> e = n.elements(); e.hasMoreElements(); ) { - mod += e.nextElement().accept(this,symt); + mod += e.nextElement().accept(this,args); _count++; } return mod; } - public String visit(NodeListOptional n, SymbolTable symt) { + public String visit(NodeListOptional n, String args) { String mod = ""; if ( n.present() ) { int _count=0; for ( Enumeration<Node> e = n.elements(); e.hasMoreElements(); ) { - mod += e.nextElement().accept(this,symt); + mod += e.nextElement().accept(this,args); _count++; } return mod; @@ -42,24 +47,24 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { return ""; } - public String visit(NodeOptional n, SymbolTable symt) { + public String visit(NodeOptional n, String args) { if ( n.present() ) - return n.node.accept(this,symt); + return n.node.accept(this,args); else return ""; } - public String visit(NodeSequence n, SymbolTable symt) { + public String visit(NodeSequence n, String args) { String mod = ""; int _count=0; for ( Enumeration<Node> e = n.elements(); e.hasMoreElements(); ) { - e.nextElement().accept(this,symt); + e.nextElement().accept(this,args); _count++; } return mod; } - public String visit(NodeToken n, SymbolTable symt) { return ""; } + public String visit(NodeToken n, String args) { return ""; } // // User-generated visitor methods below @@ -70,12 +75,12 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { * f1 -> ( TypeDeclaration() )* * f2 -> <EOF> */ - public String visit(Goal n, SymbolTable symt) { + public String visit(Goal n, String args) { this.vapor = ""; String mod = ""; - n.f0.accept(this, symt); - n.f1.accept(this, symt); - n.f2.accept(this, symt); + n.f0.accept(this, args); + n.f1.accept(this, args); + n.f2.accept(this, args); return mod; } @@ -99,39 +104,39 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { * f16 -> "}" * f17 -> "}" */ - public String visit(MainClass n, SymbolTable symt) { + public String visit(MainClass n, String args) { String id = n.f1.f0.tokenImage; - symt.setActive(TypeEnum.classname, id); - symt.setActive(TypeEnum.method, "main"); + this.symt.setActive(TypeEnum.classname, id); + this.symt.setActive(TypeEnum.method, "main"); this.tf.reset(); String mod = ""; this.vapor += "func Main()\n"; - n.f0.accept(this, symt); - n.f1.accept(this, symt); // throw class name away - n.f2.accept(this, symt); - n.f3.accept(this, symt); - n.f4.accept(this, symt); - n.f5.accept(this, symt); - n.f6.accept(this, symt); - n.f7.accept(this, symt); - n.f8.accept(this, symt); - n.f9.accept(this, symt); - n.f10.accept(this, symt); - n.f11.accept(this, symt); // throw boiler 'args' variable away - n.f12.accept(this, symt); - n.f13.accept(this, symt); - n.f14.accept(this, symt); // FIXME - n.f15.accept(this, symt); - n.f16.accept(this, symt); - n.f17.accept(this, symt); + n.f0.accept(this, args); + n.f1.accept(this, args); // throw class name away + n.f2.accept(this, args); + n.f3.accept(this, args); + n.f4.accept(this, args); + n.f5.accept(this, args); + n.f6.accept(this, args); + n.f7.accept(this, args); + n.f8.accept(this, args); + n.f9.accept(this, args); + n.f10.accept(this, args); + n.f11.accept(this, args); // throw boiler 'args' variable away + n.f12.accept(this, args); + n.f13.accept(this, args); + n.f14.accept(this, args); // FIXME + n.f15.accept(this, args); + n.f16.accept(this, args); + n.f17.accept(this, args); this.vapor += " goto :exit\nerror:\n" + " Error(\"Mem exhausted\")\n goto :exit\n" + "exit:\n ret\n\n"; - symt.removeActive(TypeEnum.method); + this.symt.removeActive(TypeEnum.method); return mod; } @@ -139,9 +144,9 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { * f0 -> ClassDeclaration() * | ClassExtendsDeclaration() */ - public String visit(TypeDeclaration n, SymbolTable symt) { + public String visit(TypeDeclaration n, String args) { String mod = ""; - n.f0.accept(this, symt); + n.f0.accept(this, args); return mod; } @@ -153,22 +158,22 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { * f4 -> ( MethodDeclaration() )* * f5 -> "}" */ - public String visit(ClassDeclaration n, SymbolTable symt) { + public String visit(ClassDeclaration n, String args) { String id = n.f1.f0.tokenImage; - symt.setActive(TypeEnum.classname, id); + this.symt.setActive(TypeEnum.classname, id); String mod = ""; - n.f0.accept(this, symt); - n.f1.accept(this, symt); + n.f0.accept(this, args); + n.f1.accept(this, args); this.vapor += String.format("const functable_%s\n", id); - for (MethodInstance mtd : symt.getClass(id).getMethods()) { + for (MethodInstance mtd : this.symt.getClass(id).getMethods()) { this.vapor += String.format(" :%s_%s\n", id, mtd); } this.vapor += "\n"; - n.f2.accept(this, symt); - // n.f3.accept(this, symt); - n.f4.accept(this, symt); - n.f5.accept(this, symt); + n.f2.accept(this, args); + // n.f3.accept(this, args); + n.f4.accept(this, args); + n.f5.accept(this, args); return mod; } @@ -183,19 +188,19 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { * f6 -> ( MethodDeclaration() )* * f7 -> "}" */ - public String visit(ClassExtendsDeclaration n, SymbolTable symt) { + public String visit(ClassExtendsDeclaration n, String args) { String id = n.f1.f0.tokenImage; - symt.setActive(TypeEnum.classname, id); + this.symt.setActive(TypeEnum.classname, id); String mod = ""; - n.f0.accept(this, symt); - n.f1.accept(this, symt); - n.f2.accept(this, symt); - n.f3.accept(this, symt); - n.f4.accept(this, symt); - n.f5.accept(this, symt); - n.f6.accept(this, symt); - n.f7.accept(this, symt); + n.f0.accept(this, args); + n.f1.accept(this, args); + n.f2.accept(this, args); + n.f3.accept(this, args); + n.f4.accept(this, args); + n.f5.accept(this, args); + n.f6.accept(this, args); + n.f7.accept(this, args); return mod; } @@ -204,19 +209,19 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { * f1 -> Identifier() * f2 -> ";" */ - public String visit(VarDeclaration n, SymbolTable symt) { + public String visit(VarDeclaration n, String args) { String mod = ""; - String cls = n.f0.accept(this, symt); - String id = n.f1.accept(this, symt); - TypeInstance t = symt.getType(id); + String cls = n.f0.accept(this, args); + String id = n.f1.accept(this, args); + TypeInstance t = this.symt.getType(id); this.vapor += String.format(" %s = HeapAllocZ(%d)\n", this.tf.alias(t), t.getSize()); this.vapor += String.format(" if0 %s goto :error\n", - this.tf.alias(symt.getType(id))); - n.f2.accept(this, symt); + this.tf.alias(this.symt.getType(id))); + n.f2.accept(this, args); return mod; } @@ -235,36 +240,36 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { * f11 -> ";" * f12 -> "}" */ - public String visit(MethodDeclaration n, SymbolTable symt) { + public String visit(MethodDeclaration n, String args) { String id = n.f2.f0.tokenImage; - symt.setActive(TypeEnum.method, id); + this.symt.setActive(TypeEnum.method, id); this.tf.reset(); String mod = ""; - n.f0.accept(this, symt); - n.f1.accept(this, symt); - n.f2.accept(this, symt); - this.vapor += "func " + symt.getActive(TypeEnum.classname) + "_" + id + "(this"; - n.f3.accept(this, symt); - String args = n.f4.accept(this, symt); - this.vapor += String.format("%s)\n", args); - n.f5.accept(this, symt); - n.f6.accept(this, symt); + n.f0.accept(this, args); + n.f1.accept(this, args); + n.f2.accept(this, args); + this.vapor += "func " + this.symt.getActive(TypeEnum.classname) + "_" + id + "(this"; + n.f3.accept(this, args); + String argu = n.f4.accept(this, args); + this.vapor += String.format("%s)\n", argu); + n.f5.accept(this, args); + n.f6.accept(this, args); // spill out all class attributes, if they're not used, who cares - for (TypeInstance attr : symt.getMethod(id) + for (TypeInstance attr : this.symt.getMethod(id) .getClassInstance() .getLocals()) { this.vapor += String.format(" %s = this\n", this.tf.alias(attr)); } - n.f7.accept(this, symt); - n.f8.accept(this, symt); - n.f9.accept(this, symt); - String ret = n.f10.accept(this, symt); // FIXME - n.f11.accept(this, symt); - n.f12.accept(this, symt); + n.f7.accept(this, args); + n.f8.accept(this, args); + n.f9.accept(this, args); + String ret = n.f10.accept(this, args); // FIXME + n.f11.accept(this, args); + n.f12.accept(this, args); TypeInstance tp1 = new TypeInstance("tp1", TypeEnum.ERROR); this.vapor += String.format(" %s = %s\n ret %s\n\n", @@ -272,7 +277,7 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { ret, this.tf.alias(tp1)); - symt.removeActive(TypeEnum.method); + this.symt.removeActive(TypeEnum.method); return mod; } @@ -280,12 +285,12 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { * f0 -> FormalParameter() * f1 -> ( FormalParameterRest() )* */ - public String visit(FormalParameterList n, SymbolTable symt) { + public String visit(FormalParameterList n, String args) { String mod = ""; - String arg = n.f0.accept(this, symt); + String arg = n.f0.accept(this, args); if (arg != null) mod += " " + arg; - mod += n.f1.accept(this, symt); + mod += n.f1.accept(this, args); return mod; } @@ -293,10 +298,10 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { * f0 -> Type() * f1 -> Identifier() */ - public String visit(FormalParameter n, SymbolTable symt) { + public String visit(FormalParameter n, String args) { String mod = ""; - mod += n.f0.accept(this, symt); - mod += n.f1.accept(this, symt); + mod += n.f0.accept(this, args); + mod += n.f1.accept(this, args); return mod; } @@ -304,10 +309,10 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { * f0 -> "," * f1 -> FormalParameter() */ - public String visit(FormalParameterRest n, SymbolTable symt) { + public String visit(FormalParameterRest n, String args) { String mod = ""; - n.f0.accept(this, symt); - String arg = n.f1.accept(this, symt); + n.f0.accept(this, args); + String arg = n.f1.accept(this, args); if (arg != null) mod += " " + arg; return mod; @@ -319,9 +324,9 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { * | IntegerType() * | Identifier() */ - public String visit(Type n, SymbolTable symt) { + public String visit(Type n, String args) { String mod = ""; - mod += n.f0.accept(this, symt); + mod += n.f0.accept(this, args); return mod; } @@ -330,29 +335,29 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { * f1 -> "[" * f2 -> "]" */ - public String visit(ArrayType n, SymbolTable symt) { + public String visit(ArrayType n, String args) { String mod = ""; - n.f0.accept(this, symt); - n.f1.accept(this, symt); - n.f2.accept(this, symt); + n.f0.accept(this, args); + n.f1.accept(this, args); + n.f2.accept(this, args); return mod; } /** * f0 -> "boolean" */ - public String visit(BooleanType n, SymbolTable symt) { + public String visit(BooleanType n, String args) { String mod = ""; - n.f0.accept(this, symt); + n.f0.accept(this, args); return mod; } /** * f0 -> "int" */ - public String visit(IntegerType n, SymbolTable symt) { + public String visit(IntegerType n, String args) { String mod = ""; - n.f0.accept(this, symt);; + n.f0.accept(this, args);; return mod; } @@ -364,9 +369,9 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { * | WhileStatement() * | PrintStatement() */ - public String visit(Statement n, SymbolTable symt) { + public String visit(Statement n, String args) { String mod = ""; - n.f0.accept(this, symt); + n.f0.accept(this, args); return mod; } @@ -375,11 +380,11 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { * f1 -> ( Statement() )* * f2 -> "}" */ - public String visit(Block n, SymbolTable symt) { + public String visit(Block n, String args) { String mod = ""; - n.f0.accept(this, symt); - n.f1.accept(this, symt); - n.f2.accept(this, symt); + n.f0.accept(this, args); + n.f1.accept(this, args); + n.f2.accept(this, args); return mod; } @@ -389,23 +394,23 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { * f2 -> Expression() * f3 -> ";" */ - public String visit(AssignmentStatement n, SymbolTable symt) { + public String visit(AssignmentStatement n, String args) { String mod = ""; - String id = n.f0.accept(this, symt); + String id = n.f0.accept(this, args); ClassInstance cls; - int attr_index = (cls = symt.getClass(symt.getActive(TypeEnum.classname))) - .getLocals().indexOf(symt.getType(id)) * 4; + int attr_index = (cls = this.symt.getClass(this.symt.getActive(TypeEnum.classname))) + .getLocals().indexOf(this.symt.getType(id)) * 4; if (attr_index < 0) attr_index = 0; else attr_index += cls.getMethods().size() * 4; - n.f1.accept(this, symt); - String expr = n.f2.accept(this, symt); - n.f3.accept(this, symt); + n.f1.accept(this, args); + String expr = n.f2.accept(this, args); + n.f3.accept(this, args); this.vapor += String.format(" [%s+%d] = %s\n", this.tf.retrieveRecentList(1), @@ -417,7 +422,7 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { // if (t == null ) { // anonymous? // t = new TypeInstance("tp1", TypeEnum.classname); // FIXME maybe this is wrong for arrays? - // t.addClassInstance(symt.getClass(cls)); + // t.addClassInstance(this.symt.getClass(cls)); // } @@ -430,15 +435,15 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { * f5 -> Expression() * f6 -> ";" */ - public String visit(ArrayAssignmentStatement n, SymbolTable symt) { + public String visit(ArrayAssignmentStatement n, String args) { String mod = ""; - n.f0.accept(this, symt); - n.f1.accept(this, symt); - n.f2.accept(this, symt); - n.f3.accept(this, symt); - n.f4.accept(this, symt); - n.f5.accept(this, symt); - n.f6.accept(this, symt); + n.f0.accept(this, args); + n.f1.accept(this, args); + n.f2.accept(this, args); + n.f3.accept(this, args); + n.f4.accept(this, args); + n.f5.accept(this, args); + n.f6.accept(this, args); return mod; } @@ -451,15 +456,15 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { * f5 -> "else" * f6 -> Statement() */ - public String visit(IfStatement n, SymbolTable symt) { + public String visit(IfStatement n, String args) { String mod = ""; - n.f0.accept(this, symt); - n.f1.accept(this, symt); - n.f2.accept(this, symt); - n.f3.accept(this, symt); - n.f4.accept(this, symt); - n.f5.accept(this, symt); - n.f6.accept(this, symt); + n.f0.accept(this, args); + n.f1.accept(this, args); + n.f2.accept(this, args); + n.f3.accept(this, args); + n.f4.accept(this, args); + n.f5.accept(this, args); + n.f6.accept(this, args); return mod; } @@ -470,13 +475,13 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { * f3 -> ")" * f4 -> Statement() */ - public String visit(WhileStatement n, SymbolTable symt) { + public String visit(WhileStatement n, String args) { String mod = ""; - n.f0.accept(this, symt); - n.f1.accept(this, symt); - n.f2.accept(this, symt); - n.f3.accept(this, symt); - n.f4.accept(this, symt); + n.f0.accept(this, args); + n.f1.accept(this, args); + n.f2.accept(this, args); + n.f3.accept(this, args); + n.f4.accept(this, args); return mod; } @@ -487,13 +492,13 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { * f3 -> ")" * f4 -> ";" */ - public String visit(PrintStatement n, SymbolTable symt) { + public String visit(PrintStatement n, String args) { String mod = ""; - n.f0.accept(this, symt); - n.f1.accept(this, symt); - String expr = n.f2.accept(this, symt); - n.f3.accept(this, symt); - n.f4.accept(this, symt); + n.f0.accept(this, args); + n.f1.accept(this, args); + String expr = n.f2.accept(this, args); + n.f3.accept(this, args); + n.f4.accept(this, args); TypeInstance tp1 = new TypeInstance("tp1", TypeEnum.ERROR); vapor += String.format(" %s = %s\n", @@ -516,9 +521,9 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { * | MessageSend() * | PrimaryExpression() */ - public String visit(Expression n, SymbolTable symt) { + public String visit(Expression n, String args) { String mod = ""; - mod += n.f0.accept(this, symt); + mod += n.f0.accept(this, args); return mod; } @@ -527,11 +532,11 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { * f1 -> "&&" * f2 -> PrimaryExpression() */ - public String visit(AndExpression n, SymbolTable symt) { + public String visit(AndExpression n, String args) { String mod = ""; - n.f0.accept(this, symt); - n.f1.accept(this, symt); - n.f2.accept(this, symt); + n.f0.accept(this, args); + n.f1.accept(this, args); + n.f2.accept(this, args); return mod; } @@ -540,11 +545,11 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { * f1 -> "<" * f2 -> PrimaryExpression() */ - public String visit(CompareExpression n, SymbolTable symt) { + public String visit(CompareExpression n, String args) { String mod = ""; - n.f0.accept(this, symt); - n.f1.accept(this, symt); - n.f2.accept(this, symt); + n.f0.accept(this, args); + n.f1.accept(this, args); + n.f2.accept(this, args); return mod; } @@ -553,11 +558,11 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { * f1 -> "+" * f2 -> PrimaryExpression() */ - public String visit(PlusExpression n, SymbolTable symt) { + public String visit(PlusExpression n, String args) { String mod = ""; - String oper1 = n.f0.accept(this, symt); - n.f1.accept(this, symt); - String oper2 = n.f2.accept(this, symt); + String oper1 = n.f0.accept(this, args); + n.f1.accept(this, args); + String oper2 = n.f2.accept(this, args); mod += String.format("Add(%s %s)", oper1, @@ -571,11 +576,11 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { * f1 -> "-" * f2 -> PrimaryExpression() */ - public String visit(MinusExpression n, SymbolTable symt) { + public String visit(MinusExpression n, String args) { String mod = ""; - String oper1 = n.f0.accept(this, symt); - n.f1.accept(this, symt); - String oper2 = n.f2.accept(this, symt); + String oper1 = n.f0.accept(this, args); + n.f1.accept(this, args); + String oper2 = n.f2.accept(this, args); mod += String.format("Sub(%s %s)", oper1, @@ -590,11 +595,11 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { * f1 -> "*" * f2 -> PrimaryExpression() */ - public String visit(TimesExpression n, SymbolTable symt) { + public String visit(TimesExpression n, String args) { String mod = ""; - String oper1 = n.f0.accept(this, symt); - n.f1.accept(this, symt); - String oper2 = n.f2.accept(this, symt); + String oper1 = n.f0.accept(this, args); + n.f1.accept(this, args); + String oper2 = n.f2.accept(this, args); mod += String.format("MulS(%s %s)", oper1, @@ -610,12 +615,12 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { * f2 -> PrimaryExpression() * f3 -> "]" */ - public String visit(ArrayLookup n, SymbolTable symt) { + public String visit(ArrayLookup n, String args) { String mod = ""; - n.f0.accept(this, symt); - n.f1.accept(this, symt); - n.f2.accept(this, symt); - n.f3.accept(this, symt); + n.f0.accept(this, args); + n.f1.accept(this, args); + n.f2.accept(this, args); + n.f3.accept(this, args); return mod; } @@ -624,11 +629,11 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { * f1 -> "." * f2 -> "length" */ - public String visit(ArrayLength n, SymbolTable symt) { + public String visit(ArrayLength n, String args) { String mod = ""; - n.f0.accept(this, symt); - n.f1.accept(this, symt); - n.f2.accept(this, symt); + n.f0.accept(this, args); + n.f1.accept(this, args); + n.f2.accept(this, args); return mod; } @@ -640,21 +645,21 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { * f4 -> ( ExpressionList() )? * f5 -> ")" */ - public String visit(MessageSend n, SymbolTable symt) { + public String visit(MessageSend n, String args) { String mod = ""; - String id = n.f0.accept(this, symt); - n.f1.accept(this, symt); - String id2 = n.f2.accept(this, symt); + String id = n.f0.accept(this, args); + n.f1.accept(this, args); + String id2 = n.f2.accept(this, args); TypeInstance tp1 = new TypeInstance("tp1", TypeEnum.ERROR); // TypeFactory likes to know who it's renting to TypeInstance tp2 = new TypeInstance("tp2", TypeEnum.ERROR); - TypeInstance cur = symt.getType(id); + TypeInstance cur = this.symt.getType(id); // System.out.println("id: " + id); // System.out.println("id2: " + id2); - // System.out.println("cur: " + symt.getType(id)); + // System.out.println("cur: " + this.symt.getType(id)); int mtdIndex = cur.getClassInstance() - .getMethods().indexOf(symt.getMethod(id2)) * 4; + .getMethods().indexOf(this.symt.getMethod(id2)) * 4; this.vapor += String.format(" %s = [%s+%d]\n", this.tf.alias(tp1), @@ -666,16 +671,16 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { this.tf.alias(tp1), mtdIndex); - n.f3.accept(this, symt); - this.vapor += n.f4.accept(this, symt); - n.f5.accept(this, symt); + n.f3.accept(this, args); + this.vapor += n.f4.accept(this, args); + n.f5.accept(this, args); mod += String.format("call %s(%s", this.tf.alias(tp2), this.tf.alias(cur)); mod += String.format(" %s)", - this.tf.retrieveRecentList(symt.getMethod(id2) + this.tf.retrieveRecentList(this.symt.getMethod(id2) .getArguments() .size())); @@ -686,16 +691,16 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { * f0 -> Expression() * f1 -> ( ExpressionRest() )* */ - public String visit(ExpressionList n, SymbolTable symt) { + public String visit(ExpressionList n, String args) { String mod = ""; - String rhs = n.f0.accept(this, symt); + String rhs = n.f0.accept(this, args); TypeInstance tp1 = new TypeInstance("tp1", TypeEnum.ERROR); mod += String.format(" %s = %s\n", this.tf.alias(tp1), rhs); - mod += n.f1.accept(this, symt); + mod += n.f1.accept(this, args); return mod; } @@ -704,10 +709,10 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { * f0 -> "," * f1 -> Expression() */ - public String visit(ExpressionRest n, SymbolTable symt) { + public String visit(ExpressionRest n, String args) { String mod = ""; - n.f0.accept(this, symt); - String rhs = n.f1.accept(this, symt); + n.f0.accept(this, args); + String rhs = n.f1.accept(this, args); TypeInstance tp1 = new TypeInstance("tp1", TypeEnum.ERROR); mod += String.format(" %s = %s\n", @@ -728,16 +733,16 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { * | NotExpression() * | BracketExpression() */ - public String visit(PrimaryExpression n, SymbolTable symt) { + public String visit(PrimaryExpression n, String args) { String mod = ""; - mod += n.f0.accept(this, symt); + mod += n.f0.accept(this, args); return mod; } /** * f0 -> <INTEGER_LITERAL> */ - public String visit(IntegerLiteral n, SymbolTable symt) { + public String visit(IntegerLiteral n, String args) { String mod = ""; mod += n.f0.tokenImage; return mod; @@ -746,25 +751,25 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { /** * f0 -> "true" */ - public String visit(TrueLiteral n, SymbolTable symt) { + public String visit(TrueLiteral n, String args) { String mod = ""; - n.f0.accept(this, symt); + n.f0.accept(this, args); return mod; } /** * f0 -> "false" */ - public String visit(FalseLiteral n, SymbolTable symt) { + public String visit(FalseLiteral n, String args) { String mod = ""; - n.f0.accept(this, symt); + n.f0.accept(this, args); return mod; } /** * f0 -> <IDENTIFIER> */ - public String visit(Identifier n, SymbolTable symt) { + public String visit(Identifier n, String args) { String mod = ""; mod += n.f0.tokenImage; return mod; @@ -773,9 +778,9 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { /** * f0 -> "this" */ - public String visit(ThisExpression n, SymbolTable symt) { + public String visit(ThisExpression n, String args) { String mod = ""; - n.f0.accept(this, symt); + n.f0.accept(this, args); return mod; } @@ -786,13 +791,13 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { * f3 -> Expression() * f4 -> "]" */ - public String visit(ArrayAllocationExpression n, SymbolTable symt) { + public String visit(ArrayAllocationExpression n, String args) { String mod = ""; - n.f0.accept(this, symt); - n.f1.accept(this, symt); - n.f2.accept(this, symt); - n.f3.accept(this, symt); - n.f4.accept(this, symt); + n.f0.accept(this, args); + n.f1.accept(this, args); + n.f2.accept(this, args); + n.f3.accept(this, args); + n.f4.accept(this, args); return mod; } @@ -802,16 +807,16 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { * f2 -> "(" * f3 -> ")" */ - public String visit(AllocationExpression n, SymbolTable symt) { + public String visit(AllocationExpression n, String args) { String mod = ""; - n.f0.accept(this, symt); - String cls = n.f1.accept(this, symt); + n.f0.accept(this, args); + String cls = n.f1.accept(this, args); mod += String.format(":functable_%s", cls); // System.out.println(vapor); - n.f2.accept(this, symt); - n.f3.accept(this, symt); + n.f2.accept(this, args); + n.f3.accept(this, args); return mod; } @@ -819,10 +824,10 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { * f0 -> "!" * f1 -> Expression() */ - public String visit(NotExpression n, SymbolTable symt) { + public String visit(NotExpression n, String args) { String mod = ""; - n.f0.accept(this, symt); - n.f1.accept(this, symt); + n.f0.accept(this, args); + n.f1.accept(this, args); return mod; } @@ -831,11 +836,11 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> { * f1 -> Expression() * f2 -> ")" */ - public String visit(BracketExpression n, SymbolTable symt) { + public String visit(BracketExpression n, String args) { String mod = ""; - n.f0.accept(this, symt); - n.f1.accept(this, symt); - n.f2.accept(this, symt); + n.f0.accept(this, args); + n.f1.accept(this, args); + n.f2.accept(this, args); return mod; } diff --git a/vaporize/library/ControlFlowGraph.java b/vaporize/library/ControlFlowGraph.java index 0153b38..787ef8f 100644 --- a/vaporize/library/ControlFlowGraph.java +++ b/vaporize/library/ControlFlowGraph.java @@ -7,35 +7,61 @@ import java.util.*; public class ControlFlowGraph<P, R> extends VInstr.VisitorPR<P, R, RuntimeException> { - public R visit(P p, VMemRead r) throws RuntimeException { + + 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 R visit(P p, VMemWrite w) throws RuntimeException { + public R visit(P p, VMemWrite n) throws RuntimeException { + PrintFilter.print(String.format("%s (%s)", + n.getClass().getSimpleName(), + n.sourcePos.toString()), true); return null; } - public R visit(P p, VAssign a) throws RuntimeException { + 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 b) throws RuntimeException { + 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 g) throws RuntimeException { + 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 c) throws RuntimeException { + 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 c) throws RuntimeException { + 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 r) throws RuntimeException { + public R visit(P p, VReturn n) throws RuntimeException { + PrintFilter.print(String.format("%s (%s)", + n.getClass().getSimpleName(), + n.sourcePos.toString()), true); return null; } diff --git a/vaporize/library/TotalSpill.java b/vaporize/library/TotalSpill.java deleted file mode 100644 index cd75712..0000000 --- a/vaporize/library/TotalSpill.java +++ /dev/null @@ -1,68 +0,0 @@ -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> { - - - 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 R visit(P p, VMemWrite n) throws RuntimeException { - PrintFilter.print(String.format("%s (%s)", - n.getClass().getSimpleName(), - n.sourcePos.toString()), true); - return null; - } - - 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; - } - -} |