[clang] 703895b - [clang] Language to String function (#69487)

via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 27 14:22:53 PDT 2023


Author: Yusra Syeda
Date: 2023-10-27T17:22:49-04:00
New Revision: 703895b131720682a3ca596a96a7c94fb281c0e4

URL: https://github.com/llvm/llvm-project/commit/703895b131720682a3ca596a96a7c94fb281c0e4
DIFF: https://github.com/llvm/llvm-project/commit/703895b131720682a3ca596a96a7c94fb281c0e4.diff

LOG: [clang] Language to String function (#69487)

This PR adds a function which converts the language to string. This is
intended to be used by the z/OS target, see the patch here:
https://github.com/llvm/llvm-project/pull/68926

---------

Co-authored-by: Yusra Syeda <yusra.syeda at ibm.com>

Added: 
    

Modified: 
    clang/include/clang/Basic/LangStandard.h
    clang/lib/Basic/LangStandards.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/LangStandard.h b/clang/include/clang/Basic/LangStandard.h
index 6356f16acc811e0..bc49669a82ad2db 100644
--- a/clang/include/clang/Basic/LangStandard.h
+++ b/clang/include/clang/Basic/LangStandard.h
@@ -43,6 +43,7 @@ enum class Language : uint8_t {
   HLSL,
   ///@}
 };
+StringRef languageToString(Language L);
 
 enum LangFeatures {
   LineComment = (1 << 0),

diff  --git a/clang/lib/Basic/LangStandards.cpp b/clang/lib/Basic/LangStandards.cpp
index af9cf4f273920ee..ab09c7221dda92f 100644
--- a/clang/lib/Basic/LangStandards.cpp
+++ b/clang/lib/Basic/LangStandards.cpp
@@ -13,6 +13,39 @@
 #include "llvm/TargetParser/Triple.h"
 using namespace clang;
 
+StringRef clang::languageToString(Language L) {
+  switch (L) {
+  case Language::Unknown:
+    return "Unknown";
+  case Language::Asm:
+    return "Asm";
+  case Language::LLVM_IR:
+    return "LLVM IR";
+  case Language::C:
+    return "C";
+  case Language::CXX:
+    return "C++";
+  case Language::ObjC:
+    return "Objective-C";
+  case Language::ObjCXX:
+    return "Objective-C++";
+  case Language::OpenCL:
+    return "OpenCL";
+  case Language::OpenCLCXX:
+    return "OpenCLC++";
+  case Language::CUDA:
+    return "CUDA";
+  case Language::RenderScript:
+    return "RenderScript";
+  case Language::HIP:
+    return "HIP";
+  case Language::HLSL:
+    return "HLSL";
+  }
+
+  llvm_unreachable("unhandled language kind");
+}
+
 #define LANGSTANDARD(id, name, lang, desc, features)                           \
   static const LangStandard Lang_##id = {name, desc, features, Language::lang};
 #include "clang/Basic/LangStandards.def"


        


More information about the cfe-commits mailing list