summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbd-912 <bdunahu@colostate.edu>2024-05-07 17:30:18 -0600
committerbd-912 <bdunahu@colostate.edu>2024-05-07 17:30:18 -0600
commit362fa7c02b5a36a351c1d1c11a7d3c3f28fb67a5 (patch)
tree1fe9f85b0e73e37e2f98037799f65a3fa51f6e4d
parent240f236b13233f7c905d1e2f12c33bdbba8ffcda (diff)
Condense bugfixes wave 2
-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;