revmc_runtime/runtime/
api.rs1use crate::{
4 EvmCompilerFn,
5 runtime::{storage::RuntimeCacheKey, worker::JitCodeBacking},
6};
7use alloy_primitives::{B256, Bytes};
8use revm_primitives::hardfork::SpecId;
9use std::sync::Arc;
10
11#[derive(Clone, Debug)]
13pub struct LookupRequest {
14 pub key: RuntimeCacheKey,
16 pub code: Bytes,
18}
19
20#[derive(Clone, Debug)]
22pub enum LookupDecision {
23 Compiled(Arc<CompiledProgram>),
25 Interpret(InterpretReason),
27}
28
29#[derive(Clone, Copy, Debug, PartialEq, Eq)]
31pub enum InterpretReason {
32 Disabled,
34 Ineligible,
36 NotReady,
38 JitFailed,
40}
41
42pub struct CompiledProgram {
44 pub func: EvmCompilerFn,
46 pub key: RuntimeCacheKey,
48 pub kind: ProgramKind,
50 _backing: ProgramBacking,
52}
53
54impl std::fmt::Debug for CompiledProgram {
55 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
56 f.debug_struct("CompiledProgram")
57 .field("key", &self.key)
58 .field("kind", &self.kind)
59 .field("func", &self.func)
60 .finish_non_exhaustive()
61 }
62}
63
64impl CompiledProgram {
65 pub(crate) fn new_aot(
67 key: RuntimeCacheKey,
68 func: EvmCompilerFn,
69 library: Arc<LoadedLibrary>,
70 ) -> Self {
71 Self { key, kind: ProgramKind::Aot, func, _backing: ProgramBacking::LoadedLibrary(library) }
72 }
73
74 pub(crate) fn new_jit(
77 key: RuntimeCacheKey,
78 func: EvmCompilerFn,
79 backing: Arc<JitCodeBacking>,
80 ) -> Self {
81 Self { key, kind: ProgramKind::Jit, func, _backing: ProgramBacking::JitModule(backing) }
82 }
83}
84
85#[derive(Clone, Debug)]
87pub struct AotRequest {
88 pub code_hash: B256,
90 pub code: Bytes,
92 pub spec_id: SpecId,
94}
95
96#[derive(Clone, Copy, Debug, PartialEq, Eq)]
98pub enum ProgramKind {
99 Aot,
101 Jit,
103}
104
105#[expect(dead_code, reason = "variant fields are held alive for Drop")]
107enum ProgramBacking {
108 LoadedLibrary(Arc<LoadedLibrary>),
110 JitModule(Arc<JitCodeBacking>),
113}
114
115pub(crate) struct LoadedLibrary {
119 _library: libloading::Library,
121}
122
123impl LoadedLibrary {
124 pub(crate) fn new(library: libloading::Library) -> Self {
126 Self { _library: library }
127 }
128}