summaryrefslogtreecommitdiff
path: root/condense/CondenseVisitor.java
diff options
context:
space:
mode:
Diffstat (limited to 'condense/CondenseVisitor.java')
-rw-r--r--condense/CondenseVisitor.java39
1 files changed, 22 insertions, 17 deletions
diff --git a/condense/CondenseVisitor.java b/condense/CondenseVisitor.java
index 7ba2beb..05b5880 100644
--- a/condense/CondenseVisitor.java
+++ b/condense/CondenseVisitor.java
@@ -149,23 +149,25 @@ public class CondenseVisitor extends VInstr.Visitor<RuntimeException>{
n.getClass().getSimpleName(),
n.sourcePos.toString()));
///////////////////////////////////////////////////////////////
+ boolean done = false;
+ String ret = "";
+ String op = ((VBuiltIn.Op) n.op).name;
+ String[] ts = new String[] { "$a0", "$t9"};
// treat the arguments (place all in temp registers)
- String[] ts = new String[] { "$a0", "$t9"};
- for (int i = 0; i < n.args.length; ++i) {
- if (this.isNumeric(n.args[i].toString()))
- this.addMIPS(String.format(" li %s %s",
- ts[i],
- n.args[i].toString()));
- else
- this.addMIPS(String.format(" move %s %s",
- ts[i],
- n.args[i].toString()));
+ if (!op.equals("Error")) {
+ for (int i = 0; i < n.args.length; ++i) {
+ if (this.isNumeric(n.args[i].toString()))
+ this.addMIPS(String.format(" li %s %s",
+ ts[i],
+ n.args[i].toString()));
+ else
+ this.addMIPS(String.format(" move %s %s",
+ ts[i],
+ n.args[i].toString()));
+ }
}
- boolean done = false;
- String ret = "";
- String op = ((VBuiltIn.Op) n.op).name;
if (op.equals("Add"))
ret += " add";
else if (op.equals("Sub"))
@@ -187,8 +189,10 @@ public class CondenseVisitor extends VInstr.Visitor<RuntimeException>{
((VVarRef.Register) n.dest).ident));
done = true;
}
- else if (op.equals("Error"))
- ret += " la $a0 _str0\n j _error";
+ else if (op.equals("Error")) {
+ this.addMIPS(" la $a0 _str0\n j _error");
+ done = true;
+ }
if (!done) {
if (n.dest != null)
@@ -244,7 +248,8 @@ public class CondenseVisitor extends VInstr.Visitor<RuntimeException>{
if (n.source instanceof VMemRef.Stack)
source = this.curr.get(((VMemRef.Stack) n.source));
else
- source = ((VMemRef.Global) n.source).base.toString();
+ source = String.format("0(%s)",
+ ((VMemRef.Global) n.source).base.toString());
this.addMIPS(String.format(" lw %s %s",
dest,
source));
@@ -266,7 +271,7 @@ public class CondenseVisitor extends VInstr.Visitor<RuntimeException>{
ret += "beqz ";
ret += n.value.toString()
- + " :";
+ + " ";
ret += n.target.ident;