LLVM 20.0.0git
|
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 | |
BinaryStreamReader & | operator= (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, BinaryStreamReader > | split (uint64_t Offset) const |
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.
|
default |
|
explicit |
Definition at line 17 of file BinaryStreamReader.cpp.
|
explicit |
Definition at line 19 of file BinaryStreamReader.cpp.
|
explicit |
Definition at line 21 of file BinaryStreamReader.cpp.
References Endian.
|
explicit |
Definition at line 25 of file BinaryStreamReader.cpp.
References Endian.
|
default |
|
virtualdefault |
|
inline |
Definition at line 248 of file BinaryStreamReader.h.
References getLength(), and getOffset().
Referenced by llvm::codeview::consume(), llvm::codeview::serialize_arrayref_tail_impl< T >::deserialize(), empty(), llvm::pdb::LinePrinter::formatMsfStreamData(), llvm::CodeViewYAML::fromDebugH(), llvm::CodeViewYAML::fromDebugS(), llvm::CodeViewYAML::fromDebugT(), llvm::pdb::PDBFile::getStringTable(), 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(), isCodeViewDebugSubsection(), isDebugSSection(), isDebugTSection(), loadSectionContribs(), llvm::codeview::CodeViewRecordIO::mapByteVectorTail(), llvm::object::ResourceEntryRef::moveNext(), llvm::pdb::PDBFile::parseFileHeaders(), llvm::pdb::PDBFile::parseStreamData(), readStreamRef(), llvm::pdb::ModuleDebugStreamRef::reload(), llvm::pdb::PublicsStream::reload(), llvm::pdb::TpiStream::reload(), llvm::pdb::PDBStringTable::reload(), llvm::pdb::InjectedSourceStream::reload(), llvm::pdb::DbiStream::reload(), llvm::codeview::LazyRandomTypeCollection::reset(), skip(), llvm::codeview::CodeViewRecordIO::skipPadding(), and llvm::BinaryStreamWriter::writeStreamRef().
|
inline |
Definition at line 244 of file BinaryStreamReader.h.
References bytesRemaining().
Referenced by llvm::codeview::consume(), llvm::codeview::serialize_vector_tail_impl< T >::deserialize(), llvm::codeview::serialize_null_term_string_array_impl::deserialize(), llvm::codeview::CodeViewRecordIO::mapVectorTail(), and llvm::pdb::InfoStream::reload().
|
inline |
Definition at line 247 of file BinaryStreamReader.h.
References llvm::BinaryStreamRefBase< RefType, StreamType >::getLength().
Referenced by bytesRemaining(), llvm::codeview::DebugSymbolsSubsectionRef::initialize(), and split().
|
inline |
Definition at line 246 of file BinaryStreamReader.h.
Referenced by bytesRemaining(), readCString(), llvm::object::readStringOrId(), readSubstream(), readWideString(), and llvm::pdb::InfoStream::reload().
|
default |
Definition at line 154 of file BinaryStreamReader.cpp.
References llvm::alignTo(), and skip().
Referenced by llvm::codeview::CodeViewRecordIO::padToAlignment().
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.
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().
|
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.
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().
|
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).
Definition at line 226 of file BinaryStreamReader.h.
References llvm::invalid_array_size, readStreamRef(), and llvm::Error::success().
|
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).
Definition at line 208 of file BinaryStreamReader.h.
References readStreamRef(), Size, and llvm::Error::success().
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.
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().
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.
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().
Similar to readInteger.
Definition at line 80 of file BinaryStreamReader.h.
References N, readInteger(), and llvm::Error::success().
Referenced by llvm::codeview::DebugInlineeLinesSubsectionRef::initialize(), and llvm::pdb::InfoStream::reload().
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.
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().
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.
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().
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.
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().
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.
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().
Error BinaryStreamReader::readSLEB128 | ( | int64_t & | Dest | ) |
Read a signed LEB128 encoded value.
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().
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.
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().
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.
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().
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.
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().
Read an unsigned LEB128 encoded value.
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().
Similar to readCString, however read a null-terminated UTF16 string instead.
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().
|
inline |
Definition at line 245 of file BinaryStreamReader.h.
Referenced by llvm::pdb::DbiModuleList::getFileName(), llvm::codeview::DebugStringTableSubsectionRef::getString(), llvm::pdb::PDBFile::parseFileHeaders(), readCString(), llvm::codeview::readCVRecordFromStream(), llvm::object::readStringOrId(), readWideString(), llvm::pdb::InfoStream::reload(), llvm::pdb::TpiStream::reload(), and resolveTypeIndexReferences().
Advance the stream's offset by Amount
bytes.
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().
std::pair< BinaryStreamReader, BinaryStreamReader > BinaryStreamReader::split | ( | uint64_t | Offset | ) | const |
Definition at line 168 of file BinaryStreamReader.cpp.
References assert(), llvm::BinaryStreamRefBase< RefType, StreamType >::drop_front(), llvm::First, and getLength().
Referenced by llvm::pdb::PDBStringTable::reload().