FileEntry.h 2.2 KB

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