diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-06-30 23:38:38 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-06-30 23:38:38 +0000 |
commit | d1d1e83b06a0e19a9f6d065b29d0a74622b97aef (patch) | |
tree | d3901649597e23039fc6264ae4624c1c0da76b69 /tools | |
parent | 76e8adc9779110165be309667dde2d6d3969875a (diff) | |
download | external_llvm-d1d1e83b06a0e19a9f6d065b29d0a74622b97aef.zip external_llvm-d1d1e83b06a0e19a9f6d065b29d0a74622b97aef.tar.gz external_llvm-d1d1e83b06a0e19a9f6d065b29d0a74622b97aef.tar.bz2 |
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
Diffstat (limited to 'tools')
-rw-r--r-- | tools/llvm-mc/AsmParser.cpp | 2 | ||||
-rw-r--r-- | tools/llvm-mc/AsmParser.h | 8 | ||||
-rw-r--r-- | tools/llvm-mc/MC-X86Specific.cpp | 47 |
3 files changed, 31 insertions, 26 deletions
diff --git a/tools/llvm-mc/AsmParser.cpp b/tools/llvm-mc/AsmParser.cpp index 4c6c4cc..744e1f6 100644 --- a/tools/llvm-mc/AsmParser.cpp +++ b/tools/llvm-mc/AsmParser.cpp @@ -506,7 +506,7 @@ bool AsmParser::ParseStatement() { } MCInst Inst; - if (ParseX86InstOperands(Inst)) + if (ParseX86InstOperands(IDVal, Inst)) return true; if (Lexer.isNot(asmtok::EndOfStatement)) diff --git a/tools/llvm-mc/AsmParser.h b/tools/llvm-mc/AsmParser.h index 3a812c3..92ff388 100644 --- a/tools/llvm-mc/AsmParser.h +++ b/tools/llvm-mc/AsmParser.h @@ -25,12 +25,14 @@ class MCStreamer; class MCValue; class AsmParser { +public: + struct X86Operand; + +private: AsmLexer Lexer; MCContext &Ctx; MCStreamer &Out; - struct X86Operand; - public: AsmParser(SourceMgr &SM, MCContext &ctx, MCStreamer &OutStr) : Lexer(SM), Ctx(ctx), Out(OutStr) {} @@ -76,7 +78,7 @@ private: bool ParseParenExpr(AsmExpr *&Res); // X86 specific. - bool ParseX86InstOperands(MCInst &Inst); + bool ParseX86InstOperands(const char *InstName, MCInst &Inst); bool ParseX86Operand(X86Operand &Op); bool ParseX86MemOperand(X86Operand &Op); diff --git a/tools/llvm-mc/MC-X86Specific.cpp b/tools/llvm-mc/MC-X86Specific.cpp index 806ec44..be0a128 100644 --- a/tools/llvm-mc/MC-X86Specific.cpp +++ b/tools/llvm-mc/MC-X86Specific.cpp @@ -65,10 +65,6 @@ struct AsmParser::X86Operand { Res.Mem.ScaleReg = ScaleReg; return Res; } - - void AddToMCInst(MCInst &I) { - // FIXME: Add in x86 order here. - } }; bool AsmParser::ParseX86Operand(X86Operand &Op) { @@ -195,27 +191,34 @@ bool AsmParser::ParseX86MemOperand(X86Operand &Op) { 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 /// them as the operands of an MCInst. -bool AsmParser::ParseX86InstOperands(MCInst &Inst) { - // If no operands are present, just return. - if (Lexer.is(asmtok::EndOfStatement)) - return false; +bool AsmParser::ParseX86InstOperands(const char *InstName, MCInst &Inst) { + llvm::SmallVector<X86Operand, 3> Operands; - // Read the first operand. - X86Operand Op; - if (ParseX86Operand(Op)) - return true; - Op.AddToMCInst(Inst); - - while (Lexer.is(asmtok::Comma)) { - Lexer.Lex(); // Eat the comma. - - // Parse and remember the operand. - Op = X86Operand(); - if (ParseX86Operand(Op)) + if (Lexer.isNot(asmtok::EndOfStatement)) { + // Read the first operand. + Operands.push_back(X86Operand()); + if (ParseX86Operand(Operands.back())) return true; - Op.AddToMCInst(Inst); + + while (Lexer.is(asmtok::Comma)) { + Lexer.Lex(); // Eat the comma. + + // Parse and remember the operand. + Operands.push_back(X86Operand()); + if (ParseX86Operand(Operands.back())) + return true; + } } - return false; + + return MatchX86Inst(InstName, Operands, Inst); } |