This repository has been archived on 2024-12-14. You can view files and clone it, but cannot push or open issues or pull requests.
rustboyadvance-ng/src/disass.rs
Michel Heily b03fe3567e Fix all warnings during build
Ran cargo-fix to automatically fix most of the build warnings,
Cleaned up dead code, and fix the rest manually


Former-commit-id: f35faba46b40eaf9c047efb8ab1e77ffa24d41b6
2020-02-14 14:21:45 +02:00

55 lines
1.3 KiB
Rust

use std::fmt;
use std::marker::PhantomData;
use super::core::arm7tdmi::InstructionDecoder;
use super::core::Addr;
pub struct Disassembler<'a, D>
where
D: InstructionDecoder,
{
base: Addr,
pos: usize,
bytes: &'a [u8],
pub word_size: usize,
instruction_decoder: PhantomData<D>,
}
impl<'a, D> Disassembler<'a, D>
where
D: InstructionDecoder,
{
pub fn new(base: Addr, bytes: &'a [u8]) -> Disassembler<'_, D> {
Disassembler {
base: base as Addr,
pos: 0,
bytes: bytes,
word_size: std::mem::size_of::<D::IntType>(),
instruction_decoder: PhantomData,
}
}
}
impl<'a, D> Iterator for Disassembler<'a, D>
where
D: InstructionDecoder + fmt::Display,
<D as InstructionDecoder>::IntType: std::fmt::LowerHex,
{
type Item = (Addr, String);
fn next(&mut self) -> Option<Self::Item> {
let mut line = String::new();
let addr = self.base + self.pos as Addr;
let decoded: D = D::decode_from_bytes(&self.bytes[(self.pos as usize)..], addr);
self.pos += self.word_size;
line.push_str(&format!(
"{:8x}:\t{:08x} \t{}",
addr,
decoded.get_raw(),
decoded
));
Some((self.pos as Addr, line))
}
}