mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-26 21:32:10 +00:00
Renaming SwapByteOrder() to getSwappedBytes()
The next commit will add swapByteOrder(), acting in-place git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210973 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
7a3a020478
commit
9bb92cb537
@ -152,7 +152,7 @@ inline uint64_t fetch64(const char *p) {
|
|||||||
uint64_t result;
|
uint64_t result;
|
||||||
memcpy(&result, p, sizeof(result));
|
memcpy(&result, p, sizeof(result));
|
||||||
if (sys::IsBigEndianHost)
|
if (sys::IsBigEndianHost)
|
||||||
return sys::SwapByteOrder(result);
|
return sys::getSwappedBytes(result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,7 +160,7 @@ inline uint32_t fetch32(const char *p) {
|
|||||||
uint32_t result;
|
uint32_t result;
|
||||||
memcpy(&result, p, sizeof(result));
|
memcpy(&result, p, sizeof(result));
|
||||||
if (sys::IsBigEndianHost)
|
if (sys::IsBigEndianHost)
|
||||||
return sys::SwapByteOrder(result);
|
return sys::getSwappedBytes(result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,7 +184,7 @@ private:
|
|||||||
std::error_code readHeader(const RawHeader &Header);
|
std::error_code readHeader(const RawHeader &Header);
|
||||||
template <class IntT>
|
template <class IntT>
|
||||||
IntT swap(IntT Int) const {
|
IntT swap(IntT Int) const {
|
||||||
return ShouldSwapBytes ? sys::SwapByteOrder(Int) : Int;
|
return ShouldSwapBytes ? sys::getSwappedBytes(Int) : Int;
|
||||||
}
|
}
|
||||||
const uint64_t *getCounter(IntPtrT CounterPtr) const {
|
const uint64_t *getCounter(IntPtrT CounterPtr) const {
|
||||||
ptrdiff_t Offset = (swap(CounterPtr) - CountersDelta) / sizeof(uint64_t);
|
ptrdiff_t Offset = (swap(CounterPtr) - CountersDelta) / sizeof(uint64_t);
|
||||||
|
@ -38,7 +38,7 @@ namespace endian {
|
|||||||
template<typename value_type, endianness endian>
|
template<typename value_type, endianness endian>
|
||||||
inline value_type byte_swap(value_type value) {
|
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 sys::getSwappedBytes(value);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,30 +68,30 @@ inline uint64_t SwapByteOrder_64(uint64_t value) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
inline unsigned char SwapByteOrder(unsigned char C) { return C; }
|
inline unsigned char getSwappedBytes(unsigned char C) { return C; }
|
||||||
inline signed char SwapByteOrder(signed char C) { return C; }
|
inline signed char getSwappedBytes(signed char C) { return C; }
|
||||||
inline char SwapByteOrder(char C) { return C; }
|
inline char getSwappedBytes(char C) { return C; }
|
||||||
|
|
||||||
inline unsigned short SwapByteOrder(unsigned short C) { return SwapByteOrder_16(C); }
|
inline unsigned short getSwappedBytes(unsigned short C) { return SwapByteOrder_16(C); }
|
||||||
inline signed short SwapByteOrder( signed short C) { return SwapByteOrder_16(C); }
|
inline signed short getSwappedBytes( signed short C) { return SwapByteOrder_16(C); }
|
||||||
|
|
||||||
inline unsigned int SwapByteOrder(unsigned int C) { return SwapByteOrder_32(C); }
|
inline unsigned int getSwappedBytes(unsigned int C) { return SwapByteOrder_32(C); }
|
||||||
inline signed int SwapByteOrder( signed int C) { return SwapByteOrder_32(C); }
|
inline signed int getSwappedBytes( signed int C) { return SwapByteOrder_32(C); }
|
||||||
|
|
||||||
#if __LONG_MAX__ == __INT_MAX__
|
#if __LONG_MAX__ == __INT_MAX__
|
||||||
inline unsigned long SwapByteOrder(unsigned long C) { return SwapByteOrder_32(C); }
|
inline unsigned long getSwappedBytes(unsigned long C) { return SwapByteOrder_32(C); }
|
||||||
inline signed long SwapByteOrder( signed long C) { return SwapByteOrder_32(C); }
|
inline signed long getSwappedBytes( signed long C) { return SwapByteOrder_32(C); }
|
||||||
#elif __LONG_MAX__ == __LONG_LONG_MAX__
|
#elif __LONG_MAX__ == __LONG_LONG_MAX__
|
||||||
inline unsigned long SwapByteOrder(unsigned long C) { return SwapByteOrder_64(C); }
|
inline unsigned long getSwappedBytes(unsigned long C) { return SwapByteOrder_64(C); }
|
||||||
inline signed long SwapByteOrder( signed long C) { return SwapByteOrder_64(C); }
|
inline signed long getSwappedBytes( signed long C) { return SwapByteOrder_64(C); }
|
||||||
#else
|
#else
|
||||||
#error "Unknown long size!"
|
#error "Unknown long size!"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
inline unsigned long long SwapByteOrder(unsigned long long C) {
|
inline unsigned long long getSwappedBytes(unsigned long long C) {
|
||||||
return SwapByteOrder_64(C);
|
return SwapByteOrder_64(C);
|
||||||
}
|
}
|
||||||
inline signed long long SwapByteOrder(signed long long C) {
|
inline signed long long getSwappedBytes(signed long long C) {
|
||||||
return SwapByteOrder_64(C);
|
return SwapByteOrder_64(C);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -245,14 +245,14 @@ protected:
|
|||||||
|
|
||||||
void writeInt16BE(uint8_t *Addr, uint16_t Value) {
|
void writeInt16BE(uint8_t *Addr, uint16_t Value) {
|
||||||
if (IsTargetLittleEndian)
|
if (IsTargetLittleEndian)
|
||||||
Value = sys::SwapByteOrder(Value);
|
Value = sys::getSwappedBytes(Value);
|
||||||
*Addr = (Value >> 8) & 0xFF;
|
*Addr = (Value >> 8) & 0xFF;
|
||||||
*(Addr + 1) = Value & 0xFF;
|
*(Addr + 1) = Value & 0xFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeInt32BE(uint8_t *Addr, uint32_t Value) {
|
void writeInt32BE(uint8_t *Addr, uint32_t Value) {
|
||||||
if (IsTargetLittleEndian)
|
if (IsTargetLittleEndian)
|
||||||
Value = sys::SwapByteOrder(Value);
|
Value = sys::getSwappedBytes(Value);
|
||||||
*Addr = (Value >> 24) & 0xFF;
|
*Addr = (Value >> 24) & 0xFF;
|
||||||
*(Addr + 1) = (Value >> 16) & 0xFF;
|
*(Addr + 1) = (Value >> 16) & 0xFF;
|
||||||
*(Addr + 2) = (Value >> 8) & 0xFF;
|
*(Addr + 2) = (Value >> 8) & 0xFF;
|
||||||
@ -261,7 +261,7 @@ protected:
|
|||||||
|
|
||||||
void writeInt64BE(uint8_t *Addr, uint64_t Value) {
|
void writeInt64BE(uint8_t *Addr, uint64_t Value) {
|
||||||
if (IsTargetLittleEndian)
|
if (IsTargetLittleEndian)
|
||||||
Value = sys::SwapByteOrder(Value);
|
Value = sys::getSwappedBytes(Value);
|
||||||
*Addr = (Value >> 56) & 0xFF;
|
*Addr = (Value >> 56) & 0xFF;
|
||||||
*(Addr + 1) = (Value >> 48) & 0xFF;
|
*(Addr + 1) = (Value >> 48) & 0xFF;
|
||||||
*(Addr + 2) = (Value >> 40) & 0xFF;
|
*(Addr + 2) = (Value >> 40) & 0xFF;
|
||||||
|
@ -1179,7 +1179,7 @@ prependCompressionHeader(uint64_t Size,
|
|||||||
if (Size <= Magic.size() + sizeof(Size) + CompressedContents.size())
|
if (Size <= Magic.size() + sizeof(Size) + CompressedContents.size())
|
||||||
return false;
|
return false;
|
||||||
if (sys::IsLittleEndianHost)
|
if (sys::IsLittleEndianHost)
|
||||||
Size = sys::SwapByteOrder(Size);
|
Size = sys::getSwappedBytes(Size);
|
||||||
CompressedContents.insert(CompressedContents.begin(),
|
CompressedContents.insert(CompressedContents.begin(),
|
||||||
Magic.size() + sizeof(Size), 0);
|
Magic.size() + sizeof(Size), 0);
|
||||||
std::copy(Magic.begin(), Magic.end(), CompressedContents.begin());
|
std::copy(Magic.begin(), Magic.end(), CompressedContents.begin());
|
||||||
|
@ -45,7 +45,7 @@ struct section_base {
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static void SwapValue(T &Value) {
|
static void SwapValue(T &Value) {
|
||||||
Value = sys::SwapByteOrder(Value);
|
Value = sys::getSwappedBytes(Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
@ -24,7 +24,7 @@ using namespace object;
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static void SwapValue(T &Value) {
|
static void SwapValue(T &Value) {
|
||||||
Value = sys::SwapByteOrder(Value);
|
Value = sys::getSwappedBytes(Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
@ -158,7 +158,7 @@ bool RawInstrProfReader<IntPtrT>::hasFormat(const MemoryBuffer &DataBuffer) {
|
|||||||
uint64_t Magic =
|
uint64_t Magic =
|
||||||
*reinterpret_cast<const uint64_t *>(DataBuffer.getBufferStart());
|
*reinterpret_cast<const uint64_t *>(DataBuffer.getBufferStart());
|
||||||
return getRawMagic<IntPtrT>() == Magic ||
|
return getRawMagic<IntPtrT>() == Magic ||
|
||||||
sys::SwapByteOrder(getRawMagic<IntPtrT>()) == Magic;
|
sys::getSwappedBytes(getRawMagic<IntPtrT>()) == Magic;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class IntPtrT>
|
template <class IntPtrT>
|
||||||
|
@ -21,7 +21,7 @@ static T getU(uint32_t *offset_ptr, const DataExtractor *de,
|
|||||||
if (de->isValidOffsetForDataOfSize(offset, sizeof(val))) {
|
if (de->isValidOffsetForDataOfSize(offset, sizeof(val))) {
|
||||||
std::memcpy(&val, &Data[offset], sizeof(val));
|
std::memcpy(&val, &Data[offset], sizeof(val));
|
||||||
if (sys::IsLittleEndianHost != isLittleEndian)
|
if (sys::IsLittleEndianHost != isLittleEndian)
|
||||||
val = sys::SwapByteOrder(val);
|
val = sys::getSwappedBytes(val);
|
||||||
|
|
||||||
// Advance the offset
|
// Advance the offset
|
||||||
*offset_ptr += sizeof(val);
|
*offset_ptr += sizeof(val);
|
||||||
|
@ -20,70 +20,70 @@ namespace {
|
|||||||
// In these first two tests all of the original_uintx values are truncated
|
// In these first two tests all of the original_uintx values are truncated
|
||||||
// except for 64. We could avoid this, but there's really no point.
|
// except for 64. We could avoid this, but there's really no point.
|
||||||
|
|
||||||
TEST(SwapByteOrder, UnsignedRoundTrip) {
|
TEST(getSwappedBytes, UnsignedRoundTrip) {
|
||||||
// The point of the bit twiddling of magic is to test with and without bits
|
// The point of the bit twiddling of magic is to test with and without bits
|
||||||
// in every byte.
|
// in every byte.
|
||||||
uint64_t value = 1;
|
uint64_t value = 1;
|
||||||
for (std::size_t i = 0; i <= sizeof(value); ++i) {
|
for (std::size_t i = 0; i <= sizeof(value); ++i) {
|
||||||
uint8_t original_uint8 = static_cast<uint8_t>(value);
|
uint8_t original_uint8 = static_cast<uint8_t>(value);
|
||||||
EXPECT_EQ(original_uint8,
|
EXPECT_EQ(original_uint8,
|
||||||
sys::SwapByteOrder(sys::SwapByteOrder(original_uint8)));
|
sys::getSwappedBytes(sys::getSwappedBytes(original_uint8)));
|
||||||
|
|
||||||
uint16_t original_uint16 = static_cast<uint16_t>(value);
|
uint16_t original_uint16 = static_cast<uint16_t>(value);
|
||||||
EXPECT_EQ(original_uint16,
|
EXPECT_EQ(original_uint16,
|
||||||
sys::SwapByteOrder(sys::SwapByteOrder(original_uint16)));
|
sys::getSwappedBytes(sys::getSwappedBytes(original_uint16)));
|
||||||
|
|
||||||
uint32_t original_uint32 = static_cast<uint32_t>(value);
|
uint32_t original_uint32 = static_cast<uint32_t>(value);
|
||||||
EXPECT_EQ(original_uint32,
|
EXPECT_EQ(original_uint32,
|
||||||
sys::SwapByteOrder(sys::SwapByteOrder(original_uint32)));
|
sys::getSwappedBytes(sys::getSwappedBytes(original_uint32)));
|
||||||
|
|
||||||
uint64_t original_uint64 = static_cast<uint64_t>(value);
|
uint64_t original_uint64 = static_cast<uint64_t>(value);
|
||||||
EXPECT_EQ(original_uint64,
|
EXPECT_EQ(original_uint64,
|
||||||
sys::SwapByteOrder(sys::SwapByteOrder(original_uint64)));
|
sys::getSwappedBytes(sys::getSwappedBytes(original_uint64)));
|
||||||
|
|
||||||
value = (value << 8) | 0x55; // binary 0101 0101.
|
value = (value << 8) | 0x55; // binary 0101 0101.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(SwapByteOrder, SignedRoundTrip) {
|
TEST(getSwappedBytes, SignedRoundTrip) {
|
||||||
// The point of the bit twiddling of magic is to test with and without bits
|
// The point of the bit twiddling of magic is to test with and without bits
|
||||||
// in every byte.
|
// in every byte.
|
||||||
uint64_t value = 1;
|
uint64_t value = 1;
|
||||||
for (std::size_t i = 0; i <= sizeof(value); ++i) {
|
for (std::size_t i = 0; i <= sizeof(value); ++i) {
|
||||||
int8_t original_int8 = static_cast<int8_t>(value);
|
int8_t original_int8 = static_cast<int8_t>(value);
|
||||||
EXPECT_EQ(original_int8,
|
EXPECT_EQ(original_int8,
|
||||||
sys::SwapByteOrder(sys::SwapByteOrder(original_int8)));
|
sys::getSwappedBytes(sys::getSwappedBytes(original_int8)));
|
||||||
|
|
||||||
int16_t original_int16 = static_cast<int16_t>(value);
|
int16_t original_int16 = static_cast<int16_t>(value);
|
||||||
EXPECT_EQ(original_int16,
|
EXPECT_EQ(original_int16,
|
||||||
sys::SwapByteOrder(sys::SwapByteOrder(original_int16)));
|
sys::getSwappedBytes(sys::getSwappedBytes(original_int16)));
|
||||||
|
|
||||||
int32_t original_int32 = static_cast<int32_t>(value);
|
int32_t original_int32 = static_cast<int32_t>(value);
|
||||||
EXPECT_EQ(original_int32,
|
EXPECT_EQ(original_int32,
|
||||||
sys::SwapByteOrder(sys::SwapByteOrder(original_int32)));
|
sys::getSwappedBytes(sys::getSwappedBytes(original_int32)));
|
||||||
|
|
||||||
int64_t original_int64 = static_cast<int64_t>(value);
|
int64_t original_int64 = static_cast<int64_t>(value);
|
||||||
EXPECT_EQ(original_int64,
|
EXPECT_EQ(original_int64,
|
||||||
sys::SwapByteOrder(sys::SwapByteOrder(original_int64)));
|
sys::getSwappedBytes(sys::getSwappedBytes(original_int64)));
|
||||||
|
|
||||||
// Test other sign.
|
// Test other sign.
|
||||||
value *= -1;
|
value *= -1;
|
||||||
|
|
||||||
original_int8 = static_cast<int8_t>(value);
|
original_int8 = static_cast<int8_t>(value);
|
||||||
EXPECT_EQ(original_int8,
|
EXPECT_EQ(original_int8,
|
||||||
sys::SwapByteOrder(sys::SwapByteOrder(original_int8)));
|
sys::getSwappedBytes(sys::getSwappedBytes(original_int8)));
|
||||||
|
|
||||||
original_int16 = static_cast<int16_t>(value);
|
original_int16 = static_cast<int16_t>(value);
|
||||||
EXPECT_EQ(original_int16,
|
EXPECT_EQ(original_int16,
|
||||||
sys::SwapByteOrder(sys::SwapByteOrder(original_int16)));
|
sys::getSwappedBytes(sys::getSwappedBytes(original_int16)));
|
||||||
|
|
||||||
original_int32 = static_cast<int32_t>(value);
|
original_int32 = static_cast<int32_t>(value);
|
||||||
EXPECT_EQ(original_int32,
|
EXPECT_EQ(original_int32,
|
||||||
sys::SwapByteOrder(sys::SwapByteOrder(original_int32)));
|
sys::getSwappedBytes(sys::getSwappedBytes(original_int32)));
|
||||||
|
|
||||||
original_int64 = static_cast<int64_t>(value);
|
original_int64 = static_cast<int64_t>(value);
|
||||||
EXPECT_EQ(original_int64,
|
EXPECT_EQ(original_int64,
|
||||||
sys::SwapByteOrder(sys::SwapByteOrder(original_int64)));
|
sys::getSwappedBytes(sys::getSwappedBytes(original_int64)));
|
||||||
|
|
||||||
// Return to normal sign and twiddle.
|
// Return to normal sign and twiddle.
|
||||||
value *= -1;
|
value *= -1;
|
||||||
@ -91,38 +91,38 @@ TEST(SwapByteOrder, SignedRoundTrip) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(SwapByteOrder, uint8_t) {
|
TEST(getSwappedBytes, uint8_t) {
|
||||||
EXPECT_EQ(uint8_t(0x11), sys::SwapByteOrder(uint8_t(0x11)));
|
EXPECT_EQ(uint8_t(0x11), sys::getSwappedBytes(uint8_t(0x11)));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(SwapByteOrder, uint16_t) {
|
TEST(getSwappedBytes, uint16_t) {
|
||||||
EXPECT_EQ(uint16_t(0x1122), sys::SwapByteOrder(uint16_t(0x2211)));
|
EXPECT_EQ(uint16_t(0x1122), sys::getSwappedBytes(uint16_t(0x2211)));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(SwapByteOrder, uint32_t) {
|
TEST(getSwappedBytes, uint32_t) {
|
||||||
EXPECT_EQ(uint32_t(0x11223344), sys::SwapByteOrder(uint32_t(0x44332211)));
|
EXPECT_EQ(uint32_t(0x11223344), sys::getSwappedBytes(uint32_t(0x44332211)));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(SwapByteOrder, uint64_t) {
|
TEST(getSwappedBytes, uint64_t) {
|
||||||
EXPECT_EQ(uint64_t(0x1122334455667788ULL),
|
EXPECT_EQ(uint64_t(0x1122334455667788ULL),
|
||||||
sys::SwapByteOrder(uint64_t(0x8877665544332211ULL)));
|
sys::getSwappedBytes(uint64_t(0x8877665544332211ULL)));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(SwapByteOrder, int8_t) {
|
TEST(getSwappedBytes, int8_t) {
|
||||||
EXPECT_EQ(int8_t(0x11), sys::SwapByteOrder(int8_t(0x11)));
|
EXPECT_EQ(int8_t(0x11), sys::getSwappedBytes(int8_t(0x11)));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(SwapByteOrder, int16_t) {
|
TEST(getSwappedBytes, int16_t) {
|
||||||
EXPECT_EQ(int16_t(0x1122), sys::SwapByteOrder(int16_t(0x2211)));
|
EXPECT_EQ(int16_t(0x1122), sys::getSwappedBytes(int16_t(0x2211)));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(SwapByteOrder, int32_t) {
|
TEST(getSwappedBytes, int32_t) {
|
||||||
EXPECT_EQ(int32_t(0x11223344), sys::SwapByteOrder(int32_t(0x44332211)));
|
EXPECT_EQ(int32_t(0x11223344), sys::getSwappedBytes(int32_t(0x44332211)));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(SwapByteOrder, int64_t) {
|
TEST(getSwappedBytes, int64_t) {
|
||||||
EXPECT_EQ(int64_t(0x1122334455667788LL),
|
EXPECT_EQ(int64_t(0x1122334455667788LL),
|
||||||
sys::SwapByteOrder(int64_t(0x8877665544332211LL)));
|
sys::getSwappedBytes(int64_t(0x8877665544332211LL)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user