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/Debug.h"
27 #include "llvm/Support/MathExtras.h"
28 #include "llvm/Support/TargetRegistry.h"
32 #define DEBUG_TYPE "mips-asm-parser"
39 class MipsAssemblerOptions {
41 MipsAssemblerOptions() : aTReg(1), reorder(true), macro(true) {}
43 unsigned getATRegNum() { return aTReg; }
44 bool setATReg(unsigned Reg);
46 bool isReorder() { return reorder; }
47 void setReorder() { reorder = true; }
48 void setNoreorder() { reorder = false; }
50 bool isMacro() { return macro; }
51 void setMacro() { macro = true; }
52 void setNomacro() { macro = false; }
62 class MipsAsmParser : public MCTargetAsmParser {
63 MipsTargetStreamer &getTargetStreamer() {
64 MCTargetStreamer &TS = *Parser.getStreamer().getTargetStreamer();
65 return static_cast<MipsTargetStreamer &>(TS);
70 MipsAssemblerOptions Options;
72 #define GET_ASSEMBLER_HEADER
73 #include "MipsGenAsmMatcher.inc"
75 unsigned checkTargetMatchPredicate(MCInst &Inst) override;
77 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
78 OperandVector &Operands, MCStreamer &Out,
80 bool MatchingInlineAsm) override;
82 /// Parse a register as used in CFI directives
83 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc) override;
85 bool ParseParenSuffix(StringRef Name, OperandVector &Operands);
87 bool ParseBracketSuffix(StringRef Name, OperandVector &Operands);
89 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
90 SMLoc NameLoc, OperandVector &Operands) override;
92 bool ParseDirective(AsmToken DirectiveID) override;
94 MipsAsmParser::OperandMatchResultTy parseMemOperand(OperandVector &Operands);
96 MipsAsmParser::OperandMatchResultTy
97 MatchAnyRegisterNameWithoutDollar(OperandVector &Operands,
98 StringRef Identifier, SMLoc S);
100 MipsAsmParser::OperandMatchResultTy
101 MatchAnyRegisterWithoutDollar(OperandVector &Operands, SMLoc S);
103 MipsAsmParser::OperandMatchResultTy ParseAnyRegister(OperandVector &Operands);
105 MipsAsmParser::OperandMatchResultTy ParseImm(OperandVector &Operands);
107 MipsAsmParser::OperandMatchResultTy ParseJumpTarget(OperandVector &Operands);
109 MipsAsmParser::OperandMatchResultTy parseInvNum(OperandVector &Operands);
111 MipsAsmParser::OperandMatchResultTy ParseLSAImm(OperandVector &Operands);
113 bool searchSymbolAlias(OperandVector &Operands);
115 bool ParseOperand(OperandVector &, StringRef Mnemonic);
117 bool needsExpansion(MCInst &Inst);
119 void expandInstruction(MCInst &Inst, SMLoc IDLoc,
120 SmallVectorImpl<MCInst> &Instructions);
121 void expandLoadImm(MCInst &Inst, SMLoc IDLoc,
122 SmallVectorImpl<MCInst> &Instructions);
123 void expandLoadAddressImm(MCInst &Inst, SMLoc IDLoc,
124 SmallVectorImpl<MCInst> &Instructions);
125 void expandLoadAddressReg(MCInst &Inst, SMLoc IDLoc,
126 SmallVectorImpl<MCInst> &Instructions);
127 void expandMemInst(MCInst &Inst, SMLoc IDLoc,
128 SmallVectorImpl<MCInst> &Instructions, bool isLoad,
130 bool reportParseError(StringRef ErrorMsg);
131 bool reportParseError(SMLoc Loc, StringRef ErrorMsg);
133 bool parseMemOffset(const MCExpr *&Res, bool isParenExpr);
134 bool parseRelocOperand(const MCExpr *&Res);
136 const MCExpr *evaluateRelocExpr(const MCExpr *Expr, StringRef RelocStr);
138 bool isEvaluated(const MCExpr *Expr);
139 bool parseSetFeature(uint64_t Feature);
140 bool parseDirectiveCPLoad(SMLoc Loc);
141 bool parseDirectiveCPSetup();
142 bool parseDirectiveNaN();
143 bool parseDirectiveSet();
144 bool parseDirectiveOption();
146 bool parseSetAtDirective();
147 bool parseSetNoAtDirective();
148 bool parseSetMacroDirective();
149 bool parseSetNoMacroDirective();
150 bool parseSetReorderDirective();
151 bool parseSetNoReorderDirective();
152 bool parseSetNoMips16Directive();
154 bool parseSetAssignment();
156 bool parseDataDirective(unsigned Size, SMLoc L);
157 bool parseDirectiveGpWord();
158 bool parseDirectiveGpDWord();
160 MCSymbolRefExpr::VariantKind getVariantKind(StringRef Symbol);
162 bool isGP64() const {
163 return (STI.getFeatureBits() & Mips::FeatureGP64Bit) != 0;
166 bool isFP64() const {
167 return (STI.getFeatureBits() & Mips::FeatureFP64Bit) != 0;
170 bool isN32() const { return STI.getFeatureBits() & Mips::FeatureN32; }
171 bool isN64() const { return STI.getFeatureBits() & Mips::FeatureN64; }
173 bool isMicroMips() const {
174 return STI.getFeatureBits() & Mips::FeatureMicroMips;
177 bool hasMips4() const { return STI.getFeatureBits() & Mips::FeatureMips4; }
178 bool hasMips32() const { return STI.getFeatureBits() & Mips::FeatureMips32; }
179 bool hasMips32r6() const {
180 return STI.getFeatureBits() & Mips::FeatureMips32r6;
182 bool hasMips64r6() const {
183 return STI.getFeatureBits() & Mips::FeatureMips64r6;
186 bool eatComma(StringRef ErrorStr);
188 int matchCPURegisterName(StringRef Symbol);
190 int matchRegisterByNumber(unsigned RegNum, unsigned RegClass);
192 int matchFPURegisterName(StringRef Name);
194 int matchFCCRegisterName(StringRef Name);
196 int matchACRegisterName(StringRef Name);
198 int matchMSA128RegisterName(StringRef Name);
200 int matchMSA128CtrlRegisterName(StringRef Name);
202 unsigned getReg(int RC, int RegNo);
204 unsigned getGPR(int RegNo);
206 int getATReg(SMLoc Loc);
208 bool processInstruction(MCInst &Inst, SMLoc IDLoc,
209 SmallVectorImpl<MCInst> &Instructions);
211 // Helper function that checks if the value of a vector index is within the
212 // boundaries of accepted values for each RegisterKind
213 // Example: INSERT.B $w0[n], $1 => 16 > n >= 0
214 bool validateMSAIndex(int Val, int RegKind);
216 void setFeatureBits(unsigned Feature, StringRef FeatureString) {
217 if (!(STI.getFeatureBits() & Feature)) {
218 setAvailableFeatures(
219 ComputeAvailableFeatures(STI.ToggleFeature(FeatureString)));
223 void clearFeatureBits(unsigned Feature, StringRef FeatureString) {
224 if (STI.getFeatureBits() & Feature) {
225 setAvailableFeatures(
226 ComputeAvailableFeatures(STI.ToggleFeature(FeatureString)));
231 enum MipsMatchResultTy {
232 Match_RequiresDifferentSrcAndDst = FIRST_TARGET_MATCH_RESULT_TY
233 #define GET_OPERAND_DIAGNOSTIC_TYPES
234 #include "MipsGenAsmMatcher.inc"
235 #undef GET_OPERAND_DIAGNOSTIC_TYPES
239 MipsAsmParser(MCSubtargetInfo &sti, MCAsmParser &parser,
240 const MCInstrInfo &MII,
241 const MCTargetOptions &Options)
242 : MCTargetAsmParser(), STI(sti), Parser(parser) {
243 // Initialize the set of available features.
244 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
246 // Assert exactly one ABI was chosen.
247 assert((((STI.getFeatureBits() & Mips::FeatureO32) != 0) +
248 ((STI.getFeatureBits() & Mips::FeatureEABI) != 0) +
249 ((STI.getFeatureBits() & Mips::FeatureN32) != 0) +
250 ((STI.getFeatureBits() & Mips::FeatureN64) != 0)) == 1);
253 MCAsmParser &getParser() const { return Parser; }
254 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
256 /// True if all of $fcc0 - $fcc7 exist for the current ISA.
257 bool hasEightFccRegisters() const { return hasMips4() || hasMips32(); }
259 /// Warn if RegNo is the current assembler temporary.
260 void WarnIfAssemblerTemporary(int RegNo, SMLoc Loc);
266 /// MipsOperand - Instances of this class represent a parsed Mips machine
268 class MipsOperand : public MCParsedAsmOperand {
270 /// Broad categories of register classes
271 /// The exact class is finalized by the render method.
273 RegKind_GPR = 1, /// GPR32 and GPR64 (depending on isGP64())
274 RegKind_FGR = 2, /// FGR32, FGR64, AFGR64 (depending on context and
276 RegKind_FCC = 4, /// FCC
277 RegKind_MSA128 = 8, /// MSA128[BHWD] (makes no difference which)
278 RegKind_MSACtrl = 16, /// MSA control registers
279 RegKind_COP2 = 32, /// COP2
280 RegKind_ACC = 64, /// HI32DSP, LO32DSP, and ACC64DSP (depending on
282 RegKind_CCR = 128, /// CCR
283 RegKind_HWRegs = 256, /// HWRegs
284 RegKind_COP3 = 512, /// COP3
286 /// Potentially any (e.g. $1)
287 RegKind_Numeric = RegKind_GPR | RegKind_FGR | RegKind_FCC | RegKind_MSA128 |
288 RegKind_MSACtrl | RegKind_COP2 | RegKind_ACC |
289 RegKind_CCR | RegKind_HWRegs | RegKind_COP3
294 k_Immediate, /// An immediate (possibly involving symbol references)
295 k_Memory, /// Base + Offset Memory Address
296 k_PhysRegister, /// A physical register from the Mips namespace
297 k_RegisterIndex, /// A register index in one or more RegKind.
298 k_Token /// A simple token
302 MipsOperand(KindTy K, MipsAsmParser &Parser)
303 : MCParsedAsmOperand(), Kind(K), AsmParser(Parser) {}
306 /// For diagnostics, and checking the assembler temporary
307 MipsAsmParser &AsmParser;
315 unsigned Num; /// Register Number
319 unsigned Index; /// Index into the register class
320 RegKind Kind; /// Bitfield of the kinds it could possibly be
321 const MCRegisterInfo *RegInfo;
335 struct PhysRegOp PhysReg;
336 struct RegIdxOp RegIdx;
341 SMLoc StartLoc, EndLoc;
343 /// Internal constructor for register kinds
344 static std::unique_ptr<MipsOperand> CreateReg(unsigned Index, RegKind RegKind,
345 const MCRegisterInfo *RegInfo,
347 MipsAsmParser &Parser) {
348 auto Op = make_unique<MipsOperand>(k_RegisterIndex, Parser);
349 Op->RegIdx.Index = Index;
350 Op->RegIdx.RegInfo = RegInfo;
351 Op->RegIdx.Kind = RegKind;
358 /// Coerce the register to GPR32 and return the real register for the current
360 unsigned getGPR32Reg() const {
361 assert(isRegIdx() && (RegIdx.Kind & RegKind_GPR) && "Invalid access!");
362 AsmParser.WarnIfAssemblerTemporary(RegIdx.Index, StartLoc);
363 unsigned ClassID = Mips::GPR32RegClassID;
364 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
367 /// Coerce the register to GPR64 and return the real register for the current
369 unsigned getGPR64Reg() const {
370 assert(isRegIdx() && (RegIdx.Kind & RegKind_GPR) && "Invalid access!");
371 unsigned ClassID = Mips::GPR64RegClassID;
372 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
376 /// Coerce the register to AFGR64 and return the real register for the current
378 unsigned getAFGR64Reg() const {
379 assert(isRegIdx() && (RegIdx.Kind & RegKind_FGR) && "Invalid access!");
380 if (RegIdx.Index % 2 != 0)
381 AsmParser.Warning(StartLoc, "Float register should be even.");
382 return RegIdx.RegInfo->getRegClass(Mips::AFGR64RegClassID)
383 .getRegister(RegIdx.Index / 2);
386 /// Coerce the register to FGR64 and return the real register for the current
388 unsigned getFGR64Reg() const {
389 assert(isRegIdx() && (RegIdx.Kind & RegKind_FGR) && "Invalid access!");
390 return RegIdx.RegInfo->getRegClass(Mips::FGR64RegClassID)
391 .getRegister(RegIdx.Index);
394 /// Coerce the register to FGR32 and return the real register for the current
396 unsigned getFGR32Reg() const {
397 assert(isRegIdx() && (RegIdx.Kind & RegKind_FGR) && "Invalid access!");
398 return RegIdx.RegInfo->getRegClass(Mips::FGR32RegClassID)
399 .getRegister(RegIdx.Index);
402 /// Coerce the register to FGRH32 and return the real register for the current
404 unsigned getFGRH32Reg() const {
405 assert(isRegIdx() && (RegIdx.Kind & RegKind_FGR) && "Invalid access!");
406 return RegIdx.RegInfo->getRegClass(Mips::FGRH32RegClassID)
407 .getRegister(RegIdx.Index);
410 /// Coerce the register to FCC and return the real register for the current
412 unsigned getFCCReg() const {
413 assert(isRegIdx() && (RegIdx.Kind & RegKind_FCC) && "Invalid access!");
414 return RegIdx.RegInfo->getRegClass(Mips::FCCRegClassID)
415 .getRegister(RegIdx.Index);
418 /// Coerce the register to MSA128 and return the real register for the current
420 unsigned getMSA128Reg() const {
421 assert(isRegIdx() && (RegIdx.Kind & RegKind_MSA128) && "Invalid access!");
422 // It doesn't matter which of the MSA128[BHWD] classes we use. They are all
424 unsigned ClassID = Mips::MSA128BRegClassID;
425 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
428 /// Coerce the register to MSACtrl and return the real register for the
430 unsigned getMSACtrlReg() const {
431 assert(isRegIdx() && (RegIdx.Kind & RegKind_MSACtrl) && "Invalid access!");
432 unsigned ClassID = Mips::MSACtrlRegClassID;
433 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
436 /// Coerce the register to COP2 and return the real register for the
438 unsigned getCOP2Reg() const {
439 assert(isRegIdx() && (RegIdx.Kind & RegKind_COP2) && "Invalid access!");
440 unsigned ClassID = Mips::COP2RegClassID;
441 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
444 /// Coerce the register to COP3 and return the real register for the
446 unsigned getCOP3Reg() const {
447 assert(isRegIdx() && (RegIdx.Kind & RegKind_COP3) && "Invalid access!");
448 unsigned ClassID = Mips::COP3RegClassID;
449 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
452 /// Coerce the register to ACC64DSP and return the real register for the
454 unsigned getACC64DSPReg() const {
455 assert(isRegIdx() && (RegIdx.Kind & RegKind_ACC) && "Invalid access!");
456 unsigned ClassID = Mips::ACC64DSPRegClassID;
457 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
460 /// Coerce the register to HI32DSP and return the real register for the
462 unsigned getHI32DSPReg() const {
463 assert(isRegIdx() && (RegIdx.Kind & RegKind_ACC) && "Invalid access!");
464 unsigned ClassID = Mips::HI32DSPRegClassID;
465 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
468 /// Coerce the register to LO32DSP and return the real register for the
470 unsigned getLO32DSPReg() const {
471 assert(isRegIdx() && (RegIdx.Kind & RegKind_ACC) && "Invalid access!");
472 unsigned ClassID = Mips::LO32DSPRegClassID;
473 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
476 /// Coerce the register to CCR and return the real register for the
478 unsigned getCCRReg() const {
479 assert(isRegIdx() && (RegIdx.Kind & RegKind_CCR) && "Invalid access!");
480 unsigned ClassID = Mips::CCRRegClassID;
481 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
484 /// Coerce the register to HWRegs and return the real register for the
486 unsigned getHWRegsReg() const {
487 assert(isRegIdx() && (RegIdx.Kind & RegKind_HWRegs) && "Invalid access!");
488 unsigned ClassID = Mips::HWRegsRegClassID;
489 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
493 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
494 // Add as immediate when possible. Null MCExpr = 0.
496 Inst.addOperand(MCOperand::CreateImm(0));
497 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
498 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
500 Inst.addOperand(MCOperand::CreateExpr(Expr));
503 void addRegOperands(MCInst &Inst, unsigned N) const {
504 llvm_unreachable("Use a custom parser instead");
507 /// Render the operand to an MCInst as a GPR32
508 /// Asserts if the wrong number of operands are requested, or the operand
509 /// is not a k_RegisterIndex compatible with RegKind_GPR
510 void addGPR32AsmRegOperands(MCInst &Inst, unsigned N) const {
511 assert(N == 1 && "Invalid number of operands!");
512 Inst.addOperand(MCOperand::CreateReg(getGPR32Reg()));
515 /// Render the operand to an MCInst as a GPR64
516 /// Asserts if the wrong number of operands are requested, or the operand
517 /// is not a k_RegisterIndex compatible with RegKind_GPR
518 void addGPR64AsmRegOperands(MCInst &Inst, unsigned N) const {
519 assert(N == 1 && "Invalid number of operands!");
520 Inst.addOperand(MCOperand::CreateReg(getGPR64Reg()));
523 void addAFGR64AsmRegOperands(MCInst &Inst, unsigned N) const {
524 assert(N == 1 && "Invalid number of operands!");
525 Inst.addOperand(MCOperand::CreateReg(getAFGR64Reg()));
528 void addFGR64AsmRegOperands(MCInst &Inst, unsigned N) const {
529 assert(N == 1 && "Invalid number of operands!");
530 Inst.addOperand(MCOperand::CreateReg(getFGR64Reg()));
533 void addFGR32AsmRegOperands(MCInst &Inst, unsigned N) const {
534 assert(N == 1 && "Invalid number of operands!");
535 Inst.addOperand(MCOperand::CreateReg(getFGR32Reg()));
538 void addFGRH32AsmRegOperands(MCInst &Inst, unsigned N) const {
539 assert(N == 1 && "Invalid number of operands!");
540 Inst.addOperand(MCOperand::CreateReg(getFGRH32Reg()));
543 void addFCCAsmRegOperands(MCInst &Inst, unsigned N) const {
544 assert(N == 1 && "Invalid number of operands!");
545 Inst.addOperand(MCOperand::CreateReg(getFCCReg()));
548 void addMSA128AsmRegOperands(MCInst &Inst, unsigned N) const {
549 assert(N == 1 && "Invalid number of operands!");
550 Inst.addOperand(MCOperand::CreateReg(getMSA128Reg()));
553 void addMSACtrlAsmRegOperands(MCInst &Inst, unsigned N) const {
554 assert(N == 1 && "Invalid number of operands!");
555 Inst.addOperand(MCOperand::CreateReg(getMSACtrlReg()));
558 void addCOP2AsmRegOperands(MCInst &Inst, unsigned N) const {
559 assert(N == 1 && "Invalid number of operands!");
560 Inst.addOperand(MCOperand::CreateReg(getCOP2Reg()));
563 void addCOP3AsmRegOperands(MCInst &Inst, unsigned N) const {
564 assert(N == 1 && "Invalid number of operands!");
565 Inst.addOperand(MCOperand::CreateReg(getCOP3Reg()));
568 void addACC64DSPAsmRegOperands(MCInst &Inst, unsigned N) const {
569 assert(N == 1 && "Invalid number of operands!");
570 Inst.addOperand(MCOperand::CreateReg(getACC64DSPReg()));
573 void addHI32DSPAsmRegOperands(MCInst &Inst, unsigned N) const {
574 assert(N == 1 && "Invalid number of operands!");
575 Inst.addOperand(MCOperand::CreateReg(getHI32DSPReg()));
578 void addLO32DSPAsmRegOperands(MCInst &Inst, unsigned N) const {
579 assert(N == 1 && "Invalid number of operands!");
580 Inst.addOperand(MCOperand::CreateReg(getLO32DSPReg()));
583 void addCCRAsmRegOperands(MCInst &Inst, unsigned N) const {
584 assert(N == 1 && "Invalid number of operands!");
585 Inst.addOperand(MCOperand::CreateReg(getCCRReg()));
588 void addHWRegsAsmRegOperands(MCInst &Inst, unsigned N) const {
589 assert(N == 1 && "Invalid number of operands!");
590 Inst.addOperand(MCOperand::CreateReg(getHWRegsReg()));
593 void addImmOperands(MCInst &Inst, unsigned N) const {
594 assert(N == 1 && "Invalid number of operands!");
595 const MCExpr *Expr = getImm();
599 void addMemOperands(MCInst &Inst, unsigned N) const {
600 assert(N == 2 && "Invalid number of operands!");
602 Inst.addOperand(MCOperand::CreateReg(getMemBase()->getGPR32Reg()));
604 const MCExpr *Expr = getMemOff();
608 bool isReg() const override {
609 // As a special case until we sort out the definition of div/divu, pretend
610 // that $0/$zero are k_PhysRegister so that MCK_ZERO works correctly.
611 if (isGPRAsmReg() && RegIdx.Index == 0)
614 return Kind == k_PhysRegister;
616 bool isRegIdx() const { return Kind == k_RegisterIndex; }
617 bool isImm() const override { return Kind == k_Immediate; }
618 bool isConstantImm() const {
619 return isImm() && dyn_cast<MCConstantExpr>(getImm());
621 bool isToken() const override {
622 // Note: It's not possible to pretend that other operand kinds are tokens.
623 // The matcher emitter checks tokens first.
624 return Kind == k_Token;
626 bool isMem() const override { return Kind == k_Memory; }
627 bool isConstantMemOff() const {
628 return isMem() && dyn_cast<MCConstantExpr>(getMemOff());
630 template <unsigned Bits> bool isMemWithSimmOffset() const {
631 return isMem() && isConstantMemOff() && isInt<Bits>(getConstantMemOff());
633 bool isInvNum() const { return Kind == k_Immediate; }
634 bool isLSAImm() const {
635 if (!isConstantImm())
637 int64_t Val = getConstantImm();
638 return 1 <= Val && Val <= 4;
641 StringRef getToken() const {
642 assert(Kind == k_Token && "Invalid access!");
643 return StringRef(Tok.Data, Tok.Length);
646 unsigned getReg() const override {
647 // As a special case until we sort out the definition of div/divu, pretend
648 // that $0/$zero are k_PhysRegister so that MCK_ZERO works correctly.
649 if (Kind == k_RegisterIndex && RegIdx.Index == 0 &&
650 RegIdx.Kind & RegKind_GPR)
651 return getGPR32Reg(); // FIXME: GPR64 too
653 assert(Kind == k_PhysRegister && "Invalid access!");
657 const MCExpr *getImm() const {
658 assert((Kind == k_Immediate) && "Invalid access!");
662 int64_t getConstantImm() const {
663 const MCExpr *Val = getImm();
664 return static_cast<const MCConstantExpr *>(Val)->getValue();
667 MipsOperand *getMemBase() const {
668 assert((Kind == k_Memory) && "Invalid access!");
672 const MCExpr *getMemOff() const {
673 assert((Kind == k_Memory) && "Invalid access!");
677 int64_t getConstantMemOff() const {
678 return static_cast<const MCConstantExpr *>(getMemOff())->getValue();
681 static std::unique_ptr<MipsOperand> CreateToken(StringRef Str, SMLoc S,
682 MipsAsmParser &Parser) {
683 auto Op = make_unique<MipsOperand>(k_Token, Parser);
684 Op->Tok.Data = Str.data();
685 Op->Tok.Length = Str.size();
691 /// Create a numeric register (e.g. $1). The exact register remains
692 /// unresolved until an instruction successfully matches
693 static std::unique_ptr<MipsOperand>
694 CreateNumericReg(unsigned Index, const MCRegisterInfo *RegInfo, SMLoc S,
695 SMLoc E, MipsAsmParser &Parser) {
696 DEBUG(dbgs() << "CreateNumericReg(" << Index << ", ...)\n");
697 return CreateReg(Index, RegKind_Numeric, RegInfo, S, E, Parser);
700 /// Create a register that is definitely a GPR.
701 /// This is typically only used for named registers such as $gp.
702 static std::unique_ptr<MipsOperand>
703 CreateGPRReg(unsigned Index, const MCRegisterInfo *RegInfo, SMLoc S, SMLoc E,
704 MipsAsmParser &Parser) {
705 return CreateReg(Index, RegKind_GPR, RegInfo, S, E, Parser);
708 /// Create a register that is definitely a FGR.
709 /// This is typically only used for named registers such as $f0.
710 static std::unique_ptr<MipsOperand>
711 CreateFGRReg(unsigned Index, const MCRegisterInfo *RegInfo, SMLoc S, SMLoc E,
712 MipsAsmParser &Parser) {
713 return CreateReg(Index, RegKind_FGR, RegInfo, S, E, Parser);
716 /// Create a register that is definitely an FCC.
717 /// This is typically only used for named registers such as $fcc0.
718 static std::unique_ptr<MipsOperand>
719 CreateFCCReg(unsigned Index, const MCRegisterInfo *RegInfo, SMLoc S, SMLoc E,
720 MipsAsmParser &Parser) {
721 return CreateReg(Index, RegKind_FCC, RegInfo, S, E, Parser);
724 /// Create a register that is definitely an ACC.
725 /// This is typically only used for named registers such as $ac0.
726 static std::unique_ptr<MipsOperand>
727 CreateACCReg(unsigned Index, const MCRegisterInfo *RegInfo, SMLoc S, SMLoc E,
728 MipsAsmParser &Parser) {
729 return CreateReg(Index, RegKind_ACC, RegInfo, S, E, Parser);
732 /// Create a register that is definitely an MSA128.
733 /// This is typically only used for named registers such as $w0.
734 static std::unique_ptr<MipsOperand>
735 CreateMSA128Reg(unsigned Index, const MCRegisterInfo *RegInfo, SMLoc S,
736 SMLoc E, MipsAsmParser &Parser) {
737 return CreateReg(Index, RegKind_MSA128, RegInfo, S, E, Parser);
740 /// Create a register that is definitely an MSACtrl.
741 /// This is typically only used for named registers such as $msaaccess.
742 static std::unique_ptr<MipsOperand>
743 CreateMSACtrlReg(unsigned Index, const MCRegisterInfo *RegInfo, SMLoc S,
744 SMLoc E, MipsAsmParser &Parser) {
745 return CreateReg(Index, RegKind_MSACtrl, RegInfo, S, E, Parser);
748 static std::unique_ptr<MipsOperand>
749 CreateImm(const MCExpr *Val, SMLoc S, SMLoc E, MipsAsmParser &Parser) {
750 auto Op = make_unique<MipsOperand>(k_Immediate, Parser);
757 static std::unique_ptr<MipsOperand>
758 CreateMem(std::unique_ptr<MipsOperand> Base, const MCExpr *Off, SMLoc S,
759 SMLoc E, MipsAsmParser &Parser) {
760 auto Op = make_unique<MipsOperand>(k_Memory, Parser);
761 Op->Mem.Base = Base.release();
768 bool isGPRAsmReg() const {
769 return isRegIdx() && RegIdx.Kind & RegKind_GPR && RegIdx.Index <= 31;
771 bool isFGRAsmReg() const {
772 // AFGR64 is $0-$15 but we handle this in getAFGR64()
773 return isRegIdx() && RegIdx.Kind & RegKind_FGR && RegIdx.Index <= 31;
775 bool isHWRegsAsmReg() const {
776 return isRegIdx() && RegIdx.Kind & RegKind_HWRegs && RegIdx.Index <= 31;
778 bool isCCRAsmReg() const {
779 return isRegIdx() && RegIdx.Kind & RegKind_CCR && RegIdx.Index <= 31;
781 bool isFCCAsmReg() const {
782 if (!(isRegIdx() && RegIdx.Kind & RegKind_FCC))
784 if (!AsmParser.hasEightFccRegisters())
785 return RegIdx.Index == 0;
786 return RegIdx.Index <= 7;
788 bool isACCAsmReg() const {
789 return isRegIdx() && RegIdx.Kind & RegKind_ACC && RegIdx.Index <= 3;
791 bool isCOP2AsmReg() const {
792 return isRegIdx() && RegIdx.Kind & RegKind_COP2 && RegIdx.Index <= 31;
794 bool isCOP3AsmReg() const {
795 return isRegIdx() && RegIdx.Kind & RegKind_COP3 && RegIdx.Index <= 31;
797 bool isMSA128AsmReg() const {
798 return isRegIdx() && RegIdx.Kind & RegKind_MSA128 && RegIdx.Index <= 31;
800 bool isMSACtrlAsmReg() const {
801 return isRegIdx() && RegIdx.Kind & RegKind_MSACtrl && RegIdx.Index <= 7;
804 /// getStartLoc - Get the location of the first token of this operand.
805 SMLoc getStartLoc() const override { return StartLoc; }
806 /// getEndLoc - Get the location of the last token of this operand.
807 SMLoc getEndLoc() const override { return EndLoc; }
809 virtual ~MipsOperand() {
817 case k_RegisterIndex:
823 void print(raw_ostream &OS) const override {
838 OS << "PhysReg<" << PhysReg.Num << ">";
840 case k_RegisterIndex:
841 OS << "RegIdx<" << RegIdx.Index << ":" << RegIdx.Kind << ">";
848 }; // class MipsOperand
852 extern const MCInstrDesc MipsInsts[];
854 static const MCInstrDesc &getInstDesc(unsigned Opcode) {
855 return MipsInsts[Opcode];
858 bool MipsAsmParser::processInstruction(MCInst &Inst, SMLoc IDLoc,
859 SmallVectorImpl<MCInst> &Instructions) {
860 const MCInstrDesc &MCID = getInstDesc(Inst.getOpcode());
864 if (MCID.isBranch() || MCID.isCall()) {
865 const unsigned Opcode = Inst.getOpcode();
875 assert(MCID.getNumOperands() == 3 && "unexpected number of operands");
876 Offset = Inst.getOperand(2);
878 break; // We'll deal with this situation later on when applying fixups.
879 if (!isIntN(isMicroMips() ? 17 : 18, Offset.getImm()))
880 return Error(IDLoc, "branch target out of range");
881 if (OffsetToAlignment(Offset.getImm(), 1LL << (isMicroMips() ? 1 : 2)))
882 return Error(IDLoc, "branch to misaligned address");
896 case Mips::BGEZAL_MM:
897 case Mips::BLTZAL_MM:
900 assert(MCID.getNumOperands() == 2 && "unexpected number of operands");
901 Offset = Inst.getOperand(1);
903 break; // We'll deal with this situation later on when applying fixups.
904 if (!isIntN(isMicroMips() ? 17 : 18, Offset.getImm()))
905 return Error(IDLoc, "branch target out of range");
906 if (OffsetToAlignment(Offset.getImm(), 1LL << (isMicroMips() ? 1 : 2)))
907 return Error(IDLoc, "branch to misaligned address");
912 // SSNOP is deprecated on MIPS32r6/MIPS64r6
913 // We still accept it but it is a normal nop.
914 if (hasMips32r6() && Inst.getOpcode() == Mips::SSNOP) {
915 std::string ISA = hasMips64r6() ? "MIPS64r6" : "MIPS32r6";
916 Warning(IDLoc, "ssnop is deprecated for " + ISA + " and is equivalent to a "
920 if (MCID.hasDelaySlot() && Options.isReorder()) {
921 // If this instruction has a delay slot and .set reorder is active,
922 // emit a NOP after it.
923 Instructions.push_back(Inst);
925 NopInst.setOpcode(Mips::SLL);
926 NopInst.addOperand(MCOperand::CreateReg(Mips::ZERO));
927 NopInst.addOperand(MCOperand::CreateReg(Mips::ZERO));
928 NopInst.addOperand(MCOperand::CreateImm(0));
929 Instructions.push_back(NopInst);
933 if (MCID.mayLoad() || MCID.mayStore()) {
934 // Check the offset of memory operand, if it is a symbol
935 // reference or immediate we may have to expand instructions.
936 for (unsigned i = 0; i < MCID.getNumOperands(); i++) {
937 const MCOperandInfo &OpInfo = MCID.OpInfo[i];
938 if ((OpInfo.OperandType == MCOI::OPERAND_MEMORY) ||
939 (OpInfo.OperandType == MCOI::OPERAND_UNKNOWN)) {
940 MCOperand &Op = Inst.getOperand(i);
942 int MemOffset = Op.getImm();
943 if (MemOffset < -32768 || MemOffset > 32767) {
944 // Offset can't exceed 16bit value.
945 expandMemInst(Inst, IDLoc, Instructions, MCID.mayLoad(), true);
948 } else if (Op.isExpr()) {
949 const MCExpr *Expr = Op.getExpr();
950 if (Expr->getKind() == MCExpr::SymbolRef) {
951 const MCSymbolRefExpr *SR =
952 static_cast<const MCSymbolRefExpr *>(Expr);
953 if (SR->getKind() == MCSymbolRefExpr::VK_None) {
955 expandMemInst(Inst, IDLoc, Instructions, MCID.mayLoad(), false);
958 } else if (!isEvaluated(Expr)) {
959 expandMemInst(Inst, IDLoc, Instructions, MCID.mayLoad(), false);
967 if (needsExpansion(Inst))
968 expandInstruction(Inst, IDLoc, Instructions);
970 Instructions.push_back(Inst);
975 bool MipsAsmParser::needsExpansion(MCInst &Inst) {
977 switch (Inst.getOpcode()) {
978 case Mips::LoadImm32Reg:
979 case Mips::LoadAddr32Imm:
980 case Mips::LoadAddr32Reg:
987 void MipsAsmParser::expandInstruction(MCInst &Inst, SMLoc IDLoc,
988 SmallVectorImpl<MCInst> &Instructions) {
989 switch (Inst.getOpcode()) {
990 case Mips::LoadImm32Reg:
991 return expandLoadImm(Inst, IDLoc, Instructions);
992 case Mips::LoadAddr32Imm:
993 return expandLoadAddressImm(Inst, IDLoc, Instructions);
994 case Mips::LoadAddr32Reg:
995 return expandLoadAddressReg(Inst, IDLoc, Instructions);
999 void MipsAsmParser::expandLoadImm(MCInst &Inst, SMLoc IDLoc,
1000 SmallVectorImpl<MCInst> &Instructions) {
1002 const MCOperand &ImmOp = Inst.getOperand(1);
1003 assert(ImmOp.isImm() && "expected immediate operand kind");
1004 const MCOperand &RegOp = Inst.getOperand(0);
1005 assert(RegOp.isReg() && "expected register operand kind");
1007 int ImmValue = ImmOp.getImm();
1008 tmpInst.setLoc(IDLoc);
1009 if (0 <= ImmValue && ImmValue <= 65535) {
1010 // For 0 <= j <= 65535.
1011 // li d,j => ori d,$zero,j
1012 tmpInst.setOpcode(Mips::ORi);
1013 tmpInst.addOperand(MCOperand::CreateReg(RegOp.getReg()));
1014 tmpInst.addOperand(MCOperand::CreateReg(Mips::ZERO));
1015 tmpInst.addOperand(MCOperand::CreateImm(ImmValue));
1016 Instructions.push_back(tmpInst);
1017 } else if (ImmValue < 0 && ImmValue >= -32768) {
1018 // For -32768 <= j < 0.
1019 // li d,j => addiu d,$zero,j
1020 tmpInst.setOpcode(Mips::ADDiu);
1021 tmpInst.addOperand(MCOperand::CreateReg(RegOp.getReg()));
1022 tmpInst.addOperand(MCOperand::CreateReg(Mips::ZERO));
1023 tmpInst.addOperand(MCOperand::CreateImm(ImmValue));
1024 Instructions.push_back(tmpInst);
1026 // For any other value of j that is representable as a 32-bit integer.
1027 // li d,j => lui d,hi16(j)
1029 tmpInst.setOpcode(Mips::LUi);
1030 tmpInst.addOperand(MCOperand::CreateReg(RegOp.getReg()));
1031 tmpInst.addOperand(MCOperand::CreateImm((ImmValue & 0xffff0000) >> 16));
1032 Instructions.push_back(tmpInst);
1034 tmpInst.setOpcode(Mips::ORi);
1035 tmpInst.addOperand(MCOperand::CreateReg(RegOp.getReg()));
1036 tmpInst.addOperand(MCOperand::CreateReg(RegOp.getReg()));
1037 tmpInst.addOperand(MCOperand::CreateImm(ImmValue & 0xffff));
1038 tmpInst.setLoc(IDLoc);
1039 Instructions.push_back(tmpInst);
1044 MipsAsmParser::expandLoadAddressReg(MCInst &Inst, SMLoc IDLoc,
1045 SmallVectorImpl<MCInst> &Instructions) {
1047 const MCOperand &ImmOp = Inst.getOperand(2);
1048 assert(ImmOp.isImm() && "expected immediate operand kind");
1049 const MCOperand &SrcRegOp = Inst.getOperand(1);
1050 assert(SrcRegOp.isReg() && "expected register operand kind");
1051 const MCOperand &DstRegOp = Inst.getOperand(0);
1052 assert(DstRegOp.isReg() && "expected register operand kind");
1053 int ImmValue = ImmOp.getImm();
1054 if (-32768 <= ImmValue && ImmValue <= 65535) {
1055 // For -32768 <= j <= 65535.
1056 // la d,j(s) => addiu d,s,j
1057 tmpInst.setOpcode(Mips::ADDiu);
1058 tmpInst.addOperand(MCOperand::CreateReg(DstRegOp.getReg()));
1059 tmpInst.addOperand(MCOperand::CreateReg(SrcRegOp.getReg()));
1060 tmpInst.addOperand(MCOperand::CreateImm(ImmValue));
1061 Instructions.push_back(tmpInst);
1063 // For any other value of j that is representable as a 32-bit integer.
1064 // la d,j(s) => lui d,hi16(j)
1067 tmpInst.setOpcode(Mips::LUi);
1068 tmpInst.addOperand(MCOperand::CreateReg(DstRegOp.getReg()));
1069 tmpInst.addOperand(MCOperand::CreateImm((ImmValue & 0xffff0000) >> 16));
1070 Instructions.push_back(tmpInst);
1072 tmpInst.setOpcode(Mips::ORi);
1073 tmpInst.addOperand(MCOperand::CreateReg(DstRegOp.getReg()));
1074 tmpInst.addOperand(MCOperand::CreateReg(DstRegOp.getReg()));
1075 tmpInst.addOperand(MCOperand::CreateImm(ImmValue & 0xffff));
1076 Instructions.push_back(tmpInst);
1078 tmpInst.setOpcode(Mips::ADDu);
1079 tmpInst.addOperand(MCOperand::CreateReg(DstRegOp.getReg()));
1080 tmpInst.addOperand(MCOperand::CreateReg(DstRegOp.getReg()));
1081 tmpInst.addOperand(MCOperand::CreateReg(SrcRegOp.getReg()));
1082 Instructions.push_back(tmpInst);
1087 MipsAsmParser::expandLoadAddressImm(MCInst &Inst, SMLoc IDLoc,
1088 SmallVectorImpl<MCInst> &Instructions) {
1090 const MCOperand &ImmOp = Inst.getOperand(1);
1091 assert(ImmOp.isImm() && "expected immediate operand kind");
1092 const MCOperand &RegOp = Inst.getOperand(0);
1093 assert(RegOp.isReg() && "expected register operand kind");
1094 int ImmValue = ImmOp.getImm();
1095 if (-32768 <= ImmValue && ImmValue <= 65535) {
1096 // For -32768 <= j <= 65535.
1097 // la d,j => addiu d,$zero,j
1098 tmpInst.setOpcode(Mips::ADDiu);
1099 tmpInst.addOperand(MCOperand::CreateReg(RegOp.getReg()));
1100 tmpInst.addOperand(MCOperand::CreateReg(Mips::ZERO));
1101 tmpInst.addOperand(MCOperand::CreateImm(ImmValue));
1102 Instructions.push_back(tmpInst);
1104 // For any other value of j that is representable as a 32-bit integer.
1105 // la d,j => lui d,hi16(j)
1107 tmpInst.setOpcode(Mips::LUi);
1108 tmpInst.addOperand(MCOperand::CreateReg(RegOp.getReg()));
1109 tmpInst.addOperand(MCOperand::CreateImm((ImmValue & 0xffff0000) >> 16));
1110 Instructions.push_back(tmpInst);
1112 tmpInst.setOpcode(Mips::ORi);
1113 tmpInst.addOperand(MCOperand::CreateReg(RegOp.getReg()));
1114 tmpInst.addOperand(MCOperand::CreateReg(RegOp.getReg()));
1115 tmpInst.addOperand(MCOperand::CreateImm(ImmValue & 0xffff));
1116 Instructions.push_back(tmpInst);
1120 void MipsAsmParser::expandMemInst(MCInst &Inst, SMLoc IDLoc,
1121 SmallVectorImpl<MCInst> &Instructions,
1122 bool isLoad, bool isImmOpnd) {
1123 const MCSymbolRefExpr *SR;
1125 unsigned ImmOffset, HiOffset, LoOffset;
1126 const MCExpr *ExprOffset;
1128 // 1st operand is either the source or destination register.
1129 assert(Inst.getOperand(0).isReg() && "expected register operand kind");
1130 unsigned RegOpNum = Inst.getOperand(0).getReg();
1131 // 2nd operand is the base register.
1132 assert(Inst.getOperand(1).isReg() && "expected register operand kind");
1133 unsigned BaseRegNum = Inst.getOperand(1).getReg();
1134 // 3rd operand is either an immediate or expression.
1136 assert(Inst.getOperand(2).isImm() && "expected immediate operand kind");
1137 ImmOffset = Inst.getOperand(2).getImm();
1138 LoOffset = ImmOffset & 0x0000ffff;
1139 HiOffset = (ImmOffset & 0xffff0000) >> 16;
1140 // If msb of LoOffset is 1(negative number) we must increment HiOffset.
1141 if (LoOffset & 0x8000)
1144 ExprOffset = Inst.getOperand(2).getExpr();
1145 // All instructions will have the same location.
1146 TempInst.setLoc(IDLoc);
1147 // These are some of the types of expansions we perform here:
1148 // 1) lw $8, sym => lui $8, %hi(sym)
1149 // lw $8, %lo(sym)($8)
1150 // 2) lw $8, offset($9) => lui $8, %hi(offset)
1152 // lw $8, %lo(offset)($9)
1153 // 3) lw $8, offset($8) => lui $at, %hi(offset)
1155 // lw $8, %lo(offset)($at)
1156 // 4) sw $8, sym => lui $at, %hi(sym)
1157 // sw $8, %lo(sym)($at)
1158 // 5) sw $8, offset($8) => lui $at, %hi(offset)
1160 // sw $8, %lo(offset)($at)
1161 // 6) ldc1 $f0, sym => lui $at, %hi(sym)
1162 // ldc1 $f0, %lo(sym)($at)
1164 // For load instructions we can use the destination register as a temporary
1165 // if base and dst are different (examples 1 and 2) and if the base register
1166 // is general purpose otherwise we must use $at (example 6) and error if it's
1167 // not available. For stores we must use $at (examples 4 and 5) because we
1168 // must not clobber the source register setting up the offset.
1169 const MCInstrDesc &Desc = getInstDesc(Inst.getOpcode());
1170 int16_t RegClassOp0 = Desc.OpInfo[0].RegClass;
1171 unsigned RegClassIDOp0 =
1172 getContext().getRegisterInfo()->getRegClass(RegClassOp0).getID();
1173 bool IsGPR = (RegClassIDOp0 == Mips::GPR32RegClassID) ||
1174 (RegClassIDOp0 == Mips::GPR64RegClassID);
1175 if (isLoad && IsGPR && (BaseRegNum != RegOpNum))
1176 TmpRegNum = RegOpNum;
1178 int AT = getATReg(IDLoc);
1179 // At this point we need AT to perform the expansions and we exit if it is
1184 getReg((isGP64()) ? Mips::GPR64RegClassID : Mips::GPR32RegClassID, AT);
1187 TempInst.setOpcode(Mips::LUi);
1188 TempInst.addOperand(MCOperand::CreateReg(TmpRegNum));
1190 TempInst.addOperand(MCOperand::CreateImm(HiOffset));
1192 if (ExprOffset->getKind() == MCExpr::SymbolRef) {
1193 SR = static_cast<const MCSymbolRefExpr *>(ExprOffset);
1194 const MCSymbolRefExpr *HiExpr = MCSymbolRefExpr::Create(
1195 SR->getSymbol().getName(), MCSymbolRefExpr::VK_Mips_ABS_HI,
1197 TempInst.addOperand(MCOperand::CreateExpr(HiExpr));
1199 const MCExpr *HiExpr = evaluateRelocExpr(ExprOffset, "hi");
1200 TempInst.addOperand(MCOperand::CreateExpr(HiExpr));
1203 // Add the instruction to the list.
1204 Instructions.push_back(TempInst);
1205 // Prepare TempInst for next instruction.
1207 // Add temp register to base.
1208 TempInst.setOpcode(Mips::ADDu);
1209 TempInst.addOperand(MCOperand::CreateReg(TmpRegNum));
1210 TempInst.addOperand(MCOperand::CreateReg(TmpRegNum));
1211 TempInst.addOperand(MCOperand::CreateReg(BaseRegNum));
1212 Instructions.push_back(TempInst);
1214 // And finally, create original instruction with low part
1215 // of offset and new base.
1216 TempInst.setOpcode(Inst.getOpcode());
1217 TempInst.addOperand(MCOperand::CreateReg(RegOpNum));
1218 TempInst.addOperand(MCOperand::CreateReg(TmpRegNum));
1220 TempInst.addOperand(MCOperand::CreateImm(LoOffset));
1222 if (ExprOffset->getKind() == MCExpr::SymbolRef) {
1223 const MCSymbolRefExpr *LoExpr = MCSymbolRefExpr::Create(
1224 SR->getSymbol().getName(), MCSymbolRefExpr::VK_Mips_ABS_LO,
1226 TempInst.addOperand(MCOperand::CreateExpr(LoExpr));
1228 const MCExpr *LoExpr = evaluateRelocExpr(ExprOffset, "lo");
1229 TempInst.addOperand(MCOperand::CreateExpr(LoExpr));
1232 Instructions.push_back(TempInst);
1236 unsigned MipsAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
1237 // As described by the Mips32r2 spec, the registers Rd and Rs for
1238 // jalr.hb must be different.
1239 unsigned Opcode = Inst.getOpcode();
1241 if (Opcode == Mips::JALR_HB &&
1242 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()))
1243 return Match_RequiresDifferentSrcAndDst;
1245 return Match_Success;
1248 bool MipsAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
1249 OperandVector &Operands,
1251 unsigned &ErrorInfo,
1252 bool MatchingInlineAsm) {
1255 SmallVector<MCInst, 8> Instructions;
1256 unsigned MatchResult =
1257 MatchInstructionImpl(Operands, Inst, ErrorInfo, MatchingInlineAsm);
1259 switch (MatchResult) {
1262 case Match_Success: {
1263 if (processInstruction(Inst, IDLoc, Instructions))
1265 for (unsigned i = 0; i < Instructions.size(); i++)
1266 Out.EmitInstruction(Instructions[i], STI);
1269 case Match_MissingFeature:
1270 Error(IDLoc, "instruction requires a CPU feature not currently enabled");
1272 case Match_InvalidOperand: {
1273 SMLoc ErrorLoc = IDLoc;
1274 if (ErrorInfo != ~0U) {
1275 if (ErrorInfo >= Operands.size())
1276 return Error(IDLoc, "too few operands for instruction");
1278 ErrorLoc = ((MipsOperand &)*Operands[ErrorInfo]).getStartLoc();
1279 if (ErrorLoc == SMLoc())
1283 return Error(ErrorLoc, "invalid operand for instruction");
1285 case Match_MnemonicFail:
1286 return Error(IDLoc, "invalid instruction");
1287 case Match_RequiresDifferentSrcAndDst:
1288 return Error(IDLoc, "source and destination must be different");
1293 void MipsAsmParser::WarnIfAssemblerTemporary(int RegIndex, SMLoc Loc) {
1294 if ((RegIndex != 0) && ((int)Options.getATRegNum() == RegIndex)) {
1296 Warning(Loc, "Used $at without \".set noat\"");
1298 Warning(Loc, Twine("Used $") + Twine(RegIndex) + " with \".set at=$" +
1299 Twine(RegIndex) + "\"");
1303 int MipsAsmParser::matchCPURegisterName(StringRef Name) {
1306 CC = StringSwitch<unsigned>(Name)
1342 if (isN32() || isN64()) {
1343 // Although SGI documentation just cuts out t0-t3 for n32/n64,
1344 // GNU pushes the values of t0-t3 to override the o32/o64 values for t4-t7
1345 // We are supporting both cases, so for t0-t3 we'll just push them to t4-t7.
1346 if (8 <= CC && CC <= 11)
1350 CC = StringSwitch<unsigned>(Name)
1363 int MipsAsmParser::matchFPURegisterName(StringRef Name) {
1365 if (Name[0] == 'f') {
1366 StringRef NumString = Name.substr(1);
1368 if (NumString.getAsInteger(10, IntVal))
1369 return -1; // This is not an integer.
1370 if (IntVal > 31) // Maximum index for fpu register.
1377 int MipsAsmParser::matchFCCRegisterName(StringRef Name) {
1379 if (Name.startswith("fcc")) {
1380 StringRef NumString = Name.substr(3);
1382 if (NumString.getAsInteger(10, IntVal))
1383 return -1; // This is not an integer.
1384 if (IntVal > 7) // There are only 8 fcc registers.
1391 int MipsAsmParser::matchACRegisterName(StringRef Name) {
1393 if (Name.startswith("ac")) {
1394 StringRef NumString = Name.substr(2);
1396 if (NumString.getAsInteger(10, IntVal))
1397 return -1; // This is not an integer.
1398 if (IntVal > 3) // There are only 3 acc registers.
1405 int MipsAsmParser::matchMSA128RegisterName(StringRef Name) {
1408 if (Name.front() != 'w' || Name.drop_front(1).getAsInteger(10, IntVal))
1417 int MipsAsmParser::matchMSA128CtrlRegisterName(StringRef Name) {
1420 CC = StringSwitch<unsigned>(Name)
1423 .Case("msaaccess", 2)
1425 .Case("msamodify", 4)
1426 .Case("msarequest", 5)
1428 .Case("msaunmap", 7)
1434 bool MipsAssemblerOptions::setATReg(unsigned Reg) {
1442 int MipsAsmParser::getATReg(SMLoc Loc) {
1443 int AT = Options.getATRegNum();
1445 reportParseError(Loc,
1446 "Pseudo instruction requires $at, which is not available");
1450 unsigned MipsAsmParser::getReg(int RC, int RegNo) {
1451 return *(getContext().getRegisterInfo()->getRegClass(RC).begin() + RegNo);
1454 unsigned MipsAsmParser::getGPR(int RegNo) {
1455 return getReg(isGP64() ? Mips::GPR64RegClassID : Mips::GPR32RegClassID,
1459 int MipsAsmParser::matchRegisterByNumber(unsigned RegNum, unsigned RegClass) {
1461 getContext().getRegisterInfo()->getRegClass(RegClass).getNumRegs() - 1)
1464 return getReg(RegClass, RegNum);
1467 bool MipsAsmParser::ParseOperand(OperandVector &Operands, StringRef Mnemonic) {
1468 DEBUG(dbgs() << "ParseOperand\n");
1470 // Check if the current operand has a custom associated parser, if so, try to
1471 // custom parse the operand, or fallback to the general approach.
1472 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
1473 if (ResTy == MatchOperand_Success)
1475 // If there wasn't a custom match, try the generic matcher below. Otherwise,
1476 // there was a match, but an error occurred, in which case, just return that
1477 // the operand parsing failed.
1478 if (ResTy == MatchOperand_ParseFail)
1481 DEBUG(dbgs() << ".. Generic Parser\n");
1483 switch (getLexer().getKind()) {
1485 Error(Parser.getTok().getLoc(), "unexpected token in operand");
1487 case AsmToken::Dollar: {
1488 // Parse the register.
1489 SMLoc S = Parser.getTok().getLoc();
1491 // Almost all registers have been parsed by custom parsers. There is only
1492 // one exception to this. $zero (and it's alias $0) will reach this point
1493 // for div, divu, and similar instructions because it is not an operand
1494 // to the instruction definition but an explicit register. Special case
1495 // this situation for now.
1496 if (ParseAnyRegister(Operands) != MatchOperand_NoMatch)
1499 // Maybe it is a symbol reference.
1500 StringRef Identifier;
1501 if (Parser.parseIdentifier(Identifier))
1504 SMLoc E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
1505 MCSymbol *Sym = getContext().GetOrCreateSymbol("$" + Identifier);
1506 // Otherwise create a symbol reference.
1508 MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_None, getContext());
1510 Operands.push_back(MipsOperand::CreateImm(Res, S, E, *this));
1513 // Else drop to expression parsing.
1514 case AsmToken::LParen:
1515 case AsmToken::Minus:
1516 case AsmToken::Plus:
1517 case AsmToken::Integer:
1518 case AsmToken::Tilde:
1519 case AsmToken::String: {
1520 DEBUG(dbgs() << ".. generic integer\n");
1521 OperandMatchResultTy ResTy = ParseImm(Operands);
1522 return ResTy != MatchOperand_Success;
1524 case AsmToken::Percent: {
1525 // It is a symbol reference or constant expression.
1526 const MCExpr *IdVal;
1527 SMLoc S = Parser.getTok().getLoc(); // Start location of the operand.
1528 if (parseRelocOperand(IdVal))
1531 SMLoc E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
1533 Operands.push_back(MipsOperand::CreateImm(IdVal, S, E, *this));
1535 } // case AsmToken::Percent
1536 } // switch(getLexer().getKind())
1540 const MCExpr *MipsAsmParser::evaluateRelocExpr(const MCExpr *Expr,
1541 StringRef RelocStr) {
1543 // Check the type of the expression.
1544 if (const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(Expr)) {
1545 // It's a constant, evaluate reloc value.
1547 switch (getVariantKind(RelocStr)) {
1548 case MCSymbolRefExpr::VK_Mips_ABS_LO:
1549 // Get the 1st 16-bits.
1550 Val = MCE->getValue() & 0xffff;
1552 case MCSymbolRefExpr::VK_Mips_ABS_HI:
1553 // Get the 2nd 16-bits. Also add 1 if bit 15 is 1, to compensate for low
1554 // 16 bits being negative.
1555 Val = ((MCE->getValue() + 0x8000) >> 16) & 0xffff;
1557 case MCSymbolRefExpr::VK_Mips_HIGHER:
1558 // Get the 3rd 16-bits.
1559 Val = ((MCE->getValue() + 0x80008000LL) >> 32) & 0xffff;
1561 case MCSymbolRefExpr::VK_Mips_HIGHEST:
1562 // Get the 4th 16-bits.
1563 Val = ((MCE->getValue() + 0x800080008000LL) >> 48) & 0xffff;
1566 report_fatal_error("Unsupported reloc value!");
1568 return MCConstantExpr::Create(Val, getContext());
1571 if (const MCSymbolRefExpr *MSRE = dyn_cast<MCSymbolRefExpr>(Expr)) {
1572 // It's a symbol, create a symbolic expression from the symbol.
1573 StringRef Symbol = MSRE->getSymbol().getName();
1574 MCSymbolRefExpr::VariantKind VK = getVariantKind(RelocStr);
1575 Res = MCSymbolRefExpr::Create(Symbol, VK, getContext());
1579 if (const MCBinaryExpr *BE = dyn_cast<MCBinaryExpr>(Expr)) {
1580 MCSymbolRefExpr::VariantKind VK = getVariantKind(RelocStr);
1582 // Try to create target expression.
1583 if (MipsMCExpr::isSupportedBinaryExpr(VK, BE))
1584 return MipsMCExpr::Create(VK, Expr, getContext());
1586 const MCExpr *LExp = evaluateRelocExpr(BE->getLHS(), RelocStr);
1587 const MCExpr *RExp = evaluateRelocExpr(BE->getRHS(), RelocStr);
1588 Res = MCBinaryExpr::Create(BE->getOpcode(), LExp, RExp, getContext());
1592 if (const MCUnaryExpr *UN = dyn_cast<MCUnaryExpr>(Expr)) {
1593 const MCExpr *UnExp = evaluateRelocExpr(UN->getSubExpr(), RelocStr);
1594 Res = MCUnaryExpr::Create(UN->getOpcode(), UnExp, getContext());
1597 // Just return the original expression.
1601 bool MipsAsmParser::isEvaluated(const MCExpr *Expr) {
1603 switch (Expr->getKind()) {
1604 case MCExpr::Constant:
1606 case MCExpr::SymbolRef:
1607 return (cast<MCSymbolRefExpr>(Expr)->getKind() != MCSymbolRefExpr::VK_None);
1608 case MCExpr::Binary:
1609 if (const MCBinaryExpr *BE = dyn_cast<MCBinaryExpr>(Expr)) {
1610 if (!isEvaluated(BE->getLHS()))
1612 return isEvaluated(BE->getRHS());
1615 return isEvaluated(cast<MCUnaryExpr>(Expr)->getSubExpr());
1616 case MCExpr::Target:
1622 bool MipsAsmParser::parseRelocOperand(const MCExpr *&Res) {
1623 Parser.Lex(); // Eat the % token.
1624 const AsmToken &Tok = Parser.getTok(); // Get next token, operation.
1625 if (Tok.isNot(AsmToken::Identifier))
1628 std::string Str = Tok.getIdentifier().str();
1630 Parser.Lex(); // Eat the identifier.
1631 // Now make an expression from the rest of the operand.
1632 const MCExpr *IdVal;
1635 if (getLexer().getKind() == AsmToken::LParen) {
1637 Parser.Lex(); // Eat the '(' token.
1638 if (getLexer().getKind() == AsmToken::Percent) {
1639 Parser.Lex(); // Eat the % token.
1640 const AsmToken &nextTok = Parser.getTok();
1641 if (nextTok.isNot(AsmToken::Identifier))
1644 Str += nextTok.getIdentifier();
1645 Parser.Lex(); // Eat the identifier.
1646 if (getLexer().getKind() != AsmToken::LParen)
1651 if (getParser().parseParenExpression(IdVal, EndLoc))
1654 while (getLexer().getKind() == AsmToken::RParen)
1655 Parser.Lex(); // Eat the ')' token.
1658 return true; // Parenthesis must follow the relocation operand.
1660 Res = evaluateRelocExpr(IdVal, Str);
1664 bool MipsAsmParser::ParseRegister(unsigned &RegNo, SMLoc &StartLoc,
1666 SmallVector<std::unique_ptr<MCParsedAsmOperand>, 1> Operands;
1667 OperandMatchResultTy ResTy = ParseAnyRegister(Operands);
1668 if (ResTy == MatchOperand_Success) {
1669 assert(Operands.size() == 1);
1670 MipsOperand &Operand = static_cast<MipsOperand &>(*Operands.front());
1671 StartLoc = Operand.getStartLoc();
1672 EndLoc = Operand.getEndLoc();
1674 // AFAIK, we only support numeric registers and named GPR's in CFI
1676 // Don't worry about eating tokens before failing. Using an unrecognised
1677 // register is a parse error.
1678 if (Operand.isGPRAsmReg()) {
1679 // Resolve to GPR32 or GPR64 appropriately.
1680 RegNo = isGP64() ? Operand.getGPR64Reg() : Operand.getGPR32Reg();
1683 return (RegNo == (unsigned)-1);
1686 assert(Operands.size() == 0);
1687 return (RegNo == (unsigned)-1);
1690 bool MipsAsmParser::parseMemOffset(const MCExpr *&Res, bool isParenExpr) {
1694 while (getLexer().getKind() == AsmToken::LParen)
1697 switch (getLexer().getKind()) {
1700 case AsmToken::Identifier:
1701 case AsmToken::LParen:
1702 case AsmToken::Integer:
1703 case AsmToken::Minus:
1704 case AsmToken::Plus:
1706 Result = getParser().parseParenExpression(Res, S);
1708 Result = (getParser().parseExpression(Res));
1709 while (getLexer().getKind() == AsmToken::RParen)
1712 case AsmToken::Percent:
1713 Result = parseRelocOperand(Res);
1718 MipsAsmParser::OperandMatchResultTy
1719 MipsAsmParser::parseMemOperand(OperandVector &Operands) {
1720 DEBUG(dbgs() << "parseMemOperand\n");
1721 const MCExpr *IdVal = nullptr;
1723 bool isParenExpr = false;
1724 MipsAsmParser::OperandMatchResultTy Res = MatchOperand_NoMatch;
1725 // First operand is the offset.
1726 S = Parser.getTok().getLoc();
1728 if (getLexer().getKind() == AsmToken::LParen) {
1733 if (getLexer().getKind() != AsmToken::Dollar) {
1734 if (parseMemOffset(IdVal, isParenExpr))
1735 return MatchOperand_ParseFail;
1737 const AsmToken &Tok = Parser.getTok(); // Get the next token.
1738 if (Tok.isNot(AsmToken::LParen)) {
1739 MipsOperand &Mnemonic = static_cast<MipsOperand &>(*Operands[0]);
1740 if (Mnemonic.getToken() == "la") {
1742 SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
1743 Operands.push_back(MipsOperand::CreateImm(IdVal, S, E, *this));
1744 return MatchOperand_Success;
1746 if (Tok.is(AsmToken::EndOfStatement)) {
1748 SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
1750 // Zero register assumed, add a memory operand with ZERO as its base.
1751 // "Base" will be managed by k_Memory.
1752 auto Base = MipsOperand::CreateGPRReg(0, getContext().getRegisterInfo(),
1755 MipsOperand::CreateMem(std::move(Base), IdVal, S, E, *this));
1756 return MatchOperand_Success;
1758 Error(Parser.getTok().getLoc(), "'(' expected");
1759 return MatchOperand_ParseFail;
1762 Parser.Lex(); // Eat the '(' token.
1765 Res = ParseAnyRegister(Operands);
1766 if (Res != MatchOperand_Success)
1769 if (Parser.getTok().isNot(AsmToken::RParen)) {
1770 Error(Parser.getTok().getLoc(), "')' expected");
1771 return MatchOperand_ParseFail;
1774 SMLoc E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
1776 Parser.Lex(); // Eat the ')' token.
1779 IdVal = MCConstantExpr::Create(0, getContext());
1781 // Replace the register operand with the memory operand.
1782 std::unique_ptr<MipsOperand> op(
1783 static_cast<MipsOperand *>(Operands.back().release()));
1784 // Remove the register from the operands.
1785 // "op" will be managed by k_Memory.
1786 Operands.pop_back();
1787 // Add the memory operand.
1788 if (const MCBinaryExpr *BE = dyn_cast<MCBinaryExpr>(IdVal)) {
1790 if (IdVal->EvaluateAsAbsolute(Imm))
1791 IdVal = MCConstantExpr::Create(Imm, getContext());
1792 else if (BE->getLHS()->getKind() != MCExpr::SymbolRef)
1793 IdVal = MCBinaryExpr::Create(BE->getOpcode(), BE->getRHS(), BE->getLHS(),
1797 Operands.push_back(MipsOperand::CreateMem(std::move(op), IdVal, S, E, *this));
1798 return MatchOperand_Success;
1801 bool MipsAsmParser::searchSymbolAlias(OperandVector &Operands) {
1803 MCSymbol *Sym = getContext().LookupSymbol(Parser.getTok().getIdentifier());
1805 SMLoc S = Parser.getTok().getLoc();
1807 if (Sym->isVariable())
1808 Expr = Sym->getVariableValue();
1811 if (Expr->getKind() == MCExpr::SymbolRef) {
1812 const MCSymbolRefExpr *Ref = static_cast<const MCSymbolRefExpr *>(Expr);
1813 const StringRef DefSymbol = Ref->getSymbol().getName();
1814 if (DefSymbol.startswith("$")) {
1815 OperandMatchResultTy ResTy =
1816 MatchAnyRegisterNameWithoutDollar(Operands, DefSymbol.substr(1), S);
1817 if (ResTy == MatchOperand_Success) {
1820 } else if (ResTy == MatchOperand_ParseFail)
1821 llvm_unreachable("Should never ParseFail");
1824 } else if (Expr->getKind() == MCExpr::Constant) {
1826 const MCConstantExpr *Const = static_cast<const MCConstantExpr *>(Expr);
1828 MipsOperand::CreateImm(Const, S, Parser.getTok().getLoc(), *this));
1835 MipsAsmParser::OperandMatchResultTy
1836 MipsAsmParser::MatchAnyRegisterNameWithoutDollar(OperandVector &Operands,
1837 StringRef Identifier,
1839 int Index = matchCPURegisterName(Identifier);
1841 Operands.push_back(MipsOperand::CreateGPRReg(
1842 Index, getContext().getRegisterInfo(), S, getLexer().getLoc(), *this));
1843 return MatchOperand_Success;
1846 Index = matchFPURegisterName(Identifier);
1848 Operands.push_back(MipsOperand::CreateFGRReg(
1849 Index, getContext().getRegisterInfo(), S, getLexer().getLoc(), *this));
1850 return MatchOperand_Success;
1853 Index = matchFCCRegisterName(Identifier);
1855 Operands.push_back(MipsOperand::CreateFCCReg(
1856 Index, getContext().getRegisterInfo(), S, getLexer().getLoc(), *this));
1857 return MatchOperand_Success;
1860 Index = matchACRegisterName(Identifier);
1862 Operands.push_back(MipsOperand::CreateACCReg(
1863 Index, getContext().getRegisterInfo(), S, getLexer().getLoc(), *this));
1864 return MatchOperand_Success;
1867 Index = matchMSA128RegisterName(Identifier);
1869 Operands.push_back(MipsOperand::CreateMSA128Reg(
1870 Index, getContext().getRegisterInfo(), S, getLexer().getLoc(), *this));
1871 return MatchOperand_Success;
1874 Index = matchMSA128CtrlRegisterName(Identifier);
1876 Operands.push_back(MipsOperand::CreateMSACtrlReg(
1877 Index, getContext().getRegisterInfo(), S, getLexer().getLoc(), *this));
1878 return MatchOperand_Success;
1881 return MatchOperand_NoMatch;
1884 MipsAsmParser::OperandMatchResultTy
1885 MipsAsmParser::MatchAnyRegisterWithoutDollar(OperandVector &Operands, SMLoc S) {
1886 auto Token = Parser.getLexer().peekTok(false);
1888 if (Token.is(AsmToken::Identifier)) {
1889 DEBUG(dbgs() << ".. identifier\n");
1890 StringRef Identifier = Token.getIdentifier();
1891 OperandMatchResultTy ResTy =
1892 MatchAnyRegisterNameWithoutDollar(Operands, Identifier, S);
1894 } else if (Token.is(AsmToken::Integer)) {
1895 DEBUG(dbgs() << ".. integer\n");
1896 Operands.push_back(MipsOperand::CreateNumericReg(
1897 Token.getIntVal(), getContext().getRegisterInfo(), S, Token.getLoc(),
1899 return MatchOperand_Success;
1902 DEBUG(dbgs() << Parser.getTok().getKind() << "\n");
1904 return MatchOperand_NoMatch;
1907 MipsAsmParser::OperandMatchResultTy
1908 MipsAsmParser::ParseAnyRegister(OperandVector &Operands) {
1909 DEBUG(dbgs() << "ParseAnyRegister\n");
1911 auto Token = Parser.getTok();
1913 SMLoc S = Token.getLoc();
1915 if (Token.isNot(AsmToken::Dollar)) {
1916 DEBUG(dbgs() << ".. !$ -> try sym aliasing\n");
1917 if (Token.is(AsmToken::Identifier)) {
1918 if (searchSymbolAlias(Operands))
1919 return MatchOperand_Success;
1921 DEBUG(dbgs() << ".. !symalias -> NoMatch\n");
1922 return MatchOperand_NoMatch;
1924 DEBUG(dbgs() << ".. $\n");
1926 OperandMatchResultTy ResTy = MatchAnyRegisterWithoutDollar(Operands, S);
1927 if (ResTy == MatchOperand_Success) {
1929 Parser.Lex(); // identifier
1934 MipsAsmParser::OperandMatchResultTy
1935 MipsAsmParser::ParseImm(OperandVector &Operands) {
1936 switch (getLexer().getKind()) {
1938 return MatchOperand_NoMatch;
1939 case AsmToken::LParen:
1940 case AsmToken::Minus:
1941 case AsmToken::Plus:
1942 case AsmToken::Integer:
1943 case AsmToken::Tilde:
1944 case AsmToken::String:
1948 const MCExpr *IdVal;
1949 SMLoc S = Parser.getTok().getLoc();
1950 if (getParser().parseExpression(IdVal))
1951 return MatchOperand_ParseFail;
1953 SMLoc E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
1954 Operands.push_back(MipsOperand::CreateImm(IdVal, S, E, *this));
1955 return MatchOperand_Success;
1958 MipsAsmParser::OperandMatchResultTy
1959 MipsAsmParser::ParseJumpTarget(OperandVector &Operands) {
1960 DEBUG(dbgs() << "ParseJumpTarget\n");
1962 SMLoc S = getLexer().getLoc();
1964 // Integers and expressions are acceptable
1965 OperandMatchResultTy ResTy = ParseImm(Operands);
1966 if (ResTy != MatchOperand_NoMatch)
1969 // Registers are a valid target and have priority over symbols.
1970 ResTy = ParseAnyRegister(Operands);
1971 if (ResTy != MatchOperand_NoMatch)
1974 const MCExpr *Expr = nullptr;
1975 if (Parser.parseExpression(Expr)) {
1976 // We have no way of knowing if a symbol was consumed so we must ParseFail
1977 return MatchOperand_ParseFail;
1980 MipsOperand::CreateImm(Expr, S, getLexer().getLoc(), *this));
1981 return MatchOperand_Success;
1984 MipsAsmParser::OperandMatchResultTy
1985 MipsAsmParser::parseInvNum(OperandVector &Operands) {
1986 const MCExpr *IdVal;
1987 // If the first token is '$' we may have register operand.
1988 if (Parser.getTok().is(AsmToken::Dollar))
1989 return MatchOperand_NoMatch;
1990 SMLoc S = Parser.getTok().getLoc();
1991 if (getParser().parseExpression(IdVal))
1992 return MatchOperand_ParseFail;
1993 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(IdVal);
1994 assert(MCE && "Unexpected MCExpr type.");
1995 int64_t Val = MCE->getValue();
1996 SMLoc E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
1997 Operands.push_back(MipsOperand::CreateImm(
1998 MCConstantExpr::Create(0 - Val, getContext()), S, E, *this));
1999 return MatchOperand_Success;
2002 MipsAsmParser::OperandMatchResultTy
2003 MipsAsmParser::ParseLSAImm(OperandVector &Operands) {
2004 switch (getLexer().getKind()) {
2006 return MatchOperand_NoMatch;
2007 case AsmToken::LParen:
2008 case AsmToken::Plus:
2009 case AsmToken::Minus:
2010 case AsmToken::Integer:
2015 SMLoc S = Parser.getTok().getLoc();
2017 if (getParser().parseExpression(Expr))
2018 return MatchOperand_ParseFail;
2021 if (!Expr->EvaluateAsAbsolute(Val)) {
2022 Error(S, "expected immediate value");
2023 return MatchOperand_ParseFail;
2026 // The LSA instruction allows a 2-bit unsigned immediate. For this reason
2027 // and because the CPU always adds one to the immediate field, the allowed
2028 // range becomes 1..4. We'll only check the range here and will deal
2029 // with the addition/subtraction when actually decoding/encoding
2031 if (Val < 1 || Val > 4) {
2032 Error(S, "immediate not in range (1..4)");
2033 return MatchOperand_ParseFail;
2037 MipsOperand::CreateImm(Expr, S, Parser.getTok().getLoc(), *this));
2038 return MatchOperand_Success;
2041 MCSymbolRefExpr::VariantKind MipsAsmParser::getVariantKind(StringRef Symbol) {
2043 MCSymbolRefExpr::VariantKind VK =
2044 StringSwitch<MCSymbolRefExpr::VariantKind>(Symbol)
2045 .Case("hi", MCSymbolRefExpr::VK_Mips_ABS_HI)
2046 .Case("lo", MCSymbolRefExpr::VK_Mips_ABS_LO)
2047 .Case("gp_rel", MCSymbolRefExpr::VK_Mips_GPREL)
2048 .Case("call16", MCSymbolRefExpr::VK_Mips_GOT_CALL)
2049 .Case("got", MCSymbolRefExpr::VK_Mips_GOT)
2050 .Case("tlsgd", MCSymbolRefExpr::VK_Mips_TLSGD)
2051 .Case("tlsldm", MCSymbolRefExpr::VK_Mips_TLSLDM)
2052 .Case("dtprel_hi", MCSymbolRefExpr::VK_Mips_DTPREL_HI)
2053 .Case("dtprel_lo", MCSymbolRefExpr::VK_Mips_DTPREL_LO)
2054 .Case("gottprel", MCSymbolRefExpr::VK_Mips_GOTTPREL)
2055 .Case("tprel_hi", MCSymbolRefExpr::VK_Mips_TPREL_HI)
2056 .Case("tprel_lo", MCSymbolRefExpr::VK_Mips_TPREL_LO)
2057 .Case("got_disp", MCSymbolRefExpr::VK_Mips_GOT_DISP)
2058 .Case("got_page", MCSymbolRefExpr::VK_Mips_GOT_PAGE)
2059 .Case("got_ofst", MCSymbolRefExpr::VK_Mips_GOT_OFST)
2060 .Case("hi(%neg(%gp_rel", MCSymbolRefExpr::VK_Mips_GPOFF_HI)
2061 .Case("lo(%neg(%gp_rel", MCSymbolRefExpr::VK_Mips_GPOFF_LO)
2062 .Case("got_hi", MCSymbolRefExpr::VK_Mips_GOT_HI16)
2063 .Case("got_lo", MCSymbolRefExpr::VK_Mips_GOT_LO16)
2064 .Case("call_hi", MCSymbolRefExpr::VK_Mips_CALL_HI16)
2065 .Case("call_lo", MCSymbolRefExpr::VK_Mips_CALL_LO16)
2066 .Case("higher", MCSymbolRefExpr::VK_Mips_HIGHER)
2067 .Case("highest", MCSymbolRefExpr::VK_Mips_HIGHEST)
2068 .Case("pcrel_hi", MCSymbolRefExpr::VK_Mips_PCREL_HI16)
2069 .Case("pcrel_lo", MCSymbolRefExpr::VK_Mips_PCREL_LO16)
2070 .Default(MCSymbolRefExpr::VK_None);
2072 assert(VK != MCSymbolRefExpr::VK_None);
2077 /// Sometimes (i.e. load/stores) the operand may be followed immediately by
2079 /// ::= '(', register, ')'
2080 /// handle it before we iterate so we don't get tripped up by the lack of
2082 bool MipsAsmParser::ParseParenSuffix(StringRef Name, OperandVector &Operands) {
2083 if (getLexer().is(AsmToken::LParen)) {
2085 MipsOperand::CreateToken("(", getLexer().getLoc(), *this));
2087 if (ParseOperand(Operands, Name)) {
2088 SMLoc Loc = getLexer().getLoc();
2089 Parser.eatToEndOfStatement();
2090 return Error(Loc, "unexpected token in argument list");
2092 if (Parser.getTok().isNot(AsmToken::RParen)) {
2093 SMLoc Loc = getLexer().getLoc();
2094 Parser.eatToEndOfStatement();
2095 return Error(Loc, "unexpected token, expected ')'");
2098 MipsOperand::CreateToken(")", getLexer().getLoc(), *this));
2104 /// Sometimes (i.e. in MSA) the operand may be followed immediately by
2105 /// either one of these.
2106 /// ::= '[', register, ']'
2107 /// ::= '[', integer, ']'
2108 /// handle it before we iterate so we don't get tripped up by the lack of
2110 bool MipsAsmParser::ParseBracketSuffix(StringRef Name,
2111 OperandVector &Operands) {
2112 if (getLexer().is(AsmToken::LBrac)) {
2114 MipsOperand::CreateToken("[", getLexer().getLoc(), *this));
2116 if (ParseOperand(Operands, Name)) {
2117 SMLoc Loc = getLexer().getLoc();
2118 Parser.eatToEndOfStatement();
2119 return Error(Loc, "unexpected token in argument list");
2121 if (Parser.getTok().isNot(AsmToken::RBrac)) {
2122 SMLoc Loc = getLexer().getLoc();
2123 Parser.eatToEndOfStatement();
2124 return Error(Loc, "unexpected token, expected ']'");
2127 MipsOperand::CreateToken("]", getLexer().getLoc(), *this));
2133 bool MipsAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
2134 SMLoc NameLoc, OperandVector &Operands) {
2135 DEBUG(dbgs() << "ParseInstruction\n");
2136 // Check if we have valid mnemonic
2137 if (!mnemonicIsValid(Name, 0)) {
2138 Parser.eatToEndOfStatement();
2139 return Error(NameLoc, "Unknown instruction");
2141 // First operand in MCInst is instruction mnemonic.
2142 Operands.push_back(MipsOperand::CreateToken(Name, NameLoc, *this));
2144 // Read the remaining operands.
2145 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2146 // Read the first operand.
2147 if (ParseOperand(Operands, Name)) {
2148 SMLoc Loc = getLexer().getLoc();
2149 Parser.eatToEndOfStatement();
2150 return Error(Loc, "unexpected token in argument list");
2152 if (getLexer().is(AsmToken::LBrac) && ParseBracketSuffix(Name, Operands))
2154 // AFAIK, parenthesis suffixes are never on the first operand
2156 while (getLexer().is(AsmToken::Comma)) {
2157 Parser.Lex(); // Eat the comma.
2158 // Parse and remember the operand.
2159 if (ParseOperand(Operands, Name)) {
2160 SMLoc Loc = getLexer().getLoc();
2161 Parser.eatToEndOfStatement();
2162 return Error(Loc, "unexpected token in argument list");
2164 // Parse bracket and parenthesis suffixes before we iterate
2165 if (getLexer().is(AsmToken::LBrac)) {
2166 if (ParseBracketSuffix(Name, Operands))
2168 } else if (getLexer().is(AsmToken::LParen) &&
2169 ParseParenSuffix(Name, Operands))
2173 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2174 SMLoc Loc = getLexer().getLoc();
2175 Parser.eatToEndOfStatement();
2176 return Error(Loc, "unexpected token in argument list");
2178 Parser.Lex(); // Consume the EndOfStatement.
2182 bool MipsAsmParser::reportParseError(StringRef ErrorMsg) {
2183 SMLoc Loc = getLexer().getLoc();
2184 Parser.eatToEndOfStatement();
2185 return Error(Loc, ErrorMsg);
2188 bool MipsAsmParser::reportParseError(SMLoc Loc, StringRef ErrorMsg) {
2189 return Error(Loc, ErrorMsg);
2192 bool MipsAsmParser::parseSetNoAtDirective() {
2193 // Line should look like: ".set noat".
2195 Options.setATReg(0);
2198 // If this is not the end of the statement, report an error.
2199 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2200 reportParseError("unexpected token in statement");
2203 Parser.Lex(); // Consume the EndOfStatement.
2207 bool MipsAsmParser::parseSetAtDirective() {
2208 // Line can be .set at - defaults to $1
2212 if (getLexer().is(AsmToken::EndOfStatement)) {
2213 Options.setATReg(1);
2214 Parser.Lex(); // Consume the EndOfStatement.
2216 } else if (getLexer().is(AsmToken::Equal)) {
2217 getParser().Lex(); // Eat the '='.
2218 if (getLexer().isNot(AsmToken::Dollar)) {
2219 reportParseError("unexpected token in statement");
2222 Parser.Lex(); // Eat the '$'.
2223 const AsmToken &Reg = Parser.getTok();
2224 if (Reg.is(AsmToken::Identifier)) {
2225 AtRegNo = matchCPURegisterName(Reg.getIdentifier());
2226 } else if (Reg.is(AsmToken::Integer)) {
2227 AtRegNo = Reg.getIntVal();
2229 reportParseError("unexpected token in statement");
2233 if (AtRegNo < 0 || AtRegNo > 31) {
2234 reportParseError("unexpected token in statement");
2238 if (!Options.setATReg(AtRegNo)) {
2239 reportParseError("unexpected token in statement");
2242 getParser().Lex(); // Eat the register.
2244 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2245 reportParseError("unexpected token in statement");
2248 Parser.Lex(); // Consume the EndOfStatement.
2251 reportParseError("unexpected token in statement");
2256 bool MipsAsmParser::parseSetReorderDirective() {
2258 // If this is not the end of the statement, report an error.
2259 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2260 reportParseError("unexpected token in statement");
2263 Options.setReorder();
2264 getTargetStreamer().emitDirectiveSetReorder();
2265 Parser.Lex(); // Consume the EndOfStatement.
2269 bool MipsAsmParser::parseSetNoReorderDirective() {
2271 // If this is not the end of the statement, report an error.
2272 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2273 reportParseError("unexpected token in statement");
2276 Options.setNoreorder();
2277 getTargetStreamer().emitDirectiveSetNoReorder();
2278 Parser.Lex(); // Consume the EndOfStatement.
2282 bool MipsAsmParser::parseSetMacroDirective() {
2284 // If this is not the end of the statement, report an error.
2285 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2286 reportParseError("unexpected token in statement");
2290 Parser.Lex(); // Consume the EndOfStatement.
2294 bool MipsAsmParser::parseSetNoMacroDirective() {
2296 // If this is not the end of the statement, report an error.
2297 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2298 reportParseError("`noreorder' must be set before `nomacro'");
2301 if (Options.isReorder()) {
2302 reportParseError("`noreorder' must be set before `nomacro'");
2305 Options.setNomacro();
2306 Parser.Lex(); // Consume the EndOfStatement.
2310 bool MipsAsmParser::parseSetNoMips16Directive() {
2312 // If this is not the end of the statement, report an error.
2313 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2314 reportParseError("unexpected token in statement");
2317 // For now do nothing.
2318 Parser.Lex(); // Consume the EndOfStatement.
2322 bool MipsAsmParser::parseSetAssignment() {
2324 const MCExpr *Value;
2326 if (Parser.parseIdentifier(Name))
2327 reportParseError("expected identifier after .set");
2329 if (getLexer().isNot(AsmToken::Comma))
2330 return reportParseError("unexpected token in .set directive");
2333 if (Parser.parseExpression(Value))
2334 return reportParseError("expected valid expression after comma");
2336 // Check if the Name already exists as a symbol.
2337 MCSymbol *Sym = getContext().LookupSymbol(Name);
2339 return reportParseError("symbol already defined");
2340 Sym = getContext().GetOrCreateSymbol(Name);
2341 Sym->setVariableValue(Value);
2346 bool MipsAsmParser::parseSetFeature(uint64_t Feature) {
2348 if (getLexer().isNot(AsmToken::EndOfStatement))
2349 return reportParseError("unexpected token in .set directive");
2353 llvm_unreachable("Unimplemented feature");
2354 case Mips::FeatureDSP:
2355 setFeatureBits(Mips::FeatureDSP, "dsp");
2356 getTargetStreamer().emitDirectiveSetDsp();
2358 case Mips::FeatureMicroMips:
2359 getTargetStreamer().emitDirectiveSetMicroMips();
2361 case Mips::FeatureMips16:
2362 getTargetStreamer().emitDirectiveSetMips16();
2364 case Mips::FeatureMips32r2:
2365 setFeatureBits(Mips::FeatureMips32r2, "mips32r2");
2366 getTargetStreamer().emitDirectiveSetMips32R2();
2368 case Mips::FeatureMips64:
2369 setFeatureBits(Mips::FeatureMips64, "mips64");
2370 getTargetStreamer().emitDirectiveSetMips64();
2372 case Mips::FeatureMips64r2:
2373 setFeatureBits(Mips::FeatureMips64r2, "mips64r2");
2374 getTargetStreamer().emitDirectiveSetMips64R2();
2380 bool MipsAsmParser::eatComma(StringRef ErrorStr) {
2381 if (getLexer().isNot(AsmToken::Comma)) {
2382 SMLoc Loc = getLexer().getLoc();
2383 Parser.eatToEndOfStatement();
2384 return Error(Loc, ErrorStr);
2387 Parser.Lex(); // Eat the comma.
2391 bool MipsAsmParser::parseDirectiveCPLoad(SMLoc Loc) {
2392 if (Options.isReorder())
2393 Warning(Loc, ".cpload in reorder section");
2395 // FIXME: Warn if cpload is used in Mips16 mode.
2397 SmallVector<std::unique_ptr<MCParsedAsmOperand>, 1> Reg;
2398 OperandMatchResultTy ResTy = ParseAnyRegister(Reg);
2399 if (ResTy == MatchOperand_NoMatch || ResTy == MatchOperand_ParseFail) {
2400 reportParseError("expected register containing function address");
2404 MipsOperand &RegOpnd = static_cast<MipsOperand &>(*Reg[0]);
2405 if (!RegOpnd.isGPRAsmReg()) {
2406 reportParseError(RegOpnd.getStartLoc(), "invalid register");
2410 getTargetStreamer().emitDirectiveCpload(RegOpnd.getGPR32Reg());
2414 bool MipsAsmParser::parseDirectiveCPSetup() {
2417 bool SaveIsReg = true;
2419 SmallVector<std::unique_ptr<MCParsedAsmOperand>, 1> TmpReg;
2420 OperandMatchResultTy ResTy = ParseAnyRegister(TmpReg);
2421 if (ResTy == MatchOperand_NoMatch) {
2422 reportParseError("expected register containing function address");
2423 Parser.eatToEndOfStatement();
2427 MipsOperand &FuncRegOpnd = static_cast<MipsOperand &>(*TmpReg[0]);
2428 if (!FuncRegOpnd.isGPRAsmReg()) {
2429 reportParseError(FuncRegOpnd.getStartLoc(), "invalid register");
2430 Parser.eatToEndOfStatement();
2434 FuncReg = FuncRegOpnd.getGPR32Reg();
2437 if (!eatComma("expected comma parsing directive"))
2440 ResTy = ParseAnyRegister(TmpReg);
2441 if (ResTy == MatchOperand_NoMatch) {
2442 const AsmToken &Tok = Parser.getTok();
2443 if (Tok.is(AsmToken::Integer)) {
2444 Save = Tok.getIntVal();
2448 reportParseError("expected save register or stack offset");
2449 Parser.eatToEndOfStatement();
2453 MipsOperand &SaveOpnd = static_cast<MipsOperand &>(*TmpReg[0]);
2454 if (!SaveOpnd.isGPRAsmReg()) {
2455 reportParseError(SaveOpnd.getStartLoc(), "invalid register");
2456 Parser.eatToEndOfStatement();
2459 Save = SaveOpnd.getGPR32Reg();
2462 if (!eatComma("expected comma parsing directive"))
2466 if (Parser.parseIdentifier(Name))
2467 reportParseError("expected identifier");
2468 MCSymbol *Sym = getContext().GetOrCreateSymbol(Name);
2470 getTargetStreamer().emitDirectiveCpsetup(FuncReg, Save, *Sym, SaveIsReg);
2474 bool MipsAsmParser::parseDirectiveNaN() {
2475 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2476 const AsmToken &Tok = Parser.getTok();
2478 if (Tok.getString() == "2008") {
2480 getTargetStreamer().emitDirectiveNaN2008();
2482 } else if (Tok.getString() == "legacy") {
2484 getTargetStreamer().emitDirectiveNaNLegacy();
2488 // If we don't recognize the option passed to the .nan
2489 // directive (e.g. no option or unknown option), emit an error.
2490 reportParseError("invalid option in .nan directive");
2494 bool MipsAsmParser::parseDirectiveSet() {
2496 // Get the next token.
2497 const AsmToken &Tok = Parser.getTok();
2499 if (Tok.getString() == "noat") {
2500 return parseSetNoAtDirective();
2501 } else if (Tok.getString() == "at") {
2502 return parseSetAtDirective();
2503 } else if (Tok.getString() == "reorder") {
2504 return parseSetReorderDirective();
2505 } else if (Tok.getString() == "noreorder") {
2506 return parseSetNoReorderDirective();
2507 } else if (Tok.getString() == "macro") {
2508 return parseSetMacroDirective();
2509 } else if (Tok.getString() == "nomacro") {
2510 return parseSetNoMacroDirective();
2511 } else if (Tok.getString() == "mips16") {
2512 return parseSetFeature(Mips::FeatureMips16);
2513 } else if (Tok.getString() == "nomips16") {
2514 return parseSetNoMips16Directive();
2515 } else if (Tok.getString() == "nomicromips") {
2516 getTargetStreamer().emitDirectiveSetNoMicroMips();
2517 Parser.eatToEndOfStatement();
2519 } else if (Tok.getString() == "micromips") {
2520 return parseSetFeature(Mips::FeatureMicroMips);
2521 } else if (Tok.getString() == "mips32r2") {
2522 return parseSetFeature(Mips::FeatureMips32r2);
2523 } else if (Tok.getString() == "mips64") {
2524 return parseSetFeature(Mips::FeatureMips64);
2525 } else if (Tok.getString() == "mips64r2") {
2526 return parseSetFeature(Mips::FeatureMips64r2);
2527 } else if (Tok.getString() == "dsp") {
2528 return parseSetFeature(Mips::FeatureDSP);
2530 // It is just an identifier, look for an assignment.
2531 parseSetAssignment();
2538 /// parseDataDirective
2539 /// ::= .word [ expression (, expression)* ]
2540 bool MipsAsmParser::parseDataDirective(unsigned Size, SMLoc L) {
2541 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2543 const MCExpr *Value;
2544 if (getParser().parseExpression(Value))
2547 getParser().getStreamer().EmitValue(Value, Size);
2549 if (getLexer().is(AsmToken::EndOfStatement))
2552 // FIXME: Improve diagnostic.
2553 if (getLexer().isNot(AsmToken::Comma))
2554 return Error(L, "unexpected token in directive");
2563 /// parseDirectiveGpWord
2564 /// ::= .gpword local_sym
2565 bool MipsAsmParser::parseDirectiveGpWord() {
2566 const MCExpr *Value;
2567 // EmitGPRel32Value requires an expression, so we are using base class
2568 // method to evaluate the expression.
2569 if (getParser().parseExpression(Value))
2571 getParser().getStreamer().EmitGPRel32Value(Value);
2573 if (getLexer().isNot(AsmToken::EndOfStatement))
2574 return Error(getLexer().getLoc(), "unexpected token in directive");
2575 Parser.Lex(); // Eat EndOfStatement token.
2579 /// parseDirectiveGpDWord
2580 /// ::= .gpdword local_sym
2581 bool MipsAsmParser::parseDirectiveGpDWord() {
2582 const MCExpr *Value;
2583 // EmitGPRel64Value requires an expression, so we are using base class
2584 // method to evaluate the expression.
2585 if (getParser().parseExpression(Value))
2587 getParser().getStreamer().EmitGPRel64Value(Value);
2589 if (getLexer().isNot(AsmToken::EndOfStatement))
2590 return Error(getLexer().getLoc(), "unexpected token in directive");
2591 Parser.Lex(); // Eat EndOfStatement token.
2595 bool MipsAsmParser::parseDirectiveOption() {
2596 // Get the option token.
2597 AsmToken Tok = Parser.getTok();
2598 // At the moment only identifiers are supported.
2599 if (Tok.isNot(AsmToken::Identifier)) {
2600 Error(Parser.getTok().getLoc(), "unexpected token in .option directive");
2601 Parser.eatToEndOfStatement();
2605 StringRef Option = Tok.getIdentifier();
2607 if (Option == "pic0") {
2608 getTargetStreamer().emitDirectiveOptionPic0();
2610 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
2611 Error(Parser.getTok().getLoc(),
2612 "unexpected token in .option pic0 directive");
2613 Parser.eatToEndOfStatement();
2618 if (Option == "pic2") {
2619 getTargetStreamer().emitDirectiveOptionPic2();
2621 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
2622 Error(Parser.getTok().getLoc(),
2623 "unexpected token in .option pic2 directive");
2624 Parser.eatToEndOfStatement();
2630 Warning(Parser.getTok().getLoc(), "unknown option in .option directive");
2631 Parser.eatToEndOfStatement();
2635 bool MipsAsmParser::ParseDirective(AsmToken DirectiveID) {
2636 StringRef IDVal = DirectiveID.getString();
2638 if (IDVal == ".cpload")
2639 return parseDirectiveCPLoad(DirectiveID.getLoc());
2640 if (IDVal == ".dword") {
2641 parseDataDirective(8, DirectiveID.getLoc());
2645 if (IDVal == ".ent") {
2646 // Ignore this directive for now.
2651 if (IDVal == ".end") {
2652 // Ignore this directive for now.
2657 if (IDVal == ".frame") {
2658 // Ignore this directive for now.
2659 Parser.eatToEndOfStatement();
2663 if (IDVal == ".set") {
2664 return parseDirectiveSet();
2667 if (IDVal == ".fmask") {
2668 // Ignore this directive for now.
2669 Parser.eatToEndOfStatement();
2673 if (IDVal == ".mask") {
2674 // Ignore this directive for now.
2675 Parser.eatToEndOfStatement();
2679 if (IDVal == ".nan")
2680 return parseDirectiveNaN();
2682 if (IDVal == ".gpword") {
2683 parseDirectiveGpWord();
2687 if (IDVal == ".gpdword") {
2688 parseDirectiveGpDWord();
2692 if (IDVal == ".word") {
2693 parseDataDirective(4, DirectiveID.getLoc());
2697 if (IDVal == ".option")
2698 return parseDirectiveOption();
2700 if (IDVal == ".abicalls") {
2701 getTargetStreamer().emitDirectiveAbiCalls();
2702 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
2703 Error(Parser.getTok().getLoc(), "unexpected token in directive");
2705 Parser.eatToEndOfStatement();
2710 if (IDVal == ".cpsetup")
2711 return parseDirectiveCPSetup();
2716 extern "C" void LLVMInitializeMipsAsmParser() {
2717 RegisterMCAsmParser<MipsAsmParser> X(TheMipsTarget);
2718 RegisterMCAsmParser<MipsAsmParser> Y(TheMipselTarget);
2719 RegisterMCAsmParser<MipsAsmParser> A(TheMips64Target);
2720 RegisterMCAsmParser<MipsAsmParser> B(TheMips64elTarget);
2723 #define GET_REGISTER_MATCHER
2724 #define GET_MATCHER_IMPLEMENTATION
2725 #include "MipsGenAsmMatcher.inc"