Jia Liu | c570711 | 2012-02-17 08:55:11 +0000 | [diff] [blame] | 1 | //===-- MipsAsmParser.cpp - Parse Mips assembly to MCInst instructions ----===// |
Rafael Espindola | fddf804 | 2012-01-11 03:56:41 +0000 | [diff] [blame] | 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 "llvm/MC/MCParser/MCAsmLexer.h" |
| 12 | #include "llvm/MC/MCTargetAsmParser.h" |
| 13 | #include "llvm/Support/TargetRegistry.h" |
Akira Hatanaka | 72e9b6a | 2012-08-17 20:16:42 +0000 | [diff] [blame] | 14 | #include "llvm/MC/MCParser/MCParsedAsmOperand.h" |
| 15 | #include "llvm/MC/MCTargetAsmParser.h" |
| 16 | #include "llvm/MC/MCInst.h" |
| 17 | #include "llvm/MC/MCExpr.h" |
| 18 | #include "llvm/Support/MathExtras.h" |
Rafael Espindola | fddf804 | 2012-01-11 03:56:41 +0000 | [diff] [blame] | 19 | |
| 20 | using namespace llvm; |
| 21 | |
| 22 | namespace { |
| 23 | class MipsAsmParser : public MCTargetAsmParser { |
Akira Hatanaka | 72e9b6a | 2012-08-17 20:16:42 +0000 | [diff] [blame] | 24 | |
| 25 | #define GET_ASSEMBLER_HEADER |
| 26 | #include "MipsGenAsmMatcher.inc" |
| 27 | |
Rafael Espindola | fddf804 | 2012-01-11 03:56:41 +0000 | [diff] [blame] | 28 | bool MatchAndEmitInstruction(SMLoc IDLoc, |
| 29 | SmallVectorImpl<MCParsedAsmOperand*> &Operands, |
| 30 | MCStreamer &Out); |
| 31 | |
| 32 | bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc); |
| 33 | |
| 34 | bool ParseInstruction(StringRef Name, SMLoc NameLoc, |
Akira Hatanaka | 72e9b6a | 2012-08-17 20:16:42 +0000 | [diff] [blame] | 35 | SmallVectorImpl<MCParsedAsmOperand*> &Operands); |
Rafael Espindola | fddf804 | 2012-01-11 03:56:41 +0000 | [diff] [blame] | 36 | |
| 37 | bool ParseDirective(AsmToken DirectiveID); |
| 38 | |
Akira Hatanaka | 72e9b6a | 2012-08-17 20:16:42 +0000 | [diff] [blame] | 39 | OperandMatchResultTy parseMemOperand(SmallVectorImpl<MCParsedAsmOperand*>&); |
Chad Rosier | 038f3e3 | 2012-09-03 18:47:45 +0000 | [diff] [blame] | 40 | |
| 41 | unsigned GetMCInstOperandNum(unsigned Kind, MCInst &Inst, |
| 42 | const SmallVectorImpl<MCParsedAsmOperand*> &Operands, |
Chad Rosier | 2cc97de | 2012-09-03 20:31:23 +0000 | [diff] [blame^] | 43 | unsigned OperandNum, unsigned &NumMCOperands); |
Chad Rosier | 038f3e3 | 2012-09-03 18:47:45 +0000 | [diff] [blame] | 44 | |
Rafael Espindola | fddf804 | 2012-01-11 03:56:41 +0000 | [diff] [blame] | 45 | public: |
| 46 | MipsAsmParser(MCSubtargetInfo &sti, MCAsmParser &parser) |
| 47 | : MCTargetAsmParser() { |
| 48 | } |
| 49 | |
| 50 | }; |
| 51 | } |
| 52 | |
Akira Hatanaka | 72e9b6a | 2012-08-17 20:16:42 +0000 | [diff] [blame] | 53 | namespace { |
| 54 | |
| 55 | /// MipsOperand - Instances of this class represent a parsed Mips machine |
| 56 | /// instruction. |
| 57 | class MipsOperand : public MCParsedAsmOperand { |
| 58 | enum KindTy { |
| 59 | k_CondCode, |
| 60 | k_CoprocNum, |
| 61 | k_Immediate, |
| 62 | k_Memory, |
| 63 | k_PostIndexRegister, |
| 64 | k_Register, |
| 65 | k_Token |
| 66 | } Kind; |
| 67 | |
| 68 | MipsOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {} |
| 69 | public: |
| 70 | void addRegOperands(MCInst &Inst, unsigned N) const { |
| 71 | llvm_unreachable("unimplemented!"); |
| 72 | } |
| 73 | void addExpr(MCInst &Inst, const MCExpr *Expr) const{ |
| 74 | llvm_unreachable("unimplemented!"); |
| 75 | } |
| 76 | void addImmOperands(MCInst &Inst, unsigned N) const { |
| 77 | llvm_unreachable("unimplemented!"); |
| 78 | } |
| 79 | void addMemOperands(MCInst &Inst, unsigned N) const { |
| 80 | llvm_unreachable("unimplemented!"); |
| 81 | } |
| 82 | |
| 83 | bool isReg() const { return Kind == k_Register; } |
| 84 | bool isImm() const { return Kind == k_Immediate; } |
| 85 | bool isToken() const { return Kind == k_Token; } |
| 86 | bool isMem() const { return Kind == k_Memory; } |
| 87 | |
| 88 | StringRef getToken() const { |
| 89 | assert(Kind == k_Token && "Invalid access!"); |
| 90 | return ""; |
| 91 | } |
| 92 | |
| 93 | unsigned getReg() const { |
| 94 | assert((Kind == k_Register) && "Invalid access!"); |
| 95 | return 0; |
| 96 | } |
| 97 | |
| 98 | virtual void print(raw_ostream &OS) const { |
| 99 | llvm_unreachable("unimplemented!"); |
| 100 | } |
| 101 | }; |
| 102 | } |
| 103 | |
Chad Rosier | 038f3e3 | 2012-09-03 18:47:45 +0000 | [diff] [blame] | 104 | unsigned MipsAsmParser:: |
| 105 | GetMCInstOperandNum(unsigned Kind, MCInst &Inst, |
| 106 | const SmallVectorImpl<MCParsedAsmOperand*> &Operands, |
Chad Rosier | 2cc97de | 2012-09-03 20:31:23 +0000 | [diff] [blame^] | 107 | unsigned OperandNum, unsigned &NumMCOperands) { |
Chad Rosier | 038f3e3 | 2012-09-03 18:47:45 +0000 | [diff] [blame] | 108 | assert (0 && "GetMCInstOperandNum() not supported by the Mips target."); |
Chad Rosier | efeaae8 | 2012-09-03 19:04:35 +0000 | [diff] [blame] | 109 | // The Mips backend doesn't currently include the matcher implementation, so |
| 110 | // the GetMCInstOperandNumImpl() is undefined. This is a temporary |
| 111 | // work around. |
Chad Rosier | 2cc97de | 2012-09-03 20:31:23 +0000 | [diff] [blame^] | 112 | NumMCOperands = 0; |
Chad Rosier | 038f3e3 | 2012-09-03 18:47:45 +0000 | [diff] [blame] | 113 | return 0; |
| 114 | } |
| 115 | |
Rafael Espindola | fddf804 | 2012-01-11 03:56:41 +0000 | [diff] [blame] | 116 | bool MipsAsmParser:: |
| 117 | MatchAndEmitInstruction(SMLoc IDLoc, |
| 118 | SmallVectorImpl<MCParsedAsmOperand*> &Operands, |
| 119 | MCStreamer &Out) { |
| 120 | return true; |
| 121 | } |
| 122 | |
| 123 | bool MipsAsmParser:: |
| 124 | ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc) { |
| 125 | return true; |
| 126 | } |
| 127 | |
| 128 | bool MipsAsmParser:: |
| 129 | ParseInstruction(StringRef Name, SMLoc NameLoc, |
| 130 | SmallVectorImpl<MCParsedAsmOperand*> &Operands) { |
| 131 | return true; |
| 132 | } |
| 133 | |
| 134 | bool MipsAsmParser:: |
| 135 | ParseDirective(AsmToken DirectiveID) { |
| 136 | return true; |
| 137 | } |
| 138 | |
Akira Hatanaka | 72e9b6a | 2012-08-17 20:16:42 +0000 | [diff] [blame] | 139 | MipsAsmParser::OperandMatchResultTy MipsAsmParser:: |
| 140 | parseMemOperand(SmallVectorImpl<MCParsedAsmOperand*>&) { |
| 141 | return MatchOperand_ParseFail; |
| 142 | } |
| 143 | |
Rafael Espindola | fddf804 | 2012-01-11 03:56:41 +0000 | [diff] [blame] | 144 | extern "C" void LLVMInitializeMipsAsmParser() { |
| 145 | RegisterMCAsmParser<MipsAsmParser> X(TheMipsTarget); |
| 146 | RegisterMCAsmParser<MipsAsmParser> Y(TheMipselTarget); |
| 147 | RegisterMCAsmParser<MipsAsmParser> A(TheMips64Target); |
| 148 | RegisterMCAsmParser<MipsAsmParser> B(TheMips64elTarget); |
| 149 | } |