Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame^] | 1 | //===- FileEntry.h ----------------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef LLVM_DEBUGINFO_GSYM_FILEENTRY_H |
| 11 | #define LLVM_DEBUGINFO_GSYM_FILEENTRY_H |
| 12 | |
| 13 | #include "llvm/ADT/DenseMapInfo.h" |
| 14 | #include "llvm/ADT/Hashing.h" |
| 15 | #include <functional> |
| 16 | #include <stdint.h> |
| 17 | #include <utility> |
| 18 | |
| 19 | namespace llvm { |
| 20 | namespace gsym { |
| 21 | |
| 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 | |
| 28 | /// Offsets in the string table. |
| 29 | /// @{ |
| 30 | uint32_t Dir = 0; |
| 31 | uint32_t Base = 0; |
| 32 | /// @} |
| 33 | |
| 34 | FileEntry() = default; |
| 35 | FileEntry(uint32_t D, uint32_t B) : Dir(D), Base(B) {} |
| 36 | |
| 37 | // Implement operator== so that FileEntry can be used as key in |
| 38 | // unordered containers. |
| 39 | bool operator==(const FileEntry &RHS) const { |
| 40 | return Base == RHS.Base && Dir == RHS.Dir; |
| 41 | }; |
| 42 | bool operator!=(const FileEntry &RHS) const { |
| 43 | return Base != RHS.Base || Dir != RHS.Dir; |
| 44 | }; |
| 45 | }; |
| 46 | |
| 47 | } // namespace gsym |
| 48 | |
| 49 | template <> struct DenseMapInfo<gsym::FileEntry> { |
| 50 | static inline gsym::FileEntry getEmptyKey() { |
| 51 | uint32_t key = DenseMapInfo<uint32_t>::getEmptyKey(); |
| 52 | return gsym::FileEntry(key, key); |
| 53 | } |
| 54 | static inline gsym::FileEntry getTombstoneKey() { |
| 55 | uint32_t key = DenseMapInfo<uint32_t>::getTombstoneKey(); |
| 56 | return gsym::FileEntry(key, key); |
| 57 | } |
| 58 | static unsigned getHashValue(const gsym::FileEntry &Val) { |
| 59 | return llvm::hash_combine(DenseMapInfo<uint32_t>::getHashValue(Val.Dir), |
| 60 | DenseMapInfo<uint32_t>::getHashValue(Val.Base)); |
| 61 | } |
| 62 | static bool isEqual(const gsym::FileEntry &LHS, const gsym::FileEntry &RHS) { |
| 63 | return LHS == RHS; |
| 64 | } |
| 65 | }; |
| 66 | |
| 67 | } // namespace llvm |
| 68 | #endif // #ifndef LLVM_DEBUGINFO_GSYM_FILEENTRY_H |