xref: /freebsd/contrib/llvm-project/llvm/include/llvm/DebugInfo/PDB/Native/TpiHashing.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
1 //===- TpiHashing.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 
9 #ifndef LLVM_DEBUGINFO_PDB_NATIVE_TPIHASHING_H
10 #define LLVM_DEBUGINFO_PDB_NATIVE_TPIHASHING_H
11 
12 #include "llvm/DebugInfo/CodeView/TypeRecord.h"
13 #include "llvm/Support/Compiler.h"
14 #include "llvm/Support/Error.h"
15 
16 namespace llvm {
17 namespace pdb {
18 
19 LLVM_ABI Expected<uint32_t> hashTypeRecord(const llvm::codeview::CVType &Type);
20 
21 struct TagRecordHash {
TagRecordHashTagRecordHash22   explicit TagRecordHash(codeview::ClassRecord CR, uint32_t Full,
23                          uint32_t Forward)
24       : FullRecordHash(Full), ForwardDeclHash(Forward), Class(std::move(CR)) {
25     State = 0;
26   }
27 
TagRecordHashTagRecordHash28   explicit TagRecordHash(codeview::EnumRecord ER, uint32_t Full,
29                          uint32_t Forward)
30       : FullRecordHash(Full), ForwardDeclHash(Forward), Enum(std::move(ER)) {
31     State = 1;
32   }
33 
TagRecordHashTagRecordHash34   explicit TagRecordHash(codeview::UnionRecord UR, uint32_t Full,
35                          uint32_t Forward)
36       : FullRecordHash(Full), ForwardDeclHash(Forward), Union(std::move(UR)) {
37     State = 2;
38   }
39 
40   uint32_t FullRecordHash;
41   uint32_t ForwardDeclHash;
42 
getRecordTagRecordHash43   codeview::TagRecord &getRecord() {
44     switch (State) {
45     case 0:
46       return Class;
47     case 1:
48       return Enum;
49     case 2:
50       return Union;
51     }
52     llvm_unreachable("unreachable!");
53   }
54 
55 private:
56   union {
57     codeview::ClassRecord Class;
58     codeview::EnumRecord Enum;
59     codeview::UnionRecord Union;
60   };
61 
62   uint8_t State = 0;
63 };
64 
65 /// Given a CVType referring to a class, structure, union, or enum, compute
66 /// the hash of its forward decl and full decl.
67 LLVM_ABI Expected<TagRecordHash> hashTagRecord(const codeview::CVType &Type);
68 
69 } // end namespace pdb
70 } // end namespace llvm
71 
72 #endif // LLVM_DEBUGINFO_PDB_NATIVE_TPIHASHING_H
73