10 #ifndef LLVM_SUPPORT_BINARYSTREAMWRITER_H 11 #define LLVM_SUPPORT_BINARYSTREAMWRITER_H 22 #include <type_traits> 66 static_assert(std::is_integral<T>::value,
67 "Cannot call writeInteger with non-integral value!");
68 uint8_t Buffer[
sizeof(
T)];
69 llvm::support::endian::write<T, llvm::support::unaligned>(
76 static_assert(std::is_enum<T>::value,
77 "Cannot call writeEnum with non-Enum type");
79 using U =
typename std::underlying_type<T>::type;
80 return writeInteger<U>(
static_cast<U
>(Num));
123 static_assert(!std::is_pointer<T>::value,
124 "writeObject should not be used with pointers, to write " 125 "the pointed-to value dereference the pointer before calling " 141 if (Array.
size() > UINT32_MAX /
sizeof(
T))
142 return make_error<BinaryStreamError>(
147 Array.
size() *
sizeof(
T)));
154 template <
typename T,
typename U>
168 std::pair<BinaryStreamWriter, BinaryStreamWriter>
split(
uint32_t Off)
const;
183 #endif // LLVM_SUPPORT_BINARYSTREAMWRITER_H Error writeObject(const T &Obj)
Writes the object Obj to the underlying stream, as if by using memcpy.
BinaryStreamWriter()=default
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
Error writeBytes(ArrayRef< uint8_t > Buffer)
Write the bytes specified in Buffer to the underlying stream.
This class represents lattice values for constants.
uint32_t getLength() const
BinaryStreamWriter(const BinaryStreamWriter &Other)
BinaryStreamWriter & operator=(const BinaryStreamWriter &Other)
BinaryStreamRef getUnderlyingStream() const
FixedStreamArray is similar to VarStreamArray, except with each record having a fixed-length.
The access may reference the value stored in memory.
Error writeArray(VarStreamArray< T, U > Array)
Writes all data from the array Array to the underlying stream.
Error writeFixedString(StringRef Str)
Write the string Str to the underlying stream without a null terminator.
virtual uint32_t getLength()=0
Return the number of bytes of data in this stream.
Error writeArray(ArrayRef< T > Array)
Writes an array of objects of type T to the underlying stream, as if by using memcpy.
virtual llvm::support::endianness getEndian() const =0
uint32_t getOffset() const
size_t size() const
size - Get the array size.
Error writeArray(FixedStreamArray< T > Array)
Writes all elements from the array Array to the underlying stream.
Error writeStreamRef(BinaryStreamRef Ref)
Efficiently reads all data from Ref, and writes it to this stream.
WritableBinaryStreamRef Stream
Provides write only access to a subclass of WritableBinaryStream.
Error writeInteger(T Value)
Write the integer Value to the underlying stream in the specified endianness.
uint32_t bytesRemaining() const
Error writeCString(StringRef Str)
Write the string Str to the underlying stream followed by a null terminator.
static ErrorSuccess success()
Create a success value.
BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.
std::pair< BinaryStreamWriter, BinaryStreamWriter > split(uint32_t Off) const
Splits the Writer into two Writers at a given offset.
virtual ~BinaryStreamWriter()
Error writeEnum(T Num)
Similar to writeInteger.
void setOffset(uint32_t Off)
BinaryStreamRef getUnderlyingStream() const
Error padToAlignment(uint32_t Align)
LLVM Value Representation.
Lightweight error class with error context and mandatory checking.
StringRef - Represent a constant reference to a string, i.e.
bool empty() const
empty - Check if the array is empty.
A BinaryStream which can be read from as well as written to.