Skip to content

Commit 354a76a

Browse files
author
David Ungar
authored
Merge pull request #14198 from davidungar/PR-18-3c-exp2
[Batch mode] Move frontend main output files to FrontendInputsAndOutputs. (1)
2 parents af35a1f + 6b1d16b commit 354a76a

39 files changed

+1157
-662
lines changed

include/swift/AST/DiagnosticsFrontend.def

+3
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ ERROR(error_implicit_output_file_is_directory,none,
150150
"the implicit output file '%0' is a directory; explicitly specify a filename "
151151
"using -o", (StringRef))
152152

153+
ERROR(error_if_any_output_files_are_specified_they_all_must_be,none,
154+
"if any output files are specified, they all must be", ())
155+
153156
ERROR(error_primary_file_not_found,none,
154157
"primary file '%0' was not found in file list '%1'",
155158
(StringRef, StringRef))

include/swift/AST/IRGenOptions.h

+5
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,11 @@ class IRGenOptions {
190190

191191
/// Gets the name of the specified output filename.
192192
/// If multiple files are specified, the last one is returned.
193+
/// This function is used by (at least)
194+
/// lldb/source/Symbol/SwiftASTContext.cpp:4603
195+
/// FIXME: This function should go away in favor of
196+
/// Instance.getFrontendOptions().InputsAndOutputs.getSingleOutputFilename
197+
/// when batch mode handles all contingencies.
193198
StringRef getSingleOutputFilename() const {
194199
if (OutputFilenames.size() >= 1)
195200
return OutputFilenames.back();

include/swift/Frontend/ArgsToFrontendInputsConverter.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ namespace swift {
4242
class ArgsToFrontendInputsConverter {
4343
DiagnosticEngine &Diags;
4444
const llvm::opt::ArgList &Args;
45-
FrontendInputs &Inputs;
45+
FrontendInputsAndOutputs &InputsAndOutputs;
4646

4747
llvm::opt::Arg const *const FilelistPathArg;
4848
llvm::opt::Arg const *const PrimaryFilelistPathArg;
@@ -54,7 +54,7 @@ class ArgsToFrontendInputsConverter {
5454
public:
5555
ArgsToFrontendInputsConverter(DiagnosticEngine &diags,
5656
const llvm::opt::ArgList &args,
57-
FrontendInputs &inputs);
57+
FrontendInputsAndOutputs &inputsAndOutputs);
5858

5959
bool convert();
6060

@@ -69,6 +69,8 @@ class ArgsToFrontendInputsConverter {
6969
std::set<StringRef>
7070
createInputFilesConsumingPrimaries(std::set<StringRef> primaryFiles);
7171
bool checkForMissingPrimaryFiles(std::set<StringRef> primaryFiles);
72+
73+
bool isSingleThreadedWMO() const;
7274
};
7375

7476
} // namespace swift

include/swift/Frontend/ArgsToFrontendOptionsConverter.h

+6-24
Original file line numberDiff line numberDiff line change
@@ -50,34 +50,13 @@ class ArgsToFrontendOptionsConverter {
5050
void setUnsignedIntegerArgument(options::ID optionID, unsigned max,
5151
unsigned &valueToSet);
5252

53-
FrontendOptions::ActionType determineRequestedAction() const;
54-
5553
bool setUpForSILOrLLVM();
5654

57-
/// Determine the correct output filename when none was specified.
58-
///
59-
/// Such an absence should only occur when invoking the frontend
60-
/// without the driver,
61-
/// because the driver will always pass -o with an appropriate filename
62-
/// if output is required for the requested action.
63-
bool deriveOutputFilenameFromInputFile();
64-
65-
/// Determine the correct output filename when a directory was specified.
66-
///
67-
/// Such a specification should only occur when invoking the frontend
68-
/// directly, because the driver will always pass -o with an appropriate
69-
/// filename if output is required for the requested action.
70-
bool deriveOutputFilenameForDirectory(StringRef outputDir);
71-
72-
std::string determineBaseNameOfOutput() const;
73-
74-
void deriveOutputFilenameFromParts(StringRef dir, StringRef base);
75-
7655
void determineSupplementaryOutputFilenames();
7756

78-
/// Returns the output filenames on the command line or in the output
79-
/// filelist. If there
80-
/// were neither -o's nor an output filelist, returns an empty vector.
57+
/// \returns the output filenames on the command line or in the output
58+
/// filelist, or an empty vector if there were neither -o's nor an output
59+
/// filelist.
8160
ArrayRef<std::string> getOutputFilenamesFromCommandLineOrFilelist();
8261

8362
bool checkForUnusedOutputPaths() const;
@@ -91,6 +70,9 @@ class ArgsToFrontendOptionsConverter {
9170
: Diags(Diags), Args(Args), Opts(Opts) {}
9271

9372
bool convert();
73+
74+
static FrontendOptions::ActionType
75+
determineRequestedAction(const llvm::opt::ArgList &);
9476
};
9577

9678
} // namespace swift
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
//===--- ArgsToFrontendOutputsConverter.h -----------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef SWIFT_FRONTEND_ARGSTOFRONTENDOUTPUTSCONVERTER_H
14+
#define SWIFT_FRONTEND_ARGSTOFRONTENDOUTPUTSCONVERTER_H
15+
16+
#include "swift/AST/DiagnosticConsumer.h"
17+
#include "swift/AST/DiagnosticEngine.h"
18+
#include "swift/Basic/LLVM.h"
19+
#include "swift/Frontend/FrontendOptions.h"
20+
#include "swift/Option/Options.h"
21+
#include "llvm/Option/ArgList.h"
22+
23+
#include <vector>
24+
25+
namespace swift {
26+
27+
/// Given the command line arguments and information about the inputs,
28+
/// Fill in all the information in FrontendInputsAndOutputs.
29+
30+
class ArgsToFrontendOutputsConverter {
31+
const llvm::opt::ArgList &Args;
32+
StringRef ModuleName;
33+
FrontendInputsAndOutputs &InputsAndOutputs;
34+
DiagnosticEngine &Diags;
35+
36+
public:
37+
ArgsToFrontendOutputsConverter(const llvm::opt::ArgList &args,
38+
StringRef moduleName,
39+
FrontendInputsAndOutputs &inputsAndOutputs,
40+
DiagnosticEngine &diags)
41+
: Args(args), ModuleName(moduleName), InputsAndOutputs(inputsAndOutputs),
42+
Diags(diags) {}
43+
44+
Optional<std::vector<std::string>> convert();
45+
46+
/// Try to read an output file list file.
47+
/// \returns `None` if it could not open the filelist.
48+
static Optional<std::vector<std::string>>
49+
readOutputFileList(StringRef filelistPath, DiagnosticEngine &diags);
50+
};
51+
52+
class OutputFilesComputer {
53+
const llvm::opt::ArgList &Args;
54+
DiagnosticEngine &Diags;
55+
const FrontendInputsAndOutputs &InputsAndOutputs;
56+
const std::vector<std::string> OutputFileArguments;
57+
const std::string OutputDirectoryArgument;
58+
const StringRef FirstInput;
59+
const FrontendOptions::ActionType RequestedAction;
60+
const llvm::opt::Arg *const ModuleNameArg;
61+
const StringRef Suffix;
62+
const bool HasTextualOutput;
63+
64+
OutputFilesComputer(const llvm::opt::ArgList &args, DiagnosticEngine &diags,
65+
const FrontendInputsAndOutputs &inputsAndOutputs,
66+
std::vector<std::string> outputFileArguments,
67+
StringRef outputDirectoryArgument, StringRef firstInput,
68+
FrontendOptions::ActionType requestedAction,
69+
const llvm::opt::Arg *moduleNameArg, StringRef suffix,
70+
bool hasTextualOutput);
71+
72+
public:
73+
static Optional<OutputFilesComputer>
74+
create(const llvm::opt::ArgList &args, DiagnosticEngine &diags,
75+
const FrontendInputsAndOutputs &inputsAndOutputs);
76+
77+
/// \return the output filenames on the command line or in the output
78+
/// filelist. If there
79+
/// were neither -o's nor an output filelist, returns an empty vector.
80+
static Optional<std::vector<std::string>>
81+
getOutputFilenamesFromCommandLineOrFilelist(const llvm::opt::ArgList &args,
82+
DiagnosticEngine &diags);
83+
84+
Optional<std::vector<std::string>> computeOutputFiles() const;
85+
86+
private:
87+
Optional<std::string> computeOutputFile(StringRef outputArg,
88+
const InputFile &input) const;
89+
90+
/// \return the correct output filename when none was specified.
91+
///
92+
/// Such an absence should only occur when invoking the frontend
93+
/// without the driver,
94+
/// because the driver will always pass -o with an appropriate filename
95+
/// if output is required for the requested action.
96+
Optional<std::string> deriveOutputFileFromInput(const InputFile &input) const;
97+
98+
/// \return the correct output filename when a directory was specified.
99+
///
100+
/// Such a specification should only occur when invoking the frontend
101+
/// directly, because the driver will always pass -o with an appropriate
102+
/// filename if output is required for the requested action.
103+
Optional<std::string>
104+
deriveOutputFileForDirectory(const InputFile &input) const;
105+
106+
std::string determineBaseNameOfOutput(const InputFile &input) const;
107+
108+
std::string deriveOutputFileFromParts(StringRef dir, StringRef base) const;
109+
};
110+
111+
} // namespace swift
112+
113+
#endif /* SWIFT_FRONTEND_ARGSTOFRONTENDOUTPUTSCONVERTER_H */

include/swift/Frontend/Frontend.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class SerializedModuleLoader;
5454
/// - options for all stages of translation,
5555
/// - information about the build environment,
5656
/// - information about the job being performed, and
57-
/// - lists of inputs.
57+
/// - lists of inputs and outputs.
5858
///
5959
/// A CompilerInvocation can be built from a frontend command line
6060
/// using parseArgs. It can then be used to build a CompilerInstance,
@@ -245,7 +245,7 @@ class CompilerInvocation {
245245

246246

247247
StringRef getOutputFilename() const {
248-
return FrontendOpts.getSingleOutputFilename();
248+
return FrontendOpts.InputsAndOutputs.getSingleOutputFilename();
249249
}
250250

251251
void setCodeCompletionPoint(llvm::MemoryBuffer *Buf, unsigned Offset) {

include/swift/Frontend/FrontendInputs.h

-127
This file was deleted.

0 commit comments

Comments
 (0)