Commit 095de95b authored by Jaroslav Sevcik's avatar Jaroslav Sevcik Committed by Commit Bot

[interpreter] printing: output the native context index as string

Bug: 
Change-Id: Iedd273d517e2ee2e548a5e9732689114800e6128
Reviewed-on: https://chromium-review.googlesource.com/649749Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Commit-Queue: Jaroslav Sevcik <jarin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47822}
parent 2bc43927
......@@ -1773,8 +1773,8 @@ void BytecodeGraphBuilder::VisitCallWithSpread() {
void BytecodeGraphBuilder::VisitCallJSRuntime() {
PrepareEagerCheckpoint();
Node* callee =
BuildLoadNativeContextField(bytecode_iterator().GetIndexOperand(0));
Node* callee = BuildLoadNativeContextField(
bytecode_iterator().GetNativeContextIndexOperand(0));
interpreter::Register receiver = bytecode_iterator().GetRegisterOperand(1);
size_t reg_count = bytecode_iterator().GetRegisterCountOperand(2);
......
......@@ -159,6 +159,14 @@ Runtime::FunctionId BytecodeArrayAccessor::GetRuntimeIdOperand(
return static_cast<Runtime::FunctionId>(raw_id);
}
uint32_t BytecodeArrayAccessor::GetNativeContextIndexOperand(
int operand_index) const {
OperandType operand_type =
Bytecodes::GetOperandType(current_bytecode(), operand_index);
DCHECK(operand_type == OperandType::kNativeContextIndex);
return GetUnsignedOperand(operand_index, operand_type);
}
Runtime::FunctionId BytecodeArrayAccessor::GetIntrinsicIdOperand(
int operand_index) const {
OperandType operand_type =
......
......@@ -85,6 +85,7 @@ class V8_EXPORT_PRIVATE BytecodeArrayAccessor {
int GetRegisterOperandRange(int operand_index) const;
Runtime::FunctionId GetRuntimeIdOperand(int operand_index) const;
Runtime::FunctionId GetIntrinsicIdOperand(int operand_index) const;
uint32_t GetNativeContextIndexOperand(int operand_index) const;
Handle<Object> GetConstantAtIndex(int offset) const;
Handle<Object> GetConstantForIndexOperand(int operand_index) const;
......
......@@ -6,6 +6,7 @@
#include <iomanip>
#include "src/contexts.h"
#include "src/interpreter/interpreter-intrinsics.h"
#include "src/objects-inl.h"
......@@ -69,6 +70,7 @@ uint32_t BytecodeDecoder::DecodeUnsignedOperand(const uint8_t* operand_start,
}
namespace {
const char* NameForRuntimeId(uint32_t idx) {
switch (idx) {
#define CASE(name, nargs, ressize) \
......@@ -82,6 +84,19 @@ const char* NameForRuntimeId(uint32_t idx) {
UNREACHABLE();
}
}
const char* NameForNativeContextIndex(uint32_t idx) {
switch (idx) {
#define CASE(index_name, type, name) \
case Context::index_name: \
return #name;
NATIVE_CONTEXT_FIELDS(CASE)
#undef CASE
default:
UNREACHABLE();
}
}
} // anonymous namespace
// static
......@@ -139,6 +154,11 @@ std::ostream& BytecodeDecoder::Decode(std::ostream& os,
os << "[" << NameForRuntimeId(IntrinsicsHelper::ToRuntimeId(id)) << "]";
break;
}
case interpreter::OperandType::kNativeContextIndex: {
auto id = DecodeUnsignedOperand(operand_start, op_type, operand_scale);
os << "[" << NameForNativeContextIndex(id) << "]";
break;
}
case interpreter::OperandType::kRuntimeId:
os << "[" << NameForRuntimeId(DecodeUnsignedOperand(
operand_start, op_type, operand_scale))
......
......@@ -35,7 +35,8 @@ namespace interpreter {
#define UNSIGNED_FIXED_SCALAR_OPERAND_TYPE_LIST(V) \
V(Flag8, OperandTypeInfo::kFixedUnsignedByte) \
V(IntrinsicId, OperandTypeInfo::kFixedUnsignedByte) \
V(RuntimeId, OperandTypeInfo::kFixedUnsignedShort)
V(RuntimeId, OperandTypeInfo::kFixedUnsignedShort) \
V(NativeContextIndex, OperandTypeInfo::kScalableUnsignedByte)
// Carefully ordered for operand type range checks below.
#define NON_REGISTER_OPERAND_TYPE_LIST(V) \
......
......@@ -183,7 +183,7 @@ namespace interpreter {
OperandType::kRegList, OperandType::kRegCount) \
V(CallRuntimeForPair, AccumulatorUse::kNone, OperandType::kRuntimeId, \
OperandType::kRegList, OperandType::kRegCount, OperandType::kRegOutPair) \
V(CallJSRuntime, AccumulatorUse::kWrite, OperandType::kIdx, \
V(CallJSRuntime, AccumulatorUse::kWrite, OperandType::kNativeContextIndex, \
OperandType::kRegList, OperandType::kRegCount) \
\
/* Intrinsics */ \
......
......@@ -516,6 +516,16 @@ Node* InterpreterAssembler::BytecodeOperandRuntimeId(int operand_index) {
return BytecodeUnsignedOperand(operand_index, operand_size);
}
Node* InterpreterAssembler::BytecodeOperandNativeContextIndex(
int operand_index) {
DCHECK(OperandType::kNativeContextIndex ==
Bytecodes::GetOperandType(bytecode_, operand_index));
OperandSize operand_size =
Bytecodes::GetOperandSize(bytecode_, operand_index, operand_scale());
return ChangeUint32ToWord(
BytecodeUnsignedOperand(operand_index, operand_size));
}
Node* InterpreterAssembler::BytecodeOperandIntrinsicId(int operand_index) {
DCHECK(OperandType::kIntrinsicId ==
Bytecodes::GetOperandType(bytecode_, operand_index));
......
......@@ -62,6 +62,9 @@ class V8_EXPORT_PRIVATE InterpreterAssembler : public CodeStubAssembler {
// Returns the 32-bit unsigned runtime id immediate for bytecode operand
// |operand_index| in the current bytecode.
compiler::Node* BytecodeOperandRuntimeId(int operand_index);
// Returns the 32-bit unsigned native context index immediate for bytecode
// operand |operand_index| in the current bytecode.
compiler::Node* BytecodeOperandNativeContextIndex(int operand_index);
// Returns the 32-bit unsigned intrinsic id immediate for bytecode operand
// |operand_index| in the current bytecode.
compiler::Node* BytecodeOperandIntrinsicId(int operand_index);
......
......@@ -1864,7 +1864,7 @@ IGNITION_HANDLER(CallRuntimeForPair, InterpreterAssembler) {
// Call the JS runtime function that has the |context_index| with the receiver
// in register |receiver| and |arg_count| arguments in subsequent registers.
IGNITION_HANDLER(CallJSRuntime, InterpreterAssembler) {
Node* context_index = BytecodeOperandIdx(0);
Node* context_index = BytecodeOperandNativeContextIndex(0);
Node* receiver_reg = BytecodeOperandReg(1);
Node* first_arg = RegisterLocation(receiver_reg);
Node* receiver_args_count = BytecodeOperandCount(2);
......
......@@ -181,12 +181,7 @@ void BytecodeExpectationsPrinter::PrintBytecodeOperand(
break;
case OperandType::kIdx: {
stream << 'U' << size_tag << '(';
uint32_t idx = bytecode_iterator.GetIndexOperand(op_index);
if (bytecode == Bytecode::kCallJSRuntime && op_index == 0) {
stream << "%" << NameForNativeContextIntrinsicIndex(idx);
} else {
stream << idx;
}
stream << bytecode_iterator.GetIndexOperand(op_index);
break;
}
case OperandType::kUImm:
......@@ -215,6 +210,12 @@ void BytecodeExpectationsPrinter::PrintBytecodeOperand(
stream << "Runtime::k" << i::Runtime::FunctionForId(id)->name;
break;
}
case OperandType::kNativeContextIndex: {
stream << 'U' << size_tag << '(';
uint32_t idx = bytecode_iterator.GetNativeContextIndexOperand(op_index);
stream << "%" << NameForNativeContextIntrinsicIndex(idx);
break;
}
default:
UNREACHABLE();
}
......
......@@ -6,6 +6,7 @@
#include "src/v8.h"
#include "src/contexts.h"
#include "src/interpreter/bytecode-decoder.h"
#include "src/runtime/runtime.h"
#include "test/unittests/interpreter/bytecode-utils.h"
......@@ -64,7 +65,10 @@ TEST(BytecodeDecoder, DecodeBytecodeAndOperands) {
6,
0,
"JumpIfNull.ExtraWide [123456789]"},
};
{{B(CallJSRuntime), U8(Context::BOOLEAN_FUNCTION_INDEX), R8(0), U8(0)},
4,
0,
" CallJSRuntime [boolean_function], r0-r0"}};
for (size_t i = 0; i < arraysize(cases); ++i) {
// Generate reference string by prepending formatted bytes.
......
......@@ -386,6 +386,11 @@ TARGET_TEST_F(InterpreterAssemblerTest, BytecodeOperand) {
IsChangeUint32ToWord(
m.IsUnsignedOperand(offset, operand_size)));
break;
case interpreter::OperandType::kNativeContextIndex:
EXPECT_THAT(m.BytecodeOperandNativeContextIndex(i),
IsChangeUint32ToWord(
m.IsUnsignedOperand(offset, operand_size)));
break;
case interpreter::OperandType::kUImm:
EXPECT_THAT(m.BytecodeOperandUImm(i),
m.IsUnsignedOperand(offset, operand_size));
......
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