From 3aebefa92757992276d91043086f5b9e50e449ca Mon Sep 17 00:00:00 2001 From: bd-912 Date: Tue, 7 May 2024 14:54:53 -0600 Subject: Partial Condense.VBuiltIn support --- condense/CondenseVisitor.java | 65 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) 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{ 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{ 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{ 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(), -- cgit v1.2.3