1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-20 19:42:54 +02:00
llvm-mirror/tools/dsymutil/NonRelocatableStringpool.cpp
Jonas Devlieghere 92b2118b05 [dsymutil] Move string pool into its own implementatino file. NFC.
The DwarfLinker implementation is already relatively large with over 4k
LOC. This commit moves the implementation of NonRelocatableStringpool
into a separate cpp file.

llvm-svn: 326425
2018-03-01 10:05:54 +00:00

52 lines
1.5 KiB
C++

//===- NonRelocatableStringpool.cpp - A simple stringpool ----------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "NonRelocatableStringpool.h"
namespace llvm {
namespace dsymutil {
DwarfStringPoolEntryRef NonRelocatableStringpool::getEntry(StringRef S) {
if (S.empty() && !Strings.empty())
return EmptyString;
auto I = Strings.insert({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);
}
StringRef NonRelocatableStringpool::internString(StringRef S) {
DwarfStringPoolEntry Entry{nullptr, 0, -1U};
auto InsertResult = Strings.insert({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;
}
} // namespace dsymutil
} // namespace llvm