//===-- llvm/MC/MCInst.h - MCInst class -------------------------*- C++ -*-===//1//2// The LLVM Compiler Infrastructure3//4// This file is distributed under the University of Illinois Open Source5// License. See LICENSE.TXT for details.6//7//===----------------------------------------------------------------------===//8//9// This file contains the declaration of the MCInst and MCOperand classes, which10// is the basic representation used to represent low-level machine code11// instructions.12//13//===----------------------------------------------------------------------===//1415/* Capstone Disassembly Engine */16/* By Nguyen Anh Quynh <[email protected]>, 2013-2019 */1718#ifndef CS_MCINST_H19#define CS_MCINST_H2021#include "include/capstone/capstone.h"22#include "MCInstrDesc.h"23#include "MCRegisterInfo.h"2425typedef struct MCInst MCInst;26typedef struct cs_struct cs_struct;27typedef struct MCOperand MCOperand;2829/// MCOperand - Instances of this class represent operands of the MCInst class.30/// This is a simple discriminated union.31struct MCOperand {32enum {33kInvalid = 0, ///< Uninitialized.34kRegister, ///< Register operand.35kImmediate, ///< Immediate operand.36kFPImmediate, ///< Floating-point immediate operand.37kDFPImmediate, ///< Double-Floating-point immediate operand.38kExpr, ///< Relocatable immediate operand.39kInst ///< Sub-instruction operand.4041} MachineOperandType;42unsigned char Kind;4344union {45unsigned RegVal;46int64_t ImmVal;47double FPImmVal;48};49};5051bool MCOperand_isValid(const MCOperand *op);5253bool MCOperand_isReg(const MCOperand *op);5455bool MCOperand_isImm(const MCOperand *op);5657bool MCOperand_isFPImm(const MCOperand *op);5859bool MCOperand_isDFPImm(const MCOperand *op);6061bool MCOperand_isExpr(const MCOperand *op);6263bool MCOperand_isInst(const MCOperand *op);6465/// getReg - Returns the register number.66unsigned MCOperand_getReg(const MCOperand *op);6768/// setReg - Set the register number.69void MCOperand_setReg(MCOperand *op, unsigned Reg);7071int64_t MCOperand_getImm(MCOperand *op);7273void MCOperand_setImm(MCOperand *op, int64_t Val);7475double MCOperand_getFPImm(const MCOperand *op);7677void MCOperand_setFPImm(MCOperand *op, double Val);7879const MCInst *MCOperand_getInst(const MCOperand *op);8081void MCOperand_setInst(MCOperand *op, const MCInst *Val);8283// create Reg operand in the next slot84void MCOperand_CreateReg0(MCInst *inst, unsigned Reg);8586// create Reg operand use the last-unused slot87MCOperand *MCOperand_CreateReg1(MCInst *inst, unsigned Reg);8889// create Imm operand in the next slot90void MCOperand_CreateImm0(MCInst *inst, int64_t Val);9192// create Imm operand in the last-unused slot93MCOperand *MCOperand_CreateImm1(MCInst *inst, int64_t Val);9495#define MAX_MC_OPS 489697/// MCInst - Instances of this class represent a single low-level machine98/// instruction.99struct MCInst {100unsigned OpcodePub; // public opcode (<arch>_INS_yyy in header files <arch>.h)101uint8_t size; // number of operands102bool has_imm; // indicate this instruction has an X86_OP_IMM operand - used for ATT syntax103uint8_t op1_size; // size of 1st operand - for X86 Intel syntax104unsigned Opcode; // private opcode105MCOperand Operands[MAX_MC_OPS];106cs_insn *flat_insn; // insn to be exposed to public107uint64_t address; // address of this insn108cs_struct *csh; // save the main csh109uint8_t x86opsize; // opsize for [mem] operand110111// These flags could be used to pass some info from one target subcomponent112// to another, for example, from disassembler to asm printer. The values of113// the flags have any sense on target level only (e.g. prefixes on x86).114unsigned flags;115116// (Optional) instruction prefix, which can be up to 4 bytes.117// A prefix byte gets value 0 when irrelevant.118// This is copied from cs_x86 struct119uint8_t x86_prefix[4];120uint8_t imm_size; // immediate size for X86_OP_IMM operand121bool writeback; // writeback for ARM122int8_t tied_op_idx123[MAX_MC_OPS]; ///< Tied operand indices. Index = Src op; Value: Dest op124// operand access index for list of registers sharing the same access right (for ARM)125uint8_t ac_idx;126uint8_t popcode_adjust; // Pseudo X86 instruction adjust127char assembly[8]; // for special instruction, so that we dont need printer128unsigned char evm_data[32]; // for EVM PUSH operand129cs_wasm_op wasm_data; // for WASM operand130MCRegisterInfo *MRI;131uint8_t xAcquireRelease; // X86 xacquire/xrelease132};133134void MCInst_Init(MCInst *inst);135136void MCInst_clear(MCInst *inst);137138// do not free operand after inserting139void MCInst_insert0(MCInst *inst, int index, MCOperand *Op);140141void MCInst_setOpcode(MCInst *inst, unsigned Op);142143unsigned MCInst_getOpcode(const MCInst*);144145void MCInst_setOpcodePub(MCInst *inst, unsigned Op);146147unsigned MCInst_getOpcodePub(const MCInst*);148149MCOperand *MCInst_getOperand(MCInst *inst, unsigned i);150151unsigned MCInst_getNumOperands(const MCInst *inst);152153// This addOperand2 function doesnt free Op154void MCInst_addOperand2(MCInst *inst, MCOperand *Op);155156bool MCInst_isPredicable(const MCInstrDesc *MIDesc);157158void MCInst_handleWriteback(MCInst *MI, const MCInstrDesc *InstDesc);159160bool MCInst_opIsTied(const MCInst *MI, unsigned OpNum);161162bool MCInst_opIsTying(const MCInst *MI, unsigned OpNum);163164#endif165166167