diff options
author | Amaury Sechet <deadalnix@gmail.com> | 2016-04-20 01:02:12 +0000 |
---|---|---|
committer | Amaury Sechet <deadalnix@gmail.com> | 2016-04-20 01:02:12 +0000 |
commit | 60b31453ac9cc8f8c1f484d6e16ae987b7059c0c (patch) | |
tree | 323b5de9d18e6738935dd2eda61b487f5ff7e781 /llvm/utils/TableGen/Attributes.cpp | |
parent | 8a57b23e8686299ce7f2695ce804eb1e54c0fbce (diff) | |
download | llvm-60b31453ac9cc8f8c1f484d6e16ae987b7059c0c.zip llvm-60b31453ac9cc8f8c1f484d6e16ae987b7059c0c.tar.gz llvm-60b31453ac9cc8f8c1f484d6e16ae987b7059c0c.tar.bz2 |
Add LLVMGetAttrKindID in the C API in order to facilitate migration away from LLVMAttribute
Summary:
LLVMAttribute has outlived its utility and is becoming a problem for C API users that what to use all the LLVM attributes. In order to help moving away from LLVMAttribute in a smooth manner, this diff introduce LLVMGetAttrKindIDInContext, which can be used instead of the enum values.
See D18749 for reference.
Reviewers: Wallbraker, whitequark, joker.eph, echristo, rafael
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D19081
llvm-svn: 266842
Diffstat (limited to 'llvm/utils/TableGen/Attributes.cpp')
-rw-r--r-- | llvm/utils/TableGen/Attributes.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/llvm/utils/TableGen/Attributes.cpp b/llvm/utils/TableGen/Attributes.cpp index 7b001bf..58dbe57 100644 --- a/llvm/utils/TableGen/Attributes.cpp +++ b/llvm/utils/TableGen/Attributes.cpp @@ -27,6 +27,7 @@ public: 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 @@ void Attributes::emitTargetIndependentEnums(raw_ostream &OS) { 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::printStrBoolAttrClasses(raw_ostream &OS, void Attributes::emit(raw_ostream &OS) { emitTargetIndependentEnums(OS); + emitConversionFn(OS); emitFnAttrCompatCheck(OS, false); } |