Commit afd2d68d authored by oth's avatar oth Committed by Commit bot

[interpreter] Fix and test for printing of bytecodes.

BUG=v8:4280,v8:4747
LOG=N

Review URL: https://codereview.chromium.org/1825103002

Cr-Commit-Position: refs/heads/master@{#35024}
parent d9e11718
......@@ -491,6 +491,7 @@ std::ostream& Bytecodes::Decode(std::ostream& os, const uint8_t* bytecode_start,
OperandScale operand_scale = OperandScale::kSingle;
if (IsPrefixScalingBytecode(bytecode)) {
prefix_offset = 1;
operand_scale = Bytecodes::PrefixBytecodeToOperandScale(bytecode);
bytecode = Bytecodes::FromByte(bytecode_start[1]);
}
int bytecode_size = Bytecodes::Size(bytecode, operand_scale);
......
......@@ -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));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment