blob: d82ff84589d4b6bdacf2a50d67c8a661c2dbf53d [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;
Pavel Labath2f088112018-08-07 09:54:52 +000021 if (I.second || !Entry.isIndexed()) {
Jonas Devliegherecaf26f22018-03-01 10:05:54 +000022 Entry.Index = NumEntries++;
23 Entry.Offset = CurrentEndOffset;
24 Entry.Symbol = nullptr;
25 CurrentEndOffset += S.size() + 1;
26 }
Pavel Labath2f088112018-08-07 09:54:52 +000027 return DwarfStringPoolEntryRef(*I.first, true);
Jonas Devliegherecaf26f22018-03-01 10:05:54 +000028}
29
30StringRef NonRelocatableStringpool::internString(StringRef S) {
Pavel Labath2f088112018-08-07 09:54:52 +000031 DwarfStringPoolEntry Entry{nullptr, 0, DwarfStringPoolEntry::NotIndexed};
Jonas Devliegherecaf26f22018-03-01 10:05:54 +000032 auto InsertResult = Strings.insert({S, Entry});
33 return InsertResult.first->getKey();
34}
35
36std::vector<DwarfStringPoolEntryRef>
Pavel Labath2f088112018-08-07 09:54:52 +000037NonRelocatableStringpool::getEntriesForEmission() const {
Jonas Devliegherecaf26f22018-03-01 10:05:54 +000038 std::vector<DwarfStringPoolEntryRef> Result;
39 Result.reserve(Strings.size());
40 for (const auto &E : Strings)
Pavel Labath2f088112018-08-07 09:54:52 +000041 if (E.getValue().isIndexed())
42 Result.emplace_back(E, true);
Fangrui Song3507c6e2018-09-30 22:31:29 +000043 llvm::sort(Result, [](const DwarfStringPoolEntryRef A,
44 const DwarfStringPoolEntryRef B) {
45 return A.getIndex() < B.getIndex();
46 });
Jonas Devliegherecaf26f22018-03-01 10:05:54 +000047 return Result;
48}
49
50} // namespace dsymutil
51} // namespace llvm