LLVM 19.0.0git
Public Member Functions | List of all members
llvm::BinaryStreamReader Class Reference

Provides read only access to a subclass of BinaryStream. More...

#include "llvm/Support/BinaryStreamReader.h"

Public Member Functions

 BinaryStreamReader ()=default
 
 BinaryStreamReader (BinaryStreamRef Ref)
 
 BinaryStreamReader (BinaryStream &Stream)
 
 BinaryStreamReader (ArrayRef< uint8_t > Data, llvm::endianness Endian)
 
 BinaryStreamReader (StringRef Data, llvm::endianness Endian)
 
 BinaryStreamReader (const BinaryStreamReader &Other)=default
 
BinaryStreamReaderoperator= (const BinaryStreamReader &Other)=default
 
virtual ~BinaryStreamReader ()=default
 
Error readLongestContiguousChunk (ArrayRef< uint8_t > &Buffer)
 Read as much as possible from the underlying string at the current offset without invoking a copy, and set Buffer to the resulting data slice.
 
Error readBytes (ArrayRef< uint8_t > &Buffer, uint32_t Size)
 Read Size bytes from the underlying stream at the current offset and and set Buffer to the resulting data slice.
 
template<typename T >
Error readInteger (T &Dest)
 Read an integer of the specified endianness into Dest and update the stream's offset.
 
template<typename T >
Error readEnum (T &Dest)
 Similar to readInteger.
 
Error readULEB128 (uint64_t &Dest)
 Read an unsigned LEB128 encoded value.
 
Error readSLEB128 (int64_t &Dest)
 Read a signed LEB128 encoded value.
 
Error readCString (StringRef &Dest)
 Read a null terminated string from Dest.
 
Error readWideString (ArrayRef< UTF16 > &Dest)
 Similar to readCString, however read a null-terminated UTF16 string instead.
 
Error readFixedString (StringRef &Dest, uint32_t Length)
 Read a Length byte string into Dest.
 
Error readStreamRef (BinaryStreamRef &Ref)
 Read the entire remainder of the underlying stream into Ref.
 
Error readStreamRef (BinaryStreamRef &Ref, uint32_t Length)
 Read Length bytes from the underlying stream into Ref.
 
Error readSubstream (BinarySubstreamRef &Ref, uint32_t Length)
 Read Length bytes from the underlying stream into Ref.
 
template<typename T >
Error readObject (const T *&Dest)
 Get a pointer to an object of type T from the underlying stream, as if by memcpy, and store the result into Dest.
 
template<typename T >
Error readArray (ArrayRef< T > &Array, uint32_t NumElements)
 Get a reference to a NumElements element array of objects of type T from the underlying stream as if by memcpy, and store the resulting array slice into array.
 
template<typename T , typename U >
Error readArray (VarStreamArray< T, U > &Array, uint32_t Size, uint32_t Skew=0)
 Read a VarStreamArray of size Size bytes and store the result into Array.
 
template<typename T >
Error readArray (FixedStreamArray< T > &Array, uint32_t NumItems)
 Read a FixedStreamArray of NumItems elements and store the result into Array.
 
bool empty () const
 
void setOffset (uint64_t Off)
 
uint64_t getOffset () const
 
uint64_t getLength () const
 
uint64_t bytesRemaining () const
 
Error skip (uint64_t Amount)
 Advance the stream's offset by Amount bytes.
 
uint8_t peek () const
 Examine the next byte of the underlying stream without advancing the stream's offset.
 
Error padToAlignment (uint32_t Align)
 
std::pair< BinaryStreamReader, BinaryStreamReadersplit (uint64_t Offset) const
 

Detailed Description

Provides read only access to a subclass of BinaryStream.

Provides bounds checking and helpers for writing certain common data types such as null-terminated strings, integers in various flavors of endianness, etc. Can be subclassed to provide reading of custom datatypes, although no are overridable.

Definition at line 29 of file BinaryStreamReader.h.

Constructor & Destructor Documentation

◆ BinaryStreamReader() [1/6]

llvm::BinaryStreamReader::BinaryStreamReader ( )
default

◆ BinaryStreamReader() [2/6]

BinaryStreamReader::BinaryStreamReader ( BinaryStreamRef  Ref)
explicit

Definition at line 17 of file BinaryStreamReader.cpp.

◆ BinaryStreamReader() [3/6]

BinaryStreamReader::BinaryStreamReader ( BinaryStream Stream)
explicit

Definition at line 19 of file BinaryStreamReader.cpp.

◆ BinaryStreamReader() [4/6]

BinaryStreamReader::BinaryStreamReader ( ArrayRef< uint8_t >  Data,
llvm::endianness  Endian 
)
explicit

Definition at line 21 of file BinaryStreamReader.cpp.

References Endian.

◆ BinaryStreamReader() [5/6]

BinaryStreamReader::BinaryStreamReader ( StringRef  Data,
llvm::endianness  Endian 
)
explicit

Definition at line 25 of file BinaryStreamReader.cpp.

References Endian.

◆ BinaryStreamReader() [6/6]

llvm::BinaryStreamReader::BinaryStreamReader ( const BinaryStreamReader Other)
default

◆ ~BinaryStreamReader()

virtual llvm::BinaryStreamReader::~BinaryStreamReader ( )
virtualdefault

Member Function Documentation

◆ bytesRemaining()

uint64_t llvm::BinaryStreamReader::bytesRemaining ( ) const
inline

◆ empty()

bool llvm::BinaryStreamReader::empty ( ) const
inline

◆ getLength()

uint64_t llvm::BinaryStreamReader::getLength ( ) const
inline

◆ getOffset()

uint64_t llvm::BinaryStreamReader::getOffset ( ) const
inline

◆ operator=()

BinaryStreamReader & llvm::BinaryStreamReader::operator= ( const BinaryStreamReader Other)
default

◆ padToAlignment()

Error BinaryStreamReader::padToAlignment ( uint32_t  Align)

Definition at line 154 of file BinaryStreamReader.cpp.

References llvm::alignTo(), and skip().

Referenced by llvm::codeview::CodeViewRecordIO::padToAlignment().

◆ peek()

uint8_t BinaryStreamReader::peek ( ) const

Examine the next byte of the underlying stream without advancing the stream's offset.

If the stream is empty the behavior is undefined.

Returns
the next byte in the stream.

Definition at line 159 of file BinaryStreamReader.cpp.

References assert(), llvm::consumeError(), and llvm::BinaryStreamRef::readBytes().

Referenced by llvm::codeview::serialize_vector_tail_impl< T >::deserialize(), llvm::codeview::serialize_null_term_string_array_impl::deserialize(), llvm::codeview::CodeViewRecordIO::mapVectorTail(), and llvm::codeview::CodeViewRecordIO::skipPadding().

◆ readArray() [1/3]

template<typename T >
Error llvm::BinaryStreamReader::readArray ( ArrayRef< T > &  Array,
uint32_t  NumElements 
)
inline

Get a reference to a NumElements element array of objects of type T from the underlying stream as if by memcpy, and store the resulting array slice into array.

It is up to the caller to ensure that objects of type T can be safely treated in this manner. Updates the stream's offset to point after the newly read object. Whether a copy occurs depends upon the implementation of the underlying stream.

Returns
a success error code if the data was successfully read, otherwise returns an appropriate error code.

Definition at line 178 of file BinaryStreamReader.h.

References assert(), llvm::ArrayRef< T >::data(), llvm::invalid_array_size, llvm::isAddrAligned(), readBytes(), and llvm::Error::success().

Referenced by llvm::codeview::serialize_array_impl< T, U >::deserialize(), llvm::codeview::serialize_arrayref_tail_impl< T >::deserialize(), llvm::CodeViewYAML::fromDebugS(), llvm::CodeViewYAML::fromDebugT(), llvm::codeview::DebugSymbolRVASubsectionRef::initialize(), llvm::codeview::DebugChecksumsSubsectionRef::initialize(), llvm::codeview::DebugCrossModuleExportsSubsectionRef::initialize(), llvm::codeview::DebugCrossModuleImportsSubsectionRef::initialize(), llvm::codeview::DebugFrameDataSubsectionRef::initialize(), llvm::codeview::DebugInlineeLinesSubsectionRef::initialize(), llvm::codeview::DebugLinesSubsectionRef::initialize(), llvm::codeview::DebugSymbolsSubsectionRef::initialize(), isDebugSSection(), isDebugTSection(), loadSectionContribs(), llvm::codeview::LineColumnExtractor::operator()(), llvm::pdb::PDBFile::parseFileHeaders(), llvm::pdb::PDBFile::parseStreamData(), readGSIHashBuckets(), readGSIHashRecords(), readWideString(), llvm::pdb::PublicsStream::reload(), llvm::pdb::SymbolStream::reload(), llvm::pdb::TpiStream::reload(), llvm::pdb::DbiStream::reload(), llvm::codeview::LazyRandomTypeCollection::reset(), and resolveTypeIndexReferences().

◆ readArray() [2/3]

template<typename T >
Error llvm::BinaryStreamReader::readArray ( FixedStreamArray< T > &  Array,
uint32_t  NumItems 
)
inline

Read a FixedStreamArray of NumItems elements and store the result into Array.

Updates the stream's offset to point after the newly read array. Never causes a copy (although iterating the elements of the FixedStreamArray may, depending upon the implementation of the underlying stream).

Returns
a success error code if the data was successfully read, otherwise returns an appropriate error code.

Definition at line 226 of file BinaryStreamReader.h.

References llvm::invalid_array_size, readStreamRef(), and llvm::Error::success().

◆ readArray() [3/3]

template<typename T , typename U >
Error llvm::BinaryStreamReader::readArray ( VarStreamArray< T, U > &  Array,
uint32_t  Size,
uint32_t  Skew = 0 
)
inline

Read a VarStreamArray of size Size bytes and store the result into Array.

Updates the stream's offset to point after the newly read array. Never causes a copy (although iterating the elements of the VarStreamArray may, depending upon the implementation of the underlying stream).

Returns
a success error code if the data was successfully read, otherwise returns an appropriate error code.

Definition at line 208 of file BinaryStreamReader.h.

References readStreamRef(), Size, and llvm::Error::success().

◆ readBytes()

Error BinaryStreamReader::readBytes ( ArrayRef< uint8_t > &  Buffer,
uint32_t  Size 
)

Read Size bytes from the underlying stream at the current offset and and set Buffer to the resulting data slice.

Whether a copy occurs depends on the implementation of the underlying stream. Updates the stream's offset to point after the newly read data.

Returns
a success error code if the data was successfully read, otherwise returns an appropriate error code.

Definition at line 36 of file BinaryStreamReader.cpp.

References llvm::BinaryStreamRef::readBytes(), Size, and llvm::Error::success().

Referenced by llvm::pdb::LinePrinter::formatMsfStreamData(), llvm::CodeViewYAML::fromDebugH(), llvm::codeview::CodeViewRecordIO::mapByteVectorTail(), llvm::codeview::CodeViewRecordIO::mapGuid(), llvm::VarStreamArrayExtractor< T >::operator()(), llvm::pdb::PDBFile::parseFileHeaders(), readArray(), llvm::codeview::readCVRecordFromStream(), readFixedString(), readInteger(), readObject(), readSLEB128(), and readULEB128().

◆ readCString()

Error BinaryStreamReader::readCString ( StringRef Dest)

Read a null terminated string from Dest.

Whether a copy occurs depends on the implementation of the underlying stream. Updates the stream's offset to point after the newly read data.

Returns
a success error code if the data was successfully read, otherwise returns an appropriate error code.

Definition at line 73 of file BinaryStreamReader.cpp.

References assert(), llvm::ArrayRef< T >::begin(), llvm::StringRef::find_first_of(), getOffset(), llvm::Length, LLVM_LIKELY, llvm::StringRef::npos, readFixedString(), readLongestContiguousChunk(), setOffset(), llvm::ArrayRef< T >::size(), and llvm::Error::success().

Referenced by llvm::codeview::consume(), llvm::codeview::serialize_null_term_string_array_impl::deserialize(), llvm::pdb::DbiModuleList::getFileName(), llvm::codeview::DebugStringTableSubsectionRef::getString(), llvm::pdb::DbiModuleDescriptor::initialize(), and llvm::codeview::CodeViewRecordIO::mapStringZ().

◆ readEnum()

template<typename T >
Error llvm::BinaryStreamReader::readEnum ( T Dest)
inline

◆ readFixedString()

Error BinaryStreamReader::readFixedString ( StringRef Dest,
uint32_t  Length 
)

Read a Length byte string into Dest.

Whether a copy occurs depends on the implementation of the underlying stream. Updates the stream's offset to point after the newly read data.

Returns
a success error code if the data was successfully read, otherwise returns an appropriate error code.

Definition at line 121 of file BinaryStreamReader.cpp.

References llvm::ArrayRef< T >::begin(), llvm::Length, readBytes(), llvm::ArrayRef< T >::size(), and llvm::Error::success().

Referenced by llvm::pdb::NamedStreamMap::load(), and readCString().

◆ readInteger()

template<typename T >
Error llvm::BinaryStreamReader::readInteger ( T Dest)
inline

Read an integer of the specified endianness into Dest and update the stream's offset.

The data is always copied from the stream's underlying buffer into Dest. Updates the stream's offset to point after the newly read data.

Returns
a success error code if the data was successfully read, otherwise returns an appropriate error code.

Definition at line 67 of file BinaryStreamReader.h.

References llvm::ArrayRef< T >::data(), llvm::BinaryStreamRefBase< RefType, StreamType >::getEndian(), readBytes(), and llvm::Error::success().

Referenced by llvm::codeview::consume(), llvm::CodeViewYAML::fromDebugH(), llvm::CodeViewYAML::fromDebugS(), llvm::CodeViewYAML::fromDebugT(), isCodeViewDebugSubsection(), llvm::pdb::HashTable< ValueT >::load(), llvm::pdb::NamedStreamMap::load(), llvm::codeview::CodeViewRecordIO::mapInteger(), llvm::codeview::CodeViewRecordIO::mapVectorN(), llvm::pdb::PDBFile::parseStreamData(), readEnum(), llvm::pdb::readSparseBitVector(), and llvm::object::readStringOrId().

◆ readLongestContiguousChunk()

Error BinaryStreamReader::readLongestContiguousChunk ( ArrayRef< uint8_t > &  Buffer)

Read as much as possible from the underlying string at the current offset without invoking a copy, and set Buffer to the resulting data slice.

Updates the stream's offset to point after the newly read data.

Returns
a success error code if the data was successfully read, otherwise returns an appropriate error code.

Definition at line 28 of file BinaryStreamReader.cpp.

References llvm::BinaryStreamRef::readLongestContiguousChunk(), llvm::ArrayRef< T >::size(), and llvm::Error::success().

Referenced by llvm::logicalview::LVSymbolVisitorDelegate::getRecordOffset(), readCString(), and llvm::BinaryStreamWriter::writeStreamRef().

◆ readObject()

template<typename T >
Error llvm::BinaryStreamReader::readObject ( const T *&  Dest)
inline

Get a pointer to an object of type T from the underlying stream, as if by memcpy, and store the result into Dest.

It is up to the caller to ensure that objects of type T can be safely treated in this manner. Updates the stream's offset to point after the newly read object. Whether a copy occurs depends upon the implementation of the underlying stream.

Returns
a success error code if the data was successfully read, otherwise returns an appropriate error code.

Definition at line 160 of file BinaryStreamReader.h.

References llvm::ArrayRef< T >::data(), readBytes(), and llvm::Error::success().

Referenced by llvm::codeview::consume(), llvm::codeview::DebugFrameDataSubsectionRef::initialize(), llvm::codeview::DebugLinesSubsectionRef::initialize(), llvm::pdb::DbiModuleDescriptor::initialize(), llvm::codeview::DebugSubsectionRecord::initialize(), llvm::pdb::HashTable< ValueT >::load(), llvm::codeview::CodeViewRecordIO::mapObject(), llvm::codeview::LineColumnExtractor::operator()(), llvm::VarStreamArrayExtractor< T >::operator()(), llvm::pdb::PDBFile::parseFileHeaders(), llvm::codeview::readCVRecordFromStream(), readGSIHashHeader(), readWideString(), llvm::pdb::InfoStream::reload(), llvm::pdb::PublicsStream::reload(), llvm::pdb::TpiStream::reload(), llvm::pdb::InjectedSourceStream::reload(), and llvm::pdb::DbiStream::reload().

◆ readSLEB128()

Error BinaryStreamReader::readSLEB128 ( int64_t &  Dest)

Read a signed LEB128 encoded value.

Returns
a success error code if the data was successfully read, otherwise returns an appropriate error code.

Definition at line 58 of file BinaryStreamReader.cpp.

References llvm::SmallVectorTemplateCommon< T, typename >::begin(), llvm::decodeSLEB128(), llvm::SmallVectorTemplateCommon< T, typename >::end(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), readBytes(), and llvm::Error::success().

◆ readStreamRef() [1/2]

Error BinaryStreamReader::readStreamRef ( BinaryStreamRef Ref)

Read the entire remainder of the underlying stream into Ref.

This is equivalent to calling getUnderlyingStream().slice(Offset). Updates the stream's offset to point to the end of the stream. Never causes a copy.

Returns
a success error code if the data was successfully read, otherwise returns an appropriate error code.

Definition at line 129 of file BinaryStreamReader.cpp.

References bytesRemaining(), readStreamRef(), and llvm::Ref.

Referenced by llvm::codeview::DebugStringTableSubsectionRef::initialize(), llvm::codeview::DebugSubsectionRecord::initialize(), readArray(), readStreamRef(), and readSubstream().

◆ readStreamRef() [2/2]

Error BinaryStreamReader::readStreamRef ( BinaryStreamRef Ref,
uint32_t  Length 
)

Read Length bytes from the underlying stream into Ref.

This is equivalent to calling getUnderlyingStream().slice(Offset, Length). Updates the stream's offset to point after the newly read object. Never causes a copy.

Returns
a success error code if the data was successfully read, otherwise returns an appropriate error code.

Definition at line 133 of file BinaryStreamReader.cpp.

References bytesRemaining(), llvm::Length, llvm::Ref, llvm::BinaryStreamRefBase< RefType, StreamType >::slice(), llvm::stream_too_short, and llvm::Error::success().

◆ readSubstream()

Error BinaryStreamReader::readSubstream ( BinarySubstreamRef Ref,
uint32_t  Length 
)

Read Length bytes from the underlying stream into Ref.

This is equivalent to calling getUnderlyingStream().slice(Offset, Length). Updates the stream's offset to point after the newly read object. Never causes a copy.

Returns
a success error code if the data was successfully read, otherwise returns an appropriate error code.

Definition at line 141 of file BinaryStreamReader.cpp.

References getOffset(), llvm::Length, readStreamRef(), and llvm::Ref.

Referenced by llvm::pdb::InfoStream::reload(), llvm::pdb::TpiStream::reload(), and llvm::pdb::DbiStream::reload().

◆ readULEB128()

Error BinaryStreamReader::readULEB128 ( uint64_t Dest)

Read an unsigned LEB128 encoded value.

Returns
a success error code if the data was successfully read, otherwise returns an appropriate error code.

Definition at line 43 of file BinaryStreamReader.cpp.

References llvm::SmallVectorTemplateCommon< T, typename >::begin(), llvm::decodeULEB128(), llvm::SmallVectorTemplateCommon< T, typename >::end(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), readBytes(), and llvm::Error::success().

◆ readWideString()

Error BinaryStreamReader::readWideString ( ArrayRef< UTF16 > &  Dest)

Similar to readCString, however read a null-terminated UTF16 string instead.

Returns
a success error code if the data was successfully read, otherwise returns an appropriate error code.

Definition at line 101 of file BinaryStreamReader.cpp.

References llvm::CallingConv::C, getOffset(), llvm::Length, readArray(), readObject(), setOffset(), and llvm::Error::success().

Referenced by llvm::object::readStringOrId().

◆ setOffset()

void llvm::BinaryStreamReader::setOffset ( uint64_t  Off)
inline

◆ skip()

Error BinaryStreamReader::skip ( uint64_t  Amount)

Advance the stream's offset by Amount bytes.

Returns
a success error code if at least Amount bytes remain in the stream, otherwise returns an appropriate error code.

Definition at line 147 of file BinaryStreamReader.cpp.

References bytesRemaining(), llvm::stream_too_short, and llvm::Error::success().

Referenced by llvm::codeview::serialize_null_term_string_array_impl::deserialize(), padToAlignment(), and llvm::codeview::CodeViewRecordIO::skipPadding().

◆ split()

std::pair< BinaryStreamReader, BinaryStreamReader > BinaryStreamReader::split ( uint64_t  Offset) const

The documentation for this class was generated from the following files: