29 this->valueMapping.clear();
35 std::enable_shared_from_this<AstContext>::operator=(other);
37 this->astRepresentation = other.astRepresentation;
38 this->modes = other.modes;
39 this->nodes = other.nodes;
40 this->valueMapping = other.valueMapping;
58 if (lvl != 0 && (lvl % 10000) == 0) {
59 this->nodes.push_front(node);
66 this->nodes.erase(std::remove_if(this->nodes.begin(), this->nodes.end(),
68 return (n.use_count() == 1 ? true : false);
75 SharedAbstractNode node = std::make_shared<ArrayNode>(indexSize, this->shared_from_this());
102 SharedAbstractNode node = std::make_shared<BvNode>(value, size, this->shared_from_this());
113 if (!expr1->isSymbolized() && expr1->evaluate() == 0)
117 if (!expr2->isSymbolized() && expr2->evaluate() == 0)
127 if (node->isSymbolized() ==
false) {
128 return this->
bv(node->evaluate(), node->getBitvectorSize());
139 if (!expr1->isSymbolized() && expr1->evaluate() == 0)
140 return this->
bv(0, expr1->getBitvectorSize());
143 if (!expr2->isSymbolized() && expr2->evaluate() == 0)
144 return this->
bv(0, expr1->getBitvectorSize());
147 if (!expr2->isSymbolized() && expr2->evaluate() == expr2->getBitvectorMask())
151 if (!expr1->isSymbolized() && expr1->evaluate() == expr1->getBitvectorMask())
155 if (!expr1->isSymbolized() && !expr2->isSymbolized() && expr1->equalTo(expr2))
165 if (node->isSymbolized() ==
false) {
166 return this->
bv(node->evaluate(), node->getBitvectorSize());
177 if (!expr1->isSymbolized() && expr1->evaluate() == 0)
178 return this->
bv(0, expr1->getBitvectorSize());
181 if (!expr2->isSymbolized() && expr2->evaluate() == 0)
191 if (node->isSymbolized() ==
false) {
192 return this->
bv(node->evaluate(), node->getBitvectorSize());
212 if (!expr1->isSymbolized() && expr1->evaluate() == 0)
213 return this->
bv(0, expr1->getBitvectorSize());
216 if (!expr2->isSymbolized() && expr2->evaluate() == 0)
220 if (!expr2->isSymbolized() && expr2->evaluate() >= expr1->getBitvectorSize())
221 return this->
bv(0, expr1->getBitvectorSize());
230 if (node->isSymbolized() ==
false) {
231 return this->
bv(node->evaluate(), node->getBitvectorSize());
242 if (!expr1->isSymbolized() && expr1->evaluate() == 0)
243 return this->
bv(0, expr1->getBitvectorSize());
246 if (!expr2->isSymbolized() && expr2->evaluate() == 0)
247 return this->
bv(0, expr1->getBitvectorSize());
250 if (!expr1->isSymbolized() && expr1->evaluate() == 1)
254 if (!expr2->isSymbolized() && expr2->evaluate() == 1)
264 if (node->isSymbolized() ==
false) {
265 return this->
bv(node->evaluate(), node->getBitvectorSize());
280 if (node->isSymbolized() ==
false) {
281 return this->
bv(node->evaluate(), node->getBitvectorSize());
296 if (node->isSymbolized() ==
false) {
297 return this->
bv(node->evaluate(), node->getBitvectorSize());
312 if (node->isSymbolized() ==
false) {
313 return this->
bv(node->evaluate(), node->getBitvectorSize());
328 if (node->isSymbolized() ==
false) {
329 return this->
bv(node->evaluate(), node->getBitvectorSize());
340 if (!expr1->isSymbolized() && expr1->evaluate() == 0)
344 if (!expr2->isSymbolized() && expr2->evaluate() == 0)
348 if (!expr1->isSymbolized() && expr1->evaluate() == expr1->getBitvectorMask())
349 return this->
bv(expr1->getBitvectorMask(), expr1->getBitvectorSize());
352 if (!expr2->isSymbolized() && expr2->evaluate() == expr2->getBitvectorMask())
353 return this->
bv(expr2->getBitvectorMask(), expr2->getBitvectorSize());
356 if (expr1->equalTo(expr2))
366 if (node->isSymbolized() ==
false) {
367 return this->
bv(node->evaluate(), node->getBitvectorSize());
382 if (node->isSymbolized() ==
false) {
383 return this->
bv(node->evaluate(), node->getBitvectorSize());
400 auto size = expr->getBitvectorSize();
401 auto bvsize = this->
bv(size, size);
402 const auto& node = this->
bvor(
416 if (node->isSymbolized() ==
false) {
417 return this->
bv(node->evaluate(), node->getBitvectorSize());
432 if (node->isSymbolized() ==
false) {
433 return this->
bv(node->evaluate(), node->getBitvectorSize());
450 auto size = expr->getBitvectorSize();
451 auto bvsize = this->
bv(size, size);
452 const auto& node = this->
bvor(
466 if (node->isSymbolized() ==
false) {
467 return this->
bv(node->evaluate(), node->getBitvectorSize());
478 if (!expr2->isSymbolized() && expr2->evaluate() == 1)
488 if (node->isSymbolized() ==
false) {
489 return this->
bv(node->evaluate(), node->getBitvectorSize());
518 if (!expr1->isSymbolized() && expr1->evaluate() == 0)
519 return this->
bv(0, expr1->getBitvectorSize());
522 if (!expr2->isSymbolized() && expr2->evaluate() == 0)
526 if (!expr2->isSymbolized() && expr2->evaluate() >= expr1->getBitvectorSize())
527 return this->
bv(0, expr1->getBitvectorSize());
536 if (node->isSymbolized() ==
false) {
537 return this->
bv(node->evaluate(), node->getBitvectorSize());
570 if (node->isSymbolized() ==
false) {
571 return this->
bv(node->evaluate(), node->getBitvectorSize());
586 if (node->isSymbolized() ==
false) {
587 return this->
bv(node->evaluate(), node->getBitvectorSize());
598 if (!expr2->isSymbolized() && expr2->evaluate() == 0)
602 if (!expr1->isSymbolized() && expr1->evaluate() == 0)
603 return this->
bvneg(expr2);
606 if (expr1->equalTo(expr2))
607 return this->
bv(0, expr1->getBitvectorSize());
616 if (node->isSymbolized() ==
false) {
617 return this->
bv(node->evaluate(), node->getBitvectorSize());
637 if (!expr2->isSymbolized() && expr2->evaluate() == 1)
647 if (node->isSymbolized() ==
false) {
648 return this->
bv(node->evaluate(), node->getBitvectorSize());
699 if (node->isSymbolized() ==
false) {
700 return this->
bv(node->evaluate(), node->getBitvectorSize());
715 if (node->isSymbolized() ==
false) {
716 return this->
bv(node->evaluate(), node->getBitvectorSize());
727 if (!expr2->isSymbolized() && expr2->evaluate() == 0)
731 if (!expr1->isSymbolized() && expr1->evaluate() == 0)
735 if (expr1->equalTo(expr2))
736 return this->
bv(0, expr1->getBitvectorSize());
745 if (node->isSymbolized() ==
false) {
746 return this->
bv(node->evaluate(), node->getBitvectorSize());
765 if (node->isSymbolized() ==
false) {
766 return this->
bv(node->evaluate(), node->getBitvectorSize());
772 SharedAbstractNode n = this->simplify_concat(std::vector<SharedAbstractNode>({expr1, expr2}));
815 if (low == 0 && (high + 1) == expr->getBitvectorSize())
831 if (node->isSymbolized() ==
false) {
832 return this->
bv(node->evaluate(), node->getBitvectorSize());
854 SharedAbstractNode node = std::make_shared<IntegerNode>(value, this->shared_from_this());
866 if (!ifExpr->isSymbolized()) {
867 return ifExpr->evaluate() ? thenExpr : elseExpr;
983 SharedAbstractNode node = std::make_shared<StringNode>(value, this->shared_from_this());
1002 if (node->isSymbolized() ==
false) {
1003 return this->
bv(node->evaluate(), node->getBitvectorSize());
1013 auto it = this->valueMapping.find(symVar->getName());
1014 if (it != this->valueMapping.end()) {
1015 if (
auto node = it->second.first.lock()) {
1016 if (node->getBitvectorSize() != symVar->getSize()) {
1026 SharedAbstractNode node = std::make_shared<VariableNode>(symVar, this->shared_from_this());
1028 if (node ==
nullptr) {
1043 if (node ==
nullptr)
1048 if (node->isSymbolized() ==
false) {
1049 return this->
bv(node->evaluate(), node->getBitvectorSize());
1058 auto it = this->valueMapping.find(name);
1059 if (it == this->valueMapping.end()) {
1060 this->valueMapping.insert(std::make_pair(name, std::make_pair(node, value)));
1069 auto it = this->valueMapping.find(name);
1070 if (it != this->valueMapping.end()) {
1071 if (
auto node = it->second.first.lock()) {
1072 it->second.second = value;
1073 node->initParents();
1080 throw triton::exceptions::Ast(
"AstContext::updateVariable(): This symbolic variable is not assigned at any AbstractNode or does not exist.");
1086 auto it = this->valueMapping.find(name);
1087 if (it != this->valueMapping.end()) {
1088 if (
auto node = it->second.first.lock())
1099 auto it = this->valueMapping.find(name);
1100 if (it != this->valueMapping.end()) {
1101 if (
auto node = it->second.first.lock())
1102 return it->second.second;
1112 this->astRepresentation.
setMode(mode);
1117 return this->astRepresentation.
getMode();
1122 return this->astRepresentation.
print(stream, node);
1126 SharedAbstractNode AstContext::simplify_concat(std::vector<SharedAbstractNode> exprs) {
1145 while (!exprs.empty()) {
1156 exprs.push_back(part);
1167 const auto& childs = n->getChildren();
1168 triton::uint32 hi = triton::ast::getInteger<triton::uint32>(childs[0]);
1169 triton::uint32 lo = triton::ast::getInteger<triton::uint32>(childs[1]);
1182 ast_ref = childs[2];
1192 if (high + 1 != lo || !n->equalTo(ast_node)) {
1203 return this->
extract(high, low, ast_ref);
1210 if (high <= low || high >= size) {
1240 if (hi == high && lo == low) {
1244 if (hi >= high && lo <= low) {
1269 n = n->getChildren()[1];
1271 if (low == 0 && high + 1 == sz) {
1294 const auto& childs = n->getChildren();
1295 triton::uint32 hi = triton::ast::getInteger<triton::uint32>(childs[0]);
1296 triton::uint32 lo = triton::ast::getInteger<triton::uint32>(childs[1]);
1297 if (lo + high <= hi) {
1304 return node == expr ? 0 : this->
extract(high, low, node);
AST Context - Used as AST builder.
TRITON_EXPORT void setRepresentationMode(triton::ast::representations::mode_e mode)
Sets the representation mode for this astContext.
TRITON_EXPORT SharedAbstractNode bvsgt(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvsgt node builder.
TRITON_EXPORT SharedAbstractNode bvmul(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvmul node builder.
TRITON_EXPORT SharedAbstractNode bvnand(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvnand node builder.
TRITON_EXPORT SharedAbstractNode bvsub(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvsub node builder.
TRITON_EXPORT SharedAbstractNode distinct(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - distinct node builder.
TRITON_EXPORT SharedAbstractNode land(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - land node builder.
TRITON_EXPORT void garbage(void)
Garbage unused nodes.
TRITON_EXPORT SharedAbstractNode bvuge(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvuge node builder.
TRITON_EXPORT SharedAbstractNode bvshl(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvshl node builder.
SharedAbstractNode compound(const T &exprs)
AST C++ API - compound node builder.
TRITON_EXPORT SharedAbstractNode iff(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - iff node builder.
TRITON_EXPORT SharedAbstractNode bvfalse(void)
AST C++ API - bvfalse node builder.
TRITON_EXPORT SharedAbstractNode bvxnor(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvxnor node builder.
TRITON_EXPORT SharedAbstractNode bvor(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvor node builder.
TRITON_EXPORT SharedAbstractNode bvrol(const SharedAbstractNode &expr, triton::uint32 rot)
AST C++ API - bvrol node builder.
TRITON_EXPORT ~AstContext()
Destructor.
TRITON_EXPORT AstContext & operator=(const AstContext &other)
Operator.
TRITON_EXPORT AstContext(const triton::modes::SharedModes &modes)
Constructor.
TRITON_EXPORT SharedAbstractNode bvule(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvule node builder.
TRITON_EXPORT SharedAbstractNode store(const SharedAbstractNode &array, triton::usize index, const SharedAbstractNode &expr)
AST C++ API - store node builder.
TRITON_EXPORT SharedAbstractNode concat(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - concat node builder.
SharedAbstractNode forall(const T &vars, const SharedAbstractNode &body)
AST C++ API - forall node builder.
TRITON_EXPORT SharedAbstractNode bvand(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvand node builder.
TRITON_EXPORT SharedAbstractNode bvudiv(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvudiv node builder.
TRITON_EXPORT SharedAbstractNode string(std::string value)
AST C++ API - string node builder.
TRITON_EXPORT SharedAbstractNode bvxor(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvxor node builder.
TRITON_EXPORT SharedAbstractNode reference(const triton::engines::symbolic::SharedSymbolicExpression &expr)
AST C++ API - reference node builder.
TRITON_EXPORT SharedAbstractNode zx(triton::uint32 sizeExt, const SharedAbstractNode &expr)
AST C++ API - zx node builder.
TRITON_EXPORT SharedAbstractNode bswap(const SharedAbstractNode &expr)
AST C++ API - bswap node builder.
TRITON_EXPORT SharedAbstractNode sx(triton::uint32 sizeExt, const SharedAbstractNode &expr)
AST C++ API - sx node builder.
TRITON_EXPORT SharedAbstractNode bvsge(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvsge node builder.
TRITON_EXPORT SharedAbstractNode bvsrem(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvsrem node builder.
TRITON_EXPORT SharedAbstractNode bvtrue(void)
AST C++ API - bvtrue node builder.
TRITON_EXPORT SharedAbstractNode bv(const triton::uint512 &value, triton::uint32 size)
AST C++ API - bv node builder.
TRITON_EXPORT SharedAbstractNode bvult(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvult node builder.
TRITON_EXPORT SharedAbstractNode bvashr(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvashr node builder.
TRITON_EXPORT SharedAbstractNode bvsdiv(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvsdiv node builder.
TRITON_EXPORT triton::ast::representations::mode_e getRepresentationMode(void) const
Gets the representations mode of this astContext.
SharedAbstractNode getVariableNode(const std::string &name)
Gets a variable node from its name.
TRITON_EXPORT SharedAbstractNode lor(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - lor node builder.
TRITON_EXPORT SharedAbstractNode bvnor(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvnor node builder.
TRITON_EXPORT SharedAbstractNode bvsle(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvsle node builder.
TRITON_EXPORT SharedAbstractNode lxor(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - lxor node builder.
TRITON_EXPORT SharedAbstractNode variable(const triton::engines::symbolic::SharedSymbolicVariable &symVar)
AST C++ API - variable node builder.
TRITON_EXPORT SharedAbstractNode bvlshr(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvlshr node builder.
TRITON_EXPORT std::ostream & print(std::ostream &stream, AbstractNode *node)
Prints the node according to the current representation mode.
TRITON_EXPORT void updateVariable(const std::string &name, const triton::uint512 &value)
Updates a variable value in this context.
TRITON_EXPORT SharedAbstractNode ite(const SharedAbstractNode &ifExpr, const SharedAbstractNode &thenExpr, const SharedAbstractNode &elseExpr)
AST C++ API - ite node builder.
TRITON_EXPORT SharedAbstractNode assert_(const SharedAbstractNode &expr)
AST C++ API - assert node builder.
TRITON_EXPORT SharedAbstractNode lnot(const SharedAbstractNode &expr)
AST C++ API - lnot node builder.
TRITON_EXPORT SharedAbstractNode select(const SharedAbstractNode &array, triton::usize index)
AST C++ API - select node builder.
TRITON_EXPORT SharedAbstractNode bvneg(const SharedAbstractNode &expr)
AST C++ API - bvneg node builder.
TRITON_EXPORT SharedAbstractNode collect(const SharedAbstractNode &node)
Collect new nodes.
TRITON_EXPORT const triton::uint512 & getVariableValue(const std::string &name) const
Gets a variable value from its name.
TRITON_EXPORT SharedAbstractNode bvugt(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvugt node builder.
TRITON_EXPORT SharedAbstractNode bvslt(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvslt node builder.
TRITON_EXPORT SharedAbstractNode equal(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - equal node builder.
TRITON_EXPORT SharedAbstractNode integer(const triton::uint512 &value)
AST C++ API - integer node builder.
TRITON_EXPORT SharedAbstractNode bvror(const SharedAbstractNode &expr, triton::uint32 rot)
AST C++ API - bvror node builder.
TRITON_EXPORT SharedAbstractNode array(triton::uint32 addrSize)
AST C++ API - array node builder.
TRITON_EXPORT SharedAbstractNode bvadd(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvadd node builder.
TRITON_EXPORT SharedAbstractNode let(std::string alias, const SharedAbstractNode &expr2, const SharedAbstractNode &expr3)
AST C++ API - let node builder.
TRITON_EXPORT void initVariable(const std::string &name, const triton::uint512 &value, const SharedAbstractNode &node)
Initializes a variable in the context.
TRITON_EXPORT SharedAbstractNode extract(triton::uint32 high, triton::uint32 low, const SharedAbstractNode &expr)
AST C++ API - extract node builder.
TRITON_EXPORT SharedAbstractNode bvsmod(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvsmod node builder.
TRITON_EXPORT SharedAbstractNode bvurem(const SharedAbstractNode &expr1, const SharedAbstractNode &expr2)
AST C++ API - bvurem node builder.
TRITON_EXPORT SharedAbstractNode bvnot(const SharedAbstractNode &expr)
AST C++ API - bvnot node builder.
TRITON_EXPORT SharedAbstractNode declare(const SharedAbstractNode &var)
AST C++ API - declare node builder.
TRITON_EXPORT std::ostream & print(std::ostream &stream, AbstractNode *node)
Prints the node according to the current representation mode.
TRITON_EXPORT void setMode(triton::ast::representations::mode_e mode)
Sets the representation mode.
TRITON_EXPORT triton::ast::representations::mode_e getMode(void) const
Returns the representation mode.
The exception class used by all AST nodes.
SharedAbstractNode dereference(const SharedAbstractNode &node)
Returns the first non referene node encountered.
std::shared_ptr< triton::ast::AbstractNode > SharedAbstractNode
Shared Abstract Node.
std::shared_ptr< triton::modes::Modes > SharedModes
Shared Modes.
@ CONSTANT_FOLDING
[symbolic] Perform a constant folding optimization of sub ASTs which do not contain symbolic variable...
@ SYMBOLIZE_INDEX_ROTATION
[symbolic] Symbolize index rotation for bvrol and bvror (see #751). This mode increases the complexit...
@ AST_OPTIMIZATIONS
[AST] Classical arithmetic optimisations to reduce the depth of the trees.
mode_e
All types of representation mode.
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::uint32_t uint32
unisgned 32-bits