]> granicus.if.org Git - clang/commitdiff
Move -target-{triple,abi} options into FrontendOptions.
authorDaniel Dunbar <daniel@zuster.org>
Fri, 13 Nov 2009 01:02:19 +0000 (01:02 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Fri, 13 Nov 2009 01:02:19 +0000 (01:02 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@87051 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Frontend/FrontendOptions.h
tools/clang-cc/Options.cpp
tools/clang-cc/clang-cc.cpp

index 0ccb242796ce60db41ebf43ce78486129b5fb1a3..0674c0bb4011642b6023a4daddb03e422cc1afdd 100644 (file)
@@ -37,6 +37,13 @@ public:
   unsigned ShowTimers : 1;                 ///< Show timers for individual
                                            /// actions.
 
+  /// If given, the name of the target triple to compile for. If not given the
+  /// target will be selected to match the host.
+  std::string TargetTriple;
+
+  /// If given, the name of the target ABI to use.
+  std::string TargetABI;
+
   /// The input files.
   std::vector<std::string> InputFilenames;
 
index bedf852811e9f58f0821c989c488f31b5e9396c9..5d01e03a9ca8b3955c78ca881044f4e4f2220f6f 100644 (file)
@@ -344,6 +344,14 @@ static llvm::cl::opt<bool>
 Stats("print-stats",
       llvm::cl::desc("Print performance metrics and statistics"));
 
+static llvm::cl::opt<std::string>
+TargetABI("target-abi",
+          llvm::cl::desc("Target a particular ABI type"));
+
+static llvm::cl::opt<std::string>
+TargetTriple("triple",
+  llvm::cl::desc("Specify target triple (e.g. i686-apple-darwin9)"));
+
 static llvm::cl::opt<bool>
 TimeReport("ftime-report",
            llvm::cl::desc("Print the amount of time each "
@@ -784,6 +792,8 @@ void clang::InitializeFrontendOptions(FrontendOptions &Opts) {
   Opts.ShowMacrosInCodeCompletion = CodeCompletionWantsMacros;
   Opts.ShowStats = Stats;
   Opts.ShowTimers = TimeReport;
+  Opts.TargetABI = TargetABI;
+  Opts.TargetTriple = TargetTriple;
   Opts.ViewClassInheritance = InheritanceViewCls;
 
   // '-' is the default input if none is given.
index 8081ceec3502f72aa542ee29243836d531506570..25672f93116d8b24cd7377d5ec2b00831f397204 100644 (file)
@@ -199,14 +199,6 @@ BaseLang("x", llvm::cl::desc("Base language to compile"),
                                "Clang AST"),
                     clEnumValEnd));
 
-static llvm::cl::opt<std::string>
-TargetTriple("triple",
-  llvm::cl::desc("Specify target triple (e.g. i686-apple-darwin9)"));
-
-static llvm::cl::opt<std::string>
-TargetABI("target-abi",
-          llvm::cl::desc("Target a particular ABI type"));
-
 //===----------------------------------------------------------------------===//
 // Utility Methods
 //===----------------------------------------------------------------------===//
@@ -905,19 +897,39 @@ static LangKind GetLanguage(const std::vector<std::string> &Inputs) {
   return LK;
 }
 
-static void ConstructCompilerInvocation(CompilerInvocation &Opts,
-                                        const char *Argv0,
-                                        const DiagnosticOptions &DiagOpts,
-                                        TargetInfo &Target,
-                                        bool &IsAST) {
+static TargetInfo *
+ConstructCompilerInvocation(CompilerInvocation &Opts, Diagnostic &Diags,
+                            const char *Argv0,
+                            const DiagnosticOptions &DiagOpts, bool &IsAST) {
   Opts.getDiagnosticOpts() = DiagOpts;
 
   // Initialize frontend options.
   InitializeFrontendOptions(Opts.getFrontendOpts());
 
+  // Initialize base triple.  If a -triple option has been specified, use
+  // that triple.  Otherwise, default to the host triple.
+  llvm::Triple Triple(Opts.getFrontendOpts().TargetTriple);
+  if (Triple.getTriple().empty())
+    Triple = llvm::Triple(llvm::sys::getHostTriple());
+
+  // Get information about the target being compiled for.
+  TargetInfo *Target = TargetInfo::CreateTargetInfo(Triple.getTriple());
+  if (!Target) {
+    Diags.Report(diag::err_fe_unknown_triple) << Triple.getTriple().c_str();
+    return 0;
+  }
+
+  // Set the target ABI if specified.
+  if (!Opts.getFrontendOpts().TargetABI.empty() &&
+      !Target->setABI(Opts.getFrontendOpts().TargetABI)) {
+    Diags.Report(diag::err_fe_unknown_target_abi)
+      << Opts.getFrontendOpts().TargetABI;
+    return 0;
+  }
+
   // Initialize backend options, which may also be used to key some language
   // options.
-  InitializeCodeGenOptions(Opts.getCodeGenOpts(), Target);
+  InitializeCodeGenOptions(Opts.getCodeGenOpts(), *Target);
 
   // Initialize language options.
   //
@@ -926,7 +938,7 @@ static void ConstructCompilerInvocation(CompilerInvocation &Opts,
   LangKind LK = GetLanguage(Opts.getFrontendOpts().InputFilenames);
   IsAST = LK == langkind_ast;
   if (!IsAST)
-    InitializeLangOptions(Opts.getLangOpts(), LK, Target,
+    InitializeLangOptions(Opts.getLangOpts(), LK, *Target,
                           Opts.getCodeGenOpts());
 
   // Initialize the static analyzer options.
@@ -952,6 +964,8 @@ static void ConstructCompilerInvocation(CompilerInvocation &Opts,
   if (Opts.getLangOpts().CPlusPlus)
     Opts.getCodeGenOpts().NoCommon = 1;
   Opts.getCodeGenOpts().TimePasses = Opts.getFrontendOpts().ShowTimers;
+
+  return Target;
 }
 
 static Diagnostic *CreateDiagnosticEngine(const DiagnosticOptions &Opts,
@@ -1007,36 +1021,19 @@ int main(int argc, char **argv) {
   // should (optionally?) take ownership of it.
   llvm::OwningPtr<DiagnosticClient> DiagClient(Diags->getClient());
 
-  // Initialize base triple.  If a -triple option has been specified, use
-  // that triple.  Otherwise, default to the host triple.
-  llvm::Triple Triple(TargetTriple);
-  if (Triple.getTriple().empty())
-    Triple = llvm::Triple(llvm::sys::getHostTriple());
-
-  // Get information about the target being compiled for.
-  llvm::OwningPtr<TargetInfo>
-  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() &&!Target->setABI(TargetABI)) {
-    Diags->Report(diag::err_fe_unknown_target_abi) << TargetABI;
-    return 1;
-  }
-
-  // Now that we have initialized the diagnostics engine and the target, finish
-  // setting up the compiler invocation.
+  // Now that we have initialized the diagnostics engine, create the target and
+  // the compiler invocation object.
   //
   // FIXME: We should move .ast inputs to taking a separate path, they are
   // really quite different.
   CompilerInvocation CompOpts;
   bool IsAST;
-  ConstructCompilerInvocation(CompOpts, argv[0], DiagOpts, *Target, IsAST);
+  llvm::OwningPtr<TargetInfo> Target(
+    ConstructCompilerInvocation(CompOpts, *Diags, argv[0], DiagOpts, IsAST));
+  if (!Target)
+    return 1;
 
-  // Validate/process some options.
+  // Validate/process some options
   if (CompOpts.getHeaderSearchOpts().Verbose)
     llvm::errs() << "clang-cc version " CLANG_VERSION_STRING
                  << " based upon " << PACKAGE_STRING