14 #ifndef LLVM_SUPPORT_SWAPBYTEORDER_H 15 #define LLVM_SUPPORT_SWAPBYTEORDER_H 20 #include <type_traits> 21 #if defined(_MSC_VER) && !defined(_DEBUG) 25 #if defined(__linux__) || defined(__GNU__) || defined(__HAIKU__) 28 #include <sys/machine.h> 31 #include <sys/types.h> 32 #define BIG_ENDIAN 4321 33 #define LITTLE_ENDIAN 1234 34 #if defined(_BIG_ENDIAN) 35 #define BYTE_ORDER BIG_ENDIAN 37 #define BYTE_ORDER LITTLE_ENDIAN 40 #if !defined(BYTE_ORDER) && !defined(_WIN32) 41 #include <machine/endian.h> 48 #if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && BYTE_ORDER == BIG_ENDIAN 51 constexpr
bool IsBigEndianHost =
false;
59 #if defined(_MSC_VER) && !defined(_DEBUG) 62 return _byteswap_ushort(value);
72 #if defined(__llvm__) || (defined(__GNUC__) && !defined(__ICC)) 73 return __builtin_bswap32(value);
74 #elif defined(_MSC_VER) && !defined(_DEBUG) 75 return _byteswap_ulong(value);
81 return (Byte0 << 24) | (Byte1 << 8) | (Byte2 >> 8) | (Byte3 >> 24);
87 #if defined(__llvm__) || (defined(__GNUC__) && !defined(__ICC)) 88 return __builtin_bswap64(value);
89 #elif defined(_MSC_VER) && !defined(_DEBUG) 90 return _byteswap_uint64(value);
94 return (Hi << 32) |
Lo;
108 #if __LONG_MAX__ == __INT_MAX__ 111 #elif __LONG_MAX__ == __LONG_LONG_MAX__ 115 #error "Unknown long size!" 145 template <
typename T>
146 inline typename std::enable_if<std::is_enum<T>::value,
T>
::type 148 return static_cast<T>(
149 getSwappedBytes(
static_cast<typename std::underlying_type<T>::type
>(C)));
void swapByteOrder(T &Value)
This class represents lattice values for constants.
constexpr bool IsBigEndianHost
uint32_t SwapByteOrder_32(uint32_t value)
This function returns a byte-swapped representation of the 32-bit argument.
static const bool IsLittleEndianHost
uint16_t SwapByteOrder_16(uint16_t value)
SwapByteOrder_16 - This function returns a byte-swapped representation of the 16-bit argument...
uint64_t SwapByteOrder_64(uint64_t value)
This function returns a byte-swapped representation of the 64-bit argument.
unsigned char getSwappedBytes(unsigned char C)
LLVM Value Representation.