File indexing completed on 2026-05-10 08:44:16
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLVM_MC_STRINGTABLEBUILDER_H
0010 #define LLVM_MC_STRINGTABLEBUILDER_H
0011
0012 #include "llvm/ADT/CachedHashString.h"
0013 #include "llvm/ADT/DenseMap.h"
0014 #include "llvm/ADT/StringRef.h"
0015 #include "llvm/Support/Alignment.h"
0016 #include <cstddef>
0017 #include <cstdint>
0018
0019 namespace llvm {
0020
0021 class raw_ostream;
0022
0023
0024 class StringTableBuilder {
0025 public:
0026 enum Kind {
0027 ELF,
0028 WinCOFF,
0029 MachO,
0030 MachO64,
0031 MachOLinked,
0032 MachO64Linked,
0033 RAW,
0034 DWARF,
0035 XCOFF,
0036 DXContainer
0037 };
0038
0039 private:
0040 DenseMap<CachedHashStringRef, size_t> StringIndexMap;
0041 size_t Size = 0;
0042 Kind K;
0043 Align Alignment;
0044 bool Finalized = false;
0045
0046 void finalizeStringTable(bool Optimize);
0047 void initSize();
0048
0049 public:
0050 StringTableBuilder(Kind K, Align Alignment = Align(1));
0051 ~StringTableBuilder();
0052
0053
0054
0055
0056 size_t add(CachedHashStringRef S);
0057 size_t add(StringRef S) { return add(CachedHashStringRef(S)); }
0058
0059
0060
0061 void finalize();
0062
0063
0064
0065 void finalizeInOrder();
0066
0067
0068
0069 size_t getOffset(CachedHashStringRef S) const;
0070 size_t getOffset(StringRef S) const {
0071 return getOffset(CachedHashStringRef(S));
0072 }
0073
0074
0075
0076
0077 bool contains(StringRef S) const { return contains(CachedHashStringRef(S)); }
0078 bool contains(CachedHashStringRef S) const { return StringIndexMap.count(S); }
0079
0080 size_t getSize() const { return Size; }
0081 void clear();
0082
0083 void write(raw_ostream &OS) const;
0084 void write(uint8_t *Buf) const;
0085
0086 bool isFinalized() const { return Finalized; }
0087 };
0088
0089 }
0090
0091 #endif