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=e608b42be245a0e253ffc20510027a328b8026a7;hb=5186b123d341165e00082608ad38500f076f90f8;hpb=89a9844d8a8684ddca28a4c7e8cd631c587aff6f diff --git a/src/org/ibex/classgen/JSSA.java b/src/org/ibex/classgen/JSSA.java index e608b42..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; @@ -435,8 +439,9 @@ public class JSSA extends MethodGen implements CGConst { if (o instanceof Long) return Type.LONG; if (o instanceof Double) return Type.DOUBLE; if (o instanceof Float) return Type.FLOAT; - if (o instanceof ConstantPool.Ent) throw new Error("unimplemented"); - throw new Error("this should not happen"); + if (o instanceof Integer) return Type.INT; + if (o instanceof String) return Type.STRING; + throw new IllegalStateException("unknown constant type"); } } @@ -465,28 +470,28 @@ 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; 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 +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 ////////////////////////////////////////////////////////////////////////////// @@ -557,19 +564,23 @@ public class JSSA extends MethodGen implements CGConst { Type.Class.Method method = (Type.Class.Method)arg; Expr args[] = new Expr[method.getNumArgs()]; for(int i=0; i