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

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

Issue 1698403002: [Interpreter] generate-bytecode-expectations improvements. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Reorganize help message, --fix => --rebaseline for real. Created 4 years, 10 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 0094ed9cf81f3da9663c9dc1214eb9bb8943dbbe..a508e5b8c1a194b4a2e4fa55262de5d49c66fcbb 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,17 @@ 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();
+ return v8::Script::Compile(isolate_->GetCurrentContext(), source)
+ .ToLocalChecked();
+}
+void BytecodeExpectationsPrinter::Run(v8::Local<v8::Script> script) const {
v8::Local<v8::Value> result;
CHECK(script->Run(isolate_->GetCurrentContext()).ToLocal(&result));
-
- return result;
+ (void)result;
rmcilroy 2016/02/17 15:24:08 Just remove result variable and instead call: CHE
Stefano Sanfilippo 2016/02/17 16:40:49 Done.
}
i::Handle<v8::internal::BytecodeArray>
@@ -86,7 +91,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 +112,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 +147,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 +156,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 +221,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,35 +254,90 @@ 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';
}
+namespace {
+
+const char* ConstantPoolTypeToString(
+ BytecodeExpectationsPrinter::ConstantPoolType type) {
+ switch (type) {
+ case BytecodeExpectationsPrinter::ConstantPoolType::kDouble:
+ return "double";
+ case BytecodeExpectationsPrinter::ConstantPoolType::kInteger:
+ return "integer";
+ case BytecodeExpectationsPrinter::ConstantPoolType::kMixed:
+ return "mixed";
+ case BytecodeExpectationsPrinter::ConstantPoolType::kString:
+ return "string";
+ default:
+ UNREACHABLE();
+ return nullptr;
+ }
+}
+
+const char* BooleanToString(bool value) { return value ? "yes" : "no"; }
+
+} // namespace
+
+void BytecodeExpectationsPrinter::PrintOptionsHeader(std::ostream& stream) {
+ stream << "---"
+ "\npool type: "
+ << ConstantPoolTypeToString(const_pool_type_)
+ << "\nexecute: " << BooleanToString(execute_)
+ << "\nwrap: " << BooleanToString(wrap_);
+
+ if (top_function_name_ != kDefaultTopFunctionName) {
+ stream << "\nwrapper name: " << top_function_name_;
+ }
+
+ stream << "\n\n";
+}
+
+void BytecodeExpectationsPrinter::PrintExpectationsArray(
+ std::ostream& stream, const std::vector<std::string>& snippet_list) {
+ stream << "#\n# Autogenerated by generate-bytecode-expectations\n#\n\n";
rmcilroy 2016/02/17 15:24:08 I meant to move this into the generate-bytecode-ex
Stefano Sanfilippo 2016/02/17 16:40:49 The issue is that if we don't have this code insid
rmcilroy 2016/02/17 17:06:36 The tests should just ignore the headers and only
Stefano Sanfilippo 2016/02/17 17:31:18 OK, then I'll make the test harness skip the golde
+ PrintOptionsHeader(stream);
+ for (const std::string& snippet : snippet_list) {
+ PrintExpectation(stream, snippet);
+ }
+}
+
} // namespace interpreter
} // namespace internal
} // namespace v8

Powered by Google App Engine
This is Rietveld 408576698