Struct MirContext

Source
pub struct MirContext { /* private fields */ }
Expand description

The context for code generation, linking and interpreter.

Almost all MIR functionality requires an initialized context to work. The context is not thread-safe.

Implementations§

Source§

impl MirContext

Available on crate feature interp only.

Link loaded modules and external names, preparing to be interpreted.

§Panics

Panic from C on unresolved names.

Available on crate feature interp only.

Link loaded modules and external names with custom resolver, preparing to be interpreted.

§Safety

resolver must return valid function pointers with prototype expected by generated code, or NULL if unresolved.

§Panics

Panic from C on unresolved names.

Source

pub unsafe fn interpret_unchecked( &self, func: FuncItemRef<'_>, results: &mut [Val], args: &[Val], )

Available on crate feature interp only.

Execute a function using the interpreter.

§Safety

The types and lengths of arguments and results must match the function signature.

§Panics

Panic from C on (detectable) interpretation errors.

Source§

impl MirContext

Source

pub fn new() -> Self

Initialize a new MIR context.

Source

pub fn as_raw(&self) -> *mut MIR_context

Get the underlying pointer for FFI.

Source

pub fn dump(&self) -> String

Dump the content in a textual representation for human consumption.

Source

pub fn get_modules(&self) -> Vec<MirModuleRef<'_>>

Get the list of all modules in the context.

This includes all modules created in this context, not necessarily loaded or linked.

Source

pub fn serialize(&self) -> Vec<u8>

Available on crate feature io only.

Serialize the context (including all modules) into bytes.

The serialization format is stable across executions, but may not be stable across MIR versions.

Source

pub unsafe fn deserialize(&self, bytes: &[u8])

Available on crate feature io only.

Deserialize context or modules from bytes.

It will create one or more modules in bytes. The deserialized modules will be as if they are created manually, not loaded or linked yet.

§Safety

bytes must be trusted and produced from previous serialization.

§Panics

Panic if there is any unfinished module. Panic from C if the bytes cannot be parsed or contain errors.

Source

pub fn enter_new_module(&self, name: &CStr) -> MirModuleBuilder<'_>

Create a new module and enter it.

The MIR context is stateful. When entering a new module, it should be correctly finished before creating another module. See MirModuleBuilder for more details.

§Panics

Panic if there is any unfinished module.

Source

pub fn load_module(&self, module: MirModuleRef<'_>)

Load an MIR module for linking.

Source

pub unsafe fn load_external(&self, name: &CStr, addr: *mut c_void)

Load an external name pointing to addr for linking.

§Example
// let ctx: &MirContext;
unsafe { ctx.load_external(c"memset", libc::memset as _) };
§Safety

addr must be a valid function pointer with prototype expected by generated code.

Link loaded modules and external names with given custom interface and resolver.

§Safety

set_interface should be one of MIR_set_*_interface. resolver must return valid function pointers with prototype expected by generated code.

Trait Implementations§

Source§

impl Debug for MirContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MirContext

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for MirContext

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.