[cfe-commits] r89462 - in /cfe/trunk/tools/clang-cc: Options.cpp Options.h clang-cc.cpp

Daniel Dunbar daniel at zuster.org
Fri Nov 20 08:55:31 PST 2009


Author: ddunbar
Date: Fri Nov 20 10:55:31 2009
New Revision: 89462

URL: http://llvm.org/viewvc/llvm-project?rev=89462&view=rev
Log:
clang-cc: Lift setForcedLangOptions out of options initialization.

Modified:
    cfe/trunk/tools/clang-cc/Options.cpp
    cfe/trunk/tools/clang-cc/Options.h
    cfe/trunk/tools/clang-cc/clang-cc.cpp

Modified: cfe/trunk/tools/clang-cc/Options.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/Options.cpp?rev=89462&r1=89461&r2=89462&view=diff

==============================================================================
--- cfe/trunk/tools/clang-cc/Options.cpp (original)
+++ cfe/trunk/tools/clang-cc/Options.cpp Fri Nov 20 10:55:31 2009
@@ -1054,11 +1054,9 @@
 }
 
 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 @@
 
   if (MainFileName.getPosition())
     Options.setMainFileName(MainFileName.c_str());
-
-  Target.setForcedLangOptions(Options);
 }
 
 void

Modified: cfe/trunk/tools/clang-cc/Options.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/Options.h?rev=89462&r1=89461&r2=89462&view=diff

==============================================================================
--- cfe/trunk/tools/clang-cc/Options.h (original)
+++ cfe/trunk/tools/clang-cc/Options.h Fri Nov 20 10:55:31 2009
@@ -42,9 +42,7 @@
 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);
 

Modified: cfe/trunk/tools/clang-cc/clang-cc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/clang-cc.cpp?rev=89462&r1=89461&r2=89462&view=diff

==============================================================================
--- cfe/trunk/tools/clang-cc/clang-cc.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang-cc.cpp Fri Nov 20 10:55:31 2009
@@ -139,18 +139,12 @@
   }
 }
 
-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<TargetInfo> Target(
-    TargetInfo::CreateTargetInfo(Diags, Opts.getTargetOpts()));
-  if (!Target)
-    return 0;
-
   // Initialize frontend options.
   InitializeFrontendOptions(Opts.getFrontendOpts());
 
@@ -160,7 +154,7 @@
     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 @@
   // 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 @@
   // 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 @@
   // 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





More information about the cfe-commits mailing list