Index: test/unittests/interpreter/bytecodes-unittest.cc |
diff --git a/test/unittests/interpreter/bytecodes-unittest.cc b/test/unittests/interpreter/bytecodes-unittest.cc |
index 5472927a40630ac98b34345d3da890903c821298..58f72c4424319b53ef14dd6d3c6d982cbba47acb 100644 |
--- a/test/unittests/interpreter/bytecodes-unittest.cc |
+++ b/test/unittests/interpreter/bytecodes-unittest.cc |
@@ -177,6 +177,74 @@ TEST(Bytecodes, DebugBreakExistForEachBytecode) { |
#undef CHECK_DEBUG_BREAK_SIZE |
} |
+TEST(Bytecodes, DecodeBytecodeAndOperands) { |
+ struct BytecodesAndResult { |
+ const uint8_t bytecode[32]; |
+ const size_t length; |
+ int parameter_count; |
+ const char* output; |
+ }; |
+ |
+#define B(Name) static_cast<uint8_t>(Bytecode::k##Name) |
+ const BytecodesAndResult cases[] = { |
+ {{B(LdaSmi), 0x01}, 2, 0, " LdaSmi [1]"}, |
+ {{B(Wide), B(LdaSmi), 0xe8, 0x03}, 4, 0, " LdaSmi.Wide [1000]"}, |
+ {{B(ExtraWide), B(LdaSmi), 0xa0, 0x86, 0x01, 0x00}, |
+ 6, |
+ 0, |
+ "LdaSmi.ExtraWide [100000]"}, |
+ {{B(LdaSmi), 0xff}, 2, 0, " LdaSmi [-1]"}, |
+ {{B(Wide), B(LdaSmi), 0x18, 0xfc}, 4, 0, " LdaSmi.Wide [-1000]"}, |
+ {{B(ExtraWide), B(LdaSmi), 0x60, 0x79, 0xfe, 0xff}, |
+ 6, |
+ 0, |
+ "LdaSmi.ExtraWide [-100000]"}, |
+ {{B(Star), 0xfb}, 2, 0, " Star r5"}, |
+ {{B(Wide), B(Star), 0x78, 0xff}, 4, 0, " Star.Wide r136"}, |
+ {{B(Wide), B(Call), 0x7a, 0xff, 0x79, 0xff, 0x02, 0x00, 0xb1, 0x00}, |
+ 10, |
+ 0, |
+ "Call.Wide r134, r135, #2, [177]"}, |
+ {{B(Ldar), |
+ static_cast<uint8_t>(Register::FromParameterIndex(2, 3).ToOperand())}, |
+ 2, |
+ 3, |
+ " Ldar a1"}, |
+ {{B(Wide), B(CreateObjectLiteral), 0x01, 0x02, 0x03, 0x04, 0xa5}, |
+ 7, |
+ 0, |
+ "CreateObjectLiteral.Wide [513], [1027], #165"}, |
+ {{B(ExtraWide), B(JumpIfNull), 0x15, 0xcd, 0x5b, 0x07}, |
+ 6, |
+ 0, |
+ "JumpIfNull.ExtraWide [123456789]"}, |
+ }; |
+#undef B |
+ |
+ for (size_t i = 0; i < arraysize(cases); ++i) { |
+ // Generate reference string by prepending formatted bytes. |
+ std::stringstream expected_ss; |
+ std::ios default_format(nullptr); |
+ default_format.copyfmt(expected_ss); |
+ // Match format of Bytecodes::Decode() for byte representations. |
+ expected_ss.fill('0'); |
+ expected_ss.flags(std::ios::right | std::ios::hex); |
+ for (size_t b = 0; b < cases[i].length; b++) { |
+ expected_ss << std::setw(2) << static_cast<uint32_t>(cases[i].bytecode[b]) |
+ << ' '; |
+ } |
+ expected_ss.copyfmt(default_format); |
+ expected_ss << cases[i].output; |
+ |
+ // Generate decoded byte output. |
+ std::stringstream actual_ss; |
+ Bytecodes::Decode(actual_ss, cases[i].bytecode, cases[i].parameter_count); |
+ |
+ // Compare. |
+ CHECK_EQ(actual_ss.str(), expected_ss.str()); |
+ } |
+} |
+ |
TEST(Bytecodes, DebugBreakForPrefixBytecodes) { |
CHECK_EQ(Bytecode::kDebugBreakWide, |
Bytecodes::GetDebugBreak(Bytecode::kWide)); |