[Support] Deprecate one form of support::endian::write (NFC) (#156140)
We have two forms of write: template <typename value_type, std::size_t alignment = unaligned> inline void write(void *memory, value_type value, endianness endian) template <typename value_type, endianness endian, std::size_t alignment> inline void write(void *memory, value_type value) The difference is that endian is a function parameter in the former but a template parameter in the latter. This patch streamlines the code by migrating the use of the latter to the former while deprecating the latter. I'm planning to do the same for byte_swap and read in follow-up patches to keep this patch simple and small.
This commit is contained in:
parent
3a2c8f7af8
commit
152d0f5c0c
@ -96,9 +96,8 @@ inline void write(void *memory, value_type value, endianness endian) {
|
||||
&value, sizeof(value_type));
|
||||
}
|
||||
|
||||
template<typename value_type,
|
||||
endianness endian,
|
||||
std::size_t alignment>
|
||||
template <typename value_type, endianness endian, std::size_t alignment>
|
||||
LLVM_DEPRECATED("Pass endian as a function argument instead", "write")
|
||||
inline void write(void *memory, value_type value) {
|
||||
write<value_type, alignment>(memory, value, endian);
|
||||
}
|
||||
@ -163,7 +162,7 @@ inline void writeAtBitAlignment(void *memory, value_type value,
|
||||
uint64_t startBit) {
|
||||
assert(startBit < 8);
|
||||
if (startBit == 0)
|
||||
write<value_type, endian, alignment>(memory, value);
|
||||
write<value_type, alignment>(memory, value, endian);
|
||||
else {
|
||||
// Read two values and shift the result into them.
|
||||
value_type val[2];
|
||||
@ -230,8 +229,8 @@ struct packed_endian_specific_integral {
|
||||
operator value_type() const { return value(); }
|
||||
|
||||
void operator=(value_type newValue) {
|
||||
endian::write<value_type, endian, alignment>(
|
||||
(void*)Value.buffer, newValue);
|
||||
endian::write<value_type, alignment>((void *)Value.buffer, newValue,
|
||||
endian);
|
||||
}
|
||||
|
||||
packed_endian_specific_integral &operator+=(value_type newValue) {
|
||||
@ -268,7 +267,7 @@ public:
|
||||
}
|
||||
|
||||
void operator=(value_type NewValue) {
|
||||
endian::write<value_type, endian, alignment>(Ptr, NewValue);
|
||||
endian::write<value_type, alignment>(Ptr, NewValue, endian);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@ -38,8 +38,8 @@ template <typename ValueType> struct BinaryBeImpl {
|
||||
template <typename ValueType>
|
||||
raw_ostream &operator<<(raw_ostream &OS, const BinaryBeImpl<ValueType> &BBE) {
|
||||
char Buffer[sizeof(BBE.Value)];
|
||||
support::endian::write<ValueType, llvm::endianness::big, support::unaligned>(
|
||||
Buffer, BBE.Value);
|
||||
support::endian::write<ValueType, support::unaligned>(Buffer, BBE.Value,
|
||||
llvm::endianness::big);
|
||||
OS.write(Buffer, sizeof(BBE.Value));
|
||||
return OS;
|
||||
}
|
||||
|
||||
@ -201,26 +201,26 @@ TEST(Endian, WriteBitAligned) {
|
||||
|
||||
TEST(Endian, Write) {
|
||||
unsigned char data[5];
|
||||
endian::write<int32_t, llvm::endianness::big, unaligned>(data, -1362446643);
|
||||
endian::write<int32_t, unaligned>(data, -1362446643, llvm::endianness::big);
|
||||
EXPECT_EQ(data[0], 0xAE);
|
||||
EXPECT_EQ(data[1], 0xCA);
|
||||
EXPECT_EQ(data[2], 0xB6);
|
||||
EXPECT_EQ(data[3], 0xCD);
|
||||
endian::write<int32_t, llvm::endianness::big, unaligned>(data + 1,
|
||||
-1362446643);
|
||||
endian::write<int32_t, unaligned>(data + 1, -1362446643,
|
||||
llvm::endianness::big);
|
||||
EXPECT_EQ(data[1], 0xAE);
|
||||
EXPECT_EQ(data[2], 0xCA);
|
||||
EXPECT_EQ(data[3], 0xB6);
|
||||
EXPECT_EQ(data[4], 0xCD);
|
||||
|
||||
endian::write<int32_t, llvm::endianness::little, unaligned>(data,
|
||||
-1362446643);
|
||||
endian::write<int32_t, unaligned>(data, -1362446643,
|
||||
llvm::endianness::little);
|
||||
EXPECT_EQ(data[0], 0xCD);
|
||||
EXPECT_EQ(data[1], 0xB6);
|
||||
EXPECT_EQ(data[2], 0xCA);
|
||||
EXPECT_EQ(data[3], 0xAE);
|
||||
endian::write<int32_t, llvm::endianness::little, unaligned>(data + 1,
|
||||
-1362446643);
|
||||
endian::write<int32_t, unaligned>(data + 1, -1362446643,
|
||||
llvm::endianness::little);
|
||||
EXPECT_EQ(data[1], 0xCD);
|
||||
EXPECT_EQ(data[2], 0xB6);
|
||||
EXPECT_EQ(data[3], 0xCA);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user