summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--VM2M.java14
-rw-r--r--condense/CondenseVisitor.java23
-rw-r--r--condense/Utilities.java40
-rw-r--r--mars.jarbin0 -> 3124936 bytes
-rw-r--r--misc/SplitProgramInputStream.java22
-rwxr-xr-xrunner.sh4
6 files changed, 102 insertions, 1 deletions
diff --git a/VM2M.java b/VM2M.java
new file mode 100644
index 0000000..e368aa1
--- /dev/null
+++ b/VM2M.java
@@ -0,0 +1,14 @@
+import java.io.*;
+import java.util.ArrayList;
+
+import condense.*;
+import misc.*;
+
+public class VM2M {
+
+ public static void main(String[] args) {
+
+ ArrayList<String> strProgram = SplitProgramInputStream.split(System.in);
+ CondenseVisitor cv = new CondenseVisitor(strProgram);
+ }
+}
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;
+ }
+}
diff --git a/mars.jar b/mars.jar
new file mode 100644
index 0000000..a7f6c6f
--- /dev/null
+++ b/mars.jar
Binary files differ
diff --git a/misc/SplitProgramInputStream.java b/misc/SplitProgramInputStream.java
new file mode 100644
index 0000000..a7f1c82
--- /dev/null
+++ b/misc/SplitProgramInputStream.java
@@ -0,0 +1,22 @@
+package misc;
+
+import java.io.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+
+public class SplitProgramInputStream {
+
+ public static ArrayList<String> split(InputStream inputStream) {
+ ArrayList<String> lines = new ArrayList<>();
+ try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
+ String line;
+ while ((line = reader.readLine()) != null) {
+ lines.add(line);
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return lines;
+ }
+
+}
diff --git a/runner.sh b/runner.sh
index 19c4960..3ff381e 100755
--- a/runner.sh
+++ b/runner.sh
@@ -37,7 +37,9 @@ function vaporize() {
function condense() {
# condense the file
- echo "Not finished!"
+ ext="s"
+ java VM2M < $1 > "./output/${filename}.$ext"
+ java -jar mars.jar nc "./output/${filename}.$ext"
}