diff options
author | Ayke van Laethem <[email protected]> | 2022-12-18 22:43:52 +0100 |
---|---|---|
committer | Ayke <[email protected]> | 2023-01-17 19:32:18 +0100 |
commit | f9d0ff3becbe6835d32a146895d797d53a09fc15 (patch) | |
tree | 4b7712ca2bf3dd5934e9d7fb5a33ece3def7b0f0 /interp | |
parent | 17176a2ceaa9ba9849671c3987588dd212377a8f (diff) | |
download | tinygo-f9d0ff3becbe6835d32a146895d797d53a09fc15.tar.gz tinygo-f9d0ff3becbe6835d32a146895d797d53a09fc15.zip |
all: store data layout as little endian value
This makes it much easier to read the value at runtime, as pointer
indices are naturally little endian. It should not affect anything else
in the program.
Diffstat (limited to 'interp')
-rw-r--r-- | interp/memory.go | 10 | ||||
-rw-r--r-- | interp/testdata/alloc.ll | 2 |
2 files changed, 11 insertions, 1 deletions
diff --git a/interp/memory.go b/interp/memory.go index 248825f64..88b7783e4 100644 --- a/interp/memory.go +++ b/interp/memory.go @@ -1289,6 +1289,7 @@ func (r *runner) readObjectLayout(layoutValue value) (uint64, *big.Int) { } rawBytes[i] = byte(v) } + reverseBytes(rawBytes) // little-endian to big-endian bitmap := new(big.Int).SetBytes(rawBytes) return objectSizeWords, bitmap } @@ -1338,3 +1339,12 @@ func (r *runner) getLLVMTypeFromLayout(layoutValue value) llvm.Type { } return llvmLayoutType } + +// Reverse a slice of bytes. From the wiki: +// https://github.com/golang/go/wiki/SliceTricks#reversing +func reverseBytes(buf []byte) { + for i := len(buf)/2 - 1; i >= 0; i-- { + opp := len(buf) - 1 - i + buf[i], buf[opp] = buf[opp], buf[i] + } +} diff --git a/interp/testdata/alloc.ll b/interp/testdata/alloc.ll index dd8819ef9..28b0c84e4 100644 --- a/interp/testdata/alloc.ll +++ b/interp/testdata/alloc.ll @@ -1,7 +1,7 @@ target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" target triple = "wasm32--wasi" -@"runtime/gc.layout:62-2000000000000001" = linkonce_odr unnamed_addr constant { i32, [8 x i8] } { i32 62, [8 x i8] c" \00\00\00\00\00\00\01" } +@"runtime/gc.layout:62-2000000000000001" = linkonce_odr unnamed_addr constant { i32, [8 x i8] } { i32 62, [8 x i8] c"\01\00\00\00\00\00\00 " } @pointerFree12 = global i8* null @pointerFree7 = global i8* null @pointerFree3 = global i8* null |