Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:44

0001 //===- DbiModuleList.h - PDB module information list ------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_DEBUGINFO_PDB_NATIVE_DBIMODULELIST_H
0010 #define LLVM_DEBUGINFO_PDB_NATIVE_DBIMODULELIST_H
0011 
0012 #include "llvm/ADT/StringRef.h"
0013 #include "llvm/ADT/iterator.h"
0014 #include "llvm/ADT/iterator_range.h"
0015 #include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h"
0016 #include "llvm/Support/BinaryStreamArray.h"
0017 #include "llvm/Support/BinaryStreamRef.h"
0018 #include "llvm/Support/Endian.h"
0019 #include "llvm/Support/Error.h"
0020 #include <cstddef>
0021 #include <cstdint>
0022 #include <iterator>
0023 #include <vector>
0024 
0025 namespace llvm {
0026 namespace pdb {
0027 
0028 class DbiModuleList;
0029 struct FileInfoSubstreamHeader;
0030 
0031 class DbiModuleSourceFilesIterator
0032     : public iterator_facade_base<DbiModuleSourceFilesIterator,
0033                                   std::random_access_iterator_tag, StringRef> {
0034   using BaseType = typename DbiModuleSourceFilesIterator::iterator_facade_base;
0035 
0036 public:
0037   DbiModuleSourceFilesIterator(const DbiModuleList &Modules, uint32_t Modi,
0038                                uint16_t Filei);
0039   DbiModuleSourceFilesIterator() = default;
0040   DbiModuleSourceFilesIterator(const DbiModuleSourceFilesIterator &R) = default;
0041   DbiModuleSourceFilesIterator &
0042   operator=(const DbiModuleSourceFilesIterator &R) = default;
0043 
0044   bool operator==(const DbiModuleSourceFilesIterator &R) const;
0045 
0046   const StringRef &operator*() const { return ThisValue; }
0047   StringRef &operator*() { return ThisValue; }
0048 
0049   bool operator<(const DbiModuleSourceFilesIterator &RHS) const;
0050   std::ptrdiff_t operator-(const DbiModuleSourceFilesIterator &R) const;
0051   DbiModuleSourceFilesIterator &operator+=(std::ptrdiff_t N);
0052   DbiModuleSourceFilesIterator &operator-=(std::ptrdiff_t N);
0053 
0054 private:
0055   void setValue();
0056 
0057   bool isEnd() const;
0058   bool isCompatible(const DbiModuleSourceFilesIterator &R) const;
0059   bool isUniversalEnd() const;
0060 
0061   StringRef ThisValue;
0062   const DbiModuleList *Modules{nullptr};
0063   uint32_t Modi{0};
0064   uint16_t Filei{0};
0065 };
0066 
0067 class DbiModuleList {
0068   friend DbiModuleSourceFilesIterator;
0069 
0070 public:
0071   Error initialize(BinaryStreamRef ModInfo, BinaryStreamRef FileInfo);
0072 
0073   Expected<StringRef> getFileName(uint32_t Index) const;
0074   uint32_t getModuleCount() const;
0075   uint32_t getSourceFileCount() const;
0076   uint16_t getSourceFileCount(uint32_t Modi) const;
0077 
0078   iterator_range<DbiModuleSourceFilesIterator>
0079   source_files(uint32_t Modi) const;
0080 
0081   DbiModuleDescriptor getModuleDescriptor(uint32_t Modi) const;
0082 
0083 private:
0084   Error initializeModInfo(BinaryStreamRef ModInfo);
0085   Error initializeFileInfo(BinaryStreamRef FileInfo);
0086 
0087   VarStreamArray<DbiModuleDescriptor> Descriptors;
0088 
0089   FixedStreamArray<support::little32_t> FileNameOffsets;
0090   FixedStreamArray<support::ulittle16_t> ModFileCountArray;
0091 
0092   // For each module, there are multiple filenames, which can be obtained by
0093   // knowing the index of the file.  Given the index of the file, one can use
0094   // that as an offset into the FileNameOffsets array, which contains the
0095   // absolute offset of the file name in NamesBuffer.  Thus, for each module
0096   // we store the first index in the FileNameOffsets array for this module.
0097   // The number of files for the corresponding module is stored in
0098   // ModFileCountArray.
0099   std::vector<uint32_t> ModuleInitialFileIndex;
0100 
0101   // In order to provide random access into the Descriptors array, we iterate it
0102   // once up front to find the offsets of the individual items and store them in
0103   // this array.
0104   std::vector<uint32_t> ModuleDescriptorOffsets;
0105 
0106   const FileInfoSubstreamHeader *FileInfoHeader = nullptr;
0107 
0108   BinaryStreamRef ModInfoSubstream;
0109   BinaryStreamRef FileInfoSubstream;
0110   BinaryStreamRef NamesBuffer;
0111 };
0112 
0113 } // end namespace pdb
0114 } // end namespace llvm
0115 
0116 #endif // LLVM_DEBUGINFO_PDB_NATIVE_DBIMODULELIST_H