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
impl MirContext
Sourcepub fn link_modules_for_interpret(&self)
Available on crate feature interp
only.
pub fn link_modules_for_interpret(&self)
interp
only.Link loaded modules and external names, preparing to be interpreted.
§Panics
Panic from C on unresolved names.
Sourcepub unsafe fn link_modules_for_interpret_with_resolver(
&self,
resolver: &dyn Fn(&CStr) -> *mut c_void,
)
Available on crate feature interp
only.
pub unsafe fn link_modules_for_interpret_with_resolver( &self, resolver: &dyn Fn(&CStr) -> *mut c_void, )
interp
only.Sourcepub unsafe fn interpret_unchecked(
&self,
func: FuncItemRef<'_>,
results: &mut [Val],
args: &[Val],
)
Available on crate feature interp
only.
pub unsafe fn interpret_unchecked( &self, func: FuncItemRef<'_>, results: &mut [Val], args: &[Val], )
interp
only.Source§impl MirContext
impl MirContext
Sourcepub fn as_raw(&self) -> *mut MIR_context
pub fn as_raw(&self) -> *mut MIR_context
Get the underlying pointer for FFI.
Sourcepub fn dump(&self) -> String
pub fn dump(&self) -> String
Dump the content in a textual representation for human consumption.
Sourcepub fn get_modules(&self) -> Vec<MirModuleRef<'_>>
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.
Sourcepub fn serialize(&self) -> Vec<u8> ⓘ
Available on crate feature io
only.
pub fn serialize(&self) -> Vec<u8> ⓘ
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.
Sourcepub unsafe fn deserialize(&self, bytes: &[u8])
Available on crate feature io
only.
pub unsafe fn deserialize(&self, bytes: &[u8])
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.
Sourcepub fn enter_new_module(&self, name: &CStr) -> MirModuleBuilder<'_>
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.
Sourcepub fn load_module(&self, module: MirModuleRef<'_>)
pub fn load_module(&self, module: MirModuleRef<'_>)
Load an MIR module for linking.
Sourcepub unsafe fn load_external(&self, name: &CStr, addr: *mut c_void)
pub unsafe fn load_external(&self, name: &CStr, addr: *mut c_void)
Sourcepub unsafe fn link_modules_raw(
&self,
set_interface: Option<unsafe extern "C-unwind" fn(ctx: MIR_context_t, item: MIR_item_t)>,
resolver: Option<&dyn Fn(&CStr) -> *mut c_void>,
)
pub unsafe fn link_modules_raw( &self, set_interface: Option<unsafe extern "C-unwind" fn(ctx: MIR_context_t, item: MIR_item_t)>, resolver: Option<&dyn Fn(&CStr) -> *mut c_void>, )
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.