22#include "llvm/ADT/STLExtras.h"
23#include "llvm/ADT/StringRef.h"
24#include "llvm/Option/ArgList.h"
25#include "llvm/Support/VirtualFileSystem.h"
26#include "llvm/TargetParser/Host.h"
30std::unique_ptr<CompilerInvocation>
33 assert(!ArgList.empty());
34 auto Diags = Opts.
Diags
35 ? std::move(Opts.
Diags)
37 Opts.
VFS ? *Opts.
VFS : *llvm::vfs::getRealFileSystem(),
45 Args, [](
const char *Elem) {
return llvm::StringRef(Elem) ==
"--"; }),
49 driver::Driver TheDriver(Args[0], llvm::sys::getDefaultTargetTriple(), *Diags,
50 "clang LLVM compiler", Opts.
VFS);
60 if (
C->getArgs().hasArg(driver::options::OPT_fdriver_only))
64 if (
C->getArgs().hasArg(driver::options::OPT__HASH_HASH_HASH)) {
65 C->getJobs().Print(llvm::errs(),
"\n",
true);
75 bool OffloadCompilation =
false;
76 if (Jobs.
size() > 1) {
77 for (
auto &A :
C->getActions()){
79 if (isa<driver::BindArchAction>(A))
80 A = *A->input_begin();
81 if (isa<driver::OffloadAction>(A)) {
82 OffloadCompilation =
true;
89 if (Jobs.
size() == 0 || (Jobs.
size() > 1 && !PickFirstOfMany)) {
91 llvm::raw_svector_ostream OS(Msg);
92 Jobs.
Print(OS,
"; ",
true);
93 Diags->Report(diag::err_fe_expected_compiler_job) << OS.str();
97 return StringRef(
Cmd.getCreator().getName()) ==
"clang";
100 Diags->Report(diag::err_fe_expected_clang_command);
104 const ArgStringList &CCArgs =
Cmd->getArguments();
106 *Opts.
CC1Args = {CCArgs.begin(), CCArgs.end()};
107 auto CI = std::make_unique<CompilerInvocation>();
void createDiagnostics(llvm::vfs::FileSystem &VFS, 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.