clang: lib/FrontendTool/ExecuteCompilerInvocation.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

16#include "clang/Config/config.h"

28#include "llvm/Option/OptTable.h"

29#include "llvm/Support/BuryPointer.h"

30#include "llvm/Support/DynamicLibrary.h"

31#include "llvm/Support/ErrorHandling.h"

32

33#if CLANG_ENABLE_CIR

34#include "mlir/IR/AsmState.h"

35#include "mlir/IR/MLIRContext.h"

36#include "mlir/Pass/PassManager.h"

39#endif

40

41using namespace clang;

43

45

46static std::unique_ptr

49 StringRef Action("unknown");

50 (void)Action;

51

54 bool EmitsCIR = Act == EmitCIR;

55

56 if (!UseCIR && EmitsCIR)

57 llvm::report_fatal_error("-emit-cir and only valid when using -fclangir");

58

60 case ASTDeclList: return std::make_unique();

61 case ASTDump: return std::make_unique();

62 case ASTPrint: return std::make_unique();

63 case ASTView: return std::make_unique();

65 return std::make_unique();

66 case DumpRawTokens: return std::make_unique();

67 case DumpTokens: return std::make_unique();

69#if CLANG_ENABLE_CIR

70 if (UseCIR)

71 return std::make_uniquecir::EmitAssemblyAction();

72#endif

73 return std::make_unique();

75#if CLANG_ENABLE_CIR

76 if (UseCIR)

77 return std::make_uniquecir::EmitBCAction();

78#endif

79 return std::make_unique();

81#if CLANG_ENABLE_CIR

82 return std::make_uniquecir::EmitCIRAction();

83#else

85 return nullptr;

86#endif

87 case EmitHTML: return std::make_unique();

89#if CLANG_ENABLE_CIR

90 if (UseCIR)

91 return std::make_uniquecir::EmitLLVMAction();

92#endif

93 return std::make_unique();

94 }

95 case EmitLLVMOnly: return std::make_unique();

96 case EmitCodeGenOnly: return std::make_unique();

98#if CLANG_ENABLE_CIR

99 if (UseCIR)

100 return std::make_uniquecir::EmitObjAction();

101#endif

102 return std::make_unique();

104 return std::make_unique();

105 case FixIt: return std::make_unique();

107 return std::make_unique();

109 return std::make_unique();

111 return std::make_unique();

113 return std::make_unique();

114 case GeneratePCH: return std::make_unique();

116 return std::make_unique();

117 case InitOnly: return std::make_unique();

118 case ParseSyntaxOnly: return std::make_unique();

119 case ModuleFileInfo: return std::make_unique();

120 case VerifyPCH: return std::make_unique();

121 case TemplightDump: return std::make_unique();

122

124 for (const FrontendPluginRegistry::entry &Plugin :

125 FrontendPluginRegistry::entries()) {

127 std::unique_ptr P(Plugin.instantiate());

130 !P->ParseArgs(

131 CI,

133 return nullptr;

134 return std::move(P);

135 }

136 }

137

140 return nullptr;

141 }

142

143 case PrintPreamble: return std::make_unique();

147 return std::make_unique();

148 return std::make_unique();

149 }

150

151 case RewriteMacros: return std::make_unique();

152 case RewriteTest: return std::make_unique();

153#if CLANG_ENABLE_OBJC_REWRITER

154 case RewriteObjC: return std::make_unique();

155#else

156 case RewriteObjC: Action = "RewriteObjC"; break;

157#endif

158#if CLANG_ENABLE_STATIC_ANALYZER

159 case RunAnalysis: return std::make_uniqueento::AnalysisAction();

160#else

161 case RunAnalysis: Action = "RunAnalysis"; break;

162#endif

163 case RunPreprocessorOnly: return std::make_unique();

165 return std::make_unique();

166 }

167

168#if !CLANG_ENABLE_STATIC_ANALYZER || !CLANG_ENABLE_OBJC_REWRITER

170 return 0;

171#else

172 llvm_unreachable("Invalid program action!");

173#endif

174}

175

176std::unique_ptr

178

180 if (!Act)

181 return nullptr;

182

184

186 Act = std::make_unique(std::move(Act));

187

189 Act = std::make_unique(std::move(Act));

190 }

191

192

193

194

199 }

201 Act = std::make_unique(std::move(Act));

202 }

203

204

205

207 Act = std::make_unique(std::move(Act),

209

210 return Act;

211}

212

215

216

219 llvm::outs(), "clang -cc1 [options] file...",

220 "LLVM 'Clang' Compiler: http://clang.llvm.org",

221 false, false,

223 return true;

224 }

225

226

227

228

230 llvm:🆑:PrintVersionMessage();

231 return true;

232 }

233

235

236

237

238

239

242 auto Args = std::make_unique<const char*[]>(NumArgs + 2);

243 Args[0] = "clang (LLVM option parsing)";

244 for (unsigned i = 0; i != NumArgs; ++i)

246 Args[NumArgs + 1] = nullptr;

247 llvm:🆑:ParseCommandLineOptions(NumArgs + 1, Args.get(), "",

248 nullptr,

250 }

251

252#if CLANG_ENABLE_STATIC_ANALYZER

253

254

256

257

261 return true;

262 }

263

264

268 return true;

269 }

270

271

274 return true;

275 }

276

277

280 return true;

281 }

282#endif

283

284#if CLANG_ENABLE_CIR

286 mlir::registerCIRPasses();

287 mlir::registerMLIRContextCLOptions();

288 mlir::registerPassManagerCLOptions();

289 mlir::registerAsmPrinterCLOptions();

291 auto Args = std::make_unique<const char *[]>(NumArgs + 2);

292 Args[0] = "clang (MLIR option parsing)";

293 for (unsigned i = 0; i != NumArgs; ++i)

295 Args[NumArgs + 1] = nullptr;

296 llvm:🆑:ParseCommandLineOptions(NumArgs + 1, Args.get());

297 }

298#endif

299

300

301

302

304 return false;

305

306

308 if (!Act)

309 return false;

312 llvm::BuryPointer(std::move(Act));

314}

315

316}

Stores options for the analyzer from the command line.

unsigned ShowCheckerOptionDeveloperList

unsigned ShowEnabledCheckerList

unsigned ShowCheckerHelpAlpha

unsigned ShowConfigOptionsList

unsigned ShowCheckerHelpDeveloper

unsigned ShowCheckerOptionList

unsigned ShowCheckerOptionAlphaList

CompilerInstance - Helper class for managing a single instance of the Clang compiler.

AnalyzerOptions & getAnalyzerOpts()

DiagnosticsEngine & getDiagnostics() const

Get the current diagnostics engine.

PreprocessorOutputOptions & getPreprocessorOutputOpts()

void LoadRequestedPlugins()

Load the list of plugins requested in the FrontendOptions.

FrontendOptions & getFrontendOpts()

llvm::vfs::FileSystem & getVirtualFileSystem() const

bool ExecuteAction(FrontendAction &Act)

ExecuteAction - Execute the provided action against the compiler's CompilerInvocation object.

LangOptions & getLangOpts()

CodeGenOptions & getCodeGenOpts()

DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)

Issue the message to the client.

unsigned getNumErrors() const

FrontendOptions - Options for controlling the behavior of the frontend.

unsigned EmitSymbolGraph

Whether to emit symbol graph files as a side effect of compilation.

std::map< std::string, std::vector< std::string > > PluginArgs

Args to pass to the plugins.

std::vector< std::string > MLIRArgs

A list of arguments to forward to MLIR's option processing; this should only be used for debugging an...

std::vector< std::string > LLVMArgs

A list of arguments to forward to LLVM's option processing; this should only be used for debugging an...

unsigned ShowHelp

Show the -help text.

unsigned FixAndRecompile

Apply fixes and recompile.

unsigned UseClangIRPipeline

Use Clang IR pipeline to emit code.

std::string ActionName

The name of the action to run when using a plugin action.

unsigned ShowVersion

Show the -version text.

std::string SymbolGraphOutputDir

std::vector< std::string > ASTMergeFiles

The list of AST files to merge.

unsigned DisableFree

Disable memory freeing on exit.

frontend::ActionKind ProgramAction

The frontend action to perform.

@ ReplaceAction

Replace the main action.

@ CmdlineAfterMainAction

Execute the action after the main action if on the command line.

unsigned RewriteIncludes

Preprocess include directives only.

unsigned RewriteImports

Include contents of transitively-imported modules.

void printEnabledCheckerList(llvm::raw_ostream &OS, CompilerInstance &CI)

void printCheckerHelp(llvm::raw_ostream &OS, CompilerInstance &CI)

void printAnalyzerConfigList(llvm::raw_ostream &OS)

void printCheckerConfigList(llvm::raw_ostream &OS, CompilerInstance &CI)

@ GenerateHeaderUnit

Generate a C++20 header unit module from a header file.

@ VerifyPCH

Load and verify that a PCH file is usable.

@ PrintPreprocessedInput

-E mode.

@ RewriteTest

Rewriter playground.

@ ParseSyntaxOnly

Parse and perform semantic analysis.

@ TemplightDump

Dump template instantiations.

@ GenerateModuleInterface

Generate pre-compiled module from a standard C++ module interface unit.

@ EmitLLVM

Emit a .ll file.

@ PrintPreamble

Print the "preamble" of the input file.

@ InitOnly

Only execute frontend initialization.

@ ASTView

Parse ASTs and view them in Graphviz.

@ PluginAction

Run a plugin action,.

@ DumpRawTokens

Dump out raw tokens.

@ PrintDependencyDirectivesSourceMinimizerOutput

Print the output of the dependency directives source minimizer.

@ RewriteObjC

ObjC->C Rewriter.

@ RunPreprocessorOnly

Just lex, no output.

@ EmitCIR

Emit a .cir file.

@ DumpCompilerOptions

Dump the compiler configuration.

@ RunAnalysis

Run one or more source code analyses.

@ ASTPrint

Parse ASTs and print them.

@ GenerateReducedModuleInterface

Generate reduced module interface for a standard C++ module interface unit.

@ GenerateInterfaceStubs

Generate Interface Stub Files.

@ ASTDump

Parse ASTs and dump them.

@ DumpTokens

Dump out preprocessed tokens.

@ FixIt

Parse and apply any fixits to the source.

@ EmitAssembly

Emit a .s file.

@ EmitCodeGenOnly

Generate machine code, but don't emit anything.

@ RewriteMacros

Expand macros but not #includes.

@ EmitHTML

Translate input source into HTML.

@ GeneratePCH

Generate pre-compiled header.

@ EmitLLVMOnly

Generate LLVM IR, but do not emit anything.

@ GenerateModule

Generate pre-compiled module from a module map.

@ ASTDeclList

Parse ASTs and list Decl nodes.

The JSON file list parser is used to communicate input to InstallAPI.

static std::unique_ptr< FrontendAction > CreateFrontendBaseAction(CompilerInstance &CI)

Definition ExecuteCompilerInvocation.cpp:47

@ Success

Annotation was successful.

bool ExecuteCompilerInvocation(CompilerInstance *Clang)

ExecuteCompilerInvocation - Execute the given actions described by the compiler invocation object in ...

Definition ExecuteCompilerInvocation.cpp:213

std::unique_ptr< FrontendAction > CreateFrontendAction(CompilerInstance &CI)

Construct the FrontendAction of a compiler invocation based on the options specified for the compiler...

Definition ExecuteCompilerInvocation.cpp:177

const llvm::opt::OptTable & getDriverOptTable()