I forgot to account for RBP offset in Store (move reg to memory).
Interestingly I don't think this will produce any bug for now, because such store comes from spill only, and I think we only spill temps that'll be used later (else its assigned register becomes immediately available after first definition). So if a spilled temp is always used later, it'll be restored, and the RBP offset in Store will be accounted for in the Load instruction there.
I also decided to move the helpers into the main offset calculation function. It's confusing that we are returning the positive offset, although looking for negative ones because stack grows downward. Encapsulate those functions and document this at the main function should make the code clearer.
I forgot to account for RBP offset in
Store
(move reg to memory).Interestingly I don't think this will produce any bug for now, because such store comes from spill only, and I think we only spill temps that'll be used later (else its assigned register becomes immediately available after first definition). So if a spilled temp is always used later, it'll be restored, and the RBP offset in
Store
will be accounted for in the Load instruction there.I also decided to move the helpers into the main offset calculation function. It's confusing that we are returning the positive offset, although looking for negative ones because stack grows downward. Encapsulate those functions and document this at the main function should make the code clearer.