forked from capstone-engine/capstone
-
Notifications
You must be signed in to change notification settings - Fork 2
/
MCInstPrinter.h
84 lines (70 loc) · 2.61 KB
/
MCInstPrinter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* Capstone Disassembly Engine */
/* By Rot127 <unisono@quyllur.org>, 2023 */
#ifndef CS_MCINSTPRINTER_H
#define CS_MCINSTPRINTER_H
#include "MCInst.h"
#include <assert.h>
#include <capstone/platform.h>
/// Returned by getMnemonic() of the AsmPrinters.
typedef struct {
const char *first; // Mnemonic
uint64_t second; // Bits
} MnemonicBitsInfo;
/// Map from opcode to pattern list by binary search.
typedef struct {
uint32_t Opcode;
uint16_t PatternStart;
uint16_t NumPatterns;
} PatternsForOpcode;
/// Data for each alias pattern. Includes feature bits, string, number of
/// operands, and a variadic list of conditions to check.
typedef struct {
uint32_t AsmStrOffset;
uint32_t AliasCondStart;
uint8_t NumOperands;
uint8_t NumConds;
} AliasPattern;
typedef enum {
AliasPatternCond_K_Feature, // Match only if a feature is enabled.
AliasPatternCond_K_NegFeature, // Match only if a feature is disabled.
AliasPatternCond_K_OrFeature, // Match only if one of a set of features is
// enabled.
AliasPatternCond_K_OrNegFeature, // Match only if one of a set of features
// is disabled.
AliasPatternCond_K_EndOrFeatures, // Note end of list of K_Or(Neg)?Features.
AliasPatternCond_K_Ignore, // Match any operand.
AliasPatternCond_K_Reg, // Match a specific register.
AliasPatternCond_K_TiedReg, // Match another already matched register.
AliasPatternCond_K_Imm, // Match a specific immediate.
AliasPatternCond_K_RegClass, // Match registers in a class.
AliasPatternCond_K_Custom, // Call custom matcher by index.
} AliasPatternCond_CondKind;
typedef struct {
AliasPatternCond_CondKind Kind;
uint32_t Value;
} AliasPatternCond;
typedef bool (*ValidateMCOperandFunc)(const MCOperand *MCOp, unsigned PredicateIndex);
/// Tablegenerated data structures needed to match alias patterns.
typedef struct {
const PatternsForOpcode *OpToPatterns;
const AliasPattern *Patterns;
const AliasPatternCond *PatternConds;
const char *AsmStrings;
const ValidateMCOperandFunc ValidateMCOperand;
} AliasMatchingData;
const char *matchAliasPatterns(MCInst *MI, const AliasMatchingData *M);
bool getUseMarkup(void);
const char *markup(const char *s);
struct IndexType {
uint16_t encoding;
unsigned index;
};
struct IndexTypeStr {
const char *name;
unsigned index;
};
// binary search for encoding in IndexType array
// return -1 if not found, or index if found
unsigned int binsearch_IndexTypeEncoding(const struct IndexType *index, size_t size, uint16_t encoding);
unsigned int binsearch_IndexTypeStrEncoding(const struct IndexTypeStr *index, size_t size, const char *name);
#endif // CS_MCINSTPRINTER_H