Skip to content

Stablize variable typing and support integer truncation and sign extension #201

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

ChAoSUnItY
Copy link
Collaborator

@ChAoSUnItY ChAoSUnItY commented May 13, 2025

This is a attempt to support variable typing for all local variables (including synthesized ones) so that integer truncation and sign extension could be implemented, which targets to fix #166.

Notice that there's still some works including type derivation from operators and code cleanup.

About sign extension in rv32

It seems that package qemu-user is currently outdated (6.2.0) so Zbb extension is not supported, which results in the implementation of sign extension in rv32 currently using straightforward way to implement, that is bitwise shifting.

Summary by Bito

This pull request significantly enhances the variable typing system by introducing support for integer truncation and sign extension, optimizing memory allocation for local variables, and improving parameter type printing. It also enhances error handling by replacing the error_no_loc function with a new fatal function, improving error message clarity and addressing existing variable handling issues. These changes lay the groundwork for future enhancements in type derivation and memory management.

Unit tests added: True

Estimated effort to review (1-5, lower is better): 2

Verified

This commit was signed with the committer’s verified signature.
ChAoSUnItY Kyle Lin

Verified

This commit was signed with the committer’s verified signature.
ChAoSUnItY Kyle Lin

Verified

This commit was signed with the committer’s verified signature.
ChAoSUnItY Kyle Lin
@jserv jserv requested review from DrXiao and vacantron and removed request for DrXiao May 13, 2025 13:24
@sysprog21 sysprog21 deleted a comment from bito-code-review bot May 13, 2025
@ChAoSUnItY
Copy link
Collaborator Author

Regards to the issue of sign extension on rv32 backend, should we introduce a compiler parameter -Zbb to allow user to choose whether generate sign extension instruction with sext.b (or sext.h in the future once short type is implemented) or with bitwise shifts?

@jserv
Copy link
Collaborator

jserv commented May 14, 2025

Regards to the issue of sign extension on rv32 backend, should we introduce a compiler parameter -Zbb to allow user to choose whether generate sign extension instruction with sext.b (or sext.h in the future once short type is implemented) or with bitwise shifts?

It is a good idea. However, we then need to an effective way to select the extensions for RISC-V backend.

Verified

This commit was signed with the committer’s verified signature.
ChAoSUnItY Kyle Lin

Verified

This commit was signed with the committer’s verified signature.
ChAoSUnItY Kyle Lin
@ChAoSUnItY ChAoSUnItY marked this pull request as ready for review May 14, 2025 11:58

Verified

This commit was signed with the committer’s verified signature.
ChAoSUnItY Kyle Lin

Verified

This commit was signed with the committer’s verified signature.
ChAoSUnItY Kyle Lin
@sysprog21 sysprog21 deleted a comment from bito-code-review bot May 15, 2025

Verified

This commit was signed with the committer’s verified signature.
ChAoSUnItY Kyle Lin

Verified

This commit was signed with the committer’s verified signature.
ChAoSUnItY Kyle Lin
@@ -167,6 +223,73 @@ opcode_t get_operator()
return op;
}

var_t *promote_unchecked(block_t *block,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the name of this function is a bit too long. How about renaming this function to __promote()?

i.e., __promote() would directly promote the variable, while promote() checks some conditions and calls __promote() if promotion is necessary.

(This suggestion is minor.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shorten naming is good in my opinion, but my thought on __ prefix is that functions using this naming should be some kind of private functions that should not be used directly (see lib/c.c)?

Fyi _unchecked suffix is inspired by Rust's naming, e.g. pointer#get_unchecked.

return promote_unchecked(block, bb, var, target_type, target_ptr);
}

var_t *truncate_unchecked(block_t *block,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, how about renaming this function to __truncate() to shorten the name?

(Also, this suggestion is minor.)

params[param_num++] = opstack_pop();
param = opstack_pop();

if (func) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that func may be NULL if encountering an indirect call. How about writing some comments to explain the situation if func is NULL?

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.

Certain operations lack consideration for data types
3 participants