diff options
Diffstat (limited to 'condense')
-rw-r--r-- | condense/CondenseVisitor.java | 54 |
1 files changed, 41 insertions, 13 deletions
diff --git a/condense/CondenseVisitor.java b/condense/CondenseVisitor.java index 0894a9f..7ba2beb 100644 --- a/condense/CondenseVisitor.java +++ b/condense/CondenseVisitor.java @@ -163,6 +163,7 @@ public class CondenseVisitor extends VInstr.Visitor<RuntimeException>{ n.args[i].toString())); } + boolean done = false; String ret = ""; String op = ((VBuiltIn.Op) n.op).name; if (op.equals("Add")) @@ -179,19 +180,26 @@ public class CondenseVisitor extends VInstr.Visitor<RuntimeException>{ ret += " slti"; else if (op.equals("PrintIntS")) ret += " jal _print"; - else if (op.equals("HeapAllocZ")) - ret += " jal _heapAlloc"; + else if (op.equals("HeapAllocZ")) { + this.addMIPS(" jal _heapAlloc"); + if (n.dest != null) + this.addMIPS(String.format(" move $%s $v0", + ((VVarRef.Register) n.dest).ident)); + done = true; + } else if (op.equals("Error")) ret += " la $a0 _str0\n j _error"; - if (n.dest != null) - ret += String.format(" $%s", - ((VVarRef.Register) n.dest).ident); - for (int i = 0; i < n.args.length; ++i) - ret += String.format(" %s", - ts[i]); + if (!done) { + if (n.dest != null) + ret += String.format(" $%s", + ((VVarRef.Register) n.dest).ident); + for (int i = 0; i < n.args.length; ++i) + ret += String.format(" %s", + ts[i]); + this.addMIPS(ret); + } - this.addMIPS(ret); /////////////////////////////////////////////////////////////// MinimalLogger.info(String.format("<-%s (%s)", n.getClass().getSimpleName(), @@ -203,9 +211,22 @@ public class CondenseVisitor extends VInstr.Visitor<RuntimeException>{ n.getClass().getSimpleName(), n.sourcePos.toString())); /////////////////////////////////////////////////////////////// + String source = n.source.toString(); + String dest; + + if (n.dest instanceof VMemRef.Stack) + dest = this.curr.get(((VMemRef.Stack) n.dest)); + else + dest = String.format("0(%s)", + ((VMemRef.Global) n.dest).base.toString()); + if (source.contains(":")) { + this.addMIPS(String.format(" la $t9 %s", + source.substring(1))); + source = "$t9"; + } this.addMIPS(String.format(" sw %s %s", - n.source.toString(), - this.curr.get(((VMemRef.Stack) n.dest)))); + source, + dest)); /////////////////////////////////////////////////////////////// MinimalLogger.info(String.format("<-%s (%s)", n.getClass().getSimpleName(), @@ -217,9 +238,16 @@ public class CondenseVisitor extends VInstr.Visitor<RuntimeException>{ n.getClass().getSimpleName(), n.sourcePos.toString())); /////////////////////////////////////////////////////////////// + String dest = n.dest.toString(); + String source; + + if (n.source instanceof VMemRef.Stack) + source = this.curr.get(((VMemRef.Stack) n.source)); + else + source = ((VMemRef.Global) n.source).base.toString(); this.addMIPS(String.format(" lw %s %s", - n.dest.toString(), - this.curr.get(((VMemRef.Stack) n.source)))); + dest, + source)); /////////////////////////////////////////////////////////////// MinimalLogger.info(String.format("<-%s (%s)", n.getClass().getSimpleName(), |