| 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 | 133 |
| 134 template <typename T> | 134 template <typename T> |
| 135 T* raw_mem_end() { | 135 T* raw_mem_end() { |
| 136 DCHECK(instance->mem_start); | 136 DCHECK(instance->mem_start); |
| 137 return reinterpret_cast<T*>(instance->mem_start + instance->mem_size); | 137 return reinterpret_cast<T*>(instance->mem_start + instance->mem_size); |
| 138 } | 138 } |
| 139 | 139 |
| 140 template <typename T> | 140 template <typename T> |
| 141 T raw_mem_at(int i) { | 141 T raw_mem_at(int i) { |
| 142 DCHECK(instance->mem_start); | 142 DCHECK(instance->mem_start); |
| 143 return ReadMemory(&(reinterpret_cast<T*>(instance->mem_start)[i])); | 143 return reinterpret_cast<T*>(instance->mem_start)[i]; |
| 144 } | 144 } |
| 145 | 145 |
| 146 template <typename T> | 146 template <typename T> |
| 147 T raw_val_at(int i) { | 147 T raw_val_at(int i) { |
| 148 return ReadMemory(reinterpret_cast<T*>(instance->mem_start + i)); | 148 T val; |
| 149 } | 149 memcpy(&val, reinterpret_cast<void*>(instance->mem_start + i), sizeof(T)); |
| 150 | 150 return val; |
| 151 template <typename T> | |
| 152 void WriteMemory(T* p, T val) { | |
| 153 WriteLittleEndianValue<T>(p, val); | |
| 154 } | |
| 155 | |
| 156 template <typename T> | |
| 157 T ReadMemory(T* p) { | |
| 158 return ReadLittleEndianValue<T>(p); | |
| 159 } | 151 } |
| 160 | 152 |
| 161 // Zero-initialize the memory. | 153 // Zero-initialize the memory. |
| 162 void BlankMemory() { | 154 void BlankMemory() { |
| 163 byte* raw = raw_mem_start<byte>(); | 155 byte* raw = raw_mem_start<byte>(); |
| 164 memset(raw, 0, instance->mem_size); | 156 memset(raw, 0, instance->mem_size); |
| 165 } | 157 } |
| 166 | 158 |
| 167 // Pseudo-randomly intialize the memory. | 159 // Pseudo-randomly intialize the memory. |
| 168 void RandomizeMemory(unsigned int seed = 88) { | 160 void RandomizeMemory(unsigned int seed = 88) { |
| (...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 // interpreter. | 755 // interpreter. |
| 764 #define WASM_EXEC_TEST(name) \ | 756 #define WASM_EXEC_TEST(name) \ |
| 765 void RunWasm_##name(WasmExecutionMode execution_mode); \ | 757 void RunWasm_##name(WasmExecutionMode execution_mode); \ |
| 766 TEST(RunWasmCompiled_##name) { RunWasm_##name(kExecuteCompiled); } \ | 758 TEST(RunWasmCompiled_##name) { RunWasm_##name(kExecuteCompiled); } \ |
| 767 TEST(RunWasmInterpreted_##name) { RunWasm_##name(kExecuteInterpreted); } \ | 759 TEST(RunWasmInterpreted_##name) { RunWasm_##name(kExecuteInterpreted); } \ |
| 768 void RunWasm_##name(WasmExecutionMode execution_mode) | 760 void RunWasm_##name(WasmExecutionMode execution_mode) |
| 769 | 761 |
| 770 } // namespace | 762 } // namespace |
| 771 | 763 |
| 772 #endif | 764 #endif |
| OLD | NEW |