use fuel_asm::Opcode;
use fuel_types::{ContractId, Word};
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde-types", 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 * (Opcode::LEN as Word);
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, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde-types", derive(serde::Serialize, serde::Deserialize))]
pub enum DebugEval {
Breakpoint(Breakpoint),
Continue,
}
impl Default for DebugEval {
fn default() -> Self {
Self::Continue
}
}
impl From<Breakpoint> for DebugEval {
fn from(b: Breakpoint) -> Self {
Self::Breakpoint(b)
}
}
impl DebugEval {
pub const fn should_continue(&self) -> bool {
match self {
Self::Continue => true,
_ => false,
}
}
pub const fn breakpoint(&self) -> Option<&Breakpoint> {
match self {
Self::Breakpoint(b) => Some(b),
_ => None,
}
}
}