Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 1 | //===- llvm/CodeGen/DwarfStringPoolEntry.h - String pool entry --*- C++ -*-===// |
| 2 | // |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 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 |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef LLVM_CODEGEN_DWARFSTRINGPOOLENTRY_H |
| 10 | #define LLVM_CODEGEN_DWARFSTRINGPOOLENTRY_H |
| 11 | |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 12 | #include "llvm/ADT/PointerIntPair.h" |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 13 | #include "llvm/ADT/StringMap.h" |
| 14 | |
| 15 | namespace llvm { |
| 16 | |
| 17 | class MCSymbol; |
| 18 | |
| 19 | /// Data for a string pool entry. |
| 20 | struct DwarfStringPoolEntry { |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 21 | static constexpr unsigned NotIndexed = -1; |
| 22 | |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 23 | MCSymbol *Symbol; |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 24 | uint64_t Offset; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 25 | unsigned Index; |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 26 | |
| 27 | bool isIndexed() const { return Index != NotIndexed; } |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 28 | }; |
| 29 | |
| 30 | /// String pool entry reference. |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 31 | class DwarfStringPoolEntryRef { |
| 32 | PointerIntPair<const StringMapEntry<DwarfStringPoolEntry> *, 1, bool> |
| 33 | MapEntryAndIndexed; |
| 34 | |
| 35 | const StringMapEntry<DwarfStringPoolEntry> *getMapEntry() const { |
| 36 | return MapEntryAndIndexed.getPointer(); |
| 37 | } |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 38 | |
| 39 | public: |
| 40 | DwarfStringPoolEntryRef() = default; |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 41 | DwarfStringPoolEntryRef(const StringMapEntry<DwarfStringPoolEntry> &Entry, |
| 42 | bool Indexed) |
| 43 | : MapEntryAndIndexed(&Entry, Indexed) {} |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 44 | |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 45 | explicit operator bool() const { return getMapEntry(); } |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 46 | MCSymbol *getSymbol() const { |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 47 | assert(getMapEntry()->second.Symbol && "No symbol available!"); |
| 48 | return getMapEntry()->second.Symbol; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 49 | } |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 50 | uint64_t getOffset() const { return getMapEntry()->second.Offset; } |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 51 | bool isIndexed() const { return MapEntryAndIndexed.getInt(); } |
| 52 | unsigned getIndex() const { |
| 53 | assert(isIndexed()); |
| 54 | assert(getMapEntry()->getValue().isIndexed()); |
| 55 | return getMapEntry()->second.Index; |
| 56 | } |
| 57 | StringRef getString() const { return getMapEntry()->first(); } |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 58 | /// Return the entire string pool entry for convenience. |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 59 | DwarfStringPoolEntry getEntry() const { return getMapEntry()->getValue(); } |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 60 | |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 61 | bool operator==(const DwarfStringPoolEntryRef &X) const { |
| 62 | return getMapEntry() == X.getMapEntry(); |
| 63 | } |
| 64 | bool operator!=(const DwarfStringPoolEntryRef &X) const { |
| 65 | return getMapEntry() != X.getMapEntry(); |
| 66 | } |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | } // end namespace llvm |
| 70 | |
| 71 | #endif |