[Sparc] Add support for parsing memory operands in sparc AsmParser.
[oota-llvm.git] / lib / Target / Sparc / AsmParser / SparcAsmParser.cpp
1 //===-- SparcAsmParser.cpp - Parse Sparc 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/SparcMCTargetDesc.h"
11 #include "llvm/ADT/STLExtras.h"
12 #include "llvm/MC/MCContext.h"
13 #include "llvm/MC/MCInst.h"
14 #include "llvm/MC/MCParser/MCParsedAsmOperand.h"
15 #include "llvm/MC/MCStreamer.h"
16 #include "llvm/MC/MCSubtargetInfo.h"
17 #include "llvm/MC/MCTargetAsmParser.h"
18 #include "llvm/Support/TargetRegistry.h"
19
20 using namespace llvm;
21
22 // The generated AsmMatcher SparcGenAsmMatcher uses "Sparc" as the target
23 // namespace. But SPARC backend uses "SP" as its namespace.
24 namespace llvm {
25   namespace Sparc {
26     using namespace SP;
27   }
28 }
29
30 namespace {
31 class SparcOperand;
32 class SparcAsmParser : public MCTargetAsmParser {
33
34   MCSubtargetInfo &STI;
35   MCAsmParser &Parser;
36
37   /// @name Auto-generated Match Functions
38   /// {
39
40 #define GET_ASSEMBLER_HEADER
41 #include "SparcGenAsmMatcher.inc"
42
43   /// }
44
45   // public interface of the MCTargetAsmParser.
46   bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
47                                SmallVectorImpl<MCParsedAsmOperand*> &Operands,
48                                MCStreamer &Out, unsigned &ErrorInfo,
49                                bool MatchingInlineAsm);
50   bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
51   bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
52                         SMLoc NameLoc,
53                         SmallVectorImpl<MCParsedAsmOperand*> &Operands);
54   bool ParseDirective(AsmToken DirectiveID);
55
56
57   // Custom parse functions for Sparc specific operands.
58   OperandMatchResultTy
59   parseMEMOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands);
60
61   OperandMatchResultTy
62   parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
63                StringRef Name);
64
65   OperandMatchResultTy
66   parseSparcAsmOperand(SparcOperand *&Operand);
67
68   // returns true if Tok is matched to a register and returns register in RegNo.
69   bool matchRegisterName(const AsmToken &Tok, unsigned &RegNo, bool isDFP,
70                          bool isQFP);
71
72 public:
73   SparcAsmParser(MCSubtargetInfo &sti, MCAsmParser &parser,
74                 const MCInstrInfo &MII)
75       : MCTargetAsmParser(), STI(sti), Parser(parser) {
76     // Initialize the set of available features.
77     setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
78   }
79
80 };
81
82   static unsigned IntRegs[32] = {
83     Sparc::G0, Sparc::G1, Sparc::G2, Sparc::G3,
84     Sparc::G4, Sparc::G5, Sparc::G6, Sparc::G7,
85     Sparc::O0, Sparc::O1, Sparc::O2, Sparc::O3,
86     Sparc::O4, Sparc::O5, Sparc::O6, Sparc::O7,
87     Sparc::L0, Sparc::L1, Sparc::L2, Sparc::L3,
88     Sparc::L4, Sparc::L5, Sparc::L6, Sparc::L7,
89     Sparc::I0, Sparc::I1, Sparc::I2, Sparc::I3,
90     Sparc::I4, Sparc::I5, Sparc::I6, Sparc::I7 };
91
92   static unsigned FloatRegs[32] = {
93     Sparc::F0,  Sparc::F1,  Sparc::F2,  Sparc::F3,
94     Sparc::F4,  Sparc::F5,  Sparc::F6,  Sparc::F7,
95     Sparc::F8,  Sparc::F9,  Sparc::F10, Sparc::F11,
96     Sparc::F12, Sparc::F13, Sparc::F14, Sparc::F15,
97     Sparc::F16, Sparc::F17, Sparc::F18, Sparc::F19,
98     Sparc::F20, Sparc::F21, Sparc::F22, Sparc::F23,
99     Sparc::F24, Sparc::F25, Sparc::F26, Sparc::F27,
100     Sparc::F28, Sparc::F29, Sparc::F30, Sparc::F31 };
101
102   static unsigned DoubleRegs[32] = {
103     Sparc::D0,  Sparc::D1,  Sparc::D2,  Sparc::D3,
104     Sparc::D4,  Sparc::D5,  Sparc::D6,  Sparc::D7,
105     Sparc::D8,  Sparc::D7,  Sparc::D8,  Sparc::D9,
106     Sparc::D12, Sparc::D13, Sparc::D14, Sparc::D15,
107     Sparc::D16, Sparc::D17, Sparc::D18, Sparc::D19,
108     Sparc::D20, Sparc::D21, Sparc::D22, Sparc::D23,
109     Sparc::D24, Sparc::D25, Sparc::D26, Sparc::D27,
110     Sparc::D28, Sparc::D29, Sparc::D30, Sparc::D31 };
111
112   static unsigned QuadFPRegs[32] = {
113     Sparc::Q0,  Sparc::Q1,  Sparc::Q2,  Sparc::Q3,
114     Sparc::Q4,  Sparc::Q5,  Sparc::Q6,  Sparc::Q7,
115     Sparc::Q8,  Sparc::Q7,  Sparc::Q8,  Sparc::Q9,
116     Sparc::Q12, Sparc::Q13, Sparc::Q14, Sparc::Q15 };
117
118
119 /// SparcOperand - Instances of this class represent a parsed Sparc machine
120 /// instruction.
121 class SparcOperand : public MCParsedAsmOperand {
122 public:
123   enum RegisterKind {
124     rk_None,
125     rk_IntReg,
126     rk_FloatReg,
127     rk_DoubleReg,
128     rk_QuadReg,
129     rk_CCReg,
130     rk_Y
131   };
132 private:
133   enum KindTy {
134     k_Token,
135     k_Register,
136     k_Immediate,
137     k_MemoryReg,
138     k_MemoryImm
139   } Kind;
140
141   SMLoc StartLoc, EndLoc;
142
143   SparcOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
144
145   struct Token {
146     const char *Data;
147     unsigned Length;
148   };
149
150   struct RegOp {
151     unsigned RegNum;
152     RegisterKind Kind;
153   };
154
155   struct ImmOp {
156     const MCExpr *Val;
157   };
158
159   struct MemOp {
160     unsigned Base;
161     unsigned OffsetReg;
162     const MCExpr *Off;
163   };
164
165   union {
166     struct Token Tok;
167     struct RegOp Reg;
168     struct ImmOp Imm;
169     struct MemOp Mem;
170   };
171 public:
172   bool isToken() const { return Kind == k_Token; }
173   bool isReg() const { return Kind == k_Register; }
174   bool isImm() const { return Kind == k_Immediate; }
175   bool isMem() const { return isMEMrr() || isMEMri(); }
176   bool isMEMrr() const { return Kind == k_MemoryReg; }
177   bool isMEMri() const { return Kind == k_MemoryImm; }
178
179   StringRef getToken() const {
180     assert(Kind == k_Token && "Invalid access!");
181     return StringRef(Tok.Data, Tok.Length);
182   }
183
184   unsigned getReg() const {
185     assert((Kind == k_Register) && "Invalid access!");
186     return Reg.RegNum;
187   }
188
189   const MCExpr *getImm() const {
190     assert((Kind == k_Immediate) && "Invalid access!");
191     return Imm.Val;
192   }
193
194   unsigned getMemBase() const {
195     assert((Kind == k_MemoryReg || Kind == k_MemoryImm) && "Invalid access!");
196     return Mem.Base;
197   }
198
199   unsigned getMemOffsetReg() const {
200     assert((Kind == k_MemoryReg) && "Invalid access!");
201     return Mem.OffsetReg;
202   }
203
204   const MCExpr *getMemOff() const {
205     assert((Kind == k_MemoryImm) && "Invalid access!");
206     return Mem.Off;
207   }
208
209   /// getStartLoc - Get the location of the first token of this operand.
210   SMLoc getStartLoc() const {
211     return StartLoc;
212   }
213   /// getEndLoc - Get the location of the last token of this operand.
214   SMLoc getEndLoc() const {
215     return EndLoc;
216   }
217
218   virtual void print(raw_ostream &OS) const {
219     switch (Kind) {
220     case k_Token:     OS << "Token: " << getToken() << "\n"; break;
221     case k_Register:  OS << "Reg: #" << getReg() << "\n"; break;
222     case k_Immediate: OS << "Imm: " << getImm() << "\n"; break;
223     case k_MemoryReg: OS << "Mem: " << getMemBase() << "+"
224                          << getMemOffsetReg() << "\n"; break;
225     case k_MemoryImm: assert(getMemOff() != 0);
226       OS << "Mem: " << getMemBase()
227          << "+" << *getMemOff()
228          << "\n"; break;
229     }
230   }
231
232   void addRegOperands(MCInst &Inst, unsigned N) const {
233     assert(N == 1 && "Invalid number of operands!");
234     Inst.addOperand(MCOperand::CreateReg(getReg()));
235   }
236
237   void addImmOperands(MCInst &Inst, unsigned N) const {
238     assert(N == 1 && "Invalid number of operands!");
239     const MCExpr *Expr = getImm();
240     addExpr(Inst, Expr);
241   }
242
243   void addExpr(MCInst &Inst, const MCExpr *Expr) const{
244     // Add as immediate when possible.  Null MCExpr = 0.
245     if (Expr == 0)
246       Inst.addOperand(MCOperand::CreateImm(0));
247     else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
248       Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
249     else
250       Inst.addOperand(MCOperand::CreateExpr(Expr));
251   }
252
253   void addMEMrrOperands(MCInst &Inst, unsigned N) const {
254     assert(N == 2 && "Invalid number of operands!");
255
256     Inst.addOperand(MCOperand::CreateReg(getMemBase()));
257
258     assert(getMemOffsetReg() != 0 && "Invalid offset");
259     Inst.addOperand(MCOperand::CreateReg(getMemOffsetReg()));
260   }
261
262   void addMEMriOperands(MCInst &Inst, unsigned N) const {
263     assert(N == 2 && "Invalid number of operands!");
264
265     Inst.addOperand(MCOperand::CreateReg(getMemBase()));
266
267     const MCExpr *Expr = getMemOff();
268     addExpr(Inst, Expr);
269   }
270
271   static SparcOperand *CreateToken(StringRef Str, SMLoc S) {
272     SparcOperand *Op = new SparcOperand(k_Token);
273     Op->Tok.Data = Str.data();
274     Op->Tok.Length = Str.size();
275     Op->StartLoc = S;
276     Op->EndLoc = S;
277     return Op;
278   }
279
280   static SparcOperand *CreateReg(unsigned RegNum,
281                                  SparcOperand::RegisterKind Kind,
282                                  SMLoc S, SMLoc E) {
283     SparcOperand *Op = new SparcOperand(k_Register);
284     Op->Reg.RegNum = RegNum;
285     Op->Reg.Kind   = Kind;
286     Op->StartLoc = S;
287     Op->EndLoc = E;
288     return Op;
289   }
290
291   static SparcOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
292     SparcOperand *Op = new SparcOperand(k_Immediate);
293     Op->Imm.Val = Val;
294     Op->StartLoc = S;
295     Op->EndLoc = E;
296     return Op;
297   }
298
299   static SparcOperand *MorphToMEMrr(unsigned Base, SparcOperand *Op) {
300     unsigned offsetReg = Op->getReg();
301     Op->Kind = k_MemoryReg;
302     Op->Mem.Base = Base;
303     Op->Mem.OffsetReg = offsetReg;
304     Op->Mem.Off = 0;
305     return Op;
306   }
307
308   static SparcOperand *CreateMEMri(unsigned Base,
309                                  const MCExpr *Off,
310                                  SMLoc S, SMLoc E) {
311     SparcOperand *Op = new SparcOperand(k_MemoryImm);
312     Op->Mem.Base = Base;
313     Op->Mem.OffsetReg = 0;
314     Op->Mem.Off = Off;
315     Op->StartLoc = S;
316     Op->EndLoc = E;
317     return Op;
318   }
319
320   static SparcOperand *MorphToMEMri(unsigned Base, SparcOperand *Op) {
321     const MCExpr *Imm  = Op->getImm();
322     Op->Kind = k_MemoryImm;
323     Op->Mem.Base = Base;
324     Op->Mem.OffsetReg = 0;
325     Op->Mem.Off = Imm;
326     return Op;
327   }
328 };
329
330 } // end namespace
331
332 bool SparcAsmParser::
333 MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
334                         SmallVectorImpl<MCParsedAsmOperand*> &Operands,
335                         MCStreamer &Out, unsigned &ErrorInfo,
336                         bool MatchingInlineAsm) {
337   MCInst Inst;
338   SmallVector<MCInst, 8> Instructions;
339   unsigned MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
340                                               MatchingInlineAsm);
341   switch (MatchResult) {
342   default:
343     break;
344
345   case Match_Success: {
346     Inst.setLoc(IDLoc);
347     Out.EmitInstruction(Inst);
348     return false;
349   }
350
351   case Match_MissingFeature:
352     return Error(IDLoc,
353                  "instruction requires a CPU feature not currently enabled");
354
355   case Match_InvalidOperand: {
356     SMLoc ErrorLoc = IDLoc;
357     if (ErrorInfo != ~0U) {
358       if (ErrorInfo >= Operands.size())
359         return Error(IDLoc, "too few operands for instruction");
360
361       ErrorLoc = ((SparcOperand*) Operands[ErrorInfo])->getStartLoc();
362       if (ErrorLoc == SMLoc())
363         ErrorLoc = IDLoc;
364     }
365
366     return Error(ErrorLoc, "invalid operand for instruction");
367   }
368   case Match_MnemonicFail:
369     return Error(IDLoc, "invalid instruction");
370   }
371   return true;
372 }
373
374 bool SparcAsmParser::
375 ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc)
376 {
377   const AsmToken &Tok = Parser.getTok();
378   StartLoc = Tok.getLoc();
379   EndLoc = Tok.getEndLoc();
380   RegNo = 0;
381   if (getLexer().getKind() != AsmToken::Percent)
382     return false;
383   Parser.Lex();
384   if (matchRegisterName(Tok, RegNo, false, false)) {
385     Parser.Lex();
386     return false;
387   }
388
389   return Error(StartLoc, "invalid register name");
390 }
391
392 bool SparcAsmParser::
393 ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
394                  SMLoc NameLoc,
395                  SmallVectorImpl<MCParsedAsmOperand*> &Operands)
396 {
397   // Check if we have valid mnemonic.
398   if (!mnemonicIsValid(Name, 0)) {
399     Parser.eatToEndOfStatement();
400     return Error(NameLoc, "Unknown instruction");
401   }
402   // First operand in MCInst is instruction mnemonic.
403   Operands.push_back(SparcOperand::CreateToken(Name, NameLoc));
404
405   if (getLexer().isNot(AsmToken::EndOfStatement)) {
406     // Read the first operand.
407     if (parseOperand(Operands, Name) != MatchOperand_Success) {
408       SMLoc Loc = getLexer().getLoc();
409       Parser.eatToEndOfStatement();
410       return Error(Loc, "unexpected token");
411     }
412
413     while (getLexer().is(AsmToken::Comma)) {
414       Parser.Lex(); // Eat the comma.
415       // Parse and remember the operand.
416       if (parseOperand(Operands, Name) != MatchOperand_Success) {
417         SMLoc Loc = getLexer().getLoc();
418         Parser.eatToEndOfStatement();
419         return Error(Loc, "unexpected token");
420       }
421     }
422   }
423   if (getLexer().isNot(AsmToken::EndOfStatement)) {
424     SMLoc Loc = getLexer().getLoc();
425     Parser.eatToEndOfStatement();
426     return Error(Loc, "unexpected token");
427   }
428   Parser.Lex(); // Consume the EndOfStatement.
429   return false;
430 }
431
432 bool SparcAsmParser::
433 ParseDirective(AsmToken DirectiveID)
434 {
435   // Ignore all directives for now.
436   Parser.eatToEndOfStatement();
437   return false;
438 }
439
440 SparcAsmParser::OperandMatchResultTy SparcAsmParser::
441 parseMEMOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands)
442 {
443
444   SMLoc S, E;
445   unsigned BaseReg = 0;
446
447   if (ParseRegister(BaseReg, S, E)) {
448     return MatchOperand_NoMatch;
449   }
450
451   switch (getLexer().getKind()) {
452   default: return MatchOperand_NoMatch;
453
454   case AsmToken::RBrac:
455   case AsmToken::EndOfStatement:
456     Operands.push_back(SparcOperand::CreateMEMri(BaseReg, 0, S, E));
457     return MatchOperand_Success;
458
459   case AsmToken:: Plus:
460     Parser.Lex(); // Eat the '+'
461     break;
462   case AsmToken::Minus:
463     break;
464   }
465
466   SparcOperand *Offset = 0;
467   OperandMatchResultTy ResTy = parseSparcAsmOperand(Offset);
468   if (ResTy != MatchOperand_Success || !Offset)
469     return MatchOperand_NoMatch;
470
471   Offset = (Offset->isImm()
472             ? SparcOperand::MorphToMEMri(BaseReg, Offset)
473             : SparcOperand::MorphToMEMrr(BaseReg, Offset));
474
475   Operands.push_back(Offset);
476   return MatchOperand_Success;
477 }
478
479 SparcAsmParser::OperandMatchResultTy SparcAsmParser::
480 parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
481              StringRef Mnemonic)
482 {
483
484   OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
485
486   // If there wasn't a custom match, try the generic matcher below. Otherwise,
487   // there was a match, but an error occurred, in which case, just return that
488   // the operand parsing failed.
489   if (ResTy == MatchOperand_Success || ResTy == MatchOperand_ParseFail)
490     return ResTy;
491
492   if (getLexer().is(AsmToken::LBrac)) {
493     // Memory operand
494     Operands.push_back(SparcOperand::CreateToken("[",
495                                                  Parser.getTok().getLoc()));
496     Parser.Lex(); // Eat the [
497
498     ResTy = parseMEMOperand(Operands);
499     if (ResTy != MatchOperand_Success)
500       return ResTy;
501
502     if (!getLexer().is(AsmToken::RBrac))
503       return MatchOperand_ParseFail;
504
505     Operands.push_back(SparcOperand::CreateToken("]",
506                                                  Parser.getTok().getLoc()));
507     Parser.Lex(); // Eat the ]
508     return MatchOperand_Success;
509   }
510
511   SparcOperand *Op = 0;
512   ResTy = parseSparcAsmOperand(Op);
513   if (ResTy != MatchOperand_Success || !Op)
514     return MatchOperand_ParseFail;
515
516   // Push the parsed operand into the list of operands
517   Operands.push_back(Op);
518
519   return MatchOperand_Success;
520 }
521
522 SparcAsmParser::OperandMatchResultTy
523 SparcAsmParser::parseSparcAsmOperand(SparcOperand *&Op)
524 {
525
526   SMLoc S = Parser.getTok().getLoc();
527   SMLoc E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
528   const MCExpr *EVal;
529
530   Op = 0;
531   switch (getLexer().getKind()) {
532   default:  break;
533
534   case AsmToken::Percent:
535     Parser.Lex(); // Eat the '%'.
536     unsigned RegNo;
537     if (matchRegisterName(Parser.getTok(), RegNo, false, false)) {
538       Parser.Lex(); // Eat the identifier token.
539       Op = SparcOperand::CreateReg(RegNo, SparcOperand::rk_None, S, E);
540       break;
541     }
542     // FIXME: Handle modifiers like %hi, %lo etc.,
543     break;
544
545   case AsmToken::Minus:
546   case AsmToken::Integer:
547     if (!getParser().parseExpression(EVal))
548       Op = SparcOperand::CreateImm(EVal, S, E);
549     break;
550
551   case AsmToken::Identifier: {
552     StringRef Identifier;
553     if (!getParser().parseIdentifier(Identifier)) {
554       SMLoc E = SMLoc::getFromPointer(Parser.getTok().
555                                       getLoc().getPointer() - 1);
556       MCSymbol *Sym = getContext().GetOrCreateSymbol(Identifier);
557
558       const MCExpr *Res = MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_None,
559                                                   getContext());
560
561       Op = SparcOperand::CreateImm(Res, S, E);
562     }
563     break;
564   }
565   }
566   return (Op) ? MatchOperand_Success : MatchOperand_ParseFail;
567 }
568
569 bool SparcAsmParser::matchRegisterName(const AsmToken &Tok,
570                                        unsigned &RegNo,
571                                        bool isDFP,
572                                        bool isQFP)
573 {
574   int64_t intVal = 0;
575   RegNo = 0;
576   if (Tok.is(AsmToken::Identifier)) {
577     StringRef name = Tok.getString();
578
579     // %fp
580     if (name.equals("fp")) {
581       RegNo = Sparc::I6;
582       return true;
583     }
584     // %sp
585     if (name.equals("sp")) {
586       RegNo = Sparc::O6;
587       return true;
588     }
589
590     if (name.equals("y")) {
591       RegNo = Sparc::Y;
592       return true;
593     }
594
595     if (name.equals("icc")) {
596       RegNo = Sparc::ICC;
597       return true;
598     }
599
600     if (name.equals("xcc")) {
601       // FIXME:: check 64bit.
602       RegNo = Sparc::ICC;
603       return true;
604     }
605
606     // %fcc0 - %fcc3
607     if (name.substr(0, 3).equals_lower("fcc")
608         && !name.substr(3).getAsInteger(10, intVal)
609         && intVal < 4) {
610       // FIXME: check 64bit and  handle %fcc1 - %fcc3
611       RegNo = Sparc::FCC;
612       return true;
613     }
614
615     // %g0 - %g7
616     if (name.substr(0, 1).equals_lower("g")
617         && !name.substr(1).getAsInteger(10, intVal)
618         && intVal < 8) {
619       RegNo = IntRegs[intVal];
620       return true;
621     }
622     // %o0 - %o7
623     if (name.substr(0, 1).equals_lower("o")
624         && !name.substr(1).getAsInteger(10, intVal)
625         && intVal < 8) {
626       RegNo = IntRegs[8 + intVal];
627       return true;
628     }
629     if (name.substr(0, 1).equals_lower("l")
630         && !name.substr(1).getAsInteger(10, intVal)
631         && intVal < 8) {
632       RegNo = IntRegs[16 + intVal];
633       return true;
634     }
635     if (name.substr(0, 1).equals_lower("i")
636         && !name.substr(1).getAsInteger(10, intVal)
637         && intVal < 8) {
638       RegNo = IntRegs[24 + intVal];
639       return true;
640     }
641     // %f0 - %f31
642     if (name.substr(0, 1).equals_lower("f")
643         && !name.substr(1, 2).getAsInteger(10, intVal) && intVal < 32) {
644       if (isDFP && (intVal%2 == 0)) {
645         RegNo = DoubleRegs[intVal/2];
646       } else if (isQFP && (intVal%4 == 0)) {
647         RegNo = QuadFPRegs[intVal/4];
648       } else {
649         RegNo = FloatRegs[intVal];
650       }
651       return true;
652     }
653     // %f32 - %f62
654     if (name.substr(0, 1).equals_lower("f")
655         && !name.substr(1, 2).getAsInteger(10, intVal)
656         && intVal >= 32 && intVal <= 62 && (intVal % 2 == 0)) {
657       if (isDFP) {
658         RegNo = DoubleRegs[16 + intVal/2];
659       } else if (isQFP && (intVal % 4 == 0)) {
660         RegNo = QuadFPRegs[8 + intVal/4];
661       } else {
662         return false;
663       }
664       return true;
665     }
666
667     // %r0 - %r31
668     if (name.substr(0, 1).equals_lower("r")
669         && !name.substr(1, 2).getAsInteger(10, intVal) && intVal < 31) {
670       RegNo = IntRegs[intVal];
671       return true;
672     }
673   }
674   return false;
675 }
676
677
678
679 extern "C" void LLVMInitializeSparcAsmParser() {
680   RegisterMCAsmParser<SparcAsmParser> A(TheSparcTarget);
681   RegisterMCAsmParser<SparcAsmParser> B(TheSparcV9Target);
682 }
683
684 #define GET_REGISTER_MATCHER
685 #define GET_MATCHER_IMPLEMENTATION
686 #include "SparcGenAsmMatcher.inc"