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