LLParser: Split out ParseMetadataAttachment(), NFC

Make the code reusable for `Function` metadata attachments (PR23340).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235778 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan P. N. Exon Smith 2015-04-24 21:21:57 +00:00
parent 2bf0f6fdab
commit eb713786cd
2 changed files with 15 additions and 5 deletions

View File

@ -1490,6 +1490,18 @@ bool LLParser::ParseOptionalCallingConv(unsigned &CC) {
return false;
}
/// ParseMetadataAttachment
/// ::= !dbg !42
bool LLParser::ParseMetadataAttachment(unsigned &Kind, MDNode *&MD) {
assert(Lex.getKind() == lltok::MetadataVar && "Expected metadata attachment");
std::string Name = Lex.getStrVal();
Kind = M->getMDKindID(Name);
Lex.Lex();
return ParseMDNode(MD);
}
/// ParseInstructionMetadata
/// ::= !dbg !42 (',' !dbg !57)*
bool LLParser::ParseInstructionMetadata(Instruction *Inst,
@ -1498,12 +1510,9 @@ bool LLParser::ParseInstructionMetadata(Instruction *Inst,
if (Lex.getKind() != lltok::MetadataVar)
return TokError("expected metadata after comma");
std::string Name = Lex.getStrVal();
unsigned MDK = M->getMDKindID(Name);
Lex.Lex();
unsigned MDK;
MDNode *N;
if (ParseMDNode(N))
if (ParseMetadataAttachment(MDK, N))
return true;
Inst->setMetadata(MDK, N);

View File

@ -392,6 +392,7 @@ namespace llvm {
bool ParseMDNode(MDNode *&MD);
bool ParseMDNodeTail(MDNode *&MD);
bool ParseMDNodeVector(SmallVectorImpl<Metadata *> &MDs);
bool ParseMetadataAttachment(unsigned &Kind, MDNode *&MD);
bool ParseInstructionMetadata(Instruction *Inst, PerFunctionState *PFS);
template <class FieldTy>