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

implement aslBackwardsVisitor #72

Merged
merged 5 commits into from
May 8, 2024
Merged

implement aslBackwardsVisitor #72

merged 5 commits into from
May 8, 2024

Conversation

katrinafyi
Copy link
Member

@katrinafyi katrinafyi commented Mar 26, 2024

This adds a visitor suitable for basic backwards analyses. In doing so, we refactor the visit_* functions to place them inside a class. This makes it possible to override one or more of the methods, as we do in aslBackwardsVisitor for visit_stmts.

The backwards visitor has the same limitations as the existing forwards visitor. That is, merging results at control flow joins is difficult to do. However, for simple analyses, this can be worked around with careful use of enter/exit scope.

There is naming confusion in aslVisitor / aslForwardsVisitor / aslBackwardsVisitor which would be good to fix. aslVisitor defines the visit actions for specific AST nodes, whereas the aslForwardsVisitor/aslBackwardsVisitor applies these recursively in a particular order. Maybe these can be called aslForwardsTransform...?

@ncough
Copy link
Collaborator

ncough commented Mar 26, 2024

Nice! My only other issue with the visitor is supporting transforms from individual statements into lists of statements. I'd be keen to get rid of the custom walks I keen implementing.

@katrinafyi katrinafyi force-pushed the backwards-visitor branch 3 times, most recently from 261b750 to 396a4c6 Compare March 26, 2024 08:31
@katrinafyi
Copy link
Member Author

katrinafyi commented Mar 26, 2024

There is now a draft commit to support returning stmt list. However, it has not been tested at all beyond the existing tests (which all use transforms on single statements, so really not at all).

Indeed, I think this will require a more careful implementation of the backwards visitor. One thought is that we need to make sure that we do not reverse statement lists before/after ChangeDoChildrenPost.

It sure would be nice to have unit tests.

@katrinafyi katrinafyi marked this pull request as ready for review March 27, 2024 03:33
@katrinafyi katrinafyi closed this Apr 11, 2024
BREAKING!
This change affects the signature of the Asl_visitor.visit_stmt method.
For compatibility, a visit_stmt_single method is provided with
equivalent behaviour to the old visit_stmt. There is also an added
helper function to convert visitActions on single statements to
visitActions on a list of statements.

Both of these compatibility helpers WILL THROW if used with a visitor
that returns non-singleton statement lists.

This gives the user the flexibility to insert new statements or delete
statements entirely. On the other hand, post-functions in
ChangeDoChildrenPost will need to handle lists of functions as well.

This follows the original CIL visitor: https://people.eecs.berkeley.edu/~necula/cil/api/Cil.cilVisitor.html
it is no longer a good idea for the backwards and forwards visitors to have a subtyping relation.
@katrinafyi katrinafyi reopened this Apr 11, 2024
@ailrst ailrst merged commit abd63cb into partial_eval May 8, 2024
2 checks passed
@katrinafyi katrinafyi deleted the backwards-visitor branch May 8, 2024 01:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants