MCInst.c
Go to the documentation of this file.
1 /* Capstone Disassembly Engine */
2 /* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2015 */
3 
4 #if defined(CAPSTONE_HAS_OSXKERNEL)
5 #include <Availability.h>
6 #include <libkern/libkern.h>
7 #else
8 #include <stdio.h>
9 #include <stdlib.h>
10 #endif
11 #include <string.h>
12 
13 #include "MCInst.h"
14 #include "utils.h"
15 
16 #define MCINST_CACHE (ARR_SIZE(mcInst->Operands) - 1)
17 
18 void MCInst_Init(MCInst *inst)
19 {
20  unsigned int i;
21 
22  for (i = 0; i < 48; i++) {
23  inst->Operands[i].Kind = kInvalid;
24  }
25 
26  inst->Opcode = 0;
27  inst->OpcodePub = 0;
28  inst->size = 0;
29  inst->has_imm = false;
30  inst->op1_size = 0;
31  inst->writeback = false;
32  inst->ac_idx = 0;
33  inst->popcode_adjust = 0;
34  inst->assembly[0] = '\0';
35 }
36 
37 void MCInst_clear(MCInst *inst)
38 {
39  inst->size = 0;
40 }
41 
42 // do not free @Op
43 void MCInst_insert0(MCInst *inst, int index, MCOperand *Op)
44 {
45  int i;
46 
47  for(i = inst->size; i > index; i--)
48  //memcpy(&(inst->Operands[i]), &(inst->Operands[i-1]), sizeof(MCOperand));
49  inst->Operands[i] = inst->Operands[i-1];
50 
51  inst->Operands[index] = *Op;
52  inst->size++;
53 }
54 
55 void MCInst_setOpcode(MCInst *inst, unsigned Op)
56 {
57  inst->Opcode = Op;
58 }
59 
60 void MCInst_setOpcodePub(MCInst *inst, unsigned Op)
61 {
62  inst->OpcodePub = Op;
63 }
64 
65 unsigned MCInst_getOpcode(const MCInst *inst)
66 {
67  return inst->Opcode;
68 }
69 
70 unsigned MCInst_getOpcodePub(const MCInst *inst)
71 {
72  return inst->OpcodePub;
73 }
74 
76 {
77  return &inst->Operands[i];
78 }
79 
80 unsigned MCInst_getNumOperands(const MCInst *inst)
81 {
82  return inst->size;
83 }
84 
85 // This addOperand2 function doesnt free Op
87 {
88  inst->Operands[inst->size] = *Op;
89 
90  inst->size++;
91 }
92 
94 {
95  return op->Kind != kInvalid;
96 }
97 
99 {
100  return op->Kind == kRegister;
101 }
102 
104 {
105  return op->Kind == kImmediate;
106 }
107 
109 {
110  return op->Kind == kFPImmediate;
111 }
112 
114 unsigned MCOperand_getReg(const MCOperand *op)
115 {
116  return op->RegVal;
117 }
118 
121 {
122  op->RegVal = Reg;
123 }
124 
126 {
127  return op->ImmVal;
128 }
129 
131 {
132  op->ImmVal = Val;
133 }
134 
136 {
137  return op->FPImmVal;
138 }
139 
140 void MCOperand_setFPImm(MCOperand *op, double Val)
141 {
142  op->FPImmVal = Val;
143 }
144 
146 {
147  MCOperand *op = &(mcInst->Operands[MCINST_CACHE]);
148 
149  op->Kind = kRegister;
150  op->RegVal = Reg;
151 
152  return op;
153 }
154 
155 void MCOperand_CreateReg0(MCInst *mcInst, unsigned Reg)
156 {
157  MCOperand *op = &(mcInst->Operands[mcInst->size]);
158  mcInst->size++;
159 
160  op->Kind = kRegister;
161  op->RegVal = Reg;
162 }
163 
165 {
166  MCOperand *op = &(mcInst->Operands[MCINST_CACHE]);
167 
168  op->Kind = kImmediate;
169  op->ImmVal = Val;
170 
171  return op;
172 }
173 
175 {
176  MCOperand *op = &(mcInst->Operands[mcInst->size]);
177  mcInst->size++;
178 
179  op->Kind = kImmediate;
180  op->ImmVal = Val;
181 }
MCOperand_getReg
unsigned MCOperand_getReg(const MCOperand *op)
getReg - Returns the register number.
Definition: MCInst.c:114
MCInst_addOperand2
void MCInst_addOperand2(MCInst *inst, MCOperand *Op)
Definition: MCInst.c:86
MCOperand
Definition: MCInst.h:30
MCOperand_isValid
bool MCOperand_isValid(const MCOperand *op)
Definition: MCInst.c:93
MCInst_insert0
void MCInst_insert0(MCInst *inst, int index, MCOperand *Op)
Definition: MCInst.c:43
MCInst::size
uint8_t size
Definition: MCInst.h:90
MCOperand_CreateReg0
void MCOperand_CreateReg0(MCInst *mcInst, unsigned Reg)
Definition: MCInst.c:155
MCInst::Opcode
unsigned Opcode
Definition: MCInst.h:93
MCInst::assembly
char assembly[8]
Definition: MCInst.h:109
string.h
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
MCInst::popcode_adjust
uint8_t popcode_adjust
Definition: MCInst.h:108
MCInst::has_imm
bool has_imm
Definition: MCInst.h:91
MCOperand_setFPImm
void MCOperand_setFPImm(MCOperand *op, double Val)
Definition: MCInst.c:140
MCInst_clear
void MCInst_clear(MCInst *inst)
Definition: MCInst.c:37
MCOperand_CreateImm1
MCOperand * MCOperand_CreateImm1(MCInst *mcInst, int64_t Val)
Definition: MCInst.c:164
MCOperand_getImm
int64_t MCOperand_getImm(MCOperand *op)
Definition: MCInst.c:125
MCOperand_isFPImm
bool MCOperand_isFPImm(const MCOperand *op)
Definition: MCInst.c:108
MCOperand_CreateImm0
void MCOperand_CreateImm0(MCInst *mcInst, int64_t Val)
Definition: MCInst.c:174
MCInst.h
MCInst_getNumOperands
unsigned MCInst_getNumOperands(const MCInst *inst)
Definition: MCInst.c:80
MCINST_CACHE
#define MCINST_CACHE
Definition: MCInst.c:16
int64_t
signed __int64 int64_t
Definition: stdint-msvc2008.h:89
utils.h
MCInst::OpcodePub
unsigned OpcodePub
Definition: MCInst.h:89
MCInst::ac_idx
uint8_t ac_idx
Definition: MCInst.h:107
MCInst_getOpcodePub
unsigned MCInst_getOpcodePub(const MCInst *inst)
Definition: MCInst.c:70
MCOperand_CreateReg1
MCOperand * MCOperand_CreateReg1(MCInst *mcInst, unsigned Reg)
Definition: MCInst.c:145
MCInst
Definition: MCInst.h:88
index
int index
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:1184
MCInst::writeback
bool writeback
Definition: MCInst.h:105
MCInst_Init
void MCInst_Init(MCInst *inst)
Definition: MCInst.c:18
MCInst_getOpcode
unsigned MCInst_getOpcode(const MCInst *inst)
Definition: MCInst.c:65
MCOperand_isImm
bool MCOperand_isImm(const MCOperand *op)
Definition: MCInst.c:103
MCOperand_setImm
void MCOperand_setImm(MCOperand *op, int64_t Val)
Definition: MCInst.c:130
MCOperand_getFPImm
double MCOperand_getFPImm(const MCOperand *op)
Definition: MCInst.c:135
WycheproofRawResult::kInvalid
@ kInvalid
Reg
Reg
Definition: X86DisassemblerDecoder.h:466
MCInst::op1_size
uint8_t op1_size
Definition: MCInst.h:92
MCOperand::Kind
unsigned char Kind
Definition: MCInst.h:37
MCInst_setOpcode
void MCInst_setOpcode(MCInst *inst, unsigned Op)
Definition: MCInst.c:55
MCInst_setOpcodePub
void MCInst_setOpcodePub(MCInst *inst, unsigned Op)
Definition: MCInst.c:60
MCInst::Operands
MCOperand Operands[48]
Definition: MCInst.h:94
op
static grpc_op * op
Definition: test/core/fling/client.cc:47
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
MCOperand_isReg
bool MCOperand_isReg(const MCOperand *op)
Definition: MCInst.c:98


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:00:35