From c14f3676114df656e5c6c07b49351c74496aaf04 Mon Sep 17 00:00:00 2001 From: bd-912 Date: Wed, 17 Apr 2024 12:22:22 -0600 Subject: Rename Node->NodeCFG to avoid namespace collision --- V2VM.java | 17 +++++---- vaporize/library/CFGSimp.java | 23 +++++++++++-- vaporize/library/ControlFlowGraph.java | 22 +++++++++--- vaporize/library/SpillEverywhere.java | 63 +++++++++++++++++----------------- 4 files changed, 76 insertions(+), 49 deletions(-) diff --git a/V2VM.java b/V2VM.java index 6a0645b..a234db6 100644 --- a/V2VM.java +++ b/V2VM.java @@ -27,18 +27,17 @@ public class V2VM { VaporProgram prog = parseVapor(System.in, System.out); - ControlFlowGraph cfg = new ControlFlowGraph(); - CFGSimp cfg_vis = new CFGSimp(cfg); - - for (VFunction f : prog.functions) - for (VInstr s : f.body) - s.accept("", cfg_vis); + ArrayList cfgs = new ArrayList(); + for (VFunction f : prog.functions) { + CFGSimp cfg = new CFGSimp(f); + cfgs.add(cfg.getCFG()); + } SpillEverywhere se = new SpillEverywhere(strProg); - for (VFunction f : prog.functions) - for (VInstr s : f.body) - s.accept("", se); + // for (VFunction f : prog.functions) + // for (VInstr s : f.body) + // s.accept("", se); } catch (IOException e) { System.out.println(e.toString()); diff --git a/vaporize/library/CFGSimp.java b/vaporize/library/CFGSimp.java index 372f926..6ab276a 100644 --- a/vaporize/library/CFGSimp.java +++ b/vaporize/library/CFGSimp.java @@ -7,10 +7,26 @@ import java.util.*; public class CFGSimp extends VInstr.VisitorPR { - ControlFlowGraph cfg; + private ControlFlowGraph cfg; - public CFGSimp(ControlFlowGraph cfg) { - this.cfg = cfg; + public CFGSimp(VFunction n) { + this.cfg = new ControlFlowGraph(); + CFGNode start = new CFGNode(n.body[0]); + this.cfg.setStart(start); + + // nodes + for (VInstr s : n.body) + this.cfg.addNode(new CFGNode(s)); + + // edges + for (VInstr s : n.body) + s.accept("", this); + + System.out.println(this.cfg.getNodes().toString()); + } + + public ControlFlowGraph getCFG() { + return this.cfg; } public R visit(P p, VMemRead n) throws RuntimeException { @@ -26,6 +42,7 @@ public class CFGSimp extends VInstr.VisitorPR { } public R visit(P p, VBranch n) throws RuntimeException { + // two edges return null; } diff --git a/vaporize/library/ControlFlowGraph.java b/vaporize/library/ControlFlowGraph.java index f181d36..773c4cd 100644 --- a/vaporize/library/ControlFlowGraph.java +++ b/vaporize/library/ControlFlowGraph.java @@ -5,9 +5,9 @@ import java.util.ArrayList; public class ControlFlowGraph { - private ArrayList nodes; - private Node start; - private Node end; + private ArrayList nodes; + private CFGNode start; + private CFGNode end; public ControlFlowGraph() { this.nodes = new ArrayList<>(); @@ -15,13 +15,25 @@ public class ControlFlowGraph { this.end = null; } - protected void addNode(Node node) { + protected void addNode(CFGNode node) { this.nodes.add(node); } - protected void addEdge(Node source, Node dest) { + protected void addEdge(CFGNode source, CFGNode dest) { source.addDest(dest); dest.addSource(source); } + protected void setStart(CFGNode start) { + this.start = start; + } + + /** + * The following methods are for testing + * only! + */ + protected ArrayList getNodes() { + return this.nodes; + } + } diff --git a/vaporize/library/SpillEverywhere.java b/vaporize/library/SpillEverywhere.java index aa8368f..5edbbfc 100644 --- a/vaporize/library/SpillEverywhere.java +++ b/vaporize/library/SpillEverywhere.java @@ -45,40 +45,39 @@ public class SpillEverywhere extends VInstr.VisitorPR