1 //===-- MipsAsmParser.cpp - Parse Mips assembly to MCInst instructions ----===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "MCTargetDesc/MipsMCExpr.h"
11 #include "MCTargetDesc/MipsMCTargetDesc.h"
12 #include "MipsRegisterInfo.h"
13 #include "MipsTargetStreamer.h"
14 #include "llvm/ADT/APInt.h"
15 #include "llvm/ADT/StringSwitch.h"
16 #include "llvm/MC/MCContext.h"
17 #include "llvm/MC/MCExpr.h"
18 #include "llvm/MC/MCInst.h"
19 #include "llvm/MC/MCInstBuilder.h"
20 #include "llvm/MC/MCParser/MCAsmLexer.h"
21 #include "llvm/MC/MCParser/MCParsedAsmOperand.h"
22 #include "llvm/MC/MCStreamer.h"
23 #include "llvm/MC/MCSubtargetInfo.h"
24 #include "llvm/MC/MCSymbol.h"
25 #include "llvm/MC/MCTargetAsmParser.h"
26 #include "llvm/Support/MathExtras.h"
27 #include "llvm/Support/TargetRegistry.h"
36 class MipsAssemblerOptions {
38 MipsAssemblerOptions() : aTReg(1), reorder(true), macro(true) {}
40 unsigned getATRegNum() { return aTReg; }
41 bool setATReg(unsigned Reg);
43 bool isReorder() { return reorder; }
44 void setReorder() { reorder = true; }
45 void setNoreorder() { reorder = false; }
47 bool isMacro() { return macro; }
48 void setMacro() { macro = true; }
49 void setNomacro() { macro = false; }
59 class MipsAsmParser : public MCTargetAsmParser {
61 MipsTargetStreamer &getTargetStreamer() {
62 MCTargetStreamer &TS = *Parser.getStreamer().getTargetStreamer();
63 return static_cast<MipsTargetStreamer &>(TS);
68 MipsAssemblerOptions Options;
69 bool hasConsumedDollar;
71 #define GET_ASSEMBLER_HEADER
72 #include "MipsGenAsmMatcher.inc"
74 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
75 SmallVectorImpl<MCParsedAsmOperand *> &Operands,
76 MCStreamer &Out, unsigned &ErrorInfo,
77 bool MatchingInlineAsm);
79 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
81 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
83 SmallVectorImpl<MCParsedAsmOperand *> &Operands);
85 bool ParseDirective(AsmToken DirectiveID);
87 MipsAsmParser::OperandMatchResultTy
88 parseRegs(SmallVectorImpl<MCParsedAsmOperand *> &Operands, int RegKind);
90 MipsAsmParser::OperandMatchResultTy
91 parseMSARegs(SmallVectorImpl<MCParsedAsmOperand *> &Operands, int RegKind);
93 MipsAsmParser::OperandMatchResultTy
94 parseMSACtrlRegs(SmallVectorImpl<MCParsedAsmOperand *> &Operands,
97 MipsAsmParser::OperandMatchResultTy
98 parseMemOperand(SmallVectorImpl<MCParsedAsmOperand *> &Operands);
100 bool parsePtrReg(SmallVectorImpl<MCParsedAsmOperand *> &Operands,
103 MipsAsmParser::OperandMatchResultTy
104 parsePtrReg(SmallVectorImpl<MCParsedAsmOperand *> &Operands);
106 MipsAsmParser::OperandMatchResultTy
107 parseGPR32(SmallVectorImpl<MCParsedAsmOperand *> &Operands);
109 MipsAsmParser::OperandMatchResultTy
110 parseGPR64(SmallVectorImpl<MCParsedAsmOperand *> &Operands);
112 MipsAsmParser::OperandMatchResultTy
113 parseHWRegs(SmallVectorImpl<MCParsedAsmOperand *> &Operands);
115 MipsAsmParser::OperandMatchResultTy
116 parseCCRRegs(SmallVectorImpl<MCParsedAsmOperand *> &Operands);
118 MipsAsmParser::OperandMatchResultTy
119 parseAFGR64Regs(SmallVectorImpl<MCParsedAsmOperand *> &Operands);
121 MipsAsmParser::OperandMatchResultTy
122 parseFGR64Regs(SmallVectorImpl<MCParsedAsmOperand *> &Operands);
124 MipsAsmParser::OperandMatchResultTy
125 parseFGR32Regs(SmallVectorImpl<MCParsedAsmOperand *> &Operands);
127 MipsAsmParser::OperandMatchResultTy
128 parseFGRH32Regs(SmallVectorImpl<MCParsedAsmOperand *> &Operands);
130 MipsAsmParser::OperandMatchResultTy
131 parseFCCRegs(SmallVectorImpl<MCParsedAsmOperand *> &Operands);
133 MipsAsmParser::OperandMatchResultTy
134 parseACC64DSP(SmallVectorImpl<MCParsedAsmOperand *> &Operands);
136 MipsAsmParser::OperandMatchResultTy
137 parseLO32DSP(SmallVectorImpl<MCParsedAsmOperand *> &Operands);
139 MipsAsmParser::OperandMatchResultTy
140 parseHI32DSP(SmallVectorImpl<MCParsedAsmOperand *> &Operands);
142 MipsAsmParser::OperandMatchResultTy
143 parseCOP2(SmallVectorImpl<MCParsedAsmOperand *> &Operands);
145 MipsAsmParser::OperandMatchResultTy
146 parseMSA128BRegs(SmallVectorImpl<MCParsedAsmOperand *> &Operands);
148 MipsAsmParser::OperandMatchResultTy
149 parseMSA128HRegs(SmallVectorImpl<MCParsedAsmOperand *> &Operands);
151 MipsAsmParser::OperandMatchResultTy
152 parseMSA128WRegs(SmallVectorImpl<MCParsedAsmOperand *> &Operands);
154 MipsAsmParser::OperandMatchResultTy
155 parseMSA128DRegs(SmallVectorImpl<MCParsedAsmOperand *> &Operands);
157 MipsAsmParser::OperandMatchResultTy
158 parseMSA128CtrlRegs(SmallVectorImpl<MCParsedAsmOperand *> &Operands);
160 MipsAsmParser::OperandMatchResultTy
161 parseInvNum(SmallVectorImpl<MCParsedAsmOperand *> &Operands);
163 MipsAsmParser::OperandMatchResultTy
164 parseLSAImm(SmallVectorImpl<MCParsedAsmOperand *> &Operands);
166 bool searchSymbolAlias(SmallVectorImpl<MCParsedAsmOperand *> &Operands,
169 bool ParseOperand(SmallVectorImpl<MCParsedAsmOperand *> &,
172 int tryParseRegister(bool is64BitReg);
174 bool tryParseRegisterOperand(SmallVectorImpl<MCParsedAsmOperand *> &Operands,
177 bool needsExpansion(MCInst &Inst);
179 void expandInstruction(MCInst &Inst, SMLoc IDLoc,
180 SmallVectorImpl<MCInst> &Instructions);
181 void expandLoadImm(MCInst &Inst, SMLoc IDLoc,
182 SmallVectorImpl<MCInst> &Instructions);
183 void expandLoadAddressImm(MCInst &Inst, SMLoc IDLoc,
184 SmallVectorImpl<MCInst> &Instructions);
185 void expandLoadAddressReg(MCInst &Inst, SMLoc IDLoc,
186 SmallVectorImpl<MCInst> &Instructions);
187 void expandMemInst(MCInst &Inst, SMLoc IDLoc,
188 SmallVectorImpl<MCInst> &Instructions, bool isLoad,
190 bool reportParseError(StringRef ErrorMsg);
192 bool parseMemOffset(const MCExpr *&Res, bool isParenExpr);
193 bool parseRelocOperand(const MCExpr *&Res);
195 const MCExpr *evaluateRelocExpr(const MCExpr *Expr, StringRef RelocStr);
197 bool isEvaluated(const MCExpr *Expr);
198 bool parseSetFeature(uint64_t Feature);
199 bool parseDirectiveCPSetup();
200 bool parseDirectiveSet();
201 bool parseDirectiveOption();
203 bool parseSetAtDirective();
204 bool parseSetNoAtDirective();
205 bool parseSetMacroDirective();
206 bool parseSetNoMacroDirective();
207 bool parseSetReorderDirective();
208 bool parseSetNoReorderDirective();
209 bool parseSetNoMips16Directive();
211 bool parseSetAssignment();
213 bool parseDataDirective(unsigned Size, SMLoc L);
214 bool parseDirectiveGpWord();
216 MCSymbolRefExpr::VariantKind getVariantKind(StringRef Symbol);
218 bool isGP64() const {
219 return (STI.getFeatureBits() & Mips::FeatureGP64Bit) != 0;
222 bool isFP64() const {
223 return (STI.getFeatureBits() & Mips::FeatureFP64Bit) != 0;
226 bool isN32() const { return STI.getFeatureBits() & Mips::FeatureN32; }
227 bool isN64() const { return STI.getFeatureBits() & Mips::FeatureN64; }
229 bool isMicroMips() const {
230 return STI.getFeatureBits() & Mips::FeatureMicroMips;
233 bool parseRegister(unsigned &RegNum);
235 bool eatComma(StringRef ErrorStr);
237 int matchRegisterName(StringRef Symbol, bool is64BitReg);
239 int matchCPURegisterName(StringRef Symbol);
241 int matchRegisterByNumber(unsigned RegNum, unsigned RegClass);
243 int matchFPURegisterName(StringRef Name);
245 int matchFCCRegisterName(StringRef Name);
247 int matchACRegisterName(StringRef Name);
249 int matchMSA128RegisterName(StringRef Name);
251 int matchMSA128CtrlRegisterName(StringRef Name);
253 int regKindToRegClass(int RegKind);
255 unsigned getReg(int RC, int RegNo);
257 unsigned getGPR(int RegNo);
261 // Warn if RegNo is the current assembler temporary.
262 void warnIfAssemblerTemporary(int RegNo);
264 bool processInstruction(MCInst &Inst, SMLoc IDLoc,
265 SmallVectorImpl<MCInst> &Instructions);
267 // Helper function that checks if the value of a vector index is within the
268 // boundaries of accepted values for each RegisterKind
269 // Example: INSERT.B $w0[n], $1 => 16 > n >= 0
270 bool validateMSAIndex(int Val, int RegKind);
272 void setFeatureBits(unsigned Feature, StringRef FeatureString) {
273 if (!(STI.getFeatureBits() & Feature)) {
274 setAvailableFeatures(ComputeAvailableFeatures(
275 STI.ToggleFeature(FeatureString)));
279 void clearFeatureBits(unsigned Feature, StringRef FeatureString) {
280 if (STI.getFeatureBits() & Feature) {
281 setAvailableFeatures(ComputeAvailableFeatures(
282 STI.ToggleFeature(FeatureString)));
287 MipsAsmParser(MCSubtargetInfo &sti, MCAsmParser &parser,
288 const MCInstrInfo &MII)
289 : MCTargetAsmParser(), STI(sti), Parser(parser),
290 hasConsumedDollar(false) {
291 // Initialize the set of available features.
292 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
294 // Assert exactly one ABI was chosen.
295 assert((((STI.getFeatureBits() & Mips::FeatureO32) != 0) +
296 ((STI.getFeatureBits() & Mips::FeatureEABI) != 0) +
297 ((STI.getFeatureBits() & Mips::FeatureN32) != 0) +
298 ((STI.getFeatureBits() & Mips::FeatureN64) != 0)) == 1);
301 MCAsmParser &getParser() const { return Parser; }
302 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
308 /// MipsOperand - Instances of this class represent a parsed Mips machine
310 class MipsOperand : public MCParsedAsmOperand {
348 MipsOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
376 SMLoc StartLoc, EndLoc;
379 void addRegOperands(MCInst &Inst, unsigned N) const {
380 assert(N == 1 && "Invalid number of operands!");
381 Inst.addOperand(MCOperand::CreateReg(getReg()));
384 void addPtrRegOperands(MCInst &Inst, unsigned N) const {
385 assert(N == 1 && "Invalid number of operands!");
386 Inst.addOperand(MCOperand::CreateReg(getPtrReg()));
389 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
390 // Add as immediate when possible. Null MCExpr = 0.
392 Inst.addOperand(MCOperand::CreateImm(0));
393 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
394 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
396 Inst.addOperand(MCOperand::CreateExpr(Expr));
399 void addImmOperands(MCInst &Inst, unsigned N) const {
400 assert(N == 1 && "Invalid number of operands!");
401 const MCExpr *Expr = getImm();
405 void addMemOperands(MCInst &Inst, unsigned N) const {
406 assert(N == 2 && "Invalid number of operands!");
408 Inst.addOperand(MCOperand::CreateReg(getMemBase()));
410 const MCExpr *Expr = getMemOff();
414 bool isReg() const { return Kind == k_Register; }
415 bool isImm() const { return Kind == k_Immediate; }
416 bool isToken() const { return Kind == k_Token; }
417 bool isMem() const { return Kind == k_Memory; }
418 bool isPtrReg() const { return Kind == k_PtrReg; }
419 bool isInvNum() const { return Kind == k_Immediate; }
420 bool isLSAImm() const { return Kind == k_LSAImm; }
422 StringRef getToken() const {
423 assert(Kind == k_Token && "Invalid access!");
424 return StringRef(Tok.Data, Tok.Length);
427 unsigned getReg() const {
428 assert((Kind == k_Register) && "Invalid access!");
432 unsigned getPtrReg() const {
433 assert((Kind == k_PtrReg) && "Invalid access!");
437 void setRegKind(RegisterKind RegKind) {
438 assert((Kind == k_Register || Kind == k_PtrReg) && "Invalid access!");
442 const MCExpr *getImm() const {
443 assert((Kind == k_Immediate || Kind == k_LSAImm) && "Invalid access!");
447 unsigned getMemBase() const {
448 assert((Kind == k_Memory) && "Invalid access!");
452 const MCExpr *getMemOff() const {
453 assert((Kind == k_Memory) && "Invalid access!");
457 static MipsOperand *CreateToken(StringRef Str, SMLoc S) {
458 MipsOperand *Op = new MipsOperand(k_Token);
459 Op->Tok.Data = Str.data();
460 Op->Tok.Length = Str.size();
466 static MipsOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
467 MipsOperand *Op = new MipsOperand(k_Register);
468 Op->Reg.RegNum = RegNum;
474 static MipsOperand *CreatePtrReg(unsigned RegNum, SMLoc S, SMLoc E) {
475 MipsOperand *Op = new MipsOperand(k_PtrReg);
476 Op->Reg.RegNum = RegNum;
482 static MipsOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
483 MipsOperand *Op = new MipsOperand(k_Immediate);
490 static MipsOperand *CreateLSAImm(const MCExpr *Val, SMLoc S, SMLoc E) {
491 MipsOperand *Op = new MipsOperand(k_LSAImm);
498 static MipsOperand *CreateMem(unsigned Base, const MCExpr *Off, SMLoc S,
500 MipsOperand *Op = new MipsOperand(k_Memory);
508 bool isGPR32Asm() const {
509 return Kind == k_Register && Reg.Kind == Kind_GPR32;
511 void addRegAsmOperands(MCInst &Inst, unsigned N) const {
512 Inst.addOperand(MCOperand::CreateReg(Reg.RegNum));
515 bool isGPR64Asm() const {
516 return Kind == k_Register && Reg.Kind == Kind_GPR64;
519 bool isHWRegsAsm() const {
520 assert((Kind == k_Register) && "Invalid access!");
521 return Reg.Kind == Kind_HWRegs;
524 bool isCCRAsm() const {
525 assert((Kind == k_Register) && "Invalid access!");
526 return Reg.Kind == Kind_CCRRegs;
529 bool isAFGR64Asm() const {
530 return Kind == k_Register && Reg.Kind == Kind_AFGR64Regs;
533 bool isFGR64Asm() const {
534 return Kind == k_Register && Reg.Kind == Kind_FGR64Regs;
537 bool isFGR32Asm() const {
538 return (Kind == k_Register) && Reg.Kind == Kind_FGR32Regs;
541 bool isFGRH32Asm() const {
542 return (Kind == k_Register) && Reg.Kind == Kind_FGRH32Regs;
545 bool isFCCRegsAsm() const {
546 return (Kind == k_Register) && Reg.Kind == Kind_FCCRegs;
549 bool isACC64DSPAsm() const {
550 return Kind == k_Register && Reg.Kind == Kind_ACC64DSP;
553 bool isLO32DSPAsm() const {
554 return Kind == k_Register && Reg.Kind == Kind_LO32DSP;
557 bool isHI32DSPAsm() const {
558 return Kind == k_Register && Reg.Kind == Kind_HI32DSP;
561 bool isCOP2Asm() const { return Kind == k_Register && Reg.Kind == Kind_COP2; }
563 bool isMSA128BAsm() const {
564 return Kind == k_Register && Reg.Kind == Kind_MSA128BRegs;
567 bool isMSA128HAsm() const {
568 return Kind == k_Register && Reg.Kind == Kind_MSA128HRegs;
571 bool isMSA128WAsm() const {
572 return Kind == k_Register && Reg.Kind == Kind_MSA128WRegs;
575 bool isMSA128DAsm() const {
576 return Kind == k_Register && Reg.Kind == Kind_MSA128DRegs;
579 bool isMSA128CRAsm() const {
580 return Kind == k_Register && Reg.Kind == Kind_MSA128CtrlRegs;
583 /// getStartLoc - Get the location of the first token of this operand.
584 SMLoc getStartLoc() const { return StartLoc; }
585 /// getEndLoc - Get the location of the last token of this operand.
586 SMLoc getEndLoc() const { return EndLoc; }
588 virtual void print(raw_ostream &OS) const {
589 llvm_unreachable("unimplemented!");
591 }; // class MipsOperand
595 extern const MCInstrDesc MipsInsts[];
597 static const MCInstrDesc &getInstDesc(unsigned Opcode) {
598 return MipsInsts[Opcode];
601 bool MipsAsmParser::processInstruction(MCInst &Inst, SMLoc IDLoc,
602 SmallVectorImpl<MCInst> &Instructions) {
603 const MCInstrDesc &MCID = getInstDesc(Inst.getOpcode());
607 if (MCID.isBranch() || MCID.isCall()) {
608 const unsigned Opcode = Inst.getOpcode();
616 assert(MCID.getNumOperands() == 3 && "unexpected number of operands");
617 Offset = Inst.getOperand(2);
619 break; // We'll deal with this situation later on when applying fixups.
620 if (!isIntN(isMicroMips() ? 17 : 18, Offset.getImm()))
621 return Error(IDLoc, "branch target out of range");
622 if (OffsetToAlignment(Offset.getImm(), 1LL << (isMicroMips() ? 1 : 2)))
623 return Error(IDLoc, "branch to misaligned address");
633 assert(MCID.getNumOperands() == 2 && "unexpected number of operands");
634 Offset = Inst.getOperand(1);
636 break; // We'll deal with this situation later on when applying fixups.
637 if (!isIntN(isMicroMips() ? 17 : 18, Offset.getImm()))
638 return Error(IDLoc, "branch target out of range");
639 if (OffsetToAlignment(Offset.getImm(), 1LL << (isMicroMips() ? 1 : 2)))
640 return Error(IDLoc, "branch to misaligned address");
645 if (MCID.hasDelaySlot() && Options.isReorder()) {
646 // If this instruction has a delay slot and .set reorder is active,
647 // emit a NOP after it.
648 Instructions.push_back(Inst);
650 NopInst.setOpcode(Mips::SLL);
651 NopInst.addOperand(MCOperand::CreateReg(Mips::ZERO));
652 NopInst.addOperand(MCOperand::CreateReg(Mips::ZERO));
653 NopInst.addOperand(MCOperand::CreateImm(0));
654 Instructions.push_back(NopInst);
658 if (MCID.mayLoad() || MCID.mayStore()) {
659 // Check the offset of memory operand, if it is a symbol
660 // reference or immediate we may have to expand instructions.
661 for (unsigned i = 0; i < MCID.getNumOperands(); i++) {
662 const MCOperandInfo &OpInfo = MCID.OpInfo[i];
663 if ((OpInfo.OperandType == MCOI::OPERAND_MEMORY) ||
664 (OpInfo.OperandType == MCOI::OPERAND_UNKNOWN)) {
665 MCOperand &Op = Inst.getOperand(i);
667 int MemOffset = Op.getImm();
668 if (MemOffset < -32768 || MemOffset > 32767) {
669 // Offset can't exceed 16bit value.
670 expandMemInst(Inst, IDLoc, Instructions, MCID.mayLoad(), true);
673 } else if (Op.isExpr()) {
674 const MCExpr *Expr = Op.getExpr();
675 if (Expr->getKind() == MCExpr::SymbolRef) {
676 const MCSymbolRefExpr *SR =
677 static_cast<const MCSymbolRefExpr *>(Expr);
678 if (SR->getKind() == MCSymbolRefExpr::VK_None) {
680 expandMemInst(Inst, IDLoc, Instructions, MCID.mayLoad(), false);
683 } else if (!isEvaluated(Expr)) {
684 expandMemInst(Inst, IDLoc, Instructions, MCID.mayLoad(), false);
692 if (needsExpansion(Inst))
693 expandInstruction(Inst, IDLoc, Instructions);
695 Instructions.push_back(Inst);
700 bool MipsAsmParser::needsExpansion(MCInst &Inst) {
702 switch (Inst.getOpcode()) {
703 case Mips::LoadImm32Reg:
704 case Mips::LoadAddr32Imm:
705 case Mips::LoadAddr32Reg:
716 void MipsAsmParser::expandInstruction(MCInst &Inst, SMLoc IDLoc,
717 SmallVectorImpl<MCInst> &Instructions) {
718 switch (Inst.getOpcode()) {
719 case Mips::LoadImm32Reg:
720 return expandLoadImm(Inst, IDLoc, Instructions);
721 case Mips::LoadAddr32Imm:
722 return expandLoadAddressImm(Inst, IDLoc, Instructions);
723 case Mips::LoadAddr32Reg:
724 return expandLoadAddressReg(Inst, IDLoc, Instructions);
726 Instructions.push_back(MCInstBuilder(Mips::ADDi)
727 .addReg(Inst.getOperand(0).getReg())
728 .addReg(Inst.getOperand(1).getReg())
729 .addImm(-Inst.getOperand(2).getImm()));
732 Instructions.push_back(MCInstBuilder(Mips::ADDiu)
733 .addReg(Inst.getOperand(0).getReg())
734 .addReg(Inst.getOperand(1).getReg())
735 .addImm(-Inst.getOperand(2).getImm()));
738 Instructions.push_back(MCInstBuilder(Mips::DADDi)
739 .addReg(Inst.getOperand(0).getReg())
740 .addReg(Inst.getOperand(1).getReg())
741 .addImm(-Inst.getOperand(2).getImm()));
744 Instructions.push_back(MCInstBuilder(Mips::DADDiu)
745 .addReg(Inst.getOperand(0).getReg())
746 .addReg(Inst.getOperand(1).getReg())
747 .addImm(-Inst.getOperand(2).getImm()));
752 void MipsAsmParser::expandLoadImm(MCInst &Inst, SMLoc IDLoc,
753 SmallVectorImpl<MCInst> &Instructions) {
755 const MCOperand &ImmOp = Inst.getOperand(1);
756 assert(ImmOp.isImm() && "expected immediate operand kind");
757 const MCOperand &RegOp = Inst.getOperand(0);
758 assert(RegOp.isReg() && "expected register operand kind");
760 int ImmValue = ImmOp.getImm();
761 tmpInst.setLoc(IDLoc);
762 if (0 <= ImmValue && ImmValue <= 65535) {
763 // For 0 <= j <= 65535.
764 // li d,j => ori d,$zero,j
765 tmpInst.setOpcode(Mips::ORi);
766 tmpInst.addOperand(MCOperand::CreateReg(RegOp.getReg()));
767 tmpInst.addOperand(MCOperand::CreateReg(Mips::ZERO));
768 tmpInst.addOperand(MCOperand::CreateImm(ImmValue));
769 Instructions.push_back(tmpInst);
770 } else if (ImmValue < 0 && ImmValue >= -32768) {
771 // For -32768 <= j < 0.
772 // li d,j => addiu d,$zero,j
773 tmpInst.setOpcode(Mips::ADDiu);
774 tmpInst.addOperand(MCOperand::CreateReg(RegOp.getReg()));
775 tmpInst.addOperand(MCOperand::CreateReg(Mips::ZERO));
776 tmpInst.addOperand(MCOperand::CreateImm(ImmValue));
777 Instructions.push_back(tmpInst);
779 // For any other value of j that is representable as a 32-bit integer.
780 // li d,j => lui d,hi16(j)
782 tmpInst.setOpcode(Mips::LUi);
783 tmpInst.addOperand(MCOperand::CreateReg(RegOp.getReg()));
784 tmpInst.addOperand(MCOperand::CreateImm((ImmValue & 0xffff0000) >> 16));
785 Instructions.push_back(tmpInst);
787 tmpInst.setOpcode(Mips::ORi);
788 tmpInst.addOperand(MCOperand::CreateReg(RegOp.getReg()));
789 tmpInst.addOperand(MCOperand::CreateReg(RegOp.getReg()));
790 tmpInst.addOperand(MCOperand::CreateImm(ImmValue & 0xffff));
791 tmpInst.setLoc(IDLoc);
792 Instructions.push_back(tmpInst);
797 MipsAsmParser::expandLoadAddressReg(MCInst &Inst, SMLoc IDLoc,
798 SmallVectorImpl<MCInst> &Instructions) {
800 const MCOperand &ImmOp = Inst.getOperand(2);
801 assert(ImmOp.isImm() && "expected immediate operand kind");
802 const MCOperand &SrcRegOp = Inst.getOperand(1);
803 assert(SrcRegOp.isReg() && "expected register operand kind");
804 const MCOperand &DstRegOp = Inst.getOperand(0);
805 assert(DstRegOp.isReg() && "expected register operand kind");
806 int ImmValue = ImmOp.getImm();
807 if (-32768 <= ImmValue && ImmValue <= 65535) {
808 // For -32768 <= j <= 65535.
809 // la d,j(s) => addiu d,s,j
810 tmpInst.setOpcode(Mips::ADDiu);
811 tmpInst.addOperand(MCOperand::CreateReg(DstRegOp.getReg()));
812 tmpInst.addOperand(MCOperand::CreateReg(SrcRegOp.getReg()));
813 tmpInst.addOperand(MCOperand::CreateImm(ImmValue));
814 Instructions.push_back(tmpInst);
816 // For any other value of j that is representable as a 32-bit integer.
817 // la d,j(s) => lui d,hi16(j)
820 tmpInst.setOpcode(Mips::LUi);
821 tmpInst.addOperand(MCOperand::CreateReg(DstRegOp.getReg()));
822 tmpInst.addOperand(MCOperand::CreateImm((ImmValue & 0xffff0000) >> 16));
823 Instructions.push_back(tmpInst);
825 tmpInst.setOpcode(Mips::ORi);
826 tmpInst.addOperand(MCOperand::CreateReg(DstRegOp.getReg()));
827 tmpInst.addOperand(MCOperand::CreateReg(DstRegOp.getReg()));
828 tmpInst.addOperand(MCOperand::CreateImm(ImmValue & 0xffff));
829 Instructions.push_back(tmpInst);
831 tmpInst.setOpcode(Mips::ADDu);
832 tmpInst.addOperand(MCOperand::CreateReg(DstRegOp.getReg()));
833 tmpInst.addOperand(MCOperand::CreateReg(DstRegOp.getReg()));
834 tmpInst.addOperand(MCOperand::CreateReg(SrcRegOp.getReg()));
835 Instructions.push_back(tmpInst);
840 MipsAsmParser::expandLoadAddressImm(MCInst &Inst, SMLoc IDLoc,
841 SmallVectorImpl<MCInst> &Instructions) {
843 const MCOperand &ImmOp = Inst.getOperand(1);
844 assert(ImmOp.isImm() && "expected immediate operand kind");
845 const MCOperand &RegOp = Inst.getOperand(0);
846 assert(RegOp.isReg() && "expected register operand kind");
847 int ImmValue = ImmOp.getImm();
848 if (-32768 <= ImmValue && ImmValue <= 65535) {
849 // For -32768 <= j <= 65535.
850 // la d,j => addiu d,$zero,j
851 tmpInst.setOpcode(Mips::ADDiu);
852 tmpInst.addOperand(MCOperand::CreateReg(RegOp.getReg()));
853 tmpInst.addOperand(MCOperand::CreateReg(Mips::ZERO));
854 tmpInst.addOperand(MCOperand::CreateImm(ImmValue));
855 Instructions.push_back(tmpInst);
857 // For any other value of j that is representable as a 32-bit integer.
858 // la d,j => lui d,hi16(j)
860 tmpInst.setOpcode(Mips::LUi);
861 tmpInst.addOperand(MCOperand::CreateReg(RegOp.getReg()));
862 tmpInst.addOperand(MCOperand::CreateImm((ImmValue & 0xffff0000) >> 16));
863 Instructions.push_back(tmpInst);
865 tmpInst.setOpcode(Mips::ORi);
866 tmpInst.addOperand(MCOperand::CreateReg(RegOp.getReg()));
867 tmpInst.addOperand(MCOperand::CreateReg(RegOp.getReg()));
868 tmpInst.addOperand(MCOperand::CreateImm(ImmValue & 0xffff));
869 Instructions.push_back(tmpInst);
873 void MipsAsmParser::expandMemInst(MCInst &Inst, SMLoc IDLoc,
874 SmallVectorImpl<MCInst> &Instructions,
875 bool isLoad, bool isImmOpnd) {
876 const MCSymbolRefExpr *SR;
878 unsigned ImmOffset, HiOffset, LoOffset;
879 const MCExpr *ExprOffset;
881 unsigned AtRegNum = getReg(
882 (isGP64()) ? Mips::GPR64RegClassID : Mips::GPR32RegClassID, getATReg());
883 // 1st operand is either the source or destination register.
884 assert(Inst.getOperand(0).isReg() && "expected register operand kind");
885 unsigned RegOpNum = Inst.getOperand(0).getReg();
886 // 2nd operand is the base register.
887 assert(Inst.getOperand(1).isReg() && "expected register operand kind");
888 unsigned BaseRegNum = Inst.getOperand(1).getReg();
889 // 3rd operand is either an immediate or expression.
891 assert(Inst.getOperand(2).isImm() && "expected immediate operand kind");
892 ImmOffset = Inst.getOperand(2).getImm();
893 LoOffset = ImmOffset & 0x0000ffff;
894 HiOffset = (ImmOffset & 0xffff0000) >> 16;
895 // If msb of LoOffset is 1(negative number) we must increment HiOffset.
896 if (LoOffset & 0x8000)
899 ExprOffset = Inst.getOperand(2).getExpr();
900 // All instructions will have the same location.
901 TempInst.setLoc(IDLoc);
902 // 1st instruction in expansion is LUi. For load instruction we can use
903 // the dst register as a temporary if base and dst are different,
904 // but for stores we must use $at.
905 TmpRegNum = (isLoad && (BaseRegNum != RegOpNum)) ? RegOpNum : AtRegNum;
906 TempInst.setOpcode(Mips::LUi);
907 TempInst.addOperand(MCOperand::CreateReg(TmpRegNum));
909 TempInst.addOperand(MCOperand::CreateImm(HiOffset));
911 if (ExprOffset->getKind() == MCExpr::SymbolRef) {
912 SR = static_cast<const MCSymbolRefExpr *>(ExprOffset);
913 const MCSymbolRefExpr *HiExpr = MCSymbolRefExpr::Create(
914 SR->getSymbol().getName(), MCSymbolRefExpr::VK_Mips_ABS_HI,
916 TempInst.addOperand(MCOperand::CreateExpr(HiExpr));
918 const MCExpr *HiExpr = evaluateRelocExpr(ExprOffset, "hi");
919 TempInst.addOperand(MCOperand::CreateExpr(HiExpr));
922 // Add the instruction to the list.
923 Instructions.push_back(TempInst);
924 // Prepare TempInst for next instruction.
926 // Add temp register to base.
927 TempInst.setOpcode(Mips::ADDu);
928 TempInst.addOperand(MCOperand::CreateReg(TmpRegNum));
929 TempInst.addOperand(MCOperand::CreateReg(TmpRegNum));
930 TempInst.addOperand(MCOperand::CreateReg(BaseRegNum));
931 Instructions.push_back(TempInst);
933 // And finally, create original instruction with low part
934 // of offset and new base.
935 TempInst.setOpcode(Inst.getOpcode());
936 TempInst.addOperand(MCOperand::CreateReg(RegOpNum));
937 TempInst.addOperand(MCOperand::CreateReg(TmpRegNum));
939 TempInst.addOperand(MCOperand::CreateImm(LoOffset));
941 if (ExprOffset->getKind() == MCExpr::SymbolRef) {
942 const MCSymbolRefExpr *LoExpr = MCSymbolRefExpr::Create(
943 SR->getSymbol().getName(), MCSymbolRefExpr::VK_Mips_ABS_LO,
945 TempInst.addOperand(MCOperand::CreateExpr(LoExpr));
947 const MCExpr *LoExpr = evaluateRelocExpr(ExprOffset, "lo");
948 TempInst.addOperand(MCOperand::CreateExpr(LoExpr));
951 Instructions.push_back(TempInst);
955 bool MipsAsmParser::MatchAndEmitInstruction(
956 SMLoc IDLoc, unsigned &Opcode,
957 SmallVectorImpl<MCParsedAsmOperand *> &Operands, MCStreamer &Out,
958 unsigned &ErrorInfo, bool MatchingInlineAsm) {
960 SmallVector<MCInst, 8> Instructions;
961 unsigned MatchResult =
962 MatchInstructionImpl(Operands, Inst, ErrorInfo, MatchingInlineAsm);
964 switch (MatchResult) {
967 case Match_Success: {
968 if (processInstruction(Inst, IDLoc, Instructions))
970 for (unsigned i = 0; i < Instructions.size(); i++)
971 Out.EmitInstruction(Instructions[i], STI);
974 case Match_MissingFeature:
975 Error(IDLoc, "instruction requires a CPU feature not currently enabled");
977 case Match_InvalidOperand: {
978 SMLoc ErrorLoc = IDLoc;
979 if (ErrorInfo != ~0U) {
980 if (ErrorInfo >= Operands.size())
981 return Error(IDLoc, "too few operands for instruction");
983 ErrorLoc = ((MipsOperand *)Operands[ErrorInfo])->getStartLoc();
984 if (ErrorLoc == SMLoc())
988 return Error(ErrorLoc, "invalid operand for instruction");
990 case Match_MnemonicFail:
991 return Error(IDLoc, "invalid instruction");
996 void MipsAsmParser::warnIfAssemblerTemporary(int RegNo) {
997 if ((RegNo != 0) && ((int)Options.getATRegNum() == RegNo)) {
999 Warning(getLexer().getLoc(), "Used $at without \".set noat\"");
1001 Warning(getLexer().getLoc(), Twine("Used $") + Twine(RegNo) +
1002 " with \".set at=$" + Twine(RegNo) +
1007 int MipsAsmParser::matchCPURegisterName(StringRef Name) {
1010 CC = StringSwitch<unsigned>(Name)
1046 if (isN32() || isN64()) {
1047 // Although SGI documentation just cuts out t0-t3 for n32/n64,
1048 // GNU pushes the values of t0-t3 to override the o32/o64 values for t4-t7
1049 // We are supporting both cases, so for t0-t3 we'll just push them to t4-t7.
1050 if (8 <= CC && CC <= 11)
1054 CC = StringSwitch<unsigned>(Name)
1064 warnIfAssemblerTemporary(CC);
1069 int MipsAsmParser::matchFPURegisterName(StringRef Name) {
1071 if (Name[0] == 'f') {
1072 StringRef NumString = Name.substr(1);
1074 if (NumString.getAsInteger(10, IntVal))
1075 return -1; // This is not an integer.
1076 if (IntVal > 31) // Maximum index for fpu register.
1083 int MipsAsmParser::matchFCCRegisterName(StringRef Name) {
1085 if (Name.startswith("fcc")) {
1086 StringRef NumString = Name.substr(3);
1088 if (NumString.getAsInteger(10, IntVal))
1089 return -1; // This is not an integer.
1090 if (IntVal > 7) // There are only 8 fcc registers.
1097 int MipsAsmParser::matchACRegisterName(StringRef Name) {
1099 if (Name.startswith("ac")) {
1100 StringRef NumString = Name.substr(2);
1102 if (NumString.getAsInteger(10, IntVal))
1103 return -1; // This is not an integer.
1104 if (IntVal > 3) // There are only 3 acc registers.
1111 int MipsAsmParser::matchMSA128RegisterName(StringRef Name) {
1114 if (Name.front() != 'w' || Name.drop_front(1).getAsInteger(10, IntVal))
1123 int MipsAsmParser::matchMSA128CtrlRegisterName(StringRef Name) {
1126 CC = StringSwitch<unsigned>(Name)
1129 .Case("msaaccess", 2)
1131 .Case("msamodify", 4)
1132 .Case("msarequest", 5)
1134 .Case("msaunmap", 7)
1140 int MipsAsmParser::matchRegisterName(StringRef Name, bool is64BitReg) {
1143 CC = matchCPURegisterName(Name);
1145 return matchRegisterByNumber(CC, is64BitReg ? Mips::GPR64RegClassID
1146 : Mips::GPR32RegClassID);
1147 CC = matchFPURegisterName(Name);
1148 // TODO: decide about fpu register class
1150 return matchRegisterByNumber(CC, isFP64() ? Mips::FGR64RegClassID
1151 : Mips::FGR32RegClassID);
1152 return matchMSA128RegisterName(Name);
1155 int MipsAsmParser::regKindToRegClass(int RegKind) {
1158 case MipsOperand::Kind_GPR32:
1159 return Mips::GPR32RegClassID;
1160 case MipsOperand::Kind_GPR64:
1161 return Mips::GPR64RegClassID;
1162 case MipsOperand::Kind_HWRegs:
1163 return Mips::HWRegsRegClassID;
1164 case MipsOperand::Kind_FGR32Regs:
1165 return Mips::FGR32RegClassID;
1166 case MipsOperand::Kind_FGRH32Regs:
1167 return Mips::FGRH32RegClassID;
1168 case MipsOperand::Kind_FGR64Regs:
1169 return Mips::FGR64RegClassID;
1170 case MipsOperand::Kind_AFGR64Regs:
1171 return Mips::AFGR64RegClassID;
1172 case MipsOperand::Kind_CCRRegs:
1173 return Mips::CCRRegClassID;
1174 case MipsOperand::Kind_ACC64DSP:
1175 return Mips::ACC64DSPRegClassID;
1176 case MipsOperand::Kind_FCCRegs:
1177 return Mips::FCCRegClassID;
1178 case MipsOperand::Kind_MSA128BRegs:
1179 return Mips::MSA128BRegClassID;
1180 case MipsOperand::Kind_MSA128HRegs:
1181 return Mips::MSA128HRegClassID;
1182 case MipsOperand::Kind_MSA128WRegs:
1183 return Mips::MSA128WRegClassID;
1184 case MipsOperand::Kind_MSA128DRegs:
1185 return Mips::MSA128DRegClassID;
1186 case MipsOperand::Kind_MSA128CtrlRegs:
1187 return Mips::MSACtrlRegClassID;
1193 bool MipsAssemblerOptions::setATReg(unsigned Reg) {
1201 int MipsAsmParser::getATReg() {
1202 int AT = Options.getATRegNum();
1204 TokError("Pseudo instruction requires $at, which is not available");
1208 unsigned MipsAsmParser::getReg(int RC, int RegNo) {
1209 return *(getContext().getRegisterInfo()->getRegClass(RC).begin() + RegNo);
1212 unsigned MipsAsmParser::getGPR(int RegNo) {
1213 return getReg(isGP64() ? Mips::GPR64RegClassID : Mips::GPR32RegClassID,
1217 int MipsAsmParser::matchRegisterByNumber(unsigned RegNum, unsigned RegClass) {
1219 getContext().getRegisterInfo()->getRegClass(RegClass).getNumRegs() - 1)
1222 if (RegClass == Mips::GPR32RegClassID || RegClass == Mips::GPR64RegClassID)
1223 warnIfAssemblerTemporary(RegNum);
1225 return getReg(RegClass, RegNum);
1228 int MipsAsmParser::tryParseRegister(bool is64BitReg) {
1229 const AsmToken &Tok = Parser.getTok();
1232 if (Tok.is(AsmToken::Identifier)) {
1233 std::string lowerCase = Tok.getString().lower();
1234 RegNum = matchRegisterName(lowerCase, is64BitReg);
1235 } else if (Tok.is(AsmToken::Integer))
1236 RegNum = matchRegisterByNumber(static_cast<unsigned>(Tok.getIntVal()),
1237 is64BitReg ? Mips::GPR64RegClassID
1238 : Mips::GPR32RegClassID);
1242 bool MipsAsmParser::tryParseRegisterOperand(
1243 SmallVectorImpl<MCParsedAsmOperand *> &Operands, bool is64BitReg) {
1245 SMLoc S = Parser.getTok().getLoc();
1248 RegNo = tryParseRegister(is64BitReg);
1253 MipsOperand::CreateReg(RegNo, S, Parser.getTok().getLoc()));
1254 Parser.Lex(); // Eat register token.
1259 MipsAsmParser::ParseOperand(SmallVectorImpl<MCParsedAsmOperand *> &Operands,
1260 StringRef Mnemonic) {
1261 // Check if the current operand has a custom associated parser, if so, try to
1262 // custom parse the operand, or fallback to the general approach.
1263 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
1264 if (ResTy == MatchOperand_Success)
1266 // If there wasn't a custom match, try the generic matcher below. Otherwise,
1267 // there was a match, but an error occurred, in which case, just return that
1268 // the operand parsing failed.
1269 if (ResTy == MatchOperand_ParseFail)
1272 switch (getLexer().getKind()) {
1274 Error(Parser.getTok().getLoc(), "unexpected token in operand");
1276 case AsmToken::Dollar: {
1277 // Parse the register.
1278 SMLoc S = Parser.getTok().getLoc();
1279 Parser.Lex(); // Eat dollar token.
1280 // Parse the register operand.
1281 if (!tryParseRegisterOperand(Operands, isGP64())) {
1282 if (getLexer().is(AsmToken::LParen)) {
1283 // Check if it is indexed addressing operand.
1284 Operands.push_back(MipsOperand::CreateToken("(", S));
1285 Parser.Lex(); // Eat the parenthesis.
1286 if (getLexer().isNot(AsmToken::Dollar))
1289 Parser.Lex(); // Eat the dollar
1290 if (tryParseRegisterOperand(Operands, isGP64()))
1293 if (!getLexer().is(AsmToken::RParen))
1296 S = Parser.getTok().getLoc();
1297 Operands.push_back(MipsOperand::CreateToken(")", S));
1302 // Maybe it is a symbol reference.
1303 StringRef Identifier;
1304 if (Parser.parseIdentifier(Identifier))
1307 SMLoc E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
1308 MCSymbol *Sym = getContext().GetOrCreateSymbol("$" + Identifier);
1309 // Otherwise create a symbol reference.
1311 MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_None, getContext());
1313 Operands.push_back(MipsOperand::CreateImm(Res, S, E));
1316 case AsmToken::Identifier:
1317 // For instruction aliases like "bc1f $Label" dedicated parser will
1318 // eat the '$' sign before failing. So in order to look for appropriate
1319 // label we must check first if we have already consumed '$'.
1320 if (hasConsumedDollar) {
1321 hasConsumedDollar = false;
1322 SMLoc S = Parser.getTok().getLoc();
1323 StringRef Identifier;
1324 if (Parser.parseIdentifier(Identifier))
1327 SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
1328 MCSymbol *Sym = getContext().GetOrCreateSymbol("$" + Identifier);
1329 // Create a symbol reference.
1331 MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_None, getContext());
1333 Operands.push_back(MipsOperand::CreateImm(Res, S, E));
1336 // Look for the existing symbol, we should check if
1337 // we need to assign the proper RegisterKind.
1338 if (searchSymbolAlias(Operands, MipsOperand::Kind_None))
1340 // Else drop to expression parsing.
1341 case AsmToken::LParen:
1342 case AsmToken::Minus:
1343 case AsmToken::Plus:
1344 case AsmToken::Integer:
1345 case AsmToken::String: {
1346 // Quoted label names.
1347 const MCExpr *IdVal;
1348 SMLoc S = Parser.getTok().getLoc();
1349 if (getParser().parseExpression(IdVal))
1351 SMLoc E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
1352 Operands.push_back(MipsOperand::CreateImm(IdVal, S, E));
1355 case AsmToken::Percent: {
1356 // It is a symbol reference or constant expression.
1357 const MCExpr *IdVal;
1358 SMLoc S = Parser.getTok().getLoc(); // Start location of the operand.
1359 if (parseRelocOperand(IdVal))
1362 SMLoc E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
1364 Operands.push_back(MipsOperand::CreateImm(IdVal, S, E));
1366 } // case AsmToken::Percent
1367 } // switch(getLexer().getKind())
1371 const MCExpr *MipsAsmParser::evaluateRelocExpr(const MCExpr *Expr,
1372 StringRef RelocStr) {
1374 // Check the type of the expression.
1375 if (const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(Expr)) {
1376 // It's a constant, evaluate lo or hi value.
1377 if (RelocStr == "lo") {
1378 short Val = MCE->getValue();
1379 Res = MCConstantExpr::Create(Val, getContext());
1380 } else if (RelocStr == "hi") {
1381 int Val = MCE->getValue();
1382 int LoSign = Val & 0x8000;
1383 Val = (Val & 0xffff0000) >> 16;
1384 // Lower part is treated as a signed int, so if it is negative
1385 // we must add 1 to the hi part to compensate.
1388 Res = MCConstantExpr::Create(Val, getContext());
1390 llvm_unreachable("Invalid RelocStr value");
1395 if (const MCSymbolRefExpr *MSRE = dyn_cast<MCSymbolRefExpr>(Expr)) {
1396 // It's a symbol, create a symbolic expression from the symbol.
1397 StringRef Symbol = MSRE->getSymbol().getName();
1398 MCSymbolRefExpr::VariantKind VK = getVariantKind(RelocStr);
1399 Res = MCSymbolRefExpr::Create(Symbol, VK, getContext());
1403 if (const MCBinaryExpr *BE = dyn_cast<MCBinaryExpr>(Expr)) {
1404 MCSymbolRefExpr::VariantKind VK = getVariantKind(RelocStr);
1406 // Check for %hi(sym1-sym2) and %lo(sym1-sym2) expressions.
1407 if (isa<MCSymbolRefExpr>(BE->getLHS()) && isa<MCSymbolRefExpr>(BE->getRHS())
1408 && (VK == MCSymbolRefExpr::VK_Mips_ABS_HI
1409 || VK == MCSymbolRefExpr::VK_Mips_ABS_LO)) {
1410 // Create target expression for %hi(sym1-sym2) and %lo(sym1-sym2).
1411 if (VK == MCSymbolRefExpr::VK_Mips_ABS_HI)
1412 return MipsMCExpr::CreateHi(Expr, getContext());
1413 return MipsMCExpr::CreateLo(Expr, getContext());
1416 const MCExpr *LExp = evaluateRelocExpr(BE->getLHS(), RelocStr);
1417 const MCExpr *RExp = evaluateRelocExpr(BE->getRHS(), RelocStr);
1418 Res = MCBinaryExpr::Create(BE->getOpcode(), LExp, RExp, getContext());
1422 if (const MCUnaryExpr *UN = dyn_cast<MCUnaryExpr>(Expr)) {
1423 const MCExpr *UnExp = evaluateRelocExpr(UN->getSubExpr(), RelocStr);
1424 Res = MCUnaryExpr::Create(UN->getOpcode(), UnExp, getContext());
1427 // Just return the original expression.
1431 bool MipsAsmParser::isEvaluated(const MCExpr *Expr) {
1433 switch (Expr->getKind()) {
1434 case MCExpr::Constant:
1436 case MCExpr::SymbolRef:
1437 return (cast<MCSymbolRefExpr>(Expr)->getKind() != MCSymbolRefExpr::VK_None);
1438 case MCExpr::Binary:
1439 if (const MCBinaryExpr *BE = dyn_cast<MCBinaryExpr>(Expr)) {
1440 if (!isEvaluated(BE->getLHS()))
1442 return isEvaluated(BE->getRHS());
1445 return isEvaluated(cast<MCUnaryExpr>(Expr)->getSubExpr());
1446 case MCExpr::Target:
1452 bool MipsAsmParser::parseRelocOperand(const MCExpr *&Res) {
1453 Parser.Lex(); // Eat the % token.
1454 const AsmToken &Tok = Parser.getTok(); // Get next token, operation.
1455 if (Tok.isNot(AsmToken::Identifier))
1458 std::string Str = Tok.getIdentifier().str();
1460 Parser.Lex(); // Eat the identifier.
1461 // Now make an expression from the rest of the operand.
1462 const MCExpr *IdVal;
1465 if (getLexer().getKind() == AsmToken::LParen) {
1467 Parser.Lex(); // Eat the '(' token.
1468 if (getLexer().getKind() == AsmToken::Percent) {
1469 Parser.Lex(); // Eat the % token.
1470 const AsmToken &nextTok = Parser.getTok();
1471 if (nextTok.isNot(AsmToken::Identifier))
1474 Str += nextTok.getIdentifier();
1475 Parser.Lex(); // Eat the identifier.
1476 if (getLexer().getKind() != AsmToken::LParen)
1481 if (getParser().parseParenExpression(IdVal, EndLoc))
1484 while (getLexer().getKind() == AsmToken::RParen)
1485 Parser.Lex(); // Eat the ')' token.
1488 return true; // Parenthesis must follow the relocation operand.
1490 Res = evaluateRelocExpr(IdVal, Str);
1494 bool MipsAsmParser::ParseRegister(unsigned &RegNo, SMLoc &StartLoc,
1496 StartLoc = Parser.getTok().getLoc();
1497 RegNo = tryParseRegister(isGP64());
1498 EndLoc = Parser.getTok().getLoc();
1499 return (RegNo == (unsigned)-1);
1502 bool MipsAsmParser::parseMemOffset(const MCExpr *&Res, bool isParenExpr) {
1506 while (getLexer().getKind() == AsmToken::LParen)
1509 switch (getLexer().getKind()) {
1512 case AsmToken::Identifier:
1513 case AsmToken::LParen:
1514 case AsmToken::Integer:
1515 case AsmToken::Minus:
1516 case AsmToken::Plus:
1518 Result = getParser().parseParenExpression(Res, S);
1520 Result = (getParser().parseExpression(Res));
1521 while (getLexer().getKind() == AsmToken::RParen)
1524 case AsmToken::Percent:
1525 Result = parseRelocOperand(Res);
1530 MipsAsmParser::OperandMatchResultTy MipsAsmParser::parseMemOperand(
1531 SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
1533 const MCExpr *IdVal = 0;
1535 bool isParenExpr = false;
1536 MipsAsmParser::OperandMatchResultTy Res = MatchOperand_NoMatch;
1537 // First operand is the offset.
1538 S = Parser.getTok().getLoc();
1540 if (getLexer().getKind() == AsmToken::LParen) {
1545 if (getLexer().getKind() != AsmToken::Dollar) {
1546 if (parseMemOffset(IdVal, isParenExpr))
1547 return MatchOperand_ParseFail;
1549 const AsmToken &Tok = Parser.getTok(); // Get the next token.
1550 if (Tok.isNot(AsmToken::LParen)) {
1551 MipsOperand *Mnemonic = static_cast<MipsOperand *>(Operands[0]);
1552 if (Mnemonic->getToken() == "la") {
1554 SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
1555 Operands.push_back(MipsOperand::CreateImm(IdVal, S, E));
1556 return MatchOperand_Success;
1558 if (Tok.is(AsmToken::EndOfStatement)) {
1560 SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
1562 // Zero register assumed, add a memory operand with ZERO as its base.
1563 Operands.push_back(MipsOperand::CreateMem(
1564 isGP64() ? Mips::ZERO_64 : Mips::ZERO, IdVal, S, E));
1565 return MatchOperand_Success;
1567 Error(Parser.getTok().getLoc(), "'(' expected");
1568 return MatchOperand_ParseFail;
1571 Parser.Lex(); // Eat the '(' token.
1574 Res = parseRegs(Operands, isGP64() ? (int)MipsOperand::Kind_GPR64
1575 : (int)MipsOperand::Kind_GPR32);
1576 if (Res != MatchOperand_Success)
1579 if (Parser.getTok().isNot(AsmToken::RParen)) {
1580 Error(Parser.getTok().getLoc(), "')' expected");
1581 return MatchOperand_ParseFail;
1584 SMLoc E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
1586 Parser.Lex(); // Eat the ')' token.
1589 IdVal = MCConstantExpr::Create(0, getContext());
1591 // Replace the register operand with the memory operand.
1592 MipsOperand *op = static_cast<MipsOperand *>(Operands.back());
1593 int RegNo = op->getReg();
1594 // Remove the register from the operands.
1595 Operands.pop_back();
1596 // Add the memory operand.
1597 if (const MCBinaryExpr *BE = dyn_cast<MCBinaryExpr>(IdVal)) {
1599 if (IdVal->EvaluateAsAbsolute(Imm))
1600 IdVal = MCConstantExpr::Create(Imm, getContext());
1601 else if (BE->getLHS()->getKind() != MCExpr::SymbolRef)
1602 IdVal = MCBinaryExpr::Create(BE->getOpcode(), BE->getRHS(), BE->getLHS(),
1606 Operands.push_back(MipsOperand::CreateMem(RegNo, IdVal, S, E));
1608 return MatchOperand_Success;
1611 bool MipsAsmParser::parsePtrReg(SmallVectorImpl<MCParsedAsmOperand *> &Operands,
1613 // If the first token is not '$' we have an error.
1614 if (Parser.getTok().isNot(AsmToken::Dollar))
1617 SMLoc S = Parser.getTok().getLoc();
1619 AsmToken::TokenKind TkKind = getLexer().getKind();
1622 if (TkKind == AsmToken::Integer) {
1623 Reg = matchRegisterByNumber(Parser.getTok().getIntVal(),
1624 regKindToRegClass(RegKind));
1627 } else if (TkKind == AsmToken::Identifier) {
1628 if ((Reg = matchCPURegisterName(Parser.getTok().getString().lower())) == -1)
1630 Reg = getReg(regKindToRegClass(RegKind), Reg);
1635 MipsOperand *Op = MipsOperand::CreatePtrReg(Reg, S, Parser.getTok().getLoc());
1636 Op->setRegKind((MipsOperand::RegisterKind)RegKind);
1637 Operands.push_back(Op);
1642 MipsAsmParser::OperandMatchResultTy
1643 MipsAsmParser::parsePtrReg(SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
1644 MipsOperand::RegisterKind RegKind =
1645 isN64() ? MipsOperand::Kind_GPR64 : MipsOperand::Kind_GPR32;
1647 // Parse index register.
1648 if (!parsePtrReg(Operands, RegKind))
1649 return MatchOperand_NoMatch;
1652 if (Parser.getTok().isNot(AsmToken::LParen))
1653 return MatchOperand_NoMatch;
1655 Operands.push_back(MipsOperand::CreateToken("(", getLexer().getLoc()));
1658 // Parse base register.
1659 if (!parsePtrReg(Operands, RegKind))
1660 return MatchOperand_NoMatch;
1663 if (Parser.getTok().isNot(AsmToken::RParen))
1664 return MatchOperand_NoMatch;
1666 Operands.push_back(MipsOperand::CreateToken(")", getLexer().getLoc()));
1669 return MatchOperand_Success;
1672 MipsAsmParser::OperandMatchResultTy
1673 MipsAsmParser::parseRegs(SmallVectorImpl<MCParsedAsmOperand *> &Operands,
1675 MipsOperand::RegisterKind Kind = (MipsOperand::RegisterKind)RegKind;
1676 if (getLexer().getKind() == AsmToken::Identifier && !hasConsumedDollar) {
1677 if (searchSymbolAlias(Operands, Kind))
1678 return MatchOperand_Success;
1679 return MatchOperand_NoMatch;
1681 SMLoc S = Parser.getTok().getLoc();
1682 // If the first token is not '$', we have an error.
1683 if (Parser.getTok().isNot(AsmToken::Dollar) && !hasConsumedDollar)
1684 return MatchOperand_NoMatch;
1685 if (!hasConsumedDollar) {
1686 Parser.Lex(); // Eat the '$'
1687 hasConsumedDollar = true;
1689 if (getLexer().getKind() == AsmToken::Identifier) {
1691 std::string RegName = Parser.getTok().getString().lower();
1692 // Match register by name
1694 case MipsOperand::Kind_GPR32:
1695 case MipsOperand::Kind_GPR64:
1696 RegNum = matchCPURegisterName(RegName);
1698 case MipsOperand::Kind_AFGR64Regs:
1699 case MipsOperand::Kind_FGR64Regs:
1700 case MipsOperand::Kind_FGR32Regs:
1701 case MipsOperand::Kind_FGRH32Regs:
1702 RegNum = matchFPURegisterName(RegName);
1703 if (RegKind == MipsOperand::Kind_AFGR64Regs)
1705 else if (RegKind == MipsOperand::Kind_FGRH32Regs && !isFP64())
1706 if (RegNum != -1 && RegNum % 2 != 0)
1707 Warning(S, "Float register should be even.");
1709 case MipsOperand::Kind_FCCRegs:
1710 RegNum = matchFCCRegisterName(RegName);
1712 case MipsOperand::Kind_ACC64DSP:
1713 RegNum = matchACRegisterName(RegName);
1716 break; // No match, value is set to -1.
1718 // No match found, return _NoMatch to give a chance to other round.
1720 return MatchOperand_NoMatch;
1722 int RegVal = getReg(regKindToRegClass(Kind), RegNum);
1724 return MatchOperand_NoMatch;
1727 MipsOperand::CreateReg(RegVal, S, Parser.getTok().getLoc());
1728 Op->setRegKind(Kind);
1729 Operands.push_back(Op);
1730 hasConsumedDollar = false;
1731 Parser.Lex(); // Eat the register name.
1732 return MatchOperand_Success;
1733 } else if (getLexer().getKind() == AsmToken::Integer) {
1734 unsigned RegNum = Parser.getTok().getIntVal();
1735 if (Kind == MipsOperand::Kind_HWRegs) {
1737 return MatchOperand_NoMatch;
1738 // Only hwreg 29 is supported, found at index 0.
1741 int Reg = matchRegisterByNumber(RegNum, regKindToRegClass(Kind));
1743 return MatchOperand_NoMatch;
1744 MipsOperand *Op = MipsOperand::CreateReg(Reg, S, Parser.getTok().getLoc());
1745 Op->setRegKind(Kind);
1746 Operands.push_back(Op);
1747 hasConsumedDollar = false;
1748 Parser.Lex(); // Eat the register number.
1749 if ((RegKind == MipsOperand::Kind_GPR32) &&
1750 (getLexer().is(AsmToken::LParen))) {
1751 // Check if it is indexed addressing operand.
1752 Operands.push_back(MipsOperand::CreateToken("(", getLexer().getLoc()));
1753 Parser.Lex(); // Eat the parenthesis.
1754 if (parseRegs(Operands, RegKind) != MatchOperand_Success)
1755 return MatchOperand_NoMatch;
1756 if (getLexer().isNot(AsmToken::RParen))
1757 return MatchOperand_NoMatch;
1758 Operands.push_back(MipsOperand::CreateToken(")", getLexer().getLoc()));
1761 return MatchOperand_Success;
1763 return MatchOperand_NoMatch;
1766 bool MipsAsmParser::validateMSAIndex(int Val, int RegKind) {
1767 MipsOperand::RegisterKind Kind = (MipsOperand::RegisterKind)RegKind;
1775 case MipsOperand::Kind_MSA128BRegs:
1777 case MipsOperand::Kind_MSA128HRegs:
1779 case MipsOperand::Kind_MSA128WRegs:
1781 case MipsOperand::Kind_MSA128DRegs:
1786 MipsAsmParser::OperandMatchResultTy
1787 MipsAsmParser::parseMSARegs(SmallVectorImpl<MCParsedAsmOperand *> &Operands,
1789 MipsOperand::RegisterKind Kind = (MipsOperand::RegisterKind)RegKind;
1790 SMLoc S = Parser.getTok().getLoc();
1791 std::string RegName;
1793 if (Parser.getTok().isNot(AsmToken::Dollar))
1794 return MatchOperand_NoMatch;
1798 return MatchOperand_ParseFail;
1799 case MipsOperand::Kind_MSA128BRegs:
1800 case MipsOperand::Kind_MSA128HRegs:
1801 case MipsOperand::Kind_MSA128WRegs:
1802 case MipsOperand::Kind_MSA128DRegs:
1806 Parser.Lex(); // Eat the '$'.
1807 if (getLexer().getKind() == AsmToken::Identifier)
1808 RegName = Parser.getTok().getString().lower();
1810 return MatchOperand_ParseFail;
1812 int RegNum = matchMSA128RegisterName(RegName);
1814 if (RegNum < 0 || RegNum > 31)
1815 return MatchOperand_ParseFail;
1817 int RegVal = getReg(regKindToRegClass(Kind), RegNum);
1819 return MatchOperand_ParseFail;
1821 MipsOperand *Op = MipsOperand::CreateReg(RegVal, S, Parser.getTok().getLoc());
1822 Op->setRegKind(Kind);
1823 Operands.push_back(Op);
1825 Parser.Lex(); // Eat the register identifier.
1827 // MSA registers may be suffixed with an index in the form of:
1828 // 1) Immediate expression.
1829 // 2) General Purpose Register.
1831 // 1) copy_s.b $29,$w0[0]
1832 // 2) sld.b $w0,$w1[$1]
1834 if (Parser.getTok().isNot(AsmToken::LBrac))
1835 return MatchOperand_Success;
1837 MipsOperand *Mnemonic = static_cast<MipsOperand *>(Operands[0]);
1839 Operands.push_back(MipsOperand::CreateToken("[", Parser.getTok().getLoc()));
1840 Parser.Lex(); // Parse the '[' token.
1842 if (Parser.getTok().is(AsmToken::Dollar)) {
1843 // This must be a GPR.
1845 SMLoc VIdx = Parser.getTok().getLoc();
1846 Parser.Lex(); // Parse the '$' token.
1848 // GPR have aliases and we must account for that. Example: $30 == $fp
1849 if (getLexer().getKind() == AsmToken::Integer) {
1850 unsigned RegNum = Parser.getTok().getIntVal();
1851 int Reg = matchRegisterByNumber(
1852 RegNum, regKindToRegClass(MipsOperand::Kind_GPR32));
1854 Error(VIdx, "invalid general purpose register");
1855 return MatchOperand_ParseFail;
1858 RegOp = MipsOperand::CreateReg(Reg, VIdx, Parser.getTok().getLoc());
1859 } else if (getLexer().getKind() == AsmToken::Identifier) {
1861 std::string RegName = Parser.getTok().getString().lower();
1863 RegNum = matchCPURegisterName(RegName);
1865 Error(VIdx, "general purpose register expected");
1866 return MatchOperand_ParseFail;
1868 RegNum = getReg(regKindToRegClass(MipsOperand::Kind_GPR32), RegNum);
1869 RegOp = MipsOperand::CreateReg(RegNum, VIdx, Parser.getTok().getLoc());
1871 return MatchOperand_ParseFail;
1873 RegOp->setRegKind(MipsOperand::Kind_GPR32);
1874 Operands.push_back(RegOp);
1875 Parser.Lex(); // Eat the register identifier.
1877 if (Parser.getTok().isNot(AsmToken::RBrac))
1878 return MatchOperand_ParseFail;
1880 Operands.push_back(MipsOperand::CreateToken("]", Parser.getTok().getLoc()));
1881 Parser.Lex(); // Parse the ']' token.
1883 return MatchOperand_Success;
1886 // The index must be a constant expression then.
1887 SMLoc VIdx = Parser.getTok().getLoc();
1888 const MCExpr *ImmVal;
1890 if (getParser().parseExpression(ImmVal))
1891 return MatchOperand_ParseFail;
1893 const MCConstantExpr *expr = dyn_cast<MCConstantExpr>(ImmVal);
1894 if (!expr || !validateMSAIndex((int)expr->getValue(), Kind)) {
1895 Error(VIdx, "invalid immediate value");
1896 return MatchOperand_ParseFail;
1899 SMLoc E = Parser.getTok().getEndLoc();
1901 if (Parser.getTok().isNot(AsmToken::RBrac))
1902 return MatchOperand_ParseFail;
1905 Mnemonic->getToken() == "insve.b" || Mnemonic->getToken() == "insve.h" ||
1906 Mnemonic->getToken() == "insve.w" || Mnemonic->getToken() == "insve.d";
1908 // The second vector index of insve instructions is always 0.
1909 if (insve && Operands.size() > 6) {
1910 if (expr->getValue() != 0) {
1911 Error(VIdx, "immediate value must be 0");
1912 return MatchOperand_ParseFail;
1914 Operands.push_back(MipsOperand::CreateToken("0", VIdx));
1916 Operands.push_back(MipsOperand::CreateImm(expr, VIdx, E));
1918 Operands.push_back(MipsOperand::CreateToken("]", Parser.getTok().getLoc()));
1920 Parser.Lex(); // Parse the ']' token.
1922 return MatchOperand_Success;
1925 MipsAsmParser::OperandMatchResultTy
1926 MipsAsmParser::parseMSACtrlRegs(SmallVectorImpl<MCParsedAsmOperand *> &Operands,
1928 MipsOperand::RegisterKind Kind = (MipsOperand::RegisterKind)RegKind;
1930 if (Kind != MipsOperand::Kind_MSA128CtrlRegs)
1931 return MatchOperand_NoMatch;
1933 if (Parser.getTok().isNot(AsmToken::Dollar))
1934 return MatchOperand_ParseFail;
1936 SMLoc S = Parser.getTok().getLoc();
1938 Parser.Lex(); // Eat the '$' symbol.
1941 if (getLexer().getKind() == AsmToken::Identifier)
1942 RegNum = matchMSA128CtrlRegisterName(Parser.getTok().getString().lower());
1943 else if (getLexer().getKind() == AsmToken::Integer)
1944 RegNum = Parser.getTok().getIntVal();
1946 return MatchOperand_ParseFail;
1948 if (RegNum < 0 || RegNum > 7)
1949 return MatchOperand_ParseFail;
1951 int RegVal = getReg(regKindToRegClass(Kind), RegNum);
1953 return MatchOperand_ParseFail;
1955 MipsOperand *RegOp =
1956 MipsOperand::CreateReg(RegVal, S, Parser.getTok().getLoc());
1957 RegOp->setRegKind(MipsOperand::Kind_MSA128CtrlRegs);
1958 Operands.push_back(RegOp);
1959 Parser.Lex(); // Eat the register identifier.
1961 return MatchOperand_Success;
1964 MipsAsmParser::OperandMatchResultTy
1965 MipsAsmParser::parseGPR64(SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
1968 return MatchOperand_NoMatch;
1969 return parseRegs(Operands, (int)MipsOperand::Kind_GPR64);
1972 MipsAsmParser::OperandMatchResultTy
1973 MipsAsmParser::parseGPR32(SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
1974 return parseRegs(Operands, (int)MipsOperand::Kind_GPR32);
1977 MipsAsmParser::OperandMatchResultTy MipsAsmParser::parseAFGR64Regs(
1978 SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
1981 return MatchOperand_NoMatch;
1982 return parseRegs(Operands, (int)MipsOperand::Kind_AFGR64Regs);
1985 MipsAsmParser::OperandMatchResultTy
1986 MipsAsmParser::parseFGR64Regs(SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
1988 return MatchOperand_NoMatch;
1989 return parseRegs(Operands, (int)MipsOperand::Kind_FGR64Regs);
1992 MipsAsmParser::OperandMatchResultTy
1993 MipsAsmParser::parseFGR32Regs(SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
1994 return parseRegs(Operands, (int)MipsOperand::Kind_FGR32Regs);
1997 MipsAsmParser::OperandMatchResultTy MipsAsmParser::parseFGRH32Regs(
1998 SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
1999 return parseRegs(Operands, (int)MipsOperand::Kind_FGRH32Regs);
2002 MipsAsmParser::OperandMatchResultTy
2003 MipsAsmParser::parseFCCRegs(SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
2004 return parseRegs(Operands, (int)MipsOperand::Kind_FCCRegs);
2007 MipsAsmParser::OperandMatchResultTy
2008 MipsAsmParser::parseACC64DSP(SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
2009 return parseRegs(Operands, (int)MipsOperand::Kind_ACC64DSP);
2012 MipsAsmParser::OperandMatchResultTy
2013 MipsAsmParser::parseLO32DSP(SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
2014 // If the first token is not '$' we have an error.
2015 if (Parser.getTok().isNot(AsmToken::Dollar))
2016 return MatchOperand_NoMatch;
2018 SMLoc S = Parser.getTok().getLoc();
2019 Parser.Lex(); // Eat the '$'
2021 const AsmToken &Tok = Parser.getTok(); // Get next token.
2023 if (Tok.isNot(AsmToken::Identifier))
2024 return MatchOperand_NoMatch;
2026 if (!Tok.getIdentifier().startswith("ac"))
2027 return MatchOperand_NoMatch;
2029 StringRef NumString = Tok.getIdentifier().substr(2);
2032 if (NumString.getAsInteger(10, IntVal))
2033 return MatchOperand_NoMatch;
2035 unsigned Reg = matchRegisterByNumber(IntVal, Mips::LO32DSPRegClassID);
2037 MipsOperand *Op = MipsOperand::CreateReg(Reg, S, Parser.getTok().getLoc());
2038 Op->setRegKind(MipsOperand::Kind_LO32DSP);
2039 Operands.push_back(Op);
2041 Parser.Lex(); // Eat the register number.
2042 return MatchOperand_Success;
2045 MipsAsmParser::OperandMatchResultTy
2046 MipsAsmParser::parseHI32DSP(SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
2047 // If the first token is not '$' we have an error.
2048 if (Parser.getTok().isNot(AsmToken::Dollar))
2049 return MatchOperand_NoMatch;
2051 SMLoc S = Parser.getTok().getLoc();
2052 Parser.Lex(); // Eat the '$'
2054 const AsmToken &Tok = Parser.getTok(); // Get next token.
2056 if (Tok.isNot(AsmToken::Identifier))
2057 return MatchOperand_NoMatch;
2059 if (!Tok.getIdentifier().startswith("ac"))
2060 return MatchOperand_NoMatch;
2062 StringRef NumString = Tok.getIdentifier().substr(2);
2065 if (NumString.getAsInteger(10, IntVal))
2066 return MatchOperand_NoMatch;
2068 unsigned Reg = matchRegisterByNumber(IntVal, Mips::HI32DSPRegClassID);
2070 MipsOperand *Op = MipsOperand::CreateReg(Reg, S, Parser.getTok().getLoc());
2071 Op->setRegKind(MipsOperand::Kind_HI32DSP);
2072 Operands.push_back(Op);
2074 Parser.Lex(); // Eat the register number.
2075 return MatchOperand_Success;
2078 MipsAsmParser::OperandMatchResultTy
2079 MipsAsmParser::parseCOP2(SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
2080 // If the first token is not '$' we have an error.
2081 if (Parser.getTok().isNot(AsmToken::Dollar))
2082 return MatchOperand_NoMatch;
2084 SMLoc S = Parser.getTok().getLoc();
2085 Parser.Lex(); // Eat the '$'
2087 const AsmToken &Tok = Parser.getTok(); // Get next token.
2089 if (Tok.isNot(AsmToken::Integer))
2090 return MatchOperand_NoMatch;
2092 unsigned IntVal = Tok.getIntVal();
2094 unsigned Reg = matchRegisterByNumber(IntVal, Mips::COP2RegClassID);
2096 MipsOperand *Op = MipsOperand::CreateReg(Reg, S, Parser.getTok().getLoc());
2097 Op->setRegKind(MipsOperand::Kind_COP2);
2098 Operands.push_back(Op);
2100 Parser.Lex(); // Eat the register number.
2101 return MatchOperand_Success;
2104 MipsAsmParser::OperandMatchResultTy MipsAsmParser::parseMSA128BRegs(
2105 SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
2106 return parseMSARegs(Operands, (int)MipsOperand::Kind_MSA128BRegs);
2109 MipsAsmParser::OperandMatchResultTy MipsAsmParser::parseMSA128HRegs(
2110 SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
2111 return parseMSARegs(Operands, (int)MipsOperand::Kind_MSA128HRegs);
2114 MipsAsmParser::OperandMatchResultTy MipsAsmParser::parseMSA128WRegs(
2115 SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
2116 return parseMSARegs(Operands, (int)MipsOperand::Kind_MSA128WRegs);
2119 MipsAsmParser::OperandMatchResultTy MipsAsmParser::parseMSA128DRegs(
2120 SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
2121 return parseMSARegs(Operands, (int)MipsOperand::Kind_MSA128DRegs);
2124 MipsAsmParser::OperandMatchResultTy MipsAsmParser::parseMSA128CtrlRegs(
2125 SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
2126 return parseMSACtrlRegs(Operands, (int)MipsOperand::Kind_MSA128CtrlRegs);
2129 bool MipsAsmParser::searchSymbolAlias(
2130 SmallVectorImpl<MCParsedAsmOperand *> &Operands, unsigned RegKind) {
2132 MCSymbol *Sym = getContext().LookupSymbol(Parser.getTok().getIdentifier());
2134 SMLoc S = Parser.getTok().getLoc();
2136 if (Sym->isVariable())
2137 Expr = Sym->getVariableValue();
2140 if (Expr->getKind() == MCExpr::SymbolRef) {
2141 MipsOperand::RegisterKind Kind = (MipsOperand::RegisterKind)RegKind;
2142 const MCSymbolRefExpr *Ref = static_cast<const MCSymbolRefExpr *>(Expr);
2143 const StringRef DefSymbol = Ref->getSymbol().getName();
2144 if (DefSymbol.startswith("$")) {
2146 APInt IntVal(32, -1);
2147 if (!DefSymbol.substr(1).getAsInteger(10, IntVal))
2148 RegNum = matchRegisterByNumber(IntVal.getZExtValue(),
2149 isGP64() ? Mips::GPR64RegClassID
2150 : Mips::GPR32RegClassID);
2152 // Lookup for the register with the corresponding name.
2154 case MipsOperand::Kind_AFGR64Regs:
2155 case MipsOperand::Kind_FGR64Regs:
2156 RegNum = matchFPURegisterName(DefSymbol.substr(1));
2158 case MipsOperand::Kind_FGR32Regs:
2159 RegNum = matchFPURegisterName(DefSymbol.substr(1));
2161 case MipsOperand::Kind_GPR64:
2162 case MipsOperand::Kind_GPR32:
2164 RegNum = matchCPURegisterName(DefSymbol.substr(1));
2168 RegNum = getReg(regKindToRegClass(Kind), RegNum);
2173 MipsOperand::CreateReg(RegNum, S, Parser.getTok().getLoc());
2174 op->setRegKind(Kind);
2175 Operands.push_back(op);
2179 } else if (Expr->getKind() == MCExpr::Constant) {
2181 const MCConstantExpr *Const = static_cast<const MCConstantExpr *>(Expr);
2183 MipsOperand::CreateImm(Const, S, Parser.getTok().getLoc());
2184 Operands.push_back(op);
2191 MipsAsmParser::OperandMatchResultTy
2192 MipsAsmParser::parseHWRegs(SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
2193 return parseRegs(Operands, (int)MipsOperand::Kind_HWRegs);
2196 MipsAsmParser::OperandMatchResultTy
2197 MipsAsmParser::parseCCRRegs(SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
2198 return parseRegs(Operands, (int)MipsOperand::Kind_CCRRegs);
2201 MipsAsmParser::OperandMatchResultTy
2202 MipsAsmParser::parseInvNum(SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
2203 const MCExpr *IdVal;
2204 // If the first token is '$' we may have register operand.
2205 if (Parser.getTok().is(AsmToken::Dollar))
2206 return MatchOperand_NoMatch;
2207 SMLoc S = Parser.getTok().getLoc();
2208 if (getParser().parseExpression(IdVal))
2209 return MatchOperand_ParseFail;
2210 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(IdVal);
2211 assert(MCE && "Unexpected MCExpr type.");
2212 int64_t Val = MCE->getValue();
2213 SMLoc E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
2214 Operands.push_back(MipsOperand::CreateImm(
2215 MCConstantExpr::Create(0 - Val, getContext()), S, E));
2216 return MatchOperand_Success;
2219 MipsAsmParser::OperandMatchResultTy
2220 MipsAsmParser::parseLSAImm(SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
2221 switch (getLexer().getKind()) {
2223 return MatchOperand_NoMatch;
2224 case AsmToken::LParen:
2225 case AsmToken::Plus:
2226 case AsmToken::Minus:
2227 case AsmToken::Integer:
2232 SMLoc S = Parser.getTok().getLoc();
2234 if (getParser().parseExpression(Expr))
2235 return MatchOperand_ParseFail;
2238 if (!Expr->EvaluateAsAbsolute(Val)) {
2239 Error(S, "expected immediate value");
2240 return MatchOperand_ParseFail;
2243 // The LSA instruction allows a 2-bit unsigned immediate. For this reason
2244 // and because the CPU always adds one to the immediate field, the allowed
2245 // range becomes 1..4. We'll only check the range here and will deal
2246 // with the addition/subtraction when actually decoding/encoding
2248 if (Val < 1 || Val > 4) {
2249 Error(S, "immediate not in range (1..4)");
2250 return MatchOperand_ParseFail;
2254 MipsOperand::CreateLSAImm(Expr, S, Parser.getTok().getLoc()));
2255 return MatchOperand_Success;
2258 MCSymbolRefExpr::VariantKind MipsAsmParser::getVariantKind(StringRef Symbol) {
2260 MCSymbolRefExpr::VariantKind VK =
2261 StringSwitch<MCSymbolRefExpr::VariantKind>(Symbol)
2262 .Case("hi", MCSymbolRefExpr::VK_Mips_ABS_HI)
2263 .Case("lo", MCSymbolRefExpr::VK_Mips_ABS_LO)
2264 .Case("gp_rel", MCSymbolRefExpr::VK_Mips_GPREL)
2265 .Case("call16", MCSymbolRefExpr::VK_Mips_GOT_CALL)
2266 .Case("got", MCSymbolRefExpr::VK_Mips_GOT)
2267 .Case("tlsgd", MCSymbolRefExpr::VK_Mips_TLSGD)
2268 .Case("tlsldm", MCSymbolRefExpr::VK_Mips_TLSLDM)
2269 .Case("dtprel_hi", MCSymbolRefExpr::VK_Mips_DTPREL_HI)
2270 .Case("dtprel_lo", MCSymbolRefExpr::VK_Mips_DTPREL_LO)
2271 .Case("gottprel", MCSymbolRefExpr::VK_Mips_GOTTPREL)
2272 .Case("tprel_hi", MCSymbolRefExpr::VK_Mips_TPREL_HI)
2273 .Case("tprel_lo", MCSymbolRefExpr::VK_Mips_TPREL_LO)
2274 .Case("got_disp", MCSymbolRefExpr::VK_Mips_GOT_DISP)
2275 .Case("got_page", MCSymbolRefExpr::VK_Mips_GOT_PAGE)
2276 .Case("got_ofst", MCSymbolRefExpr::VK_Mips_GOT_OFST)
2277 .Case("hi(%neg(%gp_rel", MCSymbolRefExpr::VK_Mips_GPOFF_HI)
2278 .Case("lo(%neg(%gp_rel", MCSymbolRefExpr::VK_Mips_GPOFF_LO)
2279 .Default(MCSymbolRefExpr::VK_None);
2284 bool MipsAsmParser::ParseInstruction(
2285 ParseInstructionInfo &Info, StringRef Name, SMLoc NameLoc,
2286 SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
2287 // Check if we have valid mnemonic
2288 if (!mnemonicIsValid(Name, 0)) {
2289 Parser.eatToEndOfStatement();
2290 return Error(NameLoc, "Unknown instruction");
2292 // First operand in MCInst is instruction mnemonic.
2293 Operands.push_back(MipsOperand::CreateToken(Name, NameLoc));
2295 // Read the remaining operands.
2296 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2297 // Read the first operand.
2298 if (ParseOperand(Operands, Name)) {
2299 SMLoc Loc = getLexer().getLoc();
2300 Parser.eatToEndOfStatement();
2301 return Error(Loc, "unexpected token in argument list");
2304 while (getLexer().is(AsmToken::Comma)) {
2305 Parser.Lex(); // Eat the comma.
2306 // Parse and remember the operand.
2307 if (ParseOperand(Operands, Name)) {
2308 SMLoc Loc = getLexer().getLoc();
2309 Parser.eatToEndOfStatement();
2310 return Error(Loc, "unexpected token in argument list");
2314 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2315 SMLoc Loc = getLexer().getLoc();
2316 Parser.eatToEndOfStatement();
2317 return Error(Loc, "unexpected token in argument list");
2319 Parser.Lex(); // Consume the EndOfStatement.
2323 bool MipsAsmParser::reportParseError(StringRef ErrorMsg) {
2324 SMLoc Loc = getLexer().getLoc();
2325 Parser.eatToEndOfStatement();
2326 return Error(Loc, ErrorMsg);
2329 bool MipsAsmParser::parseSetNoAtDirective() {
2330 // Line should look like: ".set noat".
2332 Options.setATReg(0);
2335 // If this is not the end of the statement, report an error.
2336 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2337 reportParseError("unexpected token in statement");
2340 Parser.Lex(); // Consume the EndOfStatement.
2344 bool MipsAsmParser::parseSetAtDirective() {
2345 // Line can be .set at - defaults to $1
2349 if (getLexer().is(AsmToken::EndOfStatement)) {
2350 Options.setATReg(1);
2351 Parser.Lex(); // Consume the EndOfStatement.
2353 } else if (getLexer().is(AsmToken::Equal)) {
2354 getParser().Lex(); // Eat the '='.
2355 if (getLexer().isNot(AsmToken::Dollar)) {
2356 reportParseError("unexpected token in statement");
2359 Parser.Lex(); // Eat the '$'.
2360 const AsmToken &Reg = Parser.getTok();
2361 if (Reg.is(AsmToken::Identifier)) {
2362 AtRegNo = matchCPURegisterName(Reg.getIdentifier());
2363 } else if (Reg.is(AsmToken::Integer)) {
2364 AtRegNo = Reg.getIntVal();
2366 reportParseError("unexpected token in statement");
2370 if (AtRegNo < 0 || AtRegNo > 31) {
2371 reportParseError("unexpected token in statement");
2375 if (!Options.setATReg(AtRegNo)) {
2376 reportParseError("unexpected token in statement");
2379 getParser().Lex(); // Eat the register.
2381 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2382 reportParseError("unexpected token in statement");
2385 Parser.Lex(); // Consume the EndOfStatement.
2388 reportParseError("unexpected token in statement");
2393 bool MipsAsmParser::parseSetReorderDirective() {
2395 // If this is not the end of the statement, report an error.
2396 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2397 reportParseError("unexpected token in statement");
2400 Options.setReorder();
2401 getTargetStreamer().emitDirectiveSetReorder();
2402 Parser.Lex(); // Consume the EndOfStatement.
2406 bool MipsAsmParser::parseSetNoReorderDirective() {
2408 // If this is not the end of the statement, report an error.
2409 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2410 reportParseError("unexpected token in statement");
2413 Options.setNoreorder();
2414 getTargetStreamer().emitDirectiveSetNoReorder();
2415 Parser.Lex(); // Consume the EndOfStatement.
2419 bool MipsAsmParser::parseSetMacroDirective() {
2421 // If this is not the end of the statement, report an error.
2422 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2423 reportParseError("unexpected token in statement");
2427 Parser.Lex(); // Consume the EndOfStatement.
2431 bool MipsAsmParser::parseSetNoMacroDirective() {
2433 // If this is not the end of the statement, report an error.
2434 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2435 reportParseError("`noreorder' must be set before `nomacro'");
2438 if (Options.isReorder()) {
2439 reportParseError("`noreorder' must be set before `nomacro'");
2442 Options.setNomacro();
2443 Parser.Lex(); // Consume the EndOfStatement.
2447 bool MipsAsmParser::parseSetNoMips16Directive() {
2449 // If this is not the end of the statement, report an error.
2450 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2451 reportParseError("unexpected token in statement");
2454 // For now do nothing.
2455 Parser.Lex(); // Consume the EndOfStatement.
2459 bool MipsAsmParser::parseSetAssignment() {
2461 const MCExpr *Value;
2463 if (Parser.parseIdentifier(Name))
2464 reportParseError("expected identifier after .set");
2466 if (getLexer().isNot(AsmToken::Comma))
2467 return reportParseError("unexpected token in .set directive");
2470 if (Parser.parseExpression(Value))
2471 return reportParseError("expected valid expression after comma");
2473 // Check if the Name already exists as a symbol.
2474 MCSymbol *Sym = getContext().LookupSymbol(Name);
2476 return reportParseError("symbol already defined");
2477 Sym = getContext().GetOrCreateSymbol(Name);
2478 Sym->setVariableValue(Value);
2483 bool MipsAsmParser::parseSetFeature(uint64_t Feature) {
2485 if (getLexer().isNot(AsmToken::EndOfStatement))
2486 return reportParseError("unexpected token in .set directive");
2489 default: llvm_unreachable("Unimplemented feature");
2490 case Mips::FeatureDSP:
2491 setFeatureBits(Mips::FeatureDSP, "dsp");
2492 getTargetStreamer().emitDirectiveSetDsp();
2494 case Mips::FeatureMicroMips:
2495 getTargetStreamer().emitDirectiveSetMicroMips();
2497 case Mips::FeatureMips16:
2498 getTargetStreamer().emitDirectiveSetMips16();
2500 case Mips::FeatureMips32r2:
2501 setFeatureBits(Mips::FeatureMips32r2, "mips32r2");
2502 getTargetStreamer().emitDirectiveSetMips32R2();
2504 case Mips::FeatureMips64:
2505 setFeatureBits(Mips::FeatureMips64, "mips64");
2506 getTargetStreamer().emitDirectiveSetMips64();
2508 case Mips::FeatureMips64r2:
2509 setFeatureBits(Mips::FeatureMips64r2, "mips64r2");
2510 getTargetStreamer().emitDirectiveSetMips64R2();
2516 bool MipsAsmParser::parseRegister(unsigned &RegNum) {
2517 if (!getLexer().is(AsmToken::Dollar))
2522 const AsmToken &Reg = Parser.getTok();
2523 if (Reg.is(AsmToken::Identifier)) {
2524 RegNum = matchCPURegisterName(Reg.getIdentifier());
2525 } else if (Reg.is(AsmToken::Integer)) {
2526 RegNum = Reg.getIntVal();
2535 bool MipsAsmParser::eatComma(StringRef ErrorStr) {
2536 if (getLexer().isNot(AsmToken::Comma)) {
2537 SMLoc Loc = getLexer().getLoc();
2538 Parser.eatToEndOfStatement();
2539 return Error(Loc, ErrorStr);
2542 Parser.Lex(); // Eat the comma.
2546 bool MipsAsmParser::parseDirectiveCPSetup() {
2549 bool SaveIsReg = true;
2551 if (!parseRegister(FuncReg))
2552 return reportParseError("expected register containing function address");
2553 FuncReg = getGPR(FuncReg);
2555 if (!eatComma("expected comma parsing directive"))
2558 if (!parseRegister(Save)) {
2559 const AsmToken &Tok = Parser.getTok();
2560 if (Tok.is(AsmToken::Integer)) {
2561 Save = Tok.getIntVal();
2565 return reportParseError("expected save register or stack offset");
2567 Save = getGPR(Save);
2569 if (!eatComma("expected comma parsing directive"))
2573 if (Parser.parseIdentifier(Name))
2574 reportParseError("expected identifier");
2575 MCSymbol *Sym = getContext().GetOrCreateSymbol(Name);
2576 unsigned GPReg = getGPR(matchCPURegisterName("gp"));
2578 // FIXME: The code below this point should be in the TargetStreamers.
2579 // Only N32 and N64 emit anything for .cpsetup
2580 // FIXME: We should only emit something for PIC mode too.
2581 if (!isN32() && !isN64())
2584 MCStreamer &TS = getStreamer();
2586 // Either store the old $gp in a register or on the stack
2588 // move $save, $gpreg
2589 Inst.setOpcode(Mips::DADDu);
2590 Inst.addOperand(MCOperand::CreateReg(Save));
2591 Inst.addOperand(MCOperand::CreateReg(GPReg));
2592 Inst.addOperand(MCOperand::CreateReg(getGPR(0)));
2594 // sd $gpreg, offset($sp)
2595 Inst.setOpcode(Mips::SD);
2596 Inst.addOperand(MCOperand::CreateReg(GPReg));
2597 Inst.addOperand(MCOperand::CreateReg(getGPR(matchCPURegisterName("sp"))));
2598 Inst.addOperand(MCOperand::CreateImm(Save));
2600 TS.EmitInstruction(Inst, STI);
2603 const MCSymbolRefExpr *HiExpr = MCSymbolRefExpr::Create(
2604 Sym->getName(), MCSymbolRefExpr::VK_Mips_GPOFF_HI,
2606 const MCSymbolRefExpr *LoExpr = MCSymbolRefExpr::Create(
2607 Sym->getName(), MCSymbolRefExpr::VK_Mips_GPOFF_LO,
2609 // lui $gp, %hi(%neg(%gp_rel(funcSym)))
2610 Inst.setOpcode(Mips::LUi);
2611 Inst.addOperand(MCOperand::CreateReg(GPReg));
2612 Inst.addOperand(MCOperand::CreateExpr(HiExpr));
2613 TS.EmitInstruction(Inst, STI);
2616 // addiu $gp, $gp, %lo(%neg(%gp_rel(funcSym)))
2617 Inst.setOpcode(Mips::ADDiu);
2618 Inst.addOperand(MCOperand::CreateReg(GPReg));
2619 Inst.addOperand(MCOperand::CreateReg(GPReg));
2620 Inst.addOperand(MCOperand::CreateExpr(LoExpr));
2621 TS.EmitInstruction(Inst, STI);
2624 // daddu $gp, $gp, $funcreg
2625 Inst.setOpcode(Mips::DADDu);
2626 Inst.addOperand(MCOperand::CreateReg(GPReg));
2627 Inst.addOperand(MCOperand::CreateReg(GPReg));
2628 Inst.addOperand(MCOperand::CreateReg(FuncReg));
2629 TS.EmitInstruction(Inst, STI);
2633 bool MipsAsmParser::parseDirectiveSet() {
2635 // Get the next token.
2636 const AsmToken &Tok = Parser.getTok();
2638 if (Tok.getString() == "noat") {
2639 return parseSetNoAtDirective();
2640 } else if (Tok.getString() == "at") {
2641 return parseSetAtDirective();
2642 } else if (Tok.getString() == "reorder") {
2643 return parseSetReorderDirective();
2644 } else if (Tok.getString() == "noreorder") {
2645 return parseSetNoReorderDirective();
2646 } else if (Tok.getString() == "macro") {
2647 return parseSetMacroDirective();
2648 } else if (Tok.getString() == "nomacro") {
2649 return parseSetNoMacroDirective();
2650 } else if (Tok.getString() == "mips16") {
2651 return parseSetFeature(Mips::FeatureMips16);
2652 } else if (Tok.getString() == "nomips16") {
2653 return parseSetNoMips16Directive();
2654 } else if (Tok.getString() == "nomicromips") {
2655 getTargetStreamer().emitDirectiveSetNoMicroMips();
2656 Parser.eatToEndOfStatement();
2658 } else if (Tok.getString() == "micromips") {
2659 return parseSetFeature(Mips::FeatureMicroMips);
2660 } else if (Tok.getString() == "mips32r2") {
2661 return parseSetFeature(Mips::FeatureMips32r2);
2662 } else if (Tok.getString() == "mips64") {
2663 return parseSetFeature(Mips::FeatureMips64);
2664 } else if (Tok.getString() == "mips64r2") {
2665 return parseSetFeature(Mips::FeatureMips64r2);
2666 } else if (Tok.getString() == "dsp") {
2667 return parseSetFeature(Mips::FeatureDSP);
2669 // It is just an identifier, look for an assignment.
2670 parseSetAssignment();
2677 /// parseDataDirective
2678 /// ::= .word [ expression (, expression)* ]
2679 bool MipsAsmParser::parseDataDirective(unsigned Size, SMLoc L) {
2680 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2682 const MCExpr *Value;
2683 if (getParser().parseExpression(Value))
2686 getParser().getStreamer().EmitValue(Value, Size);
2688 if (getLexer().is(AsmToken::EndOfStatement))
2691 // FIXME: Improve diagnostic.
2692 if (getLexer().isNot(AsmToken::Comma))
2693 return Error(L, "unexpected token in directive");
2702 /// parseDirectiveGpWord
2703 /// ::= .gpword local_sym
2704 bool MipsAsmParser::parseDirectiveGpWord() {
2705 const MCExpr *Value;
2706 // EmitGPRel32Value requires an expression, so we are using base class
2707 // method to evaluate the expression.
2708 if (getParser().parseExpression(Value))
2710 getParser().getStreamer().EmitGPRel32Value(Value);
2712 if (getLexer().isNot(AsmToken::EndOfStatement))
2713 return Error(getLexer().getLoc(), "unexpected token in directive");
2714 Parser.Lex(); // Eat EndOfStatement token.
2718 bool MipsAsmParser::parseDirectiveOption() {
2719 // Get the option token.
2720 AsmToken Tok = Parser.getTok();
2721 // At the moment only identifiers are supported.
2722 if (Tok.isNot(AsmToken::Identifier)) {
2723 Error(Parser.getTok().getLoc(), "unexpected token in .option directive");
2724 Parser.eatToEndOfStatement();
2728 StringRef Option = Tok.getIdentifier();
2730 if (Option == "pic0") {
2731 getTargetStreamer().emitDirectiveOptionPic0();
2733 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
2734 Error(Parser.getTok().getLoc(),
2735 "unexpected token in .option pic0 directive");
2736 Parser.eatToEndOfStatement();
2741 if (Option == "pic2") {
2742 getTargetStreamer().emitDirectiveOptionPic2();
2744 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
2745 Error(Parser.getTok().getLoc(),
2746 "unexpected token in .option pic2 directive");
2747 Parser.eatToEndOfStatement();
2753 Warning(Parser.getTok().getLoc(), "unknown option in .option directive");
2754 Parser.eatToEndOfStatement();
2758 bool MipsAsmParser::ParseDirective(AsmToken DirectiveID) {
2759 StringRef IDVal = DirectiveID.getString();
2761 if (IDVal == ".dword") {
2762 parseDataDirective(8, DirectiveID.getLoc());
2766 if (IDVal == ".ent") {
2767 // Ignore this directive for now.
2772 if (IDVal == ".end") {
2773 // Ignore this directive for now.
2778 if (IDVal == ".frame") {
2779 // Ignore this directive for now.
2780 Parser.eatToEndOfStatement();
2784 if (IDVal == ".set") {
2785 return parseDirectiveSet();
2788 if (IDVal == ".fmask") {
2789 // Ignore this directive for now.
2790 Parser.eatToEndOfStatement();
2794 if (IDVal == ".mask") {
2795 // Ignore this directive for now.
2796 Parser.eatToEndOfStatement();
2800 if (IDVal == ".gpword") {
2801 // Ignore this directive for now.
2802 parseDirectiveGpWord();
2806 if (IDVal == ".word") {
2807 parseDataDirective(4, DirectiveID.getLoc());
2811 if (IDVal == ".option")
2812 return parseDirectiveOption();
2814 if (IDVal == ".abicalls") {
2815 getTargetStreamer().emitDirectiveAbiCalls();
2816 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
2817 Error(Parser.getTok().getLoc(), "unexpected token in directive");
2819 Parser.eatToEndOfStatement();
2824 if (IDVal == ".cpsetup")
2825 return parseDirectiveCPSetup();
2830 extern "C" void LLVMInitializeMipsAsmParser() {
2831 RegisterMCAsmParser<MipsAsmParser> X(TheMipsTarget);
2832 RegisterMCAsmParser<MipsAsmParser> Y(TheMipselTarget);
2833 RegisterMCAsmParser<MipsAsmParser> A(TheMips64Target);
2834 RegisterMCAsmParser<MipsAsmParser> B(TheMips64elTarget);
2837 #define GET_REGISTER_MATCHER
2838 #define GET_MATCHER_IMPLEMENTATION
2839 #include "MipsGenAsmMatcher.inc"