forked from OSchip/llvm-project
[MC,X86] Cleanup some X86 parser functions to use MCParser helpers. NFCI.
llvm-svn: 328019
This commit is contained in:
parent
847accd001
commit
ce71989188
|
@ -2109,12 +2109,8 @@ std::unique_ptr<X86Operand> X86AsmParser::ParseMemOperand(unsigned SegReg,
|
|||
if (getLexer().isNot(AsmToken::RParen)) {
|
||||
// Parse the scale amount:
|
||||
// ::= ',' [scale-expression]
|
||||
if (getLexer().isNot(AsmToken::Comma)) {
|
||||
Error(Parser.getTok().getLoc(),
|
||||
"expected comma in scale expression");
|
||||
if (parseToken(AsmToken::Comma, "expected comma in scale expression"))
|
||||
return nullptr;
|
||||
}
|
||||
Parser.Lex(); // Eat the comma.
|
||||
|
||||
if (getLexer().isNot(AsmToken::RParen)) {
|
||||
SMLoc Loc = Parser.getTok().getLoc();
|
||||
|
@ -2155,12 +2151,9 @@ std::unique_ptr<X86Operand> X86AsmParser::ParseMemOperand(unsigned SegReg,
|
|||
}
|
||||
|
||||
// Ok, we've eaten the memory operand, verify we have a ')' and eat it too.
|
||||
if (getLexer().isNot(AsmToken::RParen)) {
|
||||
Error(Parser.getTok().getLoc(), "unexpected token in memory operand");
|
||||
return nullptr;
|
||||
}
|
||||
SMLoc MemEnd = Parser.getTok().getEndLoc();
|
||||
Parser.Lex(); // Eat the ')'.
|
||||
if (parseToken(AsmToken::RParen, "unexpected token in memory operand"))
|
||||
return nullptr;
|
||||
|
||||
// Check for use of invalid 16-bit registers. Only BX/BP/SI/DI are allowed,
|
||||
// and then only in non-64-bit modes. Except for DX, which is a special case
|
||||
|
@ -3198,10 +3191,9 @@ bool X86AsmParser::ParseDirective(AsmToken DirectiveID) {
|
|||
/// parseDirectiveEven
|
||||
/// ::= .even
|
||||
bool X86AsmParser::parseDirectiveEven(SMLoc L) {
|
||||
if (getLexer().isNot(AsmToken::EndOfStatement)) {
|
||||
TokError("unexpected token in directive");
|
||||
return false;
|
||||
}
|
||||
if (parseToken(AsmToken::EndOfStatement, "unexpected token in directive"))
|
||||
return false;
|
||||
|
||||
const MCSection *Section = getStreamer().getCurrentSectionOnly();
|
||||
if (!Section) {
|
||||
getStreamer().InitSections(false);
|
||||
|
@ -3216,37 +3208,22 @@ bool X86AsmParser::parseDirectiveEven(SMLoc L) {
|
|||
/// ParseDirectiveWord
|
||||
/// ::= .word [ expression (, expression)* ]
|
||||
bool X86AsmParser::ParseDirectiveWord(unsigned Size, SMLoc L) {
|
||||
MCAsmParser &Parser = getParser();
|
||||
if (getLexer().isNot(AsmToken::EndOfStatement)) {
|
||||
for (;;) {
|
||||
const MCExpr *Value;
|
||||
SMLoc ExprLoc = getLexer().getLoc();
|
||||
if (getParser().parseExpression(Value))
|
||||
return false;
|
||||
|
||||
if (const auto *MCE = dyn_cast<MCConstantExpr>(Value)) {
|
||||
assert(Size <= 8 && "Invalid size");
|
||||
uint64_t IntValue = MCE->getValue();
|
||||
if (!isUIntN(8 * Size, IntValue) && !isIntN(8 * Size, IntValue))
|
||||
return Error(ExprLoc, "literal value out of range for directive");
|
||||
getStreamer().EmitIntValue(IntValue, Size);
|
||||
} else {
|
||||
getStreamer().EmitValue(Value, Size, ExprLoc);
|
||||
}
|
||||
|
||||
if (getLexer().is(AsmToken::EndOfStatement))
|
||||
break;
|
||||
|
||||
// FIXME: Improve diagnostic.
|
||||
if (getLexer().isNot(AsmToken::Comma)) {
|
||||
Error(L, "unexpected token in directive");
|
||||
return false;
|
||||
}
|
||||
Parser.Lex();
|
||||
}
|
||||
}
|
||||
|
||||
Parser.Lex();
|
||||
auto parseOp = [&]() -> bool {
|
||||
const MCExpr *Value;
|
||||
SMLoc ExprLoc = getLexer().getLoc();
|
||||
if (getParser().parseExpression(Value))
|
||||
return true;
|
||||
if (const auto *MCE = dyn_cast<MCConstantExpr>(Value)) {
|
||||
assert(Size <= 8 && "Invalid size");
|
||||
uint64_t IntValue = MCE->getValue();
|
||||
if (!isUIntN(8 * Size, IntValue) && !isIntN(8 * Size, IntValue))
|
||||
return Error(ExprLoc, "literal value out of range for directive");
|
||||
getStreamer().EmitIntValue(IntValue, Size);
|
||||
} else
|
||||
getStreamer().EmitValue(Value, Size, ExprLoc);
|
||||
return false;
|
||||
};
|
||||
parseMany(parseOp);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue