Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/libs/capstone/MCInst.h
4387 views
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 <[email protected]>, 2013-2019 */
18
19
#ifndef CS_MCINST_H
20
#define CS_MCINST_H
21
22
#include "include/capstone/capstone.h"
23
#include "MCInstrDesc.h"
24
#include "MCRegisterInfo.h"
25
26
typedef struct MCInst MCInst;
27
typedef struct cs_struct cs_struct;
28
typedef struct MCOperand MCOperand;
29
30
/// MCOperand - Instances of this class represent operands of the MCInst class.
31
/// This is a simple discriminated union.
32
struct MCOperand {
33
enum {
34
kInvalid = 0, ///< Uninitialized.
35
kRegister, ///< Register operand.
36
kImmediate, ///< Immediate operand.
37
kFPImmediate, ///< Floating-point immediate operand.
38
kDFPImmediate, ///< Double-Floating-point immediate operand.
39
kExpr, ///< Relocatable immediate operand.
40
kInst ///< Sub-instruction operand.
41
42
} MachineOperandType;
43
unsigned char Kind;
44
45
union {
46
unsigned RegVal;
47
int64_t ImmVal;
48
double FPImmVal;
49
};
50
};
51
52
bool MCOperand_isValid(const MCOperand *op);
53
54
bool MCOperand_isReg(const MCOperand *op);
55
56
bool MCOperand_isImm(const MCOperand *op);
57
58
bool MCOperand_isFPImm(const MCOperand *op);
59
60
bool MCOperand_isDFPImm(const MCOperand *op);
61
62
bool MCOperand_isExpr(const MCOperand *op);
63
64
bool MCOperand_isInst(const MCOperand *op);
65
66
/// getReg - Returns the register number.
67
unsigned MCOperand_getReg(const MCOperand *op);
68
69
/// setReg - Set the register number.
70
void MCOperand_setReg(MCOperand *op, unsigned Reg);
71
72
int64_t MCOperand_getImm(MCOperand *op);
73
74
void MCOperand_setImm(MCOperand *op, int64_t Val);
75
76
double MCOperand_getFPImm(const MCOperand *op);
77
78
void MCOperand_setFPImm(MCOperand *op, double Val);
79
80
const MCInst *MCOperand_getInst(const MCOperand *op);
81
82
void MCOperand_setInst(MCOperand *op, const MCInst *Val);
83
84
// create Reg operand in the next slot
85
void MCOperand_CreateReg0(MCInst *inst, unsigned Reg);
86
87
// create Reg operand use the last-unused slot
88
MCOperand *MCOperand_CreateReg1(MCInst *inst, unsigned Reg);
89
90
// create Imm operand in the next slot
91
void MCOperand_CreateImm0(MCInst *inst, int64_t Val);
92
93
// create Imm operand in the last-unused slot
94
MCOperand *MCOperand_CreateImm1(MCInst *inst, int64_t Val);
95
96
#define MAX_MC_OPS 48
97
98
/// MCInst - Instances of this class represent a single low-level machine
99
/// instruction.
100
struct MCInst {
101
unsigned OpcodePub; // public opcode (<arch>_INS_yyy in header files <arch>.h)
102
uint8_t size; // number of operands
103
bool has_imm; // indicate this instruction has an X86_OP_IMM operand - used for ATT syntax
104
uint8_t op1_size; // size of 1st operand - for X86 Intel syntax
105
unsigned Opcode; // private opcode
106
MCOperand Operands[MAX_MC_OPS];
107
cs_insn *flat_insn; // insn to be exposed to public
108
uint64_t address; // address of this insn
109
cs_struct *csh; // save the main csh
110
uint8_t x86opsize; // opsize for [mem] operand
111
112
// These flags could be used to pass some info from one target subcomponent
113
// to another, for example, from disassembler to asm printer. The values of
114
// the flags have any sense on target level only (e.g. prefixes on x86).
115
unsigned flags;
116
117
// (Optional) instruction prefix, which can be up to 4 bytes.
118
// A prefix byte gets value 0 when irrelevant.
119
// This is copied from cs_x86 struct
120
uint8_t x86_prefix[4];
121
uint8_t imm_size; // immediate size for X86_OP_IMM operand
122
bool writeback; // writeback for ARM
123
int8_t tied_op_idx
124
[MAX_MC_OPS]; ///< Tied operand indices. Index = Src op; Value: Dest op
125
// operand access index for list of registers sharing the same access right (for ARM)
126
uint8_t ac_idx;
127
uint8_t popcode_adjust; // Pseudo X86 instruction adjust
128
char assembly[8]; // for special instruction, so that we dont need printer
129
unsigned char evm_data[32]; // for EVM PUSH operand
130
cs_wasm_op wasm_data; // for WASM operand
131
MCRegisterInfo *MRI;
132
uint8_t xAcquireRelease; // X86 xacquire/xrelease
133
};
134
135
void MCInst_Init(MCInst *inst);
136
137
void MCInst_clear(MCInst *inst);
138
139
// do not free operand after inserting
140
void MCInst_insert0(MCInst *inst, int index, MCOperand *Op);
141
142
void MCInst_setOpcode(MCInst *inst, unsigned Op);
143
144
unsigned MCInst_getOpcode(const MCInst*);
145
146
void MCInst_setOpcodePub(MCInst *inst, unsigned Op);
147
148
unsigned MCInst_getOpcodePub(const MCInst*);
149
150
MCOperand *MCInst_getOperand(MCInst *inst, unsigned i);
151
152
unsigned MCInst_getNumOperands(const MCInst *inst);
153
154
// This addOperand2 function doesnt free Op
155
void MCInst_addOperand2(MCInst *inst, MCOperand *Op);
156
157
bool MCInst_isPredicable(const MCInstrDesc *MIDesc);
158
159
void MCInst_handleWriteback(MCInst *MI, const MCInstrDesc *InstDesc);
160
161
bool MCInst_opIsTied(const MCInst *MI, unsigned OpNum);
162
163
bool MCInst_opIsTying(const MCInst *MI, unsigned OpNum);
164
165
#endif
166
167