diff options
author | bd-912 <bdunahu@colostate.edu> | 2024-04-17 01:33:05 -0600 |
---|---|---|
committer | bd-912 <bdunahu@colostate.edu> | 2024-04-17 01:33:05 -0600 |
commit | 62178e370f21ddf80766b8e1075c55e0d3945493 (patch) | |
tree | 13fcfc0d7177e578020366e905b71ca48e0857f0 /V2VM.java | |
parent | f08708ee07931db592ffb76c073bd80bcf6cf060 (diff) |
CFG Skeleton Files
Diffstat (limited to 'V2VM.java')
-rw-r--r-- | V2VM.java | 54 |
1 files changed, 49 insertions, 5 deletions
@@ -1,9 +1,12 @@ import java.io.*; +import java.util.ArrayList; import cs132.util.ProblemException; import cs132.vapor.parser.VaporParser; import cs132.vapor.ast.VaporProgram; import cs132.vapor.ast.VBuiltIn.Op; +import cs132.vapor.ast.VDataSegment; import cs132.vapor.ast.VFunction; +import cs132.vapor.ast.VInstr; import java.io.InputStreamReader; import java.io.IOException; @@ -17,13 +20,25 @@ public class V2VM { public static void main(String[] args) { try { - VFunction[] funts = parseVapor(System.in, System.out).functions; + System.in.mark(-1); + InputStream systemInCopy = createCopyOfSystemIn(); + System.in.reset(); + ArrayList<String> strProg = inputStreamToArrayList(systemInCopy); - ControlFlowGraph<String, Void> cfg = new ControlFlowGraph<String, Void>(); + VaporProgram prog = parseVapor(System.in, System.out); - for (VFunction f : funts) { - f.body[0].accept("", cfg); - } + ControlFlowGraph cfg = new ControlFlowGraph(); + CFGSimp<String, Void> cfg_vis = new CFGSimp<String, Void>(cfg); + + for (VFunction f : prog.functions) + for (VInstr s : f.body) + s.accept("", cfg_vis); + + SpillEverywhere<String, Void> se = new SpillEverywhere<String, Void>(strProg); + + for (VFunction f : prog.functions) + for (VInstr s : f.body) + s.accept("", se); } catch (IOException e) { System.out.println(e.toString()); @@ -52,4 +67,33 @@ 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; + } + + private static InputStream createCopyOfSystemIn() { + byte[] buffer = new byte[1024]; + int bytesRead; + ByteArrayInputStream bais = new ByteArrayInputStream(buffer); + + try { + bytesRead = System.in.read(buffer); + bais = new ByteArrayInputStream(buffer, 0, bytesRead); + } catch (IOException e) { + e.printStackTrace(); + } + + return bais; + } + } |