DwarfStringPoolEntry.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- llvm/CodeGen/DwarfStringPoolEntry.h - String pool entry --*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_CODEGEN_DWARFSTRINGPOOLENTRY_H
  14. #define LLVM_CODEGEN_DWARFSTRINGPOOLENTRY_H
  15. #include "llvm/ADT/PointerIntPair.h"
  16. #include "llvm/ADT/StringMap.h"
  17. namespace llvm {
  18. class MCSymbol;
  19. /// Data for a string pool entry.
  20. struct DwarfStringPoolEntry {
  21. static constexpr unsigned NotIndexed = -1;
  22. MCSymbol *Symbol;
  23. uint64_t Offset;
  24. unsigned Index;
  25. bool isIndexed() const { return Index != NotIndexed; }
  26. };
  27. /// String pool entry reference.
  28. class DwarfStringPoolEntryRef {
  29. PointerIntPair<const StringMapEntry<DwarfStringPoolEntry> *, 1, bool>
  30. MapEntryAndIndexed;
  31. const StringMapEntry<DwarfStringPoolEntry> *getMapEntry() const {
  32. return MapEntryAndIndexed.getPointer();
  33. }
  34. public:
  35. DwarfStringPoolEntryRef() = default;
  36. DwarfStringPoolEntryRef(const StringMapEntry<DwarfStringPoolEntry> &Entry,
  37. bool Indexed)
  38. : MapEntryAndIndexed(&Entry, Indexed) {}
  39. explicit operator bool() const { return getMapEntry(); }
  40. MCSymbol *getSymbol() const {
  41. assert(getMapEntry()->second.Symbol && "No symbol available!");
  42. return getMapEntry()->second.Symbol;
  43. }
  44. uint64_t getOffset() const { return getMapEntry()->second.Offset; }
  45. bool isIndexed() const { return MapEntryAndIndexed.getInt(); }
  46. unsigned getIndex() const {
  47. assert(isIndexed());
  48. assert(getMapEntry()->getValue().isIndexed());
  49. return getMapEntry()->second.Index;
  50. }
  51. StringRef getString() const { return getMapEntry()->first(); }
  52. /// Return the entire string pool entry for convenience.
  53. DwarfStringPoolEntry getEntry() const { return getMapEntry()->getValue(); }
  54. bool operator==(const DwarfStringPoolEntryRef &X) const {
  55. return getMapEntry() == X.getMapEntry();
  56. }
  57. bool operator!=(const DwarfStringPoolEntryRef &X) const {
  58. return getMapEntry() != X.getMapEntry();
  59. }
  60. };
  61. } // end namespace llvm
  62. #endif
  63. #ifdef __GNUC__
  64. #pragma GCC diagnostic pop
  65. #endif