xref: /minix3/external/bsd/llvm/dist/llvm/lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.h (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc //===-- MipsMCCodeEmitter.h - Convert Mips Code to Machine Code -----------===//
2*0a6a1f1dSLionel Sambuc //
3*0a6a1f1dSLionel Sambuc //                     The LLVM Compiler Infrastructure
4*0a6a1f1dSLionel Sambuc //
5*0a6a1f1dSLionel Sambuc // This file is distributed under the University of Illinois Open Source
6*0a6a1f1dSLionel Sambuc // License. See LICENSE.TXT for details.
7*0a6a1f1dSLionel Sambuc //
8*0a6a1f1dSLionel Sambuc //===----------------------------------------------------------------------===//
9*0a6a1f1dSLionel Sambuc //
10*0a6a1f1dSLionel Sambuc // This file defines the MipsMCCodeEmitter class.
11*0a6a1f1dSLionel Sambuc //
12*0a6a1f1dSLionel Sambuc //===----------------------------------------------------------------------===//
13*0a6a1f1dSLionel Sambuc //
14*0a6a1f1dSLionel Sambuc 
15*0a6a1f1dSLionel Sambuc #ifndef LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSMCCODEEMITTER_H
16*0a6a1f1dSLionel Sambuc #define LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSMCCODEEMITTER_H
17*0a6a1f1dSLionel Sambuc 
18*0a6a1f1dSLionel Sambuc #include "llvm/MC/MCCodeEmitter.h"
19*0a6a1f1dSLionel Sambuc #include "llvm/Support/DataTypes.h"
20*0a6a1f1dSLionel Sambuc 
21*0a6a1f1dSLionel Sambuc using namespace llvm;
22*0a6a1f1dSLionel Sambuc 
23*0a6a1f1dSLionel Sambuc namespace llvm {
24*0a6a1f1dSLionel Sambuc class MCContext;
25*0a6a1f1dSLionel Sambuc class MCExpr;
26*0a6a1f1dSLionel Sambuc class MCInst;
27*0a6a1f1dSLionel Sambuc class MCInstrInfo;
28*0a6a1f1dSLionel Sambuc class MCFixup;
29*0a6a1f1dSLionel Sambuc class MCOperand;
30*0a6a1f1dSLionel Sambuc class MCSubtargetInfo;
31*0a6a1f1dSLionel Sambuc class raw_ostream;
32*0a6a1f1dSLionel Sambuc 
33*0a6a1f1dSLionel Sambuc class MipsMCCodeEmitter : public MCCodeEmitter {
34*0a6a1f1dSLionel Sambuc   MipsMCCodeEmitter(const MipsMCCodeEmitter &) LLVM_DELETED_FUNCTION;
35*0a6a1f1dSLionel Sambuc   void operator=(const MipsMCCodeEmitter &) LLVM_DELETED_FUNCTION;
36*0a6a1f1dSLionel Sambuc   const MCInstrInfo &MCII;
37*0a6a1f1dSLionel Sambuc   MCContext &Ctx;
38*0a6a1f1dSLionel Sambuc   bool IsLittleEndian;
39*0a6a1f1dSLionel Sambuc 
40*0a6a1f1dSLionel Sambuc   bool isMicroMips(const MCSubtargetInfo &STI) const;
41*0a6a1f1dSLionel Sambuc 
42*0a6a1f1dSLionel Sambuc public:
MipsMCCodeEmitter(const MCInstrInfo & mcii,MCContext & Ctx_,bool IsLittle)43*0a6a1f1dSLionel Sambuc   MipsMCCodeEmitter(const MCInstrInfo &mcii, MCContext &Ctx_, bool IsLittle)
44*0a6a1f1dSLionel Sambuc       : MCII(mcii), Ctx(Ctx_), IsLittleEndian(IsLittle) {}
45*0a6a1f1dSLionel Sambuc 
~MipsMCCodeEmitter()46*0a6a1f1dSLionel Sambuc   ~MipsMCCodeEmitter() {}
47*0a6a1f1dSLionel Sambuc 
48*0a6a1f1dSLionel Sambuc   void EmitByte(unsigned char C, raw_ostream &OS) const;
49*0a6a1f1dSLionel Sambuc 
50*0a6a1f1dSLionel Sambuc   void EmitInstruction(uint64_t Val, unsigned Size, const MCSubtargetInfo &STI,
51*0a6a1f1dSLionel Sambuc                        raw_ostream &OS) const;
52*0a6a1f1dSLionel Sambuc 
53*0a6a1f1dSLionel Sambuc   void EncodeInstruction(const MCInst &MI, raw_ostream &OS,
54*0a6a1f1dSLionel Sambuc                          SmallVectorImpl<MCFixup> &Fixups,
55*0a6a1f1dSLionel Sambuc                          const MCSubtargetInfo &STI) const override;
56*0a6a1f1dSLionel Sambuc 
57*0a6a1f1dSLionel Sambuc   // getBinaryCodeForInstr - TableGen'erated function for getting the
58*0a6a1f1dSLionel Sambuc   // binary encoding for an instruction.
59*0a6a1f1dSLionel Sambuc   uint64_t getBinaryCodeForInstr(const MCInst &MI,
60*0a6a1f1dSLionel Sambuc                                  SmallVectorImpl<MCFixup> &Fixups,
61*0a6a1f1dSLionel Sambuc                                  const MCSubtargetInfo &STI) const;
62*0a6a1f1dSLionel Sambuc 
63*0a6a1f1dSLionel Sambuc   // getJumpTargetOpValue - Return binary encoding of the jump
64*0a6a1f1dSLionel Sambuc   // target operand. If the machine operand requires relocation,
65*0a6a1f1dSLionel Sambuc   // record the relocation and return zero.
66*0a6a1f1dSLionel Sambuc   unsigned getJumpTargetOpValue(const MCInst &MI, unsigned OpNo,
67*0a6a1f1dSLionel Sambuc                                 SmallVectorImpl<MCFixup> &Fixups,
68*0a6a1f1dSLionel Sambuc                                 const MCSubtargetInfo &STI) const;
69*0a6a1f1dSLionel Sambuc 
70*0a6a1f1dSLionel Sambuc   // getBranchJumpOpValueMM - Return binary encoding of the microMIPS jump
71*0a6a1f1dSLionel Sambuc   // target operand. If the machine operand requires relocation,
72*0a6a1f1dSLionel Sambuc   // record the relocation and return zero.
73*0a6a1f1dSLionel Sambuc   unsigned getJumpTargetOpValueMM(const MCInst &MI, unsigned OpNo,
74*0a6a1f1dSLionel Sambuc                                   SmallVectorImpl<MCFixup> &Fixups,
75*0a6a1f1dSLionel Sambuc                                   const MCSubtargetInfo &STI) const;
76*0a6a1f1dSLionel Sambuc 
77*0a6a1f1dSLionel Sambuc   // getUImm5Lsl2Encoding - Return binary encoding of the microMIPS jump
78*0a6a1f1dSLionel Sambuc   // target operand.
79*0a6a1f1dSLionel Sambuc   unsigned getUImm5Lsl2Encoding(const MCInst &MI, unsigned OpNo,
80*0a6a1f1dSLionel Sambuc                                 SmallVectorImpl<MCFixup> &Fixups,
81*0a6a1f1dSLionel Sambuc                                 const MCSubtargetInfo &STI) const;
82*0a6a1f1dSLionel Sambuc 
83*0a6a1f1dSLionel Sambuc   unsigned getSImm3Lsa2Value(const MCInst &MI, unsigned OpNo,
84*0a6a1f1dSLionel Sambuc                              SmallVectorImpl<MCFixup> &Fixups,
85*0a6a1f1dSLionel Sambuc                              const MCSubtargetInfo &STI) const;
86*0a6a1f1dSLionel Sambuc 
87*0a6a1f1dSLionel Sambuc   unsigned getUImm6Lsl2Encoding(const MCInst &MI, unsigned OpNo,
88*0a6a1f1dSLionel Sambuc                                 SmallVectorImpl<MCFixup> &Fixups,
89*0a6a1f1dSLionel Sambuc                                 const MCSubtargetInfo &STI) const;
90*0a6a1f1dSLionel Sambuc 
91*0a6a1f1dSLionel Sambuc   // getSImm9AddiuspValue - Return binary encoding of the microMIPS addiusp
92*0a6a1f1dSLionel Sambuc   // instruction immediate operand.
93*0a6a1f1dSLionel Sambuc   unsigned getSImm9AddiuspValue(const MCInst &MI, unsigned OpNo,
94*0a6a1f1dSLionel Sambuc                                 SmallVectorImpl<MCFixup> &Fixups,
95*0a6a1f1dSLionel Sambuc                                 const MCSubtargetInfo &STI) const;
96*0a6a1f1dSLionel Sambuc 
97*0a6a1f1dSLionel Sambuc   // getBranchTargetOpValue - Return binary encoding of the branch
98*0a6a1f1dSLionel Sambuc   // target operand. If the machine operand requires relocation,
99*0a6a1f1dSLionel Sambuc   // record the relocation and return zero.
100*0a6a1f1dSLionel Sambuc   unsigned getBranchTargetOpValue(const MCInst &MI, unsigned OpNo,
101*0a6a1f1dSLionel Sambuc                                   SmallVectorImpl<MCFixup> &Fixups,
102*0a6a1f1dSLionel Sambuc                                   const MCSubtargetInfo &STI) const;
103*0a6a1f1dSLionel Sambuc 
104*0a6a1f1dSLionel Sambuc   // getBranchTarget7OpValue - Return binary encoding of the microMIPS branch
105*0a6a1f1dSLionel Sambuc   // target operand. If the machine operand requires relocation,
106*0a6a1f1dSLionel Sambuc   // record the relocation and return zero.
107*0a6a1f1dSLionel Sambuc   unsigned getBranchTarget7OpValueMM(const MCInst &MI, unsigned OpNo,
108*0a6a1f1dSLionel Sambuc                                      SmallVectorImpl<MCFixup> &Fixups,
109*0a6a1f1dSLionel Sambuc                                      const MCSubtargetInfo &STI) const;
110*0a6a1f1dSLionel Sambuc 
111*0a6a1f1dSLionel Sambuc   // getBranchTargetOpValue - Return binary encoding of the microMIPS branch
112*0a6a1f1dSLionel Sambuc   // target operand. If the machine operand requires relocation,
113*0a6a1f1dSLionel Sambuc   // record the relocation and return zero.
114*0a6a1f1dSLionel Sambuc   unsigned getBranchTargetOpValueMM(const MCInst &MI, unsigned OpNo,
115*0a6a1f1dSLionel Sambuc                                     SmallVectorImpl<MCFixup> &Fixups,
116*0a6a1f1dSLionel Sambuc                                     const MCSubtargetInfo &STI) const;
117*0a6a1f1dSLionel Sambuc 
118*0a6a1f1dSLionel Sambuc   // getBranchTarget21OpValue - Return binary encoding of the branch
119*0a6a1f1dSLionel Sambuc   // offset operand. If the machine operand requires relocation,
120*0a6a1f1dSLionel Sambuc   // record the relocation and return zero.
121*0a6a1f1dSLionel Sambuc   unsigned getBranchTarget21OpValue(const MCInst &MI, unsigned OpNo,
122*0a6a1f1dSLionel Sambuc                                    SmallVectorImpl<MCFixup> &Fixups,
123*0a6a1f1dSLionel Sambuc                                    const MCSubtargetInfo &STI) const;
124*0a6a1f1dSLionel Sambuc 
125*0a6a1f1dSLionel Sambuc   // getBranchTarget26OpValue - Return binary encoding of the branch
126*0a6a1f1dSLionel Sambuc   // offset operand. If the machine operand requires relocation,
127*0a6a1f1dSLionel Sambuc   // record the relocation and return zero.
128*0a6a1f1dSLionel Sambuc   unsigned getBranchTarget26OpValue(const MCInst &MI, unsigned OpNo,
129*0a6a1f1dSLionel Sambuc                                     SmallVectorImpl<MCFixup> &Fixups,
130*0a6a1f1dSLionel Sambuc                                     const MCSubtargetInfo &STI) const;
131*0a6a1f1dSLionel Sambuc 
132*0a6a1f1dSLionel Sambuc   // getJumpOffset16OpValue - Return binary encoding of the jump
133*0a6a1f1dSLionel Sambuc   // offset operand. If the machine operand requires relocation,
134*0a6a1f1dSLionel Sambuc   // record the relocation and return zero.
135*0a6a1f1dSLionel Sambuc   unsigned getJumpOffset16OpValue(const MCInst &MI, unsigned OpNo,
136*0a6a1f1dSLionel Sambuc                                   SmallVectorImpl<MCFixup> &Fixups,
137*0a6a1f1dSLionel Sambuc                                   const MCSubtargetInfo &STI) const;
138*0a6a1f1dSLionel Sambuc 
139*0a6a1f1dSLionel Sambuc   // getMachineOpValue - Return binary encoding of operand. If the machin
140*0a6a1f1dSLionel Sambuc   // operand requires relocation, record the relocation and return zero.
141*0a6a1f1dSLionel Sambuc   unsigned getMachineOpValue(const MCInst &MI, const MCOperand &MO,
142*0a6a1f1dSLionel Sambuc                              SmallVectorImpl<MCFixup> &Fixups,
143*0a6a1f1dSLionel Sambuc                              const MCSubtargetInfo &STI) const;
144*0a6a1f1dSLionel Sambuc 
145*0a6a1f1dSLionel Sambuc   unsigned getMSAMemEncoding(const MCInst &MI, unsigned OpNo,
146*0a6a1f1dSLionel Sambuc                              SmallVectorImpl<MCFixup> &Fixups,
147*0a6a1f1dSLionel Sambuc                              const MCSubtargetInfo &STI) const;
148*0a6a1f1dSLionel Sambuc 
149*0a6a1f1dSLionel Sambuc   unsigned getMemEncoding(const MCInst &MI, unsigned OpNo,
150*0a6a1f1dSLionel Sambuc                           SmallVectorImpl<MCFixup> &Fixups,
151*0a6a1f1dSLionel Sambuc                           const MCSubtargetInfo &STI) const;
152*0a6a1f1dSLionel Sambuc   unsigned getMemEncodingMMImm4(const MCInst &MI, unsigned OpNo,
153*0a6a1f1dSLionel Sambuc                                 SmallVectorImpl<MCFixup> &Fixups,
154*0a6a1f1dSLionel Sambuc                                 const MCSubtargetInfo &STI) const;
155*0a6a1f1dSLionel Sambuc   unsigned getMemEncodingMMImm4Lsl1(const MCInst &MI, unsigned OpNo,
156*0a6a1f1dSLionel Sambuc                                     SmallVectorImpl<MCFixup> &Fixups,
157*0a6a1f1dSLionel Sambuc                                     const MCSubtargetInfo &STI) const;
158*0a6a1f1dSLionel Sambuc   unsigned getMemEncodingMMImm4Lsl2(const MCInst &MI, unsigned OpNo,
159*0a6a1f1dSLionel Sambuc                                     SmallVectorImpl<MCFixup> &Fixups,
160*0a6a1f1dSLionel Sambuc                                     const MCSubtargetInfo &STI) const;
161*0a6a1f1dSLionel Sambuc   unsigned getMemEncodingMMSPImm5Lsl2(const MCInst &MI, unsigned OpNo,
162*0a6a1f1dSLionel Sambuc                                       SmallVectorImpl<MCFixup> &Fixups,
163*0a6a1f1dSLionel Sambuc                                       const MCSubtargetInfo &STI) const;
164*0a6a1f1dSLionel Sambuc   unsigned getMemEncodingMMImm12(const MCInst &MI, unsigned OpNo,
165*0a6a1f1dSLionel Sambuc                                  SmallVectorImpl<MCFixup> &Fixups,
166*0a6a1f1dSLionel Sambuc                                  const MCSubtargetInfo &STI) const;
167*0a6a1f1dSLionel Sambuc   unsigned getMemEncodingMMImm4sp(const MCInst &MI, unsigned OpNo,
168*0a6a1f1dSLionel Sambuc                                   SmallVectorImpl<MCFixup> &Fixups,
169*0a6a1f1dSLionel Sambuc                                   const MCSubtargetInfo &STI) const;
170*0a6a1f1dSLionel Sambuc   unsigned getSizeExtEncoding(const MCInst &MI, unsigned OpNo,
171*0a6a1f1dSLionel Sambuc                               SmallVectorImpl<MCFixup> &Fixups,
172*0a6a1f1dSLionel Sambuc                               const MCSubtargetInfo &STI) const;
173*0a6a1f1dSLionel Sambuc   unsigned getSizeInsEncoding(const MCInst &MI, unsigned OpNo,
174*0a6a1f1dSLionel Sambuc                               SmallVectorImpl<MCFixup> &Fixups,
175*0a6a1f1dSLionel Sambuc                               const MCSubtargetInfo &STI) const;
176*0a6a1f1dSLionel Sambuc 
177*0a6a1f1dSLionel Sambuc   // getLSAImmEncoding - Return binary encoding of LSA immediate.
178*0a6a1f1dSLionel Sambuc   unsigned getLSAImmEncoding(const MCInst &MI, unsigned OpNo,
179*0a6a1f1dSLionel Sambuc                              SmallVectorImpl<MCFixup> &Fixups,
180*0a6a1f1dSLionel Sambuc                              const MCSubtargetInfo &STI) const;
181*0a6a1f1dSLionel Sambuc 
182*0a6a1f1dSLionel Sambuc   unsigned getSimm19Lsl2Encoding(const MCInst &MI, unsigned OpNo,
183*0a6a1f1dSLionel Sambuc                                  SmallVectorImpl<MCFixup> &Fixups,
184*0a6a1f1dSLionel Sambuc                                  const MCSubtargetInfo &STI) const;
185*0a6a1f1dSLionel Sambuc 
186*0a6a1f1dSLionel Sambuc   unsigned getSimm18Lsl3Encoding(const MCInst &MI, unsigned OpNo,
187*0a6a1f1dSLionel Sambuc                                  SmallVectorImpl<MCFixup> &Fixups,
188*0a6a1f1dSLionel Sambuc                                  const MCSubtargetInfo &STI) const;
189*0a6a1f1dSLionel Sambuc 
190*0a6a1f1dSLionel Sambuc   unsigned getUImm3Mod8Encoding(const MCInst &MI, unsigned OpNo,
191*0a6a1f1dSLionel Sambuc                                 SmallVectorImpl<MCFixup> &Fixups,
192*0a6a1f1dSLionel Sambuc                                 const MCSubtargetInfo &STI) const;
193*0a6a1f1dSLionel Sambuc   unsigned getUImm4AndValue(const MCInst &MI, unsigned OpNo,
194*0a6a1f1dSLionel Sambuc                             SmallVectorImpl<MCFixup> &Fixups,
195*0a6a1f1dSLionel Sambuc                             const MCSubtargetInfo &STI) const;
196*0a6a1f1dSLionel Sambuc 
197*0a6a1f1dSLionel Sambuc   unsigned getRegisterPairOpValue(const MCInst &MI, unsigned OpNo,
198*0a6a1f1dSLionel Sambuc                                   SmallVectorImpl<MCFixup> &Fixups,
199*0a6a1f1dSLionel Sambuc                                   const MCSubtargetInfo &STI) const;
200*0a6a1f1dSLionel Sambuc 
201*0a6a1f1dSLionel Sambuc   unsigned getExprOpValue(const MCExpr *Expr, SmallVectorImpl<MCFixup> &Fixups,
202*0a6a1f1dSLionel Sambuc                           const MCSubtargetInfo &STI) const;
203*0a6a1f1dSLionel Sambuc 
204*0a6a1f1dSLionel Sambuc   unsigned getRegisterListOpValue(const MCInst &MI, unsigned OpNo,
205*0a6a1f1dSLionel Sambuc                                   SmallVectorImpl<MCFixup> &Fixups,
206*0a6a1f1dSLionel Sambuc                                   const MCSubtargetInfo &STI) const;
207*0a6a1f1dSLionel Sambuc 
208*0a6a1f1dSLionel Sambuc   unsigned getRegisterListOpValue16(const MCInst &MI, unsigned OpNo,
209*0a6a1f1dSLionel Sambuc                                     SmallVectorImpl<MCFixup> &Fixups,
210*0a6a1f1dSLionel Sambuc                                     const MCSubtargetInfo &STI) const;
211*0a6a1f1dSLionel Sambuc }; // class MipsMCCodeEmitter
212*0a6a1f1dSLionel Sambuc } // namespace llvm.
213*0a6a1f1dSLionel Sambuc 
214*0a6a1f1dSLionel Sambuc #endif
215