libTriton version 1.0 build 1590
Loading...
Searching...
No Matches
pySolverModel.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
11#include <triton/coreUtils.hpp>
12#include <triton/exceptions.hpp>
14
15#include <iostream>
16
17
18
85namespace triton {
86 namespace bindings {
87 namespace python {
88
90 void SolverModel_dealloc(PyObject* self) {
91 std::cout << std::flush;
92 delete PySolverModel_AsSolverModel(self);
93 Py_TYPE(self)->tp_free((PyObject*)self);
94 }
95
96
97 static PyObject* SolverModel_getId(PyObject* self, PyObject* noarg) {
98 try {
99 return PyLong_FromUsize(PySolverModel_AsSolverModel(self)->getId());
100 }
101 catch (const triton::exceptions::Exception& e) {
102 return PyErr_Format(PyExc_TypeError, "%s", e.what());
103 }
104 }
105
106
107 static PyObject* SolverModel_getValue(PyObject* self, PyObject* noarg) {
108 try {
109 return PyLong_FromUint512(PySolverModel_AsSolverModel(self)->getValue());
110 }
111 catch (const triton::exceptions::Exception& e) {
112 return PyErr_Format(PyExc_TypeError, "%s", e.what());
113 }
114 }
115
116
117 static PyObject* SolverModel_getVariable(PyObject* self, PyObject* noarg) {
118 try {
119 return PySymbolicVariable(PySolverModel_AsSolverModel(self)->getVariable());
120 }
121 catch (const triton::exceptions::Exception& e) {
122 return PyErr_Format(PyExc_TypeError, "%s", e.what());
123 }
124 }
125
126
127 #if !defined(IS_PY3_8) || !IS_PY3_8
128 static int SolverModel_print(PyObject* self, void* io, int s) {
129 std::cout << PySolverModel_AsSolverModel(self);
130 return 0;
131 }
132 #endif
133
134
135 static PyObject* SolverModel_str(PyObject* self) {
136 try {
137 return PyStr_FromFormat("%s", triton::utils::toString(PySolverModel_AsSolverModel(self)).c_str());
138 }
139 catch (const triton::exceptions::Exception& e) {
140 return PyErr_Format(PyExc_TypeError, "%s", e.what());
141 }
142 }
143
144
146 PyMethodDef SolverModel_callbacks[] = {
147 {"getId", SolverModel_getId, METH_NOARGS, ""},
148 {"getValue", SolverModel_getValue, METH_NOARGS, ""},
149 {"getVariable", SolverModel_getVariable, METH_NOARGS, ""},
150 {nullptr, nullptr, 0, nullptr}
151 };
152
153
154 PyTypeObject SolverModel_Type = {
155 PyVarObject_HEAD_INIT(&PyType_Type, 0)
156 "SolverModel", /* tp_name */
157 sizeof(SolverModel_Object), /* tp_basicsize */
158 0, /* tp_itemsize */
159 (destructor)SolverModel_dealloc, /* tp_dealloc */
160 #if IS_PY3_8
161 0, /* tp_vectorcall_offset */
162 #else
163 (printfunc)SolverModel_print, /* tp_print */
164 #endif
165 0, /* tp_getattr */
166 0, /* tp_setattr */
167 0, /* tp_compare */
168 (reprfunc)SolverModel_str, /* tp_repr */
169 0, /* tp_as_number */
170 0, /* tp_as_sequence */
171 0, /* tp_as_mapping */
172 0, /* tp_hash */
173 0, /* tp_call */
174 (reprfunc)SolverModel_str, /* tp_str */
175 0, /* tp_getattro */
176 0, /* tp_setattro */
177 0, /* tp_as_buffer */
178 Py_TPFLAGS_DEFAULT, /* tp_flags */
179 "SolverModel objects", /* tp_doc */
180 0, /* tp_traverse */
181 0, /* tp_clear */
182 0, /* tp_richcompare */
183 0, /* tp_weaklistoffset */
184 0, /* tp_iter */
185 0, /* tp_iternext */
186 SolverModel_callbacks, /* tp_methods */
187 0, /* tp_members */
188 0, /* tp_getset */
189 0, /* tp_base */
190 0, /* tp_dict */
191 0, /* tp_descr_get */
192 0, /* tp_descr_set */
193 0, /* tp_dictoffset */
194 0, /* tp_init */
195 0, /* tp_alloc */
196 0, /* tp_new */
197 0, /* tp_free */
198 0, /* tp_is_gc */
199 0, /* tp_bases */
200 0, /* tp_mro */
201 0, /* tp_cache */
202 0, /* tp_subclasses */
203 0, /* tp_weaklist */
204 0, /* tp_del */
205 #if IS_PY3
206 0, /* tp_version_tag */
207 0, /* tp_finalize */
208 #if IS_PY3_8
209 0, /* tp_vectorcall */
210 #if !IS_PY3_9
211 0, /* bpo-37250: kept for backwards compatibility in CPython 3.8 only */
212 #endif
213 #endif
214 #else
215 0 /* tp_version_tag */
216 #endif
217 };
218
219
221 SolverModel_Object* object;
222
223 PyType_Ready(&SolverModel_Type);
224 object = PyObject_NEW(SolverModel_Object, &SolverModel_Type);
225 if (object != NULL)
226 object->model = new triton::engines::solver::SolverModel(model);
227
228 return (PyObject*)object;
229 }
230
231 }; /* python namespace */
232 }; /* bindings namespace */
233}; /* triton namespace */
This class is used to represent a constraint model solved.
The root class of all exceptions.
TRITON_EXPORT const char * what() const
Returns the exception message.
PyObject * PySymbolicVariable(const triton::engines::symbolic::SharedSymbolicVariable &symVar)
Creates the SymbolicVariable python class.
PyObject * PySolverModel(const triton::engines::solver::SolverModel &model)
Creates the SolverModel python class.
PyObject * PyLong_FromUsize(triton::usize value)
Returns a pyObject from a triton::usize.
Definition utils.cpp:268
PyObject * PyLong_FromUint512(triton::uint512 value)
Returns a pyObject from a triton::uint512.
Definition utils.cpp:410
PyTypeObject SolverModel_Type
pySolverModel type.
std::string toString(const T &obj)
Converts an object to a string.
Definition coreUtils.hpp:38
PyMethodDef SolverModel_callbacks[]
SolverModel methods.
void SolverModel_dealloc(PyObject *self)
SolverModel destructor.
The Triton namespace.
#define PySolverModel_AsSolverModel(v)