summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbd-912 <bdunahu@colostate.edu>2024-04-25 22:08:21 -0600
committerbd-912 <bdunahu@colostate.edu>2024-04-25 22:08:21 -0600
commita4090b25b5433ce007c91cabbd4c247f6a6c81f1 (patch)
tree478794329bd53efab260330ccbbba4890d8abf77
parent34fad9467618d10178d55f30c034f93ce03ada25 (diff)
BoilVisitor changes to Allocation
-rw-r--r--boil/library/BoilVisitor.java74
-rw-r--r--boil/tests/ex2.java7
-rw-r--r--st/SymTableMethods.java2
3 files changed, 42 insertions, 41 deletions
diff --git a/boil/library/BoilVisitor.java b/boil/library/BoilVisitor.java
index 7ae02b2..f977491 100644
--- a/boil/library/BoilVisitor.java
+++ b/boil/library/BoilVisitor.java
@@ -14,6 +14,7 @@ public class BoilVisitor extends GJDepthFirst<String,String> {
private SymbolTable symt;
private MethodInstance recentMethod = null; // the most recent method called
+ private ClassInstance recentClass = null;
public BoilVisitor(SymbolTable symt) {
this.symt = symt;
@@ -218,7 +219,7 @@ public class BoilVisitor extends GJDepthFirst<String,String> {
///////////////////////////////////////////////////////////////
this.addVapor(String.format("const functable_%s\n", id));
for (MethodInstance mtd : this.symt.getClass(id).getMethods()) {
- this.addVapor(String.format(" :%s_%s\n", id, mtd));
+ this.addVapor(String.format(" :%s_%s\n", mtd.getParentClass().getName(), mtd));
}
this.addVapor("\n");
// n.f3.accept(this, argu);
@@ -251,7 +252,7 @@ public class BoilVisitor extends GJDepthFirst<String,String> {
///////////////////////////////////////////////////////////////
this.addVapor(String.format("const functable_%s\n", id));
for (MethodInstance mtd : this.symt.getClass(id).getMethods()) {
- this.addVapor(String.format(" :%s_%s\n", id, mtd));
+ this.addVapor(String.format(" :%s_%s\n", mtd.getParentClass().getName(), mtd));
}
this.addVapor("\n");
// n.f3.accept(this, argu);
@@ -277,11 +278,10 @@ public class BoilVisitor extends GJDepthFirst<String,String> {
n.getClass().getSimpleName(),
id));
///////////////////////////////////////////////////////////////
- TypeInstance t = this.symt.getType(id);
- if (t.getClassInstance() != null)
- this.vapor += String.format(" %s = HeapAllocZ(%d)\n",
- this.tf.alias(t.getName()),
- t.getSize());
+ // if (t.getClassInstance() != null)
+ // this.addVapor(String.format(" %s = HeapAllocZ(%d)\n",
+ // this.tf.alias(t.getName()),
+ // t.getSize()));
n.f0.accept(this, argu);
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s (%s)",
@@ -514,10 +514,6 @@ public class BoilVisitor extends GJDepthFirst<String,String> {
int attr_index = 0;
TypeInstance t;
- if (expr.contains("functable")) {
- // an allocation
- lhs = String.format("[%s+%d]", lhs, attr_index);
- }
if ((t = this.symt.getType(lhs)) != null) {
// memory store
ClassInstance cur = (ClassInstance) this.symt.getActive(TypeEnum.classname);
@@ -730,10 +726,18 @@ public class BoilVisitor extends GJDepthFirst<String,String> {
///////////////////////////////////////////////////////////////
String oper1 = this.memoryRead(n.f0.accept(this, argu));
String oper2 = this.memoryRead(n.f2.accept(this, argu));
+ String one = this.tf.alias(this.getUniqueID());
+ this.addVapor(String.format(" %s = Eq(1 %s)\n",
+ one,
+ oper1));
+ String two = this.tf.alias(this.getUniqueID());
+ this.addVapor(String.format(" %s = Eq(1 %s)\n",
+ two,
+ oper2));
this.addVapor(String.format(" %s = Eq(%s %s)\n",
_ret,
- oper1,
- oper2));
+ one,
+ two));
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s with %s",
n.getClass().getSimpleName(),
@@ -939,6 +943,9 @@ public class BoilVisitor extends GJDepthFirst<String,String> {
// we'll do everything here and exit the function
MinimalLogger.info("Message send found THIS");
rhs = n.f0.accept(this, argu);
+ rhs = this.tf.alias(this.getUniqueID());
+ this.addVapor(String.format(" %s = [this]\n",
+ rhs));
ClassInstance cur = (ClassInstance) this.symt.getActive(TypeEnum.classname);
MinimalLogger.info("Calculating method index to call...");
int mtdIndex = cur.getMethods()
@@ -962,18 +969,12 @@ public class BoilVisitor extends GJDepthFirst<String,String> {
MinimalLogger.info("Message send found ANONYMOUS");
// expand the entire object out!
rhs = n.f0.accept(this, argu);
- t = new TypeInstance(this.getUniqueID(), TypeEnum.ERROR,
+ t = new TypeInstance(rhs, TypeEnum.ERROR,
(MethodInstance) this.symt.getActive(TypeEnum.method),
(ClassInstance) this.symt.getActive(TypeEnum.classname));
- t.addClassInstance(this.symt.getClass(rhs.substring(rhs.indexOf('_')+1)));
-
- this.addVapor(String.format(" %s = HeapAllocZ(%d)\n",
+ t.addClassInstance(this.recentClass);
+ this.addVapor(String.format(" %s = %s\n",
this.tf.alias(t.getName()),
- t.getSize()));
-
- this.addVapor(String.format(" [%s+%d] = %s\n",
- this.tf.alias(t.getName()),
- 0,
rhs));
break;
case 8:
@@ -995,22 +996,24 @@ public class BoilVisitor extends GJDepthFirst<String,String> {
String tp1 = this.tf.alias(this.getUniqueID());
String tp2 = this.tf.alias(this.getUniqueID());
- this.vapor += String.format(" %s = [%s+%d]\n",
+ this.addVapor(String.format(" %s = [%s+%d]\n",
tp1,
this.tf.alias(t.getName()),
- 0);
+ 0));
MinimalLogger.info("Calculating method index to call...");
MinimalLogger.severe("t: " + t);
+ MinimalLogger.severe("mtd: " + mtd);
MinimalLogger.severe("t.getClassInstance() " + t.getClassInstance());
+ MinimalLogger.severe("t.getClassInstance().getMethods() " + t.getClassInstance().getMethods().toString());
this.recentMethod = this.symt.getMethod(mtd, t.getClassInstance());
int mtdIndex = t.getClassInstance().getMethods()
.indexOf(this.symt.getMethod(mtd, t.getClassInstance())) * 4;
- this.vapor += String.format(" %s = [%s+%d]\n",
+ this.addVapor(String.format(" %s = [%s+%d]\n",
tp2,
tp1,
- mtdIndex);
+ mtdIndex));
this.addVapor(n.f4.accept(this, argu));
@@ -1180,10 +1183,7 @@ public class BoilVisitor extends GJDepthFirst<String,String> {
MinimalLogger.info(String.format("-> %s",
n.getClass().getSimpleName()));
///////////////////////////////////////////////////////////////
- String thisID = this.tf.alias(this.getUniqueID());
- this.addVapor(String.format(" %s = [this]\n",
- thisID));
- _ret += thisID;
+ _ret += "this";
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s with %s",
n.getClass().getSimpleName(),
@@ -1225,12 +1225,20 @@ public class BoilVisitor extends GJDepthFirst<String,String> {
*/
public String visit(AllocationExpression n, String argu) {
String _ret="";
+ String id = n.f1.f0.tokenImage;
MinimalLogger.info(String.format("-> %s",
n.getClass().getSimpleName()));
+ _ret += this.tf.alias(this.getUniqueID());
///////////////////////////////////////////////////////////////
- String id = n.f1.f0.tokenImage;
- _ret += String.format(":functable_%s",
- id);
+ ClassInstance cls = this.symt.getClass(id);
+ this.recentClass = cls;
+ this.addVapor(String.format(" %s = HeapAllocZ(%d)\n",
+ _ret,
+ cls.getSize()));
+
+ this.addVapor(String.format(" [%s+0] = :functable_%s\n",
+ _ret,
+ id));
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<- %s with %s",
n.getClass().getSimpleName(),
diff --git a/boil/tests/ex2.java b/boil/tests/ex2.java
deleted file mode 100644
index 986ca7d..0000000
--- a/boil/tests/ex2.java
+++ /dev/null
@@ -1,7 +0,0 @@
-class A {
- void foo() { }
-}
-
-class B {
- void bar() { }
-}
diff --git a/st/SymTableMethods.java b/st/SymTableMethods.java
index b14676a..5adac56 100644
--- a/st/SymTableMethods.java
+++ b/st/SymTableMethods.java
@@ -154,7 +154,7 @@ public class SymTableMethods<R> extends GJDepthFirst<R,SymbolTable> {
case 2:
rtrn = new ClassInstance("int"); break;
case 3:
- rtrn = new ClassInstance(((Identifier) n.f1.f0.choice).f0.tokenImage); break;
+ rtrn = symt.getClass(((Identifier) n.f1.f0.choice).f0.tokenImage); break;
default:
MinimalLogger.severe("Unsupported case");
}