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 | b574c18 | 2014-01-23 19:51:19 -0800 | [diff] [blame] | 19 | #include <inttypes.h> |
| 20 | |
| 21 | #include <iomanip> |
| 22 | |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 23 | #include "dex_file-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 24 | #include "utils.h" |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 25 | |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 26 | namespace art { |
| 27 | |
Carl Shapiro | e4c1ce4 | 2011-07-09 02:31:57 -0700 | [diff] [blame] | 28 | const char* const Instruction::kInstructionNames[] = { |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 29 | #define INSTRUCTION_NAME(o, c, pname, f, r, i, a, v) pname, |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 30 | #include "dex_instruction_list.h" |
Carl Shapiro | e4c1ce4 | 2011-07-09 02:31:57 -0700 | [diff] [blame] | 31 | DEX_INSTRUCTION_LIST(INSTRUCTION_NAME) |
| 32 | #undef DEX_INSTRUCTION_LIST |
| 33 | #undef INSTRUCTION_NAME |
| 34 | }; |
| 35 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 36 | Instruction::Format const Instruction::kInstructionFormats[] = { |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 37 | #define INSTRUCTION_FORMAT(o, c, p, format, r, i, a, v) format, |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 38 | #include "dex_instruction_list.h" |
Carl Shapiro | e4c1ce4 | 2011-07-09 02:31:57 -0700 | [diff] [blame] | 39 | DEX_INSTRUCTION_LIST(INSTRUCTION_FORMAT) |
| 40 | #undef DEX_INSTRUCTION_LIST |
| 41 | #undef INSTRUCTION_FORMAT |
| 42 | }; |
| 43 | |
| 44 | int const Instruction::kInstructionFlags[] = { |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 45 | #define INSTRUCTION_FLAGS(o, c, p, f, r, i, flags, v) flags, |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 46 | #include "dex_instruction_list.h" |
Carl Shapiro | e4c1ce4 | 2011-07-09 02:31:57 -0700 | [diff] [blame] | 47 | DEX_INSTRUCTION_LIST(INSTRUCTION_FLAGS) |
| 48 | #undef DEX_INSTRUCTION_LIST |
| 49 | #undef INSTRUCTION_FLAGS |
| 50 | }; |
| 51 | |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 52 | int const Instruction::kInstructionVerifyFlags[] = { |
| 53 | #define INSTRUCTION_VERIFY_FLAGS(o, c, p, f, r, i, a, vflags) vflags, |
| 54 | #include "dex_instruction_list.h" |
| 55 | DEX_INSTRUCTION_LIST(INSTRUCTION_VERIFY_FLAGS) |
| 56 | #undef DEX_INSTRUCTION_LIST |
| 57 | #undef INSTRUCTION_VERIFY_FLAGS |
| 58 | }; |
| 59 | |
Ian Rogers | a75a013 | 2012-09-28 11:41:42 -0700 | [diff] [blame] | 60 | int const Instruction::kInstructionSizeInCodeUnits[] = { |
| 61 | #define INSTRUCTION_SIZE(opcode, c, p, format, r, i, a, v) \ |
Brian Carlstrom | 6f485c6 | 2013-07-18 15:35:35 -0700 | [diff] [blame] | 62 | ((opcode == NOP) ? -1 : \ |
| 63 | ((format >= k10x) && (format <= k10t)) ? 1 : \ |
| 64 | ((format >= k20t) && (format <= k22c)) ? 2 : \ |
| 65 | ((format >= k32x) && (format <= k3rc)) ? 3 : \ |
| 66 | (format == k51l) ? 5 : -1), |
Ian Rogers | a75a013 | 2012-09-28 11:41:42 -0700 | [diff] [blame] | 67 | #include "dex_instruction_list.h" |
| 68 | DEX_INSTRUCTION_LIST(INSTRUCTION_SIZE) |
| 69 | #undef DEX_INSTRUCTION_LIST |
| 70 | #undef INSTRUCTION_SIZE |
| 71 | }; |
| 72 | |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 73 | /* |
| 74 | * Handy macros for helping decode instructions. |
| 75 | */ |
| 76 | #define FETCH(_offset) (insns[(_offset)]) |
Sebastien Hertz | 807a256 | 2013-04-15 09:33:39 +0200 | [diff] [blame] | 77 | #define FETCH_uint32(_offset) (fetch_uint32_impl((_offset), insns)) |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 78 | #define INST_A(_insn) (((uint16_t)(_insn) >> 8) & 0x0f) |
| 79 | #define INST_B(_insn) ((uint16_t)(_insn) >> 12) |
| 80 | #define INST_AA(_insn) ((_insn) >> 8) |
| 81 | |
Sebastien Hertz | 807a256 | 2013-04-15 09:33:39 +0200 | [diff] [blame] | 82 | /* Helper for FETCH_uint32, above. */ |
| 83 | 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] | 84 | return insns[offset] | ((uint32_t) insns[offset+1] << 16); |
| 85 | } |
| 86 | |
Dragos Sbirlea | 8cc5162 | 2013-06-21 09:20:34 -0700 | [diff] [blame] | 87 | |
| 88 | bool Instruction::HasVRegC() const { |
| 89 | switch (FormatOf(Opcode())) { |
| 90 | case k23x: return true; |
| 91 | case k35c: return true; |
| 92 | case k3rc: return true; |
| 93 | default: return false; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | bool Instruction::HasVRegB() const { |
| 98 | switch (FormatOf(Opcode())) { |
| 99 | case k12x: return true; |
| 100 | case k22b: return true; |
| 101 | case k22c: return true; |
| 102 | case k22s: return true; |
| 103 | case k22t: return true; |
| 104 | case k22x: return true; |
Dragos Sbirlea | 0e260a3 | 2013-06-21 09:20:34 -0700 | [diff] [blame] | 105 | case k23x: return true; |
Dragos Sbirlea | 8cc5162 | 2013-06-21 09:20:34 -0700 | [diff] [blame] | 106 | case k32x: return true; |
| 107 | default: return false; |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | bool Instruction::HasVRegA() const { |
| 112 | switch (FormatOf(Opcode())) { |
| 113 | case k11n: return true; |
| 114 | case k11x: return true; |
| 115 | case k12x: return true; |
| 116 | case k21c: return true; |
| 117 | case k21h: return true; |
| 118 | case k21s: return true; |
| 119 | case k21t: return true; |
| 120 | case k22b: return true; |
| 121 | case k22c: return true; |
| 122 | case k22s: return true; |
| 123 | case k22t: return true; |
| 124 | case k22x: return true; |
| 125 | case k23x: return true; |
| 126 | case k31c: return true; |
| 127 | case k31i: return true; |
| 128 | case k31t: return true; |
| 129 | case k32x: return true; |
| 130 | case k51l: return true; |
| 131 | default: return false; |
| 132 | } |
| 133 | } |
| 134 | |
Dragos Sbirlea | 39f9927 | 2013-06-25 13:17:36 -0700 | [diff] [blame] | 135 | int32_t Instruction::VRegC() const { |
| 136 | switch (FormatOf(Opcode())) { |
Dragos Sbirlea | 39f9927 | 2013-06-25 13:17:36 -0700 | [diff] [blame] | 137 | case k23x: return VRegC_23x(); |
| 138 | case k35c: return VRegC_35c(); |
| 139 | case k3rc: return VRegC_3rc(); |
| 140 | default: LOG(FATAL) << "Tried to access vC of instruction " << Name() << |
| 141 | " which has no C operand."; |
| 142 | } |
Dragos Sbirlea | 8cc5162 | 2013-06-21 09:20:34 -0700 | [diff] [blame] | 143 | return -1; |
Dragos Sbirlea | 39f9927 | 2013-06-25 13:17:36 -0700 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | int32_t Instruction::VRegB() const { |
| 147 | switch (FormatOf(Opcode())) { |
Dragos Sbirlea | 39f9927 | 2013-06-25 13:17:36 -0700 | [diff] [blame] | 148 | case k12x: return VRegB_12x(); |
Dragos Sbirlea | 39f9927 | 2013-06-25 13:17:36 -0700 | [diff] [blame] | 149 | case k22b: return VRegB_22b(); |
| 150 | case k22c: return VRegB_22c(); |
| 151 | case k22s: return VRegB_22s(); |
| 152 | case k22t: return VRegB_22t(); |
| 153 | case k22x: return VRegB_22x(); |
Dragos Sbirlea | 0e260a3 | 2013-06-21 09:20:34 -0700 | [diff] [blame] | 154 | case k23x: return VRegB_23x(); |
Dragos Sbirlea | 39f9927 | 2013-06-25 13:17:36 -0700 | [diff] [blame] | 155 | case k32x: return VRegB_32x(); |
Dragos Sbirlea | 39f9927 | 2013-06-25 13:17:36 -0700 | [diff] [blame] | 156 | default: LOG(FATAL) << "Tried to access vB of instruction " << Name() << |
| 157 | " which has no B operand."; |
| 158 | } |
Dragos Sbirlea | 8cc5162 | 2013-06-21 09:20:34 -0700 | [diff] [blame] | 159 | return -1; |
Dragos Sbirlea | 39f9927 | 2013-06-25 13:17:36 -0700 | [diff] [blame] | 160 | } |
| 161 | |
Dragos Sbirlea | d25de7a | 2013-06-21 09:20:34 -0700 | [diff] [blame] | 162 | int32_t Instruction::VRegA() const { |
| 163 | switch (FormatOf(Opcode())) { |
Dragos Sbirlea | d25de7a | 2013-06-21 09:20:34 -0700 | [diff] [blame] | 164 | case k11n: return VRegA_11n(); |
| 165 | case k11x: return VRegA_11x(); |
| 166 | case k12x: return VRegA_12x(); |
Dragos Sbirlea | d25de7a | 2013-06-21 09:20:34 -0700 | [diff] [blame] | 167 | case k21c: return VRegA_21c(); |
| 168 | case k21h: return VRegA_21h(); |
| 169 | case k21s: return VRegA_21s(); |
| 170 | case k21t: return VRegA_21t(); |
| 171 | case k22b: return VRegA_22b(); |
| 172 | case k22c: return VRegA_22c(); |
| 173 | case k22s: return VRegA_22s(); |
| 174 | case k22t: return VRegA_22t(); |
| 175 | case k22x: return VRegA_22x(); |
| 176 | case k23x: return VRegA_23x(); |
Dragos Sbirlea | d25de7a | 2013-06-21 09:20:34 -0700 | [diff] [blame] | 177 | case k31c: return VRegA_31c(); |
| 178 | case k31i: return VRegA_31i(); |
| 179 | case k31t: return VRegA_31t(); |
| 180 | case k32x: return VRegA_32x(); |
Dragos Sbirlea | d25de7a | 2013-06-21 09:20:34 -0700 | [diff] [blame] | 181 | case k51l: return VRegA_51l(); |
Dragos Sbirlea | 8cc5162 | 2013-06-21 09:20:34 -0700 | [diff] [blame] | 182 | default: LOG(FATAL) << "Tried to access vA of instruction " << Name() << |
Dragos Sbirlea | d25de7a | 2013-06-21 09:20:34 -0700 | [diff] [blame] | 183 | " which has no A operand."; |
| 184 | } |
Dragos Sbirlea | 8cc5162 | 2013-06-21 09:20:34 -0700 | [diff] [blame] | 185 | return -1; |
Dragos Sbirlea | d25de7a | 2013-06-21 09:20:34 -0700 | [diff] [blame] | 186 | } |
| 187 | |
Dragos Sbirlea | 39f9927 | 2013-06-25 13:17:36 -0700 | [diff] [blame] | 188 | int32_t Instruction::GetTargetOffset() const { |
| 189 | switch (FormatOf(Opcode())) { |
| 190 | // Cases for conditional branches follow. |
| 191 | case k22t: return VRegC_22t(); |
| 192 | case k21t: return VRegB_21t(); |
| 193 | // Cases for unconditional branches follow. |
| 194 | case k10t: return VRegA_10t(); |
| 195 | case k20t: return VRegA_20t(); |
| 196 | case k30t: return VRegA_30t(); |
| 197 | default: LOG(FATAL) << "Tried to access the branch offset of an instruction " << Name() << |
| 198 | " which does not have a target operand."; |
| 199 | } |
| 200 | return 0; |
| 201 | } |
| 202 | |
| 203 | bool Instruction::CanFlowThrough() const { |
| 204 | const uint16_t* insns = reinterpret_cast<const uint16_t*>(this); |
| 205 | uint16_t insn = *insns; |
| 206 | Code opcode = static_cast<Code>(insn & 0xFF); |
| 207 | return FlagsOf(opcode) & Instruction::kContinue; |
| 208 | } |
| 209 | |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 210 | void Instruction::Decode(uint32_t &vA, uint32_t &vB, uint64_t &vB_wide, uint32_t &vC, uint32_t arg[]) const { |
| 211 | const uint16_t* insns = reinterpret_cast<const uint16_t*>(this); |
| 212 | uint16_t insn = *insns; |
Ian Rogers | a75a013 | 2012-09-28 11:41:42 -0700 | [diff] [blame] | 213 | Code opcode = static_cast<Code>(insn & 0xFF); |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 214 | |
Ian Rogers | a75a013 | 2012-09-28 11:41:42 -0700 | [diff] [blame] | 215 | switch (FormatOf(opcode)) { |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 216 | case k10x: // op |
| 217 | /* nothing to do; copy the AA bits out for the verifier */ |
| 218 | vA = INST_AA(insn); |
| 219 | break; |
| 220 | case k12x: // op vA, vB |
| 221 | vA = INST_A(insn); |
| 222 | vB = INST_B(insn); |
| 223 | break; |
| 224 | case k11n: // op vA, #+B |
| 225 | vA = INST_A(insn); |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 226 | vB = (int32_t) (INST_B(insn) << 28) >> 28; // sign extend 4-bit value |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 227 | break; |
| 228 | case k11x: // op vAA |
| 229 | vA = INST_AA(insn); |
| 230 | break; |
| 231 | case k10t: // op +AA |
| 232 | vA = (int8_t) INST_AA(insn); // sign-extend 8-bit value |
| 233 | break; |
| 234 | case k20t: // op +AAAA |
| 235 | vA = (int16_t) FETCH(1); // sign-extend 16-bit value |
| 236 | break; |
| 237 | case k21c: // op vAA, thing@BBBB |
| 238 | case k22x: // op vAA, vBBBB |
| 239 | vA = INST_AA(insn); |
| 240 | vB = FETCH(1); |
| 241 | break; |
| 242 | case k21s: // op vAA, #+BBBB |
| 243 | case k21t: // op vAA, +BBBB |
| 244 | vA = INST_AA(insn); |
| 245 | vB = (int16_t) FETCH(1); // sign-extend 16-bit value |
| 246 | break; |
| 247 | case k21h: // op vAA, #+BBBB0000[00000000] |
| 248 | vA = INST_AA(insn); |
| 249 | /* |
| 250 | * The value should be treated as right-zero-extended, but we don't |
| 251 | * actually do that here. Among other things, we don't know if it's |
| 252 | * the top bits of a 32- or 64-bit value. |
| 253 | */ |
| 254 | vB = FETCH(1); |
| 255 | break; |
| 256 | case k23x: // op vAA, vBB, vCC |
| 257 | vA = INST_AA(insn); |
| 258 | vB = FETCH(1) & 0xff; |
| 259 | vC = FETCH(1) >> 8; |
| 260 | break; |
| 261 | case k22b: // op vAA, vBB, #+CC |
| 262 | vA = INST_AA(insn); |
| 263 | vB = FETCH(1) & 0xff; |
| 264 | vC = (int8_t) (FETCH(1) >> 8); // sign-extend 8-bit value |
| 265 | break; |
| 266 | case k22s: // op vA, vB, #+CCCC |
| 267 | case k22t: // op vA, vB, +CCCC |
| 268 | vA = INST_A(insn); |
| 269 | vB = INST_B(insn); |
| 270 | vC = (int16_t) FETCH(1); // sign-extend 16-bit value |
| 271 | break; |
| 272 | case k22c: // op vA, vB, thing@CCCC |
| 273 | vA = INST_A(insn); |
| 274 | vB = INST_B(insn); |
| 275 | vC = FETCH(1); |
| 276 | break; |
| 277 | case k30t: // op +AAAAAAAA |
Sebastien Hertz | 807a256 | 2013-04-15 09:33:39 +0200 | [diff] [blame] | 278 | vA = FETCH_uint32(1); // signed 32-bit value |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 279 | break; |
| 280 | case k31t: // op vAA, +BBBBBBBB |
| 281 | case k31c: // op vAA, string@BBBBBBBB |
| 282 | vA = INST_AA(insn); |
Sebastien Hertz | 807a256 | 2013-04-15 09:33:39 +0200 | [diff] [blame] | 283 | vB = FETCH_uint32(1); // 32-bit value |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 284 | break; |
| 285 | case k32x: // op vAAAA, vBBBB |
| 286 | vA = FETCH(1); |
| 287 | vB = FETCH(2); |
| 288 | break; |
| 289 | case k31i: // op vAA, #+BBBBBBBB |
| 290 | vA = INST_AA(insn); |
Sebastien Hertz | 807a256 | 2013-04-15 09:33:39 +0200 | [diff] [blame] | 291 | vB = FETCH_uint32(1); // signed 32-bit value |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 292 | break; |
| 293 | case k35c: // op {vC, vD, vE, vF, vG}, thing@BBBB |
| 294 | { |
| 295 | /* |
| 296 | * Note that the fields mentioned in the spec don't appear in |
| 297 | * their "usual" positions here compared to most formats. This |
| 298 | * was done so that the field names for the argument count and |
| 299 | * reference index match between this format and the corresponding |
| 300 | * range formats (3rc and friends). |
| 301 | * |
| 302 | * Bottom line: The argument count is always in vA, and the |
| 303 | * method constant (or equivalent) is always in vB. |
| 304 | */ |
| 305 | uint16_t regList; |
| 306 | int count; |
| 307 | |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 308 | vA = INST_B(insn); // This is labeled A in the spec. |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 309 | vB = FETCH(1); |
| 310 | regList = FETCH(2); |
| 311 | |
| 312 | count = vA; |
| 313 | |
| 314 | /* |
| 315 | * Copy the argument registers into the arg[] array, and |
| 316 | * also copy the first argument (if any) into vC. (The |
| 317 | * DecodedInstruction structure doesn't have separate |
| 318 | * fields for {vD, vE, vF, vG}, so there's no need to make |
| 319 | * copies of those.) Note that cases 5..2 fall through. |
| 320 | */ |
| 321 | switch (count) { |
| 322 | case 5: arg[4] = INST_A(insn); |
| 323 | case 4: arg[3] = (regList >> 12) & 0x0f; |
| 324 | case 3: arg[2] = (regList >> 8) & 0x0f; |
| 325 | case 2: arg[1] = (regList >> 4) & 0x0f; |
| 326 | case 1: vC = arg[0] = regList & 0x0f; break; |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 327 | case 0: break; // Valid, but no need to do anything. |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 328 | default: |
| 329 | LOG(ERROR) << "Invalid arg count in 35c (" << count << ")"; |
| 330 | return; |
| 331 | } |
| 332 | } |
| 333 | break; |
| 334 | case k3rc: // op {vCCCC .. v(CCCC+AA-1)}, meth@BBBB |
| 335 | vA = INST_AA(insn); |
| 336 | vB = FETCH(1); |
| 337 | vC = FETCH(2); |
| 338 | break; |
| 339 | case k51l: // op vAA, #+BBBBBBBBBBBBBBBB |
| 340 | vA = INST_AA(insn); |
Sebastien Hertz | 807a256 | 2013-04-15 09:33:39 +0200 | [diff] [blame] | 341 | vB_wide = FETCH_uint32(1) | ((uint64_t) FETCH_uint32(3) << 32); |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 342 | break; |
| 343 | default: |
Ian Rogers | a75a013 | 2012-09-28 11:41:42 -0700 | [diff] [blame] | 344 | LOG(ERROR) << "Can't decode unexpected format " << FormatOf(opcode) << " (op=" << opcode << ")"; |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 345 | return; |
| 346 | } |
| 347 | } |
| 348 | |
Ian Rogers | a75a013 | 2012-09-28 11:41:42 -0700 | [diff] [blame] | 349 | size_t Instruction::SizeInCodeUnitsComplexOpcode() const { |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 350 | const uint16_t* insns = reinterpret_cast<const uint16_t*>(this); |
Ian Rogers | a75a013 | 2012-09-28 11:41:42 -0700 | [diff] [blame] | 351 | // Handle special NOP encoded variable length sequences. |
| 352 | switch (*insns) { |
| 353 | case kPackedSwitchSignature: |
| 354 | return (4 + insns[1] * 2); |
| 355 | case kSparseSwitchSignature: |
| 356 | return (2 + insns[1] * 4); |
| 357 | case kArrayDataSignature: { |
| 358 | uint16_t element_size = insns[1]; |
| 359 | uint32_t length = insns[2] | (((uint32_t)insns[3]) << 16); |
| 360 | // The plus 1 is to round up for odd size and width. |
| 361 | return (4 + (element_size * length + 1) / 2); |
Carl Shapiro | e4c1ce4 | 2011-07-09 02:31:57 -0700 | [diff] [blame] | 362 | } |
Ian Rogers | a75a013 | 2012-09-28 11:41:42 -0700 | [diff] [blame] | 363 | default: |
| 364 | if ((*insns & 0xFF) == 0) { |
| 365 | return 1; // NOP. |
| 366 | } else { |
| 367 | LOG(FATAL) << "Unreachable: " << DumpString(NULL); |
| 368 | return 0; |
| 369 | } |
Carl Shapiro | e4c1ce4 | 2011-07-09 02:31:57 -0700 | [diff] [blame] | 370 | } |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 371 | } |
| 372 | |
Ian Rogers | 2c8a857 | 2011-10-24 17:11:36 -0700 | [diff] [blame] | 373 | std::string Instruction::DumpHex(size_t code_units) const { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 374 | size_t inst_length = SizeInCodeUnits(); |
| 375 | if (inst_length > code_units) { |
| 376 | inst_length = code_units; |
| 377 | } |
Ian Rogers | 2c8a857 | 2011-10-24 17:11:36 -0700 | [diff] [blame] | 378 | std::ostringstream os; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 379 | const uint16_t* insn = reinterpret_cast<const uint16_t*>(this); |
| 380 | for (size_t i = 0; i < inst_length; i++) { |
Ian Rogers | 2c8a857 | 2011-10-24 17:11:36 -0700 | [diff] [blame] | 381 | os << StringPrintf("0x%04x", insn[i]) << " "; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 382 | } |
| 383 | for (size_t i = inst_length; i < code_units; i++) { |
| 384 | os << " "; |
| 385 | } |
Ian Rogers | 2c8a857 | 2011-10-24 17:11:36 -0700 | [diff] [blame] | 386 | return os.str(); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 387 | } |
| 388 | |
Ian Rogers | 2c8a857 | 2011-10-24 17:11:36 -0700 | [diff] [blame] | 389 | std::string Instruction::DumpString(const DexFile* file) const { |
Ian Rogers | 2c8a857 | 2011-10-24 17:11:36 -0700 | [diff] [blame] | 390 | std::ostringstream os; |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 391 | const char* opcode = kInstructionNames[Opcode()]; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 392 | switch (FormatOf(Opcode())) { |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 393 | case k10x: os << opcode; break; |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 394 | case k12x: os << StringPrintf("%s v%d, v%d", opcode, VRegA_12x(), VRegB_12x()); break; |
| 395 | case k11n: os << StringPrintf("%s v%d, #%+d", opcode, VRegA_11n(), VRegB_11n()); break; |
| 396 | case k11x: os << StringPrintf("%s v%d", opcode, VRegA_11x()); break; |
| 397 | case k10t: os << StringPrintf("%s %+d", opcode, VRegA_10t()); break; |
| 398 | case k20t: os << StringPrintf("%s %+d", opcode, VRegA_20t()); break; |
| 399 | case k22x: os << StringPrintf("%s v%d, v%d", opcode, VRegA_22x(), VRegB_22x()); break; |
| 400 | case k21t: os << StringPrintf("%s v%d, %+d", opcode, VRegA_21t(), VRegB_21t()); break; |
| 401 | 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] | 402 | case k21h: { |
| 403 | // op vAA, #+BBBB0000[00000000] |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 404 | if (Opcode() == CONST_HIGH16) { |
| 405 | uint32_t value = VRegB_21h() << 16; |
| 406 | 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] | 407 | } else { |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 408 | uint64_t value = static_cast<uint64_t>(VRegB_21h()) << 48; |
Ian Rogers | b574c18 | 2014-01-23 19:51:19 -0800 | [diff] [blame] | 409 | os << StringPrintf("%s v%d, #long %+" PRId64 " // 0x%" PRIx64, opcode, VRegA_21h(), |
| 410 | value, value); |
Elliott Hughes | 1b3d6ca | 2012-04-25 13:00:14 -0700 | [diff] [blame] | 411 | } |
| 412 | } |
| 413 | break; |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 414 | case k21c: { |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 415 | switch (Opcode()) { |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 416 | case CONST_STRING: |
| 417 | if (file != NULL) { |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 418 | uint32_t string_idx = VRegB_21c(); |
| 419 | os << StringPrintf("const-string v%d, %s // string@%d", VRegA_21c(), |
| 420 | PrintableString(file->StringDataByIdx(string_idx)).c_str(), string_idx); |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 421 | break; |
| 422 | } // else fall-through |
Mathieu Chartier | 18c24b6 | 2012-09-10 08:54:25 -0700 | [diff] [blame] | 423 | case CHECK_CAST: |
| 424 | case CONST_CLASS: |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 425 | case NEW_INSTANCE: |
| 426 | if (file != NULL) { |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 427 | uint32_t type_idx = VRegB_21c(); |
Dragos Sbirlea | b43cef3 | 2013-05-23 11:59:20 -0700 | [diff] [blame] | 428 | os << opcode << " v" << static_cast<int>(VRegA_21c()) << ", " << PrettyType(type_idx, *file) |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 429 | << " // type@" << type_idx; |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 430 | break; |
| 431 | } // else fall-through |
| 432 | case SGET: |
| 433 | case SGET_WIDE: |
| 434 | case SGET_OBJECT: |
| 435 | case SGET_BOOLEAN: |
| 436 | case SGET_BYTE: |
| 437 | case SGET_CHAR: |
| 438 | case SGET_SHORT: |
| 439 | if (file != NULL) { |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 440 | uint32_t field_idx = VRegB_21c(); |
Dragos Sbirlea | b43cef3 | 2013-05-23 11:59:20 -0700 | [diff] [blame] | 441 | 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] | 442 | << " // field@" << field_idx; |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 443 | break; |
| 444 | } // else fall-through |
| 445 | case SPUT: |
| 446 | case SPUT_WIDE: |
| 447 | case SPUT_OBJECT: |
| 448 | case SPUT_BOOLEAN: |
| 449 | case SPUT_BYTE: |
| 450 | case SPUT_CHAR: |
| 451 | case SPUT_SHORT: |
| 452 | if (file != NULL) { |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 453 | uint32_t field_idx = VRegB_21c(); |
Dragos Sbirlea | b43cef3 | 2013-05-23 11:59:20 -0700 | [diff] [blame] | 454 | 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] | 455 | << " // field@" << field_idx; |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 456 | break; |
| 457 | } // else fall-through |
| 458 | default: |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 459 | os << StringPrintf("%s v%d, thing@%d", opcode, VRegA_21c(), VRegB_21c()); |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 460 | break; |
| 461 | } |
| 462 | break; |
| 463 | } |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 464 | case k23x: os << StringPrintf("%s v%d, v%d, v%d", opcode, VRegA_23x(), VRegB_23x(), VRegC_23x()); break; |
| 465 | case k22b: os << StringPrintf("%s v%d, v%d, #%+d", opcode, VRegA_22b(), VRegB_22b(), VRegC_22b()); break; |
| 466 | case k22t: os << StringPrintf("%s v%d, v%d, %+d", opcode, VRegA_22t(), VRegB_22t(), VRegC_22t()); break; |
| 467 | 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] | 468 | case k22c: { |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 469 | switch (Opcode()) { |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 470 | case IGET: |
| 471 | case IGET_WIDE: |
| 472 | case IGET_OBJECT: |
| 473 | case IGET_BOOLEAN: |
| 474 | case IGET_BYTE: |
| 475 | case IGET_CHAR: |
| 476 | case IGET_SHORT: |
| 477 | if (file != NULL) { |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 478 | uint32_t field_idx = VRegC_22c(); |
Dragos Sbirlea | b43cef3 | 2013-05-23 11:59:20 -0700 | [diff] [blame] | 479 | 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] | 480 | << PrettyField(field_idx, *file, true) << " // field@" << field_idx; |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 481 | break; |
| 482 | } // else fall-through |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 483 | case IGET_QUICK: |
| 484 | case IGET_OBJECT_QUICK: |
| 485 | if (file != NULL) { |
| 486 | uint32_t field_idx = VRegC_22c(); |
| 487 | os << opcode << " v" << static_cast<int>(VRegA_22c()) << ", v" << static_cast<int>(VRegB_22c()) << ", " |
| 488 | << "// offset@" << field_idx; |
| 489 | break; |
| 490 | } // else fall-through |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 491 | case IPUT: |
| 492 | case IPUT_WIDE: |
| 493 | case IPUT_OBJECT: |
| 494 | case IPUT_BOOLEAN: |
| 495 | case IPUT_BYTE: |
| 496 | case IPUT_CHAR: |
| 497 | case IPUT_SHORT: |
| 498 | if (file != NULL) { |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 499 | uint32_t field_idx = VRegC_22c(); |
Dragos Sbirlea | b43cef3 | 2013-05-23 11:59:20 -0700 | [diff] [blame] | 500 | 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] | 501 | << PrettyField(field_idx, *file, true) << " // field@" << field_idx; |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 502 | break; |
| 503 | } // else fall-through |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 504 | case IPUT_QUICK: |
| 505 | case IPUT_OBJECT_QUICK: |
| 506 | if (file != NULL) { |
| 507 | uint32_t field_idx = VRegC_22c(); |
| 508 | os << opcode << " v" << static_cast<int>(VRegA_22c()) << ", v" << static_cast<int>(VRegB_22c()) << ", " |
| 509 | << "// offset@" << field_idx; |
| 510 | break; |
| 511 | } // else fall-through |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 512 | case INSTANCE_OF: |
| 513 | if (file != NULL) { |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 514 | uint32_t type_idx = VRegC_22c(); |
Dragos Sbirlea | d4e868a | 2013-05-23 09:44:17 -0700 | [diff] [blame] | 515 | 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] | 516 | << PrettyType(type_idx, *file) << " // type@" << type_idx; |
Mathieu Chartier | 18c24b6 | 2012-09-10 08:54:25 -0700 | [diff] [blame] | 517 | break; |
| 518 | } |
| 519 | case NEW_ARRAY: |
| 520 | if (file != NULL) { |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 521 | uint32_t type_idx = VRegC_22c(); |
Dragos Sbirlea | b43cef3 | 2013-05-23 11:59:20 -0700 | [diff] [blame] | 522 | 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] | 523 | << PrettyType(type_idx, *file) << " // type@" << type_idx; |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 524 | break; |
| 525 | } // else fall-through |
| 526 | default: |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 527 | 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] | 528 | break; |
| 529 | } |
| 530 | break; |
| 531 | } |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 532 | case k32x: os << StringPrintf("%s v%d, v%d", opcode, VRegA_32x(), VRegB_32x()); break; |
| 533 | case k30t: os << StringPrintf("%s %+d", opcode, VRegA_30t()); break; |
| 534 | case k31t: os << StringPrintf("%s v%d, %+d", opcode, VRegA_31t(), VRegB_31t()); break; |
| 535 | case k31i: os << StringPrintf("%s v%d, #%+d", opcode, VRegA_31i(), VRegB_31i()); break; |
Ian Rogers | 7dfb28c | 2013-08-22 08:18:36 -0700 | [diff] [blame] | 536 | case k31c: |
| 537 | if (Opcode() == CONST_STRING_JUMBO) { |
| 538 | uint32_t string_idx = VRegB_31c(); |
| 539 | if (file != NULL) { |
| 540 | os << StringPrintf("%s v%d, %s // string@%d", opcode, VRegA_31c(), |
| 541 | PrintableString(file->StringDataByIdx(string_idx)).c_str(), |
| 542 | string_idx); |
| 543 | } else { |
| 544 | os << StringPrintf("%s v%d, string@%d", opcode, VRegA_31c(), string_idx); |
| 545 | } |
| 546 | } else { |
| 547 | os << StringPrintf("%s v%d, thing@%d", opcode, VRegA_31c(), VRegB_31c()); break; |
| 548 | } |
| 549 | break; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 550 | case k35c: { |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 551 | uint32_t arg[5]; |
| 552 | GetArgs(arg); |
| 553 | switch (Opcode()) { |
Andreas Gampe | 7aca91d | 2014-03-31 18:10:53 -0700 | [diff] [blame^] | 554 | case FILLED_NEW_ARRAY: |
| 555 | { |
| 556 | const int32_t a = VRegA_35c(); |
| 557 | os << opcode << " {"; |
| 558 | for (int i = 0; i < a; ++i) { |
| 559 | if (i > 0) { |
| 560 | os << ", "; |
| 561 | } |
| 562 | os << "v" << arg[i]; |
| 563 | } |
| 564 | os << "}, type@" << VRegB_35c(); |
| 565 | } |
| 566 | break; |
| 567 | |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 568 | case INVOKE_VIRTUAL: |
| 569 | case INVOKE_SUPER: |
| 570 | case INVOKE_DIRECT: |
| 571 | case INVOKE_STATIC: |
| 572 | case INVOKE_INTERFACE: |
| 573 | if (file != NULL) { |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 574 | os << opcode << " {"; |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 575 | uint32_t method_idx = VRegB_35c(); |
| 576 | for (size_t i = 0; i < VRegA_35c(); ++i) { |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 577 | if (i != 0) { |
| 578 | os << ", "; |
| 579 | } |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 580 | os << "v" << arg[i]; |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 581 | } |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 582 | os << "}, " << PrettyMethod(method_idx, *file) << " // method@" << method_idx; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 583 | break; |
| 584 | } // else fall-through |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 585 | case INVOKE_VIRTUAL_QUICK: |
| 586 | if (file != NULL) { |
| 587 | os << opcode << " {"; |
| 588 | uint32_t method_idx = VRegB_35c(); |
| 589 | for (size_t i = 0; i < VRegA_35c(); ++i) { |
| 590 | if (i != 0) { |
| 591 | os << ", "; |
| 592 | } |
| 593 | os << "v" << arg[i]; |
| 594 | } |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 595 | os << "}, // vtable@" << method_idx; |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 596 | break; |
| 597 | } // else fall-through |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 598 | default: |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 599 | os << opcode << " {v" << arg[0] << ", v" << arg[1] << ", v" << arg[2] |
| 600 | << ", v" << arg[3] << ", v" << arg[4] << "}, thing@" << VRegB_35c(); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 601 | break; |
| 602 | } |
| 603 | break; |
| 604 | } |
Ian Rogers | 4c5dd5a | 2012-09-07 11:27:28 -0700 | [diff] [blame] | 605 | case k3rc: { |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 606 | switch (Opcode()) { |
Ian Rogers | 4c5dd5a | 2012-09-07 11:27:28 -0700 | [diff] [blame] | 607 | case INVOKE_VIRTUAL_RANGE: |
| 608 | case INVOKE_SUPER_RANGE: |
| 609 | case INVOKE_DIRECT_RANGE: |
| 610 | case INVOKE_STATIC_RANGE: |
| 611 | case INVOKE_INTERFACE_RANGE: |
| 612 | if (file != NULL) { |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 613 | uint32_t method_idx = VRegB_3rc(); |
| 614 | os << StringPrintf("%s, {v%d .. v%d}, ", opcode, VRegC_3rc(), (VRegC_3rc() + VRegA_3rc() - 1)) |
| 615 | << PrettyMethod(method_idx, *file) << " // method@" << method_idx; |
Ian Rogers | 4c5dd5a | 2012-09-07 11:27:28 -0700 | [diff] [blame] | 616 | break; |
| 617 | } // else fall-through |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 618 | case INVOKE_VIRTUAL_RANGE_QUICK: |
| 619 | if (file != NULL) { |
| 620 | uint32_t method_idx = VRegB_3rc(); |
| 621 | os << StringPrintf("%s, {v%d .. v%d}, ", opcode, VRegC_3rc(), (VRegC_3rc() + VRegA_3rc() - 1)) |
| 622 | << "// vtable@" << method_idx; |
| 623 | break; |
| 624 | } // else fall-through |
Ian Rogers | 4c5dd5a | 2012-09-07 11:27:28 -0700 | [diff] [blame] | 625 | default: |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 626 | os << StringPrintf("%s, {v%d .. v%d}, thing@%d", opcode, VRegC_3rc(), |
| 627 | (VRegC_3rc() + VRegA_3rc() - 1), VRegB_3rc()); |
Ian Rogers | 4c5dd5a | 2012-09-07 11:27:28 -0700 | [diff] [blame] | 628 | break; |
| 629 | } |
| 630 | break; |
| 631 | } |
Ian Rogers | b574c18 | 2014-01-23 19:51:19 -0800 | [diff] [blame] | 632 | case k51l: os << StringPrintf("%s v%d, #%+" PRId64, opcode, VRegA_51l(), VRegB_51l()); break; |
Ian Rogers | 2c8a857 | 2011-10-24 17:11:36 -0700 | [diff] [blame] | 633 | default: os << " unknown format (" << DumpHex(5) << ")"; break; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 634 | } |
Ian Rogers | 2c8a857 | 2011-10-24 17:11:36 -0700 | [diff] [blame] | 635 | return os.str(); |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 636 | } |
| 637 | |
Ian Rogers | a75a013 | 2012-09-28 11:41:42 -0700 | [diff] [blame] | 638 | std::ostream& operator<<(std::ostream& os, const Instruction::Code& code) { |
| 639 | return os << Instruction::Name(code); |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 640 | } |
| 641 | |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 642 | } // namespace art |