OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <vector> | 5 #include <vector> |
6 | 6 |
7 #include "src/v8.h" | 7 #include "src/v8.h" |
8 | 8 |
9 #include "src/interpreter/bytecodes.h" | 9 #include "src/interpreter/bytecodes.h" |
10 #include "test/unittests/test-utils.h" | 10 #include "test/unittests/test-utils.h" |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 | 170 |
171 TEST(Bytecodes, DecodeBytecodeAndOperands) { | 171 TEST(Bytecodes, DecodeBytecodeAndOperands) { |
172 struct BytecodesAndResult { | 172 struct BytecodesAndResult { |
173 const uint8_t bytecode[32]; | 173 const uint8_t bytecode[32]; |
174 const size_t length; | 174 const size_t length; |
175 int parameter_count; | 175 int parameter_count; |
176 const char* output; | 176 const char* output; |
177 }; | 177 }; |
178 | 178 |
179 #define B(Name) static_cast<uint8_t>(Bytecode::k##Name) | 179 #define B(Name) static_cast<uint8_t>(Bytecode::k##Name) |
180 #define REG_OPERAND(i) \ | |
181 (InterpreterFrameConstants::kRegisterFileFromFp / kPointerSize - (i)) | |
182 #define REG8(i) static_cast<uint8_t>(REG_OPERAND(i)) | |
183 #if V8_TARGET_LITTLE_ENDIAN | |
184 #define REG16(i) \ | |
185 static_cast<uint8_t>(REG_OPERAND(i)), \ | |
186 static_cast<uint8_t>(REG_OPERAND(i) >> 8) | |
187 #elif V8_TARGET_BIG_ENDIAN | |
188 #define REG16(i) \ | |
189 static_cast<uint8_t>(REG_OPERAND(i) >> 8), \ | |
190 static_cast<uint8_t>(REG_OPERAND(i)) | |
191 #else | |
192 #error "Unknown Architecture" | |
193 #endif | |
194 const BytecodesAndResult cases[] = { | 180 const BytecodesAndResult cases[] = { |
195 #if V8_TARGET_LITTLE_ENDIAN | 181 #if V8_TARGET_LITTLE_ENDIAN |
196 {{B(LdaSmi), 0x01}, 2, 0, " LdaSmi [1]"}, | 182 {{B(LdaSmi), 0x01}, 2, 0, " LdaSmi [1]"}, |
197 {{B(Wide), B(LdaSmi), 0xe8, 0x03}, 4, 0, " LdaSmi.Wide [1000]"}, | 183 {{B(Wide), B(LdaSmi), 0xe8, 0x03}, 4, 0, " LdaSmi.Wide [1000]"}, |
198 {{B(ExtraWide), B(LdaSmi), 0xa0, 0x86, 0x01, 0x00}, | 184 {{B(ExtraWide), B(LdaSmi), 0xa0, 0x86, 0x01, 0x00}, |
199 6, | 185 6, |
200 0, | 186 0, |
201 "LdaSmi.ExtraWide [100000]"}, | 187 "LdaSmi.ExtraWide [100000]"}, |
202 {{B(LdaSmi), 0xff}, 2, 0, " LdaSmi [-1]"}, | 188 {{B(LdaSmi), 0xff}, 2, 0, " LdaSmi [-1]"}, |
203 {{B(Wide), B(LdaSmi), 0x18, 0xfc}, 4, 0, " LdaSmi.Wide [-1000]"}, | 189 {{B(Wide), B(LdaSmi), 0x18, 0xfc}, 4, 0, " LdaSmi.Wide [-1000]"}, |
204 {{B(ExtraWide), B(LdaSmi), 0x60, 0x79, 0xfe, 0xff}, | 190 {{B(ExtraWide), B(LdaSmi), 0x60, 0x79, 0xfe, 0xff}, |
205 6, | 191 6, |
206 0, | 192 0, |
207 "LdaSmi.ExtraWide [-100000]"}, | 193 "LdaSmi.ExtraWide [-100000]"}, |
208 {{B(Star), REG8(5)}, 2, 0, " Star r5"}, | 194 {{B(Star), 0xf5}, 2, 0, " Star r5"}, |
209 {{B(Wide), B(Star), REG16(136)}, 4, 0, " Star.Wide r136"}, | 195 {{B(Wide), B(Star), 0x72, 0xff}, 4, 0, " Star.Wide r136"}, |
210 {{B(Wide), B(Call), REG16(134), REG16(135), 0x02, 0x00, 0xb1, 0x00}, | 196 {{B(Wide), B(Call), 0x74, 0xff, 0x73, 0xff, 0x02, 0x00, 0xb1, 0x00}, |
211 10, | 197 10, |
212 0, | 198 0, |
213 "Call.Wide r134, r135, #2, [177]"}, | 199 "Call.Wide r134, r135, #2, [177]"}, |
214 {{B(Ldar), | 200 {{B(Ldar), |
215 static_cast<uint8_t>(Register::FromParameterIndex(2, 3).ToOperand())}, | 201 static_cast<uint8_t>(Register::FromParameterIndex(2, 3).ToOperand())}, |
216 2, | 202 2, |
217 3, | 203 3, |
218 " Ldar a1"}, | 204 " Ldar a1"}, |
219 {{B(Wide), B(CreateObjectLiteral), 0x01, 0x02, 0x03, 0x04, 0xa5}, | 205 {{B(Wide), B(CreateObjectLiteral), 0x01, 0x02, 0x03, 0x04, 0xa5}, |
220 7, | 206 7, |
221 0, | 207 0, |
222 "CreateObjectLiteral.Wide [513], [1027], #165"}, | 208 "CreateObjectLiteral.Wide [513], [1027], #165"}, |
223 {{B(ExtraWide), B(JumpIfNull), 0x15, 0xcd, 0x5b, 0x07}, | 209 {{B(ExtraWide), B(JumpIfNull), 0x15, 0xcd, 0x5b, 0x07}, |
224 6, | 210 6, |
225 0, | 211 0, |
226 "JumpIfNull.ExtraWide [123456789]"}, | 212 "JumpIfNull.ExtraWide [123456789]"}, |
227 #elif V8_TARGET_BIG_ENDIAN | 213 #elif V8_TARGET_BIG_ENDIAN |
228 {{B(LdaSmi), 0x01}, 2, 0, " LdaSmi [1]"}, | 214 {{B(LdaSmi), 0x01}, 2, 0, " LdaSmi [1]"}, |
229 {{B(Wide), B(LdaSmi), 0x03, 0xe8}, 4, 0, " LdaSmi.Wide [1000]"}, | 215 {{B(Wide), B(LdaSmi), 0x03, 0xe8}, 4, 0, " LdaSmi.Wide [1000]"}, |
230 {{B(ExtraWide), B(LdaSmi), 0x00, 0x01, 0x86, 0xa0}, | 216 {{B(ExtraWide), B(LdaSmi), 0x00, 0x01, 0x86, 0xa0}, |
231 6, | 217 6, |
232 0, | 218 0, |
233 "LdaSmi.ExtraWide [100000]"}, | 219 "LdaSmi.ExtraWide [100000]"}, |
234 {{B(LdaSmi), 0xff}, 2, 0, " LdaSmi [-1]"}, | 220 {{B(LdaSmi), 0xff}, 2, 0, " LdaSmi [-1]"}, |
235 {{B(Wide), B(LdaSmi), 0xfc, 0x18}, 4, 0, " LdaSmi.Wide [-1000]"}, | 221 {{B(Wide), B(LdaSmi), 0xfc, 0x18}, 4, 0, " LdaSmi.Wide [-1000]"}, |
236 {{B(ExtraWide), B(LdaSmi), 0xff, 0xfe, 0x79, 0x60}, | 222 {{B(ExtraWide), B(LdaSmi), 0xff, 0xfe, 0x79, 0x60}, |
237 6, | 223 6, |
238 0, | 224 0, |
239 "LdaSmi.ExtraWide [-100000]"}, | 225 "LdaSmi.ExtraWide [-100000]"}, |
240 {{B(Star), REG8(5)}, 2, 0, " Star r5"}, | 226 {{B(Star), 0xf5}, 2, 0, " Star r5"}, |
241 {{B(Wide), B(Star), REG16(136)}, 4, 0, " Star.Wide r136"}, | 227 {{B(Wide), B(Star), 0xff, 0x72}, 4, 0, " Star.Wide r136"}, |
242 {{B(Wide), B(Call), REG16(134), REG16(135), 0x00, 0x02, 0x00, 0xb1}, | 228 {{B(Wide), B(Call), 0xff, 0x74, 0xff, 0x73, 0x00, 0x02, 0x00, 0xb1}, |
243 10, | 229 10, |
244 0, | 230 0, |
245 "Call.Wide r134, r135, #2, [177]"}, | 231 "Call.Wide r134, r135, #2, [177]"}, |
246 {{B(Ldar), | 232 {{B(Ldar), |
247 static_cast<uint8_t>(Register::FromParameterIndex(2, 3).ToOperand())}, | 233 static_cast<uint8_t>(Register::FromParameterIndex(2, 3).ToOperand())}, |
248 2, | 234 2, |
249 3, | 235 3, |
250 " Ldar a1"}, | 236 " Ldar a1"}, |
251 {{B(Wide), B(CreateObjectLiteral), 0x02, 0x01, 0x04, 0x03, 0xa5}, | 237 {{B(Wide), B(CreateObjectLiteral), 0x02, 0x01, 0x04, 0x03, 0xa5}, |
252 7, | 238 7, |
253 0, | 239 0, |
254 "CreateObjectLiteral.Wide [513], [1027], #165"}, | 240 "CreateObjectLiteral.Wide [513], [1027], #165"}, |
255 {{B(ExtraWide), B(JumpIfNull), 0x07, 0x5b, 0xcd, 0x15}, | 241 {{B(ExtraWide), B(JumpIfNull), 0x07, 0x5b, 0xcd, 0x15}, |
256 6, | 242 6, |
257 0, | 243 0, |
258 "JumpIfNull.ExtraWide [123456789]"}, | 244 "JumpIfNull.ExtraWide [123456789]"}, |
259 #else | 245 #else |
260 #error "Unknown Architecture" | 246 #error "Unknown Architecture" |
261 #endif | 247 #endif |
262 }; | 248 }; |
263 #undef B | 249 #undef B |
264 #undef REG_OPERAND | |
265 #undef REG8 | |
266 #undef REG16 | |
267 | 250 |
268 for (size_t i = 0; i < arraysize(cases); ++i) { | 251 for (size_t i = 0; i < arraysize(cases); ++i) { |
269 // Generate reference string by prepending formatted bytes. | 252 // Generate reference string by prepending formatted bytes. |
270 std::stringstream expected_ss; | 253 std::stringstream expected_ss; |
271 std::ios default_format(nullptr); | 254 std::ios default_format(nullptr); |
272 default_format.copyfmt(expected_ss); | 255 default_format.copyfmt(expected_ss); |
273 // Match format of Bytecodes::Decode() for byte representations. | 256 // Match format of Bytecodes::Decode() for byte representations. |
274 expected_ss.fill('0'); | 257 expected_ss.fill('0'); |
275 expected_ss.flags(std::ios::right | std::ios::hex); | 258 expected_ss.flags(std::ios::right | std::ios::hex); |
276 for (size_t b = 0; b < cases[i].length; b++) { | 259 for (size_t b = 0; b < cases[i].length; b++) { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kNone)); | 338 names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kNone)); |
356 names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kRead)); | 339 names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kRead)); |
357 names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kWrite)); | 340 names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kWrite)); |
358 names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kReadWrite)); | 341 names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kReadWrite)); |
359 CHECK_EQ(names.size(), 4); | 342 CHECK_EQ(names.size(), 4); |
360 } | 343 } |
361 | 344 |
362 } // namespace interpreter | 345 } // namespace interpreter |
363 } // namespace internal | 346 } // namespace internal |
364 } // namespace v8 | 347 } // namespace v8 |
OLD | NEW |