[PATCH] D18749: Add LLVMGetAttrKindIDInContext in the C API in order to facilitate migration away from LLVMAttribute
Amaury SECHET via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 13 15:57:25 PDT 2016
This revision was automatically updated to reflect the committed changes.
Closed by commit rL266257: Add LLVMGetAttrKindIDInContext in the C API in order to facilitate migration… (authored by deadalnix).
Changed prior to commit:
http://reviews.llvm.org/D18749?vs=53499&id=53634#toc
Repository:
rL LLVM
http://reviews.llvm.org/D18749
Files:
llvm/trunk/include/llvm-c/Core.h
llvm/trunk/lib/IR/Core.cpp
llvm/trunk/utils/TableGen/Attributes.cpp
Index: llvm/trunk/lib/IR/Core.cpp
===================================================================
--- llvm/trunk/lib/IR/Core.cpp
+++ llvm/trunk/lib/IR/Core.cpp
@@ -13,6 +13,8 @@
//===----------------------------------------------------------------------===//
#include "llvm-c/Core.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "AttributeImpl.h"
#include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/CallSite.h"
@@ -119,6 +121,16 @@
return LLVMGetMDKindIDInContext(LLVMGetGlobalContext(), Name, SLen);
}
+#define GET_ATTR_KIND_FROM_NAME
+#include "AttributesCompatFunc.inc"
+
+unsigned LLVMGetAttrKindIDInContext(LLVMContextRef C, const char *Name,
+ size_t SLen) {
+ auto K = getAttrKindFromName(StringRef(Name, SLen));
+ assert(K != Attribute::None && "Invalid attribute");
+ return AttributeImpl::getAttrMask(K);
+}
+
char *LLVMGetDiagInfoDescription(LLVMDiagnosticInfoRef DI) {
std::string MsgStorage;
raw_string_ostream Stream(MsgStorage);
Index: llvm/trunk/utils/TableGen/Attributes.cpp
===================================================================
--- llvm/trunk/utils/TableGen/Attributes.cpp
+++ llvm/trunk/utils/TableGen/Attributes.cpp
@@ -27,6 +27,7 @@
private:
void emitTargetIndependentEnums(raw_ostream &OS);
+ void emitConversionFn(raw_ostream &OS);
void emitFnAttrCompatCheck(raw_ostream &OS, bool IsStringAttr);
void printEnumAttrClasses(raw_ostream &OS,
@@ -52,6 +53,27 @@
OS << "#endif\n";
}
+void Attributes::emitConversionFn(raw_ostream &OS) {
+ OS << "#ifdef GET_ATTR_KIND_FROM_NAME\n";
+ OS << "#undef GET_ATTR_KIND_FROM_NAME\n";
+
+ std::vector<Record*> Attrs =
+ Records.getAllDerivedDefinitions("EnumAttr");
+
+ OS << "static Attribute::AttrKind getAttrKindFromName(StringRef AttrName) {\n";
+ OS << " return StringSwitch<Attribute::AttrKind>(AttrName)\n";
+
+ for (auto A : Attrs) {
+ OS << " .Case(\"" << A->getValueAsString("AttrString");
+ OS << "\", Attribute::" << A->getName() << ")\n";
+ }
+
+ OS << " .Default(Attribute::None);\n";
+ OS << "}\n\n";
+
+ OS << "#endif\n";
+}
+
void Attributes::emitFnAttrCompatCheck(raw_ostream &OS, bool IsStringAttr) {
OS << "#ifdef GET_ATTR_COMPAT_FUNC\n";
OS << "#undef GET_ATTR_COMPAT_FUNC\n";
@@ -144,6 +166,7 @@
void Attributes::emit(raw_ostream &OS) {
emitTargetIndependentEnums(OS);
+ emitConversionFn(OS);
emitFnAttrCompatCheck(OS, false);
}
Index: llvm/trunk/include/llvm-c/Core.h
===================================================================
--- llvm/trunk/include/llvm-c/Core.h
+++ llvm/trunk/include/llvm-c/Core.h
@@ -476,6 +476,9 @@
unsigned SLen);
unsigned LLVMGetMDKindID(const char *Name, unsigned SLen);
+unsigned LLVMGetAttrKindIDInContext(LLVMContextRef C, const char *Name,
+ size_t SLen);
+
/**
* @}
*/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18749.53634.patch
Type: text/x-patch
Size: 2950 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160413/f8c293b2/attachment.bin>
More information about the llvm-commits
mailing list