diff options
author | bd-912 <bdunahu@colostate.edu> | 2024-04-25 14:39:23 -0600 |
---|---|---|
committer | bd-912 <bdunahu@colostate.edu> | 2024-04-25 14:39:23 -0600 |
commit | b57826f1ccb9dac17beb8ff4f4f53a11591d1e15 (patch) | |
tree | 61c0a9b2b6e273b56675745bb3962976b5850971 | |
parent | 63270d092073ec2bed15151315d005a0b8858073 (diff) |
Use variables to reference array indices, observe more passing tests
-rw-r--r-- | boil/library/BoilVisitor.java | 41 | ||||
-rw-r--r-- | boil/tests/ex47.java | 2 |
2 files changed, 33 insertions, 10 deletions
diff --git a/boil/library/BoilVisitor.java b/boil/library/BoilVisitor.java index eb47432..5633eb8 100644 --- a/boil/library/BoilVisitor.java +++ b/boil/library/BoilVisitor.java @@ -553,12 +553,24 @@ public class BoilVisitor extends GJDepthFirst<String,String> { arrID, arr)); - int index = Integer.parseInt(n.f2.accept(this, argu)) * 4 + 4; + String indexID = this.tf.alias(this.getUniqueID()); + this.addVapor(String.format(" %s = MulS(%s %s)\n", + indexID, + n.f2.accept(this, argu), + 4)); + this.addVapor(String.format(" %s = Add(%s %s)\n", + indexID, + indexID, + 4)); + this.addVapor(String.format(" %s = Add(%s %s)\n", + indexID, + arrID, + indexID)); + String expr = n.f5.accept(this, argu); - this.addVapor(String.format(" [%s+%d] = %s\n", - arrID, - index, + this.addVapor(String.format(" [%s] = %s\n", + indexID, expr)); /////////////////////////////////////////////////////////////// MinimalLogger.info(String.format("<- %s with %s", @@ -715,7 +727,7 @@ public class BoilVisitor extends GJDepthFirst<String,String> { _ret += this.tf.alias(this.getUniqueID()); /////////////////////////////////////////////////////////////// String oper1 = this.memoryRead(n.f0.accept(this, argu)); - String oper2 = this.memoryRead(n.f2.accept(this, argu)); + String oper2 = this.memoryRead(n.f2.accept(this, argu)); this.addVapor(String.format(" %s = Eq(%s %s)\n", _ret, oper1, @@ -842,14 +854,25 @@ public class BoilVisitor extends GJDepthFirst<String,String> { /////////////////////////////////////////////////////////////// String arrID = this.tf.alias(this.getUniqueID()); String arr = n.f0.accept(this, argu); - int index = Integer.parseInt(n.f2.accept(this, argu)) * 4 + 4; + String indexID = this.tf.alias(this.getUniqueID()); this.addVapor(String.format(" %s = %s\n", arrID, arr)); - this.addVapor(String.format(" %s = [%s+%d]\n", - _ret, + this.addVapor(String.format(" %s = MulS(%s %s)\n", + indexID, + n.f2.accept(this, argu), + 4)); + this.addVapor(String.format(" %s = Add(%s %s)\n", + indexID, + indexID, + 4)); + this.addVapor(String.format(" %s = Add(%s %s)\n", + indexID, arrID, - index)); + indexID)); + this.addVapor(String.format(" %s = [%s]\n", + _ret, + indexID)); /////////////////////////////////////////////////////////////// MinimalLogger.info(String.format("<- %s with %s", n.getClass().getSimpleName(), diff --git a/boil/tests/ex47.java b/boil/tests/ex47.java index b8d4b3a..ea4e342 100644 --- a/boil/tests/ex47.java +++ b/boil/tests/ex47.java @@ -19,6 +19,6 @@ class A { } public int get() { - return x.length ; + return x[5] ; } } |