mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-10 14:03:39 +00:00
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.
This commit is contained in:
@@ -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]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user