From 26a0cac165aea204f661b8da7b167623b12ff143 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Mon, 9 Nov 2009 22:46:17 +0000 Subject: [PATCH] Move LangOptions, HeaderSearchOptions, and the target feature map into CompilerInvocation. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86612 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Frontend/CompilerInvocation.h | 34 ++++++++-- tools/clang-cc/clang-cc.cpp | 73 +++++++++++---------- 2 files changed, 69 insertions(+), 38 deletions(-) diff --git a/include/clang/Frontend/CompilerInvocation.h b/include/clang/Frontend/CompilerInvocation.h index 7cd68e81a2..3416654481 100644 --- a/include/clang/Frontend/CompilerInvocation.h +++ b/include/clang/Frontend/CompilerInvocation.h @@ -10,7 +10,10 @@ #ifndef LLVM_CLANG_FRONTEND_COMPILERINVOCATION_H_ #define LLVM_CLANG_FRONTEND_COMPILERINVOCATION_H_ +#include "clang/Basic/LangOptions.h" #include "clang/Frontend/DiagnosticOptions.h" +#include "clang/Frontend/HeaderSearchOptions.h" +#include "llvm/ADT/StringMap.h" #include namespace clang { @@ -26,16 +29,39 @@ class CompilerInvocation { /// invocations which have no output. std::string OutputFile; - DiagnosticOptions Diags; - + /// Options controlling the diagnostic engine. + DiagnosticOptions DiagOpts; + + /// Set of target-specific code generation features to enable/disable. + llvm::StringMap TargetFeatures; + + /// Options controlling the language variant. + LangOptions LangOpts; + + /// Options controlling the #include directive. + HeaderSearchOptions HeaderSearchOpts; + public: CompilerInvocation() {} std::string &getOutputFile() { return OutputFile; } const std::string &getOutputFile() const { return OutputFile; } - DiagnosticOptions &getDiagnosticOpts() { return Diags; } - const DiagnosticOptions &getDiagnosticOpts() const { return Diags; } + DiagnosticOptions &getDiagnosticOpts() { return DiagOpts; } + const DiagnosticOptions &getDiagnosticOpts() const { return DiagOpts; } + + llvm::StringMap &getTargetFeatures() { return TargetFeatures; } + const llvm::StringMap &getTargetFeatures() const { + return TargetFeatures; + } + + LangOptions &getLangOpts() { return LangOpts; } + const LangOptions &getLangOpts() const { return LangOpts; } + + HeaderSearchOptions &getHeaderSearchOpts() { return HeaderSearchOpts; } + const HeaderSearchOptions &getHeaderSearchOpts() const { + return HeaderSearchOpts; + } }; } // end namespace clang diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp index 673e63f3d6..40f8161ebf 100644 --- a/tools/clang-cc/clang-cc.cpp +++ b/tools/clang-cc/clang-cc.cpp @@ -1041,11 +1041,10 @@ std::string GetBuiltinIncludePath(const char *Argv0) { /// InitializeIncludePaths - Process the -I options and set them in the /// HeaderSearch object. -void InitializeIncludePaths(const char *Argv0, HeaderSearch &Headers, - FileManager &FM, const LangOptions &Lang, - llvm::Triple &triple) { - HeaderSearchOptions Opts(isysroot); - +static void InitializeIncludePaths(HeaderSearchOptions &Opts, + const char *Argv0, + const LangOptions &Lang) { + Opts.Sysroot = isysroot; Opts.Verbose = Verbose; // Handle -I... and -F... options, walking the lists in parallel. @@ -1142,9 +1141,6 @@ void InitializeIncludePaths(const char *Argv0, HeaderSearch &Headers, Opts.BuiltinIncludePath = GetBuiltinIncludePath(Argv0); Opts.UseStandardIncludes = !nostdinc; - - // Apply all the options to the header search object. - ApplyHeaderSearchOptions(Opts, Headers, Lang, triple); } void InitializePreprocessorOptions(PreprocessorOptions &InitOpts) { @@ -1295,7 +1291,7 @@ NoImplicitFloat("no-implicit-float", /// ComputeTargetFeatures - Recompute the target feature list to only /// be the list of things that are enabled, based on the target cpu /// and feature list. -static void ComputeFeatureMap(const TargetInfo &Target, +static void ComputeFeatureMap(TargetInfo &Target, llvm::StringMap &Features) { assert(Features.empty() && "invalid map"); @@ -1661,7 +1657,6 @@ static ASTConsumer *CreateConsumerAction(const CompilerInvocation &CompOpts, ProgActions PA, llvm::OwningPtr &OS, llvm::sys::Path &OutPath, - const llvm::StringMap &Features, llvm::LLVMContext& Context) { switch (PA) { default: @@ -1709,7 +1704,8 @@ static ASTConsumer *CreateConsumerAction(const CompilerInvocation &CompOpts, } CompileOptions Opts; - InitializeCompileOptions(Opts, PP.getLangOptions(), Features); + InitializeCompileOptions(Opts, PP.getLangOptions(), + CompOpts.getTargetFeatures()); return CreateBackendConsumer(Act, PP.getDiagnostics(), PP.getLangOptions(), Opts, InFile, OS.get(), Context); } @@ -1730,7 +1726,6 @@ static ASTConsumer *CreateConsumerAction(const CompilerInvocation &CompOpts, static void ProcessInputFile(const CompilerInvocation &CompOpts, Preprocessor &PP, const std::string &InFile, ProgActions PA, - const llvm::StringMap &Features, llvm::LLVMContext& Context) { llvm::OwningPtr OS; llvm::OwningPtr Consumer; @@ -1742,7 +1737,7 @@ static void ProcessInputFile(const CompilerInvocation &CompOpts, switch (PA) { default: Consumer.reset(CreateConsumerAction(CompOpts, PP, InFile, PA, OS, OutPath, - Features, Context)); + Context)); if (!Consumer.get()) { PP.getDiagnostics().Report(FullSourceLoc(), @@ -2077,7 +2072,6 @@ static void ProcessInputFile(const CompilerInvocation &CompOpts, /// static void ProcessASTInputFile(const CompilerInvocation &CompOpts, const std::string &InFile, ProgActions PA, - const llvm::StringMap &Features, Diagnostic &Diags, FileManager &FileMgr, llvm::LLVMContext& Context) { std::string Error; @@ -2093,8 +2087,7 @@ static void ProcessASTInputFile(const CompilerInvocation &CompOpts, llvm::sys::Path OutPath; llvm::OwningPtr Consumer(CreateConsumerAction(CompOpts, PP, InFile, PA, OS, - OutPath, Features, - Context)); + OutPath, Context)); if (!Consumer.get()) { Diags.Report(FullSourceLoc(), diag::err_fe_invalid_ast_action); @@ -2196,11 +2189,30 @@ static void ConstructDiagnosticOptions(DiagnosticOptions &Opts) { } static void ConstructCompilerInvocation(CompilerInvocation &Opts, + const char *Argv0, const DiagnosticOptions &DiagOpts, - const TargetInfo &Target) { + TargetInfo &Target, + LangKind LK) { Opts.getDiagnosticOpts() = DiagOpts; Opts.getOutputFile() = OutputFile; + + // Compute the feature set, which may effect the language. + ComputeFeatureMap(Target, Opts.getTargetFeatures()); + + // Initialize language options. + LangOptions LangInfo; + + // FIXME: These aren't used during operations on ASTs. Split onto a separate + // code path to make this obvious. + if (LK != langkind_ast) { + InitializeLangOptions(Opts.getLangOpts(), LK); + InitializeLanguageStandard(Opts.getLangOpts(), LK, Target, + Opts.getTargetFeatures()); + } + + // Initialize the header search options. + InitializeIncludePaths(Opts.getHeaderSearchOpts(), Argv0, Opts.getLangOpts()); } int main(int argc, char **argv) { @@ -2297,7 +2309,7 @@ int main(int argc, char **argv) { // Now that we have initialized the diagnostics engine and the target, finish // setting up the compiler invocation. CompilerInvocation CompOpts; - ConstructCompilerInvocation(CompOpts, DiagOpts, *Target); + ConstructCompilerInvocation(CompOpts, argv[0], DiagOpts, *Target, LK); // Create the source manager. SourceManager SourceMgr; @@ -2305,17 +2317,13 @@ int main(int argc, char **argv) { // Create a file manager object to provide access to and cache the filesystem. FileManager FileMgr; - // Compute the feature set, unfortunately this effects the language! - llvm::StringMap Features; - ComputeFeatureMap(*Target, Features); - for (unsigned i = 0, e = InputFilenames.size(); i != e; ++i) { const std::string &InFile = InputFilenames[i]; // AST inputs are handled specially. if (LK == langkind_ast) { - ProcessASTInputFile(CompOpts, InFile, ProgAction, Features, - Diags, FileMgr, Context); + ProcessASTInputFile(CompOpts, InFile, ProgAction, Diags, FileMgr, + Context); continue; } @@ -2323,19 +2331,16 @@ int main(int argc, char **argv) { if (i) SourceMgr.clearIDTables(); - // Initialize language options, inferring file types from input filenames. - LangOptions LangInfo; - InitializeLangOptions(LangInfo, LK); - InitializeLanguageStandard(LangInfo, LK, *Target, Features); - // Process the -I options and set them in the HeaderInfo. HeaderSearch HeaderInfo(FileMgr); - - InitializeIncludePaths(argv[0], HeaderInfo, FileMgr, LangInfo, Triple); + // Apply all the options to the header search object. + ApplyHeaderSearchOptions(CompOpts.getHeaderSearchOpts(), HeaderInfo, + CompOpts.getLangOpts(), Triple); // Set up the preprocessor with these options. - llvm::OwningPtr PP(CreatePreprocessor(Diags, LangInfo, + llvm::OwningPtr PP(CreatePreprocessor(Diags, + CompOpts.getLangOpts(), *Target, SourceMgr, HeaderInfo)); @@ -2369,8 +2374,8 @@ int main(int argc, char **argv) { } // Process the source file. - Diags.getClient()->BeginSourceFile(LangInfo); - ProcessInputFile(CompOpts, *PP, InFile, ProgAction, Features, Context); + Diags.getClient()->BeginSourceFile(CompOpts.getLangOpts()); + ProcessInputFile(CompOpts, *PP, InFile, ProgAction, Context); Diags.getClient()->EndSourceFile(); HeaderInfo.ClearFileInfo(); -- 2.40.0