15#include "clang/Config/config.h"
28#include "llvm/Option/OptTable.h"
29#include "llvm/Option/Option.h"
30#include "llvm/Support/BuryPointer.h"
31#include "llvm/Support/DynamicLibrary.h"
32#include "llvm/Support/ErrorHandling.h"
43static std::unique_ptr<FrontendAction>
46 StringRef Action(
"unknown");
51 bool EmitsCIR = Act == EmitCIR;
53 if (!UseCIR && EmitsCIR)
54 llvm::report_fatal_error(
"-emit-cir and only valid when using -fclangir");
57 case ASTDeclList:
return std::make_unique<ASTDeclListAction>();
58 case ASTDump:
return std::make_unique<ASTDumpAction>();
59 case ASTPrint:
return std::make_unique<ASTPrintAction>();
60 case ASTView:
return std::make_unique<ASTViewAction>();
61 case DumpCompilerOptions:
62 return std::make_unique<DumpCompilerOptionsAction>();
63 case DumpRawTokens:
return std::make_unique<DumpRawTokensAction>();
64 case DumpTokens:
return std::make_unique<DumpTokensAction>();
65 case EmitAssembly:
return std::make_unique<EmitAssemblyAction>();
66 case EmitBC:
return std::make_unique<EmitBCAction>();
69 return std::make_unique<cir::EmitCIRAction>();
71 llvm_unreachable(
"CIR suppport not built into clang");
73 case EmitHTML:
return std::make_unique<HTMLPrintAction>();
77 return std::make_unique<cir::EmitLLVMAction>();
79 return std::make_unique<EmitLLVMAction>();
81 case EmitLLVMOnly:
return std::make_unique<EmitLLVMOnlyAction>();
82 case EmitCodeGenOnly:
return std::make_unique<EmitCodeGenOnlyAction>();
83 case EmitObj:
return std::make_unique<EmitObjAction>();
85 return std::make_unique<ExtractAPIAction>();
86 case FixIt:
return std::make_unique<FixItAction>();
88 return std::make_unique<GenerateModuleFromModuleMapAction>();
89 case GenerateModuleInterface:
90 return std::make_unique<GenerateModuleInterfaceAction>();
91 case GenerateReducedModuleInterface:
92 return std::make_unique<GenerateReducedModuleInterfaceAction>();
93 case GenerateHeaderUnit:
94 return std::make_unique<GenerateHeaderUnitAction>();
95 case GeneratePCH:
return std::make_unique<GeneratePCHAction>();
96 case GenerateInterfaceStubs:
97 return std::make_unique<GenerateInterfaceStubsAction>();
98 case InitOnly:
return std::make_unique<InitOnlyAction>();
99 case ParseSyntaxOnly:
return std::make_unique<SyntaxOnlyAction>();
100 case ModuleFileInfo:
return std::make_unique<DumpModuleInfoAction>();
101 case VerifyPCH:
return std::make_unique<VerifyPCHAction>();
102 case TemplightDump:
return std::make_unique<TemplightDumpAction>();
105 for (
const FrontendPluginRegistry::entry &Plugin :
106 FrontendPluginRegistry::entries()) {
108 std::unique_ptr<PluginASTAction>
P(Plugin.instantiate());
124 case PrintPreamble:
return std::make_unique<PrintPreambleAction>();
125 case PrintPreprocessedInput: {
128 return std::make_unique<RewriteIncludesAction>();
129 return std::make_unique<PrintPreprocessedAction>();
132 case RewriteMacros:
return std::make_unique<RewriteMacrosAction>();
133 case RewriteTest:
return std::make_unique<RewriteTestAction>();
134#if CLANG_ENABLE_OBJC_REWRITER
135 case RewriteObjC:
return std::make_unique<RewriteObjCAction>();
137 case RewriteObjC: Action =
"RewriteObjC";
break;
139#if CLANG_ENABLE_STATIC_ANALYZER
140 case RunAnalysis:
return std::make_unique<ento::AnalysisAction>();
142 case RunAnalysis: Action =
"RunAnalysis";
break;
144 case RunPreprocessorOnly:
return std::make_unique<PreprocessOnlyAction>();
145 case PrintDependencyDirectivesSourceMinimizerOutput:
146 return std::make_unique<PrintDependencyDirectivesSourceMinimizerAction>();
149#if !CLANG_ENABLE_STATIC_ANALYZER || !CLANG_ENABLE_OBJC_REWRITER
153 llvm_unreachable(
"Invalid program action!");
157std::unique_ptr<FrontendAction>
167 Act = std::make_unique<FixItRecompile>(std::move(Act));
179 Act = std::make_unique<WrappingExtractAPIAction>(std::move(Act));
185 Act = std::make_unique<ASTMergeAction>(std::move(Act),
195 llvm::outs(),
"clang -cc1 [options] file...",
196 "LLVM 'Clang' Compiler: http://clang.llvm.org",
206 llvm::cl::PrintVersionMessage();
218 auto Args = std::make_unique<const char*[]>(NumArgs + 2);
219 Args[0] =
"clang (LLVM option parsing)";
220 for (
unsigned i = 0; i != NumArgs; ++i)
222 Args[NumArgs + 1] =
nullptr;
223 llvm::cl::ParseCommandLineOptions(NumArgs + 1, Args.get());
226#if CLANG_ENABLE_STATIC_ANALYZER
267 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.
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 > 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)
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...
@ Success
Template argument deduction was successful.