Daniel Dunbar | c7df3cb | 2009-07-17 20:42:00 +0000 | [diff] [blame] | 1 | //===-- X86AsmParser.cpp - Parse X86 assembly to MCInst instructions ------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Daniel Dunbar | 0b0441e | 2009-07-18 23:03:22 +0000 | [diff] [blame] | 10 | #include "X86.h" |
Daniel Dunbar | 78929e5 | 2009-07-20 20:01:54 +0000 | [diff] [blame] | 11 | #include "llvm/ADT/SmallVector.h" |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 12 | #include "llvm/ADT/Twine.h" |
Daniel Dunbar | d80432a | 2009-07-28 20:47:52 +0000 | [diff] [blame] | 13 | #include "llvm/MC/MCAsmLexer.h" |
Daniel Dunbar | 4b0f4ef | 2009-07-20 18:55:04 +0000 | [diff] [blame] | 14 | #include "llvm/MC/MCAsmParser.h" |
Daniel Dunbar | a54716c | 2009-07-31 02:32:59 +0000 | [diff] [blame] | 15 | #include "llvm/MC/MCInst.h" |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 16 | #include "llvm/MC/MCValue.h" |
| 17 | #include "llvm/Support/SourceMgr.h" |
Daniel Dunbar | c7df3cb | 2009-07-17 20:42:00 +0000 | [diff] [blame] | 18 | #include "llvm/Target/TargetRegistry.h" |
| 19 | #include "llvm/Target/TargetAsmParser.h" |
| 20 | using namespace llvm; |
| 21 | |
| 22 | namespace { |
Benjamin Kramer | 264834b | 2009-07-31 11:35:26 +0000 | [diff] [blame] | 23 | struct X86Operand; |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 24 | |
| 25 | class X86ATTAsmParser : public TargetAsmParser { |
| 26 | MCAsmParser &Parser; |
| 27 | |
| 28 | private: |
| 29 | bool MatchInstruction(const StringRef &Name, |
Chris Lattner | eb46b49 | 2009-07-29 06:29:53 +0000 | [diff] [blame] | 30 | SmallVectorImpl<X86Operand> &Operands, |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 31 | MCInst &Inst); |
| 32 | |
| 33 | MCAsmParser &getParser() const { return Parser; } |
| 34 | |
| 35 | MCAsmLexer &getLexer() const { return Parser.getLexer(); } |
| 36 | |
| 37 | void Warning(SMLoc L, const Twine &Msg) { Parser.Warning(L, Msg); } |
| 38 | |
| 39 | bool Error(SMLoc L, const Twine &Msg) { return Parser.Error(L, Msg); } |
| 40 | |
| 41 | bool ParseRegister(X86Operand &Op); |
| 42 | |
| 43 | bool ParseOperand(X86Operand &Op); |
| 44 | |
| 45 | bool ParseMemOperand(X86Operand &Op); |
Daniel Dunbar | 85f1b39 | 2009-07-29 00:02:19 +0000 | [diff] [blame] | 46 | |
| 47 | /// @name Auto-generated Match Functions |
| 48 | /// { |
| 49 | |
| 50 | bool MatchRegisterName(const StringRef &Name, unsigned &RegNo); |
| 51 | |
| 52 | /// } |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 53 | |
| 54 | public: |
| 55 | X86ATTAsmParser(const Target &T, MCAsmParser &_Parser) |
| 56 | : TargetAsmParser(T), Parser(_Parser) {} |
| 57 | |
| 58 | virtual bool ParseInstruction(const StringRef &Name, MCInst &Inst); |
| 59 | }; |
Chris Lattner | e54532b | 2009-07-29 06:33:53 +0000 | [diff] [blame] | 60 | |
| 61 | } // end anonymous namespace |
| 62 | |
| 63 | |
| 64 | namespace { |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 65 | |
| 66 | /// X86Operand - Instances of this class represent a parsed X86 machine |
| 67 | /// instruction. |
| 68 | struct X86Operand { |
| 69 | enum { |
| 70 | Register, |
| 71 | Immediate, |
| 72 | Memory |
| 73 | } Kind; |
| 74 | |
| 75 | union { |
| 76 | struct { |
| 77 | unsigned RegNo; |
| 78 | } Reg; |
| 79 | |
| 80 | struct { |
| 81 | MCValue Val; |
| 82 | } Imm; |
| 83 | |
| 84 | struct { |
| 85 | unsigned SegReg; |
| 86 | MCValue Disp; |
| 87 | unsigned BaseReg; |
| 88 | unsigned IndexReg; |
| 89 | unsigned Scale; |
| 90 | } Mem; |
Daniel Dunbar | 78929e5 | 2009-07-20 20:01:54 +0000 | [diff] [blame] | 91 | }; |
Daniel Dunbar | c7df3cb | 2009-07-17 20:42:00 +0000 | [diff] [blame] | 92 | |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 93 | unsigned getReg() const { |
| 94 | assert(Kind == Register && "Invalid access!"); |
| 95 | return Reg.RegNo; |
| 96 | } |
Daniel Dunbar | d80432a | 2009-07-28 20:47:52 +0000 | [diff] [blame] | 97 | |
Daniel Dunbar | b7ddef1 | 2009-07-31 20:53:16 +0000 | [diff] [blame^] | 98 | const MCValue &getImm() const { |
| 99 | assert(Kind == Immediate && "Invalid access!"); |
| 100 | return Imm.Val; |
| 101 | } |
| 102 | |
| 103 | const MCValue &getMemDisp() const { |
| 104 | assert(Kind == Memory && "Invalid access!"); |
| 105 | return Mem.Disp; |
| 106 | } |
| 107 | unsigned getMemSegReg() const { |
| 108 | assert(Kind == Memory && "Invalid access!"); |
| 109 | return Mem.SegReg; |
| 110 | } |
| 111 | unsigned getMemBaseReg() const { |
| 112 | assert(Kind == Memory && "Invalid access!"); |
| 113 | return Mem.BaseReg; |
| 114 | } |
| 115 | unsigned getMemIndexReg() const { |
| 116 | assert(Kind == Memory && "Invalid access!"); |
| 117 | return Mem.IndexReg; |
| 118 | } |
| 119 | unsigned getMemScale() const { |
| 120 | assert(Kind == Memory && "Invalid access!"); |
| 121 | return Mem.Scale; |
| 122 | } |
| 123 | |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 124 | static X86Operand CreateReg(unsigned RegNo) { |
| 125 | X86Operand Res; |
| 126 | Res.Kind = Register; |
| 127 | Res.Reg.RegNo = RegNo; |
| 128 | return Res; |
| 129 | } |
| 130 | static X86Operand CreateImm(MCValue Val) { |
| 131 | X86Operand Res; |
| 132 | Res.Kind = Immediate; |
| 133 | Res.Imm.Val = Val; |
| 134 | return Res; |
| 135 | } |
| 136 | static X86Operand CreateMem(unsigned SegReg, MCValue Disp, unsigned BaseReg, |
| 137 | unsigned IndexReg, unsigned Scale) { |
Daniel Dunbar | b7ddef1 | 2009-07-31 20:53:16 +0000 | [diff] [blame^] | 138 | // The scale should always be one of {1,2,4,8}. |
| 139 | assert(((Scale == 1 || Scale == 2 || Scale == 4 || Scale == 8)) && |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 140 | "Invalid scale!"); |
| 141 | X86Operand Res; |
| 142 | Res.Kind = Memory; |
| 143 | Res.Mem.SegReg = SegReg; |
| 144 | Res.Mem.Disp = Disp; |
| 145 | Res.Mem.BaseReg = BaseReg; |
| 146 | Res.Mem.IndexReg = IndexReg; |
| 147 | Res.Mem.Scale = Scale; |
| 148 | return Res; |
| 149 | } |
| 150 | }; |
Daniel Dunbar | 4b0f4ef | 2009-07-20 18:55:04 +0000 | [diff] [blame] | 151 | |
Chris Lattner | e54532b | 2009-07-29 06:33:53 +0000 | [diff] [blame] | 152 | } // end anonymous namespace. |
Daniel Dunbar | d80432a | 2009-07-28 20:47:52 +0000 | [diff] [blame] | 153 | |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 154 | |
| 155 | bool X86ATTAsmParser::ParseRegister(X86Operand &Op) { |
Chris Lattner | e54532b | 2009-07-29 06:33:53 +0000 | [diff] [blame] | 156 | const AsmToken &Tok = getLexer().getTok(); |
Daniel Dunbar | 85f1b39 | 2009-07-29 00:02:19 +0000 | [diff] [blame] | 157 | assert(Tok.is(AsmToken::Register) && "Invalid token kind!"); |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 158 | |
Daniel Dunbar | 85f1b39 | 2009-07-29 00:02:19 +0000 | [diff] [blame] | 159 | // FIXME: Validate register for the current architecture; we have to do |
| 160 | // validation later, so maybe there is no need for this here. |
| 161 | unsigned RegNo; |
| 162 | assert(Tok.getString().startswith("%") && "Invalid register name!"); |
| 163 | if (MatchRegisterName(Tok.getString().substr(1), RegNo)) |
| 164 | return Error(Tok.getLoc(), "invalid register name"); |
| 165 | |
| 166 | Op = X86Operand::CreateReg(RegNo); |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 167 | getLexer().Lex(); // Eat register token. |
| 168 | |
| 169 | return false; |
Daniel Dunbar | c7df3cb | 2009-07-17 20:42:00 +0000 | [diff] [blame] | 170 | } |
| 171 | |
Daniel Dunbar | 78929e5 | 2009-07-20 20:01:54 +0000 | [diff] [blame] | 172 | bool X86ATTAsmParser::ParseOperand(X86Operand &Op) { |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 173 | switch (getLexer().getKind()) { |
| 174 | default: |
| 175 | return ParseMemOperand(Op); |
| 176 | case AsmToken::Register: |
| 177 | // FIXME: if a segment register, this could either be just the seg reg, or |
| 178 | // the start of a memory operand. |
| 179 | return ParseRegister(Op); |
| 180 | case AsmToken::Dollar: { |
| 181 | // $42 -> immediate. |
| 182 | getLexer().Lex(); |
| 183 | MCValue Val; |
| 184 | if (getParser().ParseRelocatableExpression(Val)) |
| 185 | return true; |
| 186 | Op = X86Operand::CreateImm(Val); |
| 187 | return false; |
| 188 | } |
Chris Lattner | e54532b | 2009-07-29 06:33:53 +0000 | [diff] [blame] | 189 | case AsmToken::Star: |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 190 | getLexer().Lex(); // Eat the star. |
| 191 | |
| 192 | if (getLexer().is(AsmToken::Register)) { |
| 193 | if (ParseRegister(Op)) |
| 194 | return true; |
| 195 | } else if (ParseMemOperand(Op)) |
| 196 | return true; |
| 197 | |
| 198 | // FIXME: Note the '*' in the operand for use by the matcher. |
| 199 | return false; |
| 200 | } |
Daniel Dunbar | 78929e5 | 2009-07-20 20:01:54 +0000 | [diff] [blame] | 201 | } |
| 202 | |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 203 | /// ParseMemOperand: segment: disp(basereg, indexreg, scale) |
| 204 | bool X86ATTAsmParser::ParseMemOperand(X86Operand &Op) { |
| 205 | // FIXME: If SegReg ':' (e.g. %gs:), eat and remember. |
| 206 | unsigned SegReg = 0; |
| 207 | |
| 208 | // We have to disambiguate a parenthesized expression "(4+5)" from the start |
| 209 | // of a memory operand with a missing displacement "(%ebx)" or "(,%eax)". The |
| 210 | // only way to do this without lookahead is to eat the ( and see what is after |
| 211 | // it. |
| 212 | MCValue Disp = MCValue::get(0, 0, 0); |
| 213 | if (getLexer().isNot(AsmToken::LParen)) { |
| 214 | if (getParser().ParseRelocatableExpression(Disp)) return true; |
| 215 | |
| 216 | // After parsing the base expression we could either have a parenthesized |
| 217 | // memory address or not. If not, return now. If so, eat the (. |
| 218 | if (getLexer().isNot(AsmToken::LParen)) { |
Daniel Dunbar | b7ddef1 | 2009-07-31 20:53:16 +0000 | [diff] [blame^] | 219 | Op = X86Operand::CreateMem(SegReg, Disp, 0, 0, 1); |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 220 | return false; |
| 221 | } |
| 222 | |
| 223 | // Eat the '('. |
| 224 | getLexer().Lex(); |
| 225 | } else { |
| 226 | // Okay, we have a '('. We don't know if this is an expression or not, but |
| 227 | // so we have to eat the ( to see beyond it. |
| 228 | getLexer().Lex(); // Eat the '('. |
| 229 | |
| 230 | if (getLexer().is(AsmToken::Register) || getLexer().is(AsmToken::Comma)) { |
| 231 | // Nothing to do here, fall into the code below with the '(' part of the |
| 232 | // memory operand consumed. |
| 233 | } else { |
| 234 | // It must be an parenthesized expression, parse it now. |
| 235 | if (getParser().ParseParenRelocatableExpression(Disp)) |
| 236 | return true; |
| 237 | |
| 238 | // After parsing the base expression we could either have a parenthesized |
| 239 | // memory address or not. If not, return now. If so, eat the (. |
| 240 | if (getLexer().isNot(AsmToken::LParen)) { |
Daniel Dunbar | b7ddef1 | 2009-07-31 20:53:16 +0000 | [diff] [blame^] | 241 | Op = X86Operand::CreateMem(SegReg, Disp, 0, 0, 1); |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 242 | return false; |
| 243 | } |
| 244 | |
| 245 | // Eat the '('. |
| 246 | getLexer().Lex(); |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | // If we reached here, then we just ate the ( of the memory operand. Process |
| 251 | // the rest of the memory operand. |
Daniel Dunbar | b7ddef1 | 2009-07-31 20:53:16 +0000 | [diff] [blame^] | 252 | unsigned BaseReg = 0, IndexReg = 0, Scale = 1; |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 253 | |
| 254 | if (getLexer().is(AsmToken::Register)) { |
| 255 | if (ParseRegister(Op)) |
| 256 | return true; |
| 257 | BaseReg = Op.getReg(); |
| 258 | } |
| 259 | |
| 260 | if (getLexer().is(AsmToken::Comma)) { |
| 261 | getLexer().Lex(); // Eat the comma. |
| 262 | |
| 263 | // Following the comma we should have either an index register, or a scale |
| 264 | // value. We don't support the later form, but we want to parse it |
| 265 | // correctly. |
| 266 | // |
| 267 | // Not that even though it would be completely consistent to support syntax |
| 268 | // like "1(%eax,,1)", the assembler doesn't. |
| 269 | if (getLexer().is(AsmToken::Register)) { |
| 270 | if (ParseRegister(Op)) |
| 271 | return true; |
| 272 | IndexReg = Op.getReg(); |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 273 | |
| 274 | if (getLexer().isNot(AsmToken::RParen)) { |
| 275 | // Parse the scale amount: |
| 276 | // ::= ',' [scale-expression] |
| 277 | if (getLexer().isNot(AsmToken::Comma)) |
| 278 | return true; |
| 279 | getLexer().Lex(); // Eat the comma. |
| 280 | |
| 281 | if (getLexer().isNot(AsmToken::RParen)) { |
| 282 | SMLoc Loc = getLexer().getTok().getLoc(); |
| 283 | |
| 284 | int64_t ScaleVal; |
| 285 | if (getParser().ParseAbsoluteExpression(ScaleVal)) |
| 286 | return true; |
| 287 | |
| 288 | // Validate the scale amount. |
| 289 | if (ScaleVal != 1 && ScaleVal != 2 && ScaleVal != 4 && ScaleVal != 8) |
| 290 | return Error(Loc, "scale factor in address must be 1, 2, 4 or 8"); |
| 291 | Scale = (unsigned)ScaleVal; |
| 292 | } |
| 293 | } |
| 294 | } else if (getLexer().isNot(AsmToken::RParen)) { |
| 295 | // Otherwise we have the unsupported form of a scale amount without an |
| 296 | // index. |
| 297 | SMLoc Loc = getLexer().getTok().getLoc(); |
| 298 | |
| 299 | int64_t Value; |
| 300 | if (getParser().ParseAbsoluteExpression(Value)) |
| 301 | return true; |
| 302 | |
| 303 | return Error(Loc, "cannot have scale factor without index register"); |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | // Ok, we've eaten the memory operand, verify we have a ')' and eat it too. |
| 308 | if (getLexer().isNot(AsmToken::RParen)) |
| 309 | return Error(getLexer().getTok().getLoc(), |
| 310 | "unexpected token in memory operand"); |
| 311 | getLexer().Lex(); // Eat the ')'. |
| 312 | |
| 313 | Op = X86Operand::CreateMem(SegReg, Disp, BaseReg, IndexReg, Scale); |
| 314 | return false; |
| 315 | } |
| 316 | |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 317 | bool X86ATTAsmParser::ParseInstruction(const StringRef &Name, MCInst &Inst) { |
Chris Lattner | eb46b49 | 2009-07-29 06:29:53 +0000 | [diff] [blame] | 318 | SmallVector<X86Operand, 3> Operands; |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 319 | |
Daniel Dunbar | a54716c | 2009-07-31 02:32:59 +0000 | [diff] [blame] | 320 | SMLoc Loc = getLexer().getTok().getLoc(); |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 321 | if (getLexer().isNot(AsmToken::EndOfStatement)) { |
| 322 | // Read the first operand. |
| 323 | Operands.push_back(X86Operand()); |
| 324 | if (ParseOperand(Operands.back())) |
| 325 | return true; |
| 326 | |
| 327 | while (getLexer().is(AsmToken::Comma)) { |
| 328 | getLexer().Lex(); // Eat the comma. |
| 329 | |
| 330 | // Parse and remember the operand. |
| 331 | Operands.push_back(X86Operand()); |
| 332 | if (ParseOperand(Operands.back())) |
| 333 | return true; |
| 334 | } |
| 335 | } |
| 336 | |
Daniel Dunbar | a54716c | 2009-07-31 02:32:59 +0000 | [diff] [blame] | 337 | if (!MatchInstruction(Name, Operands, Inst)) |
| 338 | return false; |
| 339 | |
| 340 | // FIXME: We should give nicer diagnostics about the exact failure. |
| 341 | |
| 342 | // FIXME: For now we just treat unrecognized instructions as "warnings". |
| 343 | Warning(Loc, "unrecognized instruction"); |
| 344 | |
| 345 | return false; |
Daniel Dunbar | 4b0f4ef | 2009-07-20 18:55:04 +0000 | [diff] [blame] | 346 | } |
| 347 | |
Daniel Dunbar | c7df3cb | 2009-07-17 20:42:00 +0000 | [diff] [blame] | 348 | // Force static initialization. |
| 349 | extern "C" void LLVMInitializeX86AsmParser() { |
Daniel Dunbar | c680b01 | 2009-07-25 06:49:55 +0000 | [diff] [blame] | 350 | RegisterAsmParser<X86ATTAsmParser> X(TheX86_32Target); |
| 351 | RegisterAsmParser<X86ATTAsmParser> Y(TheX86_64Target); |
Daniel Dunbar | c7df3cb | 2009-07-17 20:42:00 +0000 | [diff] [blame] | 352 | } |
Daniel Dunbar | 85f1b39 | 2009-07-29 00:02:19 +0000 | [diff] [blame] | 353 | |
Daniel Dunbar | b7ddef1 | 2009-07-31 20:53:16 +0000 | [diff] [blame^] | 354 | // FIXME: These should come from tblgen? |
Daniel Dunbar | a54716c | 2009-07-31 02:32:59 +0000 | [diff] [blame] | 355 | |
Daniel Dunbar | a54716c | 2009-07-31 02:32:59 +0000 | [diff] [blame] | 356 | static bool |
Daniel Dunbar | b7ddef1 | 2009-07-31 20:53:16 +0000 | [diff] [blame^] | 357 | Match_X86_Op_REG(const X86Operand &Op, MCOperand *MCOps, unsigned NumOps) { |
Daniel Dunbar | a54716c | 2009-07-31 02:32:59 +0000 | [diff] [blame] | 358 | assert(NumOps == 1 && "Invalid number of ops!"); |
| 359 | |
| 360 | // FIXME: Match correct registers. |
| 361 | if (Op.Kind != X86Operand::Register) |
| 362 | return true; |
| 363 | |
| 364 | MCOps[0].MakeReg(Op.getReg()); |
| 365 | return false; |
| 366 | } |
| 367 | |
Daniel Dunbar | b7ddef1 | 2009-07-31 20:53:16 +0000 | [diff] [blame^] | 368 | static bool |
| 369 | Match_X86_Op_IMM(const X86Operand &Op, MCOperand *MCOps, unsigned NumOps) { |
| 370 | assert(NumOps == 1 && "Invalid number of ops!"); |
| 371 | |
| 372 | // FIXME: We need to check widths. |
| 373 | if (Op.Kind != X86Operand::Immediate) |
| 374 | return true; |
| 375 | |
| 376 | MCOps[0].MakeMCValue(Op.getImm()); |
| 377 | return false; |
| 378 | } |
| 379 | |
| 380 | static bool Match_X86_Op_MEM(const X86Operand &Op, |
| 381 | MCOperand *MCOps, |
| 382 | unsigned NumMCOps) { |
| 383 | assert(NumMCOps == 5 && "Invalid number of ops!"); |
| 384 | |
| 385 | if (Op.Kind != X86Operand::Memory) |
| 386 | return true; |
| 387 | |
| 388 | MCOps[0].MakeReg(Op.getMemBaseReg()); |
| 389 | MCOps[1].MakeImm(Op.getMemScale()); |
| 390 | MCOps[2].MakeReg(Op.getMemIndexReg()); |
| 391 | MCOps[3].MakeMCValue(Op.getMemDisp()); |
| 392 | MCOps[4].MakeReg(Op.getMemSegReg()); |
| 393 | |
| 394 | return false; |
| 395 | } |
| 396 | |
| 397 | #define REG(name) \ |
| 398 | static bool Match_X86_Op_##name(const X86Operand &Op, \ |
| 399 | MCOperand *MCOps, \ |
| 400 | unsigned NumMCOps) { \ |
| 401 | return Match_X86_Op_REG(Op, MCOps, NumMCOps); \ |
| 402 | } |
| 403 | |
| 404 | REG(GR64) |
| 405 | REG(GR32) |
| 406 | REG(GR16) |
| 407 | REG(GR8) |
| 408 | |
| 409 | #define IMM(name) \ |
| 410 | static bool Match_X86_Op_##name(const X86Operand &Op, \ |
| 411 | MCOperand *MCOps, \ |
| 412 | unsigned NumMCOps) { \ |
| 413 | return Match_X86_Op_IMM(Op, MCOps, NumMCOps); \ |
| 414 | } |
| 415 | |
| 416 | IMM(i16i8imm) |
| 417 | IMM(i16imm) |
| 418 | IMM(i32i8imm) |
| 419 | IMM(i32imm) |
| 420 | IMM(i64i32imm) |
| 421 | IMM(i64i8imm) |
| 422 | IMM(i64imm) |
| 423 | IMM(i8imm) |
| 424 | |
| 425 | #define MEM(name) \ |
| 426 | static bool Match_X86_Op_##name(const X86Operand &Op, \ |
| 427 | MCOperand *MCOps, \ |
| 428 | unsigned NumMCOps) { \ |
| 429 | return Match_X86_Op_MEM(Op, MCOps, NumMCOps); \ |
| 430 | } |
| 431 | |
| 432 | MEM(f128mem) |
| 433 | MEM(f32mem) |
| 434 | MEM(f64mem) |
| 435 | MEM(f80mem) |
| 436 | MEM(i128mem) |
| 437 | MEM(i16mem) |
| 438 | MEM(i32mem) |
| 439 | MEM(i64mem) |
| 440 | MEM(i8mem) |
| 441 | MEM(lea32mem) |
| 442 | MEM(lea64_32mem) |
| 443 | MEM(lea64mem) |
| 444 | MEM(sdmem) |
| 445 | MEM(ssmem) |
| 446 | |
Daniel Dunbar | a54716c | 2009-07-31 02:32:59 +0000 | [diff] [blame] | 447 | #define DUMMY(name) \ |
| 448 | static bool Match_X86_Op_##name(const X86Operand &Op, \ |
| 449 | MCOperand *MCOps, \ |
| 450 | unsigned NumMCOps) { \ |
| 451 | return true; \ |
| 452 | } |
| 453 | |
| 454 | DUMMY(FR32) |
| 455 | DUMMY(FR64) |
Daniel Dunbar | a54716c | 2009-07-31 02:32:59 +0000 | [diff] [blame] | 456 | DUMMY(GR32_NOREX) |
Daniel Dunbar | a54716c | 2009-07-31 02:32:59 +0000 | [diff] [blame] | 457 | DUMMY(GR8_NOREX) |
| 458 | DUMMY(RST) |
| 459 | DUMMY(VR128) |
| 460 | DUMMY(VR64) |
| 461 | DUMMY(brtarget) |
| 462 | DUMMY(brtarget8) |
Daniel Dunbar | a54716c | 2009-07-31 02:32:59 +0000 | [diff] [blame] | 463 | DUMMY(i32imm_pcrel) |
Daniel Dunbar | a54716c | 2009-07-31 02:32:59 +0000 | [diff] [blame] | 464 | DUMMY(i64i32imm_pcrel) |
Daniel Dunbar | a54716c | 2009-07-31 02:32:59 +0000 | [diff] [blame] | 465 | DUMMY(i8mem_NOREX) |
Daniel Dunbar | a54716c | 2009-07-31 02:32:59 +0000 | [diff] [blame] | 466 | |
Daniel Dunbar | 85f1b39 | 2009-07-29 00:02:19 +0000 | [diff] [blame] | 467 | #include "X86GenAsmMatcher.inc" |