18 #include "llvm/ADT/None.h" 19 #include "llvm/ADT/STLExtras.h" 20 #include "llvm/ADT/SmallVector.h" 21 #include "llvm/ADT/Triple.h" 22 #include "llvm/Option/ArgList.h" 23 #include "llvm/Option/OptSpecifier.h" 24 #include "llvm/Option/Option.h" 25 #include "llvm/Support/FileSystem.h" 26 #include "llvm/Support/raw_ostream.h" 29 #include <system_error> 32 using namespace clang;
33 using namespace driver;
37 InputArgList *_Args, DerivedArgList *_TranslatedArgs,
39 : TheDriver(D), DefaultToolChain(_DefaultToolChain), Args(_Args),
40 TranslatedArgs(_TranslatedArgs), ContainsError(ContainsError) {
42 OrderedOffloadingToolchains.insert(
52 delete TranslatedArgs;
56 for (
auto Arg : TCArgs)
57 if (Arg.second != TranslatedArgs)
61 const DerivedArgList &
65 TC = &DefaultToolChain;
67 DerivedArgList *&Entry = TCArgs[{TC, BoundArch, DeviceOffloadKind}];
70 DerivedArgList *OpenMPArgs =
nullptr;
73 const ToolChain *HostTC = getSingleOffloadToolChain<Action::OFK_Host>();
76 *TranslatedArgs, SameTripleAsHost, AllocatedArgs);
80 Entry = TC->
TranslateArgs(*TranslatedArgs, BoundArch, DeviceOffloadKind);
82 Entry = TranslatedArgs;
84 Entry = TC->
TranslateArgs(*OpenMPArgs, BoundArch, DeviceOffloadKind);
92 for (
auto ArgPtr : AllocatedArgs)
93 Entry->AddSynthesizedArg(ArgPtr);
113 if (!llvm::sys::fs::can_write(File) || !llvm::sys::fs::is_regular_file(File))
116 if (std::error_code EC = llvm::sys::fs::remove(File)) {
130 bool IssueErrors)
const {
132 for (
const auto &File: Files)
139 bool IssueErrors)
const {
141 for (
const auto &File : Files) {
144 if (JA && File.first != JA)
152 const Command *&FailingCommand)
const {
155 raw_ostream *OS = &llvm::errs();
161 OS =
new llvm::raw_fd_ostream(
getDriver().CCPrintOptionsFilename, EC,
162 llvm::sys::fs::F_Append |
163 llvm::sys::fs::F_Text);
174 *OS <<
"[Logging clang options]";
178 if (OS != &llvm::errs())
183 bool ExecutionFailed;
184 int Res = C.
Execute(Redirects, &Error, &ExecutionFailed);
185 if (!Error.empty()) {
186 assert(Res &&
"Error string set with 0 result code!");
193 return ExecutionFailed ? 1 : Res;
200 if (FailingCommands.empty())
209 for (
const auto &CI : FailingCommands)
210 if (A == &(CI.second->getSource()))
213 for (
const auto *AI : A->
inputs())
231 for (
const auto &Job : Jobs) {
232 if (!
InputsOk(Job, FailingCommands))
234 const Command *FailingCommand =
nullptr;
236 FailingCommands.push_back(std::make_pair(Res, FailingCommand));
245 ForDiagnostics =
true;
259 FailureResultFiles.clear();
263 OptSpecifier OutputOpts[] = { options::OPT_o, options::OPT_MD,
265 for (
unsigned i = 0, e = llvm::array_lengthof(OutputOpts); i != e; ++i) {
266 if (TranslatedArgs->hasArg(OutputOpts[i]))
267 TranslatedArgs->eraseArg(OutputOpts[i]);
269 TranslatedArgs->ClaimAllArgs();
272 Redirects = {None, {
""}, {
""}};
275 ForceKeepTempFiles =
true;
283 this->Redirects = Redirects;
StringRef getSysRoot() const
Returns the sysroot path.
DiagnosticBuilder Diag(unsigned DiagID) const
static bool InputsOk(const Command &C, const FailingCommandList &FailingCommands)
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...
bool CleanupFileList(const llvm::opt::ArgStringList &Files, bool IssueErrors=false) const
CleanupFileList - Remove the files in the given list.
bool isOffloading(OffloadKind OKind) const
Action - Represent an abstract compilation step to perform.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
bool IsCLMode() const
Whether the driver should follow cl.exe like behavior.
JobList - A sequence of jobs to perform.
llvm::DenseMap< const JobAction *, const char * > ArgStringMap
ArgStringMap - Type used to map a JobAction to its result file.
bool CleanupFile(const char *File, bool IssueErrors=false) const
CleanupFile - Delete a given file.
void clear()
Clear the job list.
const llvm::opt::DerivedArgList & getArgs() const
void Redirect(ArrayRef< Optional< StringRef >> Redirects)
Redirect - Redirect output of this compilation.
Command - An executable path/name and argument vector to execute.
bool isSaveTempsEnabled() const
int ExecuteCommand(const Command &C, const Command *&FailingCommand) const
ExecuteCommand - Execute an actual command.
Compilation(const Driver &D, const ToolChain &DefaultToolChain, llvm::opt::InputArgList *Args, llvm::opt::DerivedArgList *TranslatedArgs, bool ContainsError)
void ExecuteJobs(const JobList &Jobs, SmallVectorImpl< std::pair< int, const Command *>> &FailingCommands) const
ExecuteJob - Execute a single job.
const Action & getSource() const
getSource - Return the Action which caused the creation of this job.
Dataflow Directional Tag Classes.
static bool ActionFailed(const Action *A, const FailingCommandList &FailingCommands)
std::string SysRoot
sysroot, if present
const Driver & getDriver() const
bool CleanupFileMap(const ArgStringMap &Files, const JobAction *JA, bool IssueErrors=false) const
CleanupFileMap - Remove the files in the given map.
SmallVectorImpl< std::pair< int, const Command * > > FailingCommandList
void initCompilationForDiagnostics()
initCompilationForDiagnostics - Remove stale state and suppress output so compilation can be reexecut...
virtual void Print(llvm::raw_ostream &OS, const char *Terminator, bool Quote, CrashReportInfo *CrashInfo=nullptr) const
virtual int Execute(ArrayRef< Optional< StringRef >> Redirects, std::string *ErrMsg, bool *ExecutionFailed) const