zkvmc_context/
compiler.rs

1use crate::Context;
2use std::ptr::NonNull;
3
4/// A function that compiled by the Backend.
5#[repr(transparent)]
6#[derive(Clone, Copy)]
7pub struct JitFn(pub extern "C" fn(NonNull<Context>) -> JitFn);
8
9// A trampoline function communicate between the compiled code and the VM
10// to get the next compiled code block.
11pub extern "C" fn trampoline(ctx: NonNull<Context>) -> JitFn {
12    unsafe { (*ctx.as_ptr()).compiler.compile(ctx) }
13}
14
15/// A trait for the compiler backend.
16pub trait Compiler {
17    /// Get the next compiled function from the Compiler.
18    fn compile(&mut self, ctx: NonNull<Context>) -> JitFn;
19}
20
21pub struct NoopCompiler;
22impl Compiler for NoopCompiler {
23    fn compile(&mut self, _ctx: NonNull<Context>) -> JitFn {
24        unreachable!()
25    }
26}
27
28#[derive(Default)]
29pub struct CompileConfig {
30    /// If dump the disassembly of the generated code.
31    pub dump: bool,
32}