[PowerPC] Convert r+r instructions to r+i (pre and post RA)
[llvm-core.git] / tools / dsymutil / NonRelocatableStringpool.h
blobaa21d77ad4388389c8b75d35ad3962fef6f28967
1 //===- NonRelocatableStringpool.h - A simple stringpool --------*- C++ -*-===//
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 //===----------------------------------------------------------------------===//
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"
16 #include <cstdint>
17 #include <utility>
19 namespace llvm {
20 namespace dsymutil {
22 /// \brief A string table that doesn't need relocations.
23 ///
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
27 /// strings.
28 class NonRelocatableStringpool {
29 public:
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.
33 using MapTy =
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
38 // table.
39 getStringOffset("");
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
44 /// one.
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
50 /// in place of \p S.
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; }
66 private:
67 MapTy Strings;
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