[MC] Cleanup Error Handling in AsmParser

Add parseToken and compatriot functions to stitch error checks in
straight linear code. As part of this fix some erronous handling of
directives where the EndOfStatement token either was not checked or
Lexed on termination.

Reviewers: rnk, majnemer

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D22312

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275795 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Nirav Dave 2016-07-18 15:24:03 +00:00
parent 56af121d06
commit 5646cdbe39
5 changed files with 343 additions and 429 deletions

View File

@ -428,7 +428,7 @@ void MCAsmStreamer::EmitLinkerOptions(ArrayRef<std::string> Options) {
ie = Options.end(); it != ie; ++it) { ie = Options.end(); it != ie; ++it) {
OS << ", " << '"' << *it << '"'; OS << ", " << '"' << *it << '"';
} }
OS << "\n"; EmitEOL();
} }
void MCAsmStreamer::EmitDataRegion(MCDataRegionType Kind) { void MCAsmStreamer::EmitDataRegion(MCDataRegionType Kind) {
@ -614,7 +614,7 @@ void MCAsmStreamer::emitELFSize(MCSymbolELF *Symbol, const MCExpr *Value) {
Symbol->print(OS, MAI); Symbol->print(OS, MAI);
OS << ", "; OS << ", ";
Value->print(OS, MAI); Value->print(OS, MAI);
OS << '\n'; EmitEOL();
} }
void MCAsmStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, void MCAsmStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,

File diff suppressed because it is too large Load Diff

View File

@ -537,7 +537,6 @@ bool DarwinAsmParser::parseDirectiveLinkerOption(StringRef IDVal, SMLoc) {
Args.push_back(Data); Args.push_back(Data);
Lex();
if (getLexer().is(AsmToken::EndOfStatement)) if (getLexer().is(AsmToken::EndOfStatement))
break; break;

View File

@ -212,6 +212,7 @@ bool ELFAsmParser::ParseDirectiveSize(StringRef, SMLoc) {
if (getLexer().isNot(AsmToken::EndOfStatement)) if (getLexer().isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in directive"); return TokError("unexpected token in directive");
Lex();
getStreamer().emitELFSize(Sym, Expr); getStreamer().emitELFSize(Sym, Expr);
return false; return false;
@ -478,6 +479,7 @@ bool ELFAsmParser::ParseSectionArguments(bool IsPush, SMLoc loc) {
EndStmt: EndStmt:
if (getLexer().isNot(AsmToken::EndOfStatement)) if (getLexer().isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in directive"); return TokError("unexpected token in directive");
Lex();
unsigned Type = ELF::SHT_PROGBITS; unsigned Type = ELF::SHT_PROGBITS;
@ -629,6 +631,10 @@ bool ELFAsmParser::ParseDirectiveIdent(StringRef, SMLoc) {
Lex(); Lex();
if (getLexer().isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in '.ident' directive");
Lex();
getStreamer().EmitIdent(Data); getStreamer().EmitIdent(Data);
return false; return false;
} }
@ -727,6 +733,8 @@ bool ELFAsmParser::ParseDirectiveSubsection(StringRef, SMLoc) {
if (getLexer().isNot(AsmToken::EndOfStatement)) if (getLexer().isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in directive"); return TokError("unexpected token in directive");
Lex();
getStreamer().SubSection(Subsection); getStreamer().SubSection(Subsection);
return false; return false;
} }

View File

@ -9,3 +9,5 @@ foo: #Comment here
## WHOLE LINE COMMENT ## WHOLE LINE COMMENT
cmpl $196, %eax ## EOL COMMENT cmpl $196, %eax ## EOL COMMENT
#endif #endif
.ident "clang version 3.9.0"
.section ".note.GNU-stack","",@progbits