1*e038c9c4Sjoerg //===- ModuleFile.h - Module file description -------------------*- C++ -*-===// 2*e038c9c4Sjoerg // 3*e038c9c4Sjoerg // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*e038c9c4Sjoerg // See https://llvm.org/LICENSE.txt for license information. 5*e038c9c4Sjoerg // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*e038c9c4Sjoerg // 7*e038c9c4Sjoerg //===----------------------------------------------------------------------===// 8*e038c9c4Sjoerg // 9*e038c9c4Sjoerg // This file defines the Module class, which describes a module that has 10*e038c9c4Sjoerg // been loaded from an AST file. 11*e038c9c4Sjoerg // 12*e038c9c4Sjoerg //===----------------------------------------------------------------------===// 13*e038c9c4Sjoerg 14*e038c9c4Sjoerg #ifndef LLVM_CLANG_SERIALIZATION_MODULEFILE_H 15*e038c9c4Sjoerg #define LLVM_CLANG_SERIALIZATION_MODULEFILE_H 16*e038c9c4Sjoerg 17*e038c9c4Sjoerg #include "clang/Basic/FileManager.h" 18*e038c9c4Sjoerg #include "clang/Basic/Module.h" 19*e038c9c4Sjoerg #include "clang/Basic/SourceLocation.h" 20*e038c9c4Sjoerg #include "clang/Serialization/ASTBitCodes.h" 21*e038c9c4Sjoerg #include "clang/Serialization/ContinuousRangeMap.h" 22*e038c9c4Sjoerg #include "clang/Serialization/ModuleFileExtension.h" 23*e038c9c4Sjoerg #include "llvm/ADT/DenseMap.h" 24*e038c9c4Sjoerg #include "llvm/ADT/PointerIntPair.h" 25*e038c9c4Sjoerg #include "llvm/ADT/SetVector.h" 26*e038c9c4Sjoerg #include "llvm/ADT/SmallVector.h" 27*e038c9c4Sjoerg #include "llvm/ADT/StringRef.h" 28*e038c9c4Sjoerg #include "llvm/Bitstream/BitstreamReader.h" 29*e038c9c4Sjoerg #include "llvm/Support/Endian.h" 30*e038c9c4Sjoerg #include <cassert> 31*e038c9c4Sjoerg #include <cstdint> 32*e038c9c4Sjoerg #include <memory> 33*e038c9c4Sjoerg #include <string> 34*e038c9c4Sjoerg #include <vector> 35*e038c9c4Sjoerg 36*e038c9c4Sjoerg namespace clang { 37*e038c9c4Sjoerg 38*e038c9c4Sjoerg namespace serialization { 39*e038c9c4Sjoerg 40*e038c9c4Sjoerg /// Specifies the kind of module that has been loaded. 41*e038c9c4Sjoerg enum ModuleKind { 42*e038c9c4Sjoerg /// File is an implicitly-loaded module. 43*e038c9c4Sjoerg MK_ImplicitModule, 44*e038c9c4Sjoerg 45*e038c9c4Sjoerg /// File is an explicitly-loaded module. 46*e038c9c4Sjoerg MK_ExplicitModule, 47*e038c9c4Sjoerg 48*e038c9c4Sjoerg /// File is a PCH file treated as such. 49*e038c9c4Sjoerg MK_PCH, 50*e038c9c4Sjoerg 51*e038c9c4Sjoerg /// File is a PCH file treated as the preamble. 52*e038c9c4Sjoerg MK_Preamble, 53*e038c9c4Sjoerg 54*e038c9c4Sjoerg /// File is a PCH file treated as the actual main file. 55*e038c9c4Sjoerg MK_MainFile, 56*e038c9c4Sjoerg 57*e038c9c4Sjoerg /// File is from a prebuilt module path. 58*e038c9c4Sjoerg MK_PrebuiltModule 59*e038c9c4Sjoerg }; 60*e038c9c4Sjoerg 61*e038c9c4Sjoerg /// The input file that has been loaded from this AST file, along with 62*e038c9c4Sjoerg /// bools indicating whether this was an overridden buffer or if it was 63*e038c9c4Sjoerg /// out-of-date or not-found. 64*e038c9c4Sjoerg class InputFile { 65*e038c9c4Sjoerg enum { 66*e038c9c4Sjoerg Overridden = 1, 67*e038c9c4Sjoerg OutOfDate = 2, 68*e038c9c4Sjoerg NotFound = 3 69*e038c9c4Sjoerg }; 70*e038c9c4Sjoerg llvm::PointerIntPair<const FileEntryRef::MapEntry *, 2, unsigned> Val; 71*e038c9c4Sjoerg 72*e038c9c4Sjoerg public: 73*e038c9c4Sjoerg InputFile() = default; 74*e038c9c4Sjoerg 75*e038c9c4Sjoerg InputFile(FileEntryRef File, bool isOverridden = false, 76*e038c9c4Sjoerg bool isOutOfDate = false) { 77*e038c9c4Sjoerg assert(!(isOverridden && isOutOfDate) && 78*e038c9c4Sjoerg "an overridden cannot be out-of-date"); 79*e038c9c4Sjoerg unsigned intVal = 0; 80*e038c9c4Sjoerg if (isOverridden) 81*e038c9c4Sjoerg intVal = Overridden; 82*e038c9c4Sjoerg else if (isOutOfDate) 83*e038c9c4Sjoerg intVal = OutOfDate; 84*e038c9c4Sjoerg Val.setPointerAndInt(&File.getMapEntry(), intVal); 85*e038c9c4Sjoerg } 86*e038c9c4Sjoerg getNotFound()87*e038c9c4Sjoerg static InputFile getNotFound() { 88*e038c9c4Sjoerg InputFile File; 89*e038c9c4Sjoerg File.Val.setInt(NotFound); 90*e038c9c4Sjoerg return File; 91*e038c9c4Sjoerg } 92*e038c9c4Sjoerg getFile()93*e038c9c4Sjoerg OptionalFileEntryRefDegradesToFileEntryPtr getFile() const { 94*e038c9c4Sjoerg if (auto *P = Val.getPointer()) 95*e038c9c4Sjoerg return FileEntryRef(*P); 96*e038c9c4Sjoerg return None; 97*e038c9c4Sjoerg } isOverridden()98*e038c9c4Sjoerg bool isOverridden() const { return Val.getInt() == Overridden; } isOutOfDate()99*e038c9c4Sjoerg bool isOutOfDate() const { return Val.getInt() == OutOfDate; } isNotFound()100*e038c9c4Sjoerg bool isNotFound() const { return Val.getInt() == NotFound; } 101*e038c9c4Sjoerg }; 102*e038c9c4Sjoerg 103*e038c9c4Sjoerg /// Information about a module that has been loaded by the ASTReader. 104*e038c9c4Sjoerg /// 105*e038c9c4Sjoerg /// Each instance of the Module class corresponds to a single AST file, which 106*e038c9c4Sjoerg /// may be a precompiled header, precompiled preamble, a module, or an AST file 107*e038c9c4Sjoerg /// of some sort loaded as the main file, all of which are specific formulations 108*e038c9c4Sjoerg /// of the general notion of a "module". A module may depend on any number of 109*e038c9c4Sjoerg /// other modules. 110*e038c9c4Sjoerg class ModuleFile { 111*e038c9c4Sjoerg public: ModuleFile(ModuleKind Kind,unsigned Generation)112*e038c9c4Sjoerg ModuleFile(ModuleKind Kind, unsigned Generation) 113*e038c9c4Sjoerg : Kind(Kind), Generation(Generation) {} 114*e038c9c4Sjoerg ~ModuleFile(); 115*e038c9c4Sjoerg 116*e038c9c4Sjoerg // === General information === 117*e038c9c4Sjoerg 118*e038c9c4Sjoerg /// The index of this module in the list of modules. 119*e038c9c4Sjoerg unsigned Index = 0; 120*e038c9c4Sjoerg 121*e038c9c4Sjoerg /// The type of this module. 122*e038c9c4Sjoerg ModuleKind Kind; 123*e038c9c4Sjoerg 124*e038c9c4Sjoerg /// The file name of the module file. 125*e038c9c4Sjoerg std::string FileName; 126*e038c9c4Sjoerg 127*e038c9c4Sjoerg /// The name of the module. 128*e038c9c4Sjoerg std::string ModuleName; 129*e038c9c4Sjoerg 130*e038c9c4Sjoerg /// The base directory of the module. 131*e038c9c4Sjoerg std::string BaseDirectory; 132*e038c9c4Sjoerg getTimestampFilename()133*e038c9c4Sjoerg std::string getTimestampFilename() const { 134*e038c9c4Sjoerg return FileName + ".timestamp"; 135*e038c9c4Sjoerg } 136*e038c9c4Sjoerg 137*e038c9c4Sjoerg /// The original source file name that was used to build the 138*e038c9c4Sjoerg /// primary AST file, which may have been modified for 139*e038c9c4Sjoerg /// relocatable-pch support. 140*e038c9c4Sjoerg std::string OriginalSourceFileName; 141*e038c9c4Sjoerg 142*e038c9c4Sjoerg /// The actual original source file name that was used to 143*e038c9c4Sjoerg /// build this AST file. 144*e038c9c4Sjoerg std::string ActualOriginalSourceFileName; 145*e038c9c4Sjoerg 146*e038c9c4Sjoerg /// The file ID for the original source file that was used to 147*e038c9c4Sjoerg /// build this AST file. 148*e038c9c4Sjoerg FileID OriginalSourceFileID; 149*e038c9c4Sjoerg 150*e038c9c4Sjoerg /// The directory that the PCH was originally created in. Used to 151*e038c9c4Sjoerg /// allow resolving headers even after headers+PCH was moved to a new path. 152*e038c9c4Sjoerg std::string OriginalDir; 153*e038c9c4Sjoerg 154*e038c9c4Sjoerg std::string ModuleMapPath; 155*e038c9c4Sjoerg 156*e038c9c4Sjoerg /// Whether this precompiled header is a relocatable PCH file. 157*e038c9c4Sjoerg bool RelocatablePCH = false; 158*e038c9c4Sjoerg 159*e038c9c4Sjoerg /// Whether timestamps are included in this module file. 160*e038c9c4Sjoerg bool HasTimestamps = false; 161*e038c9c4Sjoerg 162*e038c9c4Sjoerg /// Whether the top-level module has been read from the AST file. 163*e038c9c4Sjoerg bool DidReadTopLevelSubmodule = false; 164*e038c9c4Sjoerg 165*e038c9c4Sjoerg /// The file entry for the module file. 166*e038c9c4Sjoerg OptionalFileEntryRefDegradesToFileEntryPtr File; 167*e038c9c4Sjoerg 168*e038c9c4Sjoerg /// The signature of the module file, which may be used instead of the size 169*e038c9c4Sjoerg /// and modification time to identify this particular file. 170*e038c9c4Sjoerg ASTFileSignature Signature; 171*e038c9c4Sjoerg 172*e038c9c4Sjoerg /// The signature of the AST block of the module file, this can be used to 173*e038c9c4Sjoerg /// unique module files based on AST contents. 174*e038c9c4Sjoerg ASTFileSignature ASTBlockHash; 175*e038c9c4Sjoerg 176*e038c9c4Sjoerg /// Whether this module has been directly imported by the 177*e038c9c4Sjoerg /// user. 178*e038c9c4Sjoerg bool DirectlyImported = false; 179*e038c9c4Sjoerg 180*e038c9c4Sjoerg /// The generation of which this module file is a part. 181*e038c9c4Sjoerg unsigned Generation; 182*e038c9c4Sjoerg 183*e038c9c4Sjoerg /// The memory buffer that stores the data associated with 184*e038c9c4Sjoerg /// this AST file, owned by the InMemoryModuleCache. 185*e038c9c4Sjoerg llvm::MemoryBuffer *Buffer; 186*e038c9c4Sjoerg 187*e038c9c4Sjoerg /// The size of this file, in bits. 188*e038c9c4Sjoerg uint64_t SizeInBits = 0; 189*e038c9c4Sjoerg 190*e038c9c4Sjoerg /// The global bit offset (or base) of this module 191*e038c9c4Sjoerg uint64_t GlobalBitOffset = 0; 192*e038c9c4Sjoerg 193*e038c9c4Sjoerg /// The bit offset of the AST block of this module. 194*e038c9c4Sjoerg uint64_t ASTBlockStartOffset = 0; 195*e038c9c4Sjoerg 196*e038c9c4Sjoerg /// The serialized bitstream data for this file. 197*e038c9c4Sjoerg StringRef Data; 198*e038c9c4Sjoerg 199*e038c9c4Sjoerg /// The main bitstream cursor for the main block. 200*e038c9c4Sjoerg llvm::BitstreamCursor Stream; 201*e038c9c4Sjoerg 202*e038c9c4Sjoerg /// The source location where the module was explicitly or implicitly 203*e038c9c4Sjoerg /// imported in the local translation unit. 204*e038c9c4Sjoerg /// 205*e038c9c4Sjoerg /// If module A depends on and imports module B, both modules will have the 206*e038c9c4Sjoerg /// same DirectImportLoc, but different ImportLoc (B's ImportLoc will be a 207*e038c9c4Sjoerg /// source location inside module A). 208*e038c9c4Sjoerg /// 209*e038c9c4Sjoerg /// WARNING: This is largely useless. It doesn't tell you when a module was 210*e038c9c4Sjoerg /// made visible, just when the first submodule of that module was imported. 211*e038c9c4Sjoerg SourceLocation DirectImportLoc; 212*e038c9c4Sjoerg 213*e038c9c4Sjoerg /// The source location where this module was first imported. 214*e038c9c4Sjoerg SourceLocation ImportLoc; 215*e038c9c4Sjoerg 216*e038c9c4Sjoerg /// The first source location in this module. 217*e038c9c4Sjoerg SourceLocation FirstLoc; 218*e038c9c4Sjoerg 219*e038c9c4Sjoerg /// The list of extension readers that are attached to this module 220*e038c9c4Sjoerg /// file. 221*e038c9c4Sjoerg std::vector<std::unique_ptr<ModuleFileExtensionReader>> ExtensionReaders; 222*e038c9c4Sjoerg 223*e038c9c4Sjoerg /// The module offset map data for this file. If non-empty, the various 224*e038c9c4Sjoerg /// ContinuousRangeMaps described below have not yet been populated. 225*e038c9c4Sjoerg StringRef ModuleOffsetMap; 226*e038c9c4Sjoerg 227*e038c9c4Sjoerg // === Input Files === 228*e038c9c4Sjoerg 229*e038c9c4Sjoerg /// The cursor to the start of the input-files block. 230*e038c9c4Sjoerg llvm::BitstreamCursor InputFilesCursor; 231*e038c9c4Sjoerg 232*e038c9c4Sjoerg /// Offsets for all of the input file entries in the AST file. 233*e038c9c4Sjoerg const llvm::support::unaligned_uint64_t *InputFileOffsets = nullptr; 234*e038c9c4Sjoerg 235*e038c9c4Sjoerg /// The input files that have been loaded from this AST file. 236*e038c9c4Sjoerg std::vector<InputFile> InputFilesLoaded; 237*e038c9c4Sjoerg 238*e038c9c4Sjoerg // All user input files reside at the index range [0, NumUserInputFiles), and 239*e038c9c4Sjoerg // system input files reside at [NumUserInputFiles, InputFilesLoaded.size()). 240*e038c9c4Sjoerg unsigned NumUserInputFiles = 0; 241*e038c9c4Sjoerg 242*e038c9c4Sjoerg /// If non-zero, specifies the time when we last validated input 243*e038c9c4Sjoerg /// files. Zero means we never validated them. 244*e038c9c4Sjoerg /// 245*e038c9c4Sjoerg /// The time is specified in seconds since the start of the Epoch. 246*e038c9c4Sjoerg uint64_t InputFilesValidationTimestamp = 0; 247*e038c9c4Sjoerg 248*e038c9c4Sjoerg // === Source Locations === 249*e038c9c4Sjoerg 250*e038c9c4Sjoerg /// Cursor used to read source location entries. 251*e038c9c4Sjoerg llvm::BitstreamCursor SLocEntryCursor; 252*e038c9c4Sjoerg 253*e038c9c4Sjoerg /// The bit offset to the start of the SOURCE_MANAGER_BLOCK. 254*e038c9c4Sjoerg uint64_t SourceManagerBlockStartOffset = 0; 255*e038c9c4Sjoerg 256*e038c9c4Sjoerg /// The number of source location entries in this AST file. 257*e038c9c4Sjoerg unsigned LocalNumSLocEntries = 0; 258*e038c9c4Sjoerg 259*e038c9c4Sjoerg /// The base ID in the source manager's view of this module. 260*e038c9c4Sjoerg int SLocEntryBaseID = 0; 261*e038c9c4Sjoerg 262*e038c9c4Sjoerg /// The base offset in the source manager's view of this module. 263*e038c9c4Sjoerg unsigned SLocEntryBaseOffset = 0; 264*e038c9c4Sjoerg 265*e038c9c4Sjoerg /// Base file offset for the offsets in SLocEntryOffsets. Real file offset 266*e038c9c4Sjoerg /// for the entry is SLocEntryOffsetsBase + SLocEntryOffsets[i]. 267*e038c9c4Sjoerg uint64_t SLocEntryOffsetsBase = 0; 268*e038c9c4Sjoerg 269*e038c9c4Sjoerg /// Offsets for all of the source location entries in the 270*e038c9c4Sjoerg /// AST file. 271*e038c9c4Sjoerg const uint32_t *SLocEntryOffsets = nullptr; 272*e038c9c4Sjoerg 273*e038c9c4Sjoerg /// SLocEntries that we're going to preload. 274*e038c9c4Sjoerg SmallVector<uint64_t, 4> PreloadSLocEntries; 275*e038c9c4Sjoerg 276*e038c9c4Sjoerg /// Remapping table for source locations in this module. 277*e038c9c4Sjoerg ContinuousRangeMap<uint32_t, int, 2> SLocRemap; 278*e038c9c4Sjoerg 279*e038c9c4Sjoerg // === Identifiers === 280*e038c9c4Sjoerg 281*e038c9c4Sjoerg /// The number of identifiers in this AST file. 282*e038c9c4Sjoerg unsigned LocalNumIdentifiers = 0; 283*e038c9c4Sjoerg 284*e038c9c4Sjoerg /// Offsets into the identifier table data. 285*e038c9c4Sjoerg /// 286*e038c9c4Sjoerg /// This array is indexed by the identifier ID (-1), and provides 287*e038c9c4Sjoerg /// the offset into IdentifierTableData where the string data is 288*e038c9c4Sjoerg /// stored. 289*e038c9c4Sjoerg const uint32_t *IdentifierOffsets = nullptr; 290*e038c9c4Sjoerg 291*e038c9c4Sjoerg /// Base identifier ID for identifiers local to this module. 292*e038c9c4Sjoerg serialization::IdentID BaseIdentifierID = 0; 293*e038c9c4Sjoerg 294*e038c9c4Sjoerg /// Remapping table for identifier IDs in this module. 295*e038c9c4Sjoerg ContinuousRangeMap<uint32_t, int, 2> IdentifierRemap; 296*e038c9c4Sjoerg 297*e038c9c4Sjoerg /// Actual data for the on-disk hash table of identifiers. 298*e038c9c4Sjoerg /// 299*e038c9c4Sjoerg /// This pointer points into a memory buffer, where the on-disk hash 300*e038c9c4Sjoerg /// table for identifiers actually lives. 301*e038c9c4Sjoerg const unsigned char *IdentifierTableData = nullptr; 302*e038c9c4Sjoerg 303*e038c9c4Sjoerg /// A pointer to an on-disk hash table of opaque type 304*e038c9c4Sjoerg /// IdentifierHashTable. 305*e038c9c4Sjoerg void *IdentifierLookupTable = nullptr; 306*e038c9c4Sjoerg 307*e038c9c4Sjoerg /// Offsets of identifiers that we're going to preload within 308*e038c9c4Sjoerg /// IdentifierTableData. 309*e038c9c4Sjoerg std::vector<unsigned> PreloadIdentifierOffsets; 310*e038c9c4Sjoerg 311*e038c9c4Sjoerg // === Macros === 312*e038c9c4Sjoerg 313*e038c9c4Sjoerg /// The cursor to the start of the preprocessor block, which stores 314*e038c9c4Sjoerg /// all of the macro definitions. 315*e038c9c4Sjoerg llvm::BitstreamCursor MacroCursor; 316*e038c9c4Sjoerg 317*e038c9c4Sjoerg /// The number of macros in this AST file. 318*e038c9c4Sjoerg unsigned LocalNumMacros = 0; 319*e038c9c4Sjoerg 320*e038c9c4Sjoerg /// Base file offset for the offsets in MacroOffsets. Real file offset for 321*e038c9c4Sjoerg /// the entry is MacroOffsetsBase + MacroOffsets[i]. 322*e038c9c4Sjoerg uint64_t MacroOffsetsBase = 0; 323*e038c9c4Sjoerg 324*e038c9c4Sjoerg /// Offsets of macros in the preprocessor block. 325*e038c9c4Sjoerg /// 326*e038c9c4Sjoerg /// This array is indexed by the macro ID (-1), and provides 327*e038c9c4Sjoerg /// the offset into the preprocessor block where macro definitions are 328*e038c9c4Sjoerg /// stored. 329*e038c9c4Sjoerg const uint32_t *MacroOffsets = nullptr; 330*e038c9c4Sjoerg 331*e038c9c4Sjoerg /// Base macro ID for macros local to this module. 332*e038c9c4Sjoerg serialization::MacroID BaseMacroID = 0; 333*e038c9c4Sjoerg 334*e038c9c4Sjoerg /// Remapping table for macro IDs in this module. 335*e038c9c4Sjoerg ContinuousRangeMap<uint32_t, int, 2> MacroRemap; 336*e038c9c4Sjoerg 337*e038c9c4Sjoerg /// The offset of the start of the set of defined macros. 338*e038c9c4Sjoerg uint64_t MacroStartOffset = 0; 339*e038c9c4Sjoerg 340*e038c9c4Sjoerg // === Detailed PreprocessingRecord === 341*e038c9c4Sjoerg 342*e038c9c4Sjoerg /// The cursor to the start of the (optional) detailed preprocessing 343*e038c9c4Sjoerg /// record block. 344*e038c9c4Sjoerg llvm::BitstreamCursor PreprocessorDetailCursor; 345*e038c9c4Sjoerg 346*e038c9c4Sjoerg /// The offset of the start of the preprocessor detail cursor. 347*e038c9c4Sjoerg uint64_t PreprocessorDetailStartOffset = 0; 348*e038c9c4Sjoerg 349*e038c9c4Sjoerg /// Base preprocessed entity ID for preprocessed entities local to 350*e038c9c4Sjoerg /// this module. 351*e038c9c4Sjoerg serialization::PreprocessedEntityID BasePreprocessedEntityID = 0; 352*e038c9c4Sjoerg 353*e038c9c4Sjoerg /// Remapping table for preprocessed entity IDs in this module. 354*e038c9c4Sjoerg ContinuousRangeMap<uint32_t, int, 2> PreprocessedEntityRemap; 355*e038c9c4Sjoerg 356*e038c9c4Sjoerg const PPEntityOffset *PreprocessedEntityOffsets = nullptr; 357*e038c9c4Sjoerg unsigned NumPreprocessedEntities = 0; 358*e038c9c4Sjoerg 359*e038c9c4Sjoerg /// Base ID for preprocessed skipped ranges local to this module. 360*e038c9c4Sjoerg unsigned BasePreprocessedSkippedRangeID = 0; 361*e038c9c4Sjoerg 362*e038c9c4Sjoerg const PPSkippedRange *PreprocessedSkippedRangeOffsets = nullptr; 363*e038c9c4Sjoerg unsigned NumPreprocessedSkippedRanges = 0; 364*e038c9c4Sjoerg 365*e038c9c4Sjoerg // === Header search information === 366*e038c9c4Sjoerg 367*e038c9c4Sjoerg /// The number of local HeaderFileInfo structures. 368*e038c9c4Sjoerg unsigned LocalNumHeaderFileInfos = 0; 369*e038c9c4Sjoerg 370*e038c9c4Sjoerg /// Actual data for the on-disk hash table of header file 371*e038c9c4Sjoerg /// information. 372*e038c9c4Sjoerg /// 373*e038c9c4Sjoerg /// This pointer points into a memory buffer, where the on-disk hash 374*e038c9c4Sjoerg /// table for header file information actually lives. 375*e038c9c4Sjoerg const char *HeaderFileInfoTableData = nullptr; 376*e038c9c4Sjoerg 377*e038c9c4Sjoerg /// The on-disk hash table that contains information about each of 378*e038c9c4Sjoerg /// the header files. 379*e038c9c4Sjoerg void *HeaderFileInfoTable = nullptr; 380*e038c9c4Sjoerg 381*e038c9c4Sjoerg // === Submodule information === 382*e038c9c4Sjoerg 383*e038c9c4Sjoerg /// The number of submodules in this module. 384*e038c9c4Sjoerg unsigned LocalNumSubmodules = 0; 385*e038c9c4Sjoerg 386*e038c9c4Sjoerg /// Base submodule ID for submodules local to this module. 387*e038c9c4Sjoerg serialization::SubmoduleID BaseSubmoduleID = 0; 388*e038c9c4Sjoerg 389*e038c9c4Sjoerg /// Remapping table for submodule IDs in this module. 390*e038c9c4Sjoerg ContinuousRangeMap<uint32_t, int, 2> SubmoduleRemap; 391*e038c9c4Sjoerg 392*e038c9c4Sjoerg // === Selectors === 393*e038c9c4Sjoerg 394*e038c9c4Sjoerg /// The number of selectors new to this file. 395*e038c9c4Sjoerg /// 396*e038c9c4Sjoerg /// This is the number of entries in SelectorOffsets. 397*e038c9c4Sjoerg unsigned LocalNumSelectors = 0; 398*e038c9c4Sjoerg 399*e038c9c4Sjoerg /// Offsets into the selector lookup table's data array 400*e038c9c4Sjoerg /// where each selector resides. 401*e038c9c4Sjoerg const uint32_t *SelectorOffsets = nullptr; 402*e038c9c4Sjoerg 403*e038c9c4Sjoerg /// Base selector ID for selectors local to this module. 404*e038c9c4Sjoerg serialization::SelectorID BaseSelectorID = 0; 405*e038c9c4Sjoerg 406*e038c9c4Sjoerg /// Remapping table for selector IDs in this module. 407*e038c9c4Sjoerg ContinuousRangeMap<uint32_t, int, 2> SelectorRemap; 408*e038c9c4Sjoerg 409*e038c9c4Sjoerg /// A pointer to the character data that comprises the selector table 410*e038c9c4Sjoerg /// 411*e038c9c4Sjoerg /// The SelectorOffsets table refers into this memory. 412*e038c9c4Sjoerg const unsigned char *SelectorLookupTableData = nullptr; 413*e038c9c4Sjoerg 414*e038c9c4Sjoerg /// A pointer to an on-disk hash table of opaque type 415*e038c9c4Sjoerg /// ASTSelectorLookupTable. 416*e038c9c4Sjoerg /// 417*e038c9c4Sjoerg /// This hash table provides the IDs of all selectors, and the associated 418*e038c9c4Sjoerg /// instance and factory methods. 419*e038c9c4Sjoerg void *SelectorLookupTable = nullptr; 420*e038c9c4Sjoerg 421*e038c9c4Sjoerg // === Declarations === 422*e038c9c4Sjoerg 423*e038c9c4Sjoerg /// DeclsCursor - This is a cursor to the start of the DECLTYPES_BLOCK block. 424*e038c9c4Sjoerg /// It has read all the abbreviations at the start of the block and is ready 425*e038c9c4Sjoerg /// to jump around with these in context. 426*e038c9c4Sjoerg llvm::BitstreamCursor DeclsCursor; 427*e038c9c4Sjoerg 428*e038c9c4Sjoerg /// The offset to the start of the DECLTYPES_BLOCK block. 429*e038c9c4Sjoerg uint64_t DeclsBlockStartOffset = 0; 430*e038c9c4Sjoerg 431*e038c9c4Sjoerg /// The number of declarations in this AST file. 432*e038c9c4Sjoerg unsigned LocalNumDecls = 0; 433*e038c9c4Sjoerg 434*e038c9c4Sjoerg /// Offset of each declaration within the bitstream, indexed 435*e038c9c4Sjoerg /// by the declaration ID (-1). 436*e038c9c4Sjoerg const DeclOffset *DeclOffsets = nullptr; 437*e038c9c4Sjoerg 438*e038c9c4Sjoerg /// Base declaration ID for declarations local to this module. 439*e038c9c4Sjoerg serialization::DeclID BaseDeclID = 0; 440*e038c9c4Sjoerg 441*e038c9c4Sjoerg /// Remapping table for declaration IDs in this module. 442*e038c9c4Sjoerg ContinuousRangeMap<uint32_t, int, 2> DeclRemap; 443*e038c9c4Sjoerg 444*e038c9c4Sjoerg /// Mapping from the module files that this module file depends on 445*e038c9c4Sjoerg /// to the base declaration ID for that module as it is understood within this 446*e038c9c4Sjoerg /// module. 447*e038c9c4Sjoerg /// 448*e038c9c4Sjoerg /// This is effectively a reverse global-to-local mapping for declaration 449*e038c9c4Sjoerg /// IDs, so that we can interpret a true global ID (for this translation unit) 450*e038c9c4Sjoerg /// as a local ID (for this module file). 451*e038c9c4Sjoerg llvm::DenseMap<ModuleFile *, serialization::DeclID> GlobalToLocalDeclIDs; 452*e038c9c4Sjoerg 453*e038c9c4Sjoerg /// Array of file-level DeclIDs sorted by file. 454*e038c9c4Sjoerg const serialization::DeclID *FileSortedDecls = nullptr; 455*e038c9c4Sjoerg unsigned NumFileSortedDecls = 0; 456*e038c9c4Sjoerg 457*e038c9c4Sjoerg /// Array of category list location information within this 458*e038c9c4Sjoerg /// module file, sorted by the definition ID. 459*e038c9c4Sjoerg const serialization::ObjCCategoriesInfo *ObjCCategoriesMap = nullptr; 460*e038c9c4Sjoerg 461*e038c9c4Sjoerg /// The number of redeclaration info entries in ObjCCategoriesMap. 462*e038c9c4Sjoerg unsigned LocalNumObjCCategoriesInMap = 0; 463*e038c9c4Sjoerg 464*e038c9c4Sjoerg /// The Objective-C category lists for categories known to this 465*e038c9c4Sjoerg /// module. 466*e038c9c4Sjoerg SmallVector<uint64_t, 1> ObjCCategories; 467*e038c9c4Sjoerg 468*e038c9c4Sjoerg // === Types === 469*e038c9c4Sjoerg 470*e038c9c4Sjoerg /// The number of types in this AST file. 471*e038c9c4Sjoerg unsigned LocalNumTypes = 0; 472*e038c9c4Sjoerg 473*e038c9c4Sjoerg /// Offset of each type within the bitstream, indexed by the 474*e038c9c4Sjoerg /// type ID, or the representation of a Type*. 475*e038c9c4Sjoerg const UnderalignedInt64 *TypeOffsets = nullptr; 476*e038c9c4Sjoerg 477*e038c9c4Sjoerg /// Base type ID for types local to this module as represented in 478*e038c9c4Sjoerg /// the global type ID space. 479*e038c9c4Sjoerg serialization::TypeID BaseTypeIndex = 0; 480*e038c9c4Sjoerg 481*e038c9c4Sjoerg /// Remapping table for type IDs in this module. 482*e038c9c4Sjoerg ContinuousRangeMap<uint32_t, int, 2> TypeRemap; 483*e038c9c4Sjoerg 484*e038c9c4Sjoerg // === Miscellaneous === 485*e038c9c4Sjoerg 486*e038c9c4Sjoerg /// Diagnostic IDs and their mappings that the user changed. 487*e038c9c4Sjoerg SmallVector<uint64_t, 8> PragmaDiagMappings; 488*e038c9c4Sjoerg 489*e038c9c4Sjoerg /// List of modules which depend on this module 490*e038c9c4Sjoerg llvm::SetVector<ModuleFile *> ImportedBy; 491*e038c9c4Sjoerg 492*e038c9c4Sjoerg /// List of modules which this module depends on 493*e038c9c4Sjoerg llvm::SetVector<ModuleFile *> Imports; 494*e038c9c4Sjoerg 495*e038c9c4Sjoerg /// Determine whether this module was directly imported at 496*e038c9c4Sjoerg /// any point during translation. isDirectlyImported()497*e038c9c4Sjoerg bool isDirectlyImported() const { return DirectlyImported; } 498*e038c9c4Sjoerg 499*e038c9c4Sjoerg /// Is this a module file for a module (rather than a PCH or similar). isModule()500*e038c9c4Sjoerg bool isModule() const { 501*e038c9c4Sjoerg return Kind == MK_ImplicitModule || Kind == MK_ExplicitModule || 502*e038c9c4Sjoerg Kind == MK_PrebuiltModule; 503*e038c9c4Sjoerg } 504*e038c9c4Sjoerg 505*e038c9c4Sjoerg /// Dump debugging output for this module. 506*e038c9c4Sjoerg void dump(); 507*e038c9c4Sjoerg }; 508*e038c9c4Sjoerg 509*e038c9c4Sjoerg } // namespace serialization 510*e038c9c4Sjoerg 511*e038c9c4Sjoerg } // namespace clang 512*e038c9c4Sjoerg 513*e038c9c4Sjoerg #endif // LLVM_CLANG_SERIALIZATION_MODULEFILE_H 514