X-Git-Url: http://git.megacz.com/?p=org.ibex.classgen.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fclassgen%2FJSSA.java;h=f29c57fd29550d6365d01f533c15944568d64adb;hp=d01aa06774d9acdad623f382a2d6d4cccbd733c2;hb=47af83f48565cf03d4e1a4c9b692b92beab8efcf;hpb=191f3a8b02d7c1de68afbabebc9f55d91eb500f1 diff --git a/src/org/ibex/classgen/JSSA.java b/src/org/ibex/classgen/JSSA.java index d01aa06..f29c57f 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,7 +425,7 @@ 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 instanceof String ? "\"" + o + "\"" : o.toString(); } public Type getType() { if (o instanceof Byte) return Type.BYTE; if (o instanceof Short) return Type.SHORT; @@ -436,6 +435,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"); } } @@ -473,20 +473,20 @@ public class JSSA extends MethodGen implements CGConst { 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; case ASTORE_2: case DSTORE_2: case FSTORE_2: case LSTORE_2: case ISTORE_2: local[2] = pop(); return null; case ISTORE_3: case LSTORE_3: case FSTORE_3: case DSTORE_3: case ASTORE_3: local[3] = pop(); return null; - case POP: stack[--sp] = null; - case POP2: stack[--sp] = null; stack[--sp] = null; /** fixme: pops a WORD, not an item */ - case DUP: stack[sp] = stack[sp-1]; sp++; - case DUP2: stack[sp] = stack[sp-2]; stack[sp+1] = stack[sp-1]; sp+=2; + case POP: pop(); return null; + case POP2: pop(); pop(); return null; + case DUP: push(stack[sp-1]); return null; + case DUP2: push(stack[sp-2]); push(stack[sp-2]); return null; // Conversions ////////////////////////////////////////////////////////////////////////////// @@ -547,9 +547,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 ////////////////////////////////////////////////////////////////////////////// @@ -566,14 +568,14 @@ public class JSSA extends MethodGen implements CGConst { default: throw new Error("should never happen"); } if(ret.getType() != Type.VOID) push(ret); - return 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 +594,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