OLD | NEW |
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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 namespace { | 59 namespace { |
60 using namespace v8::base; | 60 using namespace v8::base; |
61 using namespace v8::internal; | 61 using namespace v8::internal; |
62 using namespace v8::internal::compiler; | 62 using namespace v8::internal::compiler; |
63 using namespace v8::internal::wasm; | 63 using namespace v8::internal::wasm; |
64 | 64 |
65 const uint32_t kMaxGlobalsSize = 128; | 65 const uint32_t kMaxGlobalsSize = 128; |
66 | 66 |
67 // A helper for module environments that adds the ability to allocate memory | 67 // A helper for module environments that adds the ability to allocate memory |
68 // and global variables. Contains a built-in {WasmModule} and | 68 // and global variables. Contains a built-in {WasmModule} and |
69 // {WasmModuleInstance}. | 69 // {WasmInstance}. |
70 class TestingModule : public ModuleEnv { | 70 class TestingModule : public ModuleEnv { |
71 public: | 71 public: |
72 explicit TestingModule(WasmExecutionMode mode = kExecuteCompiled) | 72 explicit TestingModule(WasmExecutionMode mode = kExecuteCompiled) |
73 : execution_mode_(mode), | 73 : execution_mode_(mode), |
74 instance_(&module_), | 74 instance_(&module_), |
75 isolate_(CcTest::InitIsolateOnce()), | 75 isolate_(CcTest::InitIsolateOnce()), |
76 global_offset(0), | 76 global_offset(0), |
77 interpreter_(mode == kExecuteInterpreted | 77 interpreter_(mode == kExecuteInterpreted |
78 ? new WasmInterpreter(&instance_, &allocator_) | 78 ? new WasmInterpreter(&instance_, &allocator_) |
79 : nullptr) { | 79 : nullptr) { |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 } | 251 } |
252 | 252 |
253 WasmFunction* GetFunctionAt(int index) { return &module_.functions[index]; } | 253 WasmFunction* GetFunctionAt(int index) { return &module_.functions[index]; } |
254 | 254 |
255 WasmInterpreter* interpreter() { return interpreter_; } | 255 WasmInterpreter* interpreter() { return interpreter_; } |
256 WasmExecutionMode execution_mode() { return execution_mode_; } | 256 WasmExecutionMode execution_mode() { return execution_mode_; } |
257 | 257 |
258 private: | 258 private: |
259 WasmExecutionMode execution_mode_; | 259 WasmExecutionMode execution_mode_; |
260 WasmModule module_; | 260 WasmModule module_; |
261 WasmModuleInstance instance_; | 261 WasmInstance instance_; |
262 Isolate* isolate_; | 262 Isolate* isolate_; |
263 v8::internal::AccountingAllocator allocator_; | 263 v8::internal::AccountingAllocator allocator_; |
264 uint32_t global_offset; | 264 uint32_t global_offset; |
265 V8_ALIGNED(8) byte global_data[kMaxGlobalsSize]; // preallocated global data. | 265 V8_ALIGNED(8) byte global_data[kMaxGlobalsSize]; // preallocated global data. |
266 WasmInterpreter* interpreter_; | 266 WasmInterpreter* interpreter_; |
267 | 267 |
268 const WasmGlobal* AddGlobal(LocalType type) { | 268 const WasmGlobal* AddGlobal(LocalType type) { |
269 byte size = WasmOpcodes::MemSize(WasmOpcodes::MachineTypeFor(type)); | 269 byte size = WasmOpcodes::MemSize(WasmOpcodes::MachineTypeFor(type)); |
270 global_offset = (global_offset + size - 1) & ~(size - 1); // align | 270 global_offset = (global_offset + size - 1) & ~(size - 1); // align |
271 module_.globals.push_back( | 271 module_.globals.push_back( |
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
784 // interpreter. | 784 // interpreter. |
785 #define WASM_EXEC_TEST(name) \ | 785 #define WASM_EXEC_TEST(name) \ |
786 void RunWasm_##name(WasmExecutionMode execution_mode); \ | 786 void RunWasm_##name(WasmExecutionMode execution_mode); \ |
787 TEST(RunWasmCompiled_##name) { RunWasm_##name(kExecuteCompiled); } \ | 787 TEST(RunWasmCompiled_##name) { RunWasm_##name(kExecuteCompiled); } \ |
788 TEST(RunWasmInterpreted_##name) { RunWasm_##name(kExecuteInterpreted); } \ | 788 TEST(RunWasmInterpreted_##name) { RunWasm_##name(kExecuteInterpreted); } \ |
789 void RunWasm_##name(WasmExecutionMode execution_mode) | 789 void RunWasm_##name(WasmExecutionMode execution_mode) |
790 | 790 |
791 } // namespace | 791 } // namespace |
792 | 792 |
793 #endif | 793 #endif |
OLD | NEW |