blob: deef84408dcc2de620354e472eda37ec5b299b52 [file] [log] [blame]
Jia Liuc5707112012-02-17 08:55:11 +00001//===-- MipsAsmParser.cpp - Parse Mips assembly to MCInst instructions ----===//
Rafael Espindolafddf8042012-01-11 03:56:41 +00002//
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 Hatanaka72e9b6a2012-08-17 20:16:42 +000014#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 Espindolafddf8042012-01-11 03:56:41 +000019
20using namespace llvm;
21
22namespace {
23class MipsAsmParser : public MCTargetAsmParser {
Akira Hatanaka72e9b6a2012-08-17 20:16:42 +000024
25#define GET_ASSEMBLER_HEADER
26#include "MipsGenAsmMatcher.inc"
27
Rafael Espindolafddf8042012-01-11 03:56:41 +000028 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 Hatanaka72e9b6a2012-08-17 20:16:42 +000035 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Rafael Espindolafddf8042012-01-11 03:56:41 +000036
37 bool ParseDirective(AsmToken DirectiveID);
38
Akira Hatanaka72e9b6a2012-08-17 20:16:42 +000039 OperandMatchResultTy parseMemOperand(SmallVectorImpl<MCParsedAsmOperand*>&);
Chad Rosier038f3e32012-09-03 18:47:45 +000040
41 unsigned GetMCInstOperandNum(unsigned Kind, MCInst &Inst,
42 const SmallVectorImpl<MCParsedAsmOperand*> &Operands,
43 unsigned OperandNum);
44
Rafael Espindolafddf8042012-01-11 03:56:41 +000045public:
46 MipsAsmParser(MCSubtargetInfo &sti, MCAsmParser &parser)
47 : MCTargetAsmParser() {
48 }
49
50};
51}
52
Akira Hatanaka72e9b6a2012-08-17 20:16:42 +000053namespace {
54
55/// MipsOperand - Instances of this class represent a parsed Mips machine
56/// instruction.
57class 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) {}
69public:
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 Rosier038f3e32012-09-03 18:47:45 +0000104unsigned MipsAsmParser::
105GetMCInstOperandNum(unsigned Kind, MCInst &Inst,
106 const SmallVectorImpl<MCParsedAsmOperand*> &Operands,
107 unsigned OperandNum) {
108 assert (0 && "GetMCInstOperandNum() not supported by the Mips target.");
109 return 0;
110}
111
Rafael Espindolafddf8042012-01-11 03:56:41 +0000112bool MipsAsmParser::
113MatchAndEmitInstruction(SMLoc IDLoc,
114 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
115 MCStreamer &Out) {
116 return true;
117}
118
119bool MipsAsmParser::
120ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc) {
121 return true;
122}
123
124bool MipsAsmParser::
125ParseInstruction(StringRef Name, SMLoc NameLoc,
126 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
127 return true;
128}
129
130bool MipsAsmParser::
131ParseDirective(AsmToken DirectiveID) {
132 return true;
133}
134
Akira Hatanaka72e9b6a2012-08-17 20:16:42 +0000135MipsAsmParser::OperandMatchResultTy MipsAsmParser::
136 parseMemOperand(SmallVectorImpl<MCParsedAsmOperand*>&) {
137 return MatchOperand_ParseFail;
138}
139
Rafael Espindolafddf8042012-01-11 03:56:41 +0000140extern "C" void LLVMInitializeMipsAsmParser() {
141 RegisterMCAsmParser<MipsAsmParser> X(TheMipsTarget);
142 RegisterMCAsmParser<MipsAsmParser> Y(TheMipselTarget);
143 RegisterMCAsmParser<MipsAsmParser> A(TheMips64Target);
144 RegisterMCAsmParser<MipsAsmParser> B(TheMips64elTarget);
145}