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_NATIVE_DBIMODULELIST_H
11 #define LLVM_DEBUGINFO_PDB_NATIVE_DBIMODULELIST_H
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/ADT/iterator.h"
15 #include "llvm/ADT/iterator_range.h"
16 #include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h"
17 #include "llvm/Support/BinaryStreamArray.h"
18 #include "llvm/Support/BinaryStreamRef.h"
19 #include "llvm/Support/Endian.h"
20 #include "llvm/Support/Error.h"
30 struct FileInfoSubstreamHeader;
32 class DbiModuleSourceFilesIterator
33 : public iterator_facade_base<DbiModuleSourceFilesIterator,
34 std::random_access_iterator_tag, StringRef> {
36 iterator_facade_base<DbiModuleSourceFilesIterator,
37 std::random_access_iterator_tag, StringRef>;
40 DbiModuleSourceFilesIterator(const DbiModuleList &Modules, uint32_t Modi,
42 DbiModuleSourceFilesIterator() = default;
43 DbiModuleSourceFilesIterator &
44 operator=(const DbiModuleSourceFilesIterator &R) = default;
46 bool operator==(const DbiModuleSourceFilesIterator &R) const;
48 const StringRef &operator*() const { return ThisValue; }
49 StringRef &operator*() { return ThisValue; }
51 bool operator<(const DbiModuleSourceFilesIterator &RHS) const;
52 std::ptrdiff_t operator-(const DbiModuleSourceFilesIterator &R) const;
53 DbiModuleSourceFilesIterator &operator+=(std::ptrdiff_t N);
54 DbiModuleSourceFilesIterator &operator-=(std::ptrdiff_t N);
60 bool isCompatible(const DbiModuleSourceFilesIterator &R) const;
61 bool isUniversalEnd() const;
64 const DbiModuleList *Modules{nullptr};
70 friend DbiModuleSourceFilesIterator;
73 Error initialize(BinaryStreamRef ModInfo, BinaryStreamRef FileInfo);
75 Expected<StringRef> getFileName(uint32_t Index) const;
76 uint32_t getModuleCount() const;
77 uint32_t getSourceFileCount() const;
78 uint16_t getSourceFileCount(uint32_t Modi) const;
80 iterator_range<DbiModuleSourceFilesIterator>
81 source_files(uint32_t Modi) const;
83 DbiModuleDescriptor getModuleDescriptor(uint32_t Modi) const;
86 Error initializeModInfo(BinaryStreamRef ModInfo);
87 Error initializeFileInfo(BinaryStreamRef FileInfo);
89 VarStreamArray<DbiModuleDescriptor> Descriptors;
91 FixedStreamArray<support::little32_t> FileNameOffsets;
92 FixedStreamArray<support::ulittle16_t> ModFileCountArray;
94 // For each module, there are multiple filenames, which can be obtained by
95 // knowing the index of the file. Given the index of the file, one can use
96 // that as an offset into the FileNameOffsets array, which contains the
97 // absolute offset of the file name in NamesBuffer. Thus, for each module
98 // we store the first index in the FileNameOffsets array for this module.
99 // The number of files for the corresponding module is stored in
100 // ModFileCountArray.
101 std::vector<uint32_t> ModuleInitialFileIndex;
103 // In order to provide random access into the Descriptors array, we iterate it
104 // once up front to find the offsets of the individual items and store them in
106 std::vector<uint32_t> ModuleDescriptorOffsets;
108 const FileInfoSubstreamHeader *FileInfoHeader = nullptr;
110 BinaryStreamRef ModInfoSubstream;
111 BinaryStreamRef FileInfoSubstream;
112 BinaryStreamRef NamesBuffer;
115 } // end namespace pdb
116 } // end namespace llvm
118 #endif // LLVM_DEBUGINFO_PDB_NATIVE_DBIMODULELIST_H