From: Duncan P. N. Exon Smith Date: Fri, 24 Apr 2015 21:21:57 +0000 (+0000) Subject: LLParser: Split out ParseMetadataAttachment(), NFC X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=eb713786cd8d071d79e1dfdc8b1bb6b0067bfa74;p=oota-llvm.git 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 --- diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp index 441d36cb21d..18fa6978065 100644 --- a/lib/AsmParser/LLParser.cpp +++ b/lib/AsmParser/LLParser.cpp @@ -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); diff --git a/lib/AsmParser/LLParser.h b/lib/AsmParser/LLParser.h index 117cdcba255..9db50a7b173 100644 --- a/lib/AsmParser/LLParser.h +++ b/lib/AsmParser/LLParser.h @@ -392,6 +392,7 @@ namespace llvm { bool ParseMDNode(MDNode *&MD); bool ParseMDNodeTail(MDNode *&MD); bool ParseMDNodeVector(SmallVectorImpl &MDs); + bool ParseMetadataAttachment(unsigned &Kind, MDNode *&MD); bool ParseInstructionMetadata(Instruction *Inst, PerFunctionState *PFS); template