Skip to content

Commit

Permalink
Allow to properly override get_linker_section and `get_section_flag…
Browse files Browse the repository at this point in the history
…s` in `asm` and `hasm` files (#356)

* Use `get_linker_section_linksection` and `get_section_flags` in asm and hasm files

* Fix a few files not using `get_linker_section_linksection`

* Version bump

* black

* fix

* review
  • Loading branch information
AngheloAlf authored Mar 19, 2024
1 parent d28aceb commit cec9b2d
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 23 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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

Expand Down
3 changes: 3 additions & 0 deletions src/splat/segtypes/common/asm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
3 changes: 3 additions & 0 deletions src/splat/segtypes/common/c.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"

Expand Down
6 changes: 1 addition & 5 deletions src/splat/segtypes/common/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
2 changes: 1 addition & 1 deletion src/splat/segtypes/common/rodata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 1 addition & 5 deletions src/splat/segtypes/common/textbin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/splat/segtypes/n64/asm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@


class N64SegAsm(CommonSegAsm):
@staticmethod
def get_file_header():
def get_file_header(self):
ret = []

ret.append('.include "macro.inc"')
Expand All @@ -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
6 changes: 3 additions & 3 deletions src/splat/segtypes/n64/hasm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@


class N64SegHasm(CommonSegHasm):
@staticmethod
def get_file_header():
def get_file_header(self):
ret = []

ret.append('.include "macro.inc"')
Expand All @@ -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
6 changes: 3 additions & 3 deletions src/splat/segtypes/ps2/asm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@


class Ps2SegAsm(CommonSegAsm):
@staticmethod
def get_file_header():
def get_file_header(self):
ret = []

ret.append('.include "macro.inc"')
Expand All @@ -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
6 changes: 3 additions & 3 deletions src/splat/segtypes/psx/asm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@


class PsxSegAsm(CommonSegAsm):
@staticmethod
def get_file_header():
def get_file_header(self):
ret = []

ret.append('.include "macro.inc"')
Expand All @@ -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
7 changes: 7 additions & 0 deletions src/splat/segtypes/segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit cec9b2d

Please sign in to comment.