blob: 7e775f4ed348aacbf1f6040d075305af8658d841 [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>
22
Ian Rogers576ca0c2014-06-06 15:58:22 -070023#include "base/stringprintf.h"
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070024#include "dex_file-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080025#include "utils.h"
Ian Rogersd81871c2011-10-03 13:57:23 -070026
Carl Shapiro12eb78e2011-06-24 14:51:06 -070027namespace art {
28
Carl Shapiroe4c1ce42011-07-09 02:31:57 -070029const char* const Instruction::kInstructionNames[] = {
jeffhaoba5ebb92011-08-25 17:24:37 -070030#define INSTRUCTION_NAME(o, c, pname, f, r, i, a, v) pname,
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070031#include "dex_instruction_list.h"
Carl Shapiroe4c1ce42011-07-09 02:31:57 -070032 DEX_INSTRUCTION_LIST(INSTRUCTION_NAME)
33#undef DEX_INSTRUCTION_LIST
34#undef INSTRUCTION_NAME
35};
36
Elliott Hughesadb8c672012-03-06 16:49:32 -080037Instruction::Format const Instruction::kInstructionFormats[] = {
jeffhaoba5ebb92011-08-25 17:24:37 -070038#define INSTRUCTION_FORMAT(o, c, p, format, r, i, a, v) format,
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070039#include "dex_instruction_list.h"
Carl Shapiroe4c1ce42011-07-09 02:31:57 -070040 DEX_INSTRUCTION_LIST(INSTRUCTION_FORMAT)
41#undef DEX_INSTRUCTION_LIST
42#undef INSTRUCTION_FORMAT
43};
44
45int const Instruction::kInstructionFlags[] = {
jeffhaoba5ebb92011-08-25 17:24:37 -070046#define INSTRUCTION_FLAGS(o, c, p, f, r, i, flags, v) flags,
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070047#include "dex_instruction_list.h"
Carl Shapiroe4c1ce42011-07-09 02:31:57 -070048 DEX_INSTRUCTION_LIST(INSTRUCTION_FLAGS)
49#undef DEX_INSTRUCTION_LIST
50#undef INSTRUCTION_FLAGS
51};
52
jeffhaoba5ebb92011-08-25 17:24:37 -070053int const Instruction::kInstructionVerifyFlags[] = {
54#define INSTRUCTION_VERIFY_FLAGS(o, c, p, f, r, i, a, vflags) vflags,
55#include "dex_instruction_list.h"
56 DEX_INSTRUCTION_LIST(INSTRUCTION_VERIFY_FLAGS)
57#undef DEX_INSTRUCTION_LIST
58#undef INSTRUCTION_VERIFY_FLAGS
59};
60
Ian Rogersa75a0132012-09-28 11:41:42 -070061int const Instruction::kInstructionSizeInCodeUnits[] = {
62#define INSTRUCTION_SIZE(opcode, c, p, format, r, i, a, v) \
Brian Carlstrom6f485c62013-07-18 15:35:35 -070063 ((opcode == NOP) ? -1 : \
64 ((format >= k10x) && (format <= k10t)) ? 1 : \
65 ((format >= k20t) && (format <= k22c)) ? 2 : \
66 ((format >= k32x) && (format <= k3rc)) ? 3 : \
67 (format == k51l) ? 5 : -1),
Ian Rogersa75a0132012-09-28 11:41:42 -070068#include "dex_instruction_list.h"
69 DEX_INSTRUCTION_LIST(INSTRUCTION_SIZE)
70#undef DEX_INSTRUCTION_LIST
71#undef INSTRUCTION_SIZE
72};
73
Dragos Sbirlea39f99272013-06-25 13:17:36 -070074int32_t Instruction::GetTargetOffset() const {
75 switch (FormatOf(Opcode())) {
76 // Cases for conditional branches follow.
77 case k22t: return VRegC_22t();
78 case k21t: return VRegB_21t();
79 // Cases for unconditional branches follow.
80 case k10t: return VRegA_10t();
81 case k20t: return VRegA_20t();
82 case k30t: return VRegA_30t();
83 default: LOG(FATAL) << "Tried to access the branch offset of an instruction " << Name() <<
84 " which does not have a target operand.";
85 }
86 return 0;
87}
88
89bool Instruction::CanFlowThrough() const {
90 const uint16_t* insns = reinterpret_cast<const uint16_t*>(this);
91 uint16_t insn = *insns;
92 Code opcode = static_cast<Code>(insn & 0xFF);
93 return FlagsOf(opcode) & Instruction::kContinue;
94}
95
Ian Rogersa75a0132012-09-28 11:41:42 -070096size_t Instruction::SizeInCodeUnitsComplexOpcode() const {
Carl Shapiro12eb78e2011-06-24 14:51:06 -070097 const uint16_t* insns = reinterpret_cast<const uint16_t*>(this);
Ian Rogersa75a0132012-09-28 11:41:42 -070098 // Handle special NOP encoded variable length sequences.
99 switch (*insns) {
100 case kPackedSwitchSignature:
101 return (4 + insns[1] * 2);
102 case kSparseSwitchSignature:
103 return (2 + insns[1] * 4);
104 case kArrayDataSignature: {
105 uint16_t element_size = insns[1];
106 uint32_t length = insns[2] | (((uint32_t)insns[3]) << 16);
107 // The plus 1 is to round up for odd size and width.
108 return (4 + (element_size * length + 1) / 2);
Carl Shapiroe4c1ce42011-07-09 02:31:57 -0700109 }
Ian Rogersa75a0132012-09-28 11:41:42 -0700110 default:
111 if ((*insns & 0xFF) == 0) {
112 return 1; // NOP.
113 } else {
Ian Rogersfc787ec2014-10-09 21:56:44 -0700114 LOG(FATAL) << "Unreachable: " << DumpString(nullptr);
Ian Rogersa75a0132012-09-28 11:41:42 -0700115 return 0;
116 }
Carl Shapiroe4c1ce42011-07-09 02:31:57 -0700117 }
Ian Rogersd81871c2011-10-03 13:57:23 -0700118}
119
Ian Rogers2c8a8572011-10-24 17:11:36 -0700120std::string Instruction::DumpHex(size_t code_units) const {
Ian Rogersd81871c2011-10-03 13:57:23 -0700121 size_t inst_length = SizeInCodeUnits();
122 if (inst_length > code_units) {
123 inst_length = code_units;
124 }
Ian Rogers2c8a8572011-10-24 17:11:36 -0700125 std::ostringstream os;
Ian Rogersd81871c2011-10-03 13:57:23 -0700126 const uint16_t* insn = reinterpret_cast<const uint16_t*>(this);
127 for (size_t i = 0; i < inst_length; i++) {
Ian Rogers2c8a8572011-10-24 17:11:36 -0700128 os << StringPrintf("0x%04x", insn[i]) << " ";
Ian Rogersd81871c2011-10-03 13:57:23 -0700129 }
130 for (size_t i = inst_length; i < code_units; i++) {
131 os << " ";
132 }
Ian Rogers2c8a8572011-10-24 17:11:36 -0700133 return os.str();
Ian Rogersd81871c2011-10-03 13:57:23 -0700134}
135
Ian Rogers2c8a8572011-10-24 17:11:36 -0700136std::string Instruction::DumpString(const DexFile* file) const {
Ian Rogers2c8a8572011-10-24 17:11:36 -0700137 std::ostringstream os;
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200138 const char* opcode = kInstructionNames[Opcode()];
Elliott Hughesadb8c672012-03-06 16:49:32 -0800139 switch (FormatOf(Opcode())) {
Elliott Hughese3c845c2012-02-28 17:23:01 -0800140 case k10x: os << opcode; break;
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200141 case k12x: os << StringPrintf("%s v%d, v%d", opcode, VRegA_12x(), VRegB_12x()); break;
142 case k11n: os << StringPrintf("%s v%d, #%+d", opcode, VRegA_11n(), VRegB_11n()); break;
143 case k11x: os << StringPrintf("%s v%d", opcode, VRegA_11x()); break;
144 case k10t: os << StringPrintf("%s %+d", opcode, VRegA_10t()); break;
145 case k20t: os << StringPrintf("%s %+d", opcode, VRegA_20t()); break;
146 case k22x: os << StringPrintf("%s v%d, v%d", opcode, VRegA_22x(), VRegB_22x()); break;
147 case k21t: os << StringPrintf("%s v%d, %+d", opcode, VRegA_21t(), VRegB_21t()); break;
148 case k21s: os << StringPrintf("%s v%d, #%+d", opcode, VRegA_21s(), VRegB_21s()); break;
Elliott Hughes1b3d6ca2012-04-25 13:00:14 -0700149 case k21h: {
150 // op vAA, #+BBBB0000[00000000]
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200151 if (Opcode() == CONST_HIGH16) {
152 uint32_t value = VRegB_21h() << 16;
153 os << StringPrintf("%s v%d, #int %+d // 0x%x", opcode, VRegA_21h(), value, value);
Elliott Hughes1b3d6ca2012-04-25 13:00:14 -0700154 } else {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200155 uint64_t value = static_cast<uint64_t>(VRegB_21h()) << 48;
Ian Rogersb574c182014-01-23 19:51:19 -0800156 os << StringPrintf("%s v%d, #long %+" PRId64 " // 0x%" PRIx64, opcode, VRegA_21h(),
157 value, value);
Elliott Hughes1b3d6ca2012-04-25 13:00:14 -0700158 }
159 }
160 break;
Ian Rogers90334e52012-06-06 20:22:20 -0700161 case k21c: {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200162 switch (Opcode()) {
Ian Rogers90334e52012-06-06 20:22:20 -0700163 case CONST_STRING:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700164 if (file != nullptr) {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200165 uint32_t string_idx = VRegB_21c();
166 os << StringPrintf("const-string v%d, %s // string@%d", VRegA_21c(),
167 PrintableString(file->StringDataByIdx(string_idx)).c_str(), string_idx);
Ian Rogers90334e52012-06-06 20:22:20 -0700168 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700169 }
170 FALLTHROUGH_INTENDED;
Mathieu Chartier18c24b62012-09-10 08:54:25 -0700171 case CHECK_CAST:
172 case CONST_CLASS:
Ian Rogers90334e52012-06-06 20:22:20 -0700173 case NEW_INSTANCE:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700174 if (file != nullptr) {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200175 uint32_t type_idx = VRegB_21c();
Dragos Sbirleab43cef32013-05-23 11:59:20 -0700176 os << opcode << " v" << static_cast<int>(VRegA_21c()) << ", " << PrettyType(type_idx, *file)
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200177 << " // type@" << type_idx;
Ian Rogers90334e52012-06-06 20:22:20 -0700178 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700179 }
180 FALLTHROUGH_INTENDED;
Ian Rogers90334e52012-06-06 20:22:20 -0700181 case SGET:
182 case SGET_WIDE:
183 case SGET_OBJECT:
184 case SGET_BOOLEAN:
185 case SGET_BYTE:
186 case SGET_CHAR:
187 case SGET_SHORT:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700188 if (file != nullptr) {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200189 uint32_t field_idx = VRegB_21c();
Dragos Sbirleab43cef32013-05-23 11:59:20 -0700190 os << opcode << " v" << static_cast<int>(VRegA_21c()) << ", " << PrettyField(field_idx, *file, true)
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200191 << " // field@" << field_idx;
Ian Rogers90334e52012-06-06 20:22:20 -0700192 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700193 }
194 FALLTHROUGH_INTENDED;
Ian Rogers90334e52012-06-06 20:22:20 -0700195 case SPUT:
196 case SPUT_WIDE:
197 case SPUT_OBJECT:
198 case SPUT_BOOLEAN:
199 case SPUT_BYTE:
200 case SPUT_CHAR:
201 case SPUT_SHORT:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700202 if (file != nullptr) {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200203 uint32_t field_idx = VRegB_21c();
Dragos Sbirleab43cef32013-05-23 11:59:20 -0700204 os << opcode << " v" << static_cast<int>(VRegA_21c()) << ", " << PrettyField(field_idx, *file, true)
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200205 << " // field@" << field_idx;
Ian Rogers90334e52012-06-06 20:22:20 -0700206 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700207 }
208 FALLTHROUGH_INTENDED;
Ian Rogers90334e52012-06-06 20:22:20 -0700209 default:
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200210 os << StringPrintf("%s v%d, thing@%d", opcode, VRegA_21c(), VRegB_21c());
Ian Rogers90334e52012-06-06 20:22:20 -0700211 break;
212 }
213 break;
214 }
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200215 case k23x: os << StringPrintf("%s v%d, v%d, v%d", opcode, VRegA_23x(), VRegB_23x(), VRegC_23x()); break;
216 case k22b: os << StringPrintf("%s v%d, v%d, #%+d", opcode, VRegA_22b(), VRegB_22b(), VRegC_22b()); break;
217 case k22t: os << StringPrintf("%s v%d, v%d, %+d", opcode, VRegA_22t(), VRegB_22t(), VRegC_22t()); break;
218 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 -0700219 case k22c: {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200220 switch (Opcode()) {
Ian Rogers90334e52012-06-06 20:22:20 -0700221 case IGET:
222 case IGET_WIDE:
223 case IGET_OBJECT:
224 case IGET_BOOLEAN:
225 case IGET_BYTE:
226 case IGET_CHAR:
227 case IGET_SHORT:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700228 if (file != nullptr) {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200229 uint32_t field_idx = VRegC_22c();
Dragos Sbirleab43cef32013-05-23 11:59:20 -0700230 os << opcode << " v" << static_cast<int>(VRegA_22c()) << ", v" << static_cast<int>(VRegB_22c()) << ", "
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200231 << PrettyField(field_idx, *file, true) << " // field@" << field_idx;
Ian Rogers90334e52012-06-06 20:22:20 -0700232 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700233 }
234 FALLTHROUGH_INTENDED;
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200235 case IGET_QUICK:
236 case IGET_OBJECT_QUICK:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700237 if (file != nullptr) {
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200238 uint32_t field_idx = VRegC_22c();
239 os << opcode << " v" << static_cast<int>(VRegA_22c()) << ", v" << static_cast<int>(VRegB_22c()) << ", "
240 << "// offset@" << field_idx;
241 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700242 }
243 FALLTHROUGH_INTENDED;
Ian Rogers90334e52012-06-06 20:22:20 -0700244 case IPUT:
245 case IPUT_WIDE:
246 case IPUT_OBJECT:
247 case IPUT_BOOLEAN:
248 case IPUT_BYTE:
249 case IPUT_CHAR:
250 case IPUT_SHORT:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700251 if (file != nullptr) {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200252 uint32_t field_idx = VRegC_22c();
Dragos Sbirleab43cef32013-05-23 11:59:20 -0700253 os << opcode << " v" << static_cast<int>(VRegA_22c()) << ", v" << static_cast<int>(VRegB_22c()) << ", "
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200254 << PrettyField(field_idx, *file, true) << " // field@" << field_idx;
Ian Rogers90334e52012-06-06 20:22:20 -0700255 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700256 }
257 FALLTHROUGH_INTENDED;
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200258 case IPUT_QUICK:
259 case IPUT_OBJECT_QUICK:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700260 if (file != nullptr) {
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200261 uint32_t field_idx = VRegC_22c();
262 os << opcode << " v" << static_cast<int>(VRegA_22c()) << ", v" << static_cast<int>(VRegB_22c()) << ", "
263 << "// offset@" << field_idx;
264 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700265 }
266 FALLTHROUGH_INTENDED;
Ian Rogers90334e52012-06-06 20:22:20 -0700267 case INSTANCE_OF:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700268 if (file != nullptr) {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200269 uint32_t type_idx = VRegC_22c();
Dragos Sbirlead4e868a2013-05-23 09:44:17 -0700270 os << opcode << " v" << static_cast<int>(VRegA_22c()) << ", v" << static_cast<int>(VRegB_22c()) << ", "
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200271 << PrettyType(type_idx, *file) << " // type@" << type_idx;
Mathieu Chartier18c24b62012-09-10 08:54:25 -0700272 break;
273 }
Ian Rogersfc787ec2014-10-09 21:56:44 -0700274 FALLTHROUGH_INTENDED;
Mathieu Chartier18c24b62012-09-10 08:54:25 -0700275 case NEW_ARRAY:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700276 if (file != nullptr) {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200277 uint32_t type_idx = VRegC_22c();
Dragos Sbirleab43cef32013-05-23 11:59:20 -0700278 os << opcode << " v" << static_cast<int>(VRegA_22c()) << ", v" << static_cast<int>(VRegB_22c()) << ", "
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200279 << PrettyType(type_idx, *file) << " // type@" << type_idx;
Ian Rogers90334e52012-06-06 20:22:20 -0700280 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700281 }
282 FALLTHROUGH_INTENDED;
Ian Rogers90334e52012-06-06 20:22:20 -0700283 default:
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200284 os << StringPrintf("%s v%d, v%d, thing@%d", opcode, VRegA_22c(), VRegB_22c(), VRegC_22c());
Ian Rogers90334e52012-06-06 20:22:20 -0700285 break;
286 }
287 break;
288 }
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200289 case k32x: os << StringPrintf("%s v%d, v%d", opcode, VRegA_32x(), VRegB_32x()); break;
290 case k30t: os << StringPrintf("%s %+d", opcode, VRegA_30t()); break;
291 case k31t: os << StringPrintf("%s v%d, %+d", opcode, VRegA_31t(), VRegB_31t()); break;
292 case k31i: os << StringPrintf("%s v%d, #%+d", opcode, VRegA_31i(), VRegB_31i()); break;
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700293 case k31c:
294 if (Opcode() == CONST_STRING_JUMBO) {
295 uint32_t string_idx = VRegB_31c();
Ian Rogersfc787ec2014-10-09 21:56:44 -0700296 if (file != nullptr) {
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700297 os << StringPrintf("%s v%d, %s // string@%d", opcode, VRegA_31c(),
298 PrintableString(file->StringDataByIdx(string_idx)).c_str(),
299 string_idx);
300 } else {
301 os << StringPrintf("%s v%d, string@%d", opcode, VRegA_31c(), string_idx);
302 }
303 } else {
304 os << StringPrintf("%s v%d, thing@%d", opcode, VRegA_31c(), VRegB_31c()); break;
305 }
306 break;
Ian Rogersd81871c2011-10-03 13:57:23 -0700307 case k35c: {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200308 uint32_t arg[5];
Ian Rogers29a26482014-05-02 15:27:29 -0700309 GetVarArgs(arg);
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200310 switch (Opcode()) {
Andreas Gampe7aca91d2014-03-31 18:10:53 -0700311 case FILLED_NEW_ARRAY:
312 {
313 const int32_t a = VRegA_35c();
314 os << opcode << " {";
315 for (int i = 0; i < a; ++i) {
316 if (i > 0) {
317 os << ", ";
318 }
319 os << "v" << arg[i];
320 }
321 os << "}, type@" << VRegB_35c();
322 }
323 break;
324
Ian Rogersd81871c2011-10-03 13:57:23 -0700325 case INVOKE_VIRTUAL:
326 case INVOKE_SUPER:
327 case INVOKE_DIRECT:
328 case INVOKE_STATIC:
329 case INVOKE_INTERFACE:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700330 if (file != nullptr) {
Elliott Hughese3c845c2012-02-28 17:23:01 -0800331 os << opcode << " {";
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200332 uint32_t method_idx = VRegB_35c();
333 for (size_t i = 0; i < VRegA_35c(); ++i) {
Elliott Hughese3c845c2012-02-28 17:23:01 -0800334 if (i != 0) {
335 os << ", ";
336 }
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200337 os << "v" << arg[i];
Elliott Hughese3c845c2012-02-28 17:23:01 -0800338 }
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200339 os << "}, " << PrettyMethod(method_idx, *file) << " // method@" << method_idx;
Ian Rogersd81871c2011-10-03 13:57:23 -0700340 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700341 }
342 FALLTHROUGH_INTENDED;
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200343 case INVOKE_VIRTUAL_QUICK:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700344 if (file != nullptr) {
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200345 os << opcode << " {";
346 uint32_t method_idx = VRegB_35c();
347 for (size_t i = 0; i < VRegA_35c(); ++i) {
348 if (i != 0) {
349 os << ", ";
350 }
351 os << "v" << arg[i];
352 }
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700353 os << "}, // vtable@" << method_idx;
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200354 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700355 }
356 FALLTHROUGH_INTENDED;
Ian Rogersd81871c2011-10-03 13:57:23 -0700357 default:
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200358 os << opcode << " {v" << arg[0] << ", v" << arg[1] << ", v" << arg[2]
359 << ", v" << arg[3] << ", v" << arg[4] << "}, thing@" << VRegB_35c();
Ian Rogersd81871c2011-10-03 13:57:23 -0700360 break;
361 }
362 break;
363 }
Ian Rogers4c5dd5a2012-09-07 11:27:28 -0700364 case k3rc: {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200365 switch (Opcode()) {
Ian Rogers4c5dd5a2012-09-07 11:27:28 -0700366 case INVOKE_VIRTUAL_RANGE:
367 case INVOKE_SUPER_RANGE:
368 case INVOKE_DIRECT_RANGE:
369 case INVOKE_STATIC_RANGE:
370 case INVOKE_INTERFACE_RANGE:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700371 if (file != nullptr) {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200372 uint32_t method_idx = VRegB_3rc();
373 os << StringPrintf("%s, {v%d .. v%d}, ", opcode, VRegC_3rc(), (VRegC_3rc() + VRegA_3rc() - 1))
374 << PrettyMethod(method_idx, *file) << " // method@" << method_idx;
Ian Rogers4c5dd5a2012-09-07 11:27:28 -0700375 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700376 }
377 FALLTHROUGH_INTENDED;
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200378 case INVOKE_VIRTUAL_RANGE_QUICK:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700379 if (file != nullptr) {
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200380 uint32_t method_idx = VRegB_3rc();
381 os << StringPrintf("%s, {v%d .. v%d}, ", opcode, VRegC_3rc(), (VRegC_3rc() + VRegA_3rc() - 1))
382 << "// vtable@" << method_idx;
383 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700384 }
385 FALLTHROUGH_INTENDED;
Ian Rogers4c5dd5a2012-09-07 11:27:28 -0700386 default:
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200387 os << StringPrintf("%s, {v%d .. v%d}, thing@%d", opcode, VRegC_3rc(),
388 (VRegC_3rc() + VRegA_3rc() - 1), VRegB_3rc());
Ian Rogers4c5dd5a2012-09-07 11:27:28 -0700389 break;
390 }
391 break;
392 }
Ian Rogersb574c182014-01-23 19:51:19 -0800393 case k51l: os << StringPrintf("%s v%d, #%+" PRId64, opcode, VRegA_51l(), VRegB_51l()); break;
Ian Rogers2c8a8572011-10-24 17:11:36 -0700394 default: os << " unknown format (" << DumpHex(5) << ")"; break;
Ian Rogersd81871c2011-10-03 13:57:23 -0700395 }
Ian Rogers2c8a8572011-10-24 17:11:36 -0700396 return os.str();
Carl Shapiro12eb78e2011-06-24 14:51:06 -0700397}
398
Ian Rogersa75a0132012-09-28 11:41:42 -0700399std::ostream& operator<<(std::ostream& os, const Instruction::Code& code) {
400 return os << Instruction::Name(code);
Elliott Hughesadb8c672012-03-06 16:49:32 -0800401}
402
Carl Shapiro12eb78e2011-06-24 14:51:06 -0700403} // namespace art