blob: 49e7fc9c429184a3be03c7b0ad2424fb241dae8c [file] [log] [blame]
Andrew Walbran3d2c1972020-04-07 12:24:26 +01001//===- FileEntry.h ----------------------------------------------*- C++ -*-===//
2//
Olivier Deprezf4ef2d02021-04-20 13:36:24 +02003// 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
Andrew Walbran3d2c1972020-04-07 12:24:26 +01006//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_DEBUGINFO_GSYM_FILEENTRY_H
10#define LLVM_DEBUGINFO_GSYM_FILEENTRY_H
11
12#include "llvm/ADT/DenseMapInfo.h"
13#include "llvm/ADT/Hashing.h"
14#include <functional>
15#include <stdint.h>
16#include <utility>
17
18namespace llvm {
19namespace gsym {
20
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.
25struct FileEntry {
26
27 /// Offsets in the string table.
28 /// @{
29 uint32_t Dir = 0;
30 uint32_t Base = 0;
31 /// @}
32
33 FileEntry() = default;
34 FileEntry(uint32_t D, uint32_t B) : Dir(D), Base(B) {}
35
36 // Implement operator== so that FileEntry can be used as key in
37 // unordered containers.
38 bool operator==(const FileEntry &RHS) const {
39 return Base == RHS.Base && Dir == RHS.Dir;
40 };
41 bool operator!=(const FileEntry &RHS) const {
42 return Base != RHS.Base || Dir != RHS.Dir;
43 };
44};
45
46} // namespace gsym
47
48template <> struct DenseMapInfo<gsym::FileEntry> {
49 static inline gsym::FileEntry getEmptyKey() {
50 uint32_t key = DenseMapInfo<uint32_t>::getEmptyKey();
51 return gsym::FileEntry(key, key);
52 }
53 static inline gsym::FileEntry getTombstoneKey() {
54 uint32_t key = DenseMapInfo<uint32_t>::getTombstoneKey();
55 return gsym::FileEntry(key, key);
56 }
57 static unsigned getHashValue(const gsym::FileEntry &Val) {
58 return llvm::hash_combine(DenseMapInfo<uint32_t>::getHashValue(Val.Dir),
59 DenseMapInfo<uint32_t>::getHashValue(Val.Base));
60 }
61 static bool isEqual(const gsym::FileEntry &LHS, const gsym::FileEntry &RHS) {
62 return LHS == RHS;
63 }
64};
65
66} // namespace llvm
67#endif // #ifndef LLVM_DEBUGINFO_GSYM_FILEENTRY_H