Switch a bunch of manual if-chains to use StringSwitch. Clean them up in

the process. Some of these are still a bit gross.

Still, this cuts 80 some lines out of this ridiculous file. ;]

llvm-svn: 150331
This commit is contained in:
Chandler Carruth 2012-02-12 09:27:38 +00:00
parent 9dc864b6ce
commit ff6f356b95
1 changed files with 93 additions and 170 deletions

View File

@ -9,6 +9,7 @@
#include "llvm/ADT/Triple.h" #include "llvm/ADT/Triple.h"
#include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/STLExtras.h"
#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/ErrorHandling.h"
#include <cstring> #include <cstring>
@ -134,54 +135,31 @@ const char *Triple::getEnvironmentTypeName(EnvironmentType Kind) {
} }
Triple::ArchType Triple::getArchTypeForLLVMName(StringRef Name) { Triple::ArchType Triple::getArchTypeForLLVMName(StringRef Name) {
if (Name == "arm") return StringSwitch<Triple::ArchType>(Name)
return arm; .Case("arm", arm)
if (Name == "cellspu") .Case("cellspu", cellspu)
return cellspu; .Case("mips", mips)
if (Name == "mips") .Case("mipsel", mipsel)
return mips; .Case("mips64", mips64)
if (Name == "mipsel") .Case("mips64el", mips64el)
return mipsel; .Case("msp430", msp430)
if (Name == "mips64") .Case("ppc64", ppc64)
return mips64; .Case("ppc32", ppc)
if (Name == "mips64el") .Case("ppc", ppc)
return mips64el; .Case("mblaze", mblaze)
if (Name == "msp430") .Case("hexagon", hexagon)
return msp430; .Case("sparc", sparc)
if (Name == "ppc64") .Case("sparcv9", sparcv9)
return ppc64; .Case("tce", tce)
if (Name == "ppc32") .Case("thumb", thumb)
return ppc; .Case("x86", x86)
if (Name == "ppc") .Case("x86-64", x86_64)
return ppc; .Case("xcore", xcore)
if (Name == "mblaze") .Case("ptx32", ptx32)
return mblaze; .Case("ptx64", ptx64)
if (Name == "hexagon") .Case("le32", le32)
return hexagon; .Case("amdil", amdil)
if (Name == "sparc") .Default(UnknownArch);
return sparc;
if (Name == "sparcv9")
return sparcv9;
if (Name == "tce")
return tce;
if (Name == "thumb")
return thumb;
if (Name == "x86")
return x86;
if (Name == "x86-64")
return x86_64;
if (Name == "xcore")
return xcore;
if (Name == "ptx32")
return ptx32;
if (Name == "ptx64")
return ptx64;
if (Name == "le32")
return le32;
if (Name == "amdil")
return amdil;
return UnknownArch;
} }
Triple::ArchType Triple::getArchTypeForDarwinArchName(StringRef Str) { Triple::ArchType Triple::getArchTypeForDarwinArchName(StringRef Str) {
@ -197,36 +175,21 @@ Triple::ArchType Triple::getArchTypeForDarwinArchName(StringRef Str) {
// This code must be kept in sync with Clang's Darwin specific argument // This code must be kept in sync with Clang's Darwin specific argument
// translation. // translation.
if (Str == "ppc" || Str == "ppc601" || Str == "ppc603" || Str == "ppc604" || return StringSwitch<ArchType>(Str)
Str == "ppc604e" || Str == "ppc750" || Str == "ppc7400" || .Cases("ppc", "ppc601", "ppc603", "ppc604", "ppc604e", Triple::ppc)
Str == "ppc7450" || Str == "ppc970") .Cases("ppc750", "ppc7400", "ppc7450", "ppc970", Triple::ppc)
return Triple::ppc; .Case("ppc64", Triple::ppc64)
.Cases("i386", "i486", "i486SX", "i586", "i686", Triple::x86)
if (Str == "ppc64") .Cases("pentium", "pentpro", "pentIIm3", "pentIIm5", "pentium4",
return Triple::ppc64; Triple::x86)
.Case("x86_64", Triple::x86_64)
if (Str == "i386" || Str == "i486" || Str == "i486SX" || Str == "pentium" || // This is derived from the driver driver.
Str == "i586" || Str == "pentpro" || Str == "i686" || Str == "pentIIm3" || .Cases("arm", "armv4t", "armv5", "armv6", Triple::arm)
Str == "pentIIm5" || Str == "pentium4") .Cases("armv7", "armv7f", "armv7k", "armv7s", "xscale", Triple::arm)
return Triple::x86; .Case("ptx32", Triple::ptx32)
.Case("ptx64", Triple::ptx64)
if (Str == "x86_64") .Case("amdil", Triple::amdil)
return Triple::x86_64; .Default(Triple::UnknownArch);
// This is derived from the driver driver.
if (Str == "arm" || Str == "armv4t" || Str == "armv5" || Str == "xscale" ||
Str == "armv6" || Str == "armv7" || Str == "armv7f" || Str == "armv7k" ||
Str == "armv7s")
return Triple::arm;
if (Str == "ptx32")
return Triple::ptx32;
if (Str == "ptx64")
return Triple::ptx64;
if (Str == "amdil")
return Triple::amdil;
return Triple::UnknownArch;
} }
// Returns architecture name that is understood by the target assembler. // Returns architecture name that is understood by the target assembler.
@ -234,106 +197,66 @@ const char *Triple::getArchNameForAssembler() {
if (!isOSDarwin() && getVendor() != Triple::Apple) if (!isOSDarwin() && getVendor() != Triple::Apple)
return NULL; return NULL;
StringRef Str = getArchName(); return StringSwitch<const char*>(getArchName())
if (Str == "i386") .Case("i386", "i386")
return "i386"; .Case("x86_64", "x86_64")
if (Str == "x86_64") .Case("powerpc", "ppc")
return "x86_64"; .Case("powerpc64", "ppc64")
if (Str == "powerpc") .Cases("mblaze", "microblaze", "mblaze")
return "ppc"; .Case("arm", "arm")
if (Str == "powerpc64") .Cases("armv4t", "thumbv4t", "armv4t")
return "ppc64"; .Cases("armv5", "armv5e", "thumbv5", "thumbv5e", "armv5")
if (Str == "mblaze" || Str == "microblaze") .Cases("armv6", "thumbv6", "armv6")
return "mblaze"; .Cases("armv7", "thumbv7", "armv7")
if (Str == "arm") .Case("ptx32", "ptx32")
return "arm"; .Case("ptx64", "ptx64")
if (Str == "armv4t" || Str == "thumbv4t") .Case("le32", "le32")
return "armv4t"; .Case("amdil", "amdil")
if (Str == "armv5" || Str == "armv5e" || Str == "thumbv5" .Default(NULL);
|| Str == "thumbv5e")
return "armv5";
if (Str == "armv6" || Str == "thumbv6")
return "armv6";
if (Str == "armv7" || Str == "thumbv7")
return "armv7";
if (Str == "ptx32")
return "ptx32";
if (Str == "ptx64")
return "ptx64";
if (Str == "le32")
return "le32";
if (Str == "amdil")
return "amdil";
return NULL;
} }
// //
Triple::ArchType Triple::ParseArch(StringRef ArchName) { Triple::ArchType Triple::ParseArch(StringRef ArchName) {
if (ArchName.size() == 4 && ArchName[0] == 'i' && // Handle some unusual patterns.
ArchName[2] == '8' && ArchName[3] == '6' && // FIXME: It would be good to replace these with explicit names for all the
ArchName[1] - '3' < 6) // i[3-9]86 // various suffixes supported.
return x86; if (ArchName.startswith("armv")) return arm;
else if (ArchName == "amd64" || ArchName == "x86_64") if (ArchName.startswith("thumbv")) return thumb;
return x86_64;
else if (ArchName == "powerpc") return StringSwitch<ArchType>(ArchName)
return ppc; .Cases("i386", "i486", "i586", "i686", x86)
else if ((ArchName == "powerpc64") || (ArchName == "ppu")) .Cases("i786", "i886", "i986", x86) // FIXME: Do we need to support these?
return ppc64; .Cases("amd64", "x86_64", x86_64)
else if (ArchName == "mblaze") .Case("powerpc", ppc)
return mblaze; .Cases("powerpc64", "ppu", ppc64)
else if (ArchName == "arm" || .Case("mblaze", mblaze)
ArchName.startswith("armv") || .Cases("arm", "xscale", arm)
ArchName == "xscale") .Case("thumb", thumb)
return arm; .Cases("spu", "cellspu", cellspu)
else if (ArchName == "thumb" || .Case("msp430", msp430)
ArchName.startswith("thumbv")) .Cases("mips", "mipseb", "mipsallegrex", mips)
return thumb; .Cases("mipsel", "mipsallegrexel", "psp", mipsel)
else if (ArchName == "spu" || ArchName == "cellspu") .Cases("mips64", "mips64eb", mips64)
return cellspu; .Case("mips64el", mips64el)
else if (ArchName == "msp430") .Case("hexagon", hexagon)
return msp430; .Case("sparc", sparc)
else if (ArchName == "mips" || ArchName == "mipseb" || .Case("sparcv9", sparcv9)
ArchName == "mipsallegrex") .Case("tce", tce)
return mips; .Case("xcore", xcore)
else if (ArchName == "mipsel" || ArchName == "mipsallegrexel" || .Case("ptx32", ptx32)
ArchName == "psp") .Case("ptx64", ptx64)
return mipsel; .Case("le32", le32)
else if (ArchName == "mips64" || ArchName == "mips64eb") .Case("amdil", amdil)
return mips64; .Default(UnknownArch);
else if (ArchName == "mips64el")
return mips64el;
else if (ArchName == "hexagon")
return hexagon;
else if (ArchName == "sparc")
return sparc;
else if (ArchName == "sparcv9")
return sparcv9;
else if (ArchName == "tce")
return tce;
else if (ArchName == "xcore")
return xcore;
else if (ArchName == "ptx32")
return ptx32;
else if (ArchName == "ptx64")
return ptx64;
else if (ArchName == "le32")
return le32;
else if (ArchName == "amdil")
return amdil;
else
return UnknownArch;
} }
Triple::VendorType Triple::ParseVendor(StringRef VendorName) { Triple::VendorType Triple::ParseVendor(StringRef VendorName) {
if (VendorName == "apple") return StringSwitch<VendorType>(VendorName)
return Apple; .Case("apple", Apple)
else if (VendorName == "pc") .Case("pc", PC)
return PC; .Case("scei", SCEI)
else if (VendorName == "scei") .Default(UnknownVendor);
return SCEI;
else
return UnknownVendor;
} }
Triple::OSType Triple::ParseOS(StringRef OSName) { Triple::OSType Triple::ParseOS(StringRef OSName) {