Struct MirModuleBuilder

Source
pub struct MirModuleBuilder<'ctx> { /* private fields */ }
Expand description

The currently building MIR module.

There can only be at most one unfinished module for each MirContext. It is strongly advised to explicitly call MirModuleBuilder::finish to finish the current module for clarity and observe any error outside drop impl. MirModuleBuilder will automatically finish it on drop.

Implementations§

Source§

impl<'ctx> MirModuleBuilder<'ctx>

Source

pub fn finish(self) -> MirModuleRef<'ctx>

Explicitly finish the module and return the module reference.

§Panics

Panic from C if the module content is malformed.

Source

pub fn add_proto( &self, name: &CStr, rets: &[Ty], args: &[(&CStr, Ty)], ) -> ProtoItemRef<'_>

Add a new function prototype and return its reference.

§Panics

Panic from C on duplicated names or invalid signature.

Source

pub fn add_import(&self, name: &CStr) -> ImportItemRef<'_>

Add a new import name and return its reference.

§Panics

Panic from C on duplicated names.

Source

pub fn add_export(&self, name: &CStr) -> ExportItemRef<'_>

Add a new export name and return its reference.

§Panics

Panic from C on duplicated names.

Source

pub fn add_forward(&self, name: &CStr) -> ForwardItemRef<'_>

Add a new forward declaration and return its reference.

§Panics

Panic from C on duplicated names.

Source

pub fn add_data<'a>( &self, name: impl Into<Option<&'a CStr>>, data: &[u8], ) -> DataItemRef<'_>

Add a new forward declaration and return its reference.

§Panics

Panic from C on duplicated names.

Source

pub fn add_ref_data<'a>( &self, name: impl Into<Option<&'a CStr>>, ref_item: ItemRef<'_>, disp: i64, ) -> RefDataItemRef<'_>

Add a new data referencing another item and return its reference.

The address of ref_item after linking plus disp is used to initialize the data.

§Panics

Panic from C on duplicated names.

Source

pub fn add_expr_data<'a>( &self, name: impl Into<Option<&'a CStr>>, expr_func: FuncItemRef<'_>, ) -> ExprDataItemRef<'_>

Add a new data initialized by a function and return its reference.

  • Not all MIR functions can be used for expression data. The expression function should have only one result, have no arguments, not use any call or any instruction with memory.
  • The expression function is called during linking and its result is used to initialize the data.
§Panics

Panic from C on duplicated names or unsupported functions.

Source

pub fn add_label_ref_data<'module>( &'module self, name: &CStr, label: Label<'module>, base_label: Option<Label<'module>>, disp: i64, ) -> LabelRefDataItemRef<'module>

Add a new data initialized by a label and return its reference.

The addresses defined as label[-base_label]+disp where base_label can be None. lref can refers for labels the same function (this is checked during module load) and there is a warranty label addresses to be defined only at the beginning of the function execution.

§Panics

Panic from C on duplicated names.

Source

pub fn add_bss<'a>( &self, name: impl Into<Option<&'a CStr>>, len: usize, ) -> BssItemRef<'_>

Add a new writable memory segment and return its reference.

§Panics

Panic from C on duplicated names.

Source

pub fn enter_new_function<'module>( &'module self, name: &CStr, rets: &[Ty], args: &[(&CStr, Ty)], ) -> MirFuncBuilder<'module, 'ctx>

Add a new function definition and enter into it.

The MIR context is stateful and the previous function must be finished before creating another one. See more details in MirFuncBuilder.

§Panics

Panic if there is any unfinished function. Panic from C on duplicated names or invalid signature.

Trait Implementations§

Source§

impl<'ctx> Debug for MirModuleBuilder<'ctx>

Source§

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

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

impl Drop for MirModuleBuilder<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'ctx> Freeze for MirModuleBuilder<'ctx>

§

impl<'ctx> !RefUnwindSafe for MirModuleBuilder<'ctx>

§

impl<'ctx> !Send for MirModuleBuilder<'ctx>

§

impl<'ctx> !Sync for MirModuleBuilder<'ctx>

§

impl<'ctx> Unpin for MirModuleBuilder<'ctx>

§

impl<'ctx> !UnwindSafe for MirModuleBuilder<'ctx>

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.