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