[Alignment][NFC] Convert StoreInst to MaybeAlign
[llvm-complete.git] / include / llvm / DebugInfo / PDB / Native / GlobalsStream.h
blob404baaa250771004118177a0e9b4428f6342faaa
1 //===- GlobalsStream.h - PDB Index of Symbols by Name -----------*- 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 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_DEBUGINFO_PDB_RAW_GLOBALS_STREAM_H
10 #define LLVM_DEBUGINFO_PDB_RAW_GLOBALS_STREAM_H
12 #include "llvm/ADT/iterator.h"
13 #include "llvm/DebugInfo/CodeView/SymbolRecord.h"
14 #include "llvm/DebugInfo/MSF/MappedBlockStream.h"
15 #include "llvm/DebugInfo/PDB/Native/RawConstants.h"
16 #include "llvm/DebugInfo/PDB/Native/RawTypes.h"
17 #include "llvm/DebugInfo/PDB/PDBTypes.h"
18 #include "llvm/Support/BinaryStreamArray.h"
19 #include "llvm/Support/Error.h"
21 namespace llvm {
22 namespace pdb {
23 class DbiStream;
24 class PDBFile;
25 class SymbolStream;
27 /// Iterator over hash records producing symbol record offsets. Abstracts away
28 /// the fact that symbol record offsets on disk are off-by-one.
29 class GSIHashIterator
30 : public iterator_adaptor_base<
31 GSIHashIterator, FixedStreamArrayIterator<PSHashRecord>,
32 std::random_access_iterator_tag, const uint32_t> {
33 public:
34 template <typename T>
35 GSIHashIterator(T &&v)
36 : GSIHashIterator::iterator_adaptor_base(std::forward<T &&>(v)) {}
38 uint32_t operator*() const {
39 uint32_t Off = this->I->Off;
40 return --Off;
44 /// From https://github.com/Microsoft/microsoft-pdb/blob/master/PDB/dbi/gsi.cpp
45 enum : unsigned { IPHR_HASH = 4096 };
47 /// A readonly view of a hash table used in the globals and publics streams.
48 /// Most clients will only want to iterate this to get symbol record offsets
49 /// into the PDB symbol stream.
50 class GSIHashTable {
51 public:
52 const GSIHashHeader *HashHdr;
53 FixedStreamArray<PSHashRecord> HashRecords;
54 FixedStreamArray<support::ulittle32_t> HashBitmap;
55 FixedStreamArray<support::ulittle32_t> HashBuckets;
56 std::array<int32_t, IPHR_HASH + 1> BucketMap;
58 Error read(BinaryStreamReader &Reader);
60 uint32_t getVerSignature() const { return HashHdr->VerSignature; }
61 uint32_t getVerHeader() const { return HashHdr->VerHdr; }
62 uint32_t getHashRecordSize() const { return HashHdr->HrSize; }
63 uint32_t getNumBuckets() const { return HashHdr->NumBuckets; }
65 typedef GSIHashHeader iterator;
66 GSIHashIterator begin() const { return GSIHashIterator(HashRecords.begin()); }
67 GSIHashIterator end() const { return GSIHashIterator(HashRecords.end()); }
70 class GlobalsStream {
71 public:
72 explicit GlobalsStream(std::unique_ptr<msf::MappedBlockStream> Stream);
73 ~GlobalsStream();
74 const GSIHashTable &getGlobalsTable() const { return GlobalsTable; }
75 Error reload();
77 std::vector<std::pair<uint32_t, codeview::CVSymbol>>
78 findRecordsByName(StringRef Name, const SymbolStream &Symbols) const;
80 private:
81 GSIHashTable GlobalsTable;
82 std::unique_ptr<msf::MappedBlockStream> Stream;
87 #endif