inline u2 ZipFile::GetU2() { u4 val = GetU1(); val |= (((u4) GetU1()) << 8); return val; }
inline u4 ZipFile::GetU4() { u4 val = GetU1(); val |= (((u4) GetU1()) << 8); val |= (((u4) GetU1()) << 16); val |= (((u4) GetU1()) << 24); return val; }
void Operators::OpDmp(Tuple<cp_info *> &constant_pool, Tuple<u1> &code) { int pc = 0; while (pc < code.Length()) { int info_kind = INFO_NONE; // assume no extra info int info_index = 0; int pc_start = pc; Opcode opc = (Opcode) GetU1(code, pc); const char *name, *desc; // set to name (mnemonic) and description of opcode. OpDesc((Opcode) code[pc_start], &name, &desc); pc++; char argdesc[100]; argdesc[0] = U_NULL; // assume no argument description needed unsigned au1; int ai1, ai2, ai4; switch (opc) { case OP_BIPUSH: ai1 = GetI1(code, pc); pc++; sprintf(argdesc, "%d", ai1); break; case OP_SIPUSH: ai2 = GetI2(code, pc); pc +=2; sprintf(argdesc, "%d", ai2); break; case OP_LDC: info_index = GetU1(code, pc); pc++; sprintf(argdesc,"%d", info_index); info_kind = INFO_CONST; break; case OP_LDC_W: case OP_LDC2_W: info_index = GetU2(code, pc);pc +=2; sprintf(argdesc, "%u", info_index); info_kind = INFO_CONST; break; case OP_ILOAD: case OP_LLOAD: case OP_FLOAD: case OP_DLOAD: case OP_ALOAD: case OP_ISTORE: case OP_LSTORE: case OP_FSTORE: case OP_DSTORE: case OP_ASTORE: info_index = GetU1(code, pc);pc++; sprintf(argdesc, "%u", info_index); info_kind = INFO_LOCAL; break; case OP_ILOAD_0: case OP_LLOAD_0: case OP_FLOAD_0: case OP_DLOAD_0: case OP_ALOAD_0: case OP_ISTORE_0: case OP_LSTORE_0: case OP_FSTORE_0: case OP_DSTORE_0: case OP_ASTORE_0: info_kind = INFO_LOCAL; info_index = 0; break; case OP_ILOAD_1: case OP_LLOAD_1: case OP_FLOAD_1: case OP_DLOAD_1: case OP_ALOAD_1: case OP_ISTORE_1: case OP_LSTORE_1: case OP_FSTORE_1: case OP_DSTORE_1: case OP_ASTORE_1: info_kind = INFO_LOCAL; info_index = 1; break; case OP_ILOAD_2: case OP_LLOAD_2: case OP_FLOAD_2: case OP_DLOAD_2: case OP_ALOAD_2: case OP_ISTORE_2: case OP_LSTORE_2: case OP_DSTORE_2: case OP_FSTORE_2: case OP_ASTORE_2: info_kind = INFO_LOCAL; info_index = 2; break; case OP_ILOAD_3: case OP_LLOAD_3: case OP_FLOAD_3: case OP_DLOAD_3: case OP_ALOAD_3: case OP_ISTORE_3: case OP_LSTORE_3: case OP_FSTORE_3: case OP_DSTORE_3: case OP_ASTORE_3: info_kind= INFO_LOCAL; info_index = 3; break; case OP_IINC: info_index = GetU1(code, pc); pc++; au1 = GetU1(code, pc); pc++; ai1 = GetI1(code, pc); pc++; info_kind = INFO_LOCAL; sprintf(argdesc, "%d %d", au1, ai1); break; case OP_IFEQ: case OP_IFNE: case OP_IFLT: case OP_IFGE: case OP_IFGT: case OP_IFLE: case OP_IF_ICMPEQ: case OP_IF_ICMPNE: case OP_IF_ICMPLT: case OP_IF_ICMPGE: case OP_IF_ICMPGT: case OP_IF_ICMPLE: case OP_IF_ACMPEQ: case OP_IF_ACMPNE: case OP_GOTO: case OP_JSR: case OP_IFNULL: case OP_IFNONNULL: ai2 = GetI2(code, pc); sprintf(argdesc, "%d", (int) ( ai2+pc_start)); // compute branch target pc +=2; break; case OP_RET: au1 = GetU1(code, pc); pc++; sprintf(argdesc, "%d", (int) au1); break; case OP_TABLESWITCH: { int def, low, high, len, val, pc_this; Opcode op_this; unsigned iu1; op_this = OP_TABLESWITCH; // account for padding while (pc % 4) { iu1 = GetU1(code, pc); pc++; } def = GetI4(code, pc); pc += 4; low = GetI4(code, pc); pc +=4; high = GetI4(code, pc); pc += 4; sprintf(argdesc, "default:%d low:%d high:%d", def + pc_start, low, high); OpLine(constant_pool, " ", pc_start, opc, name, argdesc, desc, info_kind, info_index); len = high - low + 1; while (len) { pc_this = pc; val = GetI4(code, pc); sprintf(argdesc, "match:%d offset:%d", low++, val + pc_start); OpLine(constant_pool,"*",pc_this, op_this, name, argdesc, desc, INFO_NONE, 0); pc += 4; len--; } info_kind = INFO_DONE; } break; case OP_LOOKUPSWITCH: { int def, npairs, len, match, offset; Opcode op_this; // account for padding unsigned iu1; op_this = OP_LOOKUPSWITCH; while (pc % 4) { iu1 = GetU1(code, pc); pc++; } def = GetI4(code, pc); pc += 4; npairs = GetI4(code, pc); pc +=4; sprintf(argdesc, "default:%d npairs:%d", def + pc_start, npairs); OpLine(constant_pool, " ", pc_start, op_this, name, argdesc, desc, info_kind, info_index); len = npairs; while (npairs) { int pcb = pc; match = GetI4(code, pc); pc +=4 ; offset = GetI4(code, pc); pc +=4; sprintf(argdesc, "match:%d offset:%d ", match, offset + pc_start); OpLine(constant_pool, "*", pcb, op_this, name, argdesc, desc, INFO_NONE, 0); npairs--; } info_kind = INFO_DONE; } break; case OP_GETSTATIC: case OP_PUTSTATIC: case OP_GETFIELD: case OP_PUTFIELD: case OP_INVOKEVIRTUAL: case OP_INVOKESPECIAL: case OP_INVOKESTATIC: case OP_NEW: case OP_ANEWARRAY: case OP_CHECKCAST: case OP_INSTANCEOF: info_index = GetU2(code, pc); pc += 2; sprintf(argdesc, "%d", info_index); info_kind = INFO_CONST; break; case OP_INVOKEINTERFACE: { int nargs; info_index = GetU2(code, pc); pc += 2; au1 = GetU1(code, pc); pc++; nargs = au1; au1 = GetU1(code, pc); pc++; assert((! au1) && "...zero byte required in this position"); sprintf(argdesc, "%d %d", nargs,info_index); info_kind=INFO_CONST; } break; case OP_NEWARRAY: au1 = GetU1(code, pc); pc++; switch (au1) { case 4: sprintf(argdesc, "%s", "BOOLEAN");break; case 5: sprintf(argdesc, "%s", "CHAR");break; case 6: sprintf(argdesc, "%s", "FLOAT");break; case 7: sprintf(argdesc, "%s", "DOUBLE");break; case 8: sprintf(argdesc, "%s", "BYTE");break; case 9: sprintf(argdesc, "%s", "SHORT");break; case 10: sprintf(argdesc, "%s", "INT");break; case 11: sprintf(argdesc, "%s", "LONG");break; default: sprintf(argdesc, "%s", "<UNKNOWN>");break; } break; case OP_WIDE: assert(false && "dmp for op_wide not supported yet"); break; case OP_MULTIANEWARRAY: info_index = GetU2(code, pc); pc += 2; au1 = GetU1(code, pc); pc++; info_kind = INFO_CONST; // au1 gives dimensions sprintf(argdesc, "%u", au1); break; case OP_GOTO_W: case OP_JSR_W: ai4 = GetI4(code, pc); pc += 4; // ai4 gives offset (wide) of branch target sprintf(argdesc, "%d", pc_start + ai4); break; default: break; } // output first part of description if (info_kind != INFO_DONE) OpLine(constant_pool, " ", pc_start, opc, name, argdesc, desc, info_kind, info_index); } }