@@ -26,15 +26,48 @@ using namespace llvm::opt;
26
26
using namespace swift ;
27
27
using namespace modulesummary ;
28
28
29
+ class MergeModuleSummaryInvocation {
30
+ public:
31
+ std::string OutputFilename;
32
+ std::vector<std::string> InputFilenames;
33
+
34
+ bool parseArgs (ArrayRef<const char *> Args, DiagnosticEngine &Diags) {
35
+ using namespace options ;
36
+
37
+ std::unique_ptr<llvm::opt::OptTable> Table = createSwiftOptTable ();
38
+ unsigned MissingIndex;
39
+ unsigned MissingCount;
40
+ llvm::opt::InputArgList ParsedArgs =
41
+ Table->ParseArgs (Args, MissingIndex, MissingCount, SwiftMergeModuleSummaryOption);
42
+
43
+ if (MissingCount) {
44
+ Diags.diagnose (SourceLoc (), diag::error_missing_arg_value,
45
+ ParsedArgs.getArgString (MissingIndex), MissingCount);
46
+ return true ;
47
+ }
48
+
49
+ for (const Arg *A : ParsedArgs.filtered (OPT_INPUT)) {
50
+ InputFilenames.push_back (A->getValue ());
51
+ }
52
+
53
+ if (const Arg *A = ParsedArgs.getLastArg (OPT_o)) {
54
+ OutputFilename = A->getValue ();
55
+ }
56
+
57
+ std::vector<const char *> LLVMArgs {" " };
58
+ for (const Arg *A : ParsedArgs.filtered (OPT_Xllvm)) {
59
+ LLVMArgs.push_back (A->getValue ());
60
+ }
61
+
62
+ llvm::cl::ParseCommandLineOptions (LLVMArgs.size (), LLVMArgs.data (), " " );
63
+ return false ;
64
+ }
65
+ };
66
+
29
67
static llvm::cl::opt<std::string>
30
68
LTOPrintLiveTrace (" lto-print-live-trace" , llvm::cl::init(" " ),
31
69
llvm::cl::desc(" Print liveness trace for the symbol" ));
32
70
33
- static llvm::cl::list<std::string>
34
- InputFilenames (llvm::cl::Positional, llvm::cl::desc(" [input files...]" ));
35
- static llvm::cl::opt<std::string>
36
- OutputFilename (" o" , llvm::cl::desc(" output filename" ));
37
-
38
71
static llvm::DenseSet<GUID> computePreservedGUIDs (ModuleSummaryIndex *summary) {
39
72
llvm::DenseSet<GUID> Set (1 );
40
73
for (auto FI = summary->functions_begin (), FE = summary->functions_end ();
@@ -239,21 +272,24 @@ int cross_module_opt_main(ArrayRef<const char *> Args, const char *Argv0,
239
272
void *MainAddr) {
240
273
INITIALIZE_LLVM ();
241
274
242
- llvm::cl::ParseCommandLineOptions (Args.size (), Args.data (), " Swift LTO\n " );
243
-
244
275
CompilerInstance Instance;
245
276
PrintingDiagnosticConsumer PDC;
246
277
Instance.addDiagnosticConsumer (&PDC);
247
278
248
- if (InputFilenames.empty ()) {
279
+ MergeModuleSummaryInvocation Invocation;
280
+ if (Invocation.parseArgs (Args, Instance.getDiags ())) {
281
+ return true ;
282
+ }
283
+
284
+ if (Invocation.InputFilenames .empty ()) {
249
285
Instance.getDiags ().diagnose (SourceLoc (),
250
286
diag::error_mode_requires_an_input_file);
251
287
return 1 ;
252
288
}
253
289
254
290
auto TheSummary = std::make_unique<ModuleSummaryIndex>();
255
291
256
- for (auto Filename : InputFilenames) {
292
+ for (auto Filename : Invocation. InputFilenames ) {
257
293
LLVM_DEBUG (llvm::dbgs () << " Loading module summary " << Filename << " \n " );
258
294
auto ErrOrBuf = llvm::MemoryBuffer::getFile (Filename);
259
295
if (!ErrOrBuf) {
@@ -276,6 +312,6 @@ int cross_module_opt_main(ArrayRef<const char *> Args, const char *Argv0,
276
312
markDeadSymbols (*TheSummary.get (), PreservedGUIDs);
277
313
278
314
modulesummary::writeModuleSummaryIndex (*TheSummary, Instance.getDiags (),
279
- OutputFilename);
315
+ Invocation. OutputFilename );
280
316
return 0 ;
281
317
}
0 commit comments