-DwarfStringPoolEntryRef NonRelocatableStringpool::getEntry(StringRef S) {
- if (S.empty() && !Strings.empty())
- return EmptyString;
-
- auto I = Strings.insert(std::make_pair(S, DwarfStringPoolEntry()));
- auto &Entry = I.first->second;
- if (I.second || Entry.Index == -1U) {
- Entry.Index = NumEntries++;
- Entry.Offset = CurrentEndOffset;
- Entry.Symbol = nullptr;
- CurrentEndOffset += S.size() + 1;
- }
- return DwarfStringPoolEntryRef(*I.first);
-}
-
-uint32_t NonRelocatableStringpool::getStringOffset(StringRef S) {
- return getEntry(S).getOffset();
-}
-
-/// Put \p S into the StringMap so that it gets permanent
-/// storage, but do not actually link it in the chain of elements
-/// that go into the output section. A latter call to
-/// getStringOffset() with the same string will chain it though.
-StringRef NonRelocatableStringpool::internString(StringRef S) {
- DwarfStringPoolEntry Entry{nullptr, 0, -1U};
- auto InsertResult = Strings.insert(std::make_pair(S, Entry));
- return InsertResult.first->getKey();
-}
-
-std::vector<DwarfStringPoolEntryRef>
-NonRelocatableStringpool::getEntries() const {
- std::vector<DwarfStringPoolEntryRef> Result;
- Result.reserve(Strings.size());
- for (const auto &E : Strings)
- Result.emplace_back(E);
- std::sort(
- Result.begin(), Result.end(),
- [](const DwarfStringPoolEntryRef A, const DwarfStringPoolEntryRef B) {
- return A.getIndex() < B.getIndex();
- });
- return Result;
-}
-