Use VersionTuple to manage macosx versions in the driver. No functionality change.

llvm-svn: 152504
This commit is contained in:
Benjamin Kramer 2012-03-10 20:55:36 +00:00
parent 53ba63643c
commit ddefa6d925
3 changed files with 13 additions and 34 deletions

View File

@ -182,14 +182,10 @@ std::string Darwin::ComputeEffectiveClangTriple(const ArgList &Args,
if (!isTargetInitialized())
return Triple.getTriple();
unsigned Version[3];
getTargetVersion(Version);
SmallString<16> Str;
llvm::raw_svector_ostream(Str)
<< (isTargetIPhoneOS() ? "ios" : "macosx")
<< Version[0] << "." << Version[1] << "." << Version[2];
Triple.setOSName(Str.str());
Str += isTargetIPhoneOS() ? "ios" : "macosx";
Str += getTargetVersion().getAsString();
Triple.setOSName(Str);
return Triple.getTriple();
}

View File

@ -13,6 +13,7 @@
#include "clang/Driver/Action.h"
#include "clang/Driver/ToolChain.h"
#include "clang/Basic/VersionTuple.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/Support/Compiler.h"
@ -198,7 +199,7 @@ private:
mutable bool TargetIsIPhoneOSSimulator;
/// The OS version we are targeting.
mutable unsigned TargetVersion[3];
mutable VersionTuple TargetVersion;
/// The default macosx-version-min of this tool chain; empty until
/// initialized.
@ -230,17 +231,14 @@ public:
// change. This will go away when we move away from argument translation.
if (TargetInitialized && TargetIsIPhoneOS == IsIPhoneOS &&
TargetIsIPhoneOSSimulator == IsIOSSim &&
TargetVersion[0] == Major && TargetVersion[1] == Minor &&
TargetVersion[2] == Micro)
TargetVersion == VersionTuple(Major, Minor, Micro))
return;
assert(!TargetInitialized && "Target already initialized!");
TargetInitialized = true;
TargetIsIPhoneOS = IsIPhoneOS;
TargetIsIPhoneOSSimulator = IsIOSSim;
TargetVersion[0] = Major;
TargetVersion[1] = Minor;
TargetVersion[2] = Micro;
TargetVersion = VersionTuple(Major, Minor, Micro);
}
bool isTargetIPhoneOS() const {
@ -261,11 +259,9 @@ public:
bool isTargetInitialized() const { return TargetInitialized; }
void getTargetVersion(unsigned (&Res)[3]) const {
VersionTuple getTargetVersion() const {
assert(TargetInitialized && "Target not initialized!");
Res[0] = TargetVersion[0];
Res[1] = TargetVersion[1];
Res[2] = TargetVersion[2];
return TargetVersion;
}
/// getDarwinArchName - Get the "Darwin" arch name for a particular compiler
@ -273,24 +269,14 @@ public:
/// distinct architectures.
StringRef getDarwinArchName(const ArgList &Args) const;
static bool isVersionLT(unsigned (&A)[3], unsigned (&B)[3]) {
for (unsigned i=0; i < 3; ++i) {
if (A[i] > B[i]) return false;
if (A[i] < B[i]) return true;
}
return false;
}
bool isIPhoneOSVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
assert(isTargetIPhoneOS() && "Unexpected call for OS X target!");
unsigned B[3] = { V0, V1, V2 };
return isVersionLT(TargetVersion, B);
return TargetVersion < VersionTuple(V0, V1, V2);
}
bool isMacosxVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
assert(!isTargetIPhoneOS() && "Unexpected call for iPhoneOS target!");
unsigned B[3] = { V0, V1, V2 };
return isVersionLT(TargetVersion, B);
return TargetVersion < VersionTuple(V0, V1, V2);
}
/// AddLinkSearchPathArgs - Add the linker search paths to \arg CmdArgs.

View File

@ -3852,8 +3852,7 @@ void darwin::Link::AddLinkArgs(Compilation &C,
Args.AddAllArgs(CmdArgs, options::OPT_init);
// Add the deployment target.
unsigned TargetVersion[3];
DarwinTC.getTargetVersion(TargetVersion);
VersionTuple TargetVersion = DarwinTC.getTargetVersion();
// If we had an explicit -mios-simulator-version-min argument, honor that,
// otherwise use the traditional deployment targets. We can't just check the
@ -3868,9 +3867,7 @@ void darwin::Link::AddLinkArgs(Compilation &C,
CmdArgs.push_back("-iphoneos_version_min");
else
CmdArgs.push_back("-macosx_version_min");
CmdArgs.push_back(Args.MakeArgString(Twine(TargetVersion[0]) + "." +
Twine(TargetVersion[1]) + "." +
Twine(TargetVersion[2])));
CmdArgs.push_back(Args.MakeArgString(TargetVersion.getAsString()));
Args.AddLastArg(CmdArgs, options::OPT_nomultidefs);
Args.AddLastArg(CmdArgs, options::OPT_multi__module);