aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-11-13 01:02:19 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-11-13 01:02:19 +0000
commit21dac5e24a14d3288565515b35ad98c38460c9dd (patch)
treeb674a5ab9eec278f312ab08ffa11c7e8601e63cf
parent914474ca51d202369241a81013208833a6bb3f12 (diff)
Move -target-{triple,abi} options into FrontendOptions.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@87051 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Frontend/FrontendOptions.h7
-rw-r--r--tools/clang-cc/Options.cpp10
-rw-r--r--tools/clang-cc/clang-cc.cpp75
3 files changed, 53 insertions, 39 deletions
diff --git a/include/clang/Frontend/FrontendOptions.h b/include/clang/Frontend/FrontendOptions.h
index 0ccb242796..0674c0bb40 100644
--- a/include/clang/Frontend/FrontendOptions.h
+++ b/include/clang/Frontend/FrontendOptions.h
@@ -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;
diff --git a/tools/clang-cc/Options.cpp b/tools/clang-cc/Options.cpp
index bedf852811..5d01e03a9c 100644
--- a/tools/clang-cc/Options.cpp
+++ b/tools/clang-cc/Options.cpp
@@ -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.
diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp
index 8081ceec35..25672f9311 100644
--- a/tools/clang-cc/clang-cc.cpp
+++ b/tools/clang-cc/clang-cc.cpp
@@ -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