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