22#include "llvm/ADT/STLExtras.h"
23#include "llvm/ADT/StringRef.h"
24#include "llvm/Option/ArgList.h"
25#include "llvm/TargetParser/Host.h"
29std::unique_ptr<CompilerInvocation>
32 assert(!ArgList.empty());
33 auto Diags = Opts.
Diags
34 ? std::move(Opts.
Diags)
42 Args, [](
const char *Elem) {
return llvm::StringRef(Elem) ==
"--"; }),
46 driver::Driver TheDriver(Args[0], llvm::sys::getDefaultTargetTriple(), *Diags,
47 "clang LLVM compiler", Opts.
VFS);
57 if (
C->getArgs().hasArg(driver::options::OPT_fdriver_only))
61 if (
C->getArgs().hasArg(driver::options::OPT__HASH_HASH_HASH)) {
62 C->getJobs().Print(llvm::errs(),
"\n",
true);
72 bool OffloadCompilation =
false;
73 if (Jobs.
size() > 1) {
74 for (
auto &A :
C->getActions()){
76 if (isa<driver::BindArchAction>(A))
77 A = *A->input_begin();
78 if (isa<driver::OffloadAction>(A)) {
79 OffloadCompilation =
true;
86 if (Jobs.
size() == 0 || (Jobs.
size() > 1 && !PickFirstOfMany)) {
88 llvm::raw_svector_ostream OS(Msg);
89 Jobs.
Print(OS,
"; ",
true);
90 Diags->Report(diag::err_fe_expected_compiler_job) << OS.str();
94 return StringRef(
Cmd.getCreator().getName()) ==
"clang";
97 Diags->Report(diag::err_fe_expected_clang_command);
101 const ArgStringList &CCArgs =
Cmd->getArguments();
103 *Opts.
CC1Args = {CCArgs.begin(), CCArgs.end()};
104 auto CI = std::make_unique<CompilerInvocation>();
void createDiagnostics(DiagnosticConsumer *Client=nullptr, bool ShouldOwnClient=true)
Create the diagnostics engine using the invocation's diagnostic options and replace any existing one ...
static bool CreateFromArgs(CompilerInvocation &Res, ArrayRef< const char * > CommandLineArgs, DiagnosticsEngine &Diags, const char *Argv0=nullptr)
Create a compiler invocation from a list of input options.
Options for controlling the compiler diagnostics engine.
Command - An executable path/name and argument vector to execute.
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
void setCheckInputsExist(bool Value)
void setProbePrecompiled(bool Value)
Compilation * BuildCompilation(ArrayRef< const char * > Args)
BuildCompilation - Construct a compilation object for a command line argument vector.
JobList - A sequence of jobs to perform.
void Print(llvm::raw_ostream &OS, const char *Terminator, bool Quote, CrashReportInfo *CrashInfo=nullptr) const
The JSON file list parser is used to communicate input to InstallAPI.
std::unique_ptr< CompilerInvocation > createInvocation(ArrayRef< const char * > Args, CreateInvocationOptions Opts={})
Interpret clang arguments in preparation to parse a file.
Optional inputs to createInvocation.
IntrusiveRefCntPtr< DiagnosticsEngine > Diags
Receives diagnostics encountered while parsing command-line flags.
bool ProbePrecompiled
Allow the driver to probe the filesystem for PCH files.
bool RecoverOnError
Whether to attempt to produce a non-null (possibly incorrect) invocation if any errors were encounter...
IntrusiveRefCntPtr< llvm::vfs::FileSystem > VFS
Used e.g.
std::vector< std::string > * CC1Args
If set, the target is populated with the cc1 args produced by the driver.