12#include <triton/config.hpp>
15#ifdef TRITON_Z3_INTERFACE
369 Py_TYPE(self)->tp_free((PyObject*)self);
373 static PyObject* AstContext_array(PyObject* self, PyObject* op1) {
374 if (!PyLong_Check(op1) && !PyInt_Check(op1))
375 return PyErr_Format(PyExc_TypeError,
"array(): expected an integer as first argument");
381 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
386 static PyObject* AstContext_assert(PyObject* self, PyObject* op1) {
388 return PyErr_Format(PyExc_TypeError,
"assert_(): expected a AstNode as first argument");
394 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
399 static PyObject* AstContext_bswap(PyObject* self, PyObject* op1) {
401 return PyErr_Format(PyExc_TypeError,
"bswap(): expected a AstNode as first argument");
407 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
412 static PyObject* AstContext_bv(PyObject* self, PyObject* args) {
413 PyObject* op1 =
nullptr;
414 PyObject* op2 =
nullptr;
417 if (PyArg_ParseTuple(args,
"|OO", &op1, &op2) ==
false) {
418 return PyErr_Format(PyExc_TypeError,
"bv(): Invalid number of arguments");
421 if (op1 ==
nullptr || (!PyLong_Check(op1) && !PyInt_Check(op1)))
422 return PyErr_Format(PyExc_TypeError,
"bv(): expected an integer as first argument");
424 if (op2 ==
nullptr || (!PyLong_Check(op2) && !PyInt_Check(op2)))
425 return PyErr_Format(PyExc_TypeError,
"bv(): expected an integer as second argument");
431 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
436 static PyObject* AstContext_bvadd(PyObject* self, PyObject* args) {
437 PyObject* op1 =
nullptr;
438 PyObject* op2 =
nullptr;
441 if (PyArg_ParseTuple(args,
"|OO", &op1, &op2) ==
false) {
442 return PyErr_Format(PyExc_TypeError,
"bvadd(): Invalid number of arguments");
446 return PyErr_Format(PyExc_TypeError,
"bvadd(): expected a AstNode as first argument");
449 return PyErr_Format(PyExc_TypeError,
"bvadd(): expected a AstNode as second argument");
455 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
460 static PyObject* AstContext_bvand(PyObject* self, PyObject* args) {
461 PyObject* op1 =
nullptr;
462 PyObject* op2 =
nullptr;
465 if (PyArg_ParseTuple(args,
"|OO", &op1, &op2) ==
false) {
466 return PyErr_Format(PyExc_TypeError,
"bvand(): Invalid number of arguments");
470 return PyErr_Format(PyExc_TypeError,
"bvand(): expected a AstNode as first argument");
473 return PyErr_Format(PyExc_TypeError,
"bvand(): expected a AstNode as second argument");
479 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
484 static PyObject* AstContext_bvashr(PyObject* self, PyObject* args) {
485 PyObject* op1 =
nullptr;
486 PyObject* op2 =
nullptr;
489 if (PyArg_ParseTuple(args,
"|OO", &op1, &op2) ==
false) {
490 return PyErr_Format(PyExc_TypeError,
"bvashr(): Invalid number of arguments");
494 return PyErr_Format(PyExc_TypeError,
"bvashr(): expected a AstNode as first argument");
497 return PyErr_Format(PyExc_TypeError,
"bvashr(): expected a AstNode as second argument");
503 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
508 static PyObject* AstContext_bvfalse(PyObject* self, PyObject* args) {
513 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
518 static PyObject* AstContext_bvtrue(PyObject* self, PyObject* args) {
523 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
528 static PyObject* AstContext_bvlshr(PyObject* self, PyObject* args) {
529 PyObject* op1 =
nullptr;
530 PyObject* op2 =
nullptr;
533 if (PyArg_ParseTuple(args,
"|OO", &op1, &op2) ==
false) {
534 return PyErr_Format(PyExc_TypeError,
"bvlshr(): Invalid number of arguments");
538 return PyErr_Format(PyExc_TypeError,
"bvlshr(): expected a AstNode as first argument");
541 return PyErr_Format(PyExc_TypeError,
"bvlshr(): expected a AstNode as second argument");
547 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
552 static PyObject* AstContext_bvmul(PyObject* self, PyObject* args) {
553 PyObject* op1 =
nullptr;
554 PyObject* op2 =
nullptr;
557 if (PyArg_ParseTuple(args,
"|OO", &op1, &op2) ==
false) {
558 return PyErr_Format(PyExc_TypeError,
"bvmul(): Invalid number of arguments");
562 return PyErr_Format(PyExc_TypeError,
"bvmul(): expected a AstNode as first argument");
565 return PyErr_Format(PyExc_TypeError,
"bvmul(): expected a AstNode as second argument");
571 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
576 static PyObject* AstContext_bvnand(PyObject* self, PyObject* args) {
577 PyObject* op1 =
nullptr;
578 PyObject* op2 =
nullptr;
581 if (PyArg_ParseTuple(args,
"|OO", &op1, &op2) ==
false) {
582 return PyErr_Format(PyExc_TypeError,
"bvnand(): Invalid number of arguments");
586 return PyErr_Format(PyExc_TypeError,
"bvnand(): expected a AstNode as first argument");
589 return PyErr_Format(PyExc_TypeError,
"bvnand(): expected a AstNode as second argument");
595 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
600 static PyObject* AstContext_bvneg(PyObject* self, PyObject* op1) {
602 return PyErr_Format(PyExc_TypeError,
"bvneg(): expected a AstNode as first argument");
608 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
613 static PyObject* AstContext_bvnor(PyObject* self, PyObject* args) {
614 PyObject* op1 =
nullptr;
615 PyObject* op2 =
nullptr;
618 if (PyArg_ParseTuple(args,
"|OO", &op1, &op2) ==
false) {
619 return PyErr_Format(PyExc_TypeError,
"bvnor(): Invalid number of arguments");
623 return PyErr_Format(PyExc_TypeError,
"bvnor(): expected a AstNode as first argument");
626 return PyErr_Format(PyExc_TypeError,
"bvnor(): expected a AstNode as second argument");
632 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
637 static PyObject* AstContext_bvnot(PyObject* self, PyObject* op1) {
639 return PyErr_Format(PyExc_TypeError,
"bvnot(): expected a AstNode as first argument");
645 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
650 static PyObject* AstContext_bvor(PyObject* self, PyObject* args) {
651 PyObject* op1 =
nullptr;
652 PyObject* op2 =
nullptr;
655 if (PyArg_ParseTuple(args,
"|OO", &op1, &op2) ==
false) {
656 return PyErr_Format(PyExc_TypeError,
"bvor(): Invalid number of arguments");
660 return PyErr_Format(PyExc_TypeError,
"bvor(): expected a AstNode as first argument");
663 return PyErr_Format(PyExc_TypeError,
"bvor(): expected a AstNode as second argument");
669 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
674 static PyObject* AstContext_bvror(PyObject* self, PyObject* args) {
675 PyObject* op1 =
nullptr;
676 PyObject* op2 =
nullptr;
679 if (PyArg_ParseTuple(args,
"|OO", &op1, &op2) ==
false) {
680 return PyErr_Format(PyExc_TypeError,
"bvror(): Invalid number of arguments");
684 return PyErr_Format(PyExc_TypeError,
"bvror(): expected a AstNode as first argument");
687 return PyErr_Format(PyExc_TypeError,
"bvror(): expected a AstNode as second argument");
693 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
698 static PyObject* AstContext_bvrol(PyObject* self, PyObject* args) {
699 PyObject* op1 =
nullptr;
700 PyObject* op2 =
nullptr;
703 if (PyArg_ParseTuple(args,
"|OO", &op1, &op2) ==
false) {
704 return PyErr_Format(PyExc_TypeError,
"bvrol(): Invalid number of arguments");
708 return PyErr_Format(PyExc_TypeError,
"bvrol(): expected a AstNode as first argument");
711 return PyErr_Format(PyExc_TypeError,
"bvrol(): expected a AstNode as second argument");
717 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
722 static PyObject* AstContext_bvsdiv(PyObject* self, PyObject* args) {
723 PyObject* op1 =
nullptr;
724 PyObject* op2 =
nullptr;
727 if (PyArg_ParseTuple(args,
"|OO", &op1, &op2) ==
false) {
728 return PyErr_Format(PyExc_TypeError,
"bvsdiv(): Invalid number of arguments");
732 return PyErr_Format(PyExc_TypeError,
"bvsdiv(): expected a AstNode as first argument");
735 return PyErr_Format(PyExc_TypeError,
"bvsdiv(): expected a AstNode as second argument");
741 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
746 static PyObject* AstContext_bvsge(PyObject* self, PyObject* args) {
747 PyObject* op1 =
nullptr;
748 PyObject* op2 =
nullptr;
751 if (PyArg_ParseTuple(args,
"|OO", &op1, &op2) ==
false) {
752 return PyErr_Format(PyExc_TypeError,
"bvsge(): Invalid number of arguments");
756 return PyErr_Format(PyExc_TypeError,
"bvsge(): expected a AstNode as first argument");
759 return PyErr_Format(PyExc_TypeError,
"bvsge(): expected a AstNode as second argument");
765 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
770 static PyObject* AstContext_bvsgt(PyObject* self, PyObject* args) {
771 PyObject* op1 =
nullptr;
772 PyObject* op2 =
nullptr;
775 if (PyArg_ParseTuple(args,
"|OO", &op1, &op2) ==
false) {
776 return PyErr_Format(PyExc_TypeError,
"bvsgt(): Invalid number of arguments");
780 return PyErr_Format(PyExc_TypeError,
"bvsgt(): expected a AstNode as first argument");
783 return PyErr_Format(PyExc_TypeError,
"bvsgt(): expected a AstNode as second argument");
789 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
794 static PyObject* AstContext_bvshl(PyObject* self, PyObject* args) {
795 PyObject* op1 =
nullptr;
796 PyObject* op2 =
nullptr;
799 if (PyArg_ParseTuple(args,
"|OO", &op1, &op2) ==
false) {
800 return PyErr_Format(PyExc_TypeError,
"bvshl(): Invalid number of arguments");
804 return PyErr_Format(PyExc_TypeError,
"bvshl(): expected a AstNode as first argument");
807 return PyErr_Format(PyExc_TypeError,
"bvshl(): expected a AstNode as second argument");
813 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
818 static PyObject* AstContext_bvsle(PyObject* self, PyObject* args) {
819 PyObject* op1 =
nullptr;
820 PyObject* op2 =
nullptr;
823 if (PyArg_ParseTuple(args,
"|OO", &op1, &op2) ==
false) {
824 return PyErr_Format(PyExc_TypeError,
"bvsle(): Invalid number of arguments");
828 return PyErr_Format(PyExc_TypeError,
"bvsle(): expected a AstNode as first argument");
831 return PyErr_Format(PyExc_TypeError,
"bvsle(): expected a AstNode as second argument");
837 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
842 static PyObject* AstContext_bvslt(PyObject* self, PyObject* args) {
843 PyObject* op1 =
nullptr;
844 PyObject* op2 =
nullptr;
847 if (PyArg_ParseTuple(args,
"|OO", &op1, &op2) ==
false) {
848 return PyErr_Format(PyExc_TypeError,
"bvslt(): Invalid number of arguments");
852 return PyErr_Format(PyExc_TypeError,
"bvslt(): expected a AstNode as first argument");
855 return PyErr_Format(PyExc_TypeError,
"bvslt(): expected a AstNode as second argument");
861 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
866 static PyObject* AstContext_bvsmod(PyObject* self, PyObject* args) {
867 PyObject* op1 =
nullptr;
868 PyObject* op2 =
nullptr;
871 if (PyArg_ParseTuple(args,
"|OO", &op1, &op2) ==
false) {
872 return PyErr_Format(PyExc_TypeError,
"bvsmod(): Invalid number of arguments");
876 return PyErr_Format(PyExc_TypeError,
"bvsmod(): expected a AstNode as first argument");
879 return PyErr_Format(PyExc_TypeError,
"bvsmod(): expected a AstNode as second argument");
885 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
890 static PyObject* AstContext_bvsrem(PyObject* self, PyObject* args) {
891 PyObject* op1 =
nullptr;
892 PyObject* op2 =
nullptr;
895 if (PyArg_ParseTuple(args,
"|OO", &op1, &op2) ==
false) {
896 return PyErr_Format(PyExc_TypeError,
"bvsrem(): Invalid number of arguments");
900 return PyErr_Format(PyExc_TypeError,
"bvsrem(): expected a AstNode as first argument");
903 return PyErr_Format(PyExc_TypeError,
"bvsrem(): expected a AstNode as second argument");
909 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
914 static PyObject* AstContext_bvsub(PyObject* self, PyObject* args) {
915 PyObject* op1 =
nullptr;
916 PyObject* op2 =
nullptr;
919 if (PyArg_ParseTuple(args,
"|OO", &op1, &op2) ==
false) {
920 return PyErr_Format(PyExc_TypeError,
"bvsub(): Invalid number of arguments");
924 return PyErr_Format(PyExc_TypeError,
"bvsub(): expected a AstNode as first argument");
927 return PyErr_Format(PyExc_TypeError,
"bvsub(): expected a AstNode as second argument");
933 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
938 static PyObject* AstContext_bvudiv(PyObject* self, PyObject* args) {
939 PyObject* op1 =
nullptr;
940 PyObject* op2 =
nullptr;
943 if (PyArg_ParseTuple(args,
"|OO", &op1, &op2) ==
false) {
944 return PyErr_Format(PyExc_TypeError,
"bvudiv(): Invalid number of arguments");
948 return PyErr_Format(PyExc_TypeError,
"bvudiv(): expected a AstNode as first argument");
951 return PyErr_Format(PyExc_TypeError,
"bvudiv(): expected a AstNode as second argument");
957 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
962 static PyObject* AstContext_bvuge(PyObject* self, PyObject* args) {
963 PyObject* op1 =
nullptr;
964 PyObject* op2 =
nullptr;
967 if (PyArg_ParseTuple(args,
"|OO", &op1, &op2) ==
false) {
968 return PyErr_Format(PyExc_TypeError,
"bvuge(): Invalid number of arguments");
972 return PyErr_Format(PyExc_TypeError,
"bvuge(): expected a AstNode as first argument");
975 return PyErr_Format(PyExc_TypeError,
"bvuge(): expected a AstNode as second argument");
981 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
986 static PyObject* AstContext_bvugt(PyObject* self, PyObject* args) {
987 PyObject* op1 =
nullptr;
988 PyObject* op2 =
nullptr;
991 if (PyArg_ParseTuple(args,
"|OO", &op1, &op2) ==
false) {
992 return PyErr_Format(PyExc_TypeError,
"bvugt(): Invalid number of arguments");
996 return PyErr_Format(PyExc_TypeError,
"bvugt(): expected a AstNode as first argument");
999 return PyErr_Format(PyExc_TypeError,
"bvugt(): expected a AstNode as second argument");
1005 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
1010 static PyObject* AstContext_bvule(PyObject* self, PyObject* args) {
1011 PyObject* op1 =
nullptr;
1012 PyObject* op2 =
nullptr;
1015 if (PyArg_ParseTuple(args,
"|OO", &op1, &op2) ==
false) {
1016 return PyErr_Format(PyExc_TypeError,
"bvule(): Invalid number of arguments");
1020 return PyErr_Format(PyExc_TypeError,
"bvule(): expected a AstNode as first argument");
1023 return PyErr_Format(PyExc_TypeError,
"bvule(): expected a AstNode as second argument");
1029 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
1034 static PyObject* AstContext_bvult(PyObject* self, PyObject* args) {
1035 PyObject* op1 =
nullptr;
1036 PyObject* op2 =
nullptr;
1039 if (PyArg_ParseTuple(args,
"|OO", &op1, &op2) ==
false) {
1040 return PyErr_Format(PyExc_TypeError,
"bvult(): Invalid number of arguments");
1044 return PyErr_Format(PyExc_TypeError,
"bvult(): expected a AstNode as first argument");
1047 return PyErr_Format(PyExc_TypeError,
"bvult(): expected a AstNode as second argument");
1053 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
1058 static PyObject* AstContext_bvurem(PyObject* self, PyObject* args) {
1059 PyObject* op1 =
nullptr;
1060 PyObject* op2 =
nullptr;
1063 if (PyArg_ParseTuple(args,
"|OO", &op1, &op2) ==
false) {
1064 return PyErr_Format(PyExc_TypeError,
"bvurem(): Invalid number of arguments");
1068 return PyErr_Format(PyExc_TypeError,
"bvurem(): expected a AstNode as first argument");
1071 return PyErr_Format(PyExc_TypeError,
"bvurem(): expected a AstNode as second argument");
1077 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
1082 static PyObject* AstContext_bvxnor(PyObject* self, PyObject* args) {
1083 PyObject* op1 =
nullptr;
1084 PyObject* op2 =
nullptr;
1087 if (PyArg_ParseTuple(args,
"|OO", &op1, &op2) ==
false) {
1088 return PyErr_Format(PyExc_TypeError,
"bvxnor(): Invalid number of arguments");
1092 return PyErr_Format(PyExc_TypeError,
"bvxnor(): expected a AstNode as first argument");
1095 return PyErr_Format(PyExc_TypeError,
"bvxnor(): expected a AstNode as second argument");
1101 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
1106 static PyObject* AstContext_bvxor(PyObject* self, PyObject* args) {
1107 PyObject* op1 =
nullptr;
1108 PyObject* op2 =
nullptr;
1111 if (PyArg_ParseTuple(args,
"|OO", &op1, &op2) ==
false) {
1112 return PyErr_Format(PyExc_TypeError,
"bvxor(): Invalid number of arguments");
1116 return PyErr_Format(PyExc_TypeError,
"bvxor(): expected a AstNode as first argument");
1119 return PyErr_Format(PyExc_TypeError,
"bvxor(): expected a AstNode as second argument");
1125 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
1130 static PyObject* AstContext_declare(PyObject* self, PyObject* sort) {
1132 return PyErr_Format(PyExc_TypeError,
"declare(): expected a AstNode as argument");
1138 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
1143 static PyObject* AstContext_dereference(PyObject* self, PyObject* node) {
1145 return PyErr_Format(PyExc_TypeError,
"dereference(): Expects a AstNode as argument.");
1151 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
1156 static PyObject* AstContext_distinct(PyObject* self, PyObject* args) {
1157 PyObject* op1 =
nullptr;
1158 PyObject* op2 =
nullptr;
1161 if (PyArg_ParseTuple(args,
"|OO", &op1, &op2) ==
false) {
1162 return PyErr_Format(PyExc_TypeError,
"distinct(): Invalid number of arguments");
1166 return PyErr_Format(PyExc_TypeError,
"distinct(): expected a AstNode as first argument");
1169 return PyErr_Format(PyExc_TypeError,
"distinct(): expected a AstNode as second argument");
1175 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
1180 static PyObject* AstContext_duplicate(PyObject* self, PyObject* node) {
1182 return PyErr_Format(PyExc_TypeError,
"duplicate(): expected a AstNode as argument");
1189 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
1194 static PyObject* AstContext_compound(PyObject* self, PyObject* exprsList) {
1195 std::vector<triton::ast::SharedAbstractNode> exprs;
1197 if (exprsList ==
nullptr || !PyList_Check(exprsList))
1198 return PyErr_Format(PyExc_TypeError,
"compound(): expected a list of AstNodes as first argument");
1201 for (Py_ssize_t i = 0; i < PyList_Size(exprsList); i++){
1202 PyObject* item = PyList_GetItem(exprsList, i);
1205 return PyErr_Format(PyExc_TypeError,
"compound(): Each element from the list must be a AstNode");
1214 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
1219 static PyObject* AstContext_concat(PyObject* self, PyObject* exprsList) {
1220 std::vector<triton::ast::SharedAbstractNode> exprs;
1222 if (exprsList ==
nullptr || !PyList_Check(exprsList))
1223 return PyErr_Format(PyExc_TypeError,
"concat(): expected a list of AstNodes as first argument");
1226 for (Py_ssize_t i = 0; i < PyList_Size(exprsList); i++){
1227 PyObject* item = PyList_GetItem(exprsList, i);
1230 return PyErr_Format(PyExc_TypeError,
"concat(): Each element from the list must be a AstNode");
1239 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
1244 static PyObject* AstContext_equal(PyObject* self, PyObject* args) {
1245 PyObject* op1 =
nullptr;
1246 PyObject* op2 =
nullptr;
1249 if (PyArg_ParseTuple(args,
"|OO", &op1, &op2) ==
false) {
1250 return PyErr_Format(PyExc_TypeError,
"equal(): Invalid number of arguments");
1254 return PyErr_Format(PyExc_TypeError,
"equal(): expected a AstNode as first argument");
1257 return PyErr_Format(PyExc_TypeError,
"equal(): expected a AstNode as second argument");
1263 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
1268 static PyObject* AstContext_extract(PyObject* self, PyObject* args) {
1269 PyObject* op1 =
nullptr;
1270 PyObject* op2 =
nullptr;
1271 PyObject* op3 =
nullptr;
1274 if (PyArg_ParseTuple(args,
"|OOO", &op1, &op2, &op3) ==
false) {
1275 return PyErr_Format(PyExc_TypeError,
"extract(): Invalid number of arguments");
1278 if (op1 ==
nullptr || (!PyLong_Check(op1) && !PyInt_Check(op1)))
1279 return PyErr_Format(PyExc_TypeError,
"extract(): expected an integer as first argument");
1281 if (op2 ==
nullptr || (!PyLong_Check(op2) && !PyInt_Check(op2)))
1282 return PyErr_Format(PyExc_TypeError,
"extract(): expected an integer as second argument");
1285 return PyErr_Format(PyExc_TypeError,
"extract(): expected a AstNode as third argument");
1291 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
1296 static PyObject* AstContext_forall(PyObject* self, PyObject* args) {
1297 std::vector<triton::ast::SharedAbstractNode> vars;
1298 PyObject* op1 =
nullptr;
1299 PyObject* op2 =
nullptr;
1302 if (PyArg_ParseTuple(args,
"|OO", &op1, &op2) ==
false) {
1303 return PyErr_Format(PyExc_TypeError,
"forall(): Invalid number of arguments");
1306 if (op1 ==
nullptr || !PyList_Check(op1))
1307 return PyErr_Format(PyExc_TypeError,
"forall(): expected a list of AstNodes as first argument");
1310 return PyErr_Format(PyExc_TypeError,
"forall(): expected a AstNode as second argument");
1313 for (Py_ssize_t i = 0; i < PyList_Size(op1); i++){
1314 PyObject* item = PyList_GetItem(op1, i);
1317 return PyErr_Format(PyExc_TypeError,
"forall(): Each element from the list must be a AstNode");
1326 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
1331 static PyObject* AstContext_iff(PyObject* self, PyObject* args) {
1332 PyObject* op1 =
nullptr;
1333 PyObject* op2 =
nullptr;
1336 if (PyArg_ParseTuple(args,
"|OO", &op1, &op2) ==
false) {
1337 return PyErr_Format(PyExc_TypeError,
"iff(): Invalid number of arguments");
1341 return PyErr_Format(PyExc_TypeError,
"iff(): expected a AstNode as first argument");
1344 return PyErr_Format(PyExc_TypeError,
"iff(): expected a AstNode as second argument");
1350 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
1355 static PyObject* AstContext_ite(PyObject* self, PyObject* args) {
1356 PyObject* op1 =
nullptr;
1357 PyObject* op2 =
nullptr;
1358 PyObject* op3 =
nullptr;
1361 if (PyArg_ParseTuple(args,
"|OOO", &op1, &op2, &op3) ==
false) {
1362 return PyErr_Format(PyExc_TypeError,
"ite(): Invalid number of arguments");
1366 return PyErr_Format(PyExc_TypeError,
"ite(): expected a AstNode as first argument");
1369 return PyErr_Format(PyExc_TypeError,
"ite(): expected a AstNode as second argument");
1372 return PyErr_Format(PyExc_TypeError,
"ite(): expected a AstNode as third argument");
1378 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
1383 static PyObject* AstContext_land(PyObject* self, PyObject* exprsList) {
1384 std::vector<triton::ast::SharedAbstractNode> exprs;
1386 if (exprsList ==
nullptr || !PyList_Check(exprsList))
1387 return PyErr_Format(PyExc_TypeError,
"land(): expected a list of AstNodes as first argument");
1390 for (Py_ssize_t i = 0; i < PyList_Size(exprsList); i++){
1391 PyObject* item = PyList_GetItem(exprsList, i);
1394 return PyErr_Format(PyExc_TypeError,
"land(): Each element from the list must be a AstNode");
1403 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
1408 static PyObject* AstContext_let(PyObject* self, PyObject* args) {
1409 PyObject* op1 =
nullptr;
1410 PyObject* op2 =
nullptr;
1411 PyObject* op3 =
nullptr;
1414 if (PyArg_ParseTuple(args,
"|OOO", &op1, &op2, &op3) ==
false) {
1415 return PyErr_Format(PyExc_TypeError,
"let(): Invalid number of arguments");
1418 if (op1 ==
nullptr || !PyStr_Check(op1))
1419 return PyErr_Format(PyExc_TypeError,
"let(): expected a string as first argument");
1422 return PyErr_Format(PyExc_TypeError,
"let(): expected a AstNode as second argument");
1425 return PyErr_Format(PyExc_TypeError,
"let(): expected a AstNode as third argument");
1431 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
1436 static PyObject* AstContext_lnot(PyObject* self, PyObject* expr) {
1438 return PyErr_Format(PyExc_TypeError,
"lnot(): expected a AstNode as argument");
1444 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
1449 static PyObject* AstContext_search(PyObject* self, PyObject* args) {
1450 PyObject* ret =
nullptr;
1451 PyObject* op1 =
nullptr;
1452 PyObject* op2 =
nullptr;
1455 if (PyArg_ParseTuple(args,
"|OO", &op1, &op2) ==
false) {
1456 return PyErr_Format(PyExc_TypeError,
"search(): Invalid number of arguments");
1460 return PyErr_Format(PyExc_TypeError,
"search(): expected a AstNode object as first argument");
1462 if (op2 ==
nullptr || (!PyLong_Check(op2) && !PyInt_Check(op2)))
1463 return PyErr_Format(PyExc_TypeError,
"search(): expected a AST_NODE enum as second argument");
1470 for (
auto&& node : nodes)
1471 PyList_SetItem(ret, index++,
PyAstNode(node));
1476 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
1481 static PyObject* AstContext_lor(PyObject* self, PyObject* exprsList) {
1482 std::vector<triton::ast::SharedAbstractNode> exprs;
1484 if (exprsList ==
nullptr || !PyList_Check(exprsList))
1485 return PyErr_Format(PyExc_TypeError,
"lor(): expected a list of AstNodes as first argument");
1488 for (Py_ssize_t i = 0; i < PyList_Size(exprsList); i++){
1489 PyObject* item = PyList_GetItem(exprsList, i);
1492 return PyErr_Format(PyExc_TypeError,
"lor(): Each element from the list must be a AstNode");
1501 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
1506 static PyObject* AstContext_lxor(PyObject* self, PyObject* exprsList) {
1507 std::vector<triton::ast::SharedAbstractNode> exprs;
1509 if (exprsList ==
nullptr || !PyList_Check(exprsList))
1510 return PyErr_Format(PyExc_TypeError,
"lxor(): expected a list of AstNodes as first argument");
1513 for (Py_ssize_t i = 0; i < PyList_Size(exprsList); i++){
1514 PyObject* item = PyList_GetItem(exprsList, i);
1517 return PyErr_Format(PyExc_TypeError,
"lxor(): Each element from the list must be a AstNode");
1526 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
1531 static PyObject* AstContext_reference(PyObject* self, PyObject* symExpr) {
1533 return PyErr_Format(PyExc_TypeError,
"reference(): expected a symbolic expression as argument");
1539 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
1544 static PyObject* AstContext_select(PyObject* self, PyObject* args) {
1545 PyObject* op1 =
nullptr;
1546 PyObject* op2 =
nullptr;
1549 PyArg_ParseTuple(args,
"|OO", &op1, &op2);
1552 return PyErr_Format(PyExc_TypeError,
"select(): expected a AstNode as first argument");
1554 if (op2 ==
nullptr || (!
PyAstNode_Check(op2) && !PyLong_Check(op2) && !PyInt_Check(op2)))
1555 return PyErr_Format(PyExc_TypeError,
"select(): expected a AstNode or an integer as second argument");
1564 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
1569 static PyObject* AstContext_store(PyObject* self, PyObject* args) {
1570 PyObject* op1 =
nullptr;
1571 PyObject* op2 =
nullptr;
1572 PyObject* op3 =
nullptr;
1575 PyArg_ParseTuple(args,
"|OOO", &op1, &op2, &op3);
1578 return PyErr_Format(PyExc_TypeError,
"store(): expected a AstNode as first argument");
1580 if (op2 ==
nullptr || (!
PyAstNode_Check(op2) && !PyLong_Check(op2) && !PyInt_Check(op2)))
1581 return PyErr_Format(PyExc_TypeError,
"select(): expected a AstNode or an integer as second argument");
1584 return PyErr_Format(PyExc_TypeError,
"store(): expected a AstNode as third argument");
1593 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
1598 static PyObject* AstContext_string(PyObject* self, PyObject* expr) {
1599 if (!PyStr_Check(expr))
1600 return PyErr_Format(PyExc_TypeError,
"string(): expected a string as first argument");
1606 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
1611 static PyObject* AstContext_sx(PyObject* self, PyObject* args) {
1612 PyObject* op1 =
nullptr;
1613 PyObject* op2 =
nullptr;
1616 if (PyArg_ParseTuple(args,
"|OO", &op1, &op2) ==
false) {
1617 return PyErr_Format(PyExc_TypeError,
"sx(): Invalid number of arguments");
1620 if (op1 ==
nullptr || (!PyLong_Check(op1) && !PyInt_Check(op1)))
1621 return PyErr_Format(PyExc_TypeError,
"sx(): expected an integer as first argument");
1624 return PyErr_Format(PyExc_TypeError,
"sx(): expected a AstNode as second argument");
1630 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
1635 static PyObject* AstContext_unroll(PyObject* self, PyObject* node) {
1637 return PyErr_Format(PyExc_TypeError,
"unroll(): Expects a AstNode as argument.");
1643 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
1648 static PyObject* AstContext_variable(PyObject* self, PyObject* symVar) {
1650 return PyErr_Format(PyExc_TypeError,
"variable(): expected a SymbolicVariable as first argument");
1656 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
1661 static PyObject* AstContext_zx(PyObject* self, PyObject* args) {
1662 PyObject* op1 =
nullptr;
1663 PyObject* op2 =
nullptr;
1666 if (PyArg_ParseTuple(args,
"|OO", &op1, &op2) ==
false) {
1667 return PyErr_Format(PyExc_TypeError,
"zx(): Invalid number of arguments");
1670 if (op1 ==
nullptr || (!PyLong_Check(op1) && !PyInt_Check(op1)))
1671 return PyErr_Format(PyExc_TypeError,
"zx(): expected an integer as first argument");
1674 return PyErr_Format(PyExc_TypeError,
"zx(): expected a AstNode as second argument");
1680 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
1686 #ifdef TRITON_Z3_INTERFACE
1687 static PyObject* AstContext_tritonToZ3(PyObject* self, PyObject* node) {
1691 return PyErr_Format(PyExc_TypeError,
"tritonToZ3(): Expects a AstNode as argument.");
1694 PyObject* z3mod = PyImport_ImportModule(
"z3");
1695 if (z3mod ==
nullptr) {
1696 return PyErr_Format(PyExc_TypeError,
"tritonToZ3(): z3 module not found.");
1700 PyObject* z3MainCtx = PyObject_CallObject(PyObject_GetAttrString(z3mod,
"main_ctx"),
nullptr);
1701 PyObject* z3CtxPtr = PyObject_GetAttrString(PyObject_GetAttrString(z3MainCtx,
"ctx"),
"value");
1702 Z3_context z3Ctx =
reinterpret_cast<Z3_context
>(PyLong_AsVoidPtr(z3CtxPtr));
1703 Py_DECREF(z3CtxPtr);
1704 Py_DECREF(z3MainCtx);
1709 Z3_ast ast = Z3_translate(expr.ctx(), expr, z3Ctx);
1712 if (Z3_get_error_code(z3Ctx) != Z3_OK) {
1714 return PyErr_Format(PyExc_RuntimeError,
"tritonToZ3(): Z3 AST translation failed.");
1718 PyObject* pyArgs = Py_BuildValue(
"(O)", PyLong_FromVoidPtr(ast));
1719 PyObject* retAst = PyObject_CallObject(PyObject_GetAttrString(z3mod,
"c_void_p"), pyArgs);
1720 PyObject_SetAttrString(retAst,
"__class__", PyObject_GetAttrString(z3mod,
"Ast"));
1724 PyObject* z3ExprRef = PyObject_GetAttrString(z3mod,
"ExprRef");
1725 pyArgs = Py_BuildValue(
"(O)", retAst);
1726 PyObject* retExpr = PyObject_CallObject(z3ExprRef, pyArgs);
1729 Py_DECREF(z3ExprRef);
1738 static PyObject* AstContext_z3ToTriton(PyObject* self, PyObject* expr) {
1742 if (std::strcmp(Py_TYPE(expr)->tp_name,
"ExprRef") && std::strcmp(Py_TYPE(expr)->tp_name,
"BitVecRef"))
1743 return PyErr_Format(PyExc_TypeError,
"z3ToTriton(): expected an ExprRef as argument");
1745 PyObject* z3AstPtr = PyObject_GetAttrString(expr,
"ast");
1746 if (z3AstPtr ==
nullptr)
1747 return PyErr_Format(PyExc_TypeError,
"z3ToTriton(): expected an ExprRef as argument");
1749 PyObject* z3AstPtrValue = PyObject_GetAttrString(z3AstPtr,
"value");
1750 if (z3AstPtrValue ==
nullptr)
1751 return PyErr_Format(PyExc_TypeError,
"z3ToTriton(): expected an ExprRef as argument");
1754 Z3_ast z3Ast =
reinterpret_cast<Z3_ast
>(PyLong_AsVoidPtr(z3AstPtrValue));
1755 z3::expr z3Expr = z3::to_expr(z3Ctx, z3Ast);
1757 return PyAstNode(z3ToTritonAst.convert(z3Expr));
1760 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
1766 static int AstContext_init(AstNode_Object *self, PyObject *args, PyObject *kwds) {
1771 static PyObject* AstContext_new(PyTypeObject* type, PyObject* args, PyObject* kwds) {
1772 return type->tp_alloc(type, 0);
1778 {
"array", AstContext_array, METH_O,
""},
1779 {
"assert_", AstContext_assert, METH_O,
""},
1780 {
"bswap", AstContext_bswap, METH_O,
""},
1781 {
"bv", AstContext_bv, METH_VARARGS,
""},
1782 {
"bvadd", AstContext_bvadd, METH_VARARGS,
""},
1783 {
"bvand", AstContext_bvand, METH_VARARGS,
""},
1784 {
"bvashr", AstContext_bvashr, METH_VARARGS,
""},
1785 {
"bvfalse", AstContext_bvfalse, METH_NOARGS,
""},
1786 {
"bvlshr", AstContext_bvlshr, METH_VARARGS,
""},
1787 {
"bvmul", AstContext_bvmul, METH_VARARGS,
""},
1788 {
"bvnand", AstContext_bvnand, METH_VARARGS,
""},
1789 {
"bvneg", AstContext_bvneg, METH_O,
""},
1790 {
"bvnor", AstContext_bvnor, METH_VARARGS,
""},
1791 {
"bvnot", AstContext_bvnot, METH_O,
""},
1792 {
"bvor", AstContext_bvor, METH_VARARGS,
""},
1793 {
"bvrol", AstContext_bvrol, METH_VARARGS,
""},
1794 {
"bvror", AstContext_bvror, METH_VARARGS,
""},
1795 {
"bvsdiv", AstContext_bvsdiv, METH_VARARGS,
""},
1796 {
"bvsge", AstContext_bvsge, METH_VARARGS,
""},
1797 {
"bvsgt", AstContext_bvsgt, METH_VARARGS,
""},
1798 {
"bvshl", AstContext_bvshl, METH_VARARGS,
""},
1799 {
"bvsle", AstContext_bvsle, METH_VARARGS,
""},
1800 {
"bvslt", AstContext_bvslt, METH_VARARGS,
""},
1801 {
"bvsmod", AstContext_bvsmod, METH_VARARGS,
""},
1802 {
"bvsrem", AstContext_bvsrem, METH_VARARGS,
""},
1803 {
"bvsub", AstContext_bvsub, METH_VARARGS,
""},
1804 {
"bvtrue", AstContext_bvtrue, METH_NOARGS,
""},
1805 {
"bvudiv", AstContext_bvudiv, METH_VARARGS,
""},
1806 {
"bvuge", AstContext_bvuge, METH_VARARGS,
""},
1807 {
"bvugt", AstContext_bvugt, METH_VARARGS,
""},
1808 {
"bvule", AstContext_bvule, METH_VARARGS,
""},
1809 {
"bvult", AstContext_bvult, METH_VARARGS,
""},
1810 {
"bvurem", AstContext_bvurem, METH_VARARGS,
""},
1811 {
"bvxnor", AstContext_bvxnor , METH_VARARGS,
""},
1812 {
"bvxor", AstContext_bvxor, METH_VARARGS,
""},
1813 {
"compound", AstContext_compound, METH_O,
""},
1814 {
"concat", AstContext_concat, METH_O,
""},
1815 {
"declare", AstContext_declare, METH_O,
""},
1816 {
"dereference", AstContext_dereference, METH_O,
""},
1817 {
"distinct", AstContext_distinct, METH_VARARGS,
""},
1818 {
"duplicate", AstContext_duplicate, METH_O,
""},
1819 {
"equal", AstContext_equal, METH_VARARGS,
""},
1820 {
"extract", AstContext_extract, METH_VARARGS,
""},
1821 {
"forall", AstContext_forall, METH_VARARGS,
""},
1822 {
"iff", AstContext_iff, METH_VARARGS,
""},
1823 {
"ite", AstContext_ite, METH_VARARGS,
""},
1824 {
"land", AstContext_land, METH_O,
""},
1825 {
"let", AstContext_let, METH_VARARGS,
""},
1826 {
"lnot", AstContext_lnot, METH_O,
""},
1827 {
"lor", AstContext_lor, METH_O,
""},
1828 {
"lxor", AstContext_lxor, METH_O,
""},
1829 {
"reference", AstContext_reference, METH_O,
""},
1830 {
"select", AstContext_select, METH_VARARGS,
""},
1831 {
"store", AstContext_store, METH_VARARGS,
""},
1832 {
"search", AstContext_search, METH_VARARGS,
""},
1833 {
"string", AstContext_string, METH_O,
""},
1834 {
"sx", AstContext_sx, METH_VARARGS,
""},
1835 {
"unroll", AstContext_unroll, METH_O,
""},
1836 {
"variable", AstContext_variable, METH_O,
""},
1837 {
"zx", AstContext_zx, METH_VARARGS,
""},
1838 #ifdef TRITON_Z3_INTERFACE
1839 {
"tritonToZ3", AstContext_tritonToZ3, METH_O,
""},
1840 {
"z3ToTriton", AstContext_z3ToTriton, METH_O,
""},
1842 {
nullptr,
nullptr, 0,
nullptr}
1848 PyVarObject_HEAD_INIT(&PyType_Type, 0)
1868 "AstContext objects",
1883 (initproc)AstContext_init,
1885 (newfunc)AstContext_new,
1910 if (actx ==
nullptr) {
1917 if (
object != NULL) {
1918 object->actx = actx;
1921 return (PyObject*)object;
Converts a Triton's AST to Z3's AST.
Converts a Z3's AST to a Triton's AST.
The root class of all exceptions.
TRITON_EXPORT const char * what() const
Returns the exception message.
SharedAbstractNode unroll(const triton::ast::SharedAbstractNode &node)
AST C++ API - Unrolls the SSA form of a given AST.
SharedAbstractNode dereference(const SharedAbstractNode &node)
Returns the first non referene node encountered.
SharedAbstractNode newInstance(AbstractNode *node, bool unroll)
AST C++ API - Duplicates the AST.
std::shared_ptr< triton::ast::AstContext > SharedAstContext
Shared AST context.
std::deque< SharedAbstractNode > search(const SharedAbstractNode &node, triton::ast::ast_e match)
Returns a deque of collected matched nodes via a depth-first pre order traversal.
triton::uint512 PyLong_AsUint512(PyObject *vv)
Returns a triton::uint512 from a pyObject.
PyObject * PyAstContext(const triton::ast::SharedAstContext &actx)
Creates an AstContext python class.
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.
triton::usize PyLong_AsUsize(PyObject *vv)
Returns a triton::usize from a pyObject.
PyObject * PyAstNode(const triton::ast::SharedAbstractNode &node)
Creates the AstNode python class.
std::uint32_t uint32
unisgned 32-bits
void AstContext_dealloc(PyObject *self)
AstContext destructor.
PyMethodDef AstContext_callbacks[]
AstContext methods.
PyTypeObject AstContext_Type
Python description for an ast context.
#define PySymbolicVariable_Check(v)
#define PyAstContext_AsAstContext(v)
#define PyAstNode_Check(v)
#define PySymbolicExpression_Check(v)
#define PySymbolicVariable_AsSymbolicVariable(v)
#define PyAstNode_AsAstNode(v)
#define PySymbolicExpression_AsSymbolicExpression(v)