use fuel_asm::Instruction;
use fuel_types::{
ContractId,
Word,
};
use crate::consts::VM_MAX_RAM;
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Breakpoint {
contract: ContractId,
pc: Word,
}
impl Breakpoint {
pub(crate) const fn raw(contract: ContractId, pc: Word) -> Self {
Self { contract, pc }
}
pub const fn new(contract: ContractId, pc: Word) -> Self {
let pc = pc.saturating_mul(Instruction::SIZE as Word);
assert!(pc <= VM_MAX_RAM, "Breakpoint cannot fit into vm memory");
Self::raw(contract, pc)
}
pub fn script(pc: Word) -> Self {
let contract = Default::default();
Self::new(contract, pc)
}
pub const fn contract(&self) -> &ContractId {
&self.contract
}
pub const fn pc(&self) -> Word {
self.pc
}
}
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum DebugEval {
Breakpoint(Breakpoint),
#[default]
Continue,
}
impl From<Breakpoint> for DebugEval {
fn from(b: Breakpoint) -> Self {
Self::Breakpoint(b)
}
}
impl DebugEval {
pub const fn should_continue(&self) -> bool {
matches!(self, Self::Continue)
}
pub const fn breakpoint(&self) -> Option<&Breakpoint> {
match self {
Self::Breakpoint(b) => Some(b),
_ => None,
}
}
}