15#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"
34#include "mlir/IR/AsmState.h"
35#include "mlir/IR/MLIRContext.h"
36#include "mlir/Pass/PassManager.h"
46static std::unique_ptr<FrontendAction>
49 StringRef Action(
"unknown");
54 bool EmitsCIR = Act == EmitCIR;
56 if (!UseCIR && EmitsCIR)
57 llvm::report_fatal_error(
"-emit-cir and only valid when using -fclangir");
60 case ASTDeclList:
return std::make_unique<ASTDeclListAction>();
61 case ASTDump:
return std::make_unique<ASTDumpAction>();
62 case ASTPrint:
return std::make_unique<ASTPrintAction>();
63 case ASTView:
return std::make_unique<ASTViewAction>();
64 case DumpCompilerOptions:
65 return std::make_unique<DumpCompilerOptionsAction>();
66 case DumpRawTokens:
return std::make_unique<DumpRawTokensAction>();
67 case DumpTokens:
return std::make_unique<DumpTokensAction>();
71 return std::make_unique<cir::EmitAssemblyAction>();
73 return std::make_unique<EmitAssemblyAction>();
77 return std::make_unique<cir::EmitBCAction>();
79 return std::make_unique<EmitBCAction>();
82 return std::make_unique<cir::EmitCIRAction>();
84 llvm_unreachable(
"CIR suppport not built into clang");
86 case EmitHTML:
return std::make_unique<HTMLPrintAction>();
90 return std::make_unique<cir::EmitLLVMAction>();
92 return std::make_unique<EmitLLVMAction>();
94 case EmitLLVMOnly:
return std::make_unique<EmitLLVMOnlyAction>();
95 case EmitCodeGenOnly:
return std::make_unique<EmitCodeGenOnlyAction>();
99 return std::make_unique<cir::EmitObjAction>();
101 return std::make_unique<EmitObjAction>();
103 return std::make_unique<ExtractAPIAction>();
104 case FixIt:
return std::make_unique<FixItAction>();
106 return std::make_unique<GenerateModuleFromModuleMapAction>();
107 case GenerateModuleInterface:
108 return std::make_unique<GenerateModuleInterfaceAction>();
109 case GenerateReducedModuleInterface:
110 return std::make_unique<GenerateReducedModuleInterfaceAction>();
111 case GenerateHeaderUnit:
112 return std::make_unique<GenerateHeaderUnitAction>();
113 case GeneratePCH:
return std::make_unique<GeneratePCHAction>();
114 case GenerateInterfaceStubs:
115 return std::make_unique<GenerateInterfaceStubsAction>();
116 case InitOnly:
return std::make_unique<InitOnlyAction>();
117 case ParseSyntaxOnly:
return std::make_unique<SyntaxOnlyAction>();
118 case ModuleFileInfo:
return std::make_unique<DumpModuleInfoAction>();
119 case VerifyPCH:
return std::make_unique<VerifyPCHAction>();
120 case TemplightDump:
return std::make_unique<TemplightDumpAction>();
123 for (
const FrontendPluginRegistry::entry &Plugin :
124 FrontendPluginRegistry::entries()) {
126 std::unique_ptr<PluginASTAction>
P(Plugin.instantiate());
142 case PrintPreamble:
return std::make_unique<PrintPreambleAction>();
143 case PrintPreprocessedInput: {
146 return std::make_unique<RewriteIncludesAction>();
147 return std::make_unique<PrintPreprocessedAction>();
150 case RewriteMacros:
return std::make_unique<RewriteMacrosAction>();
151 case RewriteTest:
return std::make_unique<RewriteTestAction>();
152#if CLANG_ENABLE_OBJC_REWRITER
153 case RewriteObjC:
return std::make_unique<RewriteObjCAction>();
155 case RewriteObjC: Action =
"RewriteObjC";
break;
157#if CLANG_ENABLE_STATIC_ANALYZER
158 case RunAnalysis:
return std::make_unique<ento::AnalysisAction>();
160 case RunAnalysis: Action =
"RunAnalysis";
break;
162 case RunPreprocessorOnly:
return std::make_unique<PreprocessOnlyAction>();
163 case PrintDependencyDirectivesSourceMinimizerOutput:
164 return std::make_unique<PrintDependencyDirectivesSourceMinimizerAction>();
167#if !CLANG_ENABLE_STATIC_ANALYZER || !CLANG_ENABLE_OBJC_REWRITER
171 llvm_unreachable(
"Invalid program action!");
175std::unique_ptr<FrontendAction>
185 Act = std::make_unique<HLSLFrontendAction>(std::move(Act));
188 Act = std::make_unique<FixItRecompile>(std::move(Act));
200 Act = std::make_unique<WrappingExtractAPIAction>(std::move(Act));
206 Act = std::make_unique<ASTMergeAction>(std::move(Act),
216 llvm::outs(),
"clang -cc1 [options] file...",
217 "LLVM 'Clang' Compiler: http://clang.llvm.org",
227 llvm::cl::PrintVersionMessage();
239 auto Args = std::make_unique<const char*[]>(NumArgs + 2);
240 Args[0] =
"clang (LLVM option parsing)";
241 for (
unsigned i = 0; i != NumArgs; ++i)
243 Args[NumArgs + 1] =
nullptr;
244 llvm::cl::ParseCommandLineOptions(NumArgs + 1, Args.get());
247#if CLANG_ENABLE_STATIC_ANALYZER
281 mlir::registerCIRPasses();
282 mlir::registerMLIRContextCLOptions();
283 mlir::registerPassManagerCLOptions();
284 mlir::registerAsmPrinterCLOptions();
286 auto Args = std::make_unique<const char *[]>(NumArgs + 2);
287 Args[0] =
"clang (MLIR option parsing)";
288 for (
unsigned i = 0; i != NumArgs; ++i)
290 Args[NumArgs + 1] =
nullptr;
291 llvm::cl::ParseCommandLineOptions(NumArgs + 1, Args.get());
304 llvm::BuryPointer(std::move(Act));
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()
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.
bool hasErrorOccurred() 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.
const llvm::opt::OptTable & getDriverOptTable()
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)
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...