[llvm-commits] [llvm] r74684 - in /llvm/trunk/tools/llvm-mc: AsmParser.h MC-X86Specific.cpp
Daniel Dunbar
daniel at zuster.org
Wed Jul 1 18:58:25 PDT 2009
Author: ddunbar
Date: Wed Jul 1 20:58:24 2009
New Revision: 74684
URL: http://llvm.org/viewvc/llvm-project?rev=74684&view=rev
Log:
llvm-mc/x86: Factor out ParseX86Register.
Modified:
llvm/trunk/tools/llvm-mc/AsmParser.h
llvm/trunk/tools/llvm-mc/MC-X86Specific.cpp
Modified: llvm/trunk/tools/llvm-mc/AsmParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmParser.h?rev=74684&r1=74683&r2=74684&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmParser.h (original)
+++ llvm/trunk/tools/llvm-mc/AsmParser.h Wed Jul 1 20:58:24 2009
@@ -81,6 +81,7 @@
bool ParseX86InstOperands(const char *InstName, MCInst &Inst);
bool ParseX86Operand(X86Operand &Op);
bool ParseX86MemOperand(X86Operand &Op);
+ bool ParseX86Register(X86Operand &Op);
// Directive Parsing.
bool ParseDirectiveDarwinSection(); // Darwin specific ".section".
Modified: llvm/trunk/tools/llvm-mc/MC-X86Specific.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/MC-X86Specific.cpp?rev=74684&r1=74683&r2=74684&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mc/MC-X86Specific.cpp (original)
+++ llvm/trunk/tools/llvm-mc/MC-X86Specific.cpp Wed Jul 1 20:58:24 2009
@@ -42,6 +42,11 @@
} Mem;
};
+ unsigned getReg() const {
+ assert(Kind == Register && "Invalid access!");
+ return Reg.RegNo;
+ }
+
static X86Operand CreateReg(unsigned RegNo) {
X86Operand Res;
Res.Kind = Register;
@@ -56,6 +61,12 @@
}
static X86Operand CreateMem(unsigned SegReg, MCValue Disp, unsigned BaseReg,
unsigned IndexReg, unsigned Scale) {
+ // If there is no index register, we should never have a scale, and we
+ // should always have a scale (in {1,2,4,8}) if we do.
+ assert(((Scale == 0 && !IndexReg) ||
+ (IndexReg && (Scale == 1 || Scale == 2 ||
+ Scale == 4 || Scale == 8))) &&
+ "Invalid scale!");
X86Operand Res;
Res.Kind = Memory;
Res.Mem.SegReg = SegReg;
@@ -67,17 +78,24 @@
}
};
+bool AsmParser::ParseX86Register(X86Operand &Op) {
+ assert(Lexer.getKind() == asmtok::Register && "Invalid token kind!");
+
+ // FIXME: Decode register number.
+ Op = X86Operand::CreateReg(123);
+ Lexer.Lex(); // Eat register token.
+
+ return false;
+}
+
bool AsmParser::ParseX86Operand(X86Operand &Op) {
switch (Lexer.getKind()) {
default:
return ParseX86MemOperand(Op);
case asmtok::Register:
- // FIXME: Decode reg #.
// FIXME: if a segment register, this could either be just the seg reg, or
// the start of a memory operand.
- Op = X86Operand::CreateReg(123);
- Lexer.Lex(); // Eat register.
- return false;
+ return ParseX86Register(Op);
case asmtok::Dollar: {
// $42 -> immediate.
Lexer.Lex();
@@ -91,13 +109,12 @@
Lexer.Lex(); // Eat the star.
if (Lexer.is(asmtok::Register)) {
- Op = X86Operand::CreateReg(123);
- Lexer.Lex(); // Eat register.
+ if (ParseX86Register(Op))
+ return true;
} else if (ParseX86MemOperand(Op))
return true;
- // FIXME: Note that these are 'dereferenced' so that clients know the '*' is
- // there.
+ // FIXME: Note the '*' in the operand for use by the matcher.
return false;
}
}
@@ -155,21 +172,23 @@
unsigned BaseReg = 0, IndexReg = 0, Scale = 0;
if (Lexer.is(asmtok::Register)) {
- BaseReg = 123; // FIXME: decode reg #
- Lexer.Lex(); // eat the register.
+ if (ParseX86Register(Op))
+ return true;
+ BaseReg = Op.getReg();
}
if (Lexer.is(asmtok::Comma)) {
Lexer.Lex(); // eat the comma.
if (Lexer.is(asmtok::Register)) {
- IndexReg = 123; // FIXME: decode reg #
- Lexer.Lex(); // eat the register.
+ if (ParseX86Register(Op))
+ return true;
+ IndexReg = Op.getReg();
Scale = 1; // If not specified, the scale defaults to 1.
}
if (Lexer.is(asmtok::Comma)) {
- Lexer.Lex(); // eat the comma.
+ Lexer.Lex(); // Eat the comma.
// If present, get and validate scale amount.
if (Lexer.is(asmtok::IntVal)) {
More information about the llvm-commits
mailing list