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