-
Notifications
You must be signed in to change notification settings - Fork 51
MWCC Struct copy improvements #294
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
base: master
Are you sure you want to change the base?
Conversation
dbalatoni13
commented
Mar 29, 2025
- Adjusted the pattern to make it possible for addresses to not start at zero
- Sometimes the last part uses different registers, this was adjusted in the pattern
- Use a store statement instead of the void function we had till now. This helps with type resolution.
Change the code to test struct type unification
This reverts commit bb4cb49.
if dest.type.is_struct() or source.type.is_struct(): | ||
dest.type.unify(source.type) | ||
|
||
# TODO are these four needed? |
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.
Are these needed here? I copied them from another place (the next four lines)
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.
Yes, that's needed. Can you break that part out into a shared emit_write
function maybe?
return line | ||
else: | ||
return fmt.with_comments( | ||
line, [f"size 0x{fmt.format_hex(self.commented_size)}"] |
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 causes an extra level of identation, do you have a suggestion maybe how we could get rid of that?
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.
Eh, it's fine.
It looks like fmt.with_comments gives additional indentation though, we need to fix that somehow.
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.
Oh, wait, I must have been really tired when reading this, I thought you were referring to Python indentation...
I think the comments probably have to be carried all the way to if_statements somehow. Maybe Statement can grow a method for getting comments from a statement (defaulting to []), and SimpleStatement can check the output of that method?
TODO: There's a bug that causes the copy to go onto |
We do support addresses not starting at 0 now, but I wonder if that causes false positives on -O4. |
It also seems to make no difference whether we manually call |
@@ -5,35 +5,35 @@ void test(void) { | |||
|
|||
} | |||
|
|||
void test_0(s32 arg0, s32 arg1) { | |||
M2C_STRUCT_COPY(arg0, arg1, 8); | |||
void test_0(? *arg0, ? *arg1) { |
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.
We should probably get these to be typed as pointers.
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.
?* is a pointer
if dest.type.is_struct() or source.type.is_struct(): | ||
dest.type.unify(source.type) | ||
|
||
# TODO are these four needed? |
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.
Yes, that's needed. Can you break that part out into a shared emit_write
function maybe?
size_expr = a.imm(2) | ||
assert isinstance(size_expr, Literal) | ||
size = size_expr.value |
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.
size_expr = a.imm(2) | |
assert isinstance(size_expr, Literal) | |
size = size_expr.value | |
size = a.imm_value(2) |
@@ -2075,7 +2076,14 @@ def format(self, fmt: Formatter) -> str: | |||
) or isinstance(dest, (ArrayAccess, LocalVar, SubroutineArg)): | |||
# Known destination; fine to elide some casts. | |||
source = elide_literal_casts(source) | |||
return format_assignment(dest, source, fmt) | |||
line = format_assignment(dest, source, fmt) | |||
# Used in struct copy statements |
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.
Drop this comment, it's mostly irrelevant it is used and it's confusing what this comment refers to exactly
return line | ||
else: | ||
return fmt.with_comments( | ||
line, [f"size 0x{fmt.format_hex(self.commented_size)}"] |
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.
Eh, it's fine.
It looks like fmt.with_comments gives additional indentation though, we need to fix that somehow.
@@ -5,35 +5,35 @@ void test(void) { | |||
|
|||
} | |||
|
|||
void test_0(s32 arg0, s32 arg1) { | |||
M2C_STRUCT_COPY(arg0, arg1, 8); | |||
void test_0(? *arg0, ? *arg1) { |
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.
?* is a pointer