From 91cd960d50f08a8187f645166bd9b463dc4f38ac Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Thu, 12 Nov 2009 15:23:20 +0000 Subject: [PATCH] clang-cc: Coalesce frontend options further. llvm-svn: 86988 --- clang/tools/clang-cc/clang-cc.cpp | 167 ++++++++++++++---------------- 1 file changed, 78 insertions(+), 89 deletions(-) diff --git a/clang/tools/clang-cc/clang-cc.cpp b/clang/tools/clang-cc/clang-cc.cpp index ad5575352729..fdac9b950137 100644 --- a/clang/tools/clang-cc/clang-cc.cpp +++ b/clang/tools/clang-cc/clang-cc.cpp @@ -76,26 +76,53 @@ using namespace clang; //===----------------------------------------------------------------------===// -// Global options. +// Code Completion Options //===----------------------------------------------------------------------===// -/// ClangFrontendTimer - The front-end activities should charge time to it with -/// TimeRegion. The -ftime-report option controls whether this will do -/// anything. -llvm::Timer *ClangFrontendTimer = 0; +enum CodeCompletionPrinter { + CCP_Debug, + CCP_CIndex +}; + +static llvm::cl::opt +CodeCompletionAt("code-completion-at", + llvm::cl::value_desc("file:line:column"), + llvm::cl::desc("Dump code-completion information at a location")); + +static llvm::cl::opt +CodeCompletionPrinter("code-completion-printer", + llvm::cl::desc("Choose output type:"), + llvm::cl::init(CCP_Debug), + llvm::cl::values( + clEnumValN(CCP_Debug, "debug", + "Debug code-completion results"), + clEnumValN(CCP_CIndex, "cindex", + "Code-completion results for the CIndex library"), + clEnumValEnd)); static llvm::cl::opt -Verbose("v", llvm::cl::desc("Enable verbose output")); -static llvm::cl::opt -Stats("print-stats", - llvm::cl::desc("Print performance metrics and statistics")); -static llvm::cl::opt -DisableFree("disable-free", - llvm::cl::desc("Disable freeing of memory on exit"), - llvm::cl::init(false)); -static llvm::cl::opt -EmptyInputOnly("empty-input-only", - llvm::cl::desc("Force running on an empty input file")); +CodeCompletionWantsMacros("code-completion-macros", + llvm::cl::desc("Include macros in code-completion results")); + +/// \brief Buld a new code-completion consumer that prints the results of +/// code completion to standard output. +static CodeCompleteConsumer *BuildPrintingCodeCompleter(Sema &S, void *) { + switch (CodeCompletionPrinter.getValue()) { + case CCP_Debug: + return new PrintingCodeCompleteConsumer(S, CodeCompletionWantsMacros, + llvm::outs()); + + case CCP_CIndex: + return new CIndexCodeCompleteConsumer(S, CodeCompletionWantsMacros, + llvm::outs()); + }; + + return 0; +} + +//===----------------------------------------------------------------------===// +// Frontend Actions +//===----------------------------------------------------------------------===// enum ProgActions { RewriteObjC, // ObjC->C Rewriter. @@ -183,74 +210,55 @@ ProgAction(llvm::cl::desc("Choose output type:"), llvm::cl::ZeroOrMore, "Rewrite Blocks to C"), clEnumValEnd)); - -enum CodeCompletionPrinter { - CCP_Debug, - CCP_CIndex -}; - -static llvm::cl::opt -CodeCompletionAt("code-completion-at", - llvm::cl::value_desc("file:line:column"), - llvm::cl::desc("Dump code-completion information at a location")); - -static llvm::cl::opt -CodeCompletionPrinter("code-completion-printer", - llvm::cl::desc("Choose output type:"), - llvm::cl::init(CCP_Debug), - llvm::cl::values( - clEnumValN(CCP_Debug, "debug", - "Debug code-completion results"), - clEnumValN(CCP_CIndex, "cindex", - "Code-completion results for the CIndex library"), - clEnumValEnd)); +//===----------------------------------------------------------------------===// +// Frontend Options +//===----------------------------------------------------------------------===// static llvm::cl::opt -CodeCompletionWantsMacros("code-completion-macros", - llvm::cl::desc("Include macros in code-completion results")); +DisableFree("disable-free", + llvm::cl::desc("Disable freeing of memory on exit"), + llvm::cl::init(false)); -/// \brief Buld a new code-completion consumer that prints the results of -/// code completion to standard output. -static CodeCompleteConsumer *BuildPrintingCodeCompleter(Sema &S, void *) { - switch (CodeCompletionPrinter.getValue()) { - case CCP_Debug: - return new PrintingCodeCompleteConsumer(S, CodeCompletionWantsMacros, - llvm::outs()); +static llvm::cl::opt +EmptyInputOnly("empty-input-only", + llvm::cl::desc("Force running on an empty input file")); - case CCP_CIndex: - return new CIndexCodeCompleteConsumer(S, CodeCompletionWantsMacros, - llvm::outs()); - }; - - return 0; -} - -//===----------------------------------------------------------------------===// -// C++ Visualization. -//===----------------------------------------------------------------------===// +static llvm::cl::list +InputFilenames(llvm::cl::Positional, llvm::cl::desc("")); static llvm::cl::opt InheritanceViewCls("cxx-inheritance-view", llvm::cl::value_desc("class name"), llvm::cl::desc("View C++ inheritance for a specified class")); -//===----------------------------------------------------------------------===// -// Frontend Options -//===----------------------------------------------------------------------===// +static llvm::cl::opt +FixItAll("fixit", llvm::cl::desc("Apply fix-it advice to the input source")); -static llvm::cl::list -InputFilenames(llvm::cl::Positional, llvm::cl::desc("")); +static llvm::cl::list +FixItAtLocations("fixit-at", llvm::cl::value_desc("source-location"), + llvm::cl::desc("Perform Fix-It modifications at the given source location")); static llvm::cl::opt OutputFile("o", llvm::cl::value_desc("path"), llvm::cl::desc("Specify output file")); +static llvm::cl::opt +RelocatablePCH("relocatable-pch", + llvm::cl::desc("Whether to build a relocatable precompiled " + "header")); +static llvm::cl::opt +Stats("print-stats", + llvm::cl::desc("Print performance metrics and statistics")); + static llvm::cl::opt TimeReport("ftime-report", llvm::cl::desc("Print the amount of time each " "phase of compilation takes")); +static llvm::cl::opt +Verbose("v", llvm::cl::desc("Enable verbose output")); + static llvm::cl::opt VerifyDiagnostics("verify", llvm::cl::desc("Verify emitted diagnostics and warnings")); @@ -331,16 +339,6 @@ static bool InitializeSourceManager(Preprocessor &PP, return false; } - -//===----------------------------------------------------------------------===// -// Preprocessor Initialization -//===----------------------------------------------------------------------===// - -static llvm::cl::opt -RelocatablePCH("relocatable-pch", - llvm::cl::desc("Whether to build a relocatable precompiled " - "header")); - //===----------------------------------------------------------------------===// // Preprocessor construction //===----------------------------------------------------------------------===// @@ -416,17 +414,6 @@ static void ParseFile(Preprocessor &PP, MinimalAction *PA) { delete PA; } -//===----------------------------------------------------------------------===// -// Fix-It Options -//===----------------------------------------------------------------------===// - -static llvm::cl::opt -FixItAll("fixit", llvm::cl::desc("Apply fix-it advice to the input source")); - -static llvm::cl::list -FixItAtLocations("fixit-at", llvm::cl::value_desc("source-location"), - llvm::cl::desc("Perform Fix-It modifications at the given source location")); - //===----------------------------------------------------------------------===// // Dump Build Information //===----------------------------------------------------------------------===// @@ -459,6 +446,11 @@ static void SetUpBuildDumpLog(const DiagnosticOptions &DiagOpts, // Main driver //===----------------------------------------------------------------------===// +/// ClangFrontendTimer - The front-end activities should charge time to it with +/// TimeRegion. The -ftime-report option controls whether this will do +/// anything. +llvm::Timer *ClangFrontendTimer = 0; + static llvm::raw_ostream *ComputeOutFile(const CompilerInvocation &CompOpts, const std::string &InFile, const char *Extension, @@ -1120,18 +1112,15 @@ int main(int argc, char **argv) { // Get information about the target being compiled for. llvm::OwningPtr Target(TargetInfo::CreateTargetInfo(Triple.getTriple())); - if (Target == 0) { Diags->Report(diag::err_fe_unknown_triple) << Triple.getTriple().c_str(); return 1; } // Set the target ABI if specified. - if (!TargetABI.empty()) { - if (!Target->setABI(TargetABI)) { - Diags->Report(diag::err_fe_unknown_target_abi) << TargetABI; - return 1; - } + if (!TargetABI.empty() &&!Target->setABI(TargetABI)) { + Diags->Report(diag::err_fe_unknown_target_abi) << TargetABI; + return 1; } if (!InheritanceViewCls.empty()) // C++ visualization?