LLVM
8.0.1
|
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::support::endianness Endian) | |
BinaryStreamReader (StringRef Data, llvm::support::endianness Endian) | |
BinaryStreamReader (const BinaryStreamReader &Other) | |
BinaryStreamReader & | operator= (const BinaryStreamReader &Other) |
virtual | ~BinaryStreamReader () |
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. More... | |
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. More... | |
template<typename T > | |
Error | readInteger (T &Dest) |
Read an integer of the specified endianness into Dest and update the stream's offset. More... | |
template<typename T > | |
Error | readEnum (T &Dest) |
Similar to readInteger. More... | |
Error | readCString (StringRef &Dest) |
Read a null terminated string from Dest . More... | |
Error | readWideString (ArrayRef< UTF16 > &Dest) |
Similar to readCString, however read a null-terminated UTF16 string instead. More... | |
Error | readFixedString (StringRef &Dest, uint32_t Length) |
Read a Length byte string into Dest . More... | |
Error | readStreamRef (BinaryStreamRef &Ref) |
Read the entire remainder of the underlying stream into Ref . More... | |
Error | readStreamRef (BinaryStreamRef &Ref, uint32_t Length) |
Read Length bytes from the underlying stream into Ref . More... | |
Error | readSubstream (BinarySubstreamRef &Stream, uint32_t Size) |
Read Length bytes from the underlying stream into Stream . More... | |
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 . More... | |
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 . More... | |
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 . More... | |
template<typename T > | |
Error | readArray (FixedStreamArray< T > &Array, uint32_t NumItems) |
Read a FixedStreamArray of NumItems elements and store the result into Array . More... | |
bool | empty () const |
void | setOffset (uint32_t Off) |
uint32_t | getOffset () const |
uint32_t | getLength () const |
uint32_t | bytesRemaining () const |
Error | skip (uint32_t Amount) |
Advance the stream's offset by Amount bytes. More... | |
uint8_t | peek () const |
Examine the next byte of the underlying stream without advancing the stream's offset. More... | |
Error | padToAlignment (uint32_t Align) |
std::pair< BinaryStreamReader, BinaryStreamReader > | split (uint32_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 32 of file BinaryStreamReader.h.
|
default |
|
explicit |
Definition at line 18 of file BinaryStreamReader.cpp.
|
explicit |
Definition at line 20 of file BinaryStreamReader.cpp.
|
explicit |
Definition at line 22 of file BinaryStreamReader.cpp.
|
explicit |
Definition at line 26 of file BinaryStreamReader.cpp.
|
inline |
Definition at line 41 of file BinaryStreamReader.h.
|
inlinevirtual |
Definition at line 50 of file BinaryStreamReader.h.
References readBytes(), readLongestContiguousChunk(), and Size.
|
inline |
Definition at line 246 of file BinaryStreamReader.h.
References llvm::AMDGPU::HSAMD::Kernel::Arg::Key::Align, getLength(), getOffset(), padToAlignment(), peek(), skip(), and split().
Referenced by llvm::codeview::consume(), llvm::codeview::serialize_arrayref_tail_impl< T >::deserialize(), empty(), llvm::CodeViewYAML::fromDebugH(), llvm::pdb::PDBStringTable::getSignature(), llvm::pdb::PDBStringTable::getStringTable(), llvm::codeview::DebugFrameDataSubsectionRef::initialize(), llvm::codeview::DebugCrossModuleExportsSubsectionRef::initialize(), llvm::codeview::DebugSymbolRVASubsectionRef::initialize(), llvm::codeview::DebugCrossModuleImportsSubsectionRef::initialize(), llvm::codeview::DebugChecksumsSubsectionRef::initialize(), llvm::codeview::DebugInlineeLinesSubsectionRef::initialize(), llvm::codeview::DebugLinesSubsectionRef::initialize(), loadSectionContribs(), llvm::codeview::CodeViewRecordIO::mapByteVectorTail(), llvm::pdb::PDBFile::parseFileHeaders(), llvm::pdb::PDBFile::parseStreamData(), readStreamRef(), llvm::pdb::PublicsStream::reload(), llvm::pdb::PDBStringTable::reload(), llvm::pdb::ModuleDebugStreamRef::reload(), llvm::pdb::TpiStream::reload(), llvm::pdb::DbiStream::reload(), llvm::codeview::LazyRandomTypeCollection::reset(), skip(), and llvm::codeview::CodeViewRecordIO::skipPadding().
|
inline |
Definition at line 242 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(), llvm::pdb::InfoStream::reload(), and visitMemberRecord().
|
inline |
Definition at line 245 of file BinaryStreamReader.h.
Referenced by bytesRemaining(), llvm::codeview::DebugSymbolsSubsectionRef::initialize(), and split().
|
inline |
Definition at line 244 of file BinaryStreamReader.h.
Referenced by bytesRemaining(), readCString(), llvm::object::readStringOrId(), readSubstream(), readWideString(), and llvm::pdb::InfoStream::reload().
|
inline |
Definition at line 44 of file BinaryStreamReader.h.
Definition at line 125 of file BinaryStreamReader.cpp.
References llvm::alignTo(), and skip().
Referenced by bytesRemaining(), and 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 130 of file BinaryStreamReader.cpp.
References assert(), llvm::consumeError(), and llvm::BinaryStreamRef::readBytes().
Referenced by bytesRemaining(), 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 176 of file BinaryStreamReader.h.
References llvm::alignmentAdjustment(), assert(), llvm::ArrayRef< T >::data(), llvm::invalid_array_size, readBytes(), llvm::Error::success(), and T.
Referenced by llvm::codeview::serialize_array_impl< T, U >::deserialize(), llvm::codeview::serialize_arrayref_tail_impl< T >::deserialize(), llvm::pdb::DbiStream::getECName(), llvm::pdb::DbiStream::getECSubstreamData(), llvm::pdb::PDBStringTable::getStringTable(), llvm::codeview::DebugSymbolsSubsectionRef::initialize(), llvm::codeview::DebugFrameDataSubsectionRef::initialize(), llvm::codeview::DebugCrossModuleExportsSubsectionRef::initialize(), llvm::codeview::DebugSymbolRVASubsectionRef::initialize(), llvm::codeview::DebugCrossModuleImportsSubsectionRef::initialize(), llvm::codeview::DebugChecksumsSubsectionRef::initialize(), llvm::codeview::DebugInlineeLinesSubsectionRef::initialize(), llvm::pdb::DbiModuleList::initialize(), llvm::codeview::DebugLinesSubsectionRef::initialize(), loadSectionContribs(), llvm::codeview::LineColumnExtractor::operator()(), llvm::pdb::PDBFile::parseFileHeaders(), llvm::pdb::PDBFile::parseStreamData(), readGSIHashBuckets(), readGSIHashRecords(), readWideString(), llvm::pdb::SymbolStream::reload(), llvm::pdb::PublicsStream::reload(), llvm::pdb::ModuleDebugStreamRef::reload(), llvm::pdb::TpiStream::reload(), llvm::pdb::DbiStream::reload(), llvm::codeview::LazyRandomTypeCollection::reset(), and resolveTypeIndexReferences().
|
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 206 of file BinaryStreamReader.h.
References readStreamRef(), llvm::VarStreamArray< ValueType, Extractor >::setUnderlyingStream(), and llvm::Error::success().
|
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 224 of file BinaryStreamReader.h.
References llvm::invalid_array_size, readStreamRef(), 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 37 of file BinaryStreamReader.cpp.
References llvm::BinaryStreamRef::readBytes(), Size, and llvm::Error::success().
Referenced by llvm::CodeViewYAML::fromDebugH(), llvm::codeview::CodeViewRecordIO::mapByteVectorTail(), llvm::codeview::CodeViewRecordIO::mapGuid(), llvm::VarStreamArrayExtractor< CrossModuleImportItem >::operator()(), llvm::pdb::PDBFile::parseFileHeaders(), readArray(), llvm::codeview::readCVRecordFromStream(), readFixedString(), readInteger(), readObject(), and ~BinaryStreamReader().
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 44 of file BinaryStreamReader.cpp.
References assert(), llvm::ArrayRef< T >::begin(), llvm::StringRef::find_first_of(), getOffset(), 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(), llvm::codeview::CodeViewRecordIO::mapStringZ(), and readEnum().
Similar to readInteger.
Definition at line 90 of file BinaryStreamReader.h.
References N, readCString(), readFixedString(), readInteger(), readStreamRef(), readSubstream(), readWideString(), and llvm::Error::success().
Referenced by llvm::pdb::DbiStream::getECName(), llvm::codeview::DebugInlineeLinesSubsectionRef::initialize(), llvm::pdb::InfoStream::reload(), and visitMemberRecord().
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 92 of file BinaryStreamReader.cpp.
References llvm::ArrayRef< T >::begin(), readBytes(), llvm::ArrayRef< T >::size(), and llvm::Error::success().
Referenced by llvm::pdb::NamedStreamMap::load(), readCString(), and readEnum().
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 76 of file BinaryStreamReader.h.
References llvm::ArrayRef< T >::data(), llvm::BinaryStream::getEndian(), readBytes(), and llvm::Error::success().
Referenced by llvm::codeview::consume(), llvm::CodeViewYAML::fromDebugH(), llvm::pdb::PDBStringTable::getStringTable(), llvm::pdb::NamedStreamMap::load(), llvm::pdb::HashTable< llvm::pdb::SrcHeaderBlockEntry, llvm::pdb::StringTableHashTraits >::load(), llvm::codeview::CodeViewRecordIO::mapInteger(), llvm::codeview::CodeViewRecordIO::mapVectorN(), llvm::pdb::PDBFile::parseStreamData(), readEnum(), llvm::pdb::readSparseBitVector(), llvm::object::readStringOrId(), and llvm::pdb::ModuleDebugStreamRef::reload().
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 29 of file BinaryStreamReader.cpp.
References llvm::BinaryStreamRef::readLongestContiguousChunk(), llvm::ArrayRef< T >::size(), and llvm::Error::success().
Referenced by readCString(), and ~BinaryStreamReader().
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 158 of file BinaryStreamReader.h.
References llvm::ArrayRef< T >::data(), readBytes(), and llvm::Error::success().
Referenced by llvm::codeview::consume(), llvm::pdb::DbiStream::getECSubstreamData(), llvm::object::ResourceSectionRef::getEntryNameString(), llvm::pdb::PDBStringTable::getSignature(), llvm::pdb::PDBStringTable::getStringTable(), llvm::codeview::DebugFrameDataSubsectionRef::initialize(), llvm::pdb::DbiModuleDescriptor::initialize(), llvm::codeview::DebugSubsectionRecord::initialize(), llvm::pdb::DbiModuleList::initialize(), llvm::codeview::DebugLinesSubsectionRef::initialize(), llvm::pdb::HashTable< llvm::pdb::SrcHeaderBlockEntry, llvm::pdb::StringTableHashTraits >::load(), llvm::codeview::CodeViewRecordIO::mapObject(), llvm::VarStreamArrayExtractor< CrossModuleImportItem >::operator()(), llvm::codeview::LineColumnExtractor::operator()(), llvm::pdb::PDBFile::parseFileHeaders(), llvm::codeview::readCVRecordFromStream(), readGSIHashHeader(), readWideString(), llvm::pdb::PublicsStream::reload(), llvm::pdb::InfoStream::reload(), llvm::pdb::TpiStream::reload(), and llvm::pdb::DbiStream::reload().
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 100 of file BinaryStreamReader.cpp.
References bytesRemaining().
Referenced by llvm::pdb::PDBStringTable::getSignature(), llvm::codeview::DebugStringTableSubsectionRef::initialize(), llvm::codeview::DebugSubsectionRecord::initialize(), llvm::pdb::DbiModuleList::initialize(), readArray(), readEnum(), 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 104 of file BinaryStreamReader.cpp.
References bytesRemaining(), llvm::BinaryStreamRefBase< RefType, StreamType >::slice(), llvm::stream_too_short, and llvm::Error::success().
Error BinaryStreamReader::readSubstream | ( | BinarySubstreamRef & | Stream, |
uint32_t | Size | ||
) |
Read Length
bytes from the underlying stream into Stream
.
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 112 of file BinaryStreamReader.cpp.
References getOffset(), llvm::BinarySubstreamRef::Offset, readStreamRef(), and llvm::BinarySubstreamRef::StreamData.
Referenced by readEnum(), llvm::pdb::InfoStream::reload(), llvm::pdb::ModuleDebugStreamRef::reload(), llvm::pdb::TpiStream::reload(), and llvm::pdb::DbiStream::reload().
Similar to readCString, however read a null-terminated UTF16 string instead.
Definition at line 72 of file BinaryStreamReader.cpp.
References C, getOffset(), readArray(), readObject(), setOffset(), and llvm::Error::success().
Referenced by readEnum(), and llvm::object::readStringOrId().
|
inline |
Definition at line 243 of file BinaryStreamReader.h.
Referenced by llvm::object::ResourceSectionRef::getEntryNameString(), 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::ModuleDebugStreamRef::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 118 of file BinaryStreamReader.cpp.
References bytesRemaining(), llvm::stream_too_short, and llvm::Error::success().
Referenced by bytesRemaining(), llvm::codeview::serialize_null_term_string_array_impl::deserialize(), padToAlignment(), and llvm::codeview::CodeViewRecordIO::skipPadding().
std::pair< BinaryStreamReader, BinaryStreamReader > BinaryStreamReader::split | ( | uint32_t | Offset | ) | const |
Definition at line 139 of file BinaryStreamReader.cpp.
References assert(), llvm::BinaryStreamRefBase< RefType, StreamType >::drop_front(), getLength(), and llvm::BinaryStreamRefBase< RefType, StreamType >::keep_front().
Referenced by bytesRemaining(), and llvm::pdb::PDBStringTable::reload().