diff options
author | Devang Patel <dpatel@apple.com> | 2009-09-29 00:01:14 +0000 |
---|---|---|
committer | Devang Patel <dpatel@apple.com> | 2009-09-29 00:01:14 +0000 |
commit | 17c60df1f139b966e696c18683d6fac7afb0d4ac (patch) | |
tree | 27fa176e397a7b67a917a5fe229c48e86bf41bdd /lib/VMCore | |
parent | 8a60e6ab5c0bdebeeb93bf7837306b526c6174cd (diff) | |
download | external_llvm-17c60df1f139b966e696c18683d6fac7afb0d4ac.zip external_llvm-17c60df1f139b966e696c18683d6fac7afb0d4ac.tar.gz external_llvm-17c60df1f139b966e696c18683d6fac7afb0d4ac.tar.bz2 |
Parse custom metadata attached with an instruction.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@83033 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r-- | lib/VMCore/AsmWriter.cpp | 2 | ||||
-rw-r--r-- | lib/VMCore/Metadata.cpp | 23 |
2 files changed, 24 insertions, 1 deletions
diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp index a8b3d05..60c5b3e 100644 --- a/lib/VMCore/AsmWriter.cpp +++ b/lib/VMCore/AsmWriter.cpp @@ -2007,7 +2007,7 @@ void AssemblyWriter::printInstruction(const Instruction &I) { for (MetadataContext::MDMapTy::const_iterator MI = MDMap->begin(), ME = MDMap->end(); MI != ME; ++MI) if (const MDNode *MD = dyn_cast_or_null<MDNode>(MI->second)) - Out << ", " << MDNames[MI->first] + Out << ", !" << MDNames[MI->first] << " !" << Machine.getMetadataSlot(MD); printInfoComment(I); diff --git a/lib/VMCore/Metadata.cpp b/lib/VMCore/Metadata.cpp index ddd5103..8ae7d30 100644 --- a/lib/VMCore/Metadata.cpp +++ b/lib/VMCore/Metadata.cpp @@ -260,6 +260,7 @@ NamedMDNode::~NamedMDNode() { /// RegisterMDKind - Register a new metadata kind and return its ID. /// A metadata kind can be registered only once. unsigned MetadataContext::RegisterMDKind(const char *Name) { + assert (validName(Name) && "Invalid custome metadata name!"); unsigned Count = MDHandlerNames.size(); StringMap<unsigned>::iterator I = MDHandlerNames.find(Name); assert(I == MDHandlerNames.end() && "Already registered MDKind!"); @@ -267,9 +268,31 @@ unsigned MetadataContext::RegisterMDKind(const char *Name) { return Count + 1; } +/// validName - Return true if Name is a valid custom metadata handler name. +bool MetadataContext::validName(const char *Name) { + if (!Name) + return false; + + if (!isalpha(*Name)) + return false; + + unsigned Length = strlen(Name); + unsigned Count = 1; + ++Name; + while (Name && + (isalnum(*Name) || *Name == '_' || *Name == '-' || *Name == '.')) { + ++Name; + ++Count; + } + if (Length != Count) + return false; + return true; +} + /// getMDKind - Return metadata kind. If the requested metadata kind /// is not registered then return 0. unsigned MetadataContext::getMDKind(const char *Name) { + assert (validName(Name) && "Invalid custome metadata name!"); StringMap<unsigned>::iterator I = MDHandlerNames.find(Name); if (I == MDHandlerNames.end()) return 0; |