1 //===- NonRelocatableStringpool.cpp - A simple stringpool ----------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "NonRelocatableStringpool.h"
14 DwarfStringPoolEntryRef
NonRelocatableStringpool::getEntry(StringRef S
) {
15 if (S
.empty() && !Strings
.empty())
20 auto I
= Strings
.insert({S
, DwarfStringPoolEntry()});
21 auto &Entry
= I
.first
->second
;
22 if (I
.second
|| !Entry
.isIndexed()) {
23 Entry
.Index
= NumEntries
++;
24 Entry
.Offset
= CurrentEndOffset
;
25 Entry
.Symbol
= nullptr;
26 CurrentEndOffset
+= S
.size() + 1;
28 return DwarfStringPoolEntryRef(*I
.first
, true);
31 StringRef
NonRelocatableStringpool::internString(StringRef S
) {
32 DwarfStringPoolEntry Entry
{nullptr, 0, DwarfStringPoolEntry::NotIndexed
};
37 auto InsertResult
= Strings
.insert({S
, Entry
});
38 return InsertResult
.first
->getKey();
41 std::vector
<DwarfStringPoolEntryRef
>
42 NonRelocatableStringpool::getEntriesForEmission() const {
43 std::vector
<DwarfStringPoolEntryRef
> Result
;
44 Result
.reserve(Strings
.size());
45 for (const auto &E
: Strings
)
46 if (E
.getValue().isIndexed())
47 Result
.emplace_back(E
, true);
48 llvm::sort(Result
, [](const DwarfStringPoolEntryRef A
,
49 const DwarfStringPoolEntryRef B
) {
50 return A
.getIndex() < B
.getIndex();
55 } // namespace dsymutil