16#include "clang/Config/config.h"
32#include "llvm/Option/OptTable.h"
33#include "llvm/Support/BuryPointer.h"
34#include "llvm/Support/DynamicLibrary.h"
35#include "llvm/Support/ErrorHandling.h"
38#include "mlir/IR/AsmState.h"
39#include "mlir/IR/MLIRContext.h"
40#include "mlir/Pass/PassManager.h"
50static std::unique_ptr<FrontendAction>
53 StringRef Action(
"unknown");
60 if (!UseCIR && EmitsCIR)
61 llvm::report_fatal_error(
"-emit-cir and only valid when using -fclangir");
64 case ASTDeclList:
return std::make_unique<ASTDeclListAction>();
65 case ASTDump:
return std::make_unique<ASTDumpAction>();
66 case ASTPrint:
return std::make_unique<ASTPrintAction>();
67 case ASTView:
return std::make_unique<ASTViewAction>();
69 return std::make_unique<DumpCompilerOptionsAction>();
70 case DumpRawTokens:
return std::make_unique<DumpRawTokensAction>();
71 case DumpTokens:
return std::make_unique<DumpTokensAction>();
75 return std::make_unique<cir::EmitAssemblyAction>();
77 return std::make_unique<EmitAssemblyAction>();
81 return std::make_unique<cir::EmitBCAction>();
83 return std::make_unique<EmitBCAction>();
86 return std::make_unique<cir::EmitCIRAction>();
91 case EmitHTML:
return std::make_unique<HTMLPrintAction>();
95 return std::make_unique<cir::EmitLLVMAction>();
97 return std::make_unique<EmitLLVMAction>();
99 case EmitLLVMOnly:
return std::make_unique<EmitLLVMOnlyAction>();
100 case EmitCodeGenOnly:
return std::make_unique<EmitCodeGenOnlyAction>();
104 return std::make_unique<cir::EmitObjAction>();
106 return std::make_unique<EmitObjAction>();
108 return std::make_unique<ExtractAPIAction>();
109 case FixIt:
return std::make_unique<FixItAction>();
111 return std::make_unique<GenerateModuleFromModuleMapAction>();
113 return std::make_unique<GenerateModuleInterfaceAction>();
115 return std::make_unique<GenerateReducedModuleInterfaceAction>();
117 return std::make_unique<GenerateHeaderUnitAction>();
118 case GeneratePCH:
return std::make_unique<GeneratePCHAction>();
120 return std::make_unique<GenerateInterfaceStubsAction>();
121 case InitOnly:
return std::make_unique<InitOnlyAction>();
123 case ModuleFileInfo:
return std::make_unique<DumpModuleInfoAction>();
125 return std::make_unique<VerifyPCHAction>();
128 for (
const FrontendPluginRegistry::entry &Plugin :
129 FrontendPluginRegistry::entries()) {
131 std::unique_ptr<PluginASTAction> P(Plugin.instantiate());
147 case PrintPreamble:
return std::make_unique<PrintPreambleAction>();
151 return std::make_unique<RewriteIncludesAction>();
152 return std::make_unique<PrintPreprocessedAction>();
155 case RewriteMacros:
return std::make_unique<RewriteMacrosAction>();
156 case RewriteTest:
return std::make_unique<RewriteTestAction>();
157#if CLANG_ENABLE_OBJC_REWRITER
158 case RewriteObjC:
return std::make_unique<RewriteObjCAction>();
162#if CLANG_ENABLE_STATIC_ANALYZER
163 case RunAnalysis:
return std::make_unique<ento::AnalysisAction>();
169 return std::make_unique<PrintDependencyDirectivesSourceMinimizerAction>();
172#if !CLANG_ENABLE_STATIC_ANALYZER || !CLANG_ENABLE_OBJC_REWRITER
176 llvm_unreachable(
"Invalid program action!");
180std::unique_ptr<FrontendAction>
190 Act = std::make_unique<HLSLFrontendAction>(std::move(Act));
193 Act = std::make_unique<FixItRecompile>(std::move(Act));
205 Act = std::make_unique<WrappingExtractAPIAction>(std::move(Act));
211 Act = std::make_unique<ASTMergeAction>(std::move(Act),
215 Act = std::make_unique<ssaf::TUSummaryExtractorFrontendAction>(
226 Act = std::make_unique<ssaf::SourceTransformationFrontendAction>(
238 llvm::outs(),
"clang -cc1 [options] file...",
239 "LLVM 'Clang' Compiler: http://clang.llvm.org",
249 llvm::cl::PrintVersionMessage();
261 auto Args = std::make_unique<const char*[]>(NumArgs + 2);
262 Args[0] =
"clang (LLVM option parsing)";
263 for (
unsigned i = 0; i != NumArgs; ++i)
265 Args[NumArgs + 1] =
nullptr;
266 llvm::cl::ParseCommandLineOptions(NumArgs + 1, Args.get(),
"",
271#if CLANG_ENABLE_STATIC_ANALYZER
305 mlir::registerCIRPasses();
306 mlir::registerMLIRContextCLOptions();
307 mlir::registerPassManagerCLOptions();
308 mlir::registerAsmPrinterCLOptions();
310 auto Args = std::make_unique<const char *[]>(NumArgs + 2);
311 Args[0] =
"clang (MLIR option parsing)";
312 for (
unsigned i = 0; i != NumArgs; ++i)
314 Args[NumArgs + 1] =
nullptr;
315 llvm::cl::ParseCommandLineOptions(NumArgs + 1, Args.get(),
333 llvm::BuryPointer(std::move(Act));
This file pulls in all built-in SSAF extractor and format registrations by referencing their anchor s...
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()
ssaf::SSAFOptions & getSSAFOpts()
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.
std::string SrcEditFile
Path of the source-edit output file produced by the source transformation.
std::string TransformationReportFile
Path of the transformation-report output file produced by the source transformation.
std::string SourceTransformation
Name of the SSAF source transformation to run.
std::string TUSummaryFile
The TU summary output file with the file extension representing the serialization format.
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.
@ 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)
@ Success
Annotation was successful.
bool ExecuteCompilerInvocation(CompilerInstance *Clang)
ExecuteCompilerInvocation - Execute the given actions described by the compiler invocation object in ...
std::unique_ptr< FrontendAction > CreateFrontendAction(CompilerInstance &CI)
Construct the FrontendAction of a compiler invocation based on the options specified for the compiler...
const llvm::opt::OptTable & getDriverOptTable()