Minor cleanup, remove Section::symbol_data

This commit is contained in:
Luke Street 2025-05-07 16:43:34 -06:00
parent 7e08f9715b
commit b77df77000
3 changed files with 6 additions and 16 deletions

View File

@ -76,7 +76,9 @@ impl Arch for ArchSuperH {
sh2_disasm(0, opcode, true, &mut parts, &resolved, &mut branch_dest); sh2_disasm(0, opcode, true, &mut parts, &resolved, &mut branch_dest);
if let Some(symbol_data) = resolved.section.symbol_data(resolved.symbol) { if let Some(symbol_data) =
resolved.section.data_range(resolved.symbol.address, resolved.symbol.size as usize)
{
// scan for data // scan for data
// map of instruction offsets to data target offsets // map of instruction offsets to data target offsets
let mut data_offsets = BTreeMap::<u64, DataInfo>::new(); let mut data_offsets = BTreeMap::<u64, DataInfo>::new();

View File

@ -99,19 +99,8 @@ impl fmt::Debug for SectionData {
impl Section { impl Section {
pub fn data_range(&self, address: u64, size: usize) -> Option<&[u8]> { pub fn data_range(&self, address: u64, size: usize) -> Option<&[u8]> {
let start = self.address; let offset = address.checked_sub(self.address)?;
let end = start + self.size; self.data.get(offset as usize..offset as usize + size)
if address >= start && address + size as u64 <= end {
let offset = (address - start) as usize;
Some(&self.data[offset..offset + size])
} else {
None
}
}
pub fn symbol_data(&self, symbol: &Symbol) -> Option<&[u8]> {
let offset = symbol.address.checked_sub(self.address)?;
self.data.get(offset as usize..offset as usize + symbol.size as usize)
} }
// The alignment to use when "Combine data/text sections" is enabled. // The alignment to use when "Combine data/text sections" is enabled.

View File

@ -57,6 +57,5 @@ pub fn align_data_to_4<W: std::io::Write + ?Sized>(
pub fn align_u64_to(len: u64, align: u64) -> u64 { len + ((align - (len % align)) % align) } pub fn align_u64_to(len: u64, align: u64) -> u64 { len + ((align - (len % align)) % align) }
pub fn align_data_slice_to(data: &mut Vec<u8>, align: u64) { pub fn align_data_slice_to(data: &mut Vec<u8>, align: u64) {
const ALIGN_BYTE: u8 = 0; data.resize(align_u64_to(data.len() as u64, align) as usize, 0);
data.resize(align_u64_to(data.len() as u64, align) as usize, ALIGN_BYTE);
} }