From 9a8a83b8fe5be9a4ca20ec6eeaafaf201ce594f9 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Sat, 14 Nov 2009 22:32:38 +0000 Subject: [PATCH] Move the program action enum to FrontendOptions. -- ddunbar@giles:clang-cc (master)$ grep llvm::cl::opt clang-cc.cpp # Woot ddunbar@giles:clang-cc (master)$ -- git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@88820 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Frontend/FrontendOptions.h | 37 ++++++++ tools/clang-cc/Options.cpp | 61 +++++++++++++ tools/clang-cc/clang-cc.cpp | 106 ++--------------------- 3 files changed, 106 insertions(+), 98 deletions(-) diff --git a/include/clang/Frontend/FrontendOptions.h b/include/clang/Frontend/FrontendOptions.h index 23a1702098..adb591ee06 100644 --- a/include/clang/Frontend/FrontendOptions.h +++ b/include/clang/Frontend/FrontendOptions.h @@ -17,6 +17,39 @@ namespace clang { +namespace frontend { + enum ActionKind { + ASTDump, ///< Parse ASTs and dump them. + ASTPrint, ///< Parse ASTs and print them. + ASTPrintXML, ///< Parse ASTs and print them in XML. + ASTView, ///< Parse ASTs and view them in Graphviz. + DumpRawTokens, ///< Dump out raw tokens. + DumpRecordLayouts, ///< Dump record layout information. + DumpTokens, ///< Dump out preprocessed tokens. + EmitAssembly, ///< Emit a .s file. + EmitBC, ///< Emit a .bc file. + EmitHTML, ///< Translate input source into HTML. + EmitLLVM, ///< Emit a .ll file. + EmitLLVMOnly, ///< Generate LLVM IR, but do not + FixIt, ///< Parse and apply any fixits to the source. + GeneratePCH, ///< Generate pre-compiled header. + GeneratePTH, ///< Generate pre-tokenized header. + HTMLTest, ///< HTML displayer testing stuff. + InheritanceView, ///< View C++ inheritance for a specified class. + ParseNoop, ///< Parse with noop callbacks. + ParsePrintCallbacks, ///< Parse and print each callback. + ParseSyntaxOnly, ///< Parse and perform semantic analysis. + PrintDeclContext, ///< Print DeclContext and their Decls. + PrintPreprocessedInput, ///< -E mode. + RewriteBlocks, ///< ObjC->C Rewriter for Blocks. + RewriteMacros, ///< Expand macros but not #includes. + RewriteObjC, ///< ObjC->C Rewriter. + RewriteTest, ///< Rewriter playground + RunAnalysis, ///< Run one or more source code analyses. + RunPreprocessorOnly ///< Just lex, no output. + }; +} + /// FrontendOptions - Options for controlling the behavior of the frontend. class FrontendOptions { public: @@ -73,11 +106,15 @@ public: /// If given, enable code completion at the provided location. ParsedSourceLocation CodeCompletionAt; + /// The frontend action to perform. + frontend::ActionKind ProgramAction; + public: FrontendOptions() { DebugCodeCompletionPrinter = 0; DisableFree = 0; EmptyInputOnly = 0; + ProgramAction = frontend::ParseSyntaxOnly; RelocatablePCH = 0; ShowMacrosInCodeCompletion = 0; ShowStats = 0; diff --git a/tools/clang-cc/Options.cpp b/tools/clang-cc/Options.cpp index 47bed4f89f..33b8d77d15 100644 --- a/tools/clang-cc/Options.cpp +++ b/tools/clang-cc/Options.cpp @@ -303,6 +303,8 @@ VerifyDiagnostics("verify", namespace frontendoptions { +using namespace clang::frontend; + static llvm::cl::opt CodeCompletionAt("code-completion-at", llvm::cl::value_desc("file:line:column"), @@ -381,6 +383,64 @@ OutputFile("o", llvm::cl::value_desc("path"), llvm::cl::desc("Specify output file")); +static llvm::cl::opt +ProgAction(llvm::cl::desc("Choose output type:"), llvm::cl::ZeroOrMore, + llvm::cl::init(ParseSyntaxOnly), + llvm::cl::values( + clEnumValN(RunPreprocessorOnly, "Eonly", + "Just run preprocessor, no output (for timings)"), + clEnumValN(PrintPreprocessedInput, "E", + "Run preprocessor, emit preprocessed file"), + clEnumValN(DumpRawTokens, "dump-raw-tokens", + "Lex file in raw mode and dump raw tokens"), + clEnumValN(RunAnalysis, "analyze", + "Run static analysis engine"), + clEnumValN(DumpTokens, "dump-tokens", + "Run preprocessor, dump internal rep of tokens"), + clEnumValN(ParseNoop, "parse-noop", + "Run parser with noop callbacks (for timings)"), + clEnumValN(ParseSyntaxOnly, "fsyntax-only", + "Run parser and perform semantic analysis"), + clEnumValN(FixIt, "fixit", + "Apply fix-it advice to the input source"), + clEnumValN(ParsePrintCallbacks, "parse-print-callbacks", + "Run parser and print each callback invoked"), + clEnumValN(EmitHTML, "emit-html", + "Output input source as HTML"), + clEnumValN(ASTPrint, "ast-print", + "Build ASTs and then pretty-print them"), + clEnumValN(ASTPrintXML, "ast-print-xml", + "Build ASTs and then print them in XML format"), + clEnumValN(ASTDump, "ast-dump", + "Build ASTs and then debug dump them"), + clEnumValN(ASTView, "ast-view", + "Build ASTs and view them with GraphViz"), + clEnumValN(PrintDeclContext, "print-decl-contexts", + "Print DeclContexts and their Decls"), + clEnumValN(DumpRecordLayouts, "dump-record-layouts", + "Dump record layout information"), + clEnumValN(GeneratePTH, "emit-pth", + "Generate pre-tokenized header file"), + clEnumValN(GeneratePCH, "emit-pch", + "Generate pre-compiled header file"), + clEnumValN(EmitAssembly, "S", + "Emit native assembly code"), + clEnumValN(EmitLLVM, "emit-llvm", + "Build ASTs then convert to LLVM, emit .ll file"), + clEnumValN(EmitBC, "emit-llvm-bc", + "Build ASTs then convert to LLVM, emit .bc file"), + clEnumValN(EmitLLVMOnly, "emit-llvm-only", + "Build ASTs and convert to LLVM, discarding output"), + clEnumValN(RewriteTest, "rewrite-test", + "Rewriter playground"), + clEnumValN(RewriteObjC, "rewrite-objc", + "Rewrite ObjC into C (code rewriter example)"), + clEnumValN(RewriteMacros, "rewrite-macros", + "Expand macros without full preprocessing"), + clEnumValN(RewriteBlocks, "rewrite-blocks", + "Rewrite Blocks to C"), + clEnumValEnd)); + static llvm::cl::opt RelocatablePCH("relocatable-pch", llvm::cl::desc("Whether to build a relocatable precompiled " @@ -830,6 +890,7 @@ void clang::InitializeFrontendOptions(FrontendOptions &Opts) { Opts.DisableFree = DisableFree; Opts.EmptyInputOnly = EmptyInputOnly; Opts.FixItLocations = FixItAtLocations; + Opts.ProgramAction = ProgAction; Opts.OutputFile = OutputFile; Opts.RelocatablePCH = RelocatablePCH; Opts.ShowMacrosInCodeCompletion = CodeCompletionWantsMacros; diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp index 35ae4b0234..75640acfed 100644 --- a/tools/clang-cc/clang-cc.cpp +++ b/tools/clang-cc/clang-cc.cpp @@ -49,99 +49,6 @@ using namespace clang; -//===----------------------------------------------------------------------===// -// Frontend Actions -//===----------------------------------------------------------------------===// - -enum ProgActions { - RewriteObjC, // ObjC->C Rewriter. - RewriteBlocks, // ObjC->C Rewriter for Blocks. - RewriteMacros, // Expand macros but not #includes. - RewriteTest, // Rewriter playground - HTMLTest, // HTML displayer testing stuff. - EmitAssembly, // Emit a .s file. - EmitLLVM, // Emit a .ll file. - EmitBC, // Emit a .bc file. - EmitLLVMOnly, // Generate LLVM IR, but do not - EmitHTML, // Translate input source into HTML. - ASTPrint, // Parse ASTs and print them. - ASTPrintXML, // Parse ASTs and print them in XML. - ASTDump, // Parse ASTs and dump them. - ASTView, // Parse ASTs and view them in Graphviz. - PrintDeclContext, // Print DeclContext and their Decls. - DumpRecordLayouts, // Dump record layout information. - ParsePrintCallbacks, // Parse and print each callback. - ParseSyntaxOnly, // Parse and perform semantic analysis. - FixIt, // Parse and apply any fixits to the source. - ParseNoop, // Parse with noop callbacks. - RunPreprocessorOnly, // Just lex, no output. - PrintPreprocessedInput, // -E mode. - DumpTokens, // Dump out preprocessed tokens. - DumpRawTokens, // Dump out raw tokens. - RunAnalysis, // Run one or more source code analyses. - GeneratePTH, // Generate pre-tokenized header. - GeneratePCH, // Generate pre-compiled header. - InheritanceView // View C++ inheritance for a specified class. -}; - -static llvm::cl::opt -ProgAction(llvm::cl::desc("Choose output type:"), llvm::cl::ZeroOrMore, - llvm::cl::init(ParseSyntaxOnly), - llvm::cl::values( - clEnumValN(RunPreprocessorOnly, "Eonly", - "Just run preprocessor, no output (for timings)"), - clEnumValN(PrintPreprocessedInput, "E", - "Run preprocessor, emit preprocessed file"), - clEnumValN(DumpRawTokens, "dump-raw-tokens", - "Lex file in raw mode and dump raw tokens"), - clEnumValN(RunAnalysis, "analyze", - "Run static analysis engine"), - clEnumValN(DumpTokens, "dump-tokens", - "Run preprocessor, dump internal rep of tokens"), - clEnumValN(ParseNoop, "parse-noop", - "Run parser with noop callbacks (for timings)"), - clEnumValN(ParseSyntaxOnly, "fsyntax-only", - "Run parser and perform semantic analysis"), - clEnumValN(FixIt, "fixit", - "Apply fix-it advice to the input source"), - clEnumValN(ParsePrintCallbacks, "parse-print-callbacks", - "Run parser and print each callback invoked"), - clEnumValN(EmitHTML, "emit-html", - "Output input source as HTML"), - clEnumValN(ASTPrint, "ast-print", - "Build ASTs and then pretty-print them"), - clEnumValN(ASTPrintXML, "ast-print-xml", - "Build ASTs and then print them in XML format"), - clEnumValN(ASTDump, "ast-dump", - "Build ASTs and then debug dump them"), - clEnumValN(ASTView, "ast-view", - "Build ASTs and view them with GraphViz"), - clEnumValN(PrintDeclContext, "print-decl-contexts", - "Print DeclContexts and their Decls"), - clEnumValN(DumpRecordLayouts, "dump-record-layouts", - "Dump record layout information"), - clEnumValN(GeneratePTH, "emit-pth", - "Generate pre-tokenized header file"), - clEnumValN(GeneratePCH, "emit-pch", - "Generate pre-compiled header file"), - clEnumValN(EmitAssembly, "S", - "Emit native assembly code"), - clEnumValN(EmitLLVM, "emit-llvm", - "Build ASTs then convert to LLVM, emit .ll file"), - clEnumValN(EmitBC, "emit-llvm-bc", - "Build ASTs then convert to LLVM, emit .bc file"), - clEnumValN(EmitLLVMOnly, "emit-llvm-only", - "Build ASTs and convert to LLVM, discarding output"), - clEnumValN(RewriteTest, "rewrite-test", - "Rewriter playground"), - clEnumValN(RewriteObjC, "rewrite-objc", - "Rewrite ObjC into C (code rewriter example)"), - clEnumValN(RewriteMacros, "rewrite-macros", - "Expand macros without full preprocessing"), - clEnumValN(RewriteBlocks, "rewrite-blocks", - "Rewrite Blocks to C"), - clEnumValEnd)); - //===----------------------------------------------------------------------===// // Utility Methods //===----------------------------------------------------------------------===// @@ -174,8 +81,10 @@ std::string GetBuiltinIncludePath(const char *Argv0) { /// anything. llvm::Timer *ClangFrontendTimer = 0; -static FrontendAction *CreateFrontendAction(ProgActions PA) { - switch (PA) { +static FrontendAction *CreateFrontendAction(frontend::ActionKind AK) { + using namespace clang::frontend; + + switch (AK) { default: return 0; case ASTDump: return new ASTDumpAction(); case ASTPrint: return new ASTPrintAction(); @@ -344,9 +253,9 @@ int main(int argc, char **argv) { // Enforce certain implications. if (!Clang.getFrontendOpts().ViewClassInheritance.empty()) - ProgAction = InheritanceView; + Clang.getFrontendOpts().ProgramAction = frontend::InheritanceView; if (!Clang.getFrontendOpts().FixItLocations.empty()) - ProgAction = FixIt; + Clang.getFrontendOpts().ProgramAction = frontend::FixIt; for (unsigned i = 0, e = Clang.getFrontendOpts().Inputs.size(); i != e; ++i) { const std::string &InFile = Clang.getFrontendOpts().Inputs[i].second; @@ -370,7 +279,8 @@ int main(int argc, char **argv) { Clang.createPreprocessor(); } - llvm::OwningPtr Act(CreateFrontendAction(ProgAction)); + llvm::OwningPtr Act( + CreateFrontendAction(Clang.getFrontendOpts().ProgramAction)); assert(Act && "Invalid program action!"); Act->setCurrentTimer(ClangFrontendTimer); if (Act->BeginSourceFile(Clang, InFile, IsAST)) { -- 2.40.0