40 switch (
E->getKind()) {
43 return Res < 0 ? -1 : Res;
50 if (Name ==
"lt")
return 0;
51 if (Name ==
"gt")
return 1;
52 if (Name ==
"eq")
return 2;
53 if (Name ==
"so")
return 3;
54 if (Name ==
"un")
return 3;
56 if (Name ==
"cr0")
return 0;
57 if (Name ==
"cr1")
return 1;
58 if (Name ==
"cr2")
return 2;
59 if (Name ==
"cr3")
return 3;
60 if (Name ==
"cr4")
return 4;
61 if (Name ==
"cr5")
return 5;
62 if (Name ==
"cr6")
return 6;
63 if (Name ==
"cr7")
return 7;
77 if (LHSVal < 0 || RHSVal < 0)
86 return Res < 0 ? -1 : Res;
106 void Warning(SMLoc L,
const Twine &Msg) { getParser().
Warning(L, Msg); }
108 bool isPPC64()
const {
return IsPPC64; }
110 MCRegister matchRegisterName(int64_t &IntVal);
112 bool parseRegister(MCRegister &
Reg, SMLoc &StartLoc, SMLoc &EndLoc)
override;
113 ParseStatus tryParseRegister(MCRegister &
Reg, SMLoc &StartLoc,
114 SMLoc &EndLoc)
override;
116 const MCExpr *extractSpecifier(
const MCExpr *
E,
118 bool parseExpression(
const MCExpr *&EVal);
122 bool parseDirectiveWord(
unsigned Size, AsmToken
ID);
123 bool parseDirectiveTC(
unsigned Size, AsmToken
ID);
124 bool parseDirectiveMachine(SMLoc L);
125 bool parseDirectiveAbiVersion(SMLoc L);
126 bool parseDirectiveLocalEntry(SMLoc L);
127 bool parseGNUAttribute(SMLoc L);
129 bool matchAndEmitInstruction(SMLoc IDLoc,
unsigned &Opcode,
132 bool MatchingInlineAsm)
override;
139#define GET_ASSEMBLER_HEADER
140#include "PPCGenAsmMatcher.inc"
150 setAvailableFeatures(ComputeAvailableFeatures(STI.
getFeatureBits()));
153 bool parseInstruction(ParseInstructionInfo &Info, StringRef Name,
156 bool ParseDirective(AsmToken DirectiveID)
override;
158 unsigned validateTargetOperandClass(MCParsedAsmOperand &
Op,
159 unsigned Kind)
override;
161 const MCExpr *applySpecifier(
const MCExpr *
E, uint32_t,
162 MCContext &Ctx)
override;
176 SMLoc StartLoc, EndLoc;
199 const MCSymbolRefExpr *Sym;
206 struct TLSRegOp TLSReg;
209 PPCOperand(KindTy K, MCContext &Ctx) : Kind(
K), Ctx(Ctx) {}
212 PPCOperand(
const PPCOperand &o) : MCParsedAsmOperand(), Ctx(
o.Ctx) {
214 StartLoc =
o.StartLoc;
222 case ContextImmediate:
236 void operator delete(
void *
p) { ::operator
delete(
p); }
239 SMLoc getStartLoc()
const override {
return StartLoc; }
242 SMLoc getEndLoc()
const override {
return EndLoc; }
246 SMRange getLocRange()
const {
return SMRange(StartLoc, EndLoc); }
249 bool isPPC64()
const {
return IsPPC64; }
252 bool isMemOpBase()
const {
return Kind == Immediate &&
Imm.IsMemOpBase; }
255 assert(Kind == Immediate &&
"Invalid access!");
258 int64_t getImmS16Context()
const {
259 assert((Kind == Immediate || Kind == ContextImmediate) &&
261 if (Kind == Immediate)
263 return static_cast<int16_t
>(
Imm.Val);
265 int64_t getImmU16Context()
const {
266 assert((Kind == Immediate || Kind == ContextImmediate) &&
271 const MCExpr *
getExpr()
const {
272 assert(Kind == Expression &&
"Invalid access!");
276 int64_t getExprCRVal()
const {
277 assert(Kind == Expression &&
"Invalid access!");
281 const MCExpr *getTLSReg()
const {
282 assert(Kind == TLSRegister &&
"Invalid access!");
289 assert(isRegNumber() &&
"Invalid access!");
290 return (
unsigned)
Imm.Val;
293 unsigned getFpReg()
const {
294 assert(isEvenRegNumber() &&
"Invalid access!");
295 return (
unsigned)(
Imm.Val >> 1);
298 unsigned getVSReg()
const {
299 assert(isVSRegNumber() &&
"Invalid access!");
300 return (
unsigned)
Imm.Val;
303 unsigned getACCReg()
const {
304 assert(isACCRegNumber() &&
"Invalid access!");
305 return (
unsigned)
Imm.Val;
308 unsigned getDMRROWReg()
const {
309 assert(isDMRROWRegNumber() &&
"Invalid access!");
310 return (
unsigned)
Imm.Val;
313 unsigned getDMRROWpReg()
const {
314 assert(isDMRROWpRegNumber() &&
"Invalid access!");
315 return (
unsigned)
Imm.Val;
318 unsigned getDMRReg()
const {
319 assert(isDMRRegNumber() &&
"Invalid access!");
320 return (
unsigned)
Imm.Val;
323 unsigned getDMRpReg()
const {
324 assert(isDMRpRegNumber() &&
"Invalid access!");
325 return (
unsigned)
Imm.Val;
328 unsigned getVSRpEvenReg()
const {
329 assert(isVSRpEvenRegNumber() &&
"Invalid access!");
330 return (
unsigned)
Imm.Val >> 1;
333 unsigned getG8pReg()
const {
334 assert(isEvenRegNumber() &&
"Invalid access!");
335 return (
unsigned)
Imm.Val;
338 unsigned getCCReg()
const {
339 assert(isCCRegNumber() &&
"Invalid access!");
340 return (
unsigned) (Kind == Immediate ?
Imm.Val : Expr.CRVal);
343 unsigned getCRBit()
const {
344 assert(isCRBitNumber() &&
"Invalid access!");
345 return (
unsigned) (Kind == Immediate ?
Imm.Val : Expr.CRVal);
348 unsigned getCRBitMask()
const {
349 assert(isCRBitMask() &&
"Invalid access!");
353 bool isToken()
const override {
return Kind == Token; }
354 bool isImm()
const override {
355 return Kind == Immediate || Kind == Expression;
358 template <u
int64_t N>
bool isUImm()
const {
361 template <u
int64_t N>
bool isSImm()
const {
364 bool isU6ImmX2()
const {
return isUImm<6>() && (
getImm() & 1) == 0; }
365 bool isU7ImmX4()
const {
return isUImm<7>() && (
getImm() & 3) == 0; }
366 bool isU8ImmX8()
const {
return isUImm<8>() && (
getImm() & 7) == 0; }
368 bool isU16Imm()
const {
return isExtImm<16>(
false, 1); }
369 bool isS16Imm()
const {
return isExtImm<16>(
true, 1); }
370 bool isS16ImmX4()
const {
return isExtImm<16>(
true, 4); }
371 bool isS16ImmX16()
const {
return isExtImm<16>(
true, 16); }
372 bool isS17Imm()
const {
return isExtImm<17>(
true, 1); }
373 bool isS32Imm()
const {
375 return Kind == Expression || isSImm<32>();
377 bool isS34Imm()
const {
380 return Kind == Expression || isSImm<34>();
382 bool isS34ImmX16()
const {
383 return Kind == Expression || (isSImm<34>() && (
getImm() & 15) == 0);
386 bool isHashImmX8()
const {
390 return (Kind == Immediate &&
getImm() <= -8 &&
getImm() >= -512 &&
394 bool isTLSReg()
const {
return Kind == TLSRegister; }
395 bool isDirectBr()
const {
396 if (Kind == Expression)
398 if (Kind != Immediate)
412 bool isCondBr()
const {
return Kind == Expression ||
415 bool isImmZero()
const {
return Kind == Immediate &&
getImm() == 0; }
416 bool isRegNumber()
const {
return Kind == Immediate &&
isUInt<5>(
getImm()); }
417 bool isACCRegNumber()
const {
420 bool isDMRROWRegNumber()
const {
423 bool isDMRROWpRegNumber()
const {
426 bool isDMRRegNumber()
const {
429 bool isDMRpRegNumber()
const {
432 bool isVSRpEvenRegNumber()
const {
435 bool isVSRegNumber()
const {
438 bool isCCRegNumber()
const {
return (Kind == Expression
442 bool isCRBitNumber()
const {
return (Kind == Expression
447 bool isEvenRegNumber()
const {
return isRegNumber() && (
getImm() & 1) == 0; }
449 bool isCRBitMask()
const {
453 bool isATBitsAsHint()
const {
return false; }
454 bool isMem()
const override {
return false; }
455 bool isReg()
const override {
return false; }
457 void addRegOperands(MCInst &Inst,
unsigned N)
const {
461 void addRegGPRCOperands(MCInst &Inst,
unsigned N)
const {
462 assert(
N == 1 &&
"Invalid number of operands!");
466 void addRegGPRC_NOR0Operands(MCInst &Inst,
unsigned N)
const {
467 assert(
N == 1 &&
"Invalid number of operands!");
471 void addRegG8RCOperands(MCInst &Inst,
unsigned N)
const {
472 assert(
N == 1 &&
"Invalid number of operands!");
476 void addRegG8RC_NOX0Operands(MCInst &Inst,
unsigned N)
const {
477 assert(
N == 1 &&
"Invalid number of operands!");
481 void addRegG8pRCOperands(MCInst &Inst,
unsigned N)
const {
482 assert(
N == 1 &&
"Invalid number of operands!");
486 void addRegGxRCOperands(MCInst &Inst,
unsigned N)
const {
488 addRegG8RCOperands(Inst,
N);
490 addRegGPRCOperands(Inst,
N);
493 void addRegGxRCNoR0Operands(MCInst &Inst,
unsigned N)
const {
495 addRegG8RC_NOX0Operands(Inst,
N);
497 addRegGPRC_NOR0Operands(Inst,
N);
500 void addRegF4RCOperands(MCInst &Inst,
unsigned N)
const {
501 assert(
N == 1 &&
"Invalid number of operands!");
505 void addRegF8RCOperands(MCInst &Inst,
unsigned N)
const {
506 assert(
N == 1 &&
"Invalid number of operands!");
510 void addRegFpRCOperands(MCInst &Inst,
unsigned N)
const {
511 assert(
N == 1 &&
"Invalid number of operands!");
515 void addRegVFRCOperands(MCInst &Inst,
unsigned N)
const {
516 assert(
N == 1 &&
"Invalid number of operands!");
520 void addRegVRRCOperands(MCInst &Inst,
unsigned N)
const {
521 assert(
N == 1 &&
"Invalid number of operands!");
525 void addRegVSRCOperands(MCInst &Inst,
unsigned N)
const {
526 assert(
N == 1 &&
"Invalid number of operands!");
530 void addRegVSFRCOperands(MCInst &Inst,
unsigned N)
const {
531 assert(
N == 1 &&
"Invalid number of operands!");
535 void addRegVSSRCOperands(MCInst &Inst,
unsigned N)
const {
536 assert(
N == 1 &&
"Invalid number of operands!");
540 void addRegSPE4RCOperands(MCInst &Inst,
unsigned N)
const {
541 assert(
N == 1 &&
"Invalid number of operands!");
545 void addRegSPERCOperands(MCInst &Inst,
unsigned N)
const {
546 assert(
N == 1 &&
"Invalid number of operands!");
550 void addRegACCRCOperands(MCInst &Inst,
unsigned N)
const {
551 assert(
N == 1 &&
"Invalid number of operands!");
555 void addRegDMRROWRCOperands(MCInst &Inst,
unsigned N)
const {
556 assert(
N == 1 &&
"Invalid number of operands!");
560 void addRegDMRROWpRCOperands(MCInst &Inst,
unsigned N)
const {
561 assert(
N == 1 &&
"Invalid number of operands!");
565 void addRegDMRRCOperands(MCInst &Inst,
unsigned N)
const {
566 assert(
N == 1 &&
"Invalid number of operands!");
570 void addRegDMRpRCOperands(MCInst &Inst,
unsigned N)
const {
571 assert(
N == 1 &&
"Invalid number of operands!");
575 void addRegWACCRCOperands(MCInst &Inst,
unsigned N)
const {
576 assert(
N == 1 &&
"Invalid number of operands!");
580 void addRegWACC_HIRCOperands(MCInst &Inst,
unsigned N)
const {
581 assert(
N == 1 &&
"Invalid number of operands!");
585 void addRegVSRpRCOperands(MCInst &Inst,
unsigned N)
const {
586 assert(
N == 1 &&
"Invalid number of operands!");
590 void addRegVSRpEvenRCOperands(MCInst &Inst,
unsigned N)
const {
591 assert(
N == 1 &&
"Invalid number of operands!");
595 void addRegCRBITRCOperands(MCInst &Inst,
unsigned N)
const {
596 assert(
N == 1 &&
"Invalid number of operands!");
600 void addRegCRRCOperands(MCInst &Inst,
unsigned N)
const {
601 assert(
N == 1 &&
"Invalid number of operands!");
605 void addCRBitMaskOperands(MCInst &Inst,
unsigned N)
const {
606 assert(
N == 1 &&
"Invalid number of operands!");
610 void addImmOperands(MCInst &Inst,
unsigned N)
const {
611 assert(
N == 1 &&
"Invalid number of operands!");
612 if (Kind == Immediate)
618 void addS16ImmOperands(MCInst &Inst,
unsigned N)
const {
619 assert(
N == 1 &&
"Invalid number of operands!");
624 case ContextImmediate:
633 void addU16ImmOperands(MCInst &Inst,
unsigned N)
const {
634 assert(
N == 1 &&
"Invalid number of operands!");
639 case ContextImmediate:
648 void addNegImmOperands(MCInst &Inst,
unsigned N)
const {
649 assert(
N == 1 &&
"Invalid number of operands!");
651 if (Kind == Immediate) {
661 void addBranchTargetOperands(MCInst &Inst,
unsigned N)
const {
662 assert(
N == 1 &&
"Invalid number of operands!");
663 if (Kind == Immediate)
669 void addTLSRegOperands(MCInst &Inst,
unsigned N)
const {
670 assert(
N == 1 &&
"Invalid number of operands!");
675 assert(Kind == Token &&
"Invalid access!");
676 return StringRef(Tok.Data, Tok.Length);
679 void print(raw_ostream &OS,
const MCAsmInfo &MAI)
const override;
681 static std::unique_ptr<PPCOperand>
682 CreateToken(StringRef Str, SMLoc S,
bool IsPPC64, MCContext &Ctx) {
683 auto Op = std::make_unique<PPCOperand>(Token, Ctx);
684 Op->Tok.Data = Str.data();
685 Op->Tok.Length = Str.size();
688 Op->IsPPC64 = IsPPC64;
692 static std::unique_ptr<PPCOperand>
693 CreateTokenWithStringCopy(StringRef Str, SMLoc S,
bool IsPPC64,
700 void *Mem = ::operator
new(
sizeof(PPCOperand) + Str.size());
701 std::unique_ptr<PPCOperand>
Op(
new (Mem) PPCOperand(Token, Ctx));
702 Op->Tok.Data =
reinterpret_cast<const char *
>(
Op.get() + 1);
703 Op->Tok.Length = Str.size();
704 std::memcpy(
const_cast<char *
>(
Op->Tok.Data), Str.data(), Str.size());
707 Op->IsPPC64 = IsPPC64;
711 static std::unique_ptr<PPCOperand> CreateImm(int64_t Val, SMLoc S, SMLoc
E,
712 bool IsPPC64, MCContext &Ctx,
713 bool IsMemOpBase =
false) {
714 auto Op = std::make_unique<PPCOperand>(Immediate, Ctx);
716 Op->Imm.IsMemOpBase = IsMemOpBase;
719 Op->IsPPC64 = IsPPC64;
723 static std::unique_ptr<PPCOperand> CreateExpr(
const MCExpr *Val, SMLoc S,
724 SMLoc
E,
bool IsPPC64,
726 auto Op = std::make_unique<PPCOperand>(Expression, Ctx);
731 Op->IsPPC64 = IsPPC64;
735 static std::unique_ptr<PPCOperand> CreateTLSReg(
const MCSymbolRefExpr *Sym,
739 auto Op = std::make_unique<PPCOperand>(TLSRegister, Ctx);
740 Op->TLSReg.Sym = Sym;
743 Op->IsPPC64 = IsPPC64;
747 static std::unique_ptr<PPCOperand>
748 CreateContextImm(int64_t Val, SMLoc S, SMLoc
E,
bool IsPPC64,
750 auto Op = std::make_unique<PPCOperand>(ContextImmediate, Ctx);
754 Op->IsPPC64 = IsPPC64;
758 static std::unique_ptr<PPCOperand>
759 CreateFromMCExpr(
const MCExpr *Val, SMLoc S, SMLoc
E,
bool IsPPC64,
762 return CreateImm(
CE->getValue(), S,
E, IsPPC64, Ctx);
767 return CreateTLSReg(SRE, S,
E, IsPPC64, Ctx);
772 return CreateContextImm(Res, S,
E, IsPPC64, Ctx);
775 return CreateExpr(Val, S,
E, IsPPC64, Ctx);
779 template <
unsigned W
idth>
780 bool isExtImm(
bool Signed,
unsigned Multiple)
const {
787 case ContextImmediate:
790 (getImmS16Context() & (Multiple - 1)) == 0;
793 (getImmU16Context() & (Multiple - 1)) == 0;
806 case ContextImmediate:
837 BinExpr->getLHS(), Ctx);
845void PPCAsmParser::processInstruction(MCInst &Inst,
854 TmpInst.
setOpcode((Opcode == PPC::DCBTx || Opcode == PPC::DCBTT) ?
855 PPC::DCBT : PPC::DCBTST);
857 (Opcode == PPC::DCBTx || Opcode == PPC::DCBTSTx) ? 0 : 16));
874 case PPC::DCBTSTDS: {
889 if (Opcode == PPC::DCBFL)
891 else if (Opcode == PPC::DCBFLP)
893 else if (Opcode == PPC::DCBFPS)
895 else if (Opcode == PPC::DCBSTPS)
918 TmpInst.
setOpcode(Opcode == PPC::PLA ? PPC::PADDI : PPC::PADDI8);
928 TmpInst.
setOpcode(Opcode == PPC::PLApc ? PPC::PADDIpc : PPC::PADDI8pc);
971 case PPC::SUBIC_rec: {
981 case PPC::EXTLWI_rec: {
985 TmpInst.
setOpcode(Opcode == PPC::EXTLWI ? PPC::RLWINM : PPC::RLWINM_rec);
995 case PPC::EXTRWI_rec: {
999 TmpInst.
setOpcode(Opcode == PPC::EXTRWI ? PPC::RLWINM : PPC::RLWINM_rec);
1009 case PPC::INSLWI_rec: {
1013 TmpInst.
setOpcode(Opcode == PPC::INSLWI ? PPC::RLWIMI : PPC::RLWIMI_rec);
1024 case PPC::INSRWI_rec: {
1028 TmpInst.
setOpcode(Opcode == PPC::INSRWI ? PPC::RLWIMI : PPC::RLWIMI_rec);
1039 case PPC::ROTRWI_rec: {
1042 TmpInst.
setOpcode(Opcode == PPC::ROTRWI ? PPC::RLWINM : PPC::RLWINM_rec);
1052 case PPC::SLWI_rec: {
1055 TmpInst.
setOpcode(Opcode == PPC::SLWI ? PPC::RLWINM : PPC::RLWINM_rec);
1065 case PPC::SRWI_rec: {
1068 TmpInst.
setOpcode(Opcode == PPC::SRWI ? PPC::RLWINM : PPC::RLWINM_rec);
1078 case PPC::CLRRWI_rec: {
1081 TmpInst.
setOpcode(Opcode == PPC::CLRRWI ? PPC::RLWINM : PPC::RLWINM_rec);
1091 case PPC::CLRLSLWI_rec: {
1095 TmpInst.
setOpcode(Opcode == PPC::CLRLSLWI ? PPC::RLWINM : PPC::RLWINM_rec);
1105 case PPC::EXTLDI_rec: {
1109 TmpInst.
setOpcode(Opcode == PPC::EXTLDI ? PPC::RLDICR : PPC::RLDICR_rec);
1118 case PPC::EXTRDI_rec: {
1122 TmpInst.
setOpcode(Opcode == PPC::EXTRDI ? PPC::RLDICL : PPC::RLDICL_rec);
1131 case PPC::INSRDI_rec: {
1135 TmpInst.
setOpcode(Opcode == PPC::INSRDI ? PPC::RLDIMI : PPC::RLDIMI_rec);
1145 case PPC::ROTRDI_rec: {
1148 TmpInst.
setOpcode(Opcode == PPC::ROTRDI ? PPC::RLDICL : PPC::RLDICL_rec);
1157 case PPC::SLDI_rec: {
1160 TmpInst.
setOpcode(Opcode == PPC::SLDI ? PPC::RLDICR : PPC::RLDICR_rec);
1168 case PPC::SUBPCIS: {
1178 case PPC::SRDI_rec: {
1181 TmpInst.
setOpcode(Opcode == PPC::SRDI ? PPC::RLDICL : PPC::RLDICL_rec);
1190 case PPC::CLRRDI_rec: {
1193 TmpInst.
setOpcode(Opcode == PPC::CLRRDI ? PPC::RLDICR : PPC::RLDICR_rec);
1202 case PPC::CLRLSLDI_rec: {
1206 TmpInst.
setOpcode(Opcode == PPC::CLRLSLDI ? PPC::RLDIC : PPC::RLDIC_rec);
1215 case PPC::RLWINMbm_rec: {
1222 TmpInst.
setOpcode(Opcode == PPC::RLWINMbm ? PPC::RLWINM : PPC::RLWINM_rec);
1232 case PPC::RLWIMIbm_rec: {
1239 TmpInst.
setOpcode(Opcode == PPC::RLWIMIbm ? PPC::RLWIMI : PPC::RLWIMI_rec);
1250 case PPC::RLWNMbm_rec: {
1257 TmpInst.
setOpcode(Opcode == PPC::RLWNMbm ? PPC::RLWNM : PPC::RLWNM_rec);
1267 if (getSTI().hasFeature(PPC::FeatureMFTB)) {
1277 unsigned VariantID = 0);
1283 for (
size_t idx = 0; idx < Operands.
size(); ++idx) {
1284 const PPCOperand &
Op =
static_cast<const PPCOperand &
>(*Operands[idx]);
1285 if (
Op.isMemOpBase() != (idx == 3 && isMemriOp))
1291bool PPCAsmParser::matchAndEmitInstruction(SMLoc IDLoc,
unsigned &Opcode,
1293 MCStreamer &Out, uint64_t &ErrorInfo,
1294 bool MatchingInlineAsm) {
1296 const PPCInstrInfo *
TII =
static_cast<const PPCInstrInfo *
>(&MII);
1298 switch (MatchInstructionImpl(Operands, Inst, ErrorInfo, MatchingInlineAsm)) {
1301 return Error(IDLoc,
"invalid operand for instruction");
1303 processInstruction(Inst, Operands);
1307 case Match_MissingFeature:
1308 return Error(IDLoc,
"instruction use requires an option to be enabled");
1309 case Match_MnemonicFail: {
1310 FeatureBitset FBS = ComputeAvailableFeatures(getSTI().getFeatureBits());
1312 ((PPCOperand &)*Operands[0]).
getToken(), FBS);
1313 return Error(IDLoc,
"invalid instruction" + Suggestion,
1314 ((PPCOperand &)*Operands[0]).getLocRange());
1316 case Match_InvalidOperand: {
1317 SMLoc ErrorLoc = IDLoc;
1318 if (ErrorInfo != ~0ULL) {
1319 if (ErrorInfo >= Operands.size())
1320 return Error(IDLoc,
"too few operands for instruction");
1322 ErrorLoc = ((PPCOperand &)*Operands[ErrorInfo]).getStartLoc();
1323 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
1326 return Error(ErrorLoc,
"invalid operand for instruction");
1333#define GET_REGISTER_MATCHER
1334#include "PPCGenAsmMatcher.inc"
1336MCRegister PPCAsmParser::matchRegisterName(int64_t &IntVal) {
1345 std::string NameBuf = getParser().getTok().getString().lower();
1351 Name.substr(Name.find_first_of(
"1234567890")).getAsInteger(10, IntVal);
1356 RegNo = isPPC64() ? PPC::LR8 : PPC::LR;
1358 }
else if (Name ==
"ctr") {
1359 RegNo = isPPC64() ? PPC::CTR8 : PPC::CTR;
1361 }
else if (Name ==
"vrsave")
1363 else if (Name.starts_with(
"r"))
1364 RegNo = isPPC64() ? XRegs[IntVal] : RRegs[IntVal];
1370bool PPCAsmParser::parseRegister(MCRegister &
Reg, SMLoc &StartLoc,
1372 if (!tryParseRegister(
Reg, StartLoc, EndLoc).isSuccess())
1373 return TokError(
"invalid register name");
1377ParseStatus PPCAsmParser::tryParseRegister(MCRegister &
Reg, SMLoc &StartLoc,
1379 const AsmToken &Tok = getParser().getTok();
1383 if (!(
Reg = matchRegisterName(IntVal)))
1391const MCExpr *PPCAsmParser::extractSpecifier(
const MCExpr *
E,
1393 MCContext &
Context = getParser().getContext();
1394 switch (
E->getKind()) {
1400 Spec =
TE->getSpecifier();
1401 (void)extractSpecifier(
TE->getSubExpr(), Spec);
1423 Error(
E->getLoc(),
"cannot contain more than one relocation specifier");
1431 const MCExpr *
Sub = extractSpecifier(UE->
getSubExpr(), Spec);
1439 const MCExpr *
LHS = extractSpecifier(BE->
getLHS(), Spec);
1440 const MCExpr *
RHS = extractSpecifier(BE->
getRHS(), Spec);
1454bool PPCAsmParser::parseExpression(
const MCExpr *&EVal) {
1457 if (getParser().parseExpression(EVal))
1461 const MCExpr *
E = extractSpecifier(EVal, Spec);
1471 MCAsmParser &Parser = getParser();
1477 switch (getLexer().getKind()) {
1482 if (!matchRegisterName(IntVal))
1483 return Error(S,
"invalid register name");
1486 PPCOperand::CreateImm(IntVal, S,
E, isPPC64(),
getContext()));
1498 if (!parseExpression(EVal))
1503 return Error(S,
"unknown operand");
1508 PPCOperand::CreateFromMCExpr(EVal, S,
E, isPPC64(),
getContext()));
1511 const char TlsGetAddr[] =
"__tls_get_addr";
1512 bool TlsCall =
false;
1513 const MCExpr *TlsCallAddend =
nullptr;
1515 TlsCall =
Ref->getSymbol().getName() == TlsGetAddr;
1519 TlsCall =
Ref->getSymbol().getName() == TlsGetAddr;
1520 TlsCallAddend =
Bin->getRHS();
1525 const MCExpr *TLSSym;
1527 if (parseExpression(TLSSym))
1528 return Error(S2,
"invalid TLS call expression");
1534 AsmToken Tok = getTok();
1541 const MCExpr *Addend =
nullptr;
1543 if (parsePrimaryExpr(Addend, EndLoc))
1549 TlsCallAddend = Addend;
1554 Operands.
back() = PPCOperand::CreateFromMCExpr(
1559 PPCOperand::CreateFromMCExpr(TLSSym, S,
E, isPPC64(),
getContext()));
1567 switch (getLexer().getKind()) {
1569 if (!matchRegisterName(IntVal))
1570 return Error(S,
"invalid register name");
1574 if (getParser().parseAbsoluteExpression(IntVal) || IntVal < 0 ||
1576 return Error(S,
"invalid register number");
1580 return Error(S,
"invalid memory operand");
1586 Operands.
push_back(PPCOperand::CreateImm(
1594bool PPCAsmParser::parseInstruction(ParseInstructionInfo &Info, StringRef Name,
1599 std::string NewOpcode;
1601 NewOpcode = std::string(Name);
1606 NewOpcode = std::string(Name);
1612 size_t Dot =
Name.find(
'.');
1613 StringRef Mnemonic =
Name.slice(0, Dot);
1614 if (!NewOpcode.empty())
1615 Operands.
push_back(PPCOperand::CreateTokenWithStringCopy(
1616 Mnemonic, NameLoc, isPPC64(),
getContext()));
1619 PPCOperand::CreateToken(Mnemonic, NameLoc, isPPC64(),
getContext()));
1622 StringRef DotStr =
Name.substr(Dot);
1623 if (!NewOpcode.empty())
1624 Operands.
push_back(PPCOperand::CreateTokenWithStringCopy(
1628 PPCOperand::CreateToken(DotStr, DotLoc, isPPC64(),
getContext()));
1636 if (parseOperand(Operands))
1652 if (getSTI().hasFeature(PPC::FeatureBookE) &&
1653 Operands.
size() == 4 &&
1654 (Name ==
"dcbt" || Name ==
"dcbtst")) {
1660 if (Name ==
"lqarx" || Name ==
"ldarx" || Name ==
"lwarx" ||
1661 Name ==
"lharx" || Name ==
"lbarx") {
1662 if (Operands.
size() != 5)
1664 PPCOperand &EHOp = (PPCOperand &)*Operands[4];
1665 if (EHOp.isUImm<1>() && EHOp.getImm() == 0)
1673bool PPCAsmParser::ParseDirective(AsmToken DirectiveID) {
1675 if (IDVal ==
".word")
1676 parseDirectiveWord(2, DirectiveID);
1677 else if (IDVal ==
".llong")
1678 parseDirectiveWord(8, DirectiveID);
1679 else if (IDVal ==
".tc")
1680 parseDirectiveTC(isPPC64() ? 8 : 4, DirectiveID);
1681 else if (IDVal ==
".machine")
1682 parseDirectiveMachine(DirectiveID.
getLoc());
1683 else if (IDVal ==
".abiversion")
1684 parseDirectiveAbiVersion(DirectiveID.
getLoc());
1685 else if (IDVal ==
".localentry")
1686 parseDirectiveLocalEntry(DirectiveID.
getLoc());
1688 parseGNUAttribute(DirectiveID.
getLoc());
1695bool PPCAsmParser::parseDirectiveWord(
unsigned Size, AsmToken
ID) {
1696 auto parseOp = [&]() ->
bool {
1697 const MCExpr *
Value;
1698 SMLoc ExprLoc = getParser().getTok().getLoc();
1699 if (getParser().parseExpression(
Value))
1703 uint64_t IntValue = MCE->getValue();
1705 return Error(ExprLoc,
"literal value out of range for '" +
1706 ID.getIdentifier() +
"' directive");
1707 getStreamer().emitIntValue(IntValue,
Size);
1709 getStreamer().emitValue(
Value,
Size, ExprLoc);
1713 if (parseMany(parseOp))
1714 return addErrorSuffix(
" in '" +
ID.getIdentifier() +
"' directive");
1719bool PPCAsmParser::parseDirectiveTC(
unsigned Size, AsmToken
ID) {
1720 MCAsmParser &Parser = getParser();
1726 return addErrorSuffix(
" in '.tc' directive");
1729 getParser().getStreamer().emitValueToAlignment(
Align(
Size));
1732 return parseDirectiveWord(
Size,
ID);
1737bool PPCAsmParser::parseDirectiveMachine(SMLoc L) {
1738 MCAsmParser &Parser = getParser();
1741 return Error(L,
"unexpected token in '.machine' directive");
1752 return addErrorSuffix(
" in '.machine' directive");
1754 PPCTargetStreamer *TStreamer =
static_cast<PPCTargetStreamer *
>(
1755 getParser().getStreamer().getTargetStreamer());
1756 if (TStreamer !=
nullptr)
1763bool PPCAsmParser::parseDirectiveAbiVersion(SMLoc L) {
1765 if (check(getParser().parseAbsoluteExpression(AbiVersion), L,
1766 "expected constant expression") ||
1768 return addErrorSuffix(
" in '.abiversion' directive");
1770 PPCTargetStreamer *TStreamer =
static_cast<PPCTargetStreamer *
>(
1771 getParser().getStreamer().getTargetStreamer());
1772 if (TStreamer !=
nullptr)
1779bool PPCAsmParser::parseDirectiveLocalEntry(SMLoc L) {
1781 if (getParser().parseIdentifier(Name))
1782 return Error(L,
"expected identifier in '.localentry' directive");
1784 auto *Sym =
static_cast<MCSymbolELF *
>(
getContext().getOrCreateSymbol(Name));
1788 check(getParser().parseExpression(Expr), L,
"expected expression") ||
1790 return addErrorSuffix(
" in '.localentry' directive");
1792 PPCTargetStreamer *TStreamer =
static_cast<PPCTargetStreamer *
>(
1793 getParser().getStreamer().getTargetStreamer());
1794 if (TStreamer !=
nullptr)
1800bool PPCAsmParser::parseGNUAttribute(SMLoc L) {
1802 int64_t IntegerValue;
1803 if (!getParser().parseGNUAttribute(L,
Tag, IntegerValue))
1806 getParser().getStreamer().emitGNUAttribute(
Tag, IntegerValue);
1820#define GET_MATCHER_IMPLEMENTATION
1821#define GET_MNEMONIC_SPELL_CHECKER
1822#include "PPCGenAsmMatcher.inc"
1833 case MCK_0: ImmVal = 0;
break;
1834 case MCK_1: ImmVal = 1;
break;
1835 case MCK_2: ImmVal = 2;
break;
1836 case MCK_3: ImmVal = 3;
break;
1837 case MCK_4: ImmVal = 4;
break;
1838 case MCK_5: ImmVal = 5;
break;
1839 case MCK_6: ImmVal = 6;
break;
1840 case MCK_7: ImmVal = 7;
break;
1841 default:
return Match_InvalidOperand;
1844 PPCOperand &
Op =
static_cast<PPCOperand &
>(AsmOp);
1845 if (
Op.isUImm<3>() &&
Op.getImm() == ImmVal)
1846 return Match_Success;
1848 return Match_InvalidOperand;
1851const MCExpr *PPCAsmParser::applySpecifier(
const MCExpr *
E, uint32_t Spec,
static MCRegister MatchRegisterName(StringRef Name)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static bool getRegNum(StringRef Str, unsigned &Num)
static bool isNot(const MachineRegisterInfo &MRI, const MachineInstr &MI)
static AMDGPUMCExpr::Specifier getSpecifier(unsigned MOFlags)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_EXTERNAL_VISIBILITY
const HexagonInstrInfo * TII
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
static MCRegister getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
static bool isReg(const MCInst &MI, unsigned OpNo)
static bool validateMemOp(const OperandVector &Operands, bool isMemriOp)
LLVM_ABI LLVM_EXTERNAL_VISIBILITY void LLVMInitializePowerPCAsmParser()
Force static initialization.
static DEFINE_PPC_REGCLASSES int64_t EvaluateCRExpr(const MCExpr *E)
static void addNegOperand(MCInst &Inst, MCOperand &Op, MCContext &Ctx)
static std::string PPCMnemonicSpellCheck(StringRef S, const FeatureBitset &FBS, unsigned VariantID=0)
#define DEFINE_PPC_REGCLASSES
LLVM_ABI SMLoc getLoc() const
bool isNot(TokenKind K) const
StringRef getString() const
Get the string for the current token, this includes all characters (for example, the quotes on string...
LLVM_ABI SMLoc getEndLoc() const
StringRef getIdentifier() const
Get the identifier string for the current token, which should be an identifier or a string.
Container class for subtarget features.
This class is intended to be used as a base class for asm properties and features specific to the tar...
void printExpr(raw_ostream &, const MCExpr &) const
bool Warning(SMLoc L, const Twine &Msg)
Generic assembler parser interface, for use by target specific assembly parsers.
const AsmToken & getTok() const
Get the current AsmToken from the stream.
virtual const AsmToken & Lex()=0
Get the next AsmToken in the stream, possibly handling file inclusion first.
Binary assembler expressions.
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
Opcode getOpcode() const
Get the kind of this binary expression.
static LLVM_ABI const MCBinaryExpr * create(Opcode Op, const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Context object for machine code objects.
Base class for the full range of assembler expressions which are needed for parsing.
@ Unary
Unary expressions.
@ Constant
Constant expressions.
@ SymbolRef
References to labels and assigned expressions.
@ Target
Target specific expression.
@ Specifier
Expression with a relocation specifier.
@ Binary
Binary expressions.
Instances of this class represent a single low-level machine instruction.
unsigned getNumOperands() const
unsigned getOpcode() const
void addOperand(const MCOperand Op)
void setOpcode(unsigned Op)
const MCOperand & getOperand(unsigned i) const
Interface to description of machine instruction set.
Instances of this class represent operands of the MCInst class.
static MCOperand createExpr(const MCExpr *Val)
static MCOperand createReg(MCRegister Reg)
static MCOperand createImm(int64_t Val)
MCParsedAsmOperand - This abstract class represents a source-level assembly instruction operand.
Wrapper class representing physical registers. Should be passed by value.
static const MCSpecifierExpr * create(const MCExpr *Expr, Spec S, MCContext &Ctx, SMLoc Loc=SMLoc())
virtual void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI)
Emit the given Instruction into the current section.
Generic base class for all target subtargets.
const FeatureBitset & getFeatureBits() const
Represent a reference to a symbol from inside an expression.
const MCSymbol & getSymbol() const
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
StringRef getName() const
getName - Get the symbol name.
MCTargetAsmParser - Generic interface to target specific assembly parsers.
Unary assembler expressions.
Opcode getOpcode() const
Get the kind of this unary expression.
static LLVM_ABI const MCUnaryExpr * create(Opcode Op, const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
const MCExpr * getSubExpr() const
Get the child of this unary expression.
static const MCUnaryExpr * createMinus(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
virtual void emitAbiVersion(int AbiVersion)
virtual void emitLocalEntry(MCSymbolELF *S, const MCExpr *LocalOffset)
virtual void emitMachine(StringRef CPU)
static constexpr StatusTy Success
static constexpr StatusTy NoMatch
static SMLoc getFromPointer(const char *Ptr)
constexpr const char * getPointer() const
void push_back(const T &Elt)
StringRef - Represent a constant reference to a string, i.e.
static constexpr size_t npos
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
LLVM_ABI int compare_insensitive(StringRef RHS) const
Compare two strings, ignoring case.
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
MCExpr const & getExpr(MCExpr const &Expr)
bool evaluateAsConstant(const MCSpecifierExpr &Expr, int64_t &Res)
@ CE
Windows NT (Windows on ARM)
Context & getContext() const
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value
Target & getThePPC64LETarget()
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr, unsigned DynamicVGPRBlockSize=0)
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
static bool isMem(const MachineInstr &MI, unsigned Op)
LLVM_ABI std::pair< StringRef, StringRef > getToken(StringRef Source, StringRef Delimiters=" \t\n\v\f\r")
getToken - This function extracts one token from source, ignoring any leading characters that appear ...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
constexpr bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
Target & getThePPC32Target()
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
constexpr bool has_single_bit(T Value) noexcept
SmallVectorImpl< std::unique_ptr< MCParsedAsmOperand > > OperandVector
MachineInstr * getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
@ Ref
The access may reference the value stored in memory.
Target & getThePPC64Target()
@ Sub
Subtraction of integers.
DWARFExpression::Operation Op
Target & getThePPC32LETarget()
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
constexpr bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
static uint16_t getSpecifier(const MCSymbolRefExpr *SRE)
static bool isRunOfOnes(unsigned Val, unsigned &MB, unsigned &ME)
Returns true iff Val consists of one contiguous run of 1s with any number of 0s on either side.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
RegisterMCAsmParser - Helper template for registering a target specific assembly parser,...