@@ -34,10 +34,6 @@ using namespace llvm::opt;
34
34
bool ArgsToFrontendOutputsConverter::convert (
35
35
std::vector<std::string> &mainOutputs,
36
36
SupplementaryOutputPaths &supplementaryOutputs) {
37
- const auto requestedAction =
38
- ArgsToFrontendOptionsConverter::determineRequestedAction (Args);
39
- if (!FrontendOptions::doesActionProduceOutput (requestedAction))
40
- return false ;
41
37
42
38
Optional<OutputFilesComputer> ofc =
43
39
OutputFilesComputer::create (Args, Diags, InputsAndOutputs);
@@ -47,15 +43,18 @@ bool ArgsToFrontendOutputsConverter::convert(
47
43
if (!mains)
48
44
return true ;
49
45
50
- Optional<SupplementaryOutputPaths> supplementaries =
46
+ Optional<std::vector< SupplementaryOutputPaths> > supplementaries =
51
47
SupplementaryOutputPathsComputer (Args, Diags, InputsAndOutputs, *mains,
52
48
ModuleName)
53
49
.computeOutputPaths ();
54
50
if (!supplementaries)
55
51
return true ;
56
52
57
53
mainOutputs = std::move (*mains);
58
- supplementaryOutputs = std::move (*supplementaries);
54
+ assert (supplementaries->size () <= 1 &&
55
+ " Have not implemented multiple primaries yet" );
56
+ if (!supplementaries->empty ())
57
+ supplementaryOutputs = std::move (supplementaries->front ());
59
58
return false ;
60
59
}
61
60
@@ -166,6 +165,13 @@ OutputFilesComputer::computeOutputFiles() const {
166
165
Optional<std::string>
167
166
OutputFilesComputer::computeOutputFile (StringRef outputArg,
168
167
const InputFile &input) const {
168
+ // Return an empty string to signify no output.
169
+ // The frontend does not currently produce a diagnostic
170
+ // if a -o argument is present for such an action
171
+ // for instance swiftc -frontend -o foo -interpret foo.swift
172
+ if (!FrontendOptions::doesActionProduceOutput (RequestedAction))
173
+ return std::string ();
174
+
169
175
if (!OutputDirectoryArgument.empty ())
170
176
return deriveOutputFileForDirectory (input);
171
177
@@ -228,16 +234,41 @@ SupplementaryOutputPathsComputer::SupplementaryOutputPathsComputer(
228
234
RequestedAction(
229
235
ArgsToFrontendOptionsConverter::determineRequestedAction (Args)) {}
230
236
231
- Optional<SupplementaryOutputPaths>
237
+ Optional<std::vector< SupplementaryOutputPaths> >
232
238
SupplementaryOutputPathsComputer::computeOutputPaths () const {
233
239
Optional<std::vector<SupplementaryOutputPaths>> pathsFromUser =
234
240
getSupplementaryOutputPathsFromArguments ();
235
241
if (!pathsFromUser)
236
242
return None;
237
243
238
- return computeOutputPathsForOneInput (
239
- OutputFiles[0 ], (*pathsFromUser)[0 ],
240
- InputsAndOutputs.firstInputProducingOutput ());
244
+ if (InputsAndOutputs.hasPrimaryInputs ())
245
+ assert (OutputFiles.size () == pathsFromUser->size ());
246
+ else if (InputsAndOutputs.isSingleThreadedWMO ())
247
+ assert (OutputFiles.size () == pathsFromUser->size () &&
248
+ pathsFromUser->size () == 1 );
249
+ else {
250
+ // Multi-threaded WMO is the exception
251
+ assert (OutputFiles.size () == InputsAndOutputs.inputCount () &&
252
+ pathsFromUser->size () == InputsAndOutputs.hasInputs ()
253
+ ? 1
254
+ : 0 );
255
+ }
256
+
257
+ std::vector<SupplementaryOutputPaths> outputPaths;
258
+ unsigned i = 0 ;
259
+ bool hadError = false ;
260
+ InputsAndOutputs.forEachInputProducingSupplementaryOutput (
261
+ [&](const InputFile &input) -> void {
262
+ if (auto suppPaths = computeOutputPathsForOneInput (
263
+ OutputFiles[i], (*pathsFromUser)[i], input))
264
+ outputPaths.push_back (*suppPaths);
265
+ else
266
+ hadError = true ;
267
+ ++i;
268
+ });
269
+ if (hadError)
270
+ return None;
271
+ return outputPaths;
241
272
}
242
273
243
274
Optional<std::vector<SupplementaryOutputPaths>>
@@ -302,7 +333,7 @@ SupplementaryOutputPathsComputer::getSupplementaryFilenamesFromArguments(
302
333
return std::vector<std::string>(N, std::string ());
303
334
304
335
Diags.diagnose (SourceLoc (), diag::error_wrong_number_of_arguments,
305
- Args.getLastArg (pathID)->getOption ().getName (), N,
336
+ Args.getLastArg (pathID)->getOption ().getPrefixedName (), N,
306
337
paths.size ());
307
338
return None;
308
339
}
@@ -387,7 +418,6 @@ SupplementaryOutputPathsComputer::determineSupplementaryOutputFilename(
387
418
options::ID emitOpt, std::string pathFromArguments, StringRef extension,
388
419
StringRef mainOutputIfUsable,
389
420
StringRef defaultSupplementaryOutputPathExcludingExtension) const {
390
- using namespace options ;
391
421
392
422
if (!pathFromArguments.empty ())
393
423
return pathFromArguments;
0 commit comments