1 //===- DbiModuleList.h - PDB module information list ------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_DEBUGINFO_PDB_RAW_DBIMODULELIST_H
11 #define LLVM_DEBUGINFO_PDB_RAW_DBIMODULELIST_H
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/ADT/iterator.h"
15 #include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h"
16 #include "llvm/Support/BinaryStreamArray.h"
17 #include "llvm/Support/BinaryStreamRef.h"
18 #include "llvm/Support/Endian.h"
19 #include "llvm/Support/Error.h"
27 struct FileInfoSubstreamHeader;
29 class DbiModuleSourceFilesIterator
30 : public iterator_facade_base<DbiModuleSourceFilesIterator,
31 std::random_access_iterator_tag, StringRef> {
32 typedef iterator_facade_base<DbiModuleSourceFilesIterator,
33 std::random_access_iterator_tag, StringRef>
37 DbiModuleSourceFilesIterator(const DbiModuleList &Modules, uint32_t Modi,
39 DbiModuleSourceFilesIterator() = default;
40 DbiModuleSourceFilesIterator &
41 operator=(const DbiModuleSourceFilesIterator &R) = default;
43 bool operator==(const DbiModuleSourceFilesIterator &R) const;
45 const StringRef &operator*() const { return ThisValue; }
46 StringRef &operator*() { return ThisValue; }
48 bool operator<(const DbiModuleSourceFilesIterator &RHS) const;
49 std::ptrdiff_t operator-(const DbiModuleSourceFilesIterator &R) const;
50 DbiModuleSourceFilesIterator &operator+=(std::ptrdiff_t N);
51 DbiModuleSourceFilesIterator &operator-=(std::ptrdiff_t N);
57 bool isCompatible(const DbiModuleSourceFilesIterator &R) const;
58 bool isUniversalEnd() const;
61 const DbiModuleList *Modules{nullptr};
67 friend DbiModuleSourceFilesIterator;
70 Error initialize(BinaryStreamRef ModInfo, BinaryStreamRef FileInfo);
72 Expected<StringRef> getFileName(uint32_t Index) const;
73 uint32_t getModuleCount() const;
74 uint32_t getSourceFileCount() const;
75 uint16_t getSourceFileCount(uint32_t Modi) const;
77 iterator_range<DbiModuleSourceFilesIterator>
78 source_files(uint32_t Modi) const;
80 DbiModuleDescriptor getModuleDescriptor(uint32_t Modi) const;
83 Error initializeModInfo(BinaryStreamRef ModInfo);
84 Error initializeFileInfo(BinaryStreamRef FileInfo);
86 VarStreamArray<DbiModuleDescriptor> Descriptors;
88 FixedStreamArray<support::little32_t> FileNameOffsets;
89 FixedStreamArray<support::ulittle16_t> ModFileCountArray;
91 // For each module, there are multiple filenames, which can be obtained by
92 // knowing the index of the file. Given the index of the file, one can use
93 // that as an offset into the FileNameOffsets array, which contains the
94 // absolute offset of the file name in NamesBuffer. Thus, for each module
95 // we store the first index in the FileNameOffsets array for this module.
96 // The number of files for the corresponding module is stored in
98 std::vector<uint32_t> ModuleInitialFileIndex;
100 // In order to provide random access into the Descriptors array, we iterate it
101 // once up front to find the offsets of the individual items and store them in
103 std::vector<uint32_t> ModuleDescriptorOffsets;
105 const FileInfoSubstreamHeader *FileInfoHeader = nullptr;
107 BinaryStreamRef ModInfoSubstream;
108 BinaryStreamRef FileInfoSubstream;
109 BinaryStreamRef NamesBuffer;
114 #endif // LLVM_DEBUGINFO_PDB_RAW_DBIMODULELIST_H