1 //===-- NonRelocatableStringpool.h - A simple stringpool -----------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 #ifndef LLVM_TOOLS_DSYMUTIL_NONRELOCATABLESTRINGPOOL_H 10 #define LLVM_TOOLS_DSYMUTIL_NONRELOCATABLESTRINGPOOL_H 11 12 #include "llvm/ADT/StringMap.h" 13 14 namespace llvm { 15 namespace dsymutil { 16 17 /// \brief A string table that doesn't need relocations. 18 /// 19 /// We are doing a final link, no need for a string table that 20 /// has relocation entries for every reference to it. This class 21 /// provides this ablitity by just associating offsets with 22 /// strings. 23 class NonRelocatableStringpool { 24 public: 25 /// \brief Entries are stored into the StringMap and simply linked 26 /// together through the second element of this pair in order to 27 /// keep track of insertion order. 28 typedef StringMap<std::pair<uint32_t, StringMapEntryBase *>, BumpPtrAllocator> 29 MapTy; 30 NonRelocatableStringpool()31 NonRelocatableStringpool() 32 : CurrentEndOffset(0), Sentinel(0), Last(&Sentinel) { 33 // Legacy dsymutil puts an empty string at the start of the line 34 // table. 35 getStringOffset(""); 36 } 37 38 /// \brief Get the offset of string \p S in the string table. This 39 /// can insert a new element or return the offset of a preexisitng 40 /// one. 41 uint32_t getStringOffset(StringRef S); 42 43 /// \brief Get permanent storage for \p S (but do not necessarily 44 /// emit \p S in the output section). 45 /// \returns The StringRef that points to permanent storage to use 46 /// in place of \p S. 47 StringRef internString(StringRef S); 48 49 // \brief Return the first entry of the string table. getFirstEntry()50 const MapTy::MapEntryTy *getFirstEntry() const { 51 return getNextEntry(&Sentinel); 52 } 53 54 // \brief Get the entry following \p E in the string table or null 55 // if \p E was the last entry. getNextEntry(const MapTy::MapEntryTy * E)56 const MapTy::MapEntryTy *getNextEntry(const MapTy::MapEntryTy *E) const { 57 return static_cast<const MapTy::MapEntryTy *>(E->getValue().second); 58 } 59 getSize()60 uint64_t getSize() { return CurrentEndOffset; } 61 62 private: 63 MapTy Strings; 64 uint32_t CurrentEndOffset; 65 MapTy::MapEntryTy Sentinel, *Last; 66 }; 67 } 68 } 69 70 #endif 71