summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--V2VM.java17
-rw-r--r--vaporize/library/CFGSimp.java23
-rw-r--r--vaporize/library/ControlFlowGraph.java22
-rw-r--r--vaporize/library/SpillEverywhere.java63
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<String, Void> cfg_vis = new CFGSimp<String, Void>(cfg);
-
- for (VFunction f : prog.functions)
- for (VInstr s : f.body)
- s.accept("", cfg_vis);
+ ArrayList<ControlFlowGraph> cfgs = new ArrayList<ControlFlowGraph>();
+ for (VFunction f : prog.functions) {
+ CFGSimp<String, Void> cfg = new CFGSimp<String, Void>(f);
+ cfgs.add(cfg.getCFG());
+ }
SpillEverywhere<String, Void> se = new SpillEverywhere<String, Void>(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<P, R> extends VInstr.VisitorPR<P, R, RuntimeException> {
- 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<P, R> extends VInstr.VisitorPR<P, R, RuntimeException> {
}
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<Node> nodes;
- private Node start;
- private Node end;
+ private ArrayList<CFGNode> 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<CFGNode> 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<P, R> extends VInstr.VisitorPR<P, R, RuntimeExcepti
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;
- }
+ 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, 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, 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, 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, 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;
- }
+ 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;
}
+
+}