libTriton version 1.0 build 1592
Loading...
Searching...
No Matches
init.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
10
11#include <iostream>
12
13
14
15namespace triton {
16 namespace bindings {
17 namespace python {
18
19 /* Triton module */
20 PyObject* tritonModule = nullptr; /* Must be global because may be updated on-the-fly */
21
23 PyModuleDef_HEAD_INIT,
24 "triton",
25 NULL,
26 -1,
27 #if IS_PY3
29 NULL, /* m_slots */
30 NULL, /* m_traverse */
31 NULL, /* m_clear */
32 NULL /* m_free */
33 #else
35 #endif
36 };
37
38 /* Python entry point (Py2/3) */
39 #if IS_PY3
40 PyMODINIT_FUNC PyInit_triton(void) {
41 #else
42 PyMODINIT_FUNC inittriton(void) {
43 PyInit_triton();
44 }
45 PyObject* PyInit_triton(void) {
46 #endif
47 /* Init python */
48 Py_Initialize();
49
50 /* Create the triton module ================================================================== */
51
54 std::cerr << "Failed to initialize the triton bindings" << std::endl;
55 PyErr_Print();
56 return nullptr;
57 }
58
59 /* Create the ARCH namespace ================================================================= */
60
61 PyObject* archDict = xPyDict_New();
62 initArchNamespace(archDict);
63 PyObject* idArchClass = xPyClass_New(nullptr, archDict, xPyString_FromString("ARCH"));
64
65 /* Create the AST_NODE namespace ============================================================= */
66
67 PyObject* astNodeDict = xPyDict_New();
68 initAstNodeNamespace(astNodeDict);
69 PyObject* idAstNodeClass = xPyClass_New(nullptr, astNodeDict, xPyString_FromString("AST_NODE"));
70
71 /* Create the AST_REPRESENTATION namespace =================================================== */
72
73 PyObject* astRepresentationDict = xPyDict_New();
74 initAstRepresentationNamespace(astRepresentationDict);
75 PyObject* idAstRepresentationClass = xPyClass_New(nullptr, astRepresentationDict, xPyString_FromString("AST_REPRESENTATION"));
76
77 /* Create the CALLBACK namespace ============================================================= */
78
79 PyObject* callbackDict = xPyDict_New();
80 initCallbackNamespace(callbackDict);
81 PyObject* idCallbackClass = xPyClass_New(nullptr, callbackDict, xPyString_FromString("CALLBACK"));
82
83 /* Create the CONDITION namespace ============================================================ */
84
85 PyObject* conditionsDict = xPyDict_New();
86 initConditionsNamespace(conditionsDict);
87 PyObject* idConditionsClass = xPyClass_New(nullptr, conditionsDict, xPyString_FromString("CONDITION"));
88
89 /* Create the CPUSIZE namespace ============================================================== */
90
91 PyObject* cpuSizeDict = xPyDict_New();
92 initCpuSizeNamespace(cpuSizeDict);
93 PyObject* idCpuSizeClass = xPyClass_New(nullptr, cpuSizeDict, xPyString_FromString("CPUSIZE"));
94
95 /* Create the EXCEPTION namespace ============================================================ */
96
97 PyObject* exceptionDict = xPyDict_New();
98 initExceptionNamespace(exceptionDict);
99 PyObject* idExceptionClass = xPyClass_New(nullptr, exceptionDict, xPyString_FromString("EXCEPTION"));
100
101 /* Create the EXTEND namespace =============================================================== */
102
103 PyObject* extendDict = xPyDict_New();
104 initExtendNamespace(extendDict);
105 PyObject* idExtendClass = xPyClass_New(nullptr, extendDict, xPyString_FromString("EXTEND"));
106
107 /* Create the VAS namespace ================================================================== */
108
109 PyObject* vasDict = xPyDict_New();
110 initVASNamespace(vasDict);
111 PyObject* idVASClass = xPyClass_New(nullptr, vasDict, xPyString_FromString("VAS"));
112
113 /* Create the OPCODE namespace =============================================================== */
114
115 PyObject* opcodesDict = xPyDict_New();
116 initOpcodesNamespace(opcodesDict);
117 PyObject* idOpcodesClass = xPyClass_New(nullptr, opcodesDict, xPyString_FromString("OPCODE"));
118
119 /* Create the OPERAND namespace ============================================================== */
120
121 PyObject* operandDict = xPyDict_New();
122 initOperandNamespace(operandDict);
123 PyObject* idOperandClass = xPyClass_New(nullptr, operandDict, xPyString_FromString("OPERAND"));
124
125 /* Create the OPTIMIZATION namespace ========================================================= */
126
127 PyObject* modeDict = xPyDict_New();
128 initModeNamespace(modeDict);
129 PyObject* idModeClass = xPyClass_New(nullptr, modeDict, xPyString_FromString("MODE"));
130
131 /* Create the PREFIX namespace =============================================================== */
132
133 PyObject* prefixesDict = xPyDict_New();
134 initPrefixesNamespace(prefixesDict);
135 PyObject* idPrefixesClass = xPyClass_New(nullptr, prefixesDict, xPyString_FromString("PREFIX"));
136
137 /* Create the REG namespace ================================================================== */
138
139 PyObject* registersDict = xPyDict_New();
140 initRegNamespace(registersDict);
141 PyObject* idRegClass = xPyClass_New(nullptr, registersDict, xPyString_FromString("REG"));
142
143 /* Create the SHIFT namespace ================================================================ */
144
145 PyObject* shiftsDict = xPyDict_New();
146 initShiftsNamespace(shiftsDict);
147 PyObject* idShiftsClass = xPyClass_New(nullptr, shiftsDict, xPyString_FromString("SHIFT"));
148
149 /* Create the SOLVER namespace =============================================================== */
150
151 PyObject* solverDict = xPyDict_New();
152 initSolverNamespace(solverDict);
153 PyObject* idSolverClass = xPyClass_New(nullptr, solverDict, xPyString_FromString("SOLVER"));
154
155 /* Create the SOLVER_STATE namespace ========================================================= */
156
157 PyObject* solverStateDict = xPyDict_New();
158 initSolverStateNamespace(solverStateDict);
159 PyObject* idSolverStateClass = xPyClass_New(nullptr, solverStateDict, xPyString_FromString("SOLVER_STATE"));
160
161 /* Create the STUBS namespace ============================================================= */
162
163 PyObject* stubsDict = xPyDict_New();
164 initStubsNamespace(stubsDict);
165 PyObject* idStubsClass = xPyClass_New(nullptr, stubsDict, xPyString_FromString("STUBS"));
166
167 /* Create the SYMBOLIC namespace ============================================================= */
168
169 PyObject* symbolicDict = xPyDict_New();
170 initSymbolicNamespace(symbolicDict);
171 PyObject* idSymbolicClass = xPyClass_New(nullptr, symbolicDict, xPyString_FromString("SYMBOLIC"));
172
173 /* Create the VERSION namespace ============================================================== */
174
175 PyObject* versionDict = xPyDict_New();
176 initVersionNamespace(versionDict);
177 PyObject* idVersionClass = xPyClass_New(nullptr, versionDict, xPyString_FromString("VERSION"));
178
179
180 /* Init triton module ======================================================================== */
181
182 /* Add every modules and namespace into the triton module */
183 PyModule_AddObject(triton::bindings::python::tritonModule, "ARCH", idArchClass);
184 PyModule_AddObject(triton::bindings::python::tritonModule, "AST_NODE", idAstNodeClass);
185 PyModule_AddObject(triton::bindings::python::tritonModule, "AST_REPRESENTATION", idAstRepresentationClass);
186 PyModule_AddObject(triton::bindings::python::tritonModule, "CALLBACK", idCallbackClass);
187 PyModule_AddObject(triton::bindings::python::tritonModule, "CONDITION", idConditionsClass);
188 PyModule_AddObject(triton::bindings::python::tritonModule, "CPUSIZE", idCpuSizeClass);
189 PyModule_AddObject(triton::bindings::python::tritonModule, "EXCEPTION", idExceptionClass);
190 PyModule_AddObject(triton::bindings::python::tritonModule, "EXTEND", idExtendClass);
191 PyModule_AddObject(triton::bindings::python::tritonModule, "MODE", idModeClass);
192 PyModule_AddObject(triton::bindings::python::tritonModule, "OPCODE", idOpcodesClass);
193 PyModule_AddObject(triton::bindings::python::tritonModule, "OPERAND", idOperandClass);
194 PyModule_AddObject(triton::bindings::python::tritonModule, "PREFIX", idPrefixesClass);
195 PyModule_AddObject(triton::bindings::python::tritonModule, "REG", idRegClass);
196 PyModule_AddObject(triton::bindings::python::tritonModule, "SHIFT", idShiftsClass);
197 PyModule_AddObject(triton::bindings::python::tritonModule, "SOLVER", idSolverClass);
198 PyModule_AddObject(triton::bindings::python::tritonModule, "SOLVER_STATE", idSolverStateClass);
199 PyModule_AddObject(triton::bindings::python::tritonModule, "STUBS", idStubsClass);
200 PyModule_AddObject(triton::bindings::python::tritonModule, "SYMBOLIC", idSymbolicClass);
201 PyModule_AddObject(triton::bindings::python::tritonModule, "VAS", idVASClass);
202 PyModule_AddObject(triton::bindings::python::tritonModule, "VERSION", idVersionClass);
203
205 }
206
207 }; /* python namespace */
208 }; /* bindings namespace */
209}; /* triton namespace */
210
void initArchNamespace(PyObject *archDict)
Initializes the ARCH python namespace.
void initSolverNamespace(PyObject *solverDict)
Initializes the SOLVER python 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...
void initSymbolicNamespace(PyObject *symbolicDict)
Initializes the SYMBOLIC python namespace.
void initSolverStateNamespace(PyObject *solverStateDict)
Initializes the SOLVER_STATE python namespace.
void initConditionsNamespace(PyObject *conditionsDict)
Initializes the CONDITION python namespace.
PyObject * xPyString_FromString(const char *v)
Creates a PyString and raises an exception if it fails.
void initOperandNamespace(PyObject *operandDict)
Initializes the OPERAND python namespace.
void initAstNodeNamespace(PyObject *astNodeDict)
Initializes the AST_NODE python namespace.
void initRegNamespace(PyObject *registersDict)
Initializes the REG python namespace.
void initCpuSizeNamespace(PyObject *cpuSizeDict)
Initializes the CPUSIZE python namespace.
void initAstRepresentationNamespace(PyObject *astRepresentationDict)
Initializes the AST_REPRESENTATION python namespace.
void initStubsNamespace(PyObject *stubsDict)
Initializes the STUBS python namespace.
PyMethodDef tritonCallbacks[]
triton python methods.
PyObject * tritonModule
triton python module.
Definition init.cpp:20
PyMODINIT_FUNC inittriton(void)
Entry point python bindings (Py2/3).
Definition init.cpp:42
void initModeNamespace(PyObject *modeDict)
Initializes the MODE python namespace.
void initOpcodesNamespace(PyObject *opcodesDict)
Initializes the OPCODE python namespace.
PyModuleDef tritonModuleDef
triton python module definition.
Definition init.cpp:22
void initCallbackNamespace(PyObject *callbackDict)
Initializes the CALLBACK python namespace.
void initShiftsNamespace(PyObject *shiftsDict)
Initializes the SHIFT python namespace.
void initExceptionNamespace(PyObject *exceptionDict)
Initializes the EXCEPTION python namespace.
void initPrefixesNamespace(PyObject *prefixesDict)
Initializes the PREFIX python namespace.
PyObject * xPyDict_New(void)
Creates a PyDict and raises an exception if it fails.
void initVASNamespace(PyObject *vasDict)
Initializes the VAS python namespace.
void initVersionNamespace(PyObject *versionDict)
Initializes the VERSION python namespace.
void initExtendNamespace(PyObject *extendDict)
Initializes the EXTEND python namespace.
The Triton namespace.