1 //===- llvm/CodeGen/DwarfStringPoolEntry.h - String pool entry --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_CODEGEN_DWARFSTRINGPOOLENTRY_H
11 #define LLVM_CODEGEN_DWARFSTRINGPOOLENTRY_H
13 #include "llvm/ADT/PointerIntPair.h"
14 #include "llvm/ADT/StringMap.h"
20 /// Data for a string pool entry.
21 struct DwarfStringPoolEntry {
22 static constexpr unsigned NotIndexed = -1;
28 bool isIndexed() const { return Index != NotIndexed; }
31 /// String pool entry reference.
32 class DwarfStringPoolEntryRef {
33 PointerIntPair<const StringMapEntry<DwarfStringPoolEntry> *, 1, bool>
36 const StringMapEntry<DwarfStringPoolEntry> *getMapEntry() const {
37 return MapEntryAndIndexed.getPointer();
41 DwarfStringPoolEntryRef() = default;
42 DwarfStringPoolEntryRef(const StringMapEntry<DwarfStringPoolEntry> &Entry,
44 : MapEntryAndIndexed(&Entry, Indexed) {}
46 explicit operator bool() const { return getMapEntry(); }
47 MCSymbol *getSymbol() const {
48 assert(getMapEntry()->second.Symbol && "No symbol available!");
49 return getMapEntry()->second.Symbol;
51 unsigned getOffset() const { return getMapEntry()->second.Offset; }
52 bool isIndexed() const { return MapEntryAndIndexed.getInt(); }
53 unsigned getIndex() const {
55 assert(getMapEntry()->getValue().isIndexed());
56 return getMapEntry()->second.Index;
58 StringRef getString() const { return getMapEntry()->first(); }
59 /// Return the entire string pool entry for convenience.
60 DwarfStringPoolEntry getEntry() const { return getMapEntry()->getValue(); }
62 bool operator==(const DwarfStringPoolEntryRef &X) const {
63 return getMapEntry() == X.getMapEntry();
65 bool operator!=(const DwarfStringPoolEntryRef &X) const {
66 return getMapEntry() != X.getMapEntry();
70 } // end namespace llvm