1 //===-- X86AsmParser.cpp - Parse X86 assembly to MCInst instructions ------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "MCTargetDesc/X86BaseInfo.h"
11 #include "llvm/ADT/APFloat.h"
12 #include "llvm/ADT/STLExtras.h"
13 #include "llvm/ADT/SmallString.h"
14 #include "llvm/ADT/SmallVector.h"
15 #include "llvm/ADT/StringSwitch.h"
16 #include "llvm/ADT/Twine.h"
17 #include "llvm/MC/MCContext.h"
18 #include "llvm/MC/MCExpr.h"
19 #include "llvm/MC/MCInst.h"
20 #include "llvm/MC/MCParser/MCAsmLexer.h"
21 #include "llvm/MC/MCParser/MCAsmParser.h"
22 #include "llvm/MC/MCParser/MCParsedAsmOperand.h"
23 #include "llvm/MC/MCRegisterInfo.h"
24 #include "llvm/MC/MCStreamer.h"
25 #include "llvm/MC/MCSubtargetInfo.h"
26 #include "llvm/MC/MCSymbol.h"
27 #include "llvm/MC/MCTargetAsmParser.h"
28 #include "llvm/Support/SourceMgr.h"
29 #include "llvm/Support/TargetRegistry.h"
30 #include "llvm/Support/raw_ostream.h"
37 static const char OpPrecedence[] = {
48 class X86AsmParser : public MCTargetAsmParser {
51 ParseInstructionInfo *InstInfo;
53 SMLoc consumeToken() {
54 SMLoc Result = Parser.getTok().getLoc();
59 enum InfixCalculatorTok {
70 class InfixCalculator {
71 typedef std::pair< InfixCalculatorTok, int64_t > ICToken;
72 SmallVector<InfixCalculatorTok, 4> InfixOperatorStack;
73 SmallVector<ICToken, 4> PostfixStack;
76 int64_t popOperand() {
77 assert (!PostfixStack.empty() && "Poped an empty stack!");
78 ICToken Op = PostfixStack.pop_back_val();
79 assert ((Op.first == IC_IMM || Op.first == IC_REGISTER)
80 && "Expected and immediate or register!");
83 void pushOperand(InfixCalculatorTok Op, int64_t Val = 0) {
84 assert ((Op == IC_IMM || Op == IC_REGISTER) &&
85 "Unexpected operand!");
86 PostfixStack.push_back(std::make_pair(Op, Val));
89 void popOperator() { InfixOperatorStack.pop_back(); }
90 void pushOperator(InfixCalculatorTok Op) {
91 // Push the new operator if the stack is empty.
92 if (InfixOperatorStack.empty()) {
93 InfixOperatorStack.push_back(Op);
97 // Push the new operator if it has a higher precedence than the operator
98 // on the top of the stack or the operator on the top of the stack is a
100 unsigned Idx = InfixOperatorStack.size() - 1;
101 InfixCalculatorTok StackOp = InfixOperatorStack[Idx];
102 if (OpPrecedence[Op] > OpPrecedence[StackOp] || StackOp == IC_LPAREN) {
103 InfixOperatorStack.push_back(Op);
107 // The operator on the top of the stack has higher precedence than the
109 unsigned ParenCount = 0;
111 // Nothing to process.
112 if (InfixOperatorStack.empty())
115 Idx = InfixOperatorStack.size() - 1;
116 StackOp = InfixOperatorStack[Idx];
117 if (!(OpPrecedence[StackOp] >= OpPrecedence[Op] || ParenCount))
120 // If we have an even parentheses count and we see a left parentheses,
121 // then stop processing.
122 if (!ParenCount && StackOp == IC_LPAREN)
125 if (StackOp == IC_RPAREN) {
127 InfixOperatorStack.pop_back();
128 } else if (StackOp == IC_LPAREN) {
130 InfixOperatorStack.pop_back();
132 InfixOperatorStack.pop_back();
133 PostfixStack.push_back(std::make_pair(StackOp, 0));
136 // Push the new operator.
137 InfixOperatorStack.push_back(Op);
140 // Push any remaining operators onto the postfix stack.
141 while (!InfixOperatorStack.empty()) {
142 InfixCalculatorTok StackOp = InfixOperatorStack.pop_back_val();
143 if (StackOp != IC_LPAREN && StackOp != IC_RPAREN)
144 PostfixStack.push_back(std::make_pair(StackOp, 0));
147 if (PostfixStack.empty())
150 SmallVector<ICToken, 16> OperandStack;
151 for (unsigned i = 0, e = PostfixStack.size(); i != e; ++i) {
152 ICToken Op = PostfixStack[i];
153 if (Op.first == IC_IMM || Op.first == IC_REGISTER) {
154 OperandStack.push_back(Op);
156 assert (OperandStack.size() > 1 && "Too few operands.");
158 ICToken Op2 = OperandStack.pop_back_val();
159 ICToken Op1 = OperandStack.pop_back_val();
162 report_fatal_error("Unexpected operator!");
165 Val = Op1.second + Op2.second;
166 OperandStack.push_back(std::make_pair(IC_IMM, Val));
169 Val = Op1.second - Op2.second;
170 OperandStack.push_back(std::make_pair(IC_IMM, Val));
173 assert (Op1.first == IC_IMM && Op2.first == IC_IMM &&
174 "Multiply operation with an immediate and a register!");
175 Val = Op1.second * Op2.second;
176 OperandStack.push_back(std::make_pair(IC_IMM, Val));
179 assert (Op1.first == IC_IMM && Op2.first == IC_IMM &&
180 "Divide operation with an immediate and a register!");
181 assert (Op2.second != 0 && "Division by zero!");
182 Val = Op1.second / Op2.second;
183 OperandStack.push_back(std::make_pair(IC_IMM, Val));
188 assert (OperandStack.size() == 1 && "Expected a single result.");
189 return OperandStack.pop_back_val().second;
193 enum IntelExprState {
208 class IntelExprStateMachine {
209 IntelExprState State, PrevState;
210 unsigned BaseReg, IndexReg, TmpReg, Scale;
214 bool StopOnLBrac, AddImmPrefix;
216 InlineAsmIdentifierInfo Info;
218 IntelExprStateMachine(int64_t imm, bool stoponlbrac, bool addimmprefix) :
219 State(IES_PLUS), PrevState(IES_ERROR), BaseReg(0), IndexReg(0), TmpReg(0),
220 Scale(1), Imm(imm), Sym(0), StopOnLBrac(stoponlbrac),
221 AddImmPrefix(addimmprefix) { Info.clear(); }
223 unsigned getBaseReg() { return BaseReg; }
224 unsigned getIndexReg() { return IndexReg; }
225 unsigned getScale() { return Scale; }
226 const MCExpr *getSym() { return Sym; }
227 StringRef getSymName() { return SymName; }
228 int64_t getImm() { return Imm + IC.execute(); }
229 bool isValidEndState() {
230 return State == IES_RBRAC || State == IES_INTEGER;
232 bool getStopOnLBrac() { return StopOnLBrac; }
233 bool getAddImmPrefix() { return AddImmPrefix; }
234 bool hadError() { return State == IES_ERROR; }
236 InlineAsmIdentifierInfo &getIdentifierInfo() {
241 IntelExprState CurrState = State;
250 IC.pushOperator(IC_PLUS);
251 if (CurrState == IES_REGISTER && PrevState != IES_MULTIPLY) {
252 // If we already have a BaseReg, then assume this is the IndexReg with
257 assert (!IndexReg && "BaseReg/IndexReg already set!");
264 PrevState = CurrState;
267 IntelExprState CurrState = State;
282 // Only push the minus operator if it is not a unary operator.
283 if (!(CurrState == IES_PLUS || CurrState == IES_MINUS ||
284 CurrState == IES_MULTIPLY || CurrState == IES_DIVIDE ||
285 CurrState == IES_LPAREN || CurrState == IES_LBRAC))
286 IC.pushOperator(IC_MINUS);
287 if (CurrState == IES_REGISTER && PrevState != IES_MULTIPLY) {
288 // If we already have a BaseReg, then assume this is the IndexReg with
293 assert (!IndexReg && "BaseReg/IndexReg already set!");
300 PrevState = CurrState;
302 void onRegister(unsigned Reg) {
303 IntelExprState CurrState = State;
310 State = IES_REGISTER;
312 IC.pushOperand(IC_REGISTER);
315 // Index Register - Scale * Register
316 if (PrevState == IES_INTEGER) {
317 assert (!IndexReg && "IndexReg already set!");
318 State = IES_REGISTER;
320 // Get the scale and replace the 'Scale * Register' with '0'.
321 Scale = IC.popOperand();
322 IC.pushOperand(IC_IMM);
329 PrevState = CurrState;
331 void onIdentifierExpr(const MCExpr *SymRef, StringRef SymRefName) {
341 SymName = SymRefName;
342 IC.pushOperand(IC_IMM);
346 void onInteger(int64_t TmpInt) {
347 IntelExprState CurrState = State;
358 if (PrevState == IES_REGISTER && CurrState == IES_MULTIPLY) {
359 // Index Register - Register * Scale
360 assert (!IndexReg && "IndexReg already set!");
363 // Get the scale and replace the 'Register * Scale' with '0'.
365 } else if ((PrevState == IES_PLUS || PrevState == IES_MINUS ||
366 PrevState == IES_MULTIPLY || PrevState == IES_DIVIDE ||
367 PrevState == IES_LPAREN || PrevState == IES_LBRAC) &&
368 CurrState == IES_MINUS) {
369 // Unary minus. No need to pop the minus operand because it was never
371 IC.pushOperand(IC_IMM, -TmpInt); // Push -Imm.
373 IC.pushOperand(IC_IMM, TmpInt);
377 PrevState = CurrState;
388 State = IES_MULTIPLY;
389 IC.pushOperator(IC_MULTIPLY);
402 IC.pushOperator(IC_DIVIDE);
414 IC.pushOperator(IC_PLUS);
419 IntelExprState CurrState = State;
428 if (CurrState == IES_REGISTER && PrevState != IES_MULTIPLY) {
429 // If we already have a BaseReg, then assume this is the IndexReg with
434 assert (!IndexReg && "BaseReg/IndexReg already set!");
441 PrevState = CurrState;
444 IntelExprState CurrState = State;
454 // FIXME: We don't handle this type of unary minus, yet.
455 if ((PrevState == IES_PLUS || PrevState == IES_MINUS ||
456 PrevState == IES_MULTIPLY || PrevState == IES_DIVIDE ||
457 PrevState == IES_LPAREN || PrevState == IES_LBRAC) &&
458 CurrState == IES_MINUS) {
463 IC.pushOperator(IC_LPAREN);
466 PrevState = CurrState;
478 IC.pushOperator(IC_RPAREN);
484 MCAsmParser &getParser() const { return Parser; }
486 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
488 bool Error(SMLoc L, const Twine &Msg,
489 ArrayRef<SMRange> Ranges = None,
490 bool MatchingInlineAsm = false) {
491 if (MatchingInlineAsm) return true;
492 return Parser.Error(L, Msg, Ranges);
495 X86Operand *ErrorOperand(SMLoc Loc, StringRef Msg) {
500 X86Operand *ParseOperand();
501 X86Operand *ParseATTOperand();
502 X86Operand *ParseIntelOperand();
503 X86Operand *ParseIntelOffsetOfOperator();
504 bool ParseIntelDotOperator(const MCExpr *Disp, const MCExpr *&NewDisp);
505 X86Operand *ParseIntelOperator(unsigned OpKind);
506 X86Operand *ParseIntelSegmentOverride(unsigned SegReg, SMLoc Start, unsigned Size);
507 X86Operand *ParseIntelMemOperand(int64_t ImmDisp, SMLoc StartLoc,
509 bool ParseIntelExpression(IntelExprStateMachine &SM, SMLoc &End);
510 X86Operand *ParseIntelBracExpression(unsigned SegReg, SMLoc Start,
511 int64_t ImmDisp, unsigned Size);
512 bool ParseIntelIdentifier(const MCExpr *&Val, StringRef &Identifier,
513 InlineAsmIdentifierInfo &Info,
514 bool IsUnevaluatedOperand, SMLoc &End);
516 X86Operand *ParseMemOperand(unsigned SegReg, SMLoc StartLoc);
518 X86Operand *CreateMemForInlineAsm(unsigned SegReg, const MCExpr *Disp,
519 unsigned BaseReg, unsigned IndexReg,
520 unsigned Scale, SMLoc Start, SMLoc End,
521 unsigned Size, StringRef Identifier,
522 InlineAsmIdentifierInfo &Info);
524 bool ParseDirectiveWord(unsigned Size, SMLoc L);
525 bool ParseDirectiveCode(StringRef IDVal, SMLoc L);
527 bool processInstruction(MCInst &Inst,
528 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
530 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
531 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
532 MCStreamer &Out, unsigned &ErrorInfo,
533 bool MatchingInlineAsm);
535 /// isSrcOp - Returns true if operand is either (%rsi) or %ds:%(rsi)
536 /// in 64bit mode or (%esi) or %es:(%esi) in 32bit mode.
537 bool isSrcOp(X86Operand &Op);
539 /// isDstOp - Returns true if operand is either (%rdi) or %es:(%rdi)
540 /// in 64bit mode or (%edi) or %es:(%edi) in 32bit mode.
541 bool isDstOp(X86Operand &Op);
543 bool is64BitMode() const {
544 // FIXME: Can tablegen auto-generate this?
545 return (STI.getFeatureBits() & X86::Mode64Bit) != 0;
548 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(X86::Mode64Bit));
549 setAvailableFeatures(FB);
552 bool isParsingIntelSyntax() {
553 return getParser().getAssemblerDialect();
556 /// @name Auto-generated Matcher Functions
559 #define GET_ASSEMBLER_HEADER
560 #include "X86GenAsmMatcher.inc"
565 X86AsmParser(MCSubtargetInfo &sti, MCAsmParser &parser,
566 const MCInstrInfo &MII)
567 : MCTargetAsmParser(), STI(sti), Parser(parser), InstInfo(0) {
569 // Initialize the set of available features.
570 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
572 virtual bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
574 virtual bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
576 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
578 virtual bool ParseDirective(AsmToken DirectiveID);
580 } // end anonymous namespace
582 /// @name Auto-generated Match Functions
585 static unsigned MatchRegisterName(StringRef Name);
589 static bool isImmSExti16i8Value(uint64_t Value) {
590 return (( Value <= 0x000000000000007FULL)||
591 (0x000000000000FF80ULL <= Value && Value <= 0x000000000000FFFFULL)||
592 (0xFFFFFFFFFFFFFF80ULL <= Value && Value <= 0xFFFFFFFFFFFFFFFFULL));
595 static bool isImmSExti32i8Value(uint64_t Value) {
596 return (( Value <= 0x000000000000007FULL)||
597 (0x00000000FFFFFF80ULL <= Value && Value <= 0x00000000FFFFFFFFULL)||
598 (0xFFFFFFFFFFFFFF80ULL <= Value && Value <= 0xFFFFFFFFFFFFFFFFULL));
601 static bool isImmZExtu32u8Value(uint64_t Value) {
602 return (Value <= 0x00000000000000FFULL);
605 static bool isImmSExti64i8Value(uint64_t Value) {
606 return (( Value <= 0x000000000000007FULL)||
607 (0xFFFFFFFFFFFFFF80ULL <= Value && Value <= 0xFFFFFFFFFFFFFFFFULL));
610 static bool isImmSExti64i32Value(uint64_t Value) {
611 return (( Value <= 0x000000007FFFFFFFULL)||
612 (0xFFFFFFFF80000000ULL <= Value && Value <= 0xFFFFFFFFFFFFFFFFULL));
616 /// X86Operand - Instances of this class represent a parsed X86 machine
618 struct X86Operand : public MCParsedAsmOperand {
626 SMLoc StartLoc, EndLoc;
661 X86Operand(KindTy K, SMLoc Start, SMLoc End)
662 : Kind(K), StartLoc(Start), EndLoc(End) {}
664 StringRef getSymName() { return SymName; }
665 void *getOpDecl() { return OpDecl; }
667 /// getStartLoc - Get the location of the first token of this operand.
668 SMLoc getStartLoc() const { return StartLoc; }
669 /// getEndLoc - Get the location of the last token of this operand.
670 SMLoc getEndLoc() const { return EndLoc; }
671 /// getLocRange - Get the range between the first and last token of this
673 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
674 /// getOffsetOfLoc - Get the location of the offset operator.
675 SMLoc getOffsetOfLoc() const { return OffsetOfLoc; }
677 virtual void print(raw_ostream &OS) const {}
679 StringRef getToken() const {
680 assert(Kind == Token && "Invalid access!");
681 return StringRef(Tok.Data, Tok.Length);
683 void setTokenValue(StringRef Value) {
684 assert(Kind == Token && "Invalid access!");
685 Tok.Data = Value.data();
686 Tok.Length = Value.size();
689 unsigned getReg() const {
690 assert(Kind == Register && "Invalid access!");
694 const MCExpr *getImm() const {
695 assert(Kind == Immediate && "Invalid access!");
699 const MCExpr *getMemDisp() const {
700 assert(Kind == Memory && "Invalid access!");
703 unsigned getMemSegReg() const {
704 assert(Kind == Memory && "Invalid access!");
707 unsigned getMemBaseReg() const {
708 assert(Kind == Memory && "Invalid access!");
711 unsigned getMemIndexReg() const {
712 assert(Kind == Memory && "Invalid access!");
715 unsigned getMemScale() const {
716 assert(Kind == Memory && "Invalid access!");
720 bool isToken() const {return Kind == Token; }
722 bool isImm() const { return Kind == Immediate; }
724 bool isImmSExti16i8() const {
728 // If this isn't a constant expr, just assume it fits and let relaxation
730 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
734 // Otherwise, check the value is in a range that makes sense for this
736 return isImmSExti16i8Value(CE->getValue());
738 bool isImmSExti32i8() const {
742 // If this isn't a constant expr, just assume it fits and let relaxation
744 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
748 // Otherwise, check the value is in a range that makes sense for this
750 return isImmSExti32i8Value(CE->getValue());
752 bool isImmZExtu32u8() const {
756 // If this isn't a constant expr, just assume it fits and let relaxation
758 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
762 // Otherwise, check the value is in a range that makes sense for this
764 return isImmZExtu32u8Value(CE->getValue());
766 bool isImmSExti64i8() const {
770 // If this isn't a constant expr, just assume it fits and let relaxation
772 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
776 // Otherwise, check the value is in a range that makes sense for this
778 return isImmSExti64i8Value(CE->getValue());
780 bool isImmSExti64i32() const {
784 // If this isn't a constant expr, just assume it fits and let relaxation
786 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
790 // Otherwise, check the value is in a range that makes sense for this
792 return isImmSExti64i32Value(CE->getValue());
795 bool isOffsetOf() const {
796 return OffsetOfLoc.getPointer();
799 bool needAddressOf() const {
803 bool isMem() const { return Kind == Memory; }
804 bool isMem8() const {
805 return Kind == Memory && (!Mem.Size || Mem.Size == 8);
807 bool isMem16() const {
808 return Kind == Memory && (!Mem.Size || Mem.Size == 16);
810 bool isMem32() const {
811 return Kind == Memory && (!Mem.Size || Mem.Size == 32);
813 bool isMem64() const {
814 return Kind == Memory && (!Mem.Size || Mem.Size == 64);
816 bool isMem80() const {
817 return Kind == Memory && (!Mem.Size || Mem.Size == 80);
819 bool isMem128() const {
820 return Kind == Memory && (!Mem.Size || Mem.Size == 128);
822 bool isMem256() const {
823 return Kind == Memory && (!Mem.Size || Mem.Size == 256);
825 bool isMem512() const {
826 return Kind == Memory && (!Mem.Size || Mem.Size == 512);
829 bool isMemVX32() const {
830 return Kind == Memory && (!Mem.Size || Mem.Size == 32) &&
831 getMemIndexReg() >= X86::XMM0 && getMemIndexReg() <= X86::XMM15;
833 bool isMemVY32() const {
834 return Kind == Memory && (!Mem.Size || Mem.Size == 32) &&
835 getMemIndexReg() >= X86::YMM0 && getMemIndexReg() <= X86::YMM15;
837 bool isMemVX64() const {
838 return Kind == Memory && (!Mem.Size || Mem.Size == 64) &&
839 getMemIndexReg() >= X86::XMM0 && getMemIndexReg() <= X86::XMM15;
841 bool isMemVY64() const {
842 return Kind == Memory && (!Mem.Size || Mem.Size == 64) &&
843 getMemIndexReg() >= X86::YMM0 && getMemIndexReg() <= X86::YMM15;
845 bool isMemVZ32() const {
846 return Kind == Memory && (!Mem.Size || Mem.Size == 32) &&
847 getMemIndexReg() >= X86::ZMM0 && getMemIndexReg() <= X86::ZMM31;
849 bool isMemVZ64() const {
850 return Kind == Memory && (!Mem.Size || Mem.Size == 64) &&
851 getMemIndexReg() >= X86::ZMM0 && getMemIndexReg() <= X86::ZMM31;
854 bool isAbsMem() const {
855 return Kind == Memory && !getMemSegReg() && !getMemBaseReg() &&
856 !getMemIndexReg() && getMemScale() == 1;
859 bool isMemOffs8() const {
860 return Kind == Memory && !getMemSegReg() && !getMemBaseReg() &&
861 !getMemIndexReg() && getMemScale() == 1 && (!Mem.Size || Mem.Size == 8);
863 bool isMemOffs16() const {
864 return Kind == Memory && !getMemSegReg() && !getMemBaseReg() &&
865 !getMemIndexReg() && getMemScale() == 1 && (!Mem.Size || Mem.Size == 16);
867 bool isMemOffs32() const {
868 return Kind == Memory && !getMemSegReg() && !getMemBaseReg() &&
869 !getMemIndexReg() && getMemScale() == 1 && (!Mem.Size || Mem.Size == 32);
871 bool isMemOffs64() const {
872 return Kind == Memory && !getMemSegReg() && !getMemBaseReg() &&
873 !getMemIndexReg() && getMemScale() == 1 && (!Mem.Size || Mem.Size == 64);
876 bool isReg() const { return Kind == Register; }
878 bool isGR32orGR64() const {
879 return Kind == Register &&
880 (X86MCRegisterClasses[X86::GR32RegClassID].contains(getReg()) ||
881 X86MCRegisterClasses[X86::GR64RegClassID].contains(getReg()));
884 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
885 // Add as immediates when possible.
886 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
887 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
889 Inst.addOperand(MCOperand::CreateExpr(Expr));
892 void addRegOperands(MCInst &Inst, unsigned N) const {
893 assert(N == 1 && "Invalid number of operands!");
894 Inst.addOperand(MCOperand::CreateReg(getReg()));
897 static unsigned getGR32FromGR64(unsigned RegNo) {
899 default: llvm_unreachable("Unexpected register");
900 case X86::RAX: return X86::EAX;
901 case X86::RCX: return X86::ECX;
902 case X86::RDX: return X86::EDX;
903 case X86::RBX: return X86::EBX;
904 case X86::RBP: return X86::EBP;
905 case X86::RSP: return X86::ESP;
906 case X86::RSI: return X86::ESI;
907 case X86::RDI: return X86::EDI;
908 case X86::R8: return X86::R8D;
909 case X86::R9: return X86::R9D;
910 case X86::R10: return X86::R10D;
911 case X86::R11: return X86::R11D;
912 case X86::R12: return X86::R12D;
913 case X86::R13: return X86::R13D;
914 case X86::R14: return X86::R14D;
915 case X86::R15: return X86::R15D;
916 case X86::RIP: return X86::EIP;
920 void addGR32orGR64Operands(MCInst &Inst, unsigned N) const {
921 assert(N == 1 && "Invalid number of operands!");
922 unsigned RegNo = getReg();
923 if (X86MCRegisterClasses[X86::GR64RegClassID].contains(RegNo))
924 RegNo = getGR32FromGR64(RegNo);
925 Inst.addOperand(MCOperand::CreateReg(RegNo));
928 void addImmOperands(MCInst &Inst, unsigned N) const {
929 assert(N == 1 && "Invalid number of operands!");
930 addExpr(Inst, getImm());
933 void addMemOperands(MCInst &Inst, unsigned N) const {
934 assert((N == 5) && "Invalid number of operands!");
935 Inst.addOperand(MCOperand::CreateReg(getMemBaseReg()));
936 Inst.addOperand(MCOperand::CreateImm(getMemScale()));
937 Inst.addOperand(MCOperand::CreateReg(getMemIndexReg()));
938 addExpr(Inst, getMemDisp());
939 Inst.addOperand(MCOperand::CreateReg(getMemSegReg()));
942 void addAbsMemOperands(MCInst &Inst, unsigned N) const {
943 assert((N == 1) && "Invalid number of operands!");
944 // Add as immediates when possible.
945 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getMemDisp()))
946 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
948 Inst.addOperand(MCOperand::CreateExpr(getMemDisp()));
951 void addMemOffsOperands(MCInst &Inst, unsigned N) const {
952 assert((N == 1) && "Invalid number of operands!");
953 // Add as immediates when possible.
954 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getMemDisp()))
955 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
957 Inst.addOperand(MCOperand::CreateExpr(getMemDisp()));
960 static X86Operand *CreateToken(StringRef Str, SMLoc Loc) {
961 SMLoc EndLoc = SMLoc::getFromPointer(Loc.getPointer() + Str.size());
962 X86Operand *Res = new X86Operand(Token, Loc, EndLoc);
963 Res->Tok.Data = Str.data();
964 Res->Tok.Length = Str.size();
968 static X86Operand *CreateReg(unsigned RegNo, SMLoc StartLoc, SMLoc EndLoc,
969 bool AddressOf = false,
970 SMLoc OffsetOfLoc = SMLoc(),
971 StringRef SymName = StringRef(),
973 X86Operand *Res = new X86Operand(Register, StartLoc, EndLoc);
974 Res->Reg.RegNo = RegNo;
975 Res->AddressOf = AddressOf;
976 Res->OffsetOfLoc = OffsetOfLoc;
977 Res->SymName = SymName;
978 Res->OpDecl = OpDecl;
982 static X86Operand *CreateImm(const MCExpr *Val, SMLoc StartLoc, SMLoc EndLoc){
983 X86Operand *Res = new X86Operand(Immediate, StartLoc, EndLoc);
988 /// Create an absolute memory operand.
989 static X86Operand *CreateMem(const MCExpr *Disp, SMLoc StartLoc, SMLoc EndLoc,
990 unsigned Size = 0, StringRef SymName = StringRef(),
992 X86Operand *Res = new X86Operand(Memory, StartLoc, EndLoc);
994 Res->Mem.Disp = Disp;
995 Res->Mem.BaseReg = 0;
996 Res->Mem.IndexReg = 0;
998 Res->Mem.Size = Size;
999 Res->SymName = SymName;
1000 Res->OpDecl = OpDecl;
1001 Res->AddressOf = false;
1005 /// Create a generalized memory operand.
1006 static X86Operand *CreateMem(unsigned SegReg, const MCExpr *Disp,
1007 unsigned BaseReg, unsigned IndexReg,
1008 unsigned Scale, SMLoc StartLoc, SMLoc EndLoc,
1010 StringRef SymName = StringRef(),
1012 // We should never just have a displacement, that should be parsed as an
1013 // absolute memory operand.
1014 assert((SegReg || BaseReg || IndexReg) && "Invalid memory operand!");
1016 // The scale should always be one of {1,2,4,8}.
1017 assert(((Scale == 1 || Scale == 2 || Scale == 4 || Scale == 8)) &&
1019 X86Operand *Res = new X86Operand(Memory, StartLoc, EndLoc);
1020 Res->Mem.SegReg = SegReg;
1021 Res->Mem.Disp = Disp;
1022 Res->Mem.BaseReg = BaseReg;
1023 Res->Mem.IndexReg = IndexReg;
1024 Res->Mem.Scale = Scale;
1025 Res->Mem.Size = Size;
1026 Res->SymName = SymName;
1027 Res->OpDecl = OpDecl;
1028 Res->AddressOf = false;
1033 } // end anonymous namespace.
1035 bool X86AsmParser::isSrcOp(X86Operand &Op) {
1036 unsigned basereg = is64BitMode() ? X86::RSI : X86::ESI;
1038 return (Op.isMem() &&
1039 (Op.Mem.SegReg == 0 || Op.Mem.SegReg == X86::DS) &&
1040 isa<MCConstantExpr>(Op.Mem.Disp) &&
1041 cast<MCConstantExpr>(Op.Mem.Disp)->getValue() == 0 &&
1042 Op.Mem.BaseReg == basereg && Op.Mem.IndexReg == 0);
1045 bool X86AsmParser::isDstOp(X86Operand &Op) {
1046 unsigned basereg = is64BitMode() ? X86::RDI : X86::EDI;
1048 return Op.isMem() &&
1049 (Op.Mem.SegReg == 0 || Op.Mem.SegReg == X86::ES) &&
1050 isa<MCConstantExpr>(Op.Mem.Disp) &&
1051 cast<MCConstantExpr>(Op.Mem.Disp)->getValue() == 0 &&
1052 Op.Mem.BaseReg == basereg && Op.Mem.IndexReg == 0;
1055 bool X86AsmParser::ParseRegister(unsigned &RegNo,
1056 SMLoc &StartLoc, SMLoc &EndLoc) {
1058 const AsmToken &PercentTok = Parser.getTok();
1059 StartLoc = PercentTok.getLoc();
1061 // If we encounter a %, ignore it. This code handles registers with and
1062 // without the prefix, unprefixed registers can occur in cfi directives.
1063 if (!isParsingIntelSyntax() && PercentTok.is(AsmToken::Percent))
1064 Parser.Lex(); // Eat percent token.
1066 const AsmToken &Tok = Parser.getTok();
1067 EndLoc = Tok.getEndLoc();
1069 if (Tok.isNot(AsmToken::Identifier)) {
1070 if (isParsingIntelSyntax()) return true;
1071 return Error(StartLoc, "invalid register name",
1072 SMRange(StartLoc, EndLoc));
1075 RegNo = MatchRegisterName(Tok.getString());
1077 // If the match failed, try the register name as lowercase.
1079 RegNo = MatchRegisterName(Tok.getString().lower());
1081 if (!is64BitMode()) {
1082 // FIXME: This should be done using Requires<In32BitMode> and
1083 // Requires<In64BitMode> so "eiz" usage in 64-bit instructions can be also
1085 // FIXME: Check AH, CH, DH, BH cannot be used in an instruction requiring a
1087 if (RegNo == X86::RIZ ||
1088 X86MCRegisterClasses[X86::GR64RegClassID].contains(RegNo) ||
1089 X86II::isX86_64NonExtLowByteReg(RegNo) ||
1090 X86II::isX86_64ExtendedReg(RegNo))
1091 return Error(StartLoc, "register %"
1092 + Tok.getString() + " is only available in 64-bit mode",
1093 SMRange(StartLoc, EndLoc));
1096 // Parse "%st" as "%st(0)" and "%st(1)", which is multiple tokens.
1097 if (RegNo == 0 && (Tok.getString() == "st" || Tok.getString() == "ST")) {
1099 Parser.Lex(); // Eat 'st'
1101 // Check to see if we have '(4)' after %st.
1102 if (getLexer().isNot(AsmToken::LParen))
1107 const AsmToken &IntTok = Parser.getTok();
1108 if (IntTok.isNot(AsmToken::Integer))
1109 return Error(IntTok.getLoc(), "expected stack index");
1110 switch (IntTok.getIntVal()) {
1111 case 0: RegNo = X86::ST0; break;
1112 case 1: RegNo = X86::ST1; break;
1113 case 2: RegNo = X86::ST2; break;
1114 case 3: RegNo = X86::ST3; break;
1115 case 4: RegNo = X86::ST4; break;
1116 case 5: RegNo = X86::ST5; break;
1117 case 6: RegNo = X86::ST6; break;
1118 case 7: RegNo = X86::ST7; break;
1119 default: return Error(IntTok.getLoc(), "invalid stack index");
1122 if (getParser().Lex().isNot(AsmToken::RParen))
1123 return Error(Parser.getTok().getLoc(), "expected ')'");
1125 EndLoc = Parser.getTok().getEndLoc();
1126 Parser.Lex(); // Eat ')'
1130 EndLoc = Parser.getTok().getEndLoc();
1132 // If this is "db[0-7]", match it as an alias
1134 if (RegNo == 0 && Tok.getString().size() == 3 &&
1135 Tok.getString().startswith("db")) {
1136 switch (Tok.getString()[2]) {
1137 case '0': RegNo = X86::DR0; break;
1138 case '1': RegNo = X86::DR1; break;
1139 case '2': RegNo = X86::DR2; break;
1140 case '3': RegNo = X86::DR3; break;
1141 case '4': RegNo = X86::DR4; break;
1142 case '5': RegNo = X86::DR5; break;
1143 case '6': RegNo = X86::DR6; break;
1144 case '7': RegNo = X86::DR7; break;
1148 EndLoc = Parser.getTok().getEndLoc();
1149 Parser.Lex(); // Eat it.
1155 if (isParsingIntelSyntax()) return true;
1156 return Error(StartLoc, "invalid register name",
1157 SMRange(StartLoc, EndLoc));
1160 Parser.Lex(); // Eat identifier token.
1164 X86Operand *X86AsmParser::ParseOperand() {
1165 if (isParsingIntelSyntax())
1166 return ParseIntelOperand();
1167 return ParseATTOperand();
1170 /// getIntelMemOperandSize - Return intel memory operand size.
1171 static unsigned getIntelMemOperandSize(StringRef OpStr) {
1172 unsigned Size = StringSwitch<unsigned>(OpStr)
1173 .Cases("BYTE", "byte", 8)
1174 .Cases("WORD", "word", 16)
1175 .Cases("DWORD", "dword", 32)
1176 .Cases("QWORD", "qword", 64)
1177 .Cases("XWORD", "xword", 80)
1178 .Cases("XMMWORD", "xmmword", 128)
1179 .Cases("YMMWORD", "ymmword", 256)
1185 X86AsmParser::CreateMemForInlineAsm(unsigned SegReg, const MCExpr *Disp,
1186 unsigned BaseReg, unsigned IndexReg,
1187 unsigned Scale, SMLoc Start, SMLoc End,
1188 unsigned Size, StringRef Identifier,
1189 InlineAsmIdentifierInfo &Info){
1190 if (isa<MCSymbolRefExpr>(Disp)) {
1191 // If this is not a VarDecl then assume it is a FuncDecl or some other label
1192 // reference. We need an 'r' constraint here, so we need to create register
1193 // operand to ensure proper matching. Just pick a GPR based on the size of
1195 if (!Info.IsVarDecl) {
1196 unsigned RegNo = is64BitMode() ? X86::RBX : X86::EBX;
1197 return X86Operand::CreateReg(RegNo, Start, End, /*AddressOf=*/true,
1198 SMLoc(), Identifier, Info.OpDecl);
1201 Size = Info.Type * 8; // Size is in terms of bits in this context.
1203 InstInfo->AsmRewrites->push_back(AsmRewrite(AOK_SizeDirective, Start,
1208 // When parsing inline assembly we set the base register to a non-zero value
1209 // if we don't know the actual value at this time. This is necessary to
1210 // get the matching correct in some cases.
1211 BaseReg = BaseReg ? BaseReg : 1;
1212 return X86Operand::CreateMem(SegReg, Disp, BaseReg, IndexReg, Scale, Start,
1213 End, Size, Identifier, Info.OpDecl);
1217 RewriteIntelBracExpression(SmallVectorImpl<AsmRewrite> *AsmRewrites,
1218 StringRef SymName, int64_t ImmDisp,
1219 int64_t FinalImmDisp, SMLoc &BracLoc,
1220 SMLoc &StartInBrac, SMLoc &End) {
1221 // Remove the '[' and ']' from the IR string.
1222 AsmRewrites->push_back(AsmRewrite(AOK_Skip, BracLoc, 1));
1223 AsmRewrites->push_back(AsmRewrite(AOK_Skip, End, 1));
1225 // If ImmDisp is non-zero, then we parsed a displacement before the
1226 // bracketed expression (i.e., ImmDisp [ BaseReg + Scale*IndexReg + Disp])
1227 // If ImmDisp doesn't match the displacement computed by the state machine
1228 // then we have an additional displacement in the bracketed expression.
1229 if (ImmDisp != FinalImmDisp) {
1231 // We have an immediate displacement before the bracketed expression.
1232 // Adjust this to match the final immediate displacement.
1234 for (SmallVectorImpl<AsmRewrite>::iterator I = AsmRewrites->begin(),
1235 E = AsmRewrites->end(); I != E; ++I) {
1236 if ((*I).Loc.getPointer() > BracLoc.getPointer())
1238 if ((*I).Kind == AOK_ImmPrefix || (*I).Kind == AOK_Imm) {
1239 assert (!Found && "ImmDisp already rewritten.");
1240 (*I).Kind = AOK_Imm;
1241 (*I).Len = BracLoc.getPointer() - (*I).Loc.getPointer();
1242 (*I).Val = FinalImmDisp;
1247 assert (Found && "Unable to rewrite ImmDisp.");
1250 // We have a symbolic and an immediate displacement, but no displacement
1251 // before the bracketed expression. Put the immediate displacement
1252 // before the bracketed expression.
1253 AsmRewrites->push_back(AsmRewrite(AOK_Imm, BracLoc, 0, FinalImmDisp));
1256 // Remove all the ImmPrefix rewrites within the brackets.
1257 for (SmallVectorImpl<AsmRewrite>::iterator I = AsmRewrites->begin(),
1258 E = AsmRewrites->end(); I != E; ++I) {
1259 if ((*I).Loc.getPointer() < StartInBrac.getPointer())
1261 if ((*I).Kind == AOK_ImmPrefix)
1262 (*I).Kind = AOK_Delete;
1264 const char *SymLocPtr = SymName.data();
1265 // Skip everything before the symbol.
1266 if (unsigned Len = SymLocPtr - StartInBrac.getPointer()) {
1267 assert(Len > 0 && "Expected a non-negative length.");
1268 AsmRewrites->push_back(AsmRewrite(AOK_Skip, StartInBrac, Len));
1270 // Skip everything after the symbol.
1271 if (unsigned Len = End.getPointer() - (SymLocPtr + SymName.size())) {
1272 SMLoc Loc = SMLoc::getFromPointer(SymLocPtr + SymName.size());
1273 assert(Len > 0 && "Expected a non-negative length.");
1274 AsmRewrites->push_back(AsmRewrite(AOK_Skip, Loc, Len));
1278 bool X86AsmParser::ParseIntelExpression(IntelExprStateMachine &SM, SMLoc &End) {
1279 const AsmToken &Tok = Parser.getTok();
1283 bool UpdateLocLex = true;
1285 // The period in the dot operator (e.g., [ebx].foo.bar) is parsed as an
1286 // identifier. Don't try an parse it as a register.
1287 if (Tok.getString().startswith("."))
1290 // If we're parsing an immediate expression, we don't expect a '['.
1291 if (SM.getStopOnLBrac() && getLexer().getKind() == AsmToken::LBrac)
1294 switch (getLexer().getKind()) {
1296 if (SM.isValidEndState()) {
1300 return Error(Tok.getLoc(), "unknown token in expression");
1302 case AsmToken::EndOfStatement: {
1306 case AsmToken::Identifier: {
1307 // This could be a register or a symbolic displacement.
1310 SMLoc IdentLoc = Tok.getLoc();
1311 StringRef Identifier = Tok.getString();
1312 if(!ParseRegister(TmpReg, IdentLoc, End)) {
1313 SM.onRegister(TmpReg);
1314 UpdateLocLex = false;
1317 if (!isParsingInlineAsm()) {
1318 if (getParser().parsePrimaryExpr(Val, End))
1319 return Error(Tok.getLoc(), "Unexpected identifier!");
1321 InlineAsmIdentifierInfo &Info = SM.getIdentifierInfo();
1322 if (ParseIntelIdentifier(Val, Identifier, Info,
1323 /*Unevaluated=*/false, End))
1326 SM.onIdentifierExpr(Val, Identifier);
1327 UpdateLocLex = false;
1330 return Error(Tok.getLoc(), "Unexpected identifier!");
1332 case AsmToken::Integer: {
1333 if (isParsingInlineAsm() && SM.getAddImmPrefix())
1334 InstInfo->AsmRewrites->push_back(AsmRewrite(AOK_ImmPrefix,
1336 // Look for 'b' or 'f' following an Integer as a directional label
1337 SMLoc Loc = getTok().getLoc();
1338 int64_t IntVal = getTok().getIntVal();
1339 End = consumeToken();
1340 UpdateLocLex = false;
1341 if (getLexer().getKind() == AsmToken::Identifier) {
1342 StringRef IDVal = getTok().getString();
1343 if (IDVal == "f" || IDVal == "b") {
1345 getContext().GetDirectionalLocalSymbol(IntVal,
1346 IDVal == "f" ? 1 : 0);
1347 MCSymbolRefExpr::VariantKind Variant = MCSymbolRefExpr::VK_None;
1349 MCSymbolRefExpr::Create(Sym, Variant, getContext());
1350 if (IDVal == "b" && Sym->isUndefined())
1351 return Error(Loc, "invalid reference to undefined symbol");
1352 StringRef Identifier = Sym->getName();
1353 SM.onIdentifierExpr(Val, Identifier);
1354 End = consumeToken();
1356 SM.onInteger(IntVal);
1359 SM.onInteger(IntVal);
1363 case AsmToken::Plus: SM.onPlus(); break;
1364 case AsmToken::Minus: SM.onMinus(); break;
1365 case AsmToken::Star: SM.onStar(); break;
1366 case AsmToken::Slash: SM.onDivide(); break;
1367 case AsmToken::LBrac: SM.onLBrac(); break;
1368 case AsmToken::RBrac: SM.onRBrac(); break;
1369 case AsmToken::LParen: SM.onLParen(); break;
1370 case AsmToken::RParen: SM.onRParen(); break;
1373 return Error(Tok.getLoc(), "unknown token in expression");
1375 if (!Done && UpdateLocLex)
1376 End = consumeToken();
1381 X86Operand *X86AsmParser::ParseIntelBracExpression(unsigned SegReg, SMLoc Start,
1384 const AsmToken &Tok = Parser.getTok();
1385 SMLoc BracLoc = Tok.getLoc(), End = Tok.getEndLoc();
1386 if (getLexer().isNot(AsmToken::LBrac))
1387 return ErrorOperand(BracLoc, "Expected '[' token!");
1388 Parser.Lex(); // Eat '['
1390 SMLoc StartInBrac = Tok.getLoc();
1391 // Parse [ Symbol + ImmDisp ] and [ BaseReg + Scale*IndexReg + ImmDisp ]. We
1392 // may have already parsed an immediate displacement before the bracketed
1394 IntelExprStateMachine SM(ImmDisp, /*StopOnLBrac=*/false, /*AddImmPrefix=*/true);
1395 if (ParseIntelExpression(SM, End))
1399 if (const MCExpr *Sym = SM.getSym()) {
1400 // A symbolic displacement.
1402 if (isParsingInlineAsm())
1403 RewriteIntelBracExpression(InstInfo->AsmRewrites, SM.getSymName(),
1404 ImmDisp, SM.getImm(), BracLoc, StartInBrac,
1407 // An immediate displacement only.
1408 Disp = MCConstantExpr::Create(SM.getImm(), getContext());
1411 // Parse the dot operator (e.g., [ebx].foo.bar).
1412 if (Tok.getString().startswith(".")) {
1413 const MCExpr *NewDisp;
1414 if (ParseIntelDotOperator(Disp, NewDisp))
1417 End = Tok.getEndLoc();
1418 Parser.Lex(); // Eat the field.
1422 int BaseReg = SM.getBaseReg();
1423 int IndexReg = SM.getIndexReg();
1424 int Scale = SM.getScale();
1425 if (!isParsingInlineAsm()) {
1427 if (!BaseReg && !IndexReg) {
1429 return X86Operand::CreateMem(Disp, Start, End, Size);
1431 return X86Operand::CreateMem(SegReg, Disp, 0, 0, 1, Start, End, Size);
1433 return X86Operand::CreateMem(SegReg, Disp, BaseReg, IndexReg, Scale, Start,
1437 InlineAsmIdentifierInfo &Info = SM.getIdentifierInfo();
1438 return CreateMemForInlineAsm(SegReg, Disp, BaseReg, IndexReg, Scale, Start,
1439 End, Size, SM.getSymName(), Info);
1442 // Inline assembly may use variable names with namespace alias qualifiers.
1443 bool X86AsmParser::ParseIntelIdentifier(const MCExpr *&Val,
1444 StringRef &Identifier,
1445 InlineAsmIdentifierInfo &Info,
1446 bool IsUnevaluatedOperand, SMLoc &End) {
1447 assert (isParsingInlineAsm() && "Expected to be parsing inline assembly.");
1450 StringRef LineBuf(Identifier.data());
1451 SemaCallback->LookupInlineAsmIdentifier(LineBuf, Info, IsUnevaluatedOperand);
1453 const AsmToken &Tok = Parser.getTok();
1455 // Advance the token stream until the end of the current token is
1456 // after the end of what the frontend claimed.
1457 const char *EndPtr = Tok.getLoc().getPointer() + LineBuf.size();
1459 End = Tok.getEndLoc();
1462 assert(End.getPointer() <= EndPtr && "frontend claimed part of a token?");
1463 if (End.getPointer() == EndPtr) break;
1466 // Create the symbol reference.
1467 Identifier = LineBuf;
1468 MCSymbol *Sym = getContext().GetOrCreateSymbol(Identifier);
1469 MCSymbolRefExpr::VariantKind Variant = MCSymbolRefExpr::VK_None;
1470 Val = MCSymbolRefExpr::Create(Sym, Variant, getParser().getContext());
1474 /// \brief Parse intel style segment override.
1475 X86Operand *X86AsmParser::ParseIntelSegmentOverride(unsigned SegReg,
1478 assert(SegReg != 0 && "Tried to parse a segment override without a segment!");
1479 const AsmToken &Tok = Parser.getTok(); // Eat colon.
1480 if (Tok.isNot(AsmToken::Colon))
1481 return ErrorOperand(Tok.getLoc(), "Expected ':' token!");
1482 Parser.Lex(); // Eat ':'
1484 int64_t ImmDisp = 0;
1485 if (getLexer().is(AsmToken::Integer)) {
1486 ImmDisp = Tok.getIntVal();
1487 AsmToken ImmDispToken = Parser.Lex(); // Eat the integer.
1489 if (isParsingInlineAsm())
1490 InstInfo->AsmRewrites->push_back(
1491 AsmRewrite(AOK_ImmPrefix, ImmDispToken.getLoc()));
1493 if (getLexer().isNot(AsmToken::LBrac)) {
1494 // An immediate following a 'segment register', 'colon' token sequence can
1495 // be followed by a bracketed expression. If it isn't we know we have our
1496 // final segment override.
1497 const MCExpr *Disp = MCConstantExpr::Create(ImmDisp, getContext());
1498 return X86Operand::CreateMem(SegReg, Disp, /*BaseReg=*/0, /*IndexReg=*/0,
1499 /*Scale=*/1, Start, ImmDispToken.getEndLoc(),
1504 if (getLexer().is(AsmToken::LBrac))
1505 return ParseIntelBracExpression(SegReg, Start, ImmDisp, Size);
1509 if (!isParsingInlineAsm()) {
1510 if (getParser().parsePrimaryExpr(Val, End))
1511 return ErrorOperand(Tok.getLoc(), "unknown token in expression");
1513 return X86Operand::CreateMem(Val, Start, End, Size);
1516 InlineAsmIdentifierInfo Info;
1517 StringRef Identifier = Tok.getString();
1518 if (ParseIntelIdentifier(Val, Identifier, Info,
1519 /*Unevaluated=*/false, End))
1521 return CreateMemForInlineAsm(/*SegReg=*/0, Val, /*BaseReg=*/0,/*IndexReg=*/0,
1522 /*Scale=*/1, Start, End, Size, Identifier, Info);
1525 /// ParseIntelMemOperand - Parse intel style memory operand.
1526 X86Operand *X86AsmParser::ParseIntelMemOperand(int64_t ImmDisp, SMLoc Start,
1528 const AsmToken &Tok = Parser.getTok();
1531 // Parse ImmDisp [ BaseReg + Scale*IndexReg + Disp ].
1532 if (getLexer().is(AsmToken::LBrac))
1533 return ParseIntelBracExpression(/*SegReg=*/0, Start, ImmDisp, Size);
1536 if (!isParsingInlineAsm()) {
1537 if (getParser().parsePrimaryExpr(Val, End))
1538 return ErrorOperand(Tok.getLoc(), "unknown token in expression");
1540 return X86Operand::CreateMem(Val, Start, End, Size);
1543 InlineAsmIdentifierInfo Info;
1544 StringRef Identifier = Tok.getString();
1545 if (ParseIntelIdentifier(Val, Identifier, Info,
1546 /*Unevaluated=*/false, End))
1548 return CreateMemForInlineAsm(/*SegReg=*/0, Val, /*BaseReg=*/0, /*IndexReg=*/0,
1549 /*Scale=*/1, Start, End, Size, Identifier, Info);
1552 /// Parse the '.' operator.
1553 bool X86AsmParser::ParseIntelDotOperator(const MCExpr *Disp,
1554 const MCExpr *&NewDisp) {
1555 const AsmToken &Tok = Parser.getTok();
1556 int64_t OrigDispVal, DotDispVal;
1558 // FIXME: Handle non-constant expressions.
1559 if (const MCConstantExpr *OrigDisp = dyn_cast<MCConstantExpr>(Disp))
1560 OrigDispVal = OrigDisp->getValue();
1562 return Error(Tok.getLoc(), "Non-constant offsets are not supported!");
1565 StringRef DotDispStr = Tok.getString().drop_front(1);
1567 // .Imm gets lexed as a real.
1568 if (Tok.is(AsmToken::Real)) {
1570 DotDispStr.getAsInteger(10, DotDisp);
1571 DotDispVal = DotDisp.getZExtValue();
1572 } else if (isParsingInlineAsm() && Tok.is(AsmToken::Identifier)) {
1574 std::pair<StringRef, StringRef> BaseMember = DotDispStr.split('.');
1575 if (SemaCallback->LookupInlineAsmField(BaseMember.first, BaseMember.second,
1577 return Error(Tok.getLoc(), "Unable to lookup field reference!");
1578 DotDispVal = DotDisp;
1580 return Error(Tok.getLoc(), "Unexpected token type!");
1582 if (isParsingInlineAsm() && Tok.is(AsmToken::Identifier)) {
1583 SMLoc Loc = SMLoc::getFromPointer(DotDispStr.data());
1584 unsigned Len = DotDispStr.size();
1585 unsigned Val = OrigDispVal + DotDispVal;
1586 InstInfo->AsmRewrites->push_back(AsmRewrite(AOK_DotOperator, Loc, Len,
1590 NewDisp = MCConstantExpr::Create(OrigDispVal + DotDispVal, getContext());
1594 /// Parse the 'offset' operator. This operator is used to specify the
1595 /// location rather then the content of a variable.
1596 X86Operand *X86AsmParser::ParseIntelOffsetOfOperator() {
1597 const AsmToken &Tok = Parser.getTok();
1598 SMLoc OffsetOfLoc = Tok.getLoc();
1599 Parser.Lex(); // Eat offset.
1602 InlineAsmIdentifierInfo Info;
1603 SMLoc Start = Tok.getLoc(), End;
1604 StringRef Identifier = Tok.getString();
1605 if (ParseIntelIdentifier(Val, Identifier, Info,
1606 /*Unevaluated=*/false, End))
1609 // Don't emit the offset operator.
1610 InstInfo->AsmRewrites->push_back(AsmRewrite(AOK_Skip, OffsetOfLoc, 7));
1612 // The offset operator will have an 'r' constraint, thus we need to create
1613 // register operand to ensure proper matching. Just pick a GPR based on
1614 // the size of a pointer.
1615 unsigned RegNo = is64BitMode() ? X86::RBX : X86::EBX;
1616 return X86Operand::CreateReg(RegNo, Start, End, /*GetAddress=*/true,
1617 OffsetOfLoc, Identifier, Info.OpDecl);
1620 enum IntelOperatorKind {
1626 /// Parse the 'LENGTH', 'TYPE' and 'SIZE' operators. The LENGTH operator
1627 /// returns the number of elements in an array. It returns the value 1 for
1628 /// non-array variables. The SIZE operator returns the size of a C or C++
1629 /// variable. A variable's size is the product of its LENGTH and TYPE. The
1630 /// TYPE operator returns the size of a C or C++ type or variable. If the
1631 /// variable is an array, TYPE returns the size of a single element.
1632 X86Operand *X86AsmParser::ParseIntelOperator(unsigned OpKind) {
1633 const AsmToken &Tok = Parser.getTok();
1634 SMLoc TypeLoc = Tok.getLoc();
1635 Parser.Lex(); // Eat operator.
1637 const MCExpr *Val = 0;
1638 InlineAsmIdentifierInfo Info;
1639 SMLoc Start = Tok.getLoc(), End;
1640 StringRef Identifier = Tok.getString();
1641 if (ParseIntelIdentifier(Val, Identifier, Info,
1642 /*Unevaluated=*/true, End))
1646 return ErrorOperand(Start, "unable to lookup expression");
1650 default: llvm_unreachable("Unexpected operand kind!");
1651 case IOK_LENGTH: CVal = Info.Length; break;
1652 case IOK_SIZE: CVal = Info.Size; break;
1653 case IOK_TYPE: CVal = Info.Type; break;
1656 // Rewrite the type operator and the C or C++ type or variable in terms of an
1657 // immediate. E.g. TYPE foo -> $$4
1658 unsigned Len = End.getPointer() - TypeLoc.getPointer();
1659 InstInfo->AsmRewrites->push_back(AsmRewrite(AOK_Imm, TypeLoc, Len, CVal));
1661 const MCExpr *Imm = MCConstantExpr::Create(CVal, getContext());
1662 return X86Operand::CreateImm(Imm, Start, End);
1665 X86Operand *X86AsmParser::ParseIntelOperand() {
1666 const AsmToken &Tok = Parser.getTok();
1669 // Offset, length, type and size operators.
1670 if (isParsingInlineAsm()) {
1671 StringRef AsmTokStr = Tok.getString();
1672 if (AsmTokStr == "offset" || AsmTokStr == "OFFSET")
1673 return ParseIntelOffsetOfOperator();
1674 if (AsmTokStr == "length" || AsmTokStr == "LENGTH")
1675 return ParseIntelOperator(IOK_LENGTH);
1676 if (AsmTokStr == "size" || AsmTokStr == "SIZE")
1677 return ParseIntelOperator(IOK_SIZE);
1678 if (AsmTokStr == "type" || AsmTokStr == "TYPE")
1679 return ParseIntelOperator(IOK_TYPE);
1682 unsigned Size = getIntelMemOperandSize(Tok.getString());
1684 Parser.Lex(); // Eat operand size (e.g., byte, word).
1685 if (Tok.getString() != "PTR" && Tok.getString() != "ptr")
1686 return ErrorOperand(Start, "Expected 'PTR' or 'ptr' token!");
1687 Parser.Lex(); // Eat ptr.
1689 Start = Tok.getLoc();
1692 if (getLexer().is(AsmToken::Integer) || getLexer().is(AsmToken::Minus) ||
1693 getLexer().is(AsmToken::LParen)) {
1694 AsmToken StartTok = Tok;
1695 IntelExprStateMachine SM(/*Imm=*/0, /*StopOnLBrac=*/true,
1696 /*AddImmPrefix=*/false);
1697 if (ParseIntelExpression(SM, End))
1700 int64_t Imm = SM.getImm();
1701 if (isParsingInlineAsm()) {
1702 unsigned Len = Tok.getLoc().getPointer() - Start.getPointer();
1703 if (StartTok.getString().size() == Len)
1704 // Just add a prefix if this wasn't a complex immediate expression.
1705 InstInfo->AsmRewrites->push_back(AsmRewrite(AOK_ImmPrefix, Start));
1707 // Otherwise, rewrite the complex expression as a single immediate.
1708 InstInfo->AsmRewrites->push_back(AsmRewrite(AOK_Imm, Start, Len, Imm));
1711 if (getLexer().isNot(AsmToken::LBrac)) {
1712 // If a directional label (ie. 1f or 2b) was parsed above from
1713 // ParseIntelExpression() then SM.getSym() was set to a pointer to
1714 // to the MCExpr with the directional local symbol and this is a
1715 // memory operand not an immediate operand.
1717 return X86Operand::CreateMem(SM.getSym(), Start, End, Size);
1719 const MCExpr *ImmExpr = MCConstantExpr::Create(Imm, getContext());
1720 return X86Operand::CreateImm(ImmExpr, Start, End);
1723 // Only positive immediates are valid.
1725 return ErrorOperand(Start, "expected a positive immediate displacement "
1726 "before bracketed expr.");
1728 // Parse ImmDisp [ BaseReg + Scale*IndexReg + Disp ].
1729 return ParseIntelMemOperand(Imm, Start, Size);
1734 if (!ParseRegister(RegNo, Start, End)) {
1735 // If this is a segment register followed by a ':', then this is the start
1736 // of a segment override, otherwise this is a normal register reference.
1737 if (getLexer().isNot(AsmToken::Colon))
1738 return X86Operand::CreateReg(RegNo, Start, End);
1740 return ParseIntelSegmentOverride(/*SegReg=*/RegNo, Start, Size);
1744 return ParseIntelMemOperand(/*Disp=*/0, Start, Size);
1747 X86Operand *X86AsmParser::ParseATTOperand() {
1748 switch (getLexer().getKind()) {
1750 // Parse a memory operand with no segment register.
1751 return ParseMemOperand(0, Parser.getTok().getLoc());
1752 case AsmToken::Percent: {
1753 // Read the register.
1756 if (ParseRegister(RegNo, Start, End)) return 0;
1757 if (RegNo == X86::EIZ || RegNo == X86::RIZ) {
1758 Error(Start, "%eiz and %riz can only be used as index registers",
1759 SMRange(Start, End));
1763 // If this is a segment register followed by a ':', then this is the start
1764 // of a memory reference, otherwise this is a normal register reference.
1765 if (getLexer().isNot(AsmToken::Colon))
1766 return X86Operand::CreateReg(RegNo, Start, End);
1768 getParser().Lex(); // Eat the colon.
1769 return ParseMemOperand(RegNo, Start);
1771 case AsmToken::Dollar: {
1772 // $42 -> immediate.
1773 SMLoc Start = Parser.getTok().getLoc(), End;
1776 if (getParser().parseExpression(Val, End))
1778 return X86Operand::CreateImm(Val, Start, End);
1783 /// ParseMemOperand: segment: disp(basereg, indexreg, scale). The '%ds:' prefix
1784 /// has already been parsed if present.
1785 X86Operand *X86AsmParser::ParseMemOperand(unsigned SegReg, SMLoc MemStart) {
1787 // We have to disambiguate a parenthesized expression "(4+5)" from the start
1788 // of a memory operand with a missing displacement "(%ebx)" or "(,%eax)". The
1789 // only way to do this without lookahead is to eat the '(' and see what is
1791 const MCExpr *Disp = MCConstantExpr::Create(0, getParser().getContext());
1792 if (getLexer().isNot(AsmToken::LParen)) {
1794 if (getParser().parseExpression(Disp, ExprEnd)) return 0;
1796 // After parsing the base expression we could either have a parenthesized
1797 // memory address or not. If not, return now. If so, eat the (.
1798 if (getLexer().isNot(AsmToken::LParen)) {
1799 // Unless we have a segment register, treat this as an immediate.
1801 return X86Operand::CreateMem(Disp, MemStart, ExprEnd);
1802 return X86Operand::CreateMem(SegReg, Disp, 0, 0, 1, MemStart, ExprEnd);
1808 // Okay, we have a '('. We don't know if this is an expression or not, but
1809 // so we have to eat the ( to see beyond it.
1810 SMLoc LParenLoc = Parser.getTok().getLoc();
1811 Parser.Lex(); // Eat the '('.
1813 if (getLexer().is(AsmToken::Percent) || getLexer().is(AsmToken::Comma)) {
1814 // Nothing to do here, fall into the code below with the '(' part of the
1815 // memory operand consumed.
1819 // It must be an parenthesized expression, parse it now.
1820 if (getParser().parseParenExpression(Disp, ExprEnd))
1823 // After parsing the base expression we could either have a parenthesized
1824 // memory address or not. If not, return now. If so, eat the (.
1825 if (getLexer().isNot(AsmToken::LParen)) {
1826 // Unless we have a segment register, treat this as an immediate.
1828 return X86Operand::CreateMem(Disp, LParenLoc, ExprEnd);
1829 return X86Operand::CreateMem(SegReg, Disp, 0, 0, 1, MemStart, ExprEnd);
1837 // If we reached here, then we just ate the ( of the memory operand. Process
1838 // the rest of the memory operand.
1839 unsigned BaseReg = 0, IndexReg = 0, Scale = 1;
1842 if (getLexer().is(AsmToken::Percent)) {
1843 SMLoc StartLoc, EndLoc;
1844 if (ParseRegister(BaseReg, StartLoc, EndLoc)) return 0;
1845 if (BaseReg == X86::EIZ || BaseReg == X86::RIZ) {
1846 Error(StartLoc, "eiz and riz can only be used as index registers",
1847 SMRange(StartLoc, EndLoc));
1852 if (getLexer().is(AsmToken::Comma)) {
1853 Parser.Lex(); // Eat the comma.
1854 IndexLoc = Parser.getTok().getLoc();
1856 // Following the comma we should have either an index register, or a scale
1857 // value. We don't support the later form, but we want to parse it
1860 // Not that even though it would be completely consistent to support syntax
1861 // like "1(%eax,,1)", the assembler doesn't. Use "eiz" or "riz" for this.
1862 if (getLexer().is(AsmToken::Percent)) {
1864 if (ParseRegister(IndexReg, L, L)) return 0;
1866 if (getLexer().isNot(AsmToken::RParen)) {
1867 // Parse the scale amount:
1868 // ::= ',' [scale-expression]
1869 if (getLexer().isNot(AsmToken::Comma)) {
1870 Error(Parser.getTok().getLoc(),
1871 "expected comma in scale expression");
1874 Parser.Lex(); // Eat the comma.
1876 if (getLexer().isNot(AsmToken::RParen)) {
1877 SMLoc Loc = Parser.getTok().getLoc();
1880 if (getParser().parseAbsoluteExpression(ScaleVal)){
1881 Error(Loc, "expected scale expression");
1885 // Validate the scale amount.
1886 if (ScaleVal != 1 && ScaleVal != 2 && ScaleVal != 4 && ScaleVal != 8){
1887 Error(Loc, "scale factor in address must be 1, 2, 4 or 8");
1890 Scale = (unsigned)ScaleVal;
1893 } else if (getLexer().isNot(AsmToken::RParen)) {
1894 // A scale amount without an index is ignored.
1896 SMLoc Loc = Parser.getTok().getLoc();
1899 if (getParser().parseAbsoluteExpression(Value))
1903 Warning(Loc, "scale factor without index register is ignored");
1908 // Ok, we've eaten the memory operand, verify we have a ')' and eat it too.
1909 if (getLexer().isNot(AsmToken::RParen)) {
1910 Error(Parser.getTok().getLoc(), "unexpected token in memory operand");
1913 SMLoc MemEnd = Parser.getTok().getEndLoc();
1914 Parser.Lex(); // Eat the ')'.
1916 // If we have both a base register and an index register make sure they are
1917 // both 64-bit or 32-bit registers.
1918 // To support VSIB, IndexReg can be 128-bit or 256-bit registers.
1919 if (BaseReg != 0 && IndexReg != 0) {
1920 if (X86MCRegisterClasses[X86::GR64RegClassID].contains(BaseReg) &&
1921 (X86MCRegisterClasses[X86::GR16RegClassID].contains(IndexReg) ||
1922 X86MCRegisterClasses[X86::GR32RegClassID].contains(IndexReg)) &&
1923 IndexReg != X86::RIZ) {
1924 Error(IndexLoc, "index register is 32-bit, but base register is 64-bit");
1927 if (X86MCRegisterClasses[X86::GR32RegClassID].contains(BaseReg) &&
1928 (X86MCRegisterClasses[X86::GR16RegClassID].contains(IndexReg) ||
1929 X86MCRegisterClasses[X86::GR64RegClassID].contains(IndexReg)) &&
1930 IndexReg != X86::EIZ){
1931 Error(IndexLoc, "index register is 64-bit, but base register is 32-bit");
1936 return X86Operand::CreateMem(SegReg, Disp, BaseReg, IndexReg, Scale,
1941 ParseInstruction(ParseInstructionInfo &Info, StringRef Name, SMLoc NameLoc,
1942 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
1944 StringRef PatchedName = Name;
1946 // FIXME: Hack to recognize setneb as setne.
1947 if (PatchedName.startswith("set") && PatchedName.endswith("b") &&
1948 PatchedName != "setb" && PatchedName != "setnb")
1949 PatchedName = PatchedName.substr(0, Name.size()-1);
1951 // FIXME: Hack to recognize cmp<comparison code>{ss,sd,ps,pd}.
1952 const MCExpr *ExtraImmOp = 0;
1953 if ((PatchedName.startswith("cmp") || PatchedName.startswith("vcmp")) &&
1954 (PatchedName.endswith("ss") || PatchedName.endswith("sd") ||
1955 PatchedName.endswith("ps") || PatchedName.endswith("pd"))) {
1956 bool IsVCMP = PatchedName[0] == 'v';
1957 unsigned SSECCIdx = IsVCMP ? 4 : 3;
1958 unsigned SSEComparisonCode = StringSwitch<unsigned>(
1959 PatchedName.slice(SSECCIdx, PatchedName.size() - 2))
1963 .Case("unord", 0x03)
1968 /* AVX only from here */
1969 .Case("eq_uq", 0x08)
1972 .Case("false", 0x0B)
1973 .Case("neq_oq", 0x0C)
1977 .Case("eq_os", 0x10)
1978 .Case("lt_oq", 0x11)
1979 .Case("le_oq", 0x12)
1980 .Case("unord_s", 0x13)
1981 .Case("neq_us", 0x14)
1982 .Case("nlt_uq", 0x15)
1983 .Case("nle_uq", 0x16)
1984 .Case("ord_s", 0x17)
1985 .Case("eq_us", 0x18)
1986 .Case("nge_uq", 0x19)
1987 .Case("ngt_uq", 0x1A)
1988 .Case("false_os", 0x1B)
1989 .Case("neq_os", 0x1C)
1990 .Case("ge_oq", 0x1D)
1991 .Case("gt_oq", 0x1E)
1992 .Case("true_us", 0x1F)
1994 if (SSEComparisonCode != ~0U && (IsVCMP || SSEComparisonCode < 8)) {
1995 ExtraImmOp = MCConstantExpr::Create(SSEComparisonCode,
1996 getParser().getContext());
1997 if (PatchedName.endswith("ss")) {
1998 PatchedName = IsVCMP ? "vcmpss" : "cmpss";
1999 } else if (PatchedName.endswith("sd")) {
2000 PatchedName = IsVCMP ? "vcmpsd" : "cmpsd";
2001 } else if (PatchedName.endswith("ps")) {
2002 PatchedName = IsVCMP ? "vcmpps" : "cmpps";
2004 assert(PatchedName.endswith("pd") && "Unexpected mnemonic!");
2005 PatchedName = IsVCMP ? "vcmppd" : "cmppd";
2010 Operands.push_back(X86Operand::CreateToken(PatchedName, NameLoc));
2012 if (ExtraImmOp && !isParsingIntelSyntax())
2013 Operands.push_back(X86Operand::CreateImm(ExtraImmOp, NameLoc, NameLoc));
2015 // Determine whether this is an instruction prefix.
2017 Name == "lock" || Name == "rep" ||
2018 Name == "repe" || Name == "repz" ||
2019 Name == "repne" || Name == "repnz" ||
2020 Name == "rex64" || Name == "data16";
2023 // This does the actual operand parsing. Don't parse any more if we have a
2024 // prefix juxtaposed with an operation like "lock incl 4(%rax)", because we
2025 // just want to parse the "lock" as the first instruction and the "incl" as
2027 if (getLexer().isNot(AsmToken::EndOfStatement) && !isPrefix) {
2029 // Parse '*' modifier.
2030 if (getLexer().is(AsmToken::Star))
2031 Operands.push_back(X86Operand::CreateToken("*", consumeToken()));
2033 // Read the first operand.
2034 if (X86Operand *Op = ParseOperand())
2035 Operands.push_back(Op);
2037 Parser.eatToEndOfStatement();
2041 while (getLexer().is(AsmToken::Comma)) {
2042 Parser.Lex(); // Eat the comma.
2044 // Parse and remember the operand.
2045 if (X86Operand *Op = ParseOperand())
2046 Operands.push_back(Op);
2048 Parser.eatToEndOfStatement();
2053 if (STI.getFeatureBits() & X86::FeatureAVX512) {
2054 // Parse mask register {%k1}
2055 if (getLexer().is(AsmToken::LCurly)) {
2056 Operands.push_back(X86Operand::CreateToken("{", consumeToken()));
2057 if (X86Operand *Op = ParseOperand()) {
2058 Operands.push_back(Op);
2059 if (!getLexer().is(AsmToken::RCurly)) {
2060 SMLoc Loc = getLexer().getLoc();
2061 Parser.eatToEndOfStatement();
2062 return Error(Loc, "Expected } at this point");
2064 Operands.push_back(X86Operand::CreateToken("}", consumeToken()));
2066 Parser.eatToEndOfStatement();
2070 // Parse "zeroing non-masked" semantic {z}
2071 if (getLexer().is(AsmToken::LCurly)) {
2072 Operands.push_back(X86Operand::CreateToken("{z}", consumeToken()));
2073 if (!getLexer().is(AsmToken::Identifier) || getLexer().getTok().getIdentifier() != "z") {
2074 SMLoc Loc = getLexer().getLoc();
2075 Parser.eatToEndOfStatement();
2076 return Error(Loc, "Expected z at this point");
2078 Parser.Lex(); // Eat the z
2079 if (!getLexer().is(AsmToken::RCurly)) {
2080 SMLoc Loc = getLexer().getLoc();
2081 Parser.eatToEndOfStatement();
2082 return Error(Loc, "Expected } at this point");
2084 Parser.Lex(); // Eat the }
2088 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2089 SMLoc Loc = getLexer().getLoc();
2090 Parser.eatToEndOfStatement();
2091 return Error(Loc, "unexpected token in argument list");
2095 if (getLexer().is(AsmToken::EndOfStatement))
2096 Parser.Lex(); // Consume the EndOfStatement
2097 else if (isPrefix && getLexer().is(AsmToken::Slash))
2098 Parser.Lex(); // Consume the prefix separator Slash
2100 if (ExtraImmOp && isParsingIntelSyntax())
2101 Operands.push_back(X86Operand::CreateImm(ExtraImmOp, NameLoc, NameLoc));
2103 // This is a terrible hack to handle "out[bwl]? %al, (%dx)" ->
2104 // "outb %al, %dx". Out doesn't take a memory form, but this is a widely
2105 // documented form in various unofficial manuals, so a lot of code uses it.
2106 if ((Name == "outb" || Name == "outw" || Name == "outl" || Name == "out") &&
2107 Operands.size() == 3) {
2108 X86Operand &Op = *(X86Operand*)Operands.back();
2109 if (Op.isMem() && Op.Mem.SegReg == 0 &&
2110 isa<MCConstantExpr>(Op.Mem.Disp) &&
2111 cast<MCConstantExpr>(Op.Mem.Disp)->getValue() == 0 &&
2112 Op.Mem.BaseReg == MatchRegisterName("dx") && Op.Mem.IndexReg == 0) {
2113 SMLoc Loc = Op.getEndLoc();
2114 Operands.back() = X86Operand::CreateReg(Op.Mem.BaseReg, Loc, Loc);
2118 // Same hack for "in[bwl]? (%dx), %al" -> "inb %dx, %al".
2119 if ((Name == "inb" || Name == "inw" || Name == "inl" || Name == "in") &&
2120 Operands.size() == 3) {
2121 X86Operand &Op = *(X86Operand*)Operands.begin()[1];
2122 if (Op.isMem() && Op.Mem.SegReg == 0 &&
2123 isa<MCConstantExpr>(Op.Mem.Disp) &&
2124 cast<MCConstantExpr>(Op.Mem.Disp)->getValue() == 0 &&
2125 Op.Mem.BaseReg == MatchRegisterName("dx") && Op.Mem.IndexReg == 0) {
2126 SMLoc Loc = Op.getEndLoc();
2127 Operands.begin()[1] = X86Operand::CreateReg(Op.Mem.BaseReg, Loc, Loc);
2131 // Transform "ins[bwl] %dx, %es:(%edi)" into "ins[bwl]"
2132 if (Name.startswith("ins") && Operands.size() == 3 &&
2133 (Name == "insb" || Name == "insw" || Name == "insl")) {
2134 X86Operand &Op = *(X86Operand*)Operands.begin()[1];
2135 X86Operand &Op2 = *(X86Operand*)Operands.begin()[2];
2136 if (Op.isReg() && Op.getReg() == X86::DX && isDstOp(Op2)) {
2137 Operands.pop_back();
2138 Operands.pop_back();
2144 // Transform "outs[bwl] %ds:(%esi), %dx" into "out[bwl]"
2145 if (Name.startswith("outs") && Operands.size() == 3 &&
2146 (Name == "outsb" || Name == "outsw" || Name == "outsl")) {
2147 X86Operand &Op = *(X86Operand*)Operands.begin()[1];
2148 X86Operand &Op2 = *(X86Operand*)Operands.begin()[2];
2149 if (isSrcOp(Op) && Op2.isReg() && Op2.getReg() == X86::DX) {
2150 Operands.pop_back();
2151 Operands.pop_back();
2157 // Transform "movs[bwl] %ds:(%esi), %es:(%edi)" into "movs[bwl]"
2158 if (Name.startswith("movs") && Operands.size() == 3 &&
2159 (Name == "movsb" || Name == "movsw" || Name == "movsl" ||
2160 (is64BitMode() && Name == "movsq"))) {
2161 X86Operand &Op = *(X86Operand*)Operands.begin()[1];
2162 X86Operand &Op2 = *(X86Operand*)Operands.begin()[2];
2163 if (isSrcOp(Op) && isDstOp(Op2)) {
2164 Operands.pop_back();
2165 Operands.pop_back();
2170 // Transform "lods[bwl] %ds:(%esi),{%al,%ax,%eax,%rax}" into "lods[bwl]"
2171 if (Name.startswith("lods") && Operands.size() == 3 &&
2172 (Name == "lods" || Name == "lodsb" || Name == "lodsw" ||
2173 Name == "lodsl" || (is64BitMode() && Name == "lodsq"))) {
2174 X86Operand *Op1 = static_cast<X86Operand*>(Operands[1]);
2175 X86Operand *Op2 = static_cast<X86Operand*>(Operands[2]);
2176 if (isSrcOp(*Op1) && Op2->isReg()) {
2178 unsigned reg = Op2->getReg();
2179 bool isLods = Name == "lods";
2180 if (reg == X86::AL && (isLods || Name == "lodsb"))
2182 else if (reg == X86::AX && (isLods || Name == "lodsw"))
2184 else if (reg == X86::EAX && (isLods || Name == "lodsl"))
2186 else if (reg == X86::RAX && (isLods || Name == "lodsq"))
2191 Operands.pop_back();
2192 Operands.pop_back();
2196 static_cast<X86Operand*>(Operands[0])->setTokenValue(ins);
2200 // Transform "stos[bwl] {%al,%ax,%eax,%rax},%es:(%edi)" into "stos[bwl]"
2201 if (Name.startswith("stos") && Operands.size() == 3 &&
2202 (Name == "stos" || Name == "stosb" || Name == "stosw" ||
2203 Name == "stosl" || (is64BitMode() && Name == "stosq"))) {
2204 X86Operand *Op1 = static_cast<X86Operand*>(Operands[1]);
2205 X86Operand *Op2 = static_cast<X86Operand*>(Operands[2]);
2206 if (isDstOp(*Op2) && Op1->isReg()) {
2208 unsigned reg = Op1->getReg();
2209 bool isStos = Name == "stos";
2210 if (reg == X86::AL && (isStos || Name == "stosb"))
2212 else if (reg == X86::AX && (isStos || Name == "stosw"))
2214 else if (reg == X86::EAX && (isStos || Name == "stosl"))
2216 else if (reg == X86::RAX && (isStos || Name == "stosq"))
2221 Operands.pop_back();
2222 Operands.pop_back();
2226 static_cast<X86Operand*>(Operands[0])->setTokenValue(ins);
2231 // FIXME: Hack to handle recognize s{hr,ar,hl} $1, <op>. Canonicalize to
2233 if ((Name.startswith("shr") || Name.startswith("sar") ||
2234 Name.startswith("shl") || Name.startswith("sal") ||
2235 Name.startswith("rcl") || Name.startswith("rcr") ||
2236 Name.startswith("rol") || Name.startswith("ror")) &&
2237 Operands.size() == 3) {
2238 if (isParsingIntelSyntax()) {
2240 X86Operand *Op1 = static_cast<X86Operand*>(Operands[2]);
2241 if (Op1->isImm() && isa<MCConstantExpr>(Op1->getImm()) &&
2242 cast<MCConstantExpr>(Op1->getImm())->getValue() == 1) {
2244 Operands.pop_back();
2247 X86Operand *Op1 = static_cast<X86Operand*>(Operands[1]);
2248 if (Op1->isImm() && isa<MCConstantExpr>(Op1->getImm()) &&
2249 cast<MCConstantExpr>(Op1->getImm())->getValue() == 1) {
2251 Operands.erase(Operands.begin() + 1);
2256 // Transforms "int $3" into "int3" as a size optimization. We can't write an
2257 // instalias with an immediate operand yet.
2258 if (Name == "int" && Operands.size() == 2) {
2259 X86Operand *Op1 = static_cast<X86Operand*>(Operands[1]);
2260 if (Op1->isImm() && isa<MCConstantExpr>(Op1->getImm()) &&
2261 cast<MCConstantExpr>(Op1->getImm())->getValue() == 3) {
2263 Operands.erase(Operands.begin() + 1);
2264 static_cast<X86Operand*>(Operands[0])->setTokenValue("int3");
2271 static bool convertToSExti8(MCInst &Inst, unsigned Opcode, unsigned Reg,
2274 TmpInst.setOpcode(Opcode);
2276 TmpInst.addOperand(MCOperand::CreateReg(Reg));
2277 TmpInst.addOperand(MCOperand::CreateReg(Reg));
2278 TmpInst.addOperand(Inst.getOperand(0));
2283 static bool convert16i16to16ri8(MCInst &Inst, unsigned Opcode,
2284 bool isCmp = false) {
2285 if (!Inst.getOperand(0).isImm() ||
2286 !isImmSExti16i8Value(Inst.getOperand(0).getImm()))
2289 return convertToSExti8(Inst, Opcode, X86::AX, isCmp);
2292 static bool convert32i32to32ri8(MCInst &Inst, unsigned Opcode,
2293 bool isCmp = false) {
2294 if (!Inst.getOperand(0).isImm() ||
2295 !isImmSExti32i8Value(Inst.getOperand(0).getImm()))
2298 return convertToSExti8(Inst, Opcode, X86::EAX, isCmp);
2301 static bool convert64i32to64ri8(MCInst &Inst, unsigned Opcode,
2302 bool isCmp = false) {
2303 if (!Inst.getOperand(0).isImm() ||
2304 !isImmSExti64i8Value(Inst.getOperand(0).getImm()))
2307 return convertToSExti8(Inst, Opcode, X86::RAX, isCmp);
2311 processInstruction(MCInst &Inst,
2312 const SmallVectorImpl<MCParsedAsmOperand*> &Ops) {
2313 switch (Inst.getOpcode()) {
2314 default: return false;
2315 case X86::AND16i16: return convert16i16to16ri8(Inst, X86::AND16ri8);
2316 case X86::AND32i32: return convert32i32to32ri8(Inst, X86::AND32ri8);
2317 case X86::AND64i32: return convert64i32to64ri8(Inst, X86::AND64ri8);
2318 case X86::XOR16i16: return convert16i16to16ri8(Inst, X86::XOR16ri8);
2319 case X86::XOR32i32: return convert32i32to32ri8(Inst, X86::XOR32ri8);
2320 case X86::XOR64i32: return convert64i32to64ri8(Inst, X86::XOR64ri8);
2321 case X86::OR16i16: return convert16i16to16ri8(Inst, X86::OR16ri8);
2322 case X86::OR32i32: return convert32i32to32ri8(Inst, X86::OR32ri8);
2323 case X86::OR64i32: return convert64i32to64ri8(Inst, X86::OR64ri8);
2324 case X86::CMP16i16: return convert16i16to16ri8(Inst, X86::CMP16ri8, true);
2325 case X86::CMP32i32: return convert32i32to32ri8(Inst, X86::CMP32ri8, true);
2326 case X86::CMP64i32: return convert64i32to64ri8(Inst, X86::CMP64ri8, true);
2327 case X86::ADD16i16: return convert16i16to16ri8(Inst, X86::ADD16ri8);
2328 case X86::ADD32i32: return convert32i32to32ri8(Inst, X86::ADD32ri8);
2329 case X86::ADD64i32: return convert64i32to64ri8(Inst, X86::ADD64ri8);
2330 case X86::SUB16i16: return convert16i16to16ri8(Inst, X86::SUB16ri8);
2331 case X86::SUB32i32: return convert32i32to32ri8(Inst, X86::SUB32ri8);
2332 case X86::SUB64i32: return convert64i32to64ri8(Inst, X86::SUB64ri8);
2333 case X86::ADC16i16: return convert16i16to16ri8(Inst, X86::ADC16ri8);
2334 case X86::ADC32i32: return convert32i32to32ri8(Inst, X86::ADC32ri8);
2335 case X86::ADC64i32: return convert64i32to64ri8(Inst, X86::ADC64ri8);
2336 case X86::SBB16i16: return convert16i16to16ri8(Inst, X86::SBB16ri8);
2337 case X86::SBB32i32: return convert32i32to32ri8(Inst, X86::SBB32ri8);
2338 case X86::SBB64i32: return convert64i32to64ri8(Inst, X86::SBB64ri8);
2339 case X86::VMOVAPDrr:
2340 case X86::VMOVAPDYrr:
2341 case X86::VMOVAPSrr:
2342 case X86::VMOVAPSYrr:
2343 case X86::VMOVDQArr:
2344 case X86::VMOVDQAYrr:
2345 case X86::VMOVDQUrr:
2346 case X86::VMOVDQUYrr:
2347 case X86::VMOVUPDrr:
2348 case X86::VMOVUPDYrr:
2349 case X86::VMOVUPSrr:
2350 case X86::VMOVUPSYrr: {
2351 if (X86II::isX86_64ExtendedReg(Inst.getOperand(0).getReg()) ||
2352 !X86II::isX86_64ExtendedReg(Inst.getOperand(1).getReg()))
2356 switch (Inst.getOpcode()) {
2357 default: llvm_unreachable("Invalid opcode");
2358 case X86::VMOVAPDrr: NewOpc = X86::VMOVAPDrr_REV; break;
2359 case X86::VMOVAPDYrr: NewOpc = X86::VMOVAPDYrr_REV; break;
2360 case X86::VMOVAPSrr: NewOpc = X86::VMOVAPSrr_REV; break;
2361 case X86::VMOVAPSYrr: NewOpc = X86::VMOVAPSYrr_REV; break;
2362 case X86::VMOVDQArr: NewOpc = X86::VMOVDQArr_REV; break;
2363 case X86::VMOVDQAYrr: NewOpc = X86::VMOVDQAYrr_REV; break;
2364 case X86::VMOVDQUrr: NewOpc = X86::VMOVDQUrr_REV; break;
2365 case X86::VMOVDQUYrr: NewOpc = X86::VMOVDQUYrr_REV; break;
2366 case X86::VMOVUPDrr: NewOpc = X86::VMOVUPDrr_REV; break;
2367 case X86::VMOVUPDYrr: NewOpc = X86::VMOVUPDYrr_REV; break;
2368 case X86::VMOVUPSrr: NewOpc = X86::VMOVUPSrr_REV; break;
2369 case X86::VMOVUPSYrr: NewOpc = X86::VMOVUPSYrr_REV; break;
2371 Inst.setOpcode(NewOpc);
2375 case X86::VMOVSSrr: {
2376 if (X86II::isX86_64ExtendedReg(Inst.getOperand(0).getReg()) ||
2377 !X86II::isX86_64ExtendedReg(Inst.getOperand(2).getReg()))
2380 switch (Inst.getOpcode()) {
2381 default: llvm_unreachable("Invalid opcode");
2382 case X86::VMOVSDrr: NewOpc = X86::VMOVSDrr_REV; break;
2383 case X86::VMOVSSrr: NewOpc = X86::VMOVSSrr_REV; break;
2385 Inst.setOpcode(NewOpc);
2391 static const char *getSubtargetFeatureName(unsigned Val);
2393 MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
2394 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
2395 MCStreamer &Out, unsigned &ErrorInfo,
2396 bool MatchingInlineAsm) {
2397 assert(!Operands.empty() && "Unexpect empty operand list!");
2398 X86Operand *Op = static_cast<X86Operand*>(Operands[0]);
2399 assert(Op->isToken() && "Leading operand should always be a mnemonic!");
2400 ArrayRef<SMRange> EmptyRanges = None;
2402 // First, handle aliases that expand to multiple instructions.
2403 // FIXME: This should be replaced with a real .td file alias mechanism.
2404 // Also, MatchInstructionImpl should actually *do* the EmitInstruction
2406 if (Op->getToken() == "fstsw" || Op->getToken() == "fstcw" ||
2407 Op->getToken() == "fstsww" || Op->getToken() == "fstcww" ||
2408 Op->getToken() == "finit" || Op->getToken() == "fsave" ||
2409 Op->getToken() == "fstenv" || Op->getToken() == "fclex") {
2411 Inst.setOpcode(X86::WAIT);
2413 if (!MatchingInlineAsm)
2414 Out.EmitInstruction(Inst);
2417 StringSwitch<const char*>(Op->getToken())
2418 .Case("finit", "fninit")
2419 .Case("fsave", "fnsave")
2420 .Case("fstcw", "fnstcw")
2421 .Case("fstcww", "fnstcw")
2422 .Case("fstenv", "fnstenv")
2423 .Case("fstsw", "fnstsw")
2424 .Case("fstsww", "fnstsw")
2425 .Case("fclex", "fnclex")
2427 assert(Repl && "Unknown wait-prefixed instruction");
2429 Operands[0] = X86Operand::CreateToken(Repl, IDLoc);
2432 bool WasOriginallyInvalidOperand = false;
2435 // First, try a direct match.
2436 switch (MatchInstructionImpl(Operands, Inst,
2437 ErrorInfo, MatchingInlineAsm,
2438 isParsingIntelSyntax())) {
2441 // Some instructions need post-processing to, for example, tweak which
2442 // encoding is selected. Loop on it while changes happen so the
2443 // individual transformations can chain off each other.
2444 if (!MatchingInlineAsm)
2445 while (processInstruction(Inst, Operands))
2449 if (!MatchingInlineAsm)
2450 Out.EmitInstruction(Inst);
2451 Opcode = Inst.getOpcode();
2453 case Match_MissingFeature: {
2454 assert(ErrorInfo && "Unknown missing feature!");
2455 // Special case the error message for the very common case where only
2456 // a single subtarget feature is missing.
2457 std::string Msg = "instruction requires:";
2459 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
2460 if (ErrorInfo & Mask) {
2462 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
2466 return Error(IDLoc, Msg, EmptyRanges, MatchingInlineAsm);
2468 case Match_InvalidOperand:
2469 WasOriginallyInvalidOperand = true;
2471 case Match_MnemonicFail:
2475 // FIXME: Ideally, we would only attempt suffix matches for things which are
2476 // valid prefixes, and we could just infer the right unambiguous
2477 // type. However, that requires substantially more matcher support than the
2480 // Change the operand to point to a temporary token.
2481 StringRef Base = Op->getToken();
2482 SmallString<16> Tmp;
2485 Op->setTokenValue(Tmp.str());
2487 // If this instruction starts with an 'f', then it is a floating point stack
2488 // instruction. These come in up to three forms for 32-bit, 64-bit, and
2489 // 80-bit floating point, which use the suffixes s,l,t respectively.
2491 // Otherwise, we assume that this may be an integer instruction, which comes
2492 // in 8/16/32/64-bit forms using the b,w,l,q suffixes respectively.
2493 const char *Suffixes = Base[0] != 'f' ? "bwlq" : "slt\0";
2495 // Check for the various suffix matches.
2496 Tmp[Base.size()] = Suffixes[0];
2497 unsigned ErrorInfoIgnore;
2498 unsigned ErrorInfoMissingFeature = 0; // Init suppresses compiler warnings.
2499 unsigned Match1, Match2, Match3, Match4;
2501 Match1 = MatchInstructionImpl(Operands, Inst, ErrorInfoIgnore,
2502 MatchingInlineAsm, isParsingIntelSyntax());
2503 // If this returned as a missing feature failure, remember that.
2504 if (Match1 == Match_MissingFeature)
2505 ErrorInfoMissingFeature = ErrorInfoIgnore;
2506 Tmp[Base.size()] = Suffixes[1];
2507 Match2 = MatchInstructionImpl(Operands, Inst, ErrorInfoIgnore,
2508 MatchingInlineAsm, isParsingIntelSyntax());
2509 // If this returned as a missing feature failure, remember that.
2510 if (Match2 == Match_MissingFeature)
2511 ErrorInfoMissingFeature = ErrorInfoIgnore;
2512 Tmp[Base.size()] = Suffixes[2];
2513 Match3 = MatchInstructionImpl(Operands, Inst, ErrorInfoIgnore,
2514 MatchingInlineAsm, isParsingIntelSyntax());
2515 // If this returned as a missing feature failure, remember that.
2516 if (Match3 == Match_MissingFeature)
2517 ErrorInfoMissingFeature = ErrorInfoIgnore;
2518 Tmp[Base.size()] = Suffixes[3];
2519 Match4 = MatchInstructionImpl(Operands, Inst, ErrorInfoIgnore,
2520 MatchingInlineAsm, isParsingIntelSyntax());
2521 // If this returned as a missing feature failure, remember that.
2522 if (Match4 == Match_MissingFeature)
2523 ErrorInfoMissingFeature = ErrorInfoIgnore;
2525 // Restore the old token.
2526 Op->setTokenValue(Base);
2528 // If exactly one matched, then we treat that as a successful match (and the
2529 // instruction will already have been filled in correctly, since the failing
2530 // matches won't have modified it).
2531 unsigned NumSuccessfulMatches =
2532 (Match1 == Match_Success) + (Match2 == Match_Success) +
2533 (Match3 == Match_Success) + (Match4 == Match_Success);
2534 if (NumSuccessfulMatches == 1) {
2536 if (!MatchingInlineAsm)
2537 Out.EmitInstruction(Inst);
2538 Opcode = Inst.getOpcode();
2542 // Otherwise, the match failed, try to produce a decent error message.
2544 // If we had multiple suffix matches, then identify this as an ambiguous
2546 if (NumSuccessfulMatches > 1) {
2548 unsigned NumMatches = 0;
2549 if (Match1 == Match_Success) MatchChars[NumMatches++] = Suffixes[0];
2550 if (Match2 == Match_Success) MatchChars[NumMatches++] = Suffixes[1];
2551 if (Match3 == Match_Success) MatchChars[NumMatches++] = Suffixes[2];
2552 if (Match4 == Match_Success) MatchChars[NumMatches++] = Suffixes[3];
2554 SmallString<126> Msg;
2555 raw_svector_ostream OS(Msg);
2556 OS << "ambiguous instructions require an explicit suffix (could be ";
2557 for (unsigned i = 0; i != NumMatches; ++i) {
2560 if (i + 1 == NumMatches)
2562 OS << "'" << Base << MatchChars[i] << "'";
2565 Error(IDLoc, OS.str(), EmptyRanges, MatchingInlineAsm);
2569 // Okay, we know that none of the variants matched successfully.
2571 // If all of the instructions reported an invalid mnemonic, then the original
2572 // mnemonic was invalid.
2573 if ((Match1 == Match_MnemonicFail) && (Match2 == Match_MnemonicFail) &&
2574 (Match3 == Match_MnemonicFail) && (Match4 == Match_MnemonicFail)) {
2575 if (!WasOriginallyInvalidOperand) {
2576 ArrayRef<SMRange> Ranges = MatchingInlineAsm ? EmptyRanges :
2578 return Error(IDLoc, "invalid instruction mnemonic '" + Base + "'",
2579 Ranges, MatchingInlineAsm);
2582 // Recover location info for the operand if we know which was the problem.
2583 if (ErrorInfo != ~0U) {
2584 if (ErrorInfo >= Operands.size())
2585 return Error(IDLoc, "too few operands for instruction",
2586 EmptyRanges, MatchingInlineAsm);
2588 X86Operand *Operand = (X86Operand*)Operands[ErrorInfo];
2589 if (Operand->getStartLoc().isValid()) {
2590 SMRange OperandRange = Operand->getLocRange();
2591 return Error(Operand->getStartLoc(), "invalid operand for instruction",
2592 OperandRange, MatchingInlineAsm);
2596 return Error(IDLoc, "invalid operand for instruction", EmptyRanges,
2600 // If one instruction matched with a missing feature, report this as a
2602 if ((Match1 == Match_MissingFeature) + (Match2 == Match_MissingFeature) +
2603 (Match3 == Match_MissingFeature) + (Match4 == Match_MissingFeature) == 1){
2604 std::string Msg = "instruction requires:";
2606 for (unsigned i = 0; i < (sizeof(ErrorInfoMissingFeature)*8-1); ++i) {
2607 if (ErrorInfoMissingFeature & Mask) {
2609 Msg += getSubtargetFeatureName(ErrorInfoMissingFeature & Mask);
2613 return Error(IDLoc, Msg, EmptyRanges, MatchingInlineAsm);
2616 // If one instruction matched with an invalid operand, report this as an
2618 if ((Match1 == Match_InvalidOperand) + (Match2 == Match_InvalidOperand) +
2619 (Match3 == Match_InvalidOperand) + (Match4 == Match_InvalidOperand) == 1){
2620 Error(IDLoc, "invalid operand for instruction", EmptyRanges,
2625 // If all of these were an outright failure, report it in a useless way.
2626 Error(IDLoc, "unknown use of instruction mnemonic without a size suffix",
2627 EmptyRanges, MatchingInlineAsm);
2632 bool X86AsmParser::ParseDirective(AsmToken DirectiveID) {
2633 StringRef IDVal = DirectiveID.getIdentifier();
2634 if (IDVal == ".word")
2635 return ParseDirectiveWord(2, DirectiveID.getLoc());
2636 else if (IDVal.startswith(".code"))
2637 return ParseDirectiveCode(IDVal, DirectiveID.getLoc());
2638 else if (IDVal.startswith(".att_syntax")) {
2639 getParser().setAssemblerDialect(0);
2641 } else if (IDVal.startswith(".intel_syntax")) {
2642 getParser().setAssemblerDialect(1);
2643 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2644 if(Parser.getTok().getString() == "noprefix") {
2645 // FIXME : Handle noprefix
2655 /// ParseDirectiveWord
2656 /// ::= .word [ expression (, expression)* ]
2657 bool X86AsmParser::ParseDirectiveWord(unsigned Size, SMLoc L) {
2658 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2660 const MCExpr *Value;
2661 if (getParser().parseExpression(Value))
2664 getParser().getStreamer().EmitValue(Value, Size);
2666 if (getLexer().is(AsmToken::EndOfStatement))
2669 // FIXME: Improve diagnostic.
2670 if (getLexer().isNot(AsmToken::Comma))
2671 return Error(L, "unexpected token in directive");
2680 /// ParseDirectiveCode
2681 /// ::= .code32 | .code64
2682 bool X86AsmParser::ParseDirectiveCode(StringRef IDVal, SMLoc L) {
2683 if (IDVal == ".code32") {
2685 if (is64BitMode()) {
2687 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
2689 } else if (IDVal == ".code64") {
2691 if (!is64BitMode()) {
2693 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code64);
2696 return Error(L, "unexpected directive " + IDVal);
2702 // Force static initialization.
2703 extern "C" void LLVMInitializeX86AsmParser() {
2704 RegisterMCAsmParser<X86AsmParser> X(TheX86_32Target);
2705 RegisterMCAsmParser<X86AsmParser> Y(TheX86_64Target);
2708 #define GET_REGISTER_MATCHER
2709 #define GET_MATCHER_IMPLEMENTATION
2710 #define GET_SUBTARGET_FEATURE_NAME
2711 #include "X86GenAsmMatcher.inc"