1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
From: Mike Hommey <mh@glandium.org>
Date: Wed, 15 Feb 2023 08:44:19 +0900
Subject: Use compiler macros to detect big endian
Both clang and GCC define endianness as builtin defines.
---
third_party/wasm2c/src/common.h | 8 ++++++++
third_party/wasm2c/src/prebuilt/wasm2c.include.c | 8 ++++++++
third_party/wasm2c/src/wasm2c.c.tmpl | 8 ++++++++
3 files changed, 24 insertions(+)
diff --git a/third_party/wasm2c/src/common.h b/third_party/wasm2c/src/common.h
index de5e44a..c4eb760 100644
--- a/third_party/wasm2c/src/common.h
+++ b/third_party/wasm2c/src/common.h
@@ -103,6 +103,14 @@
#define PRIaddress PRIu64
#define PRIoffset PRIzx
+#ifndef WABT_BIG_ENDIAN
+# if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+# define WABT_BIG_ENDIAN 1
+# elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+# define WABT_BIG_ENDIAN 0
+# endif
+#endif
+
namespace wabt {
#if WABT_BIG_ENDIAN
inline void MemcpyEndianAware(void *dst, const void *src, size_t dsize, size_t ssize, size_t doff, size_t soff, size_t len) {
diff --git a/third_party/wasm2c/src/prebuilt/wasm2c.include.c b/third_party/wasm2c/src/prebuilt/wasm2c.include.c
index de62978..5040afa 100644
--- a/third_party/wasm2c/src/prebuilt/wasm2c.include.c
+++ b/third_party/wasm2c/src/prebuilt/wasm2c.include.c
@@ -113,6 +113,14 @@ const char SECTION_NAME(declarations)[] =
"#define wasm_asm(X)\n"
"#endif\n"
"\n"
+"#ifndef WABT_BIG_ENDIAN\n"
+"# if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__\n"
+"# define WABT_BIG_ENDIAN 1\n"
+"# elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__\n"
+"# define WABT_BIG_ENDIAN 0\n"
+"# endif\n"
+"#endif\n"
+"\n"
"#if WABT_BIG_ENDIAN\n"
"static inline void load_data(void *dest, const void *src, size_t n) {\n"
" size_t i = 0;\n"
diff --git a/third_party/wasm2c/src/wasm2c.c.tmpl b/third_party/wasm2c/src/wasm2c.c.tmpl
index 6539ddc..990bb2f 100644
--- a/third_party/wasm2c/src/wasm2c.c.tmpl
+++ b/third_party/wasm2c/src/wasm2c.c.tmpl
@@ -110,6 +110,14 @@ void WASM2C_MALLOC_FAIL_CALLBACK(u32 ptr_size);
#define wasm_asm(X)
#endif
+#ifndef WABT_BIG_ENDIAN
+# if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+# define WABT_BIG_ENDIAN 1
+# elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+# define WABT_BIG_ENDIAN 0
+# endif
+#endif
+
#if WABT_BIG_ENDIAN
static inline void load_data(void *dest, const void *src, size_t n) {
size_t i = 0;
|