xref: /src/contrib/llvm-project/clang/lib/Serialization/ModuleFile.cpp (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1706b4fc4SDimitry Andric //===- ModuleFile.cpp - Module description --------------------------------===//
236981b17SDimitry Andric //
322989816SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
422989816SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
522989816SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
636981b17SDimitry Andric //
736981b17SDimitry Andric //===----------------------------------------------------------------------===//
836981b17SDimitry Andric //
9706b4fc4SDimitry Andric //  This file implements the ModuleFile class, which describes a module that
10706b4fc4SDimitry Andric //  has been loaded from an AST file.
1136981b17SDimitry Andric //
1236981b17SDimitry Andric //===----------------------------------------------------------------------===//
1348675466SDimitry Andric 
14706b4fc4SDimitry Andric #include "clang/Serialization/ModuleFile.h"
1536981b17SDimitry Andric #include "ASTReaderInternals.h"
1648675466SDimitry Andric #include "clang/Serialization/ContinuousRangeMap.h"
1748675466SDimitry Andric #include "llvm/ADT/StringRef.h"
1848675466SDimitry Andric #include "llvm/Support/Compiler.h"
19809500fcSDimitry Andric #include "llvm/Support/raw_ostream.h"
2036981b17SDimitry Andric 
2136981b17SDimitry Andric using namespace clang;
2236981b17SDimitry Andric using namespace serialization;
2336981b17SDimitry Andric using namespace reader;
2436981b17SDimitry Andric 
~ModuleFile()25dbe13110SDimitry Andric ModuleFile::~ModuleFile() {
2636981b17SDimitry Andric   delete static_cast<ASTIdentifierLookupTable *>(IdentifierLookupTable);
2736981b17SDimitry Andric   delete static_cast<HeaderFileInfoLookupTable *>(HeaderFileInfoTable);
2836981b17SDimitry Andric   delete static_cast<ASTSelectorLookupTable *>(SelectorLookupTable);
2936981b17SDimitry Andric }
3036981b17SDimitry Andric 
3136981b17SDimitry Andric template<typename Key, typename Offset, unsigned InitialCapacity>
3236981b17SDimitry Andric static void
dumpLocalRemap(StringRef Name,const ContinuousRangeMap<Key,Offset,InitialCapacity> & Map)3336981b17SDimitry Andric dumpLocalRemap(StringRef Name,
3436981b17SDimitry Andric                const ContinuousRangeMap<Key, Offset, InitialCapacity> &Map) {
3536981b17SDimitry Andric   if (Map.begin() == Map.end())
3636981b17SDimitry Andric     return;
3736981b17SDimitry Andric 
3848675466SDimitry Andric   using MapType = ContinuousRangeMap<Key, Offset, InitialCapacity>;
3948675466SDimitry Andric 
4036981b17SDimitry Andric   llvm::errs() << "  " << Name << ":\n";
4136981b17SDimitry Andric   for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end();
4236981b17SDimitry Andric        I != IEnd; ++I) {
4336981b17SDimitry Andric     llvm::errs() << "    " << I->first << " -> " << I->second << "\n";
4436981b17SDimitry Andric   }
4536981b17SDimitry Andric }
4636981b17SDimitry Andric 
dump()472b6b257fSDimitry Andric LLVM_DUMP_METHOD void ModuleFile::dump() {
4836981b17SDimitry Andric   llvm::errs() << "\nModule: " << FileName << "\n";
4936981b17SDimitry Andric   if (!Imports.empty()) {
5036981b17SDimitry Andric     llvm::errs() << "  Imports: ";
5136981b17SDimitry Andric     for (unsigned I = 0, N = Imports.size(); I != N; ++I) {
5236981b17SDimitry Andric       if (I)
5336981b17SDimitry Andric         llvm::errs() << ", ";
5436981b17SDimitry Andric       llvm::errs() << Imports[I]->FileName;
5536981b17SDimitry Andric     }
5636981b17SDimitry Andric     llvm::errs() << "\n";
5736981b17SDimitry Andric   }
5836981b17SDimitry Andric 
5936981b17SDimitry Andric   // Remapping tables.
6036981b17SDimitry Andric   llvm::errs() << "  Base source location offset: " << SLocEntryBaseOffset
6136981b17SDimitry Andric                << '\n';
6236981b17SDimitry Andric 
6336981b17SDimitry Andric   llvm::errs() << "  Base identifier ID: " << BaseIdentifierID << '\n'
6436981b17SDimitry Andric                << "  Number of identifiers: " << LocalNumIdentifiers << '\n';
6536981b17SDimitry Andric 
6613cc256eSDimitry Andric   llvm::errs() << "  Base macro ID: " << BaseMacroID << '\n'
6713cc256eSDimitry Andric                << "  Number of macros: " << LocalNumMacros << '\n';
6813cc256eSDimitry Andric   dumpLocalRemap("Macro ID local -> global map", MacroRemap);
6913cc256eSDimitry Andric 
70dbe13110SDimitry Andric   llvm::errs() << "  Base submodule ID: " << BaseSubmoduleID << '\n'
71dbe13110SDimitry Andric                << "  Number of submodules: " << LocalNumSubmodules << '\n';
72dbe13110SDimitry Andric   dumpLocalRemap("Submodule ID local -> global map", SubmoduleRemap);
73dbe13110SDimitry Andric 
7436981b17SDimitry Andric   llvm::errs() << "  Base selector ID: " << BaseSelectorID << '\n'
7536981b17SDimitry Andric                << "  Number of selectors: " << LocalNumSelectors << '\n';
7636981b17SDimitry Andric   dumpLocalRemap("Selector ID local -> global map", SelectorRemap);
7736981b17SDimitry Andric 
7836981b17SDimitry Andric   llvm::errs() << "  Base preprocessed entity ID: " << BasePreprocessedEntityID
7936981b17SDimitry Andric                << '\n'
8036981b17SDimitry Andric                << "  Number of preprocessed entities: "
8136981b17SDimitry Andric                << NumPreprocessedEntities << '\n';
8236981b17SDimitry Andric   dumpLocalRemap("Preprocessed entity ID local -> global map",
8336981b17SDimitry Andric                  PreprocessedEntityRemap);
8436981b17SDimitry Andric 
8536981b17SDimitry Andric   llvm::errs() << "  Base type index: " << BaseTypeIndex << '\n'
8636981b17SDimitry Andric                << "  Number of types: " << LocalNumTypes << '\n';
8736981b17SDimitry Andric 
88ac9a064cSDimitry Andric   llvm::errs() << "  Base decl index: " << BaseDeclIndex << '\n'
8936981b17SDimitry Andric                << "  Number of decls: " << LocalNumDecls << '\n';
9036981b17SDimitry Andric }
91