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