From 62178e370f21ddf80766b8e1075c55e0d3945493 Mon Sep 17 00:00:00 2001 From: bd-912 Date: Wed, 17 Apr 2024 01:33:05 -0600 Subject: CFG Skeleton Files --- vaporize/library/CFGSimp.java | 48 +++++++++++++++++++ vaporize/library/ControlFlowGraph.java | 69 ++++++---------------------- vaporize/library/Node.java | 38 +++++++++++++++ vaporize/library/SpillEverywhere.java | 84 ++++++++++++++++++++++++++++++++++ 4 files changed, 184 insertions(+), 55 deletions(-) create mode 100644 vaporize/library/CFGSimp.java create mode 100644 vaporize/library/Node.java create mode 100644 vaporize/library/SpillEverywhere.java (limited to 'vaporize/library') diff --git a/vaporize/library/CFGSimp.java b/vaporize/library/CFGSimp.java new file mode 100644 index 0000000..372f926 --- /dev/null +++ b/vaporize/library/CFGSimp.java @@ -0,0 +1,48 @@ +package vaporize.library; + +import cs132.vapor.ast.*; +import st.*; +import misc.*; +import java.util.*; + +public class CFGSimp extends VInstr.VisitorPR { + + ControlFlowGraph cfg; + + public CFGSimp(ControlFlowGraph cfg) { + this.cfg = cfg; + } + + public R visit(P p, VMemRead n) throws RuntimeException { + return null; + } + + public R visit(P p, VMemWrite n) throws RuntimeException { + return null; + } + + public R visit(P p, VAssign n) throws RuntimeException { + return null; + } + + public R visit(P p, VBranch n) throws RuntimeException { + return null; + } + + public R visit(P p, VGoto n) throws RuntimeException { + return null; + } + + public R visit(P p, VCall n) throws RuntimeException { + return null; + } + + public R visit(P p, VBuiltIn n) throws RuntimeException { + return null; + } + + public R visit(P p, VReturn n) throws RuntimeException { + return null; + } + +} diff --git a/vaporize/library/ControlFlowGraph.java b/vaporize/library/ControlFlowGraph.java index 787ef8f..f181d36 100644 --- a/vaporize/library/ControlFlowGraph.java +++ b/vaporize/library/ControlFlowGraph.java @@ -1,68 +1,27 @@ package vaporize.library; import cs132.vapor.ast.*; -import st.*; -import misc.*; -import java.util.*; +import java.util.ArrayList; -public class ControlFlowGraph extends VInstr.VisitorPR { +public class ControlFlowGraph { + private ArrayList nodes; + private Node start; + private Node end; - public R visit(P p, VMemRead n) throws RuntimeException { - PrintFilter.print(String.format("%s (%s)", - n.getClass().getSimpleName(), - n.sourcePos.toString()), true); - return null; + public ControlFlowGraph() { + this.nodes = new ArrayList<>(); + this.start = null; + this.end = null; } - public R visit(P p, VMemWrite n) throws RuntimeException { - PrintFilter.print(String.format("%s (%s)", - n.getClass().getSimpleName(), - n.sourcePos.toString()), true); - return null; + protected void addNode(Node node) { + this.nodes.add(node); } - public R visit(P p, VAssign n) throws RuntimeException { - PrintFilter.print(String.format("%s (%s)", - n.getClass().getSimpleName(), - n.sourcePos.toString()), true); - return null; - } - - public R visit(P p, VBranch n) throws RuntimeException { - PrintFilter.print(String.format("%s (%s)", - n.getClass().getSimpleName(), - n.sourcePos.toString()), true); - return null; - } - - public R visit(P p, VGoto n) throws RuntimeException { - PrintFilter.print(String.format("%s (%s)", - n.getClass().getSimpleName(), - n.sourcePos.toString()), true); - return null; - } - - public R visit(P p, VCall n) throws RuntimeException { - PrintFilter.print(String.format("%s (%s)", - n.getClass().getSimpleName(), - n.sourcePos.toString()), true); - return null; - } - - public R visit(P p, VBuiltIn n) throws RuntimeException { - PrintFilter.print(String.format("%s (%s:%s)", - n.getClass().getSimpleName(), - n.op.name, - n.sourcePos.toString()), true); - return null; - } - - public R visit(P p, VReturn n) throws RuntimeException { - PrintFilter.print(String.format("%s (%s)", - n.getClass().getSimpleName(), - n.sourcePos.toString()), true); - return null; + protected void addEdge(Node source, Node dest) { + source.addDest(dest); + dest.addSource(source); } } diff --git a/vaporize/library/Node.java b/vaporize/library/Node.java new file mode 100644 index 0000000..203f931 --- /dev/null +++ b/vaporize/library/Node.java @@ -0,0 +1,38 @@ +package vaporize.library; + +import cs132.vapor.ast.*; +import java.util.ArrayList; + +class Node { + + private VInstr instruction; + private ArrayList sources; + private ArrayList dests; + + protected Node(VInstr instruction) { + this.instruction = instruction; + this.sources = new ArrayList<>(); + this.dests = new ArrayList<>(); + } + + protected void addSource(Node node) { + this.sources.add(node); + } + + protected void addDest(Node node) { + this.dests.add(node); + } + + protected VInstr getInstruction() { + return this.instruction; + } + + protected ArrayList getSources() { + return this.sources; + } + + protected ArrayList getDests() { + return this.dests; + } + +} diff --git a/vaporize/library/SpillEverywhere.java b/vaporize/library/SpillEverywhere.java new file mode 100644 index 0000000..aa8368f --- /dev/null +++ b/vaporize/library/SpillEverywhere.java @@ -0,0 +1,84 @@ +package vaporize.library; + +import cs132.vapor.ast.*; +import st.*; +import misc.*; +import java.util.*; + +public class SpillEverywhere extends VInstr.VisitorPR { + + ArrayList vapor; + String vaporm; + + + public SpillEverywhere(ArrayList vapor) { + this.vapor = vapor; + this.vaporm = ""; + } + + public R visit(P p, VMemRead n) throws RuntimeException { + PrintFilter.print(String.format("%s (%s:%s)", + n.getClass().getSimpleName(), + this.vapor.get(n.sourcePos.line-1), + n.sourcePos.toString()), true); + return null; + } + + public R visit(P p, VMemWrite n) throws RuntimeException { + PrintFilter.print(String.format("%s (%s:%s)", + n.getClass().getSimpleName(), + this.vapor.get(n.sourcePos.line-1), + n.sourcePos.toString()), true); + return null; + } + + public R visit(P p, VAssign n) throws RuntimeException { + PrintFilter.print(String.format("%s (%s:%s)", + n.getClass().getSimpleName(), + this.vapor.get(n.sourcePos.line-1), + n.sourcePos.toString()), true); + return null; + } + + public R visit(P p, VBranch n) throws RuntimeException { + PrintFilter.print(String.format("%s (%s:%s)", + n.getClass().getSimpleName(), + this.vapor.get(n.sourcePos.line-1), + n.sourcePos.toString()), true); + System.out.println("NEXT: " + + return null; + } + + public R visit(P p, VGoto n) throws RuntimeException { + PrintFilter.print(String.format("%s (%s:%s)", + n.getClass().getSimpleName(), + this.vapor.get(n.sourcePos.line-1), + n.sourcePos.toString()), true); + return null; + } + + public R visit(P p, VCall n) throws RuntimeException { + PrintFilter.print(String.format("%s (%s:%s)", + n.getClass().getSimpleName(), + this.vapor.get(n.sourcePos.line-1), + n.sourcePos.toString()), true); + return null; + } + + public R visit(P p, VBuiltIn n) throws RuntimeException { + PrintFilter.print(String.format("%s (%s:%s)", + n.op.name, + this.vapor.get(n.sourcePos.line-1), + n.sourcePos.toString()), true); + return null; + } + + public R visit(P p, VReturn n) throws RuntimeException { + PrintFilter.print(String.format("%s (%s:%s)", + n.getClass().getSimpleName(), + this.vapor.get(n.sourcePos.line-1), + n.sourcePos.toString()), true); + return null; + } + + } -- cgit v1.2.3