mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-07 11:33:44 +00:00
llvm-mc: Introduce method to match a parsed x86 instruction into an MCInst.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74573 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
e303503da3
commit
d9627e11bf
@ -506,7 +506,7 @@ bool AsmParser::ParseStatement() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MCInst Inst;
|
MCInst Inst;
|
||||||
if (ParseX86InstOperands(Inst))
|
if (ParseX86InstOperands(IDVal, Inst))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (Lexer.isNot(asmtok::EndOfStatement))
|
if (Lexer.isNot(asmtok::EndOfStatement))
|
||||||
|
@ -25,12 +25,14 @@ class MCStreamer;
|
|||||||
class MCValue;
|
class MCValue;
|
||||||
|
|
||||||
class AsmParser {
|
class AsmParser {
|
||||||
|
public:
|
||||||
|
struct X86Operand;
|
||||||
|
|
||||||
|
private:
|
||||||
AsmLexer Lexer;
|
AsmLexer Lexer;
|
||||||
MCContext &Ctx;
|
MCContext &Ctx;
|
||||||
MCStreamer &Out;
|
MCStreamer &Out;
|
||||||
|
|
||||||
struct X86Operand;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AsmParser(SourceMgr &SM, MCContext &ctx, MCStreamer &OutStr)
|
AsmParser(SourceMgr &SM, MCContext &ctx, MCStreamer &OutStr)
|
||||||
: Lexer(SM), Ctx(ctx), Out(OutStr) {}
|
: Lexer(SM), Ctx(ctx), Out(OutStr) {}
|
||||||
@ -76,7 +78,7 @@ private:
|
|||||||
bool ParseParenExpr(AsmExpr *&Res);
|
bool ParseParenExpr(AsmExpr *&Res);
|
||||||
|
|
||||||
// X86 specific.
|
// X86 specific.
|
||||||
bool ParseX86InstOperands(MCInst &Inst);
|
bool ParseX86InstOperands(const char *InstName, MCInst &Inst);
|
||||||
bool ParseX86Operand(X86Operand &Op);
|
bool ParseX86Operand(X86Operand &Op);
|
||||||
bool ParseX86MemOperand(X86Operand &Op);
|
bool ParseX86MemOperand(X86Operand &Op);
|
||||||
|
|
||||||
|
@ -65,10 +65,6 @@ struct AsmParser::X86Operand {
|
|||||||
Res.Mem.ScaleReg = ScaleReg;
|
Res.Mem.ScaleReg = ScaleReg;
|
||||||
return Res;
|
return Res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddToMCInst(MCInst &I) {
|
|
||||||
// FIXME: Add in x86 order here.
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
bool AsmParser::ParseX86Operand(X86Operand &Op) {
|
bool AsmParser::ParseX86Operand(X86Operand &Op) {
|
||||||
@ -195,27 +191,34 @@ bool AsmParser::ParseX86MemOperand(X86Operand &Op) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// MatchX86Inst - Convert a parsed instruction name and operand list into a
|
||||||
|
/// concrete instruction.
|
||||||
|
static bool MatchX86Inst(const char *Name,
|
||||||
|
llvm::SmallVector<AsmParser::X86Operand, 3> &Operands,
|
||||||
|
MCInst &Inst) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/// ParseX86InstOperands - Parse the operands of an X86 instruction and return
|
/// ParseX86InstOperands - Parse the operands of an X86 instruction and return
|
||||||
/// them as the operands of an MCInst.
|
/// them as the operands of an MCInst.
|
||||||
bool AsmParser::ParseX86InstOperands(MCInst &Inst) {
|
bool AsmParser::ParseX86InstOperands(const char *InstName, MCInst &Inst) {
|
||||||
// If no operands are present, just return.
|
llvm::SmallVector<X86Operand, 3> Operands;
|
||||||
if (Lexer.is(asmtok::EndOfStatement))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
|
if (Lexer.isNot(asmtok::EndOfStatement)) {
|
||||||
// Read the first operand.
|
// Read the first operand.
|
||||||
X86Operand Op;
|
Operands.push_back(X86Operand());
|
||||||
if (ParseX86Operand(Op))
|
if (ParseX86Operand(Operands.back()))
|
||||||
return true;
|
return true;
|
||||||
Op.AddToMCInst(Inst);
|
|
||||||
|
|
||||||
while (Lexer.is(asmtok::Comma)) {
|
while (Lexer.is(asmtok::Comma)) {
|
||||||
Lexer.Lex(); // Eat the comma.
|
Lexer.Lex(); // Eat the comma.
|
||||||
|
|
||||||
// Parse and remember the operand.
|
// Parse and remember the operand.
|
||||||
Op = X86Operand();
|
Operands.push_back(X86Operand());
|
||||||
if (ParseX86Operand(Op))
|
if (ParseX86Operand(Operands.back()))
|
||||||
return true;
|
return true;
|
||||||
Op.AddToMCInst(Inst);
|
|
||||||
}
|
}
|
||||||
return false;
|
}
|
||||||
|
|
||||||
|
return MatchX86Inst(InstName, Operands, Inst);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user