summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2013-04-15 14:44:24 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2013-04-15 14:44:24 +0000
commit21a01d1ea89dba97c4f9e1f9f41485729a4046bc (patch)
tree74856a1ba8c29ceff5341282b373a58bdb2cc4d5 /include
parent604b3573f955d61ba87215c25ba2f52477c71ecc (diff)
downloadllvm-21a01d1ea89dba97c4f9e1f9f41485729a4046bc.tar.gz
llvm-21a01d1ea89dba97c4f9e1f9f41485729a4046bc.tar.bz2
llvm-21a01d1ea89dba97c4f9e1f9f41485729a4046bc.tar.xz
Make the host endianness check an integer constant expression.
I will remove the isBigEndianHost function once I update clang. The ifdef logic is designed to * not use configure/cmake to avoid breaking -arch i686 -arch ppc. * default to little endian * be as small as possible It looks like sys/endian.h is the preferred header on most modern BSD systems, but it is better to change this in a followup patch as machine/endian.h is available on FreeBSD, OpenBSD, NetBSD and OS X. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179527 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/llvm/ADT/Hashing.h4
-rw-r--r--include/llvm/Support/Endian.h2
-rw-r--r--include/llvm/Support/Host.h26
3 files changed, 20 insertions, 12 deletions
diff --git a/include/llvm/ADT/Hashing.h b/include/llvm/ADT/Hashing.h
index cda31a261d..e434417da7 100644
--- a/include/llvm/ADT/Hashing.h
+++ b/include/llvm/ADT/Hashing.h
@@ -151,7 +151,7 @@ namespace detail {
inline uint64_t fetch64(const char *p) {
uint64_t result;
memcpy(&result, p, sizeof(result));
- if (sys::isBigEndianHost())
+ if (sys::IsBigEndianHost)
return sys::SwapByteOrder(result);
return result;
}
@@ -159,7 +159,7 @@ inline uint64_t fetch64(const char *p) {
inline uint32_t fetch32(const char *p) {
uint32_t result;
memcpy(&result, p, sizeof(result));
- if (sys::isBigEndianHost())
+ if (sys::IsBigEndianHost)
return sys::SwapByteOrder(result);
return result;
}
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