AsmParser: Factor duplicated code into ParseMDNode(), NFC
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Mon, 12 Jan 2015 22:26:48 +0000 (22:26 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Mon, 12 Jan 2015 22:26:48 +0000 (22:26 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225710 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AsmParser/LLParser.cpp
lib/AsmParser/LLParser.h

index d30fccaef86723f9c5c542cd8309b7b393f1fb64..a5ead2ee53d346c086b07f0737471bc8c6403b7b 100644 (file)
@@ -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;
index eb27ca4e719d73a168719a761d01102a6c2a19a9..8607b70f312399650aad5df8ccb1d136fa98a2c0 100644 (file)
@@ -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<Metadata *> &MDs);
     bool ParseInstructionMetadata(Instruction *Inst, PerFunctionState *PFS);