From f825dae8365881df958491145d932648b52752f2 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Mon, 12 Jan 2015 22:26:48 +0000 Subject: [PATCH] AsmParser: Factor duplicated code into ParseMDNode(), NFC llvm-svn: 225710 --- llvm/lib/AsmParser/LLParser.cpp | 49 ++++++++++++++++++----------------------- llvm/lib/AsmParser/LLParser.h | 2 ++ 2 files changed, 24 insertions(+), 27 deletions(-) diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp index d30fcca..a5ead2e 100644 --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -1490,24 +1490,11 @@ bool LLParser::ParseInstructionMetadata(Instruction *Inst, unsigned MDK = M->getMDKindID(Name); Lex.Lex(); - if (ParseToken(lltok::exclaim, "expected '!' here")) + MDNode *N; + if (ParseMDNode(N)) return true; - // This code is similar to that of ParseMetadata. However, only MDNodes - // are supported here. - if (Lex.getKind() == lltok::lbrace) { - MDNode *N; - if (ParseMDTuple(N)) - return true; - Inst->setMetadata(MDK, N); - } else { - MDNode *Node; - if (ParseMDNodeID(Node)) - return true; - // If we got the node, add it to the instruction. - Inst->setMetadata(MDK, Node); - } - + Inst->setMetadata(MDK, N); if (MDK == LLVMContext::MD_tbaa) InstsWithTBAATag.push_back(Inst); @@ -2912,6 +2899,23 @@ bool LLParser::ParseMDTuple(MDNode *&MD, bool IsDistinct) { return false; } +/// MDNode: +/// ::= !{ ... } +/// ::= !7 +bool LLParser::ParseMDNode(MDNode *&N) { + return ParseToken(lltok::exclaim, "expected '!' here") || + ParseMDNodeTail(N); +} + +bool LLParser::ParseMDNodeTail(MDNode *&N) { + // !{ ... } + if (Lex.getKind() == lltok::lbrace) + return ParseMDTuple(N); + + // !42 + return ParseMDNodeID(N); +} + /// ParseMetadataAsValue /// ::= metadata i32 %local /// ::= metadata i32 @global @@ -2978,18 +2982,9 @@ bool LLParser::ParseMetadata(Metadata *&MD, PerFunctionState *PFS) { // MDNode: // !{ ... } - if (Lex.getKind() == lltok::lbrace) { - MDNode *N; - if (ParseMDTuple(N)) - return true; - MD = N; - return false; - } - - // Standalone metadata reference - // !42 + // !7 MDNode *N; - if (ParseMDNodeID(N)) + if (ParseMDNodeTail(N)) return true; MD = N; return false; diff --git a/llvm/lib/AsmParser/LLParser.h b/llvm/lib/AsmParser/LLParser.h index eb27ca4..8607b70 100644 --- a/llvm/lib/AsmParser/LLParser.h +++ b/llvm/lib/AsmParser/LLParser.h @@ -388,6 +388,8 @@ namespace llvm { bool ParseValueAsMetadata(Metadata *&MD, PerFunctionState *PFS); bool ParseMetadata(Metadata *&MD, PerFunctionState *PFS); bool ParseMDTuple(MDNode *&MD, bool IsDistinct = false); + bool ParseMDNode(MDNode *&MD); + bool ParseMDNodeTail(MDNode *&MD); bool ParseMDNodeVector(SmallVectorImpl &MDs); bool ParseInstructionMetadata(Instruction *Inst, PerFunctionState *PFS); -- 2.7.4