From: Saleem Abdulrasool Date: Mon, 31 Mar 2014 16:34:41 +0000 (+0000) Subject: Support: generalise object type handling for Windows X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=bd5fac585ed0789655a4133f41e12654c99766b9;p=oota-llvm.git 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 --- diff --git a/lib/Support/Triple.cpp b/lib/Support/Triple.cpp index 1dc279a0db4..71abb9d1657 100644 --- a/lib/Support/Triple.cpp +++ b/lib/Support/Triple.cpp @@ -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) { diff --git a/unittests/ADT/TripleTest.cpp b/unittests/ADT/TripleTest.cpp index 7beddb93c77..2e9d585b5dc 100644 --- a/unittests/ADT/TripleTest.cpp +++ b/unittests/ADT/TripleTest.cpp @@ -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")); } }