#![allow(missing_docs)]

use abi_serde::impl_struct_serde;

use super::FrameOps;

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, Default)]
#[repr(C)]
pub struct SavedFrame {
    pub rax: u64,
    pub rcx: u64,
    pub rdx: u64,
    pub rbx: u64,
    pub rsi: u64,
    pub rdi: u64,
    pub rbp: u64,

    pub r8: u64,
    pub r9: u64,
    pub r10: u64,
    pub r11: u64,
    pub r12: u64,
    pub r13: u64,
    pub r14: u64,
    pub r15: u64,

    pub user_ip: u64,
    pub user_sp: u64,
    pub rflags: u64,
}

impl FrameOps for SavedFrame {
    fn set_user_ip(&mut self, value: usize) {
        self.user_ip = value as _;
    }

    fn user_ip(&self) -> usize {
        self.user_ip as _
    }
}

impl_struct_serde!(SavedFrame: [
    rax,
    rcx,
    rdx,
    rbx,
    rsi,
    rdi,
    rbp,

    r8,
    r9,
    r10,
    r11,
    r12,
    r13,
    r14,
    r15,

    user_ip,
    user_sp,
    rflags
]);
