-
Notifications
You must be signed in to change notification settings - Fork 270
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
simplify extractbits_exprt
representation
#8246
Conversation
2f964a7
to
71827f4
Compare
The current representation of extractbits_exprt stores both the upper and lower indices of the range that is to be extracted, and their difference plus one in form of the width of the type of the expression. This removes the upper index, as it can be deduced from the lower index and the width of the result. The key benefit is reducing burden on the user of the class, who a) doesn't have to remember which index comes first, and b) doesn't have to do the calculation of the upper index.
71827f4
to
97cb8a3
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #8246 +/- ##
========================================
Coverage 79.64% 79.64%
========================================
Files 1684 1684
Lines 195661 195622 -39
========================================
- Hits 155837 155809 -28
+ Misses 39824 39813 -11 ☔ View full report in Codecov by Sentry. |
Labelling "Version 6" as we need to get this merged before the release (or otherwise alongside a goto-program-version-bump) for it would result in incompatibility with previously compiled goto binaries. |
I don't think we have a way to get this expression into a goto program. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That does simplify things doesn't it?
dest += convert_with_precedence(upper, precedence); | ||
} | ||
else | ||
dest += "?"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this result in syntactically invalid C being generated? If so, is that a problem and would it be better to throw some kind of error or have an invariant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The expr2X functions are designed to generate some string when given an unknown expression -- this should be added to the documentation.
DATA_INVARIANT( | ||
lower_as_int <= upper_as_int, | ||
"upper bound must be greater or equal to lower bound"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing invariants because that case is simply not possible seems like a good thing.
The current representation of
extractbits_exprt
stores both the upper and lower indices of the range that is to be extracted, and their difference plus one in form of the width of the type of the expression.This removes the upper index, as it can be deduced from the lower index and the width of the result. The key benefit is reducing burden on the user of the class, who a) doesn't have to remember which index comes first, and b) doesn't have to do the calculation of the upper index.