From: Daniel Dunbar Date: Fri, 20 Nov 2009 16:55:31 +0000 (+0000) Subject: clang-cc: Lift setForcedLangOptions out of options initialization. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=33b26ea31381a1e161848116e96a87dcbb379921;p=clang clang-cc: Lift setForcedLangOptions out of options initialization. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89462 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/tools/clang-cc/Options.cpp b/tools/clang-cc/Options.cpp index 584f957095..7b40a667b3 100644 --- a/tools/clang-cc/Options.cpp +++ b/tools/clang-cc/Options.cpp @@ -1054,11 +1054,9 @@ void clang::InitializePreprocessorOptions(PreprocessorOptions &Opts) { } void clang::InitializeLangOptions(LangOptions &Options, - FrontendOptions::InputKind IK, - TargetInfo &Target) { + FrontendOptions::InputKind IK) { using namespace langoptions; - switch (IK) { case FrontendOptions::IK_None: case FrontendOptions::IK_AST: @@ -1295,8 +1293,6 @@ void clang::InitializeLangOptions(LangOptions &Options, if (MainFileName.getPosition()) Options.setMainFileName(MainFileName.c_str()); - - Target.setForcedLangOptions(Options); } void diff --git a/tools/clang-cc/Options.h b/tools/clang-cc/Options.h index 9a2fd9d59a..83672231ca 100644 --- a/tools/clang-cc/Options.h +++ b/tools/clang-cc/Options.h @@ -42,9 +42,7 @@ void InitializeFrontendOptions(FrontendOptions &Opts); void InitializeHeaderSearchOptions(HeaderSearchOptions &Opts, llvm::StringRef BuiltinIncludePath); -void InitializeLangOptions(LangOptions &Options, - FrontendOptions::InputKind LK, - TargetInfo &Target); +void InitializeLangOptions(LangOptions &Options, FrontendOptions::InputKind LK); void InitializePreprocessorOptions(PreprocessorOptions &Opts); diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp index bae8697e14..cf981f18b1 100644 --- a/tools/clang-cc/clang-cc.cpp +++ b/tools/clang-cc/clang-cc.cpp @@ -139,18 +139,12 @@ static FrontendAction *CreateFrontendAction(CompilerInstance &CI) { } } -static TargetInfo * -ConstructCompilerInvocation(CompilerInvocation &Opts, Diagnostic &Diags, - const char *Argv0, bool &IsAST) { +static bool ConstructCompilerInvocation(CompilerInvocation &Opts, + Diagnostic &Diags, + const char *Argv0, bool &IsAST) { // Initialize target options. InitializeTargetOptions(Opts.getTargetOpts()); - // Get information about the target being compiled for. - llvm::OwningPtr Target( - TargetInfo::CreateTargetInfo(Diags, Opts.getTargetOpts())); - if (!Target) - return 0; - // Initialize frontend options. InitializeFrontendOptions(Opts.getFrontendOpts()); @@ -160,7 +154,7 @@ ConstructCompilerInvocation(CompilerInvocation &Opts, Diagnostic &Diags, if (Opts.getFrontendOpts().Inputs[i].first != IK) { llvm::errs() << "error: cannot have multiple input files of distinct " << "language kinds without -x\n"; - return 0; + return false; } } @@ -170,7 +164,7 @@ ConstructCompilerInvocation(CompilerInvocation &Opts, Diagnostic &Diags, // code path to make this obvious. IsAST = (IK == FrontendOptions::IK_AST); if (!IsAST) - InitializeLangOptions(Opts.getLangOpts(), IK, *Target); + InitializeLangOptions(Opts.getLangOpts(), IK); // Initialize the static analyzer options. InitializeAnalyzerOptions(Opts.getAnalyzerOpts()); @@ -188,12 +182,11 @@ ConstructCompilerInvocation(CompilerInvocation &Opts, Diagnostic &Diags, // Initialize the preprocessed output options. InitializePreprocessorOutputOptions(Opts.getPreprocessorOutputOpts()); - // Initialize backend options, which may also be used to key some language - // options. + // Initialize backend options. InitializeCodeGenOptions(Opts.getCodeGenOpts(), Opts.getLangOpts(), Opts.getFrontendOpts().ShowTimers); - return Target.take(); + return true; } int main(int argc, char **argv) { @@ -226,12 +219,23 @@ int main(int argc, char **argv) { // FIXME: We should move .ast inputs to taking a separate path, they are // really quite different. bool IsAST = false; - Clang.setTarget( - ConstructCompilerInvocation(Clang.getInvocation(), Clang.getDiagnostics(), - argv[0], IsAST)); + if (!ConstructCompilerInvocation(Clang.getInvocation(), + Clang.getDiagnostics(), + argv[0], IsAST)) + return 1; + + // Create the target instance. + Clang.setTarget(TargetInfo::CreateTargetInfo(Clang.getDiagnostics(), + Clang.getTargetOpts())); if (!Clang.hasTarget()) return 1; + // Inform the target of the language options + // + // FIXME: We shouldn't need to do this, the target should be immutable once + // created. This complexity should be lifted elsewhere. + Clang.getTarget().setForcedLangOptions(Clang.getLangOpts()); + // Validate/process some options if (Clang.getHeaderSearchOpts().Verbose) llvm::errs() << "clang-cc version " CLANG_VERSION_STRING