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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "test/cctest/interpreter/bytecode-expectations-printer.h" 5 #include "test/cctest/interpreter/bytecode-expectations-printer.h"
6 6
7 #include <iostream> 7 #include <iostream>
8 8
9 #include "include/libplatform/libplatform.h" 9 #include "include/libplatform/libplatform.h"
10 #include "include/v8.h" 10 #include "include/v8.h"
(...skipping 20 matching lines...) Expand all
31 std::string BytecodeExpectationsPrinter::WrapCodeInFunction( 31 std::string BytecodeExpectationsPrinter::WrapCodeInFunction(
32 const char* function_name, const std::string& function_body) const { 32 const char* function_name, const std::string& function_body) const {
33 std::ostringstream program_stream; 33 std::ostringstream program_stream;
34 program_stream << "function " << function_name << "() {" << function_body 34 program_stream << "function " << function_name << "() {" << function_body
35 << "}\n" 35 << "}\n"
36 << function_name << "();"; 36 << function_name << "();";
37 37
38 return program_stream.str(); 38 return program_stream.str();
39 } 39 }
40 40
41 v8::Local<v8::Value> BytecodeExpectationsPrinter::CompileAndRun( 41 v8::Local<v8::Script> BytecodeExpectationsPrinter::Compile(
42 const char* program) const { 42 const char* program) const {
43 v8::Local<v8::String> source = V8StringFromUTF8(program); 43 v8::Local<v8::String> source = V8StringFromUTF8(program);
44 v8::Local<v8::Script> script = 44 return v8::Script::Compile(isolate_->GetCurrentContext(), source)
45 v8::Script::Compile(isolate_->GetCurrentContext(), source) 45 .ToLocalChecked();
46 .ToLocalChecked(); 46 }
47 47
48 v8::Local<v8::Value> BytecodeExpectationsPrinter::Run(
49 v8::Local<v8::Script> script) const {
48 v8::Local<v8::Value> result; 50 v8::Local<v8::Value> result;
49 CHECK(script->Run(isolate_->GetCurrentContext()).ToLocal(&result)); 51 CHECK(script->Run(isolate_->GetCurrentContext()).ToLocal(&result));
50
51 return result; 52 return result;
rmcilroy 2016/02/16 16:43:48 Not using the result? If not, just drop the return
Stefano Sanfilippo 2016/02/16 20:28:26 Done.
52 } 53 }
53 54
54 i::Handle<v8::internal::BytecodeArray> 55 i::Handle<v8::internal::BytecodeArray>
55 BytecodeExpectationsPrinter::GetBytecodeArrayForGlobal( 56 BytecodeExpectationsPrinter::GetBytecodeArrayForGlobal(
56 const char* global_name) const { 57 const char* global_name) const {
57 const v8::Local<v8::Context>& context = isolate_->GetCurrentContext(); 58 const v8::Local<v8::Context>& context = isolate_->GetCurrentContext();
58 v8::Local<v8::String> v8_global_name = V8StringFromUTF8(global_name); 59 v8::Local<v8::String> v8_global_name = V8StringFromUTF8(global_name);
59 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( 60 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
60 context->Global()->Get(context, v8_global_name).ToLocalChecked()); 61 context->Global()->Get(context, v8_global_name).ToLocalChecked());
61 i::Handle<i::JSFunction> js_function = 62 i::Handle<i::JSFunction> js_function =
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 break; 101 break;
101 default: 102 default:
102 UNREACHABLE(); 103 UNREACHABLE();
103 return; 104 return;
104 } 105 }
105 106
106 if (Bytecodes::IsRegisterOperandType(op_type)) { 107 if (Bytecodes::IsRegisterOperandType(op_type)) {
107 Register register_value = bytecode_iter.GetRegisterOperand(op_index); 108 Register register_value = bytecode_iter.GetRegisterOperand(op_index);
108 stream << 'R'; 109 stream << 'R';
109 if (op_size != OperandSize::kByte) stream << size_tag; 110 if (op_size != OperandSize::kByte) stream << size_tag;
110 stream << '(' << register_value.index() << ')'; 111 if (register_value.is_new_target()) {
112 stream << "(new_target)";
113 } else if (register_value.is_current_context()) {
114 stream << "(context)";
115 } else if (register_value.is_function_closure()) {
116 stream << "(closure)";
117 } else {
118 stream << '(' << register_value.index() << ')';
rmcilroy 2016/02/16 16:43:48 Just realized, could you also special case paramet
Stefano Sanfilippo 2016/02/16 20:28:26 Done. If I understand correctly, the format you e
rmcilroy 2016/02/17 10:16:59 Yes. Could you also special-case <this> e.g., see
Stefano Sanfilippo 2016/02/17 14:32:28 Done.
119 }
111 } else { 120 } else {
112 stream << 'U' << size_tag << '('; 121 stream << 'U' << size_tag << '(';
113 122
114 if (Bytecodes::IsImmediateOperandType(op_type)) { 123 if (Bytecodes::IsImmediateOperandType(op_type)) {
115 // We need a cast, otherwise the result is printed as char. 124 // We need a cast, otherwise the result is printed as char.
116 stream << static_cast<int>(bytecode_iter.GetImmediateOperand(op_index)); 125 stream << static_cast<int>(bytecode_iter.GetImmediateOperand(op_index));
117 } else if (Bytecodes::IsRegisterCountOperandType(op_type)) { 126 } else if (Bytecodes::IsRegisterCountOperandType(op_type)) {
118 stream << bytecode_iter.GetRegisterCountOperand(op_index); 127 stream << bytecode_iter.GetRegisterCountOperand(op_index);
119 } else if (Bytecodes::IsIndexOperandType(op_type)) { 128 } else if (Bytecodes::IsIndexOperandType(op_type)) {
120 stream << bytecode_iter.GetIndexOperand(op_index); 129 stream << bytecode_iter.GetIndexOperand(op_index);
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 std::stringstream body_stream(body); 234 std::stringstream body_stream(body);
226 std::string body_line; 235 std::string body_line;
227 while (std::getline(body_stream, body_line)) { 236 while (std::getline(body_stream, body_line)) {
228 stream << " "; 237 stream << " ";
229 PrintEscapedString(stream, body_line); 238 PrintEscapedString(stream, body_line);
230 stream << '\n'; 239 stream << '\n';
231 } 240 }
232 stream << "\"\n"; 241 stream << "\"\n";
233 } 242 }
234 243
244 void BytecodeExpectationsPrinter::PrintHandlers(
245 std::ostream& stream, i::Handle<i::BytecodeArray> bytecode_array) const {
246 stream << "handlers: [\n";
247 HandlerTable* table = HandlerTable::cast(bytecode_array->handler_table());
248 for (int i = 0, num_entries = table->NumberOfRangeEntries(); i < num_entries;
249 ++i) {
250 stream << " [" << table->GetRangeStart(i) << ", " << table->GetRangeEnd(i)
251 << ", " << table->GetRangeHandler(i) << "],\n";
252 }
253 stream << "]\n";
254 }
255
235 void BytecodeExpectationsPrinter::PrintBytecodeArray( 256 void BytecodeExpectationsPrinter::PrintBytecodeArray(
236 std::ostream& stream, const std::string& body, 257 std::ostream& stream, const std::string& body,
237 i::Handle<i::BytecodeArray> bytecode_array) const { 258 i::Handle<i::BytecodeArray> bytecode_array) const {
238 stream << "---\n"; 259 stream << "---\n";
239 PrintCodeSnippet(stream, body); 260 PrintCodeSnippet(stream, body);
240 PrintFrameSize(stream, bytecode_array); 261 PrintFrameSize(stream, bytecode_array);
241 PrintBytecodeSequence(stream, bytecode_array); 262 PrintBytecodeSequence(stream, bytecode_array);
242 PrintConstantPool(stream, bytecode_array->constant_pool()); 263 PrintConstantPool(stream, bytecode_array->constant_pool());
243 264 PrintHandlers(stream, bytecode_array);
244 // TODO(ssanfilippo) print handlers.
245 i::HandlerTable* handlers =
246 i::HandlerTable::cast(bytecode_array->handler_table());
247 CHECK_EQ(handlers->NumberOfRangeEntries(), 0);
248 } 265 }
249 266
250 void BytecodeExpectationsPrinter::PrintExpectation( 267 void BytecodeExpectationsPrinter::PrintExpectation(
251 std::ostream& stream, const std::string& snippet) const { 268 std::ostream& stream, const std::string& snippet) const {
252 const char* wrapper_function_name = "__genbckexp_wrapper__"; 269 std::string source_code =
270 wrap_ ? WrapCodeInFunction(top_function_name_.c_str(), snippet) : snippet;
253 271
254 std::string source_code = WrapCodeInFunction(wrapper_function_name, snippet); 272 v8::Local<v8::Script> script = Compile(source_code.c_str());
255 CompileAndRun(source_code.c_str()); 273
274 if (execute_) Run(script);
rmcilroy 2016/02/16 16:43:48 Out of interest, when do you not want to run the c
Stefano Sanfilippo 2016/02/16 20:28:26 Apparently, MakeTopLevelBytecode does not run the
rmcilroy 2016/02/17 10:16:59 Ahh I see, yeah you are right, top level code will
Stefano Sanfilippo 2016/02/17 14:32:28 Done.
256 275
257 i::Handle<i::BytecodeArray> bytecode_array = 276 i::Handle<i::BytecodeArray> bytecode_array =
258 GetBytecodeArrayForGlobal(wrapper_function_name); 277 GetBytecodeArrayForGlobal(top_function_name_.c_str());
259 278
260 PrintBytecodeArray(stream, snippet, bytecode_array); 279 PrintBytecodeArray(stream, snippet, bytecode_array);
261 stream << '\n'; 280 stream << '\n';
262 } 281 }
263 282
264 } // namespace interpreter 283 } // namespace interpreter
265 } // namespace internal 284 } // namespace internal
266 } // namespace v8 285 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698