Added glabels whose upper/lower usage has label definitions inbetween.

This commit is contained in:
Antonio Castelli
2021-05-28 12:07:16 -07:00
parent 24a2d6bfb4
commit d2c9e706c8
6 changed files with 17 additions and 17 deletions
+6 -6
View File
@@ -2,20 +2,20 @@ import re
from file_util import FileUtil
LINE_START_REGEX = r'\n/\* ([0-9A-F]{6}) [0-9A-F]{8} [0-9A-F]{8} \*/\s+'
LINE_START_REGEX = r'\n(/\* ([0-9A-F]{6}) [0-9A-F]{8} [0-9A-F]{8} \*/\s+|\.L80[0-9A-F]{6}:)'
REG_REGEX = r'(\$(at|v[0-1]|a[0-3]|t[0-9]|s[0-7]|k[0-1]|gp|sp|fp|ra))'
GLABEL_UPPER_REGEX = '(' + LINE_START_REGEX + r'lui\s+' + REG_REGEX + r',\s+(0x80[0-9a-f]{2}))'
GLABEL_LOWER_REGEX = '(' + LINE_START_REGEX + r'l[bhw]\s+' + REG_REGEX + r',\s+(0x[0-9a-f]{4})\(\3\))'
GLABEL_REGEX = GLABEL_UPPER_REGEX + '(' + LINE_START_REGEX + '[^\n]*(?=\n)){0,10}' + GLABEL_LOWER_REGEX
GLABEL_LOWER_REGEX = '(' + LINE_START_REGEX + r'l[bhw]\s+' + REG_REGEX + r',\s+(0x[0-9a-f]{4})\(\4\))'
GLABEL_REGEX = GLABEL_UPPER_REGEX + '(' + LINE_START_REGEX + '[^\n]*){0,10}' + GLABEL_LOWER_REGEX
def _find_glabels(asm):
glabels = []
for file in FileUtil.get_filenames_from_directory_recursive('.', '.s'):
matches = re.findall(GLABEL_REGEX, FileUtil.get_text_from_file(file))
for match in matches:
offsets = (match[1], match[8]) # ROM offsets of the lu and lw
glabel_upper = int(match[4], 16) # upper immediate of glabel
glabel_lower = int(match[11], 16) # lower immediate of the glabel
offsets = (match[2], match[11]) # ROM offsets of the lu and lw
glabel_upper = int(match[5], 16) # upper immediate of glabel
glabel_lower = int(match[14], 16) # lower immediate of the glabel
if glabel_lower & 0x8000:
glabel_upper -= 1
glabel = 'D_%08X' % (glabel_upper << 16 | glabel_lower)