X-Git-Url: http://git.megacz.com/?p=org.ibex.classgen.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fclassgen%2FJSSA.java;h=55ed8dbb06cef09f087632e4486c6b1e9e358f85;hp=d6c15b7cd514e9390866c08c1e2132403dd455b5;hb=5186b123d341165e00082608ad38500f076f90f8;hpb=8272e0434b82203bdf59c66af697eff95df7bc3a diff --git a/src/org/ibex/classgen/JSSA.java b/src/org/ibex/classgen/JSSA.java index d6c15b7..55ed8db 100644 --- a/src/org/ibex/classgen/JSSA.java +++ b/src/org/ibex/classgen/JSSA.java @@ -36,36 +36,6 @@ public class JSSA extends MethodGen implements CGConst { } } } - - public void debugBodyToString(StringBuffer sb) { - StringBuffer sb0 = new StringBuffer(); - super.debugBodyToString(sb0); - StringTokenizer st = new StringTokenizer(sb0.toString(), "\n"); - String[] lines = new String[st.countTokens()]; - for(int i=0; i") ? "super" : method.name); - args(sb); - return sb.toString(); - } + public String _toString() { return _toString(method.name.equals("") ? method.getDeclaringClass().getName() : method.name); } } public class InvokeInterface extends InvokeVirtual{public InvokeInterface(Type.Class.Method m, Expr[] a, Expr e){super(m,a,e);}} public class InvokeVirtual extends Invoke { public final Expr instance; public InvokeVirtual(Type.Class.Method m, Expr[] a, Expr e) { super(m, a); instance = e; } - public String toString() { + public String _toString() { return _toString(method.name); } + protected String _toString(String name) { StringBuffer sb = new StringBuffer(); - sb.append(method.name); + sb.append(instance+"."); + sb.append(name); args(sb); return sb.toString(); } @@ -426,8 +429,9 @@ public class JSSA extends MethodGen implements CGConst { private final Object o; public Constant(int i) { this(new Integer(i)); } public Constant(Object o) { this.o = o; } - public String toString() { return o.toString(); } + public String _toString() { return o == null ? "null" : o instanceof String ? "\"" + o + "\"" : o.toString(); } public Type getType() { + if (o == null) return Type.NULL; if (o instanceof Byte) return Type.BYTE; if (o instanceof Short) return Type.SHORT; if (o instanceof Character) return Type.CHAR; @@ -436,6 +440,7 @@ public class JSSA extends MethodGen implements CGConst { if (o instanceof Double) return Type.DOUBLE; if (o instanceof Float) return Type.FLOAT; if (o instanceof Integer) return Type.INT; + if (o instanceof String) return Type.STRING; throw new IllegalStateException("unknown constant type"); } } @@ -465,19 +470,19 @@ public class JSSA extends MethodGen implements CGConst { // Stack manipulations ////////////////////////////////////////////////////////////////////////////// - case ACONST_NULL: return stack[sp++] = new Constant(null); - case ICONST_M1: return stack[sp++] = new Constant(-1); + case ACONST_NULL: push(new Constant(null)); return null; + case ICONST_M1: push(new Constant(-1)); return null; case ICONST_0: case LCONST_0: case FCONST_0: case DCONST_0: push(new Constant(0)); return null; case ICONST_1: case LCONST_1: case FCONST_1: case DCONST_1: push(new Constant(1)); return null; case ICONST_2: case FCONST_2: push(new Constant(2)); return null; case ICONST_3: push(new Constant(3)); return null; case ICONST_4: push(new Constant(4)); return null; case ICONST_5: push(new Constant(5)); return null; - case ILOAD: case LLOAD: case FLOAD: case DLOAD: case ALOAD: return push(local[i1]); - case ILOAD_0: case LLOAD_0: case FLOAD_0: case DLOAD_0: case ALOAD_0: return push(local[0]); - case ILOAD_1: case LLOAD_1: case FLOAD_1: case DLOAD_1: case ALOAD_1: return push(local[1]); - case ALOAD_2: case DLOAD_2: case FLOAD_2: case LLOAD_2: case ILOAD_2: return push(local[2]); - case ILOAD_3: case LLOAD_3: case FLOAD_3: case DLOAD_3: case ALOAD_3: return push(local[3]); + case ILOAD: case LLOAD: case FLOAD: case DLOAD: case ALOAD: push(local[i1]); return null; + case ILOAD_0: case LLOAD_0: case FLOAD_0: case DLOAD_0: case ALOAD_0: push(local[0]); return null; + case ILOAD_1: case LLOAD_1: case FLOAD_1: case DLOAD_1: case ALOAD_1: push(local[1]); return null; + case ALOAD_2: case DLOAD_2: case FLOAD_2: case LLOAD_2: case ILOAD_2: push(local[2]); return null; + case ILOAD_3: case LLOAD_3: case FLOAD_3: case DLOAD_3: case ALOAD_3: push(local[3]); return null; case ISTORE: case LSTORE: case FSTORE: case DSTORE: case ASTORE: local[i1] = pop(); return null; case ISTORE_0: case LSTORE_0: case FSTORE_0: case DSTORE_0: case ASTORE_0: local[0] = pop(); return null; case ISTORE_1: case LSTORE_1: case FSTORE_1: case DSTORE_1: case ASTORE_1: local[1] = pop(); return null; @@ -547,9 +552,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 ////////////////////////////////////////////////////////////////////////////// @@ -565,15 +572,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 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 ////////////////////////////////////////////////////////////////////////////// @@ -592,31 +599,29 @@ 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