LLVM 23.0.0git
llvm::gsym::FileWriter Class Reference

A simplified binary data writer class that doesn't require targets, target definitions, architectures, or require any other optional compile time libraries to be enabled via the build process. More...

#include "llvm/DebugInfo/GSYM/FileWriter.h"

Public Member Functions

 FileWriter (llvm::raw_pwrite_stream &S, llvm::endianness B)
LLVM_ABI ~FileWriter ()
LLVM_ABI void writeU8 (uint8_t Value)
 Write a single uint8_t value into the stream at the current file position.
LLVM_ABI void writeU16 (uint16_t Value)
 Write a single uint16_t value into the stream at the current file position.
LLVM_ABI void writeU32 (uint32_t Value)
 Write a single uint32_t value into the stream at the current file position.
LLVM_ABI void writeU64 (uint64_t Value)
 Write a single uint64_t value into the stream at the current file position.
LLVM_ABI void writeSLEB (int64_t Value)
 Write the value into the stream encoded using signed LEB128 at the current file position.
LLVM_ABI void writeULEB (uint64_t Value)
 Write the value into the stream encoded using unsigned LEB128 at the current file position.
LLVM_ABI void writeUnsigned (uint64_t Value, size_t ByteSize)
 Write a single unsigned value into the stream at the current file position.
LLVM_ABI void writeStringOffset (uint64_t Value)
 Write a string table offset of StringOffsetSize bytes into the stream.
LLVM_ABI void writeData (llvm::ArrayRef< uint8_t > Data)
 Write an array of uint8_t values into the stream at the current file position.
LLVM_ABI void writeNullTerminated (llvm::StringRef Str)
 Write a NULL terminated C string into the stream at the current file position.
LLVM_ABI void fixup32 (uint32_t Value, uint64_t Offset)
 Fixup a uint32_t value at the specified offset in the stream.
LLVM_ABI void alignTo (size_t Align)
 Pad with zeroes at the current file position until the current file position matches the specified alignment.
LLVM_ABI uint64_t tell ()
 Return the current offset within the file.
llvm::raw_pwrite_streamget_stream ()
llvm::endianness getByteOrder () const
uint8_t getStringOffsetSize () const
 Get the string offset size for this writer.
void setStringOffsetSize (uint8_t Size)
 Set the string offset size for this writer.

Detailed Description

A simplified binary data writer class that doesn't require targets, target definitions, architectures, or require any other optional compile time libraries to be enabled via the build process.

This class needs the ability to seek to different spots in the binary stream that is produces to fixup offsets and sizes.

Definition at line 30 of file FileWriter.h.

Constructor & Destructor Documentation

◆ FileWriter()

llvm::gsym::FileWriter::FileWriter ( llvm::raw_pwrite_stream & S,
llvm::endianness B )
inline

Definition at line 36 of file FileWriter.h.

References B().

◆ ~FileWriter()

FileWriter::~FileWriter ( )

Definition at line 17 of file FileWriter.cpp.

Member Function Documentation

◆ alignTo()

void FileWriter::alignTo ( size_t Align)

Pad with zeroes at the current file position until the current file position matches the specified alignment.

Parameters
AlignAn integer speciying the desired alignment. This does not need to be a power of two.

Definition at line 89 of file FileWriter.cpp.

References llvm::Offset.

Referenced by llvm::gsym::FunctionInfo::encode().

◆ fixup32()

void FileWriter::fixup32 ( uint32_t Value,
uint64_t Offset )

Fixup a uint32_t value at the specified offset in the stream.

This function will save the current file position, seek to the specified offset, overwrite the data using Value, and then restore the file position to the previous file position.

Parameters
ValueThe value to write into the stream.
OffsetThe offset at which to write the Value within the stream.

Definition at line 71 of file FileWriter.cpp.

References llvm::support::endian::byte_swap(), and llvm::Offset.

Referenced by llvm::gsym::FunctionInfo::encode(), and llvm::gsym::MergedFunctionsInfo::encode().

◆ get_stream()

llvm::raw_pwrite_stream & llvm::gsym::FileWriter::get_stream ( )
inline

Definition at line 130 of file FileWriter.h.

◆ getByteOrder()

llvm::endianness llvm::gsym::FileWriter::getByteOrder ( ) const
inline

Definition at line 134 of file FileWriter.h.

Referenced by llvm::gsym::FunctionInfo::encode().

◆ getStringOffsetSize()

uint8_t llvm::gsym::FileWriter::getStringOffsetSize ( ) const
inline

Get the string offset size for this writer.

Definition at line 137 of file FileWriter.h.

◆ setStringOffsetSize()

void llvm::gsym::FileWriter::setStringOffsetSize ( uint8_t Size)
inline

Set the string offset size for this writer.

Definition at line 139 of file FileWriter.h.

References Size.

Referenced by llvm::gsym::FunctionInfo::cacheEncoding(), and llvm::gsym::GsymCreatorV2::encode().

◆ tell()

uint64_t FileWriter::tell ( )

Return the current offset within the file.

Returns
The unsigned offset from the start of the file of the current file position.

Definition at line 85 of file FileWriter.cpp.

Referenced by llvm::gsym::FunctionInfo::encode(), and llvm::gsym::MergedFunctionsInfo::encode().

◆ writeData()

void FileWriter::writeData ( llvm::ArrayRef< uint8_t > Data)

Write an array of uint8_t values into the stream at the current file position.

Parameters
DataAn array of values to write into the stream.

Definition at line 77 of file FileWriter.cpp.

References llvm::Data.

Referenced by llvm::gsym::FunctionInfo::encode().

◆ writeNullTerminated()

void FileWriter::writeNullTerminated ( llvm::StringRef Str)

Write a NULL terminated C string into the stream at the current file position.

The entire contents of Str will be written into the steam at the current file position and then an extra NULL termation byte will be written. It is up to the user to ensure that Str doesn't contain any NULL characters unless the additional NULL characters are desired.

Parameters
StrThe value to write into the stream.

Definition at line 81 of file FileWriter.cpp.

◆ writeSLEB()

void FileWriter::writeSLEB ( int64_t Value)

Write the value into the stream encoded using signed LEB128 at the current file position.

Parameters
ValueThe value to write into the stream.

Definition at line 23 of file FileWriter.cpp.

References assert(), llvm::encodeSLEB128(), and llvm::Length.

Referenced by llvm::gsym::LineTable::encode().

◆ writeStringOffset()

void FileWriter::writeStringOffset ( uint64_t Value)

Write a string table offset of StringOffsetSize bytes into the stream.

Parameters
ValueThe string table offset to write.

Definition at line 19 of file FileWriter.cpp.

References writeUnsigned().

Referenced by llvm::gsym::FunctionInfo::encode().

◆ writeU16()

void FileWriter::writeU16 ( uint16_t Value)

Write a single uint16_t value into the stream at the current file position.

The value will be byte swapped if needed to match the byte order specified during construction.

Parameters
ValueThe value to write into the stream.

Definition at line 41 of file FileWriter.cpp.

References llvm::support::endian::byte_swap().

◆ writeU32()

void FileWriter::writeU32 ( uint32_t Value)

Write a single uint32_t value into the stream at the current file position.

The value will be byte swapped if needed to match the byte order specified during construction.

Parameters
ValueThe value to write into the stream.

Definition at line 46 of file FileWriter.cpp.

References llvm::support::endian::byte_swap().

Referenced by llvm::gsym::FunctionInfo::encode(), and llvm::gsym::MergedFunctionsInfo::encode().

◆ writeU64()

void FileWriter::writeU64 ( uint64_t Value)

Write a single uint64_t value into the stream at the current file position.

The value will be byte swapped if needed to match the byte order specified during construction.

Parameters
ValueThe value to write into the stream.

Definition at line 51 of file FileWriter.cpp.

References llvm::support::endian::byte_swap().

◆ writeU8()

void FileWriter::writeU8 ( uint8_t Value)

Write a single uint8_t value into the stream at the current file position.

Parameters
ValueThe value to write into the stream.

Definition at line 37 of file FileWriter.cpp.

Referenced by llvm::gsym::LineTable::encode().

◆ writeULEB()

void FileWriter::writeULEB ( uint64_t Value)

Write the value into the stream encoded using unsigned LEB128 at the current file position.

Parameters
ValueThe value to write into the stream.

Definition at line 30 of file FileWriter.cpp.

References assert(), llvm::encodeULEB128(), and llvm::Length.

Referenced by llvm::gsym::LineTable::encode().

◆ writeUnsigned()

void FileWriter::writeUnsigned ( uint64_t Value,
size_t ByteSize )

Write a single unsigned value into the stream at the current file position.

The value will be byte swapped if needed to match the byte order specified during construction. The size of the value is specified by the Size parameter.

Parameters
ValueThe value to write into the stream. The higher bits which don't fit into ByteSize should be zero.
ByteSizeThe size of the value to write in bytes. Can be 1-8.

Definition at line 56 of file FileWriter.cpp.

References assert(), llvm::sys::getSwappedBytes(), llvm::sys::IsLittleEndianHost, and llvm::native.

Referenced by writeStringOffset().


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