LLVM  14.0.0git
DbiModuleList.h
Go to the documentation of this file.
1 //===- DbiModuleList.h - PDB module information list ------------*- 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_DBIMODULELIST_H
10 #define LLVM_DEBUGINFO_PDB_NATIVE_DBIMODULELIST_H
11 
12 #include "llvm/ADT/StringRef.h"
13 #include "llvm/ADT/iterator.h"
18 #include "llvm/Support/Endian.h"
19 #include "llvm/Support/Error.h"
20 #include <cstddef>
21 #include <cstdint>
22 #include <iterator>
23 #include <vector>
24 
25 namespace llvm {
26 namespace pdb {
27 
28 class DbiModuleList;
29 struct FileInfoSubstreamHeader;
30 
32  : public iterator_facade_base<DbiModuleSourceFilesIterator,
33  std::random_access_iterator_tag, StringRef> {
34  using BaseType = typename DbiModuleSourceFilesIterator::iterator_facade_base;
35 
36 public:
38  uint16_t Filei);
39  DbiModuleSourceFilesIterator() = default;
42  operator=(const DbiModuleSourceFilesIterator &R) = default;
43 
44  bool operator==(const DbiModuleSourceFilesIterator &R) const;
45 
46  const StringRef &operator*() const { return ThisValue; }
47  StringRef &operator*() { return ThisValue; }
48 
49  bool operator<(const DbiModuleSourceFilesIterator &RHS) const;
50  std::ptrdiff_t operator-(const DbiModuleSourceFilesIterator &R) const;
51  DbiModuleSourceFilesIterator &operator+=(std::ptrdiff_t N);
52  DbiModuleSourceFilesIterator &operator-=(std::ptrdiff_t N);
53 
54 private:
55  void setValue();
56 
57  bool isEnd() const;
58  bool isCompatible(const DbiModuleSourceFilesIterator &R) const;
59  bool isUniversalEnd() const;
60 
61  StringRef ThisValue;
62  const DbiModuleList *Modules{nullptr};
63  uint32_t Modi{0};
64  uint16_t Filei{0};
65 };
66 
69 
70 public:
72 
74  uint32_t getModuleCount() const;
77 
79  source_files(uint32_t Modi) const;
80 
82 
83 private:
84  Error initializeModInfo(BinaryStreamRef ModInfo);
85  Error initializeFileInfo(BinaryStreamRef FileInfo);
86 
88 
91 
92  // For each module, there are multiple filenames, which can be obtained by
93  // knowing the index of the file. Given the index of the file, one can use
94  // that as an offset into the FileNameOffsets array, which contains the
95  // absolute offset of the file name in NamesBuffer. Thus, for each module
96  // we store the first index in the FileNameOffsets array for this module.
97  // The number of files for the corresponding module is stored in
98  // ModFileCountArray.
99  std::vector<uint32_t> ModuleInitialFileIndex;
100 
101  // In order to provide random access into the Descriptors array, we iterate it
102  // once up front to find the offsets of the individual items and store them in
103  // this array.
104  std::vector<uint32_t> ModuleDescriptorOffsets;
105 
106  const FileInfoSubstreamHeader *FileInfoHeader = nullptr;
107 
108  BinaryStreamRef ModInfoSubstream;
109  BinaryStreamRef FileInfoSubstream;
110  BinaryStreamRef NamesBuffer;
111 };
112 
113 } // end namespace pdb
114 } // end namespace llvm
115 
116 #endif // LLVM_DEBUGINFO_PDB_NATIVE_DBIMODULELIST_H
llvm::pdb::DbiModuleList::getModuleCount
uint32_t getModuleCount() const
Definition: DbiModuleList.cpp:241
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::pdb::DbiModuleList::initialize
Error initialize(BinaryStreamRef ModInfo, BinaryStreamRef FileInfo)
Definition: DbiModuleList.cpp:162
StringRef.h
DbiModuleDescriptor.h
Error.h
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
BaseType
llvm::FixedStreamArray
FixedStreamArray is similar to VarStreamArray, except with each record having a fixed-length.
Definition: BinaryStreamArray.h:257
llvm::pdb::DbiModuleSourceFilesIterator::operator*
StringRef & operator*()
Definition: DbiModuleList.h:47
llvm::pdb::DbiModuleList
Definition: DbiModuleList.h:67
llvm::VarStreamArray
Definition: BinaryStreamArray.h:92
llvm::pdb::DbiModuleList::getSourceFileCount
uint32_t getSourceFileCount() const
Definition: DbiModuleList.cpp:245
llvm::pdb::DbiModuleSourceFilesIterator::operator=
DbiModuleSourceFilesIterator & operator=(const DbiModuleSourceFilesIterator &R)=default
llvm::pdb::DbiModuleSourceFilesIterator::operator-
std::ptrdiff_t operator-(const DbiModuleSourceFilesIterator &R) const
Definition: DbiModuleList.cpp:71
llvm::pdb::DbiModuleSourceFilesIterator::DbiModuleSourceFilesIterator
DbiModuleSourceFilesIterator()=default
Index
uint32_t Index
Definition: ELFObjHandler.cpp:84
llvm::pdb::FileInfoSubstreamHeader
The header preceding the File Info Substream of the DBI stream.
Definition: RawTypes.h:180
iterator.h
llvm::iterator_facade_base
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
Definition: iterator.h:80
BinaryStreamArray.h
iterator_range.h
llvm::pdb::DbiModuleSourceFilesIterator::operator==
bool operator==(const DbiModuleSourceFilesIterator &R) const
Definition: DbiModuleList.cpp:30
llvm::pdb::DbiModuleSourceFilesIterator::operator+=
DbiModuleSourceFilesIterator & operator+=(std::ptrdiff_t N)
Definition: DbiModuleList.cpp:96
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
BinaryStreamRef.h
uint32_t
llvm::pdb::DbiModuleList::getFileName
Expected< StringRef > getFileName(uint32_t Index) const
Definition: DbiModuleList.cpp:268
llvm::pdb::DbiModuleSourceFilesIterator::operator-=
DbiModuleSourceFilesIterator & operator-=(std::ptrdiff_t N)
Definition: DbiModuleList.cpp:106
uint16_t
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
N
#define N
llvm::pdb::DbiModuleSourceFilesIterator
Definition: DbiModuleList.h:31
llvm::pdb::DbiModuleList::getModuleDescriptor
DbiModuleDescriptor getModuleDescriptor(uint32_t Modi) const
Definition: DbiModuleList.cpp:253
llvm::pdb::DbiModuleSourceFilesIterator::operator<
bool operator<(const DbiModuleSourceFilesIterator &RHS) const
Definition: DbiModuleList.cpp:58
llvm::iterator_range
A range adaptor for a pair of iterators.
Definition: iterator_range.h:30
llvm::pdb::DbiModuleSourceFilesIterator::operator*
const StringRef & operator*() const
Definition: DbiModuleList.h:46
llvm::pdb::DbiModuleDescriptor
Definition: DbiModuleDescriptor.h:23
Endian.h
llvm::pdb::DbiModuleList::source_files
iterator_range< DbiModuleSourceFilesIterator > source_files(uint32_t Modi) const
Definition: DbiModuleList.cpp:262
llvm::BinaryStreamRef
BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.
Definition: BinaryStreamRef.h:156