blob: 2407eff2c8a7a6cecdc04d10fc1d8a155fa198ee [file] [log] [blame]
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +08001//===-- 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 Disassembler Engine */
17/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013> */
18
19#ifndef __CS_MC_MCINST_H
20#define __CS_MC_MCINST_H
21
22#include <stdint.h>
23#include <stdbool.h>
24
25#include "include/capstone.h"
26
27typedef struct MCInst MCInst;
28typedef struct MCOperand MCOperand;
29
30/// MCOperand - Instances of this class represent operands of the MCInst class.
31/// This is a simple discriminated union.
32struct MCOperand {
33 enum {
34 kInvalid = 0, ///< Uninitialized.
35 kRegister, ///< Register operand.
36 kImmediate, ///< Immediate operand.
37 kFPImmediate, ///< Floating-point immediate operand.
38 } MachineOperandType;
39 unsigned char Kind;
40
41 union {
42 unsigned RegVal;
43 int64_t ImmVal;
44 double FPImmVal;
45 };
46};
47
48bool MCOperand_isValid(const MCOperand *op);
49
50bool MCOperand_isReg(const MCOperand *op);
51
52bool MCOperand_isImm(const MCOperand *op);
53
54bool MCOperand_isFPImm(const MCOperand *op);
55
56bool MCOperand_isInst(const MCOperand *op);
57
58void MCInst_clear(MCInst *m);
59
60/// getReg - Returns the register number.
61unsigned MCOperand_getReg(const MCOperand *op);
62
63/// setReg - Set the register number.
64void MCOperand_setReg(MCOperand *op, unsigned Reg);
65
66int64_t MCOperand_getImm(MCOperand *op);
67
68void MCOperand_setImm(MCOperand *op, int64_t Val);
69
70double MCOperand_getFPImm(const MCOperand *op);
71
72void MCOperand_setFPImm(MCOperand *op, double Val);
73
74const MCInst *MCOperand_getInst(const MCOperand *op);
75
76void MCOperand_setInst(MCOperand *op, const MCInst *Val);
77
78MCOperand *MCOperand_CreateReg(unsigned Reg);
79
80MCOperand *MCOperand_CreateImm(int64_t Val);
81
82MCOperand *MCOperand_CreateFPImm(double Val);
83
84/// MCInst - Instances of this class represent a single low-level machine
85/// instruction.
86struct MCInst {
87 unsigned Opcode;
88 MCOperand Operands[32];
89 unsigned size; // number of operands
90 cs_insn pub_insn; // insn to be exposed to public
91 cs_mode mode; // to be referenced by internal code
Nguyen Anh Quynh6b7abe32013-11-30 00:54:24 +080092 unsigned OpcodePub;
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080093};
94
95void MCInst_Init(MCInst *inst);
96
97void MCInst_clear(MCInst *inst);
98
99void MCInst_insert(MCInst *inst, int index, MCOperand *Op);
100
101void MCInst_setOpcode(MCInst *inst, unsigned Op);
102
103unsigned MCInst_getOpcode(const MCInst*);
104
Nguyen Anh Quynh6b7abe32013-11-30 00:54:24 +0800105void MCInst_setOpcodePub(MCInst *inst, unsigned Op);
106
107unsigned MCInst_getOpcodePub(const MCInst*);
108
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +0800109MCOperand *MCInst_getOperand(MCInst *inst, unsigned i);
110
111unsigned MCInst_getNumOperands(const MCInst *inst);
112
113int MCInst_addOperand(MCInst *inst, MCOperand *Op);
114
115// This addOperand2 function doesnt free Op
116int MCInst_addOperand2(MCInst *inst, MCOperand *Op);
117
118#endif