37 static const char OpPrecedence[] = {
53 enum InfixCalculatorTok {
64 class InfixCalculator {
65 typedef std::pair< InfixCalculatorTok, int64_t > ICToken;
70 int64_t popOperand() {
71 assert (!PostfixStack.empty() &&
"Poped an empty stack!");
73 assert ((Op.first == IC_IMM || Op.first == IC_REGISTER)
74 &&
"Expected and immediate or register!");
77 void pushOperand(InfixCalculatorTok Op, int64_t Val = 0) {
78 assert ((Op == IC_IMM || Op == IC_REGISTER) &&
79 "Unexpected operand!");
80 PostfixStack.push_back(std::make_pair(Op, Val));
83 void popOperator() { InfixOperatorStack.pop_back(); }
84 void pushOperator(InfixCalculatorTok Op) {
86 if (InfixOperatorStack.empty()) {
87 InfixOperatorStack.push_back(Op);
94 unsigned Idx = InfixOperatorStack.size() - 1;
95 InfixCalculatorTok StackOp = InfixOperatorStack[Idx];
96 if (OpPrecedence[Op] > OpPrecedence[StackOp] || StackOp == IC_LPAREN) {
97 InfixOperatorStack.push_back(Op);
103 unsigned ParenCount = 0;
106 if (InfixOperatorStack.empty())
109 Idx = InfixOperatorStack.size() - 1;
110 StackOp = InfixOperatorStack[Idx];
111 if (!(OpPrecedence[StackOp] >= OpPrecedence[Op] || ParenCount))
116 if (!ParenCount && StackOp == IC_LPAREN)
119 if (StackOp == IC_RPAREN) {
121 InfixOperatorStack.pop_back();
122 }
else if (StackOp == IC_LPAREN) {
124 InfixOperatorStack.pop_back();
126 InfixOperatorStack.pop_back();
127 PostfixStack.push_back(std::make_pair(StackOp, 0));
131 InfixOperatorStack.push_back(Op);
135 while (!InfixOperatorStack.empty()) {
136 InfixCalculatorTok StackOp = InfixOperatorStack.pop_back_val();
137 if (StackOp != IC_LPAREN && StackOp != IC_RPAREN)
138 PostfixStack.push_back(std::make_pair(StackOp, 0));
141 if (PostfixStack.empty())
145 for (
unsigned i = 0, e = PostfixStack.size(); i != e; ++i) {
146 ICToken Op = PostfixStack[i];
147 if (Op.first == IC_IMM || Op.first == IC_REGISTER) {
150 assert (OperandStack.
size() > 1 &&
"Too few operands.");
159 Val = Op1.second + Op2.second;
160 OperandStack.
push_back(std::make_pair(IC_IMM, Val));
163 Val = Op1.second - Op2.second;
164 OperandStack.
push_back(std::make_pair(IC_IMM, Val));
167 assert (Op1.first == IC_IMM && Op2.first == IC_IMM &&
168 "Multiply operation with an immediate and a register!");
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 "Divide operation with an immediate and a register!");
175 assert (Op2.second != 0 &&
"Division by zero!");
176 Val = Op1.second / Op2.second;
177 OperandStack.
push_back(std::make_pair(IC_IMM, Val));
182 assert (OperandStack.
size() == 1 &&
"Expected a single result.");
187 enum IntelExprState {
202 class IntelExprStateMachine {
203 IntelExprState State, PrevState;
204 unsigned BaseReg, IndexReg, TmpReg, Scale;
208 bool StopOnLBrac, AddImmPrefix;
212 IntelExprStateMachine(int64_t imm,
bool stoponlbrac,
bool addimmprefix) :
213 State(IES_PLUS), PrevState(IES_ERROR), BaseReg(0), IndexReg(0), TmpReg(0),
214 Scale(1), Imm(imm), Sym(0), StopOnLBrac(stoponlbrac),
215 AddImmPrefix(addimmprefix) { Info.clear(); }
217 unsigned getBaseReg() {
return BaseReg; }
218 unsigned getIndexReg() {
return IndexReg; }
219 unsigned getScale() {
return Scale; }
220 const MCExpr *getSym() {
return Sym; }
221 StringRef getSymName() {
return SymName; }
222 int64_t getImm() {
return Imm + IC.execute(); }
223 bool isValidEndState() {
224 return State == IES_RBRAC || State == IES_INTEGER;
226 bool getStopOnLBrac() {
return StopOnLBrac; }
227 bool getAddImmPrefix() {
return AddImmPrefix; }
228 bool hadError() {
return State == IES_ERROR; }
235 IntelExprState CurrState = State;
244 IC.pushOperator(IC_PLUS);
245 if (CurrState == IES_REGISTER && PrevState != IES_MULTIPLY) {
251 assert (!IndexReg &&
"BaseReg/IndexReg already set!");
258 PrevState = CurrState;
261 IntelExprState CurrState = State;
277 if (!(CurrState == IES_PLUS || CurrState == IES_MINUS ||
278 CurrState == IES_MULTIPLY || CurrState == IES_DIVIDE ||
279 CurrState == IES_LPAREN || CurrState == IES_LBRAC))
280 IC.pushOperator(IC_MINUS);
281 if (CurrState == IES_REGISTER && PrevState != IES_MULTIPLY) {
287 assert (!IndexReg &&
"BaseReg/IndexReg already set!");
294 PrevState = CurrState;
296 void onRegister(
unsigned Reg) {
297 IntelExprState CurrState = State;
304 State = IES_REGISTER;
306 IC.pushOperand(IC_REGISTER);
310 if (PrevState == IES_INTEGER) {
311 assert (!IndexReg &&
"IndexReg already set!");
312 State = IES_REGISTER;
315 Scale = IC.popOperand();
316 IC.pushOperand(IC_IMM);
323 PrevState = CurrState;
335 SymName = SymRefName;
336 IC.pushOperand(IC_IMM);
340 void onInteger(int64_t TmpInt) {
341 IntelExprState CurrState = State;
352 if (PrevState == IES_REGISTER && CurrState == IES_MULTIPLY) {
354 assert (!IndexReg &&
"IndexReg already set!");
359 }
else if ((PrevState == IES_PLUS || PrevState == IES_MINUS ||
360 PrevState == IES_MULTIPLY || PrevState == IES_DIVIDE ||
361 PrevState == IES_LPAREN || PrevState == IES_LBRAC) &&
362 CurrState == IES_MINUS) {
365 IC.pushOperand(IC_IMM, -TmpInt);
367 IC.pushOperand(IC_IMM, TmpInt);
371 PrevState = CurrState;
382 State = IES_MULTIPLY;
383 IC.pushOperator(IC_MULTIPLY);
396 IC.pushOperator(IC_DIVIDE);
408 IC.pushOperator(IC_PLUS);
413 IntelExprState CurrState = State;
422 if (CurrState == IES_REGISTER && PrevState != IES_MULTIPLY) {
428 assert (!IndexReg &&
"BaseReg/IndexReg already set!");
435 PrevState = CurrState;
438 IntelExprState CurrState = State;
449 if ((PrevState == IES_PLUS || PrevState == IES_MINUS ||
450 PrevState == IES_MULTIPLY || PrevState == IES_DIVIDE ||
451 PrevState == IES_LPAREN || PrevState == IES_LBRAC) &&
452 CurrState == IES_MINUS) {
457 IC.pushOperator(IC_LPAREN);
460 PrevState = CurrState;
472 IC.pushOperator(IC_RPAREN);
480 MCAsmLexer &getLexer()
const {
return Parser.getLexer(); }
484 bool MatchingInlineAsm =
false) {
485 if (MatchingInlineAsm)
return true;
486 return Parser.Error(L, Msg, Ranges);
494 X86Operand *ParseOperand();
495 X86Operand *ParseATTOperand();
496 X86Operand *ParseIntelOperand();
497 X86Operand *ParseIntelOffsetOfOperator();
498 X86Operand *ParseIntelDotOperator(
const MCExpr *Disp,
const MCExpr *&NewDisp);
499 X86Operand *ParseIntelOperator(
unsigned OpKind);
500 X86Operand *ParseIntelSegmentOverride(
unsigned SegReg,
SMLoc Start,
unsigned Size);
501 X86Operand *ParseIntelMemOperand(int64_t ImmDisp,
SMLoc StartLoc,
503 X86Operand *ParseIntelExpression(IntelExprStateMachine &SM,
SMLoc &End);
504 X86Operand *ParseIntelBracExpression(
unsigned SegReg,
SMLoc Start,
505 int64_t ImmDisp,
unsigned Size);
506 X86Operand *ParseIntelIdentifier(
const MCExpr *&Val,
StringRef &Identifier,
508 bool IsUnevaluatedOperand,
SMLoc &End);
510 X86Operand *ParseMemOperand(
unsigned SegReg,
SMLoc StartLoc);
512 X86Operand *CreateMemForInlineAsm(
unsigned SegReg,
const MCExpr *Disp,
513 unsigned BaseReg,
unsigned IndexReg,
518 bool ParseDirectiveWord(
unsigned Size,
SMLoc L);
521 bool processInstruction(
MCInst &Inst,
524 bool MatchAndEmitInstruction(
SMLoc IDLoc,
unsigned &Opcode,
527 bool MatchingInlineAsm);
531 bool isSrcOp(X86Operand &Op);
535 bool isDstOp(X86Operand &Op);
537 bool is64BitMode()
const {
539 return (STI.getFeatureBits() & X86::Mode64Bit) != 0;
542 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(X86::Mode64Bit));
543 setAvailableFeatures(FB);
546 bool isParsingIntelSyntax() {
547 return getParser().getAssemblerDialect();
553 #define GET_ASSEMBLER_HEADER
554 #include "X86GenAsmMatcher.inc"
564 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
566 virtual bool ParseRegister(
unsigned &RegNo,
SMLoc &StartLoc,
SMLoc &EndLoc);
572 virtual bool ParseDirective(
AsmToken DirectiveID);
584 return (( Value <= 0x000000000000007FULL)||
585 (0x000000000000FF80ULL <= Value && Value <= 0x000000000000FFFFULL)||
586 (0xFFFFFFFFFFFFFF80ULL <= Value && Value <= 0xFFFFFFFFFFFFFFFFULL));
590 return (( Value <= 0x000000000000007FULL)||
591 (0x00000000FFFFFF80ULL <= Value && Value <= 0x00000000FFFFFFFFULL)||
592 (0xFFFFFFFFFFFFFF80ULL <= Value && Value <= 0xFFFFFFFFFFFFFFFFULL));
596 return (Value <= 0x00000000000000FFULL);
600 return (( Value <= 0x000000000000007FULL)||
601 (0xFFFFFFFFFFFFFF80ULL <= Value && Value <= 0xFFFFFFFFFFFFFFFFULL));
605 return (( Value <= 0x000000007FFFFFFFULL)||
606 (0xFFFFFFFF80000000ULL <= Value && Value <= 0xFFFFFFFFFFFFFFFFULL));
620 SMLoc StartLoc, EndLoc;
656 :
Kind(K), StartLoc(Start), EndLoc(End) {}
658 StringRef getSymName() {
return SymName; }
659 void *getOpDecl() {
return OpDecl; }
662 SMLoc getStartLoc()
const {
return StartLoc; }
664 SMLoc getEndLoc()
const {
return EndLoc; }
669 SMLoc getOffsetOfLoc()
const {
return OffsetOfLoc; }
674 assert(
Kind == Token &&
"Invalid access!");
678 assert(
Kind == Token &&
"Invalid access!");
679 Tok.Data = Value.
data();
680 Tok.Length = Value.
size();
688 const MCExpr *getImm()
const {
689 assert(
Kind == Immediate &&
"Invalid access!");
693 const MCExpr *getMemDisp()
const {
697 unsigned getMemSegReg()
const {
701 unsigned getMemBaseReg()
const {
705 unsigned getMemIndexReg()
const {
709 unsigned getMemScale()
const {
714 bool isToken()
const {
return Kind == Token; }
716 bool isImm()
const {
return Kind == Immediate; }
718 bool isImmSExti16i8()
const {
732 bool isImmSExti32i8()
const {
746 bool isImmZExtu32u8()
const {
760 bool isImmSExti64i8()
const {
774 bool isImmSExti64i32()
const {
789 bool isOffsetOf()
const {
790 return OffsetOfLoc.getPointer();
793 bool needAddressOf()
const {
798 bool isMem8()
const {
799 return Kind ==
Memory && (!Mem.Size || Mem.Size == 8);
801 bool isMem16()
const {
802 return Kind ==
Memory && (!Mem.Size || Mem.Size == 16);
804 bool isMem32()
const {
805 return Kind ==
Memory && (!Mem.Size || Mem.Size == 32);
807 bool isMem64()
const {
808 return Kind ==
Memory && (!Mem.Size || Mem.Size == 64);
810 bool isMem80()
const {
811 return Kind ==
Memory && (!Mem.Size || Mem.Size == 80);
813 bool isMem128()
const {
814 return Kind ==
Memory && (!Mem.Size || Mem.Size == 128);
816 bool isMem256()
const {
817 return Kind ==
Memory && (!Mem.Size || Mem.Size == 256);
819 bool isMem512()
const {
820 return Kind ==
Memory && (!Mem.Size || Mem.Size == 512);
823 bool isMemVX32()
const {
824 return Kind ==
Memory && (!Mem.Size || Mem.Size == 32) &&
825 getMemIndexReg() >= X86::XMM0 && getMemIndexReg() <= X86::XMM15;
827 bool isMemVY32()
const {
828 return Kind ==
Memory && (!Mem.Size || Mem.Size == 32) &&
829 getMemIndexReg() >= X86::YMM0 && getMemIndexReg() <= X86::YMM15;
831 bool isMemVX64()
const {
832 return Kind ==
Memory && (!Mem.Size || Mem.Size == 64) &&
833 getMemIndexReg() >= X86::XMM0 && getMemIndexReg() <= X86::XMM15;
835 bool isMemVY64()
const {
836 return Kind ==
Memory && (!Mem.Size || Mem.Size == 64) &&
837 getMemIndexReg() >= X86::YMM0 && getMemIndexReg() <= X86::YMM15;
839 bool isMemVZ32()
const {
840 return Kind ==
Memory && (!Mem.Size || Mem.Size == 32) &&
841 getMemIndexReg() >= X86::ZMM0 && getMemIndexReg() <= X86::ZMM31;
843 bool isMemVZ64()
const {
844 return Kind ==
Memory && (!Mem.Size || Mem.Size == 64) &&
845 getMemIndexReg() >= X86::ZMM0 && getMemIndexReg() <= X86::ZMM31;
848 bool isAbsMem()
const {
849 return Kind ==
Memory && !getMemSegReg() && !getMemBaseReg() &&
850 !getMemIndexReg() && getMemScale() == 1;
853 bool isMemOffs8()
const {
854 return Kind ==
Memory && !getMemSegReg() && !getMemBaseReg() &&
855 !getMemIndexReg() && getMemScale() == 1 && (!Mem.Size || Mem.Size == 8);
857 bool isMemOffs16()
const {
858 return Kind ==
Memory && !getMemSegReg() && !getMemBaseReg() &&
859 !getMemIndexReg() && getMemScale() == 1 && (!Mem.Size || Mem.Size == 16);
861 bool isMemOffs32()
const {
862 return Kind ==
Memory && !getMemSegReg() && !getMemBaseReg() &&
863 !getMemIndexReg() && getMemScale() == 1 && (!Mem.Size || Mem.Size == 32);
865 bool isMemOffs64()
const {
866 return Kind ==
Memory && !getMemSegReg() && !getMemBaseReg() &&
867 !getMemIndexReg() && getMemScale() == 1 && (!Mem.Size || Mem.Size == 64);
872 bool isGR32orGR64()
const {
874 (X86MCRegisterClasses[X86::GR32RegClassID].contains(
getReg()) ||
875 X86MCRegisterClasses[X86::GR64RegClassID].contains(
getReg()));
886 void addRegOperands(
MCInst &Inst,
unsigned N)
const {
887 assert(N == 1 &&
"Invalid number of operands!");
891 static unsigned getGR32FromGR64(
unsigned RegNo) {
902 case X86::R8:
return X86::R8D;
903 case X86::R9:
return X86::R9D;
904 case X86::R10:
return X86::R10D;
905 case X86::R11:
return X86::R11D;
906 case X86::R12:
return X86::R12D;
907 case X86::R13:
return X86::R13D;
908 case X86::R14:
return X86::R14D;
909 case X86::R15:
return X86::R15D;
910 case X86::RIP:
return X86::EIP;
914 void addGR32orGR64Operands(
MCInst &Inst,
unsigned N)
const {
915 assert(N == 1 &&
"Invalid number of operands!");
916 unsigned RegNo =
getReg();
917 if (X86MCRegisterClasses[X86::GR64RegClassID].contains(RegNo))
918 RegNo = getGR32FromGR64(RegNo);
922 void addImmOperands(
MCInst &Inst,
unsigned N)
const {
923 assert(N == 1 &&
"Invalid number of operands!");
924 addExpr(Inst, getImm());
927 void addMemOperands(
MCInst &Inst,
unsigned N)
const {
928 assert((N == 5) &&
"Invalid number of operands!");
932 addExpr(Inst, getMemDisp());
936 void addAbsMemOperands(
MCInst &Inst,
unsigned N)
const {
937 assert((N == 1) &&
"Invalid number of operands!");
939 if (
const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getMemDisp()))
945 void addMemOffsOperands(
MCInst &Inst,
unsigned N)
const {
946 assert((N == 1) &&
"Invalid number of operands!");
948 if (
const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getMemDisp()))
956 X86Operand *Res =
new X86Operand(Token, Loc, EndLoc);
957 Res->Tok.Data = Str.
data();
958 Res->Tok.Length = Str.
size();
962 static X86Operand *CreateReg(
unsigned RegNo,
SMLoc StartLoc,
SMLoc EndLoc,
963 bool AddressOf =
false,
967 X86Operand *Res =
new X86Operand(
Register, StartLoc, EndLoc);
968 Res->Reg.RegNo = RegNo;
969 Res->AddressOf = AddressOf;
970 Res->OffsetOfLoc = OffsetOfLoc;
971 Res->SymName = SymName;
972 Res->OpDecl = OpDecl;
976 static X86Operand *CreateImm(
const MCExpr *Val,
SMLoc StartLoc,
SMLoc EndLoc){
977 X86Operand *Res =
new X86Operand(Immediate, StartLoc, EndLoc);
983 static X86Operand *CreateMem(
const MCExpr *Disp,
SMLoc StartLoc,
SMLoc EndLoc,
986 X86Operand *Res =
new X86Operand(
Memory, StartLoc, EndLoc);
988 Res->Mem.Disp = Disp;
989 Res->Mem.BaseReg = 0;
990 Res->Mem.IndexReg = 0;
992 Res->Mem.Size = Size;
993 Res->SymName = SymName;
994 Res->OpDecl = OpDecl;
995 Res->AddressOf =
false;
1000 static X86Operand *CreateMem(
unsigned SegReg,
const MCExpr *Disp,
1001 unsigned BaseReg,
unsigned IndexReg,
1002 unsigned Scale,
SMLoc StartLoc,
SMLoc EndLoc,
1008 assert((SegReg || BaseReg || IndexReg) &&
"Invalid memory operand!");
1011 assert(((Scale == 1 || Scale == 2 || Scale == 4 || Scale == 8)) &&
1013 X86Operand *Res =
new X86Operand(
Memory, StartLoc, EndLoc);
1014 Res->Mem.SegReg = SegReg;
1015 Res->Mem.Disp = Disp;
1016 Res->Mem.BaseReg = BaseReg;
1017 Res->Mem.IndexReg = IndexReg;
1018 Res->Mem.Scale = Scale;
1019 Res->Mem.Size = Size;
1020 Res->SymName = SymName;
1021 Res->OpDecl = OpDecl;
1022 Res->AddressOf =
false;
1029 bool X86AsmParser::isSrcOp(X86Operand &Op) {
1030 unsigned basereg = is64BitMode() ? X86::RSI :
X86::ESI;
1032 return (Op.isMem() &&
1033 (Op.Mem.SegReg == 0 || Op.Mem.SegReg == X86::DS) &&
1034 isa<MCConstantExpr>(Op.Mem.Disp) &&
1035 cast<MCConstantExpr>(Op.Mem.Disp)->getValue() == 0 &&
1036 Op.Mem.BaseReg == basereg && Op.Mem.IndexReg == 0);
1039 bool X86AsmParser::isDstOp(X86Operand &Op) {
1040 unsigned basereg = is64BitMode() ? X86::RDI :
X86::EDI;
1042 return Op.isMem() &&
1043 (Op.Mem.SegReg == 0 || Op.Mem.SegReg == X86::ES) &&
1044 isa<MCConstantExpr>(Op.Mem.Disp) &&
1045 cast<MCConstantExpr>(Op.Mem.Disp)->getValue() == 0 &&
1046 Op.Mem.BaseReg == basereg && Op.Mem.IndexReg == 0;
1049 bool X86AsmParser::ParseRegister(
unsigned &RegNo,
1052 const AsmToken &PercentTok = Parser.getTok();
1053 StartLoc = PercentTok.
getLoc();
1060 const AsmToken &Tok = Parser.getTok();
1064 if (isParsingIntelSyntax())
return true;
1065 return Error(StartLoc,
"invalid register name",
1075 if (!is64BitMode()) {
1081 if (RegNo == X86::RIZ ||
1082 X86MCRegisterClasses[X86::GR64RegClassID].contains(RegNo) ||
1085 return Error(StartLoc,
"register %"
1086 + Tok.
getString() +
" is only available in 64-bit mode",
1101 const AsmToken &IntTok = Parser.getTok();
1103 return Error(IntTok.
getLoc(),
"expected stack index");
1105 case 0: RegNo = X86::ST0;
break;
1106 case 1: RegNo = X86::ST1;
break;
1107 case 2: RegNo = X86::ST2;
break;
1108 case 3: RegNo = X86::ST3;
break;
1109 case 4: RegNo = X86::ST4;
break;
1110 case 5: RegNo = X86::ST5;
break;
1111 case 6: RegNo = X86::ST6;
break;
1112 case 7: RegNo = X86::ST7;
break;
1113 default:
return Error(IntTok.
getLoc(),
"invalid stack index");
1117 return Error(Parser.getTok().getLoc(),
"expected ')'");
1119 EndLoc = Parser.getTok().getEndLoc();
1124 EndLoc = Parser.getTok().getEndLoc();
1131 case '0': RegNo = X86::DR0;
break;
1132 case '1': RegNo = X86::DR1;
break;
1133 case '2': RegNo = X86::DR2;
break;
1134 case '3': RegNo = X86::DR3;
break;
1135 case '4': RegNo = X86::DR4;
break;
1136 case '5': RegNo = X86::DR5;
break;
1137 case '6': RegNo = X86::DR6;
break;
1138 case '7': RegNo = X86::DR7;
break;
1142 EndLoc = Parser.getTok().getEndLoc();
1149 if (isParsingIntelSyntax())
return true;
1150 return Error(StartLoc,
"invalid register name",
1158 X86Operand *X86AsmParser::ParseOperand() {
1159 if (isParsingIntelSyntax())
1160 return ParseIntelOperand();
1161 return ParseATTOperand();
1167 .Cases(
"BYTE",
"byte", 8)
1168 .
Cases(
"WORD",
"word", 16)
1169 .
Cases(
"DWORD",
"dword", 32)
1170 .
Cases(
"QWORD",
"qword", 64)
1171 .
Cases(
"XWORD",
"xword", 80)
1172 .
Cases(
"XMMWORD",
"xmmword", 128)
1173 .
Cases(
"YMMWORD",
"ymmword", 256)
1179 X86AsmParser::CreateMemForInlineAsm(
unsigned SegReg,
const MCExpr *Disp,
1180 unsigned BaseReg,
unsigned IndexReg,
1184 if (isa<MCSymbolRefExpr>(Disp)) {
1190 unsigned RegNo = is64BitMode() ? X86::RBX :
X86::EBX;
1191 return X86Operand::CreateReg(RegNo, Start, End,
true,
1195 Size = Info.
Type * 8;
1205 BaseReg = BaseReg ? BaseReg : 1;
1206 return X86Operand::CreateMem(SegReg, Disp, BaseReg, IndexReg, Scale, Start,
1207 End, Size, Identifier, Info.
OpDecl);
1213 int64_t FinalImmDisp,
SMLoc &BracLoc,
1223 if (ImmDisp != FinalImmDisp) {
1229 E = AsmRewrites->
end();
I != E; ++
I) {
1230 if ((*I).Loc.getPointer() > BracLoc.
getPointer())
1233 assert (!Found &&
"ImmDisp already rewritten.");
1235 (*I).Len = BracLoc.
getPointer() - (*I).Loc.getPointer();
1236 (*I).Val = FinalImmDisp;
1241 assert (Found &&
"Unable to rewrite ImmDisp.");
1252 E = AsmRewrites->
end();
I != E; ++
I) {
1253 if ((*I).Loc.getPointer() < StartInBrac.
getPointer())
1258 const char *SymLocPtr = SymName.
data();
1260 if (
unsigned Len = SymLocPtr - StartInBrac.
getPointer()) {
1261 assert(Len > 0 &&
"Expected a non-negative length.");
1265 if (
unsigned Len = End.
getPointer() - (SymLocPtr + SymName.
size())) {
1267 assert(Len > 0 &&
"Expected a non-negative length.");
1273 X86AsmParser::ParseIntelExpression(IntelExprStateMachine &SM,
SMLoc &End) {
1274 const AsmToken &Tok = Parser.getTok();
1278 bool UpdateLocLex =
true;
1289 switch (getLexer().getKind()) {
1291 if (SM.isValidEndState()) {
1295 return ErrorOperand(Tok.
getLoc(),
"Unexpected token!");
1307 if(!ParseRegister(TmpReg, IdentLoc, End)) {
1308 SM.onRegister(TmpReg);
1309 UpdateLocLex =
false;
1312 if (!isParsingInlineAsm()) {
1313 if (getParser().parsePrimaryExpr(Val, End))
1314 return ErrorOperand(Tok.
getLoc(),
"Unexpected identifier!");
1317 if (X86Operand *Err = ParseIntelIdentifier(Val, Identifier, Info,
1321 SM.onIdentifierExpr(Val, Identifier);
1322 UpdateLocLex =
false;
1325 return ErrorOperand(Tok.
getLoc(),
"Unexpected identifier!");
1328 if (isParsingInlineAsm() && SM.getAddImmPrefix())
1343 return ErrorOperand(Tok.
getLoc(),
"Unexpected token!");
1345 if (!Done && UpdateLocLex) {
1353 X86Operand *X86AsmParser::ParseIntelBracExpression(
unsigned SegReg,
SMLoc Start,
1356 const AsmToken &Tok = Parser.getTok();
1359 return ErrorOperand(BracLoc,
"Expected '[' token!");
1366 IntelExprStateMachine SM(ImmDisp,
false,
true);
1367 if (X86Operand *Err = ParseIntelExpression(SM, End))
1371 if (
const MCExpr *Sym = SM.getSym()) {
1374 if (isParsingInlineAsm())
1376 ImmDisp, SM.getImm(), BracLoc, StartInBrac,
1386 if (X86Operand *Err = ParseIntelDotOperator(Disp, NewDisp))
1394 int BaseReg = SM.getBaseReg();
1395 int IndexReg = SM.getIndexReg();
1396 int Scale = SM.getScale();
1397 if (!isParsingInlineAsm()) {
1399 if (!BaseReg && !IndexReg) {
1401 return X86Operand::CreateMem(Disp, Start, End, Size);
1403 return X86Operand::CreateMem(SegReg, Disp, 0, 0, 1, Start, End, Size);
1405 return X86Operand::CreateMem(SegReg, Disp, BaseReg, IndexReg, Scale, Start,
1410 return CreateMemForInlineAsm(SegReg, Disp, BaseReg, IndexReg, Scale, Start,
1411 End, Size, SM.getSymName(), Info);
1415 X86Operand *X86AsmParser::ParseIntelIdentifier(
const MCExpr *&Val,
1418 bool IsUnevaluatedOperand,
1420 assert (isParsingInlineAsm() &&
"Expected to be parsing inline assembly.");
1424 SemaCallback->LookupInlineAsmIdentifier(LineBuf, Info, IsUnevaluatedOperand);
1426 const AsmToken &Tok = Parser.getTok();
1435 assert(End.
getPointer() <= EndPtr &&
"frontend claimed part of a token?");
1440 Identifier = LineBuf;
1441 MCSymbol *Sym = getContext().GetOrCreateSymbol(Identifier);
1448 X86Operand *X86AsmParser::ParseIntelSegmentOverride(
unsigned SegReg,
1451 assert(SegReg != 0 &&
"Tried to parse a segment override without a segment!");
1452 const AsmToken &Tok = Parser.getTok();
1454 return ErrorOperand(Tok.
getLoc(),
"Expected ':' token!");
1457 int64_t ImmDisp = 0;
1460 AsmToken ImmDispToken = Parser.Lex();
1462 if (isParsingInlineAsm())
1463 InstInfo->AsmRewrites->push_back(
1471 return X86Operand::CreateMem(SegReg, Disp, 0, 0,
1478 return ParseIntelBracExpression(SegReg, Start, ImmDisp, Size);
1482 if (!isParsingInlineAsm()) {
1483 if (getParser().parsePrimaryExpr(Val, End))
1484 return ErrorOperand(Tok.
getLoc(),
"Unexpected token!");
1486 return X86Operand::CreateMem(Val, Start, End, Size);
1491 if (X86Operand *Err = ParseIntelIdentifier(Val, Identifier, Info,
1494 return CreateMemForInlineAsm(0, Val, 0,0,
1495 1, Start, End, Size, Identifier, Info);
1499 X86Operand *X86AsmParser::ParseIntelMemOperand(int64_t ImmDisp,
SMLoc Start,
1501 const AsmToken &Tok = Parser.getTok();
1506 return ParseIntelBracExpression(0, Start, ImmDisp, Size);
1509 if (!isParsingInlineAsm()) {
1510 if (getParser().parsePrimaryExpr(Val, End))
1511 return ErrorOperand(Tok.
getLoc(),
"Unexpected token!");
1513 return X86Operand::CreateMem(Val, Start, End, Size);
1518 if (X86Operand *Err = ParseIntelIdentifier(Val, Identifier, Info,
1521 return CreateMemForInlineAsm(0, Val, 0, 0,
1522 1, Start, End, Size, Identifier, Info);
1526 X86Operand *X86AsmParser::ParseIntelDotOperator(
const MCExpr *Disp,
1527 const MCExpr *&NewDisp) {
1528 const AsmToken &Tok = Parser.getTok();
1529 int64_t OrigDispVal, DotDispVal;
1532 if (
const MCConstantExpr *OrigDisp = dyn_cast<MCConstantExpr>(Disp))
1533 OrigDispVal = OrigDisp->getValue();
1535 return ErrorOperand(Tok.
getLoc(),
"Non-constant offsets are not supported!");
1543 DotDispStr.getAsInteger(10, DotDisp);
1547 std::pair<StringRef, StringRef> BaseMember = DotDispStr.split(
'.');
1548 if (SemaCallback->LookupInlineAsmField(BaseMember.first, BaseMember.second,
1550 return ErrorOperand(Tok.
getLoc(),
"Unable to lookup field reference!");
1551 DotDispVal = DotDisp;
1553 return ErrorOperand(Tok.
getLoc(),
"Unexpected token type!");
1557 unsigned Len = DotDispStr.size();
1558 unsigned Val = OrigDispVal + DotDispVal;
1569 X86Operand *X86AsmParser::ParseIntelOffsetOfOperator() {
1570 const AsmToken &Tok = Parser.getTok();
1578 if (X86Operand *Err = ParseIntelIdentifier(Val, Identifier, Info,
1588 unsigned RegNo = is64BitMode() ? X86::RBX :
X86::EBX;
1589 return X86Operand::CreateReg(RegNo, Start, End,
true,
1590 OffsetOfLoc, Identifier, Info.
OpDecl);
1605 X86Operand *X86AsmParser::ParseIntelOperator(
unsigned OpKind) {
1606 const AsmToken &Tok = Parser.getTok();
1614 if (X86Operand *Err = ParseIntelIdentifier(Val, Identifier, Info,
1632 return X86Operand::CreateImm(Imm, Start, End);
1635 X86Operand *X86AsmParser::ParseIntelOperand() {
1636 const AsmToken &Tok = Parser.getTok();
1640 if (isParsingInlineAsm()) {
1642 if (AsmTokStr ==
"offset" || AsmTokStr ==
"OFFSET")
1643 return ParseIntelOffsetOfOperator();
1644 if (AsmTokStr ==
"length" || AsmTokStr ==
"LENGTH")
1646 if (AsmTokStr ==
"size" || AsmTokStr ==
"SIZE")
1647 return ParseIntelOperator(
IOK_SIZE);
1648 if (AsmTokStr ==
"type" || AsmTokStr ==
"TYPE")
1649 return ParseIntelOperator(
IOK_TYPE);
1656 return ErrorOperand(Start,
"Expected 'PTR' or 'ptr' token!");
1665 IntelExprStateMachine SM(0,
true,
1667 if (X86Operand *Err = ParseIntelExpression(SM, End))
1670 int64_t Imm = SM.getImm();
1671 if (isParsingInlineAsm()) {
1683 return X86Operand::CreateImm(ImmExpr, Start, End);
1688 return ErrorOperand(Start,
"expected a positive immediate displacement "
1689 "before bracketed expr.");
1692 return ParseIntelMemOperand(Imm, Start, Size);
1697 if (!ParseRegister(RegNo, Start, End)) {
1701 return X86Operand::CreateReg(RegNo, Start, End);
1703 return ParseIntelSegmentOverride(RegNo, Start, Size);
1707 return ParseIntelMemOperand(0, Start, Size);
1710 X86Operand *X86AsmParser::ParseATTOperand() {
1711 switch (getLexer().getKind()) {
1714 return ParseMemOperand(0, Parser.getTok().getLoc());
1719 if (ParseRegister(RegNo, Start, End))
return 0;
1720 if (RegNo == X86::EIZ || RegNo == X86::RIZ) {
1721 Error(Start,
"%eiz and %riz can only be used as index registers",
1729 return X86Operand::CreateReg(RegNo, Start, End);
1732 return ParseMemOperand(RegNo, Start);
1736 SMLoc Start = Parser.getTok().getLoc(), End;
1739 if (getParser().parseExpression(Val, End))
1741 return X86Operand::CreateImm(Val, Start, End);
1748 X86Operand *X86AsmParser::ParseMemOperand(
unsigned SegReg,
SMLoc MemStart) {
1757 if (getParser().parseExpression(Disp, ExprEnd))
return 0;
1764 return X86Operand::CreateMem(Disp, MemStart, ExprEnd);
1765 return X86Operand::CreateMem(SegReg, Disp, 0, 0, 1, MemStart, ExprEnd);
1773 SMLoc LParenLoc = Parser.getTok().getLoc();
1783 if (getParser().parseParenExpression(Disp, ExprEnd))
1791 return X86Operand::CreateMem(Disp, LParenLoc, ExprEnd);
1792 return X86Operand::CreateMem(SegReg, Disp, 0, 0, 1, MemStart, ExprEnd);
1802 unsigned BaseReg = 0, IndexReg = 0, Scale = 1;
1806 SMLoc StartLoc, EndLoc;
1807 if (ParseRegister(BaseReg, StartLoc, EndLoc))
return 0;
1808 if (BaseReg == X86::EIZ || BaseReg == X86::RIZ) {
1809 Error(StartLoc,
"eiz and riz can only be used as index registers",
1817 IndexLoc = Parser.getTok().getLoc();
1827 if (ParseRegister(IndexReg, L, L))
return 0;
1833 Error(Parser.getTok().getLoc(),
1834 "expected comma in scale expression");
1840 SMLoc Loc = Parser.getTok().getLoc();
1843 if (getParser().parseAbsoluteExpression(ScaleVal)){
1844 Error(Loc,
"expected scale expression");
1849 if (ScaleVal != 1 && ScaleVal != 2 && ScaleVal != 4 && ScaleVal != 8){
1850 Error(Loc,
"scale factor in address must be 1, 2, 4 or 8");
1859 SMLoc Loc = Parser.getTok().getLoc();
1862 if (getParser().parseAbsoluteExpression(Value))
1866 Warning(Loc,
"scale factor without index register is ignored");
1873 Error(Parser.getTok().getLoc(),
"unexpected token in memory operand");
1876 SMLoc MemEnd = Parser.getTok().getEndLoc();
1882 if (BaseReg != 0 && IndexReg != 0) {
1883 if (X86MCRegisterClasses[X86::GR64RegClassID].contains(BaseReg) &&
1884 (X86MCRegisterClasses[X86::GR16RegClassID].contains(IndexReg) ||
1885 X86MCRegisterClasses[X86::GR32RegClassID].contains(IndexReg)) &&
1886 IndexReg != X86::RIZ) {
1887 Error(IndexLoc,
"index register is 32-bit, but base register is 64-bit");
1890 if (X86MCRegisterClasses[X86::GR32RegClassID].contains(BaseReg) &&
1891 (X86MCRegisterClasses[X86::GR16RegClassID].contains(IndexReg) ||
1892 X86MCRegisterClasses[X86::GR64RegClassID].contains(IndexReg)) &&
1893 IndexReg != X86::EIZ){
1894 Error(IndexLoc,
"index register is 64-bit, but base register is 32-bit");
1899 return X86Operand::CreateMem(SegReg, Disp, BaseReg, IndexReg, Scale,
1911 PatchedName !=
"setb" && PatchedName !=
"setnb")
1912 PatchedName = PatchedName.
substr(0, Name.
size()-1);
1915 const MCExpr *ExtraImmOp = 0;
1919 bool IsVCMP = PatchedName[0] ==
'v';
1920 unsigned SSECCIdx = IsVCMP ? 4 : 3;
1922 PatchedName.
slice(SSECCIdx, PatchedName.
size() - 2))
1926 .
Case(
"unord", 0x03)
1932 .
Case(
"eq_uq", 0x08)
1935 .
Case(
"false", 0x0B)
1936 .
Case(
"neq_oq", 0x0C)
1940 .
Case(
"eq_os", 0x10)
1941 .
Case(
"lt_oq", 0x11)
1942 .
Case(
"le_oq", 0x12)
1943 .
Case(
"unord_s", 0x13)
1944 .
Case(
"neq_us", 0x14)
1945 .
Case(
"nlt_uq", 0x15)
1946 .
Case(
"nle_uq", 0x16)
1947 .
Case(
"ord_s", 0x17)
1948 .
Case(
"eq_us", 0x18)
1949 .
Case(
"nge_uq", 0x19)
1950 .
Case(
"ngt_uq", 0x1A)
1951 .
Case(
"false_os", 0x1B)
1952 .
Case(
"neq_os", 0x1C)
1953 .
Case(
"ge_oq", 0x1D)
1954 .
Case(
"gt_oq", 0x1E)
1955 .
Case(
"true_us", 0x1F)
1957 if (SSEComparisonCode != ~0U && (IsVCMP || SSEComparisonCode < 8)) {
1959 getParser().getContext());
1961 PatchedName = IsVCMP ?
"vcmpss" :
"cmpss";
1962 }
else if (PatchedName.
endswith(
"sd")) {
1963 PatchedName = IsVCMP ?
"vcmpsd" :
"cmpsd";
1964 }
else if (PatchedName.
endswith(
"ps")) {
1965 PatchedName = IsVCMP ?
"vcmpps" :
"cmpps";
1967 assert(PatchedName.
endswith(
"pd") &&
"Unexpected mnemonic!");
1968 PatchedName = IsVCMP ?
"vcmppd" :
"cmppd";
1973 Operands.
push_back(X86Operand::CreateToken(PatchedName, NameLoc));
1975 if (ExtraImmOp && !isParsingIntelSyntax())
1976 Operands.
push_back(X86Operand::CreateImm(ExtraImmOp, NameLoc, NameLoc));
1980 Name ==
"lock" || Name ==
"rep" ||
1981 Name ==
"repe" || Name ==
"repz" ||
1982 Name ==
"repne" || Name ==
"repnz" ||
1983 Name ==
"rex64" || Name ==
"data16";
1994 SMLoc Loc = Parser.getTok().getLoc();
1995 Operands.
push_back(X86Operand::CreateToken(
"*", Loc));
2000 if (X86Operand *Op = ParseOperand())
2003 Parser.eatToEndOfStatement();
2011 if (X86Operand *Op = ParseOperand())
2014 Parser.eatToEndOfStatement();
2019 if (STI.getFeatureBits() & X86::FeatureAVX512) {
2022 SMLoc Loc = Parser.getTok().getLoc();
2023 Operands.
push_back(X86Operand::CreateToken(
"{", Loc));
2025 if (X86Operand *Op = ParseOperand()) {
2028 SMLoc Loc = getLexer().getLoc();
2029 Parser.eatToEndOfStatement();
2030 return Error(Loc,
"Expected } at this point");
2032 Loc = Parser.getTok().getLoc();
2033 Operands.
push_back(X86Operand::CreateToken(
"}", Loc));
2036 Parser.eatToEndOfStatement();
2042 SMLoc Loc = Parser.getTok().getLoc();
2043 Operands.
push_back(X86Operand::CreateToken(
"{z}", Loc));
2046 SMLoc Loc = getLexer().getLoc();
2047 Parser.eatToEndOfStatement();
2048 return Error(Loc,
"Expected z at this point");
2052 SMLoc Loc = getLexer().getLoc();
2053 Parser.eatToEndOfStatement();
2054 return Error(Loc,
"Expected } at this point");
2061 SMLoc Loc = getLexer().getLoc();
2062 Parser.eatToEndOfStatement();
2063 return Error(Loc,
"unexpected token in argument list");
2072 if (ExtraImmOp && isParsingIntelSyntax())
2073 Operands.
push_back(X86Operand::CreateImm(ExtraImmOp, NameLoc, NameLoc));
2078 if ((Name ==
"outb" || Name ==
"outw" || Name ==
"outl" || Name ==
"out") &&
2079 Operands.
size() == 3) {
2080 X86Operand &Op = *(X86Operand*)Operands.
back();
2081 if (Op.isMem() && Op.Mem.SegReg == 0 &&
2082 isa<MCConstantExpr>(Op.Mem.Disp) &&
2083 cast<MCConstantExpr>(Op.Mem.Disp)->getValue() == 0 &&
2085 SMLoc Loc = Op.getEndLoc();
2086 Operands.
back() = X86Operand::CreateReg(Op.Mem.BaseReg, Loc, Loc);
2091 if ((Name ==
"inb" || Name ==
"inw" || Name ==
"inl" || Name ==
"in") &&
2092 Operands.
size() == 3) {
2093 X86Operand &Op = *(X86Operand*)Operands.
begin()[1];
2094 if (Op.isMem() && Op.Mem.SegReg == 0 &&
2095 isa<MCConstantExpr>(Op.Mem.Disp) &&
2096 cast<MCConstantExpr>(Op.Mem.Disp)->getValue() == 0 &&
2098 SMLoc Loc = Op.getEndLoc();
2099 Operands.
begin()[1] = X86Operand::CreateReg(Op.Mem.BaseReg, Loc, Loc);
2105 (Name ==
"insb" || Name ==
"insw" || Name ==
"insl")) {
2106 X86Operand &Op = *(X86Operand*)Operands.
begin()[1];
2107 X86Operand &Op2 = *(X86Operand*)Operands.
begin()[2];
2108 if (Op.isReg() && Op.getReg() == X86::DX && isDstOp(Op2)) {
2118 (Name ==
"outsb" || Name ==
"outsw" || Name ==
"outsl")) {
2119 X86Operand &Op = *(X86Operand*)Operands.
begin()[1];
2120 X86Operand &Op2 = *(X86Operand*)Operands.
begin()[2];
2121 if (isSrcOp(Op) && Op2.isReg() && Op2.getReg() == X86::DX) {
2131 (Name ==
"movsb" || Name ==
"movsw" || Name ==
"movsl" ||
2132 (is64BitMode() && Name ==
"movsq"))) {
2133 X86Operand &Op = *(X86Operand*)Operands.
begin()[1];
2134 X86Operand &Op2 = *(X86Operand*)Operands.
begin()[2];
2135 if (isSrcOp(Op) && isDstOp(Op2)) {
2144 (Name ==
"lods" || Name ==
"lodsb" || Name ==
"lodsw" ||
2145 Name ==
"lodsl" || (is64BitMode() && Name ==
"lodsq"))) {
2146 X86Operand *Op1 =
static_cast<X86Operand*
>(Operands[1]);
2147 X86Operand *Op2 =
static_cast<X86Operand*
>(Operands[2]);
2148 if (isSrcOp(*Op1) && Op2->isReg()) {
2150 unsigned reg = Op2->getReg();
2151 bool isLods = Name ==
"lods";
2152 if (reg ==
X86::AL && (isLods || Name ==
"lodsb"))
2154 else if (reg == X86::AX && (isLods || Name ==
"lodsw"))
2156 else if (reg ==
X86::EAX && (isLods || Name ==
"lodsl"))
2158 else if (reg == X86::RAX && (isLods || Name ==
"lodsq"))
2168 static_cast<X86Operand*
>(Operands[0])->setTokenValue(ins);
2174 (Name ==
"stos" || Name ==
"stosb" || Name ==
"stosw" ||
2175 Name ==
"stosl" || (is64BitMode() && Name ==
"stosq"))) {
2176 X86Operand *Op1 =
static_cast<X86Operand*
>(Operands[1]);
2177 X86Operand *Op2 =
static_cast<X86Operand*
>(Operands[2]);
2178 if (isDstOp(*Op2) && Op1->isReg()) {
2180 unsigned reg = Op1->getReg();
2181 bool isStos = Name ==
"stos";
2182 if (reg ==
X86::AL && (isStos || Name ==
"stosb"))
2184 else if (reg == X86::AX && (isStos || Name ==
"stosw"))
2186 else if (reg ==
X86::EAX && (isStos || Name ==
"stosl"))
2188 else if (reg == X86::RAX && (isStos || Name ==
"stosq"))
2198 static_cast<X86Operand*
>(Operands[0])->setTokenValue(ins);
2209 Operands.
size() == 3) {
2210 if (isParsingIntelSyntax()) {
2212 X86Operand *Op1 =
static_cast<X86Operand*
>(Operands[2]);
2213 if (Op1->isImm() && isa<MCConstantExpr>(Op1->getImm()) &&
2214 cast<MCConstantExpr>(Op1->getImm())->getValue() == 1) {
2219 X86Operand *Op1 =
static_cast<X86Operand*
>(Operands[1]);
2220 if (Op1->isImm() && isa<MCConstantExpr>(Op1->getImm()) &&
2221 cast<MCConstantExpr>(Op1->getImm())->getValue() == 1) {
2230 if (Name ==
"int" && Operands.
size() == 2) {
2231 X86Operand *Op1 =
static_cast<X86Operand*
>(Operands[1]);
2232 if (Op1->isImm() && isa<MCConstantExpr>(Op1->getImm()) &&
2233 cast<MCConstantExpr>(Op1->getImm())->getValue() == 3) {
2236 static_cast<X86Operand*
>(Operands[0])->setTokenValue(
"int3");
2256 bool isCmp =
false) {
2265 bool isCmp =
false) {
2274 bool isCmp =
false) {
2283 processInstruction(
MCInst &Inst,
2286 default:
return false;
2311 case X86::VMOVAPDrr:
2312 case X86::VMOVAPDYrr:
2313 case X86::VMOVAPSrr:
2314 case X86::VMOVAPSYrr:
2315 case X86::VMOVDQArr:
2316 case X86::VMOVDQAYrr:
2317 case X86::VMOVDQUrr:
2318 case X86::VMOVDQUYrr:
2319 case X86::VMOVUPDrr:
2320 case X86::VMOVUPDYrr:
2321 case X86::VMOVUPSrr:
2322 case X86::VMOVUPSYrr: {
2330 case X86::VMOVAPDrr: NewOpc = X86::VMOVAPDrr_REV;
break;
2331 case X86::VMOVAPDYrr: NewOpc = X86::VMOVAPDYrr_REV;
break;
2332 case X86::VMOVAPSrr: NewOpc = X86::VMOVAPSrr_REV;
break;
2333 case X86::VMOVAPSYrr: NewOpc = X86::VMOVAPSYrr_REV;
break;
2334 case X86::VMOVDQArr: NewOpc = X86::VMOVDQArr_REV;
break;
2335 case X86::VMOVDQAYrr: NewOpc = X86::VMOVDQAYrr_REV;
break;
2336 case X86::VMOVDQUrr: NewOpc = X86::VMOVDQUrr_REV;
break;
2337 case X86::VMOVDQUYrr: NewOpc = X86::VMOVDQUYrr_REV;
break;
2338 case X86::VMOVUPDrr: NewOpc = X86::VMOVUPDrr_REV;
break;
2339 case X86::VMOVUPDYrr: NewOpc = X86::VMOVUPDYrr_REV;
break;
2340 case X86::VMOVUPSrr: NewOpc = X86::VMOVUPSrr_REV;
break;
2341 case X86::VMOVUPSYrr: NewOpc = X86::VMOVUPSYrr_REV;
break;
2347 case X86::VMOVSSrr: {
2354 case X86::VMOVSDrr: NewOpc = X86::VMOVSDrr_REV;
break;
2355 case X86::VMOVSSrr: NewOpc = X86::VMOVSSrr_REV;
break;
2365 MatchAndEmitInstruction(
SMLoc IDLoc,
unsigned &Opcode,
2368 bool MatchingInlineAsm) {
2369 assert(!Operands.
empty() &&
"Unexpect empty operand list!");
2370 X86Operand *Op =
static_cast<X86Operand*
>(Operands[0]);
2371 assert(Op->isToken() &&
"Leading operand should always be a mnemonic!");
2378 if (Op->getToken() ==
"fstsw" || Op->getToken() ==
"fstcw" ||
2379 Op->getToken() ==
"fstsww" || Op->getToken() ==
"fstcww" ||
2380 Op->getToken() ==
"finit" || Op->getToken() ==
"fsave" ||
2381 Op->getToken() ==
"fstenv" || Op->getToken() ==
"fclex") {
2385 if (!MatchingInlineAsm)
2390 .Case(
"finit",
"fninit")
2391 .
Case(
"fsave",
"fnsave")
2392 .
Case(
"fstcw",
"fnstcw")
2393 .
Case(
"fstcww",
"fnstcw")
2394 .
Case(
"fstenv",
"fnstenv")
2395 .
Case(
"fstsw",
"fnstsw")
2396 .
Case(
"fstsww",
"fnstsw")
2397 .
Case(
"fclex",
"fnclex")
2399 assert(Repl &&
"Unknown wait-prefixed instruction");
2401 Operands[0] = X86Operand::CreateToken(Repl, IDLoc);
2404 bool WasOriginallyInvalidOperand =
false;
2408 switch (MatchInstructionImpl(Operands, Inst,
2409 ErrorInfo, MatchingInlineAsm,
2410 isParsingIntelSyntax())) {
2416 if (!MatchingInlineAsm)
2417 while (processInstruction(Inst, Operands))
2421 if (!MatchingInlineAsm)
2425 case Match_MissingFeature: {
2426 assert(ErrorInfo &&
"Unknown missing feature!");
2429 std::string Msg =
"instruction requires:";
2431 for (
unsigned i = 0; i < (
sizeof(ErrorInfo)*8-1); ++i) {
2432 if (ErrorInfo & Mask) {
2438 return Error(IDLoc, Msg, EmptyRanges, MatchingInlineAsm);
2440 case Match_InvalidOperand:
2441 WasOriginallyInvalidOperand =
true;
2443 case Match_MnemonicFail:
2457 Op->setTokenValue(Tmp.
str());
2465 const char *Suffixes = Base[0] !=
'f' ?
"bwlq" :
"slt\0";
2468 Tmp[Base.
size()] = Suffixes[0];
2469 unsigned ErrorInfoIgnore;
2470 unsigned ErrorInfoMissingFeature = 0;
2471 unsigned Match1, Match2, Match3, Match4;
2473 Match1 = MatchInstructionImpl(Operands, Inst, ErrorInfoIgnore,
2474 MatchingInlineAsm, isParsingIntelSyntax());
2476 if (Match1 == Match_MissingFeature)
2477 ErrorInfoMissingFeature = ErrorInfoIgnore;
2478 Tmp[Base.
size()] = Suffixes[1];
2479 Match2 = MatchInstructionImpl(Operands, Inst, ErrorInfoIgnore,
2480 MatchingInlineAsm, isParsingIntelSyntax());
2482 if (Match2 == Match_MissingFeature)
2483 ErrorInfoMissingFeature = ErrorInfoIgnore;
2484 Tmp[Base.
size()] = Suffixes[2];
2485 Match3 = MatchInstructionImpl(Operands, Inst, ErrorInfoIgnore,
2486 MatchingInlineAsm, isParsingIntelSyntax());
2488 if (Match3 == Match_MissingFeature)
2489 ErrorInfoMissingFeature = ErrorInfoIgnore;
2490 Tmp[Base.
size()] = Suffixes[3];
2491 Match4 = MatchInstructionImpl(Operands, Inst, ErrorInfoIgnore,
2492 MatchingInlineAsm, isParsingIntelSyntax());
2494 if (Match4 == Match_MissingFeature)
2495 ErrorInfoMissingFeature = ErrorInfoIgnore;
2498 Op->setTokenValue(Base);
2503 unsigned NumSuccessfulMatches =
2504 (Match1 == Match_Success) + (Match2 == Match_Success) +
2505 (Match3 == Match_Success) + (Match4 == Match_Success);
2506 if (NumSuccessfulMatches == 1) {
2508 if (!MatchingInlineAsm)
2518 if (NumSuccessfulMatches > 1) {
2520 unsigned NumMatches = 0;
2521 if (Match1 == Match_Success) MatchChars[NumMatches++] = Suffixes[0];
2522 if (Match2 == Match_Success) MatchChars[NumMatches++] = Suffixes[1];
2523 if (Match3 == Match_Success) MatchChars[NumMatches++] = Suffixes[2];
2524 if (Match4 == Match_Success) MatchChars[NumMatches++] = Suffixes[3];
2528 OS <<
"ambiguous instructions require an explicit suffix (could be ";
2529 for (
unsigned i = 0; i != NumMatches; ++i) {
2532 if (i + 1 == NumMatches)
2534 OS <<
"'" << Base << MatchChars[i] <<
"'";
2537 Error(IDLoc, OS.str(), EmptyRanges, MatchingInlineAsm);
2545 if ((Match1 == Match_MnemonicFail) && (Match2 == Match_MnemonicFail) &&
2546 (Match3 == Match_MnemonicFail) && (Match4 == Match_MnemonicFail)) {
2547 if (!WasOriginallyInvalidOperand) {
2550 return Error(IDLoc,
"invalid instruction mnemonic '" + Base +
"'",
2551 Ranges, MatchingInlineAsm);
2555 if (ErrorInfo != ~0U) {
2556 if (ErrorInfo >= Operands.
size())
2557 return Error(IDLoc,
"too few operands for instruction",
2558 EmptyRanges, MatchingInlineAsm);
2560 X86Operand *Operand = (X86Operand*)Operands[ErrorInfo];
2561 if (Operand->getStartLoc().isValid()) {
2562 SMRange OperandRange = Operand->getLocRange();
2563 return Error(Operand->getStartLoc(),
"invalid operand for instruction",
2564 OperandRange, MatchingInlineAsm);
2568 return Error(IDLoc,
"invalid operand for instruction", EmptyRanges,
2574 if ((Match1 == Match_MissingFeature) + (Match2 == Match_MissingFeature) +
2575 (Match3 == Match_MissingFeature) + (Match4 == Match_MissingFeature) == 1){
2576 std::string Msg =
"instruction requires:";
2578 for (
unsigned i = 0; i < (
sizeof(ErrorInfoMissingFeature)*8-1); ++i) {
2579 if (ErrorInfoMissingFeature & Mask) {
2585 return Error(IDLoc, Msg, EmptyRanges, MatchingInlineAsm);
2590 if ((Match1 == Match_InvalidOperand) + (Match2 == Match_InvalidOperand) +
2591 (Match3 == Match_InvalidOperand) + (Match4 == Match_InvalidOperand) == 1){
2592 Error(IDLoc,
"invalid operand for instruction", EmptyRanges,
2598 Error(IDLoc,
"unknown use of instruction mnemonic without a size suffix",
2599 EmptyRanges, MatchingInlineAsm);
2604 bool X86AsmParser::ParseDirective(
AsmToken DirectiveID) {
2606 if (IDVal ==
".word")
2607 return ParseDirectiveWord(2, DirectiveID.
getLoc());
2609 return ParseDirectiveCode(IDVal, DirectiveID.
getLoc());
2611 getParser().setAssemblerDialect(0);
2613 }
else if (IDVal.
startswith(
".intel_syntax")) {
2614 getParser().setAssemblerDialect(1);
2616 if(Parser.getTok().getString() ==
"noprefix") {
2629 bool X86AsmParser::ParseDirectiveWord(
unsigned Size,
SMLoc L) {
2633 if (getParser().parseExpression(Value))
2636 getParser().getStreamer().EmitValue(Value, Size);
2643 return Error(L,
"unexpected token in directive");
2654 bool X86AsmParser::ParseDirectiveCode(
StringRef IDVal,
SMLoc L) {
2655 if (IDVal ==
".code32") {
2657 if (is64BitMode()) {
2659 getParser().getStreamer().EmitAssemblerFlag(
MCAF_Code32);
2661 }
else if (IDVal ==
".code64") {
2663 if (!is64BitMode()) {
2665 getParser().getStreamer().EmitAssemblerFlag(
MCAF_Code64);
2668 return Error(L,
"unexpected directive " + IDVal);
2680 #define GET_REGISTER_MATCHER
2681 #define GET_MATCHER_IMPLEMENTATION
2682 #define GET_SUBTARGET_FEATURE_NAME
2683 #include "X86GenAsmMatcher.inc"
static bool isReg(const MCInst &MI, unsigned OpNo)
void push_back(const T &Elt)
static bool isImmSExti16i8Value(uint64_t Value)
}
static bool isImmSExti32i8Value(uint64_t Value)
uint64_t getZExtValue() const
Get zero extended value.
bool isX86_64NonExtLowByteReg(unsigned reg)
const char * getPointer() const
size_t size() const
size - Get the string size.
static MCOperand CreateReg(unsigned Reg)
static const MCConstantExpr * Create(int64_t Value, MCContext &Ctx)
An abstraction for memory operations.
MCTargetAsmParser - Generic interface to target specific assembly parsers.
enable_if_c<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
bool endswith(StringRef Suffix) const
Check if this string ends with the given Suffix.
StringRef getString() const
static MCOperand CreateExpr(const MCExpr *Val)
StringRef substr(size_t Start, size_t N=npos) const
bool isNot(TokenKind K) const
virtual void EmitInstruction(const MCInst &Inst)=0
static void RewriteIntelBracExpression(SmallVectorImpl< AsmRewrite > *AsmRewrites, StringRef SymName, int64_t ImmDisp, int64_t FinalImmDisp, SMLoc &BracLoc, SMLoc &StartInBrac, SMLoc &End)
StringSwitch & Case(const char(&S)[N], const T &Value)
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const char *reason, bool gen_crash_diag=true)
static bool isImmZExtu32u8Value(uint64_t Value)
void LLVMInitializeX86AsmParser()
std::pair< StringRef, StringRef > getToken(StringRef Source, StringRef Delimiters=" \t\n\v\f\r")
T LLVM_ATTRIBUTE_UNUSED_RESULT pop_back_val()
#define llvm_unreachable(msg)
AsmToken - Target independent representation for an assembler token.
static unsigned getIntelMemOperandSize(StringRef OpStr)
getIntelMemOperandSize - Return intel memory operand size.
static bool convert16i16to16ri8(MCInst &Inst, unsigned Opcode, bool isCmp=false)
static bool isImmSExti64i32Value(uint64_t Value)
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
unsigned getReg() const
getReg - Returns the register number.
const char * data() const
int64_t getIntVal() const
bool isX86_64ExtendedReg(unsigned RegNo)
static const MCSymbolRefExpr * Create(const MCSymbol *Symbol, MCContext &Ctx)
A switch()-like statement whose cases are string literals.
This file declares a class to represent arbitrary precision floating point values and provide a varie...
iterator erase(iterator I)
static bool convert64i32to64ri8(MCInst &Inst, unsigned Opcode, bool isCmp=false)
void setOpcode(unsigned Op)
bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
StringRef drop_front(size_t N=1) const
static unsigned MatchRegisterName(StringRef Name)
static const char * getSubtargetFeatureName(unsigned Val)
Promote Memory to Register
static bool isImmSExti64i8Value(uint64_t Value)
bool is(TokenKind K) const
R Default(const T &Value) const
unsigned getOpcode() const
Class for arbitrary precision integers.
StringRef str() const
Explicit conversion to StringRef.
static bool convertToSExti8(MCInst &Inst, unsigned Opcode, unsigned Reg, bool isCmp)
.code32 (X86) / .code 32 (ARM)
static SMLoc getFromPointer(const char *Ptr)
StringRef getIdentifier() const
static MCOperand CreateImm(int64_t Val)
static bool convert32i32to32ri8(MCInst &Inst, unsigned Opcode, bool isCmp=false)
static unsigned getReg(const void *D, unsigned RC, unsigned RegNo)
static bool isMem(const MachineInstr *MI, unsigned Op)
LLVM Value Representation.
StringSwitch & Cases(const char(&S0)[N0], const char(&S1)[N1], const T &Value)
void addOperand(const MCOperand &Op)
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml","ocaml 3.10-compatible collector")
StringRef slice(size_t Start, size_t End) const
Represents a location in source code.
static RegisterPass< NVPTXAllocaHoisting > X("alloca-hoisting","Hoisting alloca instructions in non-entry ""blocks to the entry block")
std::string lower() const
const MCOperand & getOperand(unsigned i) const