Struct llvm_lib::core::module::ModuleRef

source ·
pub struct ModuleRef(/* private fields */);
Expand description

LLVM Module wrapper

Implementations§

source§

impl ModuleRef

source

pub fn new(module_name: &str) -> Self

Create LLVM module with name

§Panics

It panics if module creation is null

source

pub fn create_module_with_name(module_name: &str) -> Self

§Panics

It panics if module creation is null

source

pub fn create_module_with_name_in_context( module_name: &str, context: &ContextRef, ) -> Self

§Panics

It panics if module creation is null

source

pub fn clone_module(&self) -> Self

Return an exact copy of the current module.

source

pub fn get_module_identifier(&self) -> Option<String>

Obtain the identifier of a module.

source

pub fn set_module_identifier(&self, ident: &str)

Set the identifier of a module to a string Ident with length Len.

source

pub fn get_source_file_name(&self) -> Option<String>

Obtain the module’s original source file name.

source

pub fn set_source_file_name(&self, name: &str)

Set the original source file name of a module to a string Name with length Len.

source

pub fn get_data_layout_str(&self) -> Option<String>

Get module data layout

source

pub fn set_data_layout(&self, data_layout_str: &str)

Set the data layout for a module.

source

pub fn get_target(&self) -> Option<String>

Obtain the target triple for a module.

source

pub fn set_target(&self, triple: &str)

Set the target triple for a module.

source

pub fn copy_module_flags_metadata(&self) -> Option<ModuleFlagEntry>

Returns the module flags as an array of flag-key-value triples. The caller is responsible for freeing this array by calling dispose_module_flags_metadata.

source

pub fn get_module_flag(&self, key: &str) -> MetadataRef

Add a module-level flag to the module-level flags metadata if it doesn’t already exist.

source

pub fn add_module_flag( &self, behavior: &ModuleFlagBehavior, key: &str, val: &MetadataRef, )

source

pub fn dump_module(&self)

Dump module to stdout

source

pub fn print_module_to_file(&self, filename: &str) -> Result<(), String>

Print a representation of a module to a file. The ErrorMessage needs to be disposed with core::dispose_message. Returns 0 on success, 1 otherwise.

§Errors

Return error as String if print module fails

source

pub fn print_module_to_string(&self) -> Option<String>

Return a string representation of the module.

source

pub fn get_module_inline_asm(&self) -> Option<String>

Get inline assembly for a module.

source

pub fn set_module_inline_asm(&self, asm: &str)

Set inline assembly for a module.

source

pub fn append_module_inline_asm(&self, asm: &str)

Append inline assembly to a module.

source

pub fn get_module_context(&self) -> ContextRef

Obtain the context to which this module is associated.

source

pub fn get_first_named_metadata(&self) -> Option<NamedMetadataNodeRef>

Obtain an iterator to the first NamedMDNode in a Module.

source

pub fn get_last_named_metadata(&self) -> Option<NamedMetadataNodeRef>

Obtain an iterator to the last NamedMDNode in a Module.

source

pub fn get_named_metadata(&self, name: &str) -> Option<NamedMetadataNodeRef>

Retrieve a NamedMetadataNode with the given name, returning None if no such node exists.

source

pub fn get_or_insert_named_metadata(&self, name: &str) -> NamedMetadataNodeRef

Retrieve a NamedMetadataNode with the given name, creating a new node if no such node exists.

source

pub fn get_named_metadata_num_operands(&self, name: &str) -> u32

Obtain the number of operands for named metadata in a module.

source

pub fn get_named_metadata_operands(&self, name: &str) -> Vec<ValueRef>

Obtain the named metadata operands for a module.

The passed ValueRef pointer should refer to an array of ValueRef at least get_names_metadata_operands long. This array will be populated with the ValueRef instances. Each instance corresponds to a Metadata Node.

source

pub fn add_named_metadata_operand(&self, name: &str, val: &ValueRef)

Add an operand to named metadata.

source

pub fn add_function(&self, fn_name: &str, fn_type: &TypeRef) -> ValueRef

Set add function value based on Function type

source

pub fn get_named_function(&self, name: &str) -> ValueRef

Obtain a Function value from a Module by its name.

The returned value corresponds to a Function value.

source

pub fn get_first_function(&self) -> ValueRef

Obtain an iterator to the first Function in a Module.

source

pub fn get_last_function(&self) -> ValueRef

Obtain an iterator to the last Function in a Module.

source§

impl ModuleRef

source

pub fn add_global(&self, ty: &TypeRef, name: &str) -> ValueRef

Adds a new global variable of the specified type to the module.

This function wraps the LLVMAddGlobal function from the LLVM core library. It creates a new global variable in the current module, with the provided type and name. The global variable is initialized with a null value by default and can be further configured using other methods such as setting an initializer or modifying its linkage.

§Parameters
  • ty: A reference to the TypeRef representing the type of the global variable.
  • name: A string slice (&str) representing the name of the global variable.
§Returns

Returns a ValueRef representing the newly added global variable.

source

pub fn add_global_in_address_space( &self, ty: &TypeRef, name: &str, address_space: &AddressSpace, ) -> ValueRef

Adds a new global variable of the specified type to the module in a specific address space.

This function wraps the LLVMAddGlobalInAddressSpace function from the LLVM core library. It creates a new global variable in the specified address space within the current module, with the provided type and name. Address spaces are used in LLVM to specify different memory regions for global variables, such as GPU memory or specialized hardware regions.

§Parameters
  • ty: A reference to the TypeRef representing the type of the global variable.
  • name: A string slice (&str) representing the name of the global variable.
  • address_space: A reference to the AddressSpace where the global variable should be allocated.
§Returns

Returns a ValueRef representing the newly added global variable in the specified address space.

source

pub fn get_named_global(&self, name: &str) -> Option<ValueRef>

Retrieves a global variable by its name from the module.

This function wraps the LLVMGetNamedGlobal function from the LLVM core library. It searches for a global variable with the specified name in the current module and returns it if found. If no global variable with the given name exists in the module, it returns None.

§Parameters
  • name: A string slice (&str) representing the name of the global variable to search for.
§Returns

Returns an Option<ValueRef>:

  • Some(ValueRef) if a global variable with the specified name is found.
  • None if no global variable with the specified name exists in the module.
source

pub fn get_first_global(&self) -> Option<ValueRef>

Retrieves the first global variable defined in the module.

This function wraps the LLVMGetFirstGlobal function from the LLVM core library. It returns the first global variable in the current module, which can be useful for iterating through all global variables in the module.

§Returns

Returns an Option<ValueRef>:

  • Some(ValueRef) if the module contains at least one global variable.
  • None if the module does not have any global variables.
source

pub fn get_last_global(&self) -> Option<ValueRef>

Retrieves the last global variable defined in the module.

This function wraps the LLVMGetLastGlobal function from the LLVM core library. It returns the last global variable in the current module, which can be useful for iterating through all global variables or accessing the most recently defined one.

§Returns

Returns an Option<ValueRef>:

  • Some(ValueRef) if the module contains at least one global variable.
  • None if the module does not have any global variables.

Trait Implementations§

source§

impl Deref for ModuleRef

source§

type Target = *mut LLVMModule

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl Drop for ModuleRef

source§

fn drop(&mut self)

Dispose module

source§

impl From<*mut LLVMModule> for ModuleRef

source§

fn from(module: LLVMModuleRef) -> Self

Converts to this type from the input type.
source§

impl GetRef for ModuleRef

source§

type RawRef = *mut LLVMModule

Raw LLVM reference type
source§

fn get_ref(&self) -> Self::RawRef

Get LLVM raw reference

Auto Trait Implementations§

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.