From 28b82bc39ef076527c07718724913f70b5d60b69 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Mon, 31 Mar 2014 16:34:41 +0000 Subject: [PATCH] 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. llvm-svn: 205219 --- llvm/lib/Support/Triple.cpp | 22 +++++++++++++++------- llvm/unittests/ADT/TripleTest.cpp | 22 +++++++++++++++++----- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/llvm/lib/Support/Triple.cpp b/llvm/lib/Support/Triple.cpp index 1dc279a0db4f..71abb9d1657e 100644 --- a/llvm/lib/Support/Triple.cpp +++ b/llvm/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/llvm/unittests/ADT/TripleTest.cpp b/llvm/unittests/ADT/TripleTest.cpp index 7beddb93c77d..2e9d585b5dc8 100644 --- a/llvm/unittests/ADT/TripleTest.cpp +++ b/llvm/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")); } }