1 //===- NonRelocatableStringpool.h - A simple stringpool --------*- C++ -*-===//
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 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_TOOLS_DSYMUTIL_NONRELOCATABLESTRINGPOOL_H
11 #define LLVM_TOOLS_DSYMUTIL_NONRELOCATABLESTRINGPOOL_H
13 #include "llvm/ADT/StringMap.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/Support/Allocator.h"
22 /// \brief A string table that doesn't need relocations.
24 /// We are doing a final link, no need for a string table that
25 /// has relocation entries for every reference to it. This class
26 /// provides this ablitity by just associating offsets with
28 class NonRelocatableStringpool
{
30 /// \brief Entries are stored into the StringMap and simply linked
31 /// together through the second element of this pair in order to
32 /// keep track of insertion order.
34 StringMap
<std::pair
<uint32_t, StringMapEntryBase
*>, BumpPtrAllocator
>;
36 NonRelocatableStringpool() : Sentinel(0), Last(&Sentinel
) {
37 // Legacy dsymutil puts an empty string at the start of the line
42 /// \brief Get the offset of string \p S in the string table. This
43 /// can insert a new element or return the offset of a preexisitng
45 uint32_t getStringOffset(StringRef S
);
47 /// \brief Get permanent storage for \p S (but do not necessarily
48 /// emit \p S in the output section).
49 /// \returns The StringRef that points to permanent storage to use
51 StringRef
internString(StringRef S
);
53 // \brief Return the first entry of the string table.
54 const MapTy::MapEntryTy
*getFirstEntry() const {
55 return getNextEntry(&Sentinel
);
58 // \brief Get the entry following \p E in the string table or null
59 // if \p E was the last entry.
60 const MapTy::MapEntryTy
*getNextEntry(const MapTy::MapEntryTy
*E
) const {
61 return static_cast<const MapTy::MapEntryTy
*>(E
->getValue().second
);
64 uint64_t getSize() { return CurrentEndOffset
; }
68 uint32_t CurrentEndOffset
= 0;
69 MapTy::MapEntryTy Sentinel
, *Last
;
72 } // end namespace dsymutil
73 } // end namespace llvm
75 #endif // LLVM_TOOLS_DSYMUTIL_NONRELOCATABLESTRINGPOOL_H