46 lines · cpp
1//===-- NonRelocatableStringpool.cpp --------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "llvm/CodeGen/NonRelocatableStringpool.h"10#include "llvm/ADT/STLExtras.h"11 12using namespace llvm;13 14DwarfStringPoolEntryRef NonRelocatableStringpool::getEntry(StringRef S) {15 auto I = Strings.try_emplace(S);16 auto &Entry = I.first->second;17 if (I.second || !Entry.isIndexed()) {18 Entry.Index = NumEntries++;19 Entry.Offset = CurrentEndOffset;20 Entry.Symbol = nullptr;21 CurrentEndOffset += S.size() + 1;22 }23 return DwarfStringPoolEntryRef(*I.first);24}25 26StringRef NonRelocatableStringpool::internString(StringRef S) {27 DwarfStringPoolEntry Entry{nullptr, 0, DwarfStringPoolEntry::NotIndexed};28 29 auto InsertResult = Strings.insert({S, Entry});30 return InsertResult.first->getKey();31}32 33std::vector<DwarfStringPoolEntryRef>34NonRelocatableStringpool::getEntriesForEmission() const {35 std::vector<DwarfStringPoolEntryRef> Result;36 Result.reserve(Strings.size());37 for (const auto &E : Strings)38 if (E.getValue().isIndexed())39 Result.emplace_back(E);40 llvm::sort(Result, [](const DwarfStringPoolEntryRef A,41 const DwarfStringPoolEntryRef B) {42 return A.getIndex() < B.getIndex();43 });44 return Result;45}46