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

Side by Side Diff: test/cctest/wasm/wasm-run-utils.h

Issue 2588763002: [wasm] Implement GetPossibleBreakpoints (Closed)
Patch Set: Address comment Created 4 years 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
« no previous file with comments | « test/cctest/wasm/test-wasm-breakpoints.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef WASM_RUN_UTILS_H 5 #ifndef WASM_RUN_UTILS_H
6 #define WASM_RUN_UTILS_H 6 #define WASM_RUN_UTILS_H
7 7
8 #include <setjmp.h> 8 #include <setjmp.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 #include <stdlib.h> 10 #include <stdlib.h>
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 int table_size = static_cast<int>(table.values.size()); 259 int table_size = static_cast<int>(table.values.size());
260 for (int j = 0; j < table_size; j++) { 260 for (int j = 0; j < table_size; j++) {
261 WasmFunction& function = module_.functions[table.values[j]]; 261 WasmFunction& function = module_.functions[table.values[j]];
262 array->set(j, Smi::FromInt(table.map.Find(function.sig))); 262 array->set(j, Smi::FromInt(table.map.Find(function.sig)));
263 array->set(j + table_size, 263 array->set(j + table_size,
264 *instance->function_code[function.func_index]); 264 *instance->function_code[function.func_index]);
265 } 265 }
266 } 266 }
267 } 267 }
268 268
269 uint32_t AddBytes(Vector<const byte> bytes) {
270 Handle<SeqOneByteString> old_bytes =
271 instance_object_->get_compiled_module()->module_bytes();
272 uint32_t old_size = static_cast<uint32_t>(old_bytes->length());
273 ScopedVector<byte> new_bytes(old_size + bytes.length());
274 memcpy(new_bytes.start(), old_bytes->GetChars(), old_size);
275 memcpy(new_bytes.start() + old_size, bytes.start(), bytes.length());
276 Handle<SeqOneByteString> new_bytes_str = Handle<SeqOneByteString>::cast(
277 isolate_->factory()->NewStringFromOneByte(new_bytes).ToHandleChecked());
278 instance_object_->get_compiled_module()->set_module_bytes(new_bytes_str);
279 return old_size;
280 }
281
269 WasmFunction* GetFunctionAt(int index) { return &module_.functions[index]; } 282 WasmFunction* GetFunctionAt(int index) { return &module_.functions[index]; }
270 283
271 WasmInterpreter* interpreter() { return interpreter_; } 284 WasmInterpreter* interpreter() { return interpreter_; }
272 WasmExecutionMode execution_mode() { return execution_mode_; } 285 WasmExecutionMode execution_mode() { return execution_mode_; }
273 Isolate* isolate() { return isolate_; } 286 Isolate* isolate() { return isolate_; }
274 Handle<WasmInstanceObject> instance_object() { return instance_object_; } 287 Handle<WasmInstanceObject> instance_object() { return instance_object_; }
275 288
276 private: 289 private:
277 WasmExecutionMode execution_mode_; 290 WasmExecutionMode execution_mode_;
278 WasmModule module_; 291 WasmModule module_;
279 WasmInstance instance_; 292 WasmInstance instance_;
280 Isolate* isolate_; 293 Isolate* isolate_;
281 uint32_t global_offset; 294 uint32_t global_offset;
282 V8_ALIGNED(8) byte global_data[kMaxGlobalsSize]; // preallocated global data. 295 V8_ALIGNED(8) byte global_data[kMaxGlobalsSize]; // preallocated global data.
283 WasmInterpreter* interpreter_; 296 WasmInterpreter* interpreter_;
284 Handle<WasmInstanceObject> instance_object_; 297 Handle<WasmInstanceObject> instance_object_;
285 298
286 const WasmGlobal* AddGlobal(LocalType type) { 299 const WasmGlobal* AddGlobal(LocalType type) {
287 byte size = WasmOpcodes::MemSize(WasmOpcodes::MachineTypeFor(type)); 300 byte size = WasmOpcodes::MemSize(WasmOpcodes::MachineTypeFor(type));
288 global_offset = (global_offset + size - 1) & ~(size - 1); // align 301 global_offset = (global_offset + size - 1) & ~(size - 1); // align
289 module_.globals.push_back( 302 module_.globals.push_back(
290 {type, true, WasmInitExpr(), global_offset, false, false}); 303 {type, true, WasmInitExpr(), global_offset, false, false});
291 global_offset += size; 304 global_offset += size;
292 // limit number of globals. 305 // limit number of globals.
293 CHECK_LT(global_offset, kMaxGlobalsSize); 306 CHECK_LT(global_offset, kMaxGlobalsSize);
294 return &module->globals.back(); 307 return &module->globals.back();
295 } 308 }
296 309
297 uint32_t AddBytes(Vector<const byte> bytes) {
298 Handle<SeqOneByteString> old_bytes =
299 instance_object_->get_compiled_module()->module_bytes();
300 uint32_t old_size = static_cast<uint32_t>(old_bytes->length());
301 ScopedVector<byte> new_bytes(old_size + bytes.length());
302 memcpy(new_bytes.start(), old_bytes->GetChars(), old_size);
303 memcpy(new_bytes.start() + old_size, bytes.start(), bytes.length());
304 Handle<SeqOneByteString> new_bytes_str = Handle<SeqOneByteString>::cast(
305 isolate_->factory()->NewStringFromOneByte(new_bytes).ToHandleChecked());
306 instance_object_->get_compiled_module()->set_module_bytes(new_bytes_str);
307 return old_size;
308 }
309
310 Handle<WasmInstanceObject> InitInstanceObject() { 310 Handle<WasmInstanceObject> InitInstanceObject() {
311 Handle<Managed<wasm::WasmModule>> module_wrapper = 311 Handle<Managed<wasm::WasmModule>> module_wrapper =
312 Managed<wasm::WasmModule>::New(isolate_, &module_, false); 312 Managed<wasm::WasmModule>::New(isolate_, &module_, false);
313 Handle<WasmCompiledModule> compiled_module = 313 Handle<WasmCompiledModule> compiled_module =
314 WasmCompiledModule::New(isolate_, module_wrapper); 314 WasmCompiledModule::New(isolate_, module_wrapper);
315 // Minimally initialize the compiled module such that IsWasmCompiledModule 315 // Minimally initialize the compiled module such that IsWasmCompiledModule
316 // passes. 316 // passes.
317 // If tests need more (correct) information, add it later. 317 // If tests need more (correct) information, add it later.
318 compiled_module->set_min_mem_pages(0); 318 compiled_module->set_min_mem_pages(0);
319 compiled_module->set_max_mem_pages(Smi::kMaxValue); 319 compiled_module->set_max_mem_pages(Smi::kMaxValue);
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 CallDescriptor* descriptor() { 491 CallDescriptor* descriptor() {
492 if (descriptor_ == nullptr) { 492 if (descriptor_ == nullptr) {
493 descriptor_ = testing_module_->GetWasmCallDescriptor(zone(), sig); 493 descriptor_ = testing_module_->GetWasmCallDescriptor(zone(), sig);
494 } 494 }
495 return descriptor_; 495 return descriptor_;
496 } 496 }
497 uint32_t function_index() { return function_->func_index; } 497 uint32_t function_index() { return function_->func_index; }
498 498
499 void Build(const byte* start, const byte* end) { 499 void Build(const byte* start, const byte* end) {
500 local_decls.Prepend(zone(), &start, &end); 500 local_decls.Prepend(zone(), &start, &end);
501
502 CHECK_GE(kMaxInt, end - start);
503 int len = static_cast<int>(end - start);
504 function_->code_start_offset =
505 testing_module_->AddBytes(Vector<const byte>(start, len));
506 function_->code_end_offset = function_->code_start_offset + len;
507
501 if (interpreter_) { 508 if (interpreter_) {
502 // Add the code to the interpreter. 509 // Add the code to the interpreter.
503 CHECK(interpreter_->SetFunctionCodeForTesting(function_, start, end)); 510 CHECK(interpreter_->SetFunctionCodeForTesting(function_, start, end));
504 return; 511 return;
505 } 512 }
506 513
507 // Build the TurboFan graph. 514 // Build the TurboFan graph.
508 TestBuildingGraph(zone(), &jsgraph, testing_module_, sig, 515 TestBuildingGraph(zone(), &jsgraph, testing_module_, sig,
509 &source_position_table_, start, end); 516 &source_position_table_, start, end);
510 Handle<Code> code = Compile(); 517 Handle<Code> code = Compile();
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 void RunWasm_##name(WasmExecutionMode execution_mode) 790 void RunWasm_##name(WasmExecutionMode execution_mode)
784 791
785 #define WASM_EXEC_COMPILED_TEST(name) \ 792 #define WASM_EXEC_COMPILED_TEST(name) \
786 void RunWasm_##name(WasmExecutionMode execution_mode); \ 793 void RunWasm_##name(WasmExecutionMode execution_mode); \
787 TEST(RunWasmCompiled_##name) { RunWasm_##name(kExecuteCompiled); } \ 794 TEST(RunWasmCompiled_##name) { RunWasm_##name(kExecuteCompiled); } \
788 void RunWasm_##name(WasmExecutionMode execution_mode) 795 void RunWasm_##name(WasmExecutionMode execution_mode)
789 796
790 } // namespace 797 } // namespace
791 798
792 #endif 799 #endif
OLDNEW
« no previous file with comments | « test/cctest/wasm/test-wasm-breakpoints.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698