pub struct MirGenContext { /* private fields */ }
gen
only.Expand description
The MIR context for native code generation.
Implementations§
Source§impl MirGenContext
impl MirGenContext
Sourcepub fn new(ctx: MirContext) -> Self
pub fn new(ctx: MirContext) -> Self
Initialize the codegen context on top of an existing MIR context.
Sourcepub fn set_opt_level(&self, level: u32)
pub fn set_opt_level(&self, level: u32)
Set the optimization level to use.
See details in MIR documentation.
Sourcepub fn enable_debug(&self, level: c_int)
Available on crate feature gen-debug
only.
pub fn enable_debug(&self, level: c_int)
gen-debug
only.Enable internal debug logging with specific level.
Logs will be collected in memory and can be retrieved by Self::get_debug_output
.
Sourcepub fn get_debug_output(&self) -> String
Available on crate feature gen-debug
only.
pub fn get_debug_output(&self) -> String
gen-debug
only.Retrieve the debug logs collected so far.
Note: logs will not be cleared after the call. Memory can only be freed after destroyed the context.
§Panics
Panics if debug logging is not enabled before.
Sourcepub fn link_modules_for_codegen(&self)
pub fn link_modules_for_codegen(&self)
Link loaded modules and external names, preparing to be codegen.
§Panics
Panic from C on unresolved names.
Sourcepub unsafe fn link_modules_for_codegen_with_resolver(
&self,
resolver: &dyn Fn(&CStr) -> *mut c_void,
)
pub unsafe fn link_modules_for_codegen_with_resolver( &self, resolver: &dyn Fn(&CStr) -> *mut c_void, )
Sourcepub fn codegen_func(&self, func: FuncItemRef<'_>) -> *mut c_void
pub fn codegen_func(&self, func: FuncItemRef<'_>) -> *mut c_void
Generate native code and return the function pointer to func
.
This function is idempotic, that is, once code is generated for func
, all later calls
will do nothing and simply return the same function pointer.
Methods from Deref<Target = 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.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.