1 //===- llvm/MC/MCCodeEmitter.h - Instruction Encoding -----------*- C++ -*-===// 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 #ifndef LLVM_MC_MCCODEEMITTER_H 10 #define LLVM_MC_MCCODEEMITTER_H 11 12 namespace llvm { 13 14 class MCFixup; 15 class MCInst; 16 class MCSubtargetInfo; 17 class raw_ostream; 18 template<typename T> class SmallVectorImpl; 19 20 /// MCCodeEmitter - Generic instruction encoding interface. 21 class MCCodeEmitter { 22 protected: // Can only create subclasses. 23 MCCodeEmitter(); 24 25 public: 26 MCCodeEmitter(const MCCodeEmitter &) = delete; 27 MCCodeEmitter &operator=(const MCCodeEmitter &) = delete; 28 virtual ~MCCodeEmitter(); 29 30 /// Lifetime management reset()31 virtual void reset() {} 32 33 /// Append the prefixes of given instruction to the code buffer. 34 /// 35 /// \param Inst a single low-level machine instruction. 36 /// \param CB code buffer emitPrefix(const MCInst & Inst,SmallVectorImpl<char> & CB,const MCSubtargetInfo & STI)37 virtual void emitPrefix(const MCInst &Inst, SmallVectorImpl<char> &CB, 38 const MCSubtargetInfo &STI) const {} 39 /// Encode the given \p Inst to bytes and append to \p CB. 40 virtual void encodeInstruction(const MCInst &Inst, SmallVectorImpl<char> &CB, 41 SmallVectorImpl<MCFixup> &Fixups, 42 const MCSubtargetInfo &STI) const = 0; 43 }; 44 45 } // end namespace llvm 46 47 #endif // LLVM_MC_MCCODEEMITTER_H 48