18#include "llvm/ADT/STLExtras.h"
19#include "llvm/ADT/SmallVector.h"
20#include "llvm/Option/ArgList.h"
21#include "llvm/Option/OptSpecifier.h"
22#include "llvm/Option/Option.h"
23#include "llvm/Support/FileSystem.h"
24#include "llvm/Support/raw_ostream.h"
25#include "llvm/TargetParser/Triple.h"
28#include <system_error>
32using namespace driver;
36 InputArgList *_Args, DerivedArgList *_TranslatedArgs,
38 : TheDriver(
D), DefaultToolChain(_DefaultToolChain), Args(_Args),
39 TranslatedArgs(_TranslatedArgs), ContainsError(ContainsError) {
41 OrderedOffloadingToolchains.insert(
51 delete TranslatedArgs;
55 for (
auto Arg : TCArgs)
56 if (Arg.second != TranslatedArgs)
64 TC = &DefaultToolChain;
66 DerivedArgList *&Entry = TCArgs[{TC, BoundArch, DeviceOffloadKind}];
69 DerivedArgList *OpenMPArgs =
nullptr;
72 const ToolChain *HostTC = getSingleOffloadToolChain<Action::OFK_Host>();
75 *TranslatedArgs, SameTripleAsHost, AllocatedArgs);
78 DerivedArgList *NewDAL =
nullptr;
81 DeviceOffloadKind, &AllocatedArgs);
92 Entry = TC->
TranslateArgs(*TranslatedArgs, BoundArch, DeviceOffloadKind);
94 Entry = TranslatedArgs;
96 Entry = TC->
TranslateArgs(*NewDAL, BoundArch, DeviceOffloadKind);
104 for (
auto *ArgPtr : AllocatedArgs)
105 Entry->AddSynthesizedArg(ArgPtr);
125 if (!llvm::sys::fs::can_write(
File) || !llvm::sys::fs::is_regular_file(
File))
128 if (std::error_code EC = llvm::sys::fs::remove(
File)) {
142 bool IssueErrors)
const {
144 for (
const auto &
File: Files)
151 bool IssueErrors)
const {
153 for (
const auto &
File : Files) {
156 if (JA &&
File.first != JA)
164 const Command *&FailingCommand,
165 bool LogOnly)
const {
168 raw_ostream *OS = &llvm::errs();
169 std::unique_ptr<llvm::raw_fd_ostream> OwnedStream;
174 !
getDriver().CCPrintOptionsFilename.empty()) {
176 OwnedStream.reset(
new llvm::raw_fd_ostream(
178 llvm::sys::fs::OF_Append | llvm::sys::fs::OF_TextWithCRLF));
185 OS = OwnedStream.get();
189 *OS <<
"[Logging clang options]\n";
191 C.Print(*OS,
"\n",
getDriver().CCPrintOptions);
198 bool ExecutionFailed;
199 int Res =
C.Execute(Redirects, &Error, &ExecutionFailed);
201 PostCallback(
C, Res);
202 if (!Error.empty()) {
203 assert(Res &&
"Error string set with 0 result code!");
210 return ExecutionFailed ? 1 : Res;
217 if (FailingCommands.empty())
226 for (
const auto &CI : FailingCommands)
227 if (A == &(CI.second->getSource()))
230 for (
const auto *AI : A->
inputs())
244 bool LogOnly)
const {
249 for (
const auto &Job : Jobs) {
250 if (!
InputsOk(Job, FailingCommands))
252 const Command *FailingCommand =
nullptr;
254 FailingCommands.push_back(std::make_pair(Res, FailingCommand));
263 ForDiagnostics =
true;
277 FailureResultFiles.clear();
281 OptSpecifier OutputOpts[] = {
282 options::OPT_o, options::OPT_MD, options::OPT_MMD, options::OPT_M,
283 options::OPT_MM, options::OPT_MF, options::OPT_MG, options::OPT_MJ,
284 options::OPT_MQ, options::OPT_MT, options::OPT_MV};
285 for (
const auto &Opt : OutputOpts) {
286 if (TranslatedArgs->hasArg(Opt))
287 TranslatedArgs->eraseArg(Opt);
289 TranslatedArgs->ClaimAllArgs();
293 for (
auto Arg : TCArgs)
294 if (Arg.second != TranslatedArgs)
299 Redirects = {std::nullopt, {
""}, {
""}};
302 ForceKeepTempFiles =
true;
310 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.