Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(742)

Unified Diff: test/cctest/interpreter/bytecode-expectations-printer.cc

Issue 1963663002: [interpreter] Add checks for source position to test-bytecode-generator. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix bad implicit cast. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: test/cctest/interpreter/bytecode-expectations-printer.cc
diff --git a/test/cctest/interpreter/bytecode-expectations-printer.cc b/test/cctest/interpreter/bytecode-expectations-printer.cc
index bf43b954025a9f1043281cd17cccdaea87695aaf..b0f623611eccd96e3d8019b01f2378e2866fe1df 100644
--- a/test/cctest/interpreter/bytecode-expectations-printer.cc
+++ b/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>
@@ -19,6 +20,7 @@
#include "src/interpreter/bytecode-generator.h"
#include "src/interpreter/bytecodes.h"
#include "src/interpreter/interpreter.h"
+#include "src/interpreter/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 {
@@ -102,11 +105,11 @@ i::Runtime::FunctionId IndexToFunctionId(uint32_t 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 +128,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,19 +152,19 @@ 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);
+ uint32_t operand = bytecode_iterator.GetRuntimeIdOperand(op_index);
stream << "Runtime::k"
<< i::Runtime::FunctionForId(IndexToFunctionId(operand))->name;
break;
@@ -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.bytecode_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';
}

Powered by Google App Engine
This is Rietveld 408576698