Created
October 4, 2024 21:56
-
-
Save Yanis002/e22cbeb77c1403e1814cfb0e1ce7dfa7 to your computer and use it in GitHub Desktop.
Execute this in a dtk-type project, meant for the homeboy project
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| from pathlib import Path | |
| from dataclasses import dataclass, field | |
| @dataclass | |
| class Section: | |
| name: str | |
| start: str = "0x00000000" | |
| end: str = "0x00000000" | |
| attributes: list[str] = field(default_factory=list) | |
| class Sections: | |
| def __init__(self): | |
| self.init = Section(".init") | |
| self.text = Section(".text") | |
| self.ctors = Section(".ctors") | |
| self.dtors = Section(".dtors") | |
| self.rodata = Section(".rodata") | |
| self.data = Section(".data") | |
| self.bss = Section(".bss") | |
| self.sdata = Section(".sdata") | |
| self.sbss = Section(".sbss") | |
| self.sdata2 = Section(".sdata2") | |
| self.sbss2 = Section(".sbss2") | |
| @dataclass | |
| class Symbol: | |
| name: str | |
| section: Section | |
| attributes: str | |
| class Symbols: | |
| def __init__(self, file: Path): | |
| self.entries: list[Symbol] = [] | |
| assert file.exists() | |
| with file.open("r") as f: | |
| filedata = f.readlines() | |
| for i, line in enumerate(filedata): | |
| split = line.split(" = ") | |
| cur_symbol = Symbol( | |
| split[0], | |
| Section(split[1].split(":")[0], split[1].split(":")[1].split(";")[0]), | |
| line.split("; // ")[1] | |
| ) | |
| self.entries.append(cur_symbol) | |
| def get_txt(self, sym_list: list[str]): | |
| ret = "" | |
| for sym in self.entries: | |
| if sym.name in sym_list: | |
| ret += f"{sym.name:18} = {sym.section.start};\n" | |
| return ret | |
| def main(): | |
| symbol_map = { | |
| "oot-j": [ | |
| "cpuMapObject", | |
| "cpuSetDeviceGet", | |
| "cpuSetDevicePut", | |
| "ramSetSize", | |
| "xlHeapTake", | |
| "xlHeapFree", | |
| "xlObjectMake", | |
| "OSCreateThread", | |
| "OSResumeThread", | |
| "OSSuspendThread", | |
| ], | |
| "oot-u": [ | |
| "gpSystem", | |
| ], | |
| } | |
| for version, sym_list in symbol_map.items(): | |
| syms = Symbols(Path(f"config/{version}/symbols.txt").resolve()) | |
| output = Path(f"lib_{version.replace('-', '_')}.txt") | |
| with output.open("w") as file: | |
| file.write(syms.get_txt(sym_list)) | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment