Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

+ Reference node's children #1357

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sudmit0802
Copy link

@sudmit0802 sudmit0802 commented Aug 29, 2024

According to Issue #1356 a child for reference node obviously exists on AST graph, but it doesn't exists in vector with children, so it looks like incorrect work of API for interacting with ASTs.

There were two ways to solve this:
1.) I always have to cast SharedAbstractNode to ReferenceNode then getSymbolicExpresssion from it and then getAst from it again to finally get a real node with children. (jungles)
2.) Use AstContext::unroll(ast_node) to get a real node with children. (cannon)

In this PR I add a real node with its children as a child of Reference node in Constructor. The lifetime of a real node will not change from this, and the API will become consistent and convenient without unnecessary static_cast.

@JonathanSalwan
Copy link
Owner

thx. let me few days to really check if doesn't break anything :)

@sudmit0802
Copy link
Author

Did it break everything? :)

@JonathanSalwan
Copy link
Owner

CIs are ok but they do not really fully test the library :). To be honest, it's quite surprising, and it's a good news, that it did not break the CI :).

However, I have to double check all these following lines (the list is probably not exhaustive). My feeling is that for all references to REFERENCE_NODE, the code is now useless? and for all references to getChildren(), I have to check if it's okay to go through children of a ReferenceNode.

return triton::ast::shallowCopy(reinterpret_cast<ReferenceNode*>(node)->getSymbolicExpression()->getAst().get(), unroll);

if (unroll && ast->getType() == REFERENCE_NODE) {
const SharedAbstractNode& ref = reinterpret_cast<ReferenceNode*>(ast.get())->getSymbolicExpression()->getAst();
if (visited.find(ref.get()) == visited.end()) {
worklist.push({ref, false});
}
}

if (current->getType() == REFERENCE_NODE) {
worklist.push(reinterpret_cast<triton::ast::ReferenceNode*>(current)->getSymbolicExpression()->getAst().get());
}

SharedAbstractNode dereference(const SharedAbstractNode& node) {

if (n->getType() == triton::ast::REFERENCE_NODE) {
auto expr = reinterpret_cast<triton::ast::ReferenceNode*>(n.get())->getSymbolicExpression();
auto eid = expr->getId();
exprs[eid] = expr;
}

for (const auto& x : access) {
auto refs = triton::ast::search(x.second, triton::ast::REFERENCE_NODE);
for (const auto& ref : refs) {
auto expr = reinterpret_cast<triton::ast::ReferenceNode*>(ref.get())->getSymbolicExpression();
auto eid = expr->getId();
lifetime[eid] = expr;
}
if (x.first.getLeaAst()) {
auto refs = triton::ast::search(x.first.getLeaAst(), triton::ast::REFERENCE_NODE);
for (const auto& ref : refs) {
auto expr = reinterpret_cast<triton::ast::ReferenceNode*>(ref.get())->getSymbolicExpression();
auto eid = expr->getId();
lifetime[eid] = expr;
}
}
}

if (current->getType() == triton::ast::REFERENCE_NODE) {
worklist.push(reinterpret_cast<triton::ast::ReferenceNode*>(current)->getSymbolicExpression()->getAst().get());
}

if (current->getType() == triton::ast::REFERENCE_NODE) {
worklist.push(reinterpret_cast<triton::ast::ReferenceNode*>(current)->getSymbolicExpression()->getAst().get());
}

for (triton::uint32 index = 0; index < ast->getChildren().size(); index++) {

for (auto const& child : node->getChildren()) {

for (const auto& child : n->getChildren()) {

for (auto&& n : node->getChildren()) {

for (auto&& n : node->getChildren()) {

for (auto&& n : node->getChildren()) {

SharedAbstractNode newInstance(AbstractNode* node, bool unroll) {
std::unordered_map<AbstractNode*, SharedAbstractNode> exprs;
auto nodes = childrenExtraction(node->shared_from_this(), unroll, true);
for (auto&& n : nodes) {
/* Do a copy of all children */
const auto& newNode = shallowCopy(n.get(), unroll);
exprs[n.get()] = newNode;
/* For each child, set its parent */
auto& children = newNode->getChildren();
for (auto& child : children) {
child = exprs[child.get()];
child->setParent(newNode.get());
}
}
/* Return the root node */
return exprs.at(node);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants