diff options
Diffstat (limited to 'include/llvm/Support')
-rw-r--r-- | include/llvm/Support/Endian.h | 2 | ||||
-rw-r--r-- | include/llvm/Support/Host.h | 26 |
2 files changed, 18 insertions, 10 deletions
diff --git a/include/llvm/Support/Endian.h b/include/llvm/Support/Endian.h index d438facfa4..0d35849883 100644 --- a/include/llvm/Support/Endian.h +++ b/include/llvm/Support/Endian.h @@ -37,7 +37,7 @@ namespace detail { namespace endian { template<typename value_type, endianness endian> inline value_type byte_swap(value_type value) { - if (endian != native && sys::isBigEndianHost() != (endian == big)) + if (endian != native && sys::IsBigEndianHost != (endian == big)) return sys::SwapByteOrder(value); return value; } diff --git a/include/llvm/Support/Host.h b/include/llvm/Support/Host.h index 3a44405739..2731529dfd 100644 --- a/include/llvm/Support/Host.h +++ b/include/llvm/Support/Host.h @@ -15,22 +15,30 @@ #define LLVM_SUPPORT_HOST_H #include "llvm/ADT/StringMap.h" + +#if defined(__linux__) +#include <endian.h> +#else +#ifndef _MSC_VER +#include <machine/endian.h> +#endif +#endif + #include <string> namespace llvm { namespace sys { - inline bool isLittleEndianHost() { - union { - int i; - char c; - }; - i = 1; - return c; - } +#if BYTE_ORDER == BIG_ENDIAN + static const bool IsBigEndianHost = true; +#else + static const bool IsBigEndianHost = false; +#endif + + static const bool IsLittleEndianHost = !IsBigEndianHost; inline bool isBigEndianHost() { - return !isLittleEndianHost(); + return IsBigEndianHost; } /// getDefaultTargetTriple() - Return the default target triple the compiler |