/src/capstonenext/MCInst.h
Line  | Count  | Source  | 
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 <aquynh@gmail.com>, 2013-2019 */  | 
18  |  |  | 
19  |  | #ifndef CS_MCINST_H  | 
20  |  | #define CS_MCINST_H  | 
21  |  |  | 
22  |  | #include "include/capstone/capstone.h"  | 
23  |  | #include "MCAsmInfo.h"  | 
24  |  | #include "MCInstrDesc.h"  | 
25  |  | #include "MCRegisterInfo.h"  | 
26  |  |  | 
27  |  | typedef struct MCInst MCInst;  | 
28  |  | typedef struct cs_struct cs_struct;  | 
29  |  | typedef struct MCOperand MCOperand;  | 
30  |  | typedef void MCExpr;  | 
31  |  |  | 
32  |  | /// MCOperand - Instances of this class represent operands of the MCInst class.  | 
33  |  | /// This is a simple discriminated union.  | 
34  |  | struct MCOperand { | 
35  |  |   enum { | 
36  |  |     kInvalid = 0, ///< Uninitialized.  | 
37  |  |     kRegister, ///< Register operand.  | 
38  |  |     kImmediate, ///< Immediate operand.  | 
39  |  |     kFPImmediate, ///< Floating-point immediate operand.  | 
40  |  |     kDFPImmediate, ///< Double-Floating-point immediate operand.  | 
41  |  |     kExpr, ///< Relocatable immediate operand.  | 
42  |  |     kInst ///< Sub-instruction operand.  | 
43  |  |   } MachineOperandType;  | 
44  |  |   unsigned char Kind;  | 
45  |  |  | 
46  |  |   union { | 
47  |  |     uint64_t RegVal;  | 
48  |  |     int64_t ImmVal;  | 
49  |  |     double FPImmVal;  | 
50  |  |   };  | 
51  |  | };  | 
52  |  |  | 
53  |  | bool MCOperand_isValid(const MCOperand *op);  | 
54  |  |  | 
55  |  | bool MCOperand_isReg(const MCOperand *op);  | 
56  |  |  | 
57  |  | bool MCOperand_isImm(const MCOperand *op);  | 
58  |  |  | 
59  |  | bool MCOperand_isFPImm(const MCOperand *op);  | 
60  |  |  | 
61  |  | bool MCOperand_isDFPImm(const MCOperand *op);  | 
62  |  |  | 
63  |  | bool MCOperand_isExpr(const MCOperand *op);  | 
64  |  |  | 
65  |  | bool MCOperand_isInst(const MCOperand *op);  | 
66  |  |  | 
67  |  | /// getReg - Returns the register number.  | 
68  |  | unsigned MCOperand_getReg(const MCOperand *op);  | 
69  |  |  | 
70  |  | /// setReg - Set the register number.  | 
71  |  | void MCOperand_setReg(MCOperand *op, unsigned Reg);  | 
72  |  |  | 
73  |  | int64_t MCOperand_getImm(const MCOperand *op);  | 
74  |  |  | 
75  |  | void MCOperand_setImm(MCOperand *op, int64_t Val);  | 
76  |  |  | 
77  |  | int64_t MCOperand_getExpr(const MCOperand *op);  | 
78  |  |  | 
79  |  | double MCOperand_getFPImm(const MCOperand *op);  | 
80  |  |  | 
81  |  | void MCOperand_setFPImm(MCOperand *op, double Val);  | 
82  |  |  | 
83  |  | const MCInst *MCOperand_getInst(const MCOperand *op);  | 
84  |  |  | 
85  |  | void MCOperand_setInst(MCOperand *op, const MCInst *Val);  | 
86  |  |  | 
87  |  | // create Reg operand in the next slot  | 
88  |  | void MCOperand_CreateReg0(MCInst *inst, unsigned Reg);  | 
89  |  |  | 
90  |  | // create Reg operand use the last-unused slot  | 
91  |  | MCOperand *MCOperand_CreateReg1(MCInst *inst, unsigned Reg);  | 
92  |  |  | 
93  |  | // create Imm operand in the next slot  | 
94  |  | void MCOperand_CreateImm0(MCInst *inst, int64_t Val);  | 
95  |  |  | 
96  |  | // create Imm operand in the last-unused slot  | 
97  |  | MCOperand *MCOperand_CreateImm1(MCInst *inst, int64_t Val);  | 
98  |  |  | 
99  | 454M  | #define MAX_MC_OPS 48  | 
100  |  |  | 
101  |  | /// MCInst - Instances of this class represent a single low-level machine  | 
102  |  | /// instruction.  | 
103  |  | struct MCInst { | 
104  |  |   unsigned OpcodePub; // public opcode (<arch>_INS_yyy in header files <arch>.h)  | 
105  |  |   uint8_t size; // number of operands  | 
106  |  |   bool has_imm; // indicate this instruction has an X86_OP_IMM operand - used for ATT syntax  | 
107  |  |   uint8_t op1_size; // size of 1st operand - for X86 Intel syntax  | 
108  |  |   unsigned Opcode; // private opcode  | 
109  |  |   MCOperand Operands[MAX_MC_OPS];  | 
110  |  |   cs_insn *flat_insn; // insn to be exposed to public  | 
111  |  |   uint64_t address; // address of this insn  | 
112  |  |   cs_struct *csh; // save the main csh  | 
113  |  |   uint8_t x86opsize; // opsize for [mem] operand  | 
114  |  |  | 
115  |  |   // These flags could be used to pass some info from one target subcomponent  | 
116  |  |   // to another, for example, from disassembler to asm printer. The values of  | 
117  |  |   // the flags have any sense on target level only (e.g. prefixes on x86).  | 
118  |  |   unsigned flags;  | 
119  |  |  | 
120  |  |   // (Optional) instruction prefix, which can be up to 4 bytes.  | 
121  |  |   // A prefix byte gets value 0 when irrelevant.  | 
122  |  |   // This is copied from cs_x86 struct  | 
123  |  |   uint8_t x86_prefix[4];  | 
124  |  |   uint8_t imm_size; // immediate size for X86_OP_IMM operand  | 
125  |  |   bool writeback; // writeback for ARM  | 
126  |  |   int8_t tied_op_idx  | 
127  |  |     [MAX_MC_OPS]; ///< Tied operand indices. Index = Src op; Value: Dest op  | 
128  |  |   // operand access index for list of registers sharing the same access right (for ARM)  | 
129  |  |   uint8_t ac_idx;  | 
130  |  |   uint8_t popcode_adjust; // Pseudo X86 instruction adjust  | 
131  |  |   char assembly[8]; // for special instruction, so that we don't need printer  | 
132  |  |   unsigned char evm_data[32]; // for EVM PUSH operand  | 
133  |  |   cs_wasm_op wasm_data; // for WASM operand  | 
134  |  |   MCRegisterInfo *MRI;  | 
135  |  |   uint8_t xAcquireRelease; // X86 xacquire/xrelease  | 
136  |  |   bool isAliasInstr; // Flag if this MCInst is an alias.  | 
137  |  |   bool fillDetailOps; // If set, detail->operands gets filled.  | 
138  |  |   hppa_ext hppa_ext; ///< for HPPA operand. Contains info about modifiers and their effect on the instruction  | 
139  |  |   MCAsmInfo MAI; ///< The equivalent to MCAsmInfo in LLVM. It holds flags relevant for the asm style to print.  | 
140  |  | };  | 
141  |  |  | 
142  |  | void MCInst_Init(MCInst *inst, cs_arch arch);  | 
143  |  |  | 
144  |  | void MCInst_clear(MCInst *inst);  | 
145  |  |  | 
146  |  | // do not free operand after inserting  | 
147  |  | void MCInst_insert0(MCInst *inst, int index, MCOperand *Op);  | 
148  |  |  | 
149  |  | void MCInst_setOpcode(MCInst *inst, unsigned Op);  | 
150  |  |  | 
151  |  | unsigned MCInst_getOpcode(const MCInst *);  | 
152  |  |  | 
153  |  | void MCInst_setOpcodePub(MCInst *inst, unsigned Op);  | 
154  |  |  | 
155  |  | unsigned MCInst_getOpcodePub(const MCInst *);  | 
156  |  |  | 
157  |  | MCOperand *MCInst_getOperand(MCInst *inst, unsigned i);  | 
158  |  |  | 
159  |  | unsigned MCInst_getNumOperands(const MCInst *inst);  | 
160  |  |  | 
161  |  | // This addOperand2 function doesn't free Op  | 
162  |  | void MCInst_addOperand2(MCInst *inst, MCOperand *Op);  | 
163  |  |  | 
164  |  | bool MCInst_isPredicable(const MCInstrDesc *MIDesc);  | 
165  |  |  | 
166  |  | void MCInst_handleWriteback(MCInst *MI, const MCInstrDesc *InstDescTable,  | 
167  |  |           unsigned tbl_size);  | 
168  |  |  | 
169  |  | bool MCInst_opIsTied(const MCInst *MI, unsigned OpNum);  | 
170  |  |  | 
171  |  | bool MCInst_opIsTying(const MCInst *MI, unsigned OpNum);  | 
172  |  |  | 
173  |  | uint64_t MCInst_getOpVal(MCInst *MI, unsigned OpNum);  | 
174  |  |  | 
175  |  | void MCInst_setIsAlias(MCInst *MI, bool Flag);  | 
176  |  |  | 
177  |  | static inline bool MCInst_isAlias(const MCInst *MI)  | 
178  | 1.81M  | { | 
179  | 1.81M  |   return MI->isAliasInstr;  | 
180  | 1.81M  | } Unexecuted instantiation: cs.c:MCInst_isAlias Unexecuted instantiation: MCInst.c:MCInst_isAlias Unexecuted instantiation: SStream.c:MCInst_isAlias Unexecuted instantiation: utils.c:MCInst_isAlias Unexecuted instantiation: ARMModule.c:MCInst_isAlias Unexecuted instantiation: AArch64Module.c:MCInst_isAlias Unexecuted instantiation: MipsModule.c:MCInst_isAlias Unexecuted instantiation: PPCModule.c:MCInst_isAlias Unexecuted instantiation: X86Module.c:MCInst_isAlias Unexecuted instantiation: X86ATTInstPrinter.c:MCInst_isAlias Unexecuted instantiation: SparcModule.c:MCInst_isAlias Unexecuted instantiation: SystemZModule.c:MCInst_isAlias Unexecuted instantiation: XCoreModule.c:MCInst_isAlias Unexecuted instantiation: M68KModule.c:MCInst_isAlias Unexecuted instantiation: TMS320C64xModule.c:MCInst_isAlias Unexecuted instantiation: M680XModule.c:MCInst_isAlias Unexecuted instantiation: EVMModule.c:MCInst_isAlias Unexecuted instantiation: WASMModule.c:MCInst_isAlias Unexecuted instantiation: MOS65XXModule.c:MCInst_isAlias Unexecuted instantiation: MOS65XXDisassembler.c:MCInst_isAlias Unexecuted instantiation: BPFModule.c:MCInst_isAlias Unexecuted instantiation: RISCVModule.c:MCInst_isAlias Unexecuted instantiation: SHModule.c:MCInst_isAlias Unexecuted instantiation: TriCoreModule.c:MCInst_isAlias Unexecuted instantiation: AlphaModule.c:MCInst_isAlias Unexecuted instantiation: HPPAModule.c:MCInst_isAlias Unexecuted instantiation: LoongArchModule.c:MCInst_isAlias Unexecuted instantiation: XtensaModule.c:MCInst_isAlias Unexecuted instantiation: ARCModule.c:MCInst_isAlias Unexecuted instantiation: ARMMapping.c:MCInst_isAlias Unexecuted instantiation: AArch64Mapping.c:MCInst_isAlias Unexecuted instantiation: MipsMapping.c:MCInst_isAlias Unexecuted instantiation: PPCMapping.c:MCInst_isAlias Unexecuted instantiation: X86Disassembler.c:MCInst_isAlias Unexecuted instantiation: X86DisassemblerDecoder.c:MCInst_isAlias Unexecuted instantiation: X86IntelInstPrinter.c:MCInst_isAlias Unexecuted instantiation: X86InstPrinterCommon.c:MCInst_isAlias Unexecuted instantiation: X86Mapping.c:MCInst_isAlias Unexecuted instantiation: SparcMapping.c:MCInst_isAlias Unexecuted instantiation: SystemZMapping.c:MCInst_isAlias Unexecuted instantiation: XCoreDisassembler.c:MCInst_isAlias Unexecuted instantiation: XCoreInstPrinter.c:MCInst_isAlias Unexecuted instantiation: XCoreMapping.c:MCInst_isAlias Unexecuted instantiation: M68KDisassembler.c:MCInst_isAlias Unexecuted instantiation: M68KInstPrinter.c:MCInst_isAlias Unexecuted instantiation: TMS320C64xDisassembler.c:MCInst_isAlias Unexecuted instantiation: TMS320C64xInstPrinter.c:MCInst_isAlias Unexecuted instantiation: TMS320C64xMapping.c:MCInst_isAlias Unexecuted instantiation: M680XDisassembler.c:MCInst_isAlias Unexecuted instantiation: M680XInstPrinter.c:MCInst_isAlias Unexecuted instantiation: EVMDisassembler.c:MCInst_isAlias Unexecuted instantiation: EVMInstPrinter.c:MCInst_isAlias Unexecuted instantiation: EVMMapping.c:MCInst_isAlias Unexecuted instantiation: WASMDisassembler.c:MCInst_isAlias Unexecuted instantiation: WASMInstPrinter.c:MCInst_isAlias Unexecuted instantiation: WASMMapping.c:MCInst_isAlias Unexecuted instantiation: BPFDisassembler.c:MCInst_isAlias Unexecuted instantiation: BPFInstPrinter.c:MCInst_isAlias Unexecuted instantiation: BPFMapping.c:MCInst_isAlias Unexecuted instantiation: RISCVDisassembler.c:MCInst_isAlias Unexecuted instantiation: RISCVInstPrinter.c:MCInst_isAlias Unexecuted instantiation: RISCVMapping.c:MCInst_isAlias Unexecuted instantiation: SHDisassembler.c:MCInst_isAlias Unexecuted instantiation: SHInstPrinter.c:MCInst_isAlias Unexecuted instantiation: TriCoreDisassembler.c:MCInst_isAlias Unexecuted instantiation: TriCoreMapping.c:MCInst_isAlias Unexecuted instantiation: AlphaDisassembler.c:MCInst_isAlias Unexecuted instantiation: AlphaMapping.c:MCInst_isAlias Unexecuted instantiation: HPPADisassembler.c:MCInst_isAlias Unexecuted instantiation: HPPAInstPrinter.c:MCInst_isAlias Unexecuted instantiation: HPPAMapping.c:MCInst_isAlias Unexecuted instantiation: LoongArchMapping.c:MCInst_isAlias Unexecuted instantiation: XtensaMapping.c:MCInst_isAlias Unexecuted instantiation: ARCMapping.c:MCInst_isAlias Line  | Count  | Source  |  178  | 1.81M  | { |  179  | 1.81M  |   return MI->isAliasInstr;  |  180  | 1.81M  | }  |  
 Unexecuted instantiation: ARMBaseInfo.c:MCInst_isAlias Unexecuted instantiation: ARMDisassembler.c:MCInst_isAlias Unexecuted instantiation: ARMDisassemblerExtension.c:MCInst_isAlias Unexecuted instantiation: ARMInstPrinter.c:MCInst_isAlias Unexecuted instantiation: AArch64BaseInfo.c:MCInst_isAlias Unexecuted instantiation: AArch64Disassembler.c:MCInst_isAlias Unexecuted instantiation: AArch64DisassemblerExtension.c:MCInst_isAlias Unexecuted instantiation: AArch64InstPrinter.c:MCInst_isAlias Unexecuted instantiation: MipsDisassembler.c:MCInst_isAlias Unexecuted instantiation: MipsInstPrinter.c:MCInst_isAlias Unexecuted instantiation: PPCDisassembler.c:MCInst_isAlias Unexecuted instantiation: PPCInstPrinter.c:MCInst_isAlias Unexecuted instantiation: SparcDisassembler.c:MCInst_isAlias Unexecuted instantiation: SparcDisassemblerExtension.c:MCInst_isAlias Unexecuted instantiation: SparcInstPrinter.c:MCInst_isAlias Unexecuted instantiation: SystemZDisassembler.c:MCInst_isAlias Unexecuted instantiation: SystemZDisassemblerExtension.c:MCInst_isAlias Unexecuted instantiation: SystemZInstPrinter.c:MCInst_isAlias Unexecuted instantiation: SystemZMCTargetDesc.c:MCInst_isAlias Unexecuted instantiation: TriCoreInstPrinter.c:MCInst_isAlias Unexecuted instantiation: AlphaInstPrinter.c:MCInst_isAlias Unexecuted instantiation: LoongArchDisassembler.c:MCInst_isAlias Unexecuted instantiation: LoongArchInstPrinter.c:MCInst_isAlias Unexecuted instantiation: XtensaDisassembler.c:MCInst_isAlias Unexecuted instantiation: XtensaInstPrinter.c:MCInst_isAlias Unexecuted instantiation: ARCDisassembler.c:MCInst_isAlias Unexecuted instantiation: ARCInstPrinter.c:MCInst_isAlias Unexecuted instantiation: MCInstPrinter.c:MCInst_isAlias  | 
181  |  |  | 
182  |  | void MCInst_updateWithTmpMI(MCInst *MI, MCInst *TmpMI);  | 
183  |  |  | 
184  |  | void MCInst_setSoftFail(MCInst *MI);  | 
185  |  |  | 
186  |  | #endif  |