From c53564faf563824a08e5dbbfa3ab5f10171d06c8 Mon Sep 17 00:00:00 2001 From: brian Date: Mon, 4 Jul 2005 00:09:41 +0000 Subject: [PATCH] JSSA.Seq to for evaluation of an expr darcs-hash:20050704000941-24bed-6e114744b43a7e2b9e0979c685ff2d92ace7b9f2.gz --- src/org/ibex/classgen/JSSA.java | 44 ++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/src/org/ibex/classgen/JSSA.java b/src/org/ibex/classgen/JSSA.java index 28e6f2b..d43008b 100644 --- a/src/org/ibex/classgen/JSSA.java +++ b/src/org/ibex/classgen/JSSA.java @@ -94,6 +94,11 @@ public class JSSA extends MethodGen implements CGConst { if(sp == 0) throw new IllegalStateException("stack underflow"); return stack[--sp]; } + + private Op seqPush(Expr e) { + push(e); + return new Seq(e); + } // SSA-node classes ///////////////////////////////////////////////////////////////////////////////////////// @@ -114,7 +119,16 @@ public class JSSA extends MethodGen implements CGConst { return name; } } - + + /** A sequence point. expr is evaluated for side effects at this point, this does not generate data + Expressions that haven't been evaluated with Seq are evaluated when they are first encountered + */ + public class Seq extends Op { + private final Expr expr; + public String toString() { return expr.toString(); } + public Seq(Expr expr) { this.expr = expr; } + } + /** an operation which generates data */ public abstract class Expr extends Op { //public abstract Expr[] contributors(); // not implemented yet @@ -546,9 +560,11 @@ public class JSSA extends MethodGen implements CGConst { // Array manipulations ////////////////////////////////////////////////////////////////////////////// case IALOAD: case LALOAD: case FALOAD: case DALOAD: case AALOAD: - case BALOAD: case CALOAD: case SALOAD: push(new ArrayGet(pop(), pop())); return null; + case BALOAD: case CALOAD: case SALOAD: + return seqPush(new ArrayGet(pop(), pop())); case IASTORE: case LASTORE: case FASTORE: case DASTORE: case AASTORE: - case BASTORE: case CASTORE: case SASTORE: return new ArrayPut(pop(), pop(), pop()); + case BASTORE: case CASTORE: case SASTORE: + return new ArrayPut(pop(), pop(), pop()); // Invocation ////////////////////////////////////////////////////////////////////////////// @@ -564,19 +580,15 @@ public class JSSA extends MethodGen implements CGConst { case INVOKESTATIC: ret = new InvokeStatic(method, args); break; default: throw new Error("should never happen"); } - if(ret.getType() != Type.VOID) { - push(ret); - return null; - } else { - return ret; - } + if(ret.getType() != Type.VOID) push(ret); + return new Seq(ret); } // Field Access ////////////////////////////////////////////////////////////////////////////// - case GETSTATIC: push(new Get((Type.Class.Field)arg, null)); return null; + case GETSTATIC: return seqPush(new Get((Type.Class.Field)arg, null)); case PUTSTATIC: return new Put((Type.Class.Field)arg, pop(), null); - case GETFIELD: push(new Get((Type.Class.Field)arg, pop())); return null; + case GETFIELD: return seqPush(new Get((Type.Class.Field)arg, pop())); case PUTFIELD: return new Put((Type.Class.Field)arg, pop(), pop()); // Allocation ////////////////////////////////////////////////////////////////////////////// @@ -595,22 +607,20 @@ public class JSSA extends MethodGen implements CGConst { case 11: base = Type.LONG; break; default: throw new IllegalStateException("invalid array type"); } - push(new NewArray(base.makeArray(),pop())); - return null; + return seqPush(new NewArray(base.makeArray(),pop())); } case ANEWARRAY: push(new NewArray(((Type.Ref)arg).makeArray(), pop())); return null; case MULTIANEWARRAY: { MethodGen.MultiANewArray mana = (MethodGen.MultiANewArray) arg; Expr[] dims = new Expr[mana.dims]; for(int i=0;i