revm_handler/
instructions.rs1use auto_impl::auto_impl;
2use context_interface::ContextTr;
3use interpreter::{
4 table::{make_instruction_table, InstructionTable},
5 Host, Interpreter, InterpreterAction, InterpreterTypes,
6};
7use std::rc::Rc;
8
9#[auto_impl(&, Arc, Rc)]
11pub trait InstructionProvider {
12 type Context;
13 type InterpreterTypes: InterpreterTypes;
14 type Output;
15
16 fn instruction_table(&self) -> &InstructionTable<Self::InterpreterTypes, Self::Context>;
17}
18
19pub struct EthInstructions<WIRE: InterpreterTypes, HOST> {
20 pub instruction_table: Rc<InstructionTable<WIRE, HOST>>,
21}
22
23impl<WIRE, HOST> Clone for EthInstructions<WIRE, HOST>
24where
25 WIRE: InterpreterTypes,
26{
27 fn clone(&self) -> Self {
28 Self {
29 instruction_table: self.instruction_table.clone(),
30 }
31 }
32}
33
34impl<WIRE, HOST> EthInstructions<WIRE, HOST>
35where
36 WIRE: InterpreterTypes,
37 HOST: Host,
38{
39 pub fn new_mainnet() -> Self {
40 Self::new(make_instruction_table::<WIRE, HOST>())
41 }
42
43 pub fn new(base_table: InstructionTable<WIRE, HOST>) -> Self {
44 Self {
45 instruction_table: Rc::new(base_table),
46 }
47 }
48}
49
50pub trait ContextInspectRun {
51 type InterpreterTypes: InterpreterTypes;
52 type Context: ContextTr + Host;
53
54 fn run_context(
55 &mut self,
56 interpretere: Interpreter<Self::InterpreterTypes>,
57 instructions: &InstructionTable<Self::InterpreterTypes, Self::Context>,
58 );
59}
60
61impl<IT, CTX> InstructionProvider for EthInstructions<IT, CTX>
62where
63 IT: InterpreterTypes,
64 CTX: Host,
65{
66 type InterpreterTypes = IT;
67 type Context = CTX;
68 type Output = InterpreterAction;
71
72 fn instruction_table(&self) -> &InstructionTable<Self::InterpreterTypes, Self::Context> {
73 &self.instruction_table
74 }
75}
76
77impl<WIRE, HOST> Default for EthInstructions<WIRE, HOST>
78where
79 WIRE: InterpreterTypes,
80 HOST: Host,
81{
82 fn default() -> Self {
83 Self::new_mainnet()
84 }
85}