From a86be2223013a810ac8653ffa3214efa84245c74 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 31 Jan 2017 23:26:32 +0000 Subject: [PATCH] Move more code to helper functions. NFC. llvm-svn: 293715 --- llvm/lib/MC/MCParser/ELFAsmParser.cpp | 99 ++++++++++++++++----------- 1 file changed, 60 insertions(+), 39 deletions(-) diff --git a/llvm/lib/MC/MCParser/ELFAsmParser.cpp b/llvm/lib/MC/MCParser/ELFAsmParser.cpp index 40b589eef377..c7b53ec19d8b 100644 --- a/llvm/lib/MC/MCParser/ELFAsmParser.cpp +++ b/llvm/lib/MC/MCParser/ELFAsmParser.cpp @@ -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)) + if (Group) + if (parseGroup(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)) - 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: