Chromium Code Reviews| Index: test/cctest/wasm/wasm-run-utils.h |
| diff --git a/test/cctest/wasm/wasm-run-utils.h b/test/cctest/wasm/wasm-run-utils.h |
| index 8aa8cff940d050a7aff1ead5d5367569bcae970c..1721c97cfcefa36a3f473d0d941b9159aa3adf6c 100644 |
| --- a/test/cctest/wasm/wasm-run-utils.h |
| +++ b/test/cctest/wasm/wasm-run-utils.h |
| @@ -147,14 +147,57 @@ class TestingModule : public ModuleEnv { |
| template <typename T> |
| T raw_mem_at(int i) { |
| DCHECK(instance->mem_start); |
| - return reinterpret_cast<T*>(instance->mem_start)[i]; |
| + return ReadMemory(&(reinterpret_cast<T*>(instance->mem_start)[i])); |
| } |
| template <typename T> |
| T raw_val_at(int i) { |
| - T val; |
| - memcpy(&val, reinterpret_cast<void*>(instance->mem_start + i), sizeof(T)); |
| - return val; |
| + return ReadMemory(reinterpret_cast<T*>(instance->mem_start + i)); |
| + } |
| + |
| + template <typename T> |
| + void WriteMemory(T* p, T val) { |
|
titzer
2016/06/06 07:44:00
Can we unify these routines with the others?
ivica.bogosavljevic
2016/06/13 14:59:02
We could use ReadLittleEndianValue and WriteLittle
|
| +#if defined(V8_TARGET_LITTLE_ENDIAN) |
| + memcpy(p, &val, sizeof(T)); |
| +#elif defined(V8_TARGET_BIG_ENDIAN) |
| + byte* src = reinterpret_cast<byte*>(&val); |
| + byte* dst = reinterpret_cast<byte*>(p); |
| + for (int i = 0; i < sizeof(T); i++) { |
| + dst[i] = src[sizeof(T) - i - 1]; |
| + } |
| +#else |
| +#error Unsupported endianness |
| +#endif |
|
ivica.bogosavljevic
2016/06/13 14:59:02
For myself: Commented code, needs to be removed
|
| + // byte * tmp = reinterpret_cast<byte*>(p); |
| + // T v = val; |
| + // for (int i = 0; i < sizeof(T); i++) { |
| + // tmp[i] = v & 0xff; |
| + // v = v >> 8; |
| + // } |
| + } |
| + |
| + template <typename T> |
| + T ReadMemory(T* p) { |
| + T ret; |
| +#if defined(V8_TARGET_LITTLE_ENDIAN) |
| + memcpy(&ret, p, sizeof(T)); |
| +#elif defined(V8_TARGET_BIG_ENDIAN) |
| + byte* src = reinterpret_cast<byte*>(p); |
| + byte* dst = reinterpret_cast<byte*>(&ret); |
| + for (int i = 0; i < sizeof(T); i++) { |
| + dst[i] = src[sizeof(T) - i - 1]; |
| + } |
| +#else |
| +#error Unsupported endianness |
| +#endif |
| + return ret; |
| + // T val = 0; |
| + // byte * tmp = reinterpret_cast<byte*>(p); |
| + // for (int i = sizeof(T) - 1; i >= 0; i--) { |
| + // val = val << 8; |
| + // val = val | tmp[i]; |
| + // } |
| + // return val; |
| } |
| // Zero-initialize the memory. |