16 #include "llvm/ADT/STLExtras.h"
17 #include "llvm/Option/ArgList.h"
18 #include "llvm/Support/FileSystem.h"
19 #include "llvm/Support/raw_ostream.h"
21 using namespace clang::driver;
22 using namespace clang;
23 using namespace llvm::opt;
26 InputArgList *_Args, DerivedArgList *_TranslatedArgs)
27 : TheDriver(D), DefaultToolChain(_DefaultToolChain), ActiveOffloadMask(0u),
28 Args(_Args), TranslatedArgs(_TranslatedArgs), Redirects(nullptr),
29 ForDiagnostics(
false) {
31 OrderedOffloadingToolchains.insert(
36 delete TranslatedArgs;
40 for (llvm::DenseMap<std::pair<const ToolChain*, const char*>,
41 DerivedArgList*>::
iterator it = TCArgs.begin(),
42 ie = TCArgs.end(); it != ie; ++it)
43 if (it->second != TranslatedArgs)
56 const char *BoundArch) {
58 TC = &DefaultToolChain;
60 DerivedArgList *&Entry = TCArgs[std::make_pair(TC, BoundArch)];
64 Entry = TranslatedArgs;
84 if (!llvm::sys::fs::can_write(File) || !llvm::sys::fs::is_regular_file(File))
87 if (std::error_code EC = llvm::sys::fs::remove(File)) {
101 bool IssueErrors)
const {
103 for (ArgStringList::const_iterator
104 it = Files.begin(), ie = Files.end(); it != ie; ++it)
111 bool IssueErrors)
const {
113 for (ArgStringMap::const_iterator
114 it = Files.begin(), ie = Files.end(); it != ie; ++it) {
118 if (JA && it->first != JA)
126 const Command *&FailingCommand)
const {
129 raw_ostream *OS = &llvm::errs();
135 OS =
new llvm::raw_fd_ostream(
getDriver().CCPrintOptionsFilename, EC,
136 llvm::sys::fs::F_Append |
137 llvm::sys::fs::F_Text);
139 getDriver().
Diag(clang::diag::err_drv_cc_print_options_failure)
148 *OS <<
"[Logging clang options]";
152 if (OS != &llvm::errs())
157 bool ExecutionFailed;
158 int Res = C.
Execute(Redirects, &Error, &ExecutionFailed);
159 if (!Error.empty()) {
160 assert(Res &&
"Error string set with 0 result code!");
161 getDriver().
Diag(clang::diag::err_drv_command_failure) << Error;
167 return ExecutionFailed ? 1 : Res;
172 SmallVectorImpl<std::pair<int, const Command *>> &FailingCommands)
const {
173 for (
const auto &Job : Jobs) {
174 const Command *FailingCommand =
nullptr;
176 FailingCommands.push_back(std::make_pair(Res, FailingCommand));
185 ForDiagnostics =
true;
195 FailureResultFiles.clear();
199 OptSpecifier OutputOpts[] = { options::OPT_o, options::OPT_MD,
201 for (
unsigned i = 0, e = llvm::array_lengthof(OutputOpts); i != e; ++i) {
202 if (TranslatedArgs->hasArg(OutputOpts[i]))
203 TranslatedArgs->eraseArg(OutputOpts[i]);
205 TranslatedArgs->ClaimAllArgs();
208 Redirects =
new const StringRef*[3]();
209 Redirects[0] =
nullptr;
210 Redirects[1] =
new StringRef();
211 Redirects[2] =
new StringRef();
219 this->Redirects = Redirects;
const Driver & getDriver() const
DiagnosticBuilder Diag(unsigned DiagID) const
bool CleanupFile(const char *File, bool IssueErrors=false) const
CleanupFile - Delete a given file.
virtual void Print(llvm::raw_ostream &OS, const char *Terminator, bool Quote, CrashReportInfo *CrashInfo=nullptr) const
const llvm::opt::DerivedArgList & getArgs() const
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Compilation(const Driver &D, const ToolChain &DefaultToolChain, llvm::opt::InputArgList *Args, llvm::opt::DerivedArgList *TranslatedArgs)
bool CleanupFileList(const llvm::opt::ArgStringList &Files, bool IssueErrors=false) const
CleanupFileList - Remove the files in the given list.
virtual int Execute(const StringRef **Redirects, std::string *ErrMsg, bool *ExecutionFailed) const
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.
void clear()
Clear the job list.
bool CleanupFileMap(const ArgStringMap &Files, const JobAction *JA, bool IssueErrors=false) const
CleanupFileMap - Remove the files in the given map.
void Redirect(const StringRef **Redirects)
Redirect - Redirect output of this compilation.
Command - An executable path/name and argument vector to execute.
const llvm::opt::DerivedArgList & getArgsForToolChain(const ToolChain *TC, const char *BoundArch)
getArgsForToolChain - Return the derived argument list for the tool chain TC (or the default tool cha...
Represents a template argument.
std::string SysRoot
sysroot, if present
void ExecuteJobs(const JobList &Jobs, SmallVectorImpl< std::pair< int, const Command * >> &FailingCommands) const
ExecuteJob - Execute a single job.
int ExecuteCommand(const Command &C, const Command *&FailingCommand) const
ExecuteCommand - Execute an actual command.
StringRef getSysRoot() const
Returns the sysroot path.
void initCompilationForDiagnostics()
initCompilationForDiagnostics - Remove stale state and suppress output so compilation can be reexecut...