From fd7c230c85dbc9b1c5145319a0d5eaeb99f61176 Mon Sep 17 00:00:00 2001 From: "Michael J. Spencer" Date: Fri, 22 Oct 2010 18:45:12 +0000 Subject: [PATCH] Endian: Get rid of LLVM_IS_HOST_BIG_ENDIAN. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@117124 91177308-0d34-0410-b5e6-96231b3b80d8 --- cmake/config-ix.cmake | 2 - include/llvm/Config/config.h.cmake | 3 - include/llvm/Support/Endian.h | 91 +++++++++++++----------------- 3 files changed, 38 insertions(+), 58 deletions(-) diff --git a/cmake/config-ix.cmake b/cmake/config-ix.cmake index 1d64c13c3f5..83ef8e584f0 100755 --- a/cmake/config-ix.cmake +++ b/cmake/config-ix.cmake @@ -258,8 +258,6 @@ if( LLVM_ENABLE_THREADS ) endif() endif() -test_big_endian(LLVM_IS_HOST_BIG_ENDIAN) - if( ENABLE_THREADS ) message(STATUS "Threads enabled.") else( ENABLE_THREADS ) diff --git a/include/llvm/Config/config.h.cmake b/include/llvm/Config/config.h.cmake index 73ec246fa1b..26a39b224e4 100644 --- a/include/llvm/Config/config.h.cmake +++ b/include/llvm/Config/config.h.cmake @@ -506,9 +506,6 @@ /* Define if this is Win32ish platform */ #cmakedefine LLVM_ON_WIN32 ${LLVM_ON_WIN32} -/* Define if this is targeting a big endian system */ -#cmakedefine LLVM_IS_HOST_BIG_ENDIAN ${LLVM_IS_HOST_BIG_ENDIAN} - /* Added by Kevin -- Maximum path length */ #cmakedefine MAXPATHLEN ${MAXPATHLEN} diff --git a/include/llvm/Support/Endian.h b/include/llvm/Support/Endian.h index c98e2dc66cc..1058beff7b9 100644 --- a/include/llvm/Support/Endian.h +++ b/include/llvm/Support/Endian.h @@ -15,6 +15,7 @@ #define LLVM_SUPPORT_ENDIAN_H #include "llvm/Config/config.h" +#include "llvm/System/Host.h" #include "llvm/System/SwapByteOrder.h" #include "llvm/Support/type_traits.h" @@ -24,19 +25,6 @@ namespace support { enum endianness {big, little}; enum alignment {unaligned, aligned}; -template -static typename enable_if_c::type -SwapByteOrderIfDifferent(value_type value) { - // Target endianess is the same as the host. Just pass the value through. - return value; -} - -template -static typename enable_if_c::type -SwapByteOrderIfDifferent(value_type value) { - return sys::SwapByteOrder(value); -} - namespace detail { template @@ -60,52 +48,49 @@ struct alignment_access_helper } // end namespace detail -#if defined(LLVM_IS_HOST_BIG_ENDIAN) \ - || defined(_BIG_ENDIAN) || defined(__BIG_ENDIAN__) -static const endianness host_endianness = big; -#else -static const endianness host_endianness = little; -#endif - -struct endian { - template - static value_type read_le(const void *memory) { - return SwapByteOrderIfDifferent( - reinterpret_cast *>(memory)->val); - } - - template - static void write_le(void *memory, value_type value) { - reinterpret_cast *> - (memory)->val = - SwapByteOrderIfDifferent< value_type - , host_endianness - , little>(value); - } - - template - static value_type read_be(const void *memory) { - return SwapByteOrderIfDifferent( - reinterpret_cast *>(memory)->val); - } - - template - static void write_be(void *memory, value_type value) { - reinterpret_cast *>(memory)->val = - SwapByteOrderIfDifferent< value_type - , host_endianness - , big>(value); +namespace endian { + template + static value_type read_le(const void *memory) { + value_type t = + reinterpret_cast *>(memory)->val; + if (sys::isBigEndianHost()) + return sys::SwapByteOrder(t); + return t; + } + + template + static void write_le(void *memory, value_type value) { + if (sys::isBigEndianHost()) + value = sys::SwapByteOrder(value); + reinterpret_cast *> + (memory)->val = value; + } + + template + static value_type read_be(const void *memory) { + value_type t = + reinterpret_cast *>(memory)->val; + if (sys::isLittleEndianHost()) + return sys::SwapByteOrder(t); + return t; + } + + template + static void write_be(void *memory, value_type value) { + if (sys::isLittleEndianHost()) + value = sys::SwapByteOrder(value); + reinterpret_cast *> + (memory)->val = value; } }; namespace detail { template + endianness endian, + alignment align> class packed_endian_specific_integral; template