diff --git a/CHANGELOG.md b/CHANGELOG.md index 43a7e3da..214cac1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # splat Release Notes ### 0.22.4 + * splat now checks if symbol names can be valid filepaths and produce an error if not. * This is checked because functions are written to their own files and the symbol name is used as the filepath. * There are two checks in place: @@ -11,6 +12,7 @@ * Change `sbss` to properly work as a noload section. * To make it not behave as noload then turn off `ld_bss_is_noload`. * `ld_bss_is_noload` is now `False` by default for `psx` projects. +* Allow to properly override `get_linker_section` and `get_section_flags` in `asm` and `hasm` files. ### 0.22.3 diff --git a/src/splat/segtypes/common/asm.py b/src/splat/segtypes/common/asm.py index df3c0248..b83fe8a3 100644 --- a/src/splat/segtypes/common/asm.py +++ b/src/splat/segtypes/common/asm.py @@ -11,6 +11,9 @@ class CommonSegAsm(CommonSegCodeSubsegment): def is_text() -> bool: return True + def get_section_flags(self) -> Optional[str]: + return "ax" + def out_path(self) -> Optional[Path]: return options.opts.asm_path / self.dir / f"{self.name}.s" diff --git a/src/splat/segtypes/common/c.py b/src/splat/segtypes/common/c.py index 38b96501..a1c3d289 100644 --- a/src/splat/segtypes/common/c.py +++ b/src/splat/segtypes/common/c.py @@ -123,6 +123,9 @@ def get_global_asm_rodata_syms(c_file: Path) -> Set[str]: def is_text() -> bool: return True + def get_section_flags(self) -> Optional[str]: + return "ax" + def out_path(self) -> Optional[Path]: return options.opts.src_path / self.dir / f"{self.name}.{self.file_extension}" diff --git a/src/splat/segtypes/common/data.py b/src/splat/segtypes/common/data.py index cd82e4a6..7660f931 100644 --- a/src/splat/segtypes/common/data.py +++ b/src/splat/segtypes/common/data.py @@ -60,11 +60,7 @@ def split(self, rom_bytes: bytes): if preamble: f.write(preamble + "\n") - f.write(f".section {self.get_linker_section()}") - section_flags = self.get_section_flags() - if section_flags: - f.write(f', "{section_flags}"') - f.write("\n\n") + f.write(f"{self.get_section_asm_line()}\n\n") f.write(self.spim_section.disassemble()) diff --git a/src/splat/segtypes/common/rodata.py b/src/splat/segtypes/common/rodata.py index 54053d5c..19641e63 100644 --- a/src/splat/segtypes/common/rodata.py +++ b/src/splat/segtypes/common/rodata.py @@ -94,7 +94,7 @@ def disassemble_data(self, rom_bytes): generated_symbol = symbols.create_symbol_from_spim_symbol( self.get_most_parent(), symbol.contextSym ) - generated_symbol.linker_section = self.get_linker_section() + generated_symbol.linker_section = self.get_linker_section_linksection() possible_text = self.get_possible_text_subsegment_for_symbol(symbol) if possible_text is not None: diff --git a/src/splat/segtypes/common/textbin.py b/src/splat/segtypes/common/textbin.py index d1243701..1be9d52d 100644 --- a/src/splat/segtypes/common/textbin.py +++ b/src/splat/segtypes/common/textbin.py @@ -47,11 +47,7 @@ def write_asm_contents(self, rom_bytes, f: TextIO): assert isinstance(self.rom_start, int) assert isinstance(self.rom_end, int) - f.write(f".section {self.get_linker_section()}") - section_flags = self.get_section_flags() - if section_flags: - f.write(f', "{section_flags}"') - f.write("\n\n") + f.write(f"{self.get_section_asm_line()}\n\n") # Check if there's a symbol at this address sym = None diff --git a/src/splat/segtypes/n64/asm.py b/src/splat/segtypes/n64/asm.py index f3f90874..91b99728 100644 --- a/src/splat/segtypes/n64/asm.py +++ b/src/splat/segtypes/n64/asm.py @@ -4,8 +4,7 @@ class N64SegAsm(CommonSegAsm): - @staticmethod - def get_file_header(): + def get_file_header(self): ret = [] ret.append('.include "macro.inc"') @@ -22,7 +21,8 @@ def get_file_header(): if preamble: ret.append(preamble) ret.append("") - ret.append('.section .text, "ax"') + + ret.append(self.get_section_asm_line()) ret.append("") return ret diff --git a/src/splat/segtypes/n64/hasm.py b/src/splat/segtypes/n64/hasm.py index b4b757e2..e46319c3 100644 --- a/src/splat/segtypes/n64/hasm.py +++ b/src/splat/segtypes/n64/hasm.py @@ -4,8 +4,7 @@ class N64SegHasm(CommonSegHasm): - @staticmethod - def get_file_header(): + def get_file_header(self): ret = [] ret.append('.include "macro.inc"') @@ -22,7 +21,8 @@ def get_file_header(): if preamble: ret.append(preamble) ret.append("") - ret.append('.section .text, "ax"') + + ret.append(self.get_section_asm_line()) ret.append("") return ret diff --git a/src/splat/segtypes/ps2/asm.py b/src/splat/segtypes/ps2/asm.py index 70d4e583..a8e7680b 100644 --- a/src/splat/segtypes/ps2/asm.py +++ b/src/splat/segtypes/ps2/asm.py @@ -4,8 +4,7 @@ class Ps2SegAsm(CommonSegAsm): - @staticmethod - def get_file_header(): + def get_file_header(self): ret = [] ret.append('.include "macro.inc"') @@ -17,7 +16,8 @@ def get_file_header(): if preamble: ret.append(preamble) ret.append("") - ret.append('.section .text, "ax"') + + ret.append(self.get_section_asm_line()) ret.append("") return ret diff --git a/src/splat/segtypes/psx/asm.py b/src/splat/segtypes/psx/asm.py index f1b47f70..11ba1abd 100644 --- a/src/splat/segtypes/psx/asm.py +++ b/src/splat/segtypes/psx/asm.py @@ -4,8 +4,7 @@ class PsxSegAsm(CommonSegAsm): - @staticmethod - def get_file_header(): + def get_file_header(self): ret = [] ret.append('.include "macro.inc"') @@ -17,7 +16,8 @@ def get_file_header(): if preamble: ret.append(preamble) ret.append("") - ret.append('.section .text, "ax"') + + ret.append(self.get_section_asm_line()) ret.append("") return ret diff --git a/src/splat/segtypes/segment.py b/src/splat/segtypes/segment.py index e34974f4..901d7483 100644 --- a/src/splat/segtypes/segment.py +++ b/src/splat/segtypes/segment.py @@ -574,6 +574,13 @@ def get_section_flags(self) -> Optional[str]: """ return None + def get_section_asm_line(self) -> str: + line = f".section {self.get_linker_section_linksection()}" + section_flags = self.get_section_flags() + if section_flags: + line += f', "{section_flags}"' + return line + def out_path(self) -> Optional[Path]: return None