blob: 8b1a7af17bbf3e6d1becfd653ac762dc33fb1fc6 [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===- llvm/CodeGen/DwarfStringPoolEntry.h - String pool entry --*- 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
10#ifndef LLVM_CODEGEN_DWARFSTRINGPOOLENTRY_H
11#define LLVM_CODEGEN_DWARFSTRINGPOOLENTRY_H
12
Andrew Scullcdfcccc2018-10-05 20:58:37 +010013#include "llvm/ADT/PointerIntPair.h"
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010014#include "llvm/ADT/StringMap.h"
15
16namespace llvm {
17
18class MCSymbol;
19
20/// Data for a string pool entry.
21struct DwarfStringPoolEntry {
Andrew Scullcdfcccc2018-10-05 20:58:37 +010022 static constexpr unsigned NotIndexed = -1;
23
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010024 MCSymbol *Symbol;
25 unsigned Offset;
26 unsigned Index;
Andrew Scullcdfcccc2018-10-05 20:58:37 +010027
28 bool isIndexed() const { return Index != NotIndexed; }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010029};
30
31/// String pool entry reference.
Andrew Scullcdfcccc2018-10-05 20:58:37 +010032class DwarfStringPoolEntryRef {
33 PointerIntPair<const StringMapEntry<DwarfStringPoolEntry> *, 1, bool>
34 MapEntryAndIndexed;
35
36 const StringMapEntry<DwarfStringPoolEntry> *getMapEntry() const {
37 return MapEntryAndIndexed.getPointer();
38 }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010039
40public:
41 DwarfStringPoolEntryRef() = default;
Andrew Scullcdfcccc2018-10-05 20:58:37 +010042 DwarfStringPoolEntryRef(const StringMapEntry<DwarfStringPoolEntry> &Entry,
43 bool Indexed)
44 : MapEntryAndIndexed(&Entry, Indexed) {}
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010045
Andrew Scullcdfcccc2018-10-05 20:58:37 +010046 explicit operator bool() const { return getMapEntry(); }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010047 MCSymbol *getSymbol() const {
Andrew Scullcdfcccc2018-10-05 20:58:37 +010048 assert(getMapEntry()->second.Symbol && "No symbol available!");
49 return getMapEntry()->second.Symbol;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010050 }
Andrew Scullcdfcccc2018-10-05 20:58:37 +010051 unsigned getOffset() const { return getMapEntry()->second.Offset; }
52 bool isIndexed() const { return MapEntryAndIndexed.getInt(); }
53 unsigned getIndex() const {
54 assert(isIndexed());
55 assert(getMapEntry()->getValue().isIndexed());
56 return getMapEntry()->second.Index;
57 }
58 StringRef getString() const { return getMapEntry()->first(); }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010059 /// Return the entire string pool entry for convenience.
Andrew Scullcdfcccc2018-10-05 20:58:37 +010060 DwarfStringPoolEntry getEntry() const { return getMapEntry()->getValue(); }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010061
Andrew Scullcdfcccc2018-10-05 20:58:37 +010062 bool operator==(const DwarfStringPoolEntryRef &X) const {
63 return getMapEntry() == X.getMapEntry();
64 }
65 bool operator!=(const DwarfStringPoolEntryRef &X) const {
66 return getMapEntry() != X.getMapEntry();
67 }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010068};
69
70} // end namespace llvm
71
72#endif