LLVM 22.0.0git
Public Types | Public Member Functions | List of all members
llvm::StringTableBuilder Class Reference

Utility for building string tables with deduplicated suffixes. More...

#include "llvm/MC/StringTableBuilder.h"

Public Types

enum  Kind {
  ELF , WinCOFF , MachO , MachO64 ,
  MachOLinked , MachO64Linked , RAW , DWARF ,
  XCOFF , DXContainer
}
 

Public Member Functions

LLVM_ABI StringTableBuilder (Kind K, Align Alignment=Align(1))
 
LLVM_ABI ~StringTableBuilder ()
 
LLVM_ABI size_t add (CachedHashStringRef S, uint8_t Priority=0)
 Add a string to the builder.
 
size_t add (StringRef S, uint8_t Priority=0)
 
LLVM_ABI void finalize ()
 Analyze the strings and build the final table.
 
LLVM_ABI void finalizeInOrder ()
 Finalize the string table without reording it.
 
LLVM_ABI size_t getOffset (CachedHashStringRef S) const
 Get the offest of a string in the string table.
 
size_t getOffset (StringRef S) const
 
bool contains (StringRef S) const
 Check if a string is contained in the string table.
 
bool contains (CachedHashStringRef S) const
 
bool empty () const
 
size_t getSize () const
 
LLVM_ABI void clear ()
 
LLVM_ABI void write (raw_ostream &OS) const
 
LLVM_ABI void write (uint8_t *Buf) const
 
bool isFinalized () const
 

Detailed Description

Utility for building string tables with deduplicated suffixes.

Definition at line 25 of file StringTableBuilder.h.

Member Enumeration Documentation

◆ Kind

Enumerator
ELF 
WinCOFF 
MachO 
MachO64 
MachOLinked 
MachO64Linked 
RAW 
DWARF 
XCOFF 
DXContainer 

Definition at line 27 of file StringTableBuilder.h.

Constructor & Destructor Documentation

◆ StringTableBuilder()

StringTableBuilder::StringTableBuilder ( Kind  K,
Align  Alignment = Align(1) 
)

Definition at line 56 of file StringTableBuilder.cpp.

◆ ~StringTableBuilder()

StringTableBuilder::~StringTableBuilder ( )
default

Member Function Documentation

◆ add() [1/2]

size_t StringTableBuilder::add ( CachedHashStringRef  S,
uint8_t  Priority = 0 
)

Add a string to the builder.

Returns the position of S in the table. The position will be changed if finalize is used. Can only be used before the table is finalized. Priority is only useful with reordering. Strings with the same priority will be put together. Strings with higher priority are placed closer to the begin of string table. When adding same string with different priority, the maximum priority win.

Definition at line 220 of file StringTableBuilder.cpp.

References llvm::alignTo(), assert(), isFinalized(), llvm::COFF::NameSize, P, RAW, llvm::CachedHashStringRef::size(), and WinCOFF.

Referenced by add(), llvm::objcopy::elf::StringTableSection::addString(), llvm::MCDwarfLineStr::addString(), llvm::mcdxbc::PSVRuntimeInfo::finalize(), llvm::gsym::GsymCreator::insertString(), ProcessElementList(), llvm::object::OffloadBinary::write(), llvm::mcdxbc::Signature::write(), llvm::WinCOFFWriter::writeObject(), writeTypeIdCompatibleVtableSummaryRecord(), writeTypeIdSummaryRecord(), and writeWholeProgramDevirtResolution().

◆ add() [2/2]

size_t llvm::StringTableBuilder::add ( StringRef  S,
uint8_t  Priority = 0 
)
inline

Definition at line 63 of file StringTableBuilder.h.

References add().

◆ clear()

void StringTableBuilder::clear ( )

Definition at line 208 of file StringTableBuilder.cpp.

Referenced by llvm::WinCOFFWriter::reset().

◆ contains() [1/2]

bool llvm::StringTableBuilder::contains ( CachedHashStringRef  S) const
inline

◆ contains() [2/2]

bool llvm::StringTableBuilder::contains ( StringRef  S) const
inline

Check if a string is contained in the string table.

Since this class doesn't store the string values, this function can be used to check if storage needs to be done prior to adding the string.

Definition at line 85 of file StringTableBuilder.h.

References contains().

Referenced by contains(), and llvm::gsym::GsymCreator::insertString().

◆ empty()

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

◆ finalize()

void StringTableBuilder::finalize ( )

Analyze the strings and build the final table.

No more strings can be added after this point.

Definition at line 129 of file StringTableBuilder.cpp.

References assert(), and DWARF.

Referenced by llvm::mcdxbc::PSVRuntimeInfo::finalize(), llvm::objcopy::elf::StringTableSection::prepareForLayout(), llvm::object::OffloadBinary::write(), and llvm::WinCOFFWriter::writeObject().

◆ finalizeInOrder()

void StringTableBuilder::finalizeInOrder ( )

Finalize the string table without reording it.

In this mode, offsets returned by add will still be valid.

Definition at line 134 of file StringTableBuilder.cpp.

Referenced by llvm::gsym::GsymCreator::finalize(), llvm::MCDwarfLineStr::getFinalizedData(), upgrade(), llvm::mcdxbc::Signature::write(), and llvm::BitcodeWriter::writeStrtab().

◆ getOffset() [1/2]

size_t StringTableBuilder::getOffset ( CachedHashStringRef  S) const

Get the offest of a string in the string table.

Can only be used after the table is finalized.

Definition at line 213 of file StringTableBuilder.cpp.

References assert(), I, and isFinalized().

Referenced by llvm::mcdxbc::PSVRuntimeInfo::finalize(), llvm::objcopy::elf::StringTableSection::findIndex(), getOffset(), and llvm::object::OffloadBinary::write().

◆ getOffset() [2/2]

size_t llvm::StringTableBuilder::getOffset ( StringRef  S) const
inline

Definition at line 78 of file StringTableBuilder.h.

References getOffset().

◆ getSize()

size_t llvm::StringTableBuilder::getSize ( ) const
inline

◆ isFinalized()

bool llvm::StringTableBuilder::isFinalized ( ) const
inline

Definition at line 95 of file StringTableBuilder.h.

Referenced by add(), llvm::MCDwarfLineStr::getFinalizedData(), getOffset(), and write().

◆ write() [1/2]

void StringTableBuilder::write ( raw_ostream OS) const

◆ write() [2/2]

void StringTableBuilder::write ( uint8_t Buf) const

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