FileEntry.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //===- FileEntry.h ----------------------------------------------*- C++ -*-===//
  2. //
  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
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef LLVM_DEBUGINFO_GSYM_FILEENTRY_H
  9. #define LLVM_DEBUGINFO_GSYM_FILEENTRY_H
  10. #include "llvm/ADT/DenseMapInfo.h"
  11. #include "llvm/ADT/Hashing.h"
  12. #include <functional>
  13. #include <stdint.h>
  14. namespace llvm {
  15. namespace gsym {
  16. /// Files in GSYM are contained in FileEntry structs where we split the
  17. /// directory and basename into two different strings in the string
  18. /// table. This allows paths to shared commont directory and filename
  19. /// strings and saves space.
  20. struct FileEntry {
  21. /// Offsets in the string table.
  22. /// @{
  23. uint32_t Dir = 0;
  24. uint32_t Base = 0;
  25. /// @}
  26. FileEntry() = default;
  27. FileEntry(uint32_t D, uint32_t B) : Dir(D), Base(B) {}
  28. // Implement operator== so that FileEntry can be used as key in
  29. // unordered containers.
  30. bool operator==(const FileEntry &RHS) const {
  31. return Base == RHS.Base && Dir == RHS.Dir;
  32. };
  33. bool operator!=(const FileEntry &RHS) const {
  34. return Base != RHS.Base || Dir != RHS.Dir;
  35. };
  36. };
  37. } // namespace gsym
  38. template <> struct DenseMapInfo<gsym::FileEntry> {
  39. static inline gsym::FileEntry getEmptyKey() {
  40. uint32_t key = DenseMapInfo<uint32_t>::getEmptyKey();
  41. return gsym::FileEntry(key, key);
  42. }
  43. static inline gsym::FileEntry getTombstoneKey() {
  44. uint32_t key = DenseMapInfo<uint32_t>::getTombstoneKey();
  45. return gsym::FileEntry(key, key);
  46. }
  47. static unsigned getHashValue(const gsym::FileEntry &Val) {
  48. return llvm::hash_combine(DenseMapInfo<uint32_t>::getHashValue(Val.Dir),
  49. DenseMapInfo<uint32_t>::getHashValue(Val.Base));
  50. }
  51. static bool isEqual(const gsym::FileEntry &LHS, const gsym::FileEntry &RHS) {
  52. return LHS == RHS;
  53. }
  54. };
  55. } // namespace llvm
  56. #endif // LLVM_DEBUGINFO_GSYM_FILEENTRY_H