more sanity checking
authorbrian <brian@brianweb.net>
Fri, 28 May 2004 09:33:48 +0000 (09:33 +0000)
committerbrian <brian@brianweb.net>
Fri, 28 May 2004 09:33:48 +0000 (09:33 +0000)
darcs-hash:20040528093348-24bed-e1a1a112278a4d5db8c5806676d9122adb79e7eb.gz

src/org/ibex/classgen/CPGen.java
src/org/ibex/classgen/MethodGen.java

index 56d5149..e22fd9e 100644 (file)
@@ -99,8 +99,6 @@ class CPGen {
         Ent ent = get(o);
         if(ent != null) return ent;
         
         Ent ent = get(o);
         if(ent != null) return ent;
         
-        if(nextIndex == 65536) throw new ClassGen.Exn("constant pool full");
-        
         if(o instanceof Type.Object) {
             CPRefEnt ce = new CPRefEnt(7);
             ce.e1 = addUtf8(((Type.Object)o).internalForm());
         if(o instanceof Type.Object) {
             CPRefEnt ce = new CPRefEnt(7);
             ce.e1 = addUtf8(((Type.Object)o).internalForm());
@@ -147,8 +145,12 @@ class CPGen {
             throw new IllegalArgumentException("Unknown type passed to add");
         }
         
             throw new IllegalArgumentException("Unknown type passed to add");
         }
         
-        ent.index = nextIndex++;
-        if(ent instanceof LongEnt) nextIndex++;
+        int spaces = ent instanceof LongEnt ? 2 : 1;
+        
+        if(nextIndex + spaces > 65536) throw new ClassGen.Exn("constant pool full");
+        
+        ent.index = nextIndex;
+        nextIndex += spaces;        
         count++;
 
         entries.put(o,ent);
         count++;
 
         entries.put(o,ent);
index b82567e..68aebd2 100644 (file)
@@ -296,6 +296,12 @@ public class MethodGen implements CGConst {
                     p += 1 + 3 + 4; // opcode itself, padding, default
                     if(op == TABLESWITCH) p += 4 + 4 + targets.length * 4; // lo, hi, targets
                     else p += 4 + targets.length * 4 * 2; // count, key,val * targets
                     p += 1 + 3 + 4; // opcode itself, padding, default
                     if(op == TABLESWITCH) p += 4 + 4 + targets.length * 4; // lo, hi, targets
                     else p += 4 + targets.length * 4 * 2; // count, key,val * targets
+                    if(op == LOOKUPSWITCH) {
+                        int[] vals = ((LSI)si).vals;
+                        for(j=1;j<vals.length;j++)
+                            if(vals[j] <= vals[j-1])
+                                throw new IllegalStateException("out of order/duplicate lookupswitch values");
+                    }
                     break;
                 }
                 case LDC:
                     break;
                 }
                 case LDC: