1*480093f4SDimitry Andric //===- ModuleFile.cpp - Module description --------------------------------===//
2*480093f4SDimitry Andric //
3*480093f4SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*480093f4SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*480093f4SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*480093f4SDimitry Andric //
7*480093f4SDimitry Andric //===----------------------------------------------------------------------===//
8*480093f4SDimitry Andric //
9*480093f4SDimitry Andric //  This file implements the ModuleFile class, which describes a module that
10*480093f4SDimitry Andric //  has been loaded from an AST file.
11*480093f4SDimitry Andric //
12*480093f4SDimitry Andric //===----------------------------------------------------------------------===//
13*480093f4SDimitry Andric 
14*480093f4SDimitry Andric #include "clang/Serialization/ModuleFile.h"
15*480093f4SDimitry Andric #include "ASTReaderInternals.h"
16*480093f4SDimitry Andric #include "clang/Serialization/ContinuousRangeMap.h"
17*480093f4SDimitry Andric #include "llvm/ADT/StringRef.h"
18*480093f4SDimitry Andric #include "llvm/Support/Compiler.h"
19*480093f4SDimitry Andric #include "llvm/Support/raw_ostream.h"
20*480093f4SDimitry Andric 
21*480093f4SDimitry Andric using namespace clang;
22*480093f4SDimitry Andric using namespace serialization;
23*480093f4SDimitry Andric using namespace reader;
24*480093f4SDimitry Andric 
~ModuleFile()25*480093f4SDimitry Andric ModuleFile::~ModuleFile() {
26*480093f4SDimitry Andric   delete static_cast<ASTIdentifierLookupTable *>(IdentifierLookupTable);
27*480093f4SDimitry Andric   delete static_cast<HeaderFileInfoLookupTable *>(HeaderFileInfoTable);
28*480093f4SDimitry Andric   delete static_cast<ASTSelectorLookupTable *>(SelectorLookupTable);
29*480093f4SDimitry Andric }
30*480093f4SDimitry Andric 
31*480093f4SDimitry Andric template<typename Key, typename Offset, unsigned InitialCapacity>
32*480093f4SDimitry Andric static void
dumpLocalRemap(StringRef Name,const ContinuousRangeMap<Key,Offset,InitialCapacity> & Map)33*480093f4SDimitry Andric dumpLocalRemap(StringRef Name,
34*480093f4SDimitry Andric                const ContinuousRangeMap<Key, Offset, InitialCapacity> &Map) {
35*480093f4SDimitry Andric   if (Map.begin() == Map.end())
36*480093f4SDimitry Andric     return;
37*480093f4SDimitry Andric 
38*480093f4SDimitry Andric   using MapType = ContinuousRangeMap<Key, Offset, InitialCapacity>;
39*480093f4SDimitry Andric 
40*480093f4SDimitry Andric   llvm::errs() << "  " << Name << ":\n";
41*480093f4SDimitry Andric   for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end();
42*480093f4SDimitry Andric        I != IEnd; ++I) {
43*480093f4SDimitry Andric     llvm::errs() << "    " << I->first << " -> " << I->second << "\n";
44*480093f4SDimitry Andric   }
45*480093f4SDimitry Andric }
46*480093f4SDimitry Andric 
dump()47*480093f4SDimitry Andric LLVM_DUMP_METHOD void ModuleFile::dump() {
48*480093f4SDimitry Andric   llvm::errs() << "\nModule: " << FileName << "\n";
49*480093f4SDimitry Andric   if (!Imports.empty()) {
50*480093f4SDimitry Andric     llvm::errs() << "  Imports: ";
51*480093f4SDimitry Andric     for (unsigned I = 0, N = Imports.size(); I != N; ++I) {
52*480093f4SDimitry Andric       if (I)
53*480093f4SDimitry Andric         llvm::errs() << ", ";
54*480093f4SDimitry Andric       llvm::errs() << Imports[I]->FileName;
55*480093f4SDimitry Andric     }
56*480093f4SDimitry Andric     llvm::errs() << "\n";
57*480093f4SDimitry Andric   }
58*480093f4SDimitry Andric 
59*480093f4SDimitry Andric   // Remapping tables.
60*480093f4SDimitry Andric   llvm::errs() << "  Base source location offset: " << SLocEntryBaseOffset
61*480093f4SDimitry Andric                << '\n';
62*480093f4SDimitry Andric   dumpLocalRemap("Source location offset local -> global map", SLocRemap);
63*480093f4SDimitry Andric 
64*480093f4SDimitry Andric   llvm::errs() << "  Base identifier ID: " << BaseIdentifierID << '\n'
65*480093f4SDimitry Andric                << "  Number of identifiers: " << LocalNumIdentifiers << '\n';
66*480093f4SDimitry Andric   dumpLocalRemap("Identifier ID local -> global map", IdentifierRemap);
67*480093f4SDimitry Andric 
68*480093f4SDimitry Andric   llvm::errs() << "  Base macro ID: " << BaseMacroID << '\n'
69*480093f4SDimitry Andric                << "  Number of macros: " << LocalNumMacros << '\n';
70*480093f4SDimitry Andric   dumpLocalRemap("Macro ID local -> global map", MacroRemap);
71*480093f4SDimitry Andric 
72*480093f4SDimitry Andric   llvm::errs() << "  Base submodule ID: " << BaseSubmoduleID << '\n'
73*480093f4SDimitry Andric                << "  Number of submodules: " << LocalNumSubmodules << '\n';
74*480093f4SDimitry Andric   dumpLocalRemap("Submodule ID local -> global map", SubmoduleRemap);
75*480093f4SDimitry Andric 
76*480093f4SDimitry Andric   llvm::errs() << "  Base selector ID: " << BaseSelectorID << '\n'
77*480093f4SDimitry Andric                << "  Number of selectors: " << LocalNumSelectors << '\n';
78*480093f4SDimitry Andric   dumpLocalRemap("Selector ID local -> global map", SelectorRemap);
79*480093f4SDimitry Andric 
80*480093f4SDimitry Andric   llvm::errs() << "  Base preprocessed entity ID: " << BasePreprocessedEntityID
81*480093f4SDimitry Andric                << '\n'
82*480093f4SDimitry Andric                << "  Number of preprocessed entities: "
83*480093f4SDimitry Andric                << NumPreprocessedEntities << '\n';
84*480093f4SDimitry Andric   dumpLocalRemap("Preprocessed entity ID local -> global map",
85*480093f4SDimitry Andric                  PreprocessedEntityRemap);
86*480093f4SDimitry Andric 
87*480093f4SDimitry Andric   llvm::errs() << "  Base type index: " << BaseTypeIndex << '\n'
88*480093f4SDimitry Andric                << "  Number of types: " << LocalNumTypes << '\n';
89*480093f4SDimitry Andric   dumpLocalRemap("Type index local -> global map", TypeRemap);
90*480093f4SDimitry Andric 
91*480093f4SDimitry Andric   llvm::errs() << "  Base decl ID: " << BaseDeclID << '\n'
92*480093f4SDimitry Andric                << "  Number of decls: " << LocalNumDecls << '\n';
93*480093f4SDimitry Andric   dumpLocalRemap("Decl ID local -> global map", DeclRemap);
94*480093f4SDimitry Andric }
95