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>
impl<'ctx> MirModuleBuilder<'ctx>
Sourcepub fn finish(self) -> MirModuleRef<'ctx>
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.
Sourcepub fn add_proto(
&self,
name: &CStr,
rets: &[Ty],
args: &[(&CStr, Ty)],
) -> ProtoItemRef<'_>
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.
Sourcepub fn add_import(&self, name: &CStr) -> ImportItemRef<'_>
pub fn add_import(&self, name: &CStr) -> ImportItemRef<'_>
Sourcepub fn add_export(&self, name: &CStr) -> ExportItemRef<'_>
pub fn add_export(&self, name: &CStr) -> ExportItemRef<'_>
Sourcepub fn add_forward(&self, name: &CStr) -> ForwardItemRef<'_>
pub fn add_forward(&self, name: &CStr) -> ForwardItemRef<'_>
Sourcepub fn add_data<'a>(
&self,
name: impl Into<Option<&'a CStr>>,
data: &[u8],
) -> DataItemRef<'_>
pub fn add_data<'a>( &self, name: impl Into<Option<&'a CStr>>, data: &[u8], ) -> DataItemRef<'_>
Sourcepub fn add_ref_data<'a>(
&self,
name: impl Into<Option<&'a CStr>>,
ref_item: ItemRef<'_>,
disp: i64,
) -> RefDataItemRef<'_>
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.
Sourcepub fn add_expr_data<'a>(
&self,
name: impl Into<Option<&'a CStr>>,
expr_func: FuncItemRef<'_>,
) -> ExprDataItemRef<'_>
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.
Sourcepub fn add_label_ref_data<'module>(
&'module self,
name: &CStr,
label: Label<'module>,
base_label: Option<Label<'module>>,
disp: i64,
) -> LabelRefDataItemRef<'module>
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.
Sourcepub fn add_bss<'a>(
&self,
name: impl Into<Option<&'a CStr>>,
len: usize,
) -> BssItemRef<'_>
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.
Sourcepub fn enter_new_function<'module>(
&'module self,
name: &CStr,
rets: &[Ty],
args: &[(&CStr, Ty)],
) -> MirFuncBuilder<'module, 'ctx>
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.