Introduce poor man's consumeToken() in X86AsmParser

This makes the code a little more idiomatic.

No change in behaviour.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@196113 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Alp Toker 2013-12-02 16:06:06 +00:00
parent 15945a0b70
commit 4f9dd99c28

View File

@ -50,6 +50,12 @@ class X86AsmParser : public MCTargetAsmParser {
MCAsmParser &Parser; MCAsmParser &Parser;
ParseInstructionInfo *InstInfo; ParseInstructionInfo *InstInfo;
private: private:
SMLoc consumeToken() {
SMLoc Result = Parser.getTok().getLoc();
Parser.Lex();
return Result;
}
enum InfixCalculatorTok { enum InfixCalculatorTok {
IC_PLUS = 0, IC_PLUS = 0,
IC_MINUS, IC_MINUS,
@ -1341,10 +1347,8 @@ bool X86AsmParser::ParseIntelExpression(IntelExprStateMachine &SM, SMLoc &End) {
if (SM.hadError()) if (SM.hadError())
return Error(Tok.getLoc(), "unknown token in expression"); return Error(Tok.getLoc(), "unknown token in expression");
if (!Done && UpdateLocLex) { if (!Done && UpdateLocLex)
End = Tok.getLoc(); End = consumeToken();
Parser.Lex(); // Consume the token.
}
} }
return false; return false;
} }
@ -1991,11 +1995,8 @@ ParseInstruction(ParseInstructionInfo &Info, StringRef Name, SMLoc NameLoc,
if (getLexer().isNot(AsmToken::EndOfStatement) && !isPrefix) { if (getLexer().isNot(AsmToken::EndOfStatement) && !isPrefix) {
// Parse '*' modifier. // Parse '*' modifier.
if (getLexer().is(AsmToken::Star)) { if (getLexer().is(AsmToken::Star))
SMLoc Loc = Parser.getTok().getLoc(); Operands.push_back(X86Operand::CreateToken("*", consumeToken()));
Operands.push_back(X86Operand::CreateToken("*", Loc));
Parser.Lex(); // Eat the star.
}
// Read the first operand. // Read the first operand.
if (X86Operand *Op = ParseOperand()) if (X86Operand *Op = ParseOperand())
@ -2020,9 +2021,7 @@ ParseInstruction(ParseInstructionInfo &Info, StringRef Name, SMLoc NameLoc,
if (STI.getFeatureBits() & X86::FeatureAVX512) { if (STI.getFeatureBits() & X86::FeatureAVX512) {
// Parse mask register {%k1} // Parse mask register {%k1}
if (getLexer().is(AsmToken::LCurly)) { if (getLexer().is(AsmToken::LCurly)) {
SMLoc Loc = Parser.getTok().getLoc(); Operands.push_back(X86Operand::CreateToken("{", consumeToken()));
Operands.push_back(X86Operand::CreateToken("{", Loc));
Parser.Lex(); // Eat the {
if (X86Operand *Op = ParseOperand()) { if (X86Operand *Op = ParseOperand()) {
Operands.push_back(Op); Operands.push_back(Op);
if (!getLexer().is(AsmToken::RCurly)) { if (!getLexer().is(AsmToken::RCurly)) {
@ -2030,9 +2029,7 @@ ParseInstruction(ParseInstructionInfo &Info, StringRef Name, SMLoc NameLoc,
Parser.eatToEndOfStatement(); Parser.eatToEndOfStatement();
return Error(Loc, "Expected } at this point"); return Error(Loc, "Expected } at this point");
} }
Loc = Parser.getTok().getLoc(); Operands.push_back(X86Operand::CreateToken("}", consumeToken()));
Operands.push_back(X86Operand::CreateToken("}", Loc));
Parser.Lex(); // Eat the }
} else { } else {
Parser.eatToEndOfStatement(); Parser.eatToEndOfStatement();
return true; return true;
@ -2040,9 +2037,7 @@ ParseInstruction(ParseInstructionInfo &Info, StringRef Name, SMLoc NameLoc,
} }
// Parse "zeroing non-masked" semantic {z} // Parse "zeroing non-masked" semantic {z}
if (getLexer().is(AsmToken::LCurly)) { if (getLexer().is(AsmToken::LCurly)) {
SMLoc Loc = Parser.getTok().getLoc(); Operands.push_back(X86Operand::CreateToken("{z}", consumeToken()));
Operands.push_back(X86Operand::CreateToken("{z}", Loc));
Parser.Lex(); // Eat the {
if (!getLexer().is(AsmToken::Identifier) || getLexer().getTok().getIdentifier() != "z") { if (!getLexer().is(AsmToken::Identifier) || getLexer().getTok().getIdentifier() != "z") {
SMLoc Loc = getLexer().getLoc(); SMLoc Loc = getLexer().getLoc();
Parser.eatToEndOfStatement(); Parser.eatToEndOfStatement();