@@ -86,6 +86,7 @@ enum class ActionType {
86
86
PrintASTNotTypeChecked,
87
87
PrintASTTypeChecked,
88
88
PrintModule,
89
+ PrintModuleMetadata,
89
90
PrintHeader,
90
91
PrintSwiftFileInterface,
91
92
PrintDecl,
@@ -181,6 +182,8 @@ Action(llvm::cl::desc("Mode:"), llvm::cl::init(ActionType::None),
181
182
" print-ast-typechecked" , " Print the typechecked AST" ),
182
183
clEnumValN(ActionType::PrintModule,
183
184
" print-module" , " Print visible declarations in a module" ),
185
+ clEnumValN(ActionType::PrintModuleMetadata,
186
+ " print-module-metadata" , " Print meta-data in a module" ),
184
187
clEnumValN(ActionType::PrintHeader,
185
188
" print-header" , " Print visible declarations in a header file" ),
186
189
clEnumValN(ActionType::PrintSwiftFileInterface,
@@ -2037,6 +2040,76 @@ static int doPrintModuleGroups(const CompilerInvocation &InitInvok,
2037
2040
return ExitCode;
2038
2041
}
2039
2042
2043
+ static void printModuleMetadata (ModuleDecl *MD) {
2044
+ auto &OS = llvm::outs ();
2045
+ MD->collectLinkLibraries ([&](LinkLibrary lib) {
2046
+ OS << " link library: " << lib.getName ()
2047
+ << " , force load: " << (lib.shouldForceLoad () ? " true" : " false" ) << " \n " ;
2048
+ });
2049
+ }
2050
+
2051
+ static int doPrintModuleMetaData (const CompilerInvocation &InitInvok,
2052
+ const std::vector<std::string> ModulesToPrint) {
2053
+ CompilerInvocation Invocation (InitInvok);
2054
+
2055
+ CompilerInstance CI;
2056
+ // Display diagnostics to stderr.
2057
+ PrintingDiagnosticConsumer PrintDiags;
2058
+ CI.addDiagnosticConsumer (&PrintDiags);
2059
+ if (CI.setup (Invocation))
2060
+ return 1 ;
2061
+ registerIDERequestFunctions (CI.getASTContext ().evaluator );
2062
+ auto &Context = CI.getASTContext ();
2063
+
2064
+ // Load standard library so that Clang importer can use it.
2065
+ auto *Stdlib = getModuleByFullName (Context, Context.StdlibModuleName );
2066
+ if (!Stdlib) {
2067
+ llvm::errs () << " Failed loading stdlib\n " ;
2068
+ return 1 ;
2069
+ }
2070
+ int ExitCode = 0 ;
2071
+ for (StringRef ModuleToPrint : ModulesToPrint) {
2072
+ if (ModuleToPrint.empty ()) {
2073
+ ExitCode = 1 ;
2074
+ continue ;
2075
+ }
2076
+
2077
+ // Get the (sub)module to print.
2078
+ auto *M = getModuleByFullName (Context, ModuleToPrint);
2079
+ if (!M) {
2080
+ llvm::errs () << " error: could not find module '" << ModuleToPrint
2081
+ << " '\n " ;
2082
+ ExitCode = 1 ;
2083
+ continue ;
2084
+ }
2085
+
2086
+ // Split the module path.
2087
+ std::vector<StringRef> ModuleName;
2088
+ while (!ModuleToPrint.empty ()) {
2089
+ StringRef SubModuleName;
2090
+ std::tie (SubModuleName, ModuleToPrint) = ModuleToPrint.split (' .' );
2091
+ ModuleName.push_back (SubModuleName);
2092
+ }
2093
+ assert (!ModuleName.empty ());
2094
+
2095
+ // FIXME: If ModuleToPrint is a submodule, get its top-level module, which
2096
+ // will be the DeclContext for all of its Decls since we don't have first-
2097
+ // class submodules.
2098
+ if (ModuleName.size () > 1 ) {
2099
+ M = getModuleByFullName (Context, ModuleName[0 ]);
2100
+ if (!M) {
2101
+ llvm::errs () << " error: could not find module '" << ModuleName[0 ]
2102
+ << " '\n " ;
2103
+ ExitCode = 1 ;
2104
+ continue ;
2105
+ }
2106
+ }
2107
+ printModuleMetadata (M);
2108
+ }
2109
+
2110
+ return ExitCode;
2111
+ }
2112
+
2040
2113
static int doPrintModules (const CompilerInvocation &InitInvok,
2041
2114
const std::vector<std::string> ModulesToPrint,
2042
2115
const std::vector<std::string> GroupsToPrint,
@@ -3543,7 +3616,10 @@ int main(int argc, char *argv[]) {
3543
3616
}
3544
3617
break ;
3545
3618
}
3546
-
3619
+ case ActionType::PrintModuleMetadata: {
3620
+ ExitCode = doPrintModuleMetaData (InitInvok, options::ModuleToPrint);
3621
+ break ;
3622
+ }
3547
3623
case ActionType::PrintHeader: {
3548
3624
ExitCode = doPrintHeaders (
3549
3625
InitInvok, options::HeaderToPrint, PrintOpts,
0 commit comments