blob: fffd02084e34470f8f2cf9f98b0ba5a08a6e1832 [file] [log] [blame]
Frederic Riss30711fb2015-08-26 05:09:52 +00001//===-- 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
Benjamin Kramer391be792016-01-27 19:29:56 +000012#include "llvm/ADT/StringMap.h"
13
Frederic Riss30711fb2015-08-26 05:09:52 +000014namespace llvm {
15namespace 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.
23class NonRelocatableStringpool {
24public:
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
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.
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.
56 const MapTy::MapEntryTy *getNextEntry(const MapTy::MapEntryTy *E) const {
57 return static_cast<const MapTy::MapEntryTy *>(E->getValue().second);
58 }
59
60 uint64_t getSize() { return CurrentEndOffset; }
61
62private:
63 MapTy Strings;
64 uint32_t CurrentEndOffset;
65 MapTy::MapEntryTy Sentinel, *Last;
66};
67}
68}
69
70#endif