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

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

Issue 2540133002: [wasm] Remove raw byte pointers from WasmModule (Closed)
Patch Set: Address comments 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-run-wasm-module.cc ('k') | test/common/wasm/wasm-module-runner.h » ('j') | 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 <stdint.h> 8 #include <stdint.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <string.h> 10 #include <string.h>
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 using namespace v8::internal::wasm; 65 using namespace v8::internal::wasm;
66 66
67 const uint32_t kMaxGlobalsSize = 128; 67 const uint32_t kMaxGlobalsSize = 128;
68 68
69 // A helper for module environments that adds the ability to allocate memory 69 // A helper for module environments that adds the ability to allocate memory
70 // and global variables. Contains a built-in {WasmModule} and 70 // and global variables. Contains a built-in {WasmModule} and
71 // {WasmInstance}. 71 // {WasmInstance}.
72 class TestingModule : public ModuleEnv { 72 class TestingModule : public ModuleEnv {
73 public: 73 public:
74 explicit TestingModule(WasmExecutionMode mode = kExecuteCompiled) 74 explicit TestingModule(WasmExecutionMode mode = kExecuteCompiled)
75 : execution_mode_(mode), 75 : ModuleEnv(&module_, &instance_),
76 execution_mode_(mode),
76 instance_(&module_), 77 instance_(&module_),
77 isolate_(CcTest::InitIsolateOnce()), 78 isolate_(CcTest::InitIsolateOnce()),
78 global_offset(0), 79 global_offset(0),
79 interpreter_(mode == kExecuteInterpreted 80 interpreter_(mode == kExecuteInterpreted
80 ? new WasmInterpreter(&instance_, &allocator_) 81 ? new WasmInterpreter(
82 ModuleBytesEnv(&module_, &instance_,
83 Vector<const byte>::empty()),
84 &allocator_)
81 : nullptr) { 85 : nullptr) {
82 module = &module_;
83 instance = &instance_;
84 instance->module = &module_; 86 instance->module = &module_;
85 instance->globals_start = global_data; 87 instance->globals_start = global_data;
86 module_.globals_size = kMaxGlobalsSize; 88 module_.globals_size = kMaxGlobalsSize;
87 instance->mem_start = nullptr; 89 instance->mem_start = nullptr;
88 instance->mem_size = 0; 90 instance->mem_size = 0;
89 origin = kWasmOrigin;
90 memset(global_data, 0, sizeof(global_data)); 91 memset(global_data, 0, sizeof(global_data));
91 } 92 }
92 93
93 ~TestingModule() { 94 ~TestingModule() {
94 if (instance->mem_start) { 95 if (instance->mem_start) {
95 free(instance->mem_start); 96 free(instance->mem_start);
96 } 97 }
97 if (interpreter_) delete interpreter_; 98 if (interpreter_) delete interpreter_;
98 } 99 }
99 100
100 void ChangeOriginToAsmjs() { origin = kAsmJsOrigin; } 101 void ChangeOriginToAsmjs() { module_.origin = kAsmJsOrigin; }
101 102
102 byte* AddMemory(uint32_t size) { 103 byte* AddMemory(uint32_t size) {
103 CHECK_NULL(instance->mem_start); 104 CHECK_NULL(instance->mem_start);
104 CHECK_EQ(0u, instance->mem_size); 105 CHECK_EQ(0u, instance->mem_size);
105 instance->mem_start = reinterpret_cast<byte*>(malloc(size)); 106 instance->mem_start = reinterpret_cast<byte*>(malloc(size));
106 CHECK(instance->mem_start); 107 CHECK(instance->mem_start);
107 memset(instance->mem_start, 0, size); 108 memset(instance->mem_start, 0, size);
108 instance->mem_size = size; 109 instance->mem_size = size;
109 return raw_mem_start<byte>(); 110 return raw_mem_start<byte>();
110 } 111 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 return index; 206 return index;
206 } 207 }
207 208
208 Handle<JSFunction> WrapCode(uint32_t index) { 209 Handle<JSFunction> WrapCode(uint32_t index) {
209 // Wrap the code so it can be called as a JS function. 210 // Wrap the code so it can be called as a JS function.
210 Handle<String> name = isolate_->factory()->NewStringFromStaticChars("main"); 211 Handle<String> name = isolate_->factory()->NewStringFromStaticChars("main");
211 Handle<WasmInstanceObject> instance_obj(0, isolate_); 212 Handle<WasmInstanceObject> instance_obj(0, isolate_);
212 Handle<Code> code = instance->function_code[index]; 213 Handle<Code> code = instance->function_code[index];
213 WasmJs::InstallWasmMapsIfNeeded(isolate_, isolate_->native_context()); 214 WasmJs::InstallWasmMapsIfNeeded(isolate_, isolate_->native_context());
214 Handle<Code> ret_code = 215 Handle<Code> ret_code =
215 compiler::CompileJSToWasmWrapper(isolate_, this, code, index); 216 compiler::CompileJSToWasmWrapper(isolate_, &module_, code, index);
216 Handle<JSFunction> ret = WasmExportedFunction::New( 217 Handle<JSFunction> ret = WasmExportedFunction::New(
217 isolate_, instance_obj, name, ret_code, 218 isolate_, instance_obj, name, ret_code,
218 static_cast<int>(this->module->functions[index].sig->parameter_count()), 219 static_cast<int>(this->module->functions[index].sig->parameter_count()),
219 static_cast<int>(index)); 220 static_cast<int>(index));
220 return ret; 221 return ret;
221 } 222 }
222 223
223 void SetFunctionCode(uint32_t index, Handle<Code> code) { 224 void SetFunctionCode(uint32_t index, Handle<Code> code) {
224 instance->function_code[index] = code; 225 instance->function_code[index] = code;
225 } 226 }
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 debug_name_(debug_name), 475 debug_name_(debug_name),
475 local_decls(main_zone(), sig), 476 local_decls(main_zone(), sig),
476 source_position_table_(this->graph()), 477 source_position_table_(this->graph()),
477 interpreter_(nullptr) { 478 interpreter_(nullptr) {
478 // Create our own function. 479 // Create our own function.
479 function_ = new WasmFunction(); 480 function_ = new WasmFunction();
480 function_->sig = sig; 481 function_->sig = sig;
481 function_->func_index = 0; 482 function_->func_index = 0;
482 function_->sig_index = 0; 483 function_->sig_index = 0;
483 if (mode == kExecuteInterpreted) { 484 if (mode == kExecuteInterpreted) {
484 interpreter_ = new WasmInterpreter(nullptr, zone()->allocator()); 485 ModuleBytesEnv empty_env(nullptr, nullptr, Vector<const byte>::empty());
486 interpreter_ = new WasmInterpreter(empty_env, zone()->allocator());
485 int index = interpreter_->AddFunctionForTesting(function_); 487 int index = interpreter_->AddFunctionForTesting(function_);
486 CHECK_EQ(0, index); 488 CHECK_EQ(0, index);
487 } 489 }
488 } 490 }
489 491
490 explicit WasmFunctionCompiler( 492 explicit WasmFunctionCompiler(
491 FunctionSig* sig, TestingModule* module, 493 FunctionSig* sig, TestingModule* module,
492 Vector<const char> debug_name = ArrayVector("<WASM UNNAMED>")) 494 Vector<const char> debug_name = ArrayVector("<WASM UNNAMED>"))
493 : GraphAndBuilders(main_zone()), 495 : GraphAndBuilders(main_zone()),
494 execution_mode_(module->execution_mode()), 496 execution_mode_(module->execution_mode()),
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 // interpreter. 796 // interpreter.
795 #define WASM_EXEC_TEST(name) \ 797 #define WASM_EXEC_TEST(name) \
796 void RunWasm_##name(WasmExecutionMode execution_mode); \ 798 void RunWasm_##name(WasmExecutionMode execution_mode); \
797 TEST(RunWasmCompiled_##name) { RunWasm_##name(kExecuteCompiled); } \ 799 TEST(RunWasmCompiled_##name) { RunWasm_##name(kExecuteCompiled); } \
798 TEST(RunWasmInterpreted_##name) { RunWasm_##name(kExecuteInterpreted); } \ 800 TEST(RunWasmInterpreted_##name) { RunWasm_##name(kExecuteInterpreted); } \
799 void RunWasm_##name(WasmExecutionMode execution_mode) 801 void RunWasm_##name(WasmExecutionMode execution_mode)
800 802
801 } // namespace 803 } // namespace
802 804
803 #endif 805 #endif
OLDNEW
« no previous file with comments | « test/cctest/wasm/test-run-wasm-module.cc ('k') | test/common/wasm/wasm-module-runner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698