Module

Struct Module 

Source
pub struct Module<'a>(/* private fields */);
Expand description

Wraps LLVMModule

Implementations§

Source§

impl<'a> Module<'a>

Source

pub fn new( ctx: &Context<'a>, name: impl AsRef<str>, ) -> Result<Module<'a>, Error>

Create a new module

Source

pub fn context(&self) -> Result<Context<'a>, Error>

Get the associated context

Source

pub fn identifier(&self) -> Result<&str, Error>

Get the module identifier

Source

pub fn set_source_file(&mut self, name: impl AsRef<str>)

Set the module source file name

Source

pub fn source_file(&self) -> Result<&str, Error>

Get the source file name

Source

pub fn set_target(&mut self, target: impl AsRef<str>)

Set the module target string

Source

pub fn target(&self) -> Result<&str, Error>

Get the target string

Source

pub fn set_data_layout(&mut self, layout: impl AsRef<str>)

Set the module data layout string

Source

pub fn data_layout(&self) -> Result<&str, Error>

Get data layout string

Source

pub fn set_inline_asm(&mut self, asm: impl AsRef<str>)

Set module inline assembly

Source

pub fn append_inline_asm(&mut self, asm: impl AsRef<str>)

Append module inline assembly

Source

pub fn inline_asm(&self) -> Result<&str, Error>

Get module inline assembly

Source

pub fn verify(&self) -> Result<(), Error>

Verify the module, returning an error on failure

Source

pub fn define_function( &self, name: impl AsRef<str>, t: FuncType<'_>, ) -> Result<Func<'a>, Error>

Define a new function without declaring a function body

Source

pub fn declare_function<T: Into<Value<'a>>, F: FnOnce(Func<'a>) -> Result<T, Error>>( &self, builder: &Builder<'a>, name: impl AsRef<str>, ft: FuncType<'_>, def: F, ) -> Result<Func<'a>, Error>

Declare a new function with function body

Source

pub fn define_global( &self, name: impl AsRef<str>, ty: impl AsRef<Type<'a>>, ) -> Result<Value<'a>, Error>

Create a new global with an empty initializer

Source

pub fn define_global_in_address_space( &self, name: impl AsRef<str>, ty: impl AsRef<Type<'a>>, addr: usize, ) -> Result<Value<'a>, Error>

Define a new global in the given address space with an empty initializer

Source

pub fn declare_global( &self, name: impl AsRef<str>, t: impl AsRef<Value<'a>>, ) -> Result<Value<'a>, Error>

Create a new global with the specified initializer

Source

pub fn declare_global_in_address_space( &self, name: impl AsRef<str>, t: impl AsRef<Value<'a>>, addr: usize, ) -> Result<Value<'a>, Error>

Create a new global in the given address space with the specified initializer

Source

pub fn function(&self, name: impl AsRef<str>) -> Result<Func<'a>, Error>

Get a function by name

Source

pub fn global(&self, name: impl AsRef<str>) -> Result<Value<'a>, Error>

Get a global value by name

Source

pub fn first_global(&self) -> Result<Value<'a>, Error>

Get the first global

Source

pub fn last_global(&self) -> Result<Value<'a>, Error>

Get the last global

Source

pub fn next_global( &self, global: impl AsRef<Value<'a>>, ) -> Result<Value<'a>, Error>

Get the next global

Source

pub fn first_function(&self) -> Result<Func<'a>, Error>

Get the first function

Source

pub fn last_function(&self) -> Result<Func<'a>, Error>

Get the last function

Source

pub fn parse_ir( ctx: &Context<'_>, mem_buf: &MemoryBuffer, ) -> Result<Module<'a>, Error>

Create a new module from existing IR

Source

pub fn parse_bitcode( ctx: &Context<'_>, mem_buf: &MemoryBuffer, ) -> Option<Module<'a>>

Create a new module from existing bitcode

Source

pub fn write_bitcode_to_file( &self, path: impl AsRef<Path>, ) -> Result<bool, Error>

Write module bitcode to file

Source

pub fn write_bitcode_to_memory_buffer(&self) -> Result<MemoryBuffer, Error>

Write module bitcode to in-memory buffer

Link another module into self

Source

pub fn set_wasm32(&mut self)

Set WASM32 target/data layout

Source

pub fn set_target_data(&mut self, target: &TargetData<'_>)

Set target data

Source

pub fn target_data(&self) -> Result<TargetData<'_>, Error>

Get target data

Trait Implementations§

Source§

impl<'a> Clone for Module<'a>

Source§

fn clone(&self) -> Module<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Display for Module<'a>

Source§

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

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

impl<'a> Drop for Module<'a>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<'a> LLVM<LLVMModule> for Module<'a>

Source§

fn llvm(&self) -> *mut LLVMModule

Return a LLVM pointer

Auto Trait Implementations§

§

impl<'a> !Freeze for Module<'a>

§

impl<'a> RefUnwindSafe for Module<'a>

§

impl<'a> !Send for Module<'a>

§

impl<'a> !Sync for Module<'a>

§

impl<'a> Unpin for Module<'a>

§

impl<'a> UnwindSafe for Module<'a>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.