Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions mwccgap/preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ def preprocess_s_file(
if line.startswith("enddlabel") or line.startswith("nmlabel"):
continue

if line.startswith("glabel") or line.startswith("dlabel"):
if any(line.startswith(x) for x in ["glabel", "dlabel", "jlabel"]):
_, current_symbol = line.removesuffix(LOCAL_SUFFIX).split(" ")
is_local = (
line.endswith(LOCAL_SUFFIX) or DOLLAR_SIGN in current_symbol
line.endswith(LOCAL_SUFFIX)
or DOLLAR_SIGN in current_symbol
or line.startswith("jlabel")
)
rodata_entries[current_symbol] = Symbol(
current_symbol, local=is_local
Expand Down Expand Up @@ -125,7 +127,11 @@ def preprocess_s_file(
if line.startswith(".align") or line.startswith(".balign"):
# ignore alignment
continue
if line.startswith("glabel") or line.startswith("jlabel") or line.startswith("alabel"):
if (
line.startswith("glabel")
or line.startswith("jlabel")
or line.startswith("alabel")
):
# ignore function / jumptable labels
continue
if line.startswith("endlabel") or line.startswith("enddlabel"):
Expand Down
21 changes: 21 additions & 0 deletions tests/test_preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,27 @@ def test_dollar_symbol(self):
self.assertTrue(rodata_entries[expected_symbol_name].local)
self.assertTrue(c_lines[0].startswith("static "))

def test_rodata_jlabel(self):
asm_contents = """
.section .rodata

jlabel D_psp_0893C06C
/* 3D760 0893C06C 28D59A08 */ .word D_psp_089AD528
/* 3D764 0893C070 00000000 */ .word 0x00000000
.size D_psp_0893C06C, . - D_psp_0893C06C
"""
c_lines, rodata_entries = Preprocessor().preprocess_s_file(
"jlabel.s", asm_contents.splitlines()
)
expected_symbol_name = "D_psp_0893C06C"

self.assertEqual(1, len(c_lines))
self.assertEqual(1, len(rodata_entries))
self.assertIn(expected_symbol_name, rodata_entries)
self.assertEqual(2 * 4, rodata_entries[expected_symbol_name].size)
self.assertTrue(rodata_entries[expected_symbol_name].local)
self.assertTrue(c_lines[0].startswith("static "))


class TestPreprocessSFileExceptions(unittest.TestCase):
def test_rodata_unknown_directive(self):
Expand Down