[llvm-commits] [llvm] r76455 - in /llvm/trunk/lib/AsmParser: LLParser.cpp LLParser.h

Devang Patel dpatel at apple.com
Mon Jul 20 12:00:09 PDT 2009


Author: dpatel
Date: Mon Jul 20 14:00:08 2009
New Revision: 76455

URL: http://llvm.org/viewvc/llvm-project?rev=76455&view=rev
Log:
Refactor metadata parsing routines into separate functions.

Modified:
    llvm/trunk/lib/AsmParser/LLParser.cpp
    llvm/trunk/lib/AsmParser/LLParser.h

Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=76455&r1=76454&r2=76455&view=diff

==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLParser.cpp Mon Jul 20 14:00:08 2009
@@ -365,6 +365,47 @@
   return ParseAlias(Name, NameLoc, Visibility);
 }
 
+// MDString:
+//   ::= '!' STRINGCONSTANT
+bool LLParser::ParseMDString(Constant *&MDS) {
+  std::string Str;
+  if (ParseStringConstant(Str)) return true;
+  MDS = Context.getMDString(Str.data(), Str.data() + Str.size());
+  return false;
+}
+
+// MDNode:
+//   ::= '!' MDNodeNumber
+bool LLParser::ParseMDNode(Constant *&Node) {
+  // !{ ..., !42, ... }
+  unsigned MID = 0;
+  if (ParseUInt32(MID))  return true;
+  
+  // Check existing MDNode.
+  std::map<unsigned, Constant *>::iterator I = MetadataCache.find(MID);
+  if (I != MetadataCache.end()) {
+    Node = I->second;
+    return false;
+  }
+
+  // Check known forward references.
+  std::map<unsigned, std::pair<Constant *, LocTy> >::iterator
+    FI = ForwardRefMDNodes.find(MID);
+  if (FI != ForwardRefMDNodes.end()) {
+    Node = FI->second.first;
+    return false;
+  }
+
+  // Create MDNode forward reference
+  SmallVector<Value *, 1> Elts;
+  std::string FwdRefName = "llvm.mdnode.fwdref." + utostr(MID);
+  Elts.push_back(Context.getMDString(FwdRefName));
+  MDNode *FwdNode = Context.getMDNode(Elts.data(), Elts.size());
+  ForwardRefMDNodes[MID] = std::make_pair(FwdNode, Lex.getLoc());
+  Node = FwdNode;
+  return false;
+}    
+
 /// ParseStandaloneMetadata:
 ///   !42 = !{...} 
 bool LLParser::ParseStandaloneMetadata() {
@@ -1647,36 +1688,12 @@
 
     // Standalone metadata reference
     // !{ ..., !42, ... }
-    unsigned MID = 0;
-    if (!ParseUInt32(MID)) {
-      std::map<unsigned, Constant *>::iterator I = MetadataCache.find(MID);
-      if (I != MetadataCache.end()) 
-        ID.ConstantVal = I->second;
-      else {
-        std::map<unsigned, std::pair<Constant *, LocTy> >::iterator
-          FI = ForwardRefMDNodes.find(MID);
-        if (FI != ForwardRefMDNodes.end()) 
-          ID.ConstantVal = FI->second.first;
-        else {
-          // Create MDNode forward reference
-          SmallVector<Value *, 1> Elts;
-          std::string FwdRefName = "llvm.mdnode.fwdref." + utostr(MID);
-          Elts.push_back(Context.getMDString(FwdRefName));
-          MDNode *FwdNode = Context.getMDNode(Elts.data(), Elts.size());
-          ForwardRefMDNodes[MID] = std::make_pair(FwdNode, Lex.getLoc());
-          ID.ConstantVal = FwdNode;
-        }
-      }
-
+    if (!ParseMDNode(ID.ConstantVal))
       return false;
-    }
-    
+
     // MDString:
     //   ::= '!' STRINGCONSTANT
-    std::string Str;
-    if (ParseStringConstant(Str)) return true;
-
-    ID.ConstantVal = Context.getMDString(Str.data(), Str.data() + Str.size());
+    if (ParseMDString(ID.ConstantVal)) return true;
     return false;
   }
   case lltok::APSInt:

Modified: llvm/trunk/lib/AsmParser/LLParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.h?rev=76455&r1=76454&r2=76455&view=diff

==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.h (original)
+++ llvm/trunk/lib/AsmParser/LLParser.h Mon Jul 20 14:00:08 2009
@@ -147,6 +147,8 @@
                      bool HasLinkage, unsigned Visibility);
     bool ParseAlias(const std::string &Name, LocTy Loc, unsigned Visibility);
     bool ParseStandaloneMetadata();
+    bool ParseMDString(Constant *&S);
+    bool ParseMDNode(Constant *&N);
 
     // Type Parsing.
     bool ParseType(PATypeHolder &Result, bool AllowVoid = false);





More information about the llvm-commits mailing list