zkvmc-context 0.0.1

zkVMc runtime context
Documentation
use crate::Context;
use std::ptr::NonNull;

/// A function that compiled by the Backend.
#[repr(transparent)]
#[derive(Clone, Copy)]
pub struct JitFn(pub extern "C" fn(NonNull<Context>) -> JitFn);

// A trampoline function communicate between the compiled code and the VM
// to get the next compiled code block.
pub extern "C" fn trampoline(ctx: NonNull<Context>) -> JitFn {
    unsafe { (*ctx.as_ptr()).compiler.compile(ctx) }
}

/// A trait for the compiler backend.
pub trait Compiler {
    /// Get the next compiled function from the Compiler.
    fn compile(&mut self, ctx: NonNull<Context>) -> JitFn;
}

pub struct NoopCompiler;
impl Compiler for NoopCompiler {
    fn compile(&mut self, _ctx: NonNull<Context>) -> JitFn {
        unreachable!()
    }
}

#[derive(Default)]
pub struct CompileConfig {
    /// If dump the disassembly of the generated code.
    pub dump: bool,
}