-
Notifications
You must be signed in to change notification settings - Fork 95
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
registers.py: Fix subtractions in generated C code #1099
base: main
Are you sure you want to change the base?
registers.py: Fix subtractions in generated C code #1099
Conversation
6b8b91d
to
065f527
Compare
For an easier review, attached are the generated files before and after this change: |
@en-sc Would you please have a moment for this review? Thank you. |
registers.py
Outdated
negative_constant = arg.is_constant() and (arg < 0) | ||
result += " - " if negative_constant else " + " | ||
if negative_constant: | ||
arg = -arg # flip to positive | ||
result += stc(arg) |
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.
This seems simpler to read:
negative_constant = arg.is_constant() and (arg < 0) | |
result += " - " if negative_constant else " + " | |
if negative_constant: | |
arg = -arg # flip to positive | |
result += stc(arg) | |
if arg.is_constant() and (arg < 0): | |
result += " - %s" % stc(-arg) | |
else: | |
result += " + %s" % stc(arg) |
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.
I agree, that is much cleaner. I have adopted the suggestion. Thanks.
The registers.py generator outputs expressions with subtractions into the C code of debug_defines.{h,c} in this form: ``` ((XLEN) + -6ULL) ``` Such code may look awkward to code readers and also triggers GCC's -Wconversion warnings (when enabled). Fix the generator to produce the expressions with subtraction in a natural form: ``` ((XLEN) - 6ULL) ```
065f527
to
972156c
Compare
The registers.py generator outputs expressions with subtractions into the C code of debug_defines.{h,c} in this form:
Such code may look awkward to code readers and also triggers GCC's
-Wconversion
warnings in the projects that will include these generated C files.Fix the generator to produce expressions with subtraction in a natural form: