summaryrefslogtreecommitdiff
path: root/condense/CondenseVisitor.java
diff options
context:
space:
mode:
Diffstat (limited to 'condense/CondenseVisitor.java')
-rw-r--r--condense/CondenseVisitor.java65
1 files changed, 65 insertions, 0 deletions
diff --git a/condense/CondenseVisitor.java b/condense/CondenseVisitor.java
index a35699f..b296f4c 100644
--- a/condense/CondenseVisitor.java
+++ b/condense/CondenseVisitor.java
@@ -105,6 +105,18 @@ public class CondenseVisitor extends VInstr.Visitor<RuntimeException>{
return sort;
}
+ public static boolean isNumeric(String strNum) {
+ if (strNum == null) {
+ return false;
+ }
+ try {
+ double d = Double.parseDouble(strNum);
+ } catch (NumberFormatException nfe) {
+ return false;
+ }
+ return true;
+ }
+
public void visit(VAssign n) throws RuntimeException {
MinimalLogger.info(String.format("->%s (%s)",
n.getClass().getSimpleName(),
@@ -137,7 +149,49 @@ public class CondenseVisitor extends VInstr.Visitor<RuntimeException>{
n.getClass().getSimpleName(),
n.sourcePos.toString()));
///////////////////////////////////////////////////////////////
+ // treat the arguments (place all in temp registers)
+
+ String[] ts = new String[] { "$t9", "$v1"};
+ 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()));
+ }
+ String ret = "";
+ String op = ((VBuiltIn.Op) n.op).name;
+ if (op.equals("Add"))
+ ret += " add";
+ else if (op.equals("Sub"))
+ ret += " sub";
+ else if (op.equals("MulS"))
+ ret += " mul";
+ else if (op.equals("Eq"))
+ ret += "NULL"; // fixme
+ else if (op.equals("Lt"))
+ ;
+ else if (op.equals("LtS"))
+ ;
+ else if (op.equals("PrintIntS"))
+ ;
+ else if (op.equals("HeapAllocZ"))
+ ;
+ else if (op.equals("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]);
+
+ this.addMIPS(ret);
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<-%s (%s)",
n.getClass().getSimpleName(),
@@ -177,7 +231,18 @@ public class CondenseVisitor extends VInstr.Visitor<RuntimeException>{
n.getClass().getSimpleName(),
n.sourcePos.toString()));
///////////////////////////////////////////////////////////////
+ String ret = " ";
+ if (n.positive)
+ ret += "bnez ";
+ else
+ ret += "beqz ";
+
+ ret += n.value.toString()
+ + " :";
+
+ ret += n.target.ident;
+ this.addMIPS(ret);
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<-%s (%s)",
n.getClass().getSimpleName(),