1 //===- 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 12 namespace llvm { 13 namespace dsymutil { 14 15 DwarfStringPoolEntryRef 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 30 StringRef NonRelocatableStringpool::internString(StringRef S) { 31 DwarfStringPoolEntry Entry{nullptr, 0, -1U}; 32 auto InsertResult = Strings.insert({S, Entry}); 33 return InsertResult.first->getKey(); 34 } 35 36 std::vector<DwarfStringPoolEntryRef> 37 NonRelocatableStringpool::getEntries() const { 38 std::vector<DwarfStringPoolEntryRef> Result; 39 Result.reserve(Strings.size()); 40 for (const auto &E : Strings) 41 Result.emplace_back(E); 42 llvm::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 52