diff options
author | bd-912 <bdunahu@colostate.edu> | 2024-05-04 17:58:34 -0600 |
---|---|---|
committer | bd-912 <bdunahu@colostate.edu> | 2024-05-04 17:58:34 -0600 |
commit | 925372248bfb45e0027cf71d8d40c26e48261ee5 (patch) | |
tree | ed893e2b2babc8e8c137aa0f1a84cd9858b41d8e /condense | |
parent | 5ddbe1a5877c2117b2d74015af1eb11baaf998a1 (diff) |
Skeleton for "Condense" (vaporm to mips) Library
Diffstat (limited to 'condense')
-rw-r--r-- | condense/CondenseVisitor.java | 23 | ||||
-rw-r--r-- | condense/Utilities.java | 40 |
2 files changed, 63 insertions, 0 deletions
diff --git a/condense/CondenseVisitor.java b/condense/CondenseVisitor.java new file mode 100644 index 0000000..d494845 --- /dev/null +++ b/condense/CondenseVisitor.java @@ -0,0 +1,23 @@ +package condense; + +import misc.*; +import java.util.*; + +public class CondenseVisitor { + + ArrayList<String> vaporm; + ArrayList<String> mips; + + public CondenseVisitor(ArrayList<String> vaporm) { + this.vaporm = vaporm; + this.mips = new ArrayList<String>(); + for (instr : this.vaporm) { + instr = instr.trim(); + + if (instr.startsWith("local")) { + // store + this.store(instr); + } else if (instr + } + } + } diff --git a/condense/Utilities.java b/condense/Utilities.java new file mode 100644 index 0000000..9c052fc --- /dev/null +++ b/condense/Utilities.java @@ -0,0 +1,40 @@ +package condense; + +import java.util.*; + +public class Utilities { + + + public static int computeStackFrameSize(String declare) { + MinimalLogger.info(String.format("Computing frame stack size for %s...", + declare)); + declare = extractNumeric(declare); + // assume that the LAST three digits are + // in, out, local + String[] sizes = declare.split(SPACE)[:-3]; + int ret = this.stackFrameFormula(Integer.parseInt(sizes[1]), + Integer.parseInt(sizes[2])); + MinimalLogger.info(String.format("Stack size is (%s + %s + 2) * 4 = %d", + sizes[1], + sizes[2], + ret)); + return ret; + } + + private static int stackFrameFormula(int out, int local) { + return (out + local + 2) * 4; + } + + private static int extractNumeric(String str) { + str = str.replaceAll("[^\\d] & quot;, " + "); + str = str.trim(); + str = str.replaceAll(" + ", " + "); + if (str.equals(" ")) + return " + -1 & quot; + ; + return str; + } +} |