libTriton  version 0.8 build 1436
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 <list>
11 #include <new>
12 #include <stack>
13 #include <unordered_map>
14 #include <unordered_set>
15 #include <utility>
16 
17 #include <triton/ast.hpp>
18 #include <triton/astContext.hpp>
20 #include <triton/exceptions.hpp>
23 
24 
25 
26 namespace triton {
27  namespace ast {
28 
29  /* ====== Abstract node */
30 
32  this->ctxt = ctxt;
33  this->eval = 0;
34  this->hash = 0;
35  this->logical = false;
36  this->level = 1;
37  this->size = 0;
38  this->symbolized = false;
39  this->type = type;
40  }
41 
42 
44  /* See #828: Release ownership before calling container destructor */
45  this->children.clear();
46  }
47 
48 
50  return this->ctxt;
51  }
52 
53 
55  return this->type;
56  }
57 
58 
60  return this->size;
61  }
62 
63 
65  triton::uint512 mask = -1;
66  mask = mask >> (512 - this->size);
67  return mask;
68  }
69 
70 
71  bool AbstractNode::isSigned(void) const {
72  if ((this->eval >> (this->size-1)) & 1)
73  return true;
74  return false;
75  }
76 
77 
78  bool AbstractNode::isSymbolized(void) const {
79  return this->symbolized;
80  }
81 
82 
83  bool AbstractNode::isLogical(void) const {
84  switch (this->type) {
85  case BVSGE_NODE:
86  case BVSGT_NODE:
87  case BVSLE_NODE:
88  case BVSLT_NODE:
89  case BVUGE_NODE:
90  case BVUGT_NODE:
91  case BVULE_NODE:
92  case BVULT_NODE:
93  case DISTINCT_NODE:
94  case EQUAL_NODE:
95  case IFF_NODE:
96  case LAND_NODE:
97  case LNOT_NODE:
98  case LOR_NODE:
99  case LXOR_NODE:
100  return true;
101 
102  case ITE_NODE:
103  case REFERENCE_NODE:
104  return this->logical;
105 
106  default:
107  break;
108  }
109 
110  return false;
111  }
112 
113 
115  return (this->evaluate() == other->evaluate()) &&
116  (this->getBitvectorSize() == other->getBitvectorSize()) &&
117  (this->isLogical() == other->isLogical());
118  }
119 
120 
122  return (this->hasSameConcreteValueAndTypeAs(other)) &&
123  (this->isSymbolized() == other->isSymbolized());
124  }
125 
126 
127  bool AbstractNode::equalTo(const SharedAbstractNode& other) const {
128  return (this->evaluate() == other->evaluate()) &&
129  (this->getBitvectorSize() == other->getBitvectorSize()) &&
130  (this->getHash() == other->getHash()) &&
131  (this->getLevel() == other->getLevel());
132  }
133 
134 
136  return this->eval;
137  }
138 
139 
141  return this->hash;
142  }
143 
144 
146  return this->level;
147  }
148 
149 
151  auto ancestors = parentsExtraction(this->shared_from_this(), false);
152  for (auto& sp : ancestors) {
153  sp->init();
154  }
155  }
156 
157 
158  std::vector<SharedAbstractNode>& AbstractNode::getChildren(void) {
159  return this->children;
160  }
161 
162 
163  std::vector<SharedAbstractNode> AbstractNode::getParents(void) {
164  std::vector<SharedAbstractNode> res;
165  std::vector<AbstractNode*> toRemove;
166 
167  for (auto& kv: parents) {
168  if (auto sp = kv.second.second.lock())
169  res.push_back(sp);
170  else
171  toRemove.push_back(kv.first);
172  }
173 
174  for(auto* an: toRemove)
175  parents.erase(an);
176 
177  return res;
178  }
179 
180 
182  auto it = parents.find(p);
183 
184  if (it == parents.end()) {
185  auto A = p->shared_from_this();
186  this->parents.insert(std::make_pair(p, std::make_pair(1, WeakAbstractNode(A))));
187  }
188  else {
189  if (it->second.second.expired()) {
190  parents.erase(it);
191  auto A = p->shared_from_this();
192  this->parents.insert(std::make_pair(p, std::make_pair(1, WeakAbstractNode(A))));
193  }
194  // Ptr already in, add it for the counter
195  else {
196  it->second.first += 1;
197  }
198  }
199  }
200 
201 
203  auto it = this->parents.find(p);
204 
205  if (it == parents.end())
206  return;
207 
208  it->second.first--;
209  if (it->second.first == 0)
210  this->parents.erase(it);
211  }
212 
213 
214  void AbstractNode::setParent(std::set<AbstractNode*>& p) {
215  for (auto ptr : p)
216  this->setParent(ptr);
217  }
218 
219 
221  this->children.push_back(child);
222  }
223 
224 
226  if (index >= this->children.size())
227  throw triton::exceptions::Ast("AbstractNode::setChild(): Invalid index.");
228 
229  if (child == nullptr)
230  throw triton::exceptions::Ast("AbstractNode::setChild(): child cannot be null.");
231 
232  if (this->children[index] != child) {
233  /* Remove the parent of the old child */
234  this->children[index]->removeParent(this);
235 
236  /* Setup the parent of the child */
237  child->setParent(this);
238 
239  /* Setup the child of the parent */
240  this->children[index] = child;
241 
242  /* Init parents */
243  child->initParents();
244  }
245  }
246 
247 
249  this->size = size;
250  }
251 
252 
253  std::string AbstractNode::str(void) const {
254  std::stringstream s;
255  s << this;
256  if (!s.str().empty())
257  return s.str();
258  return nullptr;
259  }
260 
261 
262  /* ====== assert */
263 
264 
265  AssertNode::AssertNode(const SharedAbstractNode& expr): AbstractNode(ASSERT_NODE, expr->getContext()) {
266  this->addChild(expr);
267  }
268 
269 
270  void AssertNode::init(bool withParents) {
271  if (this->children.size() < 1)
272  throw triton::exceptions::Ast("AssertNode::init(): Must take at least one child.");
273 
274  if (this->children[0]->isLogical() == false)
275  throw triton::exceptions::Ast("AssertNode::init(): Must take a logical node as argument.");
276 
277  /* Init attributes */
278  this->size = this->children[0]->getBitvectorSize();
279  this->eval = ((this->children[0]->evaluate()) & this->getBitvectorMask());
280  this->level = 1;
281  this->symbolized = false;
282 
283  /* Init children and spread information */
284  for (triton::uint32 index = 0; index < this->children.size(); index++) {
285  this->children[index]->setParent(this);
286  this->symbolized |= this->children[index]->isSymbolized();
287  this->level += this->children[index]->getLevel();
288  }
289 
290  /* Init parents if needed */
291  if (withParents) {
292  this->initParents();
293  }
294 
295  this->initHash();
296  }
297 
298 
299  void AssertNode::initHash(void) {
300  triton::uint512 s = this->children.size();
301 
302  this->hash = this->type;
303  if (s) this->hash = this->hash * s;
304  for (triton::uint32 index = 0; index < this->children.size(); index++) {
305  this->hash = this->hash * this->children[index]->getHash();
306  }
307 
308  this->hash = triton::ast::rotl(this->hash, this->level);
309  }
310 
311 
312  /* ====== bvadd */
313 
314 
315  BvaddNode::BvaddNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVADD_NODE, expr1->getContext()) {
316  this->addChild(expr1);
317  this->addChild(expr2);
318  }
319 
320 
321  void BvaddNode::init(bool withParents) {
322  if (this->children.size() < 2)
323  throw triton::exceptions::Ast("BvaddNode::init(): Must take at least two children.");
324 
325  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
326  throw triton::exceptions::Ast("BvaddNode::init(): Must take two nodes of same size.");
327 
328  /* Init attributes */
329  this->size = this->children[0]->getBitvectorSize();
330  this->eval = ((this->children[0]->evaluate() + this->children[1]->evaluate()) & this->getBitvectorMask());
331  this->level = 1;
332  this->symbolized = false;
333 
334  /* Init children and spread information */
335  for (triton::uint32 index = 0; index < this->children.size(); index++) {
336  this->children[index]->setParent(this);
337  this->symbolized |= this->children[index]->isSymbolized();
338  this->level += this->children[index]->getLevel();
339  }
340 
341  /* Init parents if needed */
342  if (withParents) {
343  this->initParents();
344  }
345 
346  this->initHash();
347  }
348 
349 
350  void BvaddNode::initHash(void) {
351  triton::uint512 s = this->children.size();
352 
353  this->hash = this->type;
354  if (s) this->hash = this->hash * s;
355  for (triton::uint32 index = 0; index < this->children.size(); index++) {
356  this->hash = this->hash * this->children[index]->getHash();
357  }
358 
359  this->hash = triton::ast::rotl(this->hash, this->level);
360  }
361 
362 
363  /* ====== bvand */
364 
365 
366  BvandNode::BvandNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVAND_NODE, expr1->getContext()) {
367  this->addChild(expr1);
368  this->addChild(expr2);
369  }
370 
371 
372  void BvandNode::init(bool withParents) {
373  if (this->children.size() < 2)
374  throw triton::exceptions::Ast("BvandNode::init(): Must take at least two children.");
375 
376  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
377  throw triton::exceptions::Ast("BvandNode::init(): Must take two nodes of same size.");
378 
379  /* Init attributes */
380  this->size = this->children[0]->getBitvectorSize();
381  this->eval = (this->children[0]->evaluate() & this->children[1]->evaluate());
382  this->level = 1;
383  this->symbolized = false;
384 
385  /* Init children and spread information */
386  for (triton::uint32 index = 0; index < this->children.size(); index++) {
387  this->children[index]->setParent(this);
388  this->symbolized |= this->children[index]->isSymbolized();
389  this->level += this->children[index]->getLevel();
390  }
391 
392  /* Init parents if needed */
393  if (withParents) {
394  this->initParents();
395  }
396 
397  this->initHash();
398  }
399 
400 
401  void BvandNode::initHash(void) {
402  triton::uint512 s = this->children.size();
403 
404  this->hash = this->type;
405  if (s) this->hash = this->hash * s;
406  for (triton::uint32 index = 0; index < this->children.size(); index++) {
407  this->hash = this->hash * this->children[index]->getHash();
408  }
409 
410  this->hash = triton::ast::rotl(this->hash, this->level);
411  }
412 
413 
414  /* ====== bvashr (shift with sign extension fill) */
415 
416 
417  BvashrNode::BvashrNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVASHR_NODE, expr1->getContext()) {
418  this->addChild(expr1);
419  this->addChild(expr2);
420  }
421 
422 
423  void BvashrNode::init(bool withParents) {
424  triton::uint32 shift = 0;
425  triton::uint512 mask = 0;
426  triton::uint512 value = 0;
427 
428  if (this->children.size() < 2)
429  throw triton::exceptions::Ast("BvashrNode::init(): Must take at least two children.");
430 
431  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
432  throw triton::exceptions::Ast("BvashrNode::init(): Must take two nodes of same size.");
433 
434  value = this->children[0]->evaluate();
435  shift = this->children[1]->evaluate().convert_to<triton::uint32>();
436 
437  /* Init attributes */
438  this->size = this->children[0]->getBitvectorSize();
439  this->level = 1;
440  this->symbolized = false;
441 
442  /* Mask based on the sign */
443  if (this->children[0]->isSigned()) {
444  mask = 1;
445  mask = ((mask << (this->size-1)) & this->getBitvectorMask());
446  }
447 
448  if (shift >= this->size && this->children[0]->isSigned()) {
449  this->eval = -1;
450  this->eval &= this->getBitvectorMask();
451  }
452 
453  else if (shift >= this->size && !this->children[0]->isSigned()) {
454  this->eval = 0;
455  }
456 
457  else if (shift == 0) {
458  this->eval = value;
459  }
460 
461  else {
462  this->eval = value & this->getBitvectorMask();
463  for (triton::uint32 index = 0; index < shift; index++) {
464  this->eval = (((this->eval >> 1) | mask) & this->getBitvectorMask());
465  }
466  }
467 
468  /* Init children and spread information */
469  for (triton::uint32 index = 0; index < this->children.size(); index++) {
470  this->children[index]->setParent(this);
471  this->symbolized |= this->children[index]->isSymbolized();
472  this->level += this->children[index]->getLevel();
473  }
474 
475  /* Init parents if needed */
476  if (withParents) {
477  this->initParents();
478  }
479 
480  this->initHash();
481  }
482 
483 
484  void BvashrNode::initHash(void) {
485  triton::uint512 s = this->children.size();
486 
487  this->hash = this->type;
488  if (s) this->hash = this->hash * s;
489  for (triton::uint32 index = 0; index < this->children.size(); index++) {
490  this->hash = this->hash * triton::ast::hash2n(this->children[index]->getHash(), index+1);
491  }
492 
493  this->hash = triton::ast::rotl(this->hash, this->level);
494  }
495 
496 
497  /* ====== bvlshr (shift with zero filled) */
498 
499 
500  BvlshrNode::BvlshrNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVLSHR_NODE, expr1->getContext()) {
501  this->addChild(expr1);
502  this->addChild(expr2);
503  }
504 
505 
506  void BvlshrNode::init(bool withParents) {
507  if (this->children.size() < 2)
508  throw triton::exceptions::Ast("BvlshrNode::init(): Must take at least two children.");
509 
510  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
511  throw triton::exceptions::Ast("BvlshrNode::init(): Must take two nodes of same size.");
512 
513  /* Init attributes */
514  this->size = this->children[0]->getBitvectorSize();
515  this->eval = (this->children[0]->evaluate() >> this->children[1]->evaluate().convert_to<triton::uint32>());
516  this->level = 1;
517  this->symbolized = false;
518 
519  /* Init children and spread information */
520  for (triton::uint32 index = 0; index < this->children.size(); index++) {
521  this->children[index]->setParent(this);
522  this->symbolized |= this->children[index]->isSymbolized();
523  this->level += this->children[index]->getLevel();
524  }
525 
526  /* Init parents if needed */
527  if (withParents) {
528  this->initParents();
529  }
530 
531  this->initHash();
532  }
533 
534 
535  void BvlshrNode::initHash(void) {
536  triton::uint512 s = this->children.size();
537 
538  this->hash = this->type;
539  if (s) this->hash = this->hash * s;
540  for (triton::uint32 index = 0; index < this->children.size(); index++) {
541  this->hash = this->hash * triton::ast::hash2n(this->children[index]->getHash(), index+1);
542  }
543 
544  this->hash = triton::ast::rotl(this->hash, this->level);
545  }
546 
547 
548  /* ====== bvmul */
549 
550 
551  BvmulNode::BvmulNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVMUL_NODE, expr1->getContext()) {
552  this->addChild(expr1);
553  this->addChild(expr2);
554  }
555 
556 
557  void BvmulNode::init(bool withParents) {
558  if (this->children.size() < 2)
559  throw triton::exceptions::Ast("BvmulNode::init(): Must take at least two children.");
560 
561  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
562  throw triton::exceptions::Ast("BvmulNode::init(): Must take two nodes of same size.");
563 
564  /* Init attributes */
565  this->size = this->children[0]->getBitvectorSize();
566  this->eval = ((this->children[0]->evaluate() * this->children[1]->evaluate()) & this->getBitvectorMask());
567  this->level = 1;
568  this->symbolized = false;
569 
570  /* Init children and spread information */
571  for (triton::uint32 index = 0; index < this->children.size(); index++) {
572  this->children[index]->setParent(this);
573  this->symbolized |= this->children[index]->isSymbolized();
574  this->level += this->children[index]->getLevel();
575  }
576 
577  /* Init parents if needed */
578  if (withParents) {
579  this->initParents();
580  }
581 
582  this->initHash();
583  }
584 
585 
586  void BvmulNode::initHash(void) {
587  triton::uint512 s = this->children.size();
588 
589  this->hash = this->type;
590  if (s) this->hash = this->hash * s;
591  for (triton::uint32 index = 0; index < this->children.size(); index++) {
592  this->hash = this->hash * this->children[index]->getHash();
593  }
594 
595  this->hash = triton::ast::rotl(this->hash, this->level);
596  }
597 
598 
599  /* ====== bvnand */
600 
601 
602  BvnandNode::BvnandNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVNAND_NODE, expr1->getContext()) {
603  this->addChild(expr1);
604  this->addChild(expr2);
605  }
606 
607 
608  void BvnandNode::init(bool withParents) {
609  if (this->children.size() < 2)
610  throw triton::exceptions::Ast("BvnandNode::init(): Must take at least two children.");
611 
612  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
613  throw triton::exceptions::Ast("BvnandNode::init(): Must take two nodes of same size.");
614 
615  /* Init attributes */
616  this->size = this->children[0]->getBitvectorSize();
617  this->eval = (~(this->children[0]->evaluate() & this->children[1]->evaluate()) & this->getBitvectorMask());
618  this->level = 1;
619  this->symbolized = false;
620 
621  /* Init children and spread information */
622  for (triton::uint32 index = 0; index < this->children.size(); index++) {
623  this->children[index]->setParent(this);
624  this->symbolized |= this->children[index]->isSymbolized();
625  this->level += this->children[index]->getLevel();
626  }
627 
628  /* Init parents if needed */
629  if (withParents) {
630  this->initParents();
631  }
632 
633  this->initHash();
634  }
635 
636 
637  void BvnandNode::initHash(void) {
638  triton::uint512 s = this->children.size();
639 
640  this->hash = this->type;
641  if (s) this->hash = this->hash * s;
642  for (triton::uint32 index = 0; index < this->children.size(); index++) {
643  this->hash = this->hash * this->children[index]->getHash();
644  }
645 
646  this->hash = triton::ast::rotl(this->hash, this->level);
647  }
648 
649 
650  /* ====== bvneg */
651 
652 
653  BvnegNode::BvnegNode(const SharedAbstractNode& expr): AbstractNode(BVNEG_NODE, expr->getContext()) {
654  this->addChild(expr);
655  }
656 
657 
658  void BvnegNode::init(bool withParents) {
659  if (this->children.size() < 1)
660  throw triton::exceptions::Ast("BvnegNode::init(): Must take at least one child.");
661 
662  /* Init attributes */
663  this->size = this->children[0]->getBitvectorSize();
664  this->eval = ((-(this->children[0]->evaluate().convert_to<triton::sint512>())).convert_to<triton::uint512>() & this->getBitvectorMask());
665  this->level = 1;
666  this->symbolized = false;
667 
668  /* Init children and spread information */
669  for (triton::uint32 index = 0; index < this->children.size(); index++) {
670  this->children[index]->setParent(this);
671  this->symbolized |= this->children[index]->isSymbolized();
672  this->level += this->children[index]->getLevel();
673  }
674 
675  /* Init parents if needed */
676  if (withParents) {
677  this->initParents();
678  }
679 
680  this->initHash();
681  }
682 
683 
684  void BvnegNode::initHash(void) {
685  triton::uint512 s = this->children.size();
686 
687  this->hash = this->type;
688  if (s) this->hash = this->hash * s;
689  for (triton::uint32 index = 0; index < this->children.size(); index++) {
690  this->hash = this->hash * this->children[index]->getHash();
691  }
692 
693  this->hash = triton::ast::rotl(this->hash, this->level);
694  }
695 
696 
697  /* ====== bvnor */
698 
699 
700  BvnorNode::BvnorNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVNOR_NODE, expr1->getContext()) {
701  this->addChild(expr1);
702  this->addChild(expr2);
703  }
704 
705 
706  void BvnorNode::init(bool withParents) {
707  if (this->children.size() < 2)
708  throw triton::exceptions::Ast("BvnorNode::init(): Must take at least two children.");
709 
710  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
711  throw triton::exceptions::Ast("BvnorNode::init(): Must take two nodes of same size.");
712 
713  /* Init attributes */
714  this->size = this->children[0]->getBitvectorSize();
715  this->eval = (~(this->children[0]->evaluate() | this->children[1]->evaluate()) & this->getBitvectorMask());
716  this->level = 1;
717  this->symbolized = false;
718 
719  /* Init children and spread information */
720  for (triton::uint32 index = 0; index < this->children.size(); index++) {
721  this->children[index]->setParent(this);
722  this->symbolized |= this->children[index]->isSymbolized();
723  this->level += this->children[index]->getLevel();
724  }
725 
726  /* Init parents if needed */
727  if (withParents) {
728  this->initParents();
729  }
730 
731  this->initHash();
732  }
733 
734 
735  void BvnorNode::initHash(void) {
736  triton::uint512 s = this->children.size();
737 
738  this->hash = this->type;
739  if (s) this->hash = this->hash * s;
740  for (triton::uint32 index = 0; index < this->children.size(); index++) {
741  this->hash = this->hash * this->children[index]->getHash();
742  }
743 
744  this->hash = triton::ast::rotl(this->hash, this->level);
745  }
746 
747 
748  /* ====== bvnot */
749 
750 
751  BvnotNode::BvnotNode(const SharedAbstractNode& expr): AbstractNode(BVNOT_NODE, expr->getContext()) {
752  this->addChild(expr);
753  }
754 
755 
756  void BvnotNode::init(bool withParents) {
757  if (this->children.size() < 1)
758  throw triton::exceptions::Ast("BvnotNode::init(): Must take at least one child.");
759 
760  /* Init attributes */
761  this->size = this->children[0]->getBitvectorSize();
762  this->eval = (~this->children[0]->evaluate() & this->getBitvectorMask());
763  this->level = 1;
764  this->symbolized = false;
765 
766  /* Init children and spread information */
767  for (triton::uint32 index = 0; index < this->children.size(); index++) {
768  this->children[index]->setParent(this);
769  this->symbolized |= this->children[index]->isSymbolized();
770  this->level += this->children[index]->getLevel();
771  }
772 
773  /* Init parents if needed */
774  if (withParents) {
775  this->initParents();
776  }
777 
778  this->initHash();
779  }
780 
781 
782  void BvnotNode::initHash(void) {
783  triton::uint512 s = this->children.size();
784 
785  this->hash = this->type;
786  if (s) this->hash = this->hash * s;
787  for (triton::uint32 index = 0; index < this->children.size(); index++) {
788  this->hash = this->hash * this->children[index]->getHash();
789  }
790 
791  this->hash = triton::ast::rotl(this->hash, this->level);
792  }
793 
794 
795  /* ====== bvor */
796 
797 
798  BvorNode::BvorNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVOR_NODE, expr1->getContext()) {
799  this->addChild(expr1);
800  this->addChild(expr2);
801  }
802 
803 
804  void BvorNode::init(bool withParents) {
805  if (this->children.size() < 2)
806  throw triton::exceptions::Ast("BvorNode::init(): Must take at least two children.");
807 
808  if (this->children[0]->getBitvectorSize() != this->children[0]->getBitvectorSize())
809  throw triton::exceptions::Ast("BvorNode::init(): Must take two nodes of same size.");
810 
811  /* Init attributes */
812  this->size = this->children[0]->getBitvectorSize();
813  this->eval = (this->children[0]->evaluate() | this->children[1]->evaluate());
814  this->level = 1;
815  this->symbolized = false;
816 
817  /* Init children and spread information */
818  for (triton::uint32 index = 0; index < this->children.size(); index++) {
819  this->children[index]->setParent(this);
820  this->symbolized |= this->children[index]->isSymbolized();
821  this->level += this->children[index]->getLevel();
822  }
823 
824  /* Init parents if needed */
825  if (withParents) {
826  this->initParents();
827  }
828 
829  this->initHash();
830  }
831 
832 
833  void BvorNode::initHash(void) {
834  triton::uint512 s = this->children.size();
835 
836  this->hash = this->type;
837  if (s) this->hash = this->hash * s;
838  for (triton::uint32 index = 0; index < this->children.size(); index++) {
839  this->hash = this->hash * this->children[index]->getHash();
840  }
841 
842  this->hash = triton::ast::rotl(this->hash, this->level);
843  }
844 
845 
846  /* ====== bvrol */
847 
848 
849  BvrolNode::BvrolNode(const SharedAbstractNode& expr, triton::uint32 rot): BvrolNode(expr, expr->getContext()->integer(rot)) {
850  }
851 
852 
853  BvrolNode::BvrolNode(const SharedAbstractNode& expr, const SharedAbstractNode& rot): AbstractNode(BVROL_NODE, expr->getContext()) {
854  this->addChild(expr);
855  this->addChild(rot);
856  }
857 
858 
859  void BvrolNode::init(bool withParents) {
860  triton::uint32 rot = 0;
861  triton::uint512 value = 0;
862 
863  if (this->children.size() < 2)
864  throw triton::exceptions::Ast("BvrolNode::init(): Must take at least two children.");
865 
866  if (this->children[1]->getType() != INTEGER_NODE)
867  throw triton::exceptions::Ast("BvrolNode::init(): rot must be a INTEGER_NODE.");
868 
869  rot = reinterpret_cast<IntegerNode*>(this->children[1].get())->getInteger().convert_to<triton::uint32>();
870  value = this->children[0]->evaluate();
871 
872  /* Init attributes */
873  this->size = this->children[0]->getBitvectorSize();
874  rot %= this->size;
875  this->eval = (((value << rot) | (value >> (this->size - rot))) & this->getBitvectorMask());
876  this->level = 1;
877  this->symbolized = false;
878 
879  /* Init children and spread information */
880  for (triton::uint32 index = 0; index < this->children.size(); index++) {
881  this->children[index]->setParent(this);
882  this->symbolized |= this->children[index]->isSymbolized();
883  this->level += this->children[index]->getLevel();
884  }
885 
886  /* Init parents if needed */
887  if (withParents) {
888  this->initParents();
889  }
890 
891  this->initHash();
892  }
893 
894 
895  void BvrolNode::initHash(void) {
896  triton::uint512 s = this->children.size();
897 
898  this->hash = this->type;
899  if (s) this->hash = this->hash * s;
900  for (triton::uint32 index = 0; index < this->children.size(); index++) {
901  this->hash = this->hash * triton::ast::hash2n(this->children[index]->getHash(), index+1);
902  }
903 
904  this->hash = triton::ast::rotl(this->hash, this->level);
905  }
906 
907 
908  /* ====== bvror */
909 
910 
911  BvrorNode::BvrorNode(const SharedAbstractNode& expr, triton::uint32 rot): BvrorNode(expr, expr->getContext()->integer(rot)) {
912  }
913 
914 
915  BvrorNode::BvrorNode(const SharedAbstractNode& expr, const SharedAbstractNode& rot): AbstractNode(BVROR_NODE, expr->getContext()) {
916  this->addChild(expr);
917  this->addChild(rot);
918  }
919 
920 
921  void BvrorNode::init(bool withParents) {
922  triton::uint32 rot = 0;
923  triton::uint512 value = 0;
924 
925  if (this->children.size() < 2)
926  throw triton::exceptions::Ast("BvrorNode::init(): Must take at least two children.");
927 
928  if (this->children[1]->getType() != INTEGER_NODE)
929  throw triton::exceptions::Ast("BvrorNode::init(): rot must be a INTEGER_NODE.");
930 
931  rot = reinterpret_cast<IntegerNode*>(this->children[1].get())->getInteger().convert_to<triton::uint32>();
932  value = this->children[0]->evaluate();
933 
934  /* Init attributes */
935  this->size = this->children[0]->getBitvectorSize();
936  rot %= this->size;
937  this->eval = (((value >> rot) | (value << (this->size - rot))) & this->getBitvectorMask());
938  this->level = 1;
939  this->symbolized = false;
940 
941  /* Init children and spread information */
942  for (triton::uint32 index = 0; index < this->children.size(); index++) {
943  this->children[index]->setParent(this);
944  this->symbolized |= this->children[index]->isSymbolized();
945  this->level += this->children[index]->getLevel();
946  }
947 
948  /* Init parents if needed */
949  if (withParents) {
950  this->initParents();
951  }
952 
953  this->initHash();
954  }
955 
956 
957  void BvrorNode::initHash(void) {
958  triton::uint512 s = this->children.size();
959 
960  this->hash = this->type;
961  if (s) this->hash = this->hash * s;
962  for (triton::uint32 index = 0; index < this->children.size(); index++) {
963  this->hash = this->hash * triton::ast::hash2n(this->children[index]->getHash(), index+1);
964  }
965 
966  this->hash = triton::ast::rotl(this->hash, this->level);
967  }
968 
969 
970  /* ====== bvsdiv */
971 
972 
973  BvsdivNode::BvsdivNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVSDIV_NODE, expr1->getContext()) {
974  this->addChild(expr1);
975  this->addChild(expr2);
976  }
977 
978 
979  void BvsdivNode::init(bool withParents) {
980  triton::sint512 op1Signed = 0;
981  triton::sint512 op2Signed = 0;
982 
983  if (this->children.size() < 2)
984  throw triton::exceptions::Ast("BvsdivNode::init(): Must take at least two children.");
985 
986  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
987  throw triton::exceptions::Ast("BvsdivNode::init(): Must take two nodes of same size.");
988 
989  /* Sign extend */
990  op1Signed = triton::ast::modularSignExtend(this->children[0].get());
991  op2Signed = triton::ast::modularSignExtend(this->children[1].get());
992 
993  /* Init attributes */
994  this->size = this->children[0]->getBitvectorSize();
995  this->level = 1;
996  this->symbolized = false;
997 
998  if (op2Signed == 0) {
999  this->eval = (op1Signed < 0 ? 1 : -1);
1000  this->eval &= this->getBitvectorMask();
1001  }
1002  else
1003  this->eval = ((op1Signed / op2Signed).convert_to<triton::uint512>() & this->getBitvectorMask());
1004 
1005  /* Init children and spread information */
1006  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1007  this->children[index]->setParent(this);
1008  this->symbolized |= this->children[index]->isSymbolized();
1009  this->level += this->children[index]->getLevel();
1010  }
1011 
1012  /* Init parents if needed */
1013  if (withParents) {
1014  this->initParents();
1015  }
1016 
1017  this->initHash();
1018  }
1019 
1020 
1021  void BvsdivNode::initHash(void) {
1022  triton::uint512 s = this->children.size();
1023 
1024  this->hash = this->type;
1025  if (s) this->hash = this->hash * s;
1026  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1027  this->hash = this->hash * triton::ast::hash2n(this->children[index]->getHash(), index+1);
1028  }
1029 
1030  this->hash = triton::ast::rotl(this->hash, this->level);
1031  }
1032 
1033 
1034  /* ====== bvsge */
1035 
1036 
1037  BvsgeNode::BvsgeNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVSGE_NODE, expr1->getContext()) {
1038  this->addChild(expr1);
1039  this->addChild(expr2);
1040  }
1041 
1042 
1043  void BvsgeNode::init(bool withParents) {
1044  triton::sint512 op1Signed = 0;
1045  triton::sint512 op2Signed = 0;
1046 
1047  if (this->children.size() < 2)
1048  throw triton::exceptions::Ast("BvsgeNode::init(): Must take at least two children.");
1049 
1050  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
1051  throw triton::exceptions::Ast("BvsgeNode::init(): Must take two nodes of same size.");
1052 
1053  /* Sign extend */
1054  op1Signed = triton::ast::modularSignExtend(this->children[0].get());
1055  op2Signed = triton::ast::modularSignExtend(this->children[1].get());
1056 
1057  /* Init attributes */
1058  this->size = 1;
1059  this->eval = (op1Signed >= op2Signed);
1060  this->level = 1;
1061  this->symbolized = false;
1062 
1063  /* Init children and spread information */
1064  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1065  this->children[index]->setParent(this);
1066  this->symbolized |= this->children[index]->isSymbolized();
1067  this->level += this->children[index]->getLevel();
1068  }
1069 
1070  /* Init parents if needed */
1071  if (withParents) {
1072  this->initParents();
1073  }
1074 
1075  this->initHash();
1076  }
1077 
1078 
1079  void BvsgeNode::initHash(void) {
1080  triton::uint512 s = this->children.size();
1081 
1082  this->hash = this->type;
1083  if (s) this->hash = this->hash * s;
1084  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1085  this->hash = this->hash * triton::ast::hash2n(this->children[index]->getHash(), index+1);
1086  }
1087 
1088  this->hash = triton::ast::rotl(this->hash, this->level);
1089  }
1090 
1091 
1092  /* ====== bvsgt */
1093 
1094 
1095  BvsgtNode::BvsgtNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVSGT_NODE, expr1->getContext()) {
1096  this->addChild(expr1);
1097  this->addChild(expr2);
1098  }
1099 
1100 
1101  void BvsgtNode::init(bool withParents) {
1102  triton::sint512 op1Signed = 0;
1103  triton::sint512 op2Signed = 0;
1104 
1105  if (this->children.size() < 2)
1106  throw triton::exceptions::Ast("BvsgtNode::init(): Must take at least two children.");
1107 
1108  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
1109  throw triton::exceptions::Ast("BvsgtNode::init(): Must take two nodes of same size.");
1110 
1111  /* Sign extend */
1112  op1Signed = triton::ast::modularSignExtend(this->children[0].get());
1113  op2Signed = triton::ast::modularSignExtend(this->children[1].get());
1114 
1115  /* Init attributes */
1116  this->size = 1;
1117  this->eval = (op1Signed > op2Signed);
1118  this->level = 1;
1119  this->symbolized = false;
1120 
1121  /* Init children and spread information */
1122  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1123  this->children[index]->setParent(this);
1124  this->symbolized |= this->children[index]->isSymbolized();
1125  this->level += this->children[index]->getLevel();
1126  }
1127 
1128  /* Init parents if needed */
1129  if (withParents) {
1130  this->initParents();
1131  }
1132 
1133  this->initHash();
1134  }
1135 
1136 
1137  void BvsgtNode::initHash(void) {
1138  triton::uint512 s = this->children.size();
1139 
1140  this->hash = this->type;
1141  if (s) this->hash = this->hash * s;
1142  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1143  this->hash = this->hash * triton::ast::hash2n(this->children[index]->getHash(), index+1);
1144  }
1145 
1146  this->hash = triton::ast::rotl(this->hash, this->level);
1147  }
1148 
1149 
1150  /* ====== bvshl */
1151 
1152 
1153  BvshlNode::BvshlNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVSHL_NODE, expr1->getContext()) {
1154  this->addChild(expr1);
1155  this->addChild(expr2);
1156  }
1157 
1158 
1159  void BvshlNode::init(bool withParents) {
1160  if (this->children.size() < 2)
1161  throw triton::exceptions::Ast("BvshlNode::init(): Must take at least two children.");
1162 
1163  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
1164  throw triton::exceptions::Ast("BvshlNode::init(): Must take two nodes of same size.");
1165 
1166  /* Init attributes */
1167  this->size = this->children[0]->getBitvectorSize();
1168  this->eval = ((this->children[0]->evaluate() << this->children[1]->evaluate().convert_to<triton::uint32>()) & this->getBitvectorMask());
1169  this->level = 1;
1170  this->symbolized = false;
1171 
1172  /* Init children and spread information */
1173  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1174  this->children[index]->setParent(this);
1175  this->symbolized |= this->children[index]->isSymbolized();
1176  this->level += this->children[index]->getLevel();
1177  }
1178 
1179  /* Init parents if needed */
1180  if (withParents) {
1181  this->initParents();
1182  }
1183 
1184  this->initHash();
1185  }
1186 
1187 
1188  void BvshlNode::initHash(void) {
1189  triton::uint512 s = this->children.size();
1190 
1191  this->hash = this->type;
1192  if (s) this->hash = this->hash * s;
1193  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1194  this->hash = this->hash * triton::ast::hash2n(this->children[index]->getHash(), index+1);
1195  }
1196 
1197  this->hash = triton::ast::rotl(this->hash, this->level);
1198  }
1199 
1200 
1201  /* ====== bvsle */
1202 
1203 
1204  BvsleNode::BvsleNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVSLE_NODE, expr1->getContext()) {
1205  this->addChild(expr1);
1206  this->addChild(expr2);
1207  }
1208 
1209 
1210  void BvsleNode::init(bool withParents) {
1211  triton::sint512 op1Signed = 0;
1212  triton::sint512 op2Signed = 0;
1213 
1214  if (this->children.size() < 2)
1215  throw triton::exceptions::Ast("BvsleNode::init(): Must take at least two children.");
1216 
1217  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
1218  throw triton::exceptions::Ast("BvsleNode::init(): Must take two nodes of same size.");
1219 
1220  /* Sign extend */
1221  op1Signed = triton::ast::modularSignExtend(this->children[0].get());
1222  op2Signed = triton::ast::modularSignExtend(this->children[1].get());
1223 
1224  /* Init attributes */
1225  this->size = 1;
1226  this->eval = (op1Signed <= op2Signed);
1227  this->level = 1;
1228  this->symbolized = false;
1229 
1230  /* Init children and spread information */
1231  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1232  this->children[index]->setParent(this);
1233  this->symbolized |= this->children[index]->isSymbolized();
1234  this->level += this->children[index]->getLevel();
1235  }
1236 
1237  /* Init parents if needed */
1238  if (withParents) {
1239  this->initParents();
1240  }
1241 
1242  this->initHash();
1243  }
1244 
1245 
1246  void BvsleNode::initHash(void) {
1247  triton::uint512 s = this->children.size();
1248 
1249  this->hash = this->type;
1250  if (s) this->hash = this->hash * s;
1251  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1252  this->hash = this->hash * triton::ast::hash2n(this->children[index]->getHash(), index+1);
1253  }
1254 
1255  this->hash = triton::ast::rotl(this->hash, this->level);
1256  }
1257 
1258 
1259  /* ====== bvslt */
1260 
1261 
1262  BvsltNode::BvsltNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVSLT_NODE, expr1->getContext()) {
1263  this->addChild(expr1);
1264  this->addChild(expr2);
1265  }
1266 
1267 
1268  void BvsltNode::init(bool withParents) {
1269  triton::sint512 op1Signed = 0;
1270  triton::sint512 op2Signed = 0;
1271 
1272  if (this->children.size() < 2)
1273  throw triton::exceptions::Ast("BvsltNode::init(): Must take at least two children.");
1274 
1275  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
1276  throw triton::exceptions::Ast("BvsltNode::init(): Must take two nodes of same size.");
1277 
1278  /* Sign extend */
1279  op1Signed = triton::ast::modularSignExtend(this->children[0].get());
1280  op2Signed = triton::ast::modularSignExtend(this->children[1].get());
1281 
1282  /* Init attributes */
1283  this->size = 1;
1284  this->eval = (op1Signed < op2Signed);
1285  this->level = 1;
1286  this->symbolized = false;
1287 
1288  /* Init children and spread information */
1289  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1290  this->children[index]->setParent(this);
1291  this->symbolized |= this->children[index]->isSymbolized();
1292  this->level += this->children[index]->getLevel();
1293  }
1294 
1295  /* Init parents if needed */
1296  if (withParents) {
1297  this->initParents();
1298  }
1299 
1300  this->initHash();
1301  }
1302 
1303 
1304  void BvsltNode::initHash(void) {
1305  triton::uint512 s = this->children.size();
1306 
1307  this->hash = this->type;
1308  if (s) this->hash = this->hash * s;
1309  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1310  this->hash = this->hash * triton::ast::hash2n(this->children[index]->getHash(), index+1);
1311  }
1312 
1313  this->hash = triton::ast::rotl(this->hash, this->level);
1314  }
1315 
1316 
1317  /* ====== bvsmod - 2's complement signed remainder (sign follows divisor) */
1318 
1319 
1320  BvsmodNode::BvsmodNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVSMOD_NODE, expr1->getContext()) {
1321  this->addChild(expr1);
1322  this->addChild(expr2);
1323  }
1324 
1325 
1326  void BvsmodNode::init(bool withParents) {
1327  triton::sint512 op1Signed = 0;
1328  triton::sint512 op2Signed = 0;
1329 
1330  if (this->children.size() < 2)
1331  throw triton::exceptions::Ast("BvsmodNode::init(): Must take at least two children.");
1332 
1333  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
1334  throw triton::exceptions::Ast("BvsmodNode::init(): Must take two nodes of same size.");
1335 
1336  /* Sign extend */
1337  op1Signed = triton::ast::modularSignExtend(this->children[0].get());
1338  op2Signed = triton::ast::modularSignExtend(this->children[1].get());
1339 
1340  /* Init attributes */
1341  this->size = this->children[0]->getBitvectorSize();
1342  this->level = 1;
1343  this->symbolized = false;
1344 
1345  if (this->children[1]->evaluate() == 0)
1346  this->eval = this->children[0]->evaluate();
1347  else
1348  this->eval = ((((op1Signed % op2Signed) + op2Signed) % op2Signed).convert_to<triton::uint512>() & this->getBitvectorMask());
1349 
1350  /* Init children and spread information */
1351  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1352  this->children[index]->setParent(this);
1353  this->symbolized |= this->children[index]->isSymbolized();
1354  this->level += this->children[index]->getLevel();
1355  }
1356 
1357  /* Init parents if needed */
1358  if (withParents) {
1359  this->initParents();
1360  }
1361 
1362  this->initHash();
1363  }
1364 
1365 
1366  void BvsmodNode::initHash(void) {
1367  triton::uint512 s = this->children.size();
1368 
1369  this->hash = this->type;
1370  if (s) this->hash = this->hash * s;
1371  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1372  this->hash = this->hash * triton::ast::hash2n(this->children[index]->getHash(), index+1);
1373  }
1374 
1375  this->hash = triton::ast::rotl(this->hash, this->level);
1376  }
1377 
1378 
1379  /* ====== bvsrem - 2's complement signed remainder (sign follows dividend) */
1380 
1381 
1382  BvsremNode::BvsremNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVSREM_NODE, expr1->getContext()) {
1383  this->addChild(expr1);
1384  this->addChild(expr2);
1385  }
1386 
1387 
1388  void BvsremNode::init(bool withParents) {
1389  triton::sint512 op1Signed = 0;
1390  triton::sint512 op2Signed = 0;
1391 
1392  if (this->children.size() < 2)
1393  throw triton::exceptions::Ast("BvsremNode::init(): Must take at least two children.");
1394 
1395  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
1396  throw triton::exceptions::Ast("BvsremNode::init(): Must take two nodes of same size.");
1397 
1398  /* Sign extend */
1399  op1Signed = triton::ast::modularSignExtend(this->children[0].get());
1400  op2Signed = triton::ast::modularSignExtend(this->children[1].get());
1401 
1402  /* Init attributes */
1403  this->size = this->children[0]->getBitvectorSize();
1404  this->level = 1;
1405  this->symbolized = false;
1406 
1407  if (this->children[1]->evaluate() == 0)
1408  this->eval = this->children[0]->evaluate();
1409  else
1410  this->eval = ((op1Signed - ((op1Signed / op2Signed) * op2Signed)).convert_to<triton::uint512>() & this->getBitvectorMask());
1411 
1412  /* Init children and spread information */
1413  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1414  this->children[index]->setParent(this);
1415  this->symbolized |= this->children[index]->isSymbolized();
1416  this->level += this->children[index]->getLevel();
1417  }
1418 
1419  /* Init parents if needed */
1420  if (withParents) {
1421  this->initParents();
1422  }
1423 
1424  this->initHash();
1425  }
1426 
1427 
1428  void BvsremNode::initHash(void) {
1429  triton::uint512 s = this->children.size();
1430 
1431  this->hash = this->type;
1432  if (s) this->hash = this->hash * s;
1433  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1434  this->hash = this->hash * triton::ast::hash2n(this->children[index]->getHash(), index+1);
1435  }
1436 
1437  this->hash = triton::ast::rotl(this->hash, this->level);
1438  }
1439 
1440 
1441  /* ====== bvsub */
1442 
1443 
1444  BvsubNode::BvsubNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVSUB_NODE, expr1->getContext()) {
1445  this->addChild(expr1);
1446  this->addChild(expr2);
1447  }
1448 
1449 
1450  void BvsubNode::init(bool withParents) {
1451  if (this->children.size() < 2)
1452  throw triton::exceptions::Ast("BvsubNode::init(): Must take at least two children.");
1453 
1454  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
1455  throw triton::exceptions::Ast("BvsubNode::init(): Must take two nodes of same size.");
1456 
1457  /* Init attributes */
1458  this->size = this->children[0]->getBitvectorSize();
1459  this->eval = ((this->children[0]->evaluate() - this->children[1]->evaluate()) & this->getBitvectorMask());
1460  this->level = 1;
1461  this->symbolized = false;
1462 
1463  /* Init children and spread information */
1464  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1465  this->children[index]->setParent(this);
1466  this->symbolized |= this->children[index]->isSymbolized();
1467  this->level += this->children[index]->getLevel();
1468  }
1469 
1470  /* Init parents if needed */
1471  if (withParents) {
1472  this->initParents();
1473  }
1474 
1475  this->initHash();
1476  }
1477 
1478 
1479  void BvsubNode::initHash(void) {
1480  triton::uint512 s = this->children.size();
1481 
1482  this->hash = this->type;
1483  if (s) this->hash = this->hash * s;
1484  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1485  this->hash = this->hash * triton::ast::hash2n(this->children[index]->getHash(), index+1);
1486  }
1487 
1488  this->hash = triton::ast::rotl(this->hash, this->level);
1489  }
1490 
1491 
1492  /* ====== bvudiv */
1493 
1494 
1495  BvudivNode::BvudivNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVUDIV_NODE, expr1->getContext()) {
1496  this->addChild(expr1);
1497  this->addChild(expr2);
1498  }
1499 
1500 
1501  void BvudivNode::init(bool withParents) {
1502  if (this->children.size() < 2)
1503  throw triton::exceptions::Ast("BvudivNode::init(): Must take at least two children.");
1504 
1505  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
1506  throw triton::exceptions::Ast("BvudivNode::init(): Must take two nodes of same size.");
1507 
1508  /* Init attributes */
1509  this->size = this->children[0]->getBitvectorSize();
1510  this->level = 1;
1511  this->symbolized = false;
1512 
1513  if (this->children[1]->evaluate() == 0)
1514  this->eval = (-1 & this->getBitvectorMask());
1515  else
1516  this->eval = (this->children[0]->evaluate() / this->children[1]->evaluate());
1517 
1518  /* Init children and spread information */
1519  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1520  this->children[index]->setParent(this);
1521  this->symbolized |= this->children[index]->isSymbolized();
1522  this->level += this->children[index]->getLevel();
1523  }
1524 
1525  /* Init parents if needed */
1526  if (withParents) {
1527  this->initParents();
1528  }
1529 
1530  this->initHash();
1531  }
1532 
1533 
1534  void BvudivNode::initHash(void) {
1535  triton::uint512 s = this->children.size();
1536 
1537  this->hash = this->type;
1538  if (s) this->hash = this->hash * s;
1539  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1540  this->hash = this->hash * triton::ast::hash2n(this->children[index]->getHash(), index+1);
1541  }
1542 
1543  this->hash = triton::ast::rotl(this->hash, this->level);
1544  }
1545 
1546 
1547  /* ====== bvuge */
1548 
1549 
1550  BvugeNode::BvugeNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVUGE_NODE, expr1->getContext()) {
1551  this->addChild(expr1);
1552  this->addChild(expr2);
1553  }
1554 
1555 
1556  void BvugeNode::init(bool withParents) {
1557  if (this->children.size() < 2)
1558  throw triton::exceptions::Ast("BvugeNode::init(): Must take at least two children.");
1559 
1560  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
1561  throw triton::exceptions::Ast("BvugeNode::init(): Must take two nodes of same size.");
1562 
1563  /* Init attributes */
1564  this->size = 1;
1565  this->eval = (this->children[0]->evaluate() >= this->children[1]->evaluate());
1566  this->level = 1;
1567  this->symbolized = false;
1568 
1569  /* Init children and spread information */
1570  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1571  this->children[index]->setParent(this);
1572  this->symbolized |= this->children[index]->isSymbolized();
1573  this->level += this->children[index]->getLevel();
1574  }
1575 
1576  /* Init parents if needed */
1577  if (withParents) {
1578  this->initParents();
1579  }
1580 
1581  this->initHash();
1582  }
1583 
1584 
1585  void BvugeNode::initHash(void) {
1586  triton::uint512 s = this->children.size();
1587 
1588  this->hash = this->type;
1589  if (s) this->hash = this->hash * s;
1590  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1591  this->hash = this->hash * triton::ast::hash2n(this->children[index]->getHash(), index+1);
1592  }
1593 
1594  this->hash = triton::ast::rotl(this->hash, this->level);
1595  }
1596 
1597 
1598  /* ====== bvugt */
1599 
1600 
1601  BvugtNode::BvugtNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVUGT_NODE, expr1->getContext()) {
1602  this->addChild(expr1);
1603  this->addChild(expr2);
1604  }
1605 
1606 
1607  void BvugtNode::init(bool withParents) {
1608  if (this->children.size() < 2)
1609  throw triton::exceptions::Ast("BvugtNode::init(): Must take at least two children.");
1610 
1611  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
1612  throw triton::exceptions::Ast("BvugtNode::init(): Must take two nodes of same size.");
1613 
1614  /* Init attributes */
1615  this->size = 1;
1616  this->eval = (this->children[0]->evaluate() > this->children[1]->evaluate());
1617  this->level = 1;
1618  this->symbolized = false;
1619 
1620  /* Init children and spread information */
1621  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1622  this->children[index]->setParent(this);
1623  this->symbolized |= this->children[index]->isSymbolized();
1624  this->level += this->children[index]->getLevel();
1625  }
1626 
1627  /* Init parents if needed */
1628  if (withParents) {
1629  this->initParents();
1630  }
1631 
1632  this->initHash();
1633  }
1634 
1635 
1636  void BvugtNode::initHash(void) {
1637  triton::uint512 s = this->children.size();
1638 
1639  this->hash = this->type;
1640  if (s) this->hash = this->hash * s;
1641  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1642  this->hash = this->hash * triton::ast::hash2n(this->children[index]->getHash(), index+1);
1643  }
1644 
1645  this->hash = triton::ast::rotl(this->hash, this->level);
1646  }
1647 
1648 
1649  /* ====== bvule */
1650 
1651 
1652  BvuleNode::BvuleNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVULE_NODE, expr1->getContext()) {
1653  this->addChild(expr1);
1654  this->addChild(expr2);
1655  }
1656 
1657 
1658  void BvuleNode::init(bool withParents) {
1659  if (this->children.size() < 2)
1660  throw triton::exceptions::Ast("BvuleNode::init(): Must take at least two children.");
1661 
1662  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
1663  throw triton::exceptions::Ast("BvuleNode::init(): Must take two nodes of same size.");
1664 
1665  /* Init attributes */
1666  this->size = 1;
1667  this->eval = (this->children[0]->evaluate() <= this->children[1]->evaluate());
1668  this->level = 1;
1669  this->symbolized = false;
1670 
1671  /* Init children and spread information */
1672  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1673  this->children[index]->setParent(this);
1674  this->symbolized |= this->children[index]->isSymbolized();
1675  this->level += this->children[index]->getLevel();
1676  }
1677 
1678  /* Init parents if needed */
1679  if (withParents) {
1680  this->initParents();
1681  }
1682 
1683  this->initHash();
1684  }
1685 
1686 
1687  void BvuleNode::initHash(void) {
1688  triton::uint512 s = this->children.size();
1689 
1690  this->hash = this->type;
1691  if (s) this->hash = this->hash * s;
1692  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1693  this->hash = this->hash * triton::ast::hash2n(this->children[index]->getHash(), index+1);
1694  }
1695 
1696  this->hash = triton::ast::rotl(this->hash, this->level);
1697  }
1698 
1699 
1700  /* ====== bvult */
1701 
1702 
1703  BvultNode::BvultNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVULT_NODE, expr1->getContext()) {
1704  this->addChild(expr1);
1705  this->addChild(expr2);
1706  }
1707 
1708 
1709  void BvultNode::init(bool withParents) {
1710  if (this->children.size() < 2)
1711  throw triton::exceptions::Ast("BvultNode::init(): Must take at least two children.");
1712 
1713  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
1714  throw triton::exceptions::Ast("BvultNode::init(): Must take two nodes of same size.");
1715 
1716  /* Init attributes */
1717  this->size = 1;
1718  this->eval = (this->children[0]->evaluate() < this->children[1]->evaluate());
1719  this->level = 1;
1720  this->symbolized = false;
1721 
1722  /* Init children and spread information */
1723  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1724  this->children[index]->setParent(this);
1725  this->symbolized |= this->children[index]->isSymbolized();
1726  this->level += this->children[index]->getLevel();
1727  }
1728 
1729  /* Init parents if needed */
1730  if (withParents) {
1731  this->initParents();
1732  }
1733 
1734  this->initHash();
1735  }
1736 
1737 
1738  void BvultNode::initHash(void) {
1739  triton::uint512 s = this->children.size();
1740 
1741  this->hash = this->type;
1742  if (s) this->hash = this->hash * s;
1743  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1744  this->hash = this->hash * triton::ast::hash2n(this->children[index]->getHash(), index+1);
1745  }
1746 
1747  this->hash = triton::ast::rotl(this->hash, this->level);
1748  }
1749 
1750 
1751  /* ====== bvurem */
1752 
1753 
1754  BvuremNode::BvuremNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVUREM_NODE, expr1->getContext()) {
1755  this->addChild(expr1);
1756  this->addChild(expr2);
1757  }
1758 
1759 
1760  void BvuremNode::init(bool withParents) {
1761  if (this->children.size() < 2)
1762  throw triton::exceptions::Ast("BvuremNode::init(): Must take at least two children.");
1763 
1764  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
1765  throw triton::exceptions::Ast("BvuremNode::init(): Must take two nodes of same size.");
1766 
1767  /* Init attributes */
1768  this->size = this->children[0]->getBitvectorSize();
1769  this->level = 1;
1770  this->symbolized = false;
1771 
1772  if (this->children[1]->evaluate() == 0)
1773  this->eval = this->children[0]->evaluate();
1774  else
1775  this->eval = (this->children[0]->evaluate() % this->children[1]->evaluate());
1776 
1777  /* Init children and spread information */
1778  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1779  this->children[index]->setParent(this);
1780  this->symbolized |= this->children[index]->isSymbolized();
1781  this->level += this->children[index]->getLevel();
1782  }
1783 
1784  /* Init parents if needed */
1785  if (withParents) {
1786  this->initParents();
1787  }
1788 
1789  this->initHash();
1790  }
1791 
1792 
1793  void BvuremNode::initHash(void) {
1794  triton::uint512 s = this->children.size();
1795 
1796  this->hash = this->type;
1797  if (s) this->hash = this->hash * s;
1798  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1799  this->hash = this->hash * triton::ast::hash2n(this->children[index]->getHash(), index+1);
1800  }
1801 
1802  this->hash = triton::ast::rotl(this->hash, this->level);
1803  }
1804 
1805 
1806  /* ====== bvxnor */
1807 
1808 
1809  BvxnorNode::BvxnorNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVXNOR_NODE, expr1->getContext()) {
1810  this->addChild(expr1);
1811  this->addChild(expr2);
1812  }
1813 
1814 
1815  void BvxnorNode::init(bool withParents) {
1816  if (this->children.size() < 2)
1817  throw triton::exceptions::Ast("BvxnorNode::init(): Must take at least two children.");
1818 
1819  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
1820  throw triton::exceptions::Ast("BvxnorNode::init(): Must take two nodes of same size.");
1821 
1822  /* Init attributes */
1823  this->size = this->children[0]->getBitvectorSize();
1824  this->eval = (~(this->children[0]->evaluate() ^ this->children[1]->evaluate()) & this->getBitvectorMask());
1825  this->level = 1;
1826  this->symbolized = false;
1827 
1828  /* Init children and spread information */
1829  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1830  this->children[index]->setParent(this);
1831  this->symbolized |= this->children[index]->isSymbolized();
1832  this->level += this->children[index]->getLevel();
1833  }
1834 
1835  /* Init parents if needed */
1836  if (withParents) {
1837  this->initParents();
1838  }
1839 
1840  this->initHash();
1841  }
1842 
1843 
1844  void BvxnorNode::initHash(void) {
1845  triton::uint512 s = this->children.size();
1846 
1847  this->hash = this->type;
1848  if (s) this->hash = this->hash * s;
1849  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1850  this->hash = this->hash * this->children[index]->getHash();
1851  }
1852 
1853  this->hash = triton::ast::rotl(this->hash, this->level);
1854  }
1855 
1856 
1857  /* ====== bvxor */
1858 
1859 
1860  BvxorNode::BvxorNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(BVXOR_NODE, expr1->getContext()) {
1861  this->addChild(expr1);
1862  this->addChild(expr2);
1863  }
1864 
1865 
1866  void BvxorNode::init(bool withParents) {
1867  if (this->children.size() < 2)
1868  throw triton::exceptions::Ast("BvxorNode::init(): Must take at least two children.");
1869 
1870  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
1871  throw triton::exceptions::Ast("BvxorNode::init(): Must take two nodes of same size.");
1872 
1873  /* Init attributes */
1874  this->size = this->children[0]->getBitvectorSize();
1875  this->eval = (this->children[0]->evaluate() ^ this->children[1]->evaluate());
1876  this->level = 1;
1877  this->symbolized = false;
1878 
1879  /* Init children and spread information */
1880  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1881  this->children[index]->setParent(this);
1882  this->symbolized |= this->children[index]->isSymbolized();
1883  this->level += this->children[index]->getLevel();
1884  }
1885 
1886  /* Init parents if needed */
1887  if (withParents) {
1888  this->initParents();
1889  }
1890 
1891  this->initHash();
1892  }
1893 
1894 
1895  void BvxorNode::initHash(void) {
1896  triton::uint512 s = this->children.size();
1897 
1898  this->hash = this->type;
1899  if (s) this->hash = this->hash * s;
1900  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1901  this->hash = this->hash * this->children[index]->getHash();
1902  }
1903 
1904  this->hash = triton::ast::rotl(this->hash, this->level);
1905  }
1906 
1907 
1908  /* ====== bv */
1909 
1910 
1911  BvNode::BvNode(const triton::uint512& value, triton::uint32 size, const SharedAstContext& ctxt): AbstractNode(BV_NODE, ctxt) {
1912  this->addChild(this->ctxt->integer(value));
1913  this->addChild(this->ctxt->integer(size));
1914  }
1915 
1916 
1917  void BvNode::init(bool withParents) {
1918  triton::uint512 value = 0;
1919  triton::uint32 size = 0;
1920 
1921  if (this->children.size() < 2)
1922  throw triton::exceptions::Ast("BvNode::init(): Must take at least two children.");
1923 
1924  if (this->children[0]->getType() != INTEGER_NODE || this->children[1]->getType() != INTEGER_NODE)
1925  throw triton::exceptions::Ast("BvNode::init(): Size and value must be a INTEGER_NODE.");
1926 
1927  value = reinterpret_cast<IntegerNode*>(this->children[0].get())->getInteger();
1928  size = reinterpret_cast<IntegerNode*>(this->children[1].get())->getInteger().convert_to<triton::uint32>();
1929 
1930  if (!size)
1931  throw triton::exceptions::Ast("BvNode::init(): Size cannot be equal to zero.");
1932 
1933  if (size > MAX_BITS_SUPPORTED)
1934  throw triton::exceptions::Ast("BvNode::init(): Size cannot be greater than MAX_BITS_SUPPORTED.");
1935 
1936  /* Init attributes */
1937  this->size = size;
1938  this->eval = (value & this->getBitvectorMask());
1939  this->level = 1;
1940  this->symbolized = false;
1941 
1942  /* Init children and spread information */
1943  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1944  this->children[index]->setParent(this);
1945  this->symbolized |= this->children[index]->isSymbolized();
1946  this->level += this->children[index]->getLevel();
1947  }
1948 
1949  /* Init parents if needed */
1950  if (withParents) {
1951  this->initParents();
1952  }
1953 
1954  this->initHash();
1955  }
1956 
1957 
1958  void BvNode::initHash(void) {
1959  triton::uint512 s = this->children.size();
1960 
1961  this->hash = this->type;
1962  if (s) this->hash = this->hash * s;
1963  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1964  this->hash = this->hash * triton::ast::hash2n(this->children[index]->getHash(), index+1);
1965  }
1966 
1967  this->hash = triton::ast::rotl(this->hash, this->level);
1968  }
1969 
1970 
1971  /* ====== compound */
1972 
1973 
1974  void CompoundNode::init(bool withParents) {
1975  if (this->children.size() < 1)
1976  throw triton::exceptions::Ast("CompoundNode::init(): Must take at least one child.");
1977 
1978  /* Init attributes */
1979  this->eval = 0;
1980  this->size = 0;
1981  this->level = 1;
1982  this->symbolized = false;
1983 
1984  /* Init children and spread information */
1985  for (triton::uint32 index = 0; index < this->children.size(); index++) {
1986  this->children[index]->setParent(this);
1987  this->symbolized |= this->children[index]->isSymbolized();
1988  this->level += this->children[index]->getLevel();
1989  }
1990 
1991  /* Init parents if needed */
1992  if (withParents) {
1993  this->initParents();
1994  }
1995 
1996  this->initHash();
1997  }
1998 
1999 
2000  void CompoundNode::initHash(void) {
2001  triton::uint512 s = this->children.size();
2002 
2003  this->hash = this->type;
2004  if (s) this->hash = this->hash * s;
2005  for (triton::uint32 index = 0; index < this->children.size(); index++) {
2006  this->hash = this->hash * triton::ast::hash2n(this->children[index]->getHash(), index+1);
2007  }
2008 
2009  this->hash = triton::ast::rotl(this->hash, this->level);
2010  }
2011 
2012 
2013  /* ====== concat */
2014 
2015 
2016  ConcatNode::ConcatNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(CONCAT_NODE, expr1->getContext()) {
2017  this->addChild(expr1);
2018  this->addChild(expr2);
2019  }
2020 
2021 
2022  void ConcatNode::init(bool withParents) {
2023  if (this->children.size() < 2)
2024  throw triton::exceptions::Ast("ConcatNode::init(): Must take at least two children.");
2025 
2026  /* Init attributes */
2027  this->level = 1;
2028  this->symbolized = false;
2029  this->size = 0;
2030  for (triton::uint32 index = 0; index < this->children.size(); index++) {
2031  this->size += this->children[index]->getBitvectorSize();
2032  }
2033 
2034  if (this->size > MAX_BITS_SUPPORTED)
2035  throw triton::exceptions::Ast("ConcatNode::init(): Size cannot be greater than MAX_BITS_SUPPORTED.");
2036 
2037  this->eval = this->children[0]->evaluate();
2038  for (triton::uint32 index = 0; index < this->children.size()-1; index++)
2039  this->eval = ((this->eval << this->children[index+1]->getBitvectorSize()) | this->children[index+1]->evaluate());
2040 
2041  /* Init children and spread information */
2042  for (triton::uint32 index = 0; index < this->children.size(); index++) {
2043  this->children[index]->setParent(this);
2044  this->symbolized |= this->children[index]->isSymbolized();
2045  this->level += this->children[index]->getLevel();
2046  }
2047 
2048  /* Init parents if needed */
2049  if (withParents) {
2050  this->initParents();
2051  }
2052 
2053  this->initHash();
2054  }
2055 
2056 
2057  void ConcatNode::initHash(void) {
2058  triton::uint512 s = this->children.size();
2059 
2060  this->hash = this->type;
2061  if (s) this->hash = this->hash * s;
2062  for (triton::uint32 index = 0; index < this->children.size(); index++) {
2063  this->hash = this->hash * triton::ast::hash2n(this->children[index]->getHash(), index+1);
2064  }
2065 
2066  this->hash = triton::ast::rotl(this->hash, this->level);
2067  }
2068 
2069 
2070  /* ====== Declare */
2071 
2072 
2073  DeclareNode::DeclareNode(const SharedAbstractNode& var): AbstractNode(DECLARE_NODE, var->getContext()) {
2074  this->addChild(var);
2075  }
2076 
2077 
2078  void DeclareNode::init(bool withParents) {
2079  if (this->children.size() < 1)
2080  throw triton::exceptions::Ast("DeclareNode::init(): Must take at least one child.");
2081 
2082  if (this->children[0]->getType() != VARIABLE_NODE)
2083  throw triton::exceptions::Ast("DeclareNode::init(): The child node must be a VARIABLE_NODE.");
2084 
2085  /* Init attributes */
2086  this->size = this->children[0]->getBitvectorSize();
2087  this->eval = this->children[0]->evaluate();
2088  this->level = 1;
2089  this->symbolized = false;
2090 
2091  /* Init children and spread information */
2092  for (triton::uint32 index = 0; index < this->children.size(); index++) {
2093  this->children[index]->setParent(this);
2094  this->symbolized |= this->children[index]->isSymbolized();
2095  this->level += this->children[index]->getLevel();
2096  }
2097 
2098  /* Init parents if needed */
2099  if (withParents) {
2100  this->initParents();
2101  }
2102 
2103  this->initHash();
2104  }
2105 
2106 
2107  void DeclareNode::initHash(void) {
2108  triton::uint512 s = this->children.size();
2109 
2110  this->hash = this->type;
2111  if (s) this->hash = this->hash * s;
2112  for (triton::uint32 index = 0; index < this->children.size(); index++) {
2113  this->hash = this->hash * triton::ast::hash2n(this->children[index]->getHash(), index+1);
2114  }
2115 
2116  this->hash = triton::ast::rotl(this->hash, this->level);
2117  }
2118 
2119 
2120  /* ====== Distinct node */
2121 
2122 
2123  DistinctNode::DistinctNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(DISTINCT_NODE, expr1->getContext()) {
2124  this->addChild(expr1);
2125  this->addChild(expr2);
2126  }
2127 
2128 
2129  void DistinctNode::init(bool withParents) {
2130  if (this->children.size() < 2)
2131  throw triton::exceptions::Ast("DistinctNode::init(): Must take at least two children.");
2132 
2133  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
2134  throw triton::exceptions::Ast("DistinctNode::init(): Must take two nodes of same size.");
2135 
2136  /* Init attributes */
2137  this->size = 1;
2138  this->eval = (this->children[0]->evaluate() != this->children[1]->evaluate());
2139  this->level = 1;
2140  this->symbolized = false;
2141 
2142  /* Init children and spread information */
2143  for (triton::uint32 index = 0; index < this->children.size(); index++) {
2144  this->children[index]->setParent(this);
2145  this->symbolized |= this->children[index]->isSymbolized();
2146  this->level += this->children[index]->getLevel();
2147  }
2148 
2149  /* Init parents if needed */
2150  if (withParents) {
2151  this->initParents();
2152  }
2153 
2154  this->initHash();
2155  }
2156 
2157 
2158  void DistinctNode::initHash(void) {
2159  triton::uint512 s = this->children.size();
2160 
2161  this->hash = this->type;
2162  if (s) this->hash = this->hash * s;
2163  for (triton::uint32 index = 0; index < this->children.size(); index++) {
2164  this->hash = this->hash * this->children[index]->getHash();
2165  }
2166 
2167  this->hash = triton::ast::rotl(this->hash, this->level);
2168  }
2169 
2170 
2171  /* ====== equal */
2172 
2173 
2174  EqualNode::EqualNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(EQUAL_NODE, expr1->getContext()) {
2175  this->addChild(expr1);
2176  this->addChild(expr2);
2177  }
2178 
2179 
2180  void EqualNode::init(bool withParents) {
2181  if (this->children.size() < 2)
2182  throw triton::exceptions::Ast("EqualNode::init(): Must take at least two children.");
2183 
2184  if (this->children[0]->getBitvectorSize() != this->children[1]->getBitvectorSize())
2185  throw triton::exceptions::Ast("EqualNode::init(): Must take two nodes of same size.");
2186 
2187  /* Init attributes */
2188  this->size = 1;
2189  this->eval = (this->children[0]->evaluate() == this->children[1]->evaluate());
2190  this->level = 1;
2191  this->symbolized = false;
2192 
2193  /* Init children and spread information */
2194  for (triton::uint32 index = 0; index < this->children.size(); index++) {
2195  this->children[index]->setParent(this);
2196  this->symbolized |= this->children[index]->isSymbolized();
2197  this->level += this->children[index]->getLevel();
2198  }
2199 
2200  /* Init parents if needed */
2201  if (withParents) {
2202  this->initParents();
2203  }
2204 
2205  this->initHash();
2206  }
2207 
2208 
2209  void EqualNode::initHash(void) {
2210  triton::uint512 s = this->children.size();
2211 
2212  this->hash = this->type;
2213  if (s) this->hash = this->hash * s;
2214  for (triton::uint32 index = 0; index < this->children.size(); index++) {
2215  this->hash = this->hash * this->children[index]->getHash();
2216  }
2217 
2218  this->hash = triton::ast::rotl(this->hash, this->level);
2219  }
2220 
2221 
2222  /* ====== extract */
2223 
2224 
2225  ExtractNode::ExtractNode(triton::uint32 high, triton::uint32 low, const SharedAbstractNode& expr): AbstractNode(EXTRACT_NODE, expr->getContext()) {
2226  this->addChild(this->ctxt->integer(high));
2227  this->addChild(this->ctxt->integer(low));
2228  this->addChild(expr);
2229  }
2230 
2231 
2232  void ExtractNode::init(bool withParents) {
2233  triton::uint32 high = 0;
2234  triton::uint32 low = 0;
2235 
2236  if (this->children.size() < 3)
2237  throw triton::exceptions::Ast("ExtractNode::init(): Must take at least three children.");
2238 
2239  if (this->children[0]->getType() != INTEGER_NODE || this->children[1]->getType() != INTEGER_NODE)
2240  throw triton::exceptions::Ast("ExtractNode::init(): The high and low bit must both be a INTEGER_NODE.");
2241 
2242  high = reinterpret_cast<IntegerNode*>(this->children[0].get())->getInteger().convert_to<triton::uint32>();
2243  low = reinterpret_cast<IntegerNode*>(this->children[1].get())->getInteger().convert_to<triton::uint32>();
2244 
2245  if (low > high)
2246  throw triton::exceptions::Ast("ExtractNode::init(): The high bit must be greater than the low bit.");
2247 
2248  /* Init attributes */
2249  this->size = ((high - low) + 1);
2250  this->eval = ((this->children[2]->evaluate() >> low) & this->getBitvectorMask());
2251  this->level = 1;
2252  this->symbolized = false;
2253 
2254  if (this->size > this->children[2]->getBitvectorSize() || high >= this->children[2]->getBitvectorSize())
2255  throw triton::exceptions::Ast("ExtractNode::init(): The size of the extraction is higher than the child expression.");
2256 
2257  /* Init children and spread information */
2258  for (triton::uint32 index = 0; index < this->children.size(); index++) {
2259  this->children[index]->setParent(this);
2260  this->symbolized |= this->children[index]->isSymbolized();
2261  this->level += this->children[index]->getLevel();
2262  }
2263 
2264  /* Init parents if needed */
2265  if (withParents) {
2266  this->initParents();
2267  }
2268 
2269  this->initHash();
2270  }
2271 
2272 
2273  void ExtractNode::initHash(void) {
2274  triton::uint512 s = this->children.size();
2275 
2276  this->hash = this->type;
2277  if (s) this->hash = this->hash * s;
2278  for (triton::uint32 index = 0; index < this->children.size(); index++) {
2279  this->hash = this->hash * triton::ast::hash2n(this->children[index]->getHash(), index+1);
2280  }
2281 
2282  this->hash = triton::ast::rotl(this->hash, this->level);
2283  }
2284 
2285 
2286  /* ====== iff */
2287 
2288 
2289  IffNode::IffNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(IFF_NODE, expr1->getContext()) {
2290  this->addChild(expr1);
2291  this->addChild(expr2);
2292  }
2293 
2294 
2295  void IffNode::init(bool withParents) {
2296  if (this->children.size() < 2)
2297  throw triton::exceptions::Ast("IffNode::init(): Must take at least two children.");
2298 
2299  if (this->children[0]->isLogical() == false)
2300  throw triton::exceptions::Ast("IffNode::init(): Must take a logical node as first argument.");
2301 
2302  if (this->children[1]->isLogical() == false)
2303  throw triton::exceptions::Ast("IffNode::init(): Must take a logical node as second argument.");
2304 
2305  /* Init attributes */
2306  triton::uint512 P = this->children[0]->evaluate();
2307  triton::uint512 Q = this->children[1]->evaluate();
2308 
2309  this->size = 1;
2310  this->eval = (P && Q) || (!P && !Q);
2311  this->level = 1;
2312  this->symbolized = false;
2313 
2314  /* Init children and spread information */
2315  for (triton::uint32 index = 0; index < this->children.size(); index++) {
2316  this->children[index]->setParent(this);
2317  this->symbolized |= this->children[index]->isSymbolized();
2318  this->level += this->children[index]->getLevel();
2319  }
2320 
2321  /* Init parents if needed */
2322  if (withParents) {
2323  this->initParents();
2324  }
2325 
2326  this->initHash();
2327  }
2328 
2329 
2330  void IffNode::initHash(void) {
2331  triton::uint512 s = this->children.size();
2332 
2333  this->hash = this->type;
2334  if (s) this->hash = this->hash * s;
2335  for (triton::uint32 index = 0; index < this->children.size(); index++) {
2336  this->hash = this->hash * triton::ast::hash2n(this->children[index]->getHash(), index+1);
2337  }
2338 
2339  this->hash = triton::ast::rotl(this->hash, this->level);
2340  }
2341 
2342 
2343  /* ====== Integer node */
2344 
2345 
2346  IntegerNode::IntegerNode(const triton::uint512& value, const SharedAstContext& ctxt): AbstractNode(INTEGER_NODE, ctxt) {
2347  this->value = value;
2348  }
2349 
2350 
2351  void IntegerNode::init(bool withParents) {
2352  /* Init attributes */
2353  this->eval = 0;
2354  this->size = 0;
2355  this->level = 1;
2356  this->symbolized = false;
2357 
2358  /* Init parents if needed */
2359  if (withParents) {
2360  this->initParents();
2361  }
2362 
2363  this->initHash();
2364  }
2365 
2366 
2367  triton::uint512 IntegerNode::getInteger(void) {
2368  return this->value;
2369  }
2370 
2371 
2372  void IntegerNode::initHash(void) {
2373  this->hash = this->type ^ this->value;
2374  }
2375 
2376 
2377  /* ====== ite */
2378 
2379 
2380  IteNode::IteNode(const SharedAbstractNode& ifExpr, const SharedAbstractNode& thenExpr, const SharedAbstractNode& elseExpr): AbstractNode(ITE_NODE, ifExpr->getContext()) {
2381  this->addChild(ifExpr);
2382  this->addChild(thenExpr);
2383  this->addChild(elseExpr);
2384  }
2385 
2386 
2387  void IteNode::init(bool withParents) {
2388  if (this->children.size() < 3)
2389  throw triton::exceptions::Ast("IteNode::init(): Must take at least three children.");
2390 
2391  if (this->children[0]->isLogical() == false)
2392  throw triton::exceptions::Ast("IteNode::init(): Must take a logical node as first argument.");
2393 
2394  if (this->children[1]->getBitvectorSize() != this->children[2]->getBitvectorSize())
2395  throw triton::exceptions::Ast("IteNode::init(): Must take two nodes of same size as 'then' and 'else' branches.");
2396 
2397  if (this->children[1]->isLogical() != this->children[2]->isLogical())
2398  throw triton::exceptions::Ast("IteNode::init(): Must take either two logical nodes or two bv nodes as 'then' and 'else' branches.");
2399 
2400  /* Init attributes */
2401  this->size = this->children[1]->getBitvectorSize();
2402  this->eval = this->children[0]->evaluate() ? this->children[1]->evaluate() : this->children[2]->evaluate();
2403  this->logical = this->children[1]->isLogical();
2404  this->level = 1;
2405  this->symbolized = false;
2406 
2407  /* Init children and spread information */
2408  for (triton::uint32 index = 0; index < this->children.size(); index++) {
2409  this->children[index]->setParent(this);
2410  this->symbolized |= this->children[index]->isSymbolized();
2411  this->level += this->children[index]->getLevel();
2412  }
2413 
2414  /* Init parents if needed */
2415  if (withParents) {
2416  this->initParents();
2417  }
2418 
2419  this->initHash();
2420  }
2421 
2422 
2423  void IteNode::initHash(void) {
2424  triton::uint512 s = this->children.size();
2425 
2426  this->hash = this->type;
2427  if (s) this->hash = this->hash * s;
2428  for (triton::uint32 index = 0; index < this->children.size(); index++) {
2429  this->hash = this->hash * triton::ast::hash2n(this->children[index]->getHash(), index+1);
2430  }
2431 
2432  this->hash = triton::ast::rotl(this->hash, this->level);
2433  }
2434 
2435 
2436  /* ====== Land */
2437 
2438 
2439  LandNode::LandNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(LAND_NODE, expr1->getContext()) {
2440  this->addChild(expr1);
2441  this->addChild(expr2);
2442  }
2443 
2444 
2445  void LandNode::init(bool withParents) {
2446  if (this->children.size() < 2)
2447  throw triton::exceptions::Ast("LandNode::init(): Must take at least two children.");
2448 
2449  /* Init attributes */
2450  this->size = 1;
2451  this->eval = 1;
2452  this->level = 1;
2453  this->symbolized = false;
2454 
2455  /* Init children and spread information */
2456  for (triton::uint32 index = 0; index < this->children.size(); index++) {
2457  this->children[index]->setParent(this);
2458  this->symbolized |= this->children[index]->isSymbolized();
2459  this->eval = this->eval && this->children[index]->evaluate();
2460  this->level += this->children[index]->getLevel();
2461 
2462  if (this->children[index]->isLogical() == false)
2463  throw triton::exceptions::Ast("LandNode::init(): Must take logical nodes as arguments.");
2464  }
2465 
2466  /* Init parents if needed */
2467  if (withParents) {
2468  this->initParents();
2469  }
2470 
2471  this->initHash();
2472  }
2473 
2474 
2475  void LandNode::initHash(void) {
2476  triton::uint512 s = this->children.size();
2477 
2478  this->hash = this->type;
2479  if (s) this->hash = this->hash * s;
2480  for (triton::uint32 index = 0; index < this->children.size(); index++) {
2481  this->hash = this->hash * this->children[index]->getHash();
2482  }
2483 
2484  this->hash = triton::ast::rotl(this->hash, this->level);
2485  }
2486 
2487 
2488  /* ====== Let */
2489 
2490 
2491  LetNode::LetNode(std::string alias, const SharedAbstractNode& expr2, const SharedAbstractNode& expr3): AbstractNode(LET_NODE, expr2->getContext()) {
2492  this->addChild(this->ctxt->string(alias));
2493  this->addChild(expr2);
2494  this->addChild(expr3);
2495  }
2496 
2497 
2498  void LetNode::init(bool withParents) {
2499  if (this->children.size() < 3)
2500  throw triton::exceptions::Ast("LetNode::init(): Must take at least three children.");
2501 
2502  if (this->children[0]->getType() != STRING_NODE)
2503  throw triton::exceptions::Ast("LetNode::init(): The alias node must be a STRING_NODE.");
2504 
2505  /* Init attributes */
2506  this->size = this->children[2]->getBitvectorSize();
2507  this->eval = this->children[2]->evaluate();
2508  this->level = 1;
2509  this->symbolized = false;
2510 
2511  /* Init children and spread information */
2512  for (triton::uint32 index = 0; index < this->children.size(); index++) {
2513  this->children[index]->setParent(this);
2514  this->symbolized |= this->children[index]->isSymbolized();
2515  this->level += this->children[index]->getLevel();
2516  }
2517 
2518  /* Init parents if needed */
2519  if (withParents) {
2520  this->initParents();
2521  }
2522 
2523  this->initHash();
2524  }
2525 
2526 
2527  void LetNode::initHash(void) {
2528  triton::uint512 s = this->children.size();
2529 
2530  this->hash = this->type;
2531  if (s) this->hash = this->hash * s;
2532  for (triton::uint32 index = 0; index < this->children.size(); index++) {
2533  this->hash = this->hash * triton::ast::hash2n(this->children[index]->getHash(), index+1);
2534  }
2535 
2536  this->hash = triton::ast::rotl(this->hash, this->level);
2537  }
2538 
2539 
2540  /* ====== Lnot */
2541 
2542 
2543  LnotNode::LnotNode(const SharedAbstractNode& expr): AbstractNode(LNOT_NODE, expr->getContext()) {
2544  this->addChild(expr);
2545  }
2546 
2547 
2548  void LnotNode::init(bool withParents) {
2549  if (this->children.size() < 1)
2550  throw triton::exceptions::Ast("LnotNode::init(): Must take at least one child.");
2551 
2552  /* Init attributes */
2553  this->size = 1;
2554  this->eval = !(this->children[0]->evaluate());
2555  this->level = 1;
2556  this->symbolized = false;
2557 
2558  /* Init children and spread information */
2559  for (triton::uint32 index = 0; index < this->children.size(); index++) {
2560  this->children[index]->setParent(this);
2561  this->symbolized |= this->children[index]->isSymbolized();
2562  this->level += this->children[index]->getLevel();
2563 
2564  if (this->children[index]->isLogical() == false)
2565  throw triton::exceptions::Ast("LnotNode::init(): Must take logical nodes arguments.");
2566  }
2567 
2568  /* Init parents if needed */
2569  if (withParents) {
2570  this->initParents();
2571  }
2572 
2573  this->initHash();
2574  }
2575 
2576 
2577  void LnotNode::initHash(void) {
2578  triton::uint512 s = this->children.size();
2579 
2580  this->hash = this->type;
2581  if (s) this->hash = this->hash * s;
2582  for (triton::uint32 index = 0; index < this->children.size(); index++) {
2583  this->hash = this->hash * this->children[index]->getHash();
2584  }
2585 
2586  this->hash = triton::ast::rotl(this->hash, this->level);
2587  }
2588 
2589 
2590  /* ====== Lor */
2591 
2592 
2593  LorNode::LorNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2): AbstractNode(LOR_NODE, expr1->getContext()) {
2594  this->addChild(expr1);
2595  this->addChild(expr2);
2596  }
2597 
2598 
2599  void LorNode::init(bool withParents) {
2600  if (this->children.size() < 2)
2601  throw triton::exceptions::Ast("LorNode::init(): Must take at least two children.");
2602 
2603  /* Init attributes */
2604  this->size = 1;
2605  this->eval = 0;
2606  this->level = 1;
2607  this->symbolized = false;
2608 
2609  /* Init children and spread information */
2610  for (triton::uint32 index = 0; index < this->children.size(); index++) {
2611  this->children[index]->setParent(this);
2612  this->symbolized |= this->children[index]->isSymbolized();
2613  this->eval = this->eval || this->children[index]->evaluate();
2614  this->level += this->children[index]->getLevel();
2615 
2616  if (this->children[index]->isLogical() == false)
2617  throw triton::exceptions::Ast("LorNode::init(): Must take logical nodes as arguments.");
2618  }
2619 
2620  /* Init parents if needed */
2621  if (withParents) {
2622  this->initParents();
2623  }
2624 
2625  this->initHash();
2626  }
2627 
2628 
2629  void LorNode::initHash(void) {
2630  triton::uint512 s = this->children.size();
2631 
2632  this->hash = this->type;
2633  if (s) this->hash = this->hash * s;
2634  for (triton::uint32 index = 0; index < this->children.size(); index++) {
2635  this->hash = this->hash * this->children[index]->getHash();
2636  }
2637 
2638  this->hash = triton::ast::rotl(this->hash, this->level);
2639  }
2640 
2641 
2642  /* ====== Lxor */
2643 
2644 
2645  LxorNode::LxorNode(const SharedAbstractNode& expr1, const SharedAbstractNode& expr2) : AbstractNode(LXOR_NODE, expr1->getContext()) {
2646  this->addChild(expr1);
2647  this->addChild(expr2);
2648  }
2649 
2650 
2651  void LxorNode::init(bool withParents) {
2652  if (this->children.size() < 2)
2653  throw triton::exceptions::Ast("LxorNode::init(): Must take at least two children.");
2654 
2655  /* Init attributes */
2656  this->size = 1;
2657  this->eval = 0;
2658  this->level = 1;
2659  this->symbolized = false;
2660 
2661  /* Init children and spread information */
2662  for (triton::uint32 index = 0; index < this->children.size(); index++) {
2663  this->children[index]->setParent(this);
2664  this->symbolized |= this->children[index]->isSymbolized();
2665  this->eval = !this->eval != !this->children[index]->evaluate();
2666  this->level += this->children[index]->getLevel();
2667 
2668  if (this->children[index]->isLogical() == false)
2669  throw triton::exceptions::Ast("LxorNode::init(): Must take logical nodes as arguments.");
2670  }
2671 
2672  /* Init parents if needed */
2673  if (withParents) {
2674  this->initParents();
2675  }
2676 
2677  this->initHash();
2678  }
2679 
2680 
2681  void LxorNode::initHash(void) {
2682  triton::uint512 s = this->children.size();
2683 
2684  this->hash = this->type;
2685  if (s) this->hash = this->hash * s;
2686  for (triton::uint32 index = 0; index < this->children.size(); index++) {
2687  this->hash = this->hash * this->children[index]->getHash();
2688  }
2689 
2690  this->hash = triton::ast::rotl(this->hash, this->level);
2691  }
2692 
2693 
2694  /* ====== Reference node */
2695 
2696 
2697  ReferenceNode::ReferenceNode(const triton::engines::symbolic::SharedSymbolicExpression& expr)
2698  : AbstractNode(REFERENCE_NODE, expr->getAst()->getContext())
2699  , expr(expr) {
2700  }
2701 
2702 
2703  void ReferenceNode::init(bool withParents) {
2704  /* Init attributes */
2705  this->eval = this->expr->getAst()->evaluate();
2706  this->logical = this->expr->getAst()->isLogical();
2707  this->size = this->expr->getAst()->getBitvectorSize();
2708  this->symbolized = this->expr->getAst()->isSymbolized();
2709  this->level = 1 + this->expr->getAst()->getLevel();
2710 
2711  this->expr->getAst()->setParent(this);
2712 
2713  /* Init parents if needed */
2714  if (withParents) {
2715  this->initParents();
2716  }
2717 
2718  this->initHash();
2719  }
2720 
2721 
2722  void ReferenceNode::initHash(void) {
2723  this->hash = this->expr->getAst()->getHash();
2724  }
2725 
2726 
2727  const triton::engines::symbolic::SharedSymbolicExpression& ReferenceNode::getSymbolicExpression(void) const {
2728  return this->expr;
2729  }
2730 
2731 
2732  /* ====== String node */
2733 
2734 
2735  StringNode::StringNode(std::string value, const SharedAstContext& ctxt): AbstractNode(STRING_NODE, ctxt) {
2736  this->value = value;
2737  }
2738 
2739 
2740  void StringNode::init(bool withParents) {
2741  /* Init attributes */
2742  this->eval = 0;
2743  this->size = 0;
2744  this->level = 1;
2745  this->symbolized = false;
2746 
2747  /* Init parents if needed */
2748  if (withParents) {
2749  this->initParents();
2750  }
2751 
2752  this->initHash();
2753  }
2754 
2755 
2756  std::string StringNode::getString(void) {
2757  return this->value;
2758  }
2759 
2760 
2761  void StringNode::initHash(void) {
2762  triton::uint32 index = 1;
2763 
2764  this->hash = this->type;
2765  for (std::string::const_iterator it=this->value.cbegin(); it != this->value.cend(); it++) {
2766  this->hash = triton::ast::rotl(*it ^ this->hash ^ triton::ast::hash2n(this->hash, index++), *it);
2767  }
2768 
2769  this->hash = triton::ast::rotl(this->hash, this->level);
2770  }
2771 
2772 
2773  /* ====== sx */
2774 
2775 
2776  SxNode::SxNode(triton::uint32 sizeExt, const SharedAbstractNode& expr): AbstractNode(SX_NODE, expr->getContext()) {
2777  this->addChild(this->ctxt->integer(sizeExt));
2778  this->addChild(expr);
2779  }
2780 
2781 
2782  void SxNode::init(bool withParents) {
2783  triton::uint32 sizeExt = 0;
2784 
2785  if (this->children.size() < 2)
2786  throw triton::exceptions::Ast("SxNode::init(): Must take at least two children.");
2787 
2788  if (this->children[0]->getType() != INTEGER_NODE)
2789  throw triton::exceptions::Ast("SxNode::init(): The sizeExt must be a INTEGER_NODE.");
2790 
2791  sizeExt = reinterpret_cast<IntegerNode*>(this->children[0].get())->getInteger().convert_to<triton::uint32>();
2792 
2793  /* Init attributes */
2794  this->size = sizeExt + this->children[1]->getBitvectorSize();
2795  if (size > MAX_BITS_SUPPORTED)
2796  throw triton::exceptions::Ast("SxNode::SxNode(): Size cannot be greater than MAX_BITS_SUPPORTED.");
2797 
2798  this->level = 1;
2799  this->symbolized = false;
2800  this->eval = ((((this->children[1]->evaluate() >> (this->children[1]->getBitvectorSize()-1)) == 0) ?
2801  this->children[1]->evaluate() : (this->children[1]->evaluate() | ~(this->children[1]->getBitvectorMask()))) & this->getBitvectorMask());
2802 
2803  /* Init children and spread information */
2804  for (triton::uint32 index = 0; index < this->children.size(); index++) {
2805  this->children[index]->setParent(this);
2806  this->symbolized |= this->children[index]->isSymbolized();
2807  this->level += this->children[index]->getLevel();
2808  }
2809 
2810  /* Init parents if needed */
2811  if (withParents) {
2812  this->initParents();
2813  }
2814 
2815  this->initHash();
2816  }
2817 
2818 
2819  void SxNode::initHash(void) {
2820  triton::uint512 s = this->children.size();
2821 
2822  this->hash = this->type;
2823  if (s) this->hash = this->hash * s;
2824  for (triton::uint32 index = 0; index < this->children.size(); index++) {
2825  this->hash = this->hash * triton::ast::hash2n(this->children[index]->getHash(), index+1);
2826  }
2827 
2828  this->hash = triton::ast::rotl(this->hash, this->level);
2829  }
2830 
2831 
2832  /* ====== Variable node */
2833 
2834 
2835  VariableNode::VariableNode(const triton::engines::symbolic::SharedSymbolicVariable& symVar, const SharedAstContext& ctxt)
2836  : AbstractNode(VARIABLE_NODE, ctxt),
2837  symVar(symVar) {
2838  }
2839 
2840 
2841  void VariableNode::init(bool withParents) {
2842  this->size = this->symVar->getSize();
2843  this->eval = this->ctxt->getVariableValue(this->symVar->getName()) & this->getBitvectorMask();
2844  this->symbolized = true;
2845  this->level = 1;
2846 
2847  /* Init parents if needed */
2848  if (withParents) {
2849  this->initParents();
2850  }
2851 
2852  this->initHash();
2853  }
2854 
2855 
2856  const triton::engines::symbolic::SharedSymbolicVariable& VariableNode::getSymbolicVariable() {
2857  return this->symVar;
2858  }
2859 
2860 
2861  void VariableNode::initHash(void) {
2862  triton::uint32 index = 1;
2863  triton::usize id = this->symVar->getId();
2864 
2865  this->hash = this->type;
2866  for (char c : this->symVar->getName()) {
2867  this->hash = triton::ast::rotl(c ^ this->hash ^ triton::ast::hash2n(this->hash, index++), id);
2868  }
2869 
2870  this->hash = triton::ast::rotl(this->hash, this->level);
2871  }
2872 
2873 
2874  /* ====== zx */
2875 
2876 
2877  ZxNode::ZxNode(triton::uint32 sizeExt, const SharedAbstractNode& expr): AbstractNode(ZX_NODE, expr->getContext()) {
2878  this->addChild(this->ctxt->integer(sizeExt));
2879  this->addChild(expr);
2880  }
2881 
2882 
2883  void ZxNode::init(bool withParents) {
2884  triton::uint32 sizeExt = 0;
2885 
2886  if (this->children.size() < 2)
2887  throw triton::exceptions::Ast("ZxNode::init(): Must take at least two children.");
2888 
2889  if (this->children[0]->getType() != INTEGER_NODE)
2890  throw triton::exceptions::Ast("ZxNode::init(): The sizeExt must be a INTEGER_NODE.");
2891 
2892  sizeExt = reinterpret_cast<IntegerNode*>(this->children[0].get())->getInteger().convert_to<triton::uint32>();
2893 
2894  /* Init attributes */
2895  this->size = sizeExt + this->children[1]->getBitvectorSize();
2896  if (size > MAX_BITS_SUPPORTED)
2897  throw triton::exceptions::Ast("ZxNode::init(): Size cannot be greater than MAX_BITS_SUPPORTED.");
2898 
2899  this->eval = (this->children[1]->evaluate() & this->getBitvectorMask());
2900  this->level = 1;
2901  this->symbolized = false;
2902 
2903  /* Init children and spread information */
2904  for (triton::uint32 index = 0; index < this->children.size(); index++) {
2905  this->children[index]->setParent(this);
2906  this->symbolized |= this->children[index]->isSymbolized();
2907  this->level += this->children[index]->getLevel();
2908  }
2909 
2910  /* Init parents if needed */
2911  if (withParents) {
2912  this->initParents();
2913  }
2914 
2915  this->initHash();
2916  }
2917 
2918 
2919  void ZxNode::initHash(void) {
2920  triton::uint512 s = this->children.size();
2921 
2922  this->hash = this->type;
2923  if (s) this->hash = this->hash * s;
2924  for (triton::uint32 index = 0; index < this->children.size(); index++) {
2925  this->hash = this->hash * triton::ast::hash2n(this->children[index]->getHash(), index+1);
2926  }
2927 
2928  this->hash = triton::ast::rotl(this->hash, this->level);
2929  }
2930 
2931  }; /* ast namespace */
2932 }; /* triton namespace */
2933 
2934 
2935 
2936 /* ====== Force templates declarations */
2937 
2938 namespace triton {
2939  namespace ast {
2940 
2941  template TRITON_EXPORT CompoundNode::CompoundNode(const std::list<SharedAbstractNode>& exprs, const SharedAstContext& ctxt);
2942  template TRITON_EXPORT CompoundNode::CompoundNode(const std::vector<SharedAbstractNode>& exprs, const SharedAstContext& ctxt);
2943  template TRITON_EXPORT ConcatNode::ConcatNode(const std::list<SharedAbstractNode>& exprs, const SharedAstContext& ctxt);
2944  template TRITON_EXPORT ConcatNode::ConcatNode(const std::vector<SharedAbstractNode>& exprs, const SharedAstContext& ctxt);
2945  template TRITON_EXPORT LandNode::LandNode(const std::list<SharedAbstractNode>& exprs, const SharedAstContext& ctxt);
2946  template TRITON_EXPORT LandNode::LandNode(const std::vector<SharedAbstractNode>& exprs, const SharedAstContext& ctxt);
2947  template TRITON_EXPORT LorNode::LorNode(const std::list<SharedAbstractNode>& exprs, const SharedAstContext& ctxt);
2948  template TRITON_EXPORT LorNode::LorNode(const std::vector<SharedAbstractNode>& exprs, const SharedAstContext& ctxt);
2949  template TRITON_EXPORT LxorNode::LxorNode(const std::list<SharedAbstractNode>& exprs, const SharedAstContext& ctxt);
2950  template TRITON_EXPORT LxorNode::LxorNode(const std::vector<SharedAbstractNode>& exprs, const SharedAstContext& ctxt);
2951 
2952  }; /* ast namespace */
2953 }; /* triton namespace */
2954 
2955 
2956 
2957 /* ====== Operators */
2958 
2959 namespace triton {
2960  namespace ast {
2961 
2962  /* Representation dispatcher from an abstract node */
2963  std::ostream& operator<<(std::ostream& stream, AbstractNode* node) {
2964  return node->getContext()->print(stream, node);
2965  }
2966 
2967  }; /* ast namespace */
2968 }; /* triton namespace */
2969 
2970 
2971 
2972 /* ====== Math utils */
2973 
2974 namespace triton {
2975  namespace ast {
2976 
2978  triton::uint512 mask = -1;
2979  for (triton::uint32 i = 0; i < n; i++)
2980  hash = ((hash * hash) & mask);
2981  return hash;
2982  }
2983 
2984 
2986  if ((shift &= 511) == 0)
2987  return value;
2988  return ((value << shift) | (value >> (512 - shift)));
2989  }
2990 
2991 
2993  triton::sint512 value = 0;
2994 
2995  if ((node->evaluate() >> (node->getBitvectorSize()-1)) & 1) {
2996  value = -1;
2997  value = ((value << node->getBitvectorSize()) | node->evaluate());
2998  }
2999  else {
3000  value = node->evaluate();
3001  }
3002 
3003  return value;
3004  }
3005 
3006  }; /* ast namespace */
3007 }; /* triton namespace */
3008 
3009 
3010 
3011 /* ====== Node utilities */
3012 
3013 namespace triton {
3014  namespace ast {
3015 
3016  /* Returns a new instance of a given node. */
3017  static SharedAbstractNode shallowCopy(AbstractNode* node, bool unroll) {
3018  SharedAbstractNode newNode = nullptr;
3019 
3020  if (node == nullptr)
3021  return nullptr;
3022 
3023  switch (node->getType()) {
3024  case ASSERT_NODE: newNode = std::make_shared<AssertNode>(*reinterpret_cast<AssertNode*>(node)); break;
3025  case BVADD_NODE: newNode = std::make_shared<BvaddNode>(*reinterpret_cast<BvaddNode*>(node)); break;
3026  case BVAND_NODE: newNode = std::make_shared<BvandNode>(*reinterpret_cast<BvandNode*>(node)); break;
3027  case BVASHR_NODE: newNode = std::make_shared<BvashrNode>(*reinterpret_cast<BvashrNode*>(node)); break;
3028  case BVLSHR_NODE: newNode = std::make_shared<BvlshrNode>(*reinterpret_cast<BvlshrNode*>(node)); break;
3029  case BVMUL_NODE: newNode = std::make_shared<BvmulNode>(*reinterpret_cast<BvmulNode*>(node)); break;
3030  case BVNAND_NODE: newNode = std::make_shared<BvnandNode>(*reinterpret_cast<BvnandNode*>(node)); break;
3031  case BVNEG_NODE: newNode = std::make_shared<BvnegNode>(*reinterpret_cast<BvnegNode*>(node)); break;
3032  case BVNOR_NODE: newNode = std::make_shared<BvnorNode>(*reinterpret_cast<BvnorNode*>(node)); break;
3033  case BVNOT_NODE: newNode = std::make_shared<BvnotNode>(*reinterpret_cast<BvnotNode*>(node)); break;
3034  case BVOR_NODE: newNode = std::make_shared<BvorNode>(*reinterpret_cast<BvorNode*>(node)); break;
3035  case BVROL_NODE: newNode = std::make_shared<BvrolNode>(*reinterpret_cast<BvrolNode*>(node)); break;
3036  case BVROR_NODE: newNode = std::make_shared<BvrorNode>(*reinterpret_cast<BvrorNode*>(node)); break;
3037  case BVSDIV_NODE: newNode = std::make_shared<BvsdivNode>(*reinterpret_cast<BvsdivNode*>(node)); break;
3038  case BVSGE_NODE: newNode = std::make_shared<BvsgeNode>(*reinterpret_cast<BvsgeNode*>(node)); break;
3039  case BVSGT_NODE: newNode = std::make_shared<BvsgtNode>(*reinterpret_cast<BvsgtNode*>(node)); break;
3040  case BVSHL_NODE: newNode = std::make_shared<BvshlNode>(*reinterpret_cast<BvshlNode*>(node)); break;
3041  case BVSLE_NODE: newNode = std::make_shared<BvsleNode>(*reinterpret_cast<BvsleNode*>(node)); break;
3042  case BVSLT_NODE: newNode = std::make_shared<BvsltNode>(*reinterpret_cast<BvsltNode*>(node)); break;
3043  case BVSMOD_NODE: newNode = std::make_shared<BvsmodNode>(*reinterpret_cast<BvsmodNode*>(node)); break;
3044  case BVSREM_NODE: newNode = std::make_shared<BvsremNode>(*reinterpret_cast<BvsremNode*>(node)); break;
3045  case BVSUB_NODE: newNode = std::make_shared<BvsubNode>(*reinterpret_cast<BvsubNode*>(node)); break;
3046  case BVUDIV_NODE: newNode = std::make_shared<BvudivNode>(*reinterpret_cast<BvudivNode*>(node)); break;
3047  case BVUGE_NODE: newNode = std::make_shared<BvugeNode>(*reinterpret_cast<BvugeNode*>(node)); break;
3048  case BVUGT_NODE: newNode = std::make_shared<BvugtNode>(*reinterpret_cast<BvugtNode*>(node)); break;
3049  case BVULE_NODE: newNode = std::make_shared<BvuleNode>(*reinterpret_cast<BvuleNode*>(node)); break;
3050  case BVULT_NODE: newNode = std::make_shared<BvultNode>(*reinterpret_cast<BvultNode*>(node)); break;
3051  case BVUREM_NODE: newNode = std::make_shared<BvuremNode>(*reinterpret_cast<BvuremNode*>(node)); break;
3052  case BVXNOR_NODE: newNode = std::make_shared<BvxnorNode>(*reinterpret_cast<BvxnorNode*>(node)); break;
3053  case BVXOR_NODE: newNode = std::make_shared<BvxorNode>(*reinterpret_cast<BvxorNode*>(node)); break;
3054  case BV_NODE: newNode = std::make_shared<BvNode>(*reinterpret_cast<BvNode*>(node)); break;
3055  case COMPOUND_NODE: newNode = std::make_shared<CompoundNode>(*reinterpret_cast<CompoundNode*>(node)); break;
3056  case CONCAT_NODE: newNode = std::make_shared<ConcatNode>(*reinterpret_cast<ConcatNode*>(node)); break;
3057  case DECLARE_NODE: newNode = std::make_shared<DeclareNode>(*reinterpret_cast<DeclareNode*>(node)); break;
3058  case DISTINCT_NODE: newNode = std::make_shared<DistinctNode>(*reinterpret_cast<DistinctNode*>(node)); break;
3059  case EQUAL_NODE: newNode = std::make_shared<EqualNode>(*reinterpret_cast<EqualNode*>(node)); break;
3060  case EXTRACT_NODE: newNode = std::make_shared<ExtractNode>(*reinterpret_cast<ExtractNode*>(node)); break;
3061  case IFF_NODE: newNode = std::make_shared<IffNode>(*reinterpret_cast<IffNode*>(node)); break;
3062  case INTEGER_NODE: newNode = std::make_shared<IntegerNode>(*reinterpret_cast<IntegerNode*>(node)); break;
3063  case ITE_NODE: newNode = std::make_shared<IteNode>(*reinterpret_cast<IteNode*>(node)); break;
3064  case LAND_NODE: newNode = std::make_shared<LandNode>(*reinterpret_cast<LandNode*>(node)); break;
3065  case LET_NODE: newNode = std::make_shared<LetNode>(*reinterpret_cast<LetNode*>(node)); break;
3066  case LNOT_NODE: newNode = std::make_shared<LnotNode>(*reinterpret_cast<LnotNode*>(node)); break;
3067  case LOR_NODE: newNode = std::make_shared<LorNode>(*reinterpret_cast<LorNode*>(node)); break;
3068  case LXOR_NODE: newNode = std::make_shared<LxorNode>(*reinterpret_cast<LxorNode*>(node)); break;
3069  case REFERENCE_NODE: {
3070  if (unroll)
3071  return triton::ast::shallowCopy(reinterpret_cast<ReferenceNode*>(node)->getSymbolicExpression()->getAst().get(), unroll);
3072  else
3073  newNode = std::make_shared<ReferenceNode>(*reinterpret_cast<ReferenceNode*>(node));
3074  break;
3075  }
3076  case STRING_NODE: newNode = std::make_shared<StringNode>(*reinterpret_cast<StringNode*>(node)); break;
3077  case SX_NODE: newNode = std::make_shared<SxNode>(*reinterpret_cast<SxNode*>(node)); break;
3078  case VARIABLE_NODE: newNode = node->shared_from_this(); /* Do not duplicate shared var (see #792) */ break;
3079  case ZX_NODE: newNode = std::make_shared<ZxNode>(*reinterpret_cast<ZxNode*>(node)); break;
3080  default:
3081  throw triton::exceptions::Ast("triton::ast::shallowCopy(): Invalid type node.");
3082  }
3083 
3084  if (newNode == nullptr)
3085  throw triton::exceptions::Ast("triton::ast::shallowCopy(): Not enough memory.");
3086 
3087  /* Remove parents as this is a new node which has no connections with original AST */
3088  if (node->getType() != VARIABLE_NODE) {
3089  /* VARIABLE_NODE are not duplicated (see #792), so don't remove their parents */
3090  auto parents = newNode->getParents();
3091  for (auto& p : parents) {
3092  newNode->removeParent(p.get());
3093  }
3094  }
3095 
3096  return newNode;
3097  }
3098 
3099 
3101  std::map<AbstractNode*, SharedAbstractNode> exprs;
3102  auto nodes = childrenExtraction(node->shared_from_this(), unroll, true);
3103 
3104  for (auto&& n : nodes) {
3105  /* Do a copy of all children */
3106  auto newNode = shallowCopy(n.get(), unroll);
3107  exprs[n.get()] = newNode;
3108 
3109  /* For each child, set its parent */
3110  auto& children = newNode->getChildren();
3111  for (auto& child : children) {
3112  child = exprs[child.get()];
3113  child->setParent(newNode.get());
3114  }
3115  }
3116 
3117  /* Return the root node */
3118  return exprs.at(node);
3119  }
3120 
3121 
3123  return triton::ast::newInstance(node.get(), true);
3124  }
3125 
3126 
3127  /* Returns a vector of unique AST-nodes sorted topologically
3128  *
3129  * Depending on @descent argument this function produces topologically sorted vector of nodes from DAG consisting of
3130  * either parents or children of given @node. This helps to prevent exponential complexity when complex AST are
3131  * parsed during z3 conversion, copying and parents reinitialization.
3132  *
3133  * @unroll - traverses through ReferenceNodes
3134  * @revert - reverses the result
3135  * @descent - if true we traverse through children of nodes, otherwise parents
3136  */
3137  static std::vector<SharedAbstractNode> nodesExtraction(const SharedAbstractNode& node, bool unroll, bool revert, bool descend) {
3138  std::vector<SharedAbstractNode> result;
3139  std::unordered_set<AbstractNode*> visited;
3140  std::stack<std::pair<SharedAbstractNode, bool>> worklist;
3141 
3142  if (node == nullptr)
3143  throw triton::exceptions::Ast("triton::ast::nodesExtraction(): Node cannot be null.");
3144 
3145  /*
3146  * We use a worklist strategy to avoid recursive calls
3147  * and so stack overflow when going through a big AST.
3148  */
3149  worklist.push({node, false});
3150 
3151  while (!worklist.empty()) {
3152  SharedAbstractNode ast;
3153  bool postOrder;
3154  std::tie(ast, postOrder) = worklist.top();
3155  worklist.pop();
3156 
3157  /* It means that we visited all children of this node and we can put it in the result */
3158  if (postOrder) {
3159  result.push_back(ast);
3160  continue;
3161  }
3162 
3163  if (!visited.insert(ast.get()).second) {
3164  continue;
3165  }
3166 
3167  worklist.push({ast, true});
3168 
3169  const auto& relatives = descend ? ast->getChildren() : ast->getParents();
3170 
3171  /* Proceed relatives */
3172  for (const auto& r : relatives) {
3173  if (visited.find(r.get()) == visited.end()) {
3174  worklist.push({r, false});
3175  }
3176  }
3177 
3178  /* If unroll is true, we unroll all references */
3179  if (unroll && ast->getType() == REFERENCE_NODE) {
3180  const auto& ref = reinterpret_cast<ReferenceNode*>(ast.get())->getSymbolicExpression()->getAst();
3181  if (visited.find(ref.get()) == visited.end()) {
3182  worklist.push({ref, false});
3183  }
3184  }
3185  }
3186 
3187  /* The result is in reversed topological sort meaning that children go before parents */
3188  if (!revert) {
3189  std::reverse(result.begin(), result.end());
3190  }
3191 
3192  return result;
3193  }
3194 
3195 
3196  std::vector<SharedAbstractNode> childrenExtraction(const SharedAbstractNode& node, bool unroll, bool revert) {
3197  return nodesExtraction(node, unroll, revert, true);
3198  }
3199 
3200 
3201  std::vector<SharedAbstractNode> parentsExtraction(const SharedAbstractNode& node, bool revert) {
3202  return nodesExtraction(node, false, revert, false);
3203  }
3204 
3205 
3206  std::deque<SharedAbstractNode> search(const SharedAbstractNode& node, triton::ast::ast_e match) {
3207  std::stack<AbstractNode*> worklist;
3208  std::deque<SharedAbstractNode> result;
3209  std::unordered_set<const AbstractNode*> visited;
3210 
3211  worklist.push(node.get());
3212  while (!worklist.empty()) {
3213  auto current = worklist.top();
3214  worklist.pop();
3215 
3216  // This means that node is already in work_stack and we will not need to convert it second time
3217  if (visited.find(current) != visited.end()) {
3218  continue;
3219  }
3220 
3221  visited.insert(current);
3222  if (match == triton::ast::ANY_NODE || current->getType() == match)
3223  result.push_front(current->shared_from_this());
3224 
3225  if (current->getType() == REFERENCE_NODE) {
3226  worklist.push(reinterpret_cast<triton::ast::ReferenceNode *>(current)->getSymbolicExpression()->getAst().get());
3227  }
3228  else {
3229  for (const auto &child : current->getChildren()) {
3230  worklist.push(child.get());
3231  }
3232  }
3233  }
3234 
3235  return result;
3236  }
3237 
3238  }; /* ast namespace */
3239 }; /* triton namespace */
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:804
std::shared_ptr< triton::ast::AstContext > SharedAstContext
Shared AST context.
Definition: ast.hpp:63
triton::uint512 hash2n(triton::uint512 hash, triton::uint32 n)
Custom hash2n function for hash routine.
Definition: ast.cpp:2977
TRITON_EXPORT bool hasSameConcreteValueAndTypeAs(const SharedAbstractNode &other) const
Returns true if the node's concrete value and value type match those of the second one.
Definition: ast.cpp:114
TRITON_EXPORT bool canReplaceNodeWithoutUpdate(const SharedAbstractNode &other) const
Returns true if the node's value, value type and properties match those of the second one.
Definition: ast.cpp:121
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:2548
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:2078
SharedAbstractNode unroll(const triton::ast::SharedAbstractNode &node)
AST C++ API - Unrolls the SSA form of a given AST.
Definition: ast.cpp:3122
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:557
bool logical
True if it's a logical node.
Definition: ast.hpp:98
triton::uint512 eval
The value of the tree from this root node.
Definition: ast.hpp:89
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:2599
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:1607
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:1101
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:1760
TRITON_EXPORT triton::uint512 getBitvectorMask(void) const
Returns the vector mask according the size of the node.
Definition: ast.cpp:64
TRITON_EXPORT triton::ast::ast_e getType(void) const
Returns the type of the node.
Definition: ast.cpp:54
std::vector< SharedAbstractNode > children
The children of the node.
Definition: ast.hpp:79
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:2387
Abstract node.
Definition: ast.hpp:66
bool symbolized
True if the tree contains a symbolic variable.
Definition: ast.hpp:95
TRITON_EXPORT AbstractNode(triton::ast::ast_e type, const SharedAstContext &ctxt)
Constructor.
Definition: ast.cpp:31
std::ostream & operator<<(std::ostream &stream, AbstractNode *node)
Displays the node in ast representation.
Definition: ast.cpp:2963
TRITON_EXPORT triton::uint512 evaluate(void) const
Evaluates the tree.
Definition: ast.cpp:135
TRITON_EXPORT triton::uint32 getBitvectorSize(void) const
Returns the size of the node.
Definition: ast.cpp:59
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:2022
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:1326
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:1709
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:706
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:1210
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:1501
The Triton namespace.
Definition: api.cpp:226
triton::sint512 modularSignExtend(AbstractNode *node)
Custom modular sign extend for bitwise operation.
Definition: ast.cpp:2992
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:1815
The exception class used by all AST nodes.
Definition: exceptions.hpp:341
#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:163
std::vector< SharedAbstractNode > childrenExtraction(const SharedAbstractNode &node, bool unroll, bool revert)
Returns node and all its children of an AST sorted topologically. If unroll is true,...
Definition: ast.cpp:3196
TRITON_EXPORT bool isSigned(void) const
According to the size of the expression, returns true if the MSB is 1.
Definition: ast.cpp:71
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:1388
std::shared_ptr< triton::ast::AbstractNode > SharedAbstractNode
Shared Abstract Node.
Definition: ast.hpp:57
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:2841
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:270
TRITON_EXPORT std::vector< SharedAbstractNode > & getChildren(void)
Returns the children of the node.
Definition: ast.cpp:158
boost::multiprecision::int512_t sint512
signed 512-bits
Definition: tritonTypes.hpp:64
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:2295
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:1268
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:2351
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:1658
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:1556
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:2703
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:658
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:1450
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:2782
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:608
TRITON_EXPORT SharedAstContext getContext(void) const
Access to its context.
Definition: ast.cpp:49
TRITON_EXPORT bool isSymbolized(void) const
Returns true if the tree contains a symbolic variable.
Definition: ast.cpp:78
TRITON_EXPORT std::string str(void) const
Returns the string representation of the node.
Definition: ast.cpp:253
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:2232
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:2129
TRITON_EXPORT void removeParent(AbstractNode *p)
Removes a parent node.
Definition: ast.cpp:202
std::vector< SharedAbstractNode > parentsExtraction(const SharedAbstractNode &node, bool revert)
Returns node and all its parents of an AST sorted topologically. If revert is true,...
Definition: ast.cpp:3201
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:321
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:506
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:756
void initParents(void)
Initializes parents.
Definition: ast.cpp:150
TRITON_EXPORT void setChild(triton::uint32 index, const SharedAbstractNode &child)
Sets a child at an index.
Definition: ast.cpp:225
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:2740
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:2445
TRITON_EXPORT triton::uint32 getLevel(void) const
Returns the deep level of the tree.
Definition: ast.cpp:145
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:1159
std::shared_ptr< triton::engines::symbolic::SymbolicExpression > SharedSymbolicExpression
Shared Symbolic Expression.
Definition: ast.hpp:38
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:1917
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:2651
std::uint32_t uint32
unisgned 32-bits
Definition: tritonTypes.hpp:31
triton::uint512 rotl(const triton::uint512 &value, triton::uint32 shift)
Custom rotate left function for hash routine.
Definition: ast.cpp:2985
SharedAbstractNode newInstance(AbstractNode *node, bool unroll)
AST C++ API - Duplicates the AST.
Definition: ast.cpp:3100
virtual TRITON_EXPORT ~AbstractNode()
Destructor.
Definition: ast.cpp:43
TRITON_EXPORT ZxNode(triton::uint32 sizeExt, const SharedAbstractNode &expr)
Create a zero extend of expr to sizeExt bits.
Definition: ast.cpp:2877
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:1866
TRITON_EXPORT void addChild(const SharedAbstractNode &child)
Adds a child.
Definition: ast.cpp:220
std::shared_ptr< triton::engines::symbolic::SymbolicVariable > SharedSymbolicVariable
Shared Symbolic variable.
Definition: ast.hpp:41
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:2883
TRITON_EXPORT void setParent(AbstractNode *p)
Sets a parent node.
Definition: ast.cpp:181
TRITON_EXPORT triton::uint512 getHash(void) const
Returns the hash of the tree.
Definition: ast.cpp:140
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:423
triton::uint32 level
Deep level for computing hash.
Definition: ast.hpp:73
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:2180
TRITON_EXPORT void setBitvectorSize(triton::uint32 size)
Sets the size of the node.
Definition: ast.cpp:248
std::deque< SharedAbstractNode > search(const SharedAbstractNode &node, triton::ast::ast_e match)
Returns a deque of collected matched nodes via a depth-first pre order traversal.
Definition: ast.cpp:3206
triton::uint512 hash
The hash of the tree.
Definition: ast.hpp:92
boost::multiprecision::uint512_t uint512
unsigned 512-bits
Definition: tritonTypes.hpp:43
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:921
std::size_t usize
unsigned MAX_INT 32 or 64 bits according to the CPU.
Definition: tritonTypes.hpp:67
triton::uint32 size
The size of the node.
Definition: ast.hpp:86
triton::ast::ast_e type
The type of the node.
Definition: ast.hpp:76
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:372
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:979
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:859
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:1974
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:1043
std::weak_ptr< triton::ast::AbstractNode > WeakAbstractNode
Weak Abstract Node.
Definition: ast.hpp:60
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
Definition: ast.cpp:2498
TRITON_EXPORT bool isLogical(void) const
Returns true if it's a logical node.
Definition: ast.cpp:83
TRITON_EXPORT bool equalTo(const SharedAbstractNode &other) const
Returns true if the current tree is equal to the second one.
Definition: ast.cpp:127
SharedAstContext ctxt
Contect use to create this node.
Definition: ast.hpp:101