64 enum class TailRelocKind { Load_GOT, Add_TLS, Load_TLS, Call_TLS };
69#define GET_ASSEMBLER_HEADER
70#include "SparcGenAsmMatcher.inc"
75 bool matchAndEmitInstruction(
SMLoc IDLoc,
unsigned &Opcode,
78 bool MatchingInlineAsm)
override;
81 SMLoc &EndLoc)
override;
85 bool parseExprWithSpecifier(
const MCExpr *&Res,
SMLoc &
E);
86 bool parseDataExpr(
const MCExpr *&Res)
override;
97 template <TailRelocKind Kind>
106 ParseStatus parseSparcAsmOperand(std::unique_ptr<SparcOperand> &Operand);
117 bool isPossibleExpression(
const AsmToken &Token);
120 MatchResultTy mnemonicIsValid(
StringRef Mnemonic,
unsigned VariantID);
127 bool is64Bit()
const {
return getSTI().getTargetTriple().isSPARC64(); }
129 bool expandSET(MCInst &Inst, SMLoc IDLoc,
130 SmallVectorImpl<MCInst> &Instructions);
132 bool expandSETSW(MCInst &Inst, SMLoc IDLoc,
133 SmallVectorImpl<MCInst> &Instructions);
135 bool expandSETX(MCInst &Inst, SMLoc IDLoc,
136 SmallVectorImpl<MCInst> &Instructions);
138 SMLoc getLoc()
const {
return getParser().getTok().getLoc(); }
141 SparcAsmParser(
const MCSubtargetInfo &sti, MCAsmParser &parser,
142 const MCInstrInfo &MII)
143 : MCTargetAsmParser(sti, MII), Parser(parser),
145 Parser.addAliasForDirective(
".half",
".2byte");
146 Parser.addAliasForDirective(
".uahalf",
".2byte");
147 Parser.addAliasForDirective(
".word",
".4byte");
148 Parser.addAliasForDirective(
".uaword",
".4byte");
149 Parser.addAliasForDirective(
".nword",
is64Bit() ?
".8byte" :
".4byte");
151 Parser.addAliasForDirective(
".xword",
".8byte");
154 setAvailableFeatures(ComputeAvailableFeatures(getSTI().getFeatureBits()));
161 Sparc::G0, Sparc::G1, Sparc::G2, Sparc::G3,
162 Sparc::G4, Sparc::G5, Sparc::G6, Sparc::G7,
163 Sparc::O0, Sparc::O1, Sparc::O2, Sparc::O3,
164 Sparc::O4, Sparc::O5, Sparc::O6, Sparc::O7,
165 Sparc::L0, Sparc::L1, Sparc::L2, Sparc::L3,
166 Sparc::L4, Sparc::L5, Sparc::L6, Sparc::L7,
167 Sparc::I0, Sparc::I1, Sparc::I2, Sparc::I3,
168 Sparc::I4, Sparc::I5, Sparc::I6, Sparc::I7 };
194 SMLoc StartLoc, EndLoc;
212 MCRegister OffsetReg;
226 SparcOperand(KindTy K) : Kind(
K) {}
228 bool isToken()
const override {
return Kind == k_Token; }
229 bool isReg()
const override {
return Kind == k_Register; }
230 bool isImm()
const override {
return Kind == k_Immediate; }
231 bool isMem()
const override {
return isMEMrr() || isMEMri(); }
232 bool isMEMrr()
const {
return Kind == k_MemoryReg; }
233 bool isMEMri()
const {
return Kind == k_MemoryImm; }
234 bool isMembarTag()
const {
return Kind == k_Immediate; }
235 bool isASITag()
const {
return Kind == k_ASITag; }
236 bool isPrefetchTag()
const {
return Kind == k_PrefetchTag; }
237 bool isTailRelocSym()
const {
return Kind == k_TailRelocSym; }
239 bool isCallTarget()
const {
244 return CE->getValue() % 4 == 0;
249 bool isShiftAmtImm5()
const {
259 bool isShiftAmtImm6()
const {
270 return (Kind == k_Register &&
Reg.Kind == rk_IntReg);
274 assert(Kind == k_Token &&
"Invalid access!");
275 return StringRef(Tok.Data, Tok.Length);
278 MCRegister
getReg()
const override {
279 assert((Kind == k_Register) &&
"Invalid access!");
283 const MCExpr *
getImm()
const {
284 assert((Kind == k_Immediate) &&
"Invalid access!");
288 MCRegister getMemBase()
const {
289 assert((Kind == k_MemoryReg || Kind == k_MemoryImm) &&
"Invalid access!");
293 MCRegister getMemOffsetReg()
const {
294 assert((Kind == k_MemoryReg) &&
"Invalid access!");
295 return Mem.OffsetReg;
298 const MCExpr *getMemOff()
const {
299 assert((Kind == k_MemoryImm) &&
"Invalid access!");
303 unsigned getASITag()
const {
304 assert((Kind == k_ASITag) &&
"Invalid access!");
308 unsigned getPrefetchTag()
const {
309 assert((Kind == k_PrefetchTag) &&
"Invalid access!");
313 const MCExpr *getTailRelocSym()
const {
314 assert((Kind == k_TailRelocSym) &&
"Invalid access!");
319 SMLoc getStartLoc()
const override {
323 SMLoc getEndLoc()
const override {
327 void print(raw_ostream &OS,
const MCAsmInfo &MAI)
const override {
329 case k_Token: OS <<
"Token: " <<
getToken() <<
"\n";
break;
331 OS <<
"Reg: #" <<
getReg().
id() <<
"\n";
333 case k_Immediate: OS <<
"Imm: " <<
getImm() <<
"\n";
break;
335 OS <<
"Mem: " << getMemBase().id() <<
"+" << getMemOffsetReg().id()
338 case k_MemoryImm:
assert(getMemOff() !=
nullptr);
339 OS <<
"Mem: " << getMemBase().id() <<
"+";
344 OS <<
"ASI tag: " << getASITag() <<
"\n";
347 OS <<
"Prefetch tag: " << getPrefetchTag() <<
"\n";
350 OS <<
"TailReloc: " << getTailRelocSym() <<
"\n";
355 void addRegOperands(MCInst &Inst,
unsigned N)
const {
356 assert(
N == 1 &&
"Invalid number of operands!");
360 void addImmOperands(MCInst &Inst,
unsigned N)
const {
361 assert(
N == 1 &&
"Invalid number of operands!");
362 const MCExpr *Expr =
getImm();
366 void addShiftAmtImm5Operands(MCInst &Inst,
unsigned N)
const {
367 assert(
N == 1 &&
"Invalid number of operands!");
370 void addShiftAmtImm6Operands(MCInst &Inst,
unsigned N)
const {
371 assert(
N == 1 &&
"Invalid number of operands!");
375 void addExpr(MCInst &Inst,
const MCExpr *Expr)
const{
385 void addMEMrrOperands(MCInst &Inst,
unsigned N)
const {
386 assert(
N == 2 &&
"Invalid number of operands!");
394 void addMEMriOperands(MCInst &Inst,
unsigned N)
const {
395 assert(
N == 2 &&
"Invalid number of operands!");
399 const MCExpr *Expr = getMemOff();
403 void addASITagOperands(MCInst &Inst,
unsigned N)
const {
404 assert(
N == 1 &&
"Invalid number of operands!");
408 void addPrefetchTagOperands(MCInst &Inst,
unsigned N)
const {
409 assert(
N == 1 &&
"Invalid number of operands!");
413 void addMembarTagOperands(MCInst &Inst,
unsigned N)
const {
414 assert(
N == 1 &&
"Invalid number of operands!");
415 const MCExpr *Expr =
getImm();
420 assert(
N == 1 &&
"Invalid number of operands!");
424 void addTailRelocSymOperands(MCInst &Inst,
unsigned N)
const {
425 assert(
N == 1 &&
"Invalid number of operands!");
426 addExpr(Inst, getTailRelocSym());
429 static std::unique_ptr<SparcOperand> CreateToken(StringRef Str, SMLoc S) {
430 auto Op = std::make_unique<SparcOperand>(k_Token);
431 Op->Tok.Data = Str.data();
432 Op->Tok.Length = Str.size();
438 static std::unique_ptr<SparcOperand> CreateReg(MCRegister
Reg,
unsigned Kind,
440 auto Op = std::make_unique<SparcOperand>(k_Register);
442 Op->Reg.Kind = (SparcOperand::RegisterKind)Kind;
448 static std::unique_ptr<SparcOperand> CreateImm(
const MCExpr *Val, SMLoc S,
450 auto Op = std::make_unique<SparcOperand>(k_Immediate);
457 static std::unique_ptr<SparcOperand> CreateASITag(
unsigned Val, SMLoc S,
459 auto Op = std::make_unique<SparcOperand>(k_ASITag);
466 static std::unique_ptr<SparcOperand> CreatePrefetchTag(
unsigned Val, SMLoc S,
468 auto Op = std::make_unique<SparcOperand>(k_PrefetchTag);
475 static std::unique_ptr<SparcOperand> CreateTailRelocSym(
const MCExpr *Val,
477 auto Op = std::make_unique<SparcOperand>(k_TailRelocSym);
484 static std::unique_ptr<SparcOperand>
485 MorphToMEMrr(MCRegister
Base, std::unique_ptr<SparcOperand>
Op) {
486 MCRegister offsetReg =
Op->getReg();
487 Op->Kind = k_MemoryReg;
489 Op->Mem.OffsetReg = offsetReg;
490 Op->Mem.Off =
nullptr;
494 static std::unique_ptr<SparcOperand> CreateMEMr(MCRegister
Base, SMLoc S,
496 auto Op = std::make_unique<SparcOperand>(k_MemoryReg);
498 Op->Mem.OffsetReg = Sparc::G0;
499 Op->Mem.Off =
nullptr;
505 static std::unique_ptr<SparcOperand>
506 MorphToMEMri(MCRegister
Base, std::unique_ptr<SparcOperand>
Op) {
507 const MCExpr *
Imm =
Op->getImm();
508 Op->Kind = k_MemoryImm;
510 Op->Mem.OffsetReg = MCRegister();
518#define GET_MATCHER_IMPLEMENTATION
519#define GET_REGISTER_MATCHER
520#define GET_MNEMONIC_SPELL_CHECKER
521#include "SparcGenAsmMatcher.inc"
525SparcAsmParser::MatchResultTy
526SparcAsmParser::mnemonicIsValid(
StringRef Mnemonic,
unsigned VariantID) {
531 const MatchEntry *Start, *
End;
536 Start = std::begin(MatchTable0);
537 End = std::end(MatchTable0);
542 auto MnemonicRange = std::equal_range(Start,
End, Mnemonic, LessOpcode());
544 if (MnemonicRange.first == MnemonicRange.second)
545 return Match_MnemonicFail;
547 for (
const MatchEntry *it = MnemonicRange.first, *ie = MnemonicRange.second;
550 FeatureBitsets[it->RequiredFeaturesIdx];
551 if ((getAvailableFeatures() & RequiredFeatures) == RequiredFeatures)
552 return Match_Success;
554 return Match_MissingFeature;
557bool SparcAsmParser::expandSET(MCInst &Inst, SMLoc IDLoc,
558 SmallVectorImpl<MCInst> &Instructions) {
566 int64_t RawImmValue = IsImm ? MCValOp.
getImm() : 0;
569 if (RawImmValue < -2147483648LL || RawImmValue > 4294967295LL) {
571 "set: argument must be between -2147483648 and 4294967295");
576 int32_t ImmValue = RawImmValue;
580 bool IsEffectivelyImm13 =
581 IsImm && ((
is64Bit() ? 0 : -4096) <= ImmValue && ImmValue < 4096);
582 const MCExpr *ValExpr;
593 if (!IsEffectivelyImm13) {
595 const MCExpr *Expr = adjustPICRelocation(ELF::R_SPARC_HI22, ValExpr);
614 if (!IsImm || IsEffectivelyImm13 || (ImmValue & 0x3ff)) {
617 if (IsEffectivelyImm13)
620 Expr = adjustPICRelocation(ELF::R_SPARC_LO10, ValExpr);
631bool SparcAsmParser::expandSETSW(MCInst &Inst, SMLoc IDLoc,
632 SmallVectorImpl<MCInst> &Instructions) {
640 int64_t ImmValue = IsImm ? MCValOp.
getImm() : 0;
644 bool IsSmallImm = IsImm &&
isInt<13>(ImmValue);
645 bool NoLowBitsImm = IsImm && ((ImmValue & 0x3FF) == 0);
651 "set: argument must be between -2147483648 and 2147483647");
658 MCInstBuilder(SP::SETHIi)
660 .addExpr(adjustPICRelocation(ELF::R_SPARC_HI22, ValExpr)));
666 if (!NoLowBitsImm || IsSmallImm) {
668 IsSmallImm ? ValExpr : adjustPICRelocation(ELF::R_SPARC_LO10, ValExpr);
673 .addReg(PrevReg.getReg())
682 if (!IsImm || ImmValue < 0) {
693bool SparcAsmParser::expandSETX(MCInst &Inst, SMLoc IDLoc,
694 SmallVectorImpl<MCInst> &Instructions) {
702 bool IsImm = MCValOp.
isImm();
703 int64_t ImmValue = IsImm ? MCValOp.
getImm() : 0;
722 MCInstBuilder(SP::SETHIi)
724 .addExpr(adjustPICRelocation(ELF::R_SPARC_HI22, ValExpr)));
727 MCInstBuilder(SP::ORri)
730 .addExpr(adjustPICRelocation(ELF::R_SPARC_LO10, ValExpr)));
760 .addReg(MCRegOp.
getReg()));
765bool SparcAsmParser::matchAndEmitInstruction(SMLoc IDLoc,
unsigned &Opcode,
769 bool MatchingInlineAsm) {
772 unsigned MatchResult = MatchInstructionImpl(
Operands, Inst, ErrorInfo,
774 switch (MatchResult) {
775 case Match_Success: {
782 if (expandSET(Inst, IDLoc, Instructions))
786 if (expandSETSW(Inst, IDLoc, Instructions))
790 if (expandSETX(Inst, IDLoc, Instructions))
795 for (
const MCInst &
I : Instructions) {
796 Out.emitInstruction(
I, getSTI());
801 case Match_MissingFeature:
803 "instruction requires a CPU feature not currently enabled");
805 case Match_InvalidOperand: {
806 SMLoc ErrorLoc = IDLoc;
807 if (ErrorInfo != ~0ULL) {
809 return Error(IDLoc,
"too few operands for instruction");
811 ErrorLoc = ((SparcOperand &)*
Operands[ErrorInfo]).getStartLoc();
812 if (ErrorLoc == SMLoc())
816 return Error(ErrorLoc,
"invalid operand for instruction");
818 case Match_MnemonicFail:
819 return Error(IDLoc,
"invalid instruction mnemonic");
824bool SparcAsmParser::parseRegister(MCRegister &
Reg, SMLoc &StartLoc,
826 if (!tryParseRegister(
Reg, StartLoc, EndLoc).isSuccess())
827 return Error(StartLoc,
"invalid register name");
831ParseStatus SparcAsmParser::tryParseRegister(MCRegister &
Reg, SMLoc &StartLoc,
833 const AsmToken &Tok = Parser.
getTok();
836 Reg = Sparc::NoRegister;
840 unsigned RegKind = SparcOperand::rk_None;
847 getLexer().UnLex(Tok);
851bool SparcAsmParser::parseInstruction(ParseInstructionInfo &Info,
852 StringRef Name, SMLoc NameLoc,
863 MatchResultTy MS = mnemonicIsValid(Name, 0);
867 case Match_MissingFeature:
868 return Error(NameLoc,
869 "instruction requires a CPU feature not currently enabled");
870 case Match_MnemonicFail:
871 return Error(NameLoc,
872 "invalid instruction mnemonic" +
873 SparcMnemonicSpellCheck(Name, getAvailableFeatures(), 0));
879 Operands.push_back(SparcOperand::CreateToken(Name, NameLoc));
887 if (!parseBranchModifiers(
Operands).isSuccess()) {
888 SMLoc Loc = getLexer().getLoc();
889 return Error(Loc,
"unexpected token");
892 if (!parseOperand(
Operands, Name).isSuccess()) {
893 SMLoc Loc = getLexer().getLoc();
894 return Error(Loc,
"unexpected token");
904 if (!parseOperand(
Operands, Name).isSuccess()) {
905 SMLoc Loc = getLexer().getLoc();
906 return Error(Loc,
"unexpected token");
911 SMLoc Loc = getLexer().getLoc();
912 return Error(Loc,
"unexpected token");
918ParseStatus SparcAsmParser::parseDirective(AsmToken DirectiveID) {
919 StringRef IDVal = DirectiveID.
getString();
921 if (IDVal ==
".register") {
926 if (IDVal ==
".proc") {
932 if (IDVal ==
".seg") {
938 uint32_t Subsection = 0;
939 const MCObjectFileInfo *MCOFI =
getContext().getObjectFileInfo();
940 if (Name ==
"text") {
942 }
else if (Name ==
"data" || Name ==
"data1") {
944 Subsection =
Name ==
"data1" ? 1 : 0;
945 }
else if (Name ==
"bss") {
948 return Error(DirectiveID.
getLoc(),
"unknown segment type");
950 getStreamer().switchSection(Section, Subsection);
961 std::unique_ptr<SparcOperand>
LHS;
962 if (!parseSparcAsmOperand(
LHS).isSuccess())
967 Operands.push_back(SparcOperand::MorphToMEMri(Sparc::G0, std::move(
LHS)));
971 if (!
LHS->isIntReg())
972 return Error(
LHS->getStartLoc(),
"invalid register kind for this operand");
974 AsmToken Tok = getLexer().getTok();
980 std::unique_ptr<SparcOperand>
RHS;
981 if (!parseSparcAsmOperand(
RHS).isSuccess())
984 if (
RHS->isReg() && !
RHS->isIntReg())
986 "invalid register kind for this operand");
990 ? SparcOperand::MorphToMEMri(
LHS->getReg(), std::move(
RHS))
991 : SparcOperand::MorphToMEMrr(
LHS->getReg(), std::move(
RHS)));
996 Operands.push_back(SparcOperand::CreateMEMr(
LHS->getReg(), S,
E));
1000template <
unsigned N>
1010 if (getParser().parseExpression(Expr))
1015 return Error(S,
"constant expression expected");
1018 return Error(S,
"immediate shift value out of range");
1020 Operands.push_back(SparcOperand::CreateImm(Expr, S,
E));
1024template <SparcAsmParser::TailRelocKind Kind>
1029 auto MatchesKind = [](uint16_t RelType) ->
bool {
1031 case TailRelocKind::Load_GOT:
1034 return RelType == ELF::R_SPARC_GOTDATA_OP;
1035 case TailRelocKind::Add_TLS:
1039 case ELF::R_SPARC_TLS_GD_ADD:
1040 case ELF::R_SPARC_TLS_IE_ADD:
1041 case ELF::R_SPARC_TLS_LDM_ADD:
1042 case ELF::R_SPARC_TLS_LDO_ADD:
1047 case TailRelocKind::Load_TLS:
1051 case ELF::R_SPARC_TLS_IE_LD:
1052 case ELF::R_SPARC_TLS_IE_LDX:
1057 case TailRelocKind::Call_TLS:
1061 case ELF::R_SPARC_TLS_GD_CALL:
1062 case ELF::R_SPARC_TLS_LDM_CALL:
1074 const AsmToken Tok = Parser.
getTok();
1078 return Error(getLoc(),
"expected valid identifier for operand modifier");
1080 StringRef
Name = getParser().getTok().getIdentifier();
1083 return Error(getLoc(),
"invalid relocation specifier");
1085 if (!MatchesKind(RelType)) {
1087 getLexer().UnLex(Tok);
1093 return Error(getLoc(),
"expected '('");
1096 const MCExpr *SubExpr;
1097 if (getParser().parseParenExpression(SubExpr,
E))
1100 const MCExpr *Val = adjustPICRelocation(RelType, SubExpr);
1101 Operands.push_back(SparcOperand::CreateTailRelocSym(Val, S,
E));
1110 std::unique_ptr<SparcOperand>
Mask;
1111 if (parseSparcAsmOperand(Mask).isSuccess()) {
1112 if (!
Mask->isImm() || !
Mask->getImm()->evaluateAsAbsolute(ImmVal) ||
1113 ImmVal < 0 || ImmVal > 127)
1114 return Error(S,
"invalid membar mask number");
1118 SMLoc TagStart = getLexer().getLoc();
1120 unsigned MaskVal = StringSwitch<unsigned>(Parser.
getTok().
getString())
1121 .Case(
"LoadLoad", 0x1)
1122 .Case(
"StoreLoad", 0x2)
1123 .Case(
"LoadStore", 0x4)
1124 .Case(
"StoreStore", 0x8)
1125 .Case(
"Lookaside", 0x10)
1126 .Case(
"MemIssue", 0x20)
1133 return Error(TagStart,
"unknown membar tag");
1143 Operands.push_back(SparcOperand::CreateImm(EVal, S,
E));
1155 ParseStatus ParseExprStatus = parseExpression(ASIVal);
1157 return ParseExprStatus;
1160 return Error(S,
"invalid ASI number, must be between 0 and 255");
1162 Operands.push_back(SparcOperand::CreateASITag(ASIVal, S,
E));
1168 SMLoc TagStart = getLexer().peekTok(
false).getLoc();
1171 const SparcASITag::ASITag *ASITag = SparcASITag::lookupASITagByName(ASIName);
1173 ASITag = SparcASITag::lookupASITagByAltName(ASIName);
1177 return Error(TagStart,
"unknown ASI tag");
1181 Operands.push_back(SparcOperand::CreateASITag(ASIVal, S,
E));
1188 int64_t PrefetchVal = 0;
1193 ParseStatus ParseExprStatus = parseExpression(PrefetchVal);
1195 return ParseExprStatus;
1198 return Error(S,
"invalid prefetch number, must be between 0 and 31");
1200 Operands.push_back(SparcOperand::CreatePrefetchTag(PrefetchVal, S,
E));
1204 SMLoc TagStart = getLexer().peekTok(
false).getLoc();
1207 const SparcPrefetchTag::PrefetchTag *PrefetchTag =
1208 SparcPrefetchTag::lookupPrefetchTagByName(PrefetchName);
1212 return Error(TagStart,
"unknown prefetch tag");
1214 PrefetchVal = PrefetchTag->
Encoding;
1216 Operands.push_back(SparcOperand::CreatePrefetchTag(PrefetchVal, S,
E));
1224 switch (getLexer().getKind()) {
1234 const MCExpr *DestValue;
1235 if (getParser().parseExpression(DestValue))
1238 Operands.push_back(SparcOperand::CreateImm(DestValue, S,
E));
1243 StringRef Mnemonic) {
1245 ParseStatus Res = MatchOperandParserImpl(
Operands, Mnemonic);
1255 Operands.push_back(SparcOperand::CreateToken(
"[",
1259 if (Mnemonic ==
"cas" || Mnemonic ==
"casl" || Mnemonic ==
"casa" ||
1260 Mnemonic ==
"casx" || Mnemonic ==
"casxl" || Mnemonic ==
"casxa") {
1273 Operands.push_back(SparcOperand::CreateReg(
Reg, RegKind, S,
E));
1285 Operands.push_back(SparcOperand::CreateToken(
"]",
1296 S,
"malformed ASI tag, must be a constant integer expression");
1299 const AsmToken Tok = Parser.
getTok();
1307 if (OldMemOp.isMEMrr()) {
1308 if (OldMemOp.getMemOffsetReg() != Sparc::G0) {
1309 return Error(S,
"invalid operand for instruction");
1312 OldMemOp.getMemBase(),
1314 OldMemOp.getStartLoc(),
1315 OldMemOp.getEndLoc()));
1322 Operands.push_back(SparcOperand::CreateToken(
"%asi", S));
1326 return Error(S,
"malformed ASI tag, must be %asi, a constant integer "
1327 "expression, or a named tag");
1338 std::unique_ptr<SparcOperand>
Op;
1340 Res = parseSparcAsmOperand(
Op);
1351SparcAsmParser::parseSparcAsmOperand(std::unique_ptr<SparcOperand> &
Op) {
1357 switch (getLexer().getKind()) {
1371 if (
Reg == Sparc::ICC && Name ==
"xcc")
1372 Op = SparcOperand::CreateToken(
"%xcc", S);
1374 Op = SparcOperand::CreateReg(
Reg, RegKind, S,
E);
1377 ParseStatus Res = matchSparcAsmModifiers(EVal,
E);
1380 Op = SparcOperand::CreateImm(EVal, S,
E);
1383 Error(getLoc(),
"invalid register name");
1395 if (getParser().parseExpression(EVal,
E))
1398 Op = SparcOperand::CreateImm(EVal, S,
E);
1413 if (modName ==
"a" || modName ==
"pn" || modName ==
"pt") {
1414 Operands.push_back(SparcOperand::CreateToken(modName,
1422ParseStatus SparcAsmParser::parseExpression(int64_t &Val) {
1423 AsmToken Tok = getLexer().getTok();
1425 if (!isPossibleExpression(Tok))
1428 return getParser().parseAbsoluteExpression(Val);
1431MCRegister SparcAsmParser::matchRegisterName(
const AsmToken &Tok,
1432 unsigned &RegKind) {
1433 RegKind = SparcOperand::rk_None;
1435 return SP::NoRegister;
1448 if (
Reg == SP::ASR4 && Name ==
"tick") {
1449 RegKind = SparcOperand::rk_Special;
1454 RegKind = SparcOperand::rk_IntReg;
1463 RegKind = SparcOperand::rk_Special;
1471 if (
Name.equals_insensitive(
"o6")) {
1472 RegKind = SparcOperand::rk_IntReg;
1475 if (
Name.equals_insensitive(
"i6")) {
1476 RegKind = SparcOperand::rk_IntReg;
1482 if (
Name.starts_with_insensitive(
"r") &&
1483 !
Name.drop_front().getAsInteger(10, RegNo) && RegNo <= 31) {
1484 RegKind = SparcOperand::rk_IntReg;
1488 if (Name ==
"xcc" || Name ==
"ncc") {
1490 RegKind = SparcOperand::rk_Special;
1496 if (Name ==
"pcr") {
1497 RegKind = SparcOperand::rk_Special;
1500 if (Name ==
"pic") {
1501 RegKind = SparcOperand::rk_Special;
1504 if (Name ==
"dcr") {
1505 RegKind = SparcOperand::rk_Special;
1508 if (Name ==
"gsr") {
1509 RegKind = SparcOperand::rk_Special;
1512 if (Name ==
"set_softint") {
1513 RegKind = SparcOperand::rk_Special;
1516 if (Name ==
"clear_softint") {
1517 RegKind = SparcOperand::rk_Special;
1520 if (Name ==
"softint") {
1521 RegKind = SparcOperand::rk_Special;
1524 if (Name ==
"tick_cmpr") {
1525 RegKind = SparcOperand::rk_Special;
1528 if (Name ==
"stick" || Name ==
"sys_tick") {
1529 RegKind = SparcOperand::rk_Special;
1532 if (Name ==
"stick_cmpr" || Name ==
"sys_tick_cmpr") {
1533 RegKind = SparcOperand::rk_Special;
1537 return SP::NoRegister;
1571const MCSpecifierExpr *
1572SparcAsmParser::adjustPICRelocation(uint16_t RelType,
const MCExpr *subExpr) {
1578 if (
getContext().getObjectFileInfo()->isPositionIndependent()) {
1581 case ELF::R_SPARC_LO10:
1585 case ELF::R_SPARC_HI22:
1595ParseStatus SparcAsmParser::matchSparcAsmModifiers(
const MCExpr *&EVal,
1598 AsmToken Tok = Parser.
getTok();
1608 return Error(getLoc(),
"invalid relocation specifier");
1610 case ELF::R_SPARC_GOTDATA_OP:
1611 case ELF::R_SPARC_TLS_GD_ADD:
1612 case ELF::R_SPARC_TLS_GD_CALL:
1613 case ELF::R_SPARC_TLS_IE_ADD:
1614 case ELF::R_SPARC_TLS_IE_LD:
1615 case ELF::R_SPARC_TLS_IE_LDX:
1616 case ELF::R_SPARC_TLS_LDM_ADD:
1617 case ELF::R_SPARC_TLS_LDM_CALL:
1618 case ELF::R_SPARC_TLS_LDO_ADD:
1621 return Error(getLoc(),
"unexpected relocation specifier");
1629 const MCExpr *subExpr;
1633 EVal = adjustPICRelocation(VK, subExpr);
1637bool SparcAsmParser::parseExprWithSpecifier(
const MCExpr *&Res, SMLoc &
E) {
1638 SMLoc Loc = getLoc();
1640 return TokError(
"expected '%' relocation specifier");
1643 return TokError(
"invalid relocation specifier");
1649 const MCExpr *SubExpr;
1656bool SparcAsmParser::parseDataExpr(
const MCExpr *&Res) {
1659 return parseExprWithSpecifier(Res, EndLoc);
1663bool SparcAsmParser::isPossibleExpression(
const AsmToken &Token) {
static MCRegister MatchRegisterName(StringRef Name)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static void applyMnemonicAliases(StringRef &Mnemonic, const FeatureBitset &Features, unsigned VariantID)
static bool addCallTargetOperands(MachineInstrBuilder &CallInst, MachineIRBuilder &MIRBuilder, AMDGPUCallLowering::CallLoweringInfo &Info, bool IsDynamicVGPRChainCall=false)
static bool isNot(const MachineRegisterInfo &MRI, const MachineInstr &MI)
static MCRegister MatchRegisterAltName(StringRef Name)
Maps from the set of all alternative registernames to a register number.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_EXTERNAL_VISIBILITY
loop data Loop Data Prefetch
static MCRegister getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
static bool isReg(const MCInst &MI, unsigned OpNo)
MachineRegisterInfo & MRI
static bool isValid(const char C)
Returns true if C is a valid mangled character: <0-9a-zA-Z_>.
Func getContext().diagnose(DiagnosticInfoUnsupported(Func
This file defines the SmallVector class.
static bool hasGOTReference(const MCExpr *Expr)
static const MCPhysReg IntRegs[32]
LLVM_ABI LLVM_EXTERNAL_VISIBILITY void LLVMInitializeSparcAsmParser()
static bool is64Bit(const char *name)
Target independent representation for an assembler token.
LLVM_ABI SMLoc getLoc() const
StringRef getString() const
Get the string for the current token, this includes all characters (for example, the quotes on string...
bool is(TokenKind K) const
TokenKind getKind() const
LLVM_ABI SMLoc getEndLoc() const
StringRef getIdentifier() const
Get the identifier string for the current token, which should be an identifier or a string.
Base class for user error types.
Container class for subtarget features.
void printExpr(raw_ostream &, const MCExpr &) const
Generic assembler parser interface, for use by target specific assembly parsers.
virtual void eatToEndOfStatement()=0
Skip to the end of the current statement, for error recovery.
virtual bool parseEscapedString(std::string &Data)=0
Parse the current token as a string which may include escaped characters and return the string conten...
virtual bool parseExpression(const MCExpr *&Res, SMLoc &EndLoc)=0
Parse an arbitrary expression.
const AsmToken & getTok() const
Get the current AsmToken from the stream.
virtual bool parseParenExpression(const MCExpr *&Res, SMLoc &EndLoc)=0
Parse an arbitrary expression, assuming that an initial '(' has already been consumed.
bool parseOptionalToken(AsmToken::TokenKind T)
Attempt to parse and consume token, returning true on success.
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.
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
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.
unsigned getOpcode() const
void addOperand(const MCOperand Op)
void setOpcode(unsigned Op)
const MCOperand & getOperand(unsigned i) const
MCSection * getBSSSection() const
MCSection * getTextSection() const
MCSection * getDataSection() const
static MCOperand createExpr(const MCExpr *Val)
static MCOperand createReg(MCRegister Reg)
static MCOperand createImm(int64_t Val)
MCRegister getReg() const
Returns the register number.
const MCExpr * getExpr() const
MCParsedAsmOperand - This abstract class represents a source-level assembly instruction operand.
bool contains(MCRegister Reg) const
contains - Return true if the specified register is included in this register class.
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Wrapper class representing physical registers. Should be passed by value.
constexpr unsigned id() const
Extension point for target-specific MCExpr subclasses with a relocation specifier,...
static const MCSpecifierExpr * create(const MCExpr *Expr, Spec S, MCContext &Ctx, SMLoc Loc=SMLoc())
Streaming machine code generation interface.
Represent a reference to a symbol from inside an expression.
const MCSymbol & getSymbol() const
StringRef getName() const
getName - Get the symbol name.
MCTargetAsmParser - Generic interface to target specific assembly parsers.
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
Ternary parse status returned by various parse* methods.
constexpr bool isFailure() const
static constexpr StatusTy Failure
constexpr bool isSuccess() const
static constexpr StatusTy Success
static constexpr StatusTy NoMatch
constexpr bool isNoMatch() const
Represents a location in source code.
static SMLoc getFromPointer(const char *Ptr)
constexpr const char * getPointer() const
Represent a constant reference to a string, i.e.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
bool isIntReg(MCRegister Reg)
MCExpr const & getExpr(MCExpr const &Expr)
MCRegister matchRegisterName(StringRef Name, const MCRegisterInfo &MRI, unsigned RegClassID, unsigned AltIdx)
Match a symbolic name in RegClassID, or return an invalid register.
uint16_t parseSpecifier(StringRef name)
uint16_t parseDataSpecifier(StringRef name)
@ CE
Windows NT (Windows on ARM)
This is an optimization pass for GlobalISel generic memory operations.
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.
Target & getTheSparcTarget()
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.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
Target & getTheSparcV9Target()
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Target & getTheSparcelTarget()
@ End
Run the machine verifier once, at the end of the pipeline.
RegisterMCAsmParser - Helper template for registering a target specific assembly parser,...