summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--V2VM.java21
-rw-r--r--condense/CondenseVisitor.java13
2 files changed, 12 insertions, 22 deletions
diff --git a/V2VM.java b/V2VM.java
index 7e2f07e..cbe11eb 100644
--- a/V2VM.java
+++ b/V2VM.java
@@ -8,12 +8,6 @@ import cs132.vapor.ast.VDataSegment;
import cs132.vapor.ast.VFunction;
import cs132.vapor.ast.VInstr;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.PrintStream;
import java.util.Arrays;
import cfg.*;
@@ -31,7 +25,7 @@ public class V2VM {
InputStream is2 = new ByteArrayInputStream(bytes);
InputStream systemInCopy = createCopyOfSystemIn();
- ArrayList<String> strProg = inputStreamToArrayList(is1);
+ ArrayList<String> strProg = SplitProgramInputStream.split(is1);
VaporProgram prog = parseVapor(is2, System.out);
@@ -90,19 +84,6 @@ public class V2VM {
return program;
}
- public static ArrayList<String> inputStreamToArrayList(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;
- }
-
public static byte[] readAllBytes(InputStream inputStream) throws IOException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int nRead;
diff --git a/condense/CondenseVisitor.java b/condense/CondenseVisitor.java
index 4ca987c..96203be 100644
--- a/condense/CondenseVisitor.java
+++ b/condense/CondenseVisitor.java
@@ -40,6 +40,12 @@ public class CondenseVisitor extends VInstr.Visitor<RuntimeException>{
this.addMIPS(((VCodeLabel) n).ident + ":");
}
+ // epilogue
+ this.addMIPS(" lw $ra -4($fp)");
+ this.addMIPS(" lw $fp -8($fp)");
+ this.addMIPS(String.format(" addu $sp $sp %d",
+ this.curr.getFrameSize()));
+ this.addMIPS(" jr $ra");
}
}
@@ -85,7 +91,8 @@ public class CondenseVisitor extends VInstr.Visitor<RuntimeException>{
n.getClass().getSimpleName(),
n.sourcePos.toString()));
///////////////////////////////////////////////////////////////
-
+ this.addMIPS(String.format(" jal %s",
+ n.addr.toString().substring(1)));
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<-%s (%s)",
n.getClass().getSimpleName(),
@@ -123,7 +130,9 @@ public class CondenseVisitor extends VInstr.Visitor<RuntimeException>{
n.getClass().getSimpleName(),
n.sourcePos.toString()));
///////////////////////////////////////////////////////////////
-
+ this.addMIPS(String.format(" lw %s %s",
+ n.dest.toString(),
+ this.curr.get(((VMemRef.Stack) n.source))));
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<-%s (%s)",
n.getClass().getSimpleName(),