libTriton version 1.0 build 1592
Loading...
Searching...
No Matches
initRegNamespace.cpp
Go to the documentation of this file.
1
2/*
3** Copyright (C) - Triton
4**
5** This program is under the terms of the Apache License 2.0.
6*/
7
12
13
14/* setup doctest context
15
16>>> from triton import ARCH, TritonContext, REG
17>>> ctxt = TritonContext()
18>>> ctxt.setArchitecture(ARCH.X86_64)
19
20*/
21
82namespace triton {
83 namespace bindings {
84 namespace python {
85
86 void initRegNamespace(PyObject* registersDict) {
87 PyDict_Clear(registersDict);
88
89 // Create X86 REG namespace
90
91 PyObject* x86RegistersDict = xPyDict_New();
92
93 #define REG_SPEC(UPPER_NAME, _1, _2, _3, _4, _5, _6, _7, X86_AVAIL) \
94 if (X86_AVAIL) \
95 xPyDict_SetItemString(x86RegistersDict, #UPPER_NAME, PyLong_FromUint32(triton::arch::ID_REG_X86_##UPPER_NAME));
96 // Use REG not available in capstone as normal register
97 #define REG_SPEC_NO_CAPSTONE REG_SPEC
98 #include "triton/x86.spec"
99
100 PyObject* x86RegistersDictClass = xPyClass_New(nullptr, x86RegistersDict, xPyString_FromString("X86"));
101 xPyDict_SetItemString(registersDict, "X86", x86RegistersDictClass);
102
103 // Create X86_64 REG namespace
104
105 PyObject* x8664RegistersDict = xPyDict_New();
106
107 #define REG_SPEC(UPPER_NAME, _1, _2, _3, _4, _5, _6, _7, _8) \
108 xPyDict_SetItemString(x8664RegistersDict, #UPPER_NAME, PyLong_FromUint32(triton::arch::ID_REG_X86_##UPPER_NAME));
109 // Use REG not available in capstone as normal register
110 #define REG_SPEC_NO_CAPSTONE REG_SPEC
111 #include "triton/x86.spec"
112
113 PyObject* x8664RegistersDictClass = xPyClass_New(nullptr, x8664RegistersDict, xPyString_FromString("X86_64"));
114 xPyDict_SetItemString(registersDict, "X86_64", x8664RegistersDictClass);
115
116 // Create AArch64 REG namespace
117
118 PyObject* aarch64RegistersDict = xPyDict_New();
119
120 #define REG_SPEC(UPPER_NAME, _1, _2, _3, _4, _5) \
121 xPyDict_SetItemString(aarch64RegistersDict, #UPPER_NAME, PyLong_FromUint32(triton::arch::ID_REG_AARCH64_##UPPER_NAME));
122 // Use REG not available in capstone as normal register
123 #define REG_SPEC_NO_CAPSTONE REG_SPEC
124 #define SYS_REG_SPEC REG_SPEC
125 #include "triton/aarch64.spec"
126
127 PyObject* aarch64RegistersDictClass = xPyClass_New(nullptr, aarch64RegistersDict, xPyString_FromString("AARCH64"));
128 xPyDict_SetItemString(registersDict, "AARCH64", aarch64RegistersDictClass);
129
130 // Create ARM32 REG namespace
131
132 PyObject* arm32RegistersDict = xPyDict_New();
133
134 #define REG_SPEC(UPPER_NAME, _1, _2, _3, _4, _5) \
135 xPyDict_SetItemString(arm32RegistersDict, #UPPER_NAME, PyLong_FromUint32(triton::arch::ID_REG_ARM32_##UPPER_NAME));
136 // Use REG not available in capstone as normal register
137 #define REG_SPEC_NO_CAPSTONE REG_SPEC
138 #include "triton/arm32.spec"
139
140 PyObject* arm32RegistersDictClass = xPyClass_New(nullptr, arm32RegistersDict, xPyString_FromString("ARM32"));
141 xPyDict_SetItemString(registersDict, "ARM32", arm32RegistersDictClass);
142
143 #ifdef COMPILE_RISCV
144 // Create RISCV64 REG namespace
145
146 PyObject* riscv64RegistersDict = xPyDict_New();
147
148 #define REG_SPEC(_0, UPPER_NAME, _1, _2, _3, _4, _5) \
149 xPyDict_SetItemString(riscv64RegistersDict, #UPPER_NAME, PyLong_FromUint32(triton::arch::ID_REG_RV64_##UPPER_NAME));
150 // Use REG not available in capstone as normal register
151 #define REG_SPEC_NO_CAPSTONE REG_SPEC
152 #define SYS_REG_SPEC REG_SPEC
153 #include "triton/riscv64.spec"
154
155 PyObject* riscv64RegistersDictClass = xPyClass_New(nullptr, riscv64RegistersDict, xPyString_FromString("RV64"));
156 xPyDict_SetItemString(registersDict, "RV64", riscv64RegistersDictClass);
157
158 // Create RISCV32 REG namespace
159
160 PyObject* riscv32RegistersDict = xPyDict_New();
161
162 #define REG_SPEC(_0, UPPER_NAME, _1, _2, _3, _4, _5) \
163 xPyDict_SetItemString(riscv32RegistersDict, #UPPER_NAME, PyLong_FromUint32(triton::arch::ID_REG_RV32_##UPPER_NAME));
164 // Use REG not available in capstone as normal register
165 #define REG_SPEC_NO_CAPSTONE REG_SPEC
166 #define SYS_REG_SPEC REG_SPEC
167 #include "triton/riscv32.spec"
168
169 PyObject* riscv32RegistersDictClass = xPyClass_New(nullptr, riscv32RegistersDict, xPyString_FromString("RV32"));
170 xPyDict_SetItemString(registersDict, "RV32", riscv32RegistersDictClass);
171 #endif
172 }
173
174 }; /* python namespace */
175 }; /* bindings namespace */
176}; /* triton namespace */
PyObject * xPyClass_New(PyObject *b, PyObject *d, PyObject *n)
Creates a PyClass and raises an exception if it fails. dict is copied in Py3 ! All references are dec...
PyObject * xPyString_FromString(const char *v)
Creates a PyString and raises an exception if it fails.
void initRegNamespace(PyObject *registersDict)
Initializes the REG python namespace.
PyObject * xPyDict_New(void)
Creates a PyDict and raises an exception if it fails.
int xPyDict_SetItemString(PyObject *p, const char *key, PyObject *val)
Same as PyDict_SetItemString but decrements reference on object.
The Triton namespace.