libTriton  version 0.7 build 1419
ast.cpp
Go to the documentation of this file.
1 /*
3 ** Copyright (C) - Triton
4 **
5 ** This program is under the terms of the BSD License.
6 */
7 
8 #include <algorithm>
9 #include <cmath>
10 #include <new>
11 #include <stack>
12 #include <unordered_map>
13 #include <utility>
14 
15 #include <triton/ast.hpp>
16 #include <triton/astContext.hpp>
18 #include <triton/exceptions.hpp>
21 
22 
23 
24 namespace triton {
25  namespace ast {
26 
27  /* ====== Abstract node */
28 
30  this->ctxt = ctxt;
31  this->eval = 0;
32  this->size = 0;
33  this->symbolized = false;
34  this->type = type;
35  }
36 
37 
39  /* virtual */
40  }
41 
42 
44  return this->ctxt;
45  }
46 
47 
49  return this->type;
50  }
51 
52 
54  return this->size;
55  }
56 
57 
59  triton::uint512 mask = -1;
60  mask = mask >> (512 - this->size);
61  return mask;
62  }
63 
64 
65  bool AbstractNode::isSigned(void) const {
66  if ((this->eval >> (this->size-1)) & 1)
67  return true;
68  return false;
69  }
70 
71 
72  bool AbstractNode::isSymbolized(void) const {
73  return this->symbolized;
74  }
75 
76 
77  bool AbstractNode::isLogical(void) const {
78  switch (this->type) {
79  case BVSGE_NODE:
80  case BVSGT_NODE:
81  case BVSLE_NODE:
82  case BVSLT_NODE:
83  case BVUGE_NODE:
84  case BVUGT_NODE:
85  case BVULE_NODE:
86  case BVULT_NODE:
87  case DISTINCT_NODE:
88  case EQUAL_NODE:
89  case IFF_NODE:
90  case LAND_NODE:
91  case LNOT_NODE:
92  case LOR_NODE:
93  return true;
94 
95  case REFERENCE_NODE:
96  return this->logical;
97 
98  default:
99  break;
100  }
101 
102  return false;
103  }
104 
105 
106  bool AbstractNode::equalTo(const SharedAbstractNode& other) const {
107  return (this->evaluate() == other->evaluate()) &&
108  (this->getBitvectorSize() == other->getBitvectorSize()) &&
109  (this->hash(1) == other->hash(1));
110  }
111 
112 
114  return this->eval;
115  }
116 
117 
119  for (auto& sp : this->getParents())
120  sp->init();
121  }
122 
123 
124  std::vector<SharedAbstractNode>& AbstractNode::getChildren(void) {
125  return this->children;
126  }
127 
128 
129  std::vector<SharedAbstractNode> AbstractNode::getParents(void) {
130  std::vector<SharedAbstractNode> res;
131  std::vector<AbstractNode*> toRemove;
132 
133  for (auto& kv: parents) {
134  if (auto sp = kv.second.second.lock())
135  res.push_back(sp);
136  else
137  toRemove.push_back(kv.first);
138  }
139 
140  for(auto* an: toRemove)
141  parents.erase(an);
142 
143  return res;
144  }
145 
146 
148  auto it = parents.find(p);
149 
150  if (it == parents.end()) {
151  auto A = p->shared_from_this();
152  this->parents.insert(std::make_pair(p, std::make_pair(1, WeakAbstractNode(A))));
153  }
154  else {
155  if (it->second.second.expired()) {
156  parents.erase(it);
157  auto A = p->shared_from_this();
158  this->parents.insert(std::make_pair(p, std::make_pair(1, WeakAbstractNode(A))));
159  }
160  // Ptr already in, add it for the counter
161  else {
162  it->second.first += 1;
163  }
164  }
165  }
166 
167 
169  auto it = this->parents.find(p);
170 
171  if(it == parents.end())
172  return;
173 
174  it->second.first--;
175  if(it->second.first == 0)
176  this->parents.erase(it);
177  }
178 
179 
180  void AbstractNode::setParent(std::set<AbstractNode*>& p) {
181  for (auto ptr : p)
182  this->setParent(ptr);
183  }
184 
185 
187  this->children.push_back(child);
188  }
189 
190 
192  if (index >= this->children.size())
193  throw triton::exceptions::Ast("AbstractNode::setChild(): Invalid index.");
194 
195  if (child == nullptr)
196  throw triton::exceptions::Ast("AbstractNode::setChild(): child cannot be null.");
197 
198  /* Remove the parent of the old child */
199  this->children[index]->removeParent(this);
200 
201  /* Setup the parent of the child */
202  child->setParent(this);
203 
204  /* Setup the child of the parent */
205  this->children[index] = child;
206  }
207 
208 
210  this->size = size;
211  }
212 
213 
214  std::string AbstractNode::str(void) const {
215  std::stringstream s;
216  s << this;
217  if (!s.str().empty())
218  return s.str();
219  return nullptr;
220  }
221 
222 
223  /* ====== assert */
224 
225 
226  AssertNode::AssertNode(const SharedAbstractNode& expr): AbstractNode(ASSERT_NODE, expr->getContext()) {
227  this->addChild(expr);
228  }
229 
230 
231  void AssertNode::init(void) {
232  if (this->children.size() < 1)
233  throw triton::exceptions::Ast("AssertNode::init(): Must take at least one child.");
234 
235  if (this->children[0]->isLogical() == false)
236  throw triton::exceptions::Ast("AssertNode::init(): Must take a logical node as argument.");
237 
238  /* Init attributes */
239  this->size = this->children[0]->getBitvectorSize();
240  this->eval = ((this->children[0]->evaluate()) & this->getBitvectorMask());
241 
242  /* Init children and spread information */
243  for (triton::uint32 index = 0; index < this->children.size(); index++) {
244  this->children[index]->setParent(this);
245  this->symbolized |= this->children[index]->isSymbolized();
246  }
247 
248  /* Init parents */
249  this->initParents();
250  }
251 
252 
254  triton::uint512 h = this->type, s = this->children.size();
255  if (s) h = h * s;
256  for (triton::uint32 index = 0; index < this->children.size(); index++)
257  h = h * this->children[index]->hash(deep+1);
258  return triton::ast::rotl(h, deep);
259  }
260 
261 
262  /* ====== bvadd */
263 
264 
265  BvaddNode::BvaddNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVADD_NODE, expr1->getContext()) {
266  this->addChild(expr1);
267  this->addChild(expr2);
268  }
269 
270 
271  void BvaddNode::init(void) {
272  if (this->children.size() < 2)
273  throw triton::exceptions::Ast("BvaddNode::init(): Must take at least two children.");
274 
275  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
276  throw triton::exceptions::Ast("BvaddNode::init(): Must take two nodes of same size.");
277 
278  /* Init attributes */
279  this->size = this->children[0]->getBitvectorSize();
280  this->eval = ((this->children[0]->evaluate() + this->children[1]->evaluate()) & this->getBitvectorMask());
281 
282  /* Init children and spread information */
283  for (triton::uint32 index = 0; index < this->children.size(); index++) {
284  this->children[index]->setParent(this);
285  this->symbolized |= this->children[index]->isSymbolized();
286  }
287 
288  /* Init parents */
289  this->initParents();
290  }
291 
292 
294  triton::uint512 h = this->type, s = this->children.size();
295  if (s) h = h * s;
296  for (triton::uint32 index = 0; index < this->children.size(); index++)
297  h = h * this->children[index]->hash(deep+1);
298  return triton::ast::rotl(h, deep);
299  }
300 
301 
302  /* ====== bvand */
303 
304 
305  BvandNode::BvandNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVAND_NODE, expr1->getContext()) {
306  this->addChild(expr1);
307  this->addChild(expr2);
308  }
309 
310 
311  void BvandNode::init(void) {
312  if (this->children.size() < 2)
313  throw triton::exceptions::Ast("BvandNode::init(): Must take at least two children.");
314 
315  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
316  throw triton::exceptions::Ast("BvandNode::init(): Must take two nodes of same size.");
317 
318  /* Init attributes */
319  this->size = this->children[0]->getBitvectorSize();
320  this->eval = (this->children[0]->evaluate() & this->children[1]->evaluate());
321 
322  /* Init children and spread information */
323  for (triton::uint32 index = 0; index < this->children.size(); index++) {
324  this->children[index]->setParent(this);
325  this->symbolized |= this->children[index]->isSymbolized();
326  }
327 
328  /* Init parents */
329  this->initParents();
330  }
331 
332 
334  triton::uint512 h = this->type, s = this->children.size();
335  if (s) h = h * s;
336  for (triton::uint32 index = 0; index < this->children.size(); index++)
337  h = h * this->children[index]->hash(deep+1);
338  return triton::ast::rotl(h, deep);
339  }
340 
341 
342 
343  /* ====== bvashr (shift with sign extension fill) */
344 
345 
346  BvashrNode::BvashrNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVASHR_NODE, expr1->getContext()) {
347  this->addChild(expr1);
348  this->addChild(expr2);
349  }
350 
351 
352  void BvashrNode::init(void) {
353  triton::uint32 shift = 0;
354  triton::uint512 mask = 0;
355  triton::uint512 value = 0;
356 
357  if (this->children.size() < 2)
358  throw triton::exceptions::Ast("BvashrNode::init(): Must take at least two children.");
359 
360  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
361  throw triton::exceptions::Ast("BvashrNode::init(): Must take two nodes of same size.");
362 
363  value = this->children[0]->evaluate();
364  shift = this->children[1]->evaluate().convert_to<triton::uint32>();
365 
366  /* Init attributes */
367  this->size = this->children[0]->getBitvectorSize();
368 
369  /* Mask based on the sign */
370  if (this->children[0]->isSigned()) {
371  mask = 1;
372  mask = ((mask << (this->size-1)) & this->getBitvectorMask());
373  }
374 
375  if (shift >= this->size && this->children[0]->isSigned()) {
376  this->eval = -1;
377  this->eval &= this->getBitvectorMask();
378  }
379 
380  else if (shift >= this->size && !this->children[0]->isSigned()) {
381  this->eval = 0;
382  }
383 
384  else if (shift == 0) {
385  this->eval = value;
386  }
387 
388  else {
389  this->eval = value & this->getBitvectorMask();
390  for (triton::uint32 index = 0; index < shift; index++) {
391  this->eval = (((this->eval >> 1) | mask) & this->getBitvectorMask());
392  }
393  }
394 
395  /* Init children and spread information */
396  for (triton::uint32 index = 0; index < this->children.size(); index++) {
397  this->children[index]->setParent(this);
398  this->symbolized |= this->children[index]->isSymbolized();
399  }
400 
401  /* Init parents */
402  this->initParents();
403  }
404 
405 
407  triton::uint512 h = this->type, s = this->children.size();
408  if (s) h = h * s;
409  for (triton::uint32 index = 0; index < this->children.size(); index++)
410  h = h * triton::ast::hash2n(this->children[index]->hash(deep+1), index+1);
411  return triton::ast::rotl(h, deep);
412  }
413 
414 
415  /* ====== bvlshr (shift with zero filled) */
416 
417 
418  BvlshrNode::BvlshrNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVLSHR_NODE, expr1->getContext()) {
419  this->addChild(expr1);
420  this->addChild(expr2);
421  }
422 
423 
424  void BvlshrNode::init(void) {
425  if (this->children.size() < 2)
426  throw triton::exceptions::Ast("BvlshrNode::init(): Must take at least two children.");
427 
428  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
429  throw triton::exceptions::Ast("BvlshrNode::init(): Must take two nodes of same size.");
430 
431  /* Init attributes */
432  this->size = this->children[0]->getBitvectorSize();
433  this->eval = (this->children[0]->evaluate() >> this->children[1]->evaluate().convert_to<triton::uint32>());
434 
435  /* Init children and spread information */
436  for (triton::uint32 index = 0; index < this->children.size(); index++) {
437  this->children[index]->setParent(this);
438  this->symbolized |= this->children[index]->isSymbolized();
439  }
440 
441  /* Init parents */
442  this->initParents();
443  }
444 
445 
447  triton::uint512 h = this->type, s = this->children.size();
448  if (s) h = h * s;
449  for (triton::uint32 index = 0; index < this->children.size(); index++)
450  h = h * triton::ast::hash2n(this->children[index]->hash(deep+1), index+1);
451  return triton::ast::rotl(h, deep);
452  }
453 
454 
455  /* ====== bvmul */
456 
457 
458  BvmulNode::BvmulNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVMUL_NODE, expr1->getContext()) {
459  this->addChild(expr1);
460  this->addChild(expr2);
461  }
462 
463 
464  void BvmulNode::init(void) {
465  if (this->children.size() < 2)
466  throw triton::exceptions::Ast("BvmulNode::init(): Must take at least two children.");
467 
468  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
469  throw triton::exceptions::Ast("BvmulNode::init(): Must take two nodes of same size.");
470 
471  /* Init attributes */
472  this->size = this->children[0]->getBitvectorSize();
473  this->eval = ((this->children[0]->evaluate() * this->children[1]->evaluate()) & this->getBitvectorMask());
474 
475  /* Init children and spread information */
476  for (triton::uint32 index = 0; index < this->children.size(); index++) {
477  this->children[index]->setParent(this);
478  this->symbolized |= this->children[index]->isSymbolized();
479  }
480 
481  /* Init parents */
482  this->initParents();
483  }
484 
485 
487  triton::uint512 h = this->type, s = this->children.size();
488  if (s) h = h * s;
489  for (triton::uint32 index = 0; index < this->children.size(); index++)
490  h = h * this->children[index]->hash(deep+1);
491  return triton::ast::rotl(h, deep);
492  }
493 
494 
495  /* ====== bvnand */
496 
497 
498  BvnandNode::BvnandNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVNAND_NODE, expr1->getContext()) {
499  this->addChild(expr1);
500  this->addChild(expr2);
501  }
502 
503 
504  void BvnandNode::init(void) {
505  if (this->children.size() < 2)
506  throw triton::exceptions::Ast("BvnandNode::init(): Must take at least two children.");
507 
508  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
509  throw triton::exceptions::Ast("BvnandNode::init(): Must take two nodes of same size.");
510 
511  /* Init attributes */
512  this->size = this->children[0]->getBitvectorSize();
513  this->eval = (~(this->children[0]->evaluate() & this->children[1]->evaluate()) & this->getBitvectorMask());
514 
515  /* Init children and spread information */
516  for (triton::uint32 index = 0; index < this->children.size(); index++) {
517  this->children[index]->setParent(this);
518  this->symbolized |= this->children[index]->isSymbolized();
519  }
520 
521  /* Init parents */
522  this->initParents();
523  }
524 
525 
527  triton::uint512 h = this->type, s = this->children.size();
528  if (s) h = h * s;
529  for (triton::uint32 index = 0; index < this->children.size(); index++)
530  h = h * this->children[index]->hash(deep+1);
531  return triton::ast::rotl(h, deep);
532  }
533 
534 
535  /* ====== bvneg */
536 
537 
538  BvnegNode::BvnegNode(const SharedAbstractNode& expr): AbstractNode(BVNEG_NODE, expr->getContext()) {
539  this->addChild(expr);
540  }
541 
542 
543  void BvnegNode::init(void) {
544  if (this->children.size() < 1)
545  throw triton::exceptions::Ast("BvnegNode::init(): Must take at least one child.");
546 
547  /* Init attributes */
548  this->size = this->children[0]->getBitvectorSize();
549  this->eval = ((-(this->children[0]->evaluate().convert_to<triton::sint512>())).convert_to<triton::uint512>() & this->getBitvectorMask());
550 
551  /* Init children and spread information */
552  for (triton::uint32 index = 0; index < this->children.size(); index++) {
553  this->children[index]->setParent(this);
554  this->symbolized |= this->children[index]->isSymbolized();
555  }
556 
557  /* Init parents */
558  this->initParents();
559  }
560 
561 
563  triton::uint512 h = this->type, s = this->children.size();
564  if (s) h = h * s;
565  for (triton::uint32 index = 0; index < this->children.size(); index++)
566  h = h * this->children[index]->hash(deep+1);
567  return triton::ast::rotl(h, deep);
568  }
569 
570 
571  /* ====== bvnor */
572 
573 
574  BvnorNode::BvnorNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVNOR_NODE, expr1->getContext()) {
575  this->addChild(expr1);
576  this->addChild(expr2);
577  }
578 
579 
580  void BvnorNode::init(void) {
581  if (this->children.size() < 2)
582  throw triton::exceptions::Ast("BvnorNode::init(): Must take at least two children.");
583 
584  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
585  throw triton::exceptions::Ast("BvnorNode::init(): Must take two nodes of same size.");
586 
587  /* Init attributes */
588  this->size = this->children[0]->getBitvectorSize();
589  this->eval = (~(this->children[0]->evaluate() | this->children[1]->evaluate()) & this->getBitvectorMask());
590 
591  /* Init children and spread information */
592  for (triton::uint32 index = 0; index < this->children.size(); index++) {
593  this->children[index]->setParent(this);
594  this->symbolized |= this->children[index]->isSymbolized();
595  }
596 
597  /* Init parents */
598  this->initParents();
599  }
600 
601 
603  triton::uint512 h = this->type, s = this->children.size();
604  if (s) h = h * s;
605  for (triton::uint32 index = 0; index < this->children.size(); index++)
606  h = h * this->children[index]->hash(deep+1);
607  return triton::ast::rotl(h, deep);
608  }
609 
610 
611  /* ====== bvnot */
612 
613 
614  BvnotNode::BvnotNode(const SharedAbstractNode& expr): AbstractNode(BVNOT_NODE, expr->getContext()) {
615  this->addChild(expr);
616  }
617 
618 
619  void BvnotNode::init(void) {
620  if (this->children.size() < 1)
621  throw triton::exceptions::Ast("BvnotNode::init(): Must take at least one child.");
622 
623  /* Init attributes */
624  this->size = this->children[0]->getBitvectorSize();
625  this->eval = (~this->children[0]->evaluate() & this->getBitvectorMask());
626 
627  /* Init children and spread information */
628  for (triton::uint32 index = 0; index < this->children.size(); index++) {
629  this->children[index]->setParent(this);
630  this->symbolized |= this->children[index]->isSymbolized();
631  }
632 
633  /* Init parents */
634  this->initParents();
635  }
636 
637 
639  triton::uint512 h = this->type, s = this->children.size();
640  if (s) h = h * s;
641  for (triton::uint32 index = 0; index < this->children.size(); index++)
642  h = h * this->children[index]->hash(deep+1);
643  return triton::ast::rotl(h, deep);
644  }
645 
646 
647  /* ====== bvor */
648 
649 
650  BvorNode::BvorNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVOR_NODE, expr1->getContext()) {
651  this->addChild(expr1);
652  this->addChild(expr2);
653  }
654 
655 
656  void BvorNode::init(void) {
657  if (this->children.size() < 2)
658  throw triton::exceptions::Ast("BvorNode::init(): Must take at least two children.");
659 
660  if (this->children[0]->getBitvectorSize() != this->children[0]->getBitvectorSize())
661  throw triton::exceptions::Ast("BvorNode::init(): Must take two nodes of same size.");
662 
663  /* Init attributes */
664  this->size = this->children[0]->getBitvectorSize();
665  this->eval = (this->children[0]->evaluate() | this->children[1]->evaluate());
666 
667  /* Init children and spread information */
668  for (triton::uint32 index = 0; index < this->children.size(); index++) {
669  this->children[index]->setParent(this);
670  this->symbolized |= this->children[index]->isSymbolized();
671  }
672 
673  /* Init parents */
674  this->initParents();
675  }
676 
677 
679  triton::uint512 h = this->type, s = this->children.size();
680  if (s) h = h * s;
681  for (triton::uint32 index = 0; index < this->children.size(); index++)
682  h = h * this->children[index]->hash(deep+1);
683  return triton::ast::rotl(h, deep);
684  }
685 
686 
687  /* ====== bvrol */
688 
689 
690  BvrolNode::BvrolNode(const SharedAbstractNode& expr, triton::uint32 rot): BvrolNode(expr, expr->getContext()->integer(rot)) {
691  }
692 
693 
694  BvrolNode::BvrolNode(const SharedAbstractNode& expr, const SharedAbstractNode& rot): AbstractNode(BVROL_NODE, expr->getContext()) {
695  this->addChild(expr);
696  this->addChild(rot);
697  }
698 
699 
700  void BvrolNode::init(void) {
701  triton::uint32 rot = 0;
702  triton::uint512 value = 0;
703 
704  if (this->children.size() < 2)
705  throw triton::exceptions::Ast("BvrolNode::init(): Must take at least two children.");
706 
707  if (this->children[1]->getType() != INTEGER_NODE)
708  throw triton::exceptions::Ast("BvrolNode::init(): rot must be a INTEGER_NODE.");
709 
710  rot = reinterpret_cast<IntegerNode*>(this->children[1].get())->getInteger().convert_to<triton::uint32>();
711  value = this->children[0]->evaluate();
712 
713  /* Init attributes */
714  this->size = this->children[0]->getBitvectorSize();
715  rot %= this->size;
716  this->eval = (((value << rot) | (value >> (this->size - rot))) & this->getBitvectorMask());
717 
718  /* Init children and spread information */
719  for (triton::uint32 index = 0; index < this->children.size(); index++) {
720  this->children[index]->setParent(this);
721  this->symbolized |= this->children[index]->isSymbolized();
722  }
723 
724  /* Init parents */
725  this->initParents();
726  }
727 
728 
730  triton::uint512 h = this->type, s = this->children.size();
731  if (s) h = h * s;
732  for (triton::uint32 index = 0; index < this->children.size(); index++)
733  h = h * triton::ast::hash2n(this->children[index]->hash(deep+1), index+1);
734  return triton::ast::rotl(h, deep);
735  }
736 
737 
738  /* ====== bvror */
739 
740 
741  BvrorNode::BvrorNode(const SharedAbstractNode& expr, triton::uint32 rot): BvrorNode(expr, expr->getContext()->integer(rot)) {
742  }
743 
744 
745  BvrorNode::BvrorNode(const SharedAbstractNode& expr, const SharedAbstractNode& rot): AbstractNode(BVROR_NODE, expr->getContext()) {
746  this->addChild(expr);
747  this->addChild(rot);
748  }
749 
750 
751  void BvrorNode::init(void) {
752  triton::uint32 rot = 0;
753  triton::uint512 value = 0;
754 
755  if (this->children.size() < 2)
756  throw triton::exceptions::Ast("BvrorNode::init(): Must take at least two children.");
757 
758  if (this->children[1]->getType() != INTEGER_NODE)
759  throw triton::exceptions::Ast("BvrorNode::init(): rot must be a INTEGER_NODE.");
760 
761  rot = reinterpret_cast<IntegerNode*>(this->children[1].get())->getInteger().convert_to<triton::uint32>();
762  value = this->children[0]->evaluate();
763 
764  /* Init attributes */
765  this->size = this->children[0]->getBitvectorSize();
766  rot %= this->size;
767  this->eval = (((value >> rot) | (value << (this->size - rot))) & this->getBitvectorMask());
768 
769  /* Init children and spread information */
770  for (triton::uint32 index = 0; index < this->children.size(); index++) {
771  this->children[index]->setParent(this);
772  this->symbolized |= this->children[index]->isSymbolized();
773  }
774 
775  /* Init parents */
776  this->initParents();
777  }
778 
779 
781  triton::uint512 h = this->type, s = this->children.size();
782  if (s) h = h * s;
783  for (triton::uint32 index = 0; index < this->children.size(); index++)
784  h = h * triton::ast::hash2n(this->children[index]->hash(deep+1), index+1);
785  return triton::ast::rotl(h, deep);
786  }
787 
788 
789  /* ====== bvsdiv */
790 
791 
792  BvsdivNode::BvsdivNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVSDIV_NODE, expr1->getContext()) {
793  this->addChild(expr1);
794  this->addChild(expr2);
795  }
796 
797 
798  void BvsdivNode::init(void) {
799  triton::sint512 op1Signed = 0;
800  triton::sint512 op2Signed = 0;
801 
802  if (this->children.size() < 2)
803  throw triton::exceptions::Ast("BvsdivNode::init(): Must take at least two children.");
804 
805  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
806  throw triton::exceptions::Ast("BvsdivNode::init(): Must take two nodes of same size.");
807 
808  /* Sign extend */
809  op1Signed = triton::ast::modularSignExtend(this->children[0].get());
810  op2Signed = triton::ast::modularSignExtend(this->children[1].get());
811 
812  /* Init attributes */
813  this->size = this->children[0]->getBitvectorSize();
814 
815  if (op2Signed == 0) {
816  this->eval = (op1Signed < 0 ? 1 : -1);
817  this->eval &= this->getBitvectorMask();
818  }
819  else
820  this->eval = ((op1Signed / op2Signed).convert_to<triton::uint512>() & this->getBitvectorMask());
821 
822  /* Init children and spread information */
823  for (triton::uint32 index = 0; index < this->children.size(); index++) {
824  this->children[index]->setParent(this);
825  this->symbolized |= this->children[index]->isSymbolized();
826  }
827 
828  /* Init parents */
829  this->initParents();
830  }
831 
832 
834  triton::uint512 h = this->type, s = this->children.size();
835  if (s) h = h * s;
836  for (triton::uint32 index = 0; index < this->children.size(); index++)
837  h = h * triton::ast::hash2n(this->children[index]->hash(deep+1), index+1);
838  return triton::ast::rotl(h, deep);
839  }
840 
841 
842  /* ====== bvsge */
843 
844 
845  BvsgeNode::BvsgeNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVSGE_NODE, expr1->getContext()) {
846  this->addChild(expr1);
847  this->addChild(expr2);
848  }
849 
850 
851  void BvsgeNode::init(void) {
852  triton::sint512 op1Signed = 0;
853  triton::sint512 op2Signed = 0;
854 
855  if (this->children.size() < 2)
856  throw triton::exceptions::Ast("BvsgeNode::init(): Must take at least two children.");
857 
858  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
859  throw triton::exceptions::Ast("BvsgeNode::init(): Must take two nodes of same size.");
860 
861  /* Sign extend */
862  op1Signed = triton::ast::modularSignExtend(this->children[0].get());
863  op2Signed = triton::ast::modularSignExtend(this->children[1].get());
864 
865  /* Init attributes */
866  this->size = 1;
867  this->eval = (op1Signed >= op2Signed);
868 
869  /* Init children and spread information */
870  for (triton::uint32 index = 0; index < this->children.size(); index++) {
871  this->children[index]->setParent(this);
872  this->symbolized |= this->children[index]->isSymbolized();
873  }
874 
875  /* Init parents */
876  this->initParents();
877  }
878 
879 
881  triton::uint512 h = this->type, s = this->children.size();
882  if (s) h = h * s;
883  for (triton::uint32 index = 0; index < this->children.size(); index++)
884  h = h * triton::ast::hash2n(this->children[index]->hash(deep+1), index+1);
885  return triton::ast::rotl(h, deep);
886  }
887 
888 
889  /* ====== bvsgt */
890 
891 
892  BvsgtNode::BvsgtNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVSGT_NODE, expr1->getContext()) {
893  this->addChild(expr1);
894  this->addChild(expr2);
895  }
896 
897 
898  void BvsgtNode::init(void) {
899  triton::sint512 op1Signed = 0;
900  triton::sint512 op2Signed = 0;
901 
902  if (this->children.size() < 2)
903  throw triton::exceptions::Ast("BvsgtNode::init(): Must take at least two children.");
904 
905  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
906  throw triton::exceptions::Ast("BvsgtNode::init(): Must take two nodes of same size.");
907 
908  /* Sign extend */
909  op1Signed = triton::ast::modularSignExtend(this->children[0].get());
910  op2Signed = triton::ast::modularSignExtend(this->children[1].get());
911 
912  /* Init attributes */
913  this->size = 1;
914  this->eval = (op1Signed > op2Signed);
915 
916  /* Init children and spread information */
917  for (triton::uint32 index = 0; index < this->children.size(); index++) {
918  this->children[index]->setParent(this);
919  this->symbolized |= this->children[index]->isSymbolized();
920  }
921 
922  /* Init parents */
923  this->initParents();
924  }
925 
926 
928  triton::uint512 h = this->type, s = this->children.size();
929  if (s) h = h * s;
930  for (triton::uint32 index = 0; index < this->children.size(); index++)
931  h = h * triton::ast::hash2n(this->children[index]->hash(deep+1), index+1);
932  return triton::ast::rotl(h, deep);
933  }
934 
935 
936  /* ====== bvshl */
937 
938 
939  BvshlNode::BvshlNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVSHL_NODE, expr1->getContext()) {
940  this->addChild(expr1);
941  this->addChild(expr2);
942  }
943 
944 
945  void BvshlNode::init(void) {
946  if (this->children.size() < 2)
947  throw triton::exceptions::Ast("BvshlNode::init(): Must take at least two children.");
948 
949  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
950  throw triton::exceptions::Ast("BvshlNode::init(): Must take two nodes of same size.");
951 
952  /* Init attributes */
953  this->size = this->children[0]->getBitvectorSize();
954  this->eval = ((this->children[0]->evaluate() << this->children[1]->evaluate().convert_to<triton::uint32>()) & this->getBitvectorMask());
955 
956  /* Init children and spread information */
957  for (triton::uint32 index = 0; index < this->children.size(); index++) {
958  this->children[index]->setParent(this);
959  this->symbolized |= this->children[index]->isSymbolized();
960  }
961 
962  /* Init parents */
963  this->initParents();
964  }
965 
966 
968  triton::uint512 h = this->type, s = this->children.size();
969  if (s) h = h * s;
970  for (triton::uint32 index = 0; index < this->children.size(); index++)
971  h = h * triton::ast::hash2n(this->children[index]->hash(deep+1), index+1);
972  return triton::ast::rotl(h, deep);
973  }
974 
975 
976  /* ====== bvsle */
977 
978 
979  BvsleNode::BvsleNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVSLE_NODE, expr1->getContext()) {
980  this->addChild(expr1);
981  this->addChild(expr2);
982  }
983 
984 
985  void BvsleNode::init(void) {
986  triton::sint512 op1Signed = 0;
987  triton::sint512 op2Signed = 0;
988 
989  if (this->children.size() < 2)
990  throw triton::exceptions::Ast("BvsleNode::init(): Must take at least two children.");
991 
992  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
993  throw triton::exceptions::Ast("BvsleNode::init(): Must take two nodes of same size.");
994 
995  /* Sign extend */
996  op1Signed = triton::ast::modularSignExtend(this->children[0].get());
997  op2Signed = triton::ast::modularSignExtend(this->children[1].get());
998 
999  /* Init attributes */
1000  this->size = 1;
1001  this->eval = (op1Signed <= op2Signed);
1002 
1003  /* Init children and spread information */
1004  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1005  this->children[index]->setParent(this);
1006  this->symbolized |= this->children[index]->isSymbolized();
1007  }
1008 
1009  /* Init parents */
1010  this->initParents();
1011  }
1012 
1013 
1015  triton::uint512 h = this->type, s = this->children.size();
1016  if (s) h = h * s;
1017  for (triton::uint32 index = 0; index < this->children.size(); index++)
1018  h = h * triton::ast::hash2n(this->children[index]->hash(deep+1), index+1);
1019  return triton::ast::rotl(h, deep);
1020  }
1021 
1022 
1023  /* ====== bvslt */
1024 
1025 
1026  BvsltNode::BvsltNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVSLT_NODE, expr1->getContext()) {
1027  this->addChild(expr1);
1028  this->addChild(expr2);
1029  }
1030 
1031 
1032  void BvsltNode::init(void) {
1033  triton::sint512 op1Signed = 0;
1034  triton::sint512 op2Signed = 0;
1035 
1036  if (this->children.size() < 2)
1037  throw triton::exceptions::Ast("BvsltNode::init(): Must take at least two children.");
1038 
1039  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
1040  throw triton::exceptions::Ast("BvsltNode::init(): Must take two nodes of same size.");
1041 
1042  /* Sign extend */
1043  op1Signed = triton::ast::modularSignExtend(this->children[0].get());
1044  op2Signed = triton::ast::modularSignExtend(this->children[1].get());
1045 
1046  /* Init attributes */
1047  this->size = 1;
1048  this->eval = (op1Signed < op2Signed);
1049 
1050  /* Init children and spread information */
1051  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1052  this->children[index]->setParent(this);
1053  this->symbolized |= this->children[index]->isSymbolized();
1054  }
1055 
1056  /* Init parents */
1057  this->initParents();
1058  }
1059 
1060 
1062  triton::uint512 h = this->type, s = this->children.size();
1063  if (s) h = h * s;
1064  for (triton::uint32 index = 0; index < this->children.size(); index++)
1065  h = h * triton::ast::hash2n(this->children[index]->hash(deep+1), index+1);
1066  return triton::ast::rotl(h, deep);
1067  }
1068 
1069 
1070  /* ====== bvsmod - 2's complement signed remainder (sign follows divisor) */
1071 
1072 
1073  BvsmodNode::BvsmodNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVSMOD_NODE, expr1->getContext()) {
1074  this->addChild(expr1);
1075  this->addChild(expr2);
1076  }
1077 
1078 
1079  void BvsmodNode::init(void) {
1080  triton::sint512 op1Signed = 0;
1081  triton::sint512 op2Signed = 0;
1082 
1083  if (this->children.size() < 2)
1084  throw triton::exceptions::Ast("BvsmodNode::init(): Must take at least two children.");
1085 
1086  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
1087  throw triton::exceptions::Ast("BvsmodNode::init(): Must take two nodes of same size.");
1088 
1089  /* Sign extend */
1090  op1Signed = triton::ast::modularSignExtend(this->children[0].get());
1091  op2Signed = triton::ast::modularSignExtend(this->children[1].get());
1092 
1093  /* Init attributes */
1094  this->size = this->children[0]->getBitvectorSize();
1095 
1096  if (this->children[1]->evaluate() == 0)
1097  this->eval = this->children[0]->evaluate();
1098  else
1099  this->eval = ((((op1Signed % op2Signed) + op2Signed) % op2Signed).convert_to<triton::uint512>() & this->getBitvectorMask());
1100 
1101  /* Init children and spread information */
1102  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1103  this->children[index]->setParent(this);
1104  this->symbolized |= this->children[index]->isSymbolized();
1105  }
1106 
1107  /* Init parents */
1108  this->initParents();
1109  }
1110 
1111 
1113  triton::uint512 h = this->type, s = this->children.size();
1114  if (s) h = h * s;
1115  for (triton::uint32 index = 0; index < this->children.size(); index++)
1116  h = h * triton::ast::hash2n(this->children[index]->hash(deep+1), index+1);
1117  return triton::ast::rotl(h, deep);
1118  }
1119 
1120 
1121  /* ====== bvsrem - 2's complement signed remainder (sign follows dividend) */
1122 
1123 
1124  BvsremNode::BvsremNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVSREM_NODE, expr1->getContext()) {
1125  this->addChild(expr1);
1126  this->addChild(expr2);
1127  }
1128 
1129 
1130  void BvsremNode::init(void) {
1131  triton::sint512 op1Signed = 0;
1132  triton::sint512 op2Signed = 0;
1133 
1134  if (this->children.size() < 2)
1135  throw triton::exceptions::Ast("BvsremNode::init(): Must take at least two children.");
1136 
1137  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
1138  throw triton::exceptions::Ast("BvsremNode::init(): Must take two nodes of same size.");
1139 
1140  /* Sign extend */
1141  op1Signed = triton::ast::modularSignExtend(this->children[0].get());
1142  op2Signed = triton::ast::modularSignExtend(this->children[1].get());
1143 
1144  /* Init attributes */
1145  this->size = this->children[0]->getBitvectorSize();
1146 
1147  if (this->children[1]->evaluate() == 0)
1148  this->eval = this->children[0]->evaluate();
1149  else
1150  this->eval = ((op1Signed - ((op1Signed / op2Signed) * op2Signed)).convert_to<triton::uint512>() & this->getBitvectorMask());
1151 
1152  /* Init children and spread information */
1153  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1154  this->children[index]->setParent(this);
1155  this->symbolized |= this->children[index]->isSymbolized();
1156  }
1157 
1158  /* Init parents */
1159  this->initParents();
1160  }
1161 
1162 
1164  triton::uint512 h = this->type, s = this->children.size();
1165  if (s) h = h * s;
1166  for (triton::uint32 index = 0; index < this->children.size(); index++)
1167  h = h * triton::ast::hash2n(this->children[index]->hash(deep+1), index+1);
1168  return triton::ast::rotl(h, deep);
1169  }
1170 
1171 
1172  /* ====== bvsub */
1173 
1174 
1175  BvsubNode::BvsubNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVSUB_NODE, expr1->getContext()) {
1176  this->addChild(expr1);
1177  this->addChild(expr2);
1178  }
1179 
1180 
1181  void BvsubNode::init(void) {
1182  if (this->children.size() < 2)
1183  throw triton::exceptions::Ast("BvsubNode::init(): Must take at least two children.");
1184 
1185  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
1186  throw triton::exceptions::Ast("BvsubNode::init(): Must take two nodes of same size.");
1187 
1188  /* Init attributes */
1189  this->size = this->children[0]->getBitvectorSize();
1190  this->eval = ((this->children[0]->evaluate() - this->children[1]->evaluate()) & this->getBitvectorMask());
1191 
1192  /* Init children and spread information */
1193  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1194  this->children[index]->setParent(this);
1195  this->symbolized |= this->children[index]->isSymbolized();
1196  }
1197 
1198  /* Init parents */
1199  this->initParents();
1200  }
1201 
1202 
1204  triton::uint512 h = this->type, s = this->children.size();
1205  if (s) h = h * s;
1206  for (triton::uint32 index = 0; index < this->children.size(); index++)
1207  h = h * triton::ast::hash2n(this->children[index]->hash(deep+1), index+1);
1208  return triton::ast::rotl(h, deep);
1209  }
1210 
1211 
1212  /* ====== bvudiv */
1213 
1214 
1215  BvudivNode::BvudivNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVUDIV_NODE, expr1->getContext()) {
1216  this->addChild(expr1);
1217  this->addChild(expr2);
1218  }
1219 
1220 
1221  void BvudivNode::init(void) {
1222  if (this->children.size() < 2)
1223  throw triton::exceptions::Ast("BvudivNode::init(): Must take at least two children.");
1224 
1225  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
1226  throw triton::exceptions::Ast("BvudivNode::init(): Must take two nodes of same size.");
1227 
1228  /* Init attributes */
1229  this->size = this->children[0]->getBitvectorSize();
1230 
1231  if (this->children[1]->evaluate() == 0)
1232  this->eval = (-1 & this->getBitvectorMask());
1233  else
1234  this->eval = (this->children[0]->evaluate() / this->children[1]->evaluate());
1235 
1236  /* Init children and spread information */
1237  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1238  this->children[index]->setParent(this);
1239  this->symbolized |= this->children[index]->isSymbolized();
1240  }
1241 
1242  /* Init parents */
1243  this->initParents();
1244  }
1245 
1246 
1248  triton::uint512 h = this->type, s = this->children.size();
1249  if (s) h = h * s;
1250  for (triton::uint32 index = 0; index < this->children.size(); index++)
1251  h = h * triton::ast::hash2n(this->children[index]->hash(deep+1), index+1);
1252  return triton::ast::rotl(h, deep);
1253  }
1254 
1255 
1256  /* ====== bvuge */
1257 
1258 
1259  BvugeNode::BvugeNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVUGE_NODE, expr1->getContext()) {
1260  this->addChild(expr1);
1261  this->addChild(expr2);
1262  }
1263 
1264 
1265  void BvugeNode::init(void) {
1266  if (this->children.size() < 2)
1267  throw triton::exceptions::Ast("BvugeNode::init(): Must take at least two children.");
1268 
1269  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
1270  throw triton::exceptions::Ast("BvugeNode::init(): Must take two nodes of same size.");
1271 
1272  /* Init attributes */
1273  this->size = 1;
1274  this->eval = (this->children[0]->evaluate() >= this->children[1]->evaluate());
1275 
1276  /* Init children and spread information */
1277  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1278  this->children[index]->setParent(this);
1279  this->symbolized |= this->children[index]->isSymbolized();
1280  }
1281 
1282  /* Init parents */
1283  this->initParents();
1284  }
1285 
1286 
1288  triton::uint512 h = this->type, s = this->children.size();
1289  if (s) h = h * s;
1290  for (triton::uint32 index = 0; index < this->children.size(); index++)
1291  h = h * triton::ast::hash2n(this->children[index]->hash(deep+1), index+1);
1292  return triton::ast::rotl(h, deep);
1293  }
1294 
1295 
1296  /* ====== bvugt */
1297 
1298 
1299  BvugtNode::BvugtNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVUGT_NODE, expr1->getContext()) {
1300  this->addChild(expr1);
1301  this->addChild(expr2);
1302  }
1303 
1304 
1305  void BvugtNode::init(void) {
1306  if (this->children.size() < 2)
1307  throw triton::exceptions::Ast("BvugtNode::init(): Must take at least two children.");
1308 
1309  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
1310  throw triton::exceptions::Ast("BvugtNode::init(): Must take two nodes of same size.");
1311 
1312  /* Init attributes */
1313  this->size = 1;
1314  this->eval = (this->children[0]->evaluate() > this->children[1]->evaluate());
1315 
1316  /* Init children and spread information */
1317  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1318  this->children[index]->setParent(this);
1319  this->symbolized |= this->children[index]->isSymbolized();
1320  }
1321 
1322  /* Init parents */
1323  this->initParents();
1324  }
1325 
1326 
1328  triton::uint512 h = this->type, s = this->children.size();
1329  if (s) h = h * s;
1330  for (triton::uint32 index = 0; index < this->children.size(); index++)
1331  h = h * triton::ast::hash2n(this->children[index]->hash(deep+1), index+1);
1332  return triton::ast::rotl(h, deep);
1333  }
1334 
1335 
1336  /* ====== bvule */
1337 
1338 
1339  BvuleNode::BvuleNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVULE_NODE, expr1->getContext()) {
1340  this->addChild(expr1);
1341  this->addChild(expr2);
1342  }
1343 
1344 
1345  void BvuleNode::init(void) {
1346  if (this->children.size() < 2)
1347  throw triton::exceptions::Ast("BvuleNode::init(): Must take at least two children.");
1348 
1349  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
1350  throw triton::exceptions::Ast("BvuleNode::init(): Must take two nodes of same size.");
1351 
1352  /* Init attributes */
1353  this->size = 1;
1354  this->eval = (this->children[0]->evaluate() <= this->children[1]->evaluate());
1355 
1356  /* Init children and spread information */
1357  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1358  this->children[index]->setParent(this);
1359  this->symbolized |= this->children[index]->isSymbolized();
1360  }
1361 
1362  /* Init parents */
1363  this->initParents();
1364  }
1365 
1366 
1368  triton::uint512 h = this->type, s = this->children.size();
1369  if (s) h = h * s;
1370  for (triton::uint32 index = 0; index < this->children.size(); index++)
1371  h = h * triton::ast::hash2n(this->children[index]->hash(deep+1), index+1);
1372  return triton::ast::rotl(h, deep);
1373  }
1374 
1375 
1376  /* ====== bvult */
1377 
1378 
1379  BvultNode::BvultNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVULT_NODE, expr1->getContext()) {
1380  this->addChild(expr1);
1381  this->addChild(expr2);
1382  }
1383 
1384 
1385  void BvultNode::init(void) {
1386  if (this->children.size() < 2)
1387  throw triton::exceptions::Ast("BvultNode::init(): Must take at least two children.");
1388 
1389  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
1390  throw triton::exceptions::Ast("BvultNode::init(): Must take two nodes of same size.");
1391 
1392  /* Init attributes */
1393  this->size = 1;
1394  this->eval = (this->children[0]->evaluate() < this->children[1]->evaluate());
1395 
1396  /* Init children and spread information */
1397  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1398  this->children[index]->setParent(this);
1399  this->symbolized |= this->children[index]->isSymbolized();
1400  }
1401 
1402  /* Init parents */
1403  this->initParents();
1404  }
1405 
1406 
1408  triton::uint512 h = this->type, s = this->children.size();
1409  if (s) h = h * s;
1410  for (triton::uint32 index = 0; index < this->children.size(); index++)
1411  h = h * triton::ast::hash2n(this->children[index]->hash(deep+1), index+1);
1412  return triton::ast::rotl(h, deep);
1413  }
1414 
1415 
1416  /* ====== bvurem */
1417 
1418 
1419  BvuremNode::BvuremNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVUREM_NODE, expr1->getContext()) {
1420  this->addChild(expr1);
1421  this->addChild(expr2);
1422  }
1423 
1424 
1425  void BvuremNode::init(void) {
1426  if (this->children.size() < 2)
1427  throw triton::exceptions::Ast("BvuremNode::init(): Must take at least two children.");
1428 
1429  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
1430  throw triton::exceptions::Ast("BvuremNode::init(): Must take two nodes of same size.");
1431 
1432  /* Init attributes */
1433  this->size = this->children[0]->getBitvectorSize();
1434 
1435  if (this->children[1]->evaluate() == 0)
1436  this->eval = this->children[0]->evaluate();
1437  else
1438  this->eval = (this->children[0]->evaluate() % this->children[1]->evaluate());
1439 
1440  /* Init children and spread information */
1441  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1442  this->children[index]->setParent(this);
1443  this->symbolized |= this->children[index]->isSymbolized();
1444  }
1445 
1446  /* Init parents */
1447  this->initParents();
1448  }
1449 
1450 
1452  triton::uint512 h = this->type, s = this->children.size();
1453  if (s) h = h * s;
1454  for (triton::uint32 index = 0; index < this->children.size(); index++)
1455  h = h * triton::ast::hash2n(this->children[index]->hash(deep+1), index+1);
1456  return triton::ast::rotl(h, deep);
1457  }
1458 
1459 
1460  /* ====== bvxnor */
1461 
1462 
1463  BvxnorNode::BvxnorNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVXNOR_NODE, expr1->getContext()) {
1464  this->addChild(expr1);
1465  this->addChild(expr2);
1466  }
1467 
1468 
1469  void BvxnorNode::init(void) {
1470  if (this->children.size() < 2)
1471  throw triton::exceptions::Ast("BvxnorNode::init(): Must take at least two children.");
1472 
1473  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
1474  throw triton::exceptions::Ast("BvxnorNode::init(): Must take two nodes of same size.");
1475 
1476  /* Init attributes */
1477  this->size = this->children[0]->getBitvectorSize();
1478  this->eval = (~(this->children[0]->evaluate() ^ this->children[1]->evaluate()) & this->getBitvectorMask());
1479 
1480  /* Init children and spread information */
1481  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1482  this->children[index]->setParent(this);
1483  this->symbolized |= this->children[index]->isSymbolized();
1484  }
1485 
1486  /* Init parents */
1487  this->initParents();
1488  }
1489 
1490 
1492  triton::uint512 h = this->type, s = this->children.size();
1493  if (s) h = h * s;
1494  for (triton::uint32 index = 0; index < this->children.size(); index++)
1495  h = h * this->children[index]->hash(deep+1);
1496  return triton::ast::rotl(h, deep);
1497  }
1498 
1499 
1500  /* ====== bvxor */
1501 
1502 
1503  BvxorNode::BvxorNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVXOR_NODE, expr1->getContext()) {
1504  this->addChild(expr1);
1505  this->addChild(expr2);
1506  }
1507 
1508 
1509  void BvxorNode::init(void) {
1510  if (this->children.size() < 2)
1511  throw triton::exceptions::Ast("BvxorNode::init(): Must take at least two children.");
1512 
1513  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
1514  throw triton::exceptions::Ast("BvxorNode::init(): Must take two nodes of same size.");
1515 
1516  /* Init attributes */
1517  this->size = this->children[0]->getBitvectorSize();
1518  this->eval = (this->children[0]->evaluate() ^ this->children[1]->evaluate());
1519 
1520  /* Init children and spread information */
1521  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1522  this->children[index]->setParent(this);
1523  this->symbolized |= this->children[index]->isSymbolized();
1524  }
1525 
1526  /* Init parents */
1527  this->initParents();
1528  }
1529 
1530 
1532  triton::uint512 h = this->type, s = this->children.size();
1533  if (s) h = h * s;
1534  for (triton::uint32 index = 0; index < this->children.size(); index++)
1535  h = h * this->children[index]->hash(deep+1);
1536  return triton::ast::rotl(h, deep);
1537  }
1538 
1539 
1540  /* ====== bv */
1541 
1542 
1543  BvNode::BvNode(triton::uint512 value, triton::uint32 size, const SharedAstContext& ctxt): AbstractNode(BV_NODE, ctxt) {
1544  this->addChild(this->ctxt->integer(value));
1545  this->addChild(this->ctxt->integer(size));
1546  }
1547 
1548 
1549  void BvNode::init(void) {
1550  triton::uint512 value = 0;
1551  triton::uint32 size = 0;
1552 
1553  if (this->children.size() < 2)
1554  throw triton::exceptions::Ast("BvNode::init(): Must take at least two children.");
1555 
1556  if (this->children[0]->getType() != INTEGER_NODE || this->children[1]->getType() != INTEGER_NODE)
1557  throw triton::exceptions::Ast("BvNode::init(): Size and value must be a INTEGER_NODE.");
1558 
1559  value = reinterpret_cast<IntegerNode*>(this->children[0].get())->getInteger();
1560  size = reinterpret_cast<IntegerNode*>(this->children[1].get())->getInteger().convert_to<triton::uint32>();
1561 
1562  if (!size)
1563  throw triton::exceptions::Ast("BvNode::init(): Size connot be equal to zero.");
1564 
1565  if (size > MAX_BITS_SUPPORTED)
1566  throw triton::exceptions::Ast("BvNode::init(): Size connot be greater than MAX_BITS_SUPPORTED.");
1567 
1568  /* Init attributes */
1569  this->size = size;
1570  this->eval = (value & this->getBitvectorMask());
1571 
1572  /* Init children and spread information */
1573  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1574  this->children[index]->setParent(this);
1575  this->symbolized |= this->children[index]->isSymbolized();
1576  }
1577 
1578  /* Init parents */
1579  this->initParents();
1580  }
1581 
1582 
1584  triton::uint512 h = this->type, s = this->children.size();
1585  if (s) h = h * s;
1586  for (triton::uint32 index = 0; index < this->children.size(); index++)
1587  h = h * triton::ast::hash2n(this->children[index]->hash(deep+1), index+1);
1588  return triton::ast::rotl(h, deep);
1589  }
1590 
1591 
1592  /* ====== compound */
1593 
1594 
1595  void CompoundNode::init(void) {
1596  if (this->children.size() < 1)
1597  throw triton::exceptions::Ast("CompoundNode::init(): Must take at least one child.");
1598 
1599  /* Init attributes */
1600  this->size = 0;
1601  this->eval = 0;
1602 
1603  /* Init children and spread information */
1604  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1605  this->children[index]->setParent(this);
1606  this->symbolized |= this->children[index]->isSymbolized();
1607  }
1608 
1609  /* Init parents */
1610  this->initParents();
1611  }
1612 
1613 
1615  triton::uint512 h = this->type, s = this->children.size();
1616  if (s) h = h * s;
1617  for (triton::uint32 index = 0; index < this->children.size(); index++)
1618  h = h * triton::ast::hash2n(this->children[index]->hash(deep+1), index+1);
1619  return triton::ast::rotl(h, deep);
1620  }
1621 
1622 
1623  /* ====== concat */
1624 
1625 
1626  ConcatNode::ConcatNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(CONCAT_NODE, expr1->getContext()) {
1627  this->addChild(expr1);
1628  this->addChild(expr2);
1629  }
1630 
1631 
1632  void ConcatNode::init(void) {
1633  if (this->children.size() < 2)
1634  throw triton::exceptions::Ast("ConcatNode::init(): Must take at least two children.");
1635 
1636  /* Init attributes */
1637  this->size = 0;
1638  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1639  this->size += this->children[index]->getBitvectorSize();
1640  }
1641 
1642  if (this->size > MAX_BITS_SUPPORTED)
1643  throw triton::exceptions::Ast("ConcatNode::init(): Size connot be greater than MAX_BITS_SUPPORTED.");
1644 
1645  this->eval = this->children[0]->evaluate();
1646  for (triton::uint32 index = 0; index < this->children.size()-1; index++)
1647  this->eval = ((this->eval << this->children[index+1]->getBitvectorSize()) | this->children[index+1]->evaluate());
1648 
1649  /* Init children and spread information */
1650  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1651  this->children[index]->setParent(this);
1652  this->symbolized |= this->children[index]->isSymbolized();
1653  }
1654 
1655  /* Init parents */
1656  this->initParents();
1657  }
1658 
1659 
1661  triton::uint512 h = this->type, s = this->children.size();
1662  if (s) h = h * s;
1663  for (triton::uint32 index = 0; index < this->children.size(); index++)
1664  h = h * triton::ast::hash2n(this->children[index]->hash(deep+1), index+1);
1665  return triton::ast::rotl(h, deep);
1666  }
1667 
1668 
1669  /* ====== Declare */
1670 
1671 
1672  DeclareNode::DeclareNode(const SharedAbstractNode& var): AbstractNode(DECLARE_NODE, var->getContext()) {
1673  this->addChild(var);
1674  }
1675 
1676 
1677  void DeclareNode::init(void) {
1678  if (this->children.size() < 1)
1679  throw triton::exceptions::Ast("DeclareNode::init(): Must take at least one child.");
1680 
1681  if (this->children[0]->getType() != VARIABLE_NODE)
1682  throw triton::exceptions::Ast("DeclareNode::init(): The child node must be a VARIABLE_NODE.");
1683 
1684  /* Init attributes */
1685  this->size = this->children[0]->getBitvectorSize();
1686  this->eval = this->children[0]->evaluate();
1687 
1688  /* Init children and spread information */
1689  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1690  this->children[index]->setParent(this);
1691  this->symbolized |= this->children[index]->isSymbolized();
1692  }
1693 
1694  /* Init parents */
1695  this->initParents();
1696  }
1697 
1698 
1700  triton::uint512 h = this->type, s = this->children.size();
1701  if (s) h = h * s;
1702  for (triton::uint32 index = 0; index < this->children.size(); index++)
1703  h = h * triton::ast::hash2n(this->children[index]->hash(deep+1), index+1);
1704  return triton::ast::rotl(h, deep);
1705  }
1706 
1707 
1708  /* ====== Distinct node */
1709 
1710 
1711  DistinctNode::DistinctNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(DISTINCT_NODE, expr1->getContext()) {
1712  this->addChild(expr1);
1713  this->addChild(expr2);
1714  }
1715 
1716 
1717  void DistinctNode::init(void) {
1718  if (this->children.size() < 2)
1719  throw triton::exceptions::Ast("DistinctNode::init(): Must take at least two children.");
1720 
1721  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
1722  throw triton::exceptions::Ast("DistinctNode::init(): Must take two nodes of same size.");
1723 
1724  /* Init attributes */
1725  this->size = 1;
1726  this->eval = (this->children[0]->evaluate() != this->children[1]->evaluate());
1727 
1728  /* Init children and spread information */
1729  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1730  this->children[index]->setParent(this);
1731  this->symbolized |= this->children[index]->isSymbolized();
1732  }
1733 
1734  /* Init parents */
1735  this->initParents();
1736  }
1737 
1738 
1740  triton::uint512 h = this->type, s = this->children.size();
1741  if (s) h = h * s;
1742  for (triton::uint32 index = 0; index < this->children.size(); index++)
1743  h = h * this->children[index]->hash(deep+1);
1744  return triton::ast::rotl(h, deep);
1745  }
1746 
1747 
1748  /* ====== equal */
1749 
1750 
1751  EqualNode::EqualNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(EQUAL_NODE, expr1->getContext()) {
1752  this->addChild(expr1);
1753  this->addChild(expr2);
1754  }
1755 
1756 
1757  void EqualNode::init(void) {
1758  if (this->children.size() < 2)
1759  throw triton::exceptions::Ast("EqualNode::init(): Must take at least two children.");
1760 
1761  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
1762  throw triton::exceptions::Ast("EqualNode::init(): Must take two nodes of same size.");
1763 
1764  /* Init attributes */
1765  this->size = 1;
1766  this->eval = (this->children[0]->evaluate() == this->children[1]->evaluate());
1767 
1768  /* Init children and spread information */
1769  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1770  this->children[index]->setParent(this);
1771  this->symbolized |= this->children[index]->isSymbolized();
1772  }
1773 
1774  /* Init parents */
1775  this->initParents();
1776  }
1777 
1778 
1780  triton::uint512 h = this->type, s = this->children.size();
1781  if (s) h = h * s;
1782  for (triton::uint32 index = 0; index < this->children.size(); index++)
1783  h = h * this->children[index]->hash(deep+1);
1784  return triton::ast::rotl(h, deep);
1785  }
1786 
1787 
1788  /* ====== extract */
1789 
1790 
1791  ExtractNode::ExtractNode(triton::uint32 high, triton::uint32 low, const SharedAbstractNode& expr): AbstractNode(EXTRACT_NODE, expr->getContext()) {
1792  this->addChild(this->ctxt->integer(high));
1793  this->addChild(this->ctxt->integer(low));
1794  this->addChild(expr);
1795  }
1796 
1797 
1798  void ExtractNode::init(void) {
1799  triton::uint32 high = 0;
1800  triton::uint32 low = 0;
1801 
1802  if (this->children.size() < 3)
1803  throw triton::exceptions::Ast("ExtractNode::init(): Must take at least three children.");
1804 
1805  if (this->children[0]->getType() != INTEGER_NODE || this->children[1]->getType() != INTEGER_NODE)
1806  throw triton::exceptions::Ast("ExtractNode::init(): The highest and lower bit must be a INTEGER_NODE.");
1807 
1808  high = reinterpret_cast<IntegerNode*>(this->children[0].get())->getInteger().convert_to<triton::uint32>();
1809  low = reinterpret_cast<IntegerNode*>(this->children[1].get())->getInteger().convert_to<triton::uint32>();
1810 
1811  if (low > high)
1812  throw triton::exceptions::Ast("ExtractNode::init(): The high bit must be greater than the low bit.");
1813 
1814  /* Init attributes */
1815  this->size = ((high - low) + 1);
1816  this->eval = ((this->children[2]->evaluate() >> low) & this->getBitvectorMask());
1817 
1818  if (this->size > this->children[2]->getBitvectorSize() || high >= this->children[2]->getBitvectorSize())
1819  throw triton::exceptions::Ast("ExtractNode::init(): The size of the extraction is higher than the child expression.");
1820 
1821  /* Init children and spread information */
1822  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1823  this->children[index]->setParent(this);
1824  this->symbolized |= this->children[index]->isSymbolized();
1825  }
1826 
1827  /* Init parents */
1828  this->initParents();
1829  }
1830 
1831 
1833  triton::uint512 h = this->type, s = this->children.size();
1834  if (s) h = h * s;
1835  for (triton::uint32 index = 0; index < this->children.size(); index++)
1836  h = h * triton::ast::hash2n(this->children[index]->hash(deep+1), index+1);
1837  return triton::ast::rotl(h, deep);
1838  }
1839 
1840 
1841  /* ====== iff */
1842 
1843 
1844  IffNode::IffNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(IFF_NODE, expr1->getContext()) {
1845  this->addChild(expr1);
1846  this->addChild(expr2);
1847  }
1848 
1849 
1850  void IffNode::init(void) {
1851  if (this->children.size() < 2)
1852  throw triton::exceptions::Ast("IffNode::init(): Must take at least two children.");
1853 
1854  if (this->children[0]->isLogical() == false)
1855  throw triton::exceptions::Ast("IffNode::init(): Must take a logical node as first argument.");
1856 
1857  if (this->children[1]->isLogical() == false)
1858  throw triton::exceptions::Ast("IffNode::init(): Must take a logical node as second argument.");
1859 
1860  /* Init attributes */
1861  triton::uint512 P = this->children[0]->evaluate();
1862  triton::uint512 Q = this->children[1]->evaluate();
1863 
1864  this->size = 1;
1865  this->eval = (P && Q) || (!P && !Q);
1866 
1867  /* Init children and spread information */
1868  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1869  this->children[index]->setParent(this);
1870  this->symbolized |= this->children[index]->isSymbolized();
1871  }
1872 
1873  /* Init parents */
1874  this->initParents();
1875  }
1876 
1877 
1879  triton::uint512 h = this->type, s = this->children.size();
1880  if (s) h = h * s;
1881  for (triton::uint32 index = 0; index < this->children.size(); index++)
1882  h = h * triton::ast::hash2n(this->children[index]->hash(deep+1), index+1);
1883  return triton::ast::rotl(h, deep);
1884  }
1885 
1886 
1887  /* ====== Integer node */
1888 
1889 
1890  IntegerNode::IntegerNode(triton::uint512 value, const SharedAstContext& ctxt): AbstractNode(INTEGER_NODE, ctxt) {
1891  this->value = value;
1892  }
1893 
1894 
1895  void IntegerNode::init(void) {
1896  /* Init attributes */
1897  this->eval = 0;
1898  this->size = 0;
1899  this->symbolized = false;
1900 
1901  /* Init parents */
1902  this->initParents();
1903  }
1904 
1905 
1906  triton::uint512 IntegerNode::getInteger(void) {
1907  return this->value;
1908  }
1909 
1910 
1912  triton::uint512 hash = this->type ^ this->value;
1913  return hash;
1914  }
1915 
1916 
1917  /* ====== ite */
1918 
1919 
1920  IteNode::IteNode(const SharedAbstractNode& ifExpr, const SharedAbstractNode& thenExpr, const SharedAbstractNode& elseExpr): AbstractNode(ITE_NODE, ifExpr->getContext()) {
1921  this->addChild(ifExpr);
1922  this->addChild(thenExpr);
1923  this->addChild(elseExpr);
1924  }
1925 
1926 
1927  void IteNode::init(void) {
1928  if (this->children.size() < 3)
1929  throw triton::exceptions::Ast("IteNode::init(): Must take at least three children.");
1930 
1931  if (this->children[0]->isLogical() == false)
1932  throw triton::exceptions::Ast("IteNode::init(): Must take a logical node as first argument.");
1933 
1934  if (this->children[1]->getBitvectorSize() != this->children[2]->getBitvectorSize())
1935  throw triton::exceptions::Ast("IteNode::init(): Must take two nodes of same size as 'then' and 'else' branches.");
1936 
1937  /* Init attributes */
1938  this->size = this->children[1]->getBitvectorSize();
1939  this->eval = this->children[0]->evaluate() ? this->children[1]->evaluate() : this->children[2]->evaluate();
1940 
1941  /* Init children and spread information */
1942  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1943  this->children[index]->setParent(this);
1944  this->symbolized |= this->children[index]->isSymbolized();
1945  }
1946 
1947  /* Init parents */
1948  this->initParents();
1949  }
1950 
1951 
1953  triton::uint512 h = this->type, s = this->children.size();
1954  if (s) h = h * s;
1955  for (triton::uint32 index = 0; index < this->children.size(); index++)
1956  h = h * triton::ast::hash2n(this->children[index]->hash(deep+1), index+1);
1957  return triton::ast::rotl(h, deep);
1958  }
1959 
1960 
1961  /* ====== Land */
1962 
1963 
1964  LandNode::LandNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(LAND_NODE, expr1->getContext()) {
1965  this->addChild(expr1);
1966  this->addChild(expr2);
1967  }
1968 
1969 
1970  void LandNode::init(void) {
1971  if (this->children.size() < 2)
1972  throw triton::exceptions::Ast("LandNode::init(): Must take at least two children.");
1973 
1974  /* Init attributes */
1975  this->size = 1;
1976  this->eval = 1;
1977 
1978  /* Init children and spread information */
1979  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1980  this->children[index]->setParent(this);
1981  this->symbolized |= this->children[index]->isSymbolized();
1982  this->eval = this->eval && this->children[index]->evaluate();
1983 
1984  if (this->children[index]->isLogical() == false)
1985  throw triton::exceptions::Ast("LandNode::init(): Must take logical nodes as arguments.");
1986  }
1987 
1988  /* Init parents */
1989  this->initParents();
1990  }
1991 
1992 
1994  triton::uint512 h = this->type, s = this->children.size();
1995  if (s) h = h * s;
1996  for (triton::uint32 index = 0; index < this->children.size(); index++)
1997  h = h * this->children[index]->hash(deep+1);
1998  return triton::ast::rotl(h, deep);
1999  }
2000 
2001 
2002  /* ====== Let */
2003 
2004 
2005  LetNode::LetNode(std::string alias, const SharedAbstractNode& expr2, const SharedAbstractNode& expr3): AbstractNode(LET_NODE, expr2->getContext()) {
2006  this->addChild(this->ctxt->string(alias));
2007  this->addChild(expr2);
2008  this->addChild(expr3);
2009  }
2010 
2011 
2012  void LetNode::init(void) {
2013  if (this->children.size() < 3)
2014  throw triton::exceptions::Ast("LetNode::init(): Must take at least three children.");
2015 
2016  if (this->children[0]->getType() != STRING_NODE)
2017  throw triton::exceptions::Ast("LetNode::init(): The alias node must be a STRING_NODE.");
2018 
2019  /* Init attributes */
2020  this->size = this->children[2]->getBitvectorSize();
2021  this->eval = this->children[2]->evaluate();
2022 
2023  /* Init children and spread information */
2024  for (triton::uint32 index = 0; index < this->children.size(); index++) {
2025  this->children[index]->setParent(this);
2026  this->symbolized |= this->children[index]->isSymbolized();
2027  }
2028 
2029  /* Init parents */
2030  this->initParents();
2031  }
2032 
2033 
2035  triton::uint512 h = this->type, s = this->children.size();
2036  if (s) h = h * s;
2037  for (triton::uint32 index = 0; index < this->children.size(); index++)
2038  h = h * triton::ast::hash2n(this->children[index]->hash(deep+1), index+1);
2039  return triton::ast::rotl(h, deep);
2040  }
2041 
2042 
2043  /* ====== Lnot */
2044 
2045 
2046  LnotNode::LnotNode(const SharedAbstractNode& expr): AbstractNode(LNOT_NODE, expr->getContext()) {
2047  this->addChild(expr);
2048  }
2049 
2050 
2051  void LnotNode::init(void) {
2052  if (this->children.size() < 1)
2053  throw triton::exceptions::Ast("LnotNode::init(): Must take at least one child.");
2054 
2055  /* Init attributes */
2056  this->size = 1;
2057  this->eval = !(this->children[0]->evaluate());
2058 
2059  /* Init children and spread information */
2060  for (triton::uint32 index = 0; index < this->children.size(); index++) {
2061  this->children[index]->setParent(this);
2062  this->symbolized |= this->children[index]->isSymbolized();
2063 
2064  if (this->children[index]->isLogical() == false)
2065  throw triton::exceptions::Ast("LnotNode::init(): Must take logical nodes arguments.");
2066  }
2067 
2068 
2069  /* Init parents */
2070  this->initParents();
2071  }
2072 
2073 
2075  triton::uint512 h = this->type, s = this->children.size();
2076  if (s) h = h * s;
2077  for (triton::uint32 index = 0; index < this->children.size(); index++)
2078  h = h * this->children[index]->hash(deep+1);
2079  return triton::ast::rotl(h, deep);
2080  }
2081 
2082 
2083  /* ====== Lor */
2084 
2085 
2086  LorNode::LorNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(LOR_NODE, expr1->getContext()) {
2087  this->addChild(expr1);
2088  this->addChild(expr2);
2089  }
2090 
2091 
2092  void LorNode::init(void) {
2093  if (this->children.size() < 2)
2094  throw triton::exceptions::Ast("LorNode::init(): Must take at least two children.");
2095 
2096  /* Init attributes */
2097  this->size = 1;
2098  this->eval = 0;
2099 
2100  /* Init children and spread information */
2101  for (triton::uint32 index = 0; index < this->children.size(); index++) {
2102  this->children[index]->setParent(this);
2103  this->symbolized |= this->children[index]->isSymbolized();
2104  this->eval = this->eval || this->children[index]->evaluate();
2105 
2106  if (this->children[index]->isLogical() == false)
2107  throw triton::exceptions::Ast("LorNode::init(): Must take logical nodes as arguments.");
2108  }
2109 
2110  /* Init parents */
2111  this->initParents();
2112  }
2113 
2114 
2116  triton::uint512 h = this->type, s = this->children.size();
2117  if (s) h = h * s;
2118  for (triton::uint32 index = 0; index < this->children.size(); index++)
2119  h = h * this->children[index]->hash(deep+1);
2120  return triton::ast::rotl(h, deep);
2121  }
2122 
2123 
2124  /* ====== Reference node */
2125 
2126 
2127  ReferenceNode::ReferenceNode(const triton::engines::symbolic::SharedSymbolicExpression& expr)
2128  : AbstractNode(REFERENCE_NODE, expr->getAst()->getContext())
2129  , expr(expr) {
2130  }
2131 
2132 
2133  void ReferenceNode::init(void) {
2134  /* Init attributes */
2135  this->eval = this->expr->getAst()->evaluate();
2136  this->logical = this->expr->getAst()->isLogical();
2137  this->size = this->expr->getAst()->getBitvectorSize();
2138  this->symbolized = this->expr->getAst()->isSymbolized();
2139 
2140  this->expr->getAst()->setParent(this);
2141 
2142  /* Init parents */
2143  this->initParents();
2144  }
2145 
2146 
2148  triton::uint512 hash = this->type ^ this->expr->getId();
2149  return hash;
2150  }
2151 
2152 
2153  const triton::engines::symbolic::SharedSymbolicExpression& ReferenceNode::getSymbolicExpression(void) const {
2154  return this->expr;
2155  }
2156 
2157 
2158  /* ====== String node */
2159 
2160 
2161  StringNode::StringNode(std::string value, const SharedAstContext& ctxt): AbstractNode(STRING_NODE, ctxt) {
2162  this->value = value;
2163  }
2164 
2165 
2166  void StringNode::init(void) {
2167  /* Init attributes */
2168  this->eval = 0;
2169  this->size = 0;
2170  this->symbolized = false;
2171 
2172  /* Init parents */
2173  this->initParents();
2174  }
2175 
2176 
2177  std::string StringNode::getString(void) {
2178  return this->value;
2179  }
2180 
2181 
2183  triton::uint512 h = this->type;
2184  triton::uint32 index = 1;
2185  for (std::string::const_iterator it=this->value.cbegin(); it != this->value.cend(); it++)
2186  h = h ^ triton::ast::hash2n(*it, index++);
2187  return triton::ast::rotl(h, deep);
2188  }
2189 
2190 
2191  /* ====== sx */
2192 
2193 
2194  SxNode::SxNode(triton::uint32 sizeExt, const SharedAbstractNode& expr): AbstractNode(SX_NODE, expr->getContext()) {
2195  this->addChild(this->ctxt->integer(sizeExt));
2196  this->addChild(expr);
2197  }
2198 
2199 
2200  void SxNode::init(void) {
2201  triton::uint32 sizeExt = 0;
2202 
2203  if (this->children.size() < 2)
2204  throw triton::exceptions::Ast("SxNode::init(): Must take at least two children.");
2205 
2206  if (this->children[0]->getType() != INTEGER_NODE)
2207  throw triton::exceptions::Ast("SxNode::init(): The sizeExt must be a INTEGER_NODE.");
2208 
2209  sizeExt = reinterpret_cast<IntegerNode*>(this->children[0].get())->getInteger().convert_to<triton::uint32>();
2210 
2211  /* Init attributes */
2212  this->size = sizeExt + this->children[1]->getBitvectorSize();
2213  if (size > MAX_BITS_SUPPORTED)
2214  throw triton::exceptions::Ast("SxNode::SxNode(): Size connot be greater than MAX_BITS_SUPPORTED.");
2215 
2216  this->eval = ((((this->children[1]->evaluate() >> (this->children[1]->getBitvectorSize()-1)) == 0) ? this->children[1]->evaluate() : (this->children[1]->evaluate() | ~(this->children[1]->getBitvectorMask()))) & this->getBitvectorMask());
2217 
2218  /* Init children and spread information */
2219  for (triton::uint32 index = 0; index < this->children.size(); index++) {
2220  this->children[index]->setParent(this);
2221  this->symbolized |= this->children[index]->isSymbolized();
2222  }
2223 
2224  /* Init parents */
2225  this->initParents();
2226  }
2227 
2228 
2230  triton::uint512 h = this->type, s = this->children.size();
2231  if (s) h = h * s;
2232  for (triton::uint32 index = 0; index < this->children.size(); index++)
2233  h = h * triton::ast::hash2n(this->children[index]->hash(deep+1), index+1);
2234  return triton::ast::rotl(h, deep);
2235  }
2236 
2237 
2238  /* ====== Variable node */
2239 
2240 
2241  // WARNING: A variable ast node should not live once the SymbolicVariable is dead
2242  VariableNode::VariableNode(const triton::engines::symbolic::SharedSymbolicVariable& symVar, const SharedAstContext& ctxt)
2243  : AbstractNode(VARIABLE_NODE, ctxt),
2244  symVar(symVar) {
2245  }
2246 
2247 
2248  void VariableNode::init(void) {
2249  this->size = this->symVar->getSize();
2250  this->eval = this->ctxt->getVariableValue(this->symVar->getName()) & this->getBitvectorMask();
2251  this->symbolized = true;
2252 
2253  /* Init parents */
2254  this->initParents();
2255  }
2256 
2257 
2258  const triton::engines::symbolic::SharedSymbolicVariable& VariableNode::getSymbolicVariable() {
2259  return this->symVar;
2260  }
2261 
2262 
2264  triton::uint512 h = this->type;
2265  triton::uint32 index = 1;
2266 
2267  for (char c : this->symVar->getName())
2268  h = h ^ triton::ast::hash2n(c, index++);
2269 
2270  return triton::ast::rotl(h, deep);
2271  }
2272 
2273 
2274  /* ====== zx */
2275 
2276 
2277  ZxNode::ZxNode(triton::uint32 sizeExt, const SharedAbstractNode& expr): AbstractNode(ZX_NODE, expr->getContext()) {
2278  this->addChild(this->ctxt->integer(sizeExt));
2279  this->addChild(expr);
2280  }
2281 
2282 
2283  void ZxNode::init(void) {
2284  triton::uint32 sizeExt = 0;
2285 
2286  if (this->children.size() < 2)
2287  throw triton::exceptions::Ast("ZxNode::init(): Must take at least two children.");
2288 
2289  if (this->children[0]->getType() != INTEGER_NODE)
2290  throw triton::exceptions::Ast("ZxNode::init(): The sizeExt must be a INTEGER_NODE.");
2291 
2292  sizeExt = reinterpret_cast<IntegerNode*>(this->children[0].get())->getInteger().convert_to<triton::uint32>();
2293 
2294  /* Init attributes */
2295  this->size = sizeExt + this->children[1]->getBitvectorSize();
2296  if (size > MAX_BITS_SUPPORTED)
2297  throw triton::exceptions::Ast("ZxNode::init(): Size connot be greater than MAX_BITS_SUPPORTED.");
2298 
2299  this->eval = (this->children[1]->evaluate() & this->getBitvectorMask());
2300 
2301  /* Init children and spread information */
2302  for (triton::uint32 index = 0; index < this->children.size(); index++) {
2303  this->children[index]->setParent(this);
2304  this->symbolized |= this->children[index]->isSymbolized();
2305  }
2306 
2307  /* Init parents */
2308  this->initParents();
2309  }
2310 
2311 
2313  triton::uint512 h = this->type, s = this->children.size();
2314  if (s) h = h * s;
2315  for (triton::uint32 index = 0; index < this->children.size(); index++)
2316  h = h * triton::ast::hash2n(this->children[index]->hash(deep+1), index+1);
2317  return triton::ast::rotl(h, deep);
2318  }
2319 
2320  }; /* ast namespace */
2321 }; /* triton namespace */
2322 
2323 
2324 
2325 /* ====== Force templates declarations */
2326 
2327 namespace triton {
2328  namespace ast {
2329 
2330  template TRITON_EXPORT CompoundNode::CompoundNode(const std::list<SharedAbstractNode>& exprs, const SharedAstContext& ctxt);
2331  template TRITON_EXPORT CompoundNode::CompoundNode(const std::vector<SharedAbstractNode>& exprs, const SharedAstContext& ctxt);
2332  template TRITON_EXPORT ConcatNode::ConcatNode(const std::list<SharedAbstractNode>& exprs, const SharedAstContext& ctxt);
2333  template TRITON_EXPORT ConcatNode::ConcatNode(const std::vector<SharedAbstractNode>& exprs, const SharedAstContext& ctxt);
2334  template TRITON_EXPORT LandNode::LandNode(const std::list<SharedAbstractNode>& exprs, const SharedAstContext& ctxt);
2335  template TRITON_EXPORT LandNode::LandNode(const std::vector<SharedAbstractNode>& exprs, const SharedAstContext& ctxt);
2336  template TRITON_EXPORT LorNode::LorNode(const std::list<SharedAbstractNode>& exprs, const SharedAstContext& ctxt);
2337  template TRITON_EXPORT LorNode::LorNode(const std::vector<SharedAbstractNode>& exprs, const SharedAstContext& ctxt);
2338 
2339  }; /* ast namespace */
2340 }; /* triton namespace */
2341 
2342 
2343 
2344 /* ====== Operators */
2345 
2346 namespace triton {
2347  namespace ast {
2348 
2349  /* Representation dispatcher from an abstract node */
2350  std::ostream& operator<<(std::ostream& stream, AbstractNode* node) {
2351  return node->getContext()->print(stream, node);
2352  }
2353 
2354  }; /* ast namespace */
2355 }; /* triton namespace */
2356 
2357 
2358 
2359 /* ====== Math utils */
2360 
2361 namespace triton {
2362  namespace ast {
2363 
2365  triton::uint512 mask = -1;
2366  for (triton::uint32 i = 0; i < n; i++)
2367  hash = ((hash * hash) & mask);
2368  return hash;
2369  }
2370 
2371 
2373  if ((shift &= 511) == 0)
2374  return value;
2375  return ((value << shift) | (value >> (512 - shift)));
2376  }
2377 
2378 
2380  triton::sint512 value = 0;
2381 
2382  if ((node->evaluate() >> (node->getBitvectorSize()-1)) & 1) {
2383  value = -1;
2384  value = ((value << node->getBitvectorSize()) | node->evaluate());
2385  }
2386  else {
2387  value = node->evaluate();
2388  }
2389 
2390  return value;
2391  }
2392 
2393  }; /* ast namespace */
2394 }; /* triton namespace */
2395 
2396 
2397 
2398 /* ====== Node utilities */
2399 
2400 namespace triton {
2401  namespace ast {
2402 
2404  SharedAbstractNode newNode = nullptr;
2405 
2406  if (node == nullptr)
2407  return nullptr;
2408 
2409  switch (node->getType()) {
2410  case ASSERT_NODE: newNode = std::make_shared<AssertNode>(*reinterpret_cast<AssertNode*>(node)); break;
2411  case BVADD_NODE: newNode = std::make_shared<BvaddNode>(*reinterpret_cast<BvaddNode*>(node)); break;
2412  case BVAND_NODE: newNode = std::make_shared<BvandNode>(*reinterpret_cast<BvandNode*>(node)); break;
2413  case BVASHR_NODE: newNode = std::make_shared<BvashrNode>(*reinterpret_cast<BvashrNode*>(node)); break;
2414  case BVLSHR_NODE: newNode = std::make_shared<BvlshrNode>(*reinterpret_cast<BvlshrNode*>(node)); break;
2415  case BVMUL_NODE: newNode = std::make_shared<BvmulNode>(*reinterpret_cast<BvmulNode*>(node)); break;
2416  case BVNAND_NODE: newNode = std::make_shared<BvnandNode>(*reinterpret_cast<BvnandNode*>(node)); break;
2417  case BVNEG_NODE: newNode = std::make_shared<BvnegNode>(*reinterpret_cast<BvnegNode*>(node)); break;
2418  case BVNOR_NODE: newNode = std::make_shared<BvnorNode>(*reinterpret_cast<BvnorNode*>(node)); break;
2419  case BVNOT_NODE: newNode = std::make_shared<BvnotNode>(*reinterpret_cast<BvnotNode*>(node)); break;
2420  case BVOR_NODE: newNode = std::make_shared<BvorNode>(*reinterpret_cast<BvorNode*>(node)); break;
2421  case BVROL_NODE: newNode = std::make_shared<BvrolNode>(*reinterpret_cast<BvrolNode*>(node)); break;
2422  case BVROR_NODE: newNode = std::make_shared<BvrorNode>(*reinterpret_cast<BvrorNode*>(node)); break;
2423  case BVSDIV_NODE: newNode = std::make_shared<BvsdivNode>(*reinterpret_cast<BvsdivNode*>(node)); break;
2424  case BVSGE_NODE: newNode = std::make_shared<BvsgeNode>(*reinterpret_cast<BvsgeNode*>(node)); break;
2425  case BVSGT_NODE: newNode = std::make_shared<BvsgtNode>(*reinterpret_cast<BvsgtNode*>(node)); break;
2426  case BVSHL_NODE: newNode = std::make_shared<BvshlNode>(*reinterpret_cast<BvshlNode*>(node)); break;
2427  case BVSLE_NODE: newNode = std::make_shared<BvsleNode>(*reinterpret_cast<BvsleNode*>(node)); break;
2428  case BVSLT_NODE: newNode = std::make_shared<BvsltNode>(*reinterpret_cast<BvsltNode*>(node)); break;
2429  case BVSMOD_NODE: newNode = std::make_shared<BvsmodNode>(*reinterpret_cast<BvsmodNode*>(node)); break;
2430  case BVSREM_NODE: newNode = std::make_shared<BvsremNode>(*reinterpret_cast<BvsremNode*>(node)); break;
2431  case BVSUB_NODE: newNode = std::make_shared<BvsubNode>(*reinterpret_cast<BvsubNode*>(node)); break;
2432  case BVUDIV_NODE: newNode = std::make_shared<BvudivNode>(*reinterpret_cast<BvudivNode*>(node)); break;
2433  case BVUGE_NODE: newNode = std::make_shared<BvugeNode>(*reinterpret_cast<BvugeNode*>(node)); break;
2434  case BVUGT_NODE: newNode = std::make_shared<BvugtNode>(*reinterpret_cast<BvugtNode*>(node)); break;
2435  case BVULE_NODE: newNode = std::make_shared<BvuleNode>(*reinterpret_cast<BvuleNode*>(node)); break;
2436  case BVULT_NODE: newNode = std::make_shared<BvultNode>(*reinterpret_cast<BvultNode*>(node)); break;
2437  case BVUREM_NODE: newNode = std::make_shared<BvuremNode>(*reinterpret_cast<BvuremNode*>(node)); break;
2438  case BVXNOR_NODE: newNode = std::make_shared<BvxnorNode>(*reinterpret_cast<BvxnorNode*>(node)); break;
2439  case BVXOR_NODE: newNode = std::make_shared<BvxorNode>(*reinterpret_cast<BvxorNode*>(node)); break;
2440  case BV_NODE: newNode = std::make_shared<BvNode>(*reinterpret_cast<BvNode*>(node)); break;
2441  case COMPOUND_NODE: newNode = std::make_shared<CompoundNode>(*reinterpret_cast<CompoundNode*>(node)); break;
2442  case CONCAT_NODE: newNode = std::make_shared<ConcatNode>(*reinterpret_cast<ConcatNode*>(node)); break;
2443  case DECLARE_NODE: newNode = std::make_shared<DeclareNode>(*reinterpret_cast<DeclareNode*>(node)); break;
2444  case DISTINCT_NODE: newNode = std::make_shared<DistinctNode>(*reinterpret_cast<DistinctNode*>(node)); break;
2445  case EQUAL_NODE: newNode = std::make_shared<EqualNode>(*reinterpret_cast<EqualNode*>(node)); break;
2446  case EXTRACT_NODE: newNode = std::make_shared<ExtractNode>(*reinterpret_cast<ExtractNode*>(node)); break;
2447  case IFF_NODE: newNode = std::make_shared<IffNode>(*reinterpret_cast<IffNode*>(node)); break;
2448  case INTEGER_NODE: newNode = std::make_shared<IntegerNode>(*reinterpret_cast<IntegerNode*>(node)); break;
2449  case ITE_NODE: newNode = std::make_shared<IteNode>(*reinterpret_cast<IteNode*>(node)); break;
2450  case LAND_NODE: newNode = std::make_shared<LandNode>(*reinterpret_cast<LandNode*>(node)); break;
2451  case LET_NODE: newNode = std::make_shared<LetNode>(*reinterpret_cast<LetNode*>(node)); break;
2452  case LNOT_NODE: newNode = std::make_shared<LnotNode>(*reinterpret_cast<LnotNode*>(node)); break;
2453  case LOR_NODE: newNode = std::make_shared<LorNode>(*reinterpret_cast<LorNode*>(node)); break;
2454  case REFERENCE_NODE: {
2455  if (unroll)
2456  return triton::ast::newInstance(reinterpret_cast<ReferenceNode*>(node)->getSymbolicExpression()->getAst().get(), unroll);
2457  else
2458  newNode = std::make_shared<ReferenceNode>(*reinterpret_cast<ReferenceNode*>(node));
2459  break;
2460  }
2461  case STRING_NODE: newNode = std::make_shared<StringNode>(*reinterpret_cast<StringNode*>(node)); break;
2462  case SX_NODE: newNode = std::make_shared<SxNode>(*reinterpret_cast<SxNode*>(node)); break;
2463  case VARIABLE_NODE: newNode = node->shared_from_this(); /* Do not duplicate shared var (see #792) */ break;
2464  case ZX_NODE: newNode = std::make_shared<ZxNode>(*reinterpret_cast<ZxNode*>(node)); break;
2465  default:
2466  throw triton::exceptions::Ast("triton::ast::newInstance(): Invalid type node.");
2467  }
2468 
2469  if (newNode == nullptr)
2470  throw triton::exceptions::Ast("triton::ast::newInstance(): No enough memory.");
2471 
2472  /* Remove parents as this is a new node which has no connections with original AST */
2473  if (node->getType() != VARIABLE_NODE) {
2474  /* VARIABLE_NODE are not duplicated (see #792), so don't remove their parents */
2475  auto parents = newNode->getParents();
2476  for (auto& p : parents) {
2477  newNode->removeParent(p.get());
2478  }
2479  }
2480 
2481  /* Create new instances of children and set their new parents */
2482  auto& children = newNode->getChildren();
2483  for (triton::usize idx = 0; idx < children.size(); idx++) {
2484  children[idx] = triton::ast::newInstance(children[idx].get(), unroll);
2485  children[idx]->setParent(newNode.get());
2486  }
2487 
2488  return newNode;
2489  }
2490 
2491 
2493  return triton::ast::newInstance(node.get(), true);
2494  }
2495 
2496 
2497  void nodesExtraction(std::deque<SharedAbstractNode>* output, const SharedAbstractNode& node, bool unroll, bool revert) {
2498  std::unordered_map<triton::usize, std::set<SharedAbstractNode>> sortedlist;
2499  std::deque<std::pair<SharedAbstractNode,triton::usize>> worklist;
2500  triton::usize depth = 0;
2501 
2502  if (node == nullptr)
2503  throw triton::exceptions::Ast("triton::ast::nodesExtraction(): Node cannot be null.");
2504 
2505  /*
2506  * We use a worklist strategy to avoid recursive calls
2507  * and so stack overflow when going through a big AST.
2508  */
2509  worklist.push_back({node, 0});
2510  while (worklist.empty() == false) {
2511  auto ast = worklist.front().first;
2512  auto lvl = worklist.front().second;
2513  worklist.pop_front();
2514 
2515  /* Keep up-to-date the depth of the tree */
2516  depth = std::max(depth, lvl);
2517 
2518  /* Proceed children */
2519  for (const auto& child : ast->getChildren()) {
2520  if (std::find(worklist.begin(), worklist.end(), std::make_pair(child, lvl + 1)) == worklist.end()) {
2521  worklist.push_back({child, lvl + 1});
2522  }
2523  }
2524 
2525  /* If unroll is true, we unroll all references */
2526  if (unroll == true && ast->getType() == REFERENCE_NODE) {
2527  const auto& ref = reinterpret_cast<ReferenceNode*>(ast.get())->getSymbolicExpression()->getAst();
2528  if (std::find(worklist.begin(), worklist.end(), std::make_pair(ref, lvl + 1)) == worklist.end()) {
2529  worklist.push_back({ref, lvl + 1});
2530  }
2531  }
2532 
2533  sortedlist[lvl].insert(ast);
2534  }
2535 
2536  /* Sort nodes into the output list */
2537  for (triton::usize index = 0; index <= depth; index++) {
2538  auto& nodes = revert ? sortedlist[depth - index] : sortedlist[index];
2539  for (auto&& n : nodes) {
2540  if (std::find(output->begin(), output->end(), n) == output->end()) {
2541  output->push_back(n);
2542  }
2543  }
2544  }
2545  }
2546 
2547 
2548  std::deque<SharedAbstractNode> lookingForNodes(const SharedAbstractNode& node, triton::ast::ast_e match) {
2549  std::stack<triton::ast::AbstractNode*> worklist;
2550  std::deque<triton::ast::SharedAbstractNode> result;
2551  std::set<const triton::ast::AbstractNode*> visited;
2552 
2553  worklist.push(node.get());
2554  while (!worklist.empty()) {
2555  auto current = worklist.top();
2556  worklist.pop();
2557 
2558  // This means that node is already in work_stack and we will not need to convert it second time
2559  if (visited.find(current) != visited.end()) {
2560  continue;
2561  }
2562 
2563  visited.insert(current);
2564  if (match == triton::ast::ANY_NODE || current->getType() == match)
2565  result.push_front(current->shared_from_this());
2566 
2567  if (current->getType() == REFERENCE_NODE) {
2568  worklist.push(reinterpret_cast<triton::ast::ReferenceNode *>(current)->getSymbolicExpression()->getAst().get());
2569  } else {
2570  for (const auto &child : current->getChildren())
2571  worklist.push(child.get());
2572  }
2573  }
2574 
2575  return result;
2576  }
2577 
2578  }; /* ast namespace */
2579 }; /* triton namespace */
std::shared_ptr< triton::ast::AstContext > SharedAstContext
Shared AST context.
Definition: ast.hpp:64
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:1305
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:1850
(= <expr1> <expr2> ...) node
Definition: ast.hpp:495
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:1993
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:1163
(bvsge <expr1> <expr2>) node
Definition: ast.hpp:295
(ite <ifExpr> <thenExpr> <elseExpr>)
Definition: ast.hpp:535
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:1247
triton::uint512 hash2n(triton::uint512 hash, triton::uint32 n)
Custom hash2n function for hash routine.
Definition: ast.cpp:2364
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:1469
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:2012
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:2182
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:1221
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:1130
TRITON_EXPORT bool equalTo(const SharedAbstractNode &) const
Returns true if the current tree is equal to the second one.
Definition: ast.cpp:106
bool logical
True if it&#39;s a logical node.
Definition: ast.hpp:89
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:1660
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:1595
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:2147
triton::uint512 eval
The value of the tree from this root node.
Definition: ast.hpp:83
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:985
(bvsmod <expr1> <expr2>) node
Definition: ast.hpp:340
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:602
TRITON_EXPORT triton::uint512 getBitvectorMask(void) const
Returns the vector mask according the size of the node.
Definition: ast.cpp:58
TRITON_EXPORT triton::ast::ast_e getType(void) const
Returns the type of the node.
Definition: ast.cpp:48
(let ((<alias> <expr2>)) <expr3>)
Definition: ast.hpp:559
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:2133
std::vector< SharedAbstractNode > children
The children of the node.
Definition: ast.hpp:73
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:1367
Abstract node.
Definition: ast.hpp:67
bool symbolized
True if the tree contains a symbolic variable.
Definition: ast.hpp:86
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:1014
TRITON_EXPORT AbstractNode(triton::ast::ast_e type, const SharedAstContext &ctxt)
Constructor.
Definition: ast.cpp:29
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:2248
std::ostream & operator<<(std::ostream &stream, AbstractNode *node)
Displays the node in ast representation.
Definition: ast.cpp:2350
virtual TRITON_EXPORT triton::uint512 evaluate(void) const
Evaluates the tree.
Definition: ast.cpp:113
TRITON_EXPORT triton::uint32 getBitvectorSize(void) const
Returns the size of the node.
Definition: ast.cpp:53
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:638
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:1061
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:1287
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:1531
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:945
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:1583
Integer node.
Definition: ast.hpp:522
The Triton namespace.
Definition: api.cpp:226
triton::sint512 modularSignExtend(AbstractNode *node)
Custom modular sign extend for bitwise operation.
Definition: ast.cpp:2379
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:1203
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:1614
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:678
String node.
Definition: ast.hpp:605
The exception class used by all AST nodes.
Definition: exceptions.hpp:341
Reference node.
Definition: ast.hpp:592
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:1491
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:2200
#define MAX_BITS_SUPPORTED
Definition: cpuSize.hpp:57
TRITON_EXPORT std::vector< SharedAbstractNode > getParents(void)
Returns the parents of node or an empty set if there is still no parent defined.
Definition: ast.cpp:129
std::deque< SharedAbstractNode > lookingForNodes(const SharedAbstractNode &node, triton::ast::ast_e match)
Returns a deque of collected matched nodes via a depth-first pre order traversal. ...
Definition: ast.cpp:2548
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:526
TRITON_EXPORT bool isSigned(void) const
According to the size of the expression, returns true if the MSB is 1.
Definition: ast.cpp:65
triton::uint512 rotl(triton::uint512 value, triton::uint32 shift)
Custom rotate left function for hash routine.
Definition: ast.cpp:2372
std::shared_ptr< triton::ast::AbstractNode > SharedAbstractNode
Shared Abstract Node.
Definition: ast.hpp:58
((_ extract <high> <low>) <expr>) node
Definition: ast.hpp:504
TRITON_EXPORT std::vector< SharedAbstractNode > & getChildren(void)
Returns the children of the node.
Definition: ast.cpp:124
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:2283
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:446
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:253
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:898
boost::multiprecision::int512_t sint512
signed 512-bits
Definition: tritonTypes.hpp:64
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:967
((_ rotate_right rot) <expr>) node
Definition: ast.hpp:276
(bvugt <expr1> <expr2>) node
Definition: ast.hpp:385
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:751
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:880
(bvsle <expr1> <expr2>) node
Definition: ast.hpp:322
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:1327
(bvuge <expr1> <expr2>) node
Definition: ast.hpp:376
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:406
(assert <expr>) node
Definition: ast.hpp:167
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:1079
(bvurem <expr1> <expr2>) node
Definition: ast.hpp:412
(bvlshr <expr1> <expr2>) node
Definition: ast.hpp:203
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:2092
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:1181
((_ zero_extend sizeExt) <expr>) node
Definition: ast.hpp:640
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:1878
(lnot <expr>)
Definition: ast.hpp:568
(and <expr1> <expr2>)
Definition: ast.hpp:544
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:619
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:1970
SharedAbstractNode unrollAst(const triton::ast::SharedAbstractNode &node)
AST C++ API - Unrolls the SSA form of a given AST.
Definition: ast.cpp:2492
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:1632
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:1032
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:580
TRITON_EXPORT SharedAstContext getContext(void) const
Access to its context.
Definition: ast.cpp:43
TRITON_EXPORT bool isSymbolized(void) const
Returns true if the tree contains a symbolic variable.
Definition: ast.cpp:72
TRITON_EXPORT std::string str(void) const
Returns the string representation of the node.
Definition: ast.cpp:214
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:486
(or <expr1> <expr2>)
Definition: ast.hpp:577
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:352
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:2166
(bvneg <expr>) node
Definition: ast.hpp:230
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:1345
(bvsrem <expr1> <expr2>) node
Definition: ast.hpp:349
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:1952
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:1895
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:1832
TRITON_EXPORT void removeParent(AbstractNode *p)
Removes a parent node.
Definition: ast.cpp:168
(bvslt <expr1> <expr2>) node
Definition: ast.hpp:331
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:1717
void nodesExtraction(std::deque< SharedAbstractNode > *output, const SharedAbstractNode &node, bool unroll, bool revert)
Returns all nodes of an AST. If unroll is true, references are unrolled. If revert is true...
Definition: ast.cpp:2497
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:1911
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:2034
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:1677
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:1699
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:2229
void initParents(void)
Initializes parents.
Definition: ast.cpp:118
(_ bv<value> <size>) node
Definition: ast.hpp:439
(iff <expr1> <expr2>)
Definition: ast.hpp:513
(bvashr <expr1> <expr2>) node
Definition: ast.hpp:194
TRITON_EXPORT void setChild(triton::uint32 index, const SharedAbstractNode &child)
Sets a child at an index.
Definition: ast.cpp:191
(bvor <expr1> <expr2>) node
Definition: ast.hpp:257
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:656
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:293
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:2074
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:464
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:1798
std::shared_ptr< triton::engines::symbolic::SymbolicExpression > SharedSymbolicExpression
Shared Symbolic Expression.
Definition: ast.hpp:39
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:1779
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:851
virtual TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const =0
Returns the has of the tree. The hash is computed recursively on the whole tree.
(bvmul <expr1> <expr2>) node
Definition: ast.hpp:212
(bvxor <expr1> <expr2>) node
Definition: ast.hpp:430
(bvule <expr1> <expr2>) node
Definition: ast.hpp:394
std::uint32_t uint32
unisgned 32-bits
Definition: tritonTypes.hpp:31
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:1509
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:729
(bvand <expr1> <expr2>) node
Definition: ast.hpp:185
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:1265
SharedAbstractNode newInstance(AbstractNode *node, bool unroll)
AST C++ API - Duplicates the AST.
Definition: ast.cpp:2403
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:1927
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:1549
(bvnand <expr1> <expr2>) node
Definition: ast.hpp:221
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:1451
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:780
((_ sign_extend sizeExt) <expr>) node
Definition: ast.hpp:618
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:311
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:2051
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:1757
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:424
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:1385
virtual TRITON_EXPORT ~AbstractNode()
Destructor.
Definition: ast.cpp:38
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:798
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:927
TRITON_EXPORT ZxNode(triton::uint32 sizeExt, const SharedAbstractNode &expr)
Create a zero extend of expr to sizeExt bits.
Definition: ast.cpp:2277
(bvsub <expr1> <expr2>) node
Definition: ast.hpp:358
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:2115
TRITON_EXPORT void addChild(const SharedAbstractNode &child)
Adds a child.
Definition: ast.cpp:186
(bvxnor <expr1> <expr2>) node
Definition: ast.hpp:421
[<expr1> <expr2> <expr3> ...] node
Definition: ast.hpp:448
std::shared_ptr< triton::engines::symbolic::SymbolicVariable > SharedSymbolicVariable
Shared Symbolic variable.
Definition: ast.hpp:42
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:700
(bvnor <expr1> <expr2>) node
Definition: ast.hpp:239
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:1739
TRITON_EXPORT void setParent(AbstractNode *p)
Sets a parent node.
Definition: ast.cpp:147
(bvult <expr1> <expr2>) node
Definition: ast.hpp:403
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:2312
(concat <expr1> <expr2> ...) node
Definition: ast.hpp:462
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:1425
TRITON_EXPORT void setBitvectorSize(triton::uint32 size)
Sets the size of the node.
Definition: ast.cpp:209
(bvudiv <expr1> <expr2>) node
Definition: ast.hpp:367
(bvadd <expr1> <expr2>) node
Definition: ast.hpp:176
(bvshl <expr1> <expr2>) node
Definition: ast.hpp:313
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:562
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:271
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:504
boost::multiprecision::uint512_t uint512
unsigned 512-bits
Definition: tritonTypes.hpp:43
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:333
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:231
std::size_t usize
unsigned MAX_INT 32 or 64 bits according to the CPU.
Definition: tritonTypes.hpp:67
(distinct <expr1> <expr2> ...) node
Definition: ast.hpp:486
triton::uint32 size
The size of the node.
Definition: ast.hpp:80
triton::ast::ast_e type
The type of the node.
Definition: ast.hpp:70
((_ rotate_left rot) <expr>) node
Definition: ast.hpp:266
TRITON_EXPORT void init(void)
Init stuffs like size and eval.
Definition: ast.cpp:543
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:1407
(bvsgt <expr1> <expr2>) node
Definition: ast.hpp:304
std::weak_ptr< triton::ast::AbstractNode > WeakAbstractNode
Weak Abstract Node.
Definition: ast.hpp:61
(bvsdiv <expr1> <expr2>) node
Definition: ast.hpp:286
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:1112
(declare-fun <var_name> () (_ BitVec <var_size>)) node
Definition: ast.hpp:477
TRITON_EXPORT bool isLogical(void) const
Returns true if it&#39;s a logical node.
Definition: ast.cpp:77
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:833
TRITON_EXPORT triton::uint512 hash(triton::uint32 deep) const
Returns the has of the tree. The hash is computed recursively on the whole tree.
Definition: ast.cpp:2263
(bvnot <expr>) node
Definition: ast.hpp:248
SharedAstContext ctxt
Contect use to create this node.
Definition: ast.hpp:92