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 | |
Dragos Sbirlea | 39f9927 | 2013-06-25 13:17:36 -0700 | [diff] [blame] | 73 | int32_t Instruction::GetTargetOffset() const { |
| 74 | switch (FormatOf(Opcode())) { |
| 75 | // Cases for conditional branches follow. |
| 76 | case k22t: return VRegC_22t(); |
| 77 | case k21t: return VRegB_21t(); |
| 78 | // Cases for unconditional branches follow. |
| 79 | case k10t: return VRegA_10t(); |
| 80 | case k20t: return VRegA_20t(); |
| 81 | case k30t: return VRegA_30t(); |
| 82 | default: LOG(FATAL) << "Tried to access the branch offset of an instruction " << Name() << |
| 83 | " which does not have a target operand."; |
| 84 | } |
| 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | bool Instruction::CanFlowThrough() const { |
| 89 | const uint16_t* insns = reinterpret_cast<const uint16_t*>(this); |
| 90 | uint16_t insn = *insns; |
| 91 | Code opcode = static_cast<Code>(insn & 0xFF); |
| 92 | return FlagsOf(opcode) & Instruction::kContinue; |
| 93 | } |
| 94 | |
Ian Rogers | a75a013 | 2012-09-28 11:41:42 -0700 | [diff] [blame] | 95 | size_t Instruction::SizeInCodeUnitsComplexOpcode() const { |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 96 | const uint16_t* insns = reinterpret_cast<const uint16_t*>(this); |
Ian Rogers | a75a013 | 2012-09-28 11:41:42 -0700 | [diff] [blame] | 97 | // Handle special NOP encoded variable length sequences. |
| 98 | switch (*insns) { |
| 99 | case kPackedSwitchSignature: |
| 100 | return (4 + insns[1] * 2); |
| 101 | case kSparseSwitchSignature: |
| 102 | return (2 + insns[1] * 4); |
| 103 | case kArrayDataSignature: { |
| 104 | uint16_t element_size = insns[1]; |
| 105 | uint32_t length = insns[2] | (((uint32_t)insns[3]) << 16); |
| 106 | // The plus 1 is to round up for odd size and width. |
| 107 | return (4 + (element_size * length + 1) / 2); |
Carl Shapiro | e4c1ce4 | 2011-07-09 02:31:57 -0700 | [diff] [blame] | 108 | } |
Ian Rogers | a75a013 | 2012-09-28 11:41:42 -0700 | [diff] [blame] | 109 | default: |
| 110 | if ((*insns & 0xFF) == 0) { |
| 111 | return 1; // NOP. |
| 112 | } else { |
| 113 | LOG(FATAL) << "Unreachable: " << DumpString(NULL); |
| 114 | return 0; |
| 115 | } |
Carl Shapiro | e4c1ce4 | 2011-07-09 02:31:57 -0700 | [diff] [blame] | 116 | } |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Ian Rogers | 2c8a857 | 2011-10-24 17:11:36 -0700 | [diff] [blame] | 119 | std::string Instruction::DumpHex(size_t code_units) const { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 120 | size_t inst_length = SizeInCodeUnits(); |
| 121 | if (inst_length > code_units) { |
| 122 | inst_length = code_units; |
| 123 | } |
Ian Rogers | 2c8a857 | 2011-10-24 17:11:36 -0700 | [diff] [blame] | 124 | std::ostringstream os; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 125 | const uint16_t* insn = reinterpret_cast<const uint16_t*>(this); |
| 126 | for (size_t i = 0; i < inst_length; i++) { |
Ian Rogers | 2c8a857 | 2011-10-24 17:11:36 -0700 | [diff] [blame] | 127 | os << StringPrintf("0x%04x", insn[i]) << " "; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 128 | } |
| 129 | for (size_t i = inst_length; i < code_units; i++) { |
| 130 | os << " "; |
| 131 | } |
Ian Rogers | 2c8a857 | 2011-10-24 17:11:36 -0700 | [diff] [blame] | 132 | return os.str(); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 133 | } |
| 134 | |
Ian Rogers | 2c8a857 | 2011-10-24 17:11:36 -0700 | [diff] [blame] | 135 | std::string Instruction::DumpString(const DexFile* file) const { |
Ian Rogers | 2c8a857 | 2011-10-24 17:11:36 -0700 | [diff] [blame] | 136 | std::ostringstream os; |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 137 | const char* opcode = kInstructionNames[Opcode()]; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 138 | switch (FormatOf(Opcode())) { |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 139 | case k10x: os << opcode; break; |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 140 | case k12x: os << StringPrintf("%s v%d, v%d", opcode, VRegA_12x(), VRegB_12x()); break; |
| 141 | case k11n: os << StringPrintf("%s v%d, #%+d", opcode, VRegA_11n(), VRegB_11n()); break; |
| 142 | case k11x: os << StringPrintf("%s v%d", opcode, VRegA_11x()); break; |
| 143 | case k10t: os << StringPrintf("%s %+d", opcode, VRegA_10t()); break; |
| 144 | case k20t: os << StringPrintf("%s %+d", opcode, VRegA_20t()); break; |
| 145 | case k22x: os << StringPrintf("%s v%d, v%d", opcode, VRegA_22x(), VRegB_22x()); break; |
| 146 | case k21t: os << StringPrintf("%s v%d, %+d", opcode, VRegA_21t(), VRegB_21t()); break; |
| 147 | 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] | 148 | case k21h: { |
| 149 | // op vAA, #+BBBB0000[00000000] |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 150 | if (Opcode() == CONST_HIGH16) { |
| 151 | uint32_t value = VRegB_21h() << 16; |
| 152 | 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] | 153 | } else { |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 154 | uint64_t value = static_cast<uint64_t>(VRegB_21h()) << 48; |
Ian Rogers | b574c18 | 2014-01-23 19:51:19 -0800 | [diff] [blame] | 155 | os << StringPrintf("%s v%d, #long %+" PRId64 " // 0x%" PRIx64, opcode, VRegA_21h(), |
| 156 | value, value); |
Elliott Hughes | 1b3d6ca | 2012-04-25 13:00:14 -0700 | [diff] [blame] | 157 | } |
| 158 | } |
| 159 | break; |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 160 | case k21c: { |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 161 | switch (Opcode()) { |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 162 | case CONST_STRING: |
| 163 | if (file != NULL) { |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 164 | uint32_t string_idx = VRegB_21c(); |
| 165 | os << StringPrintf("const-string v%d, %s // string@%d", VRegA_21c(), |
| 166 | PrintableString(file->StringDataByIdx(string_idx)).c_str(), string_idx); |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 167 | break; |
| 168 | } // else fall-through |
Mathieu Chartier | 18c24b6 | 2012-09-10 08:54:25 -0700 | [diff] [blame] | 169 | case CHECK_CAST: |
| 170 | case CONST_CLASS: |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 171 | case NEW_INSTANCE: |
| 172 | if (file != NULL) { |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 173 | uint32_t type_idx = VRegB_21c(); |
Dragos Sbirlea | b43cef3 | 2013-05-23 11:59:20 -0700 | [diff] [blame] | 174 | os << opcode << " v" << static_cast<int>(VRegA_21c()) << ", " << PrettyType(type_idx, *file) |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 175 | << " // type@" << type_idx; |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 176 | break; |
| 177 | } // else fall-through |
| 178 | case SGET: |
| 179 | case SGET_WIDE: |
| 180 | case SGET_OBJECT: |
| 181 | case SGET_BOOLEAN: |
| 182 | case SGET_BYTE: |
| 183 | case SGET_CHAR: |
| 184 | case SGET_SHORT: |
| 185 | if (file != NULL) { |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 186 | uint32_t field_idx = VRegB_21c(); |
Dragos Sbirlea | b43cef3 | 2013-05-23 11:59:20 -0700 | [diff] [blame] | 187 | 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] | 188 | << " // field@" << field_idx; |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 189 | break; |
| 190 | } // else fall-through |
| 191 | case SPUT: |
| 192 | case SPUT_WIDE: |
| 193 | case SPUT_OBJECT: |
| 194 | case SPUT_BOOLEAN: |
| 195 | case SPUT_BYTE: |
| 196 | case SPUT_CHAR: |
| 197 | case SPUT_SHORT: |
| 198 | if (file != NULL) { |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 199 | uint32_t field_idx = VRegB_21c(); |
Dragos Sbirlea | b43cef3 | 2013-05-23 11:59:20 -0700 | [diff] [blame] | 200 | 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] | 201 | << " // field@" << field_idx; |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 202 | break; |
| 203 | } // else fall-through |
| 204 | default: |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 205 | os << StringPrintf("%s v%d, thing@%d", opcode, VRegA_21c(), VRegB_21c()); |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 206 | break; |
| 207 | } |
| 208 | break; |
| 209 | } |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 210 | case k23x: os << StringPrintf("%s v%d, v%d, v%d", opcode, VRegA_23x(), VRegB_23x(), VRegC_23x()); break; |
| 211 | case k22b: os << StringPrintf("%s v%d, v%d, #%+d", opcode, VRegA_22b(), VRegB_22b(), VRegC_22b()); break; |
| 212 | case k22t: os << StringPrintf("%s v%d, v%d, %+d", opcode, VRegA_22t(), VRegB_22t(), VRegC_22t()); break; |
| 213 | 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] | 214 | case k22c: { |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 215 | switch (Opcode()) { |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 216 | case IGET: |
| 217 | case IGET_WIDE: |
| 218 | case IGET_OBJECT: |
| 219 | case IGET_BOOLEAN: |
| 220 | case IGET_BYTE: |
| 221 | case IGET_CHAR: |
| 222 | case IGET_SHORT: |
| 223 | if (file != NULL) { |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 224 | uint32_t field_idx = VRegC_22c(); |
Dragos Sbirlea | b43cef3 | 2013-05-23 11:59:20 -0700 | [diff] [blame] | 225 | 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] | 226 | << PrettyField(field_idx, *file, true) << " // field@" << field_idx; |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 227 | break; |
| 228 | } // else fall-through |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 229 | case IGET_QUICK: |
| 230 | case IGET_OBJECT_QUICK: |
| 231 | if (file != NULL) { |
| 232 | uint32_t field_idx = VRegC_22c(); |
| 233 | os << opcode << " v" << static_cast<int>(VRegA_22c()) << ", v" << static_cast<int>(VRegB_22c()) << ", " |
| 234 | << "// offset@" << field_idx; |
| 235 | break; |
| 236 | } // else fall-through |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 237 | case IPUT: |
| 238 | case IPUT_WIDE: |
| 239 | case IPUT_OBJECT: |
| 240 | case IPUT_BOOLEAN: |
| 241 | case IPUT_BYTE: |
| 242 | case IPUT_CHAR: |
| 243 | case IPUT_SHORT: |
| 244 | if (file != NULL) { |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 245 | uint32_t field_idx = VRegC_22c(); |
Dragos Sbirlea | b43cef3 | 2013-05-23 11:59:20 -0700 | [diff] [blame] | 246 | 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] | 247 | << PrettyField(field_idx, *file, true) << " // field@" << field_idx; |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 248 | break; |
| 249 | } // else fall-through |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 250 | case IPUT_QUICK: |
| 251 | case IPUT_OBJECT_QUICK: |
| 252 | if (file != NULL) { |
| 253 | uint32_t field_idx = VRegC_22c(); |
| 254 | os << opcode << " v" << static_cast<int>(VRegA_22c()) << ", v" << static_cast<int>(VRegB_22c()) << ", " |
| 255 | << "// offset@" << field_idx; |
| 256 | break; |
| 257 | } // else fall-through |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 258 | case INSTANCE_OF: |
| 259 | if (file != NULL) { |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 260 | uint32_t type_idx = VRegC_22c(); |
Dragos Sbirlea | d4e868a | 2013-05-23 09:44:17 -0700 | [diff] [blame] | 261 | 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] | 262 | << PrettyType(type_idx, *file) << " // type@" << type_idx; |
Mathieu Chartier | 18c24b6 | 2012-09-10 08:54:25 -0700 | [diff] [blame] | 263 | break; |
| 264 | } |
| 265 | case NEW_ARRAY: |
| 266 | if (file != NULL) { |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 267 | uint32_t type_idx = VRegC_22c(); |
Dragos Sbirlea | b43cef3 | 2013-05-23 11:59:20 -0700 | [diff] [blame] | 268 | 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] | 269 | << PrettyType(type_idx, *file) << " // type@" << type_idx; |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 270 | break; |
| 271 | } // else fall-through |
| 272 | default: |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 273 | 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] | 274 | break; |
| 275 | } |
| 276 | break; |
| 277 | } |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 278 | case k32x: os << StringPrintf("%s v%d, v%d", opcode, VRegA_32x(), VRegB_32x()); break; |
| 279 | case k30t: os << StringPrintf("%s %+d", opcode, VRegA_30t()); break; |
| 280 | case k31t: os << StringPrintf("%s v%d, %+d", opcode, VRegA_31t(), VRegB_31t()); break; |
| 281 | 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] | 282 | case k31c: |
| 283 | if (Opcode() == CONST_STRING_JUMBO) { |
| 284 | uint32_t string_idx = VRegB_31c(); |
| 285 | if (file != NULL) { |
| 286 | os << StringPrintf("%s v%d, %s // string@%d", opcode, VRegA_31c(), |
| 287 | PrintableString(file->StringDataByIdx(string_idx)).c_str(), |
| 288 | string_idx); |
| 289 | } else { |
| 290 | os << StringPrintf("%s v%d, string@%d", opcode, VRegA_31c(), string_idx); |
| 291 | } |
| 292 | } else { |
| 293 | os << StringPrintf("%s v%d, thing@%d", opcode, VRegA_31c(), VRegB_31c()); break; |
| 294 | } |
| 295 | break; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 296 | case k35c: { |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 297 | uint32_t arg[5]; |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 298 | GetVarArgs(arg); |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 299 | switch (Opcode()) { |
Andreas Gampe | 7aca91d | 2014-03-31 18:10:53 -0700 | [diff] [blame] | 300 | case FILLED_NEW_ARRAY: |
| 301 | { |
| 302 | const int32_t a = VRegA_35c(); |
| 303 | os << opcode << " {"; |
| 304 | for (int i = 0; i < a; ++i) { |
| 305 | if (i > 0) { |
| 306 | os << ", "; |
| 307 | } |
| 308 | os << "v" << arg[i]; |
| 309 | } |
| 310 | os << "}, type@" << VRegB_35c(); |
| 311 | } |
| 312 | break; |
| 313 | |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 314 | case INVOKE_VIRTUAL: |
| 315 | case INVOKE_SUPER: |
| 316 | case INVOKE_DIRECT: |
| 317 | case INVOKE_STATIC: |
| 318 | case INVOKE_INTERFACE: |
| 319 | if (file != NULL) { |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 320 | os << opcode << " {"; |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 321 | uint32_t method_idx = VRegB_35c(); |
| 322 | for (size_t i = 0; i < VRegA_35c(); ++i) { |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 323 | if (i != 0) { |
| 324 | os << ", "; |
| 325 | } |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 326 | os << "v" << arg[i]; |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 327 | } |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 328 | os << "}, " << PrettyMethod(method_idx, *file) << " // method@" << method_idx; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 329 | break; |
| 330 | } // else fall-through |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 331 | case INVOKE_VIRTUAL_QUICK: |
| 332 | if (file != NULL) { |
| 333 | os << opcode << " {"; |
| 334 | uint32_t method_idx = VRegB_35c(); |
| 335 | for (size_t i = 0; i < VRegA_35c(); ++i) { |
| 336 | if (i != 0) { |
| 337 | os << ", "; |
| 338 | } |
| 339 | os << "v" << arg[i]; |
| 340 | } |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 341 | os << "}, // vtable@" << method_idx; |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 342 | break; |
| 343 | } // else fall-through |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 344 | default: |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 345 | os << opcode << " {v" << arg[0] << ", v" << arg[1] << ", v" << arg[2] |
| 346 | << ", v" << arg[3] << ", v" << arg[4] << "}, thing@" << VRegB_35c(); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 347 | break; |
| 348 | } |
| 349 | break; |
| 350 | } |
Ian Rogers | 4c5dd5a | 2012-09-07 11:27:28 -0700 | [diff] [blame] | 351 | case k3rc: { |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 352 | switch (Opcode()) { |
Ian Rogers | 4c5dd5a | 2012-09-07 11:27:28 -0700 | [diff] [blame] | 353 | case INVOKE_VIRTUAL_RANGE: |
| 354 | case INVOKE_SUPER_RANGE: |
| 355 | case INVOKE_DIRECT_RANGE: |
| 356 | case INVOKE_STATIC_RANGE: |
| 357 | case INVOKE_INTERFACE_RANGE: |
| 358 | if (file != NULL) { |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 359 | uint32_t method_idx = VRegB_3rc(); |
| 360 | os << StringPrintf("%s, {v%d .. v%d}, ", opcode, VRegC_3rc(), (VRegC_3rc() + VRegA_3rc() - 1)) |
| 361 | << PrettyMethod(method_idx, *file) << " // method@" << method_idx; |
Ian Rogers | 4c5dd5a | 2012-09-07 11:27:28 -0700 | [diff] [blame] | 362 | break; |
| 363 | } // else fall-through |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 364 | case INVOKE_VIRTUAL_RANGE_QUICK: |
| 365 | if (file != NULL) { |
| 366 | uint32_t method_idx = VRegB_3rc(); |
| 367 | os << StringPrintf("%s, {v%d .. v%d}, ", opcode, VRegC_3rc(), (VRegC_3rc() + VRegA_3rc() - 1)) |
| 368 | << "// vtable@" << method_idx; |
| 369 | break; |
| 370 | } // else fall-through |
Ian Rogers | 4c5dd5a | 2012-09-07 11:27:28 -0700 | [diff] [blame] | 371 | default: |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 372 | os << StringPrintf("%s, {v%d .. v%d}, thing@%d", opcode, VRegC_3rc(), |
| 373 | (VRegC_3rc() + VRegA_3rc() - 1), VRegB_3rc()); |
Ian Rogers | 4c5dd5a | 2012-09-07 11:27:28 -0700 | [diff] [blame] | 374 | break; |
| 375 | } |
| 376 | break; |
| 377 | } |
Ian Rogers | b574c18 | 2014-01-23 19:51:19 -0800 | [diff] [blame] | 378 | 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] | 379 | default: os << " unknown format (" << DumpHex(5) << ")"; break; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 380 | } |
Ian Rogers | 2c8a857 | 2011-10-24 17:11:36 -0700 | [diff] [blame] | 381 | return os.str(); |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 382 | } |
| 383 | |
Ian Rogers | a75a013 | 2012-09-28 11:41:42 -0700 | [diff] [blame] | 384 | std::ostream& operator<<(std::ostream& os, const Instruction::Code& code) { |
| 385 | return os << Instruction::Name(code); |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 386 | } |
| 387 | |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 388 | } // namespace art |