151 std::cout << std::flush;
153 Py_TYPE(self)->tp_free((PyObject*)self);
157 static PyObject* AstNode_equalTo(PyObject* self, PyObject* other) {
160 return PyErr_Format(PyExc_TypeError,
"AstNode::equalTo(): Expected a AstNode as argument.");
168 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
173 static PyObject* AstNode_evaluate(PyObject* self, PyObject* noarg) {
178 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
183 static PyObject* AstNode_getBitvectorMask(PyObject* self, PyObject* noarg) {
188 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
193 static PyObject* AstNode_getBitvectorSize(PyObject* self, PyObject* noarg) {
198 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
203 static PyObject* AstNode_getChildren(PyObject* self, PyObject* noarg) {
211 PyList_SetItem(children, index,
PyAstNode(node->getChildren()[index]));
216 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
221 static PyObject* AstNode_getHash(PyObject* self, PyObject* noarg) {
226 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
231 static PyObject* AstNode_getInteger(PyObject* self, PyObject* noarg) {
235 return PyErr_Format(PyExc_TypeError,
"AstNode::getInteger(): Only available on INTEGER_NODE type.");
241 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
246 static PyObject* AstNode_getLevel(PyObject* self, PyObject* noarg) {
251 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
256 static PyObject* AstNode_getParents(PyObject* self, PyObject* noarg) {
258 PyObject* ret =
nullptr;
262 for (
auto& sp : parents)
263 PyList_SetItem(ret, index++,
PyAstNode(sp));
267 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
272 static PyObject* AstNode_getString(PyObject* self, PyObject* noarg) {
276 return PyErr_Format(PyExc_TypeError,
"AstNode::getString(): Only available on STRING_NODE type.");
282 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
287 static PyObject* AstNode_getSymbolicExpression(PyObject* self, PyObject* noarg) {
291 return PyErr_Format(PyExc_TypeError,
"AstNode::getSymbolicExpression(): Only available on REFERENCE_NODE type.");
297 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
302 static PyObject* AstNode_getSymbolicVariable(PyObject* self, PyObject* noarg) {
306 return PyErr_Format(PyExc_TypeError,
"AstNode::getSymbolicVariable(): Only available on VARIABLE_NODE type.");
312 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
317 static PyObject* AstNode_getType(PyObject* self, PyObject* noarg) {
322 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
327 static PyObject* AstNode_isArray(PyObject* self, PyObject* noarg) {
334 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
339 static PyObject* AstNode_isLogical(PyObject* self, PyObject* noarg) {
346 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
351 static PyObject* AstNode_isSigned(PyObject* self, PyObject* noarg) {
358 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
363 static PyObject* AstNode_isSymbolized(PyObject* self, PyObject* noarg) {
370 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
375 static PyObject* AstNode_setChild(PyObject* self, PyObject* args) {
377 PyObject* index =
nullptr;
378 PyObject* node =
nullptr;
382 if (PyArg_ParseTuple(args,
"|OO", &index, &node) ==
false) {
383 return PyErr_Format(PyExc_TypeError,
"AstNode::setChild(): Invalid number of arguments");
386 if (index ==
nullptr || (!PyLong_Check(index) && !PyInt_Check(index)))
387 return PyErr_Format(PyExc_TypeError,
"AstNode::setChild(): Expected an index (integer) as first argument.");
390 return PyErr_Format(PyExc_TypeError,
"AstNode::setChild(): Expected a AstNode as second argument.");
395 dst->setChild(idx, src);
400 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
405 #if !defined(IS_PY3_8) || !IS_PY3_8
406 static int AstNode_print(PyObject* self,
void* io,
int s) {
413 #if !defined(IS_PY3) || !IS_PY3
414 static int AstNode_cmp(PyObject* a, PyObject* b) {
418 "__cmp__ not supported between instances of '%.100s' and '%.100s'",
420 b->ob_type->tp_name);
425 return (ha == hb ? 0 : (ha > hb ? 1 : -1));
430 static long AstNode_hash(PyObject* self) {
431 return static_cast<long>(
reinterpret_cast<intptr_t
>(
PyAstNode_AsAstNode(self).get()) & 0xffffffff);
435 static PyObject* AstNode_str(PyObject* self) {
440 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
445 static PyObject* AstNode_operatorAdd(PyObject* self, PyObject* other) {
448 if ((PyInt_Check(self) || PyLong_Check(self)) &&
PyAstNode_Check(other)) {
450 auto ast = nother->getContext();
452 return PyAstNode(ast->bvadd(nself, nother));
455 if (
PyAstNode_Check(self) && (PyInt_Check(other) || PyLong_Check(other))) {
457 auto ast = nself->getContext();
459 return PyAstNode(ast->bvadd(nself, nother));
466 return PyErr_Format(PyExc_TypeError,
"AstNode::operatorAdd(): Expected a AstNode as arguments.");
469 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
474 static PyObject* AstNode_operatorSub(PyObject* self, PyObject* other) {
477 if ((PyInt_Check(self) || PyLong_Check(self)) &&
PyAstNode_Check(other)) {
479 auto ast = nother->getContext();
481 return PyAstNode(ast->bvsub(nself, nother));
484 if (
PyAstNode_Check(self) && (PyInt_Check(other) || PyLong_Check(other))) {
486 auto ast = nself->getContext();
488 return PyAstNode(ast->bvsub(nself, nother));
495 return PyErr_Format(PyExc_TypeError,
"AstNode::operatorSub(): Expected a AstNode as arguments.");
498 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
503 static PyObject* AstNode_operatorMul(PyObject* self, PyObject* other) {
506 if ((PyInt_Check(self) || PyLong_Check(self)) &&
PyAstNode_Check(other)) {
508 auto ast = nother->getContext();
510 return PyAstNode(ast->bvmul(nself, nother));
513 if (
PyAstNode_Check(self) && (PyInt_Check(other) || PyLong_Check(other))) {
515 auto ast = nself->getContext();
517 return PyAstNode(ast->bvmul(nself, nother));
524 return PyErr_Format(PyExc_TypeError,
"AstNode::operatorMul(): Expected a AstNode as arguments.");
527 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
532 static PyObject* AstNode_operatorDiv(PyObject* self, PyObject* other) {
535 if ((PyInt_Check(self) || PyLong_Check(self)) &&
PyAstNode_Check(other)) {
537 auto ast = nother->getContext();
539 return PyAstNode(ast->bvudiv(nself, nother));
542 if (
PyAstNode_Check(self) && (PyInt_Check(other) || PyLong_Check(other))) {
544 auto ast = nself->getContext();
546 return PyAstNode(ast->bvudiv(nself, nother));
553 return PyErr_Format(PyExc_TypeError,
"AstNode::operatorDiv(): Expected a AstNode as arguments.");
556 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
561 static PyObject* AstNode_operatorRem(PyObject* self, PyObject* other) {
564 if ((PyInt_Check(self) || PyLong_Check(self)) &&
PyAstNode_Check(other)) {
566 auto ast = nother->getContext();
568 return PyAstNode(ast->bvurem(nself, nother));
571 if (
PyAstNode_Check(self) && (PyInt_Check(other) || PyLong_Check(other))) {
573 auto ast = nself->getContext();
575 return PyAstNode(ast->bvurem(nself, nother));
582 return PyErr_Format(PyExc_TypeError,
"AstNode::operatorMod(): Expected a AstNode as arguments.");
585 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
590 static PyObject* AstNode_operatorNeg(PyObject* node) {
593 return PyErr_Format(PyExc_TypeError,
"AstNode::operatorNeg(): Expected a AstNode as argument.");
597 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
602 static PyObject* AstNode_operatorNot(PyObject* node) {
605 return PyErr_Format(PyExc_TypeError,
"AstNode::operatorNot(): Expected a AstNode as argument.");
609 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
614 static PyObject* AstNode_operatorShl(PyObject* self, PyObject* other) {
617 if ((PyInt_Check(self) || PyLong_Check(self)) &&
PyAstNode_Check(other)) {
619 auto ast = nother->getContext();
621 return PyAstNode(ast->bvshl(nself, nother));
624 if (
PyAstNode_Check(self) && (PyInt_Check(other) || PyLong_Check(other))) {
626 auto ast = nself->getContext();
628 return PyAstNode(ast->bvshl(nself, nother));
635 return PyErr_Format(PyExc_TypeError,
"AstNode::operatorShl(): Expected a AstNode as arguments.");
638 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
643 static PyObject* AstNode_operatorShr(PyObject* self, PyObject* other) {
646 if ((PyInt_Check(self) || PyLong_Check(self)) &&
PyAstNode_Check(other)) {
648 auto ast = nother->getContext();
650 return PyAstNode(ast->bvlshr(nself, nother));
653 if (
PyAstNode_Check(self) && (PyInt_Check(other) || PyLong_Check(other))) {
655 auto ast = nself->getContext();
657 return PyAstNode(ast->bvlshr(nself, nother));
664 return PyErr_Format(PyExc_TypeError,
"AstNode::operatorShr(): Expected a AstNode as arguments.");
667 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
672 static PyObject* AstNode_operatorAnd(PyObject* self, PyObject* other) {
675 if ((PyInt_Check(self) || PyLong_Check(self)) &&
PyAstNode_Check(other)) {
677 auto ast = nother->getContext();
679 return PyAstNode(ast->bvand(nself, nother));
682 if (
PyAstNode_Check(self) && (PyInt_Check(other) || PyLong_Check(other))) {
684 auto ast = nself->getContext();
686 return PyAstNode(ast->bvand(nself, nother));
693 return PyErr_Format(PyExc_TypeError,
"AstNode::operatorAnd(): Expected a AstNode as arguments.");
696 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
701 static PyObject* AstNode_operatorXor(PyObject* self, PyObject* other) {
704 if ((PyInt_Check(self) || PyLong_Check(self)) &&
PyAstNode_Check(other)) {
706 auto ast = nother->getContext();
708 return PyAstNode(ast->bvxor(nself, nother));
711 if (
PyAstNode_Check(self) && (PyInt_Check(other) || PyLong_Check(other))) {
713 auto ast = nself->getContext();
715 return PyAstNode(ast->bvxor(nself, nother));
722 return PyErr_Format(PyExc_TypeError,
"AstNode::operatorXor(): Expected a AstNode as arguments.");
725 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
730 static PyObject* AstNode_operatorOr(PyObject* self, PyObject* other) {
733 if ((PyInt_Check(self) || PyLong_Check(self)) &&
PyAstNode_Check(other)) {
735 auto ast = nother->getContext();
737 return PyAstNode(ast->bvor(nself, nother));
740 if (
PyAstNode_Check(self) && (PyInt_Check(other) || PyLong_Check(other))) {
742 auto ast = nself->getContext();
744 return PyAstNode(ast->bvor(nself, nother));
751 return PyErr_Format(PyExc_TypeError,
"AstNode::operatorOr(): Expected a AstNode as arguments.");
754 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
759 #if !defined(IS_PY3) || !IS_PY3
760 static int AstNode_coerce(PyObject** self, PyObject** other) {
761 if (PyLong_Check(*other) || PyInt_Check(*other)) {
775 static PyObject* AstNode_richcompare(PyObject* self, PyObject* other,
int op) {
778 PyObject* result =
nullptr;
780 if (PyLong_Check(other) || PyInt_Check(other)) {
793 result = Py_NotImplemented;
800 result =
PyAstNode(node1->getContext()->bvult(node1, node2));
803 result =
PyAstNode(node1->getContext()->bvule(node1, node2));
806 result =
PyAstNode(node1->getContext()->equal(node1, node2));
809 result =
PyAstNode(node1->getContext()->lnot(node1->getContext()->equal(node1, node2)));
812 result =
PyAstNode(node1->getContext()->bvugt(node1, node2));
815 result =
PyAstNode(node1->getContext()->bvuge(node1, node2));
818 result = Py_NotImplemented;
828 static int AstNode_init(AstNode_Object* self, PyObject* args, PyObject* kwds) {
833 static PyObject* AstNode_new(PyTypeObject* type, PyObject* args, PyObject* kwds) {
834 return type->tp_alloc(type, 0);
840 {
"equalTo", AstNode_equalTo, METH_O,
""},
841 {
"evaluate", AstNode_evaluate, METH_NOARGS,
""},
842 {
"getBitvectorMask", AstNode_getBitvectorMask, METH_NOARGS,
""},
843 {
"getBitvectorSize", AstNode_getBitvectorSize, METH_NOARGS,
""},
844 {
"getChildren", AstNode_getChildren, METH_NOARGS,
""},
845 {
"getHash", AstNode_getHash, METH_NOARGS,
""},
846 {
"getInteger", AstNode_getInteger, METH_NOARGS,
""},
847 {
"getLevel", AstNode_getLevel, METH_NOARGS,
""},
848 {
"getParents", AstNode_getParents, METH_NOARGS,
""},
849 {
"getString", AstNode_getString, METH_NOARGS,
""},
850 {
"getSymbolicExpression", AstNode_getSymbolicExpression, METH_NOARGS,
""},
851 {
"getSymbolicVariable", AstNode_getSymbolicVariable, METH_NOARGS,
""},
852 {
"getType", AstNode_getType, METH_NOARGS,
""},
853 {
"isArray", AstNode_isArray, METH_NOARGS,
""},
854 {
"isLogical", AstNode_isLogical, METH_NOARGS,
""},
855 {
"isSigned", AstNode_isSigned, METH_NOARGS,
""},
856 {
"isSymbolized", AstNode_isSymbolized, METH_NOARGS,
""},
857 {
"setChild", AstNode_setChild, METH_VARARGS,
""},
858 {
nullptr,
nullptr, 0,
nullptr}
867 #if !defined(IS_PY3) || !IS_PY3
883 #if !defined(IS_PY3) || !IS_PY3
889 #if !defined(IS_PY3) || !IS_PY3
896 #if !defined(IS_PY3) || !IS_PY3
911 #if defined(IS_PY3) && IS_PY3
919 PyVarObject_HEAD_INIT(&PyType_Type, 0)
927 (printfunc)AstNode_print,
931 #
if defined(IS_PY3) && IS_PY3
934 (cmpfunc)AstNode_cmp,
936 (reprfunc)AstNode_str,
940 (hashfunc)AstNode_hash,
942 (reprfunc)AstNode_str,
950 (richcmpfunc)AstNode_richcompare,
962 (initproc)AstNode_init,
964 (newfunc)AstNode_new,
989 if (node ==
nullptr) {
998 if (
object != NULL) {
1002 return (PyObject*)object;
The root class of all exceptions.
TRITON_EXPORT const char * what() const
Returns the exception message.
std::shared_ptr< triton::ast::AbstractNode > SharedAbstractNode
Shared Abstract Node.
PyTypeObject AstNode_Type
pyAstNode type.
PyObject * PySymbolicVariable(const triton::engines::symbolic::SharedSymbolicVariable &symVar)
Creates the SymbolicVariable python class.
PyObject * PyLong_FromUint512(triton::uint512 value)
Returns a pyObject from a triton::uint512.
triton::uint512 PyLong_AsUint512(PyObject *vv)
Returns a triton::uint512 from a pyObject.
PyObject * xPyList_New(Py_ssize_t len)
Creates a PyList and raises an exception if it fails.
triton::uint32 PyLong_AsUint32(PyObject *vv)
Returns a triton::uint32 from a pyObject.
PyObject * PySymbolicExpression(const triton::engines::symbolic::SharedSymbolicExpression &symExpr)
Creates the SymbolicExpression python class.
PyObject * PyLong_FromUint32(triton::uint32 value)
Returns a pyObject from a triton::uint32.
PyObject * PyAstNode(const triton::ast::SharedAbstractNode &node)
Creates the AstNode python class.
std::size_t usize
unsigned MAX_INT 32 or 64 bits according to the CPU.
std::uint32_t uint32
unisgned 32-bits
std::string toString(const T &obj)
Converts an object to a string.
PyMethodDef AstNode_callbacks[]
AstNode methods.
PyNumberMethods AstNode_NumberMethods
AstNode operator methods.
void AstNode_dealloc(PyObject *self)
AstNode destructor.
#define PyAstNode_Check(v)
#define PyAstNode_AsAstNode(v)