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