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

[Interpreter] Consistency fixes.

Change minimum BytecodeArray frame size to zero now return value is in
the accumulator.

Fix inconsistent checks in bytecode-array-builder.cc.

Simplify bytecode disassembly by adding Bytecodes::Decode to
disassemble one bytecode and operands.

BUG=v8:4280
LOG=N

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

Cr-Commit-Position: refs/heads/master@{#29988}
parent d8ad1479
......@@ -24,6 +24,7 @@ void BytecodeArrayBuilder::set_locals_count(int number_of_locals) {
int BytecodeArrayBuilder::locals_count() const { return local_register_count_; }
Handle<BytecodeArray> BytecodeArrayBuilder::ToBytecodeArray() {
DCHECK_EQ(bytecode_generated_, false);
DCHECK_GE(local_register_count_, 0);
......@@ -157,7 +158,7 @@ void BytecodeArrayBuilder::Output(Bytecode bytecode, uint8_t operand0,
void BytecodeArrayBuilder::Output(Bytecode bytecode, uint8_t operand0,
uint8_t operand1) {
DCHECK(Bytecodes::NumberOfOperands(bytecode) == 2);
DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 2);
DCHECK(OperandIsValid(bytecode, 0, operand0) &&
OperandIsValid(bytecode, 1, operand1));
bytecodes_.push_back(Bytecodes::ToByte(bytecode));
......@@ -167,7 +168,7 @@ void BytecodeArrayBuilder::Output(Bytecode bytecode, uint8_t operand0,
void BytecodeArrayBuilder::Output(Bytecode bytecode, uint8_t operand0) {
DCHECK(Bytecodes::NumberOfOperands(bytecode) == 1);
DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 1);
DCHECK(OperandIsValid(bytecode, 0, operand0));
bytecodes_.push_back(Bytecodes::ToByte(bytecode));
bytecodes_.push_back(operand0);
......@@ -175,7 +176,7 @@ void BytecodeArrayBuilder::Output(Bytecode bytecode, uint8_t operand0) {
void BytecodeArrayBuilder::Output(Bytecode bytecode) {
DCHECK(Bytecodes::NumberOfOperands(bytecode) == 0);
DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 0);
bytecodes_.push_back(Bytecodes::ToByte(bytecode));
}
......
......@@ -86,6 +86,48 @@ int Bytecodes::MaximumNumberOfOperands() { return kMaxOperands; }
int Bytecodes::MaximumSize() { return 1 + kMaxOperands; }
// static
std::ostream& Bytecodes::Decode(std::ostream& os,
const uint8_t* bytecode_start) {
Vector<char> buf = Vector<char>::New(50);
Bytecode bytecode = Bytecodes::FromByte(bytecode_start[0]);
int bytecode_size = Bytecodes::Size(bytecode);
for (int i = 0; i < bytecode_size; i++) {
SNPrintF(buf, "%02x ", bytecode_start[i]);
os << buf.start();
}
for (int i = bytecode_size; i < Bytecodes::MaximumSize(); i++) {
os << " ";
}
os << bytecode << " ";
const uint8_t* operands_start = bytecode_start + 1;
int operands_size = bytecode_size - 1;
for (int i = 0; i < operands_size; i++) {
OperandType op_type = GetOperandType(bytecode, i);
uint8_t operand = operands_start[i];
switch (op_type) {
case interpreter::OperandType::kImm8:
os << "#" << static_cast<int>(operand);
break;
case interpreter::OperandType::kReg:
os << "r" << static_cast<int>(operand);
break;
case interpreter::OperandType::kNone:
UNREACHABLE();
break;
}
if (i != operands_size - 1) {
os << ", ";
}
}
return os;
}
std::ostream& operator<<(std::ostream& os, const Bytecode& bytecode) {
return os << Bytecodes::ToString(bytecode);
}
......
......@@ -90,15 +90,18 @@ class Bytecodes {
// Return the i-th operand of |bytecode|.
static OperandType GetOperandType(Bytecode bytecode, int i);
// Returns the size of the bytecode including its arguments.
// Returns the size of the bytecode including its operands.
static int Size(Bytecode bytecode);
// The maximum number of operands across all bytecodes.
static int MaximumNumberOfOperands();
// Maximum size of a bytecode and its arguments.
// Maximum size of a bytecode and its operands.
static int MaximumSize();
// Decode a single bytecode and operands to |os|.
static std::ostream& Decode(std::ostream& os, const uint8_t* bytecode_start);
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(Bytecodes);
};
......
......@@ -3740,8 +3740,7 @@ void BytecodeArray::set(int index, byte value) {
void BytecodeArray::set_frame_size(int frame_size) {
// We need at least one stack slot for the return register.
DCHECK_GE(frame_size, kPointerSize);
DCHECK_GE(frame_size, 0);
DCHECK(IsAligned(frame_size, static_cast<unsigned>(kPointerSize)));
WRITE_INT_FIELD(this, kFrameSizeOffset, frame_size);
}
......
......@@ -11721,39 +11721,18 @@ void Code::Disassemble(const char* name, std::ostream& os) { // NOLINT
void BytecodeArray::Disassemble(std::ostream& os) {
os << "Frame size " << frame_size() << "\n";
Vector<char> buf = Vector<char>::New(50);
int bytes = 0;
for (int i = 0; i < this->length(); i += bytes) {
interpreter::Bytecode bytecode = interpreter::Bytecodes::FromByte(get(i));
bytes = interpreter::Bytecodes::Size(bytecode);
SNPrintF(buf, "%p : ", GetFirstBytecodeAddress() + i);
os << buf.start();
for (int j = 0; j < bytes; j++) {
SNPrintF(buf, "%02x ", get(i + j));
os << buf.start();
}
for (int j = bytes; j < interpreter::Bytecodes::MaximumSize(); j++) {
os << " ";
}
os << bytecode << " ";
for (int j = 1; j < bytes; j++) {
interpreter::OperandType op_type =
interpreter::Bytecodes::GetOperandType(bytecode, j - 1);
uint8_t operand = get(i + j);
switch (op_type) {
case interpreter::OperandType::kImm8:
os << "#" << static_cast<int>(operand);
break;
case interpreter::OperandType::kReg:
os << "r" << static_cast<int>(operand);
break;
case interpreter::OperandType::kNone:
UNREACHABLE();
break;
}
if (j + 1 < bytes) {
os << ", ";
}
}
const uint8_t* first_bytecode_address = GetFirstBytecodeAddress();
int bytecode_size = 0;
for (int i = 0; i < this->length(); i += bytecode_size) {
const uint8_t* bytecode_start = &first_bytecode_address[i];
interpreter::Bytecode bytecode =
interpreter::Bytecodes::FromByte(bytecode_start[0]);
bytecode_size = interpreter::Bytecodes::Size(bytecode);
SNPrintF(buf, "%p", bytecode_start);
os << buf.start() << " : ";
interpreter::Bytecodes::Decode(os, bytecode_start);
os << "\n";
}
}
......
......@@ -67,7 +67,7 @@ TEST(AllBytecodesGenerated) {
TEST(FrameSizesLookGood) {
for (int locals = 1; locals < 5; locals++) {
for (int locals = 0; locals < 5; locals++) {
for (int temps = 0; temps < 3; temps++) {
InitializedHandleScope handle_scope;
BytecodeArrayBuilder builder(handle_scope.main_isolate());
......
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