-
Notifications
You must be signed in to change notification settings - Fork 49
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
Added compatibility for decomp-toolkit macros #275
Added compatibility for decomp-toolkit macros #275
Conversation
m2c/asm_file.py
Outdated
".asciz", | ||
".ascii", | ||
".asciiz", | ||
"string", |
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 won't work -- this section is guarded by directive.startswith(".")
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.
My bad, it should actually be ".string"
m2c/asm_file.py
Outdated
@@ -339,7 +339,9 @@ def re_comment_replacer(match: Match[str]) -> str: | |||
re_whitespace_or_string = re.compile(r'\s+|"(?:\\.|[^\\"])*"') | |||
re_local_glabel = re.compile("L(_.*_)?[0-9A-F]{8}") | |||
re_local_label = re.compile("loc_|locret_|def_|lbl_|LAB_|jump_") | |||
re_label = re.compile(r'(?:([a-zA-Z0-9_.$]+)|"([a-zA-Z0-9_.$<>@,-]+)"):') | |||
re_label = re.compile( | |||
r'(?:(?:\.obj )?([a-zA-Z0-9_.$]+)|"([a-zA-Z0-9_.$<>@,-]+)")[:,]' |
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.
Instead of complicating this regex, can you add a case near where jlabel/glabel/etc are handled?
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 will give it a try.
Thanks, compatibility with more formats is always welcome. (Sorry for not responding in time to #272, I've been a bit strapped for time.) |
No problem! |
26fcb86
to
dbebf75
Compare
Does it look alright? I also made sure to set z to True for .string. |
Sorry, my previous edit deleted the jump table change, I'm not really experienced with git yet. I added it back now. Why does black change the formatting for something that was already in the repo? |
m2c/asm_file.py
Outdated
@@ -548,6 +554,14 @@ def process_label(label: str, *, kind: LabelKind) -> None: | |||
data = parse_incbin(args, options, warnings) | |||
if data is not None: | |||
asm_file.new_data_bytes(data) | |||
elif directive == ".obj": # decomp-toolkit label format | |||
parts = line.split() |
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.
can you make use of args
instead, which is the arguments split by comma? we don't want to make unnecessary assumptions about whitespace here
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.
sure
m2c/asm_file.py
Outdated
parts = line.split() | ||
if len(parts) >= 3: | ||
try: | ||
kind = LabelKind[parts[2].upper()] |
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.
LabelKind[...] exposes internal details in an ugly way and isn't searchable. Can you use some manual if-else switch instead?
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 it fine if I set it to global by default and change it to local if the string equals local? Or rather not do anything if the value is not one of those?
I did some testing and my variables get marked as static not depending on the LabelKind at all, is that normal?
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.
Sure, that's fine. A global label here means one that starts a function; for data it doesn't make a difference whether the label is global or not. And yeah I think m2c will happily mark things as static regardless of this, it's basing that decision on the context file instead.
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 see.
m2c/flow_graph.py
Outdated
@@ -862,7 +860,7 @@ def find_block_by_label(label: str) -> Optional[Block]: | |||
and isinstance(arg.argument, AsmGlobalSymbol) | |||
and any( | |||
arg.argument.symbol_name.startswith(prefix) | |||
for prefix in ("jtbl", "jpt_", "lbl_") | |||
for prefix in ("jtbl", "jpt_", "lbl_", "_jumptable") |
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.
just double checking: _jumptable
vs jumptable_
?
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.
You are right.
86dc22f
to
7043db7
Compare
m2c/asm_file.py
Outdated
@@ -548,6 +554,12 @@ def process_label(label: str, *, kind: LabelKind) -> None: | |||
data = parse_incbin(args, options, warnings) | |||
if data is not None: | |||
asm_file.new_data_bytes(data) | |||
elif directive == ".obj": # decomp-toolkit label format | |||
if len(args) == 2: |
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.
assert len(args) == 2
instead to have some minimum of error handling. Or raise DecompFailure("...")
in an else branch but that feels like effort.
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.
Okay, I will use assert
m2c/asm_file.py
Outdated
kind = LabelKind.GLOBAL | ||
if args[1] == "local": | ||
kind = LabelKind.LOCAL |
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.
kind = LabelKind.GLOBAL | |
if args[1] == "local": | |
kind = LabelKind.LOCAL | |
kind = LabelKind.LOCAL if args[1] == "local" else LabelKind.GLOBAL |
if you want
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.
sure, black adds brackets btw
m2c/asm_file.py
Outdated
@@ -548,6 +554,12 @@ def process_label(label: str, *, kind: LabelKind) -> None: | |||
data = parse_incbin(args, options, warnings) | |||
if data is not None: | |||
asm_file.new_data_bytes(data) | |||
elif directive == ".obj": # decomp-toolkit label format |
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.
btw, maybe move this up next to the handling for .rel which is also related to decomp-toolkit?
7043db7
to
492b9f3
Compare
I ran black and it was strange that it changed the formatting in other sections of this file and also multiple other files. I didn't commit those other changes, what do you think the issue probably is? |
Test failure due to too old black version? Because I don't get reformatting in flow_graph.py locally. |
23.12.1 is the version used in CI btw (mentioned in pyproject.toml), and 24.4.2 seems to be behave the same for me. You can probably just |
Actually, nvm, 23.12.1 and 24.4.2 do not behave the same, I just had parallel install of black somehow. (depot_tools??? this is a new way of screwing up python installs that I heretofore was not aware of.) I'll push an update to master to make things simple. |
so just rebase or merge with master and you should be good |
492b9f3
to
38db511
Compare
Oh, okay. I did a rebase. |
encounter/decomp-toolkit outputs assembly files that are currently not fully compatible with m2c.
One problem is that labels have the format
This makes m2c not detect any data, bss, rodata or jump table labels.
Another problem is that jump tables have the prefix "jumptable_".
Ultimately, strings use the type ".string".