[llvm] 887d6ab - [TargetParser] Expose Triple::getObjectFormatTypeName.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 16 11:13:16 PDT 2023


Author: Lang Hames
Date: 2023-04-16T11:13:09-07:00
New Revision: 887d6ab12fa3123f61751d7438878bb4da492733

URL: https://github.com/llvm/llvm-project/commit/887d6ab12fa3123f61751d7438878bb4da492733
DIFF: https://github.com/llvm/llvm-project/commit/887d6ab12fa3123f61751d7438878bb4da492733.diff

LOG: [TargetParser] Expose Triple::getObjectFormatTypeName.

This is useful for printing the object format of a triple in debug logs.

Added: 
    

Modified: 
    llvm/include/llvm/TargetParser/Triple.h
    llvm/lib/TargetParser/Triple.cpp
    llvm/unittests/TargetParser/TripleTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/TargetParser/Triple.h b/llvm/include/llvm/TargetParser/Triple.h
index c15e9266a5132..b96e487b735f5 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -1105,6 +1105,9 @@ class Triple {
   /// Get the canonical name for the \p Kind environment.
   static StringRef getEnvironmentTypeName(EnvironmentType Kind);
 
+  /// Get the name for the \p Object format.
+  static StringRef getObjectFormatTypeName(ObjectFormatType ObjectFormat);
+
   /// @}
   /// @name Static helpers for converting alternate architecture names.
   /// @{

diff  --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index c586122ebdfc7..51b5b641b09e9 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -297,6 +297,21 @@ StringRef Triple::getEnvironmentTypeName(EnvironmentType Kind) {
   llvm_unreachable("Invalid EnvironmentType!");
 }
 
+StringRef Triple::getObjectFormatTypeName(ObjectFormatType Kind) {
+  switch (Kind) {
+  case UnknownObjectFormat: return "";
+  case COFF: return "coff";
+  case ELF: return "elf";
+  case GOFF: return "goff";
+  case MachO: return "macho";
+  case Wasm: return "wasm";
+  case XCOFF: return "xcoff";
+  case DXContainer: return "dxcontainer";
+  case SPIRV: return "spirv";
+  }
+  llvm_unreachable("unknown object format type");
+}
+
 static Triple::ArchType parseBPFArch(StringRef ArchName) {
   if (ArchName.equals("bpf")) {
     if (sys::IsLittleEndianHost)
@@ -774,30 +789,6 @@ static Triple::SubArchType parseSubArch(StringRef SubArchName) {
   }
 }
 
-static StringRef getObjectFormatTypeName(Triple::ObjectFormatType Kind) {
-  switch (Kind) {
-  case Triple::UnknownObjectFormat:
-    return "";
-  case Triple::COFF:
-    return "coff";
-  case Triple::ELF:
-    return "elf";
-  case Triple::GOFF:
-    return "goff";
-  case Triple::MachO:
-    return "macho";
-  case Triple::Wasm:
-    return "wasm";
-  case Triple::XCOFF:
-    return "xcoff";
-  case Triple::DXContainer:
-    return "dxcontainer";
-  case Triple::SPIRV:
-    return "spirv";
-  }
-  llvm_unreachable("unknown object format type");
-}
-
 static Triple::ObjectFormatType getDefaultFormat(const Triple &T) {
   switch (T.getArch()) {
   case Triple::UnknownArch:

diff  --git a/llvm/unittests/TargetParser/TripleTest.cpp b/llvm/unittests/TargetParser/TripleTest.cpp
index b4ef21e261f8c..10a27b07383b2 100644
--- a/llvm/unittests/TargetParser/TripleTest.cpp
+++ b/llvm/unittests/TargetParser/TripleTest.cpp
@@ -1879,18 +1879,23 @@ TEST(TripleTest, FileFormat) {
   Triple T = Triple("");
   T.setObjectFormat(Triple::ELF);
   EXPECT_EQ(Triple::ELF, T.getObjectFormat());
+  EXPECT_EQ("elf", Triple::getObjectFormatTypeName(T.getObjectFormat()));
 
   T.setObjectFormat(Triple::MachO);
   EXPECT_EQ(Triple::MachO, T.getObjectFormat());
+  EXPECT_EQ("macho", Triple::getObjectFormatTypeName(T.getObjectFormat()));
 
   T.setObjectFormat(Triple::XCOFF);
   EXPECT_EQ(Triple::XCOFF, T.getObjectFormat());
+  EXPECT_EQ("xcoff", Triple::getObjectFormatTypeName(T.getObjectFormat()));
 
   T.setObjectFormat(Triple::GOFF);
   EXPECT_EQ(Triple::GOFF, T.getObjectFormat());
+  EXPECT_EQ("goff", Triple::getObjectFormatTypeName(T.getObjectFormat()));
 
   T.setObjectFormat(Triple::SPIRV);
   EXPECT_EQ(Triple::SPIRV, T.getObjectFormat());
+  EXPECT_EQ("spirv", Triple::getObjectFormatTypeName(T.getObjectFormat()));
 }
 
 TEST(TripleTest, NormalizeWindows) {


        


More information about the llvm-commits mailing list