blob: af38433abc6caaad35dfaaf8e0514ef125101627 [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
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 Shapiro12eb78e2011-06-24 14:51:06 -070016
Sebastien Hertz807a2562013-04-15 09:33:39 +020017#include "dex_instruction-inl.h"
Carl Shapiro12eb78e2011-06-24 14:51:06 -070018
Ian Rogersb574c182014-01-23 19:51:19 -080019#include <inttypes.h>
20
21#include <iomanip>
Ian Rogersc7dd2952014-10-21 23:31:19 -070022#include <sstream>
Ian Rogersb574c182014-01-23 19:51:19 -080023
Ian Rogers576ca0c2014-06-06 15:58:22 -070024#include "base/stringprintf.h"
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070025#include "dex_file-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080026#include "utils.h"
Ian Rogersd81871c2011-10-03 13:57:23 -070027
Carl Shapiro12eb78e2011-06-24 14:51:06 -070028namespace art {
29
Carl Shapiroe4c1ce42011-07-09 02:31:57 -070030const char* const Instruction::kInstructionNames[] = {
jeffhaoba5ebb92011-08-25 17:24:37 -070031#define INSTRUCTION_NAME(o, c, pname, f, r, i, a, v) pname,
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070032#include "dex_instruction_list.h"
Carl Shapiroe4c1ce42011-07-09 02:31:57 -070033 DEX_INSTRUCTION_LIST(INSTRUCTION_NAME)
34#undef DEX_INSTRUCTION_LIST
35#undef INSTRUCTION_NAME
36};
37
Elliott Hughesadb8c672012-03-06 16:49:32 -080038Instruction::Format const Instruction::kInstructionFormats[] = {
jeffhaoba5ebb92011-08-25 17:24:37 -070039#define INSTRUCTION_FORMAT(o, c, p, format, r, i, a, v) format,
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070040#include "dex_instruction_list.h"
Carl Shapiroe4c1ce42011-07-09 02:31:57 -070041 DEX_INSTRUCTION_LIST(INSTRUCTION_FORMAT)
42#undef DEX_INSTRUCTION_LIST
43#undef INSTRUCTION_FORMAT
44};
45
46int const Instruction::kInstructionFlags[] = {
jeffhaoba5ebb92011-08-25 17:24:37 -070047#define INSTRUCTION_FLAGS(o, c, p, f, r, i, flags, v) flags,
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070048#include "dex_instruction_list.h"
Carl Shapiroe4c1ce42011-07-09 02:31:57 -070049 DEX_INSTRUCTION_LIST(INSTRUCTION_FLAGS)
50#undef DEX_INSTRUCTION_LIST
51#undef INSTRUCTION_FLAGS
52};
53
jeffhaoba5ebb92011-08-25 17:24:37 -070054int const Instruction::kInstructionVerifyFlags[] = {
55#define INSTRUCTION_VERIFY_FLAGS(o, c, p, f, r, i, a, vflags) vflags,
56#include "dex_instruction_list.h"
57 DEX_INSTRUCTION_LIST(INSTRUCTION_VERIFY_FLAGS)
58#undef DEX_INSTRUCTION_LIST
59#undef INSTRUCTION_VERIFY_FLAGS
60};
61
Ian Rogersa75a0132012-09-28 11:41:42 -070062int const Instruction::kInstructionSizeInCodeUnits[] = {
63#define INSTRUCTION_SIZE(opcode, c, p, format, r, i, a, v) \
Brian Carlstrom6f485c62013-07-18 15:35:35 -070064 ((opcode == NOP) ? -1 : \
65 ((format >= k10x) && (format <= k10t)) ? 1 : \
66 ((format >= k20t) && (format <= k22c)) ? 2 : \
67 ((format >= k32x) && (format <= k3rc)) ? 3 : \
68 (format == k51l) ? 5 : -1),
Ian Rogersa75a0132012-09-28 11:41:42 -070069#include "dex_instruction_list.h"
70 DEX_INSTRUCTION_LIST(INSTRUCTION_SIZE)
71#undef DEX_INSTRUCTION_LIST
72#undef INSTRUCTION_SIZE
73};
74
Dragos Sbirlea39f99272013-06-25 13:17:36 -070075int32_t Instruction::GetTargetOffset() const {
76 switch (FormatOf(Opcode())) {
77 // Cases for conditional branches follow.
78 case k22t: return VRegC_22t();
79 case k21t: return VRegB_21t();
80 // Cases for unconditional branches follow.
81 case k10t: return VRegA_10t();
82 case k20t: return VRegA_20t();
83 case k30t: return VRegA_30t();
84 default: LOG(FATAL) << "Tried to access the branch offset of an instruction " << Name() <<
85 " which does not have a target operand.";
86 }
87 return 0;
88}
89
90bool Instruction::CanFlowThrough() const {
91 const uint16_t* insns = reinterpret_cast<const uint16_t*>(this);
92 uint16_t insn = *insns;
93 Code opcode = static_cast<Code>(insn & 0xFF);
94 return FlagsOf(opcode) & Instruction::kContinue;
95}
96
Ian Rogersa75a0132012-09-28 11:41:42 -070097size_t Instruction::SizeInCodeUnitsComplexOpcode() const {
Carl Shapiro12eb78e2011-06-24 14:51:06 -070098 const uint16_t* insns = reinterpret_cast<const uint16_t*>(this);
Ian Rogersa75a0132012-09-28 11:41:42 -070099 // Handle special NOP encoded variable length sequences.
100 switch (*insns) {
101 case kPackedSwitchSignature:
102 return (4 + insns[1] * 2);
103 case kSparseSwitchSignature:
104 return (2 + insns[1] * 4);
105 case kArrayDataSignature: {
106 uint16_t element_size = insns[1];
107 uint32_t length = insns[2] | (((uint32_t)insns[3]) << 16);
108 // The plus 1 is to round up for odd size and width.
109 return (4 + (element_size * length + 1) / 2);
Carl Shapiroe4c1ce42011-07-09 02:31:57 -0700110 }
Ian Rogersa75a0132012-09-28 11:41:42 -0700111 default:
112 if ((*insns & 0xFF) == 0) {
113 return 1; // NOP.
114 } else {
Ian Rogersfc787ec2014-10-09 21:56:44 -0700115 LOG(FATAL) << "Unreachable: " << DumpString(nullptr);
Ian Rogersa75a0132012-09-28 11:41:42 -0700116 return 0;
117 }
Carl Shapiroe4c1ce42011-07-09 02:31:57 -0700118 }
Ian Rogersd81871c2011-10-03 13:57:23 -0700119}
120
Ian Rogers2c8a8572011-10-24 17:11:36 -0700121std::string Instruction::DumpHex(size_t code_units) const {
Ian Rogersd81871c2011-10-03 13:57:23 -0700122 size_t inst_length = SizeInCodeUnits();
123 if (inst_length > code_units) {
124 inst_length = code_units;
125 }
Ian Rogers2c8a8572011-10-24 17:11:36 -0700126 std::ostringstream os;
Ian Rogersd81871c2011-10-03 13:57:23 -0700127 const uint16_t* insn = reinterpret_cast<const uint16_t*>(this);
128 for (size_t i = 0; i < inst_length; i++) {
Ian Rogers2c8a8572011-10-24 17:11:36 -0700129 os << StringPrintf("0x%04x", insn[i]) << " ";
Ian Rogersd81871c2011-10-03 13:57:23 -0700130 }
131 for (size_t i = inst_length; i < code_units; i++) {
132 os << " ";
133 }
Ian Rogers2c8a8572011-10-24 17:11:36 -0700134 return os.str();
Ian Rogersd81871c2011-10-03 13:57:23 -0700135}
136
Ian Rogers2c8a8572011-10-24 17:11:36 -0700137std::string Instruction::DumpString(const DexFile* file) const {
Ian Rogers2c8a8572011-10-24 17:11:36 -0700138 std::ostringstream os;
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200139 const char* opcode = kInstructionNames[Opcode()];
Elliott Hughesadb8c672012-03-06 16:49:32 -0800140 switch (FormatOf(Opcode())) {
Elliott Hughese3c845c2012-02-28 17:23:01 -0800141 case k10x: os << opcode; break;
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200142 case k12x: os << StringPrintf("%s v%d, v%d", opcode, VRegA_12x(), VRegB_12x()); break;
143 case k11n: os << StringPrintf("%s v%d, #%+d", opcode, VRegA_11n(), VRegB_11n()); break;
144 case k11x: os << StringPrintf("%s v%d", opcode, VRegA_11x()); break;
145 case k10t: os << StringPrintf("%s %+d", opcode, VRegA_10t()); break;
146 case k20t: os << StringPrintf("%s %+d", opcode, VRegA_20t()); break;
147 case k22x: os << StringPrintf("%s v%d, v%d", opcode, VRegA_22x(), VRegB_22x()); break;
148 case k21t: os << StringPrintf("%s v%d, %+d", opcode, VRegA_21t(), VRegB_21t()); break;
149 case k21s: os << StringPrintf("%s v%d, #%+d", opcode, VRegA_21s(), VRegB_21s()); break;
Elliott Hughes1b3d6ca2012-04-25 13:00:14 -0700150 case k21h: {
151 // op vAA, #+BBBB0000[00000000]
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200152 if (Opcode() == CONST_HIGH16) {
153 uint32_t value = VRegB_21h() << 16;
154 os << StringPrintf("%s v%d, #int %+d // 0x%x", opcode, VRegA_21h(), value, value);
Elliott Hughes1b3d6ca2012-04-25 13:00:14 -0700155 } else {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200156 uint64_t value = static_cast<uint64_t>(VRegB_21h()) << 48;
Ian Rogersb574c182014-01-23 19:51:19 -0800157 os << StringPrintf("%s v%d, #long %+" PRId64 " // 0x%" PRIx64, opcode, VRegA_21h(),
158 value, value);
Elliott Hughes1b3d6ca2012-04-25 13:00:14 -0700159 }
160 }
161 break;
Ian Rogers90334e52012-06-06 20:22:20 -0700162 case k21c: {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200163 switch (Opcode()) {
Ian Rogers90334e52012-06-06 20:22:20 -0700164 case CONST_STRING:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700165 if (file != nullptr) {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200166 uint32_t string_idx = VRegB_21c();
167 os << StringPrintf("const-string v%d, %s // string@%d", VRegA_21c(),
168 PrintableString(file->StringDataByIdx(string_idx)).c_str(), string_idx);
Ian Rogers90334e52012-06-06 20:22:20 -0700169 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700170 }
171 FALLTHROUGH_INTENDED;
Mathieu Chartier18c24b62012-09-10 08:54:25 -0700172 case CHECK_CAST:
173 case CONST_CLASS:
Ian Rogers90334e52012-06-06 20:22:20 -0700174 case NEW_INSTANCE:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700175 if (file != nullptr) {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200176 uint32_t type_idx = VRegB_21c();
Dragos Sbirleab43cef32013-05-23 11:59:20 -0700177 os << opcode << " v" << static_cast<int>(VRegA_21c()) << ", " << PrettyType(type_idx, *file)
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200178 << " // type@" << type_idx;
Ian Rogers90334e52012-06-06 20:22:20 -0700179 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700180 }
181 FALLTHROUGH_INTENDED;
Ian Rogers90334e52012-06-06 20:22:20 -0700182 case SGET:
183 case SGET_WIDE:
184 case SGET_OBJECT:
185 case SGET_BOOLEAN:
186 case SGET_BYTE:
187 case SGET_CHAR:
188 case SGET_SHORT:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700189 if (file != nullptr) {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200190 uint32_t field_idx = VRegB_21c();
Dragos Sbirleab43cef32013-05-23 11:59:20 -0700191 os << opcode << " v" << static_cast<int>(VRegA_21c()) << ", " << PrettyField(field_idx, *file, true)
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200192 << " // field@" << field_idx;
Ian Rogers90334e52012-06-06 20:22:20 -0700193 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700194 }
195 FALLTHROUGH_INTENDED;
Ian Rogers90334e52012-06-06 20:22:20 -0700196 case SPUT:
197 case SPUT_WIDE:
198 case SPUT_OBJECT:
199 case SPUT_BOOLEAN:
200 case SPUT_BYTE:
201 case SPUT_CHAR:
202 case SPUT_SHORT:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700203 if (file != nullptr) {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200204 uint32_t field_idx = VRegB_21c();
Dragos Sbirleab43cef32013-05-23 11:59:20 -0700205 os << opcode << " v" << static_cast<int>(VRegA_21c()) << ", " << PrettyField(field_idx, *file, true)
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200206 << " // field@" << field_idx;
Ian Rogers90334e52012-06-06 20:22:20 -0700207 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700208 }
209 FALLTHROUGH_INTENDED;
Ian Rogers90334e52012-06-06 20:22:20 -0700210 default:
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200211 os << StringPrintf("%s v%d, thing@%d", opcode, VRegA_21c(), VRegB_21c());
Ian Rogers90334e52012-06-06 20:22:20 -0700212 break;
213 }
214 break;
215 }
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200216 case k23x: os << StringPrintf("%s v%d, v%d, v%d", opcode, VRegA_23x(), VRegB_23x(), VRegC_23x()); break;
217 case k22b: os << StringPrintf("%s v%d, v%d, #%+d", opcode, VRegA_22b(), VRegB_22b(), VRegC_22b()); break;
218 case k22t: os << StringPrintf("%s v%d, v%d, %+d", opcode, VRegA_22t(), VRegB_22t(), VRegC_22t()); break;
219 case k22s: os << StringPrintf("%s v%d, v%d, #%+d", opcode, VRegA_22s(), VRegB_22s(), VRegC_22s()); break;
Ian Rogers90334e52012-06-06 20:22:20 -0700220 case k22c: {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200221 switch (Opcode()) {
Ian Rogers90334e52012-06-06 20:22:20 -0700222 case IGET:
223 case IGET_WIDE:
224 case IGET_OBJECT:
225 case IGET_BOOLEAN:
226 case IGET_BYTE:
227 case IGET_CHAR:
228 case IGET_SHORT:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700229 if (file != nullptr) {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200230 uint32_t field_idx = VRegC_22c();
Dragos Sbirleab43cef32013-05-23 11:59:20 -0700231 os << opcode << " v" << static_cast<int>(VRegA_22c()) << ", v" << static_cast<int>(VRegB_22c()) << ", "
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200232 << PrettyField(field_idx, *file, true) << " // field@" << field_idx;
Ian Rogers90334e52012-06-06 20:22:20 -0700233 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700234 }
235 FALLTHROUGH_INTENDED;
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200236 case IGET_QUICK:
237 case IGET_OBJECT_QUICK:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700238 if (file != nullptr) {
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200239 uint32_t field_idx = VRegC_22c();
240 os << opcode << " v" << static_cast<int>(VRegA_22c()) << ", v" << static_cast<int>(VRegB_22c()) << ", "
241 << "// offset@" << field_idx;
242 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700243 }
244 FALLTHROUGH_INTENDED;
Ian Rogers90334e52012-06-06 20:22:20 -0700245 case IPUT:
246 case IPUT_WIDE:
247 case IPUT_OBJECT:
248 case IPUT_BOOLEAN:
249 case IPUT_BYTE:
250 case IPUT_CHAR:
251 case IPUT_SHORT:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700252 if (file != nullptr) {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200253 uint32_t field_idx = VRegC_22c();
Dragos Sbirleab43cef32013-05-23 11:59:20 -0700254 os << opcode << " v" << static_cast<int>(VRegA_22c()) << ", v" << static_cast<int>(VRegB_22c()) << ", "
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200255 << PrettyField(field_idx, *file, true) << " // field@" << field_idx;
Ian Rogers90334e52012-06-06 20:22:20 -0700256 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700257 }
258 FALLTHROUGH_INTENDED;
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200259 case IPUT_QUICK:
260 case IPUT_OBJECT_QUICK:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700261 if (file != nullptr) {
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200262 uint32_t field_idx = VRegC_22c();
263 os << opcode << " v" << static_cast<int>(VRegA_22c()) << ", v" << static_cast<int>(VRegB_22c()) << ", "
264 << "// offset@" << field_idx;
265 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700266 }
267 FALLTHROUGH_INTENDED;
Ian Rogers90334e52012-06-06 20:22:20 -0700268 case INSTANCE_OF:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700269 if (file != nullptr) {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200270 uint32_t type_idx = VRegC_22c();
Dragos Sbirlead4e868a2013-05-23 09:44:17 -0700271 os << opcode << " v" << static_cast<int>(VRegA_22c()) << ", v" << static_cast<int>(VRegB_22c()) << ", "
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200272 << PrettyType(type_idx, *file) << " // type@" << type_idx;
Mathieu Chartier18c24b62012-09-10 08:54:25 -0700273 break;
274 }
Ian Rogersfc787ec2014-10-09 21:56:44 -0700275 FALLTHROUGH_INTENDED;
Mathieu Chartier18c24b62012-09-10 08:54:25 -0700276 case NEW_ARRAY:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700277 if (file != nullptr) {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200278 uint32_t type_idx = VRegC_22c();
Dragos Sbirleab43cef32013-05-23 11:59:20 -0700279 os << opcode << " v" << static_cast<int>(VRegA_22c()) << ", v" << static_cast<int>(VRegB_22c()) << ", "
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200280 << PrettyType(type_idx, *file) << " // type@" << type_idx;
Ian Rogers90334e52012-06-06 20:22:20 -0700281 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700282 }
283 FALLTHROUGH_INTENDED;
Ian Rogers90334e52012-06-06 20:22:20 -0700284 default:
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200285 os << StringPrintf("%s v%d, v%d, thing@%d", opcode, VRegA_22c(), VRegB_22c(), VRegC_22c());
Ian Rogers90334e52012-06-06 20:22:20 -0700286 break;
287 }
288 break;
289 }
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200290 case k32x: os << StringPrintf("%s v%d, v%d", opcode, VRegA_32x(), VRegB_32x()); break;
291 case k30t: os << StringPrintf("%s %+d", opcode, VRegA_30t()); break;
292 case k31t: os << StringPrintf("%s v%d, %+d", opcode, VRegA_31t(), VRegB_31t()); break;
293 case k31i: os << StringPrintf("%s v%d, #%+d", opcode, VRegA_31i(), VRegB_31i()); break;
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700294 case k31c:
295 if (Opcode() == CONST_STRING_JUMBO) {
296 uint32_t string_idx = VRegB_31c();
Ian Rogersfc787ec2014-10-09 21:56:44 -0700297 if (file != nullptr) {
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700298 os << StringPrintf("%s v%d, %s // string@%d", opcode, VRegA_31c(),
299 PrintableString(file->StringDataByIdx(string_idx)).c_str(),
300 string_idx);
301 } else {
302 os << StringPrintf("%s v%d, string@%d", opcode, VRegA_31c(), string_idx);
303 }
304 } else {
305 os << StringPrintf("%s v%d, thing@%d", opcode, VRegA_31c(), VRegB_31c()); break;
306 }
307 break;
Ian Rogersd81871c2011-10-03 13:57:23 -0700308 case k35c: {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200309 uint32_t arg[5];
Ian Rogers29a26482014-05-02 15:27:29 -0700310 GetVarArgs(arg);
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200311 switch (Opcode()) {
Andreas Gampe7aca91d2014-03-31 18:10:53 -0700312 case FILLED_NEW_ARRAY:
313 {
314 const int32_t a = VRegA_35c();
315 os << opcode << " {";
316 for (int i = 0; i < a; ++i) {
317 if (i > 0) {
318 os << ", ";
319 }
320 os << "v" << arg[i];
321 }
322 os << "}, type@" << VRegB_35c();
323 }
324 break;
325
Ian Rogersd81871c2011-10-03 13:57:23 -0700326 case INVOKE_VIRTUAL:
327 case INVOKE_SUPER:
328 case INVOKE_DIRECT:
329 case INVOKE_STATIC:
330 case INVOKE_INTERFACE:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700331 if (file != nullptr) {
Elliott Hughese3c845c2012-02-28 17:23:01 -0800332 os << opcode << " {";
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200333 uint32_t method_idx = VRegB_35c();
334 for (size_t i = 0; i < VRegA_35c(); ++i) {
Elliott Hughese3c845c2012-02-28 17:23:01 -0800335 if (i != 0) {
336 os << ", ";
337 }
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200338 os << "v" << arg[i];
Elliott Hughese3c845c2012-02-28 17:23:01 -0800339 }
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200340 os << "}, " << PrettyMethod(method_idx, *file) << " // method@" << method_idx;
Ian Rogersd81871c2011-10-03 13:57:23 -0700341 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700342 }
343 FALLTHROUGH_INTENDED;
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200344 case INVOKE_VIRTUAL_QUICK:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700345 if (file != nullptr) {
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200346 os << opcode << " {";
347 uint32_t method_idx = VRegB_35c();
348 for (size_t i = 0; i < VRegA_35c(); ++i) {
349 if (i != 0) {
350 os << ", ";
351 }
352 os << "v" << arg[i];
353 }
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700354 os << "}, // vtable@" << method_idx;
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200355 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700356 }
357 FALLTHROUGH_INTENDED;
Ian Rogersd81871c2011-10-03 13:57:23 -0700358 default:
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200359 os << opcode << " {v" << arg[0] << ", v" << arg[1] << ", v" << arg[2]
360 << ", v" << arg[3] << ", v" << arg[4] << "}, thing@" << VRegB_35c();
Ian Rogersd81871c2011-10-03 13:57:23 -0700361 break;
362 }
363 break;
364 }
Ian Rogers4c5dd5a2012-09-07 11:27:28 -0700365 case k3rc: {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200366 switch (Opcode()) {
Ian Rogers4c5dd5a2012-09-07 11:27:28 -0700367 case INVOKE_VIRTUAL_RANGE:
368 case INVOKE_SUPER_RANGE:
369 case INVOKE_DIRECT_RANGE:
370 case INVOKE_STATIC_RANGE:
371 case INVOKE_INTERFACE_RANGE:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700372 if (file != nullptr) {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200373 uint32_t method_idx = VRegB_3rc();
374 os << StringPrintf("%s, {v%d .. v%d}, ", opcode, VRegC_3rc(), (VRegC_3rc() + VRegA_3rc() - 1))
375 << PrettyMethod(method_idx, *file) << " // method@" << method_idx;
Ian Rogers4c5dd5a2012-09-07 11:27:28 -0700376 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700377 }
378 FALLTHROUGH_INTENDED;
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200379 case INVOKE_VIRTUAL_RANGE_QUICK:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700380 if (file != nullptr) {
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200381 uint32_t method_idx = VRegB_3rc();
382 os << StringPrintf("%s, {v%d .. v%d}, ", opcode, VRegC_3rc(), (VRegC_3rc() + VRegA_3rc() - 1))
383 << "// vtable@" << method_idx;
384 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700385 }
386 FALLTHROUGH_INTENDED;
Ian Rogers4c5dd5a2012-09-07 11:27:28 -0700387 default:
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200388 os << StringPrintf("%s, {v%d .. v%d}, thing@%d", opcode, VRegC_3rc(),
389 (VRegC_3rc() + VRegA_3rc() - 1), VRegB_3rc());
Ian Rogers4c5dd5a2012-09-07 11:27:28 -0700390 break;
391 }
392 break;
393 }
Ian Rogersb574c182014-01-23 19:51:19 -0800394 case k51l: os << StringPrintf("%s v%d, #%+" PRId64, opcode, VRegA_51l(), VRegB_51l()); break;
Ian Rogers2c8a8572011-10-24 17:11:36 -0700395 default: os << " unknown format (" << DumpHex(5) << ")"; break;
Ian Rogersd81871c2011-10-03 13:57:23 -0700396 }
Ian Rogers2c8a8572011-10-24 17:11:36 -0700397 return os.str();
Carl Shapiro12eb78e2011-06-24 14:51:06 -0700398}
399
Ian Rogersa75a0132012-09-28 11:41:42 -0700400std::ostream& operator<<(std::ostream& os, const Instruction::Code& code) {
401 return os << Instruction::Name(code);
Elliott Hughesadb8c672012-03-06 16:49:32 -0800402}
403
Carl Shapiro12eb78e2011-06-24 14:51:06 -0700404} // namespace art