Path: blob/main/contrib/llvm-project/llvm/lib/Target/AVR/MCTargetDesc/AVRMCCodeEmitter.h
35294 views
//===-- AVRMCCodeEmitter.h - Convert AVR Code to Machine Code -------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file defines the AVRMCCodeEmitter class.9//10//===----------------------------------------------------------------------===//11//1213#ifndef LLVM_AVR_CODE_EMITTER_H14#define LLVM_AVR_CODE_EMITTER_H1516#include "AVRFixupKinds.h"1718#include "llvm/MC/MCCodeEmitter.h"19#include "llvm/Support/DataTypes.h"2021#define GET_INSTRINFO_OPERAND_TYPES_ENUM22#include "AVRGenInstrInfo.inc"2324namespace llvm {2526class MCContext;27class MCExpr;28class MCFixup;29class MCInst;30class MCInstrInfo;31class MCOperand;32class MCSubtargetInfo;33class raw_ostream;3435/// Writes AVR machine code to a stream.36class AVRMCCodeEmitter : public MCCodeEmitter {37public:38AVRMCCodeEmitter(const MCInstrInfo &MCII, MCContext &Ctx)39: MCII(MCII), Ctx(Ctx) {}4041private:42/// Finishes up encoding an LD/ST instruction.43/// The purpose of this function is to set an bit in the instruction44/// which follows no logical pattern. See the implementation for details.45unsigned loadStorePostEncoder(const MCInst &MI, unsigned EncodedValue,46const MCSubtargetInfo &STI) const;4748/// Gets the encoding for a conditional branch target.49template <AVR::Fixups Fixup>50unsigned encodeRelCondBrTarget(const MCInst &MI, unsigned OpNo,51SmallVectorImpl<MCFixup> &Fixups,52const MCSubtargetInfo &STI) const;5354/// Encodes the `PTRREGS` operand to a load or store instruction.55unsigned encodeLDSTPtrReg(const MCInst &MI, unsigned OpNo,56SmallVectorImpl<MCFixup> &Fixups,57const MCSubtargetInfo &STI) const;5859/// Encodes a `register+immediate` operand for `LDD`/`STD`.60unsigned encodeMemri(const MCInst &MI, unsigned OpNo,61SmallVectorImpl<MCFixup> &Fixups,62const MCSubtargetInfo &STI) const;6364/// Takes the complement of a number (~0 - val).65unsigned encodeComplement(const MCInst &MI, unsigned OpNo,66SmallVectorImpl<MCFixup> &Fixups,67const MCSubtargetInfo &STI) const;6869/// Encodes an immediate value with a given fixup.70/// \tparam Offset The offset into the instruction for the fixup.71template <AVR::Fixups Fixup, unsigned Offset>72unsigned encodeImm(const MCInst &MI, unsigned OpNo,73SmallVectorImpl<MCFixup> &Fixups,74const MCSubtargetInfo &STI) const;7576/// Gets the encoding of the target for the `CALL k` instruction.77unsigned encodeCallTarget(const MCInst &MI, unsigned OpNo,78SmallVectorImpl<MCFixup> &Fixups,79const MCSubtargetInfo &STI) const;8081/// TableGen'ed function to get the binary encoding for an instruction.82uint64_t getBinaryCodeForInstr(const MCInst &MI,83SmallVectorImpl<MCFixup> &Fixups,84const MCSubtargetInfo &STI) const;8586unsigned getExprOpValue(const MCExpr *Expr, SmallVectorImpl<MCFixup> &Fixups,87const MCSubtargetInfo &STI) const;8889/// Returns the binary encoding of operand.90///91/// If the machine operand requires relocation, the relocation is recorded92/// and zero is returned.93unsigned getMachineOpValue(const MCInst &MI, const MCOperand &MO,94SmallVectorImpl<MCFixup> &Fixups,95const MCSubtargetInfo &STI) const;9697void encodeInstruction(const MCInst &MI, SmallVectorImpl<char> &CB,98SmallVectorImpl<MCFixup> &Fixups,99const MCSubtargetInfo &STI) const override;100101AVRMCCodeEmitter(const AVRMCCodeEmitter &) = delete;102void operator=(const AVRMCCodeEmitter &) = delete;103104const MCInstrInfo &MCII;105MCContext &Ctx;106};107108} // namespace llvm109110#endif // LLVM_AVR_CODE_EMITTER_H111112113