Use compiler macros to detect big endian
authorMike Hommey <mh@glandium.org>
Tue, 14 Feb 2023 23:44:19 +0000 (08:44 +0900)
committerEmilio Pozuelo Monfort <pochu@debian.org>
Thu, 31 Aug 2023 17:46:53 +0000 (18:46 +0100)
Both clang and GCC define endianness as builtin defines.

Gbp-Pq: Topic porting
Gbp-Pq: Name Use-compiler-macros-to-detect-big-endian.patch

third_party/wasm2c/src/common.h
third_party/wasm2c/src/prebuilt/wasm2c.include.c
third_party/wasm2c/src/wasm2c.c.tmpl

index de5e44af36031d19989dad287c366b58e0a4c8c1..c4eb760508982ed22377a6a638bddf1f7b31808f 100644 (file)
 #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) {
index d1ca3651aeec800214a8868c3eb5cf4107b35637..e293c5379072791814a9526f007891e84f11c2e1 100644 (file)
@@ -107,6 +107,14 @@ const char SECTION_NAME(declarations)[] =
 "#  define MEM_ACCESS_REF(mem, addr) (char*) addr\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"
index 0c6dbff37ba3df617f53aa557a08e54bc0c2c2f4..6a4e5d6aebd98fedd5eebc7dd7d3013c0b2141e9 100644 (file)
@@ -104,6 +104,14 @@ void WASM2C_MALLOC_FAIL_CALLBACK(u32 ptr_size);
 #  define MEM_ACCESS_REF(mem, addr) (char*) addr
 #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;