[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

llvm-svn: 275795
This commit is contained in:
Nirav Dave 2016-07-18 15:24:03 +00:00
parent 393b37937b
commit a645433c5f
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) {
OS << ", " << '"' << *it << '"';
}
OS << "\n";
EmitEOL();
}
void MCAsmStreamer::EmitDataRegion(MCDataRegionType Kind) {
@ -614,7 +614,7 @@ void MCAsmStreamer::emitELFSize(MCSymbolELF *Symbol, const MCExpr *Value) {
Symbol->print(OS, MAI);
OS << ", ";
Value->print(OS, MAI);
OS << '\n';
EmitEOL();
}
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);
Lex();
if (getLexer().is(AsmToken::EndOfStatement))
break;

View File

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

View File

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