/rust/registry/src/index.crates.io-6f17d22bba15001f/capstone-sys-0.13.0/capstone/MCInst.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* Capstone Disassembly Engine */ |
2 | | /* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2019 */ |
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 | 0 | #define MCINST_CACHE (ARR_SIZE(mcInst->Operands) - 1) |
17 | | |
18 | | void MCInst_Init(MCInst *inst) |
19 | 0 | { |
20 | 0 | unsigned int i; |
21 | |
|
22 | 0 | for (i = 0; i < 48; i++) { |
23 | 0 | inst->Operands[i].Kind = kInvalid; |
24 | 0 | inst->Operands[i].ImmVal = 0; |
25 | 0 | } |
26 | |
|
27 | 0 | inst->Opcode = 0; |
28 | 0 | inst->OpcodePub = 0; |
29 | 0 | inst->size = 0; |
30 | 0 | inst->has_imm = false; |
31 | 0 | inst->op1_size = 0; |
32 | 0 | inst->writeback = false; |
33 | 0 | inst->ac_idx = 0; |
34 | 0 | inst->popcode_adjust = 0; |
35 | 0 | inst->assembly[0] = '\0'; |
36 | 0 | inst->wasm_data.type = WASM_OP_INVALID; |
37 | 0 | inst->xAcquireRelease = 0; |
38 | 0 | } |
39 | | |
40 | | void MCInst_clear(MCInst *inst) |
41 | 0 | { |
42 | 0 | inst->size = 0; |
43 | 0 | } |
44 | | |
45 | | // do not free @Op |
46 | | void MCInst_insert0(MCInst *inst, int index, MCOperand *Op) |
47 | 0 | { |
48 | 0 | int i; |
49 | |
|
50 | 0 | for(i = inst->size; i > index; i--) |
51 | | //memcpy(&(inst->Operands[i]), &(inst->Operands[i-1]), sizeof(MCOperand)); |
52 | 0 | inst->Operands[i] = inst->Operands[i-1]; |
53 | |
|
54 | 0 | inst->Operands[index] = *Op; |
55 | 0 | inst->size++; |
56 | 0 | } |
57 | | |
58 | | void MCInst_setOpcode(MCInst *inst, unsigned Op) |
59 | 0 | { |
60 | 0 | inst->Opcode = Op; |
61 | 0 | } |
62 | | |
63 | | void MCInst_setOpcodePub(MCInst *inst, unsigned Op) |
64 | 0 | { |
65 | 0 | inst->OpcodePub = Op; |
66 | 0 | } |
67 | | |
68 | | unsigned MCInst_getOpcode(const MCInst *inst) |
69 | 0 | { |
70 | 0 | return inst->Opcode; |
71 | 0 | } |
72 | | |
73 | | unsigned MCInst_getOpcodePub(const MCInst *inst) |
74 | 0 | { |
75 | 0 | return inst->OpcodePub; |
76 | 0 | } |
77 | | |
78 | | MCOperand *MCInst_getOperand(MCInst *inst, unsigned i) |
79 | 0 | { |
80 | 0 | return &inst->Operands[i]; |
81 | 0 | } |
82 | | |
83 | | unsigned MCInst_getNumOperands(const MCInst *inst) |
84 | 0 | { |
85 | 0 | return inst->size; |
86 | 0 | } |
87 | | |
88 | | // This addOperand2 function doesnt free Op |
89 | | void MCInst_addOperand2(MCInst *inst, MCOperand *Op) |
90 | 0 | { |
91 | 0 | inst->Operands[inst->size] = *Op; |
92 | |
|
93 | 0 | inst->size++; |
94 | 0 | } |
95 | | |
96 | | bool MCOperand_isValid(const MCOperand *op) |
97 | 0 | { |
98 | 0 | return op->Kind != kInvalid; |
99 | 0 | } |
100 | | |
101 | | bool MCOperand_isReg(const MCOperand *op) |
102 | 0 | { |
103 | 0 | return op->Kind == kRegister; |
104 | 0 | } |
105 | | |
106 | | bool MCOperand_isImm(const MCOperand *op) |
107 | 0 | { |
108 | 0 | return op->Kind == kImmediate; |
109 | 0 | } |
110 | | |
111 | | bool MCOperand_isFPImm(const MCOperand *op) |
112 | 0 | { |
113 | 0 | return op->Kind == kFPImmediate; |
114 | 0 | } |
115 | | |
116 | | /// getReg - Returns the register number. |
117 | | unsigned MCOperand_getReg(const MCOperand *op) |
118 | 0 | { |
119 | 0 | return op->RegVal; |
120 | 0 | } |
121 | | |
122 | | /// setReg - Set the register number. |
123 | | void MCOperand_setReg(MCOperand *op, unsigned Reg) |
124 | 0 | { |
125 | 0 | op->RegVal = Reg; |
126 | 0 | } |
127 | | |
128 | | int64_t MCOperand_getImm(MCOperand *op) |
129 | 0 | { |
130 | 0 | return op->ImmVal; |
131 | 0 | } |
132 | | |
133 | | void MCOperand_setImm(MCOperand *op, int64_t Val) |
134 | 0 | { |
135 | 0 | op->ImmVal = Val; |
136 | 0 | } |
137 | | |
138 | | double MCOperand_getFPImm(const MCOperand *op) |
139 | 0 | { |
140 | 0 | return op->FPImmVal; |
141 | 0 | } |
142 | | |
143 | | void MCOperand_setFPImm(MCOperand *op, double Val) |
144 | 0 | { |
145 | 0 | op->FPImmVal = Val; |
146 | 0 | } |
147 | | |
148 | | MCOperand *MCOperand_CreateReg1(MCInst *mcInst, unsigned Reg) |
149 | 0 | { |
150 | 0 | MCOperand *op = &(mcInst->Operands[MCINST_CACHE]); |
151 | |
|
152 | 0 | op->Kind = kRegister; |
153 | 0 | op->RegVal = Reg; |
154 | |
|
155 | 0 | return op; |
156 | 0 | } |
157 | | |
158 | | void MCOperand_CreateReg0(MCInst *mcInst, unsigned Reg) |
159 | 0 | { |
160 | 0 | MCOperand *op = &(mcInst->Operands[mcInst->size]); |
161 | 0 | mcInst->size++; |
162 | |
|
163 | 0 | op->Kind = kRegister; |
164 | 0 | op->RegVal = Reg; |
165 | 0 | } |
166 | | |
167 | | MCOperand *MCOperand_CreateImm1(MCInst *mcInst, int64_t Val) |
168 | 0 | { |
169 | 0 | MCOperand *op = &(mcInst->Operands[MCINST_CACHE]); |
170 | |
|
171 | 0 | op->Kind = kImmediate; |
172 | 0 | op->ImmVal = Val; |
173 | |
|
174 | 0 | return op; |
175 | 0 | } |
176 | | |
177 | | void MCOperand_CreateImm0(MCInst *mcInst, int64_t Val) |
178 | 0 | { |
179 | 0 | MCOperand *op = &(mcInst->Operands[mcInst->size]); |
180 | 0 | mcInst->size++; |
181 | |
|
182 | 0 | op->Kind = kImmediate; |
183 | 0 | op->ImmVal = Val; |
184 | 0 | } |