blob: d943b79089d1f63452a3eeb33deaae1d4c5eee9c [file] [log] [blame]
Jonas Devliegherecaf26f22018-03-01 10:05:54 +00001//===- NonRelocatableStringpool.cpp - 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
10#include "NonRelocatableStringpool.h"
11
12namespace llvm {
13namespace dsymutil {
14
15DwarfStringPoolEntryRef NonRelocatableStringpool::getEntry(StringRef S) {
16 if (S.empty() && !Strings.empty())
17 return EmptyString;
18
19 auto I = Strings.insert({S, DwarfStringPoolEntry()});
20 auto &Entry = I.first->second;
21 if (I.second || Entry.Index == -1U) {
22 Entry.Index = NumEntries++;
23 Entry.Offset = CurrentEndOffset;
24 Entry.Symbol = nullptr;
25 CurrentEndOffset += S.size() + 1;
26 }
27 return DwarfStringPoolEntryRef(*I.first);
28}
29
30StringRef NonRelocatableStringpool::internString(StringRef S) {
31 DwarfStringPoolEntry Entry{nullptr, 0, -1U};
32 auto InsertResult = Strings.insert({S, Entry});
33 return InsertResult.first->getKey();
34}
35
36std::vector<DwarfStringPoolEntryRef>
37NonRelocatableStringpool::getEntries() const {
38 std::vector<DwarfStringPoolEntryRef> Result;
39 Result.reserve(Strings.size());
40 for (const auto &E : Strings)
41 Result.emplace_back(E);
42 std::sort(
43 Result.begin(), Result.end(),
44 [](const DwarfStringPoolEntryRef A, const DwarfStringPoolEntryRef B) {
45 return A.getIndex() < B.getIndex();
46 });
47 return Result;
48}
49
50} // namespace dsymutil
51} // namespace llvm