LLVM  6.0.0svn
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::support::endianness Endian)
 
 BinaryStreamReader (StringRef Data, llvm::support::endianness Endian)
 
 BinaryStreamReader (const BinaryStreamReader &Other)
 
BinaryStreamReaderoperator= (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)
 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, BinaryStreamReadersplit (uint32_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 32 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 18 of file BinaryStreamReader.cpp.

◆ BinaryStreamReader() [3/6]

BinaryStreamReader::BinaryStreamReader ( BinaryStream Stream)
explicit

Definition at line 20 of file BinaryStreamReader.cpp.

◆ BinaryStreamReader() [4/6]

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

Definition at line 22 of file BinaryStreamReader.cpp.

◆ BinaryStreamReader() [5/6]

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

Definition at line 26 of file BinaryStreamReader.cpp.

◆ BinaryStreamReader() [6/6]

llvm::BinaryStreamReader::BinaryStreamReader ( const BinaryStreamReader Other)
inline

Definition at line 41 of file BinaryStreamReader.h.

◆ ~BinaryStreamReader()

virtual llvm::BinaryStreamReader::~BinaryStreamReader ( )
inlinevirtual

Member Function Documentation

◆ bytesRemaining()

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

◆ empty()

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

◆ getLength()

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

◆ getOffset()

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

◆ operator=()

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

Definition at line 44 of file BinaryStreamReader.h.

◆ padToAlignment()

Error BinaryStreamReader::padToAlignment ( uint32_t  Align)

◆ 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 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().

◆ 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 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::CodeViewYAML::fromDebugS(), llvm::CodeViewYAML::fromDebugT(), 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::pdb::DbiModuleList::initialize(), llvm::codeview::DebugInlineeLinesSubsectionRef::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().

◆ readArray() [2/3]

template<typename T , typename U >
Error llvm::BinaryStreamReader::readArray ( VarStreamArray< T, U > &  Array,
uint32_t  Size 
)
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 206 of file BinaryStreamReader.h.

References readStreamRef(), llvm::VarStreamArray< ValueType, Extractor >::setUnderlyingStream(), and llvm::Error::success().

◆ readArray() [3/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 223 of file BinaryStreamReader.h.

References llvm::invalid_array_size, readStreamRef(), 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 37 of file BinaryStreamReader.cpp.

References llvm::BinaryStreamRef::readBytes(), llvm::AMDGPU::HSAMD::Kernel::Arg::Key::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(), readGSIHashBuckets(), readInteger(), readObject(), and ~BinaryStreamReader().

◆ 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 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::pdb::NamedStreamMap::load(), llvm::codeview::CodeViewRecordIO::mapStringZ(), and readEnum().

◆ 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 92 of file BinaryStreamReader.cpp.

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

Referenced by readCString(), and readEnum().

◆ 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 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::CodeViewYAML::fromDebugS(), llvm::CodeViewYAML::fromDebugT(), llvm::pdb::PDBStringTable::getStringTable(), llvm::pdb::NamedStreamMap::load(), llvm::pdb::HashTable::load(), llvm::codeview::CodeViewRecordIO::mapInteger(), llvm::codeview::CodeViewRecordIO::mapVectorN(), llvm::pdb::PDBFile::parseStreamData(), readEnum(), llvm::object::readStringOrId(), and llvm::pdb::ModuleDebugStreamRef::reload().

◆ 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 29 of file BinaryStreamReader.cpp.

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

Referenced by readCString(), and ~BinaryStreamReader().

◆ 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 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::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().

◆ 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 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(), llvm::pdb::NamedStreamMap::load(), readArray(), readEnum(), 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 104 of file BinaryStreamReader.cpp.

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

◆ readSubstream()

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.

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

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().

◆ 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 72 of file BinaryStreamReader.cpp.

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

Referenced by readEnum(), and llvm::object::readStringOrId().

◆ setOffset()

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

◆ skip()

Error BinaryStreamReader::skip ( uint32_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 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().

◆ split()

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

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