Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 16 | |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 17 | #include "dex_instruction.h" |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 18 | |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 19 | #include "dex_file.h" |
| 20 | #include <iomanip> |
| 21 | |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 22 | namespace art { |
| 23 | |
Carl Shapiro | e4c1ce4 | 2011-07-09 02:31:57 -0700 | [diff] [blame] | 24 | const char* const Instruction::kInstructionNames[] = { |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 25 | #define INSTRUCTION_NAME(o, c, pname, f, r, i, a, v) pname, |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 26 | #include "dex_instruction_list.h" |
Carl Shapiro | e4c1ce4 | 2011-07-09 02:31:57 -0700 | [diff] [blame] | 27 | DEX_INSTRUCTION_LIST(INSTRUCTION_NAME) |
| 28 | #undef DEX_INSTRUCTION_LIST |
| 29 | #undef INSTRUCTION_NAME |
| 30 | }; |
| 31 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 32 | Instruction::Format const Instruction::kInstructionFormats[] = { |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 33 | #define INSTRUCTION_FORMAT(o, c, p, format, r, i, a, v) format, |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 34 | #include "dex_instruction_list.h" |
Carl Shapiro | e4c1ce4 | 2011-07-09 02:31:57 -0700 | [diff] [blame] | 35 | DEX_INSTRUCTION_LIST(INSTRUCTION_FORMAT) |
| 36 | #undef DEX_INSTRUCTION_LIST |
| 37 | #undef INSTRUCTION_FORMAT |
| 38 | }; |
| 39 | |
| 40 | int const Instruction::kInstructionFlags[] = { |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 41 | #define INSTRUCTION_FLAGS(o, c, p, f, r, i, flags, v) flags, |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 42 | #include "dex_instruction_list.h" |
Carl Shapiro | e4c1ce4 | 2011-07-09 02:31:57 -0700 | [diff] [blame] | 43 | DEX_INSTRUCTION_LIST(INSTRUCTION_FLAGS) |
| 44 | #undef DEX_INSTRUCTION_LIST |
| 45 | #undef INSTRUCTION_FLAGS |
| 46 | }; |
| 47 | |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 48 | int const Instruction::kInstructionVerifyFlags[] = { |
| 49 | #define INSTRUCTION_VERIFY_FLAGS(o, c, p, f, r, i, a, vflags) vflags, |
| 50 | #include "dex_instruction_list.h" |
| 51 | DEX_INSTRUCTION_LIST(INSTRUCTION_VERIFY_FLAGS) |
| 52 | #undef DEX_INSTRUCTION_LIST |
| 53 | #undef INSTRUCTION_VERIFY_FLAGS |
| 54 | }; |
| 55 | |
Ian Rogers | a75a013 | 2012-09-28 11:41:42 -0700 | [diff] [blame] | 56 | int const Instruction::kInstructionSizeInCodeUnits[] = { |
| 57 | #define INSTRUCTION_SIZE(opcode, c, p, format, r, i, a, v) \ |
| 58 | (( opcode == NOP ) ? -1 : \ |
| 59 | ((format >= k10x) && (format <= k10t)) ? 1 : \ |
| 60 | ((format >= k20t) && (format <= k22c)) ? 2 : \ |
| 61 | ((format >= k32x) && (format <= k3rc)) ? 3 : \ |
| 62 | ( format == k51l ) ? 5 : -1 \ |
| 63 | ), |
| 64 | #include "dex_instruction_list.h" |
| 65 | DEX_INSTRUCTION_LIST(INSTRUCTION_SIZE) |
| 66 | #undef DEX_INSTRUCTION_LIST |
| 67 | #undef INSTRUCTION_SIZE |
| 68 | }; |
| 69 | |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 70 | /* |
| 71 | * Handy macros for helping decode instructions. |
| 72 | */ |
| 73 | #define FETCH(_offset) (insns[(_offset)]) |
| 74 | #define FETCH_u4(_offset) (fetch_u4_impl((_offset), insns)) |
| 75 | #define INST_A(_insn) (((uint16_t)(_insn) >> 8) & 0x0f) |
| 76 | #define INST_B(_insn) ((uint16_t)(_insn) >> 12) |
| 77 | #define INST_AA(_insn) ((_insn) >> 8) |
| 78 | |
| 79 | /* Helper for FETCH_u4, above. */ |
| 80 | static inline uint32_t fetch_u4_impl(uint32_t offset, const uint16_t* insns) { |
| 81 | return insns[offset] | ((uint32_t) insns[offset+1] << 16); |
| 82 | } |
| 83 | |
| 84 | void Instruction::Decode(uint32_t &vA, uint32_t &vB, uint64_t &vB_wide, uint32_t &vC, uint32_t arg[]) const { |
| 85 | const uint16_t* insns = reinterpret_cast<const uint16_t*>(this); |
| 86 | uint16_t insn = *insns; |
Ian Rogers | a75a013 | 2012-09-28 11:41:42 -0700 | [diff] [blame] | 87 | Code opcode = static_cast<Code>(insn & 0xFF); |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 88 | |
Ian Rogers | a75a013 | 2012-09-28 11:41:42 -0700 | [diff] [blame] | 89 | switch (FormatOf(opcode)) { |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 90 | case k10x: // op |
| 91 | /* nothing to do; copy the AA bits out for the verifier */ |
| 92 | vA = INST_AA(insn); |
| 93 | break; |
| 94 | case k12x: // op vA, vB |
| 95 | vA = INST_A(insn); |
| 96 | vB = INST_B(insn); |
| 97 | break; |
| 98 | case k11n: // op vA, #+B |
| 99 | vA = INST_A(insn); |
| 100 | vB = (int32_t) (INST_B(insn) << 28) >> 28; // sign extend 4-bit value |
| 101 | break; |
| 102 | case k11x: // op vAA |
| 103 | vA = INST_AA(insn); |
| 104 | break; |
| 105 | case k10t: // op +AA |
| 106 | vA = (int8_t) INST_AA(insn); // sign-extend 8-bit value |
| 107 | break; |
| 108 | case k20t: // op +AAAA |
| 109 | vA = (int16_t) FETCH(1); // sign-extend 16-bit value |
| 110 | break; |
| 111 | case k21c: // op vAA, thing@BBBB |
| 112 | case k22x: // op vAA, vBBBB |
| 113 | vA = INST_AA(insn); |
| 114 | vB = FETCH(1); |
| 115 | break; |
| 116 | case k21s: // op vAA, #+BBBB |
| 117 | case k21t: // op vAA, +BBBB |
| 118 | vA = INST_AA(insn); |
| 119 | vB = (int16_t) FETCH(1); // sign-extend 16-bit value |
| 120 | break; |
| 121 | case k21h: // op vAA, #+BBBB0000[00000000] |
| 122 | vA = INST_AA(insn); |
| 123 | /* |
| 124 | * The value should be treated as right-zero-extended, but we don't |
| 125 | * actually do that here. Among other things, we don't know if it's |
| 126 | * the top bits of a 32- or 64-bit value. |
| 127 | */ |
| 128 | vB = FETCH(1); |
| 129 | break; |
| 130 | case k23x: // op vAA, vBB, vCC |
| 131 | vA = INST_AA(insn); |
| 132 | vB = FETCH(1) & 0xff; |
| 133 | vC = FETCH(1) >> 8; |
| 134 | break; |
| 135 | case k22b: // op vAA, vBB, #+CC |
| 136 | vA = INST_AA(insn); |
| 137 | vB = FETCH(1) & 0xff; |
| 138 | vC = (int8_t) (FETCH(1) >> 8); // sign-extend 8-bit value |
| 139 | break; |
| 140 | case k22s: // op vA, vB, #+CCCC |
| 141 | case k22t: // op vA, vB, +CCCC |
| 142 | vA = INST_A(insn); |
| 143 | vB = INST_B(insn); |
| 144 | vC = (int16_t) FETCH(1); // sign-extend 16-bit value |
| 145 | break; |
| 146 | case k22c: // op vA, vB, thing@CCCC |
| 147 | vA = INST_A(insn); |
| 148 | vB = INST_B(insn); |
| 149 | vC = FETCH(1); |
| 150 | break; |
| 151 | case k30t: // op +AAAAAAAA |
| 152 | vA = FETCH_u4(1); // signed 32-bit value |
| 153 | break; |
| 154 | case k31t: // op vAA, +BBBBBBBB |
| 155 | case k31c: // op vAA, string@BBBBBBBB |
| 156 | vA = INST_AA(insn); |
| 157 | vB = FETCH_u4(1); // 32-bit value |
| 158 | break; |
| 159 | case k32x: // op vAAAA, vBBBB |
| 160 | vA = FETCH(1); |
| 161 | vB = FETCH(2); |
| 162 | break; |
| 163 | case k31i: // op vAA, #+BBBBBBBB |
| 164 | vA = INST_AA(insn); |
| 165 | vB = FETCH_u4(1); // signed 32-bit value |
| 166 | break; |
| 167 | case k35c: // op {vC, vD, vE, vF, vG}, thing@BBBB |
| 168 | { |
| 169 | /* |
| 170 | * Note that the fields mentioned in the spec don't appear in |
| 171 | * their "usual" positions here compared to most formats. This |
| 172 | * was done so that the field names for the argument count and |
| 173 | * reference index match between this format and the corresponding |
| 174 | * range formats (3rc and friends). |
| 175 | * |
| 176 | * Bottom line: The argument count is always in vA, and the |
| 177 | * method constant (or equivalent) is always in vB. |
| 178 | */ |
| 179 | uint16_t regList; |
| 180 | int count; |
| 181 | |
| 182 | vA = INST_B(insn); // This is labeled A in the spec. |
| 183 | vB = FETCH(1); |
| 184 | regList = FETCH(2); |
| 185 | |
| 186 | count = vA; |
| 187 | |
| 188 | /* |
| 189 | * Copy the argument registers into the arg[] array, and |
| 190 | * also copy the first argument (if any) into vC. (The |
| 191 | * DecodedInstruction structure doesn't have separate |
| 192 | * fields for {vD, vE, vF, vG}, so there's no need to make |
| 193 | * copies of those.) Note that cases 5..2 fall through. |
| 194 | */ |
| 195 | switch (count) { |
| 196 | case 5: arg[4] = INST_A(insn); |
| 197 | case 4: arg[3] = (regList >> 12) & 0x0f; |
| 198 | case 3: arg[2] = (regList >> 8) & 0x0f; |
| 199 | case 2: arg[1] = (regList >> 4) & 0x0f; |
| 200 | case 1: vC = arg[0] = regList & 0x0f; break; |
| 201 | case 0: break; // Valid, but no need to do anything. |
| 202 | default: |
| 203 | LOG(ERROR) << "Invalid arg count in 35c (" << count << ")"; |
| 204 | return; |
| 205 | } |
| 206 | } |
| 207 | break; |
| 208 | case k3rc: // op {vCCCC .. v(CCCC+AA-1)}, meth@BBBB |
| 209 | vA = INST_AA(insn); |
| 210 | vB = FETCH(1); |
| 211 | vC = FETCH(2); |
| 212 | break; |
| 213 | case k51l: // op vAA, #+BBBBBBBBBBBBBBBB |
| 214 | vA = INST_AA(insn); |
| 215 | vB_wide = FETCH_u4(1) | ((uint64_t) FETCH_u4(3) << 32); |
| 216 | break; |
| 217 | default: |
Ian Rogers | a75a013 | 2012-09-28 11:41:42 -0700 | [diff] [blame] | 218 | LOG(ERROR) << "Can't decode unexpected format " << FormatOf(opcode) << " (op=" << opcode << ")"; |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 219 | return; |
| 220 | } |
| 221 | } |
| 222 | |
Ian Rogers | a75a013 | 2012-09-28 11:41:42 -0700 | [diff] [blame] | 223 | size_t Instruction::SizeInCodeUnitsComplexOpcode() const { |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 224 | const uint16_t* insns = reinterpret_cast<const uint16_t*>(this); |
Ian Rogers | a75a013 | 2012-09-28 11:41:42 -0700 | [diff] [blame] | 225 | // Handle special NOP encoded variable length sequences. |
| 226 | switch (*insns) { |
| 227 | case kPackedSwitchSignature: |
| 228 | return (4 + insns[1] * 2); |
| 229 | case kSparseSwitchSignature: |
| 230 | return (2 + insns[1] * 4); |
| 231 | case kArrayDataSignature: { |
| 232 | uint16_t element_size = insns[1]; |
| 233 | uint32_t length = insns[2] | (((uint32_t)insns[3]) << 16); |
| 234 | // The plus 1 is to round up for odd size and width. |
| 235 | return (4 + (element_size * length + 1) / 2); |
Carl Shapiro | e4c1ce4 | 2011-07-09 02:31:57 -0700 | [diff] [blame] | 236 | } |
Ian Rogers | a75a013 | 2012-09-28 11:41:42 -0700 | [diff] [blame] | 237 | default: |
| 238 | if ((*insns & 0xFF) == 0) { |
| 239 | return 1; // NOP. |
| 240 | } else { |
| 241 | LOG(FATAL) << "Unreachable: " << DumpString(NULL); |
| 242 | return 0; |
| 243 | } |
Carl Shapiro | e4c1ce4 | 2011-07-09 02:31:57 -0700 | [diff] [blame] | 244 | } |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 245 | } |
| 246 | |
Ian Rogers | 2c8a857 | 2011-10-24 17:11:36 -0700 | [diff] [blame] | 247 | std::string Instruction::DumpHex(size_t code_units) const { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 248 | size_t inst_length = SizeInCodeUnits(); |
| 249 | if (inst_length > code_units) { |
| 250 | inst_length = code_units; |
| 251 | } |
Ian Rogers | 2c8a857 | 2011-10-24 17:11:36 -0700 | [diff] [blame] | 252 | std::ostringstream os; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 253 | const uint16_t* insn = reinterpret_cast<const uint16_t*>(this); |
| 254 | for (size_t i = 0; i < inst_length; i++) { |
Ian Rogers | 2c8a857 | 2011-10-24 17:11:36 -0700 | [diff] [blame] | 255 | os << StringPrintf("0x%04x", insn[i]) << " "; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 256 | } |
| 257 | for (size_t i = inst_length; i < code_units; i++) { |
| 258 | os << " "; |
| 259 | } |
Ian Rogers | 2c8a857 | 2011-10-24 17:11:36 -0700 | [diff] [blame] | 260 | return os.str(); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 261 | } |
| 262 | |
Ian Rogers | 2c8a857 | 2011-10-24 17:11:36 -0700 | [diff] [blame] | 263 | std::string Instruction::DumpString(const DexFile* file) const { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 264 | DecodedInstruction insn(this); |
Ian Rogers | 2c8a857 | 2011-10-24 17:11:36 -0700 | [diff] [blame] | 265 | std::ostringstream os; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 266 | const char* opcode = kInstructionNames[insn.opcode]; |
| 267 | switch (FormatOf(Opcode())) { |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 268 | case k10x: os << opcode; break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 269 | case k12x: os << StringPrintf("%s v%d, v%d", opcode, insn.vA, insn.vB); break; |
| 270 | case k11n: os << StringPrintf("%s v%d, #%+d", opcode, insn.vA, insn.vB); break; |
| 271 | case k11x: os << StringPrintf("%s v%d", opcode, insn.vA); break; |
| 272 | case k10t: os << StringPrintf("%s %+d", opcode, insn.vA); break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 273 | case k20t: os << StringPrintf("%s %+d", opcode, insn.vA); break; |
| 274 | case k22x: os << StringPrintf("%s v%d, v%d", opcode, insn.vA, insn.vB); break; |
| 275 | case k21t: os << StringPrintf("%s v%d, %+d", opcode, insn.vA, insn.vB); break; |
| 276 | case k21s: os << StringPrintf("%s v%d, #%+d", opcode, insn.vA, insn.vB); break; |
Elliott Hughes | 1b3d6ca | 2012-04-25 13:00:14 -0700 | [diff] [blame] | 277 | case k21h: { |
| 278 | // op vAA, #+BBBB0000[00000000] |
| 279 | if (insn.opcode == CONST_HIGH16) { |
| 280 | uint32_t value = insn.vB << 16; |
| 281 | os << StringPrintf("%s v%d, #int %+d // 0x%x", opcode, insn.vA, value, value); |
| 282 | } else { |
| 283 | uint64_t value = static_cast<uint64_t>(insn.vB) << 48; |
| 284 | os << StringPrintf("%s v%d, #long %+lld // 0x%llx", opcode, insn.vA, value, value); |
| 285 | } |
| 286 | } |
| 287 | break; |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 288 | case k21c: { |
| 289 | switch (insn.opcode) { |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 290 | case CONST_STRING: |
| 291 | if (file != NULL) { |
| 292 | os << StringPrintf("const-string v%d, \"%s\" // string@%d", insn.vA, |
| 293 | file->StringDataByIdx(insn.vB), insn.vB); |
| 294 | break; |
| 295 | } // else fall-through |
Mathieu Chartier | 18c24b6 | 2012-09-10 08:54:25 -0700 | [diff] [blame] | 296 | case CHECK_CAST: |
| 297 | case CONST_CLASS: |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 298 | case NEW_INSTANCE: |
| 299 | if (file != NULL) { |
Mathieu Chartier | 18c24b6 | 2012-09-10 08:54:25 -0700 | [diff] [blame] | 300 | os << opcode << " " << PrettyType(insn.vB, *file) << " // type@" << insn.vB; |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 301 | break; |
| 302 | } // else fall-through |
| 303 | case SGET: |
| 304 | case SGET_WIDE: |
| 305 | case SGET_OBJECT: |
| 306 | case SGET_BOOLEAN: |
| 307 | case SGET_BYTE: |
| 308 | case SGET_CHAR: |
| 309 | case SGET_SHORT: |
| 310 | if (file != NULL) { |
Mathieu Chartier | 18c24b6 | 2012-09-10 08:54:25 -0700 | [diff] [blame] | 311 | os << opcode << " " << PrettyField(insn.vB, *file, true) << " // field@" << insn.vB; |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 312 | break; |
| 313 | } // else fall-through |
| 314 | case SPUT: |
| 315 | case SPUT_WIDE: |
| 316 | case SPUT_OBJECT: |
| 317 | case SPUT_BOOLEAN: |
| 318 | case SPUT_BYTE: |
| 319 | case SPUT_CHAR: |
| 320 | case SPUT_SHORT: |
| 321 | if (file != NULL) { |
Mathieu Chartier | 18c24b6 | 2012-09-10 08:54:25 -0700 | [diff] [blame] | 322 | os << opcode << " " << PrettyField(insn.vB, *file, true) << " // field@" << insn.vB; |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 323 | break; |
| 324 | } // else fall-through |
| 325 | default: |
| 326 | os << StringPrintf("%s v%d, thing@%d", opcode, insn.vA, insn.vB); |
| 327 | break; |
| 328 | } |
| 329 | break; |
| 330 | } |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 331 | case k23x: os << StringPrintf("%s v%d, v%d, v%d", opcode, insn.vA, insn.vB, insn.vC); break; |
| 332 | case k22b: os << StringPrintf("%s v%d, v%d, #%+d", opcode, insn.vA, insn.vB, insn.vC); break; |
| 333 | case k22t: os << StringPrintf("%s v%d, v%d, %+d", opcode, insn.vA, insn.vB, insn.vC); break; |
| 334 | case k22s: os << StringPrintf("%s v%d, v%d, #%+d", opcode, insn.vA, insn.vB, insn.vC); break; |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 335 | case k22c: { |
| 336 | switch (insn.opcode) { |
| 337 | case IGET: |
| 338 | case IGET_WIDE: |
| 339 | case IGET_OBJECT: |
| 340 | case IGET_BOOLEAN: |
| 341 | case IGET_BYTE: |
| 342 | case IGET_CHAR: |
| 343 | case IGET_SHORT: |
| 344 | if (file != NULL) { |
Mathieu Chartier | 18c24b6 | 2012-09-10 08:54:25 -0700 | [diff] [blame] | 345 | os << PrettyField(insn.vC, *file, true) << " // field@" << insn.vC; |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 346 | break; |
| 347 | } // else fall-through |
| 348 | case IPUT: |
| 349 | case IPUT_WIDE: |
| 350 | case IPUT_OBJECT: |
| 351 | case IPUT_BOOLEAN: |
| 352 | case IPUT_BYTE: |
| 353 | case IPUT_CHAR: |
| 354 | case IPUT_SHORT: |
| 355 | if (file != NULL) { |
Mathieu Chartier | 18c24b6 | 2012-09-10 08:54:25 -0700 | [diff] [blame] | 356 | os << opcode << " " << PrettyField(insn.vC, *file, true) << " // field@" << insn.vB; |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 357 | break; |
| 358 | } // else fall-through |
| 359 | case INSTANCE_OF: |
| 360 | if (file != NULL) { |
Mathieu Chartier | 18c24b6 | 2012-09-10 08:54:25 -0700 | [diff] [blame] | 361 | os << opcode << " " << PrettyType(insn.vC, *file) << " // type@" << insn.vC; |
| 362 | break; |
| 363 | } |
| 364 | case NEW_ARRAY: |
| 365 | if (file != NULL) { |
| 366 | os << opcode << " " << PrettyType(insn.vC, *file) << " // type@" << insn.vC; |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 367 | break; |
| 368 | } // else fall-through |
| 369 | default: |
| 370 | os << StringPrintf("%s v%d, v%d, thing@%d", opcode, insn.vA, insn.vB, insn.vC); |
| 371 | break; |
| 372 | } |
| 373 | break; |
| 374 | } |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 375 | case k32x: os << StringPrintf("%s v%d, v%d", opcode, insn.vA, insn.vB); break; |
| 376 | case k30t: os << StringPrintf("%s %+d", opcode, insn.vA); break; |
| 377 | case k31t: os << StringPrintf("%s v%d, %+d", opcode, insn.vA, insn.vB); break; |
| 378 | case k31i: os << StringPrintf("%s v%d, #%+d", opcode, insn.vA, insn.vB); break; |
| 379 | case k31c: os << StringPrintf("%s v%d, thing@%d", opcode, insn.vA, insn.vB); break; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 380 | case k35c: { |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 381 | switch (insn.opcode) { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 382 | case INVOKE_VIRTUAL: |
| 383 | case INVOKE_SUPER: |
| 384 | case INVOKE_DIRECT: |
| 385 | case INVOKE_STATIC: |
| 386 | case INVOKE_INTERFACE: |
| 387 | if (file != NULL) { |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 388 | os << opcode << " {"; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 389 | for (size_t i = 0; i < insn.vA; ++i) { |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 390 | if (i != 0) { |
| 391 | os << ", "; |
| 392 | } |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 393 | os << "v" << insn.arg[i]; |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 394 | } |
Ian Rogers | 4c5dd5a | 2012-09-07 11:27:28 -0700 | [diff] [blame] | 395 | os << "}, " << PrettyMethod(insn.vB, *file) << " // method@" << insn.vB; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 396 | break; |
| 397 | } // else fall-through |
| 398 | default: |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 399 | os << opcode << " {v" << insn.arg[0] << ", v" << insn.arg[1] << ", v" << insn.arg[2] |
| 400 | << ", v" << insn.arg[3] << ", v" << insn.arg[4] << "}, thing@" << insn.vB; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 401 | break; |
| 402 | } |
| 403 | break; |
| 404 | } |
Ian Rogers | 4c5dd5a | 2012-09-07 11:27:28 -0700 | [diff] [blame] | 405 | case k3rc: { |
| 406 | switch (insn.opcode) { |
| 407 | case INVOKE_VIRTUAL_RANGE: |
| 408 | case INVOKE_SUPER_RANGE: |
| 409 | case INVOKE_DIRECT_RANGE: |
| 410 | case INVOKE_STATIC_RANGE: |
| 411 | case INVOKE_INTERFACE_RANGE: |
| 412 | if (file != NULL) { |
| 413 | os << StringPrintf("%s, {v%d .. v%d}, ", opcode, insn.vC, (insn.vC + insn.vA - 1)) |
| 414 | << PrettyMethod(insn.vB, *file) << " // method@" << insn.vB; |
| 415 | break; |
| 416 | } // else fall-through |
| 417 | default: |
| 418 | os << StringPrintf("%s, {v%d .. v%d}, thing@%d", opcode, insn.vC, (insn.vC + insn.vA - 1), |
| 419 | insn.vB); |
| 420 | break; |
| 421 | } |
| 422 | break; |
| 423 | } |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 424 | case k51l: os << StringPrintf("%s v%d, #%+d", opcode, insn.vA, insn.vB); break; |
Ian Rogers | 2c8a857 | 2011-10-24 17:11:36 -0700 | [diff] [blame] | 425 | default: os << " unknown format (" << DumpHex(5) << ")"; break; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 426 | } |
Ian Rogers | 2c8a857 | 2011-10-24 17:11:36 -0700 | [diff] [blame] | 427 | return os.str(); |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 428 | } |
| 429 | |
Ian Rogers | a75a013 | 2012-09-28 11:41:42 -0700 | [diff] [blame] | 430 | std::ostream& operator<<(std::ostream& os, const Instruction::Code& code) { |
| 431 | return os << Instruction::Name(code); |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 432 | } |
| 433 | |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 434 | } // namespace art |