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 | |
| 56 | /* |
| 57 | * Handy macros for helping decode instructions. |
| 58 | */ |
| 59 | #define FETCH(_offset) (insns[(_offset)]) |
| 60 | #define FETCH_u4(_offset) (fetch_u4_impl((_offset), insns)) |
| 61 | #define INST_A(_insn) (((uint16_t)(_insn) >> 8) & 0x0f) |
| 62 | #define INST_B(_insn) ((uint16_t)(_insn) >> 12) |
| 63 | #define INST_AA(_insn) ((_insn) >> 8) |
| 64 | |
| 65 | /* Helper for FETCH_u4, above. */ |
| 66 | static inline uint32_t fetch_u4_impl(uint32_t offset, const uint16_t* insns) { |
| 67 | return insns[offset] | ((uint32_t) insns[offset+1] << 16); |
| 68 | } |
| 69 | |
| 70 | void Instruction::Decode(uint32_t &vA, uint32_t &vB, uint64_t &vB_wide, uint32_t &vC, uint32_t arg[]) const { |
| 71 | const uint16_t* insns = reinterpret_cast<const uint16_t*>(this); |
| 72 | uint16_t insn = *insns; |
| 73 | int opcode = insn & 0xFF; |
| 74 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 75 | switch (FormatOf(Opcode())) { |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 76 | case k10x: // op |
| 77 | /* nothing to do; copy the AA bits out for the verifier */ |
| 78 | vA = INST_AA(insn); |
| 79 | break; |
| 80 | case k12x: // op vA, vB |
| 81 | vA = INST_A(insn); |
| 82 | vB = INST_B(insn); |
| 83 | break; |
| 84 | case k11n: // op vA, #+B |
| 85 | vA = INST_A(insn); |
| 86 | vB = (int32_t) (INST_B(insn) << 28) >> 28; // sign extend 4-bit value |
| 87 | break; |
| 88 | case k11x: // op vAA |
| 89 | vA = INST_AA(insn); |
| 90 | break; |
| 91 | case k10t: // op +AA |
| 92 | vA = (int8_t) INST_AA(insn); // sign-extend 8-bit value |
| 93 | break; |
| 94 | case k20t: // op +AAAA |
| 95 | vA = (int16_t) FETCH(1); // sign-extend 16-bit value |
| 96 | break; |
jeffhao | cfe8db4 | 2012-03-13 12:37:36 -0700 | [diff] [blame] | 97 | case k20bc: // op AA, kind@BBBB |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 98 | case k21c: // op vAA, thing@BBBB |
| 99 | case k22x: // op vAA, vBBBB |
| 100 | vA = INST_AA(insn); |
| 101 | vB = FETCH(1); |
| 102 | break; |
| 103 | case k21s: // op vAA, #+BBBB |
| 104 | case k21t: // op vAA, +BBBB |
| 105 | vA = INST_AA(insn); |
| 106 | vB = (int16_t) FETCH(1); // sign-extend 16-bit value |
| 107 | break; |
| 108 | case k21h: // op vAA, #+BBBB0000[00000000] |
| 109 | vA = INST_AA(insn); |
| 110 | /* |
| 111 | * The value should be treated as right-zero-extended, but we don't |
| 112 | * actually do that here. Among other things, we don't know if it's |
| 113 | * the top bits of a 32- or 64-bit value. |
| 114 | */ |
| 115 | vB = FETCH(1); |
| 116 | break; |
| 117 | case k23x: // op vAA, vBB, vCC |
| 118 | vA = INST_AA(insn); |
| 119 | vB = FETCH(1) & 0xff; |
| 120 | vC = FETCH(1) >> 8; |
| 121 | break; |
| 122 | case k22b: // op vAA, vBB, #+CC |
| 123 | vA = INST_AA(insn); |
| 124 | vB = FETCH(1) & 0xff; |
| 125 | vC = (int8_t) (FETCH(1) >> 8); // sign-extend 8-bit value |
| 126 | break; |
| 127 | case k22s: // op vA, vB, #+CCCC |
| 128 | case k22t: // op vA, vB, +CCCC |
| 129 | vA = INST_A(insn); |
| 130 | vB = INST_B(insn); |
| 131 | vC = (int16_t) FETCH(1); // sign-extend 16-bit value |
| 132 | break; |
| 133 | case k22c: // op vA, vB, thing@CCCC |
| 134 | vA = INST_A(insn); |
| 135 | vB = INST_B(insn); |
| 136 | vC = FETCH(1); |
| 137 | break; |
| 138 | case k30t: // op +AAAAAAAA |
| 139 | vA = FETCH_u4(1); // signed 32-bit value |
| 140 | break; |
| 141 | case k31t: // op vAA, +BBBBBBBB |
| 142 | case k31c: // op vAA, string@BBBBBBBB |
| 143 | vA = INST_AA(insn); |
| 144 | vB = FETCH_u4(1); // 32-bit value |
| 145 | break; |
| 146 | case k32x: // op vAAAA, vBBBB |
| 147 | vA = FETCH(1); |
| 148 | vB = FETCH(2); |
| 149 | break; |
| 150 | case k31i: // op vAA, #+BBBBBBBB |
| 151 | vA = INST_AA(insn); |
| 152 | vB = FETCH_u4(1); // signed 32-bit value |
| 153 | break; |
| 154 | case k35c: // op {vC, vD, vE, vF, vG}, thing@BBBB |
| 155 | { |
| 156 | /* |
| 157 | * Note that the fields mentioned in the spec don't appear in |
| 158 | * their "usual" positions here compared to most formats. This |
| 159 | * was done so that the field names for the argument count and |
| 160 | * reference index match between this format and the corresponding |
| 161 | * range formats (3rc and friends). |
| 162 | * |
| 163 | * Bottom line: The argument count is always in vA, and the |
| 164 | * method constant (or equivalent) is always in vB. |
| 165 | */ |
| 166 | uint16_t regList; |
| 167 | int count; |
| 168 | |
| 169 | vA = INST_B(insn); // This is labeled A in the spec. |
| 170 | vB = FETCH(1); |
| 171 | regList = FETCH(2); |
| 172 | |
| 173 | count = vA; |
| 174 | |
| 175 | /* |
| 176 | * Copy the argument registers into the arg[] array, and |
| 177 | * also copy the first argument (if any) into vC. (The |
| 178 | * DecodedInstruction structure doesn't have separate |
| 179 | * fields for {vD, vE, vF, vG}, so there's no need to make |
| 180 | * copies of those.) Note that cases 5..2 fall through. |
| 181 | */ |
| 182 | switch (count) { |
| 183 | case 5: arg[4] = INST_A(insn); |
| 184 | case 4: arg[3] = (regList >> 12) & 0x0f; |
| 185 | case 3: arg[2] = (regList >> 8) & 0x0f; |
| 186 | case 2: arg[1] = (regList >> 4) & 0x0f; |
| 187 | case 1: vC = arg[0] = regList & 0x0f; break; |
| 188 | case 0: break; // Valid, but no need to do anything. |
| 189 | default: |
| 190 | LOG(ERROR) << "Invalid arg count in 35c (" << count << ")"; |
| 191 | return; |
| 192 | } |
| 193 | } |
| 194 | break; |
| 195 | case k3rc: // op {vCCCC .. v(CCCC+AA-1)}, meth@BBBB |
| 196 | vA = INST_AA(insn); |
| 197 | vB = FETCH(1); |
| 198 | vC = FETCH(2); |
| 199 | break; |
| 200 | case k51l: // op vAA, #+BBBBBBBBBBBBBBBB |
| 201 | vA = INST_AA(insn); |
| 202 | vB_wide = FETCH_u4(1) | ((uint64_t) FETCH_u4(3) << 32); |
| 203 | break; |
| 204 | default: |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 205 | LOG(ERROR) << "Can't decode unexpected format " << static_cast<int>(FormatOf(Opcode())) << " (op=" << opcode << ")"; |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 206 | return; |
| 207 | } |
| 208 | } |
| 209 | |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 210 | size_t Instruction::SizeInCodeUnits() const { |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 211 | const uint16_t* insns = reinterpret_cast<const uint16_t*>(this); |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 212 | if (*insns == Instruction::kPackedSwitchSignature) { |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 213 | return (4 + insns[1] * 2); |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 214 | } else if (*insns == Instruction::kSparseSwitchSignature) { |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 215 | return (2 + insns[1] * 4); |
Carl Shapiro | e4c1ce4 | 2011-07-09 02:31:57 -0700 | [diff] [blame] | 216 | } else if (*insns == kArrayDataSignature) { |
| 217 | uint16_t element_size = insns[1]; |
| 218 | uint32_t length = insns[2] | (((uint32_t)insns[3]) << 16); |
| 219 | // The plus 1 is to round up for odd size and width. |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 220 | return (4 + (element_size * length + 1) / 2); |
Carl Shapiro | e4c1ce4 | 2011-07-09 02:31:57 -0700 | [diff] [blame] | 221 | } else { |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 222 | switch (FormatOf(Opcode())) { |
Carl Shapiro | e4c1ce4 | 2011-07-09 02:31:57 -0700 | [diff] [blame] | 223 | case k10x: |
| 224 | case k12x: |
| 225 | case k11n: |
| 226 | case k11x: |
| 227 | case k10t: |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 228 | return 1; |
Ian Rogers | 9fdfc18 | 2011-10-26 23:12:52 -0700 | [diff] [blame] | 229 | case k20bc: |
Carl Shapiro | e4c1ce4 | 2011-07-09 02:31:57 -0700 | [diff] [blame] | 230 | case k20t: |
| 231 | case k22x: |
| 232 | case k21t: |
| 233 | case k21s: |
| 234 | case k21h: |
| 235 | case k21c: |
| 236 | case k23x: |
| 237 | case k22b: |
| 238 | case k22t: |
| 239 | case k22s: |
| 240 | case k22c: |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 241 | return 2; |
Carl Shapiro | e4c1ce4 | 2011-07-09 02:31:57 -0700 | [diff] [blame] | 242 | case k32x: |
| 243 | case k30t: |
| 244 | case k31t: |
| 245 | case k31i: |
| 246 | case k31c: |
| 247 | case k35c: |
| 248 | case k3rc: |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 249 | return 3; |
Carl Shapiro | e4c1ce4 | 2011-07-09 02:31:57 -0700 | [diff] [blame] | 250 | case k51l: |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 251 | return 5; |
Carl Shapiro | e4c1ce4 | 2011-07-09 02:31:57 -0700 | [diff] [blame] | 252 | default: |
| 253 | LOG(FATAL) << "Unreachable"; |
| 254 | } |
| 255 | } |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 256 | return 0; |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Carl Shapiro | e4c1ce4 | 2011-07-09 02:31:57 -0700 | [diff] [blame] | 259 | Instruction::Code Instruction::Opcode() const { |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 260 | const uint16_t* insns = reinterpret_cast<const uint16_t*>(this); |
Carl Shapiro | e4c1ce4 | 2011-07-09 02:31:57 -0700 | [diff] [blame] | 261 | int opcode = *insns & 0xFF; |
| 262 | return static_cast<Code>(opcode); |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 263 | } |
| 264 | |
Carl Shapiro | e4c1ce4 | 2011-07-09 02:31:57 -0700 | [diff] [blame] | 265 | const Instruction* Instruction::Next() const { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 266 | size_t current_size_in_bytes = SizeInCodeUnits() * sizeof(uint16_t); |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 267 | const uint8_t* ptr = reinterpret_cast<const uint8_t*>(this); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 268 | return reinterpret_cast<const Instruction*>(ptr + current_size_in_bytes); |
| 269 | } |
| 270 | |
Ian Rogers | 2c8a857 | 2011-10-24 17:11:36 -0700 | [diff] [blame] | 271 | std::string Instruction::DumpHex(size_t code_units) const { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 272 | size_t inst_length = SizeInCodeUnits(); |
| 273 | if (inst_length > code_units) { |
| 274 | inst_length = code_units; |
| 275 | } |
Ian Rogers | 2c8a857 | 2011-10-24 17:11:36 -0700 | [diff] [blame] | 276 | std::ostringstream os; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 277 | const uint16_t* insn = reinterpret_cast<const uint16_t*>(this); |
| 278 | for (size_t i = 0; i < inst_length; i++) { |
Ian Rogers | 2c8a857 | 2011-10-24 17:11:36 -0700 | [diff] [blame] | 279 | os << StringPrintf("0x%04x", insn[i]) << " "; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 280 | } |
| 281 | for (size_t i = inst_length; i < code_units; i++) { |
| 282 | os << " "; |
| 283 | } |
Ian Rogers | 2c8a857 | 2011-10-24 17:11:36 -0700 | [diff] [blame] | 284 | return os.str(); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 285 | } |
| 286 | |
Ian Rogers | 2c8a857 | 2011-10-24 17:11:36 -0700 | [diff] [blame] | 287 | std::string Instruction::DumpString(const DexFile* file) const { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 288 | DecodedInstruction insn(this); |
Ian Rogers | 2c8a857 | 2011-10-24 17:11:36 -0700 | [diff] [blame] | 289 | std::ostringstream os; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 290 | const char* opcode = kInstructionNames[insn.opcode]; |
| 291 | switch (FormatOf(Opcode())) { |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 292 | case k10x: os << opcode; break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 293 | case k12x: os << StringPrintf("%s v%d, v%d", opcode, insn.vA, insn.vB); break; |
| 294 | case k11n: os << StringPrintf("%s v%d, #%+d", opcode, insn.vA, insn.vB); break; |
| 295 | case k11x: os << StringPrintf("%s v%d", opcode, insn.vA); break; |
| 296 | case k10t: os << StringPrintf("%s %+d", opcode, insn.vA); break; |
| 297 | case k20bc: os << StringPrintf("%s %d, kind@%d", opcode, insn.vA, insn.vB); break; |
| 298 | case k20t: os << StringPrintf("%s %+d", opcode, insn.vA); break; |
| 299 | case k22x: os << StringPrintf("%s v%d, v%d", opcode, insn.vA, insn.vB); break; |
| 300 | case k21t: os << StringPrintf("%s v%d, %+d", opcode, insn.vA, insn.vB); break; |
| 301 | case k21s: os << StringPrintf("%s v%d, #%+d", opcode, insn.vA, insn.vB); break; |
| 302 | case k21h: os << StringPrintf("%s v%d, #%+d00000[00000000]", opcode, insn.vA, insn.vB); break; |
| 303 | case k21c: os << StringPrintf("%s v%d, thing@%d", opcode, insn.vA, insn.vB); break; |
| 304 | case k23x: os << StringPrintf("%s v%d, v%d, v%d", opcode, insn.vA, insn.vB, insn.vC); break; |
| 305 | case k22b: os << StringPrintf("%s v%d, v%d, #%+d", opcode, insn.vA, insn.vB, insn.vC); break; |
| 306 | case k22t: os << StringPrintf("%s v%d, v%d, %+d", opcode, insn.vA, insn.vB, insn.vC); break; |
| 307 | case k22s: os << StringPrintf("%s v%d, v%d, #%+d", opcode, insn.vA, insn.vB, insn.vC); break; |
| 308 | case k22c: os << StringPrintf("%s v%d, v%d, thing@%d", opcode, insn.vA, insn.vB, insn.vC); break; |
| 309 | case k32x: os << StringPrintf("%s v%d, v%d", opcode, insn.vA, insn.vB); break; |
| 310 | case k30t: os << StringPrintf("%s %+d", opcode, insn.vA); break; |
| 311 | case k31t: os << StringPrintf("%s v%d, %+d", opcode, insn.vA, insn.vB); break; |
| 312 | case k31i: os << StringPrintf("%s v%d, #%+d", opcode, insn.vA, insn.vB); break; |
| 313 | 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] | 314 | case k35c: { |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 315 | switch (insn.opcode) { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 316 | case INVOKE_VIRTUAL: |
| 317 | case INVOKE_SUPER: |
| 318 | case INVOKE_DIRECT: |
| 319 | case INVOKE_STATIC: |
| 320 | case INVOKE_INTERFACE: |
| 321 | if (file != NULL) { |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 322 | const DexFile::MethodId& meth_id = file->GetMethodId(insn.vB); |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 323 | os << opcode << " {"; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 324 | for (size_t i = 0; i < insn.vA; ++i) { |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 325 | if (i != 0) { |
| 326 | os << ", "; |
| 327 | } |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 328 | os << "v" << insn.arg[i]; |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 329 | } |
| 330 | os << "}, " |
| 331 | << file->GetMethodDeclaringClassDescriptor(meth_id) << "." |
| 332 | << file->GetMethodName(meth_id) << file->GetMethodSignature(meth_id) |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 333 | << " // method@" << insn.vB; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 334 | break; |
| 335 | } // else fall-through |
| 336 | default: |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 337 | os << opcode << " {v" << insn.arg[0] << ", v" << insn.arg[1] << ", v" << insn.arg[2] |
| 338 | << ", v" << insn.arg[3] << ", v" << insn.arg[4] << "}, thing@" << insn.vB; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 339 | break; |
| 340 | } |
| 341 | break; |
| 342 | } |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 343 | case k3rc: os << StringPrintf("%s, {v%d .. v%d}, method@%d", opcode, insn.vC, (insn.vC + insn.vA - 1), insn.vB); break; |
| 344 | 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] | 345 | default: os << " unknown format (" << DumpHex(5) << ")"; break; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 346 | } |
Ian Rogers | 2c8a857 | 2011-10-24 17:11:36 -0700 | [diff] [blame] | 347 | return os.str(); |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 348 | } |
| 349 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 350 | DecodedInstruction::DecodedInstruction(const Instruction* inst) { |
| 351 | inst->Decode(vA, vB, vB_wide, vC, arg); |
| 352 | opcode = inst->Opcode(); |
| 353 | } |
| 354 | |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 355 | } // namespace art |