DwarfStringPool.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //===- llvm/CodeGen/DwarfStringPool.h - Dwarf Debug Framework ---*- 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-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFSTRINGPOOL_H
  9. #define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFSTRINGPOOL_H
  10. #include "llvm/ADT/StringMap.h"
  11. #include "llvm/ADT/StringRef.h"
  12. #include "llvm/CodeGen/DwarfStringPoolEntry.h"
  13. #include "llvm/Support/Allocator.h"
  14. namespace llvm {
  15. class AsmPrinter;
  16. class MCSection;
  17. class MCSymbol;
  18. // Collection of strings for this unit and assorted symbols.
  19. // A String->Symbol mapping of strings used by indirect
  20. // references.
  21. class DwarfStringPool {
  22. using EntryTy = DwarfStringPoolEntry;
  23. StringMap<EntryTy, BumpPtrAllocator &> Pool;
  24. StringRef Prefix;
  25. uint64_t NumBytes = 0;
  26. unsigned NumIndexedStrings = 0;
  27. bool ShouldCreateSymbols;
  28. StringMapEntry<EntryTy> &getEntryImpl(AsmPrinter &Asm, StringRef Str);
  29. public:
  30. using EntryRef = DwarfStringPoolEntryRef;
  31. DwarfStringPool(BumpPtrAllocator &A, AsmPrinter &Asm, StringRef Prefix);
  32. void emitStringOffsetsTableHeader(AsmPrinter &Asm, MCSection *OffsetSection,
  33. MCSymbol *StartSym);
  34. void emit(AsmPrinter &Asm, MCSection *StrSection,
  35. MCSection *OffsetSection = nullptr,
  36. bool UseRelativeOffsets = false);
  37. bool empty() const { return Pool.empty(); }
  38. unsigned size() const { return Pool.size(); }
  39. unsigned getNumIndexedStrings() const { return NumIndexedStrings; }
  40. /// Get a reference to an entry in the string pool.
  41. EntryRef getEntry(AsmPrinter &Asm, StringRef Str);
  42. /// Same as getEntry, except that you can use EntryRef::getIndex to obtain a
  43. /// unique ID of this entry (e.g., for use in indexed forms like
  44. /// DW_FORM_strx).
  45. EntryRef getIndexedEntry(AsmPrinter &Asm, StringRef Str);
  46. };
  47. } // end namespace llvm
  48. #endif // LLVM_LIB_CODEGEN_ASMPRINTER_DWARFSTRINGPOOL_H