clang API Documentation

Public Types | Public Member Functions | Static Public Member Functions | Public Attributes
clang::driver::Driver Class Reference

#include <Driver.h>

Collaboration diagram for clang::driver::Driver:
Collaboration graph
[legend]

List of all members.

Public Types

typedef SmallVector
< std::string, 4 > 
prefix_list
typedef SmallVector< std::pair
< types::ID, const
llvm::opt::Arg * >, 16 > 
InputList
 A list of inputs and their types for the given arguments.

Public Member Functions

DiagnosticBuilder Diag (unsigned DiagID) const
bool CCCIsCXX () const
 Whether the driver should follow g++ like behavior.
bool CCCIsCPP () const
 Whether the driver is just the preprocessor.
bool IsCLMode () const
 Whether the driver should follow cl.exe like behavior.
 Driver (StringRef _ClangExecutable, StringRef _DefaultTargetTriple, DiagnosticsEngine &_Diags)
 ~Driver ()
CompilationBuildCompilation (ArrayRef< const char * > Args)
void PrintActions (const Compilation &C) const
 PrintActions - Print the list of actions.
void PrintHelp (bool ShowHidden) const
void PrintVersion (const Compilation &C, raw_ostream &OS) const
 PrintVersion - Print the driver version.
std::string GetFilePath (const char *Name, const ToolChain &TC) const
std::string GetProgramPath (const char *Name, const ToolChain &TC) const
bool HandleImmediateArgs (const Compilation &C)
std::unique_ptr< ActionConstructPhaseAction (const llvm::opt::ArgList &Args, phases::ID Phase, std::unique_ptr< Action > Input) const
void BuildJobsForAction (Compilation &C, const Action *A, const ToolChain *TC, const char *BoundArch, bool AtTopLevel, bool MultipleArchs, const char *LinkingOutput, InputInfo &Result) const
const char * GetNamedOutputPath (Compilation &C, const JobAction &JA, const char *BaseInput, const char *BoundArch, bool AtTopLevel, bool MultipleArchs) const
std::string GetTemporaryPath (StringRef Prefix, const char *Suffix) const
bool ShouldUseClangCompiler (const JobAction &JA) const
bool IsUsingLTO (const llvm::opt::ArgList &Args) const
Accessors
const std::string & getCCCGenericGCCName () const
 Name to use when invoking gcc/g++.
const llvm::opt::OptTable & getOpts () const
const DiagnosticsEnginegetDiags () const
bool getCheckInputsExist () const
void setCheckInputsExist (bool Value)
const std::string & getTitle ()
void setTitle (std::string Value)
const char * getClangProgramPath () const
 Get the path to the main clang executable.
const char * getInstalledDir () const
 Get the path to where the clang executable was installed.
void setInstalledDir (StringRef Value)
Driver Steps
void ParseDriverMode (ArrayRef< const char * > Args)
 ParseDriverMode - Look for and handle the driver mode option in Args.
llvm::opt::InputArgList * ParseArgStrings (ArrayRef< const char * > Args)
void BuildInputs (const ToolChain &TC, llvm::opt::DerivedArgList &Args, InputList &Inputs) const
void BuildActions (const ToolChain &TC, llvm::opt::DerivedArgList &Args, const InputList &Inputs, ActionList &Actions) const
void BuildUniversalActions (const ToolChain &TC, llvm::opt::DerivedArgList &Args, const InputList &BAInputs, ActionList &Actions) const
void BuildJobs (Compilation &C) const
int ExecuteCompilation (Compilation &C, SmallVectorImpl< std::pair< int, const Command * > > &FailingCommands)
void generateCompilationDiagnostics (Compilation &C, const Command &FailingCommand)

Static Public Member Functions

static bool GetReleaseVersion (const char *Str, unsigned &Major, unsigned &Minor, unsigned &Micro, bool &HadExtra)

Public Attributes

std::string Name
 The name the driver was invoked as.
std::string Dir
std::string ClangExecutable
 The original path to the clang executable.
std::string InstalledDir
 The path to the installed clang directory, if any.
std::string ResourceDir
 The path to the compiler resource directory.
prefix_list PrefixDirs
std::string SysRoot
 sysroot, if present
std::string DyldPrefix
 Dynamic loader prefix, if present.
bool UseStdLib
 If the standard library is used.
std::string DefaultTargetTriple
 Default target triple.
std::string DefaultImageName
 Default name for linked images (e.g., "a.out").
std::string DriverTitle
 Driver title to use with help.
std::string HostBits
 Information about the host which can be overridden by the user.
std::string HostMachine
std::string HostSystem
std::string HostRelease
const char * CCPrintOptionsFilename
 The file to log CC_PRINT_OPTIONS output to, if enabled.
const char * CCPrintHeadersFilename
 The file to log CC_PRINT_HEADERS output to, if enabled.
const char * CCLogDiagnosticsFilename
 The file to log CC_LOG_DIAGNOSTICS output to, if enabled.
unsigned CCCPrintBindings: 1
 Only print tool bindings, don't build any jobs.
unsigned CCPrintOptions: 1
unsigned CCPrintHeaders: 1
unsigned CCLogDiagnostics: 1
unsigned CCGenDiagnostics: 1
 Whether the driver is generating diagnostics for debugging purposes.
unsigned CCCUsePCH: 1
 Use lazy precompiled headers for PCH support.

Detailed Description

Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like command line arguments.

Definition at line 52 of file Driver.h.


Member Typedef Documentation

typedef SmallVector<std::pair<types::ID, const llvm::opt::Arg *>, 16> clang::driver::Driver::InputList

A list of inputs and their types for the given arguments.

Definition at line 127 of file Driver.h.

typedef SmallVector<std::string, 4> clang::driver::Driver::prefix_list

A prefix directory used to emulated a limited subset of GCC's '-Bprefix' functionality. FIXME: This type of customization should be removed in favor of the universal driver when it is ready.

Definition at line 92 of file Driver.h.


Constructor & Destructor Documentation

Driver::Driver ( StringRef  _ClangExecutable,
StringRef  _DefaultTargetTriple,
DiagnosticsEngine _Diags 
)

Definition at line 47 of file Driver.cpp.

References CLANG_RESOURCE_DIR, CLANG_VERSION_STRING, Dir, Name, P, and ResourceDir.

Definition at line 75 of file Driver.cpp.


Member Function Documentation

void Driver::BuildActions ( const ToolChain TC,
llvm::opt::DerivedArgList &  Args,
const InputList Inputs,
ActionList Actions 
) const

BuildActions - Construct the list of actions to perform for the given arguments, which are only done for a single architecture.

Parameters:
TC- The default host tool chain.
Args- The input arguments.
Actions- The list to store the resulting actions onto.

Definition at line 1144 of file Driver.cpp.

References clang::driver::phases::Assemble, CCCIsCPP(), clang::driver::phases::Compile, ConstructPhaseAction(), Current, Diag(), clang::driver::types::getCompilationPhases(), clang::driver::phases::getPhaseName(), clang::driver::types::getPreprocessedType(), clang::driver::phases::Link, clang::driver::phases::Preprocess, and clang::driver::types::TY_INVALID.

Referenced by BuildCompilation(), BuildUniversalActions(), and generateCompilationDiagnostics().

Compilation * Driver::BuildCompilation ( ArrayRef< const char * >  Args)

BuildCompilation - Construct a compilation object for a command line argument vector.

Returns:
A compilation, or 0 if none was built for the given argument vector. A null return value does not necessarily indicate an error condition, the diagnostics should be queried to determine if an error occurred.

Definition at line 293 of file Driver.cpp.

References BuildActions(), BuildInputs(), BuildJobs(), BuildUniversalActions(), AttributeLangSupport::C, CCCPrintBindings, CCCUsePCH, DefaultTargetTriple, Dir, DyldPrefix, clang::driver::Compilation::getActions(), clang::driver::Compilation::getArgs(), clang::driver::Compilation::getDefaultToolChain(), clang::driver::ToolChain::getTriple(), HandleImmediateArgs(), InstalledDir, IsCLMode(), ParseArgStrings(), ParseDriverMode(), PrefixDirs, PrintActions(), ResourceDir, SysRoot, and UseStdLib.

Referenced by clang::createInvocationFromCommandLine().

void Driver::BuildInputs ( const ToolChain TC,
llvm::opt::DerivedArgList &  Args,
InputList Inputs 
) const

BuildInputs - Construct the list of inputs and their types from the given arguments.

Parameters:
TC- The default host tool chain.
Args- The input arguments.
Inputs- The list to store the resulting compilation inputs onto.

Definition at line 989 of file Driver.cpp.

References CCCIsCPP(), CCCIsCXX(), Diag(), DiagnoseInputExistence(), clang::driver::types::getTypeName(), IsCLMode(), clang::driver::options::LinkerInput, clang::driver::types::lookupCXXTypeForCType(), clang::driver::ToolChain::LookupTypeForExtension(), clang::driver::types::lookupTypeForTypeSpecifier(), MakeInputArg(), Previous, and clang::driver::types::TY_INVALID.

Referenced by BuildCompilation(), and generateCompilationDiagnostics().

void Driver::BuildJobs ( Compilation C) const

BuildJobs - Bind actions to concrete tools and translate arguments to form the list of jobs to run.

Parameters:
C- The compilation that is being built.

Definition at line 1377 of file Driver.cpp.

References BuildJobsForAction(), DefaultImageName, Diag(), clang::driver::Compilation::getActions(), clang::driver::Compilation::getArgs(), clang::driver::Compilation::getDefaultToolChain(), clang::driver::ToolChain::getTriple(), clang::DiagnosticsEngine::hasErrorOccurred(), and clang::driver::options::NoArgumentUnused.

Referenced by BuildCompilation(), and generateCompilationDiagnostics().

void Driver::BuildJobsForAction ( Compilation C,
const Action A,
const ToolChain TC,
const char *  BoundArch,
bool  AtTopLevel,
bool  MultipleArchs,
const char *  LinkingOutput,
InputInfo Result 
) const
void Driver::BuildUniversalActions ( const ToolChain TC,
llvm::opt::DerivedArgList &  Args,
const InputList BAInputs,
ActionList Actions 
) const

BuildUniversalActions - Construct the list of actions to perform for the given arguments, which may require a universal build.

Parameters:
TC- The default host tool chain.
Args- The input arguments.
Actions- The list to store the resulting actions onto.

Definition at line 862 of file Driver.cpp.

References BuildActions(), clang::driver::types::canLipoType(), ContainsCompileOrAssembleAction(), Diag(), clang::driver::tools::darwin::getArchTypeForMachOArchName(), clang::driver::ToolChain::getDefaultUniversalArchName(), clang::driver::Action::getType(), and clang::driver::types::getTypeName().

Referenced by BuildCompilation(), and generateCompilationDiagnostics().

Whether the driver is just the preprocessor.

Definition at line 133 of file Driver.h.

Referenced by BuildActions(), BuildInputs(), and CheckPreprocessingOptions().

std::unique_ptr< Action > Driver::ConstructPhaseAction ( const llvm::opt::ArgList &  Args,
phases::ID  Phase,
std::unique_ptr< Action Input 
) const

ConstructAction - Construct the appropriate action to do for Phase on the Input, taking in to account arguments like -fsyntax-only or --analyze.

Definition at line 1294 of file Driver.cpp.

References clang::driver::phases::Assemble, CCGenDiagnostics, clang::driver::phases::Compile, clang::driver::types::getPreprocessedType(), IsUsingLTO(), clang::driver::phases::Link, clang::driver::phases::Precompile, clang::driver::phases::Preprocess, and clang::driver::types::TY_INVALID.

Referenced by BuildActions().

Definition at line 66 of file Driver.h.

References clang::DiagnosticsEngine::Report().

Referenced by AddLinkerInputs(), clang::driver::toolchains::DarwinClang::AddLinkRuntimeLibArgs(), BuildActions(), clang::driver::toolchains::MSVCToolChain::buildAssembler(), BuildInputs(), BuildJobs(), BuildUniversalActions(), CheckCodeGenerationOptions(), clang::driver::toolchains::Darwin::CheckObjCARC(), CheckPreprocessingOptions(), clang::driver::Compilation::CleanupFile(), CollectArgsForIntegratedAssembler(), clang::driver::tools::Clang::ConstructJob(), clang::driver::tools::gcc::Common::ConstructJob(), clang::driver::tools::hexagon::Assemble::ConstructJob(), clang::driver::tools::gnutools::Link::ConstructJob(), clang::driver::toolchains::Darwin::Darwin(), DecodeAArch64Features(), DiagnoseInputExistence(), clang::driver::FallbackCommand::Execute(), clang::driver::Compilation::ExecuteCommand(), ExecuteCompilation(), generateCompilationDiagnostics(), getAArch64TargetFeatures(), getARMFPUFeatures(), getARMHWDivFeatures(), clang::driver::ToolChain::GetCXXStdlibType(), clang::driver::toolchains::Bitrig::GetCXXStdlibType(), clang::driver::toolchains::FreeBSD::GetCXXStdlibType(), clang::driver::toolchains::NetBSD::GetCXXStdlibType(), clang::driver::toolchains::Hexagon_TC::GetCXXStdlibType(), clang::driver::ToolChain::GetLinkerPath(), getMipsFloatABI(), getMIPSTargetFeatures(), clang::driver::ToolChain::GetRuntimeLibType(), GetTemporaryPath(), getX86TargetFeatures(), ParseArgStrings(), parseArgValues(), parseClangCLEHFlags(), ParseDriverMode(), clang::driver::tools::gcc::Compile::RenderExtraToolArgs(), clang::driver::SanitizerArgs::SanitizerArgs(), clang::driver::ToolChain::ToolChain(), clang::driver::toolchains::MachO::TranslateArgs(), and clang::driver::toolchains::Darwin::TranslateArgs().

int Driver::ExecuteCompilation ( Compilation C,
SmallVectorImpl< std::pair< int, const Command * > > &  FailingCommands 
)

ExecuteCompilation - Execute the compilation according to the command line arguments and return an appropriate exit code.

This routine handles additional processing that must be done in addition to just running the subprocesses, for example reporting errors, setting up response files, removing temporary files, etc.

Definition at line 580 of file Driver.cpp.

References clang::driver::Compilation::CleanupFileList(), clang::driver::Compilation::CleanupFileMap(), Diag(), clang::driver::Compilation::ExecuteJob(), clang::driver::Compilation::getArgs(), clang::driver::Command::getCreator(), clang::driver::Compilation::getFailureResultFiles(), clang::driver::Compilation::getJobs(), clang::driver::Compilation::getResultFiles(), clang::driver::Tool::getShortName(), clang::driver::Command::getSource(), clang::driver::Compilation::getTempFiles(), clang::DiagnosticsEngine::hasErrorOccurred(), clang::driver::Tool::hasGoodDiagnostics(), and clang::driver::JobList::Print().

void Driver::generateCompilationDiagnostics ( Compilation C,
const Command FailingCommand 
)
const std::string& clang::driver::Driver::getCCCGenericGCCName ( ) const [inline]

Name to use when invoking gcc/g++.

Definition at line 210 of file Driver.h.

Referenced by clang::driver::tools::gcc::Common::ConstructJob().

Definition at line 216 of file Driver.h.

Referenced by DiagnoseInputExistence().

const char* clang::driver::Driver::getClangProgramPath ( ) const [inline]

Get the path to the main clang executable.

Definition at line 224 of file Driver.h.

References ClangExecutable.

Referenced by clang::driver::tools::visualstudio::Link::ConstructJob(), and clang::driver::tools::visualstudio::Compile::GetCommand().

Definition at line 214 of file Driver.h.

std::string Driver::GetFilePath ( const char *  Name,
const ToolChain TC 
) const

GetFilePath - Lookup Name in the list of file search paths.

Parameters:
TC- The tool chain for additional information on directories to search.

Definition at line 1793 of file Driver.cpp.

References Dir, clang::driver::ToolChain::getFilePaths(), Name, P, PrefixDirs, ResourceDir, and SysRoot.

Referenced by clang::driver::ToolChain::GetFilePath(), and HandleImmediateArgs().

const char* clang::driver::Driver::getInstalledDir ( ) const [inline]

Get the path to where the clang executable was installed.

Definition at line 229 of file Driver.h.

References Dir, and InstalledDir.

const char * Driver::GetNamedOutputPath ( Compilation C,
const JobAction JA,
const char *  BaseInput,
const char *  BoundArch,
bool  AtTopLevel,
bool  MultipleArchs 
) const

GetNamedOutputPath - Return the name to use for the output of the action JA. The result is appended to the compilation's list of temporary or result files, as appropriate.

Parameters:
C- The compilation.
JA- The action of interest.
BaseInput- The original input file that this action was triggered by.
BoundArch- The bound architecture.
AtTopLevel- Whether this is a "top-level" action.
MultipleArchs- Whether multiple -arch options were supplied.

Definition at line 1650 of file Driver.cpp.

References clang::driver::Compilation::addResultFile(), clang::driver::Compilation::addTempFile(), clang::driver::types::appendSuffixForType(), CCGenDiagnostics, DefaultImageName, clang::driver::Compilation::getArgs(), GetTemporaryPath(), clang::driver::Action::getType(), clang::driver::types::getTypeTempSuffix(), IsCLMode(), MakeCLOutputFilename(), and Name.

Referenced by BuildJobsForAction().

const llvm::opt::OptTable& clang::driver::Driver::getOpts ( ) const [inline]
std::string Driver::GetProgramPath ( const char *  Name,
const ToolChain TC 
) const

GetProgramPath - Lookup Name in the list of program search paths.

Parameters:
TC- The provided tool chain for additional information on directories to search.

Definition at line 1850 of file Driver.cpp.

References clang::driver::ToolChain::getProgramPaths(), Name, P, PrefixDirs, and ScanDirForExecutable().

Referenced by clang::driver::ToolChain::GetProgramPath(), and HandleImmediateArgs().

bool Driver::GetReleaseVersion ( const char *  Str,
unsigned Major,
unsigned Minor,
unsigned Micro,
bool HadExtra 
) [static]

GetReleaseVersion - Parse (([0-9]+)(.([0-9]+)(.([0-9]+)?))?)? and return the grouped values as integers. Numbers which are not provided are set to 0.

Returns:
True if the entire string was parsed (9.2), or all groups were parsed (10.3.5extrastuff). HadExtra is true if all groups were parsed but extra characters remain at the end.

GetReleaseVersion - Parse (([0-9]+)(.([0-9]+)(.([0-9]+)?))?)? and return the grouped values as integers. Numbers which are not provided are set to 0.

Returns:
True if the entire string was parsed (9.2), or all groups were parsed (10.3.5extrastuff).

Definition at line 2097 of file Driver.cpp.

std::string Driver::GetTemporaryPath ( StringRef  Prefix,
const char *  Suffix 
) const

GetTemporaryPath - Return the pathname of a temporary file to use as part of compilation; the file will have the given prefix and suffix.

GCC goes to extra lengths here to be a bit more robust.

Definition at line 1885 of file Driver.cpp.

References Diag().

Referenced by GetNamedOutputPath().

const std::string& clang::driver::Driver::getTitle ( ) [inline]

Definition at line 220 of file Driver.h.

References DriverTitle.

bool Driver::IsUsingLTO ( const llvm::opt::ArgList &  Args) const
InputArgList * Driver::ParseArgStrings ( ArrayRef< const char * >  Args)

ParseArgStrings - Parse the given list of strings into an ArgList.

Definition at line 108 of file Driver.cpp.

References Diag(), getOpts(), clang::DiagnosticsEngine::Report(), and clang::driver::options::Unsupported.

Referenced by BuildCompilation().

void Driver::ParseDriverMode ( ArrayRef< const char * >  Args)

ParseDriverMode - Look for and handle the driver mode option in Args.

Definition at line 81 of file Driver.cpp.

References Diag(), and getOpts().

Referenced by BuildCompilation().

void Driver::PrintActions ( const Compilation C) const

PrintActions - Print the list of actions.

Definition at line 842 of file Driver.cpp.

References clang::driver::Compilation::getActions(), and PrintActions1().

Referenced by BuildCompilation().

void Driver::PrintHelp ( bool  ShowHidden) const

PrintHelp - Print the help text.

Parameters:
ShowHidden- Show hidden options.

Definition at line 643 of file Driver.cpp.

References DriverTitle, getOpts(), Name, and clang::driver::options::NoDriverOption.

Referenced by HandleImmediateArgs().

void Driver::PrintVersion ( const Compilation C,
raw_ostream &  OS 
) const

Definition at line 218 of file Driver.h.

Referenced by clang::createInvocationFromCommandLine().

void clang::driver::Driver::setInstalledDir ( StringRef  Value) [inline]

Definition at line 234 of file Driver.h.

References InstalledDir.

void clang::driver::Driver::setTitle ( std::string  Value) [inline]

Definition at line 221 of file Driver.h.

References DriverTitle.

Referenced by clang::tooling::newDriver().

ShouldUseClangCompiler - Should the clang compiler be used to handle this action.

Definition at line 2077 of file Driver.cpp.

References clang::driver::Action::begin(), clang::driver::types::isAcceptedByClang(), and clang::driver::Action::size().


Member Data Documentation

Only print tool bindings, don't build any jobs.

Definition at line 139 of file Driver.h.

Referenced by BuildCompilation(), and BuildJobsForAction().

Use lazy precompiled headers for PCH support.

Definition at line 167 of file Driver.h.

Referenced by BuildCompilation(), and clang::driver::tools::Clang::ConstructJob().

Whether the driver is generating diagnostics for debugging purposes.

Definition at line 155 of file Driver.h.

Referenced by BuildJobsForAction(), clang::driver::tools::Clang::ConstructJob(), ConstructPhaseAction(), generateCompilationDiagnostics(), and GetNamedOutputPath().

Set CC_LOG_DIAGNOSTICS mode, which causes the frontend to log diagnostics to CCLogDiagnosticsFilename or to stderr, in a stable machine readable format.

Definition at line 152 of file Driver.h.

Referenced by clang::driver::tools::Clang::ConstructJob().

The file to log CC_LOG_DIAGNOSTICS output to, if enabled.

Definition at line 123 of file Driver.h.

Referenced by clang::driver::tools::Clang::ConstructJob().

Set CC_PRINT_HEADERS mode, which causes the frontend to log header include information to CCPrintHeadersFilename or to stderr.

Definition at line 147 of file Driver.h.

Referenced by clang::driver::tools::Clang::ConstructJob().

The file to log CC_PRINT_HEADERS output to, if enabled.

Definition at line 120 of file Driver.h.

Referenced by clang::driver::tools::Clang::ConstructJob().

Set CC_PRINT_OPTIONS mode, which is like -v but logs the commands to CCPrintOptionsFilename or to stderr.

Definition at line 143 of file Driver.h.

The file to log CC_PRINT_OPTIONS output to, if enabled.

Definition at line 117 of file Driver.h.

The original path to the clang executable.

Definition at line 80 of file Driver.h.

Referenced by getClangProgramPath().

Default name for linked images (e.g., "a.out").

Definition at line 108 of file Driver.h.

Referenced by BuildJobs(), and GetNamedOutputPath().

Default target triple.

Definition at line 105 of file Driver.h.

Referenced by BuildCompilation().

The path the driver executable was in, as invoked from the command line.

Definition at line 77 of file Driver.h.

Referenced by clang::driver::toolchains::Linux::AddClangCXXStdlibIncludeArgs(), AddGoldPlugin(), BuildCompilation(), Driver(), GetFilePath(), getInstalledDir(), and clang::driver::toolchains::Linux::Linux().

Driver title to use with help.

Definition at line 111 of file Driver.h.

Referenced by getTitle(), PrintHelp(), and setTitle().

Dynamic loader prefix, if present.

Definition at line 99 of file Driver.h.

Referenced by BuildCompilation(), and clang::driver::tools::gnutools::Link::ConstructJob().

Information about the host which can be overridden by the user.

Definition at line 114 of file Driver.h.

Definition at line 114 of file Driver.h.

Definition at line 114 of file Driver.h.

Definition at line 114 of file Driver.h.

The name the driver was invoked as.

Definition at line 73 of file Driver.h.

Referenced by BuildJobsForAction(), Driver(), GetFilePath(), GetNamedOutputPath(), GetProgramPath(), and PrintHelp().

If the standard library is used.

Definition at line 102 of file Driver.h.

Referenced by BuildCompilation().


The documentation for this class was generated from the following files: