aboutsummaryrefslogtreecommitdiffhomepage
path: root/compiler
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2024-08-22 16:42:03 +0200
committerRon Evans <[email protected]>2024-09-05 10:06:30 +0200
commit73f519b589bf45d8b9a121063bd264357f632c06 (patch)
treea55d9e8f21b22867566e28b59bed3e31340a8308 /compiler
parent25abfff63204f72140ab1b29120ab9b674d5cf41 (diff)
downloadtinygo-73f519b589bf45d8b9a121063bd264357f632c06.tar.gz
tinygo-73f519b589bf45d8b9a121063bd264357f632c06.zip
interp: support big-endian targets
The interp package was assuming that all targets were little-endian. But that's not true: we now have a big-endian target (GOARCH=mips). This fixes the interp package to use the appropriate byte order for a given target.
Diffstat (limited to 'compiler')
-rw-r--r--compiler/llvmutil/llvm.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/compiler/llvmutil/llvm.go b/compiler/llvmutil/llvm.go
index 607e91e8d..061bee6c9 100644
--- a/compiler/llvmutil/llvm.go
+++ b/compiler/llvmutil/llvm.go
@@ -8,6 +8,7 @@
package llvmutil
import (
+ "encoding/binary"
"strconv"
"strings"
@@ -216,3 +217,13 @@ func Version() int {
}
return major
}
+
+// Return the byte order for the given target triple. Most targets are little
+// endian, but for example MIPS can be big-endian.
+func ByteOrder(target string) binary.ByteOrder {
+ if strings.HasPrefix(target, "mips-") {
+ return binary.BigEndian
+ } else {
+ return binary.LittleEndian
+ }
+}