blob: ba0d595c14092c58969d1e5bc82c673210e72f4f [file] [log] [blame]
David Blaikiedaefdbf2014-04-25 21:34:35 +00001//===-- 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 Kramera7c40ef2014-08-13 16:26:38 +000010#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFSTRINGPOOL_H
11#define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFSTRINGPOOL_H
David Blaikiedaefdbf2014-04-25 21:34:35 +000012
13#include "llvm/ADT/StringMap.h"
14#include "llvm/CodeGen/AsmPrinter.h"
15#include "llvm/Support/Allocator.h"
David Blaikiedaefdbf2014-04-25 21:34:35 +000016#include <utility>
17
18namespace llvm {
19
20class MCSymbol;
21class MCSection;
22class StringRef;
23
24// Collection of strings for this unit and assorted symbols.
25// A String->Symbol mapping of strings used by indirect
26// references.
27class DwarfStringPool {
28 StringMap<std::pair<MCSymbol *, unsigned>, BumpPtrAllocator &> Pool;
29 StringRef Prefix;
David Blaikiedaefdbf2014-04-25 21:34:35 +000030
31public:
32 DwarfStringPool(BumpPtrAllocator &A, AsmPrinter &Asm, StringRef Prefix)
David Blaikie6741bb02014-09-11 21:12:48 +000033 : Pool(A), Prefix(Prefix) {}
David Blaikiedaefdbf2014-04-25 21:34:35 +000034
Rafael Espindola0709a7b2015-05-21 19:20:38 +000035 void emit(AsmPrinter &Asm, MCSection *StrSection,
36 MCSection *OffsetSection = nullptr);
David Blaikiedaefdbf2014-04-25 21:34:35 +000037
38 /// \brief Returns an entry into the string pool with the given
39 /// string text.
Duncan P. N. Exon Smith8c6499f2015-05-24 16:06:08 +000040 MCSymbol *getSymbol(AsmPrinter &Asm, StringRef Str) {
41 return getEntry(Asm, Str).first;
42 }
David Blaikiedaefdbf2014-04-25 21:34:35 +000043
44 /// \brief Returns the index into the string pool with the given
45 /// string text.
Duncan P. N. Exon Smith8c6499f2015-05-24 16:06:08 +000046 unsigned getIndex(AsmPrinter &Asm, StringRef Str) {
47 return getEntry(Asm, Str).second;
48 }
David Blaikiedaefdbf2014-04-25 21:34:35 +000049
50 bool empty() const { return Pool.empty(); }
Duncan P. N. Exon Smith8c6499f2015-05-24 16:06:08 +000051
52private:
53 std::pair<MCSymbol *, unsigned> &getEntry(AsmPrinter &Asm, StringRef Str);
David Blaikiedaefdbf2014-04-25 21:34:35 +000054};
55}
56#endif