pub trait State<'a> {
Show 16 methods
// Required methods
fn get_function(&self, func_ref: FuncRef) -> Option<&'a Function>;
fn get_current_function(&self) -> &'a Function;
fn get_libcall_handler(&self) -> LibCallHandler;
fn push_frame(&mut self, function: &'a Function);
fn pop_frame(&mut self);
fn current_frame_mut(&mut self) -> &mut Frame<'a>;
fn current_frame(&self) -> &Frame<'a>;
fn stack_address(
&self,
size: AddressSize,
slot: StackSlot,
offset: u64,
) -> Result<Address, MemoryError>;
fn checked_load(
&self,
address: Address,
ty: Type,
mem_flags: MemFlags,
) -> Result<DataValue, MemoryError>;
fn checked_store(
&mut self,
address: Address,
v: DataValue,
mem_flags: MemFlags,
) -> Result<(), MemoryError>;
fn function_address(
&self,
size: AddressSize,
name: &ExternalName,
) -> Result<Address, MemoryError>;
fn get_function_from_address(
&self,
address: Address,
) -> Option<InterpreterFunctionRef<'a>>;
fn resolve_global_value(
&self,
gv: GlobalValue,
) -> Result<DataValue, MemoryError>;
fn get_pinned_reg(&self) -> DataValue;
fn set_pinned_reg(&mut self, v: DataValue);
// Provided method
fn collect_values(&self, names: &[Value]) -> SmallVec<[DataValue; 1]> { ... }
}
Expand description
This trait manages the state necessary to interpret a single Cranelift instruction–it describes all of the ways a Cranelift interpreter can interact with its virtual state. This makes it possible to use the Interpreter in a range of situations:
- when interpretation needs to happen in a way isolated from the host a state which keeps a stack and bound checks memory accesses can be used, like InterpreterState.
- when interpretation needs to have access to the host a state which allows direct access to the host memory and native functions can be used.
Required Methods§
Sourcefn get_function(&self, func_ref: FuncRef) -> Option<&'a Function>
fn get_function(&self, func_ref: FuncRef) -> Option<&'a Function>
Retrieve a reference to a [Function].
Sourcefn get_current_function(&self) -> &'a Function
fn get_current_function(&self) -> &'a Function
Retrieve a reference to the currently executing [Function].
Sourcefn get_libcall_handler(&self) -> LibCallHandler
fn get_libcall_handler(&self) -> LibCallHandler
Retrieve the handler callback for a [LibCall]
Sourcefn push_frame(&mut self, function: &'a Function)
fn push_frame(&mut self, function: &'a Function)
Record that an interpreter has called into a new [Function].
fn current_frame_mut(&mut self) -> &mut Frame<'a>
fn current_frame(&self) -> &Frame<'a>
Sourcefn stack_address(
&self,
size: AddressSize,
slot: StackSlot,
offset: u64,
) -> Result<Address, MemoryError>
fn stack_address( &self, size: AddressSize, slot: StackSlot, offset: u64, ) -> Result<Address, MemoryError>
Computes the stack address for this stack slot, including an offset.
Sourcefn checked_load(
&self,
address: Address,
ty: Type,
mem_flags: MemFlags,
) -> Result<DataValue, MemoryError>
fn checked_load( &self, address: Address, ty: Type, mem_flags: MemFlags, ) -> Result<DataValue, MemoryError>
Retrieve a value V
from memory at the given address
, checking if it belongs either to the
stack or to one of the heaps; the number of bytes loaded corresponds to the specified [Type].
Sourcefn checked_store(
&mut self,
address: Address,
v: DataValue,
mem_flags: MemFlags,
) -> Result<(), MemoryError>
fn checked_store( &mut self, address: Address, v: DataValue, mem_flags: MemFlags, ) -> Result<(), MemoryError>
Store a value V
into memory at the given address
, checking if it belongs either to the
stack or to one of the heaps; the number of bytes stored corresponds to the specified [Type].
Sourcefn function_address(
&self,
size: AddressSize,
name: &ExternalName,
) -> Result<Address, MemoryError>
fn function_address( &self, size: AddressSize, name: &ExternalName, ) -> Result<Address, MemoryError>
Compute the address of a function given its name.
Sourcefn get_function_from_address(
&self,
address: Address,
) -> Option<InterpreterFunctionRef<'a>>
fn get_function_from_address( &self, address: Address, ) -> Option<InterpreterFunctionRef<'a>>
Retrieve a reference to a [Function] given its address.
Sourcefn resolve_global_value(
&self,
gv: GlobalValue,
) -> Result<DataValue, MemoryError>
fn resolve_global_value( &self, gv: GlobalValue, ) -> Result<DataValue, MemoryError>
Given a global value, compute the final value for that global value, applying all operations in intermediate global values.
Sourcefn get_pinned_reg(&self) -> DataValue
fn get_pinned_reg(&self) -> DataValue
Retrieves the current pinned reg value
Sourcefn set_pinned_reg(&mut self, v: DataValue)
fn set_pinned_reg(&mut self, v: DataValue)
Sets a value for the pinned reg
Provided Methods§
Sourcefn collect_values(&self, names: &[Value]) -> SmallVec<[DataValue; 1]>
fn collect_values(&self, names: &[Value]) -> SmallVec<[DataValue; 1]>
Collect a list of values V
by their value references.