MCInst.h
Go to the documentation of this file.
1 //===-- llvm/MC/MCInst.h - MCInst class -------------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains the declaration of the MCInst and MCOperand classes, which
11 // is the basic representation used to represent low-level machine code
12 // instructions.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 /* Capstone Disassembly Engine */
17 /* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2015 */
18 
19 #ifndef CS_MCINST_H
20 #define CS_MCINST_H
21 
23 
24 typedef struct MCInst MCInst;
25 typedef struct cs_struct cs_struct;
26 typedef struct MCOperand MCOperand;
27 
30 struct MCOperand {
31  enum {
32  kInvalid = 0,
37  unsigned char Kind;
38 
39  union {
40  unsigned RegVal;
42  double FPImmVal;
43  };
44 };
45 
46 bool MCOperand_isValid(const MCOperand *op);
47 
48 bool MCOperand_isReg(const MCOperand *op);
49 
50 bool MCOperand_isImm(const MCOperand *op);
51 
52 bool MCOperand_isFPImm(const MCOperand *op);
53 
54 bool MCOperand_isInst(const MCOperand *op);
55 
57 unsigned MCOperand_getReg(const MCOperand *op);
58 
60 void MCOperand_setReg(MCOperand *op, unsigned Reg);
61 
63 
65 
66 double MCOperand_getFPImm(const MCOperand *op);
67 
68 void MCOperand_setFPImm(MCOperand *op, double Val);
69 
70 const MCInst *MCOperand_getInst(const MCOperand *op);
71 
72 void MCOperand_setInst(MCOperand *op, const MCInst *Val);
73 
74 // create Reg operand in the next slot
75 void MCOperand_CreateReg0(MCInst *inst, unsigned Reg);
76 
77 // create Reg operand use the last-unused slot
78 MCOperand *MCOperand_CreateReg1(MCInst *inst, unsigned Reg);
79 
80 // create Imm operand in the next slot
81 void MCOperand_CreateImm0(MCInst *inst, int64_t Val);
82 
83 // create Imm operand in the last-unused slot
85 
88 struct MCInst {
89  unsigned OpcodePub;
90  uint8_t size; // number of operands
91  bool has_imm; // indicate this instruction has an X86_OP_IMM operand - used for ATT syntax
92  uint8_t op1_size; // size of 1st operand - for X86 Intel syntax
93  unsigned Opcode;
95  cs_insn *flat_insn; // insn to be exposed to public
96  uint64_t address; // address of this insn
97  cs_struct *csh; // save the main csh
98  uint8_t x86opsize; // opsize for [mem] operand
99 
100  // (Optional) instruction prefix, which can be up to 4 bytes.
101  // A prefix byte gets value 0 when irrelevant.
102  // This is copied from cs_x86 struct
104  uint8_t imm_size; // immediate size for X86_OP_IMM operand
105  bool writeback; // writeback for ARM
106  // operand access index for list of registers sharing the same access right (for ARM)
108  uint8_t popcode_adjust; // Pseudo X86 instruction adjust
109  char assembly[8]; // for special instruction, so that we dont need printer
110  unsigned char evm_data[32]; // for EVM PUSH operand
111 };
112 
113 void MCInst_Init(MCInst *inst);
114 
115 void MCInst_clear(MCInst *inst);
116 
117 // do not free operand after inserting
118 void MCInst_insert0(MCInst *inst, int index, MCOperand *Op);
119 
120 void MCInst_setOpcode(MCInst *inst, unsigned Op);
121 
122 unsigned MCInst_getOpcode(const MCInst*);
123 
124 void MCInst_setOpcodePub(MCInst *inst, unsigned Op);
125 
126 unsigned MCInst_getOpcodePub(const MCInst*);
127 
128 MCOperand *MCInst_getOperand(MCInst *inst, unsigned i);
129 
130 unsigned MCInst_getNumOperands(const MCInst *inst);
131 
132 // This addOperand2 function doesnt free Op
133 void MCInst_addOperand2(MCInst *inst, MCOperand *Op);
134 
135 #endif
MCInst_insert0
void MCInst_insert0(MCInst *inst, int index, MCOperand *Op)
Definition: MCInst.c:43
MCInst_getOperand
MCOperand * MCInst_getOperand(MCInst *inst, unsigned i)
Definition: MCInst.c:75
MCOperand_setReg
void MCOperand_setReg(MCOperand *op, unsigned Reg)
setReg - Set the register number.
Definition: MCInst.c:120
MCOperand
Definition: MCInst.h:30
MCInst::size
uint8_t size
Definition: MCInst.h:90
MCInst::Opcode
unsigned Opcode
Definition: MCInst.h:93
MCInst::address
uint64_t address
Definition: MCInst.h:96
MCOperand::FPImmVal
double FPImmVal
Definition: MCInst.h:42
MCInst::assembly
char assembly[8]
Definition: MCInst.h:109
MCOperand_getReg
unsigned MCOperand_getReg(const MCOperand *op)
getReg - Returns the register number.
Definition: MCInst.c:114
MCInst::popcode_adjust
uint8_t popcode_adjust
Definition: MCInst.h:108
MCOperand_getImm
int64_t MCOperand_getImm(MCOperand *op)
Definition: MCInst.c:125
MCOperand::RegVal
unsigned RegVal
Definition: MCInst.h:40
MCInst::has_imm
bool has_imm
Definition: MCInst.h:91
uint8_t
unsigned char uint8_t
Definition: stdint-msvc2008.h:78
MCInst::csh
cs_struct * csh
Definition: MCInst.h:97
MCOperand::kInvalid
@ kInvalid
Uninitialized.
Definition: MCInst.h:32
cs_struct
Definition: cs_priv.h:51
MCOperand_isInst
bool MCOperand_isInst(const MCOperand *op)
capstone.h
MCOperand_isFPImm
bool MCOperand_isFPImm(const MCOperand *op)
Definition: MCInst.c:108
int64_t
signed __int64 int64_t
Definition: stdint-msvc2008.h:89
MCInst::imm_size
uint8_t imm_size
Definition: MCInst.h:104
MCOperand_setInst
void MCOperand_setInst(MCOperand *op, const MCInst *Val)
uint64_t
unsigned __int64 uint64_t
Definition: stdint-msvc2008.h:90
MCOperand::kImmediate
@ kImmediate
Immediate operand.
Definition: MCInst.h:34
MCOperand_isValid
bool MCOperand_isValid(const MCOperand *op)
Definition: MCInst.c:93
MCInst::OpcodePub
unsigned OpcodePub
Definition: MCInst.h:89
MCInst::ac_idx
uint8_t ac_idx
Definition: MCInst.h:107
MCInst_getNumOperands
unsigned MCInst_getNumOperands(const MCInst *inst)
Definition: MCInst.c:80
MCOperand_CreateReg0
void MCOperand_CreateReg0(MCInst *inst, unsigned Reg)
Definition: MCInst.c:155
MCOperand_CreateImm0
void MCOperand_CreateImm0(MCInst *inst, int64_t Val)
Definition: MCInst.c:174
MCOperand_CreateReg1
MCOperand * MCOperand_CreateReg1(MCInst *inst, unsigned Reg)
Definition: MCInst.c:145
MCInst
Definition: MCInst.h:88
MCOperand_CreateImm1
MCOperand * MCOperand_CreateImm1(MCInst *inst, int64_t Val)
Definition: MCInst.c:164
x86_prefix
x86_prefix
Instruction prefixes - to be used in cs_x86.prefix[].
Definition: x86.h:247
MCInst_addOperand2
void MCInst_addOperand2(MCInst *inst, MCOperand *Op)
Definition: MCInst.c:86
MCOperand_getFPImm
double MCOperand_getFPImm(const MCOperand *op)
Definition: MCInst.c:135
MCInst_setOpcode
void MCInst_setOpcode(MCInst *inst, unsigned Op)
Definition: MCInst.c:55
MCInst_Init
void MCInst_Init(MCInst *inst)
Definition: MCInst.c:18
MCInst_clear
void MCInst_clear(MCInst *inst)
Definition: MCInst.c:37
MCInst_getOpcode
unsigned MCInst_getOpcode(const MCInst *)
Definition: MCInst.c:65
index
int index
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:1184
MCInst::writeback
bool writeback
Definition: MCInst.h:105
MCInst::evm_data
unsigned char evm_data[32]
Definition: MCInst.h:110
MCInst::x86opsize
uint8_t x86opsize
Definition: MCInst.h:98
MCOperand::ImmVal
int64_t ImmVal
Definition: MCInst.h:41
MCOperand_setImm
void MCOperand_setImm(MCOperand *op, int64_t Val)
Definition: MCInst.c:130
MCOperand::kFPImmediate
@ kFPImmediate
Floating-point immediate operand.
Definition: MCInst.h:35
MCInst_setOpcodePub
void MCInst_setOpcodePub(MCInst *inst, unsigned Op)
Definition: MCInst.c:60
Reg
Reg
Definition: X86DisassemblerDecoder.h:466
MCOperand_isReg
bool MCOperand_isReg(const MCOperand *op)
Definition: MCInst.c:98
MCOperand_setFPImm
void MCOperand_setFPImm(MCOperand *op, double Val)
Definition: MCInst.c:140
MCInst::op1_size
uint8_t op1_size
Definition: MCInst.h:92
MCOperand::Kind
unsigned char Kind
Definition: MCInst.h:37
MCOperand_getInst
const MCInst * MCOperand_getInst(const MCOperand *op)
MCInst_getOpcodePub
unsigned MCInst_getOpcodePub(const MCInst *)
Definition: MCInst.c:70
MCOperand_isImm
bool MCOperand_isImm(const MCOperand *op)
Definition: MCInst.c:103
MCInst::Operands
MCOperand Operands[48]
Definition: MCInst.h:94
op
static grpc_op * op
Definition: test/core/fling/client.cc:47
MCInst::flat_insn
cs_insn * flat_insn
Definition: MCInst.h:95
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
MCOperand::MachineOperandType
enum MCOperand::@177 MachineOperandType
MCOperand::kRegister
@ kRegister
Register operand.
Definition: MCInst.h:33


grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:23