blob: c139dbce03465a78044377981e095e30cc0c17e7 [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,
Chad Rosier64bfcbb2012-08-21 18:14:59 +000070 SmallVectorImpl<MCInst> &MCInsts,
71 unsigned &OrigErrorInfo);
Chad Rosier32461762012-08-09 22:04:55 +000072
Joerg Sonnenberger96622aa2011-03-18 11:59:40 +000073 /// isSrcOp - Returns true if operand is either (%rsi) or %ds:%(rsi)
Kevin Enderby0f5ab7c2012-03-13 19:47:55 +000074 /// in 64bit mode or (%esi) or %es:(%esi) in 32bit mode.
Joerg Sonnenberger96622aa2011-03-18 11:59:40 +000075 bool isSrcOp(X86Operand &Op);
76
Kevin Enderby0f5ab7c2012-03-13 19:47:55 +000077 /// isDstOp - Returns true if operand is either (%rdi) or %es:(%rdi)
78 /// in 64bit mode or (%edi) or %es:(%edi) in 32bit mode.
Joerg Sonnenberger96622aa2011-03-18 11:59:40 +000079 bool isDstOp(X86Operand &Op);
80
Evan Cheng59ee62d2011-07-11 03:57:24 +000081 bool is64BitMode() const {
Evan Chengebdeeab2011-07-08 01:53:10 +000082 // FIXME: Can tablegen auto-generate this?
Evan Chengffc0e732011-07-09 05:47:46 +000083 return (STI.getFeatureBits() & X86::Mode64Bit) != 0;
Evan Chengebdeeab2011-07-08 01:53:10 +000084 }
Evan Chengbd27f5a2011-07-27 00:38:12 +000085 void SwitchMode() {
86 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(X86::Mode64Bit));
87 setAvailableFeatures(FB);
88 }
Evan Chengebdeeab2011-07-08 01:53:10 +000089
Daniel Dunbar54074b52010-07-19 05:44:09 +000090 /// @name Auto-generated Matcher Functions
91 /// {
Michael J. Spencerc0c8df32010-10-09 11:00:50 +000092
Chris Lattner0692ee62010-09-06 19:11:01 +000093#define GET_ASSEMBLER_HEADER
94#include "X86GenAsmMatcher.inc"
Michael J. Spencerc0c8df32010-10-09 11:00:50 +000095
Daniel Dunbar0e2771f2009-07-29 00:02:19 +000096 /// }
Daniel Dunbar16cdcb32009-07-28 22:40:46 +000097
98public:
Devang Pateldd929fc2012-01-12 18:03:40 +000099 X86AsmParser(MCSubtargetInfo &sti, MCAsmParser &parser)
Devang Patel0db58bf2012-01-31 18:14:05 +0000100 : MCTargetAsmParser(), STI(sti), Parser(parser) {
Michael J. Spencerc0c8df32010-10-09 11:00:50 +0000101
Daniel Dunbar54074b52010-07-19 05:44:09 +0000102 // Initialize the set of available features.
Evan Chengffc0e732011-07-09 05:47:46 +0000103 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Daniel Dunbar54074b52010-07-19 05:44:09 +0000104 }
Roman Divackybf755322011-01-27 17:14:22 +0000105 virtual bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000106
Benjamin Kramer38e59892010-07-14 22:38:02 +0000107 virtual bool ParseInstruction(StringRef Name, SMLoc NameLoc,
Chris Lattner98986712010-01-14 22:21:20 +0000108 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Kevin Enderby9c656452009-09-10 20:51:44 +0000109
110 virtual bool ParseDirective(AsmToken DirectiveID);
Devang Patelbe3e3102012-01-30 20:02:42 +0000111
112 bool isParsingIntelSyntax() {
Devang Patel0db58bf2012-01-31 18:14:05 +0000113 return getParser().getAssemblerDialect();
Devang Patelbe3e3102012-01-30 20:02:42 +0000114 }
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000115};
Chris Lattner37dfdec2009-07-29 06:33:53 +0000116} // end anonymous namespace
117
Sean Callanane9b466d2010-01-23 00:40:33 +0000118/// @name Auto-generated Match Functions
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000119/// {
Sean Callanane9b466d2010-01-23 00:40:33 +0000120
Chris Lattnerb8d6e982010-02-09 00:34:28 +0000121static unsigned MatchRegisterName(StringRef Name);
Sean Callanane9b466d2010-01-23 00:40:33 +0000122
123/// }
Chris Lattner37dfdec2009-07-29 06:33:53 +0000124
Craig Topper76bd9382012-07-18 04:59:16 +0000125static bool isImmSExti16i8Value(uint64_t Value) {
Devang Patelb8ba13f2012-01-18 22:42:29 +0000126 return (( Value <= 0x000000000000007FULL)||
127 (0x000000000000FF80ULL <= Value && Value <= 0x000000000000FFFFULL)||
128 (0xFFFFFFFFFFFFFF80ULL <= Value && Value <= 0xFFFFFFFFFFFFFFFFULL));
129}
130
131static bool isImmSExti32i8Value(uint64_t Value) {
132 return (( Value <= 0x000000000000007FULL)||
133 (0x00000000FFFFFF80ULL <= Value && Value <= 0x00000000FFFFFFFFULL)||
134 (0xFFFFFFFFFFFFFF80ULL <= Value && Value <= 0xFFFFFFFFFFFFFFFFULL));
135}
136
137static bool isImmZExtu32u8Value(uint64_t Value) {
138 return (Value <= 0x00000000000000FFULL);
139}
140
141static bool isImmSExti64i8Value(uint64_t Value) {
142 return (( Value <= 0x000000000000007FULL)||
Craig Topper76bd9382012-07-18 04:59:16 +0000143 (0xFFFFFFFFFFFFFF80ULL <= Value && Value <= 0xFFFFFFFFFFFFFFFFULL));
Devang Patelb8ba13f2012-01-18 22:42:29 +0000144}
145
146static bool isImmSExti64i32Value(uint64_t Value) {
147 return (( Value <= 0x000000007FFFFFFFULL)||
Craig Topper76bd9382012-07-18 04:59:16 +0000148 (0xFFFFFFFF80000000ULL <= Value && Value <= 0xFFFFFFFFFFFFFFFFULL));
Devang Patelb8ba13f2012-01-18 22:42:29 +0000149}
Chris Lattner37dfdec2009-07-29 06:33:53 +0000150namespace {
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000151
152/// X86Operand - Instances of this class represent a parsed X86 machine
153/// instruction.
Chris Lattner45220a82010-01-14 21:20:55 +0000154struct X86Operand : public MCParsedAsmOperand {
Chris Lattner1f19f0f2010-01-15 19:06:59 +0000155 enum KindTy {
Daniel Dunbar20927f22009-08-07 08:26:05 +0000156 Token,
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000157 Register,
158 Immediate,
159 Memory
160 } Kind;
161
Chris Lattner29ef9a22010-01-15 18:51:29 +0000162 SMLoc StartLoc, EndLoc;
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000163
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000164 union {
165 struct {
Daniel Dunbar20927f22009-08-07 08:26:05 +0000166 const char *Data;
167 unsigned Length;
168 } Tok;
169
170 struct {
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000171 unsigned RegNo;
172 } Reg;
173
174 struct {
Daniel Dunbar8c2eebe2009-08-31 08:08:38 +0000175 const MCExpr *Val;
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000176 } Imm;
177
178 struct {
179 unsigned SegReg;
Daniel Dunbar8c2eebe2009-08-31 08:08:38 +0000180 const MCExpr *Disp;
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000181 unsigned BaseReg;
182 unsigned IndexReg;
183 unsigned Scale;
Devang Patelc59d9df2012-01-12 01:51:42 +0000184 unsigned Size;
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000185 } Mem;
Daniel Dunbardbd692a2009-07-20 20:01:54 +0000186 };
Daniel Dunbar092a9dd2009-07-17 20:42:00 +0000187
Chris Lattner0a3c5a52010-01-15 19:33:43 +0000188 X86Operand(KindTy K, SMLoc Start, SMLoc End)
Chris Lattner1f19f0f2010-01-15 19:06:59 +0000189 : Kind(K), StartLoc(Start), EndLoc(End) {}
Daniel Dunbarc918d602010-05-04 16:12:42 +0000190
Chris Lattner1f19f0f2010-01-15 19:06:59 +0000191 /// getStartLoc - Get the location of the first token of this operand.
192 SMLoc getStartLoc() const { return StartLoc; }
193 /// getEndLoc - Get the location of the last token of this operand.
194 SMLoc getEndLoc() const { return EndLoc; }
Chad Rosier36b8fed2012-06-27 22:34:28 +0000195
Chris Lattnerd8b7aa22011-10-16 04:47:35 +0000196 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
Chris Lattner1f19f0f2010-01-15 19:06:59 +0000197
Jim Grosbachb7f689b2011-07-13 15:34:57 +0000198 virtual void print(raw_ostream &OS) const {}
Daniel Dunbarb3cb6962010-08-11 06:37:04 +0000199
Daniel Dunbar20927f22009-08-07 08:26:05 +0000200 StringRef getToken() const {
201 assert(Kind == Token && "Invalid access!");
202 return StringRef(Tok.Data, Tok.Length);
203 }
Daniel Dunbarc918d602010-05-04 16:12:42 +0000204 void setTokenValue(StringRef Value) {
205 assert(Kind == Token && "Invalid access!");
206 Tok.Data = Value.data();
207 Tok.Length = Value.size();
208 }
Daniel Dunbar20927f22009-08-07 08:26:05 +0000209
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000210 unsigned getReg() const {
211 assert(Kind == Register && "Invalid access!");
212 return Reg.RegNo;
213 }
Daniel Dunbara2edbab2009-07-28 20:47:52 +0000214
Daniel Dunbar8c2eebe2009-08-31 08:08:38 +0000215 const MCExpr *getImm() const {
Daniel Dunbar022e2a82009-07-31 20:53:16 +0000216 assert(Kind == Immediate && "Invalid access!");
217 return Imm.Val;
218 }
219
Daniel Dunbar8c2eebe2009-08-31 08:08:38 +0000220 const MCExpr *getMemDisp() const {
Daniel Dunbar022e2a82009-07-31 20:53:16 +0000221 assert(Kind == Memory && "Invalid access!");
222 return Mem.Disp;
223 }
224 unsigned getMemSegReg() const {
225 assert(Kind == Memory && "Invalid access!");
226 return Mem.SegReg;
227 }
228 unsigned getMemBaseReg() const {
229 assert(Kind == Memory && "Invalid access!");
230 return Mem.BaseReg;
231 }
232 unsigned getMemIndexReg() const {
233 assert(Kind == Memory && "Invalid access!");
234 return Mem.IndexReg;
235 }
236 unsigned getMemScale() const {
237 assert(Kind == Memory && "Invalid access!");
238 return Mem.Scale;
239 }
240
Daniel Dunbara3741fa2009-08-08 07:50:56 +0000241 bool isToken() const {return Kind == Token; }
Daniel Dunbar20927f22009-08-07 08:26:05 +0000242
243 bool isImm() const { return Kind == Immediate; }
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000244
Daniel Dunbar62e4c672010-05-22 21:02:33 +0000245 bool isImmSExti16i8() const {
Daniel Dunbar5fe63382009-08-09 07:20:21 +0000246 if (!isImm())
247 return false;
248
Daniel Dunbar62e4c672010-05-22 21:02:33 +0000249 // If this isn't a constant expr, just assume it fits and let relaxation
250 // handle it.
251 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
252 if (!CE)
253 return true;
Daniel Dunbar5fe63382009-08-09 07:20:21 +0000254
Daniel Dunbar62e4c672010-05-22 21:02:33 +0000255 // Otherwise, check the value is in a range that makes sense for this
256 // extension.
Devang Patelb8ba13f2012-01-18 22:42:29 +0000257 return isImmSExti16i8Value(CE->getValue());
Daniel Dunbar5fe63382009-08-09 07:20:21 +0000258 }
Daniel Dunbar62e4c672010-05-22 21:02:33 +0000259 bool isImmSExti32i8() const {
Daniel Dunbar1fe591d2010-05-20 20:20:39 +0000260 if (!isImm())
261 return false;
262
Daniel Dunbar62e4c672010-05-22 21:02:33 +0000263 // If this isn't a constant expr, just assume it fits and let relaxation
264 // handle it.
265 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
266 if (!CE)
267 return true;
Daniel Dunbar1fe591d2010-05-20 20:20:39 +0000268
Daniel Dunbar62e4c672010-05-22 21:02:33 +0000269 // Otherwise, check the value is in a range that makes sense for this
270 // extension.
Devang Patelb8ba13f2012-01-18 22:42:29 +0000271 return isImmSExti32i8Value(CE->getValue());
Daniel Dunbar62e4c672010-05-22 21:02:33 +0000272 }
Kevin Enderbyc37d4bb2011-07-27 23:01:50 +0000273 bool isImmZExtu32u8() const {
274 if (!isImm())
275 return false;
276
277 // If this isn't a constant expr, just assume it fits and let relaxation
278 // handle it.
279 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
280 if (!CE)
281 return true;
282
283 // Otherwise, check the value is in a range that makes sense for this
284 // extension.
Devang Patelb8ba13f2012-01-18 22:42:29 +0000285 return isImmZExtu32u8Value(CE->getValue());
Kevin Enderbyc37d4bb2011-07-27 23:01:50 +0000286 }
Daniel Dunbar62e4c672010-05-22 21:02:33 +0000287 bool isImmSExti64i8() const {
288 if (!isImm())
289 return false;
290
291 // If this isn't a constant expr, just assume it fits and let relaxation
292 // handle it.
293 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
294 if (!CE)
295 return true;
296
297 // Otherwise, check the value is in a range that makes sense for this
298 // extension.
Devang Patelb8ba13f2012-01-18 22:42:29 +0000299 return isImmSExti64i8Value(CE->getValue());
Daniel Dunbar62e4c672010-05-22 21:02:33 +0000300 }
301 bool isImmSExti64i32() const {
302 if (!isImm())
303 return false;
304
305 // If this isn't a constant expr, just assume it fits and let relaxation
306 // handle it.
307 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
308 if (!CE)
309 return true;
310
311 // Otherwise, check the value is in a range that makes sense for this
312 // extension.
Devang Patelb8ba13f2012-01-18 22:42:29 +0000313 return isImmSExti64i32Value(CE->getValue());
Daniel Dunbar1fe591d2010-05-20 20:20:39 +0000314 }
315
Daniel Dunbar20927f22009-08-07 08:26:05 +0000316 bool isMem() const { return Kind == Memory; }
Chad Rosier36b8fed2012-06-27 22:34:28 +0000317 bool isMem8() const {
Devang Patelc59d9df2012-01-12 01:51:42 +0000318 return Kind == Memory && (!Mem.Size || Mem.Size == 8);
319 }
Chad Rosier36b8fed2012-06-27 22:34:28 +0000320 bool isMem16() const {
Devang Patelc59d9df2012-01-12 01:51:42 +0000321 return Kind == Memory && (!Mem.Size || Mem.Size == 16);
322 }
Chad Rosier36b8fed2012-06-27 22:34:28 +0000323 bool isMem32() const {
Devang Patelc59d9df2012-01-12 01:51:42 +0000324 return Kind == Memory && (!Mem.Size || Mem.Size == 32);
325 }
Chad Rosier36b8fed2012-06-27 22:34:28 +0000326 bool isMem64() const {
Devang Patelc59d9df2012-01-12 01:51:42 +0000327 return Kind == Memory && (!Mem.Size || Mem.Size == 64);
328 }
Chad Rosier36b8fed2012-06-27 22:34:28 +0000329 bool isMem80() const {
Devang Patelc59d9df2012-01-12 01:51:42 +0000330 return Kind == Memory && (!Mem.Size || Mem.Size == 80);
331 }
Chad Rosier36b8fed2012-06-27 22:34:28 +0000332 bool isMem128() const {
Devang Patelc59d9df2012-01-12 01:51:42 +0000333 return Kind == Memory && (!Mem.Size || Mem.Size == 128);
334 }
Chad Rosier36b8fed2012-06-27 22:34:28 +0000335 bool isMem256() const {
Devang Patelc59d9df2012-01-12 01:51:42 +0000336 return Kind == Memory && (!Mem.Size || Mem.Size == 256);
337 }
Daniel Dunbar20927f22009-08-07 08:26:05 +0000338
Craig Topper75dc33a2012-07-18 04:11:12 +0000339 bool isMemVX32() const {
340 return Kind == Memory && (!Mem.Size || Mem.Size == 32) &&
341 getMemIndexReg() >= X86::XMM0 && getMemIndexReg() <= X86::XMM15;
342 }
343 bool isMemVY32() const {
344 return Kind == Memory && (!Mem.Size || Mem.Size == 32) &&
345 getMemIndexReg() >= X86::YMM0 && getMemIndexReg() <= X86::YMM15;
346 }
347 bool isMemVX64() const {
348 return Kind == Memory && (!Mem.Size || Mem.Size == 64) &&
349 getMemIndexReg() >= X86::XMM0 && getMemIndexReg() <= X86::XMM15;
350 }
351 bool isMemVY64() const {
352 return Kind == Memory && (!Mem.Size || Mem.Size == 64) &&
353 getMemIndexReg() >= X86::YMM0 && getMemIndexReg() <= X86::YMM15;
354 }
355
Daniel Dunbarb834f5d2010-01-30 01:02:48 +0000356 bool isAbsMem() const {
357 return Kind == Memory && !getMemSegReg() && !getMemBaseReg() &&
Daniel Dunbar7b9147a2010-02-02 21:44:16 +0000358 !getMemIndexReg() && getMemScale() == 1;
Daniel Dunbarb834f5d2010-01-30 01:02:48 +0000359 }
360
Daniel Dunbar20927f22009-08-07 08:26:05 +0000361 bool isReg() const { return Kind == Register; }
362
Daniel Dunbar9c60f532010-02-13 00:17:21 +0000363 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
364 // Add as immediates when possible.
365 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
366 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
367 else
368 Inst.addOperand(MCOperand::CreateExpr(Expr));
369 }
370
Daniel Dunbar5c468e32009-08-10 21:00:45 +0000371 void addRegOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar20927f22009-08-07 08:26:05 +0000372 assert(N == 1 && "Invalid number of operands!");
373 Inst.addOperand(MCOperand::CreateReg(getReg()));
374 }
375
Daniel Dunbar5c468e32009-08-10 21:00:45 +0000376 void addImmOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar20927f22009-08-07 08:26:05 +0000377 assert(N == 1 && "Invalid number of operands!");
Daniel Dunbar9c60f532010-02-13 00:17:21 +0000378 addExpr(Inst, getImm());
Daniel Dunbar20927f22009-08-07 08:26:05 +0000379 }
380
Chad Rosier36b8fed2012-06-27 22:34:28 +0000381 void addMem8Operands(MCInst &Inst, unsigned N) const {
382 addMemOperands(Inst, N);
Devang Patelc59d9df2012-01-12 01:51:42 +0000383 }
Chad Rosier36b8fed2012-06-27 22:34:28 +0000384 void addMem16Operands(MCInst &Inst, unsigned N) const {
385 addMemOperands(Inst, N);
Devang Patelc59d9df2012-01-12 01:51:42 +0000386 }
Chad Rosier36b8fed2012-06-27 22:34:28 +0000387 void addMem32Operands(MCInst &Inst, unsigned N) const {
388 addMemOperands(Inst, N);
Devang Patelc59d9df2012-01-12 01:51:42 +0000389 }
Chad Rosier36b8fed2012-06-27 22:34:28 +0000390 void addMem64Operands(MCInst &Inst, unsigned N) const {
391 addMemOperands(Inst, N);
Devang Patelc59d9df2012-01-12 01:51:42 +0000392 }
Chad Rosier36b8fed2012-06-27 22:34:28 +0000393 void addMem80Operands(MCInst &Inst, unsigned N) const {
394 addMemOperands(Inst, N);
Devang Patelc59d9df2012-01-12 01:51:42 +0000395 }
Chad Rosier36b8fed2012-06-27 22:34:28 +0000396 void addMem128Operands(MCInst &Inst, unsigned N) const {
397 addMemOperands(Inst, N);
Devang Patelc59d9df2012-01-12 01:51:42 +0000398 }
Chad Rosier36b8fed2012-06-27 22:34:28 +0000399 void addMem256Operands(MCInst &Inst, unsigned N) const {
400 addMemOperands(Inst, N);
Devang Patelc59d9df2012-01-12 01:51:42 +0000401 }
Craig Topper75dc33a2012-07-18 04:11:12 +0000402 void addMemVX32Operands(MCInst &Inst, unsigned N) const {
403 addMemOperands(Inst, N);
404 }
405 void addMemVY32Operands(MCInst &Inst, unsigned N) const {
406 addMemOperands(Inst, N);
407 }
408 void addMemVX64Operands(MCInst &Inst, unsigned N) const {
409 addMemOperands(Inst, N);
410 }
411 void addMemVY64Operands(MCInst &Inst, unsigned N) const {
412 addMemOperands(Inst, N);
413 }
Devang Patelc59d9df2012-01-12 01:51:42 +0000414
Daniel Dunbar5c468e32009-08-10 21:00:45 +0000415 void addMemOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbarec2b1f12010-01-30 00:24:00 +0000416 assert((N == 5) && "Invalid number of operands!");
Daniel Dunbar20927f22009-08-07 08:26:05 +0000417 Inst.addOperand(MCOperand::CreateReg(getMemBaseReg()));
418 Inst.addOperand(MCOperand::CreateImm(getMemScale()));
419 Inst.addOperand(MCOperand::CreateReg(getMemIndexReg()));
Daniel Dunbar9c60f532010-02-13 00:17:21 +0000420 addExpr(Inst, getMemDisp());
Daniel Dunbarec2b1f12010-01-30 00:24:00 +0000421 Inst.addOperand(MCOperand::CreateReg(getMemSegReg()));
422 }
Daniel Dunbar20927f22009-08-07 08:26:05 +0000423
Daniel Dunbarb834f5d2010-01-30 01:02:48 +0000424 void addAbsMemOperands(MCInst &Inst, unsigned N) const {
425 assert((N == 1) && "Invalid number of operands!");
Kevin Enderbyb80d5712012-02-23 18:18:17 +0000426 // Add as immediates when possible.
427 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getMemDisp()))
428 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
429 else
430 Inst.addOperand(MCOperand::CreateExpr(getMemDisp()));
Daniel Dunbarb834f5d2010-01-30 01:02:48 +0000431 }
432
Chris Lattnerb4307b32010-01-15 19:28:38 +0000433 static X86Operand *CreateToken(StringRef Str, SMLoc Loc) {
Benjamin Kramerf82edaf2011-10-16 11:28:29 +0000434 SMLoc EndLoc = SMLoc::getFromPointer(Loc.getPointer() + Str.size() - 1);
435 X86Operand *Res = new X86Operand(Token, Loc, EndLoc);
Chris Lattner29ef9a22010-01-15 18:51:29 +0000436 Res->Tok.Data = Str.data();
437 Res->Tok.Length = Str.size();
Daniel Dunbar20927f22009-08-07 08:26:05 +0000438 return Res;
439 }
440
Chris Lattner29ef9a22010-01-15 18:51:29 +0000441 static X86Operand *CreateReg(unsigned RegNo, SMLoc StartLoc, SMLoc EndLoc) {
Chris Lattner1f19f0f2010-01-15 19:06:59 +0000442 X86Operand *Res = new X86Operand(Register, StartLoc, EndLoc);
Chris Lattner29ef9a22010-01-15 18:51:29 +0000443 Res->Reg.RegNo = RegNo;
Chris Lattner29ef9a22010-01-15 18:51:29 +0000444 return Res;
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000445 }
Daniel Dunbar20927f22009-08-07 08:26:05 +0000446
Chris Lattnerb4307b32010-01-15 19:28:38 +0000447 static X86Operand *CreateImm(const MCExpr *Val, SMLoc StartLoc, SMLoc EndLoc){
448 X86Operand *Res = new X86Operand(Immediate, StartLoc, EndLoc);
Chris Lattner29ef9a22010-01-15 18:51:29 +0000449 Res->Imm.Val = Val;
450 return Res;
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000451 }
Daniel Dunbar20927f22009-08-07 08:26:05 +0000452
Daniel Dunbarb834f5d2010-01-30 01:02:48 +0000453 /// Create an absolute memory operand.
454 static X86Operand *CreateMem(const MCExpr *Disp, SMLoc StartLoc,
Devang Patelc59d9df2012-01-12 01:51:42 +0000455 SMLoc EndLoc, unsigned Size = 0) {
Daniel Dunbarb834f5d2010-01-30 01:02:48 +0000456 X86Operand *Res = new X86Operand(Memory, StartLoc, EndLoc);
457 Res->Mem.SegReg = 0;
458 Res->Mem.Disp = Disp;
459 Res->Mem.BaseReg = 0;
460 Res->Mem.IndexReg = 0;
Daniel Dunbar7b9147a2010-02-02 21:44:16 +0000461 Res->Mem.Scale = 1;
Devang Patelc59d9df2012-01-12 01:51:42 +0000462 Res->Mem.Size = Size;
Daniel Dunbarb834f5d2010-01-30 01:02:48 +0000463 return Res;
464 }
465
466 /// Create a generalized memory operand.
Chris Lattner309264d2010-01-15 18:44:13 +0000467 static X86Operand *CreateMem(unsigned SegReg, const MCExpr *Disp,
468 unsigned BaseReg, unsigned IndexReg,
Devang Patelc59d9df2012-01-12 01:51:42 +0000469 unsigned Scale, SMLoc StartLoc, SMLoc EndLoc,
470 unsigned Size = 0) {
Daniel Dunbarb834f5d2010-01-30 01:02:48 +0000471 // We should never just have a displacement, that should be parsed as an
472 // absolute memory operand.
Daniel Dunbarc09e4112009-07-31 22:22:54 +0000473 assert((SegReg || BaseReg || IndexReg) && "Invalid memory operand!");
474
Daniel Dunbar022e2a82009-07-31 20:53:16 +0000475 // The scale should always be one of {1,2,4,8}.
476 assert(((Scale == 1 || Scale == 2 || Scale == 4 || Scale == 8)) &&
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000477 "Invalid scale!");
Chris Lattner0a3c5a52010-01-15 19:33:43 +0000478 X86Operand *Res = new X86Operand(Memory, StartLoc, EndLoc);
Chris Lattner29ef9a22010-01-15 18:51:29 +0000479 Res->Mem.SegReg = SegReg;
480 Res->Mem.Disp = Disp;
481 Res->Mem.BaseReg = BaseReg;
482 Res->Mem.IndexReg = IndexReg;
483 Res->Mem.Scale = Scale;
Devang Patelc59d9df2012-01-12 01:51:42 +0000484 Res->Mem.Size = Size;
Chris Lattner29ef9a22010-01-15 18:51:29 +0000485 return Res;
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000486 }
487};
Daniel Dunbara3af3702009-07-20 18:55:04 +0000488
Chris Lattner37dfdec2009-07-29 06:33:53 +0000489} // end anonymous namespace.
Daniel Dunbara2edbab2009-07-28 20:47:52 +0000490
Devang Pateldd929fc2012-01-12 18:03:40 +0000491bool X86AsmParser::isSrcOp(X86Operand &Op) {
Evan Cheng59ee62d2011-07-11 03:57:24 +0000492 unsigned basereg = is64BitMode() ? X86::RSI : X86::ESI;
Joerg Sonnenberger96622aa2011-03-18 11:59:40 +0000493
494 return (Op.isMem() &&
495 (Op.Mem.SegReg == 0 || Op.Mem.SegReg == X86::DS) &&
496 isa<MCConstantExpr>(Op.Mem.Disp) &&
497 cast<MCConstantExpr>(Op.Mem.Disp)->getValue() == 0 &&
498 Op.Mem.BaseReg == basereg && Op.Mem.IndexReg == 0);
499}
500
Devang Pateldd929fc2012-01-12 18:03:40 +0000501bool X86AsmParser::isDstOp(X86Operand &Op) {
Evan Cheng59ee62d2011-07-11 03:57:24 +0000502 unsigned basereg = is64BitMode() ? X86::RDI : X86::EDI;
Joerg Sonnenberger96622aa2011-03-18 11:59:40 +0000503
Chad Rosier36b8fed2012-06-27 22:34:28 +0000504 return Op.isMem() &&
Kevin Enderby0f5ab7c2012-03-13 19:47:55 +0000505 (Op.Mem.SegReg == 0 || Op.Mem.SegReg == X86::ES) &&
Joerg Sonnenberger96622aa2011-03-18 11:59:40 +0000506 isa<MCConstantExpr>(Op.Mem.Disp) &&
507 cast<MCConstantExpr>(Op.Mem.Disp)->getValue() == 0 &&
508 Op.Mem.BaseReg == basereg && Op.Mem.IndexReg == 0;
509}
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000510
Devang Pateldd929fc2012-01-12 18:03:40 +0000511bool X86AsmParser::ParseRegister(unsigned &RegNo,
512 SMLoc &StartLoc, SMLoc &EndLoc) {
Chris Lattner23075742010-01-15 18:27:19 +0000513 RegNo = 0;
Devang Patelbe3e3102012-01-30 20:02:42 +0000514 if (!isParsingIntelSyntax()) {
Devang Patel1aea4302012-01-20 22:32:05 +0000515 const AsmToken &TokPercent = Parser.getTok();
Devang Pateld37ad242012-01-17 18:00:18 +0000516 assert(TokPercent.is(AsmToken::Percent) && "Invalid token kind!");
517 StartLoc = TokPercent.getLoc();
518 Parser.Lex(); // Eat percent token.
519 }
Kevin Enderby7b4608d2009-09-03 17:15:07 +0000520
Sean Callanan18b83232010-01-19 21:44:56 +0000521 const AsmToken &Tok = Parser.getTok();
Devang Patel1aea4302012-01-20 22:32:05 +0000522 if (Tok.isNot(AsmToken::Identifier)) {
Devang Patelbe3e3102012-01-30 20:02:42 +0000523 if (isParsingIntelSyntax()) return true;
Benjamin Kramer5efabcf2011-10-16 12:10:27 +0000524 return Error(StartLoc, "invalid register name",
525 SMRange(StartLoc, Tok.getEndLoc()));
Devang Patel1aea4302012-01-20 22:32:05 +0000526 }
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000527
Kevin Enderby7b4608d2009-09-03 17:15:07 +0000528 RegNo = MatchRegisterName(Tok.getString());
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000529
Chris Lattner33d60d52010-09-22 04:11:10 +0000530 // If the match failed, try the register name as lowercase.
531 if (RegNo == 0)
Benjamin Kramer59085362011-11-06 20:37:06 +0000532 RegNo = MatchRegisterName(Tok.getString().lower());
Michael J. Spencerc0c8df32010-10-09 11:00:50 +0000533
Evan Cheng5de728c2011-07-27 23:22:03 +0000534 if (!is64BitMode()) {
535 // FIXME: This should be done using Requires<In32BitMode> and
536 // Requires<In64BitMode> so "eiz" usage in 64-bit instructions can be also
537 // checked.
538 // FIXME: Check AH, CH, DH, BH cannot be used in an instruction requiring a
539 // REX prefix.
540 if (RegNo == X86::RIZ ||
541 X86MCRegisterClasses[X86::GR64RegClassID].contains(RegNo) ||
542 X86II::isX86_64NonExtLowByteReg(RegNo) ||
543 X86II::isX86_64ExtendedReg(RegNo))
Benjamin Kramer5efabcf2011-10-16 12:10:27 +0000544 return Error(StartLoc, "register %"
545 + Tok.getString() + " is only available in 64-bit mode",
546 SMRange(StartLoc, Tok.getEndLoc()));
Evan Cheng5de728c2011-07-27 23:22:03 +0000547 }
Bruno Cardoso Lopes3c8e1be2010-07-24 00:06:39 +0000548
Chris Lattner33d60d52010-09-22 04:11:10 +0000549 // Parse "%st" as "%st(0)" and "%st(1)", which is multiple tokens.
550 if (RegNo == 0 && (Tok.getString() == "st" || Tok.getString() == "ST")) {
Chris Lattnere16b0fc2010-02-09 00:49:22 +0000551 RegNo = X86::ST0;
552 EndLoc = Tok.getLoc();
553 Parser.Lex(); // Eat 'st'
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000554
Chris Lattnere16b0fc2010-02-09 00:49:22 +0000555 // Check to see if we have '(4)' after %st.
556 if (getLexer().isNot(AsmToken::LParen))
557 return false;
558 // Lex the paren.
559 getParser().Lex();
560
561 const AsmToken &IntTok = Parser.getTok();
562 if (IntTok.isNot(AsmToken::Integer))
563 return Error(IntTok.getLoc(), "expected stack index");
564 switch (IntTok.getIntVal()) {
565 case 0: RegNo = X86::ST0; break;
566 case 1: RegNo = X86::ST1; break;
567 case 2: RegNo = X86::ST2; break;
568 case 3: RegNo = X86::ST3; break;
569 case 4: RegNo = X86::ST4; break;
570 case 5: RegNo = X86::ST5; break;
571 case 6: RegNo = X86::ST6; break;
572 case 7: RegNo = X86::ST7; break;
573 default: return Error(IntTok.getLoc(), "invalid stack index");
574 }
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000575
Chris Lattnere16b0fc2010-02-09 00:49:22 +0000576 if (getParser().Lex().isNot(AsmToken::RParen))
577 return Error(Parser.getTok().getLoc(), "expected ')'");
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000578
Chris Lattnere16b0fc2010-02-09 00:49:22 +0000579 EndLoc = Tok.getLoc();
580 Parser.Lex(); // Eat ')'
581 return false;
582 }
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000583
Chris Lattner645b2092010-06-24 07:29:18 +0000584 // If this is "db[0-7]", match it as an alias
585 // for dr[0-7].
586 if (RegNo == 0 && Tok.getString().size() == 3 &&
587 Tok.getString().startswith("db")) {
588 switch (Tok.getString()[2]) {
589 case '0': RegNo = X86::DR0; break;
590 case '1': RegNo = X86::DR1; break;
591 case '2': RegNo = X86::DR2; break;
592 case '3': RegNo = X86::DR3; break;
593 case '4': RegNo = X86::DR4; break;
594 case '5': RegNo = X86::DR5; break;
595 case '6': RegNo = X86::DR6; break;
596 case '7': RegNo = X86::DR7; break;
597 }
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000598
Chris Lattner645b2092010-06-24 07:29:18 +0000599 if (RegNo != 0) {
600 EndLoc = Tok.getLoc();
601 Parser.Lex(); // Eat it.
602 return false;
603 }
604 }
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000605
Devang Patel1aea4302012-01-20 22:32:05 +0000606 if (RegNo == 0) {
Devang Patelbe3e3102012-01-30 20:02:42 +0000607 if (isParsingIntelSyntax()) return true;
Benjamin Kramer5efabcf2011-10-16 12:10:27 +0000608 return Error(StartLoc, "invalid register name",
609 SMRange(StartLoc, Tok.getEndLoc()));
Devang Patel1aea4302012-01-20 22:32:05 +0000610 }
Daniel Dunbar0e2771f2009-07-29 00:02:19 +0000611
Benjamin Kramer5efabcf2011-10-16 12:10:27 +0000612 EndLoc = Tok.getEndLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +0000613 Parser.Lex(); // Eat identifier token.
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000614 return false;
Daniel Dunbar092a9dd2009-07-17 20:42:00 +0000615}
616
Devang Pateldd929fc2012-01-12 18:03:40 +0000617X86Operand *X86AsmParser::ParseOperand() {
Devang Patelbe3e3102012-01-30 20:02:42 +0000618 if (isParsingIntelSyntax())
Devang Patel0a338862012-01-12 01:36:43 +0000619 return ParseIntelOperand();
620 return ParseATTOperand();
621}
622
Devang Pateld37ad242012-01-17 18:00:18 +0000623/// getIntelMemOperandSize - Return intel memory operand size.
624static unsigned getIntelMemOperandSize(StringRef OpStr) {
625 unsigned Size = 0;
Devang Patel0a338862012-01-12 01:36:43 +0000626 if (OpStr == "BYTE") Size = 8;
627 if (OpStr == "WORD") Size = 16;
628 if (OpStr == "DWORD") Size = 32;
629 if (OpStr == "QWORD") Size = 64;
630 if (OpStr == "XWORD") Size = 80;
631 if (OpStr == "XMMWORD") Size = 128;
632 if (OpStr == "YMMWORD") Size = 256;
Devang Pateld37ad242012-01-17 18:00:18 +0000633 return Size;
Devang Patel0a338862012-01-12 01:36:43 +0000634}
635
Devang Patel7c64fe62012-01-23 18:31:58 +0000636X86Operand *X86AsmParser::ParseIntelBracExpression(unsigned SegReg,
637 unsigned Size) {
638 unsigned BaseReg = 0, IndexReg = 0, Scale = 1;
Devang Patel0a338862012-01-12 01:36:43 +0000639 SMLoc Start = Parser.getTok().getLoc(), End;
640
Devang Pateld37ad242012-01-17 18:00:18 +0000641 const MCExpr *Disp = MCConstantExpr::Create(0, getParser().getContext());
642 // Parse [ BaseReg + Scale*IndexReg + Disp ] or [ symbol ]
643
644 // Eat '['
645 if (getLexer().isNot(AsmToken::LBrac))
646 return ErrorOperand(Start, "Expected '[' token!");
647 Parser.Lex();
Chad Rosier36b8fed2012-06-27 22:34:28 +0000648
Devang Pateld37ad242012-01-17 18:00:18 +0000649 if (getLexer().is(AsmToken::Identifier)) {
650 // Parse BaseReg
Devang Patel1aea4302012-01-20 22:32:05 +0000651 if (ParseRegister(BaseReg, Start, End)) {
Devang Pateld37ad242012-01-17 18:00:18 +0000652 // Handle '[' 'symbol' ']'
Devang Pateld37ad242012-01-17 18:00:18 +0000653 if (getParser().ParseExpression(Disp, End)) return 0;
654 if (getLexer().isNot(AsmToken::RBrac))
Devang Patelbc51e502012-01-17 19:09:22 +0000655 return ErrorOperand(Start, "Expected ']' token!");
Devang Pateld37ad242012-01-17 18:00:18 +0000656 Parser.Lex();
657 return X86Operand::CreateMem(Disp, Start, End, Size);
658 }
659 } else if (getLexer().is(AsmToken::Integer)) {
Devang Patel3e081312012-01-23 20:20:06 +0000660 int64_t Val = Parser.getTok().getIntVal();
Devang Pateld37ad242012-01-17 18:00:18 +0000661 Parser.Lex();
Devang Patel3e081312012-01-23 20:20:06 +0000662 SMLoc Loc = Parser.getTok().getLoc();
663 if (getLexer().is(AsmToken::RBrac)) {
664 // Handle '[' number ']'
665 Parser.Lex();
Devang Patela28101e2012-01-27 19:48:28 +0000666 const MCExpr *Disp = MCConstantExpr::Create(Val, getContext());
667 if (SegReg)
668 return X86Operand::CreateMem(SegReg, Disp, 0, 0, Scale,
669 Start, End, Size);
670 return X86Operand::CreateMem(Disp, Start, End, Size);
Devang Patel3e081312012-01-23 20:20:06 +0000671 } else if (getLexer().is(AsmToken::Star)) {
672 // Handle '[' Scale*IndexReg ']'
673 Parser.Lex();
674 SMLoc IdxRegLoc = Parser.getTok().getLoc();
Craig Topper833d7f82012-07-18 04:36:35 +0000675 if (ParseRegister(IndexReg, IdxRegLoc, End))
676 return ErrorOperand(IdxRegLoc, "Expected register");
Devang Patel3e081312012-01-23 20:20:06 +0000677 Scale = Val;
678 } else
Craig Topper833d7f82012-07-18 04:36:35 +0000679 return ErrorOperand(Loc, "Unexpected token");
Devang Pateld37ad242012-01-17 18:00:18 +0000680 }
681
682 if (getLexer().is(AsmToken::Plus) || getLexer().is(AsmToken::Minus)) {
683 bool isPlus = getLexer().is(AsmToken::Plus);
684 Parser.Lex();
685 SMLoc PlusLoc = Parser.getTok().getLoc();
686 if (getLexer().is(AsmToken::Integer)) {
687 int64_t Val = Parser.getTok().getIntVal();
688 Parser.Lex();
689 if (getLexer().is(AsmToken::Star)) {
Devang Patelbc51e502012-01-17 19:09:22 +0000690 Parser.Lex();
691 SMLoc IdxRegLoc = Parser.getTok().getLoc();
Craig Topper833d7f82012-07-18 04:36:35 +0000692 if (ParseRegister(IndexReg, IdxRegLoc, End))
693 return ErrorOperand(IdxRegLoc, "Expected register");
Devang Patelbc51e502012-01-17 19:09:22 +0000694 Scale = Val;
Devang Pateld37ad242012-01-17 18:00:18 +0000695 } else if (getLexer().is(AsmToken::RBrac)) {
Devang Patelbc51e502012-01-17 19:09:22 +0000696 const MCExpr *ValExpr = MCConstantExpr::Create(Val, getContext());
Devang Patele60540f2012-01-19 18:15:51 +0000697 Disp = isPlus ? ValExpr : MCConstantExpr::Create(0-Val, getContext());
Devang Pateld37ad242012-01-17 18:00:18 +0000698 } else
Devang Patelbc51e502012-01-17 19:09:22 +0000699 return ErrorOperand(PlusLoc, "unexpected token after +");
Devang Patelf2d21372012-01-23 22:35:25 +0000700 } else if (getLexer().is(AsmToken::Identifier)) {
Devang Patel392ad6d2012-01-23 23:56:33 +0000701 // This could be an index register or a displacement expression.
Devang Patelf2d21372012-01-23 22:35:25 +0000702 End = Parser.getTok().getLoc();
703 if (!IndexReg)
704 ParseRegister(IndexReg, Start, End);
Chad Rosier36b8fed2012-06-27 22:34:28 +0000705 else if (getParser().ParseExpression(Disp, End)) return 0;
Devang Patelf2d21372012-01-23 22:35:25 +0000706 }
Devang Pateld37ad242012-01-17 18:00:18 +0000707 }
708
709 if (getLexer().isNot(AsmToken::RBrac))
710 if (getParser().ParseExpression(Disp, End)) return 0;
711
712 End = Parser.getTok().getLoc();
713 if (getLexer().isNot(AsmToken::RBrac))
714 return ErrorOperand(End, "expected ']' token!");
715 Parser.Lex();
716 End = Parser.getTok().getLoc();
Devang Patelfdd3b302012-01-20 21:21:01 +0000717
718 // handle [-42]
719 if (!BaseReg && !IndexReg)
720 return X86Operand::CreateMem(Disp, Start, End, Size);
721
Devang Pateld37ad242012-01-17 18:00:18 +0000722 return X86Operand::CreateMem(SegReg, Disp, BaseReg, IndexReg, Scale,
Devang Patelbc51e502012-01-17 19:09:22 +0000723 Start, End, Size);
Devang Pateld37ad242012-01-17 18:00:18 +0000724}
725
726/// ParseIntelMemOperand - Parse intel style memory operand.
727X86Operand *X86AsmParser::ParseIntelMemOperand() {
728 const AsmToken &Tok = Parser.getTok();
729 SMLoc Start = Parser.getTok().getLoc(), End;
Devang Patel7c64fe62012-01-23 18:31:58 +0000730 unsigned SegReg = 0;
Devang Pateld37ad242012-01-17 18:00:18 +0000731
732 unsigned Size = getIntelMemOperandSize(Tok.getString());
733 if (Size) {
734 Parser.Lex();
735 assert (Tok.getString() == "PTR" && "Unexpected token!");
736 Parser.Lex();
737 }
738
739 if (getLexer().is(AsmToken::LBrac))
Devang Patel7c64fe62012-01-23 18:31:58 +0000740 return ParseIntelBracExpression(SegReg, Size);
741
742 if (!ParseRegister(SegReg, Start, End)) {
743 // Handel SegReg : [ ... ]
744 if (getLexer().isNot(AsmToken::Colon))
745 return ErrorOperand(Start, "Expected ':' token!");
746 Parser.Lex(); // Eat :
747 if (getLexer().isNot(AsmToken::LBrac))
748 return ErrorOperand(Start, "Expected '[' token!");
749 return ParseIntelBracExpression(SegReg, Size);
750 }
Devang Pateld37ad242012-01-17 18:00:18 +0000751
752 const MCExpr *Disp = MCConstantExpr::Create(0, getParser().getContext());
753 if (getParser().ParseExpression(Disp, End)) return 0;
754 return X86Operand::CreateMem(Disp, Start, End, Size);
755}
756
757X86Operand *X86AsmParser::ParseIntelOperand() {
Devang Pateld37ad242012-01-17 18:00:18 +0000758 SMLoc Start = Parser.getTok().getLoc(), End;
759
760 // immediate.
761 if (getLexer().is(AsmToken::Integer) || getLexer().is(AsmToken::Real) ||
762 getLexer().is(AsmToken::Minus)) {
763 const MCExpr *Val;
764 if (!getParser().ParseExpression(Val, End)) {
765 End = Parser.getTok().getLoc();
766 return X86Operand::CreateImm(Val, Start, End);
767 }
768 }
769
Devang Patel0a338862012-01-12 01:36:43 +0000770 // register
Devang Patel1aea4302012-01-20 22:32:05 +0000771 unsigned RegNo = 0;
772 if (!ParseRegister(RegNo, Start, End)) {
Devang Patel0a338862012-01-12 01:36:43 +0000773 End = Parser.getTok().getLoc();
774 return X86Operand::CreateReg(RegNo, Start, End);
775 }
776
777 // mem operand
Devang Pateld37ad242012-01-17 18:00:18 +0000778 return ParseIntelMemOperand();
Devang Patel0a338862012-01-12 01:36:43 +0000779}
780
Devang Pateldd929fc2012-01-12 18:03:40 +0000781X86Operand *X86AsmParser::ParseATTOperand() {
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000782 switch (getLexer().getKind()) {
783 default:
Chris Lattnereef6d782010-04-17 18:56:34 +0000784 // Parse a memory operand with no segment register.
785 return ParseMemOperand(0, Parser.getTok().getLoc());
Chris Lattner23075742010-01-15 18:27:19 +0000786 case AsmToken::Percent: {
Chris Lattnereef6d782010-04-17 18:56:34 +0000787 // Read the register.
Chris Lattner23075742010-01-15 18:27:19 +0000788 unsigned RegNo;
Chris Lattner29ef9a22010-01-15 18:51:29 +0000789 SMLoc Start, End;
790 if (ParseRegister(RegNo, Start, End)) return 0;
Bruno Cardoso Lopes3c8e1be2010-07-24 00:06:39 +0000791 if (RegNo == X86::EIZ || RegNo == X86::RIZ) {
Benjamin Kramer5efabcf2011-10-16 12:10:27 +0000792 Error(Start, "%eiz and %riz can only be used as index registers",
793 SMRange(Start, End));
Bruno Cardoso Lopes3c8e1be2010-07-24 00:06:39 +0000794 return 0;
795 }
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000796
Chris Lattnereef6d782010-04-17 18:56:34 +0000797 // If this is a segment register followed by a ':', then this is the start
798 // of a memory reference, otherwise this is a normal register reference.
799 if (getLexer().isNot(AsmToken::Colon))
800 return X86Operand::CreateReg(RegNo, Start, End);
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000801
802
Chris Lattnereef6d782010-04-17 18:56:34 +0000803 getParser().Lex(); // Eat the colon.
804 return ParseMemOperand(RegNo, Start);
Chris Lattner23075742010-01-15 18:27:19 +0000805 }
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000806 case AsmToken::Dollar: {
807 // $42 -> immediate.
Sean Callanan18b83232010-01-19 21:44:56 +0000808 SMLoc Start = Parser.getTok().getLoc(), End;
Sean Callananb9a25b72010-01-19 20:27:46 +0000809 Parser.Lex();
Daniel Dunbar8c2eebe2009-08-31 08:08:38 +0000810 const MCExpr *Val;
Chris Lattner54482b42010-01-15 19:39:23 +0000811 if (getParser().ParseExpression(Val, End))
Chris Lattner309264d2010-01-15 18:44:13 +0000812 return 0;
Chris Lattnerb4307b32010-01-15 19:28:38 +0000813 return X86Operand::CreateImm(Val, Start, End);
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000814 }
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000815 }
Daniel Dunbardbd692a2009-07-20 20:01:54 +0000816}
817
Chris Lattnereef6d782010-04-17 18:56:34 +0000818/// ParseMemOperand: segment: disp(basereg, indexreg, scale). The '%ds:' prefix
819/// has already been parsed if present.
Devang Pateldd929fc2012-01-12 18:03:40 +0000820X86Operand *X86AsmParser::ParseMemOperand(unsigned SegReg, SMLoc MemStart) {
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000821
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000822 // We have to disambiguate a parenthesized expression "(4+5)" from the start
823 // of a memory operand with a missing displacement "(%ebx)" or "(,%eax)". The
Chris Lattner75f265f2010-01-24 01:07:33 +0000824 // only way to do this without lookahead is to eat the '(' and see what is
825 // after it.
Daniel Dunbar8c2eebe2009-08-31 08:08:38 +0000826 const MCExpr *Disp = MCConstantExpr::Create(0, getParser().getContext());
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000827 if (getLexer().isNot(AsmToken::LParen)) {
Chris Lattner54482b42010-01-15 19:39:23 +0000828 SMLoc ExprEnd;
829 if (getParser().ParseExpression(Disp, ExprEnd)) return 0;
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000830
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000831 // After parsing the base expression we could either have a parenthesized
832 // memory address or not. If not, return now. If so, eat the (.
833 if (getLexer().isNot(AsmToken::LParen)) {
Daniel Dunbarc09e4112009-07-31 22:22:54 +0000834 // Unless we have a segment register, treat this as an immediate.
Chris Lattner309264d2010-01-15 18:44:13 +0000835 if (SegReg == 0)
Daniel Dunbarb834f5d2010-01-30 01:02:48 +0000836 return X86Operand::CreateMem(Disp, MemStart, ExprEnd);
Chris Lattner0a3c5a52010-01-15 19:33:43 +0000837 return X86Operand::CreateMem(SegReg, Disp, 0, 0, 1, MemStart, ExprEnd);
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000838 }
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000839
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000840 // Eat the '('.
Sean Callananb9a25b72010-01-19 20:27:46 +0000841 Parser.Lex();
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000842 } else {
843 // Okay, we have a '('. We don't know if this is an expression or not, but
844 // so we have to eat the ( to see beyond it.
Sean Callanan18b83232010-01-19 21:44:56 +0000845 SMLoc LParenLoc = Parser.getTok().getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +0000846 Parser.Lex(); // Eat the '('.
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000847
Kevin Enderby7b4608d2009-09-03 17:15:07 +0000848 if (getLexer().is(AsmToken::Percent) || getLexer().is(AsmToken::Comma)) {
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000849 // Nothing to do here, fall into the code below with the '(' part of the
850 // memory operand consumed.
851 } else {
Chris Lattnerb4307b32010-01-15 19:28:38 +0000852 SMLoc ExprEnd;
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000853
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000854 // It must be an parenthesized expression, parse it now.
Chris Lattnerb4307b32010-01-15 19:28:38 +0000855 if (getParser().ParseParenExpression(Disp, ExprEnd))
Chris Lattner309264d2010-01-15 18:44:13 +0000856 return 0;
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000857
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000858 // After parsing the base expression we could either have a parenthesized
859 // memory address or not. If not, return now. If so, eat the (.
860 if (getLexer().isNot(AsmToken::LParen)) {
Daniel Dunbarc09e4112009-07-31 22:22:54 +0000861 // Unless we have a segment register, treat this as an immediate.
Chris Lattner309264d2010-01-15 18:44:13 +0000862 if (SegReg == 0)
Daniel Dunbarb834f5d2010-01-30 01:02:48 +0000863 return X86Operand::CreateMem(Disp, LParenLoc, ExprEnd);
Chris Lattner0a3c5a52010-01-15 19:33:43 +0000864 return X86Operand::CreateMem(SegReg, Disp, 0, 0, 1, MemStart, ExprEnd);
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000865 }
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000866
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000867 // Eat the '('.
Sean Callananb9a25b72010-01-19 20:27:46 +0000868 Parser.Lex();
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000869 }
870 }
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000871
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000872 // If we reached here, then we just ate the ( of the memory operand. Process
873 // the rest of the memory operand.
Daniel Dunbar022e2a82009-07-31 20:53:16 +0000874 unsigned BaseReg = 0, IndexReg = 0, Scale = 1;
Kevin Enderby84faf652012-03-12 21:32:09 +0000875 SMLoc IndexLoc;
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000876
Chris Lattner29ef9a22010-01-15 18:51:29 +0000877 if (getLexer().is(AsmToken::Percent)) {
Benjamin Kramer5efabcf2011-10-16 12:10:27 +0000878 SMLoc StartLoc, EndLoc;
879 if (ParseRegister(BaseReg, StartLoc, EndLoc)) return 0;
Bruno Cardoso Lopes3c8e1be2010-07-24 00:06:39 +0000880 if (BaseReg == X86::EIZ || BaseReg == X86::RIZ) {
Benjamin Kramer5efabcf2011-10-16 12:10:27 +0000881 Error(StartLoc, "eiz and riz can only be used as index registers",
882 SMRange(StartLoc, EndLoc));
Bruno Cardoso Lopes3c8e1be2010-07-24 00:06:39 +0000883 return 0;
884 }
Chris Lattner29ef9a22010-01-15 18:51:29 +0000885 }
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000886
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000887 if (getLexer().is(AsmToken::Comma)) {
Sean Callananb9a25b72010-01-19 20:27:46 +0000888 Parser.Lex(); // Eat the comma.
Kevin Enderby84faf652012-03-12 21:32:09 +0000889 IndexLoc = Parser.getTok().getLoc();
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000890
891 // Following the comma we should have either an index register, or a scale
892 // value. We don't support the later form, but we want to parse it
893 // correctly.
894 //
895 // Not that even though it would be completely consistent to support syntax
Bruno Cardoso Lopes3c8e1be2010-07-24 00:06:39 +0000896 // like "1(%eax,,1)", the assembler doesn't. Use "eiz" or "riz" for this.
Kevin Enderby7b4608d2009-09-03 17:15:07 +0000897 if (getLexer().is(AsmToken::Percent)) {
Chris Lattner29ef9a22010-01-15 18:51:29 +0000898 SMLoc L;
899 if (ParseRegister(IndexReg, L, L)) return 0;
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000900
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000901 if (getLexer().isNot(AsmToken::RParen)) {
902 // Parse the scale amount:
903 // ::= ',' [scale-expression]
Chris Lattner309264d2010-01-15 18:44:13 +0000904 if (getLexer().isNot(AsmToken::Comma)) {
Sean Callanan18b83232010-01-19 21:44:56 +0000905 Error(Parser.getTok().getLoc(),
Chris Lattner309264d2010-01-15 18:44:13 +0000906 "expected comma in scale expression");
907 return 0;
908 }
Sean Callananb9a25b72010-01-19 20:27:46 +0000909 Parser.Lex(); // Eat the comma.
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000910
911 if (getLexer().isNot(AsmToken::RParen)) {
Sean Callanan18b83232010-01-19 21:44:56 +0000912 SMLoc Loc = Parser.getTok().getLoc();
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000913
914 int64_t ScaleVal;
Kevin Enderby58dfaa12012-03-09 22:24:10 +0000915 if (getParser().ParseAbsoluteExpression(ScaleVal)){
916 Error(Loc, "expected scale expression");
Chris Lattner309264d2010-01-15 18:44:13 +0000917 return 0;
Craig Topper76bd9382012-07-18 04:59:16 +0000918 }
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000919
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000920 // Validate the scale amount.
Chris Lattner309264d2010-01-15 18:44:13 +0000921 if (ScaleVal != 1 && ScaleVal != 2 && ScaleVal != 4 && ScaleVal != 8){
922 Error(Loc, "scale factor in address must be 1, 2, 4 or 8");
923 return 0;
924 }
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000925 Scale = (unsigned)ScaleVal;
926 }
927 }
928 } else if (getLexer().isNot(AsmToken::RParen)) {
Daniel Dunbaree910252010-08-24 19:13:38 +0000929 // A scale amount without an index is ignored.
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000930 // index.
Sean Callanan18b83232010-01-19 21:44:56 +0000931 SMLoc Loc = Parser.getTok().getLoc();
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000932
933 int64_t Value;
934 if (getParser().ParseAbsoluteExpression(Value))
Chris Lattner309264d2010-01-15 18:44:13 +0000935 return 0;
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000936
Daniel Dunbaree910252010-08-24 19:13:38 +0000937 if (Value != 1)
938 Warning(Loc, "scale factor without index register is ignored");
939 Scale = 1;
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000940 }
941 }
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000942
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000943 // Ok, we've eaten the memory operand, verify we have a ')' and eat it too.
Chris Lattner309264d2010-01-15 18:44:13 +0000944 if (getLexer().isNot(AsmToken::RParen)) {
Sean Callanan18b83232010-01-19 21:44:56 +0000945 Error(Parser.getTok().getLoc(), "unexpected token in memory operand");
Chris Lattner309264d2010-01-15 18:44:13 +0000946 return 0;
947 }
Sean Callanan18b83232010-01-19 21:44:56 +0000948 SMLoc MemEnd = Parser.getTok().getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +0000949 Parser.Lex(); // Eat the ')'.
Bruno Cardoso Lopesf64a7d42010-07-23 22:15:26 +0000950
Kevin Enderby84faf652012-03-12 21:32:09 +0000951 // If we have both a base register and an index register make sure they are
952 // both 64-bit or 32-bit registers.
Manman Ren1f7a1b62012-06-26 19:47:59 +0000953 // To support VSIB, IndexReg can be 128-bit or 256-bit registers.
Kevin Enderby84faf652012-03-12 21:32:09 +0000954 if (BaseReg != 0 && IndexReg != 0) {
955 if (X86MCRegisterClasses[X86::GR64RegClassID].contains(BaseReg) &&
Manman Ren1f7a1b62012-06-26 19:47:59 +0000956 (X86MCRegisterClasses[X86::GR16RegClassID].contains(IndexReg) ||
957 X86MCRegisterClasses[X86::GR32RegClassID].contains(IndexReg)) &&
Kevin Enderby84faf652012-03-12 21:32:09 +0000958 IndexReg != X86::RIZ) {
959 Error(IndexLoc, "index register is 32-bit, but base register is 64-bit");
960 return 0;
961 }
962 if (X86MCRegisterClasses[X86::GR32RegClassID].contains(BaseReg) &&
Manman Ren1f7a1b62012-06-26 19:47:59 +0000963 (X86MCRegisterClasses[X86::GR16RegClassID].contains(IndexReg) ||
964 X86MCRegisterClasses[X86::GR64RegClassID].contains(IndexReg)) &&
Kevin Enderby84faf652012-03-12 21:32:09 +0000965 IndexReg != X86::EIZ){
966 Error(IndexLoc, "index register is 64-bit, but base register is 32-bit");
967 return 0;
968 }
969 }
970
Chris Lattner0a3c5a52010-01-15 19:33:43 +0000971 return X86Operand::CreateMem(SegReg, Disp, BaseReg, IndexReg, Scale,
972 MemStart, MemEnd);
Daniel Dunbar16cdcb32009-07-28 22:40:46 +0000973}
974
Devang Pateldd929fc2012-01-12 18:03:40 +0000975bool X86AsmParser::
Benjamin Kramer38e59892010-07-14 22:38:02 +0000976ParseInstruction(StringRef Name, SMLoc NameLoc,
Chris Lattner98986712010-01-14 22:21:20 +0000977 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Chris Lattner693173f2010-10-30 19:23:13 +0000978 StringRef PatchedName = Name;
Daniel Dunbar39e2dd72010-05-25 19:49:32 +0000979
Chris Lattnerd8f71792010-11-28 20:23:50 +0000980 // FIXME: Hack to recognize setneb as setne.
981 if (PatchedName.startswith("set") && PatchedName.endswith("b") &&
982 PatchedName != "setb" && PatchedName != "setnb")
983 PatchedName = PatchedName.substr(0, Name.size()-1);
Chad Rosier36b8fed2012-06-27 22:34:28 +0000984
Daniel Dunbar39e2dd72010-05-25 19:49:32 +0000985 // FIXME: Hack to recognize cmp<comparison code>{ss,sd,ps,pd}.
986 const MCExpr *ExtraImmOp = 0;
Bruno Cardoso Lopes428256b2010-06-23 21:10:57 +0000987 if ((PatchedName.startswith("cmp") || PatchedName.startswith("vcmp")) &&
Daniel Dunbar39e2dd72010-05-25 19:49:32 +0000988 (PatchedName.endswith("ss") || PatchedName.endswith("sd") ||
989 PatchedName.endswith("ps") || PatchedName.endswith("pd"))) {
Craig Topper9e6ddcb2012-03-29 07:11:23 +0000990 bool IsVCMP = PatchedName[0] == 'v';
Bruno Cardoso Lopes428256b2010-06-23 21:10:57 +0000991 unsigned SSECCIdx = IsVCMP ? 4 : 3;
Daniel Dunbar39e2dd72010-05-25 19:49:32 +0000992 unsigned SSEComparisonCode = StringSwitch<unsigned>(
Bruno Cardoso Lopes428256b2010-06-23 21:10:57 +0000993 PatchedName.slice(SSECCIdx, PatchedName.size() - 2))
Craig Topper9e6ddcb2012-03-29 07:11:23 +0000994 .Case("eq", 0x00)
995 .Case("lt", 0x01)
996 .Case("le", 0x02)
997 .Case("unord", 0x03)
998 .Case("neq", 0x04)
999 .Case("nlt", 0x05)
1000 .Case("nle", 0x06)
1001 .Case("ord", 0x07)
1002 /* AVX only from here */
1003 .Case("eq_uq", 0x08)
1004 .Case("nge", 0x09)
Bruno Cardoso Lopescc69e132010-07-07 22:24:03 +00001005 .Case("ngt", 0x0A)
1006 .Case("false", 0x0B)
1007 .Case("neq_oq", 0x0C)
1008 .Case("ge", 0x0D)
1009 .Case("gt", 0x0E)
1010 .Case("true", 0x0F)
1011 .Case("eq_os", 0x10)
1012 .Case("lt_oq", 0x11)
1013 .Case("le_oq", 0x12)
1014 .Case("unord_s", 0x13)
1015 .Case("neq_us", 0x14)
1016 .Case("nlt_uq", 0x15)
1017 .Case("nle_uq", 0x16)
1018 .Case("ord_s", 0x17)
1019 .Case("eq_us", 0x18)
1020 .Case("nge_uq", 0x19)
1021 .Case("ngt_uq", 0x1A)
1022 .Case("false_os", 0x1B)
1023 .Case("neq_os", 0x1C)
1024 .Case("ge_oq", 0x1D)
1025 .Case("gt_oq", 0x1E)
1026 .Case("true_us", 0x1F)
Daniel Dunbar39e2dd72010-05-25 19:49:32 +00001027 .Default(~0U);
Craig Topper9e6ddcb2012-03-29 07:11:23 +00001028 if (SSEComparisonCode != ~0U && (IsVCMP || SSEComparisonCode < 8)) {
Daniel Dunbar39e2dd72010-05-25 19:49:32 +00001029 ExtraImmOp = MCConstantExpr::Create(SSEComparisonCode,
1030 getParser().getContext());
1031 if (PatchedName.endswith("ss")) {
Bruno Cardoso Lopes428256b2010-06-23 21:10:57 +00001032 PatchedName = IsVCMP ? "vcmpss" : "cmpss";
Daniel Dunbar39e2dd72010-05-25 19:49:32 +00001033 } else if (PatchedName.endswith("sd")) {
Bruno Cardoso Lopes428256b2010-06-23 21:10:57 +00001034 PatchedName = IsVCMP ? "vcmpsd" : "cmpsd";
Daniel Dunbar39e2dd72010-05-25 19:49:32 +00001035 } else if (PatchedName.endswith("ps")) {
Bruno Cardoso Lopes428256b2010-06-23 21:10:57 +00001036 PatchedName = IsVCMP ? "vcmpps" : "cmpps";
Daniel Dunbar39e2dd72010-05-25 19:49:32 +00001037 } else {
1038 assert(PatchedName.endswith("pd") && "Unexpected mnemonic!");
Bruno Cardoso Lopes428256b2010-06-23 21:10:57 +00001039 PatchedName = IsVCMP ? "vcmppd" : "cmppd";
Daniel Dunbar39e2dd72010-05-25 19:49:32 +00001040 }
1041 }
1042 }
Bruno Cardoso Lopesf528d2b2010-07-23 18:41:12 +00001043
Daniel Dunbar1b6c0602010-02-10 21:19:28 +00001044 Operands.push_back(X86Operand::CreateToken(PatchedName, NameLoc));
Daniel Dunbar16cdcb32009-07-28 22:40:46 +00001045
Devang Patel885f65b2012-01-30 22:47:12 +00001046 if (ExtraImmOp && !isParsingIntelSyntax())
Daniel Dunbar39e2dd72010-05-25 19:49:32 +00001047 Operands.push_back(X86Operand::CreateImm(ExtraImmOp, NameLoc, NameLoc));
Michael J. Spencerc0c8df32010-10-09 11:00:50 +00001048
Chris Lattner2544f422010-09-08 05:17:37 +00001049 // Determine whether this is an instruction prefix.
1050 bool isPrefix =
Chris Lattner693173f2010-10-30 19:23:13 +00001051 Name == "lock" || Name == "rep" ||
1052 Name == "repe" || Name == "repz" ||
Rafael Espindolabeb68982010-11-23 11:23:24 +00001053 Name == "repne" || Name == "repnz" ||
Rafael Espindolabfd2d262010-11-27 20:29:45 +00001054 Name == "rex64" || Name == "data16";
Michael J. Spencerc0c8df32010-10-09 11:00:50 +00001055
1056
Chris Lattner2544f422010-09-08 05:17:37 +00001057 // This does the actual operand parsing. Don't parse any more if we have a
1058 // prefix juxtaposed with an operation like "lock incl 4(%rax)", because we
1059 // just want to parse the "lock" as the first instruction and the "incl" as
1060 // the next one.
1061 if (getLexer().isNot(AsmToken::EndOfStatement) && !isPrefix) {
Daniel Dunbar0db68f42009-08-11 05:00:25 +00001062
1063 // Parse '*' modifier.
1064 if (getLexer().is(AsmToken::Star)) {
Sean Callanan18b83232010-01-19 21:44:56 +00001065 SMLoc Loc = Parser.getTok().getLoc();
Chris Lattnerb4307b32010-01-15 19:28:38 +00001066 Operands.push_back(X86Operand::CreateToken("*", Loc));
Sean Callananb9a25b72010-01-19 20:27:46 +00001067 Parser.Lex(); // Eat the star.
Daniel Dunbar0db68f42009-08-11 05:00:25 +00001068 }
1069
Daniel Dunbar16cdcb32009-07-28 22:40:46 +00001070 // Read the first operand.
Chris Lattner309264d2010-01-15 18:44:13 +00001071 if (X86Operand *Op = ParseOperand())
1072 Operands.push_back(Op);
Chris Lattnercbf8a982010-09-11 16:18:25 +00001073 else {
1074 Parser.EatToEndOfStatement();
Daniel Dunbar16cdcb32009-07-28 22:40:46 +00001075 return true;
Chris Lattnercbf8a982010-09-11 16:18:25 +00001076 }
Daniel Dunbar39e2dd72010-05-25 19:49:32 +00001077
Daniel Dunbar16cdcb32009-07-28 22:40:46 +00001078 while (getLexer().is(AsmToken::Comma)) {
Sean Callananb9a25b72010-01-19 20:27:46 +00001079 Parser.Lex(); // Eat the comma.
Daniel Dunbar16cdcb32009-07-28 22:40:46 +00001080
1081 // Parse and remember the operand.
Chris Lattner309264d2010-01-15 18:44:13 +00001082 if (X86Operand *Op = ParseOperand())
1083 Operands.push_back(Op);
Chris Lattnercbf8a982010-09-11 16:18:25 +00001084 else {
1085 Parser.EatToEndOfStatement();
Daniel Dunbar16cdcb32009-07-28 22:40:46 +00001086 return true;
Chris Lattnercbf8a982010-09-11 16:18:25 +00001087 }
Daniel Dunbar16cdcb32009-07-28 22:40:46 +00001088 }
Michael J. Spencerc0c8df32010-10-09 11:00:50 +00001089
Chris Lattnercbf8a982010-09-11 16:18:25 +00001090 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Chris Lattnerc146c4d2010-11-18 02:53:02 +00001091 SMLoc Loc = getLexer().getLoc();
Chris Lattnercbf8a982010-09-11 16:18:25 +00001092 Parser.EatToEndOfStatement();
Chris Lattnerc146c4d2010-11-18 02:53:02 +00001093 return Error(Loc, "unexpected token in argument list");
Chris Lattnercbf8a982010-09-11 16:18:25 +00001094 }
Daniel Dunbar16cdcb32009-07-28 22:40:46 +00001095 }
Michael J. Spencerc0c8df32010-10-09 11:00:50 +00001096
Chris Lattner2544f422010-09-08 05:17:37 +00001097 if (getLexer().is(AsmToken::EndOfStatement))
1098 Parser.Lex(); // Consume the EndOfStatement
Kevin Enderby76331752010-12-08 23:57:59 +00001099 else if (isPrefix && getLexer().is(AsmToken::Slash))
1100 Parser.Lex(); // Consume the prefix separator Slash
Daniel Dunbar16cdcb32009-07-28 22:40:46 +00001101
Devang Patel885f65b2012-01-30 22:47:12 +00001102 if (ExtraImmOp && isParsingIntelSyntax())
1103 Operands.push_back(X86Operand::CreateImm(ExtraImmOp, NameLoc, NameLoc));
1104
Chris Lattner98c870f2010-11-06 19:25:43 +00001105 // This is a terrible hack to handle "out[bwl]? %al, (%dx)" ->
1106 // "outb %al, %dx". Out doesn't take a memory form, but this is a widely
1107 // documented form in various unofficial manuals, so a lot of code uses it.
1108 if ((Name == "outb" || Name == "outw" || Name == "outl" || Name == "out") &&
1109 Operands.size() == 3) {
1110 X86Operand &Op = *(X86Operand*)Operands.back();
1111 if (Op.isMem() && Op.Mem.SegReg == 0 &&
1112 isa<MCConstantExpr>(Op.Mem.Disp) &&
1113 cast<MCConstantExpr>(Op.Mem.Disp)->getValue() == 0 &&
1114 Op.Mem.BaseReg == MatchRegisterName("dx") && Op.Mem.IndexReg == 0) {
1115 SMLoc Loc = Op.getEndLoc();
1116 Operands.back() = X86Operand::CreateReg(Op.Mem.BaseReg, Loc, Loc);
1117 delete &Op;
1118 }
1119 }
Joerg Sonnenberger00743c22011-02-22 20:40:09 +00001120 // Same hack for "in[bwl]? (%dx), %al" -> "inb %dx, %al".
1121 if ((Name == "inb" || Name == "inw" || Name == "inl" || Name == "in") &&
1122 Operands.size() == 3) {
1123 X86Operand &Op = *(X86Operand*)Operands.begin()[1];
1124 if (Op.isMem() && Op.Mem.SegReg == 0 &&
1125 isa<MCConstantExpr>(Op.Mem.Disp) &&
1126 cast<MCConstantExpr>(Op.Mem.Disp)->getValue() == 0 &&
1127 Op.Mem.BaseReg == MatchRegisterName("dx") && Op.Mem.IndexReg == 0) {
1128 SMLoc Loc = Op.getEndLoc();
1129 Operands.begin()[1] = X86Operand::CreateReg(Op.Mem.BaseReg, Loc, Loc);
1130 delete &Op;
1131 }
1132 }
Joerg Sonnenberger96622aa2011-03-18 11:59:40 +00001133 // Transform "ins[bwl] %dx, %es:(%edi)" into "ins[bwl]"
1134 if (Name.startswith("ins") && Operands.size() == 3 &&
1135 (Name == "insb" || Name == "insw" || Name == "insl")) {
1136 X86Operand &Op = *(X86Operand*)Operands.begin()[1];
1137 X86Operand &Op2 = *(X86Operand*)Operands.begin()[2];
1138 if (Op.isReg() && Op.getReg() == X86::DX && isDstOp(Op2)) {
1139 Operands.pop_back();
1140 Operands.pop_back();
1141 delete &Op;
1142 delete &Op2;
1143 }
1144 }
1145
1146 // Transform "outs[bwl] %ds:(%esi), %dx" into "out[bwl]"
1147 if (Name.startswith("outs") && Operands.size() == 3 &&
1148 (Name == "outsb" || Name == "outsw" || Name == "outsl")) {
1149 X86Operand &Op = *(X86Operand*)Operands.begin()[1];
1150 X86Operand &Op2 = *(X86Operand*)Operands.begin()[2];
1151 if (isSrcOp(Op) && Op2.isReg() && Op2.getReg() == X86::DX) {
1152 Operands.pop_back();
1153 Operands.pop_back();
1154 delete &Op;
1155 delete &Op2;
1156 }
1157 }
1158
1159 // Transform "movs[bwl] %ds:(%esi), %es:(%edi)" into "movs[bwl]"
1160 if (Name.startswith("movs") && Operands.size() == 3 &&
1161 (Name == "movsb" || Name == "movsw" || Name == "movsl" ||
Evan Cheng59ee62d2011-07-11 03:57:24 +00001162 (is64BitMode() && Name == "movsq"))) {
Joerg Sonnenberger96622aa2011-03-18 11:59:40 +00001163 X86Operand &Op = *(X86Operand*)Operands.begin()[1];
1164 X86Operand &Op2 = *(X86Operand*)Operands.begin()[2];
1165 if (isSrcOp(Op) && isDstOp(Op2)) {
1166 Operands.pop_back();
1167 Operands.pop_back();
1168 delete &Op;
1169 delete &Op2;
1170 }
1171 }
1172 // Transform "lods[bwl] %ds:(%esi),{%al,%ax,%eax,%rax}" into "lods[bwl]"
1173 if (Name.startswith("lods") && Operands.size() == 3 &&
1174 (Name == "lods" || Name == "lodsb" || Name == "lodsw" ||
Evan Cheng59ee62d2011-07-11 03:57:24 +00001175 Name == "lodsl" || (is64BitMode() && Name == "lodsq"))) {
Joerg Sonnenberger96622aa2011-03-18 11:59:40 +00001176 X86Operand *Op1 = static_cast<X86Operand*>(Operands[1]);
1177 X86Operand *Op2 = static_cast<X86Operand*>(Operands[2]);
1178 if (isSrcOp(*Op1) && Op2->isReg()) {
1179 const char *ins;
1180 unsigned reg = Op2->getReg();
1181 bool isLods = Name == "lods";
1182 if (reg == X86::AL && (isLods || Name == "lodsb"))
1183 ins = "lodsb";
1184 else if (reg == X86::AX && (isLods || Name == "lodsw"))
1185 ins = "lodsw";
1186 else if (reg == X86::EAX && (isLods || Name == "lodsl"))
1187 ins = "lodsl";
1188 else if (reg == X86::RAX && (isLods || Name == "lodsq"))
1189 ins = "lodsq";
1190 else
1191 ins = NULL;
1192 if (ins != NULL) {
1193 Operands.pop_back();
1194 Operands.pop_back();
1195 delete Op1;
1196 delete Op2;
1197 if (Name != ins)
1198 static_cast<X86Operand*>(Operands[0])->setTokenValue(ins);
1199 }
1200 }
1201 }
1202 // Transform "stos[bwl] {%al,%ax,%eax,%rax},%es:(%edi)" into "stos[bwl]"
1203 if (Name.startswith("stos") && Operands.size() == 3 &&
1204 (Name == "stos" || Name == "stosb" || Name == "stosw" ||
Evan Cheng59ee62d2011-07-11 03:57:24 +00001205 Name == "stosl" || (is64BitMode() && Name == "stosq"))) {
Joerg Sonnenberger96622aa2011-03-18 11:59:40 +00001206 X86Operand *Op1 = static_cast<X86Operand*>(Operands[1]);
1207 X86Operand *Op2 = static_cast<X86Operand*>(Operands[2]);
1208 if (isDstOp(*Op2) && Op1->isReg()) {
1209 const char *ins;
1210 unsigned reg = Op1->getReg();
1211 bool isStos = Name == "stos";
1212 if (reg == X86::AL && (isStos || Name == "stosb"))
1213 ins = "stosb";
1214 else if (reg == X86::AX && (isStos || Name == "stosw"))
1215 ins = "stosw";
1216 else if (reg == X86::EAX && (isStos || Name == "stosl"))
1217 ins = "stosl";
1218 else if (reg == X86::RAX && (isStos || Name == "stosq"))
1219 ins = "stosq";
1220 else
1221 ins = NULL;
1222 if (ins != NULL) {
1223 Operands.pop_back();
1224 Operands.pop_back();
1225 delete Op1;
1226 delete Op2;
1227 if (Name != ins)
1228 static_cast<X86Operand*>(Operands[0])->setTokenValue(ins);
1229 }
1230 }
1231 }
1232
Chris Lattnere9e16a32010-09-15 04:33:27 +00001233 // FIXME: Hack to handle recognize s{hr,ar,hl} $1, <op>. Canonicalize to
Chris Lattneree211d02010-09-11 16:32:12 +00001234 // "shift <op>".
Daniel Dunbard5e77052010-03-13 00:47:29 +00001235 if ((Name.startswith("shr") || Name.startswith("sar") ||
Chris Lattner8c24b0c2010-11-06 21:23:40 +00001236 Name.startswith("shl") || Name.startswith("sal") ||
1237 Name.startswith("rcl") || Name.startswith("rcr") ||
1238 Name.startswith("rol") || Name.startswith("ror")) &&
Chris Lattner47ab90b2010-09-06 18:32:06 +00001239 Operands.size() == 3) {
Devang Patelbe3e3102012-01-30 20:02:42 +00001240 if (isParsingIntelSyntax()) {
Devang Patel3b96e1f2012-01-24 21:43:36 +00001241 // Intel syntax
1242 X86Operand *Op1 = static_cast<X86Operand*>(Operands[2]);
1243 if (Op1->isImm() && isa<MCConstantExpr>(Op1->getImm()) &&
Craig Topper76bd9382012-07-18 04:59:16 +00001244 cast<MCConstantExpr>(Op1->getImm())->getValue() == 1) {
1245 delete Operands[2];
1246 Operands.pop_back();
Devang Patel3b96e1f2012-01-24 21:43:36 +00001247 }
1248 } else {
1249 X86Operand *Op1 = static_cast<X86Operand*>(Operands[1]);
1250 if (Op1->isImm() && isa<MCConstantExpr>(Op1->getImm()) &&
Craig Topper76bd9382012-07-18 04:59:16 +00001251 cast<MCConstantExpr>(Op1->getImm())->getValue() == 1) {
1252 delete Operands[1];
1253 Operands.erase(Operands.begin() + 1);
Devang Patel3b96e1f2012-01-24 21:43:36 +00001254 }
Chris Lattner47ab90b2010-09-06 18:32:06 +00001255 }
Daniel Dunbarf2de13f2010-03-20 22:36:38 +00001256 }
Chad Rosier36b8fed2012-06-27 22:34:28 +00001257
Chris Lattner15f89512011-04-09 19:41:05 +00001258 // Transforms "int $3" into "int3" as a size optimization. We can't write an
1259 // instalias with an immediate operand yet.
1260 if (Name == "int" && Operands.size() == 2) {
1261 X86Operand *Op1 = static_cast<X86Operand*>(Operands[1]);
1262 if (Op1->isImm() && isa<MCConstantExpr>(Op1->getImm()) &&
1263 cast<MCConstantExpr>(Op1->getImm())->getValue() == 3) {
1264 delete Operands[1];
1265 Operands.erase(Operands.begin() + 1);
1266 static_cast<X86Operand*>(Operands[0])->setTokenValue("int3");
1267 }
1268 }
Michael J. Spencerc0c8df32010-10-09 11:00:50 +00001269
Chris Lattner98986712010-01-14 22:21:20 +00001270 return false;
Daniel Dunbara3af3702009-07-20 18:55:04 +00001271}
1272
Devang Pateldd929fc2012-01-12 18:03:40 +00001273bool X86AsmParser::
Devang Patelb8ba13f2012-01-18 22:42:29 +00001274processInstruction(MCInst &Inst,
1275 const SmallVectorImpl<MCParsedAsmOperand*> &Ops) {
1276 switch (Inst.getOpcode()) {
1277 default: return false;
1278 case X86::AND16i16: {
1279 if (!Inst.getOperand(0).isImm() ||
1280 !isImmSExti16i8Value(Inst.getOperand(0).getImm()))
1281 return false;
1282
1283 MCInst TmpInst;
1284 TmpInst.setOpcode(X86::AND16ri8);
1285 TmpInst.addOperand(MCOperand::CreateReg(X86::AX));
1286 TmpInst.addOperand(MCOperand::CreateReg(X86::AX));
1287 TmpInst.addOperand(Inst.getOperand(0));
1288 Inst = TmpInst;
1289 return true;
1290 }
1291 case X86::AND32i32: {
1292 if (!Inst.getOperand(0).isImm() ||
1293 !isImmSExti32i8Value(Inst.getOperand(0).getImm()))
1294 return false;
1295
1296 MCInst TmpInst;
1297 TmpInst.setOpcode(X86::AND32ri8);
1298 TmpInst.addOperand(MCOperand::CreateReg(X86::EAX));
1299 TmpInst.addOperand(MCOperand::CreateReg(X86::EAX));
1300 TmpInst.addOperand(Inst.getOperand(0));
1301 Inst = TmpInst;
1302 return true;
1303 }
1304 case X86::AND64i32: {
1305 if (!Inst.getOperand(0).isImm() ||
1306 !isImmSExti64i8Value(Inst.getOperand(0).getImm()))
1307 return false;
1308
1309 MCInst TmpInst;
1310 TmpInst.setOpcode(X86::AND64ri8);
1311 TmpInst.addOperand(MCOperand::CreateReg(X86::RAX));
1312 TmpInst.addOperand(MCOperand::CreateReg(X86::RAX));
1313 TmpInst.addOperand(Inst.getOperand(0));
1314 Inst = TmpInst;
1315 return true;
1316 }
Devang Patelac0f0482012-01-19 17:53:25 +00001317 case X86::XOR16i16: {
1318 if (!Inst.getOperand(0).isImm() ||
1319 !isImmSExti16i8Value(Inst.getOperand(0).getImm()))
1320 return false;
1321
1322 MCInst TmpInst;
1323 TmpInst.setOpcode(X86::XOR16ri8);
1324 TmpInst.addOperand(MCOperand::CreateReg(X86::AX));
1325 TmpInst.addOperand(MCOperand::CreateReg(X86::AX));
1326 TmpInst.addOperand(Inst.getOperand(0));
1327 Inst = TmpInst;
1328 return true;
1329 }
1330 case X86::XOR32i32: {
1331 if (!Inst.getOperand(0).isImm() ||
1332 !isImmSExti32i8Value(Inst.getOperand(0).getImm()))
1333 return false;
1334
1335 MCInst TmpInst;
1336 TmpInst.setOpcode(X86::XOR32ri8);
1337 TmpInst.addOperand(MCOperand::CreateReg(X86::EAX));
1338 TmpInst.addOperand(MCOperand::CreateReg(X86::EAX));
1339 TmpInst.addOperand(Inst.getOperand(0));
1340 Inst = TmpInst;
1341 return true;
1342 }
1343 case X86::XOR64i32: {
1344 if (!Inst.getOperand(0).isImm() ||
1345 !isImmSExti64i8Value(Inst.getOperand(0).getImm()))
1346 return false;
1347
1348 MCInst TmpInst;
1349 TmpInst.setOpcode(X86::XOR64ri8);
1350 TmpInst.addOperand(MCOperand::CreateReg(X86::RAX));
1351 TmpInst.addOperand(MCOperand::CreateReg(X86::RAX));
1352 TmpInst.addOperand(Inst.getOperand(0));
1353 Inst = TmpInst;
1354 return true;
1355 }
1356 case X86::OR16i16: {
1357 if (!Inst.getOperand(0).isImm() ||
1358 !isImmSExti16i8Value(Inst.getOperand(0).getImm()))
1359 return false;
1360
1361 MCInst TmpInst;
1362 TmpInst.setOpcode(X86::OR16ri8);
1363 TmpInst.addOperand(MCOperand::CreateReg(X86::AX));
1364 TmpInst.addOperand(MCOperand::CreateReg(X86::AX));
1365 TmpInst.addOperand(Inst.getOperand(0));
1366 Inst = TmpInst;
1367 return true;
1368 }
1369 case X86::OR32i32: {
1370 if (!Inst.getOperand(0).isImm() ||
1371 !isImmSExti32i8Value(Inst.getOperand(0).getImm()))
1372 return false;
1373
1374 MCInst TmpInst;
1375 TmpInst.setOpcode(X86::OR32ri8);
1376 TmpInst.addOperand(MCOperand::CreateReg(X86::EAX));
1377 TmpInst.addOperand(MCOperand::CreateReg(X86::EAX));
1378 TmpInst.addOperand(Inst.getOperand(0));
1379 Inst = TmpInst;
1380 return true;
1381 }
1382 case X86::OR64i32: {
1383 if (!Inst.getOperand(0).isImm() ||
1384 !isImmSExti64i8Value(Inst.getOperand(0).getImm()))
1385 return false;
1386
1387 MCInst TmpInst;
1388 TmpInst.setOpcode(X86::OR64ri8);
1389 TmpInst.addOperand(MCOperand::CreateReg(X86::RAX));
1390 TmpInst.addOperand(MCOperand::CreateReg(X86::RAX));
1391 TmpInst.addOperand(Inst.getOperand(0));
1392 Inst = TmpInst;
1393 return true;
1394 }
1395 case X86::CMP16i16: {
1396 if (!Inst.getOperand(0).isImm() ||
1397 !isImmSExti16i8Value(Inst.getOperand(0).getImm()))
1398 return false;
1399
1400 MCInst TmpInst;
1401 TmpInst.setOpcode(X86::CMP16ri8);
1402 TmpInst.addOperand(MCOperand::CreateReg(X86::AX));
1403 TmpInst.addOperand(Inst.getOperand(0));
1404 Inst = TmpInst;
1405 return true;
1406 }
1407 case X86::CMP32i32: {
1408 if (!Inst.getOperand(0).isImm() ||
1409 !isImmSExti32i8Value(Inst.getOperand(0).getImm()))
1410 return false;
1411
1412 MCInst TmpInst;
1413 TmpInst.setOpcode(X86::CMP32ri8);
1414 TmpInst.addOperand(MCOperand::CreateReg(X86::EAX));
1415 TmpInst.addOperand(Inst.getOperand(0));
1416 Inst = TmpInst;
1417 return true;
1418 }
1419 case X86::CMP64i32: {
1420 if (!Inst.getOperand(0).isImm() ||
1421 !isImmSExti64i8Value(Inst.getOperand(0).getImm()))
1422 return false;
1423
1424 MCInst TmpInst;
1425 TmpInst.setOpcode(X86::CMP64ri8);
1426 TmpInst.addOperand(MCOperand::CreateReg(X86::RAX));
1427 TmpInst.addOperand(Inst.getOperand(0));
1428 Inst = TmpInst;
1429 return true;
1430 }
Devang Patela951f772012-01-19 18:40:55 +00001431 case X86::ADD16i16: {
1432 if (!Inst.getOperand(0).isImm() ||
1433 !isImmSExti16i8Value(Inst.getOperand(0).getImm()))
1434 return false;
1435
1436 MCInst TmpInst;
1437 TmpInst.setOpcode(X86::ADD16ri8);
1438 TmpInst.addOperand(MCOperand::CreateReg(X86::AX));
1439 TmpInst.addOperand(MCOperand::CreateReg(X86::AX));
1440 TmpInst.addOperand(Inst.getOperand(0));
1441 Inst = TmpInst;
1442 return true;
1443 }
1444 case X86::ADD32i32: {
1445 if (!Inst.getOperand(0).isImm() ||
1446 !isImmSExti32i8Value(Inst.getOperand(0).getImm()))
1447 return false;
1448
1449 MCInst TmpInst;
1450 TmpInst.setOpcode(X86::ADD32ri8);
1451 TmpInst.addOperand(MCOperand::CreateReg(X86::EAX));
1452 TmpInst.addOperand(MCOperand::CreateReg(X86::EAX));
1453 TmpInst.addOperand(Inst.getOperand(0));
1454 Inst = TmpInst;
1455 return true;
1456 }
1457 case X86::ADD64i32: {
1458 if (!Inst.getOperand(0).isImm() ||
1459 !isImmSExti64i8Value(Inst.getOperand(0).getImm()))
1460 return false;
1461
1462 MCInst TmpInst;
1463 TmpInst.setOpcode(X86::ADD64ri8);
1464 TmpInst.addOperand(MCOperand::CreateReg(X86::RAX));
1465 TmpInst.addOperand(MCOperand::CreateReg(X86::RAX));
1466 TmpInst.addOperand(Inst.getOperand(0));
1467 Inst = TmpInst;
1468 return true;
1469 }
1470 case X86::SUB16i16: {
1471 if (!Inst.getOperand(0).isImm() ||
1472 !isImmSExti16i8Value(Inst.getOperand(0).getImm()))
1473 return false;
1474
1475 MCInst TmpInst;
1476 TmpInst.setOpcode(X86::SUB16ri8);
1477 TmpInst.addOperand(MCOperand::CreateReg(X86::AX));
1478 TmpInst.addOperand(MCOperand::CreateReg(X86::AX));
1479 TmpInst.addOperand(Inst.getOperand(0));
1480 Inst = TmpInst;
1481 return true;
1482 }
1483 case X86::SUB32i32: {
1484 if (!Inst.getOperand(0).isImm() ||
1485 !isImmSExti32i8Value(Inst.getOperand(0).getImm()))
1486 return false;
1487
1488 MCInst TmpInst;
1489 TmpInst.setOpcode(X86::SUB32ri8);
1490 TmpInst.addOperand(MCOperand::CreateReg(X86::EAX));
1491 TmpInst.addOperand(MCOperand::CreateReg(X86::EAX));
1492 TmpInst.addOperand(Inst.getOperand(0));
1493 Inst = TmpInst;
1494 return true;
1495 }
1496 case X86::SUB64i32: {
1497 if (!Inst.getOperand(0).isImm() ||
1498 !isImmSExti64i8Value(Inst.getOperand(0).getImm()))
1499 return false;
1500
1501 MCInst TmpInst;
1502 TmpInst.setOpcode(X86::SUB64ri8);
1503 TmpInst.addOperand(MCOperand::CreateReg(X86::RAX));
1504 TmpInst.addOperand(MCOperand::CreateReg(X86::RAX));
1505 TmpInst.addOperand(Inst.getOperand(0));
1506 Inst = TmpInst;
1507 return true;
1508 }
Devang Patelb8ba13f2012-01-18 22:42:29 +00001509 }
Devang Patelb8ba13f2012-01-18 22:42:29 +00001510}
1511
1512bool X86AsmParser::
Chris Lattner7036f8b2010-09-29 01:42:58 +00001513MatchAndEmitInstruction(SMLoc IDLoc,
Chris Lattner7c51a312010-09-29 01:50:45 +00001514 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chris Lattner7036f8b2010-09-29 01:42:58 +00001515 MCStreamer &Out) {
Chad Rosier32461762012-08-09 22:04:55 +00001516 SmallVector<MCInst, 2> Insts;
Chad Rosier64bfcbb2012-08-21 18:14:59 +00001517 unsigned ErrorInfo;
1518 bool Error = MatchInstruction(IDLoc, Operands, Insts, ErrorInfo);
Chad Rosier32461762012-08-09 22:04:55 +00001519 if (!Error)
1520 for (unsigned i = 0, e = Insts.size(); i != e; ++i)
1521 Out.EmitInstruction(Insts[i]);
1522 return Error;
1523}
1524
1525bool X86AsmParser::
1526MatchInstruction(SMLoc IDLoc,
1527 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier64bfcbb2012-08-21 18:14:59 +00001528 SmallVectorImpl<MCInst> &MCInsts,
1529 unsigned &OrigErrorInfo) {
Daniel Dunbarf1e29d42010-08-12 00:55:38 +00001530 assert(!Operands.empty() && "Unexpect empty operand list!");
Chris Lattner7c51a312010-09-29 01:50:45 +00001531 X86Operand *Op = static_cast<X86Operand*>(Operands[0]);
1532 assert(Op->isToken() && "Leading operand should always be a mnemonic!");
Daniel Dunbarf1e29d42010-08-12 00:55:38 +00001533
Chris Lattner7c51a312010-09-29 01:50:45 +00001534 // First, handle aliases that expand to multiple instructions.
1535 // FIXME: This should be replaced with a real .td file alias mechanism.
Chris Lattner90fd7972010-11-06 19:57:21 +00001536 // Also, MatchInstructionImpl should do actually *do* the EmitInstruction
1537 // call.
Andrew Trick0966ec02010-10-22 03:58:29 +00001538 if (Op->getToken() == "fstsw" || Op->getToken() == "fstcw" ||
Chris Lattner8b260a72010-10-30 18:07:17 +00001539 Op->getToken() == "fstsww" || Op->getToken() == "fstcww" ||
Chris Lattner905f2e02010-09-30 17:11:29 +00001540 Op->getToken() == "finit" || Op->getToken() == "fsave" ||
Kevin Enderby5a378072010-10-27 02:53:04 +00001541 Op->getToken() == "fstenv" || Op->getToken() == "fclex") {
Chris Lattner7c51a312010-09-29 01:50:45 +00001542 MCInst Inst;
1543 Inst.setOpcode(X86::WAIT);
Jim Grosbachcb5dca32012-01-27 00:51:27 +00001544 Inst.setLoc(IDLoc);
Chad Rosier32461762012-08-09 22:04:55 +00001545 MCInsts.push_back(Inst);
Chris Lattner7c51a312010-09-29 01:50:45 +00001546
Chris Lattner0bb83a82010-09-30 16:39:29 +00001547 const char *Repl =
1548 StringSwitch<const char*>(Op->getToken())
Chris Lattner8b260a72010-10-30 18:07:17 +00001549 .Case("finit", "fninit")
1550 .Case("fsave", "fnsave")
1551 .Case("fstcw", "fnstcw")
1552 .Case("fstcww", "fnstcw")
Chris Lattner905f2e02010-09-30 17:11:29 +00001553 .Case("fstenv", "fnstenv")
Chris Lattner8b260a72010-10-30 18:07:17 +00001554 .Case("fstsw", "fnstsw")
1555 .Case("fstsww", "fnstsw")
1556 .Case("fclex", "fnclex")
Chris Lattner0bb83a82010-09-30 16:39:29 +00001557 .Default(0);
1558 assert(Repl && "Unknown wait-prefixed instruction");
Benjamin Kramerb0f96fa2010-10-01 12:25:27 +00001559 delete Operands[0];
Chris Lattner0bb83a82010-09-30 16:39:29 +00001560 Operands[0] = X86Operand::CreateToken(Repl, IDLoc);
Chris Lattner7c51a312010-09-29 01:50:45 +00001561 }
Michael J. Spencerc0c8df32010-10-09 11:00:50 +00001562
Chris Lattnera008e8a2010-09-06 21:54:15 +00001563 bool WasOriginallyInvalidOperand = false;
Chris Lattner7036f8b2010-09-29 01:42:58 +00001564 MCInst Inst;
Michael J. Spencerc0c8df32010-10-09 11:00:50 +00001565
Daniel Dunbarc918d602010-05-04 16:12:42 +00001566 // First, try a direct match.
Devang Patelbe3e3102012-01-30 20:02:42 +00001567 switch (MatchInstructionImpl(Operands, Inst, OrigErrorInfo,
1568 isParsingIntelSyntax())) {
Jim Grosbach19cb7f42011-08-15 23:03:29 +00001569 default: break;
Chris Lattnerec6789f2010-09-06 20:08:02 +00001570 case Match_Success:
Devang Patelb8ba13f2012-01-18 22:42:29 +00001571 // Some instructions need post-processing to, for example, tweak which
1572 // encoding is selected. Loop on it while changes happen so the
Chad Rosier36b8fed2012-06-27 22:34:28 +00001573 // individual transformations can chain off each other.
Devang Patelb8ba13f2012-01-18 22:42:29 +00001574 while (processInstruction(Inst, Operands))
1575 ;
1576
Jim Grosbachcb5dca32012-01-27 00:51:27 +00001577 Inst.setLoc(IDLoc);
Chad Rosier32461762012-08-09 22:04:55 +00001578 MCInsts.push_back(Inst);
Daniel Dunbarc918d602010-05-04 16:12:42 +00001579 return false;
Chris Lattnerec6789f2010-09-06 20:08:02 +00001580 case Match_MissingFeature:
1581 Error(IDLoc, "instruction requires a CPU feature not currently enabled");
1582 return true;
Daniel Dunbarb4129152011-02-04 17:12:23 +00001583 case Match_ConversionFail:
1584 return Error(IDLoc, "unable to convert operands to instruction");
Chris Lattnera008e8a2010-09-06 21:54:15 +00001585 case Match_InvalidOperand:
1586 WasOriginallyInvalidOperand = true;
1587 break;
1588 case Match_MnemonicFail:
Chris Lattnerec6789f2010-09-06 20:08:02 +00001589 break;
1590 }
Daniel Dunbarc918d602010-05-04 16:12:42 +00001591
Daniel Dunbarc918d602010-05-04 16:12:42 +00001592 // FIXME: Ideally, we would only attempt suffix matches for things which are
1593 // valid prefixes, and we could just infer the right unambiguous
1594 // type. However, that requires substantially more matcher support than the
1595 // following hack.
Michael J. Spencerc0c8df32010-10-09 11:00:50 +00001596
Daniel Dunbarc918d602010-05-04 16:12:42 +00001597 // Change the operand to point to a temporary token.
Daniel Dunbarc918d602010-05-04 16:12:42 +00001598 StringRef Base = Op->getToken();
Daniel Dunbarf1e29d42010-08-12 00:55:38 +00001599 SmallString<16> Tmp;
1600 Tmp += Base;
1601 Tmp += ' ';
1602 Op->setTokenValue(Tmp.str());
Daniel Dunbarc918d602010-05-04 16:12:42 +00001603
Chris Lattnerfb7000f2010-11-06 18:28:02 +00001604 // If this instruction starts with an 'f', then it is a floating point stack
1605 // instruction. These come in up to three forms for 32-bit, 64-bit, and
1606 // 80-bit floating point, which use the suffixes s,l,t respectively.
1607 //
1608 // Otherwise, we assume that this may be an integer instruction, which comes
1609 // in 8/16/32/64-bit forms using the b,w,l,q suffixes respectively.
1610 const char *Suffixes = Base[0] != 'f' ? "bwlq" : "slt\0";
Chad Rosier36b8fed2012-06-27 22:34:28 +00001611
Daniel Dunbarc918d602010-05-04 16:12:42 +00001612 // Check for the various suffix matches.
Chris Lattnerfb7000f2010-11-06 18:28:02 +00001613 Tmp[Base.size()] = Suffixes[0];
1614 unsigned ErrorInfoIgnore;
Jim Grosbach19cb7f42011-08-15 23:03:29 +00001615 unsigned Match1, Match2, Match3, Match4;
Chad Rosier36b8fed2012-06-27 22:34:28 +00001616
Chris Lattnerfb7000f2010-11-06 18:28:02 +00001617 Match1 = MatchInstructionImpl(Operands, Inst, ErrorInfoIgnore);
1618 Tmp[Base.size()] = Suffixes[1];
1619 Match2 = MatchInstructionImpl(Operands, Inst, ErrorInfoIgnore);
1620 Tmp[Base.size()] = Suffixes[2];
1621 Match3 = MatchInstructionImpl(Operands, Inst, ErrorInfoIgnore);
1622 Tmp[Base.size()] = Suffixes[3];
1623 Match4 = MatchInstructionImpl(Operands, Inst, ErrorInfoIgnore);
Daniel Dunbarc918d602010-05-04 16:12:42 +00001624
1625 // Restore the old token.
1626 Op->setTokenValue(Base);
1627
1628 // If exactly one matched, then we treat that as a successful match (and the
1629 // instruction will already have been filled in correctly, since the failing
1630 // matches won't have modified it).
Chris Lattnerec6789f2010-09-06 20:08:02 +00001631 unsigned NumSuccessfulMatches =
Chris Lattnerfb7000f2010-11-06 18:28:02 +00001632 (Match1 == Match_Success) + (Match2 == Match_Success) +
1633 (Match3 == Match_Success) + (Match4 == Match_Success);
Chris Lattner7036f8b2010-09-29 01:42:58 +00001634 if (NumSuccessfulMatches == 1) {
Jim Grosbachcb5dca32012-01-27 00:51:27 +00001635 Inst.setLoc(IDLoc);
Chad Rosier32461762012-08-09 22:04:55 +00001636 MCInsts.push_back(Inst);
Daniel Dunbarc918d602010-05-04 16:12:42 +00001637 return false;
Chris Lattner7036f8b2010-09-29 01:42:58 +00001638 }
Daniel Dunbarc918d602010-05-04 16:12:42 +00001639
Chris Lattnerec6789f2010-09-06 20:08:02 +00001640 // Otherwise, the match failed, try to produce a decent error message.
Daniel Dunbarf1e29d42010-08-12 00:55:38 +00001641
Daniel Dunbar09062b12010-08-12 00:55:42 +00001642 // If we had multiple suffix matches, then identify this as an ambiguous
1643 // match.
Chris Lattnerec6789f2010-09-06 20:08:02 +00001644 if (NumSuccessfulMatches > 1) {
Daniel Dunbar09062b12010-08-12 00:55:42 +00001645 char MatchChars[4];
1646 unsigned NumMatches = 0;
Chris Lattnerfb7000f2010-11-06 18:28:02 +00001647 if (Match1 == Match_Success) MatchChars[NumMatches++] = Suffixes[0];
1648 if (Match2 == Match_Success) MatchChars[NumMatches++] = Suffixes[1];
1649 if (Match3 == Match_Success) MatchChars[NumMatches++] = Suffixes[2];
1650 if (Match4 == Match_Success) MatchChars[NumMatches++] = Suffixes[3];
Daniel Dunbar09062b12010-08-12 00:55:42 +00001651
1652 SmallString<126> Msg;
1653 raw_svector_ostream OS(Msg);
1654 OS << "ambiguous instructions require an explicit suffix (could be ";
1655 for (unsigned i = 0; i != NumMatches; ++i) {
1656 if (i != 0)
1657 OS << ", ";
1658 if (i + 1 == NumMatches)
1659 OS << "or ";
1660 OS << "'" << Base << MatchChars[i] << "'";
1661 }
1662 OS << ")";
1663 Error(IDLoc, OS.str());
Chris Lattnerec6789f2010-09-06 20:08:02 +00001664 return true;
Daniel Dunbar09062b12010-08-12 00:55:42 +00001665 }
Michael J. Spencerc0c8df32010-10-09 11:00:50 +00001666
Chris Lattnera008e8a2010-09-06 21:54:15 +00001667 // Okay, we know that none of the variants matched successfully.
Michael J. Spencerc0c8df32010-10-09 11:00:50 +00001668
Chris Lattnera008e8a2010-09-06 21:54:15 +00001669 // If all of the instructions reported an invalid mnemonic, then the original
1670 // mnemonic was invalid.
Chris Lattnerfb7000f2010-11-06 18:28:02 +00001671 if ((Match1 == Match_MnemonicFail) && (Match2 == Match_MnemonicFail) &&
1672 (Match3 == Match_MnemonicFail) && (Match4 == Match_MnemonicFail)) {
Chris Lattnerce4a3352010-09-06 22:11:18 +00001673 if (!WasOriginallyInvalidOperand) {
Benjamin Kramerf82edaf2011-10-16 11:28:29 +00001674 return Error(IDLoc, "invalid instruction mnemonic '" + Base + "'",
1675 Op->getLocRange());
Chris Lattnerce4a3352010-09-06 22:11:18 +00001676 }
1677
1678 // Recover location info for the operand if we know which was the problem.
Chris Lattnerce4a3352010-09-06 22:11:18 +00001679 if (OrigErrorInfo != ~0U) {
Chris Lattnerf8840122010-09-15 03:50:11 +00001680 if (OrigErrorInfo >= Operands.size())
1681 return Error(IDLoc, "too few operands for instruction");
Michael J. Spencerc0c8df32010-10-09 11:00:50 +00001682
Chris Lattnerd8b7aa22011-10-16 04:47:35 +00001683 X86Operand *Operand = (X86Operand*)Operands[OrigErrorInfo];
1684 if (Operand->getStartLoc().isValid()) {
1685 SMRange OperandRange = Operand->getLocRange();
1686 return Error(Operand->getStartLoc(), "invalid operand for instruction",
1687 OperandRange);
1688 }
Chris Lattnerce4a3352010-09-06 22:11:18 +00001689 }
1690
Chris Lattnerd8b7aa22011-10-16 04:47:35 +00001691 return Error(IDLoc, "invalid operand for instruction");
Chris Lattnera008e8a2010-09-06 21:54:15 +00001692 }
Michael J. Spencerc0c8df32010-10-09 11:00:50 +00001693
Chris Lattnerec6789f2010-09-06 20:08:02 +00001694 // If one instruction matched with a missing feature, report this as a
1695 // missing feature.
Chris Lattnerfb7000f2010-11-06 18:28:02 +00001696 if ((Match1 == Match_MissingFeature) + (Match2 == Match_MissingFeature) +
1697 (Match3 == Match_MissingFeature) + (Match4 == Match_MissingFeature) == 1){
Chris Lattnerec6789f2010-09-06 20:08:02 +00001698 Error(IDLoc, "instruction requires a CPU feature not currently enabled");
1699 return true;
1700 }
Michael J. Spencerc0c8df32010-10-09 11:00:50 +00001701
Chris Lattnera008e8a2010-09-06 21:54:15 +00001702 // If one instruction matched with an invalid operand, report this as an
1703 // operand failure.
Chris Lattnerfb7000f2010-11-06 18:28:02 +00001704 if ((Match1 == Match_InvalidOperand) + (Match2 == Match_InvalidOperand) +
1705 (Match3 == Match_InvalidOperand) + (Match4 == Match_InvalidOperand) == 1){
Chris Lattnera008e8a2010-09-06 21:54:15 +00001706 Error(IDLoc, "invalid operand for instruction");
1707 return true;
1708 }
Michael J. Spencerc0c8df32010-10-09 11:00:50 +00001709
Chris Lattnerec6789f2010-09-06 20:08:02 +00001710 // If all of these were an outright failure, report it in a useless way.
Chris Lattnera008e8a2010-09-06 21:54:15 +00001711 Error(IDLoc, "unknown use of instruction mnemonic without a size suffix");
Daniel Dunbarc918d602010-05-04 16:12:42 +00001712 return true;
1713}
1714
1715
Devang Pateldd929fc2012-01-12 18:03:40 +00001716bool X86AsmParser::ParseDirective(AsmToken DirectiveID) {
Chris Lattner537ca842010-10-30 17:38:55 +00001717 StringRef IDVal = DirectiveID.getIdentifier();
1718 if (IDVal == ".word")
1719 return ParseDirectiveWord(2, DirectiveID.getLoc());
Evan Chengbd27f5a2011-07-27 00:38:12 +00001720 else if (IDVal.startswith(".code"))
1721 return ParseDirectiveCode(IDVal, DirectiveID.getLoc());
Devang Patelbe3e3102012-01-30 20:02:42 +00001722 else if (IDVal.startswith(".intel_syntax")) {
Devang Patel0db58bf2012-01-31 18:14:05 +00001723 getParser().setAssemblerDialect(1);
Devang Patelbe3e3102012-01-30 20:02:42 +00001724 if (getLexer().isNot(AsmToken::EndOfStatement)) {
1725 if(Parser.getTok().getString() == "noprefix") {
Craig Topper76bd9382012-07-18 04:59:16 +00001726 // FIXME : Handle noprefix
1727 Parser.Lex();
Devang Patelbe3e3102012-01-30 20:02:42 +00001728 } else
Craig Topper76bd9382012-07-18 04:59:16 +00001729 return true;
Devang Patelbe3e3102012-01-30 20:02:42 +00001730 }
1731 return false;
1732 }
Chris Lattner537ca842010-10-30 17:38:55 +00001733 return true;
1734}
1735
1736/// ParseDirectiveWord
1737/// ::= .word [ expression (, expression)* ]
Devang Pateldd929fc2012-01-12 18:03:40 +00001738bool X86AsmParser::ParseDirectiveWord(unsigned Size, SMLoc L) {
Chris Lattner537ca842010-10-30 17:38:55 +00001739 if (getLexer().isNot(AsmToken::EndOfStatement)) {
1740 for (;;) {
1741 const MCExpr *Value;
1742 if (getParser().ParseExpression(Value))
1743 return true;
Chad Rosier36b8fed2012-06-27 22:34:28 +00001744
Chris Lattner537ca842010-10-30 17:38:55 +00001745 getParser().getStreamer().EmitValue(Value, Size, 0 /*addrspace*/);
Chad Rosier36b8fed2012-06-27 22:34:28 +00001746
Chris Lattner537ca842010-10-30 17:38:55 +00001747 if (getLexer().is(AsmToken::EndOfStatement))
1748 break;
Chad Rosier36b8fed2012-06-27 22:34:28 +00001749
Chris Lattner537ca842010-10-30 17:38:55 +00001750 // FIXME: Improve diagnostic.
1751 if (getLexer().isNot(AsmToken::Comma))
1752 return Error(L, "unexpected token in directive");
1753 Parser.Lex();
1754 }
1755 }
Chad Rosier36b8fed2012-06-27 22:34:28 +00001756
Chris Lattner537ca842010-10-30 17:38:55 +00001757 Parser.Lex();
1758 return false;
1759}
1760
Evan Chengbd27f5a2011-07-27 00:38:12 +00001761/// ParseDirectiveCode
1762/// ::= .code32 | .code64
Devang Pateldd929fc2012-01-12 18:03:40 +00001763bool X86AsmParser::ParseDirectiveCode(StringRef IDVal, SMLoc L) {
Evan Chengbd27f5a2011-07-27 00:38:12 +00001764 if (IDVal == ".code32") {
1765 Parser.Lex();
1766 if (is64BitMode()) {
1767 SwitchMode();
1768 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
1769 }
1770 } else if (IDVal == ".code64") {
1771 Parser.Lex();
1772 if (!is64BitMode()) {
1773 SwitchMode();
1774 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code64);
1775 }
1776 } else {
1777 return Error(L, "unexpected directive " + IDVal);
1778 }
Chris Lattner537ca842010-10-30 17:38:55 +00001779
Evan Chengbd27f5a2011-07-27 00:38:12 +00001780 return false;
1781}
Chris Lattner537ca842010-10-30 17:38:55 +00001782
1783
Sean Callanane88f5522010-01-23 02:43:15 +00001784extern "C" void LLVMInitializeX86AsmLexer();
1785
Daniel Dunbar092a9dd2009-07-17 20:42:00 +00001786// Force static initialization.
1787extern "C" void LLVMInitializeX86AsmParser() {
Devang Pateldd929fc2012-01-12 18:03:40 +00001788 RegisterMCAsmParser<X86AsmParser> X(TheX86_32Target);
1789 RegisterMCAsmParser<X86AsmParser> Y(TheX86_64Target);
Sean Callanane88f5522010-01-23 02:43:15 +00001790 LLVMInitializeX86AsmLexer();
Daniel Dunbar092a9dd2009-07-17 20:42:00 +00001791}
Daniel Dunbar0e2771f2009-07-29 00:02:19 +00001792
Chris Lattner0692ee62010-09-06 19:11:01 +00001793#define GET_REGISTER_MATCHER
1794#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar0e2771f2009-07-29 00:02:19 +00001795#include "X86GenAsmMatcher.inc"