13#include <unordered_map>
14#include <unordered_set>
67 mask = mask >> (512 - this->
size);
73 if ((this->
eval >> (this->
size-1)) & 1)
117 switch (this->
type) {
139 return (this->
evaluate() == other->evaluate()) &&
141 (this->
isLogical() == other->isLogical());
152 return (this->
evaluate() == other->evaluate()) &&
154 (this->
getHash() == other->getHash()) &&
155 (this->
getLevel() == other->getLevel());
176 for (
auto& sp : ancestors) {
188 std::vector<SharedAbstractNode> res;
189 std::vector<AbstractNode*> toRemove;
191 for (
auto& kv: parents) {
192 if (
auto sp = kv.second.second.lock())
195 toRemove.push_back(kv.first);
198 for(
auto* an: toRemove)
206 auto it = parents.find(p);
208 if (it == parents.end()) {
210 this->parents.insert(std::make_pair(p, std::make_pair(1,
WeakAbstractNode(A))));
213 if (it->second.second.expired()) {
216 this->parents.insert(std::make_pair(p, std::make_pair(1,
WeakAbstractNode(A))));
220 it->second.first += 1;
227 auto it = this->parents.find(p);
229 if (it == parents.end())
233 if (it->second.first == 0)
234 this->parents.erase(it);
254 if (child ==
nullptr)
257 if (this->
children[index] != child) {
259 this->
children[index]->removeParent(
this);
262 child->setParent(
this);
268 child->initParents();
281 if (!s.str().empty())
291 this->indexSize = indexSize;
292 this->
addChild(this->ctxt->integer(indexSize));
305 this->
children[index]->setParent(
this);
319 void ArrayNode::initHash(
void) {
323 if (s) this->hash = this->hash * s;
325 this->hash = this->hash * this->
children[index]->getHash();
333 this->memory[addr] = value;
338 if (this->memory.find(addr) != this->memory.end()) {
339 return this->memory.at(addr);
361 return this->indexSize;
388 this->
children[index]->setParent(
this);
402 void AssertNode::initHash(
void) {
406 if (s) this->hash = this->hash * s;
408 this->hash = this->hash * this->
children[index]->getHash();
442 this->
eval |= ((this->
children[0]->evaluate() >> index) & 0xff);
447 this->
children[index]->setParent(
this);
461 void BswapNode::initHash(
void) {
465 if (s) this->hash = this->hash * s;
467 this->hash = this->hash * this->
children[index]->getHash();
501 this->
children[index]->setParent(
this);
515 void BvaddNode::initHash(
void) {
519 if (s) this->hash = this->hash * s;
521 this->hash = this->hash * this->
children[index]->getHash();
555 this->
children[index]->setParent(
this);
569 void BvandNode::initHash(
void) {
573 if (s) this->hash = this->hash * s;
575 this->hash = this->hash * this->
children[index]->getHash();
605 value = this->
children[0]->evaluate();
628 else if (shift == 0) {
641 this->
children[index]->setParent(
this);
655 void BvashrNode::initHash(
void) {
659 if (s) this->hash = this->hash * s;
695 this->
children[index]->setParent(
this);
709 void BvlshrNode::initHash(
void) {
713 if (s) this->hash = this->hash * s;
749 this->
children[index]->setParent(
this);
763 void BvmulNode::initHash(
void) {
767 if (s) this->hash = this->hash * s;
769 this->hash = this->hash * this->
children[index]->getHash();
803 this->
children[index]->setParent(
this);
817 void BvnandNode::initHash(
void) {
821 if (s) this->hash = this->hash * s;
823 this->hash = this->hash * this->
children[index]->getHash();
853 this->
children[index]->setParent(
this);
867 void BvnegNode::initHash(
void) {
871 if (s) this->hash = this->hash * s;
873 this->hash = this->hash * this->
children[index]->getHash();
907 this->
children[index]->setParent(
this);
921 void BvnorNode::initHash(
void) {
925 if (s) this->hash = this->hash * s;
927 this->hash = this->hash * this->
children[index]->getHash();
957 this->
children[index]->setParent(
this);
971 void BvnotNode::initHash(
void) {
975 if (s) this->hash = this->hash * s;
977 this->hash = this->hash * this->
children[index]->getHash();
1011 this->
children[index]->setParent(
this);
1025 void BvorNode::initHash(
void) {
1029 if (s) this->hash = this->hash * s;
1031 this->hash = this->hash * this->
children[index]->getHash();
1061 rot = triton::ast::getInteger<triton::uint32>(this->
children[1]);
1062 value = this->
children[0]->evaluate();
1073 this->
children[index]->setParent(
this);
1087 void BvrolNode::initHash(
void) {
1091 if (s) this->hash = this->hash * s;
1123 rot = triton::ast::getInteger<triton::uint32>(this->
children[1]);
1124 value = this->
children[0]->evaluate();
1135 this->
children[index]->setParent(
this);
1149 void BvrorNode::initHash(
void) {
1153 if (s) this->hash = this->hash * s;
1193 if (op2Signed == 0) {
1194 this->
eval = (op1Signed < 0 ? 1 : -1);
1202 this->
children[index]->setParent(
this);
1216 void BvsdivNode::initHash(
void) {
1220 if (s) this->hash = this->hash * s;
1257 this->
eval = (op1Signed >= op2Signed);
1263 this->
children[index]->setParent(
this);
1277 void BvsgeNode::initHash(
void) {
1281 if (s) this->hash = this->hash * s;
1318 this->
eval = (op1Signed > op2Signed);
1324 this->
children[index]->setParent(
this);
1338 void BvsgtNode::initHash(
void) {
1342 if (s) this->hash = this->hash * s;
1378 this->
children[index]->setParent(
this);
1392 void BvshlNode::initHash(
void) {
1396 if (s) this->hash = this->hash * s;
1433 this->
eval = (op1Signed <= op2Signed);
1439 this->
children[index]->setParent(
this);
1453 void BvsleNode::initHash(
void) {
1457 if (s) this->hash = this->hash * s;
1494 this->
eval = (op1Signed < op2Signed);
1500 this->
children[index]->setParent(
this);
1514 void BvsltNode::initHash(
void) {
1518 if (s) this->hash = this->hash * s;
1565 this->
children[index]->setParent(
this);
1579 void BvsmodNode::initHash(
void) {
1583 if (s) this->hash = this->hash * s;
1630 this->
children[index]->setParent(
this);
1644 void BvsremNode::initHash(
void) {
1648 if (s) this->hash = this->hash * s;
1684 this->
children[index]->setParent(
this);
1698 void BvsubNode::initHash(
void) {
1702 if (s) this->hash = this->hash * s;
1742 this->
children[index]->setParent(
this);
1756 void BvudivNode::initHash(
void) {
1760 if (s) this->hash = this->hash * s;
1796 this->
children[index]->setParent(
this);
1810 void BvugeNode::initHash(
void) {
1814 if (s) this->hash = this->hash * s;
1850 this->
children[index]->setParent(
this);
1864 void BvugtNode::initHash(
void) {
1868 if (s) this->hash = this->hash * s;
1904 this->
children[index]->setParent(
this);
1918 void BvuleNode::initHash(
void) {
1922 if (s) this->hash = this->hash * s;
1958 this->
children[index]->setParent(
this);
1972 void BvultNode::initHash(
void) {
1976 if (s) this->hash = this->hash * s;
2016 this->
children[index]->setParent(
this);
2030 void BvuremNode::initHash(
void) {
2034 if (s) this->hash = this->hash * s;
2070 this->
children[index]->setParent(
this);
2084 void BvxnorNode::initHash(
void) {
2088 if (s) this->hash = this->hash * s;
2090 this->hash = this->hash * this->
children[index]->getHash();
2124 this->
children[index]->setParent(
this);
2138 void BvxorNode::initHash(
void) {
2142 if (s) this->hash = this->hash * s;
2144 this->hash = this->hash * this->
children[index]->getHash();
2156 this->
addChild(this->ctxt->integer(value & this->getBitvectorMask()));
2168 value = triton::ast::getInteger<triton::uint512>(this->
children[0]);
2169 size = triton::ast::getInteger<triton::uint32>(this->
children[1]);
2185 this->
children[index]->setParent(
this);
2199 void BvNode::initHash(
void) {
2203 if (s) this->hash = this->hash * s;
2227 this->
children[index]->setParent(
this);
2241 void CompoundNode::initHash(
void) {
2245 if (s) this->hash = this->hash * s;
2272 this->
size += this->
children[index]->getBitvectorSize();
2276 throw triton::exceptions::Ast(
"ConcatNode::init(): Size cannot be greater than triton::bitsize::max_supported.");
2287 this->
children[index]->setParent(
this);
2301 void ConcatNode::initHash(
void) {
2305 if (s) this->hash = this->hash * s;
2327 throw triton::exceptions::Ast(
"DeclareNode::init(): The child node must be a VARIABLE_NODE or an ARRAY_NODE.");
2337 this->
children[index]->setParent(
this);
2351 void DeclareNode::initHash(
void) {
2355 if (s) this->hash = this->hash * s;
2391 this->
children[index]->setParent(
this);
2405 void DistinctNode::initHash(
void) {
2409 if (s) this->hash = this->hash * s;
2411 this->hash = this->hash * this->
children[index]->getHash();
2445 this->
children[index]->setParent(
this);
2459 void EqualNode::initHash(
void) {
2463 if (s) this->hash = this->hash * s;
2465 this->hash = this->hash * this->
children[index]->getHash();
2492 high = triton::ast::getInteger<triton::uint32>(this->
children[0]);
2493 low = triton::ast::getInteger<triton::uint32>(this->
children[1]);
2499 this->
size = ((high - low) + 1);
2505 throw triton::exceptions::Ast(
"ExtractNode::init(): The size of the extraction is higher than the child expression.");
2509 this->
children[index]->setParent(
this);
2523 void ExtractNode::initHash(
void) {
2527 if (s) this->hash = this->hash * s;
2560 this->
children[index]->setParent(
this);
2574 void ForallNode::initHash(
void) {
2578 if (s) this->hash = this->hash * s;
2611 this->
eval = (P && Q) || (!P && !Q);
2617 this->
children[index]->setParent(
this);
2631 void IffNode::initHash(
void) {
2635 if (s) this->hash = this->hash * s;
2648 this->value = value;
2673 void IntegerNode::initHash(
void) {
2675 if ((this->value & 1) == 0) {
2701 throw triton::exceptions::Ast(
"IteNode::init(): Must take two nodes of same size as 'then' and 'else' branches.");
2707 throw triton::exceptions::Ast(
"IteNode::init(): Must take either two logical nodes or two bv nodes as 'then' and 'else' branches.");
2718 this->
children[index]->setParent(
this);
2738 void IteNode::initHash(
void) {
2742 if (s) this->hash = this->hash * s;
2775 this->
children[index]->setParent(
this);
2790 void LandNode::initHash(
void) {
2794 if (s) this->hash = this->hash * s;
2796 this->hash = this->hash * this->
children[index]->getHash();
2828 this->
children[index]->setParent(
this);
2842 void LetNode::initHash(
void) {
2846 if (s) this->hash = this->hash * s;
2878 this->
children[index]->setParent(
this);
2892 void LnotNode::initHash(
void) {
2896 if (s) this->hash = this->hash * s;
2898 this->hash = this->hash * this->
children[index]->getHash();
2929 this->
children[index]->setParent(
this);
2944 void LorNode::initHash(
void) {
2948 if (s) this->hash = this->hash * s;
2950 this->hash = this->hash * this->
children[index]->getHash();
2981 this->
children[index]->setParent(
this);
2996 void LxorNode::initHash(
void) {
3000 if (s) this->hash = this->hash * s;
3002 this->hash = this->hash * this->
children[index]->getHash();
3020 this->
array = this->expr->getAst()->isArray();
3021 this->
eval = this->expr->getAst()->evaluate();
3022 this->
logical = this->expr->getAst()->isLogical();
3023 this->
size = this->expr->getAst()->getBitvectorSize();
3024 this->
symbolized = this->expr->getAst()->isSymbolized();
3025 this->
level = 1 + this->expr->getAst()->getLevel();
3027 this->expr->getAst()->setParent(
this);
3038 void ReferenceNode::initHash(
void) {
3039 this->hash = this->expr->getAst()->getHash();
3078 switch(node->getType()) {
3091 this->
children[index]->setParent(
this);
3105 void SelectNode::initHash(
void) {
3109 if (s) this->hash = this->hash * s;
3111 this->hash = this->hash * this->
children[index]->getHash();
3143 throw triton::exceptions::Ast(
"StoreNode::init(): Size of indexing must be equal to the array indexing size.");
3156 switch(node->getType()) {
3174 this->
children[index]->setParent(
this);
3188 void StoreNode::initHash(
void) {
3192 if (s) this->hash = this->hash * s;
3194 this->hash = this->hash * this->
children[index]->getHash();
3202 if (this->memory.find(addr) != this->memory.end()) {
3203 return this->memory.at(addr);
3220 return this->memory;
3225 return this->indexSize;
3233 this->value = value;
3253 std::string StringNode::getString(
void) {
3258 void StringNode::initHash(
void) {
3262 for (std::string::const_iterator it=this->value.cbegin(); it != this->value.cend(); it++) {
3288 sizeExt = triton::ast::getInteger<triton::uint32>(this->
children[0]);
3291 this->
size = sizeExt + this->
children[1]->getBitvectorSize();
3293 throw triton::exceptions::Ast(
"SxNode::SxNode(): Size cannot be greater than triton::bitsize::max_supported.");
3297 this->
eval = ((((this->
children[1]->evaluate() >> (this->
children[1]->getBitvectorSize()-1)) == 0) ?
3302 this->
children[index]->setParent(
this);
3316 void SxNode::initHash(
void) {
3320 if (s) this->hash = this->hash * s;
3339 this->
size = this->symVar->getSize();
3354 return this->symVar;
3358 void VariableNode::initHash(
void) {
3363 for (
char c : this->symVar->getName()) {
3389 sizeExt = triton::ast::getInteger<triton::uint32>(this->
children[0]);
3392 this->
size = sizeExt + this->
children[1]->getBitvectorSize();
3402 this->
children[index]->setParent(
this);
3416 void ZxNode::initHash(
void) {
3420 if (s) this->hash = this->hash * s;
3438 template TRITON_EXPORT CompoundNode::CompoundNode(
const std::list<SharedAbstractNode>& exprs,
const SharedAstContext& ctxt);
3439 template TRITON_EXPORT CompoundNode::CompoundNode(
const std::vector<SharedAbstractNode>& exprs,
const SharedAstContext& ctxt);
3440 template TRITON_EXPORT ConcatNode::ConcatNode(
const std::list<SharedAbstractNode>& exprs,
const SharedAstContext& ctxt);
3441 template TRITON_EXPORT ConcatNode::ConcatNode(
const std::vector<SharedAbstractNode>& exprs,
const SharedAstContext& ctxt);
3442 template TRITON_EXPORT ForallNode::ForallNode(
const std::list<SharedAbstractNode>& vars,
const SharedAbstractNode& body);
3443 template TRITON_EXPORT ForallNode::ForallNode(
const std::vector<SharedAbstractNode>& vars,
const SharedAbstractNode& body);
3444 template TRITON_EXPORT LandNode::LandNode(
const std::list<SharedAbstractNode>& exprs,
const SharedAstContext& ctxt);
3445 template TRITON_EXPORT LandNode::LandNode(
const std::vector<SharedAbstractNode>& exprs,
const SharedAstContext& ctxt);
3446 template TRITON_EXPORT LorNode::LorNode(
const std::list<SharedAbstractNode>& exprs,
const SharedAstContext& ctxt);
3447 template TRITON_EXPORT LorNode::LorNode(
const std::vector<SharedAbstractNode>& exprs,
const SharedAstContext& ctxt);
3448 template TRITON_EXPORT LxorNode::LxorNode(
const std::list<SharedAbstractNode>& exprs,
const SharedAstContext& ctxt);
3449 template TRITON_EXPORT LxorNode::LxorNode(
const std::vector<SharedAbstractNode>& exprs,
const SharedAstContext& ctxt);
3463 return node->
getContext()->print(stream, node);
3479 hash = ((hash * hash) & mask);
3485 if ((shift &= 511) == 0)
3487 return ((value << shift) | (value >> (512 - shift))) | 1;
3519 if (node ==
nullptr)
3522 switch (node->getType()) {
3523 case ARRAY_NODE: newNode = std::make_shared<ArrayNode>(*
reinterpret_cast<ArrayNode*
>(node));
break;
3524 case ASSERT_NODE: newNode = std::make_shared<AssertNode>(*
reinterpret_cast<AssertNode*
>(node));
break;
3525 case BSWAP_NODE: newNode = std::make_shared<BswapNode>(*
reinterpret_cast<BswapNode*
>(node));
break;
3526 case BVADD_NODE: newNode = std::make_shared<BvaddNode>(*
reinterpret_cast<BvaddNode*
>(node));
break;
3527 case BVAND_NODE: newNode = std::make_shared<BvandNode>(*
reinterpret_cast<BvandNode*
>(node));
break;
3528 case BVASHR_NODE: newNode = std::make_shared<BvashrNode>(*
reinterpret_cast<BvashrNode*
>(node));
break;
3529 case BVLSHR_NODE: newNode = std::make_shared<BvlshrNode>(*
reinterpret_cast<BvlshrNode*
>(node));
break;
3530 case BVMUL_NODE: newNode = std::make_shared<BvmulNode>(*
reinterpret_cast<BvmulNode*
>(node));
break;
3531 case BVNAND_NODE: newNode = std::make_shared<BvnandNode>(*
reinterpret_cast<BvnandNode*
>(node));
break;
3532 case BVNEG_NODE: newNode = std::make_shared<BvnegNode>(*
reinterpret_cast<BvnegNode*
>(node));
break;
3533 case BVNOR_NODE: newNode = std::make_shared<BvnorNode>(*
reinterpret_cast<BvnorNode*
>(node));
break;
3534 case BVNOT_NODE: newNode = std::make_shared<BvnotNode>(*
reinterpret_cast<BvnotNode*
>(node));
break;
3535 case BVOR_NODE: newNode = std::make_shared<BvorNode>(*
reinterpret_cast<BvorNode*
>(node));
break;
3536 case BVROL_NODE: newNode = std::make_shared<BvrolNode>(*
reinterpret_cast<BvrolNode*
>(node));
break;
3537 case BVROR_NODE: newNode = std::make_shared<BvrorNode>(*
reinterpret_cast<BvrorNode*
>(node));
break;
3538 case BVSDIV_NODE: newNode = std::make_shared<BvsdivNode>(*
reinterpret_cast<BvsdivNode*
>(node));
break;
3539 case BVSGE_NODE: newNode = std::make_shared<BvsgeNode>(*
reinterpret_cast<BvsgeNode*
>(node));
break;
3540 case BVSGT_NODE: newNode = std::make_shared<BvsgtNode>(*
reinterpret_cast<BvsgtNode*
>(node));
break;
3541 case BVSHL_NODE: newNode = std::make_shared<BvshlNode>(*
reinterpret_cast<BvshlNode*
>(node));
break;
3542 case BVSLE_NODE: newNode = std::make_shared<BvsleNode>(*
reinterpret_cast<BvsleNode*
>(node));
break;
3543 case BVSLT_NODE: newNode = std::make_shared<BvsltNode>(*
reinterpret_cast<BvsltNode*
>(node));
break;
3544 case BVSMOD_NODE: newNode = std::make_shared<BvsmodNode>(*
reinterpret_cast<BvsmodNode*
>(node));
break;
3545 case BVSREM_NODE: newNode = std::make_shared<BvsremNode>(*
reinterpret_cast<BvsremNode*
>(node));
break;
3546 case BVSUB_NODE: newNode = std::make_shared<BvsubNode>(*
reinterpret_cast<BvsubNode*
>(node));
break;
3547 case BVUDIV_NODE: newNode = std::make_shared<BvudivNode>(*
reinterpret_cast<BvudivNode*
>(node));
break;
3548 case BVUGE_NODE: newNode = std::make_shared<BvugeNode>(*
reinterpret_cast<BvugeNode*
>(node));
break;
3549 case BVUGT_NODE: newNode = std::make_shared<BvugtNode>(*
reinterpret_cast<BvugtNode*
>(node));
break;
3550 case BVULE_NODE: newNode = std::make_shared<BvuleNode>(*
reinterpret_cast<BvuleNode*
>(node));
break;
3551 case BVULT_NODE: newNode = std::make_shared<BvultNode>(*
reinterpret_cast<BvultNode*
>(node));
break;
3552 case BVUREM_NODE: newNode = std::make_shared<BvuremNode>(*
reinterpret_cast<BvuremNode*
>(node));
break;
3553 case BVXNOR_NODE: newNode = std::make_shared<BvxnorNode>(*
reinterpret_cast<BvxnorNode*
>(node));
break;
3554 case BVXOR_NODE: newNode = std::make_shared<BvxorNode>(*
reinterpret_cast<BvxorNode*
>(node));
break;
3555 case BV_NODE: newNode = std::make_shared<BvNode>(*
reinterpret_cast<BvNode*
>(node));
break;
3556 case COMPOUND_NODE: newNode = std::make_shared<CompoundNode>(*
reinterpret_cast<CompoundNode*
>(node));
break;
3557 case CONCAT_NODE: newNode = std::make_shared<ConcatNode>(*
reinterpret_cast<ConcatNode*
>(node));
break;
3558 case DECLARE_NODE: newNode = std::make_shared<DeclareNode>(*
reinterpret_cast<DeclareNode*
>(node));
break;
3559 case DISTINCT_NODE: newNode = std::make_shared<DistinctNode>(*
reinterpret_cast<DistinctNode*
>(node));
break;
3560 case EQUAL_NODE: newNode = std::make_shared<EqualNode>(*
reinterpret_cast<EqualNode*
>(node));
break;
3561 case EXTRACT_NODE: newNode = std::make_shared<ExtractNode>(*
reinterpret_cast<ExtractNode*
>(node));
break;
3562 case FORALL_NODE: newNode = std::make_shared<ForallNode>(*
reinterpret_cast<ForallNode*
>(node));
break;
3563 case IFF_NODE: newNode = std::make_shared<IffNode>(*
reinterpret_cast<IffNode*
>(node));
break;
3564 case INTEGER_NODE: newNode = std::make_shared<IntegerNode>(*
reinterpret_cast<IntegerNode*
>(node));
break;
3565 case ITE_NODE: newNode = std::make_shared<IteNode>(*
reinterpret_cast<IteNode*
>(node));
break;
3566 case LAND_NODE: newNode = std::make_shared<LandNode>(*
reinterpret_cast<LandNode*
>(node));
break;
3567 case LET_NODE: newNode = std::make_shared<LetNode>(*
reinterpret_cast<LetNode*
>(node));
break;
3568 case LNOT_NODE: newNode = std::make_shared<LnotNode>(*
reinterpret_cast<LnotNode*
>(node));
break;
3569 case LOR_NODE: newNode = std::make_shared<LorNode>(*
reinterpret_cast<LorNode*
>(node));
break;
3570 case LXOR_NODE: newNode = std::make_shared<LxorNode>(*
reinterpret_cast<LxorNode*
>(node));
break;
3573 return triton::ast::shallowCopy(
reinterpret_cast<ReferenceNode*
>(node)->getSymbolicExpression()->getAst().get(), unroll);
3575 newNode = std::make_shared<ReferenceNode>(*
reinterpret_cast<ReferenceNode*
>(node));
3578 case SELECT_NODE: newNode = std::make_shared<SelectNode>(*
reinterpret_cast<SelectNode*
>(node));
break;
3579 case STORE_NODE: newNode = std::make_shared<StoreNode>(*
reinterpret_cast<StoreNode*
>(node));
break;
3580 case STRING_NODE: newNode = std::make_shared<StringNode>(*
reinterpret_cast<StringNode*
>(node));
break;
3581 case SX_NODE: newNode = std::make_shared<SxNode>(*
reinterpret_cast<SxNode*
>(node));
break;
3582 case VARIABLE_NODE: newNode = node->shared_from_this();
break;
3583 case ZX_NODE: newNode = std::make_shared<ZxNode>(*
reinterpret_cast<ZxNode*
>(node));
break;
3588 if (newNode ==
nullptr)
3592 if (node->getType() != VARIABLE_NODE) {
3594 auto parents = newNode->getParents();
3595 for (
auto& p : parents) {
3596 newNode->removeParent(p.get());
3600 return node->getContext()->collect(newNode);
3605 std::unordered_map<AbstractNode*, SharedAbstractNode> exprs;
3608 for (
auto&& n : nodes) {
3610 const auto& newNode = shallowCopy(n.get(),
unroll);
3611 exprs[n.get()] = newNode;
3614 auto& children = newNode->getChildren();
3615 for (
auto& child : children) {
3616 child = exprs[child.get()];
3617 child->setParent(newNode.get());
3622 return exprs.at(node);
3641 static std::vector<SharedAbstractNode> nodesExtraction(
const SharedAbstractNode& node,
bool unroll,
bool revert,
bool descend) {
3642 std::vector<SharedAbstractNode> result;
3643 std::unordered_set<AbstractNode*> visited;
3644 std::stack<std::pair<SharedAbstractNode, bool>> worklist;
3646 if (node ==
nullptr)
3653 worklist.push({node,
false});
3655 while (!worklist.empty()) {
3656 SharedAbstractNode ast;
3658 std::tie(ast, postOrder) = worklist.top();
3663 result.push_back(ast);
3667 if (!visited.insert(ast.get()).second) {
3671 worklist.push({ast,
true});
3673 const auto& relatives = descend ? ast->getChildren() : ast->getParents();
3676 for (
const auto& r : relatives) {
3677 if (visited.find(r.get()) == visited.end()) {
3678 worklist.push({r,
false});
3683 if (unroll && ast->getType() == REFERENCE_NODE) {
3684 const SharedAbstractNode& ref =
reinterpret_cast<ReferenceNode*
>(ast.get())->getSymbolicExpression()->getAst();
3685 if (visited.find(ref.get()) == visited.end()) {
3686 worklist.push({ref,
false});
3693 std::reverse(result.begin(), result.end());
3701 return nodesExtraction(node,
unroll, revert,
true);
3706 return nodesExtraction(node,
false, revert,
false);
3711 std::stack<AbstractNode*> worklist;
3712 std::deque<SharedAbstractNode> result;
3713 std::unordered_set<const AbstractNode*> visited;
3715 worklist.push(node.get());
3716 while (!worklist.empty()) {
3721 if (visited.find(current) != visited.end()) {
3725 visited.insert(current);
3727 result.push_front(current->shared_from_this());
3734 worklist.push(child.get());
3748 ptr = ref->getSymbolicExpression()->getAst().get();
3751 return ptr->shared_from_this();
3757 switch(nref->getType()) {
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.
TRITON_EXPORT triton::uint32 getLevel(void) const
Returns the deep level of the tree.
bool symbolized
True if the tree contains a symbolic variable.
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.
TRITON_EXPORT SharedAstContext getContext(void) const
Access to its context.
TRITON_EXPORT AbstractNode(triton::ast::ast_e type, const SharedAstContext &ctxt)
Constructor.
triton::ast::ast_e type
The type of the node.
TRITON_EXPORT void setParent(AbstractNode *p)
Sets a parent node.
TRITON_EXPORT bool equalTo(const SharedAbstractNode &other) const
Returns true if the current tree is equal to the second one.
TRITON_EXPORT void setChild(triton::uint32 index, const SharedAbstractNode &child)
Sets a child at an index.
TRITON_EXPORT bool isSigned(void) const
According to the size of the expression, returns true if the MSB is 1.
TRITON_EXPORT std::vector< SharedAbstractNode > getParents(void)
Returns the parents of node or an empty set if there is still no parent defined.
TRITON_EXPORT triton::uint512 getHash(void) const
Returns the hash of the tree.
bool array
True if it's an array node.
SharedAstContext ctxt
Contect use to create this node.
TRITON_EXPORT triton::uint512 getBitvectorMask(void) const
Returns the vector mask according the size of the node.
TRITON_EXPORT bool isArray(void) const
Returns true if it's an array node.
virtual TRITON_EXPORT ~AbstractNode()
Destructor.
triton::uint32 size
The size of the node.
TRITON_EXPORT bool isSymbolized(void) const
Returns true if the tree contains a symbolic variable.
std::vector< SharedAbstractNode > children
The children of the node.
TRITON_EXPORT triton::uint32 getBitvectorSize(void) const
Returns the size of the node.
TRITON_EXPORT bool isLogical(void) const
Returns true if it's a logical node.
TRITON_EXPORT std::vector< SharedAbstractNode > & getChildren(void)
Returns the children of the node.
bool logical
True if it's a logical node.
TRITON_EXPORT void setBitvectorSize(triton::uint32 size)
Sets the size of the node.
triton::uint512 eval
The value of the tree from this root node.
triton::uint512 hash
The hash of the tree.
TRITON_EXPORT std::string str(void) const
Returns the string representation of the node.
TRITON_EXPORT void addChild(const SharedAbstractNode &child)
Adds a child.
TRITON_EXPORT void removeParent(AbstractNode *p)
Removes a parent node.
void initParents(void)
Initializes parents.
TRITON_EXPORT triton::uint512 evaluate(void) const
Evaluates the tree.
TRITON_EXPORT triton::ast::ast_e getType(void) const
Returns the type of the node.
triton::uint32 level
Deep level for computing hash.
(Array (_ BitVec indexSize) (_ BitVec 8)) node
TRITON_EXPORT void store(triton::uint64 addr, triton::uint8 value)
Stores a concrete value into the memory array.
TRITON_EXPORT triton::uint8 select(triton::uint64 addr) const
Select a concrete value into the memory array.
TRITON_EXPORT triton::uint32 getIndexSize(void) const
Gets the index size.
TRITON_EXPORT std::unordered_map< triton::uint64, triton::uint8 > & getMemory(void)
Gets the concrete memory array.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT triton::uint32 getIndexSize(void) const
Gets the index size.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT std::unordered_map< triton::uint64, triton::uint8 > & getMemory(void)
Gets the concrete memory array.
TRITON_EXPORT triton::uint8 select(triton::uint64 addr) const
Select a concrete value into the memory array.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
TRITON_EXPORT ZxNode(triton::uint32 sizeExt, const SharedAbstractNode &expr)
Create a zero extend of expr to sizeExt bits.
TRITON_EXPORT void init(bool withParents=false)
Init properties of the node. If withParents is true, init also properties of parents.
The exception class used by all AST nodes.
triton::uint32 getIndexSize(const SharedAbstractNode &node)
Gets the index size of an array.
SharedAbstractNode unroll(const triton::ast::SharedAbstractNode &node)
AST C++ API - Unrolls the SSA form of a given AST.
SharedAbstractNode dereference(const SharedAbstractNode &node)
Returns the first non referene node encountered.
triton::uint512 hash2n(triton::uint512 hash, triton::uint32 n)
Custom hash2n function for hash routine.
std::vector< SharedAbstractNode > parentsExtraction(const SharedAbstractNode &node, bool revert)
Returns node and all its parents of an AST sorted topologically. If revert is true,...
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,...
std::shared_ptr< triton::ast::AbstractNode > SharedAbstractNode
Shared Abstract Node.
std::weak_ptr< triton::ast::AbstractNode > WeakAbstractNode
Weak Abstract Node.
SharedAbstractNode newInstance(AbstractNode *node, bool unroll)
AST C++ API - Duplicates the AST.
std::shared_ptr< triton::ast::AstContext > SharedAstContext
Shared AST context.
triton::sint512 modularSignExtend(AbstractNode *node)
Custom modular sign extend for bitwise operation.
std::deque< SharedAbstractNode > search(const SharedAbstractNode &node, triton::ast::ast_e match)
Returns a deque of collected matched nodes via a depth-first pre order traversal.
triton::uint512 rotl(const triton::uint512 &value, triton::uint32 shift)
Custom rotate left function for hash routine.
constexpr triton::uint32 byte
byte size in bit
constexpr triton::uint32 max_supported
max size supported in bit
std::shared_ptr< triton::engines::symbolic::SymbolicExpression > SharedSymbolicExpression
Shared Symbolic Expression.
std::shared_ptr< triton::engines::symbolic::SymbolicVariable > SharedSymbolicVariable
Shared Symbolic variable.
std::size_t usize
unsigned MAX_INT 32 or 64 bits according to the CPU.
std::uint64_t uint64
unisgned 64-bits
math::wide_integer::uint512_t uint512
unsigned 512-bits
std::uint32_t uint32
unisgned 32-bits
std::uint8_t uint8
unisgned 8-bits