use crate::error::JingleError;
use jingle_sleigh::{Instruction, SleighArchInfo};
use crate::modeling::ModeledInstruction;
use jingle_sleigh::JingleSleighError::InstructionDecode;
use jingle_sleigh::context::loaded::LoadedSleighContext;
#[derive(Debug, Clone)]
pub struct SleighTranslator<'a> {
info: SleighArchInfo,
sleigh: &'a LoadedSleighContext<'a>,
}
impl<'a> SleighTranslator<'a> {
pub fn new(sleigh: &'a LoadedSleighContext) -> Self {
Self {
info: sleigh.arch_info().clone(),
sleigh,
}
}
pub fn model_instruction_at(&self, offset: u64) -> Result<ModeledInstruction, JingleError> {
let op = self
.sleigh
.instruction_at(offset)
.ok_or(InstructionDecode)?;
self.model_instruction(op)
}
fn model_instruction(&self, instr: Instruction) -> Result<ModeledInstruction, JingleError> {
ModeledInstruction::new(instr, &self.info)
}
}