Fix address analysis with negative `add` operands

Resolves #76
This commit is contained in:
Luke Street 2024-10-14 09:40:46 -06:00
parent 8d8d801b2f
commit 5c7560bcea
2 changed files with 6 additions and 2 deletions

View File

@ -56,6 +56,10 @@ impl SectionAddress {
}
pub fn is_aligned(self, align: u32) -> bool { self.address & (align - 1) == 0 }
pub fn wrapping_add(self, rhs: u32) -> Self {
Self { section: self.section, address: self.address.wrapping_add(rhs) }
}
}
impl Add<u32> for SectionAddress {

View File

@ -208,11 +208,11 @@ impl VM {
(
GprValue::Address(RelocationTarget::Address(left)),
GprValue::Constant(right),
) => GprValue::Address(RelocationTarget::Address(left + right)),
) => GprValue::Address(RelocationTarget::Address(left.wrapping_add(right))),
(
GprValue::Constant(left),
GprValue::Address(RelocationTarget::Address(right)),
) => GprValue::Address(RelocationTarget::Address(right + left)),
) => GprValue::Address(RelocationTarget::Address(right.wrapping_add(left))),
_ => GprValue::Unknown,
};
self.gpr[ins.field_rd() as usize].set_direct(value);