17#include "llvm/Option/ArgList.h"
18#include "llvm/Option/OptSpecifier.h"
19#include "llvm/Option/Option.h"
20#include "llvm/Support/FileSystem.h"
21#include "llvm/Support/raw_ostream.h"
22#include "llvm/TargetParser/Triple.h"
25#include <system_error>
29using namespace driver;
33 InputArgList *_Args, DerivedArgList *_TranslatedArgs,
35 : TheDriver(
D), DefaultToolChain(_DefaultToolChain), Args(_Args),
36 TranslatedArgs(_TranslatedArgs), ContainsError(ContainsError) {
38 OrderedOffloadingToolchains.insert(
48 delete TranslatedArgs;
52 for (
auto Arg : TCArgs)
53 if (Arg.second != TranslatedArgs)
61 TC = &DefaultToolChain;
63 DerivedArgList *&Entry = TCArgs[{TC, BoundArch, DeviceOffloadKind}];
66 DerivedArgList *OpenMPArgs =
nullptr;
69 const ToolChain *HostTC = getSingleOffloadToolChain<Action::OFK_Host>();
72 *TranslatedArgs, SameTripleAsHost, AllocatedArgs);
75 DerivedArgList *NewDAL =
nullptr;
78 DeviceOffloadKind, &AllocatedArgs);
89 Entry = TC->
TranslateArgs(*TranslatedArgs, BoundArch, DeviceOffloadKind);
91 Entry = TranslatedArgs;
93 Entry = TC->
TranslateArgs(*NewDAL, BoundArch, DeviceOffloadKind);
101 for (
auto *ArgPtr : AllocatedArgs)
102 Entry->AddSynthesizedArg(ArgPtr);
122 if (!llvm::sys::fs::can_write(
File) || !llvm::sys::fs::is_regular_file(
File))
125 if (std::error_code EC = llvm::sys::fs::remove(
File)) {
139 bool IssueErrors)
const {
141 for (
const auto &
File: Files)
148 bool IssueErrors)
const {
150 for (
const auto &
File : Files) {
153 if (JA &&
File.first != JA)
161 const Command *&FailingCommand,
162 bool LogOnly)
const {
165 raw_ostream *OS = &llvm::errs();
166 std::unique_ptr<llvm::raw_fd_ostream> OwnedStream;
171 !
getDriver().CCPrintOptionsFilename.empty()) {
173 OwnedStream.reset(
new llvm::raw_fd_ostream(
175 llvm::sys::fs::OF_Append | llvm::sys::fs::OF_TextWithCRLF));
182 OS = OwnedStream.get();
186 *OS <<
"[Logging clang options]\n";
188 C.Print(*OS,
"\n",
getDriver().CCPrintOptions);
195 bool ExecutionFailed;
196 int Res =
C.Execute(Redirects, &Error, &ExecutionFailed);
198 PostCallback(
C, Res);
199 if (!Error.empty()) {
200 assert(Res &&
"Error string set with 0 result code!");
207 return ExecutionFailed ? 1 : Res;
214 if (FailingCommands.empty())
223 for (
const auto &CI : FailingCommands)
224 if (A == &(CI.second->getSource()))
227 for (
const auto *AI : A->
inputs())
241 bool LogOnly)
const {
246 for (
const auto &Job : Jobs) {
247 if (!
InputsOk(Job, FailingCommands))
249 const Command *FailingCommand =
nullptr;
251 FailingCommands.push_back(std::make_pair(Res, FailingCommand));
260 ForDiagnostics =
true;
274 FailureResultFiles.clear();
278 OptSpecifier OutputOpts[] = {
279 options::OPT_o, options::OPT_MD, options::OPT_MMD, options::OPT_M,
280 options::OPT_MM, options::OPT_MF, options::OPT_MG, options::OPT_MJ,
281 options::OPT_MQ, options::OPT_MT, options::OPT_MV};
282 for (
const auto &Opt : OutputOpts) {
283 if (TranslatedArgs->hasArg(Opt))
284 TranslatedArgs->eraseArg(Opt);
286 TranslatedArgs->ClaimAllArgs();
290 for (
auto Arg : TCArgs)
291 if (Arg.second != TranslatedArgs)
296 Redirects = {std::nullopt, {
""}, {
""}};
299 ForceKeepTempFiles =
true;
307 this->Redirects = Redirects;
static bool ActionFailed(const Action *A, const FailingCommandList &FailingCommands)
static bool InputsOk(const Command &C, const FailingCommandList &FailingCommands)
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Action - Represent an abstract compilation step to perform.
bool isOffloading(OffloadKind OKind) const
Command - An executable path/name and argument vector to execute.
const llvm::opt::DerivedArgList & getArgsForToolChain(const ToolChain *TC, StringRef BoundArch, Action::OffloadKind DeviceOffloadKind)
getArgsForToolChain - Return the derived argument list for the tool chain TC (or the default tool cha...
int ExecuteCommand(const Command &C, const Command *&FailingCommand, bool LogOnly=false) const
ExecuteCommand - Execute an actual command.
bool CleanupFileMap(const ArgStringMap &Files, const JobAction *JA, bool IssueErrors=false) const
CleanupFileMap - Remove the files in the given map.
bool CleanupFile(const char *File, bool IssueErrors=false) const
CleanupFile - Delete a given file.
Compilation(const Driver &D, const ToolChain &DefaultToolChain, llvm::opt::InputArgList *Args, llvm::opt::DerivedArgList *TranslatedArgs, bool ContainsError)
bool CleanupFileList(const llvm::opt::ArgStringList &Files, bool IssueErrors=false) const
CleanupFileList - Remove the files in the given list.
StringRef getSysRoot() const
Returns the sysroot path.
void Redirect(ArrayRef< std::optional< StringRef > > Redirects)
Redirect - Redirect output of this compilation.
void initCompilationForDiagnostics()
initCompilationForDiagnostics - Remove stale state and suppress output so compilation can be reexecut...
const llvm::opt::DerivedArgList & getArgs() const
void ExecuteJobs(const JobList &Jobs, SmallVectorImpl< std::pair< int, const Command * > > &FailingCommands, bool LogOnly=false) const
ExecuteJob - Execute a single job.
const Driver & getDriver() const
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
std::string SysRoot
sysroot, if present
bool isSaveTempsEnabled() const
bool IsCLMode() const
Whether the driver should follow cl.exe like behavior.
DiagnosticBuilder Diag(unsigned DiagID) const
JobList - A sequence of jobs to perform.
void clear()
Clear the job list.
llvm::DenseMap< const JobAction *, const char * > ArgStringMap
ArgStringMap - Type used to map a JobAction to its result file.
The JSON file list parser is used to communicate input to InstallAPI.
@ Success
Template argument deduction was successful.