--- SPIRV-LLVM-Translator-18.1.6/lib/SPIRV/libSPIRV/SPIRVStream.h.old 2024-10-30 05:39:48.000000000 -0500 +++ SPIRV-LLVM-Translator-18.1.6/lib/SPIRV/libSPIRV/SPIRVStream.h 2024-11-22 20:17:06.139226884 -0600 @@ -43,6 +43,16 @@ #include "SPIRVDebug.h" #include "SPIRVExtInst.h" #include "SPIRVModule.h" +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +#include +#define cpu_to_le32(x) __bswap32(x) +#define le32_to_cpu(x) __bswap32(x) +#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +#define cpu_to_le32(x) x +#define le32_to_cpu(x) x +#else +#error Endianness unknown (neither big nor little) +#endif #include #include #include @@ -102,7 +112,7 @@ const SPIRVDecoder &decodeBinary(const SPIRVDecoder &I, T &V) { uint32_t W; I.IS.read(reinterpret_cast(&W), sizeof(W)); - V = static_cast(W); + V = static_cast(le32_to_cpu(W)); SPIRVDBG(spvdbgs() << "Read word: W = " << W << " V = " << V << '\n'); return I; } @@ -185,7 +195,7 @@ return O; } #endif - uint32_t W = static_cast(V); + uint32_t W = cpu_to_le32(static_cast(V)); O.OS.write(reinterpret_cast(&W), sizeof(W)); return O; }