Support: generalise object type handling for Windows

This generalises the object file type parsing to all Windows environments.  This
is used by cygwin as well as MSVC environments for MCJIT.  This also makes the
triple more similar to Chandler's suggestion of a separate field for the object
file format.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@205219 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Saleem Abdulrasool 2014-03-31 16:34:41 +00:00
parent 93f807bd05
commit bd5fac585e
2 changed files with 32 additions and 12 deletions

View File

@ -547,24 +547,27 @@ std::string Triple::normalize(StringRef Str) {
Components.resize(4);
Components[2] = "windows";
if (Environment == UnknownEnvironment) {
if (ObjectFormat == UnknownObjectFormat)
if (ObjectFormat == UnknownObjectFormat || ObjectFormat == Triple::COFF)
Components[3] = "msvc";
else
Components[3] = getObjectFormatTypeName(ObjectFormat);
} else if (ObjectFormat != UnknownObjectFormat &&
ObjectFormat != Triple::COFF) {
Components.resize(5);
Components[4] = getObjectFormatTypeName(ObjectFormat);
}
} else if (OS == Triple::MinGW32) {
Components.resize(4);
Components[2] = "windows";
Components[3] = (ObjectFormat == Triple::ELF) ? "gnuelf" : "gnu";
Components[3] = "gnu";
} else if (OS == Triple::Cygwin) {
Components.resize(4);
Components[2] = "windows";
Components[3] = "cygnus";
}
if (OS == Triple::MinGW32 || OS == Triple::Cygwin ||
(OS == Triple::Win32 && Environment != UnknownEnvironment)) {
if (ObjectFormat != UnknownObjectFormat && ObjectFormat != Triple::COFF) {
Components.resize(5);
Components[4] = getObjectFormatTypeName(ObjectFormat);
}
}
// Stick the corrected components back together to form the normalized string.
std::string Normalized;
@ -726,7 +729,12 @@ void Triple::setEnvironment(EnvironmentType Kind) {
}
void Triple::setObjectFormat(ObjectFormatType Kind) {
setEnvironmentName(getObjectFormatTypeName(Kind));
if (Environment == UnknownEnvironment)
return setEnvironmentName(getObjectFormatTypeName(Kind));
Twine Env = getEnvironmentTypeName(Environment) + Twine("-") +
getObjectFormatTypeName(Kind);
setEnvironmentName(Env.str());
}
void Triple::setArchName(StringRef Str) {

View File

@ -510,11 +510,19 @@ TEST(TripleTest, FileFormat) {
EXPECT_EQ(Triple::COFF, Triple("i686--win32").getObjectFormat());
EXPECT_EQ(Triple::ELF, Triple("i686-pc-windows-msvc-elf").getObjectFormat());
EXPECT_EQ(Triple::ELF, Triple("i686-pc-cygwin-elf").getObjectFormat());
{
Triple Normalized(Triple::normalize("i686-pc-windows-msvc-elf"));
EXPECT_EQ(Triple::ELF, Normalized.getObjectFormat());
}
Triple MSVCNormalized(Triple::normalize("i686-pc-windows-msvc-elf"));
EXPECT_EQ(Triple::ELF, MSVCNormalized.getObjectFormat());
Triple GNUWindowsNormalized(Triple::normalize("i686-pc-windows-gnu-elf"));
EXPECT_EQ(Triple::ELF, GNUWindowsNormalized.getObjectFormat());
Triple CygnusNormalised(Triple::normalize("i686-pc-windows-cygnus-elf"));
EXPECT_EQ(Triple::ELF, CygnusNormalised.getObjectFormat());
Triple CygwinNormalized(Triple::normalize("i686-pc-cygwin-elf"));
EXPECT_EQ(Triple::ELF, CygwinNormalized.getObjectFormat());
Triple T = Triple("");
T.setObjectFormat(Triple::ELF);
@ -548,8 +556,12 @@ TEST(TripleTest, NormalizeWindows) {
EXPECT_EQ("x86_64-pc-windows-macho", Triple::normalize("x86_64-pc-win32-macho"));
EXPECT_EQ("x86_64--windows-macho", Triple::normalize("x86_64-win32-macho"));
EXPECT_EQ("i686-pc-windows-cygnus",
Triple::normalize("i686-pc-windows-cygnus"));
EXPECT_EQ("i686-pc-windows-gnu", Triple::normalize("i686-pc-windows-gnu"));
EXPECT_EQ("i686-pc-windows-itanium", Triple::normalize("i686-pc-windows-itanium"));
EXPECT_EQ("i686-pc-windows-msvc", Triple::normalize("i686-pc-windows-msvc"));
EXPECT_EQ("i686-pc-windows-elf", Triple::normalize("i686-pc-windows-elf-elf"));
}
}