32ed5cc9d18b3b9969a990e67d60310c4ea5b7f9
[oota-llvm.git] / lib / Target / Mips / MCTargetDesc / MipsMCCodeEmitter.h
1 //===-- MipsMCCodeEmitter.h - Convert Mips Code to Machine Code -----------===//
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 // This file defines the MipsMCCodeEmitter class.
11 //
12 //===----------------------------------------------------------------------===//
13 //
14
15 #ifndef LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSMCCODEEMITTER_H
16 #define LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSMCCODEEMITTER_H
17
18 #include "llvm/MC/MCCodeEmitter.h"
19 #include "llvm/Support/DataTypes.h"
20
21 using namespace llvm;
22
23 namespace llvm {
24 class MCContext;
25 class MCExpr;
26 class MCInst;
27 class MCInstrInfo;
28 class MCFixup;
29 class MCOperand;
30 class MCSubtargetInfo;
31 class raw_ostream;
32
33 class MipsMCCodeEmitter : public MCCodeEmitter {
34   MipsMCCodeEmitter(const MipsMCCodeEmitter &) LLVM_DELETED_FUNCTION;
35   void operator=(const MipsMCCodeEmitter &) LLVM_DELETED_FUNCTION;
36   const MCInstrInfo &MCII;
37   MCContext &Ctx;
38   bool IsLittleEndian;
39
40   bool isMicroMips(const MCSubtargetInfo &STI) const;
41
42 public:
43   MipsMCCodeEmitter(const MCInstrInfo &mcii, MCContext &Ctx_, bool IsLittle)
44       : MCII(mcii), Ctx(Ctx_), IsLittleEndian(IsLittle) {}
45
46   ~MipsMCCodeEmitter() {}
47
48   void EmitByte(unsigned char C, raw_ostream &OS) const;
49
50   void EmitInstruction(uint64_t Val, unsigned Size, const MCSubtargetInfo &STI,
51                        raw_ostream &OS) const;
52
53   void EncodeInstruction(const MCInst &MI, raw_ostream &OS,
54                          SmallVectorImpl<MCFixup> &Fixups,
55                          const MCSubtargetInfo &STI) const override;
56
57   // getBinaryCodeForInstr - TableGen'erated function for getting the
58   // binary encoding for an instruction.
59   uint64_t getBinaryCodeForInstr(const MCInst &MI,
60                                  SmallVectorImpl<MCFixup> &Fixups,
61                                  const MCSubtargetInfo &STI) const;
62
63   // getBranchJumpOpValue - Return binary encoding of the jump
64   // target operand. If the machine operand requires relocation,
65   // record the relocation and return zero.
66   unsigned getJumpTargetOpValue(const MCInst &MI, unsigned OpNo,
67                                 SmallVectorImpl<MCFixup> &Fixups,
68                                 const MCSubtargetInfo &STI) const;
69
70   // getBranchJumpOpValueMM - Return binary encoding of the microMIPS jump
71   // target operand. If the machine operand requires relocation,
72   // record the relocation and return zero.
73   unsigned getJumpTargetOpValueMM(const MCInst &MI, unsigned OpNo,
74                                   SmallVectorImpl<MCFixup> &Fixups,
75                                   const MCSubtargetInfo &STI) const;
76
77   // getUImm5Lsl2Encoding - Return binary encoding of the microMIPS jump
78   // target operand.
79   unsigned getUImm5Lsl2Encoding(const MCInst &MI, unsigned OpNo,
80                                 SmallVectorImpl<MCFixup> &Fixups,
81                                 const MCSubtargetInfo &STI) const;
82
83   // getSImm9AddiuspValue - Return binary encoding of the microMIPS addiusp
84   // instruction immediate operand.
85   unsigned getSImm9AddiuspValue(const MCInst &MI, unsigned OpNo,
86                                 SmallVectorImpl<MCFixup> &Fixups,
87                                 const MCSubtargetInfo &STI) const;
88
89   // getBranchTargetOpValue - Return binary encoding of the branch
90   // target operand. If the machine operand requires relocation,
91   // record the relocation and return zero.
92   unsigned getBranchTargetOpValue(const MCInst &MI, unsigned OpNo,
93                                   SmallVectorImpl<MCFixup> &Fixups,
94                                   const MCSubtargetInfo &STI) const;
95
96   // getBranchTargetOpValue - Return binary encoding of the microMIPS branch
97   // target operand. If the machine operand requires relocation,
98   // record the relocation and return zero.
99   unsigned getBranchTargetOpValueMM(const MCInst &MI, unsigned OpNo,
100                                     SmallVectorImpl<MCFixup> &Fixups,
101                                     const MCSubtargetInfo &STI) const;
102
103   // getBranchTarget21OpValue - Return binary encoding of the branch
104   // offset operand. If the machine operand requires relocation,
105   // record the relocation and return zero.
106   unsigned getBranchTarget21OpValue(const MCInst &MI, unsigned OpNo,
107                                    SmallVectorImpl<MCFixup> &Fixups,
108                                    const MCSubtargetInfo &STI) const;
109
110   // getBranchTarget26OpValue - Return binary encoding of the branch
111   // offset operand. If the machine operand requires relocation,
112   // record the relocation and return zero.
113   unsigned getBranchTarget26OpValue(const MCInst &MI, unsigned OpNo,
114                                     SmallVectorImpl<MCFixup> &Fixups,
115                                     const MCSubtargetInfo &STI) const;
116
117   // getJumpOffset16OpValue - Return binary encoding of the jump
118   // offset operand. If the machine operand requires relocation,
119   // record the relocation and return zero.
120   unsigned getJumpOffset16OpValue(const MCInst &MI, unsigned OpNo,
121                                   SmallVectorImpl<MCFixup> &Fixups,
122                                   const MCSubtargetInfo &STI) const;
123
124   // getMachineOpValue - Return binary encoding of operand. If the machin
125   // operand requires relocation, record the relocation and return zero.
126   unsigned getMachineOpValue(const MCInst &MI, const MCOperand &MO,
127                              SmallVectorImpl<MCFixup> &Fixups,
128                              const MCSubtargetInfo &STI) const;
129
130   unsigned getMSAMemEncoding(const MCInst &MI, unsigned OpNo,
131                              SmallVectorImpl<MCFixup> &Fixups,
132                              const MCSubtargetInfo &STI) const;
133
134   unsigned getMemEncoding(const MCInst &MI, unsigned OpNo,
135                           SmallVectorImpl<MCFixup> &Fixups,
136                           const MCSubtargetInfo &STI) const;
137   unsigned getMemEncodingMMImm12(const MCInst &MI, unsigned OpNo,
138                                  SmallVectorImpl<MCFixup> &Fixups,
139                                  const MCSubtargetInfo &STI) const;
140   unsigned getSizeExtEncoding(const MCInst &MI, unsigned OpNo,
141                               SmallVectorImpl<MCFixup> &Fixups,
142                               const MCSubtargetInfo &STI) const;
143   unsigned getSizeInsEncoding(const MCInst &MI, unsigned OpNo,
144                               SmallVectorImpl<MCFixup> &Fixups,
145                               const MCSubtargetInfo &STI) const;
146
147   // getLSAImmEncoding - Return binary encoding of LSA immediate.
148   unsigned getLSAImmEncoding(const MCInst &MI, unsigned OpNo,
149                              SmallVectorImpl<MCFixup> &Fixups,
150                              const MCSubtargetInfo &STI) const;
151
152   unsigned getSimm19Lsl2Encoding(const MCInst &MI, unsigned OpNo,
153                                  SmallVectorImpl<MCFixup> &Fixups,
154                                  const MCSubtargetInfo &STI) const;
155
156   unsigned getSimm18Lsl3Encoding(const MCInst &MI, unsigned OpNo,
157                                  SmallVectorImpl<MCFixup> &Fixups,
158                                  const MCSubtargetInfo &STI) const;
159
160   unsigned getUImm3Mod8Encoding(const MCInst &MI, unsigned OpNo,
161                                 SmallVectorImpl<MCFixup> &Fixups,
162                                 const MCSubtargetInfo &STI) const;
163
164   unsigned getExprOpValue(const MCExpr *Expr, SmallVectorImpl<MCFixup> &Fixups,
165                           const MCSubtargetInfo &STI) const;
166
167 }; // class MipsMCCodeEmitter
168 } // namespace llvm.
169
170 #endif