brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.6 KiB · 8ccb4a5 Raw
75 lines · c
1//===- StringEntryToDwarfStringPoolEntryMap.h -------------------*- C++ -*-===//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#ifndef LLVM_LIB_DWARFLINKER_PARALLEL_STRINGENTRYTODWARFSTRINGPOOLENTRYMAP_H10#define LLVM_LIB_DWARFLINKER_PARALLEL_STRINGENTRYTODWARFSTRINGPOOLENTRYMAP_H11 12#include "DWARFLinkerGlobalData.h"13#include "llvm/ADT/SmallVector.h"14#include "llvm/DWARFLinker/StringPool.h"15 16namespace llvm {17namespace dwarf_linker {18namespace parallel {19 20/// This class creates a DwarfStringPoolEntry for the corresponding StringEntry.21class StringEntryToDwarfStringPoolEntryMap {22public:23  StringEntryToDwarfStringPoolEntryMap(LinkingGlobalData &GlobalData)24      : GlobalData(GlobalData) {}25  ~StringEntryToDwarfStringPoolEntryMap() = default;26 27  /// Create DwarfStringPoolEntry for specified StringEntry if necessary.28  /// Initialize DwarfStringPoolEntry with initial values.29  DwarfStringPoolEntryWithExtString *add(const StringEntry *String) {30    DwarfStringPoolEntriesTy::iterator it = DwarfStringPoolEntries.find(String);31 32    if (it == DwarfStringPoolEntries.end()) {33      DwarfStringPoolEntryWithExtString *DataPtr =34          GlobalData.getAllocator()35              .Allocate<DwarfStringPoolEntryWithExtString>();36      DataPtr->String = String->getKey();37      DataPtr->Index = DwarfStringPoolEntry::NotIndexed;38      DataPtr->Offset = 0;39      DataPtr->Symbol = nullptr;40      it = DwarfStringPoolEntries.insert(std::make_pair(String, DataPtr)).first;41    }42 43    assert(it->second != nullptr);44    return it->second;45  }46 47  /// Returns already existed DwarfStringPoolEntry for the specified48  /// StringEntry.49  DwarfStringPoolEntryWithExtString *50  getExistingEntry(const StringEntry *String) const {51    DwarfStringPoolEntriesTy::const_iterator it =52        DwarfStringPoolEntries.find(String);53 54    assert(it != DwarfStringPoolEntries.end());55    assert(it->second != nullptr);56    return it->second;57  }58 59  /// Erase contents of StringsForEmission.60  void clear() { DwarfStringPoolEntries.clear(); }61 62protected:63  using DwarfStringPoolEntriesTy =64      DenseMap<const StringEntry *, DwarfStringPoolEntryWithExtString *>;65  DwarfStringPoolEntriesTy DwarfStringPoolEntries;66 67  LinkingGlobalData &GlobalData;68};69 70} // end of namespace parallel71} // end of namespace dwarf_linker72} // end of namespace llvm73 74#endif // LLVM_LIB_DWARFLINKER_PARALLEL_STRINGENTRYTODWARFSTRINGPOOLENTRYMAP_H75