[mips][msa] Direct Object Emission of INSERT.{B,H,W} instruction.
[oota-llvm.git] / lib / Target / Mips / AsmParser / MipsAsmParser.cpp
1 //===-- MipsAsmParser.cpp - Parse Mips assembly to MCInst instructions ----===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "MCTargetDesc/MipsMCTargetDesc.h"
11 #include "MipsRegisterInfo.h"
12 #include "MipsTargetStreamer.h"
13 #include "llvm/ADT/StringSwitch.h"
14 #include "llvm/MC/MCContext.h"
15 #include "llvm/MC/MCExpr.h"
16 #include "llvm/MC/MCInst.h"
17 #include "llvm/MC/MCParser/MCAsmLexer.h"
18 #include "llvm/MC/MCParser/MCParsedAsmOperand.h"
19 #include "llvm/MC/MCStreamer.h"
20 #include "llvm/MC/MCSubtargetInfo.h"
21 #include "llvm/MC/MCSymbol.h"
22 #include "llvm/MC/MCTargetAsmParser.h"
23 #include "llvm/Support/TargetRegistry.h"
24 #include "llvm/ADT/APInt.h"
25
26 using namespace llvm;
27
28 namespace llvm {
29 class MCInstrInfo;
30 }
31
32 namespace {
33 class MipsAssemblerOptions {
34 public:
35   MipsAssemblerOptions():
36     aTReg(1), reorder(true), macro(true) {
37   }
38
39   unsigned getATRegNum() {return aTReg;}
40   bool setATReg(unsigned Reg);
41
42   bool isReorder() {return reorder;}
43   void setReorder() {reorder = true;}
44   void setNoreorder() {reorder = false;}
45
46   bool isMacro() {return macro;}
47   void setMacro() {macro = true;}
48   void setNomacro() {macro = false;}
49
50 private:
51   unsigned aTReg;
52   bool reorder;
53   bool macro;
54 };
55 }
56
57 namespace {
58 class MipsAsmParser : public MCTargetAsmParser {
59
60   MipsTargetStreamer &getTargetStreamer() {
61     MCTargetStreamer &TS = Parser.getStreamer().getTargetStreamer();
62     return static_cast<MipsTargetStreamer &>(TS);
63   }
64
65   MCSubtargetInfo &STI;
66   MCAsmParser &Parser;
67   MipsAssemblerOptions Options;
68   bool hasConsumedDollar;
69
70 #define GET_ASSEMBLER_HEADER
71 #include "MipsGenAsmMatcher.inc"
72
73   bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
74                                SmallVectorImpl<MCParsedAsmOperand*> &Operands,
75                                MCStreamer &Out, unsigned &ErrorInfo,
76                                bool MatchingInlineAsm);
77
78   bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
79
80   bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
81                         SMLoc NameLoc,
82                         SmallVectorImpl<MCParsedAsmOperand*> &Operands);
83
84   bool ParseDirective(AsmToken DirectiveID);
85
86   MipsAsmParser::OperandMatchResultTy
87   parseRegs(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
88                          int RegKind);
89
90   MipsAsmParser::OperandMatchResultTy
91   parseMSARegs(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
92                int RegKind);
93
94   MipsAsmParser::OperandMatchResultTy
95   parseMemOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands);
96
97   bool parsePtrReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands, int RegKind);
98
99   MipsAsmParser::OperandMatchResultTy
100   parsePtrReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands);
101
102   MipsAsmParser::OperandMatchResultTy
103   parseGPR32(SmallVectorImpl<MCParsedAsmOperand*> &Operands);
104
105   MipsAsmParser::OperandMatchResultTy
106   parseGPR64(SmallVectorImpl<MCParsedAsmOperand*> &Operands);
107
108   MipsAsmParser::OperandMatchResultTy
109   parseHWRegs(SmallVectorImpl<MCParsedAsmOperand*> &Operands);
110
111   MipsAsmParser::OperandMatchResultTy
112   parseCCRRegs(SmallVectorImpl<MCParsedAsmOperand*> &Operands);
113
114   MipsAsmParser::OperandMatchResultTy
115   parseAFGR64Regs(SmallVectorImpl<MCParsedAsmOperand*> &Operands);
116
117   MipsAsmParser::OperandMatchResultTy
118   parseFGR64Regs(SmallVectorImpl<MCParsedAsmOperand*> &Operands);
119
120   MipsAsmParser::OperandMatchResultTy
121   parseFGR32Regs(SmallVectorImpl<MCParsedAsmOperand*> &Operands);
122
123   MipsAsmParser::OperandMatchResultTy
124   parseFGRH32Regs(SmallVectorImpl<MCParsedAsmOperand*> &Operands);
125
126   MipsAsmParser::OperandMatchResultTy
127   parseFCCRegs(SmallVectorImpl<MCParsedAsmOperand*> &Operands);
128
129   MipsAsmParser::OperandMatchResultTy
130   parseACC64DSP(SmallVectorImpl<MCParsedAsmOperand*> &Operands);
131
132   MipsAsmParser::OperandMatchResultTy
133   parseLO32DSP(SmallVectorImpl<MCParsedAsmOperand*> &Operands);
134
135   MipsAsmParser::OperandMatchResultTy
136   parseHI32DSP(SmallVectorImpl<MCParsedAsmOperand*> &Operands);
137
138   MipsAsmParser::OperandMatchResultTy
139   parseCOP2(SmallVectorImpl<MCParsedAsmOperand*> &Operands);
140
141   MipsAsmParser::OperandMatchResultTy
142   parseMSA128BRegs(SmallVectorImpl<MCParsedAsmOperand*> &Operands);
143
144   MipsAsmParser::OperandMatchResultTy
145   parseMSA128HRegs(SmallVectorImpl<MCParsedAsmOperand*> &Operands);
146
147   MipsAsmParser::OperandMatchResultTy
148   parseMSA128WRegs(SmallVectorImpl<MCParsedAsmOperand*> &Operands);
149
150   MipsAsmParser::OperandMatchResultTy
151   parseMSA128DRegs(SmallVectorImpl<MCParsedAsmOperand*> &Operands);
152
153   MipsAsmParser::OperandMatchResultTy
154   parseInvNum(SmallVectorImpl<MCParsedAsmOperand*> &Operands);
155
156   bool searchSymbolAlias(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
157                          unsigned RegKind);
158
159   bool ParseOperand(SmallVectorImpl<MCParsedAsmOperand*> &,
160                     StringRef Mnemonic);
161
162   int tryParseRegister(bool is64BitReg);
163
164   bool tryParseRegisterOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
165                                bool is64BitReg);
166
167   bool needsExpansion(MCInst &Inst);
168
169   void expandInstruction(MCInst &Inst, SMLoc IDLoc,
170                          SmallVectorImpl<MCInst> &Instructions);
171   void expandLoadImm(MCInst &Inst, SMLoc IDLoc,
172                      SmallVectorImpl<MCInst> &Instructions);
173   void expandLoadAddressImm(MCInst &Inst, SMLoc IDLoc,
174                             SmallVectorImpl<MCInst> &Instructions);
175   void expandLoadAddressReg(MCInst &Inst, SMLoc IDLoc,
176                             SmallVectorImpl<MCInst> &Instructions);
177   void expandMemInst(MCInst &Inst, SMLoc IDLoc,
178                      SmallVectorImpl<MCInst> &Instructions,
179                      bool isLoad,bool isImmOpnd);
180   bool reportParseError(StringRef ErrorMsg);
181
182   bool parseMemOffset(const MCExpr *&Res, bool isParenExpr);
183   bool parseRelocOperand(const MCExpr *&Res);
184
185   const MCExpr* evaluateRelocExpr(const MCExpr *Expr, StringRef RelocStr);
186
187   bool isEvaluated(const MCExpr *Expr);
188   bool parseDirectiveSet();
189   bool parseDirectiveMipsHackStocg();
190   bool parseDirectiveMipsHackELFFlags();
191
192   bool parseSetAtDirective();
193   bool parseSetNoAtDirective();
194   bool parseSetMacroDirective();
195   bool parseSetNoMacroDirective();
196   bool parseSetReorderDirective();
197   bool parseSetNoReorderDirective();
198
199   bool parseSetAssignment();
200
201   bool parseDirectiveWord(unsigned Size, SMLoc L);
202
203   MCSymbolRefExpr::VariantKind getVariantKind(StringRef Symbol);
204
205   bool isMips64() const {
206     return (STI.getFeatureBits() & Mips::FeatureMips64) != 0;
207   }
208
209   bool isFP64() const {
210     return (STI.getFeatureBits() & Mips::FeatureFP64Bit) != 0;
211   }
212
213   bool isN64() const {
214     return STI.getFeatureBits() & Mips::FeatureN64;
215   }
216
217   int matchRegisterName(StringRef Symbol, bool is64BitReg);
218
219   int matchCPURegisterName(StringRef Symbol);
220
221   int matchRegisterByNumber(unsigned RegNum, unsigned RegClass);
222
223   int matchFPURegisterName(StringRef Name);
224
225   int matchFCCRegisterName(StringRef Name);
226
227   int matchACRegisterName(StringRef Name);
228
229   int matchMSA128RegisterName(StringRef Name);
230
231   int regKindToRegClass(int RegKind);
232
233   unsigned getReg(int RC, int RegNo);
234
235   int getATReg();
236
237   bool processInstruction(MCInst &Inst, SMLoc IDLoc,
238                         SmallVectorImpl<MCInst> &Instructions);
239
240   // Helper function that checks if the value of a vector index is within the
241   // boundaries of accepted values for each RegisterKind
242   // Example: INSERT.B $w0[n], $1 => 16 > n >= 0
243   bool validateMSAIndex(int Val, int RegKind);
244
245 public:
246   MipsAsmParser(MCSubtargetInfo &sti, MCAsmParser &parser,
247                 const MCInstrInfo &MII)
248       : MCTargetAsmParser(), STI(sti), Parser(parser),
249         hasConsumedDollar(false) {
250     // Initialize the set of available features.
251     setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
252   }
253
254   MCAsmParser &getParser() const { return Parser; }
255   MCAsmLexer &getLexer() const { return Parser.getLexer(); }
256
257 };
258 }
259
260 namespace {
261
262 /// MipsOperand - Instances of this class represent a parsed Mips machine
263 /// instruction.
264 class MipsOperand : public MCParsedAsmOperand {
265
266 public:
267   enum RegisterKind {
268     Kind_None,
269     Kind_GPR32,
270     Kind_GPR64,
271     Kind_HWRegs,
272     Kind_FGR32Regs,
273     Kind_FGRH32Regs,
274     Kind_FGR64Regs,
275     Kind_AFGR64Regs,
276     Kind_CCRRegs,
277     Kind_FCCRegs,
278     Kind_ACC64DSP,
279     Kind_LO32DSP,
280     Kind_HI32DSP,
281     Kind_COP2,
282     Kind_MSA128BRegs,
283     Kind_MSA128HRegs,
284     Kind_MSA128WRegs,
285     Kind_MSA128DRegs
286   };
287
288 private:
289   enum KindTy {
290     k_CondCode,
291     k_CoprocNum,
292     k_Immediate,
293     k_Memory,
294     k_PostIndexRegister,
295     k_Register,
296     k_PtrReg,
297     k_Token
298   } Kind;
299
300   MipsOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
301
302   struct Token {
303     const char *Data;
304     unsigned Length;
305   };
306
307   struct RegOp {
308     unsigned RegNum;
309     RegisterKind Kind;
310   };
311
312   struct ImmOp {
313     const MCExpr *Val;
314   };
315
316   struct MemOp {
317     unsigned Base;
318     const MCExpr *Off;
319   };
320
321   union {
322     struct Token Tok;
323     struct RegOp Reg;
324     struct ImmOp Imm;
325     struct MemOp Mem;
326   };
327
328   SMLoc StartLoc, EndLoc;
329
330 public:
331   void addRegOperands(MCInst &Inst, unsigned N) const {
332     assert(N == 1 && "Invalid number of operands!");
333     Inst.addOperand(MCOperand::CreateReg(getReg()));
334   }
335
336   void addPtrRegOperands(MCInst &Inst, unsigned N) const {
337     assert(N == 1 && "Invalid number of operands!");
338     Inst.addOperand(MCOperand::CreateReg(getPtrReg()));
339   }
340
341   void addExpr(MCInst &Inst, const MCExpr *Expr) const{
342     // Add as immediate when possible.  Null MCExpr = 0.
343     if (Expr == 0)
344       Inst.addOperand(MCOperand::CreateImm(0));
345     else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
346       Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
347     else
348       Inst.addOperand(MCOperand::CreateExpr(Expr));
349   }
350
351   void addImmOperands(MCInst &Inst, unsigned N) const {
352     assert(N == 1 && "Invalid number of operands!");
353     const MCExpr *Expr = getImm();
354     addExpr(Inst, Expr);
355   }
356
357   void addMemOperands(MCInst &Inst, unsigned N) const {
358     assert(N == 2 && "Invalid number of operands!");
359
360     Inst.addOperand(MCOperand::CreateReg(getMemBase()));
361
362     const MCExpr *Expr = getMemOff();
363     addExpr(Inst, Expr);
364   }
365
366   bool isReg() const { return Kind == k_Register; }
367   bool isImm() const { return Kind == k_Immediate; }
368   bool isToken() const { return Kind == k_Token; }
369   bool isMem() const { return Kind == k_Memory; }
370   bool isPtrReg() const { return Kind == k_PtrReg; }
371   bool isInvNum() const { return Kind == k_Immediate; }
372
373   StringRef getToken() const {
374     assert(Kind == k_Token && "Invalid access!");
375     return StringRef(Tok.Data, Tok.Length);
376   }
377
378   unsigned getReg() const {
379     assert((Kind == k_Register) && "Invalid access!");
380     return Reg.RegNum;
381   }
382
383   unsigned getPtrReg() const {
384     assert((Kind == k_PtrReg) && "Invalid access!");
385     return Reg.RegNum;
386   }
387
388   void setRegKind(RegisterKind RegKind) {
389     assert((Kind == k_Register || Kind == k_PtrReg) && "Invalid access!");
390     Reg.Kind = RegKind;
391   }
392
393   const MCExpr *getImm() const {
394     assert((Kind == k_Immediate) && "Invalid access!");
395     return Imm.Val;
396   }
397
398   unsigned getMemBase() const {
399     assert((Kind == k_Memory) && "Invalid access!");
400     return Mem.Base;
401   }
402
403   const MCExpr *getMemOff() const {
404     assert((Kind == k_Memory) && "Invalid access!");
405     return Mem.Off;
406   }
407
408   static MipsOperand *CreateToken(StringRef Str, SMLoc S) {
409     MipsOperand *Op = new MipsOperand(k_Token);
410     Op->Tok.Data = Str.data();
411     Op->Tok.Length = Str.size();
412     Op->StartLoc = S;
413     Op->EndLoc = S;
414     return Op;
415   }
416
417   static MipsOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
418     MipsOperand *Op = new MipsOperand(k_Register);
419     Op->Reg.RegNum = RegNum;
420     Op->StartLoc = S;
421     Op->EndLoc = E;
422     return Op;
423   }
424
425   static MipsOperand *CreatePtrReg(unsigned RegNum, SMLoc S, SMLoc E) {
426     MipsOperand *Op = new MipsOperand(k_PtrReg);
427     Op->Reg.RegNum = RegNum;
428     Op->StartLoc = S;
429     Op->EndLoc = E;
430     return Op;
431   }
432
433   static MipsOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
434     MipsOperand *Op = new MipsOperand(k_Immediate);
435     Op->Imm.Val = Val;
436     Op->StartLoc = S;
437     Op->EndLoc = E;
438     return Op;
439   }
440
441   static MipsOperand *CreateMem(unsigned Base, const MCExpr *Off,
442                                  SMLoc S, SMLoc E) {
443     MipsOperand *Op = new MipsOperand(k_Memory);
444     Op->Mem.Base = Base;
445     Op->Mem.Off = Off;
446     Op->StartLoc = S;
447     Op->EndLoc = E;
448     return Op;
449   }
450
451   bool isGPR32Asm() const {
452     return Kind == k_Register && Reg.Kind == Kind_GPR32;
453   }
454   void addRegAsmOperands(MCInst &Inst, unsigned N) const {
455     Inst.addOperand(MCOperand::CreateReg(Reg.RegNum));
456   }
457
458   bool isGPR64Asm() const {
459     return Kind == k_Register && Reg.Kind == Kind_GPR64;
460   }
461
462   bool isHWRegsAsm() const {
463     assert((Kind == k_Register) && "Invalid access!");
464     return Reg.Kind == Kind_HWRegs;
465   }
466
467   bool isCCRAsm() const {
468     assert((Kind == k_Register) && "Invalid access!");
469     return Reg.Kind == Kind_CCRRegs;
470   }
471
472    bool isAFGR64Asm() const {
473     return Kind == k_Register && Reg.Kind == Kind_AFGR64Regs;
474   }
475
476   bool isFGR64Asm() const {
477     return Kind == k_Register && Reg.Kind == Kind_FGR64Regs;
478   }
479
480   bool isFGR32Asm() const {
481     return (Kind == k_Register) && Reg.Kind == Kind_FGR32Regs;
482   }
483
484   bool isFGRH32Asm() const {
485     return (Kind == k_Register) && Reg.Kind == Kind_FGRH32Regs;
486   }
487
488   bool isFCCRegsAsm() const {
489     return (Kind == k_Register) && Reg.Kind == Kind_FCCRegs;
490   }
491
492   bool isACC64DSPAsm() const {
493     return Kind == k_Register && Reg.Kind == Kind_ACC64DSP;
494   }
495
496   bool isLO32DSPAsm() const {
497     return Kind == k_Register && Reg.Kind == Kind_LO32DSP;
498   }
499
500   bool isHI32DSPAsm() const {
501     return Kind == k_Register && Reg.Kind == Kind_HI32DSP;
502   }
503
504   bool isCOP2Asm() const {
505     return Kind == k_Register && Reg.Kind == Kind_COP2;
506   }
507
508   bool isMSA128BAsm() const {
509     return Kind == k_Register && Reg.Kind == Kind_MSA128BRegs;
510   }
511
512   bool isMSA128HAsm() const {
513     return Kind == k_Register && Reg.Kind == Kind_MSA128HRegs;
514   }
515
516   bool isMSA128WAsm() const {
517     return Kind == k_Register && Reg.Kind == Kind_MSA128WRegs;
518   }
519
520   bool isMSA128DAsm() const {
521     return Kind == k_Register && Reg.Kind == Kind_MSA128DRegs;
522   }
523
524   /// getStartLoc - Get the location of the first token of this operand.
525   SMLoc getStartLoc() const {
526     return StartLoc;
527   }
528   /// getEndLoc - Get the location of the last token of this operand.
529   SMLoc getEndLoc() const {
530     return EndLoc;
531   }
532
533   virtual void print(raw_ostream &OS) const {
534     llvm_unreachable("unimplemented!");
535   }
536 }; // class MipsOperand
537 }  // namespace
538
539 namespace llvm {
540 extern const MCInstrDesc MipsInsts[];
541 }
542 static const MCInstrDesc &getInstDesc(unsigned Opcode) {
543   return MipsInsts[Opcode];
544 }
545
546 bool MipsAsmParser::processInstruction(MCInst &Inst, SMLoc IDLoc,
547                                        SmallVectorImpl<MCInst> &Instructions) {
548   const MCInstrDesc &MCID = getInstDesc(Inst.getOpcode());
549   Inst.setLoc(IDLoc);
550   if (MCID.hasDelaySlot() && Options.isReorder()) {
551     // If this instruction has a delay slot and .set reorder is active,
552     // emit a NOP after it.
553     Instructions.push_back(Inst);
554     MCInst NopInst;
555     NopInst.setOpcode(Mips::SLL);
556     NopInst.addOperand(MCOperand::CreateReg(Mips::ZERO));
557     NopInst.addOperand(MCOperand::CreateReg(Mips::ZERO));
558     NopInst.addOperand(MCOperand::CreateImm(0));
559     Instructions.push_back(NopInst);
560     return false;
561   }
562
563   if (MCID.mayLoad() || MCID.mayStore()) {
564     // Check the offset of memory operand, if it is a symbol
565     // reference or immediate we may have to expand instructions.
566     for (unsigned i = 0; i < MCID.getNumOperands(); i++) {
567       const MCOperandInfo &OpInfo = MCID.OpInfo[i];
568       if ((OpInfo.OperandType == MCOI::OPERAND_MEMORY)
569           || (OpInfo.OperandType == MCOI::OPERAND_UNKNOWN)) {
570         MCOperand &Op = Inst.getOperand(i);
571         if (Op.isImm()) {
572           int MemOffset = Op.getImm();
573           if (MemOffset < -32768 || MemOffset > 32767) {
574             // Offset can't exceed 16bit value.
575             expandMemInst(Inst, IDLoc, Instructions, MCID.mayLoad(), true);
576             return false;
577           }
578         } else if (Op.isExpr()) {
579           const MCExpr *Expr = Op.getExpr();
580           if (Expr->getKind() == MCExpr::SymbolRef) {
581             const MCSymbolRefExpr *SR =
582                 static_cast<const MCSymbolRefExpr*>(Expr);
583             if (SR->getKind() == MCSymbolRefExpr::VK_None) {
584               // Expand symbol.
585               expandMemInst(Inst, IDLoc, Instructions, MCID.mayLoad(), false);
586               return false;
587             }
588           } else if (!isEvaluated(Expr)) {
589             expandMemInst(Inst, IDLoc, Instructions, MCID.mayLoad(), false);
590             return false;
591           }
592         }
593       }
594     } // for
595   } // if load/store
596
597   if (needsExpansion(Inst))
598     expandInstruction(Inst, IDLoc, Instructions);
599   else
600     Instructions.push_back(Inst);
601
602   return false;
603 }
604
605 bool MipsAsmParser::needsExpansion(MCInst &Inst) {
606
607   switch (Inst.getOpcode()) {
608   case Mips::LoadImm32Reg:
609   case Mips::LoadAddr32Imm:
610   case Mips::LoadAddr32Reg:
611     return true;
612   default:
613     return false;
614   }
615 }
616
617 void MipsAsmParser::expandInstruction(MCInst &Inst, SMLoc IDLoc,
618                                        SmallVectorImpl<MCInst> &Instructions) {
619   switch (Inst.getOpcode()) {
620   case Mips::LoadImm32Reg:
621     return expandLoadImm(Inst, IDLoc, Instructions);
622   case Mips::LoadAddr32Imm:
623     return expandLoadAddressImm(Inst, IDLoc, Instructions);
624   case Mips::LoadAddr32Reg:
625     return expandLoadAddressReg(Inst, IDLoc, Instructions);
626   }
627 }
628
629 void MipsAsmParser::expandLoadImm(MCInst &Inst, SMLoc IDLoc,
630                                   SmallVectorImpl<MCInst> &Instructions) {
631   MCInst tmpInst;
632   const MCOperand &ImmOp = Inst.getOperand(1);
633   assert(ImmOp.isImm() && "expected immediate operand kind");
634   const MCOperand &RegOp = Inst.getOperand(0);
635   assert(RegOp.isReg() && "expected register operand kind");
636
637   int ImmValue = ImmOp.getImm();
638   tmpInst.setLoc(IDLoc);
639   if (0 <= ImmValue && ImmValue <= 65535) {
640     // For 0 <= j <= 65535.
641     // li d,j => ori d,$zero,j
642     tmpInst.setOpcode(Mips::ORi);
643     tmpInst.addOperand(MCOperand::CreateReg(RegOp.getReg()));
644     tmpInst.addOperand(MCOperand::CreateReg(Mips::ZERO));
645     tmpInst.addOperand(MCOperand::CreateImm(ImmValue));
646     Instructions.push_back(tmpInst);
647   } else if (ImmValue < 0 && ImmValue >= -32768) {
648     // For -32768 <= j < 0.
649     // li d,j => addiu d,$zero,j
650     tmpInst.setOpcode(Mips::ADDiu);
651     tmpInst.addOperand(MCOperand::CreateReg(RegOp.getReg()));
652     tmpInst.addOperand(MCOperand::CreateReg(Mips::ZERO));
653     tmpInst.addOperand(MCOperand::CreateImm(ImmValue));
654     Instructions.push_back(tmpInst);
655   } else {
656     // For any other value of j that is representable as a 32-bit integer.
657     // li d,j => lui d,hi16(j)
658     //           ori d,d,lo16(j)
659     tmpInst.setOpcode(Mips::LUi);
660     tmpInst.addOperand(MCOperand::CreateReg(RegOp.getReg()));
661     tmpInst.addOperand(MCOperand::CreateImm((ImmValue & 0xffff0000) >> 16));
662     Instructions.push_back(tmpInst);
663     tmpInst.clear();
664     tmpInst.setOpcode(Mips::ORi);
665     tmpInst.addOperand(MCOperand::CreateReg(RegOp.getReg()));
666     tmpInst.addOperand(MCOperand::CreateReg(RegOp.getReg()));
667     tmpInst.addOperand(MCOperand::CreateImm(ImmValue & 0xffff));
668     tmpInst.setLoc(IDLoc);
669     Instructions.push_back(tmpInst);
670   }
671 }
672
673 void MipsAsmParser::expandLoadAddressReg(MCInst &Inst, SMLoc IDLoc,
674                                        SmallVectorImpl<MCInst> &Instructions) {
675   MCInst tmpInst;
676   const MCOperand &ImmOp = Inst.getOperand(2);
677   assert(ImmOp.isImm() && "expected immediate operand kind");
678   const MCOperand &SrcRegOp = Inst.getOperand(1);
679   assert(SrcRegOp.isReg() && "expected register operand kind");
680   const MCOperand &DstRegOp = Inst.getOperand(0);
681   assert(DstRegOp.isReg() && "expected register operand kind");
682   int ImmValue = ImmOp.getImm();
683   if (-32768 <= ImmValue && ImmValue <= 65535) {
684     // For -32768 <= j <= 65535.
685     // la d,j(s) => addiu d,s,j
686     tmpInst.setOpcode(Mips::ADDiu);
687     tmpInst.addOperand(MCOperand::CreateReg(DstRegOp.getReg()));
688     tmpInst.addOperand(MCOperand::CreateReg(SrcRegOp.getReg()));
689     tmpInst.addOperand(MCOperand::CreateImm(ImmValue));
690     Instructions.push_back(tmpInst);
691   } else {
692     // For any other value of j that is representable as a 32-bit integer.
693     // la d,j(s) => lui d,hi16(j)
694     //              ori d,d,lo16(j)
695     //              addu d,d,s
696     tmpInst.setOpcode(Mips::LUi);
697     tmpInst.addOperand(MCOperand::CreateReg(DstRegOp.getReg()));
698     tmpInst.addOperand(MCOperand::CreateImm((ImmValue & 0xffff0000) >> 16));
699     Instructions.push_back(tmpInst);
700     tmpInst.clear();
701     tmpInst.setOpcode(Mips::ORi);
702     tmpInst.addOperand(MCOperand::CreateReg(DstRegOp.getReg()));
703     tmpInst.addOperand(MCOperand::CreateReg(DstRegOp.getReg()));
704     tmpInst.addOperand(MCOperand::CreateImm(ImmValue & 0xffff));
705     Instructions.push_back(tmpInst);
706     tmpInst.clear();
707     tmpInst.setOpcode(Mips::ADDu);
708     tmpInst.addOperand(MCOperand::CreateReg(DstRegOp.getReg()));
709     tmpInst.addOperand(MCOperand::CreateReg(DstRegOp.getReg()));
710     tmpInst.addOperand(MCOperand::CreateReg(SrcRegOp.getReg()));
711     Instructions.push_back(tmpInst);
712   }
713 }
714
715 void MipsAsmParser::expandLoadAddressImm(MCInst &Inst, SMLoc IDLoc,
716                                        SmallVectorImpl<MCInst> &Instructions) {
717   MCInst tmpInst;
718   const MCOperand &ImmOp = Inst.getOperand(1);
719   assert(ImmOp.isImm() && "expected immediate operand kind");
720   const MCOperand &RegOp = Inst.getOperand(0);
721   assert(RegOp.isReg() && "expected register operand kind");
722   int ImmValue = ImmOp.getImm();
723   if (-32768 <= ImmValue && ImmValue <= 65535) {
724     // For -32768 <= j <= 65535.
725     // la d,j => addiu d,$zero,j
726     tmpInst.setOpcode(Mips::ADDiu);
727     tmpInst.addOperand(MCOperand::CreateReg(RegOp.getReg()));
728     tmpInst.addOperand(MCOperand::CreateReg(Mips::ZERO));
729     tmpInst.addOperand(MCOperand::CreateImm(ImmValue));
730     Instructions.push_back(tmpInst);
731   } else {
732     // For any other value of j that is representable as a 32-bit integer.
733     // la d,j => lui d,hi16(j)
734     //           ori d,d,lo16(j)
735     tmpInst.setOpcode(Mips::LUi);
736     tmpInst.addOperand(MCOperand::CreateReg(RegOp.getReg()));
737     tmpInst.addOperand(MCOperand::CreateImm((ImmValue & 0xffff0000) >> 16));
738     Instructions.push_back(tmpInst);
739     tmpInst.clear();
740     tmpInst.setOpcode(Mips::ORi);
741     tmpInst.addOperand(MCOperand::CreateReg(RegOp.getReg()));
742     tmpInst.addOperand(MCOperand::CreateReg(RegOp.getReg()));
743     tmpInst.addOperand(MCOperand::CreateImm(ImmValue & 0xffff));
744     Instructions.push_back(tmpInst);
745   }
746 }
747
748 void MipsAsmParser::expandMemInst(MCInst &Inst, SMLoc IDLoc,
749           SmallVectorImpl<MCInst> &Instructions, bool isLoad, bool isImmOpnd) {
750   const MCSymbolRefExpr *SR;
751   MCInst TempInst;
752   unsigned ImmOffset, HiOffset, LoOffset;
753   const MCExpr *ExprOffset;
754   unsigned TmpRegNum;
755   unsigned AtRegNum = getReg((isMips64()) ? Mips::GPR64RegClassID
756                              : Mips::GPR32RegClassID, getATReg());
757   // 1st operand is either the source or destination register.
758   assert(Inst.getOperand(0).isReg() && "expected register operand kind");
759   unsigned RegOpNum = Inst.getOperand(0).getReg();
760   // 2nd operand is the base register.
761   assert(Inst.getOperand(1).isReg() && "expected register operand kind");
762   unsigned BaseRegNum = Inst.getOperand(1).getReg();
763   // 3rd operand is either an immediate or expression.
764   if (isImmOpnd) {
765     assert(Inst.getOperand(2).isImm() && "expected immediate operand kind");
766     ImmOffset = Inst.getOperand(2).getImm();
767     LoOffset = ImmOffset & 0x0000ffff;
768     HiOffset = (ImmOffset & 0xffff0000) >> 16;
769     // If msb of LoOffset is 1(negative number) we must increment HiOffset.
770     if (LoOffset & 0x8000)
771       HiOffset++;
772   } else
773     ExprOffset = Inst.getOperand(2).getExpr();
774   // All instructions will have the same location.
775   TempInst.setLoc(IDLoc);
776   // 1st instruction in expansion is LUi. For load instruction we can use
777   // the dst register as a temporary if base and dst are different,
778   // but for stores we must use $at.
779   TmpRegNum = (isLoad && (BaseRegNum != RegOpNum)) ? RegOpNum : AtRegNum;
780   TempInst.setOpcode(Mips::LUi);
781   TempInst.addOperand(MCOperand::CreateReg(TmpRegNum));
782   if (isImmOpnd)
783     TempInst.addOperand(MCOperand::CreateImm(HiOffset));
784   else {
785     if (ExprOffset->getKind() == MCExpr::SymbolRef) {
786       SR = static_cast<const MCSymbolRefExpr*>(ExprOffset);
787       const MCSymbolRefExpr *HiExpr = MCSymbolRefExpr::Create(
788           SR->getSymbol().getName(), MCSymbolRefExpr::VK_Mips_ABS_HI,
789           getContext());
790       TempInst.addOperand(MCOperand::CreateExpr(HiExpr));
791     } else {
792       const MCExpr *HiExpr = evaluateRelocExpr(ExprOffset, "hi");
793       TempInst.addOperand(MCOperand::CreateExpr(HiExpr));
794     }
795   }
796   // Add the instruction to the list.
797   Instructions.push_back(TempInst);
798   // Prepare TempInst for next instruction.
799   TempInst.clear();
800   // Add temp register to base.
801   TempInst.setOpcode(Mips::ADDu);
802   TempInst.addOperand(MCOperand::CreateReg(TmpRegNum));
803   TempInst.addOperand(MCOperand::CreateReg(TmpRegNum));
804   TempInst.addOperand(MCOperand::CreateReg(BaseRegNum));
805   Instructions.push_back(TempInst);
806   TempInst.clear();
807   // And finaly, create original instruction with low part
808   // of offset and new base.
809   TempInst.setOpcode(Inst.getOpcode());
810   TempInst.addOperand(MCOperand::CreateReg(RegOpNum));
811   TempInst.addOperand(MCOperand::CreateReg(TmpRegNum));
812   if (isImmOpnd)
813     TempInst.addOperand(MCOperand::CreateImm(LoOffset));
814   else {
815     if (ExprOffset->getKind() == MCExpr::SymbolRef) {
816       const MCSymbolRefExpr *LoExpr = MCSymbolRefExpr::Create(
817           SR->getSymbol().getName(), MCSymbolRefExpr::VK_Mips_ABS_LO,
818           getContext());
819       TempInst.addOperand(MCOperand::CreateExpr(LoExpr));
820     } else {
821       const MCExpr *LoExpr = evaluateRelocExpr(ExprOffset, "lo");
822       TempInst.addOperand(MCOperand::CreateExpr(LoExpr));
823     }
824   }
825   Instructions.push_back(TempInst);
826   TempInst.clear();
827 }
828
829 bool MipsAsmParser::
830 MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
831                         SmallVectorImpl<MCParsedAsmOperand*> &Operands,
832                         MCStreamer &Out, unsigned &ErrorInfo,
833                         bool MatchingInlineAsm) {
834   MCInst Inst;
835   SmallVector<MCInst, 8> Instructions;
836   unsigned MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
837                                               MatchingInlineAsm);
838
839   switch (MatchResult) {
840   default:
841     break;
842   case Match_Success: {
843     if (processInstruction(Inst, IDLoc, Instructions))
844       return true;
845     for (unsigned i = 0; i < Instructions.size(); i++)
846       Out.EmitInstruction(Instructions[i]);
847     return false;
848   }
849   case Match_MissingFeature:
850     Error(IDLoc, "instruction requires a CPU feature not currently enabled");
851     return true;
852   case Match_InvalidOperand: {
853     SMLoc ErrorLoc = IDLoc;
854     if (ErrorInfo != ~0U) {
855       if (ErrorInfo >= Operands.size())
856         return Error(IDLoc, "too few operands for instruction");
857
858       ErrorLoc = ((MipsOperand*) Operands[ErrorInfo])->getStartLoc();
859       if (ErrorLoc == SMLoc())
860         ErrorLoc = IDLoc;
861     }
862
863     return Error(ErrorLoc, "invalid operand for instruction");
864   }
865   case Match_MnemonicFail:
866     return Error(IDLoc, "invalid instruction");
867   }
868   return true;
869 }
870
871 int MipsAsmParser::matchCPURegisterName(StringRef Name) {
872    int CC;
873
874   if (Name == "at")
875     return getATReg();
876
877     CC = StringSwitch<unsigned>(Name)
878     .Case("zero", 0)
879     .Case("a0",   4)
880     .Case("a1",   5)
881     .Case("a2",   6)
882     .Case("a3",   7)
883     .Case("v0",   2)
884     .Case("v1",   3)
885     .Case("s0",  16)
886     .Case("s1",  17)
887     .Case("s2",  18)
888     .Case("s3",  19)
889     .Case("s4",  20)
890     .Case("s5",  21)
891     .Case("s6",  22)
892     .Case("s7",  23)
893     .Case("k0",  26)
894     .Case("k1",  27)
895     .Case("sp",  29)
896     .Case("fp",  30)
897     .Case("gp",  28)
898     .Case("ra",  31)
899     .Case("t0",   8)
900     .Case("t1",   9)
901     .Case("t2",  10)
902     .Case("t3",  11)
903     .Case("t4",  12)
904     .Case("t5",  13)
905     .Case("t6",  14)
906     .Case("t7",  15)
907     .Case("t8",  24)
908     .Case("t9",  25)
909     .Default(-1);
910
911   // Although SGI documentation just cuts out t0-t3 for n32/n64,
912   // GNU pushes the values of t0-t3 to override the o32/o64 values for t4-t7
913   // We are supporting both cases, so for t0-t3 we'll just push them to t4-t7.
914   if (isMips64() && 8 <= CC && CC <= 11)
915     CC += 4;
916
917   if (CC == -1 && isMips64())
918     CC = StringSwitch<unsigned>(Name)
919       .Case("a4",   8)
920       .Case("a5",   9)
921       .Case("a6",  10)
922       .Case("a7",  11)
923       .Case("kt0", 26)
924       .Case("kt1", 27)
925       .Case("s8",  30)
926       .Default(-1);
927
928   return CC;
929 }
930
931 int MipsAsmParser::matchFPURegisterName(StringRef Name) {
932
933   if (Name[0] == 'f') {
934     StringRef NumString = Name.substr(1);
935     unsigned IntVal;
936     if (NumString.getAsInteger(10, IntVal))
937       return -1; // This is not an integer.
938     if (IntVal > 31) // Maximum index for fpu register.
939       return -1;
940     return IntVal;
941   }
942   return -1;
943 }
944
945 int MipsAsmParser::matchFCCRegisterName(StringRef Name) {
946
947   if (Name.startswith("fcc")) {
948     StringRef NumString = Name.substr(3);
949     unsigned IntVal;
950     if (NumString.getAsInteger(10, IntVal))
951       return -1; // This is not an integer.
952     if (IntVal > 7) // There are only 8 fcc registers.
953       return -1;
954     return IntVal;
955   }
956   return -1;
957 }
958
959 int MipsAsmParser::matchACRegisterName(StringRef Name) {
960
961   if (Name.startswith("ac")) {
962     StringRef NumString = Name.substr(2);
963     unsigned IntVal;
964     if (NumString.getAsInteger(10, IntVal))
965       return -1; // This is not an integer.
966     if (IntVal > 3) // There are only 3 acc registers.
967       return -1;
968     return IntVal;
969   }
970   return -1;
971 }
972
973 int MipsAsmParser::matchMSA128RegisterName(StringRef Name) {
974   unsigned IntVal;
975
976   if (Name.front() != 'w' || Name.drop_front(1).getAsInteger(10, IntVal))
977     return -1;
978
979   if (IntVal > 31)
980     return -1;
981
982   return IntVal;
983 }
984
985 int MipsAsmParser::matchRegisterName(StringRef Name, bool is64BitReg) {
986
987   int CC;
988   CC = matchCPURegisterName(Name);
989   if (CC != -1)
990     return matchRegisterByNumber(CC, is64BitReg ? Mips::GPR64RegClassID
991                                                 : Mips::GPR32RegClassID);
992   CC = matchFPURegisterName(Name);
993   //TODO: decide about fpu register class
994   if (CC != -1)
995     return matchRegisterByNumber(CC, isFP64() ? Mips::FGR64RegClassID
996                                               : Mips::FGR32RegClassID);
997   return matchMSA128RegisterName(Name);
998 }
999
1000 int MipsAsmParser::regKindToRegClass(int RegKind) {
1001
1002   switch (RegKind) {
1003   case MipsOperand::Kind_GPR32: return Mips::GPR32RegClassID;
1004   case MipsOperand::Kind_GPR64: return Mips::GPR64RegClassID;
1005   case MipsOperand::Kind_HWRegs: return Mips::HWRegsRegClassID;
1006   case MipsOperand::Kind_FGR32Regs: return Mips::FGR32RegClassID;
1007   case MipsOperand::Kind_FGRH32Regs: return Mips::FGRH32RegClassID;
1008   case MipsOperand::Kind_FGR64Regs: return Mips::FGR64RegClassID;
1009   case MipsOperand::Kind_AFGR64Regs: return Mips::AFGR64RegClassID;
1010   case MipsOperand::Kind_CCRRegs: return Mips::CCRRegClassID;
1011   case MipsOperand::Kind_ACC64DSP: return Mips::ACC64DSPRegClassID;
1012   case MipsOperand::Kind_FCCRegs: return Mips::FCCRegClassID;
1013   case MipsOperand::Kind_MSA128BRegs: return Mips::MSA128BRegClassID;
1014   case MipsOperand::Kind_MSA128HRegs: return Mips::MSA128HRegClassID;
1015   case MipsOperand::Kind_MSA128WRegs: return Mips::MSA128WRegClassID;
1016   case MipsOperand::Kind_MSA128DRegs: return Mips::MSA128DRegClassID;
1017   default :return -1;
1018   }
1019
1020 }
1021
1022 bool MipsAssemblerOptions::setATReg(unsigned Reg) {
1023   if (Reg > 31)
1024     return false;
1025
1026   aTReg = Reg;
1027   return true;
1028 }
1029
1030 int MipsAsmParser::getATReg() {
1031   return Options.getATRegNum();
1032 }
1033
1034 unsigned MipsAsmParser::getReg(int RC, int RegNo) {
1035   return *(getContext().getRegisterInfo()->getRegClass(RC).begin() + RegNo);
1036 }
1037
1038 int MipsAsmParser::matchRegisterByNumber(unsigned RegNum, unsigned RegClass) {
1039   if (RegNum >
1040        getContext().getRegisterInfo()->getRegClass(RegClass).getNumRegs())
1041     return -1;
1042
1043   return getReg(RegClass, RegNum);
1044 }
1045
1046 int MipsAsmParser::tryParseRegister(bool is64BitReg) {
1047   const AsmToken &Tok = Parser.getTok();
1048   int RegNum = -1;
1049
1050   if (Tok.is(AsmToken::Identifier)) {
1051     std::string lowerCase = Tok.getString().lower();
1052     RegNum = matchRegisterName(lowerCase, is64BitReg);
1053   } else if (Tok.is(AsmToken::Integer))
1054     RegNum = matchRegisterByNumber(static_cast<unsigned>(Tok.getIntVal()),
1055         is64BitReg ? Mips::GPR64RegClassID : Mips::GPR32RegClassID);
1056   return RegNum;
1057 }
1058
1059 bool MipsAsmParser::tryParseRegisterOperand(
1060              SmallVectorImpl<MCParsedAsmOperand*> &Operands, bool is64BitReg) {
1061
1062   SMLoc S = Parser.getTok().getLoc();
1063   int RegNo = -1;
1064
1065   RegNo = tryParseRegister(is64BitReg);
1066   if (RegNo == -1)
1067     return true;
1068
1069   Operands.push_back(MipsOperand::CreateReg(RegNo, S,
1070                                             Parser.getTok().getLoc()));
1071   Parser.Lex(); // Eat register token.
1072   return false;
1073 }
1074
1075 bool MipsAsmParser::ParseOperand(SmallVectorImpl<MCParsedAsmOperand*>&Operands,
1076                                  StringRef Mnemonic) {
1077   // Check if the current operand has a custom associated parser, if so, try to
1078   // custom parse the operand, or fallback to the general approach.
1079   OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
1080   if (ResTy == MatchOperand_Success)
1081     return false;
1082   // If there wasn't a custom match, try the generic matcher below. Otherwise,
1083   // there was a match, but an error occurred, in which case, just return that
1084   // the operand parsing failed.
1085   if (ResTy == MatchOperand_ParseFail)
1086     return true;
1087
1088   switch (getLexer().getKind()) {
1089   default:
1090     Error(Parser.getTok().getLoc(), "unexpected token in operand");
1091     return true;
1092   case AsmToken::Dollar: {
1093     // Parse the register.
1094     SMLoc S = Parser.getTok().getLoc();
1095     Parser.Lex(); // Eat dollar token.
1096     // Parse the register operand.
1097     if (!tryParseRegisterOperand(Operands, isMips64())) {
1098       if (getLexer().is(AsmToken::LParen)) {
1099         // Check if it is indexed addressing operand.
1100         Operands.push_back(MipsOperand::CreateToken("(", S));
1101         Parser.Lex(); // Eat the parenthesis.
1102         if (getLexer().isNot(AsmToken::Dollar))
1103           return true;
1104
1105         Parser.Lex(); // Eat the dollar
1106         if (tryParseRegisterOperand(Operands, isMips64()))
1107           return true;
1108
1109         if (!getLexer().is(AsmToken::RParen))
1110           return true;
1111
1112         S = Parser.getTok().getLoc();
1113         Operands.push_back(MipsOperand::CreateToken(")", S));
1114         Parser.Lex();
1115       }
1116       return false;
1117     }
1118     // Maybe it is a symbol reference.
1119     StringRef Identifier;
1120     if (Parser.parseIdentifier(Identifier))
1121       return true;
1122
1123     SMLoc E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
1124
1125     MCSymbol *Sym = getContext().GetOrCreateSymbol("$" + Identifier);
1126
1127     // Otherwise create a symbol reference.
1128     const MCExpr *Res = MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_None,
1129                                                 getContext());
1130
1131     Operands.push_back(MipsOperand::CreateImm(Res, S, E));
1132     return false;
1133   }
1134   case AsmToken::Identifier:
1135     // Look for the existing symbol, we should check if
1136     // we need to assigne the propper RegisterKind.
1137     if (searchSymbolAlias(Operands, MipsOperand::Kind_None))
1138       return false;
1139     // Else drop to expression parsing.
1140   case AsmToken::LParen:
1141   case AsmToken::Minus:
1142   case AsmToken::Plus:
1143   case AsmToken::Integer:
1144   case AsmToken::String: {
1145     // Quoted label names.
1146     const MCExpr *IdVal;
1147     SMLoc S = Parser.getTok().getLoc();
1148     if (getParser().parseExpression(IdVal))
1149       return true;
1150     SMLoc E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
1151     Operands.push_back(MipsOperand::CreateImm(IdVal, S, E));
1152     return false;
1153   }
1154   case AsmToken::Percent: {
1155     // It is a symbol reference or constant expression.
1156     const MCExpr *IdVal;
1157     SMLoc S = Parser.getTok().getLoc(); // Start location of the operand.
1158     if (parseRelocOperand(IdVal))
1159       return true;
1160
1161     SMLoc E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
1162
1163     Operands.push_back(MipsOperand::CreateImm(IdVal, S, E));
1164     return false;
1165   } // case AsmToken::Percent
1166   } // switch(getLexer().getKind())
1167   return true;
1168 }
1169
1170 const MCExpr* MipsAsmParser::evaluateRelocExpr(const MCExpr *Expr,
1171                                                StringRef RelocStr) {
1172   const MCExpr *Res;
1173   // Check the type of the expression.
1174   if (const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(Expr)) {
1175     // It's a constant, evaluate lo or hi value.
1176     if (RelocStr == "lo") {
1177       short Val = MCE->getValue();
1178       Res = MCConstantExpr::Create(Val, getContext());
1179     } else if (RelocStr == "hi") {
1180       int Val = MCE->getValue();
1181       int LoSign = Val & 0x8000;
1182       Val = (Val & 0xffff0000) >> 16;
1183       // Lower part is treated as a signed int, so if it is negative
1184       // we must add 1 to the hi part to compensate.
1185       if (LoSign)
1186         Val++;
1187       Res = MCConstantExpr::Create(Val, getContext());
1188     } else {
1189       llvm_unreachable("Invalid RelocStr value");
1190     }
1191     return Res;
1192   }
1193
1194   if (const MCSymbolRefExpr *MSRE = dyn_cast<MCSymbolRefExpr>(Expr)) {
1195     // It's a symbol, create a symbolic expression from the symbol.
1196     StringRef Symbol = MSRE->getSymbol().getName();
1197     MCSymbolRefExpr::VariantKind VK = getVariantKind(RelocStr);
1198     Res = MCSymbolRefExpr::Create(Symbol, VK, getContext());
1199     return Res;
1200   }
1201
1202   if (const MCBinaryExpr *BE = dyn_cast<MCBinaryExpr>(Expr)) {
1203     const MCExpr *LExp = evaluateRelocExpr(BE->getLHS(), RelocStr);
1204     const MCExpr *RExp = evaluateRelocExpr(BE->getRHS(), RelocStr);
1205     Res = MCBinaryExpr::Create(BE->getOpcode(), LExp, RExp, getContext());
1206     return Res;
1207   }
1208
1209   if (const MCUnaryExpr *UN = dyn_cast<MCUnaryExpr>(Expr)) {
1210     const MCExpr *UnExp = evaluateRelocExpr(UN->getSubExpr(), RelocStr);
1211     Res = MCUnaryExpr::Create(UN->getOpcode(), UnExp, getContext());
1212     return Res;
1213   }
1214   // Just return the original expression.
1215   return Expr;
1216 }
1217
1218 bool MipsAsmParser::isEvaluated(const MCExpr *Expr) {
1219
1220   switch (Expr->getKind()) {
1221   case MCExpr::Constant:
1222     return true;
1223   case MCExpr::SymbolRef:
1224     return (cast<MCSymbolRefExpr>(Expr)->getKind() != MCSymbolRefExpr::VK_None);
1225   case MCExpr::Binary:
1226     if (const MCBinaryExpr *BE = dyn_cast<MCBinaryExpr>(Expr)) {
1227       if (!isEvaluated(BE->getLHS()))
1228         return false;
1229       return isEvaluated(BE->getRHS());
1230     }
1231   case MCExpr::Unary:
1232     return isEvaluated(cast<MCUnaryExpr>(Expr)->getSubExpr());
1233   default:
1234     return false;
1235   }
1236   return false;
1237 }
1238
1239 bool MipsAsmParser::parseRelocOperand(const MCExpr *&Res) {
1240   Parser.Lex(); // Eat the % token.
1241   const AsmToken &Tok = Parser.getTok(); // Get next token, operation.
1242   if (Tok.isNot(AsmToken::Identifier))
1243     return true;
1244
1245   std::string Str = Tok.getIdentifier().str();
1246
1247   Parser.Lex(); // Eat the identifier.
1248   // Now make an expression from the rest of the operand.
1249   const MCExpr *IdVal;
1250   SMLoc EndLoc;
1251
1252   if (getLexer().getKind() == AsmToken::LParen) {
1253     while (1) {
1254       Parser.Lex(); // Eat the '(' token.
1255       if (getLexer().getKind() == AsmToken::Percent) {
1256         Parser.Lex(); // Eat the % token.
1257         const AsmToken &nextTok = Parser.getTok();
1258         if (nextTok.isNot(AsmToken::Identifier))
1259           return true;
1260         Str += "(%";
1261         Str += nextTok.getIdentifier();
1262         Parser.Lex(); // Eat the identifier.
1263         if (getLexer().getKind() != AsmToken::LParen)
1264           return true;
1265       } else
1266         break;
1267     }
1268     if (getParser().parseParenExpression(IdVal, EndLoc))
1269       return true;
1270
1271     while (getLexer().getKind() == AsmToken::RParen)
1272       Parser.Lex(); // Eat the ')' token.
1273
1274   } else
1275     return true; // Parenthesis must follow the relocation operand.
1276
1277   Res = evaluateRelocExpr(IdVal, Str);
1278   return false;
1279 }
1280
1281 bool MipsAsmParser::ParseRegister(unsigned &RegNo, SMLoc &StartLoc,
1282                                   SMLoc &EndLoc) {
1283   StartLoc = Parser.getTok().getLoc();
1284   RegNo = tryParseRegister(isMips64());
1285   EndLoc = Parser.getTok().getLoc();
1286   return (RegNo == (unsigned) -1);
1287 }
1288
1289 bool MipsAsmParser::parseMemOffset(const MCExpr *&Res, bool isParenExpr) {
1290   SMLoc S;
1291   bool Result = true;
1292
1293   while (getLexer().getKind() == AsmToken::LParen)
1294     Parser.Lex();
1295
1296   switch (getLexer().getKind()) {
1297   default:
1298     return true;
1299   case AsmToken::Identifier:
1300   case AsmToken::LParen:
1301   case AsmToken::Integer:
1302   case AsmToken::Minus:
1303   case AsmToken::Plus:
1304     if (isParenExpr)
1305       Result = getParser().parseParenExpression(Res, S);
1306     else
1307       Result = (getParser().parseExpression(Res));
1308     while (getLexer().getKind() == AsmToken::RParen)
1309       Parser.Lex();
1310     break;
1311   case AsmToken::Percent:
1312     Result = parseRelocOperand(Res);
1313   }
1314   return Result;
1315 }
1316
1317 MipsAsmParser::OperandMatchResultTy MipsAsmParser::parseMemOperand(
1318                                SmallVectorImpl<MCParsedAsmOperand*>&Operands) {
1319
1320   const MCExpr *IdVal = 0;
1321   SMLoc S;
1322   bool isParenExpr = false;
1323   MipsAsmParser::OperandMatchResultTy Res = MatchOperand_NoMatch;
1324   // First operand is the offset.
1325   S = Parser.getTok().getLoc();
1326
1327   if (getLexer().getKind() == AsmToken::LParen) {
1328     Parser.Lex();
1329     isParenExpr = true;
1330   }
1331
1332   if (getLexer().getKind() != AsmToken::Dollar) {
1333     if (parseMemOffset(IdVal, isParenExpr))
1334       return MatchOperand_ParseFail;
1335
1336     const AsmToken &Tok = Parser.getTok(); // Get the next token.
1337     if (Tok.isNot(AsmToken::LParen)) {
1338       MipsOperand *Mnemonic = static_cast<MipsOperand*>(Operands[0]);
1339       if (Mnemonic->getToken() == "la") {
1340         SMLoc E = SMLoc::getFromPointer(
1341             Parser.getTok().getLoc().getPointer() - 1);
1342         Operands.push_back(MipsOperand::CreateImm(IdVal, S, E));
1343         return MatchOperand_Success;
1344       }
1345       if (Tok.is(AsmToken::EndOfStatement)) {
1346         SMLoc E = SMLoc::getFromPointer(
1347             Parser.getTok().getLoc().getPointer() - 1);
1348
1349         // Zero register assumed, add a memory operand with ZERO as its base.
1350         Operands.push_back(MipsOperand::CreateMem(isMips64() ? Mips::ZERO_64
1351                                                              : Mips::ZERO,
1352                            IdVal, S, E));
1353         return MatchOperand_Success;
1354       }
1355       Error(Parser.getTok().getLoc(), "'(' expected");
1356       return MatchOperand_ParseFail;
1357     }
1358
1359     Parser.Lex(); // Eat the '(' token.
1360   }
1361
1362   Res = parseRegs(Operands, isMips64()? (int) MipsOperand::Kind_GPR64:
1363                                         (int) MipsOperand::Kind_GPR32);
1364   if (Res != MatchOperand_Success)
1365     return Res;
1366
1367   if (Parser.getTok().isNot(AsmToken::RParen)) {
1368     Error(Parser.getTok().getLoc(), "')' expected");
1369     return MatchOperand_ParseFail;
1370   }
1371
1372   SMLoc E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
1373
1374   Parser.Lex(); // Eat the ')' token.
1375
1376   if (IdVal == 0)
1377     IdVal = MCConstantExpr::Create(0, getContext());
1378
1379   // Replace the register operand with the memory operand.
1380   MipsOperand* op = static_cast<MipsOperand*>(Operands.back());
1381   int RegNo = op->getReg();
1382   // Remove the register from the operands.
1383   Operands.pop_back();
1384   // Add the memory operand.
1385   if (const MCBinaryExpr *BE = dyn_cast<MCBinaryExpr>(IdVal)) {
1386     int64_t Imm;
1387     if (IdVal->EvaluateAsAbsolute(Imm))
1388       IdVal = MCConstantExpr::Create(Imm, getContext());
1389     else if (BE->getLHS()->getKind() != MCExpr::SymbolRef)
1390       IdVal = MCBinaryExpr::Create(BE->getOpcode(), BE->getRHS(), BE->getLHS(),
1391                                    getContext());
1392   }
1393
1394   Operands.push_back(MipsOperand::CreateMem(RegNo, IdVal, S, E));
1395   delete op;
1396   return MatchOperand_Success;
1397 }
1398
1399 bool
1400 MipsAsmParser::parsePtrReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
1401                            int RegKind) {
1402   // If the first token is not '$' we have an error.
1403   if (Parser.getTok().isNot(AsmToken::Dollar))
1404     return false;
1405
1406   SMLoc S = Parser.getTok().getLoc();
1407   Parser.Lex();
1408   AsmToken::TokenKind TkKind = getLexer().getKind();
1409   int Reg;
1410
1411   if (TkKind == AsmToken::Integer) {
1412     Reg = matchRegisterByNumber(Parser.getTok().getIntVal(),
1413                                 regKindToRegClass(RegKind));
1414     if (Reg == -1)
1415       return false;
1416   } else if (TkKind == AsmToken::Identifier) {
1417     if ((Reg = matchCPURegisterName(Parser.getTok().getString().lower())) == -1)
1418       return false;
1419     Reg = getReg(regKindToRegClass(RegKind), Reg);
1420   } else {
1421     return false;
1422   }
1423
1424   MipsOperand *Op = MipsOperand::CreatePtrReg(Reg, S, Parser.getTok().getLoc());
1425   Op->setRegKind((MipsOperand::RegisterKind)RegKind);
1426   Operands.push_back(Op);
1427   Parser.Lex();
1428   return true;
1429 }
1430
1431 MipsAsmParser::OperandMatchResultTy
1432 MipsAsmParser::parsePtrReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
1433   MipsOperand::RegisterKind RegKind = isN64() ? MipsOperand::Kind_GPR64 :
1434                                                 MipsOperand::Kind_GPR32;
1435
1436   // Parse index register.
1437   if (!parsePtrReg(Operands, RegKind))
1438     return MatchOperand_NoMatch;
1439
1440   // Parse '('.
1441   if (Parser.getTok().isNot(AsmToken::LParen))
1442     return MatchOperand_NoMatch;
1443
1444   Operands.push_back(MipsOperand::CreateToken("(", getLexer().getLoc()));
1445   Parser.Lex();
1446
1447   // Parse base register.
1448   if (!parsePtrReg(Operands, RegKind))
1449     return MatchOperand_NoMatch;
1450
1451   // Parse ')'.
1452   if (Parser.getTok().isNot(AsmToken::RParen))
1453     return MatchOperand_NoMatch;
1454
1455   Operands.push_back(MipsOperand::CreateToken(")", getLexer().getLoc()));
1456   Parser.Lex();
1457
1458   return MatchOperand_Success;
1459 }
1460
1461 MipsAsmParser::OperandMatchResultTy
1462 MipsAsmParser::parseRegs(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
1463                          int RegKind) {
1464   MipsOperand::RegisterKind Kind = (MipsOperand::RegisterKind)RegKind;
1465   if (getLexer().getKind() == AsmToken::Identifier
1466        && !hasConsumedDollar) {
1467     if (searchSymbolAlias(Operands, Kind))
1468       return MatchOperand_Success;
1469     return MatchOperand_NoMatch;
1470   }
1471   SMLoc S = Parser.getTok().getLoc();
1472   // If the first token is not '$', we have an error.
1473   if (Parser.getTok().isNot(AsmToken::Dollar) && !hasConsumedDollar)
1474     return MatchOperand_NoMatch;
1475   if (!hasConsumedDollar) {
1476     Parser.Lex(); // Eat the '$'
1477     hasConsumedDollar = true;
1478   }
1479   if (getLexer().getKind() == AsmToken::Identifier) {
1480     int RegNum = -1;
1481     std::string RegName = Parser.getTok().getString().lower();
1482   // Match register by name
1483     switch (RegKind) {
1484     case MipsOperand::Kind_GPR32:
1485     case MipsOperand::Kind_GPR64:
1486       RegNum = matchCPURegisterName(RegName);
1487       break;
1488     case MipsOperand::Kind_AFGR64Regs:
1489     case MipsOperand::Kind_FGR64Regs:
1490     case MipsOperand::Kind_FGR32Regs:
1491     case MipsOperand::Kind_FGRH32Regs:
1492       RegNum = matchFPURegisterName(RegName);
1493       if (RegKind == MipsOperand::Kind_AFGR64Regs)
1494         RegNum /= 2;
1495       else if (RegKind == MipsOperand::Kind_FGRH32Regs
1496                && !isFP64())
1497         if (RegNum != -1 && RegNum %2 != 0)
1498           Warning(S, "Float register should be even.");
1499       break;
1500     case MipsOperand::Kind_FCCRegs:
1501       RegNum = matchFCCRegisterName(RegName);
1502       break;
1503     case MipsOperand::Kind_ACC64DSP:
1504       RegNum = matchACRegisterName(RegName);
1505       break;
1506     default: break; // No match, value is set to -1.
1507     }
1508     // No match found, return _NoMatch to give a chance to other round.
1509     if (RegNum < 0)
1510       return MatchOperand_NoMatch;
1511
1512     int RegVal = getReg(regKindToRegClass(Kind), RegNum);
1513     if (RegVal == -1)
1514       return MatchOperand_NoMatch;
1515
1516     MipsOperand *Op = MipsOperand::CreateReg(RegVal, S,
1517                                              Parser.getTok().getLoc());
1518     Op->setRegKind(Kind);
1519     Operands.push_back(Op);
1520     hasConsumedDollar = false;
1521     Parser.Lex(); // Eat the register name.
1522     return MatchOperand_Success;
1523   } else if (getLexer().getKind() == AsmToken::Integer) {
1524     unsigned RegNum = Parser.getTok().getIntVal();
1525     if (Kind == MipsOperand::Kind_HWRegs) {
1526       if (RegNum != 29)
1527         return MatchOperand_NoMatch;
1528       // Only hwreg 29 is supported, found at index 0.
1529       RegNum = 0;
1530     }
1531     int Reg = matchRegisterByNumber(RegNum, regKindToRegClass(Kind));
1532     if (Reg == -1)
1533       return MatchOperand_NoMatch;
1534     MipsOperand *Op = MipsOperand::CreateReg(Reg, S, Parser.getTok().getLoc());
1535     Op->setRegKind(Kind);
1536     Operands.push_back(Op);
1537     hasConsumedDollar = false;
1538     Parser.Lex(); // Eat the register number.
1539         if ((RegKind == MipsOperand::Kind_GPR32)
1540       && (getLexer().is(AsmToken::LParen))) {
1541       // Check if it is indexed addressing operand.
1542       Operands.push_back(MipsOperand::CreateToken("(", getLexer().getLoc()));
1543       Parser.Lex(); // Eat the parenthesis.
1544       if (parseRegs(Operands,RegKind) != MatchOperand_Success)
1545         return MatchOperand_NoMatch;
1546       if (getLexer().isNot(AsmToken::RParen))
1547         return MatchOperand_NoMatch;
1548       Operands.push_back(MipsOperand::CreateToken(")", getLexer().getLoc()));
1549       Parser.Lex();
1550     }
1551     return MatchOperand_Success;
1552   }
1553   return MatchOperand_NoMatch;
1554 }
1555
1556 bool MipsAsmParser::validateMSAIndex(int Val, int RegKind) {
1557   MipsOperand::RegisterKind Kind = (MipsOperand::RegisterKind)RegKind;
1558
1559   if (Val < 0)
1560     return false;
1561
1562   switch (Kind) {
1563   default:
1564     return false;
1565   case MipsOperand::Kind_MSA128BRegs:
1566     return Val < 16;
1567   case MipsOperand::Kind_MSA128HRegs:
1568     return Val < 8;
1569   case MipsOperand::Kind_MSA128WRegs:
1570     return Val < 4;
1571   case MipsOperand::Kind_MSA128DRegs:
1572     return Val < 2;
1573   }
1574 }
1575
1576 MipsAsmParser::OperandMatchResultTy
1577 MipsAsmParser::parseMSARegs(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
1578                             int RegKind) {
1579   MipsOperand::RegisterKind Kind = (MipsOperand::RegisterKind)RegKind;
1580   SMLoc S = Parser.getTok().getLoc();
1581   std::string RegName;
1582
1583   if (Parser.getTok().isNot(AsmToken::Dollar))
1584     return MatchOperand_NoMatch;
1585
1586   switch (RegKind) {
1587   default:
1588     return MatchOperand_ParseFail;
1589   case MipsOperand::Kind_MSA128BRegs:
1590   case MipsOperand::Kind_MSA128HRegs:
1591   case MipsOperand::Kind_MSA128WRegs:
1592   case MipsOperand::Kind_MSA128DRegs:
1593     break;
1594   }
1595
1596   Parser.Lex(); // Eat the '$'.
1597   if (getLexer().getKind() == AsmToken::Identifier)
1598     RegName = Parser.getTok().getString().lower();
1599   else
1600     return MatchOperand_ParseFail;
1601
1602   int RegNum = matchMSA128RegisterName(RegName);
1603
1604   if (RegNum < 0 || RegNum > 31)
1605     return MatchOperand_ParseFail;
1606
1607   int RegVal = getReg(regKindToRegClass(Kind), RegNum);
1608   if (RegVal == -1)
1609     return MatchOperand_ParseFail;
1610
1611   MipsOperand *Op = MipsOperand::CreateReg(RegVal, S,
1612                                            Parser.getTok().getLoc());
1613   Op->setRegKind(Kind);
1614   Operands.push_back(Op);
1615
1616   Parser.Lex(); // Eat the register identifier.
1617
1618   // MSA registers may be suffixed with an index in the form of:
1619   // 1) Immediate expression.
1620   // 2) General Purpose Register.
1621   // Examples:
1622   //   1) copy_s.b $29,$w0[0]
1623   //   2) sld.b $w0,$w1[$1]
1624
1625   if (Parser.getTok().isNot(AsmToken::LBrac))
1626     return MatchOperand_Success;
1627
1628   MipsOperand *Mnemonic = static_cast<MipsOperand *>(Operands[0]);
1629
1630   Operands.push_back(MipsOperand::CreateToken("[", Parser.getTok().getLoc()));
1631   Parser.Lex(); // Parse the '[' token.
1632
1633   if (Parser.getTok().is(AsmToken::Dollar)) {
1634     // This must be a GPR.
1635     MipsOperand *RegOp;
1636     SMLoc VIdx = Parser.getTok().getLoc();
1637     Parser.Lex(); // Parse the '$' token.
1638
1639     // GPR have aliases and we must account for that. Example: $30 == $fp
1640     if (getLexer().getKind() == AsmToken::Integer) {
1641       unsigned RegNum = Parser.getTok().getIntVal();
1642       int Reg = matchRegisterByNumber(
1643           RegNum, regKindToRegClass(MipsOperand::Kind_GPR32));
1644       if (Reg == -1) {
1645         Error(VIdx, "invalid general purpose register");
1646         return MatchOperand_ParseFail;
1647       }
1648
1649       RegOp = MipsOperand::CreateReg(Reg, VIdx, Parser.getTok().getLoc());
1650     } else if (getLexer().getKind() == AsmToken::Identifier) {
1651       int RegNum = -1;
1652       std::string RegName = Parser.getTok().getString().lower();
1653
1654       RegNum = matchCPURegisterName(RegName);
1655       if (RegNum == -1) {
1656         Error(VIdx, "general purpose register expected");
1657         return MatchOperand_ParseFail;
1658       }
1659       RegNum = getReg(regKindToRegClass(MipsOperand::Kind_GPR32), RegNum);
1660       RegOp = MipsOperand::CreateReg(RegNum, VIdx, Parser.getTok().getLoc());
1661     }
1662
1663     RegOp->setRegKind(MipsOperand::Kind_GPR32);
1664     Operands.push_back(RegOp);
1665     Parser.Lex(); // Eat the register identifier.
1666
1667     if (Parser.getTok().isNot(AsmToken::RBrac))
1668       return MatchOperand_ParseFail;
1669
1670     Operands.push_back(MipsOperand::CreateToken("]", Parser.getTok().getLoc()));
1671     Parser.Lex(); // Parse the ']' token.
1672
1673     return MatchOperand_Success;
1674   }
1675
1676   // The index must be a constant expression then.
1677   SMLoc VIdx = Parser.getTok().getLoc();
1678   const MCExpr *ImmVal;
1679
1680   if (getParser().parseExpression(ImmVal))
1681     return MatchOperand_ParseFail;
1682
1683   const MCConstantExpr *expr = dyn_cast<MCConstantExpr>(ImmVal);
1684   if (!expr || !validateMSAIndex((int)expr->getValue(), Kind)) {
1685     Error(VIdx, "invalid immediate value");
1686     return MatchOperand_ParseFail;
1687   }
1688
1689   SMLoc E = Parser.getTok().getEndLoc();
1690
1691   if (Parser.getTok().isNot(AsmToken::RBrac))
1692     return MatchOperand_ParseFail;
1693
1694   bool insve = Mnemonic->getToken() == "insve.b" ||
1695                Mnemonic->getToken() == "insve.h" ||
1696                Mnemonic->getToken() == "insve.w" ||
1697                Mnemonic->getToken() == "insve.d";
1698
1699   // The second vector index of insve instructions is always 0.
1700   if (insve && Operands.size() > 6) {
1701     if (expr->getValue() != 0) {
1702       Error(VIdx, "immediate value must be 0");
1703       return MatchOperand_ParseFail;
1704     }
1705     Operands.push_back(MipsOperand::CreateToken("0", VIdx));
1706   } else
1707     Operands.push_back(MipsOperand::CreateImm(expr, VIdx, E));
1708
1709   Operands.push_back(MipsOperand::CreateToken("]", Parser.getTok().getLoc()));
1710
1711   Parser.Lex(); // Parse the ']' token.
1712
1713   return MatchOperand_Success;
1714 }
1715
1716 MipsAsmParser::OperandMatchResultTy
1717 MipsAsmParser::parseGPR64(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
1718
1719   if (!isMips64())
1720     return MatchOperand_NoMatch;
1721   return parseRegs(Operands, (int) MipsOperand::Kind_GPR64);
1722 }
1723
1724 MipsAsmParser::OperandMatchResultTy
1725 MipsAsmParser::parseGPR32(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
1726  return parseRegs(Operands, (int) MipsOperand::Kind_GPR32);
1727 }
1728
1729 MipsAsmParser::OperandMatchResultTy
1730 MipsAsmParser::parseAFGR64Regs(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
1731
1732   if (isFP64())
1733     return MatchOperand_NoMatch;
1734   return parseRegs(Operands, (int) MipsOperand::Kind_AFGR64Regs);
1735 }
1736
1737 MipsAsmParser::OperandMatchResultTy
1738 MipsAsmParser::parseFGR64Regs(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
1739   if (!isFP64())
1740     return MatchOperand_NoMatch;
1741  return parseRegs(Operands, (int) MipsOperand::Kind_FGR64Regs);
1742 }
1743
1744 MipsAsmParser::OperandMatchResultTy
1745 MipsAsmParser::parseFGR32Regs(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
1746   return parseRegs(Operands, (int) MipsOperand::Kind_FGR32Regs);
1747 }
1748
1749 MipsAsmParser::OperandMatchResultTy
1750 MipsAsmParser::parseFGRH32Regs(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
1751   return parseRegs(Operands, (int) MipsOperand::Kind_FGRH32Regs);
1752 }
1753
1754 MipsAsmParser::OperandMatchResultTy
1755 MipsAsmParser::parseFCCRegs(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
1756   return parseRegs(Operands, (int) MipsOperand::Kind_FCCRegs);
1757 }
1758
1759 MipsAsmParser::OperandMatchResultTy
1760 MipsAsmParser::parseACC64DSP(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
1761   return parseRegs(Operands, (int) MipsOperand::Kind_ACC64DSP);
1762 }
1763
1764 MipsAsmParser::OperandMatchResultTy
1765 MipsAsmParser::parseLO32DSP(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
1766   // If the first token is not '$' we have an error.
1767   if (Parser.getTok().isNot(AsmToken::Dollar))
1768     return MatchOperand_NoMatch;
1769
1770   SMLoc S = Parser.getTok().getLoc();
1771   Parser.Lex(); // Eat the '$'
1772
1773   const AsmToken &Tok = Parser.getTok(); // Get next token.
1774
1775   if (Tok.isNot(AsmToken::Identifier))
1776     return MatchOperand_NoMatch;
1777
1778   if (!Tok.getIdentifier().startswith("ac"))
1779     return MatchOperand_NoMatch;
1780
1781   StringRef NumString = Tok.getIdentifier().substr(2);
1782
1783   unsigned IntVal;
1784   if (NumString.getAsInteger(10, IntVal))
1785     return MatchOperand_NoMatch;
1786
1787   unsigned Reg = matchRegisterByNumber(IntVal, Mips::LO32DSPRegClassID);
1788
1789   MipsOperand *Op = MipsOperand::CreateReg(Reg, S, Parser.getTok().getLoc());
1790   Op->setRegKind(MipsOperand::Kind_LO32DSP);
1791   Operands.push_back(Op);
1792
1793   Parser.Lex(); // Eat the register number.
1794   return MatchOperand_Success;
1795 }
1796
1797 MipsAsmParser::OperandMatchResultTy
1798 MipsAsmParser::parseHI32DSP(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
1799   // If the first token is not '$' we have an error.
1800   if (Parser.getTok().isNot(AsmToken::Dollar))
1801     return MatchOperand_NoMatch;
1802
1803   SMLoc S = Parser.getTok().getLoc();
1804   Parser.Lex(); // Eat the '$'
1805
1806   const AsmToken &Tok = Parser.getTok(); // Get next token.
1807
1808   if (Tok.isNot(AsmToken::Identifier))
1809     return MatchOperand_NoMatch;
1810
1811   if (!Tok.getIdentifier().startswith("ac"))
1812     return MatchOperand_NoMatch;
1813
1814   StringRef NumString = Tok.getIdentifier().substr(2);
1815
1816   unsigned IntVal;
1817   if (NumString.getAsInteger(10, IntVal))
1818     return MatchOperand_NoMatch;
1819
1820   unsigned Reg = matchRegisterByNumber(IntVal, Mips::HI32DSPRegClassID);
1821
1822   MipsOperand *Op = MipsOperand::CreateReg(Reg, S, Parser.getTok().getLoc());
1823   Op->setRegKind(MipsOperand::Kind_HI32DSP);
1824   Operands.push_back(Op);
1825
1826   Parser.Lex(); // Eat the register number.
1827   return MatchOperand_Success;
1828 }
1829
1830 MipsAsmParser::OperandMatchResultTy
1831 MipsAsmParser::parseCOP2(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
1832   // If the first token is not '$' we have an error.
1833   if (Parser.getTok().isNot(AsmToken::Dollar))
1834     return MatchOperand_NoMatch;
1835
1836   SMLoc S = Parser.getTok().getLoc();
1837   Parser.Lex(); // Eat the '$'
1838
1839   const AsmToken &Tok = Parser.getTok(); // Get next token.
1840
1841   if (Tok.isNot(AsmToken::Integer))
1842     return MatchOperand_NoMatch;
1843
1844   unsigned IntVal = Tok.getIntVal();
1845
1846   unsigned Reg = matchRegisterByNumber(IntVal, Mips::COP2RegClassID);
1847
1848   MipsOperand *Op = MipsOperand::CreateReg(Reg, S, Parser.getTok().getLoc());
1849   Op->setRegKind(MipsOperand::Kind_COP2);
1850   Operands.push_back(Op);
1851
1852   Parser.Lex(); // Eat the register number.
1853   return MatchOperand_Success;
1854 }
1855
1856 MipsAsmParser::OperandMatchResultTy
1857 MipsAsmParser::parseMSA128BRegs(
1858                               SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
1859   return parseMSARegs(Operands, (int) MipsOperand::Kind_MSA128BRegs);
1860 }
1861
1862 MipsAsmParser::OperandMatchResultTy
1863 MipsAsmParser::parseMSA128HRegs(
1864                               SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
1865   return parseMSARegs(Operands, (int) MipsOperand::Kind_MSA128HRegs);
1866 }
1867
1868 MipsAsmParser::OperandMatchResultTy
1869 MipsAsmParser::parseMSA128WRegs(
1870                               SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
1871   return parseMSARegs(Operands, (int) MipsOperand::Kind_MSA128WRegs);
1872 }
1873
1874 MipsAsmParser::OperandMatchResultTy
1875 MipsAsmParser::parseMSA128DRegs(
1876                               SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
1877   return parseMSARegs(Operands, (int) MipsOperand::Kind_MSA128DRegs);
1878 }
1879
1880 bool MipsAsmParser::searchSymbolAlias(
1881     SmallVectorImpl<MCParsedAsmOperand*> &Operands, unsigned RegKind) {
1882
1883   MCSymbol *Sym = getContext().LookupSymbol(Parser.getTok().getIdentifier());
1884   if (Sym) {
1885     SMLoc S = Parser.getTok().getLoc();
1886     const MCExpr *Expr;
1887     if (Sym->isVariable())
1888       Expr = Sym->getVariableValue();
1889     else
1890       return false;
1891     if (Expr->getKind() == MCExpr::SymbolRef) {
1892       MipsOperand::RegisterKind Kind = (MipsOperand::RegisterKind) RegKind;
1893       const MCSymbolRefExpr *Ref = static_cast<const MCSymbolRefExpr*>(Expr);
1894       const StringRef DefSymbol = Ref->getSymbol().getName();
1895       if (DefSymbol.startswith("$")) {
1896         int RegNum = -1;
1897         APInt IntVal(32, -1);
1898         if (!DefSymbol.substr(1).getAsInteger(10, IntVal))
1899           RegNum = matchRegisterByNumber(IntVal.getZExtValue(),
1900                                      isMips64()
1901                                        ? Mips::GPR64RegClassID
1902                                        : Mips::GPR32RegClassID);
1903         else {
1904           // Lookup for the register with the corresponding name.
1905           switch (Kind) {
1906           case MipsOperand::Kind_AFGR64Regs:
1907           case MipsOperand::Kind_FGR64Regs:
1908             RegNum = matchFPURegisterName(DefSymbol.substr(1));
1909             break;
1910           case MipsOperand::Kind_FGR32Regs:
1911             RegNum = matchFPURegisterName(DefSymbol.substr(1));
1912             break;
1913           case MipsOperand::Kind_GPR64:
1914           case MipsOperand::Kind_GPR32:
1915           default:
1916             RegNum = matchCPURegisterName(DefSymbol.substr(1));
1917             break;
1918           }
1919           if (RegNum > -1)
1920             RegNum = getReg(regKindToRegClass(Kind), RegNum);
1921         }
1922         if (RegNum > -1) {
1923           Parser.Lex();
1924           MipsOperand *op = MipsOperand::CreateReg(RegNum, S,
1925                                                    Parser.getTok().getLoc());
1926           op->setRegKind(Kind);
1927           Operands.push_back(op);
1928           return true;
1929         }
1930       }
1931     } else if (Expr->getKind() == MCExpr::Constant) {
1932       Parser.Lex();
1933       const MCConstantExpr *Const = static_cast<const MCConstantExpr*>(Expr);
1934       MipsOperand *op = MipsOperand::CreateImm(Const, S,
1935           Parser.getTok().getLoc());
1936       Operands.push_back(op);
1937       return true;
1938     }
1939   }
1940   return false;
1941 }
1942
1943 MipsAsmParser::OperandMatchResultTy
1944 MipsAsmParser::parseHWRegs(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
1945   return parseRegs(Operands, (int) MipsOperand::Kind_HWRegs);
1946 }
1947
1948 MipsAsmParser::OperandMatchResultTy
1949 MipsAsmParser::parseCCRRegs(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
1950   return parseRegs(Operands, (int) MipsOperand::Kind_CCRRegs);
1951 }
1952
1953 MipsAsmParser::OperandMatchResultTy
1954 MipsAsmParser::parseInvNum(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
1955   const MCExpr *IdVal;
1956   // If the first token is '$' we may have register operand.
1957   if (Parser.getTok().is(AsmToken::Dollar))
1958     return MatchOperand_NoMatch;
1959   SMLoc S = Parser.getTok().getLoc();
1960   if (getParser().parseExpression(IdVal))
1961     return MatchOperand_ParseFail;
1962   const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(IdVal);
1963     assert( MCE && "Unexpected MCExpr type.");
1964   int64_t Val = MCE->getValue();
1965   SMLoc E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
1966   Operands.push_back(MipsOperand::CreateImm(
1967                      MCConstantExpr::Create(0 - Val, getContext()), S, E));
1968   return MatchOperand_Success;
1969 }
1970
1971 MCSymbolRefExpr::VariantKind MipsAsmParser::getVariantKind(StringRef Symbol) {
1972
1973   MCSymbolRefExpr::VariantKind VK
1974                    = StringSwitch<MCSymbolRefExpr::VariantKind>(Symbol)
1975     .Case("hi",          MCSymbolRefExpr::VK_Mips_ABS_HI)
1976     .Case("lo",          MCSymbolRefExpr::VK_Mips_ABS_LO)
1977     .Case("gp_rel",      MCSymbolRefExpr::VK_Mips_GPREL)
1978     .Case("call16",      MCSymbolRefExpr::VK_Mips_GOT_CALL)
1979     .Case("got",         MCSymbolRefExpr::VK_Mips_GOT)
1980     .Case("tlsgd",       MCSymbolRefExpr::VK_Mips_TLSGD)
1981     .Case("tlsldm",      MCSymbolRefExpr::VK_Mips_TLSLDM)
1982     .Case("dtprel_hi",   MCSymbolRefExpr::VK_Mips_DTPREL_HI)
1983     .Case("dtprel_lo",   MCSymbolRefExpr::VK_Mips_DTPREL_LO)
1984     .Case("gottprel",    MCSymbolRefExpr::VK_Mips_GOTTPREL)
1985     .Case("tprel_hi",    MCSymbolRefExpr::VK_Mips_TPREL_HI)
1986     .Case("tprel_lo",    MCSymbolRefExpr::VK_Mips_TPREL_LO)
1987     .Case("got_disp",    MCSymbolRefExpr::VK_Mips_GOT_DISP)
1988     .Case("got_page",    MCSymbolRefExpr::VK_Mips_GOT_PAGE)
1989     .Case("got_ofst",    MCSymbolRefExpr::VK_Mips_GOT_OFST)
1990     .Case("hi(%neg(%gp_rel",    MCSymbolRefExpr::VK_Mips_GPOFF_HI)
1991     .Case("lo(%neg(%gp_rel",    MCSymbolRefExpr::VK_Mips_GPOFF_LO)
1992     .Default(MCSymbolRefExpr::VK_None);
1993
1994   return VK;
1995 }
1996
1997 bool MipsAsmParser::
1998 ParseInstruction(ParseInstructionInfo &Info, StringRef Name, SMLoc NameLoc,
1999                  SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2000   // Check if we have valid mnemonic
2001   if (!mnemonicIsValid(Name, 0)) {
2002     Parser.eatToEndOfStatement();
2003     return Error(NameLoc, "Unknown instruction");
2004   }
2005   // First operand in MCInst is instruction mnemonic.
2006   Operands.push_back(MipsOperand::CreateToken(Name, NameLoc));
2007
2008   // Read the remaining operands.
2009   if (getLexer().isNot(AsmToken::EndOfStatement)) {
2010     // Read the first operand.
2011     if (ParseOperand(Operands, Name)) {
2012       SMLoc Loc = getLexer().getLoc();
2013       Parser.eatToEndOfStatement();
2014       return Error(Loc, "unexpected token in argument list");
2015     }
2016
2017     while (getLexer().is(AsmToken::Comma)) {
2018       Parser.Lex(); // Eat the comma.
2019       // Parse and remember the operand.
2020       if (ParseOperand(Operands, Name)) {
2021         SMLoc Loc = getLexer().getLoc();
2022         Parser.eatToEndOfStatement();
2023         return Error(Loc, "unexpected token in argument list");
2024       }
2025     }
2026   }
2027   if (getLexer().isNot(AsmToken::EndOfStatement)) {
2028     SMLoc Loc = getLexer().getLoc();
2029     Parser.eatToEndOfStatement();
2030     return Error(Loc, "unexpected token in argument list");
2031   }
2032   Parser.Lex(); // Consume the EndOfStatement.
2033   return false;
2034 }
2035
2036 bool MipsAsmParser::reportParseError(StringRef ErrorMsg) {
2037   SMLoc Loc = getLexer().getLoc();
2038   Parser.eatToEndOfStatement();
2039   return Error(Loc, ErrorMsg);
2040 }
2041
2042 bool MipsAsmParser::parseSetNoAtDirective() {
2043   // Line should look like: ".set noat".
2044   // set at reg to 0.
2045   Options.setATReg(0);
2046   // eat noat
2047   Parser.Lex();
2048   // If this is not the end of the statement, report an error.
2049   if (getLexer().isNot(AsmToken::EndOfStatement)) {
2050     reportParseError("unexpected token in statement");
2051     return false;
2052   }
2053   Parser.Lex(); // Consume the EndOfStatement.
2054   return false;
2055 }
2056
2057 bool MipsAsmParser::parseSetAtDirective() {
2058   // Line can be .set at - defaults to $1
2059   // or .set at=$reg
2060   int AtRegNo;
2061   getParser().Lex();
2062   if (getLexer().is(AsmToken::EndOfStatement)) {
2063     Options.setATReg(1);
2064     Parser.Lex(); // Consume the EndOfStatement.
2065     return false;
2066   } else if (getLexer().is(AsmToken::Equal)) {
2067     getParser().Lex(); // Eat the '='.
2068     if (getLexer().isNot(AsmToken::Dollar)) {
2069       reportParseError("unexpected token in statement");
2070       return false;
2071     }
2072     Parser.Lex(); // Eat the '$'.
2073     const AsmToken &Reg = Parser.getTok();
2074     if (Reg.is(AsmToken::Identifier)) {
2075       AtRegNo = matchCPURegisterName(Reg.getIdentifier());
2076     } else if (Reg.is(AsmToken::Integer)) {
2077       AtRegNo = Reg.getIntVal();
2078     } else {
2079       reportParseError("unexpected token in statement");
2080       return false;
2081     }
2082
2083     if (AtRegNo < 1 || AtRegNo > 31) {
2084       reportParseError("unexpected token in statement");
2085       return false;
2086     }
2087
2088     if (!Options.setATReg(AtRegNo)) {
2089       reportParseError("unexpected token in statement");
2090       return false;
2091     }
2092     getParser().Lex(); // Eat the register.
2093
2094     if (getLexer().isNot(AsmToken::EndOfStatement)) {
2095       reportParseError("unexpected token in statement");
2096       return false;
2097     }
2098     Parser.Lex(); // Consume the EndOfStatement.
2099     return false;
2100   } else {
2101     reportParseError("unexpected token in statement");
2102     return false;
2103   }
2104 }
2105
2106 bool MipsAsmParser::parseSetReorderDirective() {
2107   Parser.Lex();
2108   // If this is not the end of the statement, report an error.
2109   if (getLexer().isNot(AsmToken::EndOfStatement)) {
2110     reportParseError("unexpected token in statement");
2111     return false;
2112   }
2113   Options.setReorder();
2114   Parser.Lex(); // Consume the EndOfStatement.
2115   return false;
2116 }
2117
2118 bool MipsAsmParser::parseSetNoReorderDirective() {
2119   Parser.Lex();
2120   // If this is not the end of the statement, report an error.
2121   if (getLexer().isNot(AsmToken::EndOfStatement)) {
2122     reportParseError("unexpected token in statement");
2123     return false;
2124   }
2125   Options.setNoreorder();
2126   Parser.Lex(); // Consume the EndOfStatement.
2127   return false;
2128 }
2129
2130 bool MipsAsmParser::parseSetMacroDirective() {
2131   Parser.Lex();
2132   // If this is not the end of the statement, report an error.
2133   if (getLexer().isNot(AsmToken::EndOfStatement)) {
2134     reportParseError("unexpected token in statement");
2135     return false;
2136   }
2137   Options.setMacro();
2138   Parser.Lex(); // Consume the EndOfStatement.
2139   return false;
2140 }
2141
2142 bool MipsAsmParser::parseSetNoMacroDirective() {
2143   Parser.Lex();
2144   // If this is not the end of the statement, report an error.
2145   if (getLexer().isNot(AsmToken::EndOfStatement)) {
2146     reportParseError("`noreorder' must be set before `nomacro'");
2147     return false;
2148   }
2149   if (Options.isReorder()) {
2150     reportParseError("`noreorder' must be set before `nomacro'");
2151     return false;
2152   }
2153   Options.setNomacro();
2154   Parser.Lex(); // Consume the EndOfStatement.
2155   return false;
2156 }
2157
2158 bool MipsAsmParser::parseSetAssignment() {
2159   StringRef Name;
2160   const MCExpr *Value;
2161
2162   if (Parser.parseIdentifier(Name))
2163     reportParseError("expected identifier after .set");
2164
2165   if (getLexer().isNot(AsmToken::Comma))
2166     return reportParseError("unexpected token in .set directive");
2167   Lex(); // Eat comma
2168
2169   if (getLexer().is(AsmToken::Dollar)) {
2170     MCSymbol *Symbol;
2171     SMLoc DollarLoc = getLexer().getLoc();
2172     // Consume the dollar sign, and check for a following identifier.
2173     Parser.Lex();
2174     // We have a '$' followed by something, make sure they are adjacent.
2175     if (DollarLoc.getPointer() + 1 != getTok().getLoc().getPointer())
2176       return true;
2177     StringRef Res = StringRef(DollarLoc.getPointer(),
2178         getTok().getEndLoc().getPointer() - DollarLoc.getPointer());
2179     Symbol = getContext().GetOrCreateSymbol(Res);
2180     Parser.Lex();
2181     Value = MCSymbolRefExpr::Create(Symbol, MCSymbolRefExpr::VK_None,
2182                                     getContext());
2183   } else if (Parser.parseExpression(Value))
2184     return reportParseError("expected valid expression after comma");
2185
2186   // Check if the Name already exists as a symbol.
2187   MCSymbol *Sym = getContext().LookupSymbol(Name);
2188   if (Sym)
2189     return reportParseError("symbol already defined");
2190   Sym = getContext().GetOrCreateSymbol(Name);
2191   Sym->setVariableValue(Value);
2192
2193   return false;
2194 }
2195
2196 bool MipsAsmParser::parseDirectiveSet() {
2197
2198   // Get the next token.
2199   const AsmToken &Tok = Parser.getTok();
2200
2201   if (Tok.getString() == "noat") {
2202     return parseSetNoAtDirective();
2203   } else if (Tok.getString() == "at") {
2204     return parseSetAtDirective();
2205   } else if (Tok.getString() == "reorder") {
2206     return parseSetReorderDirective();
2207   } else if (Tok.getString() == "noreorder") {
2208     return parseSetNoReorderDirective();
2209   } else if (Tok.getString() == "macro") {
2210     return parseSetMacroDirective();
2211   } else if (Tok.getString() == "nomacro") {
2212     return parseSetNoMacroDirective();
2213   } else if (Tok.getString() == "nomips16") {
2214     // Ignore this directive for now.
2215     Parser.eatToEndOfStatement();
2216     return false;
2217   } else if (Tok.getString() == "nomicromips") {
2218     // Ignore this directive for now.
2219     Parser.eatToEndOfStatement();
2220     return false;
2221   } else {
2222     // It is just an identifier, look for an assignment.
2223     parseSetAssignment();
2224     return false;
2225   }
2226
2227   return true;
2228 }
2229
2230 bool MipsAsmParser::parseDirectiveMipsHackStocg() {
2231   MCAsmParser &Parser = getParser();
2232   StringRef Name;
2233   if (Parser.parseIdentifier(Name))
2234     reportParseError("expected identifier");
2235
2236   MCSymbol *Sym = getContext().GetOrCreateSymbol(Name);
2237   if (getLexer().isNot(AsmToken::Comma))
2238     return TokError("unexpected token");
2239   Lex();
2240
2241   int64_t Flags = 0;
2242   if (Parser.parseAbsoluteExpression(Flags))
2243     return TokError("unexpected token");
2244
2245   getTargetStreamer().emitMipsHackSTOCG(Sym, Flags);
2246   return false;
2247 }
2248
2249 bool MipsAsmParser::parseDirectiveMipsHackELFFlags() {
2250   int64_t Flags = 0;
2251   if (Parser.parseAbsoluteExpression(Flags))
2252     return TokError("unexpected token");
2253
2254   getTargetStreamer().emitMipsHackELFFlags(Flags);
2255   return false;
2256 }
2257
2258 /// parseDirectiveWord
2259 ///  ::= .word [ expression (, expression)* ]
2260 bool MipsAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
2261   if (getLexer().isNot(AsmToken::EndOfStatement)) {
2262     for (;;) {
2263       const MCExpr *Value;
2264       if (getParser().parseExpression(Value))
2265         return true;
2266
2267       getParser().getStreamer().EmitValue(Value, Size);
2268
2269       if (getLexer().is(AsmToken::EndOfStatement))
2270         break;
2271
2272       // FIXME: Improve diagnostic.
2273       if (getLexer().isNot(AsmToken::Comma))
2274         return Error(L, "unexpected token in directive");
2275       Parser.Lex();
2276     }
2277   }
2278
2279   Parser.Lex();
2280   return false;
2281 }
2282
2283 bool MipsAsmParser::ParseDirective(AsmToken DirectiveID) {
2284
2285   StringRef IDVal = DirectiveID.getString();
2286
2287   if (IDVal == ".ent") {
2288     // Ignore this directive for now.
2289     Parser.Lex();
2290     return false;
2291   }
2292
2293   if (IDVal == ".end") {
2294     // Ignore this directive for now.
2295     Parser.Lex();
2296     return false;
2297   }
2298
2299   if (IDVal == ".frame") {
2300     // Ignore this directive for now.
2301     Parser.eatToEndOfStatement();
2302     return false;
2303   }
2304
2305   if (IDVal == ".set") {
2306     return parseDirectiveSet();
2307   }
2308
2309   if (IDVal == ".fmask") {
2310     // Ignore this directive for now.
2311     Parser.eatToEndOfStatement();
2312     return false;
2313   }
2314
2315   if (IDVal == ".mask") {
2316     // Ignore this directive for now.
2317     Parser.eatToEndOfStatement();
2318     return false;
2319   }
2320
2321   if (IDVal == ".gpword") {
2322     // Ignore this directive for now.
2323     Parser.eatToEndOfStatement();
2324     return false;
2325   }
2326
2327   if (IDVal == ".word") {
2328     parseDirectiveWord(4, DirectiveID.getLoc());
2329     return false;
2330   }
2331
2332   if (IDVal == ".mips_hack_stocg")
2333     return parseDirectiveMipsHackStocg();
2334
2335   if (IDVal == ".mips_hack_elf_flags")
2336     return parseDirectiveMipsHackELFFlags();
2337
2338   return true;
2339 }
2340
2341 extern "C" void LLVMInitializeMipsAsmParser() {
2342   RegisterMCAsmParser<MipsAsmParser> X(TheMipsTarget);
2343   RegisterMCAsmParser<MipsAsmParser> Y(TheMipselTarget);
2344   RegisterMCAsmParser<MipsAsmParser> A(TheMips64Target);
2345   RegisterMCAsmParser<MipsAsmParser> B(TheMips64elTarget);
2346 }
2347
2348 #define GET_REGISTER_MATCHER
2349 #define GET_MATCHER_IMPLEMENTATION
2350 #include "MipsGenAsmMatcher.inc"