40#define DEBUG_TYPE "csky-asm-parser"
43#define GEN_COMPRESS_INSTR
44#include "CSKYGenCompressInstEmitter.inc"
47 "Number of C-SKY Compressed instructions emitted");
53 const CSKYMCOptions &CLOpts;
56 unsigned Kind)
override;
62 SMLoc getLoc()
const {
return getParser().getTok().getLoc(); }
64 bool matchAndEmitInstruction(SMLoc IDLoc,
unsigned &Opcode,
67 bool MatchingInlineAsm)
override;
69 bool parseRegister(MCRegister &
Reg, SMLoc &StartLoc, SMLoc &EndLoc)
override;
71 bool parseInstruction(ParseInstructionInfo &Info, StringRef Name,
74 ParseStatus parseDirective(AsmToken DirectiveID)
override;
78 void emitToStreamer(MCStreamer &S,
const MCInst &Inst);
80 ParseStatus tryParseRegister(MCRegister &
Reg, SMLoc &StartLoc,
81 SMLoc &EndLoc)
override;
85 bool processLRW(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out);
86 bool processJSRI(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out);
87 bool processJMPI(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out);
89 CSKYTargetStreamer &getTargetStreamer() {
90 assert(getParser().getStreamer().getTargetStreamer() &&
91 "do not have a target streamer");
92 MCTargetStreamer &TS = *getParser().getStreamer().getTargetStreamer();
93 return static_cast<CSKYTargetStreamer &
>(TS);
97#define GET_ASSEMBLER_HEADER
98#include "CSKYGenAsmMatcher.inc"
112 bool parseDirectiveAttribute();
115 enum CSKYMatchResultTy {
116 Match_Dummy = FIRST_TARGET_MATCH_RESULT_TY,
117 Match_RequiresSameSrcAndDst,
118 Match_InvalidRegOutOfRange,
119#define GET_OPERAND_DIAGNOSTIC_TYPES
120#include "CSKYGenAsmMatcher.inc"
121#undef GET_OPERAND_DIAGNOSTIC_TYPES
124 CSKYAsmParser(
const MCSubtargetInfo &STI, MCAsmParser &Parser,
125 const MCInstrInfo &MII)
126 : MCTargetAsmParser(STI, MII),
131 setAvailableFeatures(ComputeAvailableFeatures(STI.
getFeatureBits()));
132 if (CLOpts.add_build_attributes)
133 getTargetStreamer().emitTargetAttributes(STI,
false);
162 MCRegister RegNumFrom;
167 MCRegister List1From;
169 MCRegister List2From;
171 MCRegister List3From;
173 MCRegister List4From;
177 SMLoc StartLoc, EndLoc;
187 CSKYOperand(KindTy K) : MCParsedAsmOperand(), Kind(
K) {}
190 CSKYOperand(
const CSKYOperand &o) : MCParsedAsmOperand() {
192 StartLoc =
o.StartLoc;
216 bool isToken()
const override {
return Kind == Token; }
217 bool isReg()
const override {
return Kind == Register; }
218 bool isImm()
const override {
return Kind == Immediate; }
219 bool isRegisterSeq()
const {
return Kind == RegisterSeq; }
220 bool isRegisterList()
const {
return Kind == RegisterList; }
221 bool isConstPoolOp()
const {
return Kind == CPOP; }
223 bool isMem()
const override {
return false; }
225 static bool evaluateConstantImm(
const MCExpr *Expr, int64_t &
Imm) {
227 Imm =
CE->getValue();
234 template <
unsigned num,
unsigned shift = 0>
bool isUImm()
const {
239 bool IsConstantImm = evaluateConstantImm(
getImm(),
Imm);
243 template <
unsigned num>
bool isOImm()
const {
248 bool IsConstantImm = evaluateConstantImm(
getImm(),
Imm);
252 template <
unsigned num,
unsigned shift = 0>
bool isSImm()
const {
257 bool IsConstantImm = evaluateConstantImm(
getImm(),
Imm);
261 bool isUImm1()
const {
return isUImm<1>(); }
262 bool isUImm2()
const {
return isUImm<2>(); }
263 bool isUImm3()
const {
return isUImm<3>(); }
264 bool isUImm4()
const {
return isUImm<4>(); }
265 bool isUImm5()
const {
return isUImm<5>(); }
266 bool isUImm6()
const {
return isUImm<6>(); }
267 bool isUImm7()
const {
return isUImm<7>(); }
268 bool isUImm8()
const {
return isUImm<8>(); }
269 bool isUImm12()
const {
return isUImm<12>(); }
270 bool isUImm16()
const {
return isUImm<16>(); }
271 bool isUImm20()
const {
return isUImm<20>(); }
272 bool isUImm24()
const {
return isUImm<24>(); }
274 bool isOImm3()
const {
return isOImm<3>(); }
275 bool isOImm4()
const {
return isOImm<4>(); }
276 bool isOImm5()
const {
return isOImm<5>(); }
277 bool isOImm6()
const {
return isOImm<6>(); }
278 bool isOImm8()
const {
return isOImm<8>(); }
279 bool isOImm12()
const {
return isOImm<12>(); }
280 bool isOImm16()
const {
return isOImm<16>(); }
282 bool isSImm8()
const {
return isSImm<8>(); }
284 bool isUImm5Shift1() {
return isUImm<5, 1>(); }
285 bool isUImm5Shift2() {
return isUImm<5, 2>(); }
286 bool isUImm7Shift1() {
return isUImm<7, 1>(); }
287 bool isUImm7Shift2() {
return isUImm<7, 2>(); }
288 bool isUImm7Shift3() {
return isUImm<7, 3>(); }
289 bool isUImm8Shift2() {
return isUImm<8, 2>(); }
290 bool isUImm8Shift3() {
return isUImm<8, 3>(); }
291 bool isUImm8Shift8() {
return isUImm<8, 8>(); }
292 bool isUImm8Shift16() {
return isUImm<8, 16>(); }
293 bool isUImm8Shift24() {
return isUImm<8, 24>(); }
294 bool isUImm12Shift1() {
return isUImm<12, 1>(); }
295 bool isUImm12Shift2() {
return isUImm<12, 2>(); }
296 bool isUImm16Shift8() {
return isUImm<16, 8>(); }
297 bool isUImm16Shift16() {
return isUImm<16, 16>(); }
298 bool isUImm24Shift8() {
return isUImm<24, 8>(); }
300 bool isSImm16Shift1() {
return isSImm<16, 1>(); }
302 bool isCSKYSymbol()
const {
return isImm(); }
304 bool isConstpool()
const {
return isConstPoolOp(); }
305 bool isDataSymbol()
const {
return isConstPoolOp(); }
307 bool isPSRFlag()
const {
310 if (!isImm() || !evaluateConstantImm(
getImm(),
Imm))
316 template <
unsigned MIN,
unsigned MAX>
bool isRegSeqTemplate()
const {
317 if (!isRegisterSeq())
320 std::pair<unsigned, unsigned> regSeq = getRegSeq();
322 return MIN <= regSeq.first && regSeq.first <= regSeq.second &&
323 regSeq.second <=
MAX;
326 bool isRegSeq()
const {
return isRegSeqTemplate<CSKY::R0, CSKY::R31>(); }
328 bool isRegSeqV1()
const {
329 return isRegSeqTemplate<CSKY::F0_32, CSKY::F15_32>();
332 bool isRegSeqV2()
const {
333 return isRegSeqTemplate<CSKY::F0_32, CSKY::F31_32>();
336 static bool isLegalRegList(
unsigned from,
unsigned to) {
337 if (from == 0 && to == 0)
341 if (from != CSKY::R4 && from != CSKY::R15 && from != CSKY::R16 &&
347 if (from != CSKY::R4 && from != CSKY::R16)
350 if (from == CSKY::R4 && to > CSKY::R4 && to < CSKY::R12)
352 else if (from == CSKY::R16 && to > CSKY::R16 && to < CSKY::R18)
359 bool isRegList()
const {
360 if (!isRegisterList())
363 auto regList = getRegList();
365 if (!isLegalRegList(regList.List1From, regList.List1To))
367 if (!isLegalRegList(regList.List2From, regList.List2To))
369 if (!isLegalRegList(regList.List3From, regList.List3To))
371 if (!isLegalRegList(regList.List4From, regList.List4To))
382 bool IsConstantImm = evaluateConstantImm(
getImm(),
Imm);
386 int uimm4 =
Imm & 0xf;
392 SMLoc getStartLoc()
const override {
return StartLoc; }
394 SMLoc getEndLoc()
const override {
return EndLoc; }
396 MCRegister
getReg()
const override {
397 assert(Kind == Register &&
"Invalid type access!");
401 std::pair<MCRegister, MCRegister> getRegSeq()
const {
402 assert(Kind == RegisterSeq &&
"Invalid type access!");
403 return {RegSeq.RegNumFrom, RegSeq.RegNumTo};
406 RegListOp getRegList()
const {
407 assert(Kind == RegisterList &&
"Invalid type access!");
411 const MCExpr *
getImm()
const {
412 assert(Kind == Immediate &&
"Invalid type access!");
416 const MCExpr *getConstpoolOp()
const {
417 assert(Kind == CPOP &&
"Invalid type access!");
422 assert(Kind == Token &&
"Invalid type access!");
426 void print(raw_ostream &OS,
const MCAsmInfo &MAI)
const override {
442 case KindTy::Register:
446 OS <<
"<register-seq ";
447 OS <<
RegName(getRegSeq().first) <<
"-" <<
RegName(getRegSeq().second)
451 OS <<
"<register-list ";
452 OS <<
RegName(getRegList().List1From) <<
"-"
453 <<
RegName(getRegList().List1To) <<
",";
454 OS <<
RegName(getRegList().List2From) <<
"-"
455 <<
RegName(getRegList().List2To) <<
",";
456 OS <<
RegName(getRegList().List3From) <<
"-"
457 <<
RegName(getRegList().List3To) <<
",";
458 OS <<
RegName(getRegList().List4From) <<
"-"
459 <<
RegName(getRegList().List4To);
467 static std::unique_ptr<CSKYOperand> createToken(StringRef Str, SMLoc S) {
468 auto Op = std::make_unique<CSKYOperand>(Token);
475 static std::unique_ptr<CSKYOperand> createReg(MCRegister RegNo, SMLoc S,
477 auto Op = std::make_unique<CSKYOperand>(Register);
478 Op->Reg.RegNum = RegNo;
484 static std::unique_ptr<CSKYOperand>
485 createRegSeq(MCRegister RegNoFrom, MCRegister RegNoTo, SMLoc S) {
486 auto Op = std::make_unique<CSKYOperand>(RegisterSeq);
487 Op->RegSeq.RegNumFrom = RegNoFrom;
488 Op->RegSeq.RegNumTo = RegNoTo;
494 static std::unique_ptr<CSKYOperand>
496 auto Op = std::make_unique<CSKYOperand>(RegisterList);
497 Op->RegList.List1From = 0;
498 Op->RegList.List1To = 0;
499 Op->RegList.List2From = 0;
500 Op->RegList.List2To = 0;
501 Op->RegList.List3From = 0;
502 Op->RegList.List3To = 0;
503 Op->RegList.List4From = 0;
504 Op->RegList.List4To = 0;
506 for (
unsigned i = 0; i < reglist.
size(); i += 2) {
507 if (
Op->RegList.List1From == 0) {
508 Op->RegList.List1From = reglist[i];
509 Op->RegList.List1To = reglist[i + 1];
510 }
else if (
Op->RegList.List2From == 0) {
511 Op->RegList.List2From = reglist[i];
512 Op->RegList.List2To = reglist[i + 1];
513 }
else if (
Op->RegList.List3From == 0) {
514 Op->RegList.List3From = reglist[i];
515 Op->RegList.List3To = reglist[i + 1];
516 }
else if (
Op->RegList.List4From == 0) {
517 Op->RegList.List4From = reglist[i];
518 Op->RegList.List4To = reglist[i + 1];
529 static std::unique_ptr<CSKYOperand> createImm(
const MCExpr *Val, SMLoc S,
531 auto Op = std::make_unique<CSKYOperand>(Immediate);
538 static std::unique_ptr<CSKYOperand> createConstpoolOp(
const MCExpr *Val,
540 auto Op = std::make_unique<CSKYOperand>(CPOP);
547 void addExpr(MCInst &Inst,
const MCExpr *Expr)
const {
548 assert(Expr &&
"Expr shouldn't be null!");
556 void addRegOperands(MCInst &Inst,
unsigned N)
const {
557 assert(
N == 1 &&
"Invalid number of operands!");
561 void addImmOperands(MCInst &Inst,
unsigned N)
const {
562 assert(
N == 1 &&
"Invalid number of operands!");
566 void addConstpoolOperands(MCInst &Inst,
unsigned N)
const {
567 assert(
N == 1 &&
"Invalid number of operands!");
571 void addRegSeqOperands(MCInst &Inst,
unsigned N)
const {
572 assert(
N == 2 &&
"Invalid number of operands!");
573 auto regSeq = getRegSeq();
579 static unsigned getListValue(
unsigned ListFrom,
unsigned ListTo) {
580 if (ListFrom == ListTo && ListFrom == CSKY::R15)
582 else if (ListFrom == ListTo && ListFrom == CSKY::R28)
584 else if (ListFrom == CSKY::R4)
585 return ListTo - ListFrom + 1;
586 else if (ListFrom == CSKY::R16)
587 return ((ListTo - ListFrom + 1) << 5);
592 void addRegListOperands(MCInst &Inst,
unsigned N)
const {
593 assert(
N == 1 &&
"Invalid number of operands!");
594 auto regList = getRegList();
598 unsigned T = getListValue(regList.List1From, regList.List1To);
602 T = getListValue(regList.List2From, regList.List2To);
606 T = getListValue(regList.List3From, regList.List3To);
610 T = getListValue(regList.List4From, regList.List4To);
617 bool isValidForTie(
const CSKYOperand &
Other)
const {
618 if (Kind !=
Other.Kind)
626 return Reg.RegNum ==
Other.Reg.RegNum;
632#define GET_REGISTER_MATCHER
633#define GET_SUBTARGET_FEATURE_NAME
634#define GET_MATCHER_IMPLEMENTATION
635#define GET_MNEMONIC_SPELL_CHECKER
636#include "CSKYGenAsmMatcher.inc"
639 unsigned VariantID = 0);
641bool CSKYAsmParser::generateImmOutOfRangeError(
643 const Twine &
Msg =
"immediate must be an integer in the range") {
648bool CSKYAsmParser::matchAndEmitInstruction(SMLoc IDLoc,
unsigned &Opcode,
652 bool MatchingInlineAsm) {
654 FeatureBitset MissingFeatures;
656 auto Result = MatchInstructionImpl(
Operands, Inst, ErrorInfo, MissingFeatures,
662 return processInstruction(Inst, IDLoc,
Operands, Out);
663 case Match_MissingFeature: {
664 assert(MissingFeatures.
any() &&
"Unknown missing features!");
666 std::string
Msg =
"instruction requires the following: ";
667 for (
unsigned Feature : MissingFeatures) {
673 case Match_MnemonicFail: {
674 FeatureBitset FBS = ComputeAvailableFeatures(getSTI().getFeatureBits());
675 std::string Suggestion =
677 return Error(IDLoc,
"unrecognized instruction mnemonic" + Suggestion);
679 case Match_InvalidTiedOperand:
680 case Match_InvalidOperand: {
681 SMLoc ErrorLoc = IDLoc;
682 if (ErrorInfo != ~0U) {
684 return Error(ErrorLoc,
"too few operands for instruction");
686 ErrorLoc = ((CSKYOperand &)*
Operands[ErrorInfo]).getStartLoc();
687 if (ErrorLoc == SMLoc())
690 return Error(ErrorLoc,
"invalid operand for instruction");
697 if (Result > FIRST_TARGET_MATCH_RESULT_TY) {
698 SMLoc ErrorLoc = IDLoc;
699 if (ErrorInfo != ~0U && ErrorInfo >=
Operands.size())
700 return Error(ErrorLoc,
"too few operands for instruction");
706 case Match_InvalidSImm8:
707 return generateImmOutOfRangeError(
Operands, ErrorInfo, -(1 << 7),
709 case Match_InvalidOImm3:
710 return generateImmOutOfRangeError(
Operands, ErrorInfo, 1, (1 << 3));
711 case Match_InvalidOImm4:
712 return generateImmOutOfRangeError(
Operands, ErrorInfo, 1, (1 << 4));
713 case Match_InvalidOImm5:
714 return generateImmOutOfRangeError(
Operands, ErrorInfo, 1, (1 << 5));
715 case Match_InvalidOImm6:
716 return generateImmOutOfRangeError(
Operands, ErrorInfo, 1, (1 << 6));
717 case Match_InvalidOImm8:
718 return generateImmOutOfRangeError(
Operands, ErrorInfo, 1, (1 << 8));
719 case Match_InvalidOImm12:
720 return generateImmOutOfRangeError(
Operands, ErrorInfo, 1, (1 << 12));
721 case Match_InvalidOImm16:
722 return generateImmOutOfRangeError(
Operands, ErrorInfo, 1, (1 << 16));
723 case Match_InvalidUImm1:
724 return generateImmOutOfRangeError(
Operands, ErrorInfo, 0, (1 << 1) - 1);
725 case Match_InvalidUImm2:
726 return generateImmOutOfRangeError(
Operands, ErrorInfo, 0, (1 << 2) - 1);
727 case Match_InvalidUImm3:
728 return generateImmOutOfRangeError(
Operands, ErrorInfo, 0, (1 << 3) - 1);
729 case Match_InvalidUImm4:
730 return generateImmOutOfRangeError(
Operands, ErrorInfo, 0, (1 << 4) - 1);
731 case Match_InvalidUImm5:
732 return generateImmOutOfRangeError(
Operands, ErrorInfo, 0, (1 << 5) - 1);
733 case Match_InvalidUImm6:
734 return generateImmOutOfRangeError(
Operands, ErrorInfo, 0, (1 << 6) - 1);
735 case Match_InvalidUImm7:
736 return generateImmOutOfRangeError(
Operands, ErrorInfo, 0, (1 << 7) - 1);
737 case Match_InvalidUImm8:
738 return generateImmOutOfRangeError(
Operands, ErrorInfo, 0, (1 << 8) - 1);
739 case Match_InvalidUImm12:
740 return generateImmOutOfRangeError(
Operands, ErrorInfo, 0, (1 << 12) - 1);
741 case Match_InvalidUImm16:
742 return generateImmOutOfRangeError(
Operands, ErrorInfo, 0, (1 << 16) - 1);
743 case Match_InvalidUImm5Shift1:
744 return generateImmOutOfRangeError(
745 Operands, ErrorInfo, 0, (1 << 5) - 2,
746 "immediate must be a multiple of 2 bytes in the range");
747 case Match_InvalidUImm12Shift1:
748 return generateImmOutOfRangeError(
749 Operands, ErrorInfo, 0, (1 << 12) - 2,
750 "immediate must be a multiple of 2 bytes in the range");
751 case Match_InvalidUImm5Shift2:
752 return generateImmOutOfRangeError(
753 Operands, ErrorInfo, 0, (1 << 5) - 4,
754 "immediate must be a multiple of 4 bytes in the range");
755 case Match_InvalidUImm7Shift1:
756 return generateImmOutOfRangeError(
757 Operands, ErrorInfo, 0, (1 << 7) - 2,
758 "immediate must be a multiple of 2 bytes in the range");
759 case Match_InvalidUImm7Shift2:
760 return generateImmOutOfRangeError(
761 Operands, ErrorInfo, 0, (1 << 7) - 4,
762 "immediate must be a multiple of 4 bytes in the range");
763 case Match_InvalidUImm8Shift2:
764 return generateImmOutOfRangeError(
765 Operands, ErrorInfo, 0, (1 << 8) - 4,
766 "immediate must be a multiple of 4 bytes in the range");
767 case Match_InvalidUImm8Shift3:
768 return generateImmOutOfRangeError(
769 Operands, ErrorInfo, 0, (1 << 8) - 8,
770 "immediate must be a multiple of 8 bytes in the range");
771 case Match_InvalidUImm8Shift8:
772 return generateImmOutOfRangeError(
773 Operands, ErrorInfo, 0, (1 << 8) - 256,
774 "immediate must be a multiple of 256 bytes in the range");
775 case Match_InvalidUImm12Shift2:
776 return generateImmOutOfRangeError(
777 Operands, ErrorInfo, 0, (1 << 12) - 4,
778 "immediate must be a multiple of 4 bytes in the range");
779 case Match_InvalidCSKYSymbol: {
780 SMLoc ErrorLoc = ((CSKYOperand &)*
Operands[ErrorInfo]).getStartLoc();
781 return Error(ErrorLoc,
"operand must be a symbol name");
783 case Match_InvalidConstpool: {
784 SMLoc ErrorLoc = ((CSKYOperand &)*
Operands[ErrorInfo]).getStartLoc();
785 return Error(ErrorLoc,
"operand must be a constpool symbol name");
787 case Match_InvalidPSRFlag: {
788 SMLoc ErrorLoc = ((CSKYOperand &)*
Operands[ErrorInfo]).getStartLoc();
789 return Error(ErrorLoc,
"psrset operand is not valid");
791 case Match_InvalidRegSeq: {
792 SMLoc ErrorLoc = ((CSKYOperand &)*
Operands[ErrorInfo]).getStartLoc();
793 return Error(ErrorLoc,
"Register sequence is not valid");
795 case Match_InvalidRegOutOfRange: {
796 SMLoc ErrorLoc = ((CSKYOperand &)*
Operands[ErrorInfo]).getStartLoc();
797 return Error(ErrorLoc,
"register is out of range");
799 case Match_RequiresSameSrcAndDst: {
800 SMLoc ErrorLoc = ((CSKYOperand &)*
Operands[ErrorInfo]).getStartLoc();
801 return Error(ErrorLoc,
"src and dst operand must be same");
803 case Match_InvalidRegList: {
804 SMLoc ErrorLoc = ((CSKYOperand &)*
Operands[ErrorInfo]).getStartLoc();
805 return Error(ErrorLoc,
"invalid register list");
812bool CSKYAsmParser::processLRW(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out) {
817 if (Inst.
getOpcode() == CSKY::PseudoLRW16)
818 Opcode = CSKY::LRW16;
820 Opcode = CSKY::LRW32;
825 Opcode = CSKY::MOVI16;
826 }
else if (getSTI().
hasFeature(CSKY::HasE2) &&
828 Opcode = CSKY::MOVI32;
830 auto *Expr = getTargetStreamer().addConstantPoolEntry(
837 const MCExpr *AdjustExpr =
nullptr;
838 if (
const auto *CSKYExpr =
848 auto *Expr = getTargetStreamer().addConstantPoolEntry(
856 Out.emitInstruction(Inst, getSTI());
860bool CSKYAsmParser::processJSRI(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out) {
864 const MCExpr *Expr = getTargetStreamer().addConstantPoolEntry(
871 const MCExpr *Expr = getTargetStreamer().addConstantPoolEntry(
877 Out.emitInstruction(Inst, getSTI());
881bool CSKYAsmParser::processJMPI(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out) {
885 const MCExpr *Expr = getTargetStreamer().addConstantPoolEntry(
892 const MCExpr *Expr = getTargetStreamer().addConstantPoolEntry(
898 Out.emitInstruction(Inst, getSTI());
902bool CSKYAsmParser::processInstruction(MCInst &Inst, SMLoc IDLoc,
913 return Error(IDLoc,
"Register sequence is not valid. 'r4-r7' expected");
920 return Error(IDLoc,
"msb must be greater or equal to lsb");
924 return Error(IDLoc,
"msb must be greater or equal to lsb");
928 return Error(IDLoc,
"n must be in range [0,32]");
959 case CSKY::PseudoLRW16:
960 case CSKY::PseudoLRW32:
961 return processLRW(Inst, IDLoc, Out);
962 case CSKY::PseudoJSRI32:
963 return processJSRI(Inst, IDLoc, Out);
964 case CSKY::PseudoJMPI32:
965 return processJMPI(Inst, IDLoc, Out);
976 const MCExpr *Expr = getTargetStreamer().addConstantPoolEntry(
983 emitToStreamer(Out, Inst);
994 if (
Reg == CSKY::NoRegister)
997 return Reg == CSKY::NoRegister;
1000bool CSKYAsmParser::parseRegister(MCRegister &
Reg, SMLoc &StartLoc,
1002 const AsmToken &Tok = getParser().getTok();
1005 StringRef
Name = getLexer().getTok().getIdentifier();
1019 switch (getLexer().getKind()) {
1023 StringRef
Name = getLexer().getTok().getIdentifier();
1040 Operands.push_back(CSKYOperand::createToken(
"(", getLoc()));
1042 auto Tok = getParser().Lex();
1044 if (!parseRegister(
Operands).isSuccess()) {
1045 getLexer().UnLex(Tok);
1051 Operands.push_back(CSKYOperand::createToken(
")", getLoc()));
1057 return Error(getLoc(),
"expected ','");
1061 if (parseRegister(
Operands).isSuccess()) {
1063 return Error(getLoc(),
"expected '<<'");
1065 Operands.push_back(CSKYOperand::createToken(
"<<", getLoc()));
1070 return Error(getLoc(),
"expected imm");
1073 return Error(getLoc(),
"expected imm");
1077 return Error(getLoc(),
"expected ')'");
1079 Operands.push_back(CSKYOperand::createToken(
")", getLoc()));
1087 switch (getLexer().getKind()) {
1098 const MCExpr *IdVal;
1100 if (getParser().parseExpression(IdVal))
1101 return Error(getLoc(),
"unknown expression");
1104 Operands.push_back(CSKYOperand::createImm(IdVal, S,
E));
1115 MatchOperandParserImpl(
Operands, Mnemonic,
true);
1122 auto Res = parseRegister(
Operands);
1123 if (Res.isSuccess())
1125 if (Res.isFailure())
1131 if (Res.isSuccess())
1133 if (Res.isFailure())
1138 if (Res.isSuccess())
1140 if (Res.isFailure())
1144 Error(getLoc(),
"unknown operand");
1157 AsmToken Tok = getLexer().getTok();
1159 if (getParser().parseIdentifier(Identifier))
1160 return Error(getLoc(),
"unknown identifier");
1171 else if (
Identifier.consume_back(
"@TLSGD32"))
1173 else if (
Identifier.consume_back(
"@GOTTPOFF"))
1177 else if (
Identifier.consume_back(
"@TLSLDM32"))
1179 else if (
Identifier.consume_back(
"@TLSLDO32"))
1185 Sym =
getContext().getOrCreateSymbol(Identifier);
1190 getLexer().UnLex(Tok);
1191 return Error(getLoc(),
"unknown symbol");
1198 switch (getLexer().getKind()) {
1203 Operands.push_back(CSKYOperand::createImm(Res, S,
E));
1216 if (getParser().parseExpression(Expr))
1217 return Error(getLoc(),
"unknown expression");
1219 Operands.push_back(CSKYOperand::createImm(Res, S,
E));
1232 if (getParser().parseExpression(Expr))
1233 return Error(getLoc(),
"unknown expression");
1238 Operands.push_back(CSKYOperand::createConstpoolOp(Expr, S,
E));
1242 AsmToken Tok = getLexer().getTok();
1245 if (getParser().parseIdentifier(Identifier))
1246 return Error(getLoc(),
"unknown identifier " + Identifier);
1257 Sym =
getContext().getOrCreateSymbol(Identifier);
1262 getLexer().UnLex(Tok);
1263 return Error(getLoc(),
"unknown symbol");
1271 switch (getLexer().getKind()) {
1273 return Error(getLoc(),
"unknown symbol");
1281 Operands.push_back(CSKYOperand::createConstpoolOp(Res, S,
E));
1294 if (getParser().parseExpression(Expr))
1295 return Error(getLoc(),
"unknown expression");
1300 Operands.push_back(CSKYOperand::createConstpoolOp(Res, S,
E));
1314 if (getParser().parseExpression(Expr))
1315 return Error(getLoc(),
"unknown expression");
1319 Operands.push_back(CSKYOperand::createConstpoolOp(Expr, S,
E));
1323 AsmToken Tok = getLexer().getTok();
1326 if (getParser().parseIdentifier(Identifier))
1327 return Error(getLoc(),
"unknown identifier");
1332 Sym =
getContext().getOrCreateSymbol(Identifier);
1337 getLexer().UnLex(Tok);
1338 return Error(getLoc(),
"unknown symbol");
1346 switch (getLexer().getKind()) {
1348 return Error(getLoc(),
"unknown symbol");
1353 Operands.push_back(CSKYOperand::createConstpoolOp(Res, S,
E));
1366 if (getParser().parseExpression(Expr))
1367 return Error(getLoc(),
"unknown expression");
1372 Operands.push_back(CSKYOperand::createConstpoolOp(Res, S,
E));
1384 if (getParser().parseIdentifier(Identifier))
1385 return Error(getLoc(),
"unknown identifier " + Identifier);
1387 if (Identifier ==
"sie")
1388 Flag = (1 << 4) | Flag;
1389 else if (Identifier ==
"ee")
1390 Flag = (1 << 3) | Flag;
1391 else if (Identifier ==
"ie")
1392 Flag = (1 << 2) | Flag;
1393 else if (Identifier ==
"fe")
1394 Flag = (1 << 1) | Flag;
1395 else if (Identifier ==
"af")
1396 Flag = (1 << 0) | Flag;
1398 return Error(getLoc(),
"expected " + Identifier);
1415 if (!parseRegister(
Operands).isSuccess())
1418 auto Ry =
Operands.back()->getReg();
1423 if (!parseRegister(
Operands).isSuccess())
1424 return Error(getLoc(),
"invalid register");
1426 auto Rz =
Operands.back()->getReg();
1429 Operands.push_back(CSKYOperand::createRegSeq(Ry, Rz, S));
1438 if (!parseRegister(
Operands).isSuccess())
1439 return Error(getLoc(),
"invalid register");
1441 auto Ry =
Operands.back()->getReg();
1445 if (!parseRegister(
Operands).isSuccess())
1446 return Error(getLoc(),
"invalid register");
1448 auto Rz =
Operands.back()->getReg();
1465 return Error(getLoc(),
"invalid register list");
1473bool CSKYAsmParser::parseInstruction(ParseInstructionInfo &Info, StringRef Name,
1476 Operands.push_back(CSKYOperand::createToken(Name, NameLoc));
1492 SMLoc Loc = getLexer().getLoc();
1493 getParser().eatToEndOfStatement();
1494 return Error(Loc,
"unexpected token");
1501ParseStatus CSKYAsmParser::tryParseRegister(MCRegister &
Reg, SMLoc &StartLoc,
1503 const AsmToken &Tok = getParser().getTok();
1507 StringRef
Name = getLexer().getTok().getIdentifier();
1516ParseStatus CSKYAsmParser::parseDirective(AsmToken DirectiveID) {
1517 StringRef IDVal = DirectiveID.
getString();
1519 if (IDVal ==
".csky_attribute")
1520 return parseDirectiveAttribute();
1527bool CSKYAsmParser::parseDirectiveAttribute() {
1528 MCAsmParser &Parser = getParser();
1534 std::optional<unsigned> Ret =
1537 return Error(TagLoc,
"attribute name not recognised: " + Name);
1541 const MCExpr *AttrExpr;
1549 return Error(TagLoc,
"expected numeric constant");
1551 Tag =
CE->getValue();
1557 StringRef StringValue;
1558 int64_t IntegerValue = 0;
1564 if (IsIntegerValue) {
1565 const MCExpr *ValueExpr;
1571 return Error(ValueExprLoc,
"expected numeric constant");
1572 IntegerValue =
CE->getValue();
1585 getTargetStreamer().emitAttribute(
Tag, IntegerValue);
1587 getTargetStreamer().emitTextAttribute(
Tag, StringValue);
1592 if (ID == CSKY::ArchKind::INVALID)
1594 ?
"unknown arch name"
1595 :
"unknown cpu name");
1597 getTargetStreamer().emitTextAttribute(
Tag, StringValue);
1603unsigned CSKYAsmParser::validateTargetOperandClass(MCParsedAsmOperand &AsmOp,
1605 CSKYOperand &
Op =
static_cast<CSKYOperand &
>(AsmOp);
1608 return Match_InvalidOperand;
1610 MCRegister
Reg =
Op.getReg();
1614 if (Kind == MCK_sFPR64 &&
1615 getCSKYMCRegisterClass(CSKY::FPR32RegClassID).
contains(
Reg))
1616 return Match_InvalidRegOutOfRange;
1618 return Match_InvalidOperand;
1621void CSKYAsmParser::emitToStreamer(MCStreamer &S,
const MCInst &Inst) {
1624 if (CLOpts.asm_compressed_inst)
1625 Res = compressInst(CInst, Inst, getSTI());
1627 ++CSKYNumInstrsCompressed;
static MCRegister MatchRegisterName(StringRef Name)
static const char * getSubtargetFeatureName(uint64_t Val)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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.
bpf unwind BPF Unwind Lower
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static bool matchRegisterNameHelper(const MCSubtargetInfo &STI, MCRegister &Reg, StringRef Name)
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeCSKYAsmParser()
static std::string CSKYMnemonicSpellCheck(StringRef S, const FeatureBitset &FBS, unsigned VariantID=0)
#define LLVM_EXTERNAL_VISIBILITY
static bool hasFeature(StringRef Feature, const FeatureBitset &FeatureBits, ArrayRef< SubtargetFeatureKV > ProcFeatures)
static MCRegister getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
static bool isReg(const MCInst &MI, unsigned OpNo)
static bool isUImm2(const MachineOperand &MO)
Func getContext().diagnose(DiagnosticInfoUnsupported(Func
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
bool parseImmediate(MCInst &MI, uint64_t &Size, ArrayRef< uint8_t > Bytes)
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...
StringRef getStringContents() const
Get the contents of a string token (without quotes).
bool is(TokenKind K) 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.
static const char * getRegisterName(const CSKYMCOptions &CLOpts, MCRegister Reg)
Base class for user error types.
Container class for subtarget features.
void printExpr(raw_ostream &, const MCExpr &) const
const MCTargetOptions & getTargetOptions() const
virtual void Initialize(MCAsmParser &Parser)
Initialize the extension for parsing using the given Parser.
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 const AsmToken & Lex()=0
Get the next AsmToken in the stream, possibly handling file inclusion first.
static LLVM_ABI const MCBinaryExpr * create(Opcode Op, const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
unsigned getNumOperands() const
unsigned getOpcode() const
iterator insert(iterator I, const MCOperand &Op)
void addOperand(const MCOperand Op)
void setOpcode(unsigned Op)
const MCOperand & getOperand(unsigned i) 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.
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
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
bool isVariable() const
isVariable - Check if this is a variable symbol.
const MCExpr * getVariableValue() const
Get the expression of the variable symbol.
MCTargetAsmParser - Generic interface to target specific assembly parsers.
Ternary parse status returned by various parse* methods.
static constexpr StatusTy Failure
static constexpr StatusTy Success
static constexpr StatusTy NoMatch
Represents a location in source code.
static SMLoc getFromPointer(const char *Ptr)
constexpr const char * getPointer() const
void push_back(const T &Elt)
Represent a constant reference to a string, i.e.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
const AArch64MCOptions & getCLOpts(const MCTargetOptions &Options)
LLVM_ABI const TagNameMap & getCSKYAttributeTags()
const CSKYMCOptions & getCLOpts(const MCTargetOptions &Options)
LLVM_ABI ArchKind parseCPUArch(StringRef CPU)
LLVM_ABI ArchKind parseArch(StringRef Arch)
LLVM_ABI std::optional< unsigned > attrTypeFromString(StringRef tag, TagNameMap tagNameMap)
Flag
These should be considered private to the implementation of the MCInstrDesc class.
@ CE
Windows NT (Windows on ARM)
LLVM_ABI TargetOptions getTargetOptions(const cl::LibraryOptionsContext &LibraryOptions, const llvm::Triple &TheTriple)
Common utility function tightly tied to the options listed here.
This is an optimization pass for GlobalISel generic memory operations.
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr, unsigned DynamicVGPRBlockSize=0)
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.
SmallVectorImpl< std::unique_ptr< MCParsedAsmOperand > > OperandVector
MachineInstr * getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
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...
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...
Target & getTheCSKYTarget()
DWARFExpression::Operation Op
constexpr bool isShiftedInt(int64_t x)
Checks if a signed integer is an N bit number shifted left by S.
constexpr bool isShiftedUInt(uint64_t x)
Checks if a unsigned integer is an N bit number shifted left by S.
RegisterMCAsmParser - Helper template for registering a target specific assembly parser,...