summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--vaporize/library/Kettle.java45
-rw-r--r--vaporize/library/SpillEverywhere.java20
2 files changed, 47 insertions, 18 deletions
diff --git a/vaporize/library/Kettle.java b/vaporize/library/Kettle.java
index 2590d4b..340d53e 100644
--- a/vaporize/library/Kettle.java
+++ b/vaporize/library/Kettle.java
@@ -5,7 +5,8 @@ import java.util.ArrayList;
/**
* This class contains various generic methods for
- * assembling common-use vaporm strings.
+ * assembling common-use vaporm strings and managing
+ * the original input program.
*
* Robert Martin cries
*/
@@ -17,20 +18,21 @@ class Kettle {
this.vapor = vapor;
}
- protected String indexOriginal(Node n) {
+ protected String get(Node n) {
/**
* Given the source position of a Node, returns the original line.
*/
- return this.vapor.get(n.sourcePos.line-1);
+ return this.vapor.get(this.indexOf(n));
}
- protected String functionParameters(VFunction prev, int in,
+ protected void replaceFunctionDeclare(VFunction prev, int in,
int out, int local) {
- return String.format("func %s [in %d, out %d, local %d]",
- this.indexOriginal(prev).split(" ")[1],
- in,
- out,
- local);
+ this.set(prev,
+ String.format("func %s [in %d, out %d, local %d]",
+ this.parseFuncName(this.get(prev)),
+ in,
+ out,
+ local));
}
protected String spill() {
@@ -40,4 +42,29 @@ class Kettle {
protected String backup() {
return null;
}
+
+ protected String dump() {
+ return String.join("\n", this.vapor);
+ }
+
+ private int indexOf(Node n) {
+ return n.sourcePos.line-1;
+ }
+
+ private void set(Node n, String s) {
+ /**
+ * Sets the position of Node n in the original
+ * file to String s.
+ */
+ this.vapor.set(this.indexOf(n), s);
+ }
+
+ private static String parseFuncName(String func) {
+ /**
+ * "func A_foo(this t.1)" -> "A_foo"
+ */
+ int openParenIndex = func.indexOf('(');
+ return func.substring(5, openParenIndex);
+ }
+
}
diff --git a/vaporize/library/SpillEverywhere.java b/vaporize/library/SpillEverywhere.java
index b910270..a1b0968 100644
--- a/vaporize/library/SpillEverywhere.java
+++ b/vaporize/library/SpillEverywhere.java
@@ -33,14 +33,16 @@ public class SpillEverywhere extends VInstr.VisitorPR<String, String, RuntimeExc
for (VInstr s : f.body) {
// s.accept("", this);
}
- PrintFilter.print(this.kettle.indexOriginal(f), true);
+ PrintFilter.print(this.kettle.get(f), true);
+ this.kettle.replaceFunctionDeclare(f, 0, 0, 0);
}
+ PrintFilter.print(kettle.dump(), true);
}
public String visit(String p, VMemRead n) throws RuntimeException {
PrintFilter.print(String.format("%s (%s:%s)",
n.getClass().getSimpleName(),
- this.kettle.indexOriginal(n),
+ this.kettle.get(n),
n.sourcePos.toString()), true);
return null;
}
@@ -48,7 +50,7 @@ public class SpillEverywhere extends VInstr.VisitorPR<String, String, RuntimeExc
public String visit(String p, VMemWrite n) throws RuntimeException {
PrintFilter.print(String.format("%s (%s:%s)",
n.getClass().getSimpleName(),
- this.kettle.indexOriginal(n),
+ this.kettle.get(n),
n.sourcePos.toString()), true);
return null;
}
@@ -56,7 +58,7 @@ public class SpillEverywhere extends VInstr.VisitorPR<String, String, RuntimeExc
public String visit(String p, VAssign n) throws RuntimeException {
PrintFilter.print(String.format("%s (%s:%s)",
n.getClass().getSimpleName(),
- this.kettle.indexOriginal(n),
+ this.kettle.get(n),
n.sourcePos.toString()), true);
return null;
}
@@ -64,7 +66,7 @@ public class SpillEverywhere extends VInstr.VisitorPR<String, String, RuntimeExc
public String visit(String p, VBranch n) throws RuntimeException {
PrintFilter.print(String.format("%s (%s:%s)",
n.getClass().getSimpleName(),
- this.kettle.indexOriginal(n),
+ this.kettle.get(n),
n.sourcePos.toString()), true);
return null;
}
@@ -72,7 +74,7 @@ public class SpillEverywhere extends VInstr.VisitorPR<String, String, RuntimeExc
public String visit(String p, VGoto n) throws RuntimeException {
PrintFilter.print(String.format("%s (%s:%s)",
n.getClass().getSimpleName(),
- this.kettle.indexOriginal(n),
+ this.kettle.get(n),
n.sourcePos.toString()), true);
return null;
}
@@ -80,7 +82,7 @@ public class SpillEverywhere extends VInstr.VisitorPR<String, String, RuntimeExc
public String visit(String p, VCall n) throws RuntimeException {
PrintFilter.print(String.format("%s (%s:%s)",
n.getClass().getSimpleName(),
- this.kettle.indexOriginal(n),
+ this.kettle.get(n),
n.sourcePos.toString()), true);
return null;
}
@@ -88,7 +90,7 @@ public class SpillEverywhere extends VInstr.VisitorPR<String, String, RuntimeExc
public String visit(String p, VBuiltIn n) throws RuntimeException {
PrintFilter.print(String.format("%s (%s:%s)",
n.op.name,
- this.kettle.indexOriginal(n),
+ this.kettle.get(n),
n.sourcePos.toString()), true);
return null;
}
@@ -96,7 +98,7 @@ public class SpillEverywhere extends VInstr.VisitorPR<String, String, RuntimeExc
public String visit(String p, VReturn n) throws RuntimeException {
PrintFilter.print(String.format("%s (%s:%s)",
n.getClass().getSimpleName(),
- this.kettle.indexOriginal(n),
+ this.kettle.get(n),
n.sourcePos.toString()), true);
return null;
}