FileEntry.h 2.2 KB

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