diff options
author | Daniel Dunbar <daniel@zuster.org> | 2010-01-26 01:44:04 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2010-01-26 01:44:04 +0000 |
commit | 21ae3196c9677a79523d294f9a62a4788ba40694 (patch) | |
tree | c7d4ea3032dfe3b5d78988be40c3daaf84f11df8 | |
parent | 86820f58e077bfd8fdf7309129b6ff2c5c4eb0e4 (diff) |
Driver/Darwin: Stuff iPhoneOS into environment portion of the (llvm/clang) triple instead of keying off architecture. Also, fix version define to properly include the revision/micro component of the version number.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94487 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Basic/Targets.cpp | 85 | ||||
-rw-r--r-- | lib/Driver/Tools.cpp | 60 | ||||
-rw-r--r-- | test/CodeGenObjC/image-info.m | 2 |
3 files changed, 73 insertions, 74 deletions
diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index ea076ae0bb..e019d6a0cb 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -74,7 +74,8 @@ public: } // end anonymous namespace -static void getDarwinDefines(MacroBuilder &Builder, const LangOptions &Opts) { +static void getDarwinDefines(MacroBuilder &Builder, const LangOptions &Opts, + const llvm::Triple &Triple) { Builder.defineMacro("__APPLE_CC__", "5621"); Builder.defineMacro("__APPLE__"); Builder.defineMacro("__MACH__"); @@ -96,51 +97,45 @@ static void getDarwinDefines(MacroBuilder &Builder, const LangOptions &Opts) { if (Opts.POSIXThreads) Builder.defineMacro("_REENTRANT"); -} - -static void getDarwinOSXDefines(MacroBuilder &Builder, - const llvm::Triple &Triple) { - if (Triple.getOS() != llvm::Triple::Darwin) - return; - // Figure out which "darwin number" the target triple is. "darwin9" -> 10.5. + // Get the OS version number from the triple. unsigned Maj, Min, Rev; - Triple.getDarwinNumber(Maj, Min, Rev); - - char MacOSXStr[] = "1000"; - if (Maj >= 4 && Maj <= 13) { // 10.0-10.9 - // darwin7 -> 1030, darwin8 -> 1040, darwin9 -> 1050, etc. - MacOSXStr[2] = '0' + Maj-4; - } - - // Handle minor version: 10.4.9 -> darwin8.9 -> "1049" - // Cap 10.4.11 -> darwin8.11 -> "1049" - MacOSXStr[3] = std::min(Min, 9U)+'0'; - Builder.defineMacro("__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__", - MacOSXStr); -} -static void getDarwinIPhoneOSDefines(MacroBuilder &Builder, - const llvm::Triple &Triple) { - if (Triple.getOS() != llvm::Triple::Darwin) - return; - - // Figure out which "darwin number" the target triple is. "darwin9" -> 10.5. - unsigned Maj, Min, Rev; - Triple.getDarwinNumber(Maj, Min, Rev); - - // When targetting iPhone OS, interpret the minor version and - // revision as the iPhone OS version - char iPhoneOSStr[] = "10000"; - if (Min >= 2 && Min <= 9) { // iPhone OS 2.0-9.0 - // darwin9.2.0 -> 20000, darwin9.3.0 -> 30000, etc. - iPhoneOSStr[0] = '0' + Min; + // If no version was given, default to to 10.4.0, for simplifying tests. + if (Triple.getOSName() == "darwin") { + Min = Rev = 0; + Maj = 8; + } else + Triple.getDarwinNumber(Maj, Min, Rev); + + // Set the appropriate OS version define. + if (Triple.getEnvironmentName() == "iphoneos") { + assert(Maj < 10 && Min < 99 && Rev < 99 && "Invalid version!"); + char Str[6]; + Str[0] = '0' + Maj; + Str[1] = '0' + (Min / 10); + Str[2] = '0' + (Min % 10); + Str[3] = '0' + (Rev / 10); + Str[4] = '0' + (Rev % 10); + Str[5] = '\0'; + Builder.defineMacro("__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__", Str); + } else { + // For historical reasons that make little sense, the version passed here is + // the "darwin" version, which drops the 10 and offsets by 4. + Rev = Min; + Min = Maj - 4; + Maj = 10; + + assert(Triple.getEnvironmentName().empty() && "Invalid environment!"); + assert(Maj < 99 && Min < 10 && Rev < 10 && "Invalid version!"); + char Str[5]; + Str[0] = '0' + (Maj / 10); + Str[1] = '0' + (Maj % 10); + Str[2] = '0' + Min; + Str[3] = '0' + Rev; + Str[4] = '\0'; + Builder.defineMacro("__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__", Str); } - - // Handle minor version: 2.2 -> darwin9.2.2 -> 20200 - iPhoneOSStr[2] = std::min(Rev, 9U)+'0'; - Builder.defineMacro("__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__", - iPhoneOSStr); } namespace { @@ -149,8 +144,7 @@ class DarwinTargetInfo : public OSTargetInfo<Target> { protected: virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const { - getDarwinDefines(Builder, Opts); - getDarwinOSXDefines(Builder, Triple); + getDarwinDefines(Builder, Opts, Triple); } public: @@ -1461,8 +1455,7 @@ class DarwinARMTargetInfo : protected: virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const { - getDarwinDefines(Builder, Opts); - getDarwinIPhoneOSDefines(Builder, Triple); + getDarwinDefines(Builder, Opts, Triple); } public: diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 29dd3f55c4..61b4ee675e 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -586,44 +586,50 @@ static std::string getEffectiveClangTriple(const Driver &D, const ArgList &Args) { llvm::Triple Triple(getLLVMTriple(TC, Args)); + // Honor -mmacosx-version-min and -miphoneos-version-min. + Arg *VersionArg = Args.getLastArg(options::OPT_mmacosx_version_min_EQ, + options::OPT_miphoneos_version_min_EQ); if (Triple.getOS() != llvm::Triple::Darwin) { // Diagnose use of -mmacosx-version-min and -miphoneos-version-min on // non-Darwin. - if (Arg *A = Args.getLastArg(options::OPT_mmacosx_version_min_EQ, - options::OPT_miphoneos_version_min_EQ)) - D.Diag(clang::diag::err_drv_clang_unsupported) << A->getAsString(Args); - return Triple.getTriple(); - } + if (VersionArg) + D.Diag(clang::diag::err_drv_clang_unsupported) + << VersionArg->getAsString(Args); + } else { + bool isIPhoneTarget = + VersionArg->getOption().matches(options::OPT_miphoneos_version_min_EQ); + assert(VersionArg && "Missing version argument (lost in translation)?"); - // If -mmacosx-version-min=10.3.9 is specified, change the effective triple - // from being something like powerpc-apple-darwin9 to powerpc-apple-darwin7. - if (Arg *A = Args.getLastArg(options::OPT_mmacosx_version_min_EQ)) { + // Validate the version number. unsigned Major, Minor, Micro; bool HadExtra; - if (!Driver::GetReleaseVersion(A->getValue(Args), Major, Minor, Micro, - HadExtra) || HadExtra || - Major != 10) + if (!Driver::GetReleaseVersion(VersionArg->getValue(Args), Major, Minor, + Micro, HadExtra) || HadExtra) D.Diag(clang::diag::err_drv_invalid_version_number) - << A->getAsString(Args); + << VersionArg->getAsString(Args); + + // Mangle the target version into the OS triple component. For historical + // reasons that make little sense, the version passed here is the "darwin" + // version, which drops the 10 and offsets by 4. See inverse code when + // setting the OS version preprocessor define. + if (!isIPhoneTarget) { + if (Major != 10 || Minor >= 10 || Micro >= 10) + D.Diag(clang::diag::err_drv_invalid_version_number) + << VersionArg->getAsString(Args); + + Major = Minor + 4; + Minor = Micro; + Micro = 0; + } - // Mangle the MacOS version min number into the Darwin number: e.g. 10.3.9 - // is darwin7.9. llvm::SmallString<16> Str; - llvm::raw_svector_ostream(Str) << "darwin" << Minor + 4 << "." << Micro; + llvm::raw_svector_ostream(Str) << "darwin" << Major << "." << Minor + << "." << Micro; Triple.setOSName(Str.str()); - } else if (Arg *A = Args.getLastArg(options::OPT_miphoneos_version_min_EQ)) { - unsigned Major, Minor, Micro; - bool HadExtra; - if (!Driver::GetReleaseVersion(A->getValue(Args), Major, Minor, Micro, - HadExtra) || HadExtra) - D.Diag(clang::diag::err_drv_invalid_version_number) - << A->getAsString(Args); - // Mangle the iPhoneOS version number into the Darwin number: e.g. 2.0 is 2 - // -> 9.2.0. - llvm::SmallString<16> Str; - llvm::raw_svector_ostream(Str) << "darwin9." << Major << "." << Minor; - Triple.setOSName(Str.str()); + // Use the environment to communicate OS we are targetting. + if (isIPhoneTarget) + Triple.setEnvironmentName("iphoneos"); } return Triple.getTriple(); diff --git a/test/CodeGenObjC/image-info.m b/test/CodeGenObjC/image-info.m index 17f75319a0..8916d0053f 100644 --- a/test/CodeGenObjC/image-info.m +++ b/test/CodeGenObjC/image-info.m @@ -1,2 +1,2 @@ -// RUN: %clang_cc1 -triple x86_64-apple-darwin-10 -emit-llvm -o %t %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -o %t %s // RUN: grep -F '@"\01L_OBJC_IMAGE_INFO" = internal constant [2 x i32] [i32 0, i32 16], section "__OBJC, __image_info,regular"' %t |