David Blaikie | daefdbf | 2014-04-25 21:34:35 +0000 | [diff] [blame] | 1 | //===-- llvm/CodeGen/DwarfStringPool.h - Dwarf Debug Framework -*- C++ -*--===// |
| 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 | |
Benjamin Kramer | a7c40ef | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 10 | #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFSTRINGPOOL_H |
| 11 | #define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFSTRINGPOOL_H |
David Blaikie | daefdbf | 2014-04-25 21:34:35 +0000 | [diff] [blame] | 12 | |
| 13 | #include "llvm/ADT/StringMap.h" |
| 14 | #include "llvm/CodeGen/AsmPrinter.h" |
| 15 | #include "llvm/Support/Allocator.h" |
David Blaikie | daefdbf | 2014-04-25 21:34:35 +0000 | [diff] [blame] | 16 | #include <utility> |
| 17 | |
| 18 | namespace llvm { |
| 19 | |
| 20 | class MCSymbol; |
| 21 | class MCSection; |
| 22 | class StringRef; |
| 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 | StringMap<std::pair<MCSymbol *, unsigned>, BumpPtrAllocator &> Pool; |
| 29 | StringRef Prefix; |
David Blaikie | daefdbf | 2014-04-25 21:34:35 +0000 | [diff] [blame] | 30 | |
| 31 | public: |
| 32 | DwarfStringPool(BumpPtrAllocator &A, AsmPrinter &Asm, StringRef Prefix) |
David Blaikie | 6741bb0 | 2014-09-11 21:12:48 +0000 | [diff] [blame] | 33 | : Pool(A), Prefix(Prefix) {} |
David Blaikie | daefdbf | 2014-04-25 21:34:35 +0000 | [diff] [blame] | 34 | |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 35 | void emit(AsmPrinter &Asm, MCSection *StrSection, |
| 36 | MCSection *OffsetSection = nullptr); |
David Blaikie | daefdbf | 2014-04-25 21:34:35 +0000 | [diff] [blame] | 37 | |
| 38 | /// \brief Returns an entry into the string pool with the given |
| 39 | /// string text. |
Duncan P. N. Exon Smith | 8c6499f | 2015-05-24 16:06:08 +0000 | [diff] [blame^] | 40 | MCSymbol *getSymbol(AsmPrinter &Asm, StringRef Str) { |
| 41 | return getEntry(Asm, Str).first; |
| 42 | } |
David Blaikie | daefdbf | 2014-04-25 21:34:35 +0000 | [diff] [blame] | 43 | |
| 44 | /// \brief Returns the index into the string pool with the given |
| 45 | /// string text. |
Duncan P. N. Exon Smith | 8c6499f | 2015-05-24 16:06:08 +0000 | [diff] [blame^] | 46 | unsigned getIndex(AsmPrinter &Asm, StringRef Str) { |
| 47 | return getEntry(Asm, Str).second; |
| 48 | } |
David Blaikie | daefdbf | 2014-04-25 21:34:35 +0000 | [diff] [blame] | 49 | |
| 50 | bool empty() const { return Pool.empty(); } |
Duncan P. N. Exon Smith | 8c6499f | 2015-05-24 16:06:08 +0000 | [diff] [blame^] | 51 | |
| 52 | private: |
| 53 | std::pair<MCSymbol *, unsigned> &getEntry(AsmPrinter &Asm, StringRef Str); |
David Blaikie | daefdbf | 2014-04-25 21:34:35 +0000 | [diff] [blame] | 54 | }; |
| 55 | } |
| 56 | #endif |