Commit 8bfd4a5a authored by ssanfilippo's avatar ssanfilippo Committed by Commit bot

[Interpreter] Handle negative ints in generate-bytecode-expectations.

The previous implementation used GetRawOperand(), which allows a nicely
unified handling of all scalar types, but returns an unsigned type.
Because of this, generate-bytecode-expectations couldn't properly handle
negative numbers.

This commit differentiate between different types of scalar operands and
uses the appropriate getter from i::interpreter::BytecodeArrayIterator,
thus correctly handling signed types where needed.

Two new helpers have been added to i::interpreter::Bytecodes:

 * IsImmediateOperandType()
 * IsIndexOperandType()

with the intuitive semantic.

BUG=v8:4280
LOG=N

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

Cr-Commit-Position: refs/heads/master@{#33874}
parent d1c28849
......@@ -264,16 +264,29 @@ bool Bytecodes::IsJumpOrReturn(Bytecode bytecode) {
return bytecode == Bytecode::kReturn || IsJump(bytecode);
}
bool Bytecodes::IsMaybeRegisterOperandType(OperandType operand_type) {
return (operand_type == OperandType::kMaybeReg8 ||
operand_type == OperandType::kMaybeReg16);
// static
bool Bytecodes::IsIndexOperandType(OperandType operand_type) {
return operand_type == OperandType::kIdx8 ||
operand_type == OperandType::kIdx16;
}
// static
bool Bytecodes::IsImmediateOperandType(OperandType operand_type) {
return operand_type == OperandType::kImm8;
}
// static
bool Bytecodes::IsRegisterCountOperandType(OperandType operand_type) {
return (operand_type == OperandType::kRegCount8 ||
operand_type == OperandType::kRegCount16);
}
// static
bool Bytecodes::IsMaybeRegisterOperandType(OperandType operand_type) {
return (operand_type == OperandType::kMaybeReg8 ||
operand_type == OperandType::kMaybeReg16);
}
// static
bool Bytecodes::IsRegisterOperandType(OperandType operand_type) {
switch (operand_type) {
......
......@@ -463,9 +463,11 @@ class Bytecodes {
// Returns true if the bytecode is a conditional jump, a jump, or a return.
static bool IsJumpOrReturn(Bytecode bytecode);
// Returns true if |operand_type| is a maybe register operand
// (kMaybeReg8/kMaybeReg16).
static bool IsMaybeRegisterOperandType(OperandType operand_type);
// Returns true if |operand_type| is a register index operand (kIdx8/kIdx16).
static bool IsIndexOperandType(OperandType operand_type);
// Returns true if |operand_type| represents an immediate.
static bool IsImmediateOperandType(OperandType operand_type);
// Returns true if |operand_type| is a register count operand
// (kRegCount8/kRegCount16).
......@@ -480,6 +482,10 @@ class Bytecodes {
// Returns true if |operand_type| represents a register used as an output.
static bool IsRegisterOutputOperandType(OperandType operand_type);
// Returns true if |operand_type| is a maybe register operand
// (kMaybeReg8/kMaybeReg16).
static bool IsMaybeRegisterOperandType(OperandType operand_type);
// Decode a single bytecode and operands to |os|.
static std::ostream& Decode(std::ostream& os, const uint8_t* bytecode_start,
int number_of_parameters);
......
......@@ -146,8 +146,20 @@ void PrintBytecodeOperand(std::ostream& stream,
if (op_size != OperandSize::kByte) stream << size_tag;
stream << '(' << register_value.index() << ')';
} else {
uint32_t raw_value = bytecode_iter.GetRawOperand(op_index, op_type);
stream << 'U' << size_tag << '(' << raw_value << ')';
stream << 'U' << size_tag << '(';
if (Bytecodes::IsImmediateOperandType(op_type)) {
// We need a cast, otherwise the result is printed as char.
stream << static_cast<int>(bytecode_iter.GetImmediateOperand(op_index));
} else if (Bytecodes::IsRegisterCountOperandType(op_type)) {
stream << bytecode_iter.GetCountOperand(op_index);
} else if (Bytecodes::IsIndexOperandType(op_type)) {
stream << bytecode_iter.GetIndexOperand(op_index);
} else {
UNREACHABLE();
}
stream << ')';
}
}
......
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