fix totally broken jssa array handling
authorbrian <brian@brianweb.net>
Mon, 4 Jul 2005 00:29:20 +0000 (00:29 +0000)
committerbrian <brian@brianweb.net>
Mon, 4 Jul 2005 00:29:20 +0000 (00:29 +0000)
darcs-hash:20050704002920-24bed-708cf21e487ce9a97b9f3c6916dbf1eb10b42f00.gz

src/org/ibex/classgen/ConstantPool.java
src/org/ibex/classgen/JSSA.java
src/org/ibex/classgen/Type.java

index bdfddf0..f3fbdf0 100644 (file)
@@ -85,7 +85,9 @@ class ConstantPool implements CGConst {
         ClassEnt(String s) { this(); this.utf8 = (Utf8Ent) addUtf8(s); }
         void dump(DataOutput o) throws IOException { super.dump(o); o.writeShort(utf8.n); }
         Type.Class getTypeClass() { return  (Type.Class) key(); }
-        Object _key() { return Type.Class.instance(utf8.s); }
+        Object _key() {
+            return Type.fromDescriptor(utf8.s.startsWith("[") ? utf8.s : "L" + utf8.s + ";"); 
+        }
         void unref() { utf8.unref(); super.unref(); }
         public String toString() { return "[Class: " + utf8.s + "]"; }
     }
index d584b53..b01d262 100644 (file)
@@ -304,6 +304,18 @@ public class JSSA extends MethodGen implements CGConst {
         public NewArray(Type.Array t, Expr[] dims) { this.t = t; this.dims = dims; }
         public NewArray(Type.Array t, Expr dim) { this(t,new Expr[]{dim}); }
         public Type getType() { return t; }
+        public String _toString() {
+            Type base = t;
+            int totalDims = 0;
+            while(base.isArray()) {
+                totalDims++;
+                base = base.asArray().getElementType(); 
+            }
+            StringBuffer sb = new StringBuffer("new " + base);
+            for(int i=0;i<totalDims;i++)
+                sb.append("[" + (i < dims.length ? dims[i].toString() : "") + "]");
+            return sb.toString();
+        }
     }
     
     public class Return extends Op {
@@ -349,13 +361,15 @@ public class JSSA extends MethodGen implements CGConst {
 
     public class ArrayPut extends Op {
         final Expr e, i, v;
-        public ArrayPut(Expr e, Expr i, Expr v) { this.e = e; this.i = i; this.v = v; }
+        public ArrayPut(Expr v, Expr i, Expr e) { this.e = e; this.i = i; this.v = v; }
+        public String toString() { return e + "[" + i + "] := " + v; }
     }
 
     public class ArrayGet extends Expr {
         final Expr e, i;
-        public ArrayGet(Expr e, Expr i) { this.e = e; this.i = i; }
+        public ArrayGet(Expr i, Expr e) { this.e = e; this.i = i; }
         public Type getType() { return e.getType().asArray().getElementType(); }
+        public String _toString() { return e + "[" + i + "]"; }
     }
 
     public class ArrayLength extends Expr {
index b5428ad..28c30dd 100644 (file)
@@ -85,7 +85,7 @@ public abstract class Type implements CGConst {
         public Type.Array asArray() { return this; }
         public boolean isArray() { return true; }
         public String toString() { return base.toString() + "[]"; }
-        public Type getElementType() { return Type.fromDescriptor(getDescriptor().substring(0, getDescriptor().length()-1)); }
+        public Type getElementType() { return base; }
     }
 
     public static class Class extends Type.Ref {
@@ -115,7 +115,7 @@ public abstract class Type implements CGConst {
             return p == -1 ? descriptor.substring(1,descriptor.length()-1) : descriptor.substring(p+1,descriptor.length()-1);
         }
         private static String _initHelper(String s) {
-            if (!s.startsWith("L") || !s.endsWith(";")) throw new Error("invalid");
+            if (!s.startsWith("L") || !s.endsWith(";")) throw new Error("invalid: " + s);
             return s;
         }
         String[] components() {