diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2017-01-31 23:07:08 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2017-01-31 23:07:08 +0000 |
commit | d9953d9dd289b87c17ed6b60d14f2db62b1f9dc4 (patch) | |
tree | b8252ed344f5d949d7d11bc8d00a32e422a79934 /llvm/lib/MC/MCParser/ELFAsmParser.cpp | |
parent | 8789a5a9f6bfae34dbb31d80ef7ed4dfb6fb5c13 (diff) | |
download | bcm5719-llvm-d9953d9dd289b87c17ed6b60d14f2db62b1f9dc4.tar.gz bcm5719-llvm-d9953d9dd289b87c17ed6b60d14f2db62b1f9dc4.zip |
Move some code to a helper function. NFC.
llvm-svn: 293712
Diffstat (limited to 'llvm/lib/MC/MCParser/ELFAsmParser.cpp')
-rw-r--r-- | llvm/lib/MC/MCParser/ELFAsmParser.cpp | 107 |
1 files changed, 59 insertions, 48 deletions
diff --git a/llvm/lib/MC/MCParser/ELFAsmParser.cpp b/llvm/lib/MC/MCParser/ELFAsmParser.cpp index 8d7ba0d0336..40b589eef37 100644 --- a/llvm/lib/MC/MCParser/ELFAsmParser.cpp +++ b/llvm/lib/MC/MCParser/ELFAsmParser.cpp @@ -142,6 +142,7 @@ private: bool ParseSectionName(StringRef &SectionName); bool ParseSectionArguments(bool IsPush, SMLoc loc); unsigned parseSunStyleSectionFlags(); + bool maybeParseSectionType(StringRef &TypeName); }; } @@ -366,6 +367,21 @@ bool ELFAsmParser::ParseDirectiveSection(StringRef, SMLoc loc) { return ParseSectionArguments(/*IsPush=*/false, loc); } +bool ELFAsmParser::maybeParseSectionType(StringRef &TypeName) { + MCAsmLexer &L = getLexer(); + if (L.isNot(AsmToken::Comma)) + return false; + Lex(); + if (L.isNot(AsmToken::At) && L.isNot(AsmToken::Percent) && + L.isNot(AsmToken::String)) + return TokError("expected '@<type>', '%<type>' or \"<type>\""); + if (!L.is(AsmToken::String)) + Lex(); + if (getParser().parseIdentifier(TypeName)) + return TokError("expected identifier in directive"); + return false; +} + bool ELFAsmParser::ParseSectionArguments(bool IsPush, SMLoc loc) { StringRef SectionName; @@ -422,65 +438,60 @@ bool ELFAsmParser::ParseSectionArguments(bool IsPush, SMLoc loc) { return TokError("Section cannot specifiy a group name while also acting " "as a member of the last group"); - if (getLexer().isNot(AsmToken::Comma)) { + if (maybeParseSectionType(TypeName)) + return true; + + MCAsmLexer &L = getLexer(); + if (TypeName.empty()) { if (Mergeable) return TokError("Mergeable section must specify the type"); if (Group) return TokError("Group section must specify the type"); - } else { - Lex(); - if (getLexer().is(AsmToken::At) || getLexer().is(AsmToken::Percent) || - getLexer().is(AsmToken::String)) { - if (!getLexer().is(AsmToken::String)) - Lex(); - } else - return TokError("expected '@<type>', '%<type>' or \"<type>\""); - - if (getParser().parseIdentifier(TypeName)) - return TokError("expected identifier in directive"); + if (L.isNot(AsmToken::EndOfStatement)) + return TokError("unexpected token in directive"); + } - if (Mergeable) { - 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"); - } + if (Mergeable) { + 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"); + } - 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 (Group) { + if (getLexer().isNot(AsmToken::Comma)) + return TokError("expected group name"); + Lex(); + if (getParser().parseIdentifier(GroupName)) + return true; 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)) + StringRef Linkage; + if (getParser().parseIdentifier(Linkage)) 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 (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"); + } } EndStmt: |