summaryrefslogtreecommitdiff
path: root/deps/v8/test/cctest/interpreter/bytecode-expectations-printer.cc
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/test/cctest/interpreter/bytecode-expectations-printer.cc')
-rw-r--r--deps/v8/test/cctest/interpreter/bytecode-expectations-printer.cc81
1 files changed, 54 insertions, 27 deletions
diff --git a/deps/v8/test/cctest/interpreter/bytecode-expectations-printer.cc b/deps/v8/test/cctest/interpreter/bytecode-expectations-printer.cc
index bf43b95402..507875742d 100644
--- a/deps/v8/test/cctest/interpreter/bytecode-expectations-printer.cc
+++ b/deps/v8/test/cctest/interpreter/bytecode-expectations-printer.cc
@@ -4,6 +4,7 @@
#include "test/cctest/interpreter/bytecode-expectations-printer.h"
+#include <iomanip>
#include <iostream>
#include <vector>
@@ -11,14 +12,15 @@
#include "include/v8.h"
#include "src/base/logging.h"
-#include "src/base/smart-pointers.h"
#include "src/compiler.h"
#include "src/runtime/runtime.h"
#include "src/interpreter/bytecode-array-iterator.h"
#include "src/interpreter/bytecode-generator.h"
#include "src/interpreter/bytecodes.h"
+#include "src/interpreter/interpreter-intrinsics.h"
#include "src/interpreter/interpreter.h"
+#include "src/source-position-table.h"
namespace v8 {
namespace internal {
@@ -27,6 +29,7 @@ namespace interpreter {
// static
const char* const BytecodeExpectationsPrinter::kDefaultTopFunctionName =
"__genbckexp_wrapper__";
+const char* const BytecodeExpectationsPrinter::kIndent = " ";
v8::Local<v8::String> BytecodeExpectationsPrinter::V8StringFromUTF8(
const char* data) const {
@@ -95,18 +98,12 @@ void BytecodeExpectationsPrinter::PrintEscapedString(
}
}
-namespace {
-i::Runtime::FunctionId IndexToFunctionId(uint32_t index) {
- return static_cast<i::Runtime::FunctionId>(index);
-}
-} // namespace
-
void BytecodeExpectationsPrinter::PrintBytecodeOperand(
- std::ostream& stream, const BytecodeArrayIterator& bytecode_iter,
+ std::ostream& stream, const BytecodeArrayIterator& bytecode_iterator,
const Bytecode& bytecode, int op_index, int parameter_count) const {
OperandType op_type = Bytecodes::GetOperandType(bytecode, op_index);
OperandSize op_size = Bytecodes::GetOperandSize(
- bytecode, op_index, bytecode_iter.current_operand_scale());
+ bytecode, op_index, bytecode_iterator.current_operand_scale());
const char* size_tag;
switch (op_size) {
@@ -125,7 +122,7 @@ void BytecodeExpectationsPrinter::PrintBytecodeOperand(
}
if (Bytecodes::IsRegisterOperandType(op_type)) {
- Register register_value = bytecode_iter.GetRegisterOperand(op_index);
+ Register register_value = bytecode_iterator.GetRegisterOperand(op_index);
stream << 'R';
if (op_size != OperandSize::kByte) stream << size_tag;
if (register_value.is_new_target()) {
@@ -149,21 +146,27 @@ void BytecodeExpectationsPrinter::PrintBytecodeOperand(
switch (op_type) {
case OperandType::kFlag8:
- stream << bytecode_iter.GetFlagOperand(op_index);
+ stream << bytecode_iterator.GetFlagOperand(op_index);
break;
case OperandType::kIdx:
- stream << bytecode_iter.GetIndexOperand(op_index);
+ stream << bytecode_iterator.GetIndexOperand(op_index);
break;
case OperandType::kImm:
- stream << bytecode_iter.GetImmediateOperand(op_index);
+ stream << bytecode_iterator.GetImmediateOperand(op_index);
break;
case OperandType::kRegCount:
- stream << bytecode_iter.GetRegisterCountOperand(op_index);
+ stream << bytecode_iterator.GetRegisterCountOperand(op_index);
break;
case OperandType::kRuntimeId: {
- uint32_t operand = bytecode_iter.GetRuntimeIdOperand(op_index);
- stream << "Runtime::k"
- << i::Runtime::FunctionForId(IndexToFunctionId(operand))->name;
+ Runtime::FunctionId id =
+ bytecode_iterator.GetRuntimeIdOperand(op_index);
+ stream << "Runtime::k" << i::Runtime::FunctionForId(id)->name;
+ break;
+ }
+ case OperandType::kIntrinsicId: {
+ Runtime::FunctionId id =
+ bytecode_iterator.GetIntrinsicIdOperand(op_index);
+ stream << "Runtime::k" << i::Runtime::FunctionForId(id)->name;
break;
}
default:
@@ -175,10 +178,10 @@ void BytecodeExpectationsPrinter::PrintBytecodeOperand(
}
void BytecodeExpectationsPrinter::PrintBytecode(
- std::ostream& stream, const BytecodeArrayIterator& bytecode_iter,
+ std::ostream& stream, const BytecodeArrayIterator& bytecode_iterator,
int parameter_count) const {
- Bytecode bytecode = bytecode_iter.current_bytecode();
- OperandScale operand_scale = bytecode_iter.current_operand_scale();
+ Bytecode bytecode = bytecode_iterator.current_bytecode();
+ OperandScale operand_scale = bytecode_iterator.current_operand_scale();
if (Bytecodes::OperandScaleRequiresPrefixBytecode(operand_scale)) {
Bytecode prefix = Bytecodes::OperandScaleToPrefixBytecode(operand_scale);
stream << "B(" << Bytecodes::ToString(prefix) << "), ";
@@ -187,11 +190,30 @@ void BytecodeExpectationsPrinter::PrintBytecode(
int operands_count = Bytecodes::NumberOfOperands(bytecode);
for (int op_index = 0; op_index < operands_count; ++op_index) {
stream << ", ";
- PrintBytecodeOperand(stream, bytecode_iter, bytecode, op_index,
+ PrintBytecodeOperand(stream, bytecode_iterator, bytecode, op_index,
parameter_count);
}
}
+void BytecodeExpectationsPrinter::PrintSourcePosition(
+ std::ostream& stream, SourcePositionTableIterator& source_iterator,
+ int bytecode_offset) const {
+ static const size_t kPositionWidth = 4;
+ if (!source_iterator.done() &&
+ source_iterator.code_offset() == bytecode_offset) {
+ stream << "/* " << std::setw(kPositionWidth)
+ << source_iterator.source_position();
+ if (source_iterator.is_statement()) {
+ stream << " S> */ ";
+ } else {
+ stream << " E> */ ";
+ }
+ source_iterator.Advance();
+ } else {
+ stream << " " << std::setw(kPositionWidth) << ' ' << " ";
+ }
+}
+
void BytecodeExpectationsPrinter::PrintV8String(std::ostream& stream,
i::String* string) const {
stream << '"';
@@ -246,10 +268,15 @@ void BytecodeExpectationsPrinter::PrintBytecodeSequence(
std::ostream& stream, i::Handle<i::BytecodeArray> bytecode_array) const {
stream << "bytecode array length: " << bytecode_array->length()
<< "\nbytecodes: [\n";
- BytecodeArrayIterator bytecode_iter(bytecode_array);
- for (; !bytecode_iter.done(); bytecode_iter.Advance()) {
- stream << " ";
- PrintBytecode(stream, bytecode_iter, bytecode_array->parameter_count());
+
+ SourcePositionTableIterator source_iterator(
+ bytecode_array->source_position_table());
+ BytecodeArrayIterator bytecode_iterator(bytecode_array);
+ for (; !bytecode_iterator.done(); bytecode_iterator.Advance()) {
+ stream << kIndent;
+ PrintSourcePosition(stream, source_iterator,
+ bytecode_iterator.current_offset());
+ PrintBytecode(stream, bytecode_iterator, bytecode_array->parameter_count());
stream << ",\n";
}
stream << "]\n";
@@ -261,7 +288,7 @@ void BytecodeExpectationsPrinter::PrintConstantPool(
int num_constants = constant_pool->length();
if (num_constants > 0) {
for (int i = 0; i < num_constants; ++i) {
- stream << " ";
+ stream << kIndent;
PrintConstant(stream, i::FixedArray::get(constant_pool, i, i_isolate()));
stream << ",\n";
}
@@ -275,7 +302,7 @@ void BytecodeExpectationsPrinter::PrintCodeSnippet(
std::stringstream body_stream(body);
std::string body_line;
while (std::getline(body_stream, body_line)) {
- stream << " ";
+ stream << kIndent;
PrintEscapedString(stream, body_line);
stream << '\n';
}