blob: 9db1f3342bd3f4f561fddf45f30fc99af7b1d244 [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
12namespace llvm {
13namespace dsymutil {
14
15/// \brief A string table that doesn't need relocations.
16///
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
20/// strings.
21class NonRelocatableStringpool {
22public:
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>
27 MapTy;
28
29 NonRelocatableStringpool()
30 : CurrentEndOffset(0), Sentinel(0), Last(&Sentinel) {
31 // Legacy dsymutil puts an empty string at the start of the line
32 // table.
33 getStringOffset("");
34 }
35
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
38 /// one.
39 uint32_t getStringOffset(StringRef S);
40
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
44 /// in place of \p S.
45 StringRef internString(StringRef S);
46
47 // \brief Return the first entry of the string table.
48 const MapTy::MapEntryTy *getFirstEntry() const {
49 return getNextEntry(&Sentinel);
50 }
51
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);
56 }
57
58 uint64_t getSize() { return CurrentEndOffset; }
59
60private:
61 MapTy Strings;
62 uint32_t CurrentEndOffset;
63 MapTy::MapEntryTy Sentinel, *Last;
64};
65}
66}
67
68#endif