Skip to content

Commit a6d55eb

Browse files
authored
include_asm_macro_style setting (#476)
* maspsx_include_asm_hack * lineendings * change setting to include_asm_macro_style * Fix test * Update src/splat/scripts/create_config.py
1 parent c6c0dca commit a6d55eb

File tree

9 files changed

+85
-21
lines changed

9 files changed

+85
-21
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# splat Release Notes
22

3+
### 0.36.0
4+
5+
* New yaml option: `include_asm_macro_style`:
6+
* Allows configuring the style used by the generated `INCLUDE_ASM` macro. It currently allows two possible values:
7+
* `default`: Uses the default definition for the macro. This is the default.
8+
* `maspsx_hack`: Changes the definition of the generated `INCLUDE_ASM` to be compatible with the one expected by `maspsx` when using the [reordering workaround hack](https://github.com/mkst/maspsx?tab=readme-ov-file#include_asm-reordering-workaround-hack). This value is only relevant for psx projects.
39
* `spimdisasm` 1.36.1 or above is now required.
410

511
### 0.35.2

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ The brackets corresponds to the optional dependencies to install while installin
2121
If you use a `requirements.txt` file in your repository, then you can add this library with the following line:
2222

2323
```txt
24-
splat64[mips]>=0.35.2,<1.0.0
24+
splat64[mips]>=0.36.0,<1.0.0
2525
```
2626

2727
### Optional dependencies

docs/Configuration.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,15 @@ Some files may not be generated depending on the selected platform and compiler,
138138

139139
Defaults to `True`.
140140

141+
### include_asm_macro_style
142+
143+
Allows configuring the style used by the generated `INCLUDE_ASM` macro. It currently allows two possible values:
144+
145+
- `default`: Uses the default definition for the macro. This is the default.
146+
- `maspsx_hack`: Changes the definition of the generated `INCLUDE_ASM` to be compatible with the one expected by `maspsx` when using the [reordering workaround hack](https://github.com/mkst/maspsx?tab=readme-ov-file#include_asm-reordering-workaround-hack).
147+
148+
Defaults to `default`.
149+
141150
### o_as_suffix
142151

143152
Used to determine the file extension of the built files that will be listed on the linker script.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
22
name = "splat64"
33
# Should be synced with src/splat/__init__.py
4-
version = "0.35.2"
4+
version = "0.36.0"
55
description = "A binary splitting tool to assist with decompilation and modding projects"
66
readme = "README.md"
77
license = {file = "LICENSE"}

src/splat/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
__package_name__ = __name__
22

33
# Should be synced with pyproject.toml
4-
__version__ = "0.35.2"
4+
__version__ = "0.36.0"
55
__author__ = "ethteck"
66

77
from . import util as util

src/splat/scripts/create_config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,10 @@ def create_psx_config(exe_path: Path, exe_bytes: bytes):
309309
data_string_encoding: ASCII
310310
rodata_string_guesser_level: 2
311311
data_string_guesser_level: 2
312+
313+
# Uncomment this line if you need to use the maspsx reorder workaround hack
314+
# https://github.com/mkst/maspsx?tab=readme-ov-file#include_asm-reordering-workaround-hack
315+
# include_asm_macro_style: maspsx_hack
312316
"""
313317

314318
segments = f"""\

src/splat/segtypes/n64/i1.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import n64img.image
2-
3-
from .img import N64SegImg
4-
5-
6-
class N64SegI1(N64SegImg):
7-
def __init__(self, *args, **kwargs):
8-
kwargs["img_cls"] = n64img.image.I1
9-
super().__init__(*args, **kwargs)
1+
import n64img.image
2+
3+
from .img import N64SegImg
4+
5+
6+
class N64SegI1(N64SegImg):
7+
def __init__(self, *args, **kwargs):
8+
kwargs["img_cls"] = n64img.image.I1
9+
super().__init__(*args, **kwargs)

src/splat/util/file_presets.py

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,23 @@ def write_include_asm_h():
3333
# These compilers do not use the `INCLUDE_ASM` macro.
3434
return
3535

36-
file_data = """\
37-
#ifndef INCLUDE_ASM_H
38-
#define INCLUDE_ASM_H
39-
40-
#if !defined(M2CTX) && !defined(PERMUTER)
41-
42-
#ifndef INCLUDE_ASM
36+
if options.opts.include_asm_macro_style == "maspsx_hack":
37+
include_asm_macro = """\
38+
#define INCLUDE_ASM(FOLDER, NAME) \\
39+
void __maspsx_include_asm_hack_##NAME() { \\
40+
__asm__( \\
41+
".text # maspsx-keep \\n" \\
42+
" .align 2 # maspsx-keep\\n" \\
43+
" .set noat # maspsx-keep\\n" \\
44+
" .set noreorder # maspsx-keep\\n" \\
45+
" .include \\"" FOLDER "/" #NAME ".s\\" # maspsx-keep\\n" \\
46+
" .set reorder # maspsx-keep\\n" \\
47+
" .set at # maspsx-keep\\n" \\
48+
); \\
49+
}
50+
"""
51+
else: # default
52+
include_asm_macro = """\
4353
#define INCLUDE_ASM(FOLDER, NAME) \\
4454
__asm__( \\
4555
".section .text\\n" \\
@@ -49,14 +59,28 @@ def write_include_asm_h():
4959
" .set reorder\\n" \\
5060
" .set at\\n" \\
5161
)
52-
#endif
53-
#ifndef INCLUDE_RODATA
62+
"""
63+
64+
include_rodata_macro = """\
5465
#define INCLUDE_RODATA(FOLDER, NAME) \\
5566
__asm__( \\
5667
".section .rodata\\n" \\
5768
" .include \\"" FOLDER "/" #NAME ".s\\"\\n" \\
5869
".section .text" \\
5970
)
71+
"""
72+
73+
file_data = f"""\
74+
#ifndef INCLUDE_ASM_H
75+
#define INCLUDE_ASM_H
76+
77+
#if !defined(M2CTX) && !defined(PERMUTER)
78+
79+
#ifndef INCLUDE_ASM
80+
{include_asm_macro}\
81+
#endif
82+
#ifndef INCLUDE_RODATA
83+
{include_rodata_macro}\
6084
#endif
6185
__asm__(".include \\"include/labels.inc\\"\\n");
6286

src/splat/util/options.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ class SplatOpts:
3737
generated_s_preamble: str
3838
# Determines any extra content to be added in the generated macro.inc file
3939
generated_macro_inc_content: Optional[str]
40+
# Determines if files related to assembly macros should be regenerated by splat
4041
generate_asm_macros_files: bool
42+
# Changes the definition of the generated `INCLUDE_ASM`.
43+
# default: The default one.
44+
# maspsx_hack: Use the maspsx hack workaround definition https://github.com/mkst/maspsx?tab=readme-ov-file#include_asm-reordering-workaround-hack
45+
include_asm_macro_style: Literal["default", "maspsx_hack"]
4146
# Determines whether to use .o as the suffix for all binary files?... TODO document
4247
use_o_as_suffix: bool
4348
# the value of the $gp register to correctly calculate offset to %gp_rel relocs
@@ -400,6 +405,21 @@ def parse_endianness() -> Literal["big", "little"]:
400405
else:
401406
raise ValueError(f"Invalid endianness: {endianness}")
402407

408+
def parse_include_asm_macro_style() -> Literal["default", "maspsx_hack"]:
409+
include_asm_macro_style = p.parse_opt_within(
410+
"include_asm_macro_style",
411+
str,
412+
["default", "maspsx_hack"],
413+
"default",
414+
)
415+
416+
if include_asm_macro_style == "default":
417+
return "default"
418+
elif include_asm_macro_style == "maspsx_hack":
419+
return "maspsx_hack"
420+
else:
421+
raise ValueError(f"Invalid endianness: {include_asm_macro_style}")
422+
403423
default_ld_bss_is_noload = True
404424
if platform == "psx":
405425
default_ld_bss_is_noload = False
@@ -431,6 +451,7 @@ def parse_endianness() -> Literal["big", "little"]:
431451
"generated_macro_inc_content", str
432452
),
433453
generate_asm_macros_files=p.parse_opt("generate_asm_macros_files", bool, True),
454+
include_asm_macro_style=parse_include_asm_macro_style(),
434455
use_o_as_suffix=p.parse_opt("o_as_suffix", bool, False),
435456
gp=p.parse_optional_opt("gp_value", int),
436457
check_consecutive_segment_types=p.parse_opt(

0 commit comments

Comments
 (0)