13a02247dSChandler Carruth //===--- Module.cpp - Describe a module -----------------------------------===//
2de3ef502SDouglas Gregor //
3de3ef502SDouglas Gregor //                     The LLVM Compiler Infrastructure
4de3ef502SDouglas Gregor //
5de3ef502SDouglas Gregor // This file is distributed under the University of Illinois Open Source
6de3ef502SDouglas Gregor // License. See LICENSE.TXT for details.
7de3ef502SDouglas Gregor //
8de3ef502SDouglas Gregor //===----------------------------------------------------------------------===//
9de3ef502SDouglas Gregor //
10de3ef502SDouglas Gregor // This file defines the Module class, which describes a module in the source
11de3ef502SDouglas Gregor // code.
12de3ef502SDouglas Gregor //
13de3ef502SDouglas Gregor //===----------------------------------------------------------------------===//
14de3ef502SDouglas Gregor #include "clang/Basic/Module.h"
15de3ef502SDouglas Gregor #include "clang/Basic/FileManager.h"
161fb5c3a6SDouglas Gregor #include "clang/Basic/LangOptions.h"
170070c0bfSDouglas Gregor #include "clang/Basic/TargetInfo.h"
183c5305c1SArgyrios Kyrtzidis #include "llvm/ADT/ArrayRef.h"
191fb5c3a6SDouglas Gregor #include "llvm/ADT/SmallVector.h"
201fb5c3a6SDouglas Gregor #include "llvm/ADT/StringSwitch.h"
213a02247dSChandler Carruth #include "llvm/Support/ErrorHandling.h"
223a02247dSChandler Carruth #include "llvm/Support/raw_ostream.h"
23de3ef502SDouglas Gregor using namespace clang;
24de3ef502SDouglas Gregor 
25eb90e830SDouglas Gregor Module::Module(StringRef Name, SourceLocation DefinitionLoc, Module *Parent,
26eb90e830SDouglas Gregor                bool IsFramework, bool IsExplicit)
27eb90e830SDouglas Gregor   : Name(Name), DefinitionLoc(DefinitionLoc), Parent(Parent),
2843af5132SArgyrios Kyrtzidis     Umbrella(), ASTFile(0), IsAvailable(true), IsFromModuleFile(false),
29a686e1b0SDouglas Gregor     IsFramework(IsFramework), IsExplicit(IsExplicit), IsSystem(false),
30a686e1b0SDouglas Gregor     InferSubmodules(false), InferExplicitSubmodules(false),
318d932427SDouglas Gregor     InferExportWildcard(false), ConfigMacrosExhaustive(false),
328d932427SDouglas Gregor     NameVisibility(Hidden)
33eb90e830SDouglas Gregor {
34eb90e830SDouglas Gregor   if (Parent) {
35eb90e830SDouglas Gregor     if (!Parent->isAvailable())
36eb90e830SDouglas Gregor       IsAvailable = false;
373ec6663bSDouglas Gregor     if (Parent->IsSystem)
383ec6663bSDouglas Gregor       IsSystem = true;
39eb90e830SDouglas Gregor 
40eb90e830SDouglas Gregor     Parent->SubModuleIndex[Name] = Parent->SubModules.size();
41eb90e830SDouglas Gregor     Parent->SubModules.push_back(this);
42eb90e830SDouglas Gregor   }
43eb90e830SDouglas Gregor }
44eb90e830SDouglas Gregor 
45de3ef502SDouglas Gregor Module::~Module() {
46eb90e830SDouglas Gregor   for (submodule_iterator I = submodule_begin(), IEnd = submodule_end();
47de3ef502SDouglas Gregor        I != IEnd; ++I) {
48eb90e830SDouglas Gregor     delete *I;
49de3ef502SDouglas Gregor   }
50de3ef502SDouglas Gregor }
51de3ef502SDouglas Gregor 
521fb5c3a6SDouglas Gregor /// \brief Determine whether a translation unit built using the current
531fb5c3a6SDouglas Gregor /// language options has the given feature.
5489929282SDouglas Gregor static bool hasFeature(StringRef Feature, const LangOptions &LangOpts,
5589929282SDouglas Gregor                        const TargetInfo &Target) {
561fb5c3a6SDouglas Gregor   return llvm::StringSwitch<bool>(Feature)
570070c0bfSDouglas Gregor            .Case("altivec", LangOpts.AltiVec)
581fb5c3a6SDouglas Gregor            .Case("blocks", LangOpts.Blocks)
591fb5c3a6SDouglas Gregor            .Case("cplusplus", LangOpts.CPlusPlus)
602bf7fdb7SRichard Smith            .Case("cplusplus11", LangOpts.CPlusPlus11)
611fb5c3a6SDouglas Gregor            .Case("objc", LangOpts.ObjC1)
621fb5c3a6SDouglas Gregor            .Case("objc_arc", LangOpts.ObjCAutoRefCount)
630070c0bfSDouglas Gregor            .Case("opencl", LangOpts.OpenCL)
640070c0bfSDouglas Gregor            .Case("tls", Target.isTLSSupported())
650070c0bfSDouglas Gregor            .Default(Target.hasFeature(Feature));
661fb5c3a6SDouglas Gregor }
671fb5c3a6SDouglas Gregor 
681fb5c3a6SDouglas Gregor bool
6989929282SDouglas Gregor Module::isAvailable(const LangOptions &LangOpts, const TargetInfo &Target,
7089929282SDouglas Gregor                     StringRef &Feature) const {
711fb5c3a6SDouglas Gregor   if (IsAvailable)
721fb5c3a6SDouglas Gregor     return true;
731fb5c3a6SDouglas Gregor 
741fb5c3a6SDouglas Gregor   for (const Module *Current = this; Current; Current = Current->Parent) {
751fb5c3a6SDouglas Gregor     for (unsigned I = 0, N = Current->Requires.size(); I != N; ++I) {
7689929282SDouglas Gregor       if (!hasFeature(Current->Requires[I], LangOpts, Target)) {
771fb5c3a6SDouglas Gregor         Feature = Current->Requires[I];
781fb5c3a6SDouglas Gregor         return false;
791fb5c3a6SDouglas Gregor       }
801fb5c3a6SDouglas Gregor     }
811fb5c3a6SDouglas Gregor   }
821fb5c3a6SDouglas Gregor 
831fb5c3a6SDouglas Gregor   llvm_unreachable("could not find a reason why module is unavailable");
841fb5c3a6SDouglas Gregor }
851fb5c3a6SDouglas Gregor 
86f5eedd05SDouglas Gregor bool Module::isSubModuleOf(Module *Other) const {
87f5eedd05SDouglas Gregor   const Module *This = this;
88f5eedd05SDouglas Gregor   do {
89f5eedd05SDouglas Gregor     if (This == Other)
90f5eedd05SDouglas Gregor       return true;
91f5eedd05SDouglas Gregor 
92f5eedd05SDouglas Gregor     This = This->Parent;
93f5eedd05SDouglas Gregor   } while (This);
94f5eedd05SDouglas Gregor 
95f5eedd05SDouglas Gregor   return false;
96f5eedd05SDouglas Gregor }
97f5eedd05SDouglas Gregor 
9873441091SDouglas Gregor const Module *Module::getTopLevelModule() const {
9973441091SDouglas Gregor   const Module *Result = this;
10073441091SDouglas Gregor   while (Result->Parent)
10173441091SDouglas Gregor     Result = Result->Parent;
10273441091SDouglas Gregor 
10373441091SDouglas Gregor   return Result;
10473441091SDouglas Gregor }
10573441091SDouglas Gregor 
106de3ef502SDouglas Gregor std::string Module::getFullModuleName() const {
107f857950dSDmitri Gribenko   SmallVector<StringRef, 2> Names;
108de3ef502SDouglas Gregor 
109de3ef502SDouglas Gregor   // Build up the set of module names (from innermost to outermost).
110de3ef502SDouglas Gregor   for (const Module *M = this; M; M = M->Parent)
111de3ef502SDouglas Gregor     Names.push_back(M->Name);
112de3ef502SDouglas Gregor 
113de3ef502SDouglas Gregor   std::string Result;
11461ac906bSCraig Topper   for (SmallVectorImpl<StringRef>::reverse_iterator I = Names.rbegin(),
115de3ef502SDouglas Gregor                                                  IEnd = Names.rend();
116de3ef502SDouglas Gregor        I != IEnd; ++I) {
117de3ef502SDouglas Gregor     if (!Result.empty())
118de3ef502SDouglas Gregor       Result += '.';
119de3ef502SDouglas Gregor 
120de3ef502SDouglas Gregor     Result += *I;
121de3ef502SDouglas Gregor   }
122de3ef502SDouglas Gregor 
123de3ef502SDouglas Gregor   return Result;
124de3ef502SDouglas Gregor }
125de3ef502SDouglas Gregor 
12673141fa9SDouglas Gregor const DirectoryEntry *Module::getUmbrellaDir() const {
12773141fa9SDouglas Gregor   if (const FileEntry *Header = getUmbrellaHeader())
12873141fa9SDouglas Gregor     return Header->getDir();
12973141fa9SDouglas Gregor 
13073141fa9SDouglas Gregor   return Umbrella.dyn_cast<const DirectoryEntry *>();
13173141fa9SDouglas Gregor }
13273141fa9SDouglas Gregor 
1333c5305c1SArgyrios Kyrtzidis ArrayRef<const FileEntry *> Module::getTopHeaders(FileManager &FileMgr) {
1343c5305c1SArgyrios Kyrtzidis   if (!TopHeaderNames.empty()) {
1353c5305c1SArgyrios Kyrtzidis     for (std::vector<std::string>::iterator
1363c5305c1SArgyrios Kyrtzidis            I = TopHeaderNames.begin(), E = TopHeaderNames.end(); I != E; ++I) {
1373c5305c1SArgyrios Kyrtzidis       if (const FileEntry *FE = FileMgr.getFile(*I))
1383c5305c1SArgyrios Kyrtzidis         TopHeaders.insert(FE);
1393c5305c1SArgyrios Kyrtzidis     }
1403c5305c1SArgyrios Kyrtzidis     TopHeaderNames.clear();
1413c5305c1SArgyrios Kyrtzidis   }
1423c5305c1SArgyrios Kyrtzidis 
1433c5305c1SArgyrios Kyrtzidis   return llvm::makeArrayRef(TopHeaders.begin(), TopHeaders.end());
1443c5305c1SArgyrios Kyrtzidis }
1453c5305c1SArgyrios Kyrtzidis 
14689929282SDouglas Gregor void Module::addRequirement(StringRef Feature, const LangOptions &LangOpts,
14789929282SDouglas Gregor                             const TargetInfo &Target) {
1481fb5c3a6SDouglas Gregor   Requires.push_back(Feature);
1491fb5c3a6SDouglas Gregor 
1501fb5c3a6SDouglas Gregor   // If this feature is currently available, we're done.
15189929282SDouglas Gregor   if (hasFeature(Feature, LangOpts, Target))
1521fb5c3a6SDouglas Gregor     return;
1531fb5c3a6SDouglas Gregor 
1541fb5c3a6SDouglas Gregor   if (!IsAvailable)
1551fb5c3a6SDouglas Gregor     return;
1561fb5c3a6SDouglas Gregor 
157f857950dSDmitri Gribenko   SmallVector<Module *, 2> Stack;
1581fb5c3a6SDouglas Gregor   Stack.push_back(this);
1591fb5c3a6SDouglas Gregor   while (!Stack.empty()) {
1601fb5c3a6SDouglas Gregor     Module *Current = Stack.back();
1611fb5c3a6SDouglas Gregor     Stack.pop_back();
1621fb5c3a6SDouglas Gregor 
1631fb5c3a6SDouglas Gregor     if (!Current->IsAvailable)
1641fb5c3a6SDouglas Gregor       continue;
1651fb5c3a6SDouglas Gregor 
1661fb5c3a6SDouglas Gregor     Current->IsAvailable = false;
167eb90e830SDouglas Gregor     for (submodule_iterator Sub = Current->submodule_begin(),
168eb90e830SDouglas Gregor                          SubEnd = Current->submodule_end();
1691fb5c3a6SDouglas Gregor          Sub != SubEnd; ++Sub) {
170eb90e830SDouglas Gregor       if ((*Sub)->IsAvailable)
171eb90e830SDouglas Gregor         Stack.push_back(*Sub);
1721fb5c3a6SDouglas Gregor     }
1731fb5c3a6SDouglas Gregor   }
1741fb5c3a6SDouglas Gregor }
1751fb5c3a6SDouglas Gregor 
176eb90e830SDouglas Gregor Module *Module::findSubmodule(StringRef Name) const {
177eb90e830SDouglas Gregor   llvm::StringMap<unsigned>::const_iterator Pos = SubModuleIndex.find(Name);
178eb90e830SDouglas Gregor   if (Pos == SubModuleIndex.end())
179eb90e830SDouglas Gregor     return 0;
180eb90e830SDouglas Gregor 
181eb90e830SDouglas Gregor   return SubModules[Pos->getValue()];
182eb90e830SDouglas Gregor }
183eb90e830SDouglas Gregor 
184f857950dSDmitri Gribenko static void printModuleId(raw_ostream &OS, const ModuleId &Id) {
18524bb923aSDouglas Gregor   for (unsigned I = 0, N = Id.size(); I != N; ++I) {
18624bb923aSDouglas Gregor     if (I)
18724bb923aSDouglas Gregor       OS << ".";
18824bb923aSDouglas Gregor     OS << Id[I].first;
18924bb923aSDouglas Gregor   }
19024bb923aSDouglas Gregor }
19124bb923aSDouglas Gregor 
1928739f7b7SArgyrios Kyrtzidis void Module::getExportedModules(SmallVectorImpl<Module *> &Exported) const {
1938739f7b7SArgyrios Kyrtzidis   bool AnyWildcard = false;
1948739f7b7SArgyrios Kyrtzidis   bool UnrestrictedWildcard = false;
1958739f7b7SArgyrios Kyrtzidis   SmallVector<Module *, 4> WildcardRestrictions;
1968739f7b7SArgyrios Kyrtzidis   for (unsigned I = 0, N = Exports.size(); I != N; ++I) {
1978739f7b7SArgyrios Kyrtzidis     Module *Mod = Exports[I].getPointer();
1988739f7b7SArgyrios Kyrtzidis     if (!Exports[I].getInt()) {
1998739f7b7SArgyrios Kyrtzidis       // Export a named module directly; no wildcards involved.
2008739f7b7SArgyrios Kyrtzidis       Exported.push_back(Mod);
2018739f7b7SArgyrios Kyrtzidis 
2028739f7b7SArgyrios Kyrtzidis       continue;
2038739f7b7SArgyrios Kyrtzidis     }
2048739f7b7SArgyrios Kyrtzidis 
2058739f7b7SArgyrios Kyrtzidis     // Wildcard export: export all of the imported modules that match
2068739f7b7SArgyrios Kyrtzidis     // the given pattern.
2078739f7b7SArgyrios Kyrtzidis     AnyWildcard = true;
2088739f7b7SArgyrios Kyrtzidis     if (UnrestrictedWildcard)
2098739f7b7SArgyrios Kyrtzidis       continue;
2108739f7b7SArgyrios Kyrtzidis 
2118739f7b7SArgyrios Kyrtzidis     if (Module *Restriction = Exports[I].getPointer())
2128739f7b7SArgyrios Kyrtzidis       WildcardRestrictions.push_back(Restriction);
2138739f7b7SArgyrios Kyrtzidis     else {
2148739f7b7SArgyrios Kyrtzidis       WildcardRestrictions.clear();
2158739f7b7SArgyrios Kyrtzidis       UnrestrictedWildcard = true;
2168739f7b7SArgyrios Kyrtzidis     }
2178739f7b7SArgyrios Kyrtzidis   }
2188739f7b7SArgyrios Kyrtzidis 
2198739f7b7SArgyrios Kyrtzidis   // If there were any wildcards, push any imported modules that were
2208739f7b7SArgyrios Kyrtzidis   // re-exported by the wildcard restriction.
2218739f7b7SArgyrios Kyrtzidis   if (!AnyWildcard)
2228739f7b7SArgyrios Kyrtzidis     return;
2238739f7b7SArgyrios Kyrtzidis 
2248739f7b7SArgyrios Kyrtzidis   for (unsigned I = 0, N = Imports.size(); I != N; ++I) {
2258739f7b7SArgyrios Kyrtzidis     Module *Mod = Imports[I];
2268739f7b7SArgyrios Kyrtzidis     bool Acceptable = UnrestrictedWildcard;
2278739f7b7SArgyrios Kyrtzidis     if (!Acceptable) {
2288739f7b7SArgyrios Kyrtzidis       // Check whether this module meets one of the restrictions.
2298739f7b7SArgyrios Kyrtzidis       for (unsigned R = 0, NR = WildcardRestrictions.size(); R != NR; ++R) {
2308739f7b7SArgyrios Kyrtzidis         Module *Restriction = WildcardRestrictions[R];
2318739f7b7SArgyrios Kyrtzidis         if (Mod == Restriction || Mod->isSubModuleOf(Restriction)) {
2328739f7b7SArgyrios Kyrtzidis           Acceptable = true;
2338739f7b7SArgyrios Kyrtzidis           break;
2348739f7b7SArgyrios Kyrtzidis         }
2358739f7b7SArgyrios Kyrtzidis       }
2368739f7b7SArgyrios Kyrtzidis     }
2378739f7b7SArgyrios Kyrtzidis 
2388739f7b7SArgyrios Kyrtzidis     if (!Acceptable)
2398739f7b7SArgyrios Kyrtzidis       continue;
2408739f7b7SArgyrios Kyrtzidis 
2418739f7b7SArgyrios Kyrtzidis     Exported.push_back(Mod);
2428739f7b7SArgyrios Kyrtzidis   }
2438739f7b7SArgyrios Kyrtzidis }
2448739f7b7SArgyrios Kyrtzidis 
2450e5d7b8cSRichard Smith void Module::buildVisibleModulesCache() const {
2460e5d7b8cSRichard Smith   assert(VisibleModulesCache.empty() && "cache does not need building");
2470e5d7b8cSRichard Smith 
2480e5d7b8cSRichard Smith   // This module is visible to itself.
2490e5d7b8cSRichard Smith   VisibleModulesCache.insert(this);
2500e5d7b8cSRichard Smith 
2510e5d7b8cSRichard Smith   llvm::SmallVector<Module*, 4> Exported;
2520e5d7b8cSRichard Smith   for (unsigned I = 0, N = Imports.size(); I != N; ++I) {
2530e5d7b8cSRichard Smith     // Every imported module is visible.
2540e5d7b8cSRichard Smith     VisibleModulesCache.insert(Imports[I]);
2550e5d7b8cSRichard Smith 
2560e5d7b8cSRichard Smith     // Every module exported by an imported module is visible.
2570e5d7b8cSRichard Smith     Imports[I]->getExportedModules(Exported);
2580e5d7b8cSRichard Smith     VisibleModulesCache.insert(Exported.begin(), Exported.end());
2590e5d7b8cSRichard Smith     Exported.clear();
2600e5d7b8cSRichard Smith   }
2610e5d7b8cSRichard Smith }
2620e5d7b8cSRichard Smith 
263f857950dSDmitri Gribenko void Module::print(raw_ostream &OS, unsigned Indent) const {
264de3ef502SDouglas Gregor   OS.indent(Indent);
265de3ef502SDouglas Gregor   if (IsFramework)
266de3ef502SDouglas Gregor     OS << "framework ";
267de3ef502SDouglas Gregor   if (IsExplicit)
268de3ef502SDouglas Gregor     OS << "explicit ";
269a686e1b0SDouglas Gregor   OS << "module " << Name;
270a686e1b0SDouglas Gregor 
271a686e1b0SDouglas Gregor   if (IsSystem) {
272a686e1b0SDouglas Gregor     OS.indent(Indent + 2);
273a686e1b0SDouglas Gregor     OS << " [system]";
274a686e1b0SDouglas Gregor   }
275a686e1b0SDouglas Gregor 
276a686e1b0SDouglas Gregor   OS << " {\n";
277de3ef502SDouglas Gregor 
2781fb5c3a6SDouglas Gregor   if (!Requires.empty()) {
2791fb5c3a6SDouglas Gregor     OS.indent(Indent + 2);
2801fb5c3a6SDouglas Gregor     OS << "requires ";
2811fb5c3a6SDouglas Gregor     for (unsigned I = 0, N = Requires.size(); I != N; ++I) {
2821fb5c3a6SDouglas Gregor       if (I)
2831fb5c3a6SDouglas Gregor         OS << ", ";
2841fb5c3a6SDouglas Gregor       OS << Requires[I];
2851fb5c3a6SDouglas Gregor     }
2861fb5c3a6SDouglas Gregor     OS << "\n";
2871fb5c3a6SDouglas Gregor   }
2881fb5c3a6SDouglas Gregor 
28973141fa9SDouglas Gregor   if (const FileEntry *UmbrellaHeader = getUmbrellaHeader()) {
290de3ef502SDouglas Gregor     OS.indent(Indent + 2);
291322f633cSDouglas Gregor     OS << "umbrella header \"";
292de3ef502SDouglas Gregor     OS.write_escaped(UmbrellaHeader->getName());
293de3ef502SDouglas Gregor     OS << "\"\n";
294322f633cSDouglas Gregor   } else if (const DirectoryEntry *UmbrellaDir = getUmbrellaDir()) {
295322f633cSDouglas Gregor     OS.indent(Indent + 2);
296322f633cSDouglas Gregor     OS << "umbrella \"";
297322f633cSDouglas Gregor     OS.write_escaped(UmbrellaDir->getName());
298322f633cSDouglas Gregor     OS << "\"\n";
299de3ef502SDouglas Gregor   }
300de3ef502SDouglas Gregor 
30135b13eceSDouglas Gregor   if (!ConfigMacros.empty() || ConfigMacrosExhaustive) {
30235b13eceSDouglas Gregor     OS.indent(Indent + 2);
30335b13eceSDouglas Gregor     OS << "config_macros ";
30435b13eceSDouglas Gregor     if (ConfigMacrosExhaustive)
3058d932427SDouglas Gregor       OS << "[exhaustive]";
30635b13eceSDouglas Gregor     for (unsigned I = 0, N = ConfigMacros.size(); I != N; ++I) {
30735b13eceSDouglas Gregor       if (I)
30835b13eceSDouglas Gregor         OS << ", ";
30935b13eceSDouglas Gregor       OS << ConfigMacros[I];
31035b13eceSDouglas Gregor     }
3118d932427SDouglas Gregor     OS << "\n";
31235b13eceSDouglas Gregor   }
31335b13eceSDouglas Gregor 
314b53e5483SLawrence Crowl   for (unsigned I = 0, N = NormalHeaders.size(); I != N; ++I) {
315de3ef502SDouglas Gregor     OS.indent(Indent + 2);
316de3ef502SDouglas Gregor     OS << "header \"";
317b53e5483SLawrence Crowl     OS.write_escaped(NormalHeaders[I]->getName());
318de3ef502SDouglas Gregor     OS << "\"\n";
319de3ef502SDouglas Gregor   }
32059527666SDouglas Gregor 
32159527666SDouglas Gregor   for (unsigned I = 0, N = ExcludedHeaders.size(); I != N; ++I) {
32259527666SDouglas Gregor     OS.indent(Indent + 2);
32359527666SDouglas Gregor     OS << "exclude header \"";
32459527666SDouglas Gregor     OS.write_escaped(ExcludedHeaders[I]->getName());
32559527666SDouglas Gregor     OS << "\"\n";
32659527666SDouglas Gregor   }
327de3ef502SDouglas Gregor 
328b53e5483SLawrence Crowl   for (unsigned I = 0, N = PrivateHeaders.size(); I != N; ++I) {
329b53e5483SLawrence Crowl     OS.indent(Indent + 2);
330b53e5483SLawrence Crowl     OS << "private header \"";
331b53e5483SLawrence Crowl     OS.write_escaped(PrivateHeaders[I]->getName());
332b53e5483SLawrence Crowl     OS << "\"\n";
333b53e5483SLawrence Crowl   }
334b53e5483SLawrence Crowl 
335eb90e830SDouglas Gregor   for (submodule_const_iterator MI = submodule_begin(), MIEnd = submodule_end();
336de3ef502SDouglas Gregor        MI != MIEnd; ++MI)
337eb90e830SDouglas Gregor     (*MI)->print(OS, Indent + 2);
338de3ef502SDouglas Gregor 
33924bb923aSDouglas Gregor   for (unsigned I = 0, N = Exports.size(); I != N; ++I) {
34024bb923aSDouglas Gregor     OS.indent(Indent + 2);
3418c7c8352SDouglas Gregor     OS << "export ";
3428c7c8352SDouglas Gregor     if (Module *Restriction = Exports[I].getPointer()) {
3438c7c8352SDouglas Gregor       OS << Restriction->getFullModuleName();
34424bb923aSDouglas Gregor       if (Exports[I].getInt())
34524bb923aSDouglas Gregor         OS << ".*";
3468c7c8352SDouglas Gregor     } else {
3478c7c8352SDouglas Gregor       OS << "*";
3488c7c8352SDouglas Gregor     }
34924bb923aSDouglas Gregor     OS << "\n";
35024bb923aSDouglas Gregor   }
35124bb923aSDouglas Gregor 
35224bb923aSDouglas Gregor   for (unsigned I = 0, N = UnresolvedExports.size(); I != N; ++I) {
35324bb923aSDouglas Gregor     OS.indent(Indent + 2);
35424bb923aSDouglas Gregor     OS << "export ";
35524bb923aSDouglas Gregor     printModuleId(OS, UnresolvedExports[I].Id);
3568c7c8352SDouglas Gregor     if (UnresolvedExports[I].Wildcard) {
3578c7c8352SDouglas Gregor       if (UnresolvedExports[I].Id.empty())
3588c7c8352SDouglas Gregor         OS << "*";
3598c7c8352SDouglas Gregor       else
36024bb923aSDouglas Gregor         OS << ".*";
3618c7c8352SDouglas Gregor     }
36224bb923aSDouglas Gregor     OS << "\n";
36324bb923aSDouglas Gregor   }
36424bb923aSDouglas Gregor 
365*ba7f2f71SDaniel Jasper   for (unsigned I = 0, N = DirectUses.size(); I != N; ++I) {
366*ba7f2f71SDaniel Jasper     OS.indent(Indent + 2);
367*ba7f2f71SDaniel Jasper     OS << "use ";
368*ba7f2f71SDaniel Jasper     OS << DirectUses[I]->getFullModuleName();
369*ba7f2f71SDaniel Jasper     OS << "\n";
370*ba7f2f71SDaniel Jasper   }
371*ba7f2f71SDaniel Jasper 
372*ba7f2f71SDaniel Jasper   for (unsigned I = 0, N = UnresolvedDirectUses.size(); I != N; ++I) {
373*ba7f2f71SDaniel Jasper     OS.indent(Indent + 2);
374*ba7f2f71SDaniel Jasper     OS << "use ";
375*ba7f2f71SDaniel Jasper     printModuleId(OS, UnresolvedDirectUses[I]);
376*ba7f2f71SDaniel Jasper     OS << "\n";
377*ba7f2f71SDaniel Jasper   }
378*ba7f2f71SDaniel Jasper 
3796ddfca91SDouglas Gregor   for (unsigned I = 0, N = LinkLibraries.size(); I != N; ++I) {
3806ddfca91SDouglas Gregor     OS.indent(Indent + 2);
3816ddfca91SDouglas Gregor     OS << "link ";
3826ddfca91SDouglas Gregor     if (LinkLibraries[I].IsFramework)
3836ddfca91SDouglas Gregor       OS << "framework ";
3846ddfca91SDouglas Gregor     OS << "\"";
3856ddfca91SDouglas Gregor     OS.write_escaped(LinkLibraries[I].Library);
3866ddfca91SDouglas Gregor     OS << "\"";
3876ddfca91SDouglas Gregor   }
3886ddfca91SDouglas Gregor 
389fb912657SDouglas Gregor   for (unsigned I = 0, N = UnresolvedConflicts.size(); I != N; ++I) {
390fb912657SDouglas Gregor     OS.indent(Indent + 2);
391fb912657SDouglas Gregor     OS << "conflict ";
392fb912657SDouglas Gregor     printModuleId(OS, UnresolvedConflicts[I].Id);
393fb912657SDouglas Gregor     OS << ", \"";
394fb912657SDouglas Gregor     OS.write_escaped(UnresolvedConflicts[I].Message);
395fb912657SDouglas Gregor     OS << "\"\n";
396fb912657SDouglas Gregor   }
397fb912657SDouglas Gregor 
398fb912657SDouglas Gregor   for (unsigned I = 0, N = Conflicts.size(); I != N; ++I) {
399fb912657SDouglas Gregor     OS.indent(Indent + 2);
400fb912657SDouglas Gregor     OS << "conflict ";
401fb912657SDouglas Gregor     OS << Conflicts[I].Other->getFullModuleName();
402fb912657SDouglas Gregor     OS << ", \"";
403fb912657SDouglas Gregor     OS.write_escaped(Conflicts[I].Message);
404fb912657SDouglas Gregor     OS << "\"\n";
405fb912657SDouglas Gregor   }
406fb912657SDouglas Gregor 
40773441091SDouglas Gregor   if (InferSubmodules) {
40873441091SDouglas Gregor     OS.indent(Indent + 2);
40973441091SDouglas Gregor     if (InferExplicitSubmodules)
41073441091SDouglas Gregor       OS << "explicit ";
41173441091SDouglas Gregor     OS << "module * {\n";
41273441091SDouglas Gregor     if (InferExportWildcard) {
41373441091SDouglas Gregor       OS.indent(Indent + 4);
41473441091SDouglas Gregor       OS << "export *\n";
41573441091SDouglas Gregor     }
41673441091SDouglas Gregor     OS.indent(Indent + 2);
41773441091SDouglas Gregor     OS << "}\n";
41873441091SDouglas Gregor   }
41973441091SDouglas Gregor 
420de3ef502SDouglas Gregor   OS.indent(Indent);
421de3ef502SDouglas Gregor   OS << "}\n";
422de3ef502SDouglas Gregor }
423de3ef502SDouglas Gregor 
424de3ef502SDouglas Gregor void Module::dump() const {
425de3ef502SDouglas Gregor   print(llvm::errs());
426de3ef502SDouglas Gregor }
427de3ef502SDouglas Gregor 
428de3ef502SDouglas Gregor 
429