File indexing completed on 2026-05-10 08:44:34
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef LLVM_SUPPORT_SWAPBYTEORDER_H
0015 #define LLVM_SUPPORT_SWAPBYTEORDER_H
0016
0017 #include "llvm/ADT/STLForwardCompat.h"
0018 #include "llvm/ADT/bit.h"
0019 #include <cstdint>
0020 #include <type_traits>
0021
0022 namespace llvm {
0023
0024 namespace sys {
0025
0026 constexpr bool IsBigEndianHost =
0027 llvm::endianness::native == llvm::endianness::big;
0028
0029 static const bool IsLittleEndianHost = !IsBigEndianHost;
0030
0031 inline unsigned char getSwappedBytes(unsigned char C) { return llvm::byteswap(C); }
0032 inline signed char getSwappedBytes( signed char C) { return llvm::byteswap(C); }
0033 inline char getSwappedBytes( char C) { return llvm::byteswap(C); }
0034
0035 inline unsigned short getSwappedBytes(unsigned short C) { return llvm::byteswap(C); }
0036 inline signed short getSwappedBytes( signed short C) { return llvm::byteswap(C); }
0037
0038 inline unsigned int getSwappedBytes(unsigned int C) { return llvm::byteswap(C); }
0039 inline signed int getSwappedBytes( signed int C) { return llvm::byteswap(C); }
0040
0041 inline unsigned long getSwappedBytes(unsigned long C) { return llvm::byteswap(C); }
0042 inline signed long getSwappedBytes( signed long C) { return llvm::byteswap(C); }
0043
0044 inline unsigned long long getSwappedBytes(unsigned long long C) { return llvm::byteswap(C); }
0045 inline signed long long getSwappedBytes( signed long long C) { return llvm::byteswap(C); }
0046
0047 inline float getSwappedBytes(float C) {
0048 return llvm::bit_cast<float>(llvm::byteswap(llvm::bit_cast<uint32_t>(C)));
0049 }
0050
0051 inline double getSwappedBytes(double C) {
0052 return llvm::bit_cast<double>(llvm::byteswap(llvm::bit_cast<uint64_t>(C)));
0053 }
0054
0055 template <typename T>
0056 inline std::enable_if_t<std::is_enum_v<T>, T> getSwappedBytes(T C) {
0057 return static_cast<T>(llvm::byteswap(llvm::to_underlying(C)));
0058 }
0059
0060 template<typename T>
0061 inline void swapByteOrder(T &Value) {
0062 Value = getSwappedBytes(Value);
0063 }
0064
0065 }
0066 }
0067
0068 #endif