Line data Source code
1 : //===- TpiHashing.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_PDB_TPIHASHING_H
11 : #define LLVM_DEBUGINFO_PDB_TPIHASHING_H
12 :
13 : #include "llvm/ADT/Optional.h"
14 : #include "llvm/ADT/StringExtras.h"
15 : #include "llvm/DebugInfo/CodeView/TypeIndex.h"
16 : #include "llvm/DebugInfo/CodeView/TypeRecord.h"
17 : #include "llvm/DebugInfo/CodeView/TypeVisitorCallbacks.h"
18 : #include "llvm/DebugInfo/MSF/StreamArray.h"
19 : #include "llvm/DebugInfo/PDB/Raw/RawError.h"
20 : #include "llvm/Support/Endian.h"
21 : #include "llvm/Support/Error.h"
22 : #include <cstdint>
23 : #include <string>
24 :
25 : namespace llvm {
26 : namespace pdb {
27 :
28 570 : class TpiHashUpdater : public codeview::TypeVisitorCallbacks {
29 : public:
30 : TpiHashUpdater() = default;
31 :
32 : #define TYPE_RECORD(EnumName, EnumVal, Name) \
33 : virtual Error visitKnownRecord(codeview::CVType &CVR, \
34 : codeview::Name##Record &Record) override { \
35 : visitKnownRecordImpl(CVR, Record); \
36 : return Error::success(); \
37 : }
38 : #define TYPE_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
39 : #define MEMBER_RECORD(EnumName, EnumVal, Name)
40 : #define MEMBER_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
41 : #include "llvm/DebugInfo/CodeView/TypeRecords.def"
42 :
43 : private:
44 : template <typename RecordKind>
45 : void visitKnownRecordImpl(codeview::CVType &CVR, RecordKind &Record) {
46 184 : CVR.Hash = 0;
47 : }
48 :
49 : void visitKnownRecordImpl(codeview::CVType &CVR,
50 : codeview::UdtSourceLineRecord &Rec);
51 : void visitKnownRecordImpl(codeview::CVType &CVR,
52 : codeview::UdtModSourceLineRecord &Rec);
53 : void visitKnownRecordImpl(codeview::CVType &CVR, codeview::ClassRecord &Rec);
54 : void visitKnownRecordImpl(codeview::CVType &CVR, codeview::EnumRecord &Rec);
55 : void visitKnownRecordImpl(codeview::CVType &CVR, codeview::UnionRecord &Rec);
56 : };
57 :
58 26 : class TpiHashVerifier : public codeview::TypeVisitorCallbacks {
59 : public:
60 : TpiHashVerifier(msf::FixedStreamArray<support::ulittle32_t> &HashValues,
61 : uint32_t NumHashBuckets)
62 26 : : HashValues(HashValues), NumHashBuckets(NumHashBuckets) {}
63 :
64 : Error visitKnownRecord(codeview::CVType &CVR,
65 : codeview::UdtSourceLineRecord &Rec) override;
66 : Error visitKnownRecord(codeview::CVType &CVR,
67 : codeview::UdtModSourceLineRecord &Rec) override;
68 : Error visitKnownRecord(codeview::CVType &CVR,
69 : codeview::ClassRecord &Rec) override;
70 : Error visitKnownRecord(codeview::CVType &CVR,
71 : codeview::EnumRecord &Rec) override;
72 : Error visitKnownRecord(codeview::CVType &CVR,
73 : codeview::UnionRecord &Rec) override;
74 : Error visitTypeBegin(codeview::CVType &CVR) override;
75 :
76 : private:
77 : Error verifySourceLine(codeview::TypeIndex TI);
78 :
79 0 : Error errorInvalidHash() {
80 : return make_error<RawError>(
81 : raw_error_code::invalid_tpi_hash,
82 0 : "Type index is 0x" +
83 0 : utohexstr(codeview::TypeIndex::FirstNonSimpleIndex + Index));
84 : }
85 :
86 : msf::FixedStreamArray<support::ulittle32_t> HashValues;
87 : codeview::CVType RawRecord;
88 : uint32_t NumHashBuckets;
89 : uint32_t Index = -1;
90 : };
91 :
92 : } // end namespace pdb
93 : } // end namespace llvm
94 :
95 : #endif // LLVM_DEBUGINFO_PDB_TPIHASHING_H
|