Rizin
unix-like reverse engineering framework and cli tools
MCInst.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "MCInst.h"
#include "utils.h"

Go to the source code of this file.

Macros

#define MCINST_CACHE   (ARR_SIZE(mcInst->Operands) - 1)
 

Functions

void MCInst_Init (MCInst *inst)
 
void MCInst_clear (MCInst *inst)
 
void MCInst_insert0 (MCInst *inst, int index, MCOperand *Op)
 
void MCInst_setOpcode (MCInst *inst, unsigned Op)
 
void MCInst_setOpcodePub (MCInst *inst, unsigned Op)
 
unsigned MCInst_getOpcode (const MCInst *inst)
 
unsigned MCInst_getOpcodePub (const MCInst *inst)
 
MCOperandMCInst_getOperand (MCInst *inst, unsigned i)
 
unsigned MCInst_getNumOperands (const MCInst *inst)
 
void MCInst_addOperand2 (MCInst *inst, MCOperand *Op)
 
bool MCOperand_isValid (const MCOperand *op)
 
bool MCOperand_isReg (const MCOperand *op)
 
bool MCOperand_isImm (const MCOperand *op)
 
bool MCOperand_isFPImm (const MCOperand *op)
 
unsigned MCOperand_getReg (const MCOperand *op)
 getReg - Returns the register number. More...
 
void MCOperand_setReg (MCOperand *op, unsigned Reg)
 setReg - Set the register number. More...
 
int64_t MCOperand_getImm (MCOperand *op)
 
void MCOperand_setImm (MCOperand *op, int64_t Val)
 
double MCOperand_getFPImm (const MCOperand *op)
 
void MCOperand_setFPImm (MCOperand *op, double Val)
 
MCOperandMCOperand_CreateReg1 (MCInst *mcInst, unsigned Reg)
 
void MCOperand_CreateReg0 (MCInst *mcInst, unsigned Reg)
 
MCOperandMCOperand_CreateImm1 (MCInst *mcInst, int64_t Val)
 
void MCOperand_CreateImm0 (MCInst *mcInst, int64_t Val)
 

Macro Definition Documentation

◆ MCINST_CACHE

#define MCINST_CACHE   (ARR_SIZE(mcInst->Operands) - 1)

Definition at line 16 of file MCInst.c.

Function Documentation

◆ MCInst_addOperand2()

void MCInst_addOperand2 ( MCInst inst,
MCOperand Op 
)

Definition at line 89 of file MCInst.c.

90 {
91  inst->Operands[inst->size] = *Op;
92 
93  inst->size++;
94 }
uint8_t size
Definition: MCInst.h:90
MCOperand Operands[48]
Definition: MCInst.h:94

References MCInst::Operands, and MCInst::size.

◆ MCInst_clear()

void MCInst_clear ( MCInst inst)

Definition at line 40 of file MCInst.c.

41 {
42  inst->size = 0;
43 }

References MCInst::size.

◆ MCInst_getNumOperands()

unsigned MCInst_getNumOperands ( const MCInst inst)

Definition at line 83 of file MCInst.c.

84 {
85  return inst->size;
86 }

References MCInst::size.

◆ MCInst_getOpcode()

unsigned MCInst_getOpcode ( const MCInst inst)

Definition at line 68 of file MCInst.c.

69 {
70  return inst->Opcode;
71 }
unsigned Opcode
Definition: MCInst.h:93

References MCInst::Opcode.

◆ MCInst_getOpcodePub()

unsigned MCInst_getOpcodePub ( const MCInst inst)

Definition at line 73 of file MCInst.c.

74 {
75  return inst->OpcodePub;
76 }
unsigned OpcodePub
Definition: MCInst.h:89

References MCInst::OpcodePub.

Referenced by fill_insn().

◆ MCInst_getOperand()

MCOperand* MCInst_getOperand ( MCInst inst,
unsigned  i 
)

Definition at line 78 of file MCInst.c.

79 {
80  return &inst->Operands[i];
81 }
lzma_index ** i
Definition: index.h:629

References i, and MCInst::Operands.

◆ MCInst_Init()

void MCInst_Init ( MCInst inst)

Definition at line 18 of file MCInst.c.

19 {
20  unsigned int i;
21 
22  for (i = 0; i < 48; i++) {
23  inst->Operands[i].Kind = kInvalid;
24  inst->Operands[i].ImmVal = 0;
25  }
26 
27  memset(inst, 0, sizeof(MCInst));
28  inst->Opcode = 0;
29  inst->OpcodePub = 0;
30  inst->size = 0;
31  inst->has_imm = false;
32  inst->op1_size = 0;
33  inst->writeback = false;
34  inst->ac_idx = 0;
35  inst->popcode_adjust = 0;
36  inst->assembly[0] = '\0';
37  inst->xAcquireRelease = 0;
38 }
return memset(p, 0, total)
Definition: MCInst.h:88
uint8_t ac_idx
Definition: MCInst.h:107
uint8_t op1_size
Definition: MCInst.h:92
bool has_imm
Definition: MCInst.h:91
char assembly[8]
Definition: MCInst.h:109
uint8_t xAcquireRelease
Definition: MCInst.h:111
bool writeback
Definition: MCInst.h:105
uint8_t popcode_adjust
Definition: MCInst.h:108
unsigned char Kind
Definition: MCInst.h:37
int64_t ImmVal
Definition: MCInst.h:41

References MCInst::ac_idx, MCInst::assembly, MCInst::has_imm, i, MCOperand::ImmVal, MCOperand::Kind, memset(), MCInst::op1_size, MCInst::Opcode, MCInst::OpcodePub, MCInst::Operands, MCInst::popcode_adjust, MCInst::size, MCInst::writeback, and MCInst::xAcquireRelease.

Referenced by cs_disasm(), and cs_disasm_iter().

◆ MCInst_insert0()

void MCInst_insert0 ( MCInst inst,
int  index,
MCOperand Op 
)

Definition at line 46 of file MCInst.c.

47 {
48  int i;
49 
50  for(i = inst->size; i > index; i--)
51  //memcpy(&(inst->Operands[i]), &(inst->Operands[i-1]), sizeof(MCOperand));
52  inst->Operands[i] = inst->Operands[i-1];
53 
54  inst->Operands[index] = *Op;
55  inst->size++;
56 }

References i, MCInst::Operands, and MCInst::size.

◆ MCInst_setOpcode()

void MCInst_setOpcode ( MCInst inst,
unsigned  Op 
)

◆ MCInst_setOpcodePub()

void MCInst_setOpcodePub ( MCInst inst,
unsigned  Op 
)

Definition at line 63 of file MCInst.c.

64 {
65  inst->OpcodePub = Op;
66 }

References MCInst::OpcodePub.

◆ MCOperand_CreateImm0()

void MCOperand_CreateImm0 ( MCInst mcInst,
int64_t  Val 
)

Definition at line 177 of file MCInst.c.

178 {
179  MCOperand *op = &(mcInst->Operands[mcInst->size]);
180  mcInst->size++;
181 
182  op->Kind = kImmediate;
183  op->ImmVal = Val;
184 }
Definition: dis.c:32

References MCInst::Operands, and MCInst::size.

◆ MCOperand_CreateImm1()

MCOperand* MCOperand_CreateImm1 ( MCInst mcInst,
int64_t  Val 
)

Definition at line 167 of file MCInst.c.

168 {
169  MCOperand *op = &(mcInst->Operands[MCINST_CACHE]);
170 
171  op->Kind = kImmediate;
172  op->ImmVal = Val;
173 
174  return op;
175 }
ut8 op
Definition: 6502dis.c:13
#define MCINST_CACHE
Definition: MCInst.c:16

References MCINST_CACHE, op, and MCInst::Operands.

◆ MCOperand_CreateReg0()

void MCOperand_CreateReg0 ( MCInst mcInst,
unsigned  Reg 
)

Definition at line 158 of file MCInst.c.

159 {
160  MCOperand *op = &(mcInst->Operands[mcInst->size]);
161  mcInst->size++;
162 
163  op->Kind = kRegister;
164  op->RegVal = Reg;
165 }

References MCInst::Operands, and MCInst::size.

◆ MCOperand_CreateReg1()

MCOperand* MCOperand_CreateReg1 ( MCInst mcInst,
unsigned  Reg 
)

Definition at line 148 of file MCInst.c.

149 {
150  MCOperand *op = &(mcInst->Operands[MCINST_CACHE]);
151 
152  op->Kind = kRegister;
153  op->RegVal = Reg;
154 
155  return op;
156 }

References MCINST_CACHE, op, and MCInst::Operands.

◆ MCOperand_getFPImm()

double MCOperand_getFPImm ( const MCOperand op)

Definition at line 138 of file MCInst.c.

139 {
140  return op->FPImmVal;
141 }

◆ MCOperand_getImm()

int64_t MCOperand_getImm ( MCOperand op)

Definition at line 128 of file MCInst.c.

129 {
130  return op->ImmVal;
131 }

◆ MCOperand_getReg()

unsigned MCOperand_getReg ( const MCOperand op)

getReg - Returns the register number.

Definition at line 117 of file MCInst.c.

118 {
119  return op->RegVal;
120 }

◆ MCOperand_isFPImm()

bool MCOperand_isFPImm ( const MCOperand op)

Definition at line 111 of file MCInst.c.

112 {
113  return op->Kind == kFPImmediate;
114 }

◆ MCOperand_isImm()

bool MCOperand_isImm ( const MCOperand op)

Definition at line 106 of file MCInst.c.

107 {
108  return op->Kind == kImmediate;
109 }

◆ MCOperand_isReg()

bool MCOperand_isReg ( const MCOperand op)

Definition at line 101 of file MCInst.c.

102 {
103  return op->Kind == kRegister;
104 }

◆ MCOperand_isValid()

bool MCOperand_isValid ( const MCOperand op)

Definition at line 96 of file MCInst.c.

97 {
98  return op->Kind != kInvalid;
99 }

◆ MCOperand_setFPImm()

void MCOperand_setFPImm ( MCOperand op,
double  Val 
)

Definition at line 143 of file MCInst.c.

144 {
145  op->FPImmVal = Val;
146 }

◆ MCOperand_setImm()

void MCOperand_setImm ( MCOperand op,
int64_t  Val 
)

Definition at line 133 of file MCInst.c.

134 {
135  op->ImmVal = Val;
136 }

◆ MCOperand_setReg()

void MCOperand_setReg ( MCOperand op,
unsigned  Reg 
)

setReg - Set the register number.

Definition at line 123 of file MCInst.c.

124 {
125  op->RegVal = Reg;
126 }