16 #include "clang/Config/config.h" 27 #include "llvm/Option/OptTable.h" 28 #include "llvm/Option/Option.h" 29 #include "llvm/Support/BuryPointer.h" 30 #include "llvm/Support/DynamicLibrary.h" 31 #include "llvm/Support/ErrorHandling.h" 32 using namespace clang;
37 static std::unique_ptr<FrontendAction>
40 StringRef Action(
"unknown");
44 case ASTDeclList:
return std::make_unique<ASTDeclListAction>();
45 case ASTDump:
return std::make_unique<ASTDumpAction>();
46 case ASTPrint:
return std::make_unique<ASTPrintAction>();
47 case ASTView:
return std::make_unique<ASTViewAction>();
49 return std::make_unique<DumpCompilerOptionsAction>();
50 case DumpRawTokens:
return std::make_unique<DumpRawTokensAction>();
51 case DumpTokens:
return std::make_unique<DumpTokensAction>();
52 case EmitAssembly:
return std::make_unique<EmitAssemblyAction>();
53 case EmitBC:
return std::make_unique<EmitBCAction>();
54 case EmitHTML:
return std::make_unique<HTMLPrintAction>();
55 case EmitLLVM:
return std::make_unique<EmitLLVMAction>();
56 case EmitLLVMOnly:
return std::make_unique<EmitLLVMOnlyAction>();
58 case EmitObj:
return std::make_unique<EmitObjAction>();
59 case FixIt:
return std::make_unique<FixItAction>();
61 return std::make_unique<GenerateModuleFromModuleMapAction>();
63 return std::make_unique<GenerateModuleInterfaceAction>();
65 return std::make_unique<GenerateHeaderModuleAction>();
66 case GeneratePCH:
return std::make_unique<GeneratePCHAction>();
68 return std::make_unique<GenerateInterfaceIfsExpV1Action>();
69 case InitOnly:
return std::make_unique<InitOnlyAction>();
71 case ModuleFileInfo:
return std::make_unique<DumpModuleInfoAction>();
72 case VerifyPCH:
return std::make_unique<VerifyPCHAction>();
73 case TemplightDump:
return std::make_unique<TemplightDumpAction>();
76 for (FrontendPluginRegistry::iterator it =
77 FrontendPluginRegistry::begin(), ie = FrontendPluginRegistry::end();
80 std::unique_ptr<PluginASTAction>
P(it->instantiate());
94 case PrintPreamble:
return std::make_unique<PrintPreambleAction>();
98 return std::make_unique<RewriteIncludesAction>();
99 return std::make_unique<PrintPreprocessedAction>();
102 case RewriteMacros:
return std::make_unique<RewriteMacrosAction>();
103 case RewriteTest:
return std::make_unique<RewriteTestAction>();
104 #if CLANG_ENABLE_OBJC_REWRITER 105 case RewriteObjC:
return std::make_unique<RewriteObjCAction>();
109 #if CLANG_ENABLE_ARCMT 111 return std::make_unique<arcmt::MigrateSourceAction>();
115 #if CLANG_ENABLE_STATIC_ANALYZER 116 case RunAnalysis:
return std::make_unique<ento::AnalysisAction>();
122 return std::make_unique<PrintDependencyDirectivesSourceMinimizerAction>();
125 #if !CLANG_ENABLE_ARCMT || !CLANG_ENABLE_STATIC_ANALYZER \ 126 || !CLANG_ENABLE_OBJC_REWRITER 130 llvm_unreachable(
"Invalid program action!");
134 std::unique_ptr<FrontendAction>
144 Act = std::make_unique<FixItRecompile>(std::move(Act));
147 #if CLANG_ENABLE_ARCMT 155 Act = std::make_unique<arcmt::CheckAction>(std::move(Act));
158 Act = std::make_unique<arcmt::ModifyAction>(std::move(Act));
161 Act = std::make_unique<arcmt::MigrateAction>(std::move(Act),
169 Act = std::make_unique<arcmt::ObjCMigrateAction>(std::move(Act),
179 Act = std::make_unique<ASTMergeAction>(std::move(Act),
189 llvm::outs(),
"clang -cc1 [options] file...",
190 "LLVM 'Clang' Compiler: http://clang.llvm.org",
200 llvm::cl::PrintVersionMessage();
209 if (llvm::sys::DynamicLibrary::LoadLibraryPermanently(Path.c_str(), &
Error))
215 for (FrontendPluginRegistry::iterator it = FrontendPluginRegistry::begin(),
216 ie = FrontendPluginRegistry::end();
218 std::unique_ptr<PluginASTAction>
P(it->instantiate());
232 auto Args = std::make_unique<const char*[]>(NumArgs + 2);
233 Args[0] =
"clang (LLVM option parsing)";
234 for (
unsigned i = 0; i != NumArgs; ++i)
236 Args[NumArgs + 1] =
nullptr;
237 llvm::cl::ParseCommandLineOptions(NumArgs + 1, Args.get());
240 #if CLANG_ENABLE_STATIC_ANALYZER 245 if (AnOpts.ShowCheckerHelp || AnOpts.ShowCheckerHelpAlpha ||
246 AnOpts.ShowCheckerHelpDeveloper) {
256 if (AnOpts.ShowCheckerOptionList || AnOpts.ShowCheckerOptionAlphaList ||
257 AnOpts.ShowCheckerOptionDeveloperList) {
267 if (AnOpts.ShowEnabledCheckerList) {
277 if (AnOpts.ShowConfigOptionsList) {
292 llvm::BuryPointer(std::move(Act));
Expand macros but not #includes.
LangOptions & getLangOpts()
bool hasErrorOccurred() const
void printEnabledCheckerList(raw_ostream &OS, ArrayRef< std::string > plugins, AnalyzerOptions &opts, DiagnosticsEngine &diags, const LangOptions &LangOpts)
Generate pre-compiled module from a module map.
Print the output of the dependency directives source minimizer.
Parse and perform semantic analysis.
std::unique_ptr< FrontendAction > CreateFrontendAction(CompilerInstance &CI)
Construct the FrontendAction of a compiler invocation based on the options specified for the compiler...
Parse ASTs and print them.
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
void printAnalyzerConfigList(raw_ostream &OS)
Parse and apply any fixits to the source.
Translate input source into HTML.
static std::unique_ptr< FrontendAction > CreateFrontendBaseAction(CompilerInstance &CI)
std::vector< std::string > ASTMergeFiles
The list of AST files to merge.
Action is determined by the cc1 command-line.
Generate LLVM IR, but do not emit anything.
FrontendOptions & getFrontendOpts()
PreprocessorOutputOptions & getPreprocessorOutputOpts()
void printCheckerHelp(raw_ostream &OS, ArrayRef< std::string > plugins, AnalyzerOptions &opts, DiagnosticsEngine &diags, const LangOptions &LangOpts)
AnalyzerOptionsRef getAnalyzerOpts()
unsigned FixAndRecompile
Apply fixes and recompile.
Dump the compiler configuration.
Dump template instantiations.
Dump out preprocessed tokens.
const llvm::opt::OptTable & getDriverOptTable()
Generate pre-compiled module from a C++ module interface file.
std::vector< std::string > Plugins
The list of plugins to load.
enum clang::FrontendOptions::@196 ARCMTAction
unsigned RewriteIncludes
Preprocess include directives only.
Generate Interface Stub Files.
Only execute frontend initialization.
Print the "preamble" of the input file.
void printCheckerConfigList(raw_ostream &OS, ArrayRef< std::string > plugins, AnalyzerOptions &opts, DiagnosticsEngine &diags, const LangOptions &LangOpts)
unsigned ARCMTMigrateEmitARCErrors
Emit ARC errors even if the migrator can fix them.
bool ExecuteAction(FrontendAction &Act)
ExecuteAction - Execute the provided action against the compiler's CompilerInvocation object...
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
Generate machine code, but don't emit anything.
Parse ASTs and view them in Graphviz.
Parse ASTs and list Decl nodes.
std::unordered_map< std::string, std::vector< std::string > > PluginArgs
Args to pass to the plugins.
Load and verify that a PCH file is usable.
unsigned ShowVersion
Show the -version text.
unsigned RewriteImports
Include contents of transitively-imported modules.
unsigned ShowHelp
Show the -help text.
Dataflow Directional Tag Classes.
frontend::ActionKind ProgramAction
The frontend action to perform.
std::string ARCMTMigrateReportOut
FrontendOptions - Options for controlling the behavior of the frontend.
Parse ASTs and dump them.
bool ExecuteCompilerInvocation(CompilerInstance *Clang)
ExecuteCompilerInvocation - Execute the given actions described by the compiler invocation object in ...
Stores options for the analyzer from the command line.
unsigned DisableFree
Disable memory freeing on exit.
Generate pre-compiled header.
Generate pre-compiled module from a set of header files.
std::string ActionName
The name of the action to run when using a plugin action.
Run one or more source code analyses.
DiagnosticsEngine & getDiagnostics() const
Get the current diagnostics engine.
std::vector< std::string > LLVMArgs
A list of arguments to forward to LLVM's option processing; this should only be used for debugging an...
Dump information about a module file.