forked from OSchip/llvm-project
Remove NoVendor and NoOS, added in commit 123990, from Triple. While it
may be useful to understand "none", this is not the place for it. Tweak the fix to Normalize while there: the fix added in 123990 works correctly, but I like this way better. Finally, now that Triple understands some non-trivial environment values, teach the unittests about them. llvm-svn: 124720
This commit is contained in:
parent
fe719128e9
commit
fdfdbd091d
|
@ -72,8 +72,7 @@ public:
|
|||
UnknownVendor,
|
||||
|
||||
Apple,
|
||||
PC,
|
||||
NoVendor
|
||||
PC
|
||||
};
|
||||
enum OSType {
|
||||
UnknownOS,
|
||||
|
@ -93,8 +92,7 @@ public:
|
|||
Solaris,
|
||||
Win32,
|
||||
Haiku,
|
||||
Minix,
|
||||
NoOS
|
||||
Minix
|
||||
};
|
||||
enum EnvironmentType {
|
||||
UnknownEnvironment,
|
||||
|
|
|
@ -84,7 +84,6 @@ const char *Triple::getVendorTypeName(VendorType Kind) {
|
|||
|
||||
case Apple: return "apple";
|
||||
case PC: return "pc";
|
||||
case NoVendor: return "none";
|
||||
}
|
||||
|
||||
return "<invalid>";
|
||||
|
@ -110,7 +109,6 @@ const char *Triple::getOSTypeName(OSType Kind) {
|
|||
case Win32: return "win32";
|
||||
case Haiku: return "haiku";
|
||||
case Minix: return "minix";
|
||||
case NoOS: return "none";
|
||||
}
|
||||
|
||||
return "<invalid>";
|
||||
|
@ -299,8 +297,6 @@ Triple::VendorType Triple::ParseVendor(StringRef VendorName) {
|
|||
return Apple;
|
||||
else if (VendorName == "pc")
|
||||
return PC;
|
||||
else if (VendorName == "none")
|
||||
return NoVendor;
|
||||
else
|
||||
return UnknownVendor;
|
||||
}
|
||||
|
@ -338,8 +334,6 @@ Triple::OSType Triple::ParseOS(StringRef OSName) {
|
|||
return Haiku;
|
||||
else if (OSName.startswith("minix"))
|
||||
return Minix;
|
||||
else if (OSName.startswith("eabi"))
|
||||
return NoOS;
|
||||
else
|
||||
return UnknownOS;
|
||||
}
|
||||
|
@ -363,12 +357,7 @@ void Triple::Parse() const {
|
|||
Arch = ParseArch(getArchName());
|
||||
Vendor = ParseVendor(getVendorName());
|
||||
OS = ParseOS(getOSName());
|
||||
if (OS == NoOS) {
|
||||
// Some targets don't have an OS (embedded systems)
|
||||
Environment = ParseEnvironment(getOSName());
|
||||
} else {
|
||||
Environment = ParseEnvironment(getEnvironmentName());
|
||||
}
|
||||
Environment = ParseEnvironment(getEnvironmentName());
|
||||
|
||||
assert(isInitialized() && "Failed to initialize!");
|
||||
}
|
||||
|
@ -435,13 +424,7 @@ std::string Triple::normalize(StringRef Str) {
|
|||
break;
|
||||
case 2:
|
||||
OS = ParseOS(Comp);
|
||||
// Some targets don't have an OS (embedded systems)
|
||||
if (OS == NoOS) {
|
||||
Environment = ParseEnvironment(Comp);
|
||||
Valid = Environment != UnknownEnvironment;
|
||||
} else {
|
||||
Valid = OS != UnknownOS;
|
||||
}
|
||||
Valid = OS != UnknownOS;
|
||||
break;
|
||||
case 3:
|
||||
Environment = ParseEnvironment(Comp);
|
||||
|
@ -477,18 +460,15 @@ std::string Triple::normalize(StringRef Str) {
|
|||
do {
|
||||
// Insert one empty component at Idx.
|
||||
StringRef CurrentComponent(""); // The empty component.
|
||||
for (unsigned i = Idx; i < Components.size(); ++i) {
|
||||
// Skip over any fixed components.
|
||||
while (i < array_lengthof(Found) && Found[i]) ++i;
|
||||
// Fix problem when Components vector is not big enough
|
||||
if (i >= Components.size())
|
||||
Components.push_back(StringRef(""));
|
||||
for (unsigned i = Idx; i < Components.size();) {
|
||||
// Place the component at the new position, getting the component
|
||||
// that was at this position - it will be moved right.
|
||||
std::swap(CurrentComponent, Components[i]);
|
||||
// If it was placed on top of an empty component then we are done.
|
||||
if (CurrentComponent.empty())
|
||||
break;
|
||||
// Advance to the next component, skipping any fixed components.
|
||||
while (++i < array_lengthof(Found) && Found[i]);
|
||||
}
|
||||
// The last component was pushed off the end - append it.
|
||||
if (!CurrentComponent.empty())
|
||||
|
|
|
@ -93,10 +93,10 @@ TEST(TripleTest, ParsedIDs) {
|
|||
EXPECT_EQ(Triple::UnknownOS, T.getOS());
|
||||
EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
|
||||
|
||||
T = Triple("arm-none-eabi");
|
||||
T = Triple("arm-none-none-eabi");
|
||||
EXPECT_EQ(Triple::arm, T.getArch());
|
||||
EXPECT_EQ(Triple::NoVendor, T.getVendor());
|
||||
EXPECT_EQ(Triple::NoOS, T.getOS());
|
||||
EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
|
||||
EXPECT_EQ(Triple::UnknownOS, T.getOS());
|
||||
EXPECT_EQ(Triple::EABI, T.getEnvironment());
|
||||
|
||||
T = Triple("huh");
|
||||
|
@ -154,7 +154,6 @@ TEST(TripleTest, Normalization) {
|
|||
// Check that normalizing a permutated set of valid components returns a
|
||||
// triple with the unpermuted components.
|
||||
StringRef C[4];
|
||||
C[3] = "environment";
|
||||
for (int Arch = 1+Triple::UnknownArch; Arch < Triple::InvalidArch; ++Arch) {
|
||||
C[0] = Triple::getArchTypeName(Triple::ArchType(Arch));
|
||||
for (int Vendor = 1+Triple::UnknownVendor; Vendor <= Triple::PC;
|
||||
|
@ -162,47 +161,51 @@ TEST(TripleTest, Normalization) {
|
|||
C[1] = Triple::getVendorTypeName(Triple::VendorType(Vendor));
|
||||
for (int OS = 1+Triple::UnknownOS; OS <= Triple::Minix; ++OS) {
|
||||
C[2] = Triple::getOSTypeName(Triple::OSType(OS));
|
||||
for (int Env = 1+Triple::UnknownEnvironment; Env <= Triple::MachO;
|
||||
++Env) {
|
||||
C[3] = Triple::getEnvironmentTypeName(Triple::EnvironmentType(Env));
|
||||
|
||||
std::string E = Join(C[0], C[1], C[2]);
|
||||
std::string F = Join(C[0], C[1], C[2], C[3]);
|
||||
EXPECT_EQ(E, Triple::normalize(Join(C[0], C[1], C[2])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[0], C[1], C[2], C[3])));
|
||||
std::string E = Join(C[0], C[1], C[2]);
|
||||
std::string F = Join(C[0], C[1], C[2], C[3]);
|
||||
EXPECT_EQ(E, Triple::normalize(Join(C[0], C[1], C[2])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[0], C[1], C[2], C[3])));
|
||||
|
||||
// If a value has multiple interpretations, then the permutation
|
||||
// test will inevitably fail. Currently this is only the case for
|
||||
// "psp" which parses as both an architecture and an O/S.
|
||||
if (OS == Triple::Psp)
|
||||
continue;
|
||||
// If a value has multiple interpretations, then the permutation
|
||||
// test will inevitably fail. Currently this is only the case for
|
||||
// "psp" which parses as both an architecture and an O/S.
|
||||
if (OS == Triple::Psp)
|
||||
continue;
|
||||
|
||||
EXPECT_EQ(E, Triple::normalize(Join(C[0], C[2], C[1])));
|
||||
EXPECT_EQ(E, Triple::normalize(Join(C[1], C[2], C[0])));
|
||||
EXPECT_EQ(E, Triple::normalize(Join(C[1], C[0], C[2])));
|
||||
EXPECT_EQ(E, Triple::normalize(Join(C[2], C[0], C[1])));
|
||||
EXPECT_EQ(E, Triple::normalize(Join(C[2], C[1], C[0])));
|
||||
EXPECT_EQ(E, Triple::normalize(Join(C[0], C[2], C[1])));
|
||||
EXPECT_EQ(E, Triple::normalize(Join(C[1], C[2], C[0])));
|
||||
EXPECT_EQ(E, Triple::normalize(Join(C[1], C[0], C[2])));
|
||||
EXPECT_EQ(E, Triple::normalize(Join(C[2], C[0], C[1])));
|
||||
EXPECT_EQ(E, Triple::normalize(Join(C[2], C[1], C[0])));
|
||||
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[0], C[1], C[3], C[2])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[0], C[2], C[3], C[1])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[0], C[2], C[1], C[3])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[0], C[3], C[1], C[2])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[0], C[3], C[2], C[1])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[1], C[2], C[3], C[0])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[1], C[2], C[0], C[3])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[1], C[3], C[0], C[2])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[1], C[3], C[2], C[0])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[1], C[0], C[2], C[3])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[1], C[0], C[3], C[2])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[2], C[3], C[0], C[1])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[2], C[3], C[1], C[0])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[2], C[0], C[1], C[3])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[2], C[0], C[3], C[1])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[2], C[1], C[3], C[0])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[2], C[1], C[0], C[3])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[3], C[0], C[1], C[2])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[3], C[0], C[2], C[1])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[3], C[1], C[2], C[0])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[3], C[1], C[0], C[2])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[3], C[2], C[0], C[1])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[3], C[2], C[1], C[0])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[0], C[1], C[3], C[2])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[0], C[2], C[3], C[1])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[0], C[2], C[1], C[3])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[0], C[3], C[1], C[2])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[0], C[3], C[2], C[1])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[1], C[2], C[3], C[0])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[1], C[2], C[0], C[3])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[1], C[3], C[0], C[2])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[1], C[3], C[2], C[0])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[1], C[0], C[2], C[3])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[1], C[0], C[3], C[2])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[2], C[3], C[0], C[1])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[2], C[3], C[1], C[0])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[2], C[0], C[1], C[3])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[2], C[0], C[3], C[1])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[2], C[1], C[3], C[0])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[2], C[1], C[0], C[3])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[3], C[0], C[1], C[2])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[3], C[0], C[2], C[1])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[3], C[1], C[2], C[0])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[3], C[1], C[0], C[2])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[3], C[2], C[0], C[1])));
|
||||
EXPECT_EQ(F, Triple::normalize(Join(C[3], C[2], C[1], C[0])));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -217,6 +220,7 @@ TEST(TripleTest, Normalization) {
|
|||
EXPECT_EQ("i486--linux-gnu", Triple::normalize("i486-linux-gnu")); // i486-pc-linux-gnu
|
||||
EXPECT_EQ("i386-redhat-linux", Triple::normalize("i386-redhat-linux")); // i386-redhat-linux-gnu
|
||||
EXPECT_EQ("i686--linux", Triple::normalize("i686-linux")); // i686-pc-linux-gnu
|
||||
EXPECT_EQ("arm-none--eabi", Triple::normalize("arm-none-eabi")); // arm-none-eabi
|
||||
}
|
||||
|
||||
TEST(TripleTest, MutateName) {
|
||||
|
|
Loading…
Reference in New Issue