Fix bugs about bound checking for immediate

This commit is contained in:
Bananymous 2024-04-29 21:57:45 +03:00
parent db4f37709f
commit 999cc0d5d1
1 changed files with 6 additions and 0 deletions

View File

@ -420,6 +420,9 @@ class CompileData:
if instructions[i].opcode not in ['addq', 'subq']:
i += 1
continue
if instructions[i].operands[1][0] != '$' or instructions[i + 1].operands[1][0] != '$':
i += 1
continue
if instructions[i].operands[1] != instructions[i + 1].operands[1]:
i += 1
continue
@ -428,6 +431,9 @@ class CompileData:
rhs = int(instructions[i + 1].operands[0][1:])
if instructions[i + 1].opcode == 'subq': rhs = -rhs
new_value = lhs + rhs
if abs(new_value) > 0xFFFFFFFF:
i += 1
continue
new_opcode = 'addq' if new_value >= 0 else 'subq'
instructions[i] = Instruction(new_opcode, [f'${abs(new_value)}', instructions[i].operands[1]])
instructions.pop(i + 1)