summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbd-912 <bdunahu@colostate.edu>2024-04-14 02:21:48 -0600
committerbd-912 <bdunahu@colostate.edu>2024-04-14 02:21:48 -0600
commitee60d3f9a32f75c628961f40a9bf4f1bf387ac06 (patch)
treef424f292d987f6472f9ca1f5283127797461a075
parent6ecd1893b4586c7077c6969431b47ca4e0962240 (diff)
Proper Allocation sizes for Boil VarDeclaration
-rw-r--r--boil/library/BoilSimp.java32
-rw-r--r--boil/library/TypeFactory.java4
-rw-r--r--boil/tests/ex33.java11
-rw-r--r--st/AbstractInstance.java5
-rw-r--r--st/ClassInstance.java5
-rw-r--r--st/MethodInstance.java4
-rw-r--r--st/TypeInstance.java5
7 files changed, 46 insertions, 20 deletions
diff --git a/boil/library/BoilSimp.java b/boil/library/BoilSimp.java
index b8fee08..9e8d40a 100644
--- a/boil/library/BoilSimp.java
+++ b/boil/library/BoilSimp.java
@@ -160,7 +160,7 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> {
}
mod += "\n";
mod += n.f2.accept(this, symt);
- mod += n.f3.accept(this, symt);
+ n.f3.accept(this, symt);
mod += n.f4.accept(this, symt);
mod += n.f5.accept(this, symt);
@@ -203,8 +203,10 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> {
n.f0.accept(this, symt);
String id = n.f1.accept(this, symt);
- mod += String.format(" %s = HeapAllocZ(32)\n",
- this.tf.alias(symt.getType(id))); // FIXME add proper allocation size
+ TypeInstance t = symt.getType(id);
+ mod += String.format(" %s = HeapAllocZ(%d)\n",
+ this.tf.alias(t),
+ t.getSize()); // FIXME add proper allocation size
mod += String.format(" if0 %s goto :error\n",
this.tf.alias(symt.getType(id)));
mod += n.f2.accept(this, symt);
@@ -452,6 +454,9 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> {
mod += n.f2.accept(this, symt);
mod += n.f3.accept(this, symt);
mod += n.f4.accept(this, symt);
+
+ mod += String.format(" PrintIntS(%s)\n",
+ this.tf.retrieveRecentList(1));
return mod;
}
@@ -504,7 +509,7 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> {
* f2 -> PrimaryExpression()
*/
public String visit(PlusExpression n, SymbolTable symt) {
- String mod = "";
+ String mod = "p";
String oper1 = n.f0.accept(this, symt);
mod += n.f1.accept(this, symt);
String oper2 = n.f2.accept(this, symt);
@@ -617,14 +622,19 @@ public class BoilSimp extends GJDepthFirst<String,SymbolTable> {
mod += n.f4.accept(this, symt);
mod += n.f5.accept(this, symt);
- mod += String.format(" call %s(%s",
- this.tf.alias(tp2),
- this.tf.alias(cur));
+ String call = String.format("call %s(%s",
+ this.tf.alias(tp2),
+ this.tf.alias(cur));
+
+ call += String.format(" %s)",
+ this.tf.retrieveRecentList(symt.getMethod(id2)
+ .getArguments()
+ .size()));
- mod += String.format("%s)\n",
- this.tf.retrieveRecentList(symt.getMethod(id2)
- .getArguments()
- .size()));
+ TypeInstance tp3 = new TypeInstance("tp3", TypeEnum.ERROR);
+ mod += String.format(" %s = %s\n",
+ this.tf.alias(tp3),
+ call);
return mod;
}
diff --git a/boil/library/TypeFactory.java b/boil/library/TypeFactory.java
index c84f64e..432fc0f 100644
--- a/boil/library/TypeFactory.java
+++ b/boil/library/TypeFactory.java
@@ -33,7 +33,9 @@ public class TypeFactory {
* list of the x most recent entries.
*/
String rtn = "";
- for (int i = type_num-x; i < type_num; ++i) {
+ rtn += String.format("t.%d",
+ type_num-x);
+ for (int i = type_num-(x+1); i < type_num; ++i) {
rtn += String.format(" t.%d",
i);
}
diff --git a/boil/tests/ex33.java b/boil/tests/ex33.java
index 53e369f..3325ea8 100644
--- a/boil/tests/ex33.java
+++ b/boil/tests/ex33.java
@@ -1,13 +1,18 @@
-class ex31 {
+class ex33 {
public static void main(String[] a) {
A a ;
a = new A() ;
- System.out.println(a.foo(12 + 13)) ;
+ System.out.println(a.bar(0-1, 400, 6*7)) ;
+ System.out.println(a.foo(0+1, 400)) ;
}
}
class A {
- public int foo(int a) {
+ public int foo(int a, int b) {
return 22 ;
}
+
+ public int bar(int x, int y, int z) {
+ return 6 ;
+ }
}
diff --git a/st/AbstractInstance.java b/st/AbstractInstance.java
index 241991d..d236044 100644
--- a/st/AbstractInstance.java
+++ b/st/AbstractInstance.java
@@ -5,7 +5,6 @@ import java.util.ArrayList;
public abstract class AbstractInstance {
protected String name; // the literal name of the declaration
protected TypeEnum type; // the type of the declaration
- protected int size; // the size in memory
protected ArrayList<AbstractInstance> scope; // the scope where the instance is valid
public AbstractInstance(String name, TypeEnum type) {
@@ -50,10 +49,6 @@ public abstract class AbstractInstance {
return this.type;
}
- public int getSize() {
- return this.size;
- }
-
public ArrayList<AbstractInstance> getScope() {
return this.scope;
}
diff --git a/st/ClassInstance.java b/st/ClassInstance.java
index ad7e6b0..e93d3bd 100644
--- a/st/ClassInstance.java
+++ b/st/ClassInstance.java
@@ -29,6 +29,11 @@ public class ClassInstance extends AbstractInstance {
return this.mtds;
}
+ public int getSize() {
+ return 4 * (this.attrs.size() +
+ this.mtds.size());
+ }
+
protected void addLocal(TypeInstance attr) {
this.attrs.add(attr);
}
diff --git a/st/MethodInstance.java b/st/MethodInstance.java
index c7df92f..6cf6ccc 100644
--- a/st/MethodInstance.java
+++ b/st/MethodInstance.java
@@ -22,6 +22,10 @@ public class MethodInstance extends AbstractInstance {
return this.lvars;
}
+ public TypeEnum getReturn() {
+ return this.rtrn;
+ }
+
protected void addArgument(TypeInstance arg) {
this.args.add(arg);
this.lvars.add(arg);
diff --git a/st/TypeInstance.java b/st/TypeInstance.java
index 596f638..65311a8 100644
--- a/st/TypeInstance.java
+++ b/st/TypeInstance.java
@@ -12,6 +12,11 @@ public class TypeInstance extends AbstractInstance {
this.cls = cls;
}
+ public int getSize() {
+ return (this.cls != null) ?
+ cls.getSize() : 4;
+ }
+
public ClassInstance getClassInstance() {
return this.cls;
}