[llvm] r205219 - Support: generalise object type handling for Windows
Saleem Abdulrasool
compnerd at compnerd.org
Mon Mar 31 09:34:41 PDT 2014
Author: compnerd
Date: Mon Mar 31 11:34:41 2014
New Revision: 205219
URL: http://llvm.org/viewvc/llvm-project?rev=205219&view=rev
Log:
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.
Modified:
llvm/trunk/lib/Support/Triple.cpp
llvm/trunk/unittests/ADT/TripleTest.cpp
Modified: llvm/trunk/lib/Support/Triple.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Triple.cpp?rev=205219&r1=205218&r2=205219&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Triple.cpp (original)
+++ llvm/trunk/lib/Support/Triple.cpp Mon Mar 31 11:34:41 2014
@@ -547,24 +547,27 @@ std::string Triple::normalize(StringRef
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(EnvironmentT
}
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) {
Modified: llvm/trunk/unittests/ADT/TripleTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/TripleTest.cpp?rev=205219&r1=205218&r2=205219&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/TripleTest.cpp (original)
+++ llvm/trunk/unittests/ADT/TripleTest.cpp Mon Mar 31 11:34:41 2014
@@ -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"));
}
}
More information about the llvm-commits
mailing list