blob: fbbaa9500c99b298fe1a5524dccc22dd79af3eb9 [file] [log] [blame]
Daniel Dunbar092a9dd2009-07-17 20:42:00 +00001//===-- 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
Evan Cheng94b95502011-07-26 00:24:13 +000010#include "MCTargetDesc/X86BaseInfo.h"
11#include "llvm/MC/MCTargetAsmParser.h"
Kevin Enderby9c656452009-09-10 20:51:44 +000012#include "llvm/MC/MCStreamer.h"
Daniel Dunbar8c2eebe2009-08-31 08:08:38 +000013#include "llvm/MC/MCExpr.h"
Daniel Dunbara027d222009-07-31 02:32:59 +000014#include "llvm/MC/MCInst.h"
Evan Cheng5de728c2011-07-27 23:22:03 +000015#include "llvm/MC/MCRegisterInfo.h"
Evan Chengebdeeab2011-07-08 01:53:10 +000016#include "llvm/MC/MCSubtargetInfo.h"
Chris Lattnerc6ef2772010-01-22 01:44:57 +000017#include "llvm/MC/MCParser/MCAsmLexer.h"
18#include "llvm/MC/MCParser/MCAsmParser.h"
19#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
Chris Lattner33d60d52010-09-22 04:11:10 +000020#include "llvm/ADT/SmallString.h"
21#include "llvm/ADT/SmallVector.h"
Chris Lattner33d60d52010-09-22 04:11:10 +000022#include "llvm/ADT/StringSwitch.h"
23#include "llvm/ADT/Twine.h"
Daniel Dunbar16cdcb32009-07-28 22:40:46 +000024#include "llvm/Support/SourceMgr.h"
Evan Cheng3e74d6f2011-08-24 18:08:43 +000025#include "llvm/Support/TargetRegistry.h"
Daniel Dunbar09062b12010-08-12 00:55:42 +000026#include "llvm/Support/raw_ostream.h"
Evan Chengebdeeab2011-07-08 01:53:10 +000027
Daniel Dunbar092a9dd2009-07-17 20:42:00 +000028using namespace llvm;
29
30namespace {
Benjamin Kramerc6b79ac2009-07-31 11:35:26 +000031struct X86Operand;
Daniel Dunbar16cdcb32009-07-28 22:40:46 +000032
Devang Pateldd929fc2012-01-12 18:03:40 +000033class X86AsmParser : public MCTargetAsmParser {
Evan Chengffc0e732011-07-09 05:47:46 +000034 MCSubtargetInfo &STI;
Daniel Dunbar16cdcb32009-07-28 22:40:46 +000035 MCAsmParser &Parser;
Daniel Dunbar16cdcb32009-07-28 22:40:46 +000036private:
Daniel Dunbar16cdcb32009-07-28 22:40:46 +000037 MCAsmParser &getParser() const { return Parser; }
38
39 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
40
Chris Lattnerd8b7aa22011-10-16 04:47:35 +000041 bool Error(SMLoc L, const Twine &Msg,
42 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()) {
43 return Parser.Error(L, Msg, Ranges);
44 }
Daniel Dunbar16cdcb32009-07-28 22:40:46 +000045
Devang Pateld37ad242012-01-17 18:00:18 +000046 X86Operand *ErrorOperand(SMLoc Loc, StringRef Msg) {
47 Error(Loc, Msg);
48 return 0;
49 }
50
Chris Lattner309264d2010-01-15 18:44:13 +000051 X86Operand *ParseOperand();
Devang Patel0a338862012-01-12 01:36:43 +000052 X86Operand *ParseATTOperand();
53 X86Operand *ParseIntelOperand();
Devang Pateld37ad242012-01-17 18:00:18 +000054 X86Operand *ParseIntelMemOperand();
Devang Patel7c64fe62012-01-23 18:31:58 +000055 X86Operand *ParseIntelBracExpression(unsigned SegReg, unsigned Size);
Chris Lattnereef6d782010-04-17 18:56:34 +000056 X86Operand *ParseMemOperand(unsigned SegReg, SMLoc StartLoc);
Kevin Enderby9c656452009-09-10 20:51:44 +000057
58 bool ParseDirectiveWord(unsigned Size, SMLoc L);
Evan Chengbd27f5a2011-07-27 00:38:12 +000059 bool ParseDirectiveCode(StringRef IDVal, SMLoc L);
Kevin Enderby9c656452009-09-10 20:51:44 +000060
Devang Patelb8ba13f2012-01-18 22:42:29 +000061 bool processInstruction(MCInst &Inst,
62 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
63
Chris Lattner7036f8b2010-09-29 01:42:58 +000064 bool MatchAndEmitInstruction(SMLoc IDLoc,
Chris Lattner7c51a312010-09-29 01:50:45 +000065 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chris Lattner7036f8b2010-09-29 01:42:58 +000066 MCStreamer &Out);
Daniel Dunbar20927f22009-08-07 08:26:05 +000067
Chad Rosier32461762012-08-09 22:04:55 +000068 bool MatchInstruction(SMLoc IDLoc,
69 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
70 SmallVectorImpl<MCInst> &MCInsts);
71
Joerg Sonnenberger96622aa2011-03-18 11:59:40 +000072 /// isSrcOp - Returns true if operand is either (%rsi) or %ds:%(rsi)
Kevin Enderby0f5ab7c2012-03-13 19:47:55 +000073 /// in 64bit mode or (%esi) or %es:(%esi) in 32bit mode.
Joerg Sonnenberger96622aa2011-03-18 11:59:40 +000074 bool isSrcOp(X86Operand &Op);
75
Kevin Enderby0f5ab7c2012-03-13 19:47:55 +000076 /// isDstOp - Returns true if operand is either (%rdi) or %es:(%rdi)
77 /// in 64bit mode or (%edi) or %es:(%edi) in 32bit mode.
Joerg Sonnenberger96622aa2011-03-18 11:59:40 +000078 bool isDstOp(X86Operand &Op);
79
Evan Cheng59ee62d2011-07-11 03:57:24 +000080 bool is64BitMode() const {
Evan Chengebdeeab2011-07-08 01:53:10 +000081 // FIXME: Can tablegen auto-generate this?
Evan Chengffc0e732011-07-09 05:47:46 +000082 return (STI.getFeatureBits() & X86::Mode64Bit) != 0;
Evan Chengebdeeab2011-07-08 01:53:10 +000083 }
Evan Chengbd27f5a2011-07-27 00:38:12 +000084 void SwitchMode() {
85 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(X86::Mode64Bit));
86 setAvailableFeatures(FB);
87 }
Evan Chengebdeeab2011-07-08 01:53:10 +000088
Daniel Dunbar54074b52010-07-19 05:44:09 +000089 /// @name Auto-generated Matcher Functions
90 /// {
Michael J. Spencerc0c8df32010-10-09 11:00:50 +000091
Chris Lattner0692ee62010-09-06 19:11:01 +000092#define GET_ASSEMBLER_HEADER
93#include "X86GenAsmMatcher.inc"
Michael J. Spencerc0c8df32010-10-09 11:00:50 +000094
Daniel Dunbar0e2771f2009-07-29 00:02:19 +000095 /// }
Daniel Dunbar16cdcb32009-07-28 22:40:46 +000096
97public:
Devang Pateldd929fc2012-01-12 18:03:40 +000098 X86AsmParser(MCSubtargetInfo &sti, MCAsmParser &parser)
Devang Patel0db58bf2012-01-31 18:14:05 +000099 : MCTargetAsmParser(), STI(sti), Parser(parser) {
Michael J. Spencerc0c8df32010-10-09 11:00:50 +0000100
Daniel Dunbar54074b52010-07-19 05:44:09 +0000101 // Initialize the set of available features.
Evan Chengffc0e732011-07-09 05:47:46 +0000102 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Daniel Dunbar54074b52010-07-19 05:44:09 +0000103 }
Roman Divackybf755322011-01-27 17:14:22 +0000104 virtual bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000105
Benjamin Kramer38e59892010-07-14 22:38:02 +0000106 virtual bool ParseInstruction(StringRef Name, SMLoc NameLoc,
Chris Lattner98986712010-01-14 22:21:20 +0000107 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Kevin Enderby9c656452009-09-10 20:51:44 +0000108
109 virtual bool ParseDirective(AsmToken DirectiveID);
Devang Patelbe3e3102012-01-30 20:02:42 +0000110
111 bool isParsingIntelSyntax() {
Devang Patel0db58bf2012-01-31 18:14:05 +0000112 return getParser().getAssemblerDialect();
Devang Patelbe3e3102012-01-30 20:02:42 +0000113 }
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000114};
Chris Lattner37dfdec2009-07-29 06:33:53 +0000115} // end anonymous namespace
116
Sean Callanane9b466d2010-01-23 00:40:33 +0000117/// @name Auto-generated Match Functions
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000118/// {
Sean Callanane9b466d2010-01-23 00:40:33 +0000119
Chris Lattnerb8d6e982010-02-09 00:34:28 +0000120static unsigned MatchRegisterName(StringRef Name);
Sean Callanane9b466d2010-01-23 00:40:33 +0000121
122/// }
Chris Lattner37dfdec2009-07-29 06:33:53 +0000123
Craig Topper76bd9382012-07-18 04:59:16 +0000124static bool isImmSExti16i8Value(uint64_t Value) {
Devang Patelb8ba13f2012-01-18 22:42:29 +0000125 return (( Value <= 0x000000000000007FULL)||
126 (0x000000000000FF80ULL <= Value && Value <= 0x000000000000FFFFULL)||
127 (0xFFFFFFFFFFFFFF80ULL <= Value && Value <= 0xFFFFFFFFFFFFFFFFULL));
128}
129
130static bool isImmSExti32i8Value(uint64_t Value) {
131 return (( Value <= 0x000000000000007FULL)||
132 (0x00000000FFFFFF80ULL <= Value && Value <= 0x00000000FFFFFFFFULL)||
133 (0xFFFFFFFFFFFFFF80ULL <= Value && Value <= 0xFFFFFFFFFFFFFFFFULL));
134}
135
136static bool isImmZExtu32u8Value(uint64_t Value) {
137 return (Value <= 0x00000000000000FFULL);
138}
139
140static bool isImmSExti64i8Value(uint64_t Value) {
141 return (( Value <= 0x000000000000007FULL)||
Craig Topper76bd9382012-07-18 04:59:16 +0000142 (0xFFFFFFFFFFFFFF80ULL <= Value && Value <= 0xFFFFFFFFFFFFFFFFULL));
Devang Patelb8ba13f2012-01-18 22:42:29 +0000143}
144
145static bool isImmSExti64i32Value(uint64_t Value) {
146 return (( Value <= 0x000000007FFFFFFFULL)||
Craig Topper76bd9382012-07-18 04:59:16 +0000147 (0xFFFFFFFF80000000ULL <= Value && Value <= 0xFFFFFFFFFFFFFFFFULL));
Devang Patelb8ba13f2012-01-18 22:42:29 +0000148}
Chris Lattner37dfdec2009-07-29 06:33:53 +0000149namespace {
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000150
151/// X86Operand - Instances of this class represent a parsed X86 machine
152/// instruction.
Chris Lattner45220a82010-01-14 21:20:55 +0000153struct X86Operand : public MCParsedAsmOperand {
Chris Lattner1f19f0f2010-01-15 19:06:59 +0000154 enum KindTy {
Daniel Dunbar20927f22009-08-07 08:26:05 +0000155 Token,
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000156 Register,
157 Immediate,
158 Memory
159 } Kind;
160
Chris Lattner29ef9a22010-01-15 18:51:29 +0000161 SMLoc StartLoc, EndLoc;
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000162
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000163 union {
164 struct {
Daniel Dunbar20927f22009-08-07 08:26:05 +0000165 const char *Data;
166 unsigned Length;
167 } Tok;
168
169 struct {
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000170 unsigned RegNo;
171 } Reg;
172
173 struct {
Daniel Dunbar8c2eebe2009-08-31 08:08:38 +0000174 const MCExpr *Val;
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000175 } Imm;
176
177 struct {
178 unsigned SegReg;
Daniel Dunbar8c2eebe2009-08-31 08:08:38 +0000179 const MCExpr *Disp;
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000180 unsigned BaseReg;
181 unsigned IndexReg;
182 unsigned Scale;
Devang Patelc59d9df2012-01-12 01:51:42 +0000183 unsigned Size;
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000184 } Mem;
Daniel Dunbardbd692a2009-07-20 20:01:54 +0000185 };
Daniel Dunbar092a9dd2009-07-17 20:42:00 +0000186
Chris Lattner0a3c5a52010-01-15 19:33:43 +0000187 X86Operand(KindTy K, SMLoc Start, SMLoc End)
Chris Lattner1f19f0f2010-01-15 19:06:59 +0000188 : Kind(K), StartLoc(Start), EndLoc(End) {}
Daniel Dunbarc918d602010-05-04 16:12:42 +0000189
Chris Lattner1f19f0f2010-01-15 19:06:59 +0000190 /// getStartLoc - Get the location of the first token of this operand.
191 SMLoc getStartLoc() const { return StartLoc; }
192 /// getEndLoc - Get the location of the last token of this operand.
193 SMLoc getEndLoc() const { return EndLoc; }
Chad Rosier36b8fed2012-06-27 22:34:28 +0000194
Chris Lattnerd8b7aa22011-10-16 04:47:35 +0000195 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
Chris Lattner1f19f0f2010-01-15 19:06:59 +0000196
Jim Grosbachb7f689b2011-07-13 15:34:57 +0000197 virtual void print(raw_ostream &OS) const {}
Daniel Dunbarb3cb6962010-08-11 06:37:04 +0000198
Daniel Dunbar20927f22009-08-07 08:26:05 +0000199 StringRef getToken() const {
200 assert(Kind == Token && "Invalid access!");
201 return StringRef(Tok.Data, Tok.Length);
202 }
Daniel Dunbarc918d602010-05-04 16:12:42 +0000203 void setTokenValue(StringRef Value) {
204 assert(Kind == Token && "Invalid access!");
205 Tok.Data = Value.data();
206 Tok.Length = Value.size();
207 }
Daniel Dunbar20927f22009-08-07 08:26:05 +0000208
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000209 unsigned getReg() const {
210 assert(Kind == Register && "Invalid access!");
211 return Reg.RegNo;
212 }
Daniel Dunbara2edbab2009-07-28 20:47:52 +0000213
Daniel Dunbar8c2eebe2009-08-31 08:08:38 +0000214 const MCExpr *getImm() const {
Daniel Dunbar022e2a82009-07-31 20:53:16 +0000215 assert(Kind == Immediate && "Invalid access!");
216 return Imm.Val;
217 }
218
Daniel Dunbar8c2eebe2009-08-31 08:08:38 +0000219 const MCExpr *getMemDisp() const {
Daniel Dunbar022e2a82009-07-31 20:53:16 +0000220 assert(Kind == Memory && "Invalid access!");
221 return Mem.Disp;
222 }
223 unsigned getMemSegReg() const {
224 assert(Kind == Memory && "Invalid access!");
225 return Mem.SegReg;
226 }
227 unsigned getMemBaseReg() const {
228 assert(Kind == Memory && "Invalid access!");
229 return Mem.BaseReg;
230 }
231 unsigned getMemIndexReg() const {
232 assert(Kind == Memory && "Invalid access!");
233 return Mem.IndexReg;
234 }
235 unsigned getMemScale() const {
236 assert(Kind == Memory && "Invalid access!");
237 return Mem.Scale;
238 }
239
Daniel Dunbara3741fa2009-08-08 07:50:56 +0000240 bool isToken() const {return Kind == Token; }
Daniel Dunbar20927f22009-08-07 08:26:05 +0000241
242 bool isImm() const { return Kind == Immediate; }
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000243
Daniel Dunbar62e4c672010-05-22 21:02:33 +0000244 bool isImmSExti16i8() const {
Daniel Dunbar5fe63382009-08-09 07:20:21 +0000245 if (!isImm())
246 return false;
247
Daniel Dunbar62e4c672010-05-22 21:02:33 +0000248 // If this isn't a constant expr, just assume it fits and let relaxation
249 // handle it.
250 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
251 if (!CE)
252 return true;
Daniel Dunbar5fe63382009-08-09 07:20:21 +0000253
Daniel Dunbar62e4c672010-05-22 21:02:33 +0000254 // Otherwise, check the value is in a range that makes sense for this
255 // extension.
Devang Patelb8ba13f2012-01-18 22:42:29 +0000256 return isImmSExti16i8Value(CE->getValue());
Daniel Dunbar5fe63382009-08-09 07:20:21 +0000257 }
Daniel Dunbar62e4c672010-05-22 21:02:33 +0000258 bool isImmSExti32i8() const {
Daniel Dunbar1fe591d2010-05-20 20:20:39 +0000259 if (!isImm())
260 return false;
261
Daniel Dunbar62e4c672010-05-22 21:02:33 +0000262 // If this isn't a constant expr, just assume it fits and let relaxation
263 // handle it.
264 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
265 if (!CE)
266 return true;
Daniel Dunbar1fe591d2010-05-20 20:20:39 +0000267
Daniel Dunbar62e4c672010-05-22 21:02:33 +0000268 // Otherwise, check the value is in a range that makes sense for this
269 // extension.
Devang Patelb8ba13f2012-01-18 22:42:29 +0000270 return isImmSExti32i8Value(CE->getValue());
Daniel Dunbar62e4c672010-05-22 21:02:33 +0000271 }
Kevin Enderbyc37d4bb2011-07-27 23:01:50 +0000272 bool isImmZExtu32u8() const {
273 if (!isImm())
274 return false;
275
276 // If this isn't a constant expr, just assume it fits and let relaxation
277 // handle it.
278 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
279 if (!CE)
280 return true;
281
282 // Otherwise, check the value is in a range that makes sense for this
283 // extension.
Devang Patelb8ba13f2012-01-18 22:42:29 +0000284 return isImmZExtu32u8Value(CE->getValue());
Kevin Enderbyc37d4bb2011-07-27 23:01:50 +0000285 }
Daniel Dunbar62e4c672010-05-22 21:02:33 +0000286 bool isImmSExti64i8() const {
287 if (!isImm())
288 return false;
289
290 // If this isn't a constant expr, just assume it fits and let relaxation
291 // handle it.
292 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
293 if (!CE)
294 return true;
295
296 // Otherwise, check the value is in a range that makes sense for this
297 // extension.
Devang Patelb8ba13f2012-01-18 22:42:29 +0000298 return isImmSExti64i8Value(CE->getValue());
Daniel Dunbar62e4c672010-05-22 21:02:33 +0000299 }
300 bool isImmSExti64i32() const {
301 if (!isImm())
302 return false;
303
304 // If this isn't a constant expr, just assume it fits and let relaxation
305 // handle it.
306 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
307 if (!CE)
308 return true;
309
310 // Otherwise, check the value is in a range that makes sense for this
311 // extension.
Devang Patelb8ba13f2012-01-18 22:42:29 +0000312 return isImmSExti64i32Value(CE->getValue());
Daniel Dunbar1fe591d2010-05-20 20:20:39 +0000313 }
314
Daniel Dunbar20927f22009-08-07 08:26:05 +0000315 bool isMem() const { return Kind == Memory; }
Chad Rosier36b8fed2012-06-27 22:34:28 +0000316 bool isMem8() const {
Devang Patelc59d9df2012-01-12 01:51:42 +0000317 return Kind == Memory && (!Mem.Size || Mem.Size == 8);
318 }
Chad Rosier36b8fed2012-06-27 22:34:28 +0000319 bool isMem16() const {
Devang Patelc59d9df2012-01-12 01:51:42 +0000320 return Kind == Memory && (!Mem.Size || Mem.Size == 16);
321 }
Chad Rosier36b8fed2012-06-27 22:34:28 +0000322 bool isMem32() const {
Devang Patelc59d9df2012-01-12 01:51:42 +0000323 return Kind == Memory && (!Mem.Size || Mem.Size == 32);
324 }
Chad Rosier36b8fed2012-06-27 22:34:28 +0000325 bool isMem64() const {
Devang Patelc59d9df2012-01-12 01:51:42 +0000326 return Kind == Memory && (!Mem.Size || Mem.Size == 64);
327 }
Chad Rosier36b8fed2012-06-27 22:34:28 +0000328 bool isMem80() const {
Devang Patelc59d9df2012-01-12 01:51:42 +0000329 return Kind == Memory && (!Mem.Size || Mem.Size == 80);
330 }
Chad Rosier36b8fed2012-06-27 22:34:28 +0000331 bool isMem128() const {
Devang Patelc59d9df2012-01-12 01:51:42 +0000332 return Kind == Memory && (!Mem.Size || Mem.Size == 128);
333 }
Chad Rosier36b8fed2012-06-27 22:34:28 +0000334 bool isMem256() const {
Devang Patelc59d9df2012-01-12 01:51:42 +0000335 return Kind == Memory && (!Mem.Size || Mem.Size == 256);
336 }
Daniel Dunbar20927f22009-08-07 08:26:05 +0000337
Craig Topper75dc33a2012-07-18 04:11:12 +0000338 bool isMemVX32() const {
339 return Kind == Memory && (!Mem.Size || Mem.Size == 32) &&
340 getMemIndexReg() >= X86::XMM0 && getMemIndexReg() <= X86::XMM15;
341 }
342 bool isMemVY32() const {
343 return Kind == Memory && (!Mem.Size || Mem.Size == 32) &&
344 getMemIndexReg() >= X86::YMM0 && getMemIndexReg() <= X86::YMM15;
345 }
346 bool isMemVX64() const {
347 return Kind == Memory && (!Mem.Size || Mem.Size == 64) &&
348 getMemIndexReg() >= X86::XMM0 && getMemIndexReg() <= X86::XMM15;
349 }
350 bool isMemVY64() const {
351 return Kind == Memory && (!Mem.Size || Mem.Size == 64) &&
352 getMemIndexReg() >= X86::YMM0 && getMemIndexReg() <= X86::YMM15;
353 }
354
Daniel Dunbarb834f5d2010-01-30 01:02:48 +0000355 bool isAbsMem() const {
356 return Kind == Memory && !getMemSegReg() && !getMemBaseReg() &&
Daniel Dunbar7b9147a2010-02-02 21:44:16 +0000357 !getMemIndexReg() && getMemScale() == 1;
Daniel Dunbarb834f5d2010-01-30 01:02:48 +0000358 }
359
Daniel Dunbar20927f22009-08-07 08:26:05 +0000360 bool isReg() const { return Kind == Register; }
361
Daniel Dunbar9c60f532010-02-13 00:17:21 +0000362 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
363 // Add as immediates when possible.
364 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
365 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
366 else
367 Inst.addOperand(MCOperand::CreateExpr(Expr));
368 }
369
Daniel Dunbar5c468e32009-08-10 21:00:45 +0000370 void addRegOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar20927f22009-08-07 08:26:05 +0000371 assert(N == 1 && "Invalid number of operands!");
372 Inst.addOperand(MCOperand::CreateReg(getReg()));
373 }
374
Daniel Dunbar5c468e32009-08-10 21:00:45 +0000375 void addImmOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar20927f22009-08-07 08:26:05 +0000376 assert(N == 1 && "Invalid number of operands!");
Daniel Dunbar9c60f532010-02-13 00:17:21 +0000377 addExpr(Inst, getImm());
Daniel Dunbar20927f22009-08-07 08:26:05 +0000378 }
379
Chad Rosier36b8fed2012-06-27 22:34:28 +0000380 void addMem8Operands(MCInst &Inst, unsigned N) const {
381 addMemOperands(Inst, N);
Devang Patelc59d9df2012-01-12 01:51:42 +0000382 }
Chad Rosier36b8fed2012-06-27 22:34:28 +0000383 void addMem16Operands(MCInst &Inst, unsigned N) const {
384 addMemOperands(Inst, N);
Devang Patelc59d9df2012-01-12 01:51:42 +0000385 }
Chad Rosier36b8fed2012-06-27 22:34:28 +0000386 void addMem32Operands(MCInst &Inst, unsigned N) const {
387 addMemOperands(Inst, N);
Devang Patelc59d9df2012-01-12 01:51:42 +0000388 }
Chad Rosier36b8fed2012-06-27 22:34:28 +0000389 void addMem64Operands(MCInst &Inst, unsigned N) const {
390 addMemOperands(Inst, N);
Devang Patelc59d9df2012-01-12 01:51:42 +0000391 }
Chad Rosier36b8fed2012-06-27 22:34:28 +0000392 void addMem80Operands(MCInst &Inst, unsigned N) const {
393 addMemOperands(Inst, N);
Devang Patelc59d9df2012-01-12 01:51:42 +0000394 }
Chad Rosier36b8fed2012-06-27 22:34:28 +0000395 void addMem128Operands(MCInst &Inst, unsigned N) const {
396 addMemOperands(Inst, N);
Devang Patelc59d9df2012-01-12 01:51:42 +0000397 }
Chad Rosier36b8fed2012-06-27 22:34:28 +0000398 void addMem256Operands(MCInst &Inst, unsigned N) const {
399 addMemOperands(Inst, N);
Devang Patelc59d9df2012-01-12 01:51:42 +0000400 }
Craig Topper75dc33a2012-07-18 04:11:12 +0000401 void addMemVX32Operands(MCInst &Inst, unsigned N) const {
402 addMemOperands(Inst, N);
403 }
404 void addMemVY32Operands(MCInst &Inst, unsigned N) const {
405 addMemOperands(Inst, N);
406 }
407 void addMemVX64Operands(MCInst &Inst, unsigned N) const {
408 addMemOperands(Inst, N);
409 }
410 void addMemVY64Operands(MCInst &Inst, unsigned N) const {
411 addMemOperands(Inst, N);
412 }
Devang Patelc59d9df2012-01-12 01:51:42 +0000413
Daniel Dunbar5c468e32009-08-10 21:00:45 +0000414 void addMemOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbarec2b1f12010-01-30 00:24:00 +0000415 assert((N == 5) && "Invalid number of operands!");
Daniel Dunbar20927f22009-08-07 08:26:05 +0000416 Inst.addOperand(MCOperand::CreateReg(getMemBaseReg()));
417 Inst.addOperand(MCOperand::CreateImm(getMemScale()));
418 Inst.addOperand(MCOperand::CreateReg(getMemIndexReg()));
Daniel Dunbar9c60f532010-02-13 00:17:21 +0000419 addExpr(Inst, getMemDisp());
Daniel Dunbarec2b1f12010-01-30 00:24:00 +0000420 Inst.addOperand(MCOperand::CreateReg(getMemSegReg()));
421 }
Daniel Dunbar20927f22009-08-07 08:26:05 +0000422
Daniel Dunbarb834f5d2010-01-30 01:02:48 +0000423 void addAbsMemOperands(MCInst &Inst, unsigned N) const {
424 assert((N == 1) && "Invalid number of operands!");
Kevin Enderbyb80d5712012-02-23 18:18:17 +0000425 // Add as immediates when possible.
426 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getMemDisp()))
427 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
428 else
429 Inst.addOperand(MCOperand::CreateExpr(getMemDisp()));
Daniel Dunbarb834f5d2010-01-30 01:02:48 +0000430 }
431
Chris Lattnerb4307b32010-01-15 19:28:38 +0000432 static X86Operand *CreateToken(StringRef Str, SMLoc Loc) {
Benjamin Kramerf82edaf2011-10-16 11:28:29 +0000433 SMLoc EndLoc = SMLoc::getFromPointer(Loc.getPointer() + Str.size() - 1);
434 X86Operand *Res = new X86Operand(Token, Loc, EndLoc);
Chris Lattner29ef9a22010-01-15 18:51:29 +0000435 Res->Tok.Data = Str.data();
436 Res->Tok.Length = Str.size();
Daniel Dunbar20927f22009-08-07 08:26:05 +0000437 return Res;
438 }
439
Chris Lattner29ef9a22010-01-15 18:51:29 +0000440 static X86Operand *CreateReg(unsigned RegNo, SMLoc StartLoc, SMLoc EndLoc) {
Chris Lattner1f19f0f2010-01-15 19:06:59 +0000441 X86Operand *Res = new X86Operand(Register, StartLoc, EndLoc);
Chris Lattner29ef9a22010-01-15 18:51:29 +0000442 Res->Reg.RegNo = RegNo;
Chris Lattner29ef9a22010-01-15 18:51:29 +0000443 return Res;
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000444 }
Daniel Dunbar20927f22009-08-07 08:26:05 +0000445
Chris Lattnerb4307b32010-01-15 19:28:38 +0000446 static X86Operand *CreateImm(const MCExpr *Val, SMLoc StartLoc, SMLoc EndLoc){
447 X86Operand *Res = new X86Operand(Immediate, StartLoc, EndLoc);
Chris Lattner29ef9a22010-01-15 18:51:29 +0000448 Res->Imm.Val = Val;
449 return Res;
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000450 }
Daniel Dunbar20927f22009-08-07 08:26:05 +0000451
Daniel Dunbarb834f5d2010-01-30 01:02:48 +0000452 /// Create an absolute memory operand.
453 static X86Operand *CreateMem(const MCExpr *Disp, SMLoc StartLoc,
Devang Patelc59d9df2012-01-12 01:51:42 +0000454 SMLoc EndLoc, unsigned Size = 0) {
Daniel Dunbarb834f5d2010-01-30 01:02:48 +0000455 X86Operand *Res = new X86Operand(Memory, StartLoc, EndLoc);
456 Res->Mem.SegReg = 0;
457 Res->Mem.Disp = Disp;
458 Res->Mem.BaseReg = 0;
459 Res->Mem.IndexReg = 0;
Daniel Dunbar7b9147a2010-02-02 21:44:16 +0000460 Res->Mem.Scale = 1;
Devang Patelc59d9df2012-01-12 01:51:42 +0000461 Res->Mem.Size = Size;
Daniel Dunbarb834f5d2010-01-30 01:02:48 +0000462 return Res;
463 }
464
465 /// Create a generalized memory operand.
Chris Lattner309264d2010-01-15 18:44:13 +0000466 static X86Operand *CreateMem(unsigned SegReg, const MCExpr *Disp,
467 unsigned BaseReg, unsigned IndexReg,
Devang Patelc59d9df2012-01-12 01:51:42 +0000468 unsigned Scale, SMLoc StartLoc, SMLoc EndLoc,
469 unsigned Size = 0) {
Daniel Dunbarb834f5d2010-01-30 01:02:48 +0000470 // We should never just have a displacement, that should be parsed as an
471 // absolute memory operand.
Daniel Dunbarc09e4112009-07-31 22:22:54 +0000472 assert((SegReg || BaseReg || IndexReg) && "Invalid memory operand!");
473
Daniel Dunbar022e2a82009-07-31 20:53:16 +0000474 // The scale should always be one of {1,2,4,8}.
475 assert(((Scale == 1 || Scale == 2 || Scale == 4 || Scale == 8)) &&
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000476 "Invalid scale!");
Chris Lattner0a3c5a52010-01-15 19:33:43 +0000477 X86Operand *Res = new X86Operand(Memory, StartLoc, EndLoc);
Chris Lattner29ef9a22010-01-15 18:51:29 +0000478 Res->Mem.SegReg = SegReg;
479 Res->Mem.Disp = Disp;
480 Res->Mem.BaseReg = BaseReg;
481 Res->Mem.IndexReg = IndexReg;
482 Res->Mem.Scale = Scale;
Devang Patelc59d9df2012-01-12 01:51:42 +0000483 Res->Mem.Size = Size;
Chris Lattner29ef9a22010-01-15 18:51:29 +0000484 return Res;
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000485 }
486};
Daniel Dunbara3af3702009-07-20 18:55:04 +0000487
Chris Lattner37dfdec2009-07-29 06:33:53 +0000488} // end anonymous namespace.
Daniel Dunbara2edbab2009-07-28 20:47:52 +0000489
Devang Pateldd929fc2012-01-12 18:03:40 +0000490bool X86AsmParser::isSrcOp(X86Operand &Op) {
Evan Cheng59ee62d2011-07-11 03:57:24 +0000491 unsigned basereg = is64BitMode() ? X86::RSI : X86::ESI;
Joerg Sonnenberger96622aa2011-03-18 11:59:40 +0000492
493 return (Op.isMem() &&
494 (Op.Mem.SegReg == 0 || Op.Mem.SegReg == X86::DS) &&
495 isa<MCConstantExpr>(Op.Mem.Disp) &&
496 cast<MCConstantExpr>(Op.Mem.Disp)->getValue() == 0 &&
497 Op.Mem.BaseReg == basereg && Op.Mem.IndexReg == 0);
498}
499
Devang Pateldd929fc2012-01-12 18:03:40 +0000500bool X86AsmParser::isDstOp(X86Operand &Op) {
Evan Cheng59ee62d2011-07-11 03:57:24 +0000501 unsigned basereg = is64BitMode() ? X86::RDI : X86::EDI;
Joerg Sonnenberger96622aa2011-03-18 11:59:40 +0000502
Chad Rosier36b8fed2012-06-27 22:34:28 +0000503 return Op.isMem() &&
Kevin Enderby0f5ab7c2012-03-13 19:47:55 +0000504 (Op.Mem.SegReg == 0 || Op.Mem.SegReg == X86::ES) &&
Joerg Sonnenberger96622aa2011-03-18 11:59:40 +0000505 isa<MCConstantExpr>(Op.Mem.Disp) &&
506 cast<MCConstantExpr>(Op.Mem.Disp)->getValue() == 0 &&
507 Op.Mem.BaseReg == basereg && Op.Mem.IndexReg == 0;
508}
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000509
Devang Pateldd929fc2012-01-12 18:03:40 +0000510bool X86AsmParser::ParseRegister(unsigned &RegNo,
511 SMLoc &StartLoc, SMLoc &EndLoc) {
Chris Lattner23075742010-01-15 18:27:19 +0000512 RegNo = 0;
Devang Patelbe3e3102012-01-30 20:02:42 +0000513 if (!isParsingIntelSyntax()) {
Devang Patel1aea4302012-01-20 22:32:05 +0000514 const AsmToken &TokPercent = Parser.getTok();
Devang Pateld37ad242012-01-17 18:00:18 +0000515 assert(TokPercent.is(AsmToken::Percent) && "Invalid token kind!");
516 StartLoc = TokPercent.getLoc();
517 Parser.Lex(); // Eat percent token.
518 }
Kevin Enderby7b4608d2009-09-03 17:15:07 +0000519
Sean Callanan18b83232010-01-19 21:44:56 +0000520 const AsmToken &Tok = Parser.getTok();
Devang Patel1aea4302012-01-20 22:32:05 +0000521 if (Tok.isNot(AsmToken::Identifier)) {
Devang Patelbe3e3102012-01-30 20:02:42 +0000522 if (isParsingIntelSyntax()) return true;
Benjamin Kramer5efabcf2011-10-16 12:10:27 +0000523 return Error(StartLoc, "invalid register name",
524 SMRange(StartLoc, Tok.getEndLoc()));
Devang Patel1aea4302012-01-20 22:32:05 +0000525 }
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000526
Kevin Enderby7b4608d2009-09-03 17:15:07 +0000527 RegNo = MatchRegisterName(Tok.getString());
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000528
Chris Lattner33d60d52010-09-22 04:11:10 +0000529 // If the match failed, try the register name as lowercase.
530 if (RegNo == 0)
Benjamin Kramer59085362011-11-06 20:37:06 +0000531 RegNo = MatchRegisterName(Tok.getString().lower());
Michael J. Spencerc0c8df32010-10-09 11:00:50 +0000532
Evan Cheng5de728c2011-07-27 23:22:03 +0000533 if (!is64BitMode()) {
534 // FIXME: This should be done using Requires<In32BitMode> and
535 // Requires<In64BitMode> so "eiz" usage in 64-bit instructions can be also
536 // checked.
537 // FIXME: Check AH, CH, DH, BH cannot be used in an instruction requiring a
538 // REX prefix.
539 if (RegNo == X86::RIZ ||
540 X86MCRegisterClasses[X86::GR64RegClassID].contains(RegNo) ||
541 X86II::isX86_64NonExtLowByteReg(RegNo) ||
542 X86II::isX86_64ExtendedReg(RegNo))
Benjamin Kramer5efabcf2011-10-16 12:10:27 +0000543 return Error(StartLoc, "register %"
544 + Tok.getString() + " is only available in 64-bit mode",
545 SMRange(StartLoc, Tok.getEndLoc()));
Evan Cheng5de728c2011-07-27 23:22:03 +0000546 }
Bruno Cardoso Lopes3c8e1be2010-07-24 00:06:39 +0000547
Chris Lattner33d60d52010-09-22 04:11:10 +0000548 // Parse "%st" as "%st(0)" and "%st(1)", which is multiple tokens.
549 if (RegNo == 0 && (Tok.getString() == "st" || Tok.getString() == "ST")) {
Chris Lattnere16b0fc2010-02-09 00:49:22 +0000550 RegNo = X86::ST0;
551 EndLoc = Tok.getLoc();
552 Parser.Lex(); // Eat 'st'
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000553
Chris Lattnere16b0fc2010-02-09 00:49:22 +0000554 // Check to see if we have '(4)' after %st.
555 if (getLexer().isNot(AsmToken::LParen))
556 return false;
557 // Lex the paren.
558 getParser().Lex();
559
560 const AsmToken &IntTok = Parser.getTok();
561 if (IntTok.isNot(AsmToken::Integer))
562 return Error(IntTok.getLoc(), "expected stack index");
563 switch (IntTok.getIntVal()) {
564 case 0: RegNo = X86::ST0; break;
565 case 1: RegNo = X86::ST1; break;
566 case 2: RegNo = X86::ST2; break;
567 case 3: RegNo = X86::ST3; break;
568 case 4: RegNo = X86::ST4; break;
569 case 5: RegNo = X86::ST5; break;
570 case 6: RegNo = X86::ST6; break;
571 case 7: RegNo = X86::ST7; break;
572 default: return Error(IntTok.getLoc(), "invalid stack index");
573 }
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000574
Chris Lattnere16b0fc2010-02-09 00:49:22 +0000575 if (getParser().Lex().isNot(AsmToken::RParen))
576 return Error(Parser.getTok().getLoc(), "expected ')'");
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000577
Chris Lattnere16b0fc2010-02-09 00:49:22 +0000578 EndLoc = Tok.getLoc();
579 Parser.Lex(); // Eat ')'
580 return false;
581 }
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000582
Chris Lattner645b2092010-06-24 07:29:18 +0000583 // If this is "db[0-7]", match it as an alias
584 // for dr[0-7].
585 if (RegNo == 0 && Tok.getString().size() == 3 &&
586 Tok.getString().startswith("db")) {
587 switch (Tok.getString()[2]) {
588 case '0': RegNo = X86::DR0; break;
589 case '1': RegNo = X86::DR1; break;
590 case '2': RegNo = X86::DR2; break;
591 case '3': RegNo = X86::DR3; break;
592 case '4': RegNo = X86::DR4; break;
593 case '5': RegNo = X86::DR5; break;
594 case '6': RegNo = X86::DR6; break;
595 case '7': RegNo = X86::DR7; break;
596 }
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000597
Chris Lattner645b2092010-06-24 07:29:18 +0000598 if (RegNo != 0) {
599 EndLoc = Tok.getLoc();
600 Parser.Lex(); // Eat it.
601 return false;
602 }
603 }
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000604
Devang Patel1aea4302012-01-20 22:32:05 +0000605 if (RegNo == 0) {
Devang Patelbe3e3102012-01-30 20:02:42 +0000606 if (isParsingIntelSyntax()) return true;
Benjamin Kramer5efabcf2011-10-16 12:10:27 +0000607 return Error(StartLoc, "invalid register name",
608 SMRange(StartLoc, Tok.getEndLoc()));
Devang Patel1aea4302012-01-20 22:32:05 +0000609 }
Daniel Dunbar0e2771f2009-07-29 00:02:19 +0000610
Benjamin Kramer5efabcf2011-10-16 12:10:27 +0000611 EndLoc = Tok.getEndLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +0000612 Parser.Lex(); // Eat identifier token.
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000613 return false;
Daniel Dunbar092a9dd2009-07-17 20:42:00 +0000614}
615
Devang Pateldd929fc2012-01-12 18:03:40 +0000616X86Operand *X86AsmParser::ParseOperand() {
Devang Patelbe3e3102012-01-30 20:02:42 +0000617 if (isParsingIntelSyntax())
Devang Patel0a338862012-01-12 01:36:43 +0000618 return ParseIntelOperand();
619 return ParseATTOperand();
620}
621
Devang Pateld37ad242012-01-17 18:00:18 +0000622/// getIntelMemOperandSize - Return intel memory operand size.
623static unsigned getIntelMemOperandSize(StringRef OpStr) {
624 unsigned Size = 0;
Devang Patel0a338862012-01-12 01:36:43 +0000625 if (OpStr == "BYTE") Size = 8;
626 if (OpStr == "WORD") Size = 16;
627 if (OpStr == "DWORD") Size = 32;
628 if (OpStr == "QWORD") Size = 64;
629 if (OpStr == "XWORD") Size = 80;
630 if (OpStr == "XMMWORD") Size = 128;
631 if (OpStr == "YMMWORD") Size = 256;
Devang Pateld37ad242012-01-17 18:00:18 +0000632 return Size;
Devang Patel0a338862012-01-12 01:36:43 +0000633}
634
Devang Patel7c64fe62012-01-23 18:31:58 +0000635X86Operand *X86AsmParser::ParseIntelBracExpression(unsigned SegReg,
636 unsigned Size) {
637 unsigned BaseReg = 0, IndexReg = 0, Scale = 1;
Devang Patel0a338862012-01-12 01:36:43 +0000638 SMLoc Start = Parser.getTok().getLoc(), End;
639
Devang Pateld37ad242012-01-17 18:00:18 +0000640 const MCExpr *Disp = MCConstantExpr::Create(0, getParser().getContext());
641 // Parse [ BaseReg + Scale*IndexReg + Disp ] or [ symbol ]
642
643 // Eat '['
644 if (getLexer().isNot(AsmToken::LBrac))
645 return ErrorOperand(Start, "Expected '[' token!");
646 Parser.Lex();
Chad Rosier36b8fed2012-06-27 22:34:28 +0000647
Devang Pateld37ad242012-01-17 18:00:18 +0000648 if (getLexer().is(AsmToken::Identifier)) {
649 // Parse BaseReg
Devang Patel1aea4302012-01-20 22:32:05 +0000650 if (ParseRegister(BaseReg, Start, End)) {
Devang Pateld37ad242012-01-17 18:00:18 +0000651 // Handle '[' 'symbol' ']'
Devang Pateld37ad242012-01-17 18:00:18 +0000652 if (getParser().ParseExpression(Disp, End)) return 0;
653 if (getLexer().isNot(AsmToken::RBrac))
Devang Patelbc51e502012-01-17 19:09:22 +0000654 return ErrorOperand(Start, "Expected ']' token!");
Devang Pateld37ad242012-01-17 18:00:18 +0000655 Parser.Lex();
656 return X86Operand::CreateMem(Disp, Start, End, Size);
657 }
658 } else if (getLexer().is(AsmToken::Integer)) {
Devang Patel3e081312012-01-23 20:20:06 +0000659 int64_t Val = Parser.getTok().getIntVal();
Devang Pateld37ad242012-01-17 18:00:18 +0000660 Parser.Lex();
Devang Patel3e081312012-01-23 20:20:06 +0000661 SMLoc Loc = Parser.getTok().getLoc();
662 if (getLexer().is(AsmToken::RBrac)) {
663 // Handle '[' number ']'
664 Parser.Lex();
Devang Patela28101e2012-01-27 19:48:28 +0000665 const MCExpr *Disp = MCConstantExpr::Create(Val, getContext());
666 if (SegReg)
667 return X86Operand::CreateMem(SegReg, Disp, 0, 0, Scale,
668 Start, End, Size);
669 return X86Operand::CreateMem(Disp, Start, End, Size);
Devang Patel3e081312012-01-23 20:20:06 +0000670 } else if (getLexer().is(AsmToken::Star)) {
671 // Handle '[' Scale*IndexReg ']'
672 Parser.Lex();
673 SMLoc IdxRegLoc = Parser.getTok().getLoc();
Craig Topper833d7f82012-07-18 04:36:35 +0000674 if (ParseRegister(IndexReg, IdxRegLoc, End))
675 return ErrorOperand(IdxRegLoc, "Expected register");
Devang Patel3e081312012-01-23 20:20:06 +0000676 Scale = Val;
677 } else
Craig Topper833d7f82012-07-18 04:36:35 +0000678 return ErrorOperand(Loc, "Unexpected token");
Devang Pateld37ad242012-01-17 18:00:18 +0000679 }
680
681 if (getLexer().is(AsmToken::Plus) || getLexer().is(AsmToken::Minus)) {
682 bool isPlus = getLexer().is(AsmToken::Plus);
683 Parser.Lex();
684 SMLoc PlusLoc = Parser.getTok().getLoc();
685 if (getLexer().is(AsmToken::Integer)) {
686 int64_t Val = Parser.getTok().getIntVal();
687 Parser.Lex();
688 if (getLexer().is(AsmToken::Star)) {
Devang Patelbc51e502012-01-17 19:09:22 +0000689 Parser.Lex();
690 SMLoc IdxRegLoc = Parser.getTok().getLoc();
Craig Topper833d7f82012-07-18 04:36:35 +0000691 if (ParseRegister(IndexReg, IdxRegLoc, End))
692 return ErrorOperand(IdxRegLoc, "Expected register");
Devang Patelbc51e502012-01-17 19:09:22 +0000693 Scale = Val;
Devang Pateld37ad242012-01-17 18:00:18 +0000694 } else if (getLexer().is(AsmToken::RBrac)) {
Devang Patelbc51e502012-01-17 19:09:22 +0000695 const MCExpr *ValExpr = MCConstantExpr::Create(Val, getContext());
Devang Patele60540f2012-01-19 18:15:51 +0000696 Disp = isPlus ? ValExpr : MCConstantExpr::Create(0-Val, getContext());
Devang Pateld37ad242012-01-17 18:00:18 +0000697 } else
Devang Patelbc51e502012-01-17 19:09:22 +0000698 return ErrorOperand(PlusLoc, "unexpected token after +");
Devang Patelf2d21372012-01-23 22:35:25 +0000699 } else if (getLexer().is(AsmToken::Identifier)) {
Devang Patel392ad6d2012-01-23 23:56:33 +0000700 // This could be an index register or a displacement expression.
Devang Patelf2d21372012-01-23 22:35:25 +0000701 End = Parser.getTok().getLoc();
702 if (!IndexReg)
703 ParseRegister(IndexReg, Start, End);
Chad Rosier36b8fed2012-06-27 22:34:28 +0000704 else if (getParser().ParseExpression(Disp, End)) return 0;
Devang Patelf2d21372012-01-23 22:35:25 +0000705 }
Devang Pateld37ad242012-01-17 18:00:18 +0000706 }
707
708 if (getLexer().isNot(AsmToken::RBrac))
709 if (getParser().ParseExpression(Disp, End)) return 0;
710
711 End = Parser.getTok().getLoc();
712 if (getLexer().isNot(AsmToken::RBrac))
713 return ErrorOperand(End, "expected ']' token!");
714 Parser.Lex();
715 End = Parser.getTok().getLoc();
Devang Patelfdd3b302012-01-20 21:21:01 +0000716
717 // handle [-42]
718 if (!BaseReg && !IndexReg)
719 return X86Operand::CreateMem(Disp, Start, End, Size);
720
Devang Pateld37ad242012-01-17 18:00:18 +0000721 return X86Operand::CreateMem(SegReg, Disp, BaseReg, IndexReg, Scale,
Devang Patelbc51e502012-01-17 19:09:22 +0000722 Start, End, Size);
Devang Pateld37ad242012-01-17 18:00:18 +0000723}
724
725/// ParseIntelMemOperand - Parse intel style memory operand.
726X86Operand *X86AsmParser::ParseIntelMemOperand() {
727 const AsmToken &Tok = Parser.getTok();
728 SMLoc Start = Parser.getTok().getLoc(), End;
Devang Patel7c64fe62012-01-23 18:31:58 +0000729 unsigned SegReg = 0;
Devang Pateld37ad242012-01-17 18:00:18 +0000730
731 unsigned Size = getIntelMemOperandSize(Tok.getString());
732 if (Size) {
733 Parser.Lex();
734 assert (Tok.getString() == "PTR" && "Unexpected token!");
735 Parser.Lex();
736 }
737
738 if (getLexer().is(AsmToken::LBrac))
Devang Patel7c64fe62012-01-23 18:31:58 +0000739 return ParseIntelBracExpression(SegReg, Size);
740
741 if (!ParseRegister(SegReg, Start, End)) {
742 // Handel SegReg : [ ... ]
743 if (getLexer().isNot(AsmToken::Colon))
744 return ErrorOperand(Start, "Expected ':' token!");
745 Parser.Lex(); // Eat :
746 if (getLexer().isNot(AsmToken::LBrac))
747 return ErrorOperand(Start, "Expected '[' token!");
748 return ParseIntelBracExpression(SegReg, Size);
749 }
Devang Pateld37ad242012-01-17 18:00:18 +0000750
751 const MCExpr *Disp = MCConstantExpr::Create(0, getParser().getContext());
752 if (getParser().ParseExpression(Disp, End)) return 0;
753 return X86Operand::CreateMem(Disp, Start, End, Size);
754}
755
756X86Operand *X86AsmParser::ParseIntelOperand() {
Devang Pateld37ad242012-01-17 18:00:18 +0000757 SMLoc Start = Parser.getTok().getLoc(), End;
758
759 // immediate.
760 if (getLexer().is(AsmToken::Integer) || getLexer().is(AsmToken::Real) ||
761 getLexer().is(AsmToken::Minus)) {
762 const MCExpr *Val;
763 if (!getParser().ParseExpression(Val, End)) {
764 End = Parser.getTok().getLoc();
765 return X86Operand::CreateImm(Val, Start, End);
766 }
767 }
768
Devang Patel0a338862012-01-12 01:36:43 +0000769 // register
Devang Patel1aea4302012-01-20 22:32:05 +0000770 unsigned RegNo = 0;
771 if (!ParseRegister(RegNo, Start, End)) {
Devang Patel0a338862012-01-12 01:36:43 +0000772 End = Parser.getTok().getLoc();
773 return X86Operand::CreateReg(RegNo, Start, End);
774 }
775
776 // mem operand
Devang Pateld37ad242012-01-17 18:00:18 +0000777 return ParseIntelMemOperand();
Devang Patel0a338862012-01-12 01:36:43 +0000778}
779
Devang Pateldd929fc2012-01-12 18:03:40 +0000780X86Operand *X86AsmParser::ParseATTOperand() {
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000781 switch (getLexer().getKind()) {
782 default:
Chris Lattnereef6d782010-04-17 18:56:34 +0000783 // Parse a memory operand with no segment register.
784 return ParseMemOperand(0, Parser.getTok().getLoc());
Chris Lattner23075742010-01-15 18:27:19 +0000785 case AsmToken::Percent: {
Chris Lattnereef6d782010-04-17 18:56:34 +0000786 // Read the register.
Chris Lattner23075742010-01-15 18:27:19 +0000787 unsigned RegNo;
Chris Lattner29ef9a22010-01-15 18:51:29 +0000788 SMLoc Start, End;
789 if (ParseRegister(RegNo, Start, End)) return 0;
Bruno Cardoso Lopes3c8e1be2010-07-24 00:06:39 +0000790 if (RegNo == X86::EIZ || RegNo == X86::RIZ) {
Benjamin Kramer5efabcf2011-10-16 12:10:27 +0000791 Error(Start, "%eiz and %riz can only be used as index registers",
792 SMRange(Start, End));
Bruno Cardoso Lopes3c8e1be2010-07-24 00:06:39 +0000793 return 0;
794 }
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000795
Chris Lattnereef6d782010-04-17 18:56:34 +0000796 // If this is a segment register followed by a ':', then this is the start
797 // of a memory reference, otherwise this is a normal register reference.
798 if (getLexer().isNot(AsmToken::Colon))
799 return X86Operand::CreateReg(RegNo, Start, End);
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000800
801
Chris Lattnereef6d782010-04-17 18:56:34 +0000802 getParser().Lex(); // Eat the colon.
803 return ParseMemOperand(RegNo, Start);
Chris Lattner23075742010-01-15 18:27:19 +0000804 }
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000805 case AsmToken::Dollar: {
806 // $42 -> immediate.
Sean Callanan18b83232010-01-19 21:44:56 +0000807 SMLoc Start = Parser.getTok().getLoc(), End;
Sean Callananb9a25b72010-01-19 20:27:46 +0000808 Parser.Lex();
Daniel Dunbar8c2eebe2009-08-31 08:08:38 +0000809 const MCExpr *Val;
Chris Lattner54482b42010-01-15 19:39:23 +0000810 if (getParser().ParseExpression(Val, End))
Chris Lattner309264d2010-01-15 18:44:13 +0000811 return 0;
Chris Lattnerb4307b32010-01-15 19:28:38 +0000812 return X86Operand::CreateImm(Val, Start, End);
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000813 }
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000814 }
Daniel Dunbardbd692a2009-07-20 20:01:54 +0000815}
816
Chris Lattnereef6d782010-04-17 18:56:34 +0000817/// ParseMemOperand: segment: disp(basereg, indexreg, scale). The '%ds:' prefix
818/// has already been parsed if present.
Devang Pateldd929fc2012-01-12 18:03:40 +0000819X86Operand *X86AsmParser::ParseMemOperand(unsigned SegReg, SMLoc MemStart) {
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000820
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000821 // We have to disambiguate a parenthesized expression "(4+5)" from the start
822 // of a memory operand with a missing displacement "(%ebx)" or "(,%eax)". The
Chris Lattner75f265f2010-01-24 01:07:33 +0000823 // only way to do this without lookahead is to eat the '(' and see what is
824 // after it.
Daniel Dunbar8c2eebe2009-08-31 08:08:38 +0000825 const MCExpr *Disp = MCConstantExpr::Create(0, getParser().getContext());
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000826 if (getLexer().isNot(AsmToken::LParen)) {
Chris Lattner54482b42010-01-15 19:39:23 +0000827 SMLoc ExprEnd;
828 if (getParser().ParseExpression(Disp, ExprEnd)) return 0;
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000829
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000830 // After parsing the base expression we could either have a parenthesized
831 // memory address or not. If not, return now. If so, eat the (.
832 if (getLexer().isNot(AsmToken::LParen)) {
Daniel Dunbarc09e4112009-07-31 22:22:54 +0000833 // Unless we have a segment register, treat this as an immediate.
Chris Lattner309264d2010-01-15 18:44:13 +0000834 if (SegReg == 0)
Daniel Dunbarb834f5d2010-01-30 01:02:48 +0000835 return X86Operand::CreateMem(Disp, MemStart, ExprEnd);
Chris Lattner0a3c5a52010-01-15 19:33:43 +0000836 return X86Operand::CreateMem(SegReg, Disp, 0, 0, 1, MemStart, ExprEnd);
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000837 }
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000838
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000839 // Eat the '('.
Sean Callananb9a25b72010-01-19 20:27:46 +0000840 Parser.Lex();
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000841 } else {
842 // Okay, we have a '('. We don't know if this is an expression or not, but
843 // so we have to eat the ( to see beyond it.
Sean Callanan18b83232010-01-19 21:44:56 +0000844 SMLoc LParenLoc = Parser.getTok().getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +0000845 Parser.Lex(); // Eat the '('.
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000846
Kevin Enderby7b4608d2009-09-03 17:15:07 +0000847 if (getLexer().is(AsmToken::Percent) || getLexer().is(AsmToken::Comma)) {
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000848 // Nothing to do here, fall into the code below with the '(' part of the
849 // memory operand consumed.
850 } else {
Chris Lattnerb4307b32010-01-15 19:28:38 +0000851 SMLoc ExprEnd;
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000852
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000853 // It must be an parenthesized expression, parse it now.
Chris Lattnerb4307b32010-01-15 19:28:38 +0000854 if (getParser().ParseParenExpression(Disp, ExprEnd))
Chris Lattner309264d2010-01-15 18:44:13 +0000855 return 0;
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000856
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000857 // After parsing the base expression we could either have a parenthesized
858 // memory address or not. If not, return now. If so, eat the (.
859 if (getLexer().isNot(AsmToken::LParen)) {
Daniel Dunbarc09e4112009-07-31 22:22:54 +0000860 // Unless we have a segment register, treat this as an immediate.
Chris Lattner309264d2010-01-15 18:44:13 +0000861 if (SegReg == 0)
Daniel Dunbarb834f5d2010-01-30 01:02:48 +0000862 return X86Operand::CreateMem(Disp, LParenLoc, ExprEnd);
Chris Lattner0a3c5a52010-01-15 19:33:43 +0000863 return X86Operand::CreateMem(SegReg, Disp, 0, 0, 1, MemStart, ExprEnd);
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000864 }
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000865
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000866 // Eat the '('.
Sean Callananb9a25b72010-01-19 20:27:46 +0000867 Parser.Lex();
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000868 }
869 }
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000870
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000871 // If we reached here, then we just ate the ( of the memory operand. Process
872 // the rest of the memory operand.
Daniel Dunbar022e2a82009-07-31 20:53:16 +0000873 unsigned BaseReg = 0, IndexReg = 0, Scale = 1;
Kevin Enderby84faf652012-03-12 21:32:09 +0000874 SMLoc IndexLoc;
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000875
Chris Lattner29ef9a22010-01-15 18:51:29 +0000876 if (getLexer().is(AsmToken::Percent)) {
Benjamin Kramer5efabcf2011-10-16 12:10:27 +0000877 SMLoc StartLoc, EndLoc;
878 if (ParseRegister(BaseReg, StartLoc, EndLoc)) return 0;
Bruno Cardoso Lopes3c8e1be2010-07-24 00:06:39 +0000879 if (BaseReg == X86::EIZ || BaseReg == X86::RIZ) {
Benjamin Kramer5efabcf2011-10-16 12:10:27 +0000880 Error(StartLoc, "eiz and riz can only be used as index registers",
881 SMRange(StartLoc, EndLoc));
Bruno Cardoso Lopes3c8e1be2010-07-24 00:06:39 +0000882 return 0;
883 }
Chris Lattner29ef9a22010-01-15 18:51:29 +0000884 }
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000885
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000886 if (getLexer().is(AsmToken::Comma)) {
Sean Callananb9a25b72010-01-19 20:27:46 +0000887 Parser.Lex(); // Eat the comma.
Kevin Enderby84faf652012-03-12 21:32:09 +0000888 IndexLoc = Parser.getTok().getLoc();
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000889
890 // Following the comma we should have either an index register, or a scale
891 // value. We don't support the later form, but we want to parse it
892 // correctly.
893 //
894 // Not that even though it would be completely consistent to support syntax
Bruno Cardoso Lopes3c8e1be2010-07-24 00:06:39 +0000895 // like "1(%eax,,1)", the assembler doesn't. Use "eiz" or "riz" for this.
Kevin Enderby7b4608d2009-09-03 17:15:07 +0000896 if (getLexer().is(AsmToken::Percent)) {
Chris Lattner29ef9a22010-01-15 18:51:29 +0000897 SMLoc L;
898 if (ParseRegister(IndexReg, L, L)) return 0;
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000899
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000900 if (getLexer().isNot(AsmToken::RParen)) {
901 // Parse the scale amount:
902 // ::= ',' [scale-expression]
Chris Lattner309264d2010-01-15 18:44:13 +0000903 if (getLexer().isNot(AsmToken::Comma)) {
Sean Callanan18b83232010-01-19 21:44:56 +0000904 Error(Parser.getTok().getLoc(),
Chris Lattner309264d2010-01-15 18:44:13 +0000905 "expected comma in scale expression");
906 return 0;
907 }
Sean Callananb9a25b72010-01-19 20:27:46 +0000908 Parser.Lex(); // Eat the comma.
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000909
910 if (getLexer().isNot(AsmToken::RParen)) {
Sean Callanan18b83232010-01-19 21:44:56 +0000911 SMLoc Loc = Parser.getTok().getLoc();
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000912
913 int64_t ScaleVal;
Kevin Enderby58dfaa12012-03-09 22:24:10 +0000914 if (getParser().ParseAbsoluteExpression(ScaleVal)){
915 Error(Loc, "expected scale expression");
Chris Lattner309264d2010-01-15 18:44:13 +0000916 return 0;
Craig Topper76bd9382012-07-18 04:59:16 +0000917 }
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000918
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000919 // Validate the scale amount.
Chris Lattner309264d2010-01-15 18:44:13 +0000920 if (ScaleVal != 1 && ScaleVal != 2 && ScaleVal != 4 && ScaleVal != 8){
921 Error(Loc, "scale factor in address must be 1, 2, 4 or 8");
922 return 0;
923 }
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000924 Scale = (unsigned)ScaleVal;
925 }
926 }
927 } else if (getLexer().isNot(AsmToken::RParen)) {
Daniel Dunbaree910252010-08-24 19:13:38 +0000928 // A scale amount without an index is ignored.
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000929 // index.
Sean Callanan18b83232010-01-19 21:44:56 +0000930 SMLoc Loc = Parser.getTok().getLoc();
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000931
932 int64_t Value;
933 if (getParser().ParseAbsoluteExpression(Value))
Chris Lattner309264d2010-01-15 18:44:13 +0000934 return 0;
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000935
Daniel Dunbaree910252010-08-24 19:13:38 +0000936 if (Value != 1)
937 Warning(Loc, "scale factor without index register is ignored");
938 Scale = 1;
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000939 }
940 }
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000941
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000942 // Ok, we've eaten the memory operand, verify we have a ')' and eat it too.
Chris Lattner309264d2010-01-15 18:44:13 +0000943 if (getLexer().isNot(AsmToken::RParen)) {
Sean Callanan18b83232010-01-19 21:44:56 +0000944 Error(Parser.getTok().getLoc(), "unexpected token in memory operand");
Chris Lattner309264d2010-01-15 18:44:13 +0000945 return 0;
946 }
Sean Callanan18b83232010-01-19 21:44:56 +0000947 SMLoc MemEnd = Parser.getTok().getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +0000948 Parser.Lex(); // Eat the ')'.
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000949
Kevin Enderby84faf652012-03-12 21:32:09 +0000950 // If we have both a base register and an index register make sure they are
951 // both 64-bit or 32-bit registers.
Manman Ren1f7a1b62012-06-26 19:47:59 +0000952 // To support VSIB, IndexReg can be 128-bit or 256-bit registers.
Kevin Enderby84faf652012-03-12 21:32:09 +0000953 if (BaseReg != 0 && IndexReg != 0) {
954 if (X86MCRegisterClasses[X86::GR64RegClassID].contains(BaseReg) &&
Manman Ren1f7a1b62012-06-26 19:47:59 +0000955 (X86MCRegisterClasses[X86::GR16RegClassID].contains(IndexReg) ||
956 X86MCRegisterClasses[X86::GR32RegClassID].contains(IndexReg)) &&
Kevin Enderby84faf652012-03-12 21:32:09 +0000957 IndexReg != X86::RIZ) {
958 Error(IndexLoc, "index register is 32-bit, but base register is 64-bit");
959 return 0;
960 }
961 if (X86MCRegisterClasses[X86::GR32RegClassID].contains(BaseReg) &&
Manman Ren1f7a1b62012-06-26 19:47:59 +0000962 (X86MCRegisterClasses[X86::GR16RegClassID].contains(IndexReg) ||
963 X86MCRegisterClasses[X86::GR64RegClassID].contains(IndexReg)) &&
Kevin Enderby84faf652012-03-12 21:32:09 +0000964 IndexReg != X86::EIZ){
965 Error(IndexLoc, "index register is 64-bit, but base register is 32-bit");
966 return 0;
967 }
968 }
969
Chris Lattner0a3c5a52010-01-15 19:33:43 +0000970 return X86Operand::CreateMem(SegReg, Disp, BaseReg, IndexReg, Scale,
971 MemStart, MemEnd);
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000972}
973
Devang Pateldd929fc2012-01-12 18:03:40 +0000974bool X86AsmParser::
Benjamin Kramer38e59892010-07-14 22:38:02 +0000975ParseInstruction(StringRef Name, SMLoc NameLoc,
Chris Lattner98986712010-01-14 22:21:20 +0000976 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Chris Lattner693173f2010-10-30 19:23:13 +0000977 StringRef PatchedName = Name;
Daniel Dunbar39e2dd72010-05-25 19:49:32 +0000978
Chris Lattnerd8f71792010-11-28 20:23:50 +0000979 // FIXME: Hack to recognize setneb as setne.
980 if (PatchedName.startswith("set") && PatchedName.endswith("b") &&
981 PatchedName != "setb" && PatchedName != "setnb")
982 PatchedName = PatchedName.substr(0, Name.size()-1);
Chad Rosier36b8fed2012-06-27 22:34:28 +0000983
Daniel Dunbar39e2dd72010-05-25 19:49:32 +0000984 // FIXME: Hack to recognize cmp<comparison code>{ss,sd,ps,pd}.
985 const MCExpr *ExtraImmOp = 0;
Bruno Cardoso Lopes428256b2010-06-23 21:10:57 +0000986 if ((PatchedName.startswith("cmp") || PatchedName.startswith("vcmp")) &&
Daniel Dunbar39e2dd72010-05-25 19:49:32 +0000987 (PatchedName.endswith("ss") || PatchedName.endswith("sd") ||
988 PatchedName.endswith("ps") || PatchedName.endswith("pd"))) {
Craig Topper9e6ddcb2012-03-29 07:11:23 +0000989 bool IsVCMP = PatchedName[0] == 'v';
Bruno Cardoso Lopes428256b2010-06-23 21:10:57 +0000990 unsigned SSECCIdx = IsVCMP ? 4 : 3;
Daniel Dunbar39e2dd72010-05-25 19:49:32 +0000991 unsigned SSEComparisonCode = StringSwitch<unsigned>(
Bruno Cardoso Lopes428256b2010-06-23 21:10:57 +0000992 PatchedName.slice(SSECCIdx, PatchedName.size() - 2))
Craig Topper9e6ddcb2012-03-29 07:11:23 +0000993 .Case("eq", 0x00)
994 .Case("lt", 0x01)
995 .Case("le", 0x02)
996 .Case("unord", 0x03)
997 .Case("neq", 0x04)
998 .Case("nlt", 0x05)
999 .Case("nle", 0x06)
1000 .Case("ord", 0x07)
1001 /* AVX only from here */
1002 .Case("eq_uq", 0x08)
1003 .Case("nge", 0x09)
Bruno Cardoso Lopescc69e132010-07-07 22:24:03 +00001004 .Case("ngt", 0x0A)
1005 .Case("false", 0x0B)
1006 .Case("neq_oq", 0x0C)
1007 .Case("ge", 0x0D)
1008 .Case("gt", 0x0E)
1009 .Case("true", 0x0F)
1010 .Case("eq_os", 0x10)
1011 .Case("lt_oq", 0x11)
1012 .Case("le_oq", 0x12)
1013 .Case("unord_s", 0x13)
1014 .Case("neq_us", 0x14)
1015 .Case("nlt_uq", 0x15)
1016 .Case("nle_uq", 0x16)
1017 .Case("ord_s", 0x17)
1018 .Case("eq_us", 0x18)
1019 .Case("nge_uq", 0x19)
1020 .Case("ngt_uq", 0x1A)
1021 .Case("false_os", 0x1B)
1022 .Case("neq_os", 0x1C)
1023 .Case("ge_oq", 0x1D)
1024 .Case("gt_oq", 0x1E)
1025 .Case("true_us", 0x1F)
Daniel Dunbar39e2dd72010-05-25 19:49:32 +00001026 .Default(~0U);
Craig Topper9e6ddcb2012-03-29 07:11:23 +00001027 if (SSEComparisonCode != ~0U && (IsVCMP || SSEComparisonCode < 8)) {
Daniel Dunbar39e2dd72010-05-25 19:49:32 +00001028 ExtraImmOp = MCConstantExpr::Create(SSEComparisonCode,
1029 getParser().getContext());
1030 if (PatchedName.endswith("ss")) {
Bruno Cardoso Lopes428256b2010-06-23 21:10:57 +00001031 PatchedName = IsVCMP ? "vcmpss" : "cmpss";
Daniel Dunbar39e2dd72010-05-25 19:49:32 +00001032 } else if (PatchedName.endswith("sd")) {
Bruno Cardoso Lopes428256b2010-06-23 21:10:57 +00001033 PatchedName = IsVCMP ? "vcmpsd" : "cmpsd";
Daniel Dunbar39e2dd72010-05-25 19:49:32 +00001034 } else if (PatchedName.endswith("ps")) {
Bruno Cardoso Lopes428256b2010-06-23 21:10:57 +00001035 PatchedName = IsVCMP ? "vcmpps" : "cmpps";
Daniel Dunbar39e2dd72010-05-25 19:49:32 +00001036 } else {
1037 assert(PatchedName.endswith("pd") && "Unexpected mnemonic!");
Bruno Cardoso Lopes428256b2010-06-23 21:10:57 +00001038 PatchedName = IsVCMP ? "vcmppd" : "cmppd";
Daniel Dunbar39e2dd72010-05-25 19:49:32 +00001039 }
1040 }
1041 }
Bruno Cardoso Lopesf528d2b2010-07-23 18:41:12 +00001042
Daniel Dunbar1b6c0602010-02-10 21:19:28 +00001043 Operands.push_back(X86Operand::CreateToken(PatchedName, NameLoc));
Daniel Dunbar16cdcb32009-07-28 22:40:46 +00001044
Devang Patel885f65b2012-01-30 22:47:12 +00001045 if (ExtraImmOp && !isParsingIntelSyntax())
Daniel Dunbar39e2dd72010-05-25 19:49:32 +00001046 Operands.push_back(X86Operand::CreateImm(ExtraImmOp, NameLoc, NameLoc));
Michael J. Spencerc0c8df32010-10-09 11:00:50 +00001047
Chris Lattner2544f422010-09-08 05:17:37 +00001048 // Determine whether this is an instruction prefix.
1049 bool isPrefix =
Chris Lattner693173f2010-10-30 19:23:13 +00001050 Name == "lock" || Name == "rep" ||
1051 Name == "repe" || Name == "repz" ||
Rafael Espindolabeb68982010-11-23 11:23:24 +00001052 Name == "repne" || Name == "repnz" ||
Rafael Espindolabfd2d262010-11-27 20:29:45 +00001053 Name == "rex64" || Name == "data16";
Michael J. Spencerc0c8df32010-10-09 11:00:50 +00001054
1055
Chris Lattner2544f422010-09-08 05:17:37 +00001056 // This does the actual operand parsing. Don't parse any more if we have a
1057 // prefix juxtaposed with an operation like "lock incl 4(%rax)", because we
1058 // just want to parse the "lock" as the first instruction and the "incl" as
1059 // the next one.
1060 if (getLexer().isNot(AsmToken::EndOfStatement) && !isPrefix) {
Daniel Dunbar0db68f42009-08-11 05:00:25 +00001061
1062 // Parse '*' modifier.
1063 if (getLexer().is(AsmToken::Star)) {
Sean Callanan18b83232010-01-19 21:44:56 +00001064 SMLoc Loc = Parser.getTok().getLoc();
Chris Lattnerb4307b32010-01-15 19:28:38 +00001065 Operands.push_back(X86Operand::CreateToken("*", Loc));
Sean Callananb9a25b72010-01-19 20:27:46 +00001066 Parser.Lex(); // Eat the star.
Daniel Dunbar0db68f42009-08-11 05:00:25 +00001067 }
1068
Daniel Dunbar16cdcb32009-07-28 22:40:46 +00001069 // Read the first operand.
Chris Lattner309264d2010-01-15 18:44:13 +00001070 if (X86Operand *Op = ParseOperand())
1071 Operands.push_back(Op);
Chris Lattnercbf8a982010-09-11 16:18:25 +00001072 else {
1073 Parser.EatToEndOfStatement();
Daniel Dunbar16cdcb32009-07-28 22:40:46 +00001074 return true;
Chris Lattnercbf8a982010-09-11 16:18:25 +00001075 }
Daniel Dunbar39e2dd72010-05-25 19:49:32 +00001076
Daniel Dunbar16cdcb32009-07-28 22:40:46 +00001077 while (getLexer().is(AsmToken::Comma)) {
Sean Callananb9a25b72010-01-19 20:27:46 +00001078 Parser.Lex(); // Eat the comma.
Daniel Dunbar16cdcb32009-07-28 22:40:46 +00001079
1080 // Parse and remember the operand.
Chris Lattner309264d2010-01-15 18:44:13 +00001081 if (X86Operand *Op = ParseOperand())
1082 Operands.push_back(Op);
Chris Lattnercbf8a982010-09-11 16:18:25 +00001083 else {
1084 Parser.EatToEndOfStatement();
Daniel Dunbar16cdcb32009-07-28 22:40:46 +00001085 return true;
Chris Lattnercbf8a982010-09-11 16:18:25 +00001086 }
Daniel Dunbar16cdcb32009-07-28 22:40:46 +00001087 }
Michael J. Spencerc0c8df32010-10-09 11:00:50 +00001088
Chris Lattnercbf8a982010-09-11 16:18:25 +00001089 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Chris Lattnerc146c4d2010-11-18 02:53:02 +00001090 SMLoc Loc = getLexer().getLoc();
Chris Lattnercbf8a982010-09-11 16:18:25 +00001091 Parser.EatToEndOfStatement();
Chris Lattnerc146c4d2010-11-18 02:53:02 +00001092 return Error(Loc, "unexpected token in argument list");
Chris Lattnercbf8a982010-09-11 16:18:25 +00001093 }
Daniel Dunbar16cdcb32009-07-28 22:40:46 +00001094 }
Michael J. Spencerc0c8df32010-10-09 11:00:50 +00001095
Chris Lattner2544f422010-09-08 05:17:37 +00001096 if (getLexer().is(AsmToken::EndOfStatement))
1097 Parser.Lex(); // Consume the EndOfStatement
Kevin Enderby76331752010-12-08 23:57:59 +00001098 else if (isPrefix && getLexer().is(AsmToken::Slash))
1099 Parser.Lex(); // Consume the prefix separator Slash
Daniel Dunbar16cdcb32009-07-28 22:40:46 +00001100
Devang Patel885f65b2012-01-30 22:47:12 +00001101 if (ExtraImmOp && isParsingIntelSyntax())
1102 Operands.push_back(X86Operand::CreateImm(ExtraImmOp, NameLoc, NameLoc));
1103
Chris Lattner98c870f2010-11-06 19:25:43 +00001104 // This is a terrible hack to handle "out[bwl]? %al, (%dx)" ->
1105 // "outb %al, %dx". Out doesn't take a memory form, but this is a widely
1106 // documented form in various unofficial manuals, so a lot of code uses it.
1107 if ((Name == "outb" || Name == "outw" || Name == "outl" || Name == "out") &&
1108 Operands.size() == 3) {
1109 X86Operand &Op = *(X86Operand*)Operands.back();
1110 if (Op.isMem() && Op.Mem.SegReg == 0 &&
1111 isa<MCConstantExpr>(Op.Mem.Disp) &&
1112 cast<MCConstantExpr>(Op.Mem.Disp)->getValue() == 0 &&
1113 Op.Mem.BaseReg == MatchRegisterName("dx") && Op.Mem.IndexReg == 0) {
1114 SMLoc Loc = Op.getEndLoc();
1115 Operands.back() = X86Operand::CreateReg(Op.Mem.BaseReg, Loc, Loc);
1116 delete &Op;
1117 }
1118 }
Joerg Sonnenberger00743c22011-02-22 20:40:09 +00001119 // Same hack for "in[bwl]? (%dx), %al" -> "inb %dx, %al".
1120 if ((Name == "inb" || Name == "inw" || Name == "inl" || Name == "in") &&
1121 Operands.size() == 3) {
1122 X86Operand &Op = *(X86Operand*)Operands.begin()[1];
1123 if (Op.isMem() && Op.Mem.SegReg == 0 &&
1124 isa<MCConstantExpr>(Op.Mem.Disp) &&
1125 cast<MCConstantExpr>(Op.Mem.Disp)->getValue() == 0 &&
1126 Op.Mem.BaseReg == MatchRegisterName("dx") && Op.Mem.IndexReg == 0) {
1127 SMLoc Loc = Op.getEndLoc();
1128 Operands.begin()[1] = X86Operand::CreateReg(Op.Mem.BaseReg, Loc, Loc);
1129 delete &Op;
1130 }
1131 }
Joerg Sonnenberger96622aa2011-03-18 11:59:40 +00001132 // Transform "ins[bwl] %dx, %es:(%edi)" into "ins[bwl]"
1133 if (Name.startswith("ins") && Operands.size() == 3 &&
1134 (Name == "insb" || Name == "insw" || Name == "insl")) {
1135 X86Operand &Op = *(X86Operand*)Operands.begin()[1];
1136 X86Operand &Op2 = *(X86Operand*)Operands.begin()[2];
1137 if (Op.isReg() && Op.getReg() == X86::DX && isDstOp(Op2)) {
1138 Operands.pop_back();
1139 Operands.pop_back();
1140 delete &Op;
1141 delete &Op2;
1142 }
1143 }
1144
1145 // Transform "outs[bwl] %ds:(%esi), %dx" into "out[bwl]"
1146 if (Name.startswith("outs") && Operands.size() == 3 &&
1147 (Name == "outsb" || Name == "outsw" || Name == "outsl")) {
1148 X86Operand &Op = *(X86Operand*)Operands.begin()[1];
1149 X86Operand &Op2 = *(X86Operand*)Operands.begin()[2];
1150 if (isSrcOp(Op) && Op2.isReg() && Op2.getReg() == X86::DX) {
1151 Operands.pop_back();
1152 Operands.pop_back();
1153 delete &Op;
1154 delete &Op2;
1155 }
1156 }
1157
1158 // Transform "movs[bwl] %ds:(%esi), %es:(%edi)" into "movs[bwl]"
1159 if (Name.startswith("movs") && Operands.size() == 3 &&
1160 (Name == "movsb" || Name == "movsw" || Name == "movsl" ||
Evan Cheng59ee62d2011-07-11 03:57:24 +00001161 (is64BitMode() && Name == "movsq"))) {
Joerg Sonnenberger96622aa2011-03-18 11:59:40 +00001162 X86Operand &Op = *(X86Operand*)Operands.begin()[1];
1163 X86Operand &Op2 = *(X86Operand*)Operands.begin()[2];
1164 if (isSrcOp(Op) && isDstOp(Op2)) {
1165 Operands.pop_back();
1166 Operands.pop_back();
1167 delete &Op;
1168 delete &Op2;
1169 }
1170 }
1171 // Transform "lods[bwl] %ds:(%esi),{%al,%ax,%eax,%rax}" into "lods[bwl]"
1172 if (Name.startswith("lods") && Operands.size() == 3 &&
1173 (Name == "lods" || Name == "lodsb" || Name == "lodsw" ||
Evan Cheng59ee62d2011-07-11 03:57:24 +00001174 Name == "lodsl" || (is64BitMode() && Name == "lodsq"))) {
Joerg Sonnenberger96622aa2011-03-18 11:59:40 +00001175 X86Operand *Op1 = static_cast<X86Operand*>(Operands[1]);
1176 X86Operand *Op2 = static_cast<X86Operand*>(Operands[2]);
1177 if (isSrcOp(*Op1) && Op2->isReg()) {
1178 const char *ins;
1179 unsigned reg = Op2->getReg();
1180 bool isLods = Name == "lods";
1181 if (reg == X86::AL && (isLods || Name == "lodsb"))
1182 ins = "lodsb";
1183 else if (reg == X86::AX && (isLods || Name == "lodsw"))
1184 ins = "lodsw";
1185 else if (reg == X86::EAX && (isLods || Name == "lodsl"))
1186 ins = "lodsl";
1187 else if (reg == X86::RAX && (isLods || Name == "lodsq"))
1188 ins = "lodsq";
1189 else
1190 ins = NULL;
1191 if (ins != NULL) {
1192 Operands.pop_back();
1193 Operands.pop_back();
1194 delete Op1;
1195 delete Op2;
1196 if (Name != ins)
1197 static_cast<X86Operand*>(Operands[0])->setTokenValue(ins);
1198 }
1199 }
1200 }
1201 // Transform "stos[bwl] {%al,%ax,%eax,%rax},%es:(%edi)" into "stos[bwl]"
1202 if (Name.startswith("stos") && Operands.size() == 3 &&
1203 (Name == "stos" || Name == "stosb" || Name == "stosw" ||
Evan Cheng59ee62d2011-07-11 03:57:24 +00001204 Name == "stosl" || (is64BitMode() && Name == "stosq"))) {
Joerg Sonnenberger96622aa2011-03-18 11:59:40 +00001205 X86Operand *Op1 = static_cast<X86Operand*>(Operands[1]);
1206 X86Operand *Op2 = static_cast<X86Operand*>(Operands[2]);
1207 if (isDstOp(*Op2) && Op1->isReg()) {
1208 const char *ins;
1209 unsigned reg = Op1->getReg();
1210 bool isStos = Name == "stos";
1211 if (reg == X86::AL && (isStos || Name == "stosb"))
1212 ins = "stosb";
1213 else if (reg == X86::AX && (isStos || Name == "stosw"))
1214 ins = "stosw";
1215 else if (reg == X86::EAX && (isStos || Name == "stosl"))
1216 ins = "stosl";
1217 else if (reg == X86::RAX && (isStos || Name == "stosq"))
1218 ins = "stosq";
1219 else
1220 ins = NULL;
1221 if (ins != NULL) {
1222 Operands.pop_back();
1223 Operands.pop_back();
1224 delete Op1;
1225 delete Op2;
1226 if (Name != ins)
1227 static_cast<X86Operand*>(Operands[0])->setTokenValue(ins);
1228 }
1229 }
1230 }
1231
Chris Lattnere9e16a32010-09-15 04:33:27 +00001232 // FIXME: Hack to handle recognize s{hr,ar,hl} $1, <op>. Canonicalize to
Chris Lattneree211d02010-09-11 16:32:12 +00001233 // "shift <op>".
Daniel Dunbard5e77052010-03-13 00:47:29 +00001234 if ((Name.startswith("shr") || Name.startswith("sar") ||
Chris Lattner8c24b0c2010-11-06 21:23:40 +00001235 Name.startswith("shl") || Name.startswith("sal") ||
1236 Name.startswith("rcl") || Name.startswith("rcr") ||
1237 Name.startswith("rol") || Name.startswith("ror")) &&
Chris Lattner47ab90b2010-09-06 18:32:06 +00001238 Operands.size() == 3) {
Devang Patelbe3e3102012-01-30 20:02:42 +00001239 if (isParsingIntelSyntax()) {
Devang Patel3b96e1f2012-01-24 21:43:36 +00001240 // Intel syntax
1241 X86Operand *Op1 = static_cast<X86Operand*>(Operands[2]);
1242 if (Op1->isImm() && isa<MCConstantExpr>(Op1->getImm()) &&
Craig Topper76bd9382012-07-18 04:59:16 +00001243 cast<MCConstantExpr>(Op1->getImm())->getValue() == 1) {
1244 delete Operands[2];
1245 Operands.pop_back();
Devang Patel3b96e1f2012-01-24 21:43:36 +00001246 }
1247 } else {
1248 X86Operand *Op1 = static_cast<X86Operand*>(Operands[1]);
1249 if (Op1->isImm() && isa<MCConstantExpr>(Op1->getImm()) &&
Craig Topper76bd9382012-07-18 04:59:16 +00001250 cast<MCConstantExpr>(Op1->getImm())->getValue() == 1) {
1251 delete Operands[1];
1252 Operands.erase(Operands.begin() + 1);
Devang Patel3b96e1f2012-01-24 21:43:36 +00001253 }
Chris Lattner47ab90b2010-09-06 18:32:06 +00001254 }
Daniel Dunbarf2de13f2010-03-20 22:36:38 +00001255 }
Chad Rosier36b8fed2012-06-27 22:34:28 +00001256
Chris Lattner15f89512011-04-09 19:41:05 +00001257 // Transforms "int $3" into "int3" as a size optimization. We can't write an
1258 // instalias with an immediate operand yet.
1259 if (Name == "int" && Operands.size() == 2) {
1260 X86Operand *Op1 = static_cast<X86Operand*>(Operands[1]);
1261 if (Op1->isImm() && isa<MCConstantExpr>(Op1->getImm()) &&
1262 cast<MCConstantExpr>(Op1->getImm())->getValue() == 3) {
1263 delete Operands[1];
1264 Operands.erase(Operands.begin() + 1);
1265 static_cast<X86Operand*>(Operands[0])->setTokenValue("int3");
1266 }
1267 }
Michael J. Spencerc0c8df32010-10-09 11:00:50 +00001268
Chris Lattner98986712010-01-14 22:21:20 +00001269 return false;
Daniel Dunbara3af3702009-07-20 18:55:04 +00001270}
1271
Devang Pateldd929fc2012-01-12 18:03:40 +00001272bool X86AsmParser::
Devang Patelb8ba13f2012-01-18 22:42:29 +00001273processInstruction(MCInst &Inst,
1274 const SmallVectorImpl<MCParsedAsmOperand*> &Ops) {
1275 switch (Inst.getOpcode()) {
1276 default: return false;
1277 case X86::AND16i16: {
1278 if (!Inst.getOperand(0).isImm() ||
1279 !isImmSExti16i8Value(Inst.getOperand(0).getImm()))
1280 return false;
1281
1282 MCInst TmpInst;
1283 TmpInst.setOpcode(X86::AND16ri8);
1284 TmpInst.addOperand(MCOperand::CreateReg(X86::AX));
1285 TmpInst.addOperand(MCOperand::CreateReg(X86::AX));
1286 TmpInst.addOperand(Inst.getOperand(0));
1287 Inst = TmpInst;
1288 return true;
1289 }
1290 case X86::AND32i32: {
1291 if (!Inst.getOperand(0).isImm() ||
1292 !isImmSExti32i8Value(Inst.getOperand(0).getImm()))
1293 return false;
1294
1295 MCInst TmpInst;
1296 TmpInst.setOpcode(X86::AND32ri8);
1297 TmpInst.addOperand(MCOperand::CreateReg(X86::EAX));
1298 TmpInst.addOperand(MCOperand::CreateReg(X86::EAX));
1299 TmpInst.addOperand(Inst.getOperand(0));
1300 Inst = TmpInst;
1301 return true;
1302 }
1303 case X86::AND64i32: {
1304 if (!Inst.getOperand(0).isImm() ||
1305 !isImmSExti64i8Value(Inst.getOperand(0).getImm()))
1306 return false;
1307
1308 MCInst TmpInst;
1309 TmpInst.setOpcode(X86::AND64ri8);
1310 TmpInst.addOperand(MCOperand::CreateReg(X86::RAX));
1311 TmpInst.addOperand(MCOperand::CreateReg(X86::RAX));
1312 TmpInst.addOperand(Inst.getOperand(0));
1313 Inst = TmpInst;
1314 return true;
1315 }
Devang Patelac0f0482012-01-19 17:53:25 +00001316 case X86::XOR16i16: {
1317 if (!Inst.getOperand(0).isImm() ||
1318 !isImmSExti16i8Value(Inst.getOperand(0).getImm()))
1319 return false;
1320
1321 MCInst TmpInst;
1322 TmpInst.setOpcode(X86::XOR16ri8);
1323 TmpInst.addOperand(MCOperand::CreateReg(X86::AX));
1324 TmpInst.addOperand(MCOperand::CreateReg(X86::AX));
1325 TmpInst.addOperand(Inst.getOperand(0));
1326 Inst = TmpInst;
1327 return true;
1328 }
1329 case X86::XOR32i32: {
1330 if (!Inst.getOperand(0).isImm() ||
1331 !isImmSExti32i8Value(Inst.getOperand(0).getImm()))
1332 return false;
1333
1334 MCInst TmpInst;
1335 TmpInst.setOpcode(X86::XOR32ri8);
1336 TmpInst.addOperand(MCOperand::CreateReg(X86::EAX));
1337 TmpInst.addOperand(MCOperand::CreateReg(X86::EAX));
1338 TmpInst.addOperand(Inst.getOperand(0));
1339 Inst = TmpInst;
1340 return true;
1341 }
1342 case X86::XOR64i32: {
1343 if (!Inst.getOperand(0).isImm() ||
1344 !isImmSExti64i8Value(Inst.getOperand(0).getImm()))
1345 return false;
1346
1347 MCInst TmpInst;
1348 TmpInst.setOpcode(X86::XOR64ri8);
1349 TmpInst.addOperand(MCOperand::CreateReg(X86::RAX));
1350 TmpInst.addOperand(MCOperand::CreateReg(X86::RAX));
1351 TmpInst.addOperand(Inst.getOperand(0));
1352 Inst = TmpInst;
1353 return true;
1354 }
1355 case X86::OR16i16: {
1356 if (!Inst.getOperand(0).isImm() ||
1357 !isImmSExti16i8Value(Inst.getOperand(0).getImm()))
1358 return false;
1359
1360 MCInst TmpInst;
1361 TmpInst.setOpcode(X86::OR16ri8);
1362 TmpInst.addOperand(MCOperand::CreateReg(X86::AX));
1363 TmpInst.addOperand(MCOperand::CreateReg(X86::AX));
1364 TmpInst.addOperand(Inst.getOperand(0));
1365 Inst = TmpInst;
1366 return true;
1367 }
1368 case X86::OR32i32: {
1369 if (!Inst.getOperand(0).isImm() ||
1370 !isImmSExti32i8Value(Inst.getOperand(0).getImm()))
1371 return false;
1372
1373 MCInst TmpInst;
1374 TmpInst.setOpcode(X86::OR32ri8);
1375 TmpInst.addOperand(MCOperand::CreateReg(X86::EAX));
1376 TmpInst.addOperand(MCOperand::CreateReg(X86::EAX));
1377 TmpInst.addOperand(Inst.getOperand(0));
1378 Inst = TmpInst;
1379 return true;
1380 }
1381 case X86::OR64i32: {
1382 if (!Inst.getOperand(0).isImm() ||
1383 !isImmSExti64i8Value(Inst.getOperand(0).getImm()))
1384 return false;
1385
1386 MCInst TmpInst;
1387 TmpInst.setOpcode(X86::OR64ri8);
1388 TmpInst.addOperand(MCOperand::CreateReg(X86::RAX));
1389 TmpInst.addOperand(MCOperand::CreateReg(X86::RAX));
1390 TmpInst.addOperand(Inst.getOperand(0));
1391 Inst = TmpInst;
1392 return true;
1393 }
1394 case X86::CMP16i16: {
1395 if (!Inst.getOperand(0).isImm() ||
1396 !isImmSExti16i8Value(Inst.getOperand(0).getImm()))
1397 return false;
1398
1399 MCInst TmpInst;
1400 TmpInst.setOpcode(X86::CMP16ri8);
1401 TmpInst.addOperand(MCOperand::CreateReg(X86::AX));
1402 TmpInst.addOperand(Inst.getOperand(0));
1403 Inst = TmpInst;
1404 return true;
1405 }
1406 case X86::CMP32i32: {
1407 if (!Inst.getOperand(0).isImm() ||
1408 !isImmSExti32i8Value(Inst.getOperand(0).getImm()))
1409 return false;
1410
1411 MCInst TmpInst;
1412 TmpInst.setOpcode(X86::CMP32ri8);
1413 TmpInst.addOperand(MCOperand::CreateReg(X86::EAX));
1414 TmpInst.addOperand(Inst.getOperand(0));
1415 Inst = TmpInst;
1416 return true;
1417 }
1418 case X86::CMP64i32: {
1419 if (!Inst.getOperand(0).isImm() ||
1420 !isImmSExti64i8Value(Inst.getOperand(0).getImm()))
1421 return false;
1422
1423 MCInst TmpInst;
1424 TmpInst.setOpcode(X86::CMP64ri8);
1425 TmpInst.addOperand(MCOperand::CreateReg(X86::RAX));
1426 TmpInst.addOperand(Inst.getOperand(0));
1427 Inst = TmpInst;
1428 return true;
1429 }
Devang Patela951f772012-01-19 18:40:55 +00001430 case X86::ADD16i16: {
1431 if (!Inst.getOperand(0).isImm() ||
1432 !isImmSExti16i8Value(Inst.getOperand(0).getImm()))
1433 return false;
1434
1435 MCInst TmpInst;
1436 TmpInst.setOpcode(X86::ADD16ri8);
1437 TmpInst.addOperand(MCOperand::CreateReg(X86::AX));
1438 TmpInst.addOperand(MCOperand::CreateReg(X86::AX));
1439 TmpInst.addOperand(Inst.getOperand(0));
1440 Inst = TmpInst;
1441 return true;
1442 }
1443 case X86::ADD32i32: {
1444 if (!Inst.getOperand(0).isImm() ||
1445 !isImmSExti32i8Value(Inst.getOperand(0).getImm()))
1446 return false;
1447
1448 MCInst TmpInst;
1449 TmpInst.setOpcode(X86::ADD32ri8);
1450 TmpInst.addOperand(MCOperand::CreateReg(X86::EAX));
1451 TmpInst.addOperand(MCOperand::CreateReg(X86::EAX));
1452 TmpInst.addOperand(Inst.getOperand(0));
1453 Inst = TmpInst;
1454 return true;
1455 }
1456 case X86::ADD64i32: {
1457 if (!Inst.getOperand(0).isImm() ||
1458 !isImmSExti64i8Value(Inst.getOperand(0).getImm()))
1459 return false;
1460
1461 MCInst TmpInst;
1462 TmpInst.setOpcode(X86::ADD64ri8);
1463 TmpInst.addOperand(MCOperand::CreateReg(X86::RAX));
1464 TmpInst.addOperand(MCOperand::CreateReg(X86::RAX));
1465 TmpInst.addOperand(Inst.getOperand(0));
1466 Inst = TmpInst;
1467 return true;
1468 }
1469 case X86::SUB16i16: {
1470 if (!Inst.getOperand(0).isImm() ||
1471 !isImmSExti16i8Value(Inst.getOperand(0).getImm()))
1472 return false;
1473
1474 MCInst TmpInst;
1475 TmpInst.setOpcode(X86::SUB16ri8);
1476 TmpInst.addOperand(MCOperand::CreateReg(X86::AX));
1477 TmpInst.addOperand(MCOperand::CreateReg(X86::AX));
1478 TmpInst.addOperand(Inst.getOperand(0));
1479 Inst = TmpInst;
1480 return true;
1481 }
1482 case X86::SUB32i32: {
1483 if (!Inst.getOperand(0).isImm() ||
1484 !isImmSExti32i8Value(Inst.getOperand(0).getImm()))
1485 return false;
1486
1487 MCInst TmpInst;
1488 TmpInst.setOpcode(X86::SUB32ri8);
1489 TmpInst.addOperand(MCOperand::CreateReg(X86::EAX));
1490 TmpInst.addOperand(MCOperand::CreateReg(X86::EAX));
1491 TmpInst.addOperand(Inst.getOperand(0));
1492 Inst = TmpInst;
1493 return true;
1494 }
1495 case X86::SUB64i32: {
1496 if (!Inst.getOperand(0).isImm() ||
1497 !isImmSExti64i8Value(Inst.getOperand(0).getImm()))
1498 return false;
1499
1500 MCInst TmpInst;
1501 TmpInst.setOpcode(X86::SUB64ri8);
1502 TmpInst.addOperand(MCOperand::CreateReg(X86::RAX));
1503 TmpInst.addOperand(MCOperand::CreateReg(X86::RAX));
1504 TmpInst.addOperand(Inst.getOperand(0));
1505 Inst = TmpInst;
1506 return true;
1507 }
Devang Patelb8ba13f2012-01-18 22:42:29 +00001508 }
Devang Patelb8ba13f2012-01-18 22:42:29 +00001509}
1510
1511bool X86AsmParser::
Chris Lattner7036f8b2010-09-29 01:42:58 +00001512MatchAndEmitInstruction(SMLoc IDLoc,
Chris Lattner7c51a312010-09-29 01:50:45 +00001513 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chris Lattner7036f8b2010-09-29 01:42:58 +00001514 MCStreamer &Out) {
Chad Rosier32461762012-08-09 22:04:55 +00001515 SmallVector<MCInst, 2> Insts;
1516 bool Error = MatchInstruction(IDLoc, Operands, Insts);
1517 if (!Error)
1518 for (unsigned i = 0, e = Insts.size(); i != e; ++i)
1519 Out.EmitInstruction(Insts[i]);
1520 return Error;
1521}
1522
1523bool X86AsmParser::
1524MatchInstruction(SMLoc IDLoc,
1525 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
1526 SmallVectorImpl<MCInst> &MCInsts) {
Daniel Dunbarf1e29d42010-08-12 00:55:38 +00001527 assert(!Operands.empty() && "Unexpect empty operand list!");
Chris Lattner7c51a312010-09-29 01:50:45 +00001528 X86Operand *Op = static_cast<X86Operand*>(Operands[0]);
1529 assert(Op->isToken() && "Leading operand should always be a mnemonic!");
Daniel Dunbarf1e29d42010-08-12 00:55:38 +00001530
Chris Lattner7c51a312010-09-29 01:50:45 +00001531 // First, handle aliases that expand to multiple instructions.
1532 // FIXME: This should be replaced with a real .td file alias mechanism.
Chris Lattner90fd7972010-11-06 19:57:21 +00001533 // Also, MatchInstructionImpl should do actually *do* the EmitInstruction
1534 // call.
Andrew Trick0966ec02010-10-22 03:58:29 +00001535 if (Op->getToken() == "fstsw" || Op->getToken() == "fstcw" ||
Chris Lattner8b260a72010-10-30 18:07:17 +00001536 Op->getToken() == "fstsww" || Op->getToken() == "fstcww" ||
Chris Lattner905f2e02010-09-30 17:11:29 +00001537 Op->getToken() == "finit" || Op->getToken() == "fsave" ||
Kevin Enderby5a378072010-10-27 02:53:04 +00001538 Op->getToken() == "fstenv" || Op->getToken() == "fclex") {
Chris Lattner7c51a312010-09-29 01:50:45 +00001539 MCInst Inst;
1540 Inst.setOpcode(X86::WAIT);
Jim Grosbachcb5dca32012-01-27 00:51:27 +00001541 Inst.setLoc(IDLoc);
Chad Rosier32461762012-08-09 22:04:55 +00001542 MCInsts.push_back(Inst);
Chris Lattner7c51a312010-09-29 01:50:45 +00001543
Chris Lattner0bb83a82010-09-30 16:39:29 +00001544 const char *Repl =
1545 StringSwitch<const char*>(Op->getToken())
Chris Lattner8b260a72010-10-30 18:07:17 +00001546 .Case("finit", "fninit")
1547 .Case("fsave", "fnsave")
1548 .Case("fstcw", "fnstcw")
1549 .Case("fstcww", "fnstcw")
Chris Lattner905f2e02010-09-30 17:11:29 +00001550 .Case("fstenv", "fnstenv")
Chris Lattner8b260a72010-10-30 18:07:17 +00001551 .Case("fstsw", "fnstsw")
1552 .Case("fstsww", "fnstsw")
1553 .Case("fclex", "fnclex")
Chris Lattner0bb83a82010-09-30 16:39:29 +00001554 .Default(0);
1555 assert(Repl && "Unknown wait-prefixed instruction");
Benjamin Kramerb0f96fa2010-10-01 12:25:27 +00001556 delete Operands[0];
Chris Lattner0bb83a82010-09-30 16:39:29 +00001557 Operands[0] = X86Operand::CreateToken(Repl, IDLoc);
Chris Lattner7c51a312010-09-29 01:50:45 +00001558 }
Michael J. Spencerc0c8df32010-10-09 11:00:50 +00001559
Chris Lattnera008e8a2010-09-06 21:54:15 +00001560 bool WasOriginallyInvalidOperand = false;
Chris Lattnerce4a3352010-09-06 22:11:18 +00001561 unsigned OrigErrorInfo;
Chris Lattner7036f8b2010-09-29 01:42:58 +00001562 MCInst Inst;
Michael J. Spencerc0c8df32010-10-09 11:00:50 +00001563
Daniel Dunbarc918d602010-05-04 16:12:42 +00001564 // First, try a direct match.
Devang Patelbe3e3102012-01-30 20:02:42 +00001565 switch (MatchInstructionImpl(Operands, Inst, OrigErrorInfo,
1566 isParsingIntelSyntax())) {
Jim Grosbach19cb7f42011-08-15 23:03:29 +00001567 default: break;
Chris Lattnerec6789f2010-09-06 20:08:02 +00001568 case Match_Success:
Devang Patelb8ba13f2012-01-18 22:42:29 +00001569 // Some instructions need post-processing to, for example, tweak which
1570 // encoding is selected. Loop on it while changes happen so the
Chad Rosier36b8fed2012-06-27 22:34:28 +00001571 // individual transformations can chain off each other.
Devang Patelb8ba13f2012-01-18 22:42:29 +00001572 while (processInstruction(Inst, Operands))
1573 ;
1574
Jim Grosbachcb5dca32012-01-27 00:51:27 +00001575 Inst.setLoc(IDLoc);
Chad Rosier32461762012-08-09 22:04:55 +00001576 MCInsts.push_back(Inst);
Daniel Dunbarc918d602010-05-04 16:12:42 +00001577 return false;
Chris Lattnerec6789f2010-09-06 20:08:02 +00001578 case Match_MissingFeature:
1579 Error(IDLoc, "instruction requires a CPU feature not currently enabled");
1580 return true;
Daniel Dunbarb4129152011-02-04 17:12:23 +00001581 case Match_ConversionFail:
1582 return Error(IDLoc, "unable to convert operands to instruction");
Chris Lattnera008e8a2010-09-06 21:54:15 +00001583 case Match_InvalidOperand:
1584 WasOriginallyInvalidOperand = true;
1585 break;
1586 case Match_MnemonicFail:
Chris Lattnerec6789f2010-09-06 20:08:02 +00001587 break;
1588 }
Daniel Dunbarc918d602010-05-04 16:12:42 +00001589
Daniel Dunbarc918d602010-05-04 16:12:42 +00001590 // FIXME: Ideally, we would only attempt suffix matches for things which are
1591 // valid prefixes, and we could just infer the right unambiguous
1592 // type. However, that requires substantially more matcher support than the
1593 // following hack.
Michael J. Spencerc0c8df32010-10-09 11:00:50 +00001594
Daniel Dunbarc918d602010-05-04 16:12:42 +00001595 // Change the operand to point to a temporary token.
Daniel Dunbarc918d602010-05-04 16:12:42 +00001596 StringRef Base = Op->getToken();
Daniel Dunbarf1e29d42010-08-12 00:55:38 +00001597 SmallString<16> Tmp;
1598 Tmp += Base;
1599 Tmp += ' ';
1600 Op->setTokenValue(Tmp.str());
Daniel Dunbarc918d602010-05-04 16:12:42 +00001601
Chris Lattnerfb7000f2010-11-06 18:28:02 +00001602 // If this instruction starts with an 'f', then it is a floating point stack
1603 // instruction. These come in up to three forms for 32-bit, 64-bit, and
1604 // 80-bit floating point, which use the suffixes s,l,t respectively.
1605 //
1606 // Otherwise, we assume that this may be an integer instruction, which comes
1607 // in 8/16/32/64-bit forms using the b,w,l,q suffixes respectively.
1608 const char *Suffixes = Base[0] != 'f' ? "bwlq" : "slt\0";
Chad Rosier36b8fed2012-06-27 22:34:28 +00001609
Daniel Dunbarc918d602010-05-04 16:12:42 +00001610 // Check for the various suffix matches.
Chris Lattnerfb7000f2010-11-06 18:28:02 +00001611 Tmp[Base.size()] = Suffixes[0];
1612 unsigned ErrorInfoIgnore;
Jim Grosbach19cb7f42011-08-15 23:03:29 +00001613 unsigned Match1, Match2, Match3, Match4;
Chad Rosier36b8fed2012-06-27 22:34:28 +00001614
Chris Lattnerfb7000f2010-11-06 18:28:02 +00001615 Match1 = MatchInstructionImpl(Operands, Inst, ErrorInfoIgnore);
1616 Tmp[Base.size()] = Suffixes[1];
1617 Match2 = MatchInstructionImpl(Operands, Inst, ErrorInfoIgnore);
1618 Tmp[Base.size()] = Suffixes[2];
1619 Match3 = MatchInstructionImpl(Operands, Inst, ErrorInfoIgnore);
1620 Tmp[Base.size()] = Suffixes[3];
1621 Match4 = MatchInstructionImpl(Operands, Inst, ErrorInfoIgnore);
Daniel Dunbarc918d602010-05-04 16:12:42 +00001622
1623 // Restore the old token.
1624 Op->setTokenValue(Base);
1625
1626 // If exactly one matched, then we treat that as a successful match (and the
1627 // instruction will already have been filled in correctly, since the failing
1628 // matches won't have modified it).
Chris Lattnerec6789f2010-09-06 20:08:02 +00001629 unsigned NumSuccessfulMatches =
Chris Lattnerfb7000f2010-11-06 18:28:02 +00001630 (Match1 == Match_Success) + (Match2 == Match_Success) +
1631 (Match3 == Match_Success) + (Match4 == Match_Success);
Chris Lattner7036f8b2010-09-29 01:42:58 +00001632 if (NumSuccessfulMatches == 1) {
Jim Grosbachcb5dca32012-01-27 00:51:27 +00001633 Inst.setLoc(IDLoc);
Chad Rosier32461762012-08-09 22:04:55 +00001634 MCInsts.push_back(Inst);
Daniel Dunbarc918d602010-05-04 16:12:42 +00001635 return false;
Chris Lattner7036f8b2010-09-29 01:42:58 +00001636 }
Daniel Dunbarc918d602010-05-04 16:12:42 +00001637
Chris Lattnerec6789f2010-09-06 20:08:02 +00001638 // Otherwise, the match failed, try to produce a decent error message.
Daniel Dunbarf1e29d42010-08-12 00:55:38 +00001639
Daniel Dunbar09062b12010-08-12 00:55:42 +00001640 // If we had multiple suffix matches, then identify this as an ambiguous
1641 // match.
Chris Lattnerec6789f2010-09-06 20:08:02 +00001642 if (NumSuccessfulMatches > 1) {
Daniel Dunbar09062b12010-08-12 00:55:42 +00001643 char MatchChars[4];
1644 unsigned NumMatches = 0;
Chris Lattnerfb7000f2010-11-06 18:28:02 +00001645 if (Match1 == Match_Success) MatchChars[NumMatches++] = Suffixes[0];
1646 if (Match2 == Match_Success) MatchChars[NumMatches++] = Suffixes[1];
1647 if (Match3 == Match_Success) MatchChars[NumMatches++] = Suffixes[2];
1648 if (Match4 == Match_Success) MatchChars[NumMatches++] = Suffixes[3];
Daniel Dunbar09062b12010-08-12 00:55:42 +00001649
1650 SmallString<126> Msg;
1651 raw_svector_ostream OS(Msg);
1652 OS << "ambiguous instructions require an explicit suffix (could be ";
1653 for (unsigned i = 0; i != NumMatches; ++i) {
1654 if (i != 0)
1655 OS << ", ";
1656 if (i + 1 == NumMatches)
1657 OS << "or ";
1658 OS << "'" << Base << MatchChars[i] << "'";
1659 }
1660 OS << ")";
1661 Error(IDLoc, OS.str());
Chris Lattnerec6789f2010-09-06 20:08:02 +00001662 return true;
Daniel Dunbar09062b12010-08-12 00:55:42 +00001663 }
Michael J. Spencerc0c8df32010-10-09 11:00:50 +00001664
Chris Lattnera008e8a2010-09-06 21:54:15 +00001665 // Okay, we know that none of the variants matched successfully.
Michael J. Spencerc0c8df32010-10-09 11:00:50 +00001666
Chris Lattnera008e8a2010-09-06 21:54:15 +00001667 // If all of the instructions reported an invalid mnemonic, then the original
1668 // mnemonic was invalid.
Chris Lattnerfb7000f2010-11-06 18:28:02 +00001669 if ((Match1 == Match_MnemonicFail) && (Match2 == Match_MnemonicFail) &&
1670 (Match3 == Match_MnemonicFail) && (Match4 == Match_MnemonicFail)) {
Chris Lattnerce4a3352010-09-06 22:11:18 +00001671 if (!WasOriginallyInvalidOperand) {
Benjamin Kramerf82edaf2011-10-16 11:28:29 +00001672 return Error(IDLoc, "invalid instruction mnemonic '" + Base + "'",
1673 Op->getLocRange());
Chris Lattnerce4a3352010-09-06 22:11:18 +00001674 }
1675
1676 // Recover location info for the operand if we know which was the problem.
Chris Lattnerce4a3352010-09-06 22:11:18 +00001677 if (OrigErrorInfo != ~0U) {
Chris Lattnerf8840122010-09-15 03:50:11 +00001678 if (OrigErrorInfo >= Operands.size())
1679 return Error(IDLoc, "too few operands for instruction");
Michael J. Spencerc0c8df32010-10-09 11:00:50 +00001680
Chris Lattnerd8b7aa22011-10-16 04:47:35 +00001681 X86Operand *Operand = (X86Operand*)Operands[OrigErrorInfo];
1682 if (Operand->getStartLoc().isValid()) {
1683 SMRange OperandRange = Operand->getLocRange();
1684 return Error(Operand->getStartLoc(), "invalid operand for instruction",
1685 OperandRange);
1686 }
Chris Lattnerce4a3352010-09-06 22:11:18 +00001687 }
1688
Chris Lattnerd8b7aa22011-10-16 04:47:35 +00001689 return Error(IDLoc, "invalid operand for instruction");
Chris Lattnera008e8a2010-09-06 21:54:15 +00001690 }
Michael J. Spencerc0c8df32010-10-09 11:00:50 +00001691
Chris Lattnerec6789f2010-09-06 20:08:02 +00001692 // If one instruction matched with a missing feature, report this as a
1693 // missing feature.
Chris Lattnerfb7000f2010-11-06 18:28:02 +00001694 if ((Match1 == Match_MissingFeature) + (Match2 == Match_MissingFeature) +
1695 (Match3 == Match_MissingFeature) + (Match4 == Match_MissingFeature) == 1){
Chris Lattnerec6789f2010-09-06 20:08:02 +00001696 Error(IDLoc, "instruction requires a CPU feature not currently enabled");
1697 return true;
1698 }
Michael J. Spencerc0c8df32010-10-09 11:00:50 +00001699
Chris Lattnera008e8a2010-09-06 21:54:15 +00001700 // If one instruction matched with an invalid operand, report this as an
1701 // operand failure.
Chris Lattnerfb7000f2010-11-06 18:28:02 +00001702 if ((Match1 == Match_InvalidOperand) + (Match2 == Match_InvalidOperand) +
1703 (Match3 == Match_InvalidOperand) + (Match4 == Match_InvalidOperand) == 1){
Chris Lattnera008e8a2010-09-06 21:54:15 +00001704 Error(IDLoc, "invalid operand for instruction");
1705 return true;
1706 }
Michael J. Spencerc0c8df32010-10-09 11:00:50 +00001707
Chris Lattnerec6789f2010-09-06 20:08:02 +00001708 // If all of these were an outright failure, report it in a useless way.
Chris Lattnera008e8a2010-09-06 21:54:15 +00001709 Error(IDLoc, "unknown use of instruction mnemonic without a size suffix");
Daniel Dunbarc918d602010-05-04 16:12:42 +00001710 return true;
1711}
1712
1713
Devang Pateldd929fc2012-01-12 18:03:40 +00001714bool X86AsmParser::ParseDirective(AsmToken DirectiveID) {
Chris Lattner537ca842010-10-30 17:38:55 +00001715 StringRef IDVal = DirectiveID.getIdentifier();
1716 if (IDVal == ".word")
1717 return ParseDirectiveWord(2, DirectiveID.getLoc());
Evan Chengbd27f5a2011-07-27 00:38:12 +00001718 else if (IDVal.startswith(".code"))
1719 return ParseDirectiveCode(IDVal, DirectiveID.getLoc());
Devang Patelbe3e3102012-01-30 20:02:42 +00001720 else if (IDVal.startswith(".intel_syntax")) {
Devang Patel0db58bf2012-01-31 18:14:05 +00001721 getParser().setAssemblerDialect(1);
Devang Patelbe3e3102012-01-30 20:02:42 +00001722 if (getLexer().isNot(AsmToken::EndOfStatement)) {
1723 if(Parser.getTok().getString() == "noprefix") {
Craig Topper76bd9382012-07-18 04:59:16 +00001724 // FIXME : Handle noprefix
1725 Parser.Lex();
Devang Patelbe3e3102012-01-30 20:02:42 +00001726 } else
Craig Topper76bd9382012-07-18 04:59:16 +00001727 return true;
Devang Patelbe3e3102012-01-30 20:02:42 +00001728 }
1729 return false;
1730 }
Chris Lattner537ca842010-10-30 17:38:55 +00001731 return true;
1732}
1733
1734/// ParseDirectiveWord
1735/// ::= .word [ expression (, expression)* ]
Devang Pateldd929fc2012-01-12 18:03:40 +00001736bool X86AsmParser::ParseDirectiveWord(unsigned Size, SMLoc L) {
Chris Lattner537ca842010-10-30 17:38:55 +00001737 if (getLexer().isNot(AsmToken::EndOfStatement)) {
1738 for (;;) {
1739 const MCExpr *Value;
1740 if (getParser().ParseExpression(Value))
1741 return true;
Chad Rosier36b8fed2012-06-27 22:34:28 +00001742
Chris Lattner537ca842010-10-30 17:38:55 +00001743 getParser().getStreamer().EmitValue(Value, Size, 0 /*addrspace*/);
Chad Rosier36b8fed2012-06-27 22:34:28 +00001744
Chris Lattner537ca842010-10-30 17:38:55 +00001745 if (getLexer().is(AsmToken::EndOfStatement))
1746 break;
Chad Rosier36b8fed2012-06-27 22:34:28 +00001747
Chris Lattner537ca842010-10-30 17:38:55 +00001748 // FIXME: Improve diagnostic.
1749 if (getLexer().isNot(AsmToken::Comma))
1750 return Error(L, "unexpected token in directive");
1751 Parser.Lex();
1752 }
1753 }
Chad Rosier36b8fed2012-06-27 22:34:28 +00001754
Chris Lattner537ca842010-10-30 17:38:55 +00001755 Parser.Lex();
1756 return false;
1757}
1758
Evan Chengbd27f5a2011-07-27 00:38:12 +00001759/// ParseDirectiveCode
1760/// ::= .code32 | .code64
Devang Pateldd929fc2012-01-12 18:03:40 +00001761bool X86AsmParser::ParseDirectiveCode(StringRef IDVal, SMLoc L) {
Evan Chengbd27f5a2011-07-27 00:38:12 +00001762 if (IDVal == ".code32") {
1763 Parser.Lex();
1764 if (is64BitMode()) {
1765 SwitchMode();
1766 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
1767 }
1768 } else if (IDVal == ".code64") {
1769 Parser.Lex();
1770 if (!is64BitMode()) {
1771 SwitchMode();
1772 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code64);
1773 }
1774 } else {
1775 return Error(L, "unexpected directive " + IDVal);
1776 }
Chris Lattner537ca842010-10-30 17:38:55 +00001777
Evan Chengbd27f5a2011-07-27 00:38:12 +00001778 return false;
1779}
Chris Lattner537ca842010-10-30 17:38:55 +00001780
1781
Sean Callanane88f5522010-01-23 02:43:15 +00001782extern "C" void LLVMInitializeX86AsmLexer();
1783
Daniel Dunbar092a9dd2009-07-17 20:42:00 +00001784// Force static initialization.
1785extern "C" void LLVMInitializeX86AsmParser() {
Devang Pateldd929fc2012-01-12 18:03:40 +00001786 RegisterMCAsmParser<X86AsmParser> X(TheX86_32Target);
1787 RegisterMCAsmParser<X86AsmParser> Y(TheX86_64Target);
Sean Callanane88f5522010-01-23 02:43:15 +00001788 LLVMInitializeX86AsmLexer();
Daniel Dunbar092a9dd2009-07-17 20:42:00 +00001789}
Daniel Dunbar0e2771f2009-07-29 00:02:19 +00001790
Chris Lattner0692ee62010-09-06 19:11:01 +00001791#define GET_REGISTER_MATCHER
1792#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar0e2771f2009-07-29 00:02:19 +00001793#include "X86GenAsmMatcher.inc"