]> granicus.if.org Git - llvm/commitdiff
Move more code to helper functions. NFC.
authorRafael Espindola <rafael.espindola@gmail.com>
Tue, 31 Jan 2017 23:26:32 +0000 (23:26 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Tue, 31 Jan 2017 23:26:32 +0000 (23:26 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293715 91177308-0d34-0410-b5e6-96231b3b80d8

lib/MC/MCParser/ELFAsmParser.cpp

index 40b589eef377b67d5a4d8b95a11a19001db1f689..c7b53ec19d8b58aaba5a11803d171713508599cf 100644 (file)
@@ -143,6 +143,9 @@ private:
   bool ParseSectionArguments(bool IsPush, SMLoc loc);
   unsigned parseSunStyleSectionFlags();
   bool maybeParseSectionType(StringRef &TypeName);
+  bool parseMergeSize(int64_t &Size);
+  bool parseGroup(StringRef &GroupName);
+  bool maybeParseUniqueID(int64_t &UniqueID);
 };
 
 }
@@ -382,6 +385,57 @@ bool ELFAsmParser::maybeParseSectionType(StringRef &TypeName) {
   return false;
 }
 
+bool ELFAsmParser::parseMergeSize(int64_t &Size) {
+  if (getLexer().isNot(AsmToken::Comma))
+    return TokError("expected the entry size");
+  Lex();
+  if (getParser().parseAbsoluteExpression(Size))
+    return true;
+  if (Size <= 0)
+    return TokError("entry size must be positive");
+  return false;
+}
+
+bool ELFAsmParser::parseGroup(StringRef &GroupName) {
+  MCAsmLexer &L = getLexer();
+  if (L.isNot(AsmToken::Comma))
+    return TokError("expected group name");
+  Lex();
+  if (getParser().parseIdentifier(GroupName))
+    return true;
+  if (L.is(AsmToken::Comma)) {
+    Lex();
+    StringRef Linkage;
+    if (getParser().parseIdentifier(Linkage))
+      return true;
+    if (Linkage != "comdat")
+      return TokError("Linkage must be 'comdat'");
+  }
+  return false;
+}
+
+bool ELFAsmParser::maybeParseUniqueID(int64_t &UniqueID) {
+  MCAsmLexer &L = getLexer();
+  if (L.isNot(AsmToken::Comma))
+    return false;
+  Lex();
+  StringRef UniqueStr;
+  if (getParser().parseIdentifier(UniqueStr))
+    return TokError("expected identifier in directive");
+  if (UniqueStr != "unique")
+    return TokError("expected 'unique'");
+  if (L.isNot(AsmToken::Comma))
+    return TokError("expected commma");
+  Lex();
+  if (getParser().parseAbsoluteExpression(UniqueID))
+    return true;
+  if (UniqueID < 0)
+    return TokError("unique id must be positive");
+  if (!isUInt<32>(UniqueID) || UniqueID == ~0U)
+    return TokError("unique id is too large");
+  return false;
+}
+
 bool ELFAsmParser::ParseSectionArguments(bool IsPush, SMLoc loc) {
   StringRef SectionName;
 
@@ -451,47 +505,14 @@ bool ELFAsmParser::ParseSectionArguments(bool IsPush, SMLoc loc) {
         return TokError("unexpected token in directive");
     }
 
-    if (Mergeable) {
-      if (getLexer().isNot(AsmToken::Comma))
-        return TokError("expected the entry size");
-      Lex();
-      if (getParser().parseAbsoluteExpression(Size))
+    if (Mergeable)
+      if (parseMergeSize(Size))
         return true;
-      if (Size <= 0)
-        return TokError("entry size must be positive");
-    }
-
-    if (Group) {
-      if (getLexer().isNot(AsmToken::Comma))
-        return TokError("expected group name");
-      Lex();
-      if (getParser().parseIdentifier(GroupName))
-        return true;
-      if (getLexer().is(AsmToken::Comma)) {
-        Lex();
-        StringRef Linkage;
-        if (getParser().parseIdentifier(Linkage))
-          return true;
-        if (Linkage != "comdat")
-          return TokError("Linkage must be 'comdat'");
-      }
-    }
-    if (getLexer().is(AsmToken::Comma)) {
-      Lex();
-      if (getParser().parseIdentifier(UniqueStr))
-        return TokError("expected identifier in directive");
-      if (UniqueStr != "unique")
-        return TokError("expected 'unique'");
-      if (getLexer().isNot(AsmToken::Comma))
-        return TokError("expected commma");
-      Lex();
-      if (getParser().parseAbsoluteExpression(UniqueID))
+    if (Group)
+      if (parseGroup(GroupName))
         return true;
-      if (UniqueID < 0)
-        return TokError("unique id must be positive");
-      if (!isUInt<32>(UniqueID) || UniqueID == ~0U)
-        return TokError("unique id is too large");
-    }
+    if (maybeParseUniqueID(UniqueID))
+      return true;
   }
 
 EndStmt: