llvm.org GIT mirror llvm / fd7c230
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 Michael J. Spencer 9 years ago
3 changed file(s) with 38 addition(s) and 58 deletion(s). Raw diff Collapse all Expand all
257257 endif()
258258 endif()
259259
260 test_big_endian(LLVM_IS_HOST_BIG_ENDIAN)
261
262260 if( ENABLE_THREADS )
263261 message(STATUS "Threads enabled.")
264262 else( ENABLE_THREADS )
504504
505505 /* Define if this is Win32ish platform */
506506 #cmakedefine LLVM_ON_WIN32 ${LLVM_ON_WIN32}
507
508 /* Define if this is targeting a big endian system */
509 #cmakedefine LLVM_IS_HOST_BIG_ENDIAN ${LLVM_IS_HOST_BIG_ENDIAN}
510507
511508 /* Added by Kevin -- Maximum path length */
512509 #cmakedefine MAXPATHLEN ${MAXPATHLEN}
1414 #define LLVM_SUPPORT_ENDIAN_H
1515
1616 #include "llvm/Config/config.h"
17 #include "llvm/System/Host.h"
1718 #include "llvm/System/SwapByteOrder.h"
1819 #include "llvm/Support/type_traits.h"
1920
2223
2324 enum endianness {big, little};
2425 enum alignment {unaligned, aligned};
25
26 template
27 static typename enable_if_c::type
28 SwapByteOrderIfDifferent(value_type value) {
29 // Target endianess is the same as the host. Just pass the value through.
30 return value;
31 }
32
33 template
34 static typename enable_if_c::type
35 SwapByteOrderIfDifferent(value_type value) {
36 return sys::SwapByteOrder(value);
37 }
3826
3927 namespace detail {
4028
5947
6048 } // end namespace detail
6149
62 #if defined(LLVM_IS_HOST_BIG_ENDIAN) \
63 || defined(_BIG_ENDIAN) || defined(__BIG_ENDIAN__)
64 static const endianness host_endianness = big;
65 #else
66 static const endianness host_endianness = little;
67 #endif
68
69 struct endian {
70 template
71 static value_type read_le(const void *memory) {
72 return SwapByteOrderIfDifferent(
73 reinterpret_cast
74 *>(memory)->val);
75 }
76
77 template
78 static void write_le(void *memory, value_type value) {
79 reinterpret_cast *>
80 (memory)->val =
81 SwapByteOrderIfDifferent< value_type
82 , host_endianness
83 , little>(value);
84 }
85
86 template
87 static value_type read_be(const void *memory) {
88 return SwapByteOrderIfDifferent(
89 reinterpret_cast
90 *>(memory)->val);
91 }
92
93 template
94 static void write_be(void *memory, value_type value) {
95 reinterpret_cast
96 *>(memory)->val =
97 SwapByteOrderIfDifferent< value_type
98 , host_endianness
99 , big>(value);
50 namespace endian {
51 template
52 static value_type read_le(const void *memory) {
53 value_type t =
54 reinterpret_cast
55 *>(memory)->val;
56 if (sys::isBigEndianHost())
57 return sys::SwapByteOrder(t);
58 return t;
59 }
60
61 template
62 static void write_le(void *memory, value_type value) {
63 if (sys::isBigEndianHost())
64 value = sys::SwapByteOrder(value);
65 reinterpret_cast *>
66 (memory)->val = value;
67 }
68
69 template
70 static value_type read_be(const void *memory) {
71 value_type t =
72 reinterpret_cast
73 *>(memory)->val;
74 if (sys::isLittleEndianHost())
75 return sys::SwapByteOrder(t);
76 return t;
77 }
78
79 template
80 static void write_be(void *memory, value_type value) {
81 if (sys::isLittleEndianHost())
82 value = sys::SwapByteOrder(value);
83 reinterpret_cast *>
84 (memory)->val = value;
10085 }
10186 };
10287
10388 namespace detail {
10489
10590 template
106 endianness target_endianness,
107 alignment target_alignment>
91 endianness endian,
92 alignment align>
10893 class packed_endian_specific_integral;
10994
11095 template