mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-09 11:25:55 +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:
@@ -81,17 +81,17 @@ struct AsmParser::X86Operand {
|
|||||||
};
|
};
|
||||||
|
|
||||||
bool AsmParser::ParseX86Register(X86Operand &Op) {
|
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.
|
// FIXME: Decode register number.
|
||||||
Op = X86Operand::CreateReg(123);
|
Op = X86Operand::CreateReg(123);
|
||||||
Lexer.Lex(); // Eat register token.
|
getLexer().Lex(); // Eat register token.
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AsmParser::ParseX86Operand(X86Operand &Op) {
|
bool AsmParser::ParseX86Operand(X86Operand &Op) {
|
||||||
switch (Lexer.getKind()) {
|
switch (getLexer().getKind()) {
|
||||||
default:
|
default:
|
||||||
return ParseX86MemOperand(Op);
|
return ParseX86MemOperand(Op);
|
||||||
case AsmToken::Register:
|
case AsmToken::Register:
|
||||||
@@ -100,7 +100,7 @@ bool AsmParser::ParseX86Operand(X86Operand &Op) {
|
|||||||
return ParseX86Register(Op);
|
return ParseX86Register(Op);
|
||||||
case AsmToken::Dollar: {
|
case AsmToken::Dollar: {
|
||||||
// $42 -> immediate.
|
// $42 -> immediate.
|
||||||
Lexer.Lex();
|
getLexer().Lex();
|
||||||
MCValue Val;
|
MCValue Val;
|
||||||
if (ParseRelocatableExpression(Val))
|
if (ParseRelocatableExpression(Val))
|
||||||
return true;
|
return true;
|
||||||
@@ -108,9 +108,9 @@ bool AsmParser::ParseX86Operand(X86Operand &Op) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
case AsmToken::Star: {
|
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))
|
if (ParseX86Register(Op))
|
||||||
return true;
|
return true;
|
||||||
} else if (ParseX86MemOperand(Op))
|
} 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
|
// only way to do this without lookahead is to eat the ( and see what is after
|
||||||
// it.
|
// it.
|
||||||
MCValue Disp = MCValue::get(0, 0, 0);
|
MCValue Disp = MCValue::get(0, 0, 0);
|
||||||
if (Lexer.isNot(AsmToken::LParen)) {
|
if (getLexer().isNot(AsmToken::LParen)) {
|
||||||
if (ParseRelocatableExpression(Disp)) return true;
|
if (ParseRelocatableExpression(Disp)) return true;
|
||||||
|
|
||||||
// After parsing the base expression we could either have a parenthesized
|
// After parsing the base expression we could either have a parenthesized
|
||||||
// memory address or not. If not, return now. If so, eat the (.
|
// 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);
|
Op = X86Operand::CreateMem(SegReg, Disp, 0, 0, 0);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Eat the '('.
|
// Eat the '('.
|
||||||
Lexer.Lex();
|
getLexer().Lex();
|
||||||
} else {
|
} else {
|
||||||
// Okay, we have a '('. We don't know if this is an expression or not, but
|
// 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.
|
// 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
|
// Nothing to do here, fall into the code below with the '(' part of the
|
||||||
// memory operand consumed.
|
// memory operand consumed.
|
||||||
} else {
|
} else {
|
||||||
@@ -159,13 +159,13 @@ bool AsmParser::ParseX86MemOperand(X86Operand &Op) {
|
|||||||
|
|
||||||
// After parsing the base expression we could either have a parenthesized
|
// After parsing the base expression we could either have a parenthesized
|
||||||
// memory address or not. If not, return now. If so, eat the (.
|
// 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);
|
Op = X86Operand::CreateMem(SegReg, Disp, 0, 0, 0);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Eat the '('.
|
// Eat the '('.
|
||||||
Lexer.Lex();
|
getLexer().Lex();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,14 +173,14 @@ bool AsmParser::ParseX86MemOperand(X86Operand &Op) {
|
|||||||
// the rest of the memory operand.
|
// the rest of the memory operand.
|
||||||
unsigned BaseReg = 0, IndexReg = 0, Scale = 0;
|
unsigned BaseReg = 0, IndexReg = 0, Scale = 0;
|
||||||
|
|
||||||
if (Lexer.is(AsmToken::Register)) {
|
if (getLexer().is(AsmToken::Register)) {
|
||||||
if (ParseX86Register(Op))
|
if (ParseX86Register(Op))
|
||||||
return true;
|
return true;
|
||||||
BaseReg = Op.getReg();
|
BaseReg = Op.getReg();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Lexer.is(AsmToken::Comma)) {
|
if (getLexer().is(AsmToken::Comma)) {
|
||||||
Lexer.Lex(); // Eat the comma.
|
getLexer().Lex(); // Eat the comma.
|
||||||
|
|
||||||
// Following the comma we should have either an index register, or a scale
|
// 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
|
// 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
|
// Not that even though it would be completely consistent to support syntax
|
||||||
// like "1(%eax,,1)", the assembler doesn't.
|
// like "1(%eax,,1)", the assembler doesn't.
|
||||||
if (Lexer.is(AsmToken::Register)) {
|
if (getLexer().is(AsmToken::Register)) {
|
||||||
if (ParseX86Register(Op))
|
if (ParseX86Register(Op))
|
||||||
return true;
|
return true;
|
||||||
IndexReg = Op.getReg();
|
IndexReg = Op.getReg();
|
||||||
Scale = 1; // If not specified, the scale defaults to 1.
|
Scale = 1; // If not specified, the scale defaults to 1.
|
||||||
|
|
||||||
if (Lexer.isNot(AsmToken::RParen)) {
|
if (getLexer().isNot(AsmToken::RParen)) {
|
||||||
// Parse the scale amount:
|
// Parse the scale amount:
|
||||||
// ::= ',' [scale-expression]
|
// ::= ',' [scale-expression]
|
||||||
if (Lexer.isNot(AsmToken::Comma))
|
if (getLexer().isNot(AsmToken::Comma))
|
||||||
return true;
|
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;
|
int64_t ScaleVal;
|
||||||
if (ParseAbsoluteExpression(ScaleVal))
|
if (ParseAbsoluteExpression(ScaleVal))
|
||||||
return true;
|
return true;
|
||||||
@@ -212,10 +212,10 @@ bool AsmParser::ParseX86MemOperand(X86Operand &Op) {
|
|||||||
Scale = (unsigned)ScaleVal;
|
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
|
// Otherwise we have the unsupported form of a scale amount without an
|
||||||
// index.
|
// index.
|
||||||
SMLoc Loc = Lexer.getLoc();
|
SMLoc Loc = getLexer().getTok().getLoc();
|
||||||
|
|
||||||
int64_t Value;
|
int64_t Value;
|
||||||
if (ParseAbsoluteExpression(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.
|
// 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");
|
return TokError("unexpected token in memory operand");
|
||||||
Lexer.Lex(); // Eat the ')'.
|
getLexer().Lex(); // Eat the ')'.
|
||||||
|
|
||||||
Op = X86Operand::CreateMem(SegReg, Disp, BaseReg, IndexReg, Scale);
|
Op = X86Operand::CreateMem(SegReg, Disp, BaseReg, IndexReg, Scale);
|
||||||
return false;
|
return false;
|
||||||
@@ -247,14 +247,14 @@ static bool MatchX86Inst(const StringRef &Name,
|
|||||||
bool AsmParser::ParseX86InstOperands(const StringRef &InstName, MCInst &Inst) {
|
bool AsmParser::ParseX86InstOperands(const StringRef &InstName, MCInst &Inst) {
|
||||||
llvm::SmallVector<X86Operand, 3> Operands;
|
llvm::SmallVector<X86Operand, 3> Operands;
|
||||||
|
|
||||||
if (Lexer.isNot(AsmToken::EndOfStatement)) {
|
if (getLexer().isNot(AsmToken::EndOfStatement)) {
|
||||||
// Read the first operand.
|
// Read the first operand.
|
||||||
Operands.push_back(X86Operand());
|
Operands.push_back(X86Operand());
|
||||||
if (ParseX86Operand(Operands.back()))
|
if (ParseX86Operand(Operands.back()))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
while (Lexer.is(AsmToken::Comma)) {
|
while (getLexer().is(AsmToken::Comma)) {
|
||||||
Lexer.Lex(); // Eat the comma.
|
getLexer().Lex(); // Eat the comma.
|
||||||
|
|
||||||
// Parse and remember the operand.
|
// Parse and remember the operand.
|
||||||
Operands.push_back(X86Operand());
|
Operands.push_back(X86Operand());
|
||||||
|
Reference in New Issue
Block a user