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: |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 29 | MCAsmParser &getParser() const { return Parser; } |
| 30 | |
| 31 | MCAsmLexer &getLexer() const { return Parser.getLexer(); } |
| 32 | |
| 33 | void Warning(SMLoc L, const Twine &Msg) { Parser.Warning(L, Msg); } |
| 34 | |
| 35 | bool Error(SMLoc L, const Twine &Msg) { return Parser.Error(L, Msg); } |
| 36 | |
| 37 | bool ParseRegister(X86Operand &Op); |
| 38 | |
| 39 | bool ParseOperand(X86Operand &Op); |
| 40 | |
| 41 | bool ParseMemOperand(X86Operand &Op); |
Daniel Dunbar | 85f1b39 | 2009-07-29 00:02:19 +0000 | [diff] [blame] | 42 | |
| 43 | /// @name Auto-generated Match Functions |
| 44 | /// { |
| 45 | |
Daniel Dunbar | fe6759e | 2009-08-07 08:26:05 +0000 | [diff] [blame] | 46 | bool MatchInstruction(SmallVectorImpl<X86Operand> &Operands, |
| 47 | MCInst &Inst); |
| 48 | |
Daniel Dunbar | 85f1b39 | 2009-07-29 00:02:19 +0000 | [diff] [blame] | 49 | bool MatchRegisterName(const StringRef &Name, unsigned &RegNo); |
| 50 | |
| 51 | /// } |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 52 | |
| 53 | public: |
| 54 | X86ATTAsmParser(const Target &T, MCAsmParser &_Parser) |
| 55 | : TargetAsmParser(T), Parser(_Parser) {} |
| 56 | |
| 57 | virtual bool ParseInstruction(const StringRef &Name, MCInst &Inst); |
| 58 | }; |
Chris Lattner | e54532b | 2009-07-29 06:33:53 +0000 | [diff] [blame] | 59 | |
| 60 | } // end anonymous namespace |
| 61 | |
| 62 | |
| 63 | namespace { |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 64 | |
| 65 | /// X86Operand - Instances of this class represent a parsed X86 machine |
| 66 | /// instruction. |
| 67 | struct X86Operand { |
| 68 | enum { |
Daniel Dunbar | fe6759e | 2009-08-07 08:26:05 +0000 | [diff] [blame] | 69 | Token, |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 70 | Register, |
| 71 | Immediate, |
| 72 | Memory |
| 73 | } Kind; |
| 74 | |
| 75 | union { |
| 76 | struct { |
Daniel Dunbar | fe6759e | 2009-08-07 08:26:05 +0000 | [diff] [blame] | 77 | const char *Data; |
| 78 | unsigned Length; |
| 79 | } Tok; |
| 80 | |
| 81 | struct { |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 82 | unsigned RegNo; |
| 83 | } Reg; |
| 84 | |
| 85 | struct { |
| 86 | MCValue Val; |
| 87 | } Imm; |
| 88 | |
| 89 | struct { |
| 90 | unsigned SegReg; |
| 91 | MCValue Disp; |
| 92 | unsigned BaseReg; |
| 93 | unsigned IndexReg; |
| 94 | unsigned Scale; |
| 95 | } Mem; |
Daniel Dunbar | 78929e5 | 2009-07-20 20:01:54 +0000 | [diff] [blame] | 96 | }; |
Daniel Dunbar | c7df3cb | 2009-07-17 20:42:00 +0000 | [diff] [blame] | 97 | |
Daniel Dunbar | fe6759e | 2009-08-07 08:26:05 +0000 | [diff] [blame] | 98 | StringRef getToken() const { |
| 99 | assert(Kind == Token && "Invalid access!"); |
| 100 | return StringRef(Tok.Data, Tok.Length); |
| 101 | } |
| 102 | |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 103 | unsigned getReg() const { |
| 104 | assert(Kind == Register && "Invalid access!"); |
| 105 | return Reg.RegNo; |
| 106 | } |
Daniel Dunbar | d80432a | 2009-07-28 20:47:52 +0000 | [diff] [blame] | 107 | |
Daniel Dunbar | b7ddef1 | 2009-07-31 20:53:16 +0000 | [diff] [blame] | 108 | const MCValue &getImm() const { |
| 109 | assert(Kind == Immediate && "Invalid access!"); |
| 110 | return Imm.Val; |
| 111 | } |
| 112 | |
| 113 | const MCValue &getMemDisp() const { |
| 114 | assert(Kind == Memory && "Invalid access!"); |
| 115 | return Mem.Disp; |
| 116 | } |
| 117 | unsigned getMemSegReg() const { |
| 118 | assert(Kind == Memory && "Invalid access!"); |
| 119 | return Mem.SegReg; |
| 120 | } |
| 121 | unsigned getMemBaseReg() const { |
| 122 | assert(Kind == Memory && "Invalid access!"); |
| 123 | return Mem.BaseReg; |
| 124 | } |
| 125 | unsigned getMemIndexReg() const { |
| 126 | assert(Kind == Memory && "Invalid access!"); |
| 127 | return Mem.IndexReg; |
| 128 | } |
| 129 | unsigned getMemScale() const { |
| 130 | assert(Kind == Memory && "Invalid access!"); |
| 131 | return Mem.Scale; |
| 132 | } |
| 133 | |
Daniel Dunbar | 378bee9 | 2009-08-08 07:50:56 +0000 | [diff] [blame^] | 134 | bool isToken() const {return Kind == Token; } |
Daniel Dunbar | fe6759e | 2009-08-07 08:26:05 +0000 | [diff] [blame] | 135 | |
| 136 | bool isImm() const { return Kind == Immediate; } |
| 137 | |
| 138 | bool isMem() const { return Kind == Memory; } |
| 139 | |
| 140 | bool isReg() const { return Kind == Register; } |
| 141 | |
| 142 | void addRegOperands(MCInst &Inst, unsigned N) { |
| 143 | assert(N == 1 && "Invalid number of operands!"); |
| 144 | Inst.addOperand(MCOperand::CreateReg(getReg())); |
| 145 | } |
| 146 | |
| 147 | void addImmOperands(MCInst &Inst, unsigned N) { |
| 148 | assert(N == 1 && "Invalid number of operands!"); |
| 149 | Inst.addOperand(MCOperand::CreateMCValue(getImm())); |
| 150 | } |
| 151 | |
| 152 | void addMemOperands(MCInst &Inst, unsigned N) { |
| 153 | assert((N == 4 || N == 5) && "Invalid number of operands!"); |
| 154 | |
| 155 | Inst.addOperand(MCOperand::CreateReg(getMemBaseReg())); |
| 156 | Inst.addOperand(MCOperand::CreateImm(getMemScale())); |
| 157 | Inst.addOperand(MCOperand::CreateReg(getMemIndexReg())); |
| 158 | Inst.addOperand(MCOperand::CreateMCValue(getMemDisp())); |
| 159 | |
| 160 | // FIXME: What a hack. |
| 161 | if (N == 5) |
| 162 | Inst.addOperand(MCOperand::CreateReg(getMemSegReg())); |
| 163 | } |
| 164 | |
| 165 | static X86Operand CreateToken(StringRef Str) { |
| 166 | X86Operand Res; |
| 167 | Res.Kind = Token; |
| 168 | Res.Tok.Data = Str.data(); |
| 169 | Res.Tok.Length = Str.size(); |
| 170 | return Res; |
| 171 | } |
| 172 | |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 173 | static X86Operand CreateReg(unsigned RegNo) { |
| 174 | X86Operand Res; |
| 175 | Res.Kind = Register; |
| 176 | Res.Reg.RegNo = RegNo; |
| 177 | return Res; |
| 178 | } |
Daniel Dunbar | fe6759e | 2009-08-07 08:26:05 +0000 | [diff] [blame] | 179 | |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 180 | static X86Operand CreateImm(MCValue Val) { |
| 181 | X86Operand Res; |
| 182 | Res.Kind = Immediate; |
| 183 | Res.Imm.Val = Val; |
| 184 | return Res; |
| 185 | } |
Daniel Dunbar | fe6759e | 2009-08-07 08:26:05 +0000 | [diff] [blame] | 186 | |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 187 | static X86Operand CreateMem(unsigned SegReg, MCValue Disp, unsigned BaseReg, |
| 188 | unsigned IndexReg, unsigned Scale) { |
Daniel Dunbar | 2409171 | 2009-07-31 22:22:54 +0000 | [diff] [blame] | 189 | // We should never just have a displacement, that would be an immediate. |
| 190 | assert((SegReg || BaseReg || IndexReg) && "Invalid memory operand!"); |
| 191 | |
Daniel Dunbar | b7ddef1 | 2009-07-31 20:53:16 +0000 | [diff] [blame] | 192 | // The scale should always be one of {1,2,4,8}. |
| 193 | assert(((Scale == 1 || Scale == 2 || Scale == 4 || Scale == 8)) && |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 194 | "Invalid scale!"); |
| 195 | X86Operand Res; |
| 196 | Res.Kind = Memory; |
| 197 | Res.Mem.SegReg = SegReg; |
| 198 | Res.Mem.Disp = Disp; |
| 199 | Res.Mem.BaseReg = BaseReg; |
| 200 | Res.Mem.IndexReg = IndexReg; |
| 201 | Res.Mem.Scale = Scale; |
| 202 | return Res; |
| 203 | } |
| 204 | }; |
Daniel Dunbar | 4b0f4ef | 2009-07-20 18:55:04 +0000 | [diff] [blame] | 205 | |
Chris Lattner | e54532b | 2009-07-29 06:33:53 +0000 | [diff] [blame] | 206 | } // end anonymous namespace. |
Daniel Dunbar | d80432a | 2009-07-28 20:47:52 +0000 | [diff] [blame] | 207 | |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 208 | |
| 209 | bool X86ATTAsmParser::ParseRegister(X86Operand &Op) { |
Chris Lattner | e54532b | 2009-07-29 06:33:53 +0000 | [diff] [blame] | 210 | const AsmToken &Tok = getLexer().getTok(); |
Daniel Dunbar | 85f1b39 | 2009-07-29 00:02:19 +0000 | [diff] [blame] | 211 | assert(Tok.is(AsmToken::Register) && "Invalid token kind!"); |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 212 | |
Daniel Dunbar | 85f1b39 | 2009-07-29 00:02:19 +0000 | [diff] [blame] | 213 | // FIXME: Validate register for the current architecture; we have to do |
| 214 | // validation later, so maybe there is no need for this here. |
| 215 | unsigned RegNo; |
| 216 | assert(Tok.getString().startswith("%") && "Invalid register name!"); |
| 217 | if (MatchRegisterName(Tok.getString().substr(1), RegNo)) |
| 218 | return Error(Tok.getLoc(), "invalid register name"); |
| 219 | |
| 220 | Op = X86Operand::CreateReg(RegNo); |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 221 | getLexer().Lex(); // Eat register token. |
| 222 | |
| 223 | return false; |
Daniel Dunbar | c7df3cb | 2009-07-17 20:42:00 +0000 | [diff] [blame] | 224 | } |
| 225 | |
Daniel Dunbar | 78929e5 | 2009-07-20 20:01:54 +0000 | [diff] [blame] | 226 | bool X86ATTAsmParser::ParseOperand(X86Operand &Op) { |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 227 | switch (getLexer().getKind()) { |
| 228 | default: |
| 229 | return ParseMemOperand(Op); |
| 230 | case AsmToken::Register: |
| 231 | // FIXME: if a segment register, this could either be just the seg reg, or |
| 232 | // the start of a memory operand. |
| 233 | return ParseRegister(Op); |
| 234 | case AsmToken::Dollar: { |
| 235 | // $42 -> immediate. |
| 236 | getLexer().Lex(); |
| 237 | MCValue Val; |
| 238 | if (getParser().ParseRelocatableExpression(Val)) |
| 239 | return true; |
| 240 | Op = X86Operand::CreateImm(Val); |
| 241 | return false; |
| 242 | } |
Chris Lattner | e54532b | 2009-07-29 06:33:53 +0000 | [diff] [blame] | 243 | case AsmToken::Star: |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 244 | getLexer().Lex(); // Eat the star. |
| 245 | |
| 246 | if (getLexer().is(AsmToken::Register)) { |
| 247 | if (ParseRegister(Op)) |
| 248 | return true; |
| 249 | } else if (ParseMemOperand(Op)) |
| 250 | return true; |
| 251 | |
| 252 | // FIXME: Note the '*' in the operand for use by the matcher. |
| 253 | return false; |
| 254 | } |
Daniel Dunbar | 78929e5 | 2009-07-20 20:01:54 +0000 | [diff] [blame] | 255 | } |
| 256 | |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 257 | /// ParseMemOperand: segment: disp(basereg, indexreg, scale) |
| 258 | bool X86ATTAsmParser::ParseMemOperand(X86Operand &Op) { |
| 259 | // FIXME: If SegReg ':' (e.g. %gs:), eat and remember. |
| 260 | unsigned SegReg = 0; |
| 261 | |
| 262 | // We have to disambiguate a parenthesized expression "(4+5)" from the start |
| 263 | // of a memory operand with a missing displacement "(%ebx)" or "(,%eax)". The |
| 264 | // only way to do this without lookahead is to eat the ( and see what is after |
| 265 | // it. |
| 266 | MCValue Disp = MCValue::get(0, 0, 0); |
| 267 | if (getLexer().isNot(AsmToken::LParen)) { |
| 268 | if (getParser().ParseRelocatableExpression(Disp)) return true; |
| 269 | |
| 270 | // After parsing the base expression we could either have a parenthesized |
| 271 | // memory address or not. If not, return now. If so, eat the (. |
| 272 | if (getLexer().isNot(AsmToken::LParen)) { |
Daniel Dunbar | 2409171 | 2009-07-31 22:22:54 +0000 | [diff] [blame] | 273 | // Unless we have a segment register, treat this as an immediate. |
| 274 | if (SegReg) |
| 275 | Op = X86Operand::CreateMem(SegReg, Disp, 0, 0, 1); |
| 276 | else |
| 277 | Op = X86Operand::CreateImm(Disp); |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 278 | return false; |
| 279 | } |
| 280 | |
| 281 | // Eat the '('. |
| 282 | getLexer().Lex(); |
| 283 | } else { |
| 284 | // Okay, we have a '('. We don't know if this is an expression or not, but |
| 285 | // so we have to eat the ( to see beyond it. |
| 286 | getLexer().Lex(); // Eat the '('. |
| 287 | |
| 288 | if (getLexer().is(AsmToken::Register) || getLexer().is(AsmToken::Comma)) { |
| 289 | // Nothing to do here, fall into the code below with the '(' part of the |
| 290 | // memory operand consumed. |
| 291 | } else { |
| 292 | // It must be an parenthesized expression, parse it now. |
| 293 | if (getParser().ParseParenRelocatableExpression(Disp)) |
| 294 | return true; |
| 295 | |
| 296 | // After parsing the base expression we could either have a parenthesized |
| 297 | // memory address or not. If not, return now. If so, eat the (. |
| 298 | if (getLexer().isNot(AsmToken::LParen)) { |
Daniel Dunbar | 2409171 | 2009-07-31 22:22:54 +0000 | [diff] [blame] | 299 | // Unless we have a segment register, treat this as an immediate. |
| 300 | if (SegReg) |
| 301 | Op = X86Operand::CreateMem(SegReg, Disp, 0, 0, 1); |
| 302 | else |
| 303 | Op = X86Operand::CreateImm(Disp); |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 304 | return false; |
| 305 | } |
| 306 | |
| 307 | // Eat the '('. |
| 308 | getLexer().Lex(); |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | // If we reached here, then we just ate the ( of the memory operand. Process |
| 313 | // the rest of the memory operand. |
Daniel Dunbar | b7ddef1 | 2009-07-31 20:53:16 +0000 | [diff] [blame] | 314 | unsigned BaseReg = 0, IndexReg = 0, Scale = 1; |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 315 | |
| 316 | if (getLexer().is(AsmToken::Register)) { |
| 317 | if (ParseRegister(Op)) |
| 318 | return true; |
| 319 | BaseReg = Op.getReg(); |
| 320 | } |
| 321 | |
| 322 | if (getLexer().is(AsmToken::Comma)) { |
| 323 | getLexer().Lex(); // Eat the comma. |
| 324 | |
| 325 | // Following the comma we should have either an index register, or a scale |
| 326 | // value. We don't support the later form, but we want to parse it |
| 327 | // correctly. |
| 328 | // |
| 329 | // Not that even though it would be completely consistent to support syntax |
| 330 | // like "1(%eax,,1)", the assembler doesn't. |
| 331 | if (getLexer().is(AsmToken::Register)) { |
| 332 | if (ParseRegister(Op)) |
| 333 | return true; |
| 334 | IndexReg = Op.getReg(); |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 335 | |
| 336 | if (getLexer().isNot(AsmToken::RParen)) { |
| 337 | // Parse the scale amount: |
| 338 | // ::= ',' [scale-expression] |
| 339 | if (getLexer().isNot(AsmToken::Comma)) |
| 340 | return true; |
| 341 | getLexer().Lex(); // Eat the comma. |
| 342 | |
| 343 | if (getLexer().isNot(AsmToken::RParen)) { |
| 344 | SMLoc Loc = getLexer().getTok().getLoc(); |
| 345 | |
| 346 | int64_t ScaleVal; |
| 347 | if (getParser().ParseAbsoluteExpression(ScaleVal)) |
| 348 | return true; |
| 349 | |
| 350 | // Validate the scale amount. |
| 351 | if (ScaleVal != 1 && ScaleVal != 2 && ScaleVal != 4 && ScaleVal != 8) |
| 352 | return Error(Loc, "scale factor in address must be 1, 2, 4 or 8"); |
| 353 | Scale = (unsigned)ScaleVal; |
| 354 | } |
| 355 | } |
| 356 | } else if (getLexer().isNot(AsmToken::RParen)) { |
| 357 | // Otherwise we have the unsupported form of a scale amount without an |
| 358 | // index. |
| 359 | SMLoc Loc = getLexer().getTok().getLoc(); |
| 360 | |
| 361 | int64_t Value; |
| 362 | if (getParser().ParseAbsoluteExpression(Value)) |
| 363 | return true; |
| 364 | |
| 365 | return Error(Loc, "cannot have scale factor without index register"); |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | // Ok, we've eaten the memory operand, verify we have a ')' and eat it too. |
| 370 | if (getLexer().isNot(AsmToken::RParen)) |
| 371 | return Error(getLexer().getTok().getLoc(), |
| 372 | "unexpected token in memory operand"); |
| 373 | getLexer().Lex(); // Eat the ')'. |
| 374 | |
| 375 | Op = X86Operand::CreateMem(SegReg, Disp, BaseReg, IndexReg, Scale); |
| 376 | return false; |
| 377 | } |
| 378 | |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 379 | bool X86ATTAsmParser::ParseInstruction(const StringRef &Name, MCInst &Inst) { |
Daniel Dunbar | 62beebc | 2009-08-07 20:33:39 +0000 | [diff] [blame] | 380 | SmallVector<X86Operand, 8> Operands; |
Daniel Dunbar | fe6759e | 2009-08-07 08:26:05 +0000 | [diff] [blame] | 381 | |
| 382 | Operands.push_back(X86Operand::CreateToken(Name)); |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 383 | |
Daniel Dunbar | a54716c | 2009-07-31 02:32:59 +0000 | [diff] [blame] | 384 | SMLoc Loc = getLexer().getTok().getLoc(); |
Daniel Dunbar | 14c5bf8 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 385 | if (getLexer().isNot(AsmToken::EndOfStatement)) { |
| 386 | // Read the first operand. |
| 387 | Operands.push_back(X86Operand()); |
| 388 | if (ParseOperand(Operands.back())) |
| 389 | return true; |
| 390 | |
| 391 | while (getLexer().is(AsmToken::Comma)) { |
| 392 | getLexer().Lex(); // Eat the comma. |
| 393 | |
| 394 | // Parse and remember the operand. |
| 395 | Operands.push_back(X86Operand()); |
| 396 | if (ParseOperand(Operands.back())) |
| 397 | return true; |
| 398 | } |
| 399 | } |
| 400 | |
Daniel Dunbar | fe6759e | 2009-08-07 08:26:05 +0000 | [diff] [blame] | 401 | if (!MatchInstruction(Operands, Inst)) |
Daniel Dunbar | a54716c | 2009-07-31 02:32:59 +0000 | [diff] [blame] | 402 | return false; |
| 403 | |
| 404 | // FIXME: We should give nicer diagnostics about the exact failure. |
| 405 | |
| 406 | // FIXME: For now we just treat unrecognized instructions as "warnings". |
| 407 | Warning(Loc, "unrecognized instruction"); |
| 408 | |
| 409 | return false; |
Daniel Dunbar | 4b0f4ef | 2009-07-20 18:55:04 +0000 | [diff] [blame] | 410 | } |
| 411 | |
Daniel Dunbar | c7df3cb | 2009-07-17 20:42:00 +0000 | [diff] [blame] | 412 | // Force static initialization. |
| 413 | extern "C" void LLVMInitializeX86AsmParser() { |
Daniel Dunbar | c680b01 | 2009-07-25 06:49:55 +0000 | [diff] [blame] | 414 | RegisterAsmParser<X86ATTAsmParser> X(TheX86_32Target); |
| 415 | RegisterAsmParser<X86ATTAsmParser> Y(TheX86_64Target); |
Daniel Dunbar | c7df3cb | 2009-07-17 20:42:00 +0000 | [diff] [blame] | 416 | } |
Daniel Dunbar | 85f1b39 | 2009-07-29 00:02:19 +0000 | [diff] [blame] | 417 | |
| 418 | #include "X86GenAsmMatcher.inc" |