From: Daniel Dunbar Date: Wed, 11 Nov 2009 10:07:44 +0000 (+0000) Subject: Add PreprocessorOutputOptions to CompilerInvocation, and move initialization to X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=29cf746aef63b1984c013448e843a290b2badf7b;p=clang Add PreprocessorOutputOptions to CompilerInvocation, and move initialization to clang-cc/Options.cpp git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86828 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Frontend/CompilerInvocation.h b/include/clang/Frontend/CompilerInvocation.h index c2a66bdf1d..b217dca965 100644 --- a/include/clang/Frontend/CompilerInvocation.h +++ b/include/clang/Frontend/CompilerInvocation.h @@ -15,6 +15,7 @@ #include "clang/Frontend/DiagnosticOptions.h" #include "clang/Frontend/HeaderSearchOptions.h" #include "clang/Frontend/PreprocessorOptions.h" +#include "clang/Frontend/PreprocessorOutputOptions.h" #include "llvm/ADT/StringMap.h" #include @@ -42,13 +43,13 @@ class CompilerInvocation { /// Options controlling the preprocessor (aside from #include handling). PreprocessorOptions PreprocessorOpts; + /// Options controlling preprocessed output. + PreprocessorOutputOptions PreprocessorOutputOpts; + /// The location for the output file. This is optional only for compiler /// invocations which have no output. std::string OutputFile; - /// Set of target-specific code generation features to enable/disable. - llvm::StringMap TargetFeatures; - public: CompilerInvocation() {} @@ -58,11 +59,6 @@ public: std::string &getOutputFile() { return OutputFile; } const std::string &getOutputFile() const { return OutputFile; } - llvm::StringMap &getTargetFeatures() { return TargetFeatures; } - const llvm::StringMap &getTargetFeatures() const { - return TargetFeatures; - } - /// @} /// @name Option Subgroups /// @{ @@ -88,6 +84,13 @@ public: return PreprocessorOpts; } + PreprocessorOutputOptions &getPreprocessorOutputOpts() { + return PreprocessorOutputOpts; + } + const PreprocessorOutputOptions &getPreprocessorOutputOpts() const { + return PreprocessorOutputOpts; + } + /// @} }; diff --git a/include/clang/Frontend/Utils.h b/include/clang/Frontend/Utils.h index ffaaaea30b..d3a0b097f0 100644 --- a/include/clang/Frontend/Utils.h +++ b/include/clang/Frontend/Utils.h @@ -59,7 +59,7 @@ bool ProcessWarningOptions(Diagnostic &Diags, /// DoPrintPreprocessedInput - Implement -E mode. void DoPrintPreprocessedInput(Preprocessor &PP, llvm::raw_ostream* OS, - PreprocessorOutputOptions &Opts); + const PreprocessorOutputOptions &Opts); /// RewriteMacrosInInput - Implement -rewrite-macros mode. void RewriteMacrosInInput(Preprocessor &PP, llvm::raw_ostream* OS); diff --git a/lib/Frontend/PrintPreprocessedOutput.cpp b/lib/Frontend/PrintPreprocessedOutput.cpp index b1a1936150..3742405780 100644 --- a/lib/Frontend/PrintPreprocessedOutput.cpp +++ b/lib/Frontend/PrintPreprocessedOutput.cpp @@ -468,7 +468,7 @@ static void DoPrintMacros(Preprocessor &PP, llvm::raw_ostream *OS) { /// DoPrintPreprocessedInput - This implements -E mode. /// void clang::DoPrintPreprocessedInput(Preprocessor &PP, llvm::raw_ostream *OS, - PreprocessorOutputOptions &Opts) { + const PreprocessorOutputOptions &Opts) { // Show macros with no output is handled specially. if (!Opts.ShowCPP) { assert(Opts.ShowMacros && "Not yet implemented!"); diff --git a/tools/clang-cc/Options.cpp b/tools/clang-cc/Options.cpp index 7b22d28fcb..211f1412a1 100644 --- a/tools/clang-cc/Options.cpp +++ b/tools/clang-cc/Options.cpp @@ -20,6 +20,7 @@ #include "clang/Frontend/HeaderSearchOptions.h" #include "clang/Frontend/PCHReader.h" #include "clang/Frontend/PreprocessorOptions.h" +#include "clang/Frontend/PreprocessorOutputOptions.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringMap.h" #include "llvm/Support/CommandLine.h" @@ -526,6 +527,31 @@ isysroot("isysroot", llvm::cl::value_desc("dir"), llvm::cl::init("/"), } +//===----------------------------------------------------------------------===// +// Preprocessed Output Options +//===----------------------------------------------------------------------===// + +namespace preprocessoroutputoptions { + +static llvm::cl::opt +DisableLineMarkers("P", llvm::cl::desc("Disable linemarker output in -E mode")); + +static llvm::cl::opt +EnableCommentOutput("C", llvm::cl::desc("Enable comment output in -E mode")); + +static llvm::cl::opt +EnableMacroCommentOutput("CC", + llvm::cl::desc("Enable comment output in -E mode, " + "even from macro expansions")); +static llvm::cl::opt +DumpMacros("dM", llvm::cl::desc("Print macro definitions in -E mode instead of" + " normal output")); +static llvm::cl::opt +DumpDefines("dD", llvm::cl::desc("Print macro definitions in -E mode in " + "addition to normal output")); + +} + //===----------------------------------------------------------------------===// // Option Object Construction //===----------------------------------------------------------------------===// @@ -1010,3 +1036,15 @@ void clang::InitializeLangOptions(LangOptions &Options, LangKind LK, Target.setForcedLangOptions(Options); } + +void +clang::InitializePreprocessorOutputOptions(PreprocessorOutputOptions &Opts) { + using namespace preprocessoroutputoptions; + + Opts.ShowCPP = !DumpMacros; + Opts.ShowMacros = DumpMacros || DumpDefines; + Opts.ShowLineMarkers = !DisableLineMarkers; + Opts.ShowComments = EnableCommentOutput; + Opts.ShowMacroComments = EnableMacroCommentOutput; +} + diff --git a/tools/clang-cc/Options.h b/tools/clang-cc/Options.h index 6d1447d991..88acb4263a 100644 --- a/tools/clang-cc/Options.h +++ b/tools/clang-cc/Options.h @@ -20,6 +20,7 @@ class DiagnosticOptions; class HeaderSearchOptions; class LangOptions; class PreprocessorOptions; +class PreprocessorOutputOptions; class TargetInfo; enum LangKind { @@ -55,6 +56,8 @@ void InitializeLangOptions(LangOptions &Options, LangKind LK, void InitializePreprocessorOptions(PreprocessorOptions &Opts); +void InitializePreprocessorOutputOptions(PreprocessorOutputOptions &Opts); + } // end namespace clang #endif diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp index e812e364e8..d8c9ddd220 100644 --- a/tools/clang-cc/clang-cc.cpp +++ b/tools/clang-cc/clang-cc.cpp @@ -454,27 +454,10 @@ static llvm::cl::opt OptPedantic("pedantic"); static llvm::cl::opt OptPedanticErrors("pedantic-errors"); static llvm::cl::opt OptNoWarnings("w"); -//===----------------------------------------------------------------------===// -// Preprocessing (-E mode) Options -//===----------------------------------------------------------------------===// -static llvm::cl::opt -DisableLineMarkers("P", llvm::cl::desc("Disable linemarker output in -E mode")); -static llvm::cl::opt -EnableCommentOutput("C", llvm::cl::desc("Enable comment output in -E mode")); -static llvm::cl::opt -EnableMacroCommentOutput("CC", - llvm::cl::desc("Enable comment output in -E mode, " - "even from macro expansions")); -static llvm::cl::opt -DumpMacros("dM", llvm::cl::desc("Print macro definitions in -E mode instead of" - " normal output")); -static llvm::cl::opt -DumpDefines("dD", llvm::cl::desc("Print macro definitions in -E mode in " - "addition to normal output")); - //===----------------------------------------------------------------------===// // Dependency file options //===----------------------------------------------------------------------===// + static llvm::cl::opt DependencyFile("dependency-file", llvm::cl::desc("Filename (or -) to write dependency output to")); @@ -920,13 +903,8 @@ static void ProcessInputFile(const CompilerInvocation &CompOpts, case PrintPreprocessedInput: { llvm::TimeRegion Timer(ClangFrontendTimer); - PreprocessorOutputOptions Opts; - Opts.ShowCPP = !DumpMacros; - Opts.ShowMacros = DumpMacros || DumpDefines; - Opts.ShowLineMarkers = !DisableLineMarkers; - Opts.ShowComments = EnableCommentOutput; - Opts.ShowMacroComments = EnableMacroCommentOutput; - DoPrintPreprocessedInput(PP, OS.get(), Opts); + DoPrintPreprocessedInput(PP, OS.get(), + CompOpts.getPreprocessorOutputOpts()); ClearSourceMgr = true; } @@ -1123,6 +1101,9 @@ static void ConstructCompilerInvocation(CompilerInvocation &Opts, // Initialize the other preprocessor options. InitializePreprocessorOptions(Opts.getPreprocessorOpts()); + // Initialize the preprocessed output options. + InitializePreprocessorOutputOptions(Opts.getPreprocessorOutputOpts()); + // Finalize some code generation options. FinalizeCompileOptions(Opts.getCompileOpts(), Opts.getLangOpts()); }