summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--V2VM.java2
-rw-r--r--boil/library/BoilSimp.java35
-rw-r--r--vaporize/library/CFGSimp.java18
-rw-r--r--vaporize/library/Node.java38
4 files changed, 35 insertions, 58 deletions
diff --git a/V2VM.java b/V2VM.java
index a234db6..12064ad 100644
--- a/V2VM.java
+++ b/V2VM.java
@@ -29,7 +29,7 @@ public class V2VM {
ArrayList<ControlFlowGraph> cfgs = new ArrayList<ControlFlowGraph>();
for (VFunction f : prog.functions) {
- CFGSimp<String, Void> cfg = new CFGSimp<String, Void>(f);
+ CFGSimp cfg = new CFGSimp(f);
cfgs.add(cfg.getCFG());
}
diff --git a/boil/library/BoilSimp.java b/boil/library/BoilSimp.java
index 0d45485..03e18fb 100644
--- a/boil/library/BoilSimp.java
+++ b/boil/library/BoilSimp.java
@@ -373,7 +373,7 @@ public class BoilSimp extends GJDepthFirst<String,String> {
*/
public String visit(Statement n, String args) {
String mod = "";
- n.f0.accept(this, args);
+ mod += n.f0.accept(this, args);
return mod;
}
@@ -422,12 +422,6 @@ public class BoilSimp extends GJDepthFirst<String,String> {
return mod;
}
- // if (t == null ) { // anonymous?
- // t = new TypeInstance(Integer.toString(this.id++), TypeEnum.classname); // FIXME maybe this is wrong for arrays?
- // t.addClassInstance(this.symt.getClass(cls));
- // }
-
-
/**
* f0 -> Identifier()
* f1 -> "["
@@ -479,11 +473,26 @@ public class BoilSimp extends GJDepthFirst<String,String> {
*/
public String visit(WhileStatement n, String args) {
String mod = "";
+ int while_id = this.id++;
+ vapor += String.format("while%d_test:\n",
+ while_id);
n.f0.accept(this, args);
n.f1.accept(this, args);
- n.f2.accept(this, args);
+ String expr = n.f2.accept(this, args);
+ vapor += String.format(" %s = %s\n",
+ this.tf.alias(Integer.toString(this.id++)),
+ expr);
+ vapor += String.format(" if0 %s goto :while%d_end\nwhile%d_body:\n",
+ this.tf.alias(Integer.toString(this.id-1)),
+ while_id,
+ while_id);
+
n.f3.accept(this, args);
n.f4.accept(this, args);
+
+ vapor += String.format(" goto :while%d_test\nwhile%d_end:\n",
+ while_id,
+ while_id);
return mod;
}
@@ -548,9 +557,13 @@ public class BoilSimp extends GJDepthFirst<String,String> {
*/
public String visit(CompareExpression n, String args) {
String mod = "";
- n.f0.accept(this, args);
+ String oper1 = n.f0.accept(this, args);
n.f1.accept(this, args);
- n.f2.accept(this, args);
+ String oper2 = n.f2.accept(this, args);
+
+ mod += String.format("LtS(%s %s)",
+ oper1,
+ oper2);
return mod;
}
@@ -675,6 +688,8 @@ public class BoilSimp extends GJDepthFirst<String,String> {
String tp1 = Integer.toString(this.id++); // TypeFactory likes to know who it's renting to
String tp2 = "tp2";
+ System.out.println("id " + id);
+ System.out.println("cur " + cur);
int mtdIndex = cur.getClassInstance().getMethods()
.indexOf(this.symt.getMethod(id2)) * 4;
diff --git a/vaporize/library/CFGSimp.java b/vaporize/library/CFGSimp.java
index 6ab276a..3a612bd 100644
--- a/vaporize/library/CFGSimp.java
+++ b/vaporize/library/CFGSimp.java
@@ -5,7 +5,7 @@ import st.*;
import misc.*;
import java.util.*;
-public class CFGSimp<P, R> extends VInstr.VisitorPR<P, R, RuntimeException> {
+public class CFGSimp extends VInstr.VisitorPR<String, String, RuntimeException> {
private ControlFlowGraph cfg;
@@ -29,36 +29,36 @@ public class CFGSimp<P, R> extends VInstr.VisitorPR<P, R, RuntimeException> {
return this.cfg;
}
- public R visit(P p, VMemRead n) throws RuntimeException {
+ public String visit(String p, VMemRead n) throws RuntimeException {
return null;
}
- public R visit(P p, VMemWrite n) throws RuntimeException {
+ public String visit(String p, VMemWrite n) throws RuntimeException {
return null;
}
- public R visit(P p, VAssign n) throws RuntimeException {
+ public String visit(String p, VAssign n) throws RuntimeException {
return null;
}
- public R visit(P p, VBranch n) throws RuntimeException {
+ public String visit(String p, VBranch n) throws RuntimeException {
// two edges
return null;
}
- public R visit(P p, VGoto n) throws RuntimeException {
+ public String visit(String p, VGoto n) throws RuntimeException {
return null;
}
- public R visit(P p, VCall n) throws RuntimeException {
+ public String visit(String p, VCall n) throws RuntimeException {
return null;
}
- public R visit(P p, VBuiltIn n) throws RuntimeException {
+ public String visit(String p, VBuiltIn n) throws RuntimeException {
return null;
}
- public R visit(P p, VReturn n) throws RuntimeException {
+ public String visit(String p, VReturn n) throws RuntimeException {
return null;
}
diff --git a/vaporize/library/Node.java b/vaporize/library/Node.java
deleted file mode 100644
index 203f931..0000000
--- a/vaporize/library/Node.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package vaporize.library;
-
-import cs132.vapor.ast.*;
-import java.util.ArrayList;
-
-class Node {
-
- private VInstr instruction;
- private ArrayList<Node> sources;
- private ArrayList<Node> 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<Node> getSources() {
- return this.sources;
- }
-
- protected ArrayList<Node> getDests() {
- return this.dests;
- }
-
-}