mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-04 17:58:22 +00:00
Switch X86 assembly parser to using the generic lexer interface.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77341 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
5743854f47
commit
8e7c38e17b
@ -81,17 +81,17 @@ struct AsmParser::X86Operand {
|
||||
};
|
||||
|
||||
bool AsmParser::ParseX86Register(X86Operand &Op) {
|
||||
assert(Lexer.getKind() == AsmToken::Register && "Invalid token kind!");
|
||||
assert(getLexer().is(AsmToken::Register) && "Invalid token kind!");
|
||||
|
||||
// FIXME: Decode register number.
|
||||
Op = X86Operand::CreateReg(123);
|
||||
Lexer.Lex(); // Eat register token.
|
||||
getLexer().Lex(); // Eat register token.
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AsmParser::ParseX86Operand(X86Operand &Op) {
|
||||
switch (Lexer.getKind()) {
|
||||
switch (getLexer().getKind()) {
|
||||
default:
|
||||
return ParseX86MemOperand(Op);
|
||||
case AsmToken::Register:
|
||||
@ -100,7 +100,7 @@ bool AsmParser::ParseX86Operand(X86Operand &Op) {
|
||||
return ParseX86Register(Op);
|
||||
case AsmToken::Dollar: {
|
||||
// $42 -> immediate.
|
||||
Lexer.Lex();
|
||||
getLexer().Lex();
|
||||
MCValue Val;
|
||||
if (ParseRelocatableExpression(Val))
|
||||
return true;
|
||||
@ -108,9 +108,9 @@ bool AsmParser::ParseX86Operand(X86Operand &Op) {
|
||||
return false;
|
||||
}
|
||||
case AsmToken::Star: {
|
||||
Lexer.Lex(); // Eat the star.
|
||||
getLexer().Lex(); // Eat the star.
|
||||
|
||||
if (Lexer.is(AsmToken::Register)) {
|
||||
if (getLexer().is(AsmToken::Register)) {
|
||||
if (ParseX86Register(Op))
|
||||
return true;
|
||||
} else if (ParseX86MemOperand(Op))
|
||||
@ -132,24 +132,24 @@ bool AsmParser::ParseX86MemOperand(X86Operand &Op) {
|
||||
// only way to do this without lookahead is to eat the ( and see what is after
|
||||
// it.
|
||||
MCValue Disp = MCValue::get(0, 0, 0);
|
||||
if (Lexer.isNot(AsmToken::LParen)) {
|
||||
if (getLexer().isNot(AsmToken::LParen)) {
|
||||
if (ParseRelocatableExpression(Disp)) return true;
|
||||
|
||||
// After parsing the base expression we could either have a parenthesized
|
||||
// memory address or not. If not, return now. If so, eat the (.
|
||||
if (Lexer.isNot(AsmToken::LParen)) {
|
||||
if (getLexer().isNot(AsmToken::LParen)) {
|
||||
Op = X86Operand::CreateMem(SegReg, Disp, 0, 0, 0);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Eat the '('.
|
||||
Lexer.Lex();
|
||||
getLexer().Lex();
|
||||
} else {
|
||||
// Okay, we have a '('. We don't know if this is an expression or not, but
|
||||
// so we have to eat the ( to see beyond it.
|
||||
Lexer.Lex(); // Eat the '('.
|
||||
getLexer().Lex(); // Eat the '('.
|
||||
|
||||
if (Lexer.is(AsmToken::Register) || Lexer.is(AsmToken::Comma)) {
|
||||
if (getLexer().is(AsmToken::Register) || getLexer().is(AsmToken::Comma)) {
|
||||
// Nothing to do here, fall into the code below with the '(' part of the
|
||||
// memory operand consumed.
|
||||
} else {
|
||||
@ -159,13 +159,13 @@ bool AsmParser::ParseX86MemOperand(X86Operand &Op) {
|
||||
|
||||
// After parsing the base expression we could either have a parenthesized
|
||||
// memory address or not. If not, return now. If so, eat the (.
|
||||
if (Lexer.isNot(AsmToken::LParen)) {
|
||||
if (getLexer().isNot(AsmToken::LParen)) {
|
||||
Op = X86Operand::CreateMem(SegReg, Disp, 0, 0, 0);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Eat the '('.
|
||||
Lexer.Lex();
|
||||
getLexer().Lex();
|
||||
}
|
||||
}
|
||||
|
||||
@ -173,14 +173,14 @@ bool AsmParser::ParseX86MemOperand(X86Operand &Op) {
|
||||
// the rest of the memory operand.
|
||||
unsigned BaseReg = 0, IndexReg = 0, Scale = 0;
|
||||
|
||||
if (Lexer.is(AsmToken::Register)) {
|
||||
if (getLexer().is(AsmToken::Register)) {
|
||||
if (ParseX86Register(Op))
|
||||
return true;
|
||||
BaseReg = Op.getReg();
|
||||
}
|
||||
|
||||
if (Lexer.is(AsmToken::Comma)) {
|
||||
Lexer.Lex(); // Eat the comma.
|
||||
if (getLexer().is(AsmToken::Comma)) {
|
||||
getLexer().Lex(); // Eat the comma.
|
||||
|
||||
// Following the comma we should have either an index register, or a scale
|
||||
// value. We don't support the later form, but we want to parse it
|
||||
@ -188,20 +188,20 @@ bool AsmParser::ParseX86MemOperand(X86Operand &Op) {
|
||||
//
|
||||
// Not that even though it would be completely consistent to support syntax
|
||||
// like "1(%eax,,1)", the assembler doesn't.
|
||||
if (Lexer.is(AsmToken::Register)) {
|
||||
if (getLexer().is(AsmToken::Register)) {
|
||||
if (ParseX86Register(Op))
|
||||
return true;
|
||||
IndexReg = Op.getReg();
|
||||
Scale = 1; // If not specified, the scale defaults to 1.
|
||||
|
||||
if (Lexer.isNot(AsmToken::RParen)) {
|
||||
if (getLexer().isNot(AsmToken::RParen)) {
|
||||
// Parse the scale amount:
|
||||
// ::= ',' [scale-expression]
|
||||
if (Lexer.isNot(AsmToken::Comma))
|
||||
if (getLexer().isNot(AsmToken::Comma))
|
||||
return true;
|
||||
Lexer.Lex(); // Eat the comma.
|
||||
getLexer().Lex(); // Eat the comma.
|
||||
|
||||
if (Lexer.isNot(AsmToken::RParen)) {
|
||||
if (getLexer().isNot(AsmToken::RParen)) {
|
||||
int64_t ScaleVal;
|
||||
if (ParseAbsoluteExpression(ScaleVal))
|
||||
return true;
|
||||
@ -212,10 +212,10 @@ bool AsmParser::ParseX86MemOperand(X86Operand &Op) {
|
||||
Scale = (unsigned)ScaleVal;
|
||||
}
|
||||
}
|
||||
} else if (Lexer.isNot(AsmToken::RParen)) {
|
||||
} else if (getLexer().isNot(AsmToken::RParen)) {
|
||||
// Otherwise we have the unsupported form of a scale amount without an
|
||||
// index.
|
||||
SMLoc Loc = Lexer.getLoc();
|
||||
SMLoc Loc = getLexer().getTok().getLoc();
|
||||
|
||||
int64_t Value;
|
||||
if (ParseAbsoluteExpression(Value))
|
||||
@ -226,9 +226,9 @@ bool AsmParser::ParseX86MemOperand(X86Operand &Op) {
|
||||
}
|
||||
|
||||
// Ok, we've eaten the memory operand, verify we have a ')' and eat it too.
|
||||
if (Lexer.isNot(AsmToken::RParen))
|
||||
if (getLexer().isNot(AsmToken::RParen))
|
||||
return TokError("unexpected token in memory operand");
|
||||
Lexer.Lex(); // Eat the ')'.
|
||||
getLexer().Lex(); // Eat the ')'.
|
||||
|
||||
Op = X86Operand::CreateMem(SegReg, Disp, BaseReg, IndexReg, Scale);
|
||||
return false;
|
||||
@ -247,14 +247,14 @@ static bool MatchX86Inst(const StringRef &Name,
|
||||
bool AsmParser::ParseX86InstOperands(const StringRef &InstName, MCInst &Inst) {
|
||||
llvm::SmallVector<X86Operand, 3> Operands;
|
||||
|
||||
if (Lexer.isNot(AsmToken::EndOfStatement)) {
|
||||
if (getLexer().isNot(AsmToken::EndOfStatement)) {
|
||||
// Read the first operand.
|
||||
Operands.push_back(X86Operand());
|
||||
if (ParseX86Operand(Operands.back()))
|
||||
return true;
|
||||
|
||||
while (Lexer.is(AsmToken::Comma)) {
|
||||
Lexer.Lex(); // Eat the comma.
|
||||
while (getLexer().is(AsmToken::Comma)) {
|
||||
getLexer().Lex(); // Eat the comma.
|
||||
|
||||
// Parse and remember the operand.
|
||||
Operands.push_back(X86Operand());
|
||||
|
Loading…
Reference in New Issue
Block a user