pub struct EvmBackend { /* private fields */ }Expand description
EVM bytecode code generation backend.
Converts an EvmContract into:
- Raw binary bytecode (
Vec<u8>) - Hex string representation
- Human-readable assembly text
Implementations§
Source§impl EvmBackend
impl EvmBackend
Sourcepub fn compute_selector(signature: &str) -> [u8; 4]
pub fn compute_selector(signature: &str) -> [u8; 4]
Compute a 4-byte function selector from an ABI signature string.
This is a placeholder using a fast mixing hash (not real keccak256). In production this should use a proper keccak256 crate.
Sourcepub fn emit_dispatcher(&self, contract: &EvmContract) -> Vec<EvmInstruction>
pub fn emit_dispatcher(&self, contract: &EvmContract) -> Vec<EvmInstruction>
Emit the standard ABI dispatcher preamble.
This code:
- Loads the first 4 bytes of calldata (the function selector).
- Compares against each known selector.
- Jumps to the appropriate handler block.
- Falls through to REVERT if no selector matches.
Sourcepub fn emit_sload(&self, slot: u64) -> Vec<EvmInstruction>
pub fn emit_sload(&self, slot: u64) -> Vec<EvmInstruction>
Emit instructions to load a storage variable onto the stack.
Sourcepub fn emit_sstore(&self, slot: u64) -> Vec<EvmInstruction>
pub fn emit_sstore(&self, slot: u64) -> Vec<EvmInstruction>
Emit instructions to store the top-of-stack value into a storage slot.
Assumes the value to store is already on the stack.
Sourcepub fn emit_constructor_bytes(&self, contract: &EvmContract) -> Vec<u8> ⓘ
pub fn emit_constructor_bytes(&self, contract: &EvmContract) -> Vec<u8> ⓘ
Encode the constructor code portion of a contract to raw bytes.
Sourcepub fn emit_runtime_bytes(&self, contract: &EvmContract) -> Vec<u8> ⓘ
pub fn emit_runtime_bytes(&self, contract: &EvmContract) -> Vec<u8> ⓘ
Encode the full runtime bytecode of a contract to raw bytes.
Layout: dispatcher preamble + function bodies (each starting with JUMPDEST).
Sourcepub fn emit_init_code(&self, contract: &EvmContract) -> Vec<u8> ⓘ
pub fn emit_init_code(&self, contract: &EvmContract) -> Vec<u8> ⓘ
Encode the complete init code (constructor + runtime deployment stub).
The init code:
- Runs constructor logic.
- Returns a copy of the runtime bytecode so the EVM stores it.
Sourcepub fn emit_hex(&self, contract: &EvmContract) -> String
pub fn emit_hex(&self, contract: &EvmContract) -> String
Encode the runtime bytecode as a hex string (no 0x prefix).
Sourcepub fn emit_hex_prefixed(&self, contract: &EvmContract) -> String
pub fn emit_hex_prefixed(&self, contract: &EvmContract) -> String
Encode the runtime bytecode as a hex string with 0x prefix.
Sourcepub fn emit_init_hex(&self, contract: &EvmContract) -> String
pub fn emit_init_hex(&self, contract: &EvmContract) -> String
Encode the full init code as a hex string with 0x prefix.
Sourcepub fn emit_assembly(&self, contract: &EvmContract) -> String
pub fn emit_assembly(&self, contract: &EvmContract) -> String
Emit human-readable assembly text for an EvmContract.
Sourcepub fn build_arithmetic_function(
name: &str,
signature: &str,
selector: [u8; 4],
op: EvmOpcode,
) -> EvmFunction
pub fn build_arithmetic_function( name: &str, signature: &str, selector: [u8; 4], op: EvmOpcode, ) -> EvmFunction
Build a simple two-argument arithmetic function (e.g. add(uint256,uint256)).
Loads arg0 from calldata[4], arg1 from calldata[36], applies op, stores
result in memory[0..32], and returns 32 bytes.