xref: /freebsd/contrib/llvm-project/llvm/lib/Target/CSKY/MCTargetDesc/CSKYMCCodeEmitter.h (revision 19261079b74319502c6ffa1249920079f0f69a72)
1 //===-- CSKYMCCodeEmitter.cpp - CSKY Code Emitter interface ---------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the CSKYMCCodeEmitter class.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_LIB_TARGET_CSKY_MCTARGETDESC_CSKYMCCODEEMITTER_H
14 #define LLVM_LIB_TARGET_CSKY_MCTARGETDESC_CSKYMCCODEEMITTER_H
15 
16 #include "llvm/MC/MCCodeEmitter.h"
17 #include "llvm/MC/MCContext.h"
18 
19 namespace llvm {
20 
21 class CSKYMCCodeEmitter : public MCCodeEmitter {
22   MCContext &Ctx;
23   const MCInstrInfo &MII;
24 
25 public:
26   CSKYMCCodeEmitter(MCContext &Ctx, const MCInstrInfo &MII)
27       : Ctx(Ctx), MII(MII) {}
28 
29   ~CSKYMCCodeEmitter() {}
30 
31   void encodeInstruction(const MCInst &Inst, raw_ostream &OS,
32                          SmallVectorImpl<MCFixup> &Fixups,
33                          const MCSubtargetInfo &STI) const override;
34 
35   // Generated by tablegen.
36   uint64_t getBinaryCodeForInstr(const MCInst &MI,
37                                  SmallVectorImpl<MCFixup> &Fixups,
38                                  const MCSubtargetInfo &STI) const;
39 
40   // Default encoding method used by tablegen.
41   unsigned getMachineOpValue(const MCInst &MI, const MCOperand &MO,
42                              SmallVectorImpl<MCFixup> &Fixups,
43                              const MCSubtargetInfo &STI) const;
44 
45   template <int shift = 0>
46   unsigned getImmOpValue(const MCInst &MI, unsigned Idx,
47                          SmallVectorImpl<MCFixup> &Fixups,
48                          const MCSubtargetInfo &STI) const {
49     const MCOperand &MO = MI.getOperand(Idx);
50     assert(MO.isImm() && "Unexpected MO type.");
51     return (MO.getImm() >> shift);
52   }
53 
54   unsigned getOImmOpValue(const MCInst &MI, unsigned Idx,
55                           SmallVectorImpl<MCFixup> &Fixups,
56                           const MCSubtargetInfo &STI) const;
57 };
58 
59 } // namespace llvm
60 
61 #endif // LLVM_LIB_TARGET_CSKY_MCTARGETDESC_CSKYMCCODEEMITTER_H
62