From 21f8331c41f268de77b4cc87f9e118effc6017cb Mon Sep 17 00:00:00 2001 From: bd-912 Date: Mon, 6 May 2024 01:09:18 -0600 Subject: Condense epilogue, VCall, MemWrite --- V2VM.java | 21 +-------------------- condense/CondenseVisitor.java | 13 +++++++++++-- 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 strProg = inputStreamToArrayList(is1); + ArrayList strProg = SplitProgramInputStream.split(is1); VaporProgram prog = parseVapor(is2, System.out); @@ -90,19 +84,6 @@ public class V2VM { return program; } - public static ArrayList inputStreamToArrayList(InputStream inputStream) { - ArrayList 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{ 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{ 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{ 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(), -- cgit v1.2.3