1
//! \file
2
/*
3
**  Copyright (C) - Triton
4
**
5
**  This program is under the terms of the Apache License 2.0.
6
*/
7

8
#include <triton/pythonObjects.hpp>
9
#include <triton/pythonUtils.hpp>
10
#include <triton/pythonXFunctions.hpp>
11
#include <triton/astContext.hpp>
12
#include <triton/config.hpp>
13
#include <triton/exceptions.hpp>
14
#include <triton/register.hpp>
15
#ifdef TRITON_Z3_INTERFACE
16
  #include <triton/tritonToZ3Ast.hpp>
17
  #include <triton/z3ToTritonAst.hpp>
18
#endif
19

20
#include <cstring>
21

22

23

24
/* setup doctest context
25

26
>>> from __future__ import print_function
27
>>> from triton import REG, TritonContext, ARCH, Instruction, AST_REPRESENTATION
28
>>> ctxt = TritonContext()
29
>>> ctxt.setArchitecture(ARCH.X86_64)
30

31
>>> opcode = b"\x48\x31\xD0"
32
>>> inst = Instruction()
33

34
>>> inst.setOpcode(opcode)
35
>>> inst.setAddress(0x400000)
36
>>> ctxt.setConcreteRegisterValue(ctxt.registers.rax, 12345)
37
>>> ctxt.setConcreteRegisterValue(ctxt.registers.rdx, 67890)
38

39
>>> ctxt.processing(inst)
40
True
41
>>> print(inst)
42
0x400000: xor rax, rdx
43

44
*/
45

46
/*! \page py_AstContext_page AstContext
47
    \brief [**python api**] All information about the AstContext Python object.
48

49
\tableofcontents
50

51
\section ast_description Description
52
<hr>
53

54
Triton converts the x86, x86-64 and AArch64 instruction set architecture into an AST representation.
55
This class is used to build your own AST nodes.
56

57
\anchor ast
58
\section AstContext_py_api Python API - Methods of the AstContext class
59
<hr>
60

61
- <b>\ref py_AstNode_page bv(integer value, integer size)</b><br>
62
Creates a `bv` node (bitvector). The `size` must be in bits.<br>
63
e.g: `(_ bv<balue> size)`.
64

65
- <b>\ref py_AstNode_page bvadd(\ref py_AstNode_page node1, \ref py_AstNode_page node2)</b><br>
66
Creates a `bvadd` node.<br>
67
e.g: `(bvadd node1 epxr2)`.
68

69
- <b>\ref py_AstNode_page bvand(\ref py_AstNode_page node1, \ref py_AstNode_page node2)</b><br>
70
Creates a `bvand` node.<br>
71
e.g: `(bvand node1 epxr2)`.
72

73
- <b>\ref py_AstNode_page bvashr(\ref py_AstNode_page node1, \ref py_AstNode_page node2)</b><br>
74
Creates a `bvashr` node (arithmetic shift right).<br>
75
e.g: `(bvashr node1 epxr2)`.
76

77
- <b>\ref py_AstNode_page bvfalse(void)</b><br>
78
This is an alias on the `(_ bv0 1)` ast expression.
79

80
- <b>\ref py_AstNode_page bvlshr(\ref py_AstNode_page node1, \ref py_AstNode_page node2)</b><br>
81
Creates a `bvlshr` node (logical shift right).<br>
82
e.g: `(lshr node1 epxr2)`.
83

84
- <b>\ref py_AstNode_page bvmul(\ref py_AstNode_page node1, \ref py_AstNode_page node2)</b><br>
85
Creates a `bvmul` node.<br>
86
e.g: `(bvmul node1 node2)`.
87

88
- <b>\ref py_AstNode_page bvnand(\ref py_AstNode_page node1, \ref py_AstNode_page node2)</b><br>
89
Creates a `bvnand` node.<br>
90
e.g: `(bvnand node1 node2)`.
91

92
- <b>\ref py_AstNode_page bvneg(\ref py_AstNode_page node1)</b><br>
93
Creates a `bvneg` node.<br>
94
e.g: `(bvneg node1)`.
95

96
- <b>\ref py_AstNode_page bvnor(\ref py_AstNode_page node1, \ref py_AstNode_page node2)</b><br>
97
Creates a `bvnor` node.<br>
98
e.g: `(bvnor node1 node2)`.
99

100
- <b>\ref py_AstNode_page bvnot(\ref py_AstNode_page node1)</b><br>
101
Creates a `bvnot` node.<br>
102
e.g: `(bvnot node1)`.
103

104
- <b>\ref py_AstNode_page bvor(\ref py_AstNode_page node1, \ref py_AstNode_page node2)</b><br>
105
Creates a `bvor` node.<br>
106
e.g: `(bvor node1 node2)`.
107

108
- <b>\ref py_AstNode_page bvror(\ref py_AstNode_page node, \ref py_AstNode_page rot)</b><br>
109
Creates a `bvror` node (rotate right).<br>
110
e.g: `((_ rotate_right rot) node)`.
111

112
- <b>\ref py_AstNode_page bvrol(\ref py_AstNode_page node, \ref py_AstNode_page rot)</b><br>
113
Creates a `bvrol` node (rotate left).<br>
114
e.g: `((_ rotate_left rot) node)`.
115

116
- <b>\ref py_AstNode_page bvsdiv(\ref py_AstNode_page node1, \ref py_AstNode_page node2)</b><br>
117
Creates a `bvsdiv` node.<br>
118
e.g: `(bvsdiv node1 epxr2)`.
119

120
- <b>\ref py_AstNode_page bvsge(\ref py_AstNode_page node1, \ref py_AstNode_page node2)</b><br>
121
Creates a `bvsge` node.<br>
122
e.g: `(bvsge node1 epxr2)`.
123

124
- <b>\ref py_AstNode_page bvsgt(\ref py_AstNode_page node1, \ref py_AstNode_page node2)</b><br>
125
Creates a `bvsgt` node.<br>
126
e.g: `(bvsgt node1 epxr2)`.
127

128
- <b>\ref py_AstNode_page bvshl(\ref py_AstNode_page node1, \ref py_AstNode_page node2)</b><br>
129
Creates a Bvshl node (shift left).<br>
130
e.g: `(bvshl node1 node2)`.
131

132
- <b>\ref py_AstNode_page bvsle(\ref py_AstNode_page node1, \ref py_AstNode_page node2)</b><br>
133
Creates a `bvsle` node.<br>
134
e.g: `(bvsle node1 epxr2)`.
135

136
- <b>\ref py_AstNode_page bvslt(\ref py_AstNode_page node1, \ref py_AstNode_page node2)</b><br>
137
Creates a `bvslt` node.<br>
138
e.g: `(bvslt node1 epxr2)`.
139

140
- <b>\ref py_AstNode_page bvsmod(\ref py_AstNode_page node1, \ref py_AstNode_page node2)</b><br>
141
Creates a `bvsmod` node (2's complement signed remainder, sign follows divisor).<br>
142
e.g: `(bvsmod node1 node2)`.
143

144
- <b>\ref py_AstNode_page bvsrem(\ref py_AstNode_page node1, \ref py_AstNode_page node2)</b><br>
145
Creates a `bvsrem` node (2's complement signed remainder, sign follows dividend).<br>
146
e.g: `(bvsrem node1 node2)`.
147

148
- <b>\ref py_AstNode_page bvsub(\ref py_AstNode_page node1, \ref py_AstNode_page node2)</b><br>
149
Creates a `bvsub` node.<br>
150
e.g: `(bvsub node1 epxr2)`.
151

152
- <b>\ref py_AstNode_page bvtrue(void)</b><br>
153
This is an alias on the `(_ bv1 1)` ast expression.<br>
154

155
- <b>\ref py_AstNode_page bvudiv(\ref py_AstNode_page node1, \ref py_AstNode_page node2)</b><br>
156
Creates a `bvudiv` node.<br>
157
e.g: `(bvudiv node1 epxr2)`.
158

159
- <b>\ref py_AstNode_page bvuge(\ref py_AstNode_page node1, \ref py_AstNode_page node2)</b><br>
160
Creates a `bvuge` node.<br>
161
e.g: `(bvuge node1 epxr2)`.
162

163
- <b>\ref py_AstNode_page bvugt(\ref py_AstNode_page node1, \ref py_AstNode_page node2)</b><br>
164
Creates a `bvugt` node.<br>
165
e.g: `(bvugt node1 epxr2)`.
166

167
- <b>\ref py_AstNode_page bvule(\ref py_AstNode_page node1, \ref py_AstNode_page node2)</b><br>
168
Creates a `bvule` node.<br>
169
e.g: `(bvule node1 epxr2)`.
170

171
- <b>\ref py_AstNode_page bvult(\ref py_AstNode_page node1, \ref py_AstNode_page node2)</b><br>
172
Creates a `bvult` node.<br>
173
e.g: `(bvult node1 epxr2)`.
174

175
- <b>\ref py_AstNode_page bvurem(\ref py_AstNode_page node1, \ref py_AstNode_page node2)</b><br>
176
Creates a `bvurem` node (unsigned remainder).<br>
177
e.g: `(bvurem node1 node2)`.
178

179
- <b>\ref py_AstNode_page bvxnor(\ref py_AstNode_page node1, \ref py_AstNode_page node2)</b><br>
180
Creates a `bvxnor` node.<br>
181
e.g: `(bvxnor node1 node2)`.
182

183
- <b>\ref py_AstNode_page bvxor(\ref py_AstNode_page node1, \ref py_AstNode_page node2)</b><br>
184
Creates a `bvxor` node.<br>
185
e.g: `(bvxor node1 epxr2)`.
186

187
- <b>\ref py_AstNode_page concat([\ref py_AstNode_page, ...])</b><br>
188
Concatenates several nodes.
189

190
- <b>\ref py_AstNode_page distinct(\ref py_AstNode_page node1, \ref py_AstNode_page node2)</b><br>
191
Creates a `distinct` node.<br>
192
e.g: `(distinct node1 node2)`
193

194
- <b>\ref py_AstNode_page equal(\ref py_AstNode_page node1, \ref py_AstNode_page node2)</b><br>
195
Creates an `equal` node.<br>
196
e.g: `(= node1 epxr2)`.
197

198
- <b>\ref py_AstNode_page extract(integer high, integer low, \ref py_AstNode_page node1)</b><br>
199
Creates an `extract` node. The `high` and `low` fields represent the bits position.<br>
200
e.g: `((_ extract high low) node1)`.
201

202
- <b>\ref py_AstNode_page forall([\ref py_AstNode_page var, ...], \ref py_AstNode_page body)</b><br>
203
Creates an `forall` node.<br>
204
e.g: `(forall ((x (_ BitVec <size>)), ...) body)`.
205

206
- <b>\ref py_AstNode_page iff(\ref py_AstNode_page node1, \ref py_AstNode_page node2)</b><br>
207
Creates an `iff` node (if and only if).<br>
208
e.g: `(iff node1 node2)`.
209

210
- <b>\ref py_AstNode_page ite(\ref py_AstNode_page ifExpr, \ref py_AstNode_page thenExpr, \ref py_AstNode_page elseExpr)</b><br>
211
Creates an `ite` node (if-then-else node).<br>
212
e.g: `(ite ifExpr thenExpr elseExpr)`.
213

214
- <b>\ref py_AstNode_page land([\ref py_AstNode_page, ...])</b><br>
215
Creates a logical `AND` on several nodes.
216
e.g: `(and node1 node2 node3 node4)`.
217

218
- <b>\ref py_AstNode_page let(string alias, \ref py_AstNode_page node2, \ref py_AstNode_page node3)</b><br>
219
Creates a `let` node.<br>
220
e.g: `(let ((alias node2)) node3)`.
221

222
- <b>\ref py_AstNode_page lnot(\ref py_AstNode_page node)</b><br>
223
Creates a `lnot` node (logical NOT).<br>
224
e.g: `(not node)`.
225

226
- <b>\ref py_AstNode_page lor([\ref py_AstNode_page, ...])</b><br>
227
Creates a logical `OR` on several nodes.
228
e.g: `(or node1 node2 node3 node4)`.
229

230
- <b>\ref py_AstNode_page lxor([\ref py_AstNode_page, ...])</b><br>
231
Creates a logical `XOR` on several nodes.
232
e.g: `(xor node1 node2 node3 node4)`.
233

234
- <b>\ref py_AstNode_page reference(\ref py_SymbolicExpression_page expr)</b><br>
235
Creates a reference node (SSA-based).<br>
236
e.g: `ref!123`.
237

238
- <b>\ref py_AstNode_page string(string s)</b><br>
239
Creates a `string` node.
240

241
- <b>\ref py_AstNode_page sx(integer sizeExt, \ref py_AstNode_page node1)</b><br>
242
Creates a `sx` node (sign extend).<br>
243
e.g: `((_ sign_extend sizeExt) node1)`.
244

245
- <b>\ref py_AstNode_page variable(\ref py_SymbolicVariable_page symVar)</b><br>
246
Creates a `variable` node.
247

248
- <b>\ref py_AstNode_page zx(integer sizeExt, \ref py_AstNode_page node1)</b><br>
249
Creates a `zx` node (zero extend).<br>
250
e.g: `((_ zero_extend sizeExt) node1)`.
251

252

253
\section AstContext_convert_py_api Python API - Utility methods of the AstContext class
254
<hr>
255

256
- <b>\ref py_AstNode_page duplicate(\ref py_AstNode_page node)</b><br>
257
Duplicates the node and returns a new instance as \ref py_AstNode_page.
258

259
- <b>[\ref py_AstNode_page, ...] search(\ref py_AstNode_page node, \ref py_AST_NODE_page match)</b><br>
260
Returns a list of collected matched nodes via a depth-first pre order traversal.
261

262
- <b>z3::expr tritonToZ3(\ref py_AstNode_page node)</b><br>
263
Convert a Triton AST to a Z3 AST.
264

265
- <b>\ref py_AstNode_page unroll(\ref py_AstNode_page node)</b><br>
266
Unrolls the SSA form of a given AST.
267

268
- <b>\ref py_AstNode_page z3ToTriton(z3::expr expr)</b><br>
269
Convert a Z3 AST to a Triton AST.
270

271

272
\section ast_py_examples_page_3 Python API - Operators
273
<hr>
274

275
As we can not overload all AST operators only the following operators are overloaded:
276

277
Python's Operator | e.g: SMT2-Lib format
278
------------------|---------------------
279
a + b             | (bvadd a b)
280
a - b             | (bvsub a b)
281
a \* b            | (bvmul a b)
282
a / b             | (bvudiv a b)
283
a \| b            | (bvor a b)
284
a & b             | (bvand a b)
285
a ^ b             | (bvxor a b)
286
a % b             | (bvurem a b)
287
a << b            | (bvshl a b)
288
a \>> b           | (bvlshr a b)
289
~a                | (bvnot a)
290
-a                | (bvneg a)
291
a == b            | (= a b)
292
a != b            | (not (= a b))
293
a <= b            | (bvule a b)
294
a >= b            | (bvuge a b)
295
a < b             | (bvult a b)
296
a > b             | (bvugt a b)
297

298
\section ast_smt_python_page The SMT or Python Syntax
299
<hr>
300

301
By default, Triton represents semantics in [SMT-LIB](http://smtlib.cs.uiowa.edu/) which is an international initiative aimed at facilitating research and development in Satisfiability Modulo Theories (SMT). However,
302
Triton also allows you to display your AST using a Python syntax.
303

304
~~~~~~~~~~~~~{.py}
305
>>> ctxt = TritonContext()
306
>>> ctxt.setArchitecture(ARCH.X86_64)
307
>>> ctxt.setAstRepresentationMode(AST_REPRESENTATION.PYTHON)
308
>>> inst = Instruction()
309
>>> inst.setOpcode(b"\x48\x01\xd8") # add rax, rbx
310
>>> inst.setAddress(0x400000)
311
>>> ctxt.setConcreteRegisterValue(ctxt.registers.rax, 0x1122334455667788)
312
>>> ctxt.setConcreteRegisterValue(ctxt.registers.rbx, 0x8877665544332211)
313
>>> ctxt.processing(inst)
314
True
315
>>> print(inst)
316
0x400000: add rax, rbx
317

318
>>> for expr in inst.getSymbolicExpressions():
319
...     print(expr)
320
...
321
ref_0 = ((0x1122334455667788 + 0x8877665544332211) & 0xFFFFFFFFFFFFFFFF) # ADD operation
322
ref_1 = (0x1 if (0x10 == (0x10 & (ref_0 ^ (0x1122334455667788 ^ 0x8877665544332211)))) else 0x0) # Adjust flag
323
ref_2 = ((((0x1122334455667788 & 0x8877665544332211) ^ (((0x1122334455667788 ^ 0x8877665544332211) ^ ref_0) & (0x1122334455667788 ^ 0x8877665544332211))) >> 63) & 0x1) # Carry flag
324
ref_3 = ((((0x1122334455667788 ^ (~(0x8877665544332211) & 0xFFFFFFFFFFFFFFFF)) & (0x1122334455667788 ^ ref_0)) >> 63) & 0x1) # Overflow flag
325
ref_4 = ((((((((0x1 ^ (((ref_0 & 0xFF) >> 0x0) & 0x1)) ^ (((ref_0 & 0xFF) >> 0x1) & 0x1)) ^ (((ref_0 & 0xFF) >> 0x2) & 0x1)) ^ (((ref_0 & 0xFF) >> 0x3) & 0x1)) ^ (((ref_0 & 0xFF) >> 0x4) & 0x1)) ^ (((ref_0 & 0xFF) >> 0x5) & 0x1)) ^ (((ref_0 & 0xFF) >> 0x6) & 0x1)) ^ (((ref_0 & 0xFF) >> 0x7) & 0x1)) # Parity flag
326
ref_5 = ((ref_0 >> 63) & 0x1) # Sign flag
327
ref_6 = (0x1 if (ref_0 == 0x0) else 0x0) # Zero flag
328
ref_7 = 0x400003 # Program Counter
329

330
~~~~~~~~~~~~~
331

332
*/
333

334

335
namespace triton {
336
  namespace bindings {
337
    namespace python {
338

339
      //! AstContext destructor.
340 1
      void AstContext_dealloc(PyObject* self) {
341 1
        PyAstContext_AsAstContext(self) = nullptr; // decref the shared_ptr
342 1
        Py_TYPE(self)->tp_free((PyObject*)self);
343
      }
344

345

346 1
      static PyObject* AstContext_assert(PyObject* self, PyObject* op1) {
347 1
        if (!PyAstNode_Check(op1))
348 0
          return PyErr_Format(PyExc_TypeError, "assert_(): expected a AstNode as first argument");
349

350
        try {
351 1
          return PyAstNode(PyAstContext_AsAstContext(self)->assert_(PyAstNode_AsAstNode(op1)));
352
        }
353 0
        catch (const triton::exceptions::Exception& e) {
354 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
355
        }
356
      }
357

358

359 1
      static PyObject* AstContext_bv(PyObject* self, PyObject* args) {
360 1
        PyObject* op1 = nullptr;
361 1
        PyObject* op2 = nullptr;
362

363
        /* Extract arguments */
364 1
        if (PyArg_ParseTuple(args, "|OO", &op1, &op2) == false) {
365 0
          return PyErr_Format(PyExc_TypeError, "bv(): Invalid number of arguments");
366
        }
367

368 1
        if (op1 == nullptr || (!PyLong_Check(op1) && !PyInt_Check(op1)))
369 0
          return PyErr_Format(PyExc_TypeError, "bv(): expected an integer as first argument");
370

371 1
        if (op2 == nullptr || (!PyLong_Check(op2) && !PyInt_Check(op2)))
372 0
          return PyErr_Format(PyExc_TypeError, "bv(): expected an integer as second argument");
373

374
        try {
375 1
          return PyAstNode(PyAstContext_AsAstContext(self)->bv(PyLong_AsUint512(op1), PyLong_AsUint32(op2)));
376
        }
377 0
        catch (const triton::exceptions::Exception& e) {
378 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
379
        }
380
      }
381

382

383 1
      static PyObject* AstContext_bvadd(PyObject* self, PyObject* args) {
384 1
        PyObject* op1 = nullptr;
385 1
        PyObject* op2 = nullptr;
386

387
        /* Extract arguments */
388 1
        if (PyArg_ParseTuple(args, "|OO", &op1, &op2) == false) {
389 0
          return PyErr_Format(PyExc_TypeError, "bvadd(): Invalid number of arguments");
390
        }
391

392 1
        if (op1 == nullptr || !PyAstNode_Check(op1))
393 0
          return PyErr_Format(PyExc_TypeError, "bvadd(): expected a AstNode as first argument");
394

395 1
        if (op2 == nullptr || !PyAstNode_Check(op2))
396 0
          return PyErr_Format(PyExc_TypeError, "bvadd(): expected a AstNode as second argument");
397

398
        try {
399 1
          return PyAstNode(PyAstContext_AsAstContext(self)->bvadd(PyAstNode_AsAstNode(op1), PyAstNode_AsAstNode(op2)));
400
        }
401 1
        catch (const triton::exceptions::Exception& e) {
402 1
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
403
        }
404
      }
405

406

407 1
      static PyObject* AstContext_bvand(PyObject* self, PyObject* args) {
408 1
        PyObject* op1 = nullptr;
409 1
        PyObject* op2 = nullptr;
410

411
        /* Extract arguments */
412 1
        if (PyArg_ParseTuple(args, "|OO", &op1, &op2) == false) {
413 0
          return PyErr_Format(PyExc_TypeError, "bvand(): Invalid number of arguments");
414
        }
415

416 1
        if (op1 == nullptr || !PyAstNode_Check(op1))
417 0
          return PyErr_Format(PyExc_TypeError, "bvand(): expected a AstNode as first argument");
418

419 1
        if (op2 == nullptr || !PyAstNode_Check(op2))
420 0
          return PyErr_Format(PyExc_TypeError, "bvand(): expected a AstNode as second argument");
421

422
        try {
423 1
          return PyAstNode(PyAstContext_AsAstContext(self)->bvand(PyAstNode_AsAstNode(op1), PyAstNode_AsAstNode(op2)));
424
        }
425 0
        catch (const triton::exceptions::Exception& e) {
426 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
427
        }
428
      }
429

430

431 1
      static PyObject* AstContext_bvashr(PyObject* self, PyObject* args) {
432 1
        PyObject* op1 = nullptr;
433 1
        PyObject* op2 = nullptr;
434

435
        /* Extract arguments */
436 1
        if (PyArg_ParseTuple(args, "|OO", &op1, &op2) == false) {
437 0
          return PyErr_Format(PyExc_TypeError, "bvashr(): Invalid number of arguments");
438
        }
439

440 1
        if (op1 == nullptr || !PyAstNode_Check(op1))
441 0
          return PyErr_Format(PyExc_TypeError, "bvashr(): expected a AstNode as first argument");
442

443 1
        if (op2 == nullptr || !PyAstNode_Check(op2))
444 0
          return PyErr_Format(PyExc_TypeError, "bvashr(): expected a AstNode as second argument");
445

446
        try {
447 1
          return PyAstNode(PyAstContext_AsAstContext(self)->bvashr(PyAstNode_AsAstNode(op1), PyAstNode_AsAstNode(op2)));
448
        }
449 0
        catch (const triton::exceptions::Exception& e) {
450 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
451
        }
452
      }
453

454

455 1
      static PyObject* AstContext_bvfalse(PyObject* self, PyObject* args) {
456
        try {
457 1
          return PyAstNode(PyAstContext_AsAstContext(self)->bvfalse());
458
        }
459 0
        catch (const triton::exceptions::Exception& e) {
460 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
461
        }
462
      }
463

464

465 1
      static PyObject* AstContext_bvtrue(PyObject* self, PyObject* args) {
466
        try {
467 1
          return PyAstNode(PyAstContext_AsAstContext(self)->bvtrue());
468
        }
469 0
        catch (const triton::exceptions::Exception& e) {
470 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
471
        }
472
      }
473

474

475 1
      static PyObject* AstContext_bvlshr(PyObject* self, PyObject* args) {
476 1
        PyObject* op1 = nullptr;
477 1
        PyObject* op2 = nullptr;
478

479
        /* Extract arguments */
480 1
        if (PyArg_ParseTuple(args, "|OO", &op1, &op2) == false) {
481 0
          return PyErr_Format(PyExc_TypeError, "bvlshr(): Invalid number of arguments");
482
        }
483

484 1
        if (op1 == nullptr || !PyAstNode_Check(op1))
485 0
          return PyErr_Format(PyExc_TypeError, "bvlshr(): expected a AstNode as first argument");
486

487 1
        if (op2 == nullptr || !PyAstNode_Check(op2))
488 0
          return PyErr_Format(PyExc_TypeError, "bvlshr(): expected a AstNode as second argument");
489

490
        try {
491 1
          return PyAstNode(PyAstContext_AsAstContext(self)->bvlshr(PyAstNode_AsAstNode(op1), PyAstNode_AsAstNode(op2)));
492
        }
493 0
        catch (const triton::exceptions::Exception& e) {
494 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
495
        }
496
      }
497

498

499 1
      static PyObject* AstContext_bvmul(PyObject* self, PyObject* args) {
500 1
        PyObject* op1 = nullptr;
501 1
        PyObject* op2 = nullptr;
502

503
        /* Extract arguments */
504 1
        if (PyArg_ParseTuple(args, "|OO", &op1, &op2) == false) {
505 0
          return PyErr_Format(PyExc_TypeError, "bvmul(): Invalid number of arguments");
506
        }
507

508 1
        if (op1 == nullptr || !PyAstNode_Check(op1))
509 0
          return PyErr_Format(PyExc_TypeError, "bvmul(): expected a AstNode as first argument");
510

511 1
        if (op2 == nullptr || !PyAstNode_Check(op2))
512 0
          return PyErr_Format(PyExc_TypeError, "bvmul(): expected a AstNode as second argument");
513

514
        try {
515 1
          return PyAstNode(PyAstContext_AsAstContext(self)->bvmul(PyAstNode_AsAstNode(op1), PyAstNode_AsAstNode(op2)));
516
        }
517 0
        catch (const triton::exceptions::Exception& e) {
518 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
519
        }
520
      }
521

522

523 1
      static PyObject* AstContext_bvnand(PyObject* self, PyObject* args) {
524 1
        PyObject* op1 = nullptr;
525 1
        PyObject* op2 = nullptr;
526

527
        /* Extract arguments */
528 1
        if (PyArg_ParseTuple(args, "|OO", &op1, &op2) == false) {
529 0
          return PyErr_Format(PyExc_TypeError, "bvnand(): Invalid number of arguments");
530
        }
531

532 1
        if (op1 == nullptr || !PyAstNode_Check(op1))
533 0
          return PyErr_Format(PyExc_TypeError, "bvnand(): expected a AstNode as first argument");
534

535 1
        if (op2 == nullptr || !PyAstNode_Check(op2))
536 0
          return PyErr_Format(PyExc_TypeError, "bvnand(): expected a AstNode as second argument");
537

538
        try {
539 1
          return PyAstNode(PyAstContext_AsAstContext(self)->bvnand(PyAstNode_AsAstNode(op1), PyAstNode_AsAstNode(op2)));
540
        }
541 0
        catch (const triton::exceptions::Exception& e) {
542 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
543
        }
544
      }
545

546

547 1
      static PyObject* AstContext_bvneg(PyObject* self, PyObject* op1) {
548 1
        if (!PyAstNode_Check(op1))
549 0
          return PyErr_Format(PyExc_TypeError, "bvneg(): expected a AstNode as first argument");
550

551
        try {
552 1
          return PyAstNode(PyAstContext_AsAstContext(self)->bvneg(PyAstNode_AsAstNode(op1)));
553
        }
554 0
        catch (const triton::exceptions::Exception& e) {
555 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
556
        }
557
      }
558

559

560 1
      static PyObject* AstContext_bvnor(PyObject* self, PyObject* args) {
561 1
        PyObject* op1 = nullptr;
562 1
        PyObject* op2 = nullptr;
563

564
        /* Extract arguments */
565 1
        if (PyArg_ParseTuple(args, "|OO", &op1, &op2) == false) {
566 0
          return PyErr_Format(PyExc_TypeError, "bvnor(): Invalid number of arguments");
567
        }
568

569 1
        if (op1 == nullptr || !PyAstNode_Check(op1))
570 0
          return PyErr_Format(PyExc_TypeError, "bvnor(): expected a AstNode as first argument");
571

572 1
        if (op2 == nullptr || !PyAstNode_Check(op2))
573 0
          return PyErr_Format(PyExc_TypeError, "bvnor(): expected a AstNode as second argument");
574

575
        try {
576 1
          return PyAstNode(PyAstContext_AsAstContext(self)->bvnor(PyAstNode_AsAstNode(op1), PyAstNode_AsAstNode(op2)));
577
        }
578 0
        catch (const triton::exceptions::Exception& e) {
579 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
580
        }
581
      }
582

583

584 1
      static PyObject* AstContext_bvnot(PyObject* self, PyObject* op1) {
585 1
        if (!PyAstNode_Check(op1))
586 0
          return PyErr_Format(PyExc_TypeError, "bvnot(): expected a AstNode as first argument");
587

588
        try {
589 1
          return PyAstNode(PyAstContext_AsAstContext(self)->bvnot(PyAstNode_AsAstNode(op1)));
590
        }
591 0
        catch (const triton::exceptions::Exception& e) {
592 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
593
        }
594
      }
595

596

597 1
      static PyObject* AstContext_bvor(PyObject* self, PyObject* args) {
598 1
        PyObject* op1 = nullptr;
599 1
        PyObject* op2 = nullptr;
600

601
        /* Extract arguments */
602 1
        if (PyArg_ParseTuple(args, "|OO", &op1, &op2) == false) {
603 0
          return PyErr_Format(PyExc_TypeError, "bvor(): Invalid number of arguments");
604
        }
605

606 1
        if (op1 == nullptr || !PyAstNode_Check(op1))
607 0
          return PyErr_Format(PyExc_TypeError, "bvor(): expected a AstNode as first argument");
608

609 1
        if (op2 == nullptr || !PyAstNode_Check(op2))
610 0
          return PyErr_Format(PyExc_TypeError, "bvor(): expected a AstNode as second argument");
611

612
        try {
613 1
          return PyAstNode(PyAstContext_AsAstContext(self)->bvor(PyAstNode_AsAstNode(op1), PyAstNode_AsAstNode(op2)));
614
        }
615 0
        catch (const triton::exceptions::Exception& e) {
616 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
617
        }
618
      }
619

620

621 1
      static PyObject* AstContext_bvror(PyObject* self, PyObject* args) {
622 1
        PyObject* op1 = nullptr;
623 1
        PyObject* op2 = nullptr;
624

625
        /* Extract arguments */
626 1
        if (PyArg_ParseTuple(args, "|OO", &op1, &op2) == false) {
627 0
          return PyErr_Format(PyExc_TypeError, "bvror(): Invalid number of arguments");
628
        }
629

630 1
        if (op1 == nullptr || !PyAstNode_Check(op1))
631 0
          return PyErr_Format(PyExc_TypeError, "bvror(): expected a AstNode as first argument");
632

633 1
        if (op2 == nullptr || !PyAstNode_Check(op2))
634 0
          return PyErr_Format(PyExc_TypeError, "bvror(): expected a AstNode as second argument");
635

636
        try {
637 1
          return PyAstNode(PyAstContext_AsAstContext(self)->bvror(PyAstNode_AsAstNode(op1), PyAstNode_AsAstNode(op2)));
638
        }
639 0
        catch (const triton::exceptions::Exception& e) {
640 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
641
        }
642
      }
643

644

645 1
      static PyObject* AstContext_bvrol(PyObject* self, PyObject* args) {
646 1
        PyObject* op1 = nullptr;
647 1
        PyObject* op2 = nullptr;
648

649
        /* Extract arguments */
650 1
        if (PyArg_ParseTuple(args, "|OO", &op1, &op2) == false) {
651 0
          return PyErr_Format(PyExc_TypeError, "bvrol(): Invalid number of arguments");
652
        }
653

654 1
        if (op1 == nullptr || !PyAstNode_Check(op1))
655 0
          return PyErr_Format(PyExc_TypeError, "bvrol(): expected a AstNode as first argument");
656

657 1
        if (op2 == nullptr || !PyAstNode_Check(op2))
658 0
          return PyErr_Format(PyExc_TypeError, "bvrol(): expected a AstNode as second argument");
659

660
        try {
661 1
          return PyAstNode(PyAstContext_AsAstContext(self)->bvrol(PyAstNode_AsAstNode(op1), PyAstNode_AsAstNode(op2)));
662
        }
663 0
        catch (const triton::exceptions::Exception& e) {
664 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
665
        }
666
      }
667

668

669 1
      static PyObject* AstContext_bvsdiv(PyObject* self, PyObject* args) {
670 1
        PyObject* op1 = nullptr;
671 1
        PyObject* op2 = nullptr;
672

673
        /* Extract arguments */
674 1
        if (PyArg_ParseTuple(args, "|OO", &op1, &op2) == false) {
675 0
          return PyErr_Format(PyExc_TypeError, "bvsdiv(): Invalid number of arguments");
676
        }
677

678 1
        if (op1 == nullptr || !PyAstNode_Check(op1))
679 0
          return PyErr_Format(PyExc_TypeError, "bvsdiv(): expected a AstNode as first argument");
680

681 1
        if (op2 == nullptr || !PyAstNode_Check(op2))
682 0
          return PyErr_Format(PyExc_TypeError, "bvsdiv(): expected a AstNode as second argument");
683

684
        try {
685 1
          return PyAstNode(PyAstContext_AsAstContext(self)->bvsdiv(PyAstNode_AsAstNode(op1), PyAstNode_AsAstNode(op2)));
686
        }
687 0
        catch (const triton::exceptions::Exception& e) {
688 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
689
        }
690
      }
691

692

693 1
      static PyObject* AstContext_bvsge(PyObject* self, PyObject* args) {
694 1
        PyObject* op1 = nullptr;
695 1
        PyObject* op2 = nullptr;
696

697
        /* Extract arguments */
698 1
        if (PyArg_ParseTuple(args, "|OO", &op1, &op2) == false) {
699 0
          return PyErr_Format(PyExc_TypeError, "bvsge(): Invalid number of arguments");
700
        }
701

702 1
        if (op1 == nullptr || !PyAstNode_Check(op1))
703 0
          return PyErr_Format(PyExc_TypeError, "bvsge(): expected a AstNode as first argument");
704

705 1
        if (op2 == nullptr || !PyAstNode_Check(op2))
706 0
          return PyErr_Format(PyExc_TypeError, "bvsge(): expected a AstNode as second argument");
707

708
        try {
709 1
          return PyAstNode(PyAstContext_AsAstContext(self)->bvsge(PyAstNode_AsAstNode(op1), PyAstNode_AsAstNode(op2)));
710
        }
711 0
        catch (const triton::exceptions::Exception& e) {
712 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
713
        }
714
      }
715

716

717 1
      static PyObject* AstContext_bvsgt(PyObject* self, PyObject* args) {
718 1
        PyObject* op1 = nullptr;
719 1
        PyObject* op2 = nullptr;
720

721
        /* Extract arguments */
722 1
        if (PyArg_ParseTuple(args, "|OO", &op1, &op2) == false) {
723 0
          return PyErr_Format(PyExc_TypeError, "bvsgt(): Invalid number of arguments");
724
        }
725

726 1
        if (op1 == nullptr || !PyAstNode_Check(op1))
727 0
          return PyErr_Format(PyExc_TypeError, "bvsgt(): expected a AstNode as first argument");
728

729 1
        if (op2 == nullptr || !PyAstNode_Check(op2))
730 0
          return PyErr_Format(PyExc_TypeError, "bvsgt(): expected a AstNode as second argument");
731

732
        try {
733 1
          return PyAstNode(PyAstContext_AsAstContext(self)->bvsgt(PyAstNode_AsAstNode(op1), PyAstNode_AsAstNode(op2)));
734
        }
735 0
        catch (const triton::exceptions::Exception& e) {
736 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
737
        }
738
      }
739

740

741 1
      static PyObject* AstContext_bvshl(PyObject* self, PyObject* args) {
742 1
        PyObject* op1 = nullptr;
743 1
        PyObject* op2 = nullptr;
744

745
        /* Extract arguments */
746 1
        if (PyArg_ParseTuple(args, "|OO", &op1, &op2) == false) {
747 0
          return PyErr_Format(PyExc_TypeError, "bvshl(): Invalid number of arguments");
748
        }
749

750 1
        if (op1 == nullptr || !PyAstNode_Check(op1))
751 0
          return PyErr_Format(PyExc_TypeError, "bvshl(): expected a AstNode as first argument");
752

753 1
        if (op2 == nullptr || !PyAstNode_Check(op2))
754 0
          return PyErr_Format(PyExc_TypeError, "bvshl(): expected a AstNode as second argument");
755

756
        try {
757 1
          return PyAstNode(PyAstContext_AsAstContext(self)->bvshl(PyAstNode_AsAstNode(op1), PyAstNode_AsAstNode(op2)));
758
        }
759 0
        catch (const triton::exceptions::Exception& e) {
760 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
761
        }
762
      }
763

764

765 1
      static PyObject* AstContext_bvsle(PyObject* self, PyObject* args) {
766 1
        PyObject* op1 = nullptr;
767 1
        PyObject* op2 = nullptr;
768

769
        /* Extract arguments */
770 1
        if (PyArg_ParseTuple(args, "|OO", &op1, &op2) == false) {
771 0
          return PyErr_Format(PyExc_TypeError, "bvsle(): Invalid number of arguments");
772
        }
773

774 1
        if (op1 == nullptr || !PyAstNode_Check(op1))
775 0
          return PyErr_Format(PyExc_TypeError, "bvsle(): expected a AstNode as first argument");
776

777 1
        if (op2 == nullptr || !PyAstNode_Check(op2))
778 0
          return PyErr_Format(PyExc_TypeError, "bvsle(): expected a AstNode as second argument");
779

780
        try {
781 1
          return PyAstNode(PyAstContext_AsAstContext(self)->bvsle(PyAstNode_AsAstNode(op1), PyAstNode_AsAstNode(op2)));
782
        }
783 0
        catch (const triton::exceptions::Exception& e) {
784 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
785
        }
786
      }
787

788

789 1
      static PyObject* AstContext_bvslt(PyObject* self, PyObject* args) {
790 1
        PyObject* op1 = nullptr;
791 1
        PyObject* op2 = nullptr;
792

793
        /* Extract arguments */
794 1
        if (PyArg_ParseTuple(args, "|OO", &op1, &op2) == false) {
795 0
          return PyErr_Format(PyExc_TypeError, "bvslt(): Invalid number of arguments");
796
        }
797

798 1
        if (op1 == nullptr || !PyAstNode_Check(op1))
799 0
          return PyErr_Format(PyExc_TypeError, "bvslt(): expected a AstNode as first argument");
800

801 1
        if (op2 == nullptr || !PyAstNode_Check(op2))
802 0
          return PyErr_Format(PyExc_TypeError, "bvslt(): expected a AstNode as second argument");
803

804
        try {
805 1
          return PyAstNode(PyAstContext_AsAstContext(self)->bvslt(PyAstNode_AsAstNode(op1), PyAstNode_AsAstNode(op2)));
806
        }
807 0
        catch (const triton::exceptions::Exception& e) {
808 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
809
        }
810
      }
811

812

813 1
      static PyObject* AstContext_bvsmod(PyObject* self, PyObject* args) {
814 1
        PyObject* op1 = nullptr;
815 1
        PyObject* op2 = nullptr;
816

817
        /* Extract arguments */
818 1
        if (PyArg_ParseTuple(args, "|OO", &op1, &op2) == false) {
819 0
          return PyErr_Format(PyExc_TypeError, "bvsmod(): Invalid number of arguments");
820
        }
821

822 1
        if (op1 == nullptr || !PyAstNode_Check(op1))
823 0
          return PyErr_Format(PyExc_TypeError, "bvsmod(): expected a AstNode as first argument");
824

825 1
        if (op2 == nullptr || !PyAstNode_Check(op2))
826 0
          return PyErr_Format(PyExc_TypeError, "bvsmod(): expected a AstNode as second argument");
827

828
        try {
829 1
          return PyAstNode(PyAstContext_AsAstContext(self)->bvsmod(PyAstNode_AsAstNode(op1), PyAstNode_AsAstNode(op2)));
830
        }
831 0
        catch (const triton::exceptions::Exception& e) {
832 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
833
        }
834
      }
835

836

837 1
      static PyObject* AstContext_bvsrem(PyObject* self, PyObject* args) {
838 1
        PyObject* op1 = nullptr;
839 1
        PyObject* op2 = nullptr;
840

841
        /* Extract arguments */
842 1
        if (PyArg_ParseTuple(args, "|OO", &op1, &op2) == false) {
843 0
          return PyErr_Format(PyExc_TypeError, "bvsrem(): Invalid number of arguments");
844
        }
845

846 1
        if (op1 == nullptr || !PyAstNode_Check(op1))
847 0
          return PyErr_Format(PyExc_TypeError, "bvsrem(): expected a AstNode as first argument");
848

849 1
        if (op2 == nullptr || !PyAstNode_Check(op2))
850 0
          return PyErr_Format(PyExc_TypeError, "bvsrem(): expected a AstNode as second argument");
851

852
        try {
853 1
          return PyAstNode(PyAstContext_AsAstContext(self)->bvsrem(PyAstNode_AsAstNode(op1), PyAstNode_AsAstNode(op2)));
854
        }
855 0
        catch (const triton::exceptions::Exception& e) {
856 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
857
        }
858
      }
859

860

861 1
      static PyObject* AstContext_bvsub(PyObject* self, PyObject* args) {
862 1
        PyObject* op1 = nullptr;
863 1
        PyObject* op2 = nullptr;
864

865
        /* Extract arguments */
866 1
        if (PyArg_ParseTuple(args, "|OO", &op1, &op2) == false) {
867 0
          return PyErr_Format(PyExc_TypeError, "bvsub(): Invalid number of arguments");
868
        }
869

870 1
        if (op1 == nullptr || !PyAstNode_Check(op1))
871 0
          return PyErr_Format(PyExc_TypeError, "bvsub(): expected a AstNode as first argument");
872

873 1
        if (op2 == nullptr || !PyAstNode_Check(op2))
874 0
          return PyErr_Format(PyExc_TypeError, "bvsub(): expected a AstNode as second argument");
875

876
        try {
877 1
          return PyAstNode(PyAstContext_AsAstContext(self)->bvsub(PyAstNode_AsAstNode(op1), PyAstNode_AsAstNode(op2)));
878
        }
879 0
        catch (const triton::exceptions::Exception& e) {
880 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
881
        }
882
      }
883

884

885 1
      static PyObject* AstContext_bvudiv(PyObject* self, PyObject* args) {
886 1
        PyObject* op1 = nullptr;
887 1
        PyObject* op2 = nullptr;
888

889
        /* Extract arguments */
890 1
        if (PyArg_ParseTuple(args, "|OO", &op1, &op2) == false) {
891 0
          return PyErr_Format(PyExc_TypeError, "bvudiv(): Invalid number of arguments");
892
        }
893

894 1
        if (op1 == nullptr || !PyAstNode_Check(op1))
895 0
          return PyErr_Format(PyExc_TypeError, "bvudiv(): expected a AstNode as first argument");
896

897 1
        if (op2 == nullptr || !PyAstNode_Check(op2))
898 0
          return PyErr_Format(PyExc_TypeError, "bvudiv(): expected a AstNode as second argument");
899

900
        try {
901 1
          return PyAstNode(PyAstContext_AsAstContext(self)->bvudiv(PyAstNode_AsAstNode(op1), PyAstNode_AsAstNode(op2)));
902
        }
903 0
        catch (const triton::exceptions::Exception& e) {
904 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
905
        }
906
      }
907

908

909 1
      static PyObject* AstContext_bvuge(PyObject* self, PyObject* args) {
910 1
        PyObject* op1 = nullptr;
911 1
        PyObject* op2 = nullptr;
912

913
        /* Extract arguments */
914 1
        if (PyArg_ParseTuple(args, "|OO", &op1, &op2) == false) {
915 0
          return PyErr_Format(PyExc_TypeError, "bvuge(): Invalid number of arguments");
916
        }
917

918 1
        if (op1 == nullptr || !PyAstNode_Check(op1))
919 0
          return PyErr_Format(PyExc_TypeError, "bvuge(): expected a AstNode as first argument");
920

921 1
        if (op2 == nullptr || !PyAstNode_Check(op2))
922 0
          return PyErr_Format(PyExc_TypeError, "bvuge(): expected a AstNode as second argument");
923

924
        try {
925 1
          return PyAstNode(PyAstContext_AsAstContext(self)->bvuge(PyAstNode_AsAstNode(op1), PyAstNode_AsAstNode(op2)));
926
        }
927 0
        catch (const triton::exceptions::Exception& e) {
928 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
929
        }
930
      }
931

932

933 1
      static PyObject* AstContext_bvugt(PyObject* self, PyObject* args) {
934 1
        PyObject* op1 = nullptr;
935 1
        PyObject* op2 = nullptr;
936

937
        /* Extract arguments */
938 1
        if (PyArg_ParseTuple(args, "|OO", &op1, &op2) == false) {
939 0
          return PyErr_Format(PyExc_TypeError, "bvugt(): Invalid number of arguments");
940
        }
941

942 1
        if (op1 == nullptr || !PyAstNode_Check(op1))
943 0
          return PyErr_Format(PyExc_TypeError, "bvugt(): expected a AstNode as first argument");
944

945 1
        if (op2 == nullptr || !PyAstNode_Check(op2))
946 0
          return PyErr_Format(PyExc_TypeError, "bvugt(): expected a AstNode as second argument");
947

948
        try {
949 1
          return PyAstNode(PyAstContext_AsAstContext(self)->bvugt(PyAstNode_AsAstNode(op1), PyAstNode_AsAstNode(op2)));
950
        }
951 0
        catch (const triton::exceptions::Exception& e) {
952 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
953
        }
954
      }
955

956

957 1
      static PyObject* AstContext_bvule(PyObject* self, PyObject* args) {
958 1
        PyObject* op1 = nullptr;
959 1
        PyObject* op2 = nullptr;
960

961
        /* Extract arguments */
962 1
        if (PyArg_ParseTuple(args, "|OO", &op1, &op2) == false) {
963 0
          return PyErr_Format(PyExc_TypeError, "bvule(): Invalid number of arguments");
964
        }
965

966 1
        if (op1 == nullptr || !PyAstNode_Check(op1))
967 0
          return PyErr_Format(PyExc_TypeError, "bvule(): expected a AstNode as first argument");
968

969 1
        if (op2 == nullptr || !PyAstNode_Check(op2))
970 0
          return PyErr_Format(PyExc_TypeError, "bvule(): expected a AstNode as second argument");
971

972
        try {
973 1
          return PyAstNode(PyAstContext_AsAstContext(self)->bvule(PyAstNode_AsAstNode(op1), PyAstNode_AsAstNode(op2)));
974
        }
975 0
        catch (const triton::exceptions::Exception& e) {
976 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
977
        }
978
      }
979

980

981 1
      static PyObject* AstContext_bvult(PyObject* self, PyObject* args) {
982 1
        PyObject* op1 = nullptr;
983 1
        PyObject* op2 = nullptr;
984

985
        /* Extract arguments */
986 1
        if (PyArg_ParseTuple(args, "|OO", &op1, &op2) == false) {
987 0
          return PyErr_Format(PyExc_TypeError, "bvult(): Invalid number of arguments");
988
        }
989

990 1
        if (op1 == nullptr || !PyAstNode_Check(op1))
991 0
          return PyErr_Format(PyExc_TypeError, "bvult(): expected a AstNode as first argument");
992

993 1
        if (op2 == nullptr || !PyAstNode_Check(op2))
994 0
          return PyErr_Format(PyExc_TypeError, "bvult(): expected a AstNode as second argument");
995

996
        try {
997 1
          return PyAstNode(PyAstContext_AsAstContext(self)->bvult(PyAstNode_AsAstNode(op1), PyAstNode_AsAstNode(op2)));
998
        }
999 0
        catch (const triton::exceptions::Exception& e) {
1000 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
1001
        }
1002
      }
1003

1004

1005 1
      static PyObject* AstContext_bvurem(PyObject* self, PyObject* args) {
1006 1
        PyObject* op1 = nullptr;
1007 1
        PyObject* op2 = nullptr;
1008

1009
        /* Extract arguments */
1010 1
        if (PyArg_ParseTuple(args, "|OO", &op1, &op2) == false) {
1011 0
          return PyErr_Format(PyExc_TypeError, "bvurem(): Invalid number of arguments");
1012
        }
1013

1014 1
        if (op1 == nullptr || !PyAstNode_Check(op1))
1015 0
          return PyErr_Format(PyExc_TypeError, "bvurem(): expected a AstNode as first argument");
1016

1017 1
        if (op2 == nullptr || !PyAstNode_Check(op2))
1018 0
          return PyErr_Format(PyExc_TypeError, "bvurem(): expected a AstNode as second argument");
1019

1020
        try {
1021 1
          return PyAstNode(PyAstContext_AsAstContext(self)->bvurem(PyAstNode_AsAstNode(op1), PyAstNode_AsAstNode(op2)));
1022
        }
1023 0
        catch (const triton::exceptions::Exception& e) {
1024 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
1025
        }
1026
      }
1027

1028

1029 1
      static PyObject* AstContext_bvxnor(PyObject* self, PyObject* args) {
1030 1
        PyObject* op1 = nullptr;
1031 1
        PyObject* op2 = nullptr;
1032

1033
        /* Extract arguments */
1034 1
        if (PyArg_ParseTuple(args, "|OO", &op1, &op2) == false) {
1035 0
          return PyErr_Format(PyExc_TypeError, "bvxnor(): Invalid number of arguments");
1036
        }
1037

1038 1
        if (op1 == nullptr || !PyAstNode_Check(op1))
1039 0
          return PyErr_Format(PyExc_TypeError, "bvxnor(): expected a AstNode as first argument");
1040

1041 1
        if (op2 == nullptr || !PyAstNode_Check(op2))
1042 0
          return PyErr_Format(PyExc_TypeError, "bvxnor(): expected a AstNode as second argument");
1043

1044
        try {
1045 1
          return PyAstNode(PyAstContext_AsAstContext(self)->bvxnor(PyAstNode_AsAstNode(op1), PyAstNode_AsAstNode(op2)));
1046
        }
1047 0
        catch (const triton::exceptions::Exception& e) {
1048 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
1049
        }
1050
      }
1051

1052

1053 1
      static PyObject* AstContext_bvxor(PyObject* self, PyObject* args) {
1054 1
        PyObject* op1 = nullptr;
1055 1
        PyObject* op2 = nullptr;
1056

1057
        /* Extract arguments */
1058 1
        if (PyArg_ParseTuple(args, "|OO", &op1, &op2) == false) {
1059 0
          return PyErr_Format(PyExc_TypeError, "bvxor(): Invalid number of arguments");
1060
        }
1061

1062 1
        if (op1 == nullptr || !PyAstNode_Check(op1))
1063 0
          return PyErr_Format(PyExc_TypeError, "bvxor(): expected a AstNode as first argument");
1064

1065 1
        if (op2 == nullptr || !PyAstNode_Check(op2))
1066 0
          return PyErr_Format(PyExc_TypeError, "bvxor(): expected a AstNode as second argument");
1067

1068
        try {
1069 1
          return PyAstNode(PyAstContext_AsAstContext(self)->bvxor(PyAstNode_AsAstNode(op1), PyAstNode_AsAstNode(op2)));
1070
        }
1071 0
        catch (const triton::exceptions::Exception& e) {
1072 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
1073
        }
1074
      }
1075

1076

1077 1
      static PyObject* AstContext_declare(PyObject* self, PyObject* var) {
1078 1
        if (!PyAstNode_Check(var))
1079 0
          return PyErr_Format(PyExc_TypeError, "declare(): expected a AstNode as argument");
1080

1081
        try {
1082 1
          return PyAstNode(PyAstContext_AsAstContext(self)->declare(PyAstNode_AsAstNode(var)));
1083
        }
1084 0
        catch (const triton::exceptions::Exception& e) {
1085 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
1086
        }
1087
      }
1088

1089

1090 1
      static PyObject* AstContext_distinct(PyObject* self, PyObject* args) {
1091 1
        PyObject* op1 = nullptr;
1092 1
        PyObject* op2 = nullptr;
1093

1094
        /* Extract arguments */
1095 1
        if (PyArg_ParseTuple(args, "|OO", &op1, &op2) == false) {
1096 0
          return PyErr_Format(PyExc_TypeError, "distinct(): Invalid number of arguments");
1097
        }
1098

1099 1
        if (op1 == nullptr || !PyAstNode_Check(op1))
1100 0
          return PyErr_Format(PyExc_TypeError, "distinct(): expected a AstNode as first argument");
1101

1102 1
        if (op2 == nullptr || !PyAstNode_Check(op2))
1103 0
          return PyErr_Format(PyExc_TypeError, "distinct(): expected a AstNode as second argument");
1104

1105
        try {
1106 1
          return PyAstNode(PyAstContext_AsAstContext(self)->distinct(PyAstNode_AsAstNode(op1), PyAstNode_AsAstNode(op2)));
1107
        }
1108 0
        catch (const triton::exceptions::Exception& e) {
1109 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
1110
        }
1111
      }
1112

1113

1114 1
      static PyObject* AstContext_duplicate(PyObject* self, PyObject* node) {
1115 1
        if (!PyAstNode_Check(node))
1116 0
          return PyErr_Format(PyExc_TypeError, "duplicate(): expected a AstNode as argument");
1117

1118
        try {
1119 1
          return PyAstNode(triton::ast::newInstance(PyAstNode_AsAstNode(node).get()));
1120
        }
1121 0
        catch (const triton::exceptions::Exception& e) {
1122 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
1123
        }
1124
      }
1125

1126

1127 1
      static PyObject* AstContext_compound(PyObject* self, PyObject* exprsList) {
1128 1
        std::vector<triton::ast::SharedAbstractNode> exprs;
1129

1130 1
        if (exprsList == nullptr || !PyList_Check(exprsList))
1131 0
          return PyErr_Format(PyExc_TypeError, "compound(): expected a list of AstNodes as first argument");
1132

1133
        /* Check if the list contains only PyAstNode */
1134 1
        for (Py_ssize_t i = 0; i < PyList_Size(exprsList); i++){
1135 1
          PyObject* item = PyList_GetItem(exprsList, i);
1136

1137 1
          if (!PyAstNode_Check(item))
1138 0
            return PyErr_Format(PyExc_TypeError, "compound(): Each element from the list must be a AstNode");
1139

1140 1
          exprs.push_back(PyAstNode_AsAstNode(item));
1141
        }
1142

1143
        try {
1144 1
          return PyAstNode(PyAstContext_AsAstContext(self)->compound(exprs));
1145
        }
1146 0
        catch (const triton::exceptions::Exception& e) {
1147 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
1148
        }
1149
      }
1150

1151

1152 1
      static PyObject* AstContext_concat(PyObject* self, PyObject* exprsList) {
1153 1
        std::vector<triton::ast::SharedAbstractNode> exprs;
1154

1155 1
        if (exprsList == nullptr || !PyList_Check(exprsList))
1156 0
          return PyErr_Format(PyExc_TypeError, "concat(): expected a list of AstNodes as first argument");
1157

1158
        /* Check if the list contains only PyAstNode */
1159 1
        for (Py_ssize_t i = 0; i < PyList_Size(exprsList); i++){
1160 1
          PyObject* item = PyList_GetItem(exprsList, i);
1161

1162 1
          if (!PyAstNode_Check(item))
1163 0
            return PyErr_Format(PyExc_TypeError, "concat(): Each element from the list must be a AstNode");
1164

1165 1
          exprs.push_back(PyAstNode_AsAstNode(item));
1166
        }
1167

1168
        try {
1169 1
          return PyAstNode(PyAstContext_AsAstContext(self)->concat(exprs));
1170
        }
1171 0
        catch (const triton::exceptions::Exception& e) {
1172 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
1173
        }
1174
      }
1175

1176

1177 1
      static PyObject* AstContext_equal(PyObject* self, PyObject* args) {
1178 1
        PyObject* op1 = nullptr;
1179 1
        PyObject* op2 = nullptr;
1180

1181
        /* Extract arguments */
1182 1
        if (PyArg_ParseTuple(args, "|OO", &op1, &op2) == false) {
1183 0
          return PyErr_Format(PyExc_TypeError, "equal(): Invalid number of arguments");
1184
        }
1185

1186 1
        if (op1 == nullptr || !PyAstNode_Check(op1))
1187 0
          return PyErr_Format(PyExc_TypeError, "equal(): expected a AstNode as first argument");
1188

1189 1
        if (op2 == nullptr || !PyAstNode_Check(op2))
1190 0
          return PyErr_Format(PyExc_TypeError, "equal(): expected a AstNode as second argument");
1191

1192
        try {
1193 1
          return PyAstNode(PyAstContext_AsAstContext(self)->equal(PyAstNode_AsAstNode(op1), PyAstNode_AsAstNode(op2)));
1194
        }
1195 0
        catch (const triton::exceptions::Exception& e) {
1196 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
1197
        }
1198
      }
1199

1200

1201 1
      static PyObject* AstContext_extract(PyObject* self, PyObject* args) {
1202 1
        PyObject* op1 = nullptr;
1203 1
        PyObject* op2 = nullptr;
1204 1
        PyObject* op3 = nullptr;
1205

1206
        /* Extract arguments */
1207 1
        if (PyArg_ParseTuple(args, "|OOO", &op1, &op2, &op3) == false) {
1208 0
          return PyErr_Format(PyExc_TypeError, "extract(): Invalid number of arguments");
1209
        }
1210

1211 1
        if (op1 == nullptr || (!PyLong_Check(op1) && !PyInt_Check(op1)))
1212 0
          return PyErr_Format(PyExc_TypeError, "extract(): expected an integer as first argument");
1213

1214 1
        if (op2 == nullptr || (!PyLong_Check(op2) && !PyInt_Check(op2)))
1215 0
          return PyErr_Format(PyExc_TypeError, "extract(): expected an integer as second argument");
1216

1217 1
        if (op3 == nullptr || !PyAstNode_Check(op3))
1218 0
          return PyErr_Format(PyExc_TypeError, "extract(): expected a AstNode as third argument");
1219

1220
        try {
1221 1
          return PyAstNode(PyAstContext_AsAstContext(self)->extract(PyLong_AsUint32(op1), PyLong_AsUint32(op2), PyAstNode_AsAstNode(op3)));
1222
        }
1223 0
        catch (const triton::exceptions::Exception& e) {
1224 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
1225
        }
1226
      }
1227

1228

1229 1
      static PyObject* AstContext_forall(PyObject* self, PyObject* args) {
1230 1
        std::vector<triton::ast::SharedAbstractNode> vars;
1231 1
        PyObject* op1 = nullptr;
1232 1
        PyObject* op2 = nullptr;
1233

1234
        /* Extract arguments */
1235 1
        if (PyArg_ParseTuple(args, "|OO", &op1, &op2) == false) {
1236 0
          return PyErr_Format(PyExc_TypeError, "forall(): Invalid number of arguments");
1237
        }
1238

1239 1
        if (op1 == nullptr || !PyList_Check(op1))
1240 0
          return PyErr_Format(PyExc_TypeError, "forall(): expected a list of AstNodes as first argument");
1241

1242 1
        if (op2 == nullptr || !PyAstNode_Check(op2))
1243 0
          return PyErr_Format(PyExc_TypeError, "forall(): expected a AstNode as second argument");
1244

1245
        /* Check if the list contains only PyAstNode */
1246 1
        for (Py_ssize_t i = 0; i < PyList_Size(op1); i++){
1247 1
          PyObject* item = PyList_GetItem(op1, i);
1248

1249 1
          if (!PyAstNode_Check(item))
1250 0
            return PyErr_Format(PyExc_TypeError, "forall(): Each element from the list must be a AstNode");
1251

1252 1
          vars.push_back(PyAstNode_AsAstNode(item));
1253
        }
1254

1255
        try {
1256 1
          return PyAstNode(PyAstContext_AsAstContext(self)->forall(vars, PyAstNode_AsAstNode(op2)));
1257
        }
1258 0
        catch (const triton::exceptions::Exception& e) {
1259 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
1260
        }
1261
      }
1262

1263

1264 1
      static PyObject* AstContext_iff(PyObject* self, PyObject* args) {
1265 1
        PyObject* op1 = nullptr;
1266 1
        PyObject* op2 = nullptr;
1267

1268
        /* Extract arguments */
1269 1
        if (PyArg_ParseTuple(args, "|OO", &op1, &op2) == false) {
1270 0
          return PyErr_Format(PyExc_TypeError, "iff(): Invalid number of arguments");
1271
        }
1272

1273 1
        if (op1 == nullptr || !PyAstNode_Check(op1))
1274 0
          return PyErr_Format(PyExc_TypeError, "iff(): expected a AstNode as first argument");
1275

1276 1
        if (op2 == nullptr || !PyAstNode_Check(op2))
1277 0
          return PyErr_Format(PyExc_TypeError, "iff(): expected a AstNode as second argument");
1278

1279
        try {
1280 1
          return PyAstNode(PyAstContext_AsAstContext(self)->iff(PyAstNode_AsAstNode(op1), PyAstNode_AsAstNode(op2)));
1281
        }
1282 0
        catch (const triton::exceptions::Exception& e) {
1283 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
1284
        }
1285
      }
1286

1287

1288 1
      static PyObject* AstContext_ite(PyObject* self, PyObject* args) {
1289 1
        PyObject* op1 = nullptr;
1290 1
        PyObject* op2 = nullptr;
1291 1
        PyObject* op3 = nullptr;
1292

1293
        /* Extract arguments */
1294 1
        if (PyArg_ParseTuple(args, "|OOO", &op1, &op2, &op3) == false) {
1295 0
          return PyErr_Format(PyExc_TypeError, "ite(): Invalid number of arguments");
1296
        }
1297

1298 1
        if (op1 == nullptr || !PyAstNode_Check(op1))
1299 0
          return PyErr_Format(PyExc_TypeError, "ite(): expected a AstNode as first argument");
1300

1301 1
        if (op2 == nullptr || !PyAstNode_Check(op2))
1302 0
          return PyErr_Format(PyExc_TypeError, "ite(): expected a AstNode as second argument");
1303

1304 1
        if (op3 == nullptr || !PyAstNode_Check(op3))
1305 0
          return PyErr_Format(PyExc_TypeError, "ite(): expected a AstNode as third argument");
1306

1307
        try {
1308 1
          return PyAstNode(PyAstContext_AsAstContext(self)->ite(PyAstNode_AsAstNode(op1), PyAstNode_AsAstNode(op2), PyAstNode_AsAstNode(op3)));
1309
        }
1310 0
        catch (const triton::exceptions::Exception& e) {
1311 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
1312
        }
1313
      }
1314

1315

1316 1
      static PyObject* AstContext_land(PyObject* self, PyObject* exprsList) {
1317 1
        std::vector<triton::ast::SharedAbstractNode> exprs;
1318

1319 1
        if (exprsList == nullptr || !PyList_Check(exprsList))
1320 0
          return PyErr_Format(PyExc_TypeError, "land(): expected a list of AstNodes as first argument");
1321

1322
        /* Check if the list contains only PyAstNode */
1323 1
        for (Py_ssize_t i = 0; i < PyList_Size(exprsList); i++){
1324 1
          PyObject* item = PyList_GetItem(exprsList, i);
1325

1326 1
          if (!PyAstNode_Check(item))
1327 0
            return PyErr_Format(PyExc_TypeError, "land(): Each element from the list must be a AstNode");
1328

1329 1
          exprs.push_back(PyAstNode_AsAstNode(item));
1330
        }
1331

1332
        try {
1333 1
          return PyAstNode(PyAstContext_AsAstContext(self)->land(exprs));
1334
        }
1335 0
        catch (const triton::exceptions::Exception& e) {
1336 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
1337
        }
1338
      }
1339

1340

1341 1
      static PyObject* AstContext_let(PyObject* self, PyObject* args) {
1342 1
        PyObject* op1 = nullptr;
1343 1
        PyObject* op2 = nullptr;
1344 1
        PyObject* op3 = nullptr;
1345

1346
        /* Extract arguments */
1347 1
        if (PyArg_ParseTuple(args, "|OOO", &op1, &op2, &op3) == false) {
1348 0
          return PyErr_Format(PyExc_TypeError, "let(): Invalid number of arguments");
1349
        }
1350

1351 1
        if (op1 == nullptr || !PyStr_Check(op1))
1352 0
          return PyErr_Format(PyExc_TypeError, "let(): expected a string as first argument");
1353

1354 1
        if (op2 == nullptr || !PyAstNode_Check(op2))
1355 0
          return PyErr_Format(PyExc_TypeError, "let(): expected a AstNode as second argument");
1356

1357 1
        if (op3 == nullptr || !PyAstNode_Check(op3))
1358 0
          return PyErr_Format(PyExc_TypeError, "let(): expected a AstNode as third argument");
1359

1360
        try {
1361 1
          return PyAstNode(PyAstContext_AsAstContext(self)->let(PyStr_AsString(op1), PyAstNode_AsAstNode(op2), PyAstNode_AsAstNode(op3)));
1362
        }
1363 0
        catch (const triton::exceptions::Exception& e) {
1364 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
1365
        }
1366
      }
1367

1368

1369 1
      static PyObject* AstContext_lnot(PyObject* self, PyObject* expr) {
1370 1
        if (expr == nullptr || !PyAstNode_Check(expr))
1371 0
          return PyErr_Format(PyExc_TypeError, "lnot(): expected a AstNode as argument");
1372

1373
        try {
1374 1
          return PyAstNode(PyAstContext_AsAstContext(self)->lnot(PyAstNode_AsAstNode(expr)));
1375
        }
1376 0
        catch (const triton::exceptions::Exception& e) {
1377 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
1378
        }
1379
      }
1380

1381

1382 1
      static PyObject* AstContext_search(PyObject* self, PyObject* args) {
1383 1
        PyObject* ret = nullptr;
1384 1
        PyObject* op1 = nullptr;
1385 1
        PyObject* op2 = nullptr;
1386

1387
        /* Extract arguments */
1388 1
        if (PyArg_ParseTuple(args, "|OO", &op1, &op2) == false) {
1389 0
          return PyErr_Format(PyExc_TypeError, "search(): Invalid number of arguments");
1390
        }
1391

1392 1
        if (op1 == nullptr || !PyAstNode_Check(op1))
1393 0
          return PyErr_Format(PyExc_TypeError, "search(): expected a AstNode object as first argument");
1394

1395 1
        if (op2 == nullptr || (!PyLong_Check(op2) && !PyInt_Check(op2)))
1396 0
          return PyErr_Format(PyExc_TypeError, "search(): expected a AST_NODE enum as second argument");
1397

1398
        try {
1399 1
          auto nodes = triton::ast::search(PyAstNode_AsAstNode(op1), static_cast<triton::ast::ast_e>(PyLong_AsUint32(op2)));
1400 1
          ret = xPyList_New(nodes.size());
1401

1402 1
          triton::uint32 index = 0;
1403 1
          for (auto&& node : nodes)
1404 1
            PyList_SetItem(ret, index++, PyAstNode(node));
1405

1406
          return ret;
1407
        }
1408 0
        catch (const triton::exceptions::Exception& e) {
1409 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
1410
        }
1411
      }
1412

1413

1414 1
      static PyObject* AstContext_lor(PyObject* self, PyObject* exprsList) {
1415 1
        std::vector<triton::ast::SharedAbstractNode> exprs;
1416

1417 1
        if (exprsList == nullptr || !PyList_Check(exprsList))
1418 0
          return PyErr_Format(PyExc_TypeError, "lor(): expected a list of AstNodes as first argument");
1419

1420
        /* Check if the list contains only PyAstNode */
1421 1
        for (Py_ssize_t i = 0; i < PyList_Size(exprsList); i++){
1422 1
          PyObject* item = PyList_GetItem(exprsList, i);
1423

1424 1
          if (!PyAstNode_Check(item))
1425 0
            return PyErr_Format(PyExc_TypeError, "lor(): Each element from the list must be a AstNode");
1426

1427 1
          exprs.push_back(PyAstNode_AsAstNode(item));
1428
        }
1429

1430
        try {
1431 1
          return PyAstNode(PyAstContext_AsAstContext(self)->lor(exprs));
1432
        }
1433 0
        catch (const triton::exceptions::Exception& e) {
1434 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
1435
        }
1436
      }
1437

1438

1439 1
      static PyObject* AstContext_lxor(PyObject* self, PyObject* exprsList) {
1440 1
        std::vector<triton::ast::SharedAbstractNode> exprs;
1441

1442 1
        if (exprsList == nullptr || !PyList_Check(exprsList))
1443 0
          return PyErr_Format(PyExc_TypeError, "lxor(): expected a list of AstNodes as first argument");
1444

1445
        /* Check if the list contains only PyAstNode */
1446 1
        for (Py_ssize_t i = 0; i < PyList_Size(exprsList); i++){
1447 1
          PyObject* item = PyList_GetItem(exprsList, i);
1448

1449 1
          if (!PyAstNode_Check(item))
1450 0
            return PyErr_Format(PyExc_TypeError, "lxor(): Each element from the list must be a AstNode");
1451

1452 1
          exprs.push_back(PyAstNode_AsAstNode(item));
1453
        }
1454

1455
        try {
1456 1
          return PyAstNode(PyAstContext_AsAstContext(self)->lxor(exprs));
1457
        }
1458 0
        catch (const triton::exceptions::Exception& e) {
1459 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
1460
        }
1461
      }
1462

1463

1464 1
      static PyObject* AstContext_reference(PyObject* self, PyObject* symExpr) {
1465 1
        if (!PySymbolicExpression_Check(symExpr))
1466 0
          return PyErr_Format(PyExc_TypeError, "reference(): expected a symbolic expression as argument");
1467

1468
        try {
1469 1
          return PyAstNode(PyAstContext_AsAstContext(self)->reference(PySymbolicExpression_AsSymbolicExpression(symExpr)));
1470
        }
1471 0
        catch (const triton::exceptions::Exception& e) {
1472 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
1473
        }
1474
      }
1475

1476

1477 1
      static PyObject* AstContext_string(PyObject* self, PyObject* expr) {
1478 1
        if (!PyStr_Check(expr))
1479 0
          return PyErr_Format(PyExc_TypeError, "string(): expected a string as first argument");
1480

1481
        try {
1482 1
          return PyAstNode(PyAstContext_AsAstContext(self)->string(PyStr_AsString(expr)));
1483
        }
1484 0
        catch (const triton::exceptions::Exception& e) {
1485 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
1486
        }
1487
      }
1488

1489

1490 1
      static PyObject* AstContext_sx(PyObject* self, PyObject* args) {
1491 1
        PyObject* op1 = nullptr;
1492 1
        PyObject* op2 = nullptr;
1493

1494
        /* Extract arguments */
1495 1
        if (PyArg_ParseTuple(args, "|OO", &op1, &op2) == false) {
1496 0
          return PyErr_Format(PyExc_TypeError, "sx(): Invalid number of arguments");
1497
        }
1498

1499 1
        if (op1 == nullptr || (!PyLong_Check(op1) && !PyInt_Check(op1)))
1500 0
          return PyErr_Format(PyExc_TypeError, "sx(): expected an integer as first argument");
1501

1502 1
        if (op2 == nullptr || !PyAstNode_Check(op2))
1503 0
          return PyErr_Format(PyExc_TypeError, "sx(): expected a AstNode as second argument");
1504

1505
        try {
1506 1
          return PyAstNode(PyAstContext_AsAstContext(self)->sx(PyLong_AsUint32(op1), PyAstNode_AsAstNode(op2)));
1507
        }
1508 0
        catch (const triton::exceptions::Exception& e) {
1509 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
1510
        }
1511
      }
1512

1513

1514 1
      static PyObject* AstContext_unroll(PyObject* self, PyObject* node) {
1515 1
        if (!PyAstNode_Check(node))
1516 0
          return PyErr_Format(PyExc_TypeError, "unroll(): Expects a AstNode as argument.");
1517

1518
        try {
1519 1
          return PyAstNode(triton::ast::unroll(PyAstNode_AsAstNode(node)));
1520
        }
1521 0
        catch (const triton::exceptions::Exception& e) {
1522 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
1523
        }
1524
      }
1525

1526

1527 1
      static PyObject* AstContext_variable(PyObject* self, PyObject* symVar) {
1528 1
        if (!PySymbolicVariable_Check(symVar))
1529 0
          return PyErr_Format(PyExc_TypeError, "variable(): expected a SymbolicVariable as first argument");
1530

1531
        try {
1532 1
          return PyAstNode(PyAstContext_AsAstContext(self)->variable(PySymbolicVariable_AsSymbolicVariable(symVar)));
1533
        }
1534 0
        catch (const triton::exceptions::Exception& e) {
1535 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
1536
        }
1537
      }
1538

1539

1540 1
      static PyObject* AstContext_zx(PyObject* self, PyObject* args) {
1541 1
        PyObject* op1 = nullptr;
1542 1
        PyObject* op2 = nullptr;
1543

1544
        /* Extract arguments */
1545 1
        if (PyArg_ParseTuple(args, "|OO", &op1, &op2) == false) {
1546 0
          return PyErr_Format(PyExc_TypeError, "zx(): Invalid number of arguments");
1547
        }
1548

1549 1
        if (op1 == nullptr || (!PyLong_Check(op1) && !PyInt_Check(op1)))
1550 0
          return PyErr_Format(PyExc_TypeError, "zx(): expected an integer as first argument");
1551

1552 1
        if (op2 == nullptr || !PyAstNode_Check(op2))
1553 0
          return PyErr_Format(PyExc_TypeError, "zx(): expected a AstNode as second argument");
1554

1555
        try {
1556 1
          return PyAstNode(PyAstContext_AsAstContext(self)->zx(PyLong_AsUint32(op1), PyAstNode_AsAstNode(op2)));
1557
        }
1558 0
        catch (const triton::exceptions::Exception& e) {
1559 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
1560
        }
1561
      }
1562

1563
      // *********************************************************************
1564

1565
      #ifdef TRITON_Z3_INTERFACE
1566 0
      static PyObject* AstContext_tritonToZ3(PyObject* self, PyObject* node) {
1567 0
        triton::ast::TritonToZ3Ast tritonToZ3Ast{false};
1568

1569 0
        if (node == nullptr || (!PyAstNode_Check(node)))
1570 0
          return PyErr_Format(PyExc_TypeError, "tritonToZ3(): Expects a AstNode as argument.");
1571

1572
        // import z3
1573 0
        PyObject* z3mod = PyImport_ImportModule("z3");
1574 0
        if (z3mod == nullptr) {
1575 0
          return PyErr_Format(PyExc_TypeError, "tritonToZ3(): z3 module not found.");
1576
        }
1577

1578
        // z3.main_ctx().ctx.value
1579 0
        PyObject* z3MainCtx = PyObject_CallObject(PyObject_GetAttrString(z3mod, "main_ctx"), nullptr);
1580 0
        PyObject* z3CtxPtr  = PyObject_GetAttrString(PyObject_GetAttrString(z3MainCtx, "ctx"), "value");
1581 0
        Z3_context z3Ctx    = reinterpret_cast<Z3_context>(PyLong_AsVoidPtr(z3CtxPtr));
1582 0
        Py_DECREF(z3CtxPtr);
1583 0
        Py_DECREF(z3MainCtx);
1584

1585
        // Convert the node to a Z3++ expression and translate it into
1586
        // python's z3 main context
1587 0
        z3::expr expr = tritonToZ3Ast.convert(PyAstNode_AsAstNode(node));
1588 0
        Z3_ast ast    = Z3_translate(expr.ctx(), expr, z3Ctx);
1589

1590
        // Check that everything went fine
1591 0
        if (Z3_get_error_code(z3Ctx) != Z3_OK) {
1592 0
          Py_DECREF(z3mod);
1593 0
          return PyErr_Format(PyExc_RuntimeError, "tritonToZ3(): Z3 AST translation failed.");
1594
        }
1595

1596
        // retAst = ctypes.c_void_p(ctx_ptr); retAst.__class__ = z3.Ast
1597 0
        PyObject* pyArgs = Py_BuildValue("(O)", PyLong_FromVoidPtr(ast));
1598 0
        PyObject* retAst = PyObject_CallObject(PyObject_GetAttrString(z3mod, "c_void_p"), pyArgs);
1599 0
        PyObject_SetAttrString(retAst, "__class__", PyObject_GetAttrString(z3mod, "Ast"));
1600 0
        Py_DECREF(pyArgs);
1601

1602
        // return z3.ExprRef(ast)
1603 0
        PyObject* z3ExprRef = PyObject_GetAttrString(z3mod, "ExprRef");
1604 0
        pyArgs = Py_BuildValue("(O)", retAst);
1605 0
        PyObject* retExpr = PyObject_CallObject(z3ExprRef, pyArgs);
1606 0
        Py_DECREF(pyArgs);
1607 0
        Py_DECREF(retAst);
1608 0
        Py_DECREF(z3ExprRef);
1609

1610
        // Cleanup
1611 0
        Py_DECREF(z3mod);
1612

1613
        return retExpr;
1614
      }
1615

1616

1617 0
      static PyObject* AstContext_z3ToTriton(PyObject* self, PyObject* expr) {
1618 0
        triton::ast::Z3ToTritonAst  z3ToTritonAst{PyAstContext_AsAstContext(self)};
1619 0
        z3::context                 z3Ctx;
1620

1621 0
        if (std::strcmp(Py_TYPE(expr)->tp_name, "ExprRef") && std::strcmp(Py_TYPE(expr)->tp_name, "BitVecRef"))
1622 0
          return PyErr_Format(PyExc_TypeError, "z3ToTriton(): expected an ExprRef as argument");
1623

1624 0
        PyObject* z3AstPtr = PyObject_GetAttrString(expr, "ast");
1625 0
        if  (z3AstPtr == nullptr)
1626 0
          return PyErr_Format(PyExc_TypeError, "z3ToTriton(): expected an ExprRef as argument");
1627

1628 0
        PyObject* z3AstPtrValue = PyObject_GetAttrString(z3AstPtr, "value");
1629 0
        if (z3AstPtrValue == nullptr)
1630 0
          return PyErr_Format(PyExc_TypeError, "z3ToTriton(): expected an ExprRef as argument");
1631

1632
        try {
1633 0
          Z3_ast z3Ast    = reinterpret_cast<Z3_ast>(PyLong_AsVoidPtr(z3AstPtrValue));
1634 0
          z3::expr z3Expr = z3::to_expr(z3Ctx, z3Ast);
1635

1636 0
          return PyAstNode(z3ToTritonAst.convert(z3Expr));
1637
        }
1638 0
        catch (const triton::exceptions::Exception& e) {
1639 0
          return PyErr_Format(PyExc_TypeError, "%s", e.what());
1640
        }
1641
      }
1642
      #endif
1643

1644

1645 1
      static int AstContext_init(AstNode_Object *self, PyObject *args, PyObject *kwds) {
1646 1
        return 0;
1647
      }
1648

1649

1650 1
      static PyObject* AstContext_new(PyTypeObject* type, PyObject* args, PyObject* kwds) {
1651 1
        return type->tp_alloc(type, 0);
1652
      }
1653

1654

1655
      //! AstContext methods.
1656
      PyMethodDef AstContext_callbacks[] = {
1657
        {"assert_",         AstContext_assert,          METH_O,           ""},
1658
        {"bv",              AstContext_bv,              METH_VARARGS,     ""},
1659
        {"bvadd",           AstContext_bvadd,           METH_VARARGS,     ""},
1660
        {"bvand",           AstContext_bvand,           METH_VARARGS,     ""},
1661
        {"bvashr",          AstContext_bvashr,          METH_VARARGS,     ""},
1662
        {"bvfalse",         AstContext_bvfalse,         METH_NOARGS,      ""},
1663
        {"bvlshr",          AstContext_bvlshr,          METH_VARARGS,     ""},
1664
        {"bvmul",           AstContext_bvmul,           METH_VARARGS,     ""},
1665
        {"bvnand",          AstContext_bvnand,          METH_VARARGS,     ""},
1666
        {"bvneg",           AstContext_bvneg,           METH_O,           ""},
1667
        {"bvnor",           AstContext_bvnor,           METH_VARARGS,     ""},
1668
        {"bvnot",           AstContext_bvnot,           METH_O,           ""},
1669
        {"bvor",            AstContext_bvor,            METH_VARARGS,     ""},
1670
        {"bvrol",           AstContext_bvrol,           METH_VARARGS,     ""},
1671
        {"bvror",           AstContext_bvror,           METH_VARARGS,     ""},
1672
        {"bvsdiv",          AstContext_bvsdiv,          METH_VARARGS,     ""},
1673
        {"bvsge",           AstContext_bvsge,           METH_VARARGS,     ""},
1674
        {"bvsgt",           AstContext_bvsgt,           METH_VARARGS,     ""},
1675
        {"bvshl",           AstContext_bvshl,           METH_VARARGS,     ""},
1676
        {"bvsle",           AstContext_bvsle,           METH_VARARGS,     ""},
1677
        {"bvslt",           AstContext_bvslt,           METH_VARARGS,     ""},
1678
        {"bvsmod",          AstContext_bvsmod,          METH_VARARGS,     ""},
1679
        {"bvsrem",          AstContext_bvsrem,          METH_VARARGS,     ""},
1680
        {"bvsub",           AstContext_bvsub,           METH_VARARGS,     ""},
1681
        {"bvtrue",          AstContext_bvtrue,          METH_NOARGS,      ""},
1682
        {"bvudiv",          AstContext_bvudiv,          METH_VARARGS,     ""},
1683
        {"bvuge",           AstContext_bvuge,           METH_VARARGS,     ""},
1684
        {"bvugt",           AstContext_bvugt,           METH_VARARGS,     ""},
1685
        {"bvule",           AstContext_bvule,           METH_VARARGS,     ""},
1686
        {"bvult",           AstContext_bvult,           METH_VARARGS,     ""},
1687
        {"bvurem",          AstContext_bvurem,          METH_VARARGS,     ""},
1688
        {"bvxnor",          AstContext_bvxnor ,         METH_VARARGS,     ""},
1689
        {"bvxor",           AstContext_bvxor,           METH_VARARGS,     ""},
1690
        {"compound",        AstContext_compound,        METH_O,           ""},
1691
        {"concat",          AstContext_concat,          METH_O,           ""},
1692
        {"declare",         AstContext_declare,         METH_O,           ""},
1693
        {"distinct",        AstContext_distinct,        METH_VARARGS,     ""},
1694
        {"duplicate",       AstContext_duplicate,       METH_O,           ""},
1695
        {"equal",           AstContext_equal,           METH_VARARGS,     ""},
1696
        {"extract",         AstContext_extract,         METH_VARARGS,     ""},
1697
        {"forall",          AstContext_forall,          METH_VARARGS,     ""},
1698
        {"iff",             AstContext_iff,             METH_VARARGS,     ""},
1699
        {"ite",             AstContext_ite,             METH_VARARGS,     ""},
1700
        {"land",            AstContext_land,            METH_O,           ""},
1701
        {"let",             AstContext_let,             METH_VARARGS,     ""},
1702
        {"lnot",            AstContext_lnot,            METH_O,           ""},
1703
        {"lor",             AstContext_lor,             METH_O,           ""},
1704
        {"lxor",            AstContext_lxor,            METH_O,           ""},
1705
        {"reference",       AstContext_reference,       METH_O,           ""},
1706
        {"search",          AstContext_search,          METH_VARARGS,     ""},
1707
        {"string",          AstContext_string,          METH_O,           ""},
1708
        {"sx",              AstContext_sx,              METH_VARARGS,     ""},
1709
        {"unroll",          AstContext_unroll,          METH_O,           ""},
1710
        {"variable",        AstContext_variable,        METH_O,           ""},
1711
        {"zx",              AstContext_zx,              METH_VARARGS,     ""},
1712
        #ifdef TRITON_Z3_INTERFACE
1713
        {"tritonToZ3",      AstContext_tritonToZ3,      METH_O,           ""},
1714
        {"z3ToTriton",      AstContext_z3ToTriton,      METH_O,           ""},
1715
        #endif
1716
        {nullptr,           nullptr,                    0,                nullptr}
1717
      };
1718

1719

1720
      //! Python description for an ast context.
1721
      PyTypeObject AstContext_Type = {
1722
        PyVarObject_HEAD_INIT(&PyType_Type, 0)
1723
        "AstContext",                               /* tp_name */
1724
        sizeof(AstContext_Object),                  /* tp_basicsize */
1725
        0,                                          /* tp_itemsize */
1726
        (destructor)AstContext_dealloc,             /* tp_dealloc */
1727
        0,                                          /* tp_print or tp_vectorcall_offset */
1728
        0,                                          /* tp_getattr */
1729
        0,                                          /* tp_setattr */
1730
        0,                                          /* tp_compare */
1731
        0,                                          /* tp_repr */
1732
        0,                                          /* tp_as_number */
1733
        0,                                          /* tp_as_sequence */
1734
        0,                                          /* tp_as_mapping */
1735
        0,                                          /* tp_hash */
1736
        0,                                          /* tp_call */
1737
        0,                                          /* tp_str */
1738
        0,                                          /* tp_getattro */
1739
        0,                                          /* tp_setattro */
1740
        0,                                          /* tp_as_buffer */
1741
        Py_TPFLAGS_DEFAULT,                         /* tp_flags */
1742
        "AstContext objects",                       /* tp_doc */
1743
        0,                                          /* tp_traverse */
1744
        0,                                          /* tp_clear */
1745
        0,                                          /* tp_richcompare */
1746
        0,                                          /* tp_weaklistoffset */
1747
        0,                                          /* tp_iter */
1748
        0,                                          /* tp_iternext */
1749
        AstContext_callbacks,                       /* tp_methods */
1750
        0,                                          /* tp_members */
1751
        0,                                          /* tp_getset */
1752
        0,                                          /* tp_base */
1753
        0,                                          /* tp_dict */
1754
        0,                                          /* tp_descr_get */
1755
        0,                                          /* tp_descr_set */
1756
        0,                                          /* tp_dictoffset */
1757
        (initproc)AstContext_init,                  /* tp_init */
1758
        0,                                          /* tp_alloc */
1759
        (newfunc)AstContext_new,                    /* tp_new */
1760
        0,                                          /* tp_free */
1761
        0,                                          /* tp_is_gc */
1762
        0,                                          /* tp_bases */
1763
        0,                                          /* tp_mro */
1764
        0,                                          /* tp_cache */
1765
        0,                                          /* tp_subclasses */
1766
        0,                                          /* tp_weaklist */
1767
        0,                                          /* tp_del */
1768
        #if IS_PY3
1769
        0,                                          /* tp_version_tag */
1770
        0,                                          /* tp_finalize */
1771
        #if IS_PY3_8
1772
        0,                                          /* tp_vectorcall */
1773
        0,                                          /* bpo-37250: kept for backwards compatibility in CPython 3.8 only */
1774
        #endif
1775
        #else
1776
        0                                           /* tp_version_tag */
1777
        #endif
1778
      };
1779

1780

1781 1
      PyObject* PyAstContext(const triton::ast::SharedAstContext& ctxt) {
1782 1
        if (ctxt == nullptr) {
1783 0
          Py_INCREF(Py_None);
1784 0
          return Py_None;
1785
        }
1786

1787 1
        PyType_Ready(&AstContext_Type);
1788 1
        auto* object = (triton::bindings::python::AstContext_Object*)PyObject_CallObject((PyObject*)&AstContext_Type, nullptr);
1789 1
        if (object != NULL) {
1790 1
          object->ctxt = ctxt;
1791
        }
1792

1793
        return (PyObject*)object;
1794
      }
1795

1796
    }; /* python namespace */
1797
  }; /* bindings namespace */
1798 1
}; /* triton namespace */

Read our documentation on viewing source code .

Loading