From 4907f4ed2f471f2ca23dd7ab30f602c1baed84c6 Mon Sep 17 00:00:00 2001 From: bd-912 Date: Mon, 15 Apr 2024 00:54:47 -0600 Subject: Add skeleton of CFG visitor --- V2VM.java | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 V2VM.java (limited to 'V2VM.java') diff --git a/V2VM.java b/V2VM.java new file mode 100644 index 0000000..0f745f0 --- /dev/null +++ b/V2VM.java @@ -0,0 +1,51 @@ +import java.io.*; +import cs132.util.ProblemException; +import cs132.vapor.parser.VaporParser; +import cs132.vapor.ast.VaporProgram; +import cs132.vapor.ast.VBuiltIn.Op; + +import java.io.InputStreamReader; +import java.io.IOException; +import java.io.PrintStream; + +import st.*; +import misc.*; +import vaporize.library.*; + +public class V2VM { + + public static void main(String[] args) { + try { + VaporProgram pgrm = parseVapor(System.in, System.out); + System.out.println(pgrm); + + ControlFlowGraph vp = new ControlFlowGraph(); + + } catch (IOException e) { + System.out.println(e.toString()); + System.exit(1); + } + } + + public static VaporProgram parseVapor(InputStream in, PrintStream err) throws IOException { + Op[] ops = { + Op.Add, Op.Sub, Op.MulS, Op.Eq, Op.Lt, Op.LtS, + Op.PrintIntS, Op.HeapAllocZ, Op.Error, + }; + boolean allowLocals = true; + String[] registers = null; + boolean allowStack = false; + + VaporProgram program; + try { + program = VaporParser.run(new InputStreamReader(in), 1, 1, + java.util.Arrays.asList(ops), + allowLocals, registers, allowStack); + } catch (ProblemException ex) { + err.println(ex.getMessage()); + return null; + } + + return program; + } +} -- cgit v1.2.3