diff options
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; + } +} |