[cfe-commits] r79320 - /cfe/trunk/lib/Basic/Targets.cpp
Daniel Dunbar
daniel at zuster.org
Mon Aug 17 22:47:58 PDT 2009
Author: ddunbar
Date: Tue Aug 18 00:47:58 2009
New Revision: 79320
URL: http://llvm.org/viewvc/llvm-project?rev=79320&view=rev
Log:
Convert CreateTargetInfo to use a Triple instead of manul string munging.
- Patch by Yonggang Luo (with some formatting tweaks by Eli and myself).
Modified:
cfe/trunk/lib/Basic/Targets.cpp
Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=79320&r1=79319&r2=79320&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Tue Aug 18 00:47:58 2009
@@ -1486,100 +1486,94 @@
// Driver code
//===----------------------------------------------------------------------===//
-static inline bool IsX86(const std::string& TT) {
- return (TT.size() >= 5 && TT[0] == 'i' && TT[2] == '8' && TT[3] == '6' &&
- TT[4] == '-' && TT[1] - '3' < 6);
-}
-
/// CreateTargetInfo - Return the target info object for the specified target
/// triple.
TargetInfo* TargetInfo::CreateTargetInfo(const std::string &T) {
- // OS detection; this isn't really anywhere near complete.
- // Additions and corrections are welcome.
- bool isDarwin = T.find("-darwin") != std::string::npos;
- bool isDragonFly = T.find("-dragonfly") != std::string::npos;
- bool isNetBSD = T.find("-netbsd") != std::string::npos;
- bool isOpenBSD = T.find("-openbsd") != std::string::npos;
- bool isFreeBSD = T.find("-freebsd") != std::string::npos;
- bool isSolaris = T.find("-solaris") != std::string::npos;
- bool isLinux = T.find("-linux") != std::string::npos;
- bool isWindows = T.find("-windows") != std::string::npos ||
- T.find("-win32") != std::string::npos ||
- T.find("-mingw") != std::string::npos;
+ llvm::Triple Triple(T);
+ llvm::Triple::OSType os = Triple.getOS();
+
+ switch (Triple.getArch()) {
+ default:
+ return NULL;
+
+ case llvm::Triple::arm:
+ switch (os) {
+ case llvm::Triple::Darwin:
+ return new DarwinARMTargetInfo(T);
+ case llvm::Triple::FreeBSD:
+ return new FreeBSDTargetInfo<ARMTargetInfo>(T);
+ default:
+ return new ARMTargetInfo(T);
+ }
+
+ case llvm::Triple::bfin:
+ return new BlackfinTargetInfo(T);
+
+ case llvm::Triple::msp430:
+ return new MSP430TargetInfo(T);
+
+ case llvm::Triple::pic16:
+ return new PIC16TargetInfo(T);
- if (T.find("ppc-") == 0 || T.find("powerpc-") == 0) {
- if (isDarwin)
+ case llvm::Triple::ppc:
+ if (os == llvm::Triple::Darwin)
return new DarwinTargetInfo<PPCTargetInfo>(T);
return new PPC32TargetInfo(T);
- }
- if (T.find("ppc64-") == 0 || T.find("powerpc64-") == 0) {
- if (isDarwin)
+ case llvm::Triple::ppc64:
+ if (os == llvm::Triple::Darwin)
return new DarwinTargetInfo<PPC64TargetInfo>(T);
return new PPC64TargetInfo(T);
- }
-
- if (T.find("armv") == 0 || T.find("arm-") == 0 || T.find("xscale") == 0) {
- if (isDarwin)
- return new DarwinARMTargetInfo(T);
- if (isFreeBSD)
- return new FreeBSDTargetInfo<ARMTargetInfo>(T);
- return new ARMTargetInfo(T);
- }
- if (T.find("sparc-") == 0) {
- if (isSolaris)
+ case llvm::Triple::sparc:
+ if (os == llvm::Triple::Solaris)
return new SolarisSparcV8TargetInfo(T);
return new SparcV8TargetInfo(T);
- }
- if (T.find("x86_64-") == 0 || T.find("amd64-") == 0) {
- if (isDarwin)
- return new DarwinX86_64TargetInfo(T);
- if (isLinux)
- return new LinuxTargetInfo<X86_64TargetInfo>(T);
- if (isNetBSD)
- return new NetBSDTargetInfo<X86_64TargetInfo>(T);
- if (isOpenBSD)
- return new OpenBSDX86_64TargetInfo(T);
- if (isFreeBSD)
- return new FreeBSDTargetInfo<X86_64TargetInfo>(T);
- if (isSolaris)
- return new SolarisTargetInfo<X86_64TargetInfo>(T);
- return new X86_64TargetInfo(T);
- }
-
- if (T.find("pic16-") == 0)
- return new PIC16TargetInfo(T);
-
- if (T.find("msp430-") == 0)
- return new MSP430TargetInfo(T);
-
- if (T.find("s390x-") == 0)
+ case llvm::Triple::systemz:
return new SystemZTargetInfo(T);
- if (T.find("bfin-") == 0)
- return new BlackfinTargetInfo(T);
-
- if (IsX86(T)) {
- if (isDarwin)
+ case llvm::Triple::x86:
+ switch (os) {
+ case llvm::Triple::Darwin:
return new DarwinI386TargetInfo(T);
- if (isLinux)
+ case llvm::Triple::Linux:
return new LinuxTargetInfo<X86_32TargetInfo>(T);
- if (isDragonFly)
+ case llvm::Triple::DragonFly:
return new DragonFlyBSDTargetInfo<X86_32TargetInfo>(T);
- if (isNetBSD)
+ case llvm::Triple::NetBSD:
return new NetBSDTargetInfo<X86_32TargetInfo>(T);
- if (isOpenBSD)
+ case llvm::Triple::OpenBSD:
return new OpenBSDI386TargetInfo(T);
- if (isFreeBSD)
+ case llvm::Triple::FreeBSD:
return new FreeBSDTargetInfo<X86_32TargetInfo>(T);
- if (isSolaris)
+ case llvm::Triple::Solaris:
return new SolarisTargetInfo<X86_32TargetInfo>(T);
- if (isWindows)
+ case llvm::Triple::Cygwin:
+ case llvm::Triple::MinGW32:
+ case llvm::Triple::MinGW64:
+ case llvm::Triple::Win32:
return new WindowsX86_32TargetInfo(T);
- return new X86_32TargetInfo(T);
+ default:
+ return new X86_32TargetInfo(T);
+ }
+
+ case llvm::Triple::x86_64:
+ switch (os) {
+ case llvm::Triple::Darwin:
+ return new DarwinX86_64TargetInfo(T);
+ case llvm::Triple::Linux:
+ return new LinuxTargetInfo<X86_64TargetInfo>(T);
+ case llvm::Triple::NetBSD:
+ return new NetBSDTargetInfo<X86_64TargetInfo>(T);
+ case llvm::Triple::OpenBSD:
+ return new OpenBSDX86_64TargetInfo(T);
+ case llvm::Triple::FreeBSD:
+ return new FreeBSDTargetInfo<X86_64TargetInfo>(T);
+ case llvm::Triple::Solaris:
+ return new SolarisTargetInfo<X86_64TargetInfo>(T);
+ default:
+ return new X86_64TargetInfo(T);
+ }
}
-
- return NULL;
}
More information about the cfe-commits
mailing list