class CompilerInvocation

Declaration

class CompilerInvocation : public CompilerInvocationRefBase,
                           public CompilerInvocationValueBase { /* full declaration omitted */ };

Description

Helper class for holding the data necessary to invoke the compiler. This class is designed to represent an abstract "invocation" of the compiler, including data such as the include paths, the code generation options, the warning flags, and so on.

Declared at: clang/include/clang/Frontend/CompilerInvocation.h:193

Inherits from: CompilerInvocationRefBase, CompilerInvocationValueBase

Member Variables

Inherited from CompilerInvocationValueBase:

protected MigratorOpts
protected CodeGenOpts
protected DependencyOutputOpts
protected FileSystemOpts
protected FrontendOpts
protected PreprocessorOutputOpts

Inherited from CompilerInvocationRefBase:

public LangOpts
public TargetOpts
public DiagnosticOpts
public HeaderSearchOpts
public PreprocessorOpts
public AnalyzerOpts

Method Overview

  • public static bool CreateFromArgs(clang::CompilerInvocation & Res, ArrayRef<const char *> CommandLineArgs, clang::DiagnosticsEngine & Diags, const char * Argv0 = nullptr)
  • private static bool CreateFromArgsImpl(clang::CompilerInvocation & Res, ArrayRef<const char *> CommandLineArgs, clang::DiagnosticsEngine & Diags, const char * Argv0)
  • private static void GenerateCodeGenArgs(const clang::CodeGenOptions & Opts, SmallVectorImpl<const char *> & Args, clang::CompilerInvocation::StringAllocator SA, const llvm::Triple & T, const std::string & OutputFile, const clang::LangOptions * LangOpts)
  • private static void GenerateDiagnosticArgs(const clang::DiagnosticOptions & Opts, SmallVectorImpl<const char *> & Args, clang::CompilerInvocation::StringAllocator SA, bool DefaultDiagColor)
  • private static void GenerateLangArgs(const clang::LangOptions & Opts, SmallVectorImpl<const char *> & Args, clang::CompilerInvocation::StringAllocator SA, const llvm::Triple & T, clang::InputKind IK)
  • public static std::string GetResourcesPath(const char * Argv0, void * MainAddr)
  • private static bool ParseCodeGenArgs(clang::CodeGenOptions & Opts, llvm::opt::ArgList & Args, clang::InputKind IK, clang::DiagnosticsEngine & Diags, const llvm::Triple & T, const std::string & OutputFile, const clang::LangOptions & LangOptsRef)
  • private static bool ParseLangArgs(clang::LangOptions & Opts, llvm::opt::ArgList & Args, clang::InputKind IK, const llvm::Triple & T, std::vector<std::string> & Includes, clang::DiagnosticsEngine & Diags)
  • public void generateCC1CommandLine(llvm::SmallVectorImpl<const char *> & Args, clang::CompilerInvocation::StringAllocator SA) const
  • public std::string getModuleHash() const

Inherited from CompilerInvocationValueBase:

Inherited from CompilerInvocationRefBase:

Methods

static bool CreateFromArgs(
    clang::CompilerInvocation& Res,
    ArrayRef<const char*> CommandLineArgs,
    clang::DiagnosticsEngine& Diags,
    const char* Argv0 = nullptr)

Description

Create a compiler invocation from a list of input options.

Declared at: clang/include/clang/Frontend/CompilerInvocation.h:207

Parameters

clang::CompilerInvocation& Res
- The resulting invocation.
ArrayRef<const char*> CommandLineArgs
- Array of argument strings, this must not contain "-cc1".
clang::DiagnosticsEngine& Diags
const char* Argv0 = nullptr

Returns

false if an error was encountered while parsing the arguments and attempts to recover and continue parsing the rest of the arguments. The recovery is best-effort and only guarantees that \p Res will end up in one of the vaild-to-access (albeit arbitrary) states.

static bool CreateFromArgsImpl(
    clang::CompilerInvocation& Res,
    ArrayRef<const char*> CommandLineArgs,
    clang::DiagnosticsEngine& Diags,
    const char* Argv0)

Declared at: clang/include/clang/Frontend/CompilerInvocation.h:239

Parameters

clang::CompilerInvocation& Res
ArrayRef<const char*> CommandLineArgs
clang::DiagnosticsEngine& Diags
const char* Argv0

static void GenerateCodeGenArgs(
    const clang::CodeGenOptions& Opts,
    SmallVectorImpl<const char*>& Args,
    clang::CompilerInvocation::StringAllocator SA,
    const llvm::Triple& T,
    const std::string& OutputFile,
    const clang::LangOptions* LangOpts)

Declared at: clang/include/clang/Frontend/CompilerInvocation.h:268

Parameters

const clang::CodeGenOptions& Opts
SmallVectorImpl<const char*>& Args
clang::CompilerInvocation::StringAllocator SA
const llvm::Triple& T
const std::string& OutputFile
const clang::LangOptions* LangOpts

static void GenerateDiagnosticArgs(
    const clang::DiagnosticOptions& Opts,
    SmallVectorImpl<const char*>& Args,
    clang::CompilerInvocation::StringAllocator SA,
    bool DefaultDiagColor)

Description

Generate command line options from DiagnosticOptions.

Declared at: clang/include/clang/Frontend/CompilerInvocation.h:244

Parameters

const clang::DiagnosticOptions& Opts
SmallVectorImpl<const char*>& Args
clang::CompilerInvocation::StringAllocator SA
bool DefaultDiagColor

static void GenerateLangArgs(
    const clang::LangOptions& Opts,
    SmallVectorImpl<const char*>& Args,
    clang::CompilerInvocation::StringAllocator SA,
    const llvm::Triple& T,
    clang::InputKind IK)

Description

Generate command line options from LangOptions.

Declared at: clang/include/clang/Frontend/CompilerInvocation.h:255

Parameters

const clang::LangOptions& Opts
SmallVectorImpl<const char*>& Args
clang::CompilerInvocation::StringAllocator SA
const llvm::Triple& T
clang::InputKind IK

static std::string GetResourcesPath(
    const char* Argv0,
    void* MainAddr)

Description

Get the directory where the compiler headers reside, relative to the compiler binary (found by the passed in arguments).

Declared at: clang/include/clang/Frontend/CompilerInvocation.h:220

Parameters

const char* Argv0
- The program path (from argv[0]), for finding the builtin compiler path.
void* MainAddr
- The address of main (or some other function in the main executable), for finding the builtin compiler path.

static bool ParseCodeGenArgs(
    clang::CodeGenOptions& Opts,
    llvm::opt::ArgList& Args,
    clang::InputKind IK,
    clang::DiagnosticsEngine& Diags,
    const llvm::Triple& T,
    const std::string& OutputFile,
    const clang::LangOptions& LangOptsRef)

Description

Parse command line options that map to CodeGenOptions.

Declared at: clang/include/clang/Frontend/CompilerInvocation.h:261

Parameters

clang::CodeGenOptions& Opts
llvm::opt::ArgList& Args
clang::InputKind IK
clang::DiagnosticsEngine& Diags
const llvm::Triple& T
const std::string& OutputFile
const clang::LangOptions& LangOptsRef

static bool ParseLangArgs(
    clang::LangOptions& Opts,
    llvm::opt::ArgList& Args,
    clang::InputKind IK,
    const llvm::Triple& T,
    std::vector<std::string>& Includes,
    clang::DiagnosticsEngine& Diags)

Description

Parse command line options that map to LangOptions.

Declared at: clang/include/clang/Frontend/CompilerInvocation.h:249

Parameters

clang::LangOptions& Opts
llvm::opt::ArgList& Args
clang::InputKind IK
const llvm::Triple& T
std::vector<std::string>& Includes
clang::DiagnosticsEngine& Diags

void generateCC1CommandLine(
    llvm::SmallVectorImpl<const char*>& Args,
    clang::CompilerInvocation::StringAllocator SA)
    const

Description

Generate a cc1-compatible command line arguments from this instance.

Declared at: clang/include/clang/Frontend/CompilerInvocation.h:235

Parameters

llvm::SmallVectorImpl<const char*>& Args
- The generated arguments. Note that the caller is responsible for inserting the path to the clang executable and "-cc1" if desired.
clang::CompilerInvocation::StringAllocator SA
- A function that given a Twine can allocate storage for a given command line argument and return a pointer to the newly allocated string. The returned pointer is what gets appended to Args.

std::string getModuleHash() const

Description

Retrieve a module hash string that is suitable for uniquely identifying the conditions under which the module was built.

Declared at: clang/include/clang/Frontend/CompilerInvocation.h:224