} Mem;
};
+ unsigned getReg() const {
+ assert(Kind == Register && "Invalid access!");
+ return Reg.RegNo;
+ }
+
static X86Operand CreateReg(unsigned RegNo) {
X86Operand Res;
Res.Kind = Register;
}
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;
}
};
+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();
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;
}
}
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)) {