From: Jonas Devlieghere Date: Thu, 1 Mar 2018 10:05:54 +0000 (+0000) Subject: [dsymutil] Move string pool into its own implementatino file. NFC. X-Git-Tag: android-x86-7.1-r4~4400 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;ds=sidebyside;h=e993fb5d704ad113a3c63c303e42c87c13d091fb;p=android-x86%2Fexternal-llvm.git [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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@326425 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/tools/dsymutil/CMakeLists.txt b/tools/dsymutil/CMakeLists.txt index d002afb3dea..a5783f5a67e 100644 --- a/tools/dsymutil/CMakeLists.txt +++ b/tools/dsymutil/CMakeLists.txt @@ -16,6 +16,7 @@ add_llvm_tool(llvm-dsymutil DwarfLinker.cpp MachODebugMapParser.cpp MachOUtils.cpp + NonRelocatableStringpool.cpp DEPENDS intrinsics_gen diff --git a/tools/dsymutil/DwarfLinker.cpp b/tools/dsymutil/DwarfLinker.cpp index e35e17c9c02..6acf305d3c6 100644 --- a/tools/dsymutil/DwarfLinker.cpp +++ b/tools/dsymutil/DwarfLinker.cpp @@ -4137,49 +4137,6 @@ bool DwarfLinker::link(const DebugMap &Map) { return Options.NoOutput ? true : Streamer->finish(Map); } -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 -NonRelocatableStringpool::getEntries() const { - std::vector 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; -} - void warn(const Twine &Warning, const Twine &Context) { errs() << Twine("while processing ") + Context + ":\n"; errs() << Twine("warning: ") + Warning + "\n"; diff --git a/tools/dsymutil/NonRelocatableStringpool.cpp b/tools/dsymutil/NonRelocatableStringpool.cpp new file mode 100644 index 00000000000..d943b79089d --- /dev/null +++ b/tools/dsymutil/NonRelocatableStringpool.cpp @@ -0,0 +1,51 @@ +//===- 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 +NonRelocatableStringpool::getEntries() const { + std::vector 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 diff --git a/tools/dsymutil/NonRelocatableStringpool.h b/tools/dsymutil/NonRelocatableStringpool.h index d9161e67c01..b06b79b1dbf 100644 --- a/tools/dsymutil/NonRelocatableStringpool.h +++ b/tools/dsymutil/NonRelocatableStringpool.h @@ -15,7 +15,7 @@ #include "llvm/CodeGen/DwarfStringPoolEntry.h" #include "llvm/Support/Allocator.h" #include -#include +#include namespace llvm { namespace dsymutil { @@ -41,10 +41,12 @@ public: /// Get the offset of string \p S in the string table. This can insert a new /// element or return the offset of a pre-existing one. - uint32_t getStringOffset(StringRef S); + uint32_t getStringOffset(StringRef S) { return getEntry(S).getOffset(); } /// Get permanent storage for \p S (but do not necessarily emit \p S in the - /// output section). + /// output section). A latter call to getStringOffset() with the same string + /// will chain it though. + /// /// \returns The StringRef that points to permanent storage to use /// in place of \p S. StringRef internString(StringRef S);