mirror of
https://github.com/izzy2lost/Diddy-Kong-Racing.git
synced 2026-06-19 01:16:26 -07:00
Merge pull request #88 from AntonioCastelli/data-split-tool
Added .rodata and .bss sections to data region splitter tool.
This commit is contained in:
@@ -8,10 +8,12 @@ from file_util import FileUtil
|
||||
DATA_FILE_PATH = 'data/dkr.data.s'
|
||||
GLABEL_REGEX = r'D_[0-9A-F]{8}'
|
||||
GLABEL_DEF_REGEX = r'glabel (%s)' % GLABEL_REGEX
|
||||
RODATA_START = 'D_800E49DC' # i.e. the end of .data
|
||||
BSS_START = 'D_800E98D0' # i.e. the end of .rodata
|
||||
# List of labels that are not used in the file they are defined in.
|
||||
# This throws off the splitter algorithm, so the troublesome ones
|
||||
# must be individually blacklisted for now.
|
||||
IGNORE_GLABELS = ['D_800E0001']
|
||||
IGNORE_GLABELS = ['D_800E0001', 'D_800E63E0', 'D_800E94D0']
|
||||
|
||||
def _rom_offset(vaddr):
|
||||
"""
|
||||
@@ -26,11 +28,15 @@ def _rom_offset(vaddr):
|
||||
|
||||
def _get_glabels():
|
||||
"""
|
||||
Returns all the glabel definitions in the data file.
|
||||
Returns all the glabel definitions in the data file, split into .data,
|
||||
.rodata, and .bss.
|
||||
"""
|
||||
data_file = FileUtil.get_text_from_file(DATA_FILE_PATH)
|
||||
glabels = re.findall(GLABEL_DEF_REGEX, data_file)
|
||||
return [glabel for glabel in glabels if glabel not in IGNORE_GLABELS]
|
||||
glabels = [glabel for glabel in glabels if glabel not in IGNORE_GLABELS]
|
||||
rodata_idx = glabels.index(RODATA_START)
|
||||
bss_idx = glabels.index(BSS_START)
|
||||
return glabels[:rodata_idx], glabels[rodata_idx:bss_idx], glabels[bss_idx:]
|
||||
|
||||
def _get_file_offset(file, contents):
|
||||
"""
|
||||
@@ -108,21 +114,28 @@ def _split_glabel_files(glabel_usage, c_file_offsets):
|
||||
glabel_idx = 0
|
||||
for i in range(len(c_file_offsets)):
|
||||
file = c_file_offsets[i]
|
||||
while glabel_usage[glabel_idx][1] < file[1]:
|
||||
while glabel_idx < len(glabel_usage) and glabel_usage[glabel_idx][1] < file[1]:
|
||||
glabel_idx += 1
|
||||
glabel = glabel_usage[glabel_idx]
|
||||
glabel_name = glabel[0] if i < len(c_file_offsets) - 1 and glabel[1] < c_file_offsets[i + 1][1] else None
|
||||
if glabel_idx < len(glabel_usage) and i < len(c_file_offsets) - 1:
|
||||
glabel = glabel_usage[glabel_idx]
|
||||
glabel_name = glabel[0] if glabel[1] < c_file_offsets[i + 1][1] else None
|
||||
else:
|
||||
glabel_name = None
|
||||
file_splits.append((file[0], file[1], glabel_name))
|
||||
return file_splits
|
||||
|
||||
def main():
|
||||
FileUtil.set_working_dir_to_project_base()
|
||||
glabels = _get_glabels()
|
||||
usage, c_file_offsets = _log_glabel_usage(glabels)
|
||||
filtered_usage = _filter_glabel_usage(usage)
|
||||
file_splits = _split_glabel_files(filtered_usage, c_file_offsets)
|
||||
for split in file_splits:
|
||||
print('%s (%06X): %s' % split)
|
||||
data_glabels, rodata_glabels, bss_glabels = _get_glabels()
|
||||
for section in [('.data', data_glabels), ('.rodata', rodata_glabels), ('.bss', bss_glabels)]:
|
||||
glabels = section[1]
|
||||
usage, c_file_offsets = _log_glabel_usage(glabels)
|
||||
filtered_usage = _filter_glabel_usage(usage)
|
||||
file_splits = _split_glabel_files(filtered_usage, c_file_offsets)
|
||||
print('File splits for %s:' % section[0])
|
||||
for split in file_splits:
|
||||
print('%s (%06X): %s' % split)
|
||||
print()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user