1579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson/* 2579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * Copyright (C) 2007 The Android Open Source Project 3579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * 4579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * Licensed under the Apache License, Version 2.0 (the "License"); 5579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * you may not use this file except in compliance with the License. 6579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * You may obtain a copy of the License at 7579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * 8579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * http://www.apache.org/licenses/LICENSE-2.0 9579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * 10579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * Unless required by applicable law or agreed to in writing, software 11579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * distributed under the License is distributed on an "AS IS" BASIS, 12579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * See the License for the specific language governing permissions and 14579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * limitations under the License. 15579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson */ 16579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 17579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilsonpackage com.android.dx.rop.code; 18579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 19579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilsonimport com.android.dx.util.Hex; 20579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 21579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson/** 22579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * All the register-based opcodes, and related utilities. 23579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * 24579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * <p><b>Note:</b> Opcode descriptions use a rough pseudocode. {@code r} 25579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * is the result register, {@code x} is the first argument, 26579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * {@code y} is the second argument, and {@code z} is the 27579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * third argument. The expression which describes 28579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * the operation uses Java-ish syntax but is preceded by type indicators for 29579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * each of the values. 30579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson */ 31579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilsonpublic final class RegOps { 32579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** {@code nop()} */ 33579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int NOP = 1; 34579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 35579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** {@code T: any type; r,x: T :: r = x;} */ 36579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int MOVE = 2; 37579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 38579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** {@code T: any type; r,param(x): T :: r = param(x)} */ 39579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int MOVE_PARAM = 3; 40579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 41579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** 42579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * {@code T: Throwable; r: T :: r = caught_exception}. 43579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * <b>Note:</b> This opcode should only ever be used in the 44579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * first instruction of a block, and such blocks must be 45579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * the start of an exception handler. 46579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson */ 47579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int MOVE_EXCEPTION = 4; 48579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 49579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** {@code T: any type; r, literal: T :: r = literal;} */ 50579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int CONST = 5; 51579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 52579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** {@code goto label} */ 53579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int GOTO = 6; 54579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 55579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** 56579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * {@code T: int or Object; x,y: T :: if (x == y) goto 57579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * label} 58579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson */ 59579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int IF_EQ = 7; 60579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 61579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** 62579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * {@code T: int or Object; x,y: T :: if (x != y) goto 63579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * label} 64579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson */ 65579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int IF_NE = 8; 66579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 67579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** {@code x,y: int :: if (x < y) goto label} */ 68579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int IF_LT = 9; 69579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 70579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** {@code x,y: int :: if (x >= y) goto label} */ 71579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int IF_GE = 10; 72579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 73579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** {@code x,y: int :: if (x <= y) goto label} */ 74579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int IF_LE = 11; 75579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 76579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** {@code x,y: int :: if (x > y) goto label} */ 77579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int IF_GT = 12; 78579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 79579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** {@code x: int :: goto table[x]} */ 80579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int SWITCH = 13; 81579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 82579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** {@code T: any numeric type; r,x,y: T :: r = x + y} */ 83579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int ADD = 14; 84579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 85579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** {@code T: any numeric type; r,x,y: T :: r = x - y} */ 86579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int SUB = 15; 87579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 88579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** {@code T: any numeric type; r,x,y: T :: r = x * y} */ 89579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int MUL = 16; 90579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 91579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** {@code T: any numeric type; r,x,y: T :: r = x / y} */ 92579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int DIV = 17; 93579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 94579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** 95579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * {@code T: any numeric type; r,x,y: T :: r = x % y} 96579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * (Java-style remainder) 97579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson */ 98579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int REM = 18; 99579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 100579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** {@code T: any numeric type; r,x: T :: r = -x} */ 101579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int NEG = 19; 102579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 103579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** {@code T: any integral type; r,x,y: T :: r = x & y} */ 104579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int AND = 20; 105579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 106579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** {@code T: any integral type; r,x,y: T :: r = x | y} */ 107579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int OR = 21; 108579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 109579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** {@code T: any integral type; r,x,y: T :: r = x ^ y} */ 110579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int XOR = 22; 111579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 112579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** 113579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * {@code T: any integral type; r,x: T; y: int :: r = x << y} 114579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson */ 115579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int SHL = 23; 116579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 117579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** 118579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * {@code T: any integral type; r,x: T; y: int :: r = x >> y} 119579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * (signed right-shift) 120579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson */ 121579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int SHR = 24; 122579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 123579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** 124579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * {@code T: any integral type; r,x: T; y: int :: r = x >>> y} 125579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * (unsigned right-shift) 126579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson */ 127579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int USHR = 25; 128579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 129579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** {@code T: any integral type; r,x: T :: r = ~x} */ 130579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int NOT = 26; 131579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 132579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** 133579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * {@code T: any numeric type; r: int; x,y: T :: r = (x == y) ? 0 134579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * : (x > y) ? 1 : -1} (Java-style "cmpl" where a NaN is 135579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * considered "less than" all other values; also used for integral 136579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * comparisons) 137579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson */ 138579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int CMPL = 27; 139579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 140579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** 141579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * {@code T: any floating point type; r: int; x,y: T :: r = (x == y) ? 0 142579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * : (x < y) ? -1 : 1} (Java-style "cmpg" where a NaN is 143579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * considered "greater than" all other values) 144579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson */ 145579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int CMPG = 28; 146579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 147579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** 148579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * {@code T: any numeric type; U: any numeric type; r: T; x: U :: 149579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * r = (T) x} (numeric type conversion between the four 150579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * "real" numeric types) 151579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson */ 152579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int CONV = 29; 153579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 154579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** 155579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * {@code r,x: int :: r = (x << 24) >> 24} (Java-style 156579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * convert int to byte) 157579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson */ 158579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int TO_BYTE = 30; 159579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 160579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** 161579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * {@code r,x: int :: r = x & 0xffff} (Java-style convert int to char) 162579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson */ 163579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int TO_CHAR = 31; 164579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 165579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** 166579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * {@code r,x: int :: r = (x << 16) >> 16} (Java-style 167579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * convert int to short) 168579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson */ 169579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int TO_SHORT = 32; 170579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 171579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** {@code T: return type for the method; x: T; return x} */ 172579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int RETURN = 33; 173579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 174579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** {@code T: any type; r: int; x: T[]; :: r = x.length} */ 175579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int ARRAY_LENGTH = 34; 176579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 177579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** {@code x: Throwable :: throw(x)} */ 178579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int THROW = 35; 179579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 180579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** {@code x: Object :: monitorenter(x)} */ 181579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int MONITOR_ENTER = 36; 182579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 183579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** {@code x: Object :: monitorexit(x)} */ 184579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int MONITOR_EXIT = 37; 185579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 186579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** {@code T: any type; r: T; x: T[]; y: int :: r = x[y]} */ 187579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int AGET = 38; 188579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 189579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** {@code T: any type; x: T; y: T[]; z: int :: x[y] = z} */ 190579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int APUT = 39; 191579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 192579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** 193579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * {@code T: any non-array object type :: r = 194579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * alloc(T)} (allocate heap space for an object) 195579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson */ 196579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int NEW_INSTANCE = 40; 197579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 198579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** {@code T: any array type; r: T; x: int :: r = new T[x]} */ 199579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int NEW_ARRAY = 41; 200579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 201579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** 202579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * {@code T: any array type; r: T; x: int; v0..vx: T :: r = new T[x] 203579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * {v0, ..., vx}} 204579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson */ 205579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int FILLED_NEW_ARRAY = 42; 206579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 207579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** 208579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * {@code T: any object type; x: Object :: (T) x} (can 209579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * throw {@code ClassCastException}) 210579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson */ 211579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int CHECK_CAST = 43; 212579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 213579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** 214579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * {@code T: any object type; x: Object :: x instanceof T} 215579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson */ 216579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int INSTANCE_OF = 44; 217579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 218579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** 219579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * {@code T: any type; r: T; x: Object; f: instance field spec of 220579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * type T :: r = x.f} 221579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson */ 222579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int GET_FIELD = 45; 223579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 224579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** 225579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * {@code T: any type; r: T; f: static field spec of type T :: r = 226579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * f} 227579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson */ 228579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int GET_STATIC = 46; 229579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 230579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** 231579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * {@code T: any type; x: T; y: Object; f: instance field spec of type 232579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * T :: y.f = x} 233579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson */ 234579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int PUT_FIELD = 47; 235579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 236579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** 237579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * {@code T: any type; f: static field spec of type T; x: T :: f = x} 238579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson */ 239579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int PUT_STATIC = 48; 240579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 241579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** 242579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * {@code Tr, T0, T1...: any types; r: Tr; m: static method spec; 243579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * y0: T0; y1: T1 ... :: r = m(y0, y1, ...)} (call static 244579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * method) 245579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson */ 246579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int INVOKE_STATIC = 49; 247579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 248579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** 249579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * {@code Tr, T0, T1...: any types; r: Tr; x: Object; m: instance method 250579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * spec; y0: T0; y1: T1 ... :: r = x.m(y0, y1, ...)} (call normal 251579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * virtual method) 252579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson */ 253579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int INVOKE_VIRTUAL = 50; 254579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 255579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** 256579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * {@code Tr, T0, T1...: any types; r: Tr; x: Object; m: instance method 257579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * spec; y0: T0; y1: T1 ... :: r = x.m(y0, y1, ...)} (call 258579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * superclass virtual method) 259579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson */ 260579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int INVOKE_SUPER = 51; 261579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 262579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** 263579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * {@code Tr, T0, T1...: any types; r: Tr; x: Object; m: instance method 264579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * spec; y0: T0; y1: T1 ... :: r = x.m(y0, y1, ...)} (call 265579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * direct/special method) 266579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson */ 267579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int INVOKE_DIRECT = 52; 268579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 269579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** 270579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * {@code Tr, T0, T1...: any types; r: Tr; x: Object; m: interface 271579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * (instance) method spec; y0: T0; y1: T1 ... :: r = x.m(y0, y1, 272579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * ...)} (call interface method) 273579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson */ 274579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int INVOKE_INTERFACE = 53; 275579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 276579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** 277579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * {@code T0: any type; name: local variable name :: mark(name,T0)} 278579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * (mark beginning or end of local variable name) 279579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson */ 280579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int MARK_LOCAL = 54; 281579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 282579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** 283579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * {@code T: Any type; r: T :: r = return_type}. 284579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * <b>Note:</b> This opcode should only ever be used in the 285579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * first instruction of a block following an invoke-*. 286579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson */ 287579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int MOVE_RESULT = 55; 288579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 289579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** 290579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * {@code T: Any type; r: T :: r = return_type}. 291579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * <b>Note:</b> This opcode should only ever be used in the 292579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * first instruction of a block following a non-invoke throwing insn 293579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson */ 294579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int MOVE_RESULT_PSEUDO = 56; 295579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 296579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** {@code T: Any primitive type; v0..vx: T :: {v0, ..., vx}} */ 297579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static final int FILL_ARRAY_DATA = 57; 298579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 299579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** 300579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * This class is uninstantiable. 301579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson */ 302579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson private RegOps() { 303579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson // This space intentionally left blank. 304579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson } 305579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 306579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** 307579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * Gets the name of the given opcode. 308579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * 309579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * @param opcode the opcode 310579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * @return {@code non-null;} its name 311579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson */ 312579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static String opName(int opcode) { 313579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson switch (opcode) { 314579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case NOP: return "nop"; 315579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case MOVE: return "move"; 316579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case MOVE_PARAM: return "move-param"; 317579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case MOVE_EXCEPTION: return "move-exception"; 318579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case CONST: return "const"; 319579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case GOTO: return "goto"; 320579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case IF_EQ: return "if-eq"; 321579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case IF_NE: return "if-ne"; 322579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case IF_LT: return "if-lt"; 323579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case IF_GE: return "if-ge"; 324579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case IF_LE: return "if-le"; 325579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case IF_GT: return "if-gt"; 326579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case SWITCH: return "switch"; 327579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case ADD: return "add"; 328579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case SUB: return "sub"; 329579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case MUL: return "mul"; 330579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case DIV: return "div"; 331579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case REM: return "rem"; 332579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case NEG: return "neg"; 333579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case AND: return "and"; 334579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case OR: return "or"; 335579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case XOR: return "xor"; 336579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case SHL: return "shl"; 337579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case SHR: return "shr"; 338579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case USHR: return "ushr"; 339579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case NOT: return "not"; 340579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case CMPL: return "cmpl"; 341579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case CMPG: return "cmpg"; 342579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case CONV: return "conv"; 343579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case TO_BYTE: return "to-byte"; 344579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case TO_CHAR: return "to-char"; 345579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case TO_SHORT: return "to-short"; 346579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case RETURN: return "return"; 347579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case ARRAY_LENGTH: return "array-length"; 348579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case THROW: return "throw"; 349579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case MONITOR_ENTER: return "monitor-enter"; 350579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case MONITOR_EXIT: return "monitor-exit"; 351579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case AGET: return "aget"; 352579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case APUT: return "aput"; 353579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case NEW_INSTANCE: return "new-instance"; 354579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case NEW_ARRAY: return "new-array"; 355579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case FILLED_NEW_ARRAY: return "filled-new-array"; 356579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case CHECK_CAST: return "check-cast"; 357579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case INSTANCE_OF: return "instance-of"; 358579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case GET_FIELD: return "get-field"; 359579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case GET_STATIC: return "get-static"; 360579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case PUT_FIELD: return "put-field"; 361579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case PUT_STATIC: return "put-static"; 362579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case INVOKE_STATIC: return "invoke-static"; 363579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case INVOKE_VIRTUAL: return "invoke-virtual"; 364579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case INVOKE_SUPER: return "invoke-super"; 365579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case INVOKE_DIRECT: return "invoke-direct"; 366579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case INVOKE_INTERFACE: return "invoke-interface"; 367579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case MOVE_RESULT: return "move-result"; 368579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case MOVE_RESULT_PSEUDO: return "move-result-pseudo"; 369579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case FILL_ARRAY_DATA: return "fill-array-data"; 370579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson } 371579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 372579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson return "unknown-" + Hex.u1(opcode); 373579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson } 374579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson 375579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson /** 376579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * Given an IF_* RegOp, returns the right-to-left flipped version. For 377579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * example, IF_GT becomes IF_LT. 378579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * 379579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * @param opcode An IF_* RegOp 380579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson * @return flipped IF Regop 381579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson */ 382579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson public static int flippedIfOpcode(final int opcode) { 383579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson switch (opcode) { 384579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case RegOps.IF_EQ: 385579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case RegOps.IF_NE: 386579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson return opcode; 387579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case RegOps.IF_LT: 388579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson return RegOps.IF_GT; 389579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case RegOps.IF_GE: 390579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson return RegOps.IF_LE; 391579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case RegOps.IF_LE: 392579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson return RegOps.IF_GE; 393579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson case RegOps.IF_GT: 394579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson return RegOps.IF_LT; 395579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson default: 396579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson throw new RuntimeException("Unrecognized IF regop: " + opcode); 397579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson } 398579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson } 399579d7739c53a2707ad711a2d2cae46d7d782f06Jesse Wilson} 400