major updates to JSSA
[org.ibex.classgen.git] / src / org / ibex / classgen / MethodGen.java
index 8051a9e..7c740d1 100644 (file)
@@ -10,7 +10,7 @@ public class MethodGen implements CGConst {
     
     private static final int NO_CODE = -1;
 
-    private final Type.Class.Method method;
+    public final Type.Class.Method method;
     private final int flags;
     private final ClassFile.AttrGen attrs;
     private final ClassFile.AttrGen codeAttrs;
@@ -25,7 +25,8 @@ public class MethodGen implements CGConst {
     private byte[] op;
     private Object[] arg;
     private ConstantPool.Ent[] cparg;
-    
+
+   
     // Constructors //////////////////////////////////////////////////////////////////////////////
 
     MethodGen(Type.Class.Method method, int flags) {
@@ -142,12 +143,14 @@ public class MethodGen implements CGConst {
                     ConstantPool.Ent ent = cp.getByIndex(in.readUnsignedShort());
                     if (ent.tag != CONSTANT_INTERFACEMETHODREF) throw new ClassFile.ClassReadExn("illegal argument to bytecode");
                     arg = ((ConstantPool.InterfaceMethodKey)ent.key()).method;
-                    if (in.readByte() == 0 || in.readByte() != 0) throw new ClassFile.ClassReadExn("illegal count or 0 arg to invokeinterface");
+                    if (in.readByte() == 0 || in.readByte() != 0)
+                        throw new ClassFile.ClassReadExn("illegal count or 0 arg to invokeinterface");
                     break;
                 }
                 default:
                     if ((opdata&OP_CPENT_FLAG)!=0) {
-                        ConstantPool.Ent ent = cp.getByIndex(argLength == 2 ? in.readUnsignedShort() : argLength == 1 ? in.readUnsignedByte() : -1);
+                        ConstantPool.Ent ent =
+                            cp.getByIndex(argLength == 2 ? in.readUnsignedShort() : argLength == 1 ? in.readUnsignedByte() : -1);
                         int tag = ent.tag;
                         Object key = ent.key();
                         switch(op) {
@@ -163,25 +166,32 @@ public class MethodGen implements CGConst {
                                     case CONSTANT_CLASS:
                                         break;
                                     default:
-                                        throw new ClassFile.ClassReadExn("illegal argument to bytecode 0x" + Integer.toString(op&0xff,16));
+                                        throw new ClassFile.ClassReadExn("illegal argument to bytecode 0x" +
+                                                                         Integer.toString(op&0xff,16));
                                 }
                                 break;
                             case GETSTATIC:
                             case PUTSTATIC:
                             case GETFIELD:
                             case PUTFIELD:
-                                if (tag != CONSTANT_FIELDREF) throw new ClassFile.ClassReadExn("illegal argument to bytecode 0x" + Integer.toString(op&0xff,16));
+                                if (tag != CONSTANT_FIELDREF)
+                                    throw new ClassFile.ClassReadExn("illegal argument to bytecode 0x" +
+                                                                     Integer.toString(op&0xff,16));
                                 break;
                             case INVOKEVIRTUAL:
                             case INVOKESPECIAL:
                             case INVOKESTATIC:
-                                if (tag != CONSTANT_METHODREF) throw new ClassFile.ClassReadExn("illegal argument to bytecode 0x" + Integer.toString(op&0xff,16));
+                                if (tag != CONSTANT_METHODREF)
+                                    throw new ClassFile.ClassReadExn("illegal argument to bytecode 0x" +
+                                                                     Integer.toString(op&0xff,16));
                                 break;
                             case NEW:
                             case ANEWARRAY:
                             case CHECKCAST:
                             case INSTANCEOF:
-                                if (tag != CONSTANT_CLASS) throw new ClassFile.ClassReadExn("illegal argument to bytecode 0x" + Integer.toString(op&0xff,16));
+                                if (tag != CONSTANT_CLASS)
+                                    throw new ClassFile.ClassReadExn("illegal argument to bytecode 0x" +
+                                                                     Integer.toString(op&0xff,16));
                                 break;                        
                             default:
                                 throw new Error("should never happen");
@@ -211,7 +221,8 @@ public class MethodGen implements CGConst {
                     Switch si = (Switch) arg[i];
                     
                     int pos = map[si.getDefaultTarget()];
-                    if (pos < 0)  throw new ClassFile.ClassReadExn("default target points to invalid bytecode: " + si.getDefaultTarget());
+                    if (pos < 0)
+                        throw new ClassFile.ClassReadExn("default target points to invalid bytecode: " + si.getDefaultTarget());
                     si.setDefaultTarget(pos);
                     
                     for(int j=0;j<si.size();j++) {
@@ -281,7 +292,8 @@ public class MethodGen implements CGConst {
     }
     
     /** Adds a exception type that can be thrown from this method
-        NOTE: This isn't enforced by the JVM. This is for reference only. A method can throw exceptions not declared to be thrown 
+        NOTE: This isn't enforced by the JVM. This is for reference
+        only. A method can throw exceptions not declared to be thrown
         @param type The type of exception that can be thrown 
     */
     public final void addThrow(Type.Class type) { thrownExceptions.put(type, type); }
@@ -537,30 +549,6 @@ public class MethodGen implements CGConst {
 
     // Emitting Bits //////////////////////////////////////////////////////////////////////////////
    
-    /** Negates the IF* instruction, <i>op</i>  (IF_ICMPGT -> IF_ICMPLE, IFNE -> IFEQ,  etc)
-        @exception IllegalArgumentException if <i>op</i> isn't an IF* instruction */
-    public static byte negate(byte op) {
-        switch(op) {
-            case IFEQ: return IFNE;
-            case IFNE: return IFEQ;
-            case IFLT: return IFGE;
-            case IFGE: return IFLT;
-            case IFGT: return IFLE;
-            case IFLE: return IFGT;
-            case IF_ICMPEQ: return IF_ICMPNE;
-            case IF_ICMPNE: return IF_ICMPEQ;
-            case IF_ICMPLT: return IF_ICMPGE;
-            case IF_ICMPGE: return IF_ICMPLT;
-            case IF_ICMPGT: return IF_ICMPLE;
-            case IF_ICMPLE: return IF_ICMPGT;
-            case IF_ACMPEQ: return IF_ACMPNE;
-            case IF_ACMPNE: return IF_ACMPEQ;
-            
-            default:
-                throw new IllegalArgumentException("Can't negate " + Integer.toHexString(op));
-        }
-    }
-
     private Object resolveTarget(Object arg) {
         int target;
         if (arg instanceof PhantomTarget) {
@@ -1034,4 +1022,31 @@ public class MethodGen implements CGConst {
         }
     }
 
+    // Unused //////////////////////////////////////////////////////////////////////////////
+
+    /** Negates the IF* instruction, <i>op</i>  (IF_ICMPGT -> IF_ICMPLE, IFNE -> IFEQ,  etc)
+        @exception IllegalArgumentException if <i>op</i> isn't an IF* instruction */
+    public static byte negate(byte op) {
+        switch(op) {
+            case IFEQ: return IFNE;
+            case IFNE: return IFEQ;
+            case IFLT: return IFGE;
+            case IFGE: return IFLT;
+            case IFGT: return IFLE;
+            case IFLE: return IFGT;
+            case IF_ICMPEQ: return IF_ICMPNE;
+            case IF_ICMPNE: return IF_ICMPEQ;
+            case IF_ICMPLT: return IF_ICMPGE;
+            case IF_ICMPGE: return IF_ICMPLT;
+            case IF_ICMPGT: return IF_ICMPLE;
+            case IF_ICMPLE: return IF_ICMPGT;
+            case IF_ACMPEQ: return IF_ACMPNE;
+            case IF_ACMPNE: return IF_ACMPEQ;
+            
+            default:
+                throw new IllegalArgumentException("Can't negate " + Integer.toHexString(op));
+        }
+    }
+
+
 }