[llvm] r326425 - [dsymutil] Move string pool into its own implementatino file. NFC.
Jonas Devlieghere via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 1 02:05:54 PST 2018
Author: jdevlieghere
Date: Thu Mar 1 02:05:54 2018
New Revision: 326425
URL: http://llvm.org/viewvc/llvm-project?rev=326425&view=rev
Log:
[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.
Added:
llvm/trunk/tools/dsymutil/NonRelocatableStringpool.cpp
Modified:
llvm/trunk/tools/dsymutil/CMakeLists.txt
llvm/trunk/tools/dsymutil/DwarfLinker.cpp
llvm/trunk/tools/dsymutil/NonRelocatableStringpool.h
Modified: llvm/trunk/tools/dsymutil/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/CMakeLists.txt?rev=326425&r1=326424&r2=326425&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/CMakeLists.txt (original)
+++ llvm/trunk/tools/dsymutil/CMakeLists.txt Thu Mar 1 02:05:54 2018
@@ -16,6 +16,7 @@ add_llvm_tool(llvm-dsymutil
DwarfLinker.cpp
MachODebugMapParser.cpp
MachOUtils.cpp
+ NonRelocatableStringpool.cpp
DEPENDS
intrinsics_gen
Modified: llvm/trunk/tools/dsymutil/DwarfLinker.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/DwarfLinker.cpp?rev=326425&r1=326424&r2=326425&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/DwarfLinker.cpp (original)
+++ llvm/trunk/tools/dsymutil/DwarfLinker.cpp Thu Mar 1 02:05:54 2018
@@ -4137,49 +4137,6 @@ bool DwarfLinker::link(const DebugMap &M
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<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;
-}
-
void warn(const Twine &Warning, const Twine &Context) {
errs() << Twine("while processing ") + Context + ":\n";
errs() << Twine("warning: ") + Warning + "\n";
Added: llvm/trunk/tools/dsymutil/NonRelocatableStringpool.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/NonRelocatableStringpool.cpp?rev=326425&view=auto
==============================================================================
--- llvm/trunk/tools/dsymutil/NonRelocatableStringpool.cpp (added)
+++ llvm/trunk/tools/dsymutil/NonRelocatableStringpool.cpp Thu Mar 1 02:05:54 2018
@@ -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<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
Modified: llvm/trunk/tools/dsymutil/NonRelocatableStringpool.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/NonRelocatableStringpool.h?rev=326425&r1=326424&r2=326425&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/NonRelocatableStringpool.h (original)
+++ llvm/trunk/tools/dsymutil/NonRelocatableStringpool.h Thu Mar 1 02:05:54 2018
@@ -15,7 +15,7 @@
#include "llvm/CodeGen/DwarfStringPoolEntry.h"
#include "llvm/Support/Allocator.h"
#include <cstdint>
-#include <utility>
+#include <vector>
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);
More information about the llvm-commits
mailing list