xref: /freebsd-src/contrib/llvm-project/clang/lib/Serialization/ModuleFile.cpp (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1480093f4SDimitry Andric //===- ModuleFile.cpp - Module description --------------------------------===//
2480093f4SDimitry Andric //
3480093f4SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4480093f4SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5480093f4SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6480093f4SDimitry Andric //
7480093f4SDimitry Andric //===----------------------------------------------------------------------===//
8480093f4SDimitry Andric //
9480093f4SDimitry Andric //  This file implements the ModuleFile class, which describes a module that
10480093f4SDimitry Andric //  has been loaded from an AST file.
11480093f4SDimitry Andric //
12480093f4SDimitry Andric //===----------------------------------------------------------------------===//
13480093f4SDimitry Andric 
14480093f4SDimitry Andric #include "clang/Serialization/ModuleFile.h"
15480093f4SDimitry Andric #include "ASTReaderInternals.h"
16480093f4SDimitry Andric #include "clang/Serialization/ContinuousRangeMap.h"
17480093f4SDimitry Andric #include "llvm/ADT/StringRef.h"
18480093f4SDimitry Andric #include "llvm/Support/Compiler.h"
19480093f4SDimitry Andric #include "llvm/Support/raw_ostream.h"
20480093f4SDimitry Andric 
21480093f4SDimitry Andric using namespace clang;
22480093f4SDimitry Andric using namespace serialization;
23480093f4SDimitry Andric using namespace reader;
24480093f4SDimitry Andric 
25480093f4SDimitry Andric ModuleFile::~ModuleFile() {
26480093f4SDimitry Andric   delete static_cast<ASTIdentifierLookupTable *>(IdentifierLookupTable);
27480093f4SDimitry Andric   delete static_cast<HeaderFileInfoLookupTable *>(HeaderFileInfoTable);
28480093f4SDimitry Andric   delete static_cast<ASTSelectorLookupTable *>(SelectorLookupTable);
29480093f4SDimitry Andric }
30480093f4SDimitry Andric 
31480093f4SDimitry Andric template<typename Key, typename Offset, unsigned InitialCapacity>
32480093f4SDimitry Andric static void
33480093f4SDimitry Andric dumpLocalRemap(StringRef Name,
34480093f4SDimitry Andric                const ContinuousRangeMap<Key, Offset, InitialCapacity> &Map) {
35480093f4SDimitry Andric   if (Map.begin() == Map.end())
36480093f4SDimitry Andric     return;
37480093f4SDimitry Andric 
38480093f4SDimitry Andric   using MapType = ContinuousRangeMap<Key, Offset, InitialCapacity>;
39480093f4SDimitry Andric 
40480093f4SDimitry Andric   llvm::errs() << "  " << Name << ":\n";
41480093f4SDimitry Andric   for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end();
42480093f4SDimitry Andric        I != IEnd; ++I) {
43480093f4SDimitry Andric     llvm::errs() << "    " << I->first << " -> " << I->second << "\n";
44480093f4SDimitry Andric   }
45480093f4SDimitry Andric }
46480093f4SDimitry Andric 
47480093f4SDimitry Andric LLVM_DUMP_METHOD void ModuleFile::dump() {
48480093f4SDimitry Andric   llvm::errs() << "\nModule: " << FileName << "\n";
49480093f4SDimitry Andric   if (!Imports.empty()) {
50480093f4SDimitry Andric     llvm::errs() << "  Imports: ";
51480093f4SDimitry Andric     for (unsigned I = 0, N = Imports.size(); I != N; ++I) {
52480093f4SDimitry Andric       if (I)
53480093f4SDimitry Andric         llvm::errs() << ", ";
54480093f4SDimitry Andric       llvm::errs() << Imports[I]->FileName;
55480093f4SDimitry Andric     }
56480093f4SDimitry Andric     llvm::errs() << "\n";
57480093f4SDimitry Andric   }
58480093f4SDimitry Andric 
59480093f4SDimitry Andric   // Remapping tables.
60480093f4SDimitry Andric   llvm::errs() << "  Base source location offset: " << SLocEntryBaseOffset
61480093f4SDimitry Andric                << '\n';
62480093f4SDimitry Andric 
63480093f4SDimitry Andric   llvm::errs() << "  Base identifier ID: " << BaseIdentifierID << '\n'
64480093f4SDimitry Andric                << "  Number of identifiers: " << LocalNumIdentifiers << '\n';
65480093f4SDimitry Andric 
66480093f4SDimitry Andric   llvm::errs() << "  Base macro ID: " << BaseMacroID << '\n'
67480093f4SDimitry Andric                << "  Number of macros: " << LocalNumMacros << '\n';
68480093f4SDimitry Andric   dumpLocalRemap("Macro ID local -> global map", MacroRemap);
69480093f4SDimitry Andric 
70480093f4SDimitry Andric   llvm::errs() << "  Base submodule ID: " << BaseSubmoduleID << '\n'
71480093f4SDimitry Andric                << "  Number of submodules: " << LocalNumSubmodules << '\n';
72480093f4SDimitry Andric   dumpLocalRemap("Submodule ID local -> global map", SubmoduleRemap);
73480093f4SDimitry Andric 
74480093f4SDimitry Andric   llvm::errs() << "  Base selector ID: " << BaseSelectorID << '\n'
75480093f4SDimitry Andric                << "  Number of selectors: " << LocalNumSelectors << '\n';
76480093f4SDimitry Andric   dumpLocalRemap("Selector ID local -> global map", SelectorRemap);
77480093f4SDimitry Andric 
78480093f4SDimitry Andric   llvm::errs() << "  Base preprocessed entity ID: " << BasePreprocessedEntityID
79480093f4SDimitry Andric                << '\n'
80480093f4SDimitry Andric                << "  Number of preprocessed entities: "
81480093f4SDimitry Andric                << NumPreprocessedEntities << '\n';
82480093f4SDimitry Andric   dumpLocalRemap("Preprocessed entity ID local -> global map",
83480093f4SDimitry Andric                  PreprocessedEntityRemap);
84480093f4SDimitry Andric 
85480093f4SDimitry Andric   llvm::errs() << "  Base type index: " << BaseTypeIndex << '\n'
86480093f4SDimitry Andric                << "  Number of types: " << LocalNumTypes << '\n';
87480093f4SDimitry Andric 
88*0fca6ea1SDimitry Andric   llvm::errs() << "  Base decl index: " << BaseDeclIndex << '\n'
89480093f4SDimitry Andric                << "  Number of decls: " << LocalNumDecls << '\n';
90480093f4SDimitry Andric }
91