-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathajs_parsing.h
135 lines (118 loc) · 2.87 KB
/
ajs_parsing.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
* ajs_parsing.h
*
* Created on: 01.09.2016
* Author: kruppa
*/
#ifndef AJS_PARSING_H_
#define AJS_PARSING_H_
#include <string>
#include <asmjit/asmjit.h>
#define regreg2(N,M) do {if (istrcmp(name, #N)) return M;} while(0)
#define regreg(N) regreg2(N,N)
static bool
istrcmp(const std::string s1, const char *s2) {
bool result = true;
if (s1.size() != strlen(s2))
result = false;
for (size_t i = 0; result && i < s1.size(); i++) {
if (toupper(s1.at(i)) != toupper(s2[i]))
result = false;
}
return result;
}
static asmjit::X86Reg getXmmRegFromName(std::string name) {
using namespace asmjit::x86;
regreg(xmm0);
regreg(xmm1);
regreg(xmm2);
regreg(xmm3);
regreg(xmm4);
regreg(xmm5);
regreg(xmm6);
regreg(xmm7);
regreg(xmm8);
regreg(xmm9);
regreg(xmm10);
regreg(xmm11);
regreg(xmm12);
regreg(xmm13);
regreg(xmm14);
regreg(xmm15);
return noGpReg;
}
static asmjit::X86Reg getYmmRegFromName(std::string name) {
using namespace asmjit::x86;
regreg(ymm0);
regreg(ymm1);
regreg(ymm2);
regreg(ymm3);
regreg(ymm4);
regreg(ymm5);
regreg(ymm6);
regreg(ymm7);
regreg(ymm8);
regreg(ymm9);
regreg(ymm10);
regreg(ymm11);
regreg(ymm12);
regreg(ymm13);
regreg(ymm14);
regreg(ymm15);
return noGpReg;
}
/* The ax, bx, cx, dx registers can be named, e.g.,
* rax, eax, ax, ah, al, axl (=al)
* to refer to different widths/parts.
* The "axl" form is supported by gas, so we allow it, too. */
#define regabcd(X) \
do { \
regreg(r##X##x); \
regreg(e##X##x); \
regreg(X##x); \
regreg(X##h); \
regreg(X##l); \
regreg2(X##xl,X##l); \
} while (0)
/* The bp, sp, si, di registers can be named, e.g.,
* rbp, ebp, bp, bpl.
*/
#define regbssd(X) \
do { \
regreg(r##X); \
regreg(e##X); \
regreg(X); \
regreg(X##l); \
} while (0)
/* The r8, ..., r15 registers can be named, e.g.,
* r8, r8d, r8w, r8b.
*/
#define reg8_15(X) \
do { \
regreg(r##X); \
regreg(r##X##d); \
regreg(r##X##w); \
regreg(r##X##b); \
} while (0)
static asmjit::X86GpReg
getGpRegFromName(std::string name) {
using namespace asmjit::x86;
regabcd(a); regabcd(b); regabcd(c); regabcd(d);
regbssd(bp); regbssd(sp); regbssd(si); regbssd(di);
reg8_15(8); reg8_15(9); reg8_15(10); reg8_15(11);
reg8_15(12); reg8_15(13); reg8_15(14); reg8_15(15);
return noGpReg;
}
static asmjit::X86Reg
getRegFromName(std::string name) {
if (tolower(name.at(0)) == 'x') {
return getXmmRegFromName(name);
} else if (tolower(name.at(0)) == 'y') {
return getYmmRegFromName(name);
} else
return getGpRegFromName(name);
}
asmjit::X86Mem
parse_pointer_intel(std::string ptr_str, uint32_t size, bool verbose=false);
#undef regreg
#endif /* AJS_PARSING_H_ */