| 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 0094ed9cf81f3da9663c9dc1214eb9bb8943dbbe..1017565f558d6f90be0b7faf38bd42e6146be1ce 100644
|
| --- a/test/cctest/interpreter/bytecode-expectations-printer.cc
|
| +++ b/test/cctest/interpreter/bytecode-expectations-printer.cc
|
| @@ -5,6 +5,7 @@
|
| #include "test/cctest/interpreter/bytecode-expectations-printer.h"
|
|
|
| #include <iostream>
|
| +#include <vector>
|
|
|
| #include "include/libplatform/libplatform.h"
|
| #include "include/v8.h"
|
| @@ -22,6 +23,10 @@ namespace v8 {
|
| namespace internal {
|
| namespace interpreter {
|
|
|
| +// static
|
| +const char* const BytecodeExpectationsPrinter::kDefaultTopFunctionName =
|
| + "__genbckexp_wrapper__";
|
| +
|
| v8::Local<v8::String> BytecodeExpectationsPrinter::V8StringFromUTF8(
|
| const char* data) const {
|
| return v8::String::NewFromUtf8(isolate_, data, v8::NewStringType::kNormal)
|
| @@ -38,17 +43,15 @@ std::string BytecodeExpectationsPrinter::WrapCodeInFunction(
|
| return program_stream.str();
|
| }
|
|
|
| -v8::Local<v8::Value> BytecodeExpectationsPrinter::CompileAndRun(
|
| +v8::Local<v8::Script> BytecodeExpectationsPrinter::Compile(
|
| const char* program) const {
|
| v8::Local<v8::String> source = V8StringFromUTF8(program);
|
| - v8::Local<v8::Script> script =
|
| - v8::Script::Compile(isolate_->GetCurrentContext(), source)
|
| - .ToLocalChecked();
|
| -
|
| - v8::Local<v8::Value> result;
|
| - CHECK(script->Run(isolate_->GetCurrentContext()).ToLocal(&result));
|
| + return v8::Script::Compile(isolate_->GetCurrentContext(), source)
|
| + .ToLocalChecked();
|
| +}
|
|
|
| - return result;
|
| +void BytecodeExpectationsPrinter::Run(v8::Local<v8::Script> script) const {
|
| + CHECK(!script->Run(isolate_->GetCurrentContext()).IsEmpty());
|
| }
|
|
|
| i::Handle<v8::internal::BytecodeArray>
|
| @@ -86,7 +89,7 @@ void BytecodeExpectationsPrinter::PrintEscapedString(
|
|
|
| void BytecodeExpectationsPrinter::PrintBytecodeOperand(
|
| std::ostream& stream, const BytecodeArrayIterator& bytecode_iter,
|
| - const Bytecode& bytecode, int op_index) const {
|
| + 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);
|
|
|
| @@ -107,7 +110,22 @@ void BytecodeExpectationsPrinter::PrintBytecodeOperand(
|
| Register register_value = bytecode_iter.GetRegisterOperand(op_index);
|
| stream << 'R';
|
| if (op_size != OperandSize::kByte) stream << size_tag;
|
| - stream << '(' << register_value.index() << ')';
|
| + if (register_value.is_new_target()) {
|
| + stream << "(new_target)";
|
| + } else if (register_value.is_current_context()) {
|
| + stream << "(context)";
|
| + } else if (register_value.is_function_closure()) {
|
| + stream << "(closure)";
|
| + } else if (register_value.is_parameter()) {
|
| + int parameter_index = register_value.ToParameterIndex(parameter_count);
|
| + if (parameter_index == 0) {
|
| + stream << "(this)";
|
| + } else {
|
| + stream << "(arg" << (parameter_index - 1) << ')';
|
| + }
|
| + } else {
|
| + stream << '(' << register_value.index() << ')';
|
| + }
|
| } else {
|
| stream << 'U' << size_tag << '(';
|
|
|
| @@ -127,7 +145,8 @@ void BytecodeExpectationsPrinter::PrintBytecodeOperand(
|
| }
|
|
|
| void BytecodeExpectationsPrinter::PrintBytecode(
|
| - std::ostream& stream, const BytecodeArrayIterator& bytecode_iter) const {
|
| + std::ostream& stream, const BytecodeArrayIterator& bytecode_iter,
|
| + int parameter_count) const {
|
| Bytecode bytecode = bytecode_iter.current_bytecode();
|
|
|
| stream << "B(" << Bytecodes::ToString(bytecode) << ')';
|
| @@ -135,7 +154,8 @@ 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_iter, bytecode, op_index,
|
| + parameter_count);
|
| }
|
| }
|
|
|
| @@ -199,7 +219,7 @@ void BytecodeExpectationsPrinter::PrintBytecodeSequence(
|
| BytecodeArrayIterator bytecode_iter(bytecode_array);
|
| for (; !bytecode_iter.done(); bytecode_iter.Advance()) {
|
| stream << " ";
|
| - PrintBytecode(stream, bytecode_iter);
|
| + PrintBytecode(stream, bytecode_iter, bytecode_array->parameter_count());
|
| stream << ",\n";
|
| }
|
| stream << "]\n";
|
| @@ -232,32 +252,41 @@ void BytecodeExpectationsPrinter::PrintCodeSnippet(
|
| stream << "\"\n";
|
| }
|
|
|
| +void BytecodeExpectationsPrinter::PrintHandlers(
|
| + std::ostream& stream, i::Handle<i::BytecodeArray> bytecode_array) const {
|
| + stream << "handlers: [\n";
|
| + HandlerTable* table = HandlerTable::cast(bytecode_array->handler_table());
|
| + for (int i = 0, num_entries = table->NumberOfRangeEntries(); i < num_entries;
|
| + ++i) {
|
| + stream << " [" << table->GetRangeStart(i) << ", " << table->GetRangeEnd(i)
|
| + << ", " << table->GetRangeHandler(i) << "],\n";
|
| + }
|
| + stream << "]\n";
|
| +}
|
| +
|
| void BytecodeExpectationsPrinter::PrintBytecodeArray(
|
| - std::ostream& stream, const std::string& body,
|
| - i::Handle<i::BytecodeArray> bytecode_array) const {
|
| - stream << "---\n";
|
| - PrintCodeSnippet(stream, body);
|
| + std::ostream& stream, i::Handle<i::BytecodeArray> bytecode_array) const {
|
| PrintFrameSize(stream, bytecode_array);
|
| PrintBytecodeSequence(stream, bytecode_array);
|
| PrintConstantPool(stream, bytecode_array->constant_pool());
|
| -
|
| - // TODO(ssanfilippo) print handlers.
|
| - i::HandlerTable* handlers =
|
| - i::HandlerTable::cast(bytecode_array->handler_table());
|
| - CHECK_EQ(handlers->NumberOfRangeEntries(), 0);
|
| + PrintHandlers(stream, bytecode_array);
|
| }
|
|
|
| void BytecodeExpectationsPrinter::PrintExpectation(
|
| std::ostream& stream, const std::string& snippet) const {
|
| - const char* wrapper_function_name = "__genbckexp_wrapper__";
|
| + std::string source_code =
|
| + wrap_ ? WrapCodeInFunction(top_function_name_.c_str(), snippet) : snippet;
|
|
|
| - std::string source_code = WrapCodeInFunction(wrapper_function_name, snippet);
|
| - CompileAndRun(source_code.c_str());
|
| + v8::Local<v8::Script> script = Compile(source_code.c_str());
|
| +
|
| + if (execute_) Run(script);
|
|
|
| i::Handle<i::BytecodeArray> bytecode_array =
|
| - GetBytecodeArrayForGlobal(wrapper_function_name);
|
| + GetBytecodeArrayForGlobal(top_function_name_.c_str());
|
|
|
| - PrintBytecodeArray(stream, snippet, bytecode_array);
|
| + stream << "---\n";
|
| + PrintCodeSnippet(stream, snippet);
|
| + PrintBytecodeArray(stream, bytecode_array);
|
| stream << '\n';
|
| }
|
|
|
|
|