OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/disassembler.h" | 5 #include "vm/disassembler.h" |
6 | 6 |
7 #include "vm/globals.h" // Needed here to get TARGET_ARCH_DBC. | 7 #include "vm/globals.h" // Needed here to get TARGET_ARCH_DBC. |
8 #if defined(TARGET_ARCH_DBC) | 8 #if defined(TARGET_ARCH_DBC) |
9 | 9 |
10 #include "platform/assert.h" | 10 #include "platform/assert.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 | 22 |
23 static const size_t kOpcodeCount = | 23 static const size_t kOpcodeCount = |
24 sizeof(kOpcodeNames) / sizeof(kOpcodeNames[0]); | 24 sizeof(kOpcodeNames) / sizeof(kOpcodeNames[0]); |
25 | 25 |
26 typedef void (*BytecodeFormatter)(char* buffer, | 26 typedef void (*BytecodeFormatter)(char* buffer, |
27 intptr_t size, | 27 intptr_t size, |
28 uword pc, | 28 uword pc, |
29 uint32_t bc); | 29 uint32_t bc); |
30 typedef void (*Fmt)(char** buf, intptr_t* size, uword pc, int32_t value); | 30 typedef void (*Fmt)(char** buf, intptr_t* size, uword pc, int32_t value); |
31 | 31 |
32 | |
33 template <typename ValueType> | 32 template <typename ValueType> |
34 void FormatOperand(char** buf, | 33 void FormatOperand(char** buf, |
35 intptr_t* size, | 34 intptr_t* size, |
36 const char* fmt, | 35 const char* fmt, |
37 ValueType value) { | 36 ValueType value) { |
38 intptr_t written = OS::SNPrint(*buf, *size, fmt, value); | 37 intptr_t written = OS::SNPrint(*buf, *size, fmt, value); |
39 if (written < *size) { | 38 if (written < *size) { |
40 *buf += written; | 39 *buf += written; |
41 *size += written; | 40 *size += written; |
42 } else { | 41 } else { |
43 *size = -1; | 42 *size = -1; |
44 } | 43 } |
45 } | 44 } |
46 | 45 |
47 | |
48 static void Fmt___(char** buf, intptr_t* size, uword pc, int32_t value) {} | 46 static void Fmt___(char** buf, intptr_t* size, uword pc, int32_t value) {} |
49 | 47 |
50 | |
51 static void Fmttgt(char** buf, intptr_t* size, uword pc, int32_t value) { | 48 static void Fmttgt(char** buf, intptr_t* size, uword pc, int32_t value) { |
52 FormatOperand(buf, size, "-> %" Px, pc + (value << 2)); | 49 FormatOperand(buf, size, "-> %" Px, pc + (value << 2)); |
53 } | 50 } |
54 | 51 |
55 | |
56 static void Fmtlit(char** buf, intptr_t* size, uword pc, int32_t value) { | 52 static void Fmtlit(char** buf, intptr_t* size, uword pc, int32_t value) { |
57 FormatOperand(buf, size, "k%d", value); | 53 FormatOperand(buf, size, "k%d", value); |
58 } | 54 } |
59 | 55 |
60 | |
61 static void Fmtreg(char** buf, intptr_t* size, uword pc, int32_t value) { | 56 static void Fmtreg(char** buf, intptr_t* size, uword pc, int32_t value) { |
62 FormatOperand(buf, size, "r%d", value); | 57 FormatOperand(buf, size, "r%d", value); |
63 } | 58 } |
64 | 59 |
65 | |
66 static void Fmtxeg(char** buf, intptr_t* size, uword pc, int32_t value) { | 60 static void Fmtxeg(char** buf, intptr_t* size, uword pc, int32_t value) { |
67 if (value < 0) { | 61 if (value < 0) { |
68 FormatOperand(buf, size, "FP[%d]", value); | 62 FormatOperand(buf, size, "FP[%d]", value); |
69 } else { | 63 } else { |
70 Fmtreg(buf, size, pc, value); | 64 Fmtreg(buf, size, pc, value); |
71 } | 65 } |
72 } | 66 } |
73 | 67 |
74 | |
75 static void Fmtnum(char** buf, intptr_t* size, uword pc, int32_t value) { | 68 static void Fmtnum(char** buf, intptr_t* size, uword pc, int32_t value) { |
76 FormatOperand(buf, size, "#%d", value); | 69 FormatOperand(buf, size, "#%d", value); |
77 } | 70 } |
78 | 71 |
79 | |
80 static void Apply(char** buf, | 72 static void Apply(char** buf, |
81 intptr_t* size, | 73 intptr_t* size, |
82 uword pc, | 74 uword pc, |
83 Fmt fmt, | 75 Fmt fmt, |
84 int32_t value, | 76 int32_t value, |
85 const char* suffix) { | 77 const char* suffix) { |
86 if (*size <= 0) { | 78 if (*size <= 0) { |
87 return; | 79 return; |
88 } | 80 } |
89 | 81 |
90 fmt(buf, size, pc, value); | 82 fmt(buf, size, pc, value); |
91 if (*size > 0) { | 83 if (*size > 0) { |
92 FormatOperand(buf, size, "%s", suffix); | 84 FormatOperand(buf, size, "%s", suffix); |
93 } | 85 } |
94 } | 86 } |
95 | 87 |
96 | |
97 static void Format0(char* buf, | 88 static void Format0(char* buf, |
98 intptr_t size, | 89 intptr_t size, |
99 uword pc, | 90 uword pc, |
100 uint32_t op, | 91 uint32_t op, |
101 Fmt op1, | 92 Fmt op1, |
102 Fmt op2, | 93 Fmt op2, |
103 Fmt op3) {} | 94 Fmt op3) {} |
104 | 95 |
105 | |
106 static void FormatT(char* buf, | 96 static void FormatT(char* buf, |
107 intptr_t size, | 97 intptr_t size, |
108 uword pc, | 98 uword pc, |
109 uint32_t op, | 99 uint32_t op, |
110 Fmt op1, | 100 Fmt op1, |
111 Fmt op2, | 101 Fmt op2, |
112 Fmt op3) { | 102 Fmt op3) { |
113 const int32_t x = static_cast<int32_t>(op) >> 8; | 103 const int32_t x = static_cast<int32_t>(op) >> 8; |
114 Apply(&buf, &size, pc, op1, x, ""); | 104 Apply(&buf, &size, pc, op1, x, ""); |
115 } | 105 } |
116 | 106 |
117 | |
118 static void FormatA(char* buf, | 107 static void FormatA(char* buf, |
119 intptr_t size, | 108 intptr_t size, |
120 uword pc, | 109 uword pc, |
121 uint32_t op, | 110 uint32_t op, |
122 Fmt op1, | 111 Fmt op1, |
123 Fmt op2, | 112 Fmt op2, |
124 Fmt op3) { | 113 Fmt op3) { |
125 const int32_t a = (op & 0xFF00) >> 8; | 114 const int32_t a = (op & 0xFF00) >> 8; |
126 Apply(&buf, &size, pc, op1, a, ""); | 115 Apply(&buf, &size, pc, op1, a, ""); |
127 } | 116 } |
128 | 117 |
129 | |
130 static void FormatA_D(char* buf, | 118 static void FormatA_D(char* buf, |
131 intptr_t size, | 119 intptr_t size, |
132 uword pc, | 120 uword pc, |
133 uint32_t op, | 121 uint32_t op, |
134 Fmt op1, | 122 Fmt op1, |
135 Fmt op2, | 123 Fmt op2, |
136 Fmt op3) { | 124 Fmt op3) { |
137 const int32_t a = (op & 0xFF00) >> 8; | 125 const int32_t a = (op & 0xFF00) >> 8; |
138 const int32_t bc = op >> 16; | 126 const int32_t bc = op >> 16; |
139 Apply(&buf, &size, pc, op1, a, ", "); | 127 Apply(&buf, &size, pc, op1, a, ", "); |
140 Apply(&buf, &size, pc, op2, bc, ""); | 128 Apply(&buf, &size, pc, op2, bc, ""); |
141 } | 129 } |
142 | 130 |
143 | |
144 static void FormatA_X(char* buf, | 131 static void FormatA_X(char* buf, |
145 intptr_t size, | 132 intptr_t size, |
146 uword pc, | 133 uword pc, |
147 uint32_t op, | 134 uint32_t op, |
148 Fmt op1, | 135 Fmt op1, |
149 Fmt op2, | 136 Fmt op2, |
150 Fmt op3) { | 137 Fmt op3) { |
151 const int32_t a = (op & 0xFF00) >> 8; | 138 const int32_t a = (op & 0xFF00) >> 8; |
152 const int32_t bc = static_cast<int32_t>(op) >> 16; | 139 const int32_t bc = static_cast<int32_t>(op) >> 16; |
153 Apply(&buf, &size, pc, op1, a, ", "); | 140 Apply(&buf, &size, pc, op1, a, ", "); |
154 Apply(&buf, &size, pc, op2, bc, ""); | 141 Apply(&buf, &size, pc, op2, bc, ""); |
155 } | 142 } |
156 | 143 |
157 | |
158 static void FormatX(char* buf, | 144 static void FormatX(char* buf, |
159 intptr_t size, | 145 intptr_t size, |
160 uword pc, | 146 uword pc, |
161 uint32_t op, | 147 uint32_t op, |
162 Fmt op1, | 148 Fmt op1, |
163 Fmt op2, | 149 Fmt op2, |
164 Fmt op3) { | 150 Fmt op3) { |
165 const int32_t bc = static_cast<int32_t>(op) >> 16; | 151 const int32_t bc = static_cast<int32_t>(op) >> 16; |
166 Apply(&buf, &size, pc, op1, bc, ""); | 152 Apply(&buf, &size, pc, op1, bc, ""); |
167 } | 153 } |
168 | 154 |
169 | |
170 static void FormatD(char* buf, | 155 static void FormatD(char* buf, |
171 intptr_t size, | 156 intptr_t size, |
172 uword pc, | 157 uword pc, |
173 uint32_t op, | 158 uint32_t op, |
174 Fmt op1, | 159 Fmt op1, |
175 Fmt op2, | 160 Fmt op2, |
176 Fmt op3) { | 161 Fmt op3) { |
177 const int32_t bc = op >> 16; | 162 const int32_t bc = op >> 16; |
178 Apply(&buf, &size, pc, op1, bc, ""); | 163 Apply(&buf, &size, pc, op1, bc, ""); |
179 } | 164 } |
180 | 165 |
181 | |
182 static void FormatA_B_C(char* buf, | 166 static void FormatA_B_C(char* buf, |
183 intptr_t size, | 167 intptr_t size, |
184 uword pc, | 168 uword pc, |
185 uint32_t op, | 169 uint32_t op, |
186 Fmt op1, | 170 Fmt op1, |
187 Fmt op2, | 171 Fmt op2, |
188 Fmt op3) { | 172 Fmt op3) { |
189 const int32_t a = (op >> 8) & 0xFF; | 173 const int32_t a = (op >> 8) & 0xFF; |
190 const int32_t b = (op >> 16) & 0xFF; | 174 const int32_t b = (op >> 16) & 0xFF; |
191 const int32_t c = (op >> 24) & 0xFF; | 175 const int32_t c = (op >> 24) & 0xFF; |
192 Apply(&buf, &size, pc, op1, a, ", "); | 176 Apply(&buf, &size, pc, op1, a, ", "); |
193 Apply(&buf, &size, pc, op2, b, ", "); | 177 Apply(&buf, &size, pc, op2, b, ", "); |
194 Apply(&buf, &size, pc, op3, c, ""); | 178 Apply(&buf, &size, pc, op3, c, ""); |
195 } | 179 } |
196 | 180 |
197 | |
198 #define BYTECODE_FORMATTER(name, encoding, op1, op2, op3) \ | 181 #define BYTECODE_FORMATTER(name, encoding, op1, op2, op3) \ |
199 static void Format##name(char* buf, intptr_t size, uword pc, uint32_t op) { \ | 182 static void Format##name(char* buf, intptr_t size, uword pc, uint32_t op) { \ |
200 Format##encoding(buf, size, pc, op, Fmt##op1, Fmt##op2, Fmt##op3); \ | 183 Format##encoding(buf, size, pc, op, Fmt##op1, Fmt##op2, Fmt##op3); \ |
201 } | 184 } |
202 BYTECODES_LIST(BYTECODE_FORMATTER) | 185 BYTECODES_LIST(BYTECODE_FORMATTER) |
203 #undef BYTECODE_FORMATTER | 186 #undef BYTECODE_FORMATTER |
204 | 187 |
205 | |
206 static const BytecodeFormatter kFormatters[] = { | 188 static const BytecodeFormatter kFormatters[] = { |
207 #define BYTECODE_FORMATTER(name, encoding, op1, op2, op3) &Format##name, | 189 #define BYTECODE_FORMATTER(name, encoding, op1, op2, op3) &Format##name, |
208 BYTECODES_LIST(BYTECODE_FORMATTER) | 190 BYTECODES_LIST(BYTECODE_FORMATTER) |
209 #undef BYTECODE_FORMATTER | 191 #undef BYTECODE_FORMATTER |
210 }; | 192 }; |
211 | 193 |
212 | |
213 void Disassembler::DecodeInstruction(char* hex_buffer, | 194 void Disassembler::DecodeInstruction(char* hex_buffer, |
214 intptr_t hex_size, | 195 intptr_t hex_size, |
215 char* human_buffer, | 196 char* human_buffer, |
216 intptr_t human_size, | 197 intptr_t human_size, |
217 int* out_instr_size, | 198 int* out_instr_size, |
218 const Code& code, | 199 const Code& code, |
219 Object** object, | 200 Object** object, |
220 uword pc) { | 201 uword pc) { |
221 const uint32_t instr = *reinterpret_cast<uint32_t*>(pc); | 202 const uint32_t instr = *reinterpret_cast<uint32_t*>(pc); |
222 const uint8_t opcode = instr & 0xFF; | 203 const uint8_t opcode = instr & 0xFF; |
(...skipping 12 matching lines...) Expand all Loading... |
235 | 216 |
236 *object = NULL; | 217 *object = NULL; |
237 if (!code.IsNull()) { | 218 if (!code.IsNull()) { |
238 *object = &Object::Handle(); | 219 *object = &Object::Handle(); |
239 if (!DecodeLoadObjectFromPoolOrThread(pc, code, *object)) { | 220 if (!DecodeLoadObjectFromPoolOrThread(pc, code, *object)) { |
240 *object = NULL; | 221 *object = NULL; |
241 } | 222 } |
242 } | 223 } |
243 } | 224 } |
244 | 225 |
245 | |
246 } // namespace dart | 226 } // namespace dart |
247 | 227 |
248 #endif // defined TARGET_ARCH_DBC | 228 #endif // defined TARGET_ARCH_DBC |
OLD | NEW |