revm_handler/
instructions.rs1use auto_impl::auto_impl;
2use interpreter::{
3 instructions::{instruction_table, InstructionTable},
4 Host, Instruction, InterpreterTypes,
5};
6use std::boxed::Box;
7
8#[auto_impl(&, Arc, Rc)]
10pub trait InstructionProvider {
11 type Context;
13 type InterpreterTypes: InterpreterTypes;
15
16 fn instruction_table(&self) -> &InstructionTable<Self::InterpreterTypes, Self::Context>;
18}
19
20#[derive(Debug)]
22pub struct EthInstructions<WIRE: InterpreterTypes, HOST> {
23 pub instruction_table: Box<InstructionTable<WIRE, HOST>>,
25}
26
27impl<WIRE, HOST> Clone for EthInstructions<WIRE, HOST>
28where
29 WIRE: InterpreterTypes,
30{
31 fn clone(&self) -> Self {
32 Self {
33 instruction_table: self.instruction_table.clone(),
34 }
35 }
36}
37
38impl<WIRE, HOST> EthInstructions<WIRE, HOST>
39where
40 WIRE: InterpreterTypes,
41 HOST: Host,
42{
43 pub fn new_mainnet() -> Self {
45 Self::new(instruction_table::<WIRE, HOST>())
46 }
47
48 pub fn new(base_table: InstructionTable<WIRE, HOST>) -> Self {
50 Self {
51 instruction_table: Box::new(base_table),
52 }
53 }
54
55 pub fn insert_instruction(&mut self, opcode: u8, instruction: Instruction<WIRE, HOST>) {
57 self.instruction_table[opcode as usize] = instruction;
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
69 fn instruction_table(&self) -> &InstructionTable<Self::InterpreterTypes, Self::Context> {
70 &self.instruction_table
71 }
72}
73
74impl<WIRE, HOST> Default for EthInstructions<WIRE, HOST>
75where
76 WIRE: InterpreterTypes,
77 HOST: Host,
78{
79 fn default() -> Self {
80 Self::new_mainnet()
81 }
82}