[clang] [clang] Language to String function (PR #69487)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 26 06:22:16 PDT 2023
================
@@ -10,9 +10,49 @@
#include "clang/Config/config.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/FormatVariadic.h"
#include "llvm/TargetParser/Triple.h"
using namespace clang;
+const char *clang::languageToString(Language L) {
+ // I would like to make this function and the definition of Language
+ // in the .h file simply expand the contents of a .def file.
+ // However, in the .h the members of the enum have doxygen annotations
+ // and/or comments which would be lost.
+ 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 "CXX";
+ case Language::ObjC:
+ return "ObjC";
+ case Language::ObjCXX:
+ return "ObjCXX";
+ case Language::OpenCL:
+ return "OpenCL";
+ case Language::OpenCLCXX:
+ return "OpenCLCXX";
+ case Language::CUDA:
+ return "CUDA";
+ case Language::RenderScript:
+ return "RenderScript";
+ case Language::HIP:
+ return "HIP";
+ case Language::HLSL:
+ return "HLSL";
+ }
+
+ std::string msg = llvm::formatv(
+ "Unknown value ({0}) passed to languageToString", (unsigned int)L);
+ llvm_unreachable(msg.c_str());
----------------
AaronBallman wrote:
```suggestion
llvm_unreachable("unhandled language kind");
```
https://github.com/llvm/llvm-project/pull/69487
More information about the cfe-commits
mailing list