pub struct ModuleRef(/* private fields */);
Expand description
LLVM Module wrapper
Implementations§
source§impl ModuleRef
impl ModuleRef
sourcepub fn create_module_with_name(module_name: &str) -> Self
pub fn create_module_with_name(module_name: &str) -> Self
§Panics
It panics if module creation is null
sourcepub fn create_module_with_name_in_context(
module_name: &str,
context: &ContextRef,
) -> Self
pub fn create_module_with_name_in_context( module_name: &str, context: &ContextRef, ) -> Self
§Panics
It panics if module creation is null
sourcepub fn clone_module(&self) -> Self
pub fn clone_module(&self) -> Self
Return an exact copy of the current module.
sourcepub fn get_module_identifier(&self) -> Option<String>
pub fn get_module_identifier(&self) -> Option<String>
Obtain the identifier of a module.
sourcepub fn set_module_identifier(&self, ident: &str)
pub fn set_module_identifier(&self, ident: &str)
Set the identifier of a module to a string Ident with length Len.
sourcepub fn get_source_file_name(&self) -> Option<String>
pub fn get_source_file_name(&self) -> Option<String>
Obtain the module’s original source file name.
sourcepub fn set_source_file_name(&self, name: &str)
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.
sourcepub fn get_data_layout_str(&self) -> Option<String>
pub fn get_data_layout_str(&self) -> Option<String>
Get module data layout
sourcepub fn set_data_layout(&self, data_layout_str: &str)
pub fn set_data_layout(&self, data_layout_str: &str)
Set the data layout for a module.
sourcepub fn get_target(&self) -> Option<String>
pub fn get_target(&self) -> Option<String>
Obtain the target triple for a module.
sourcepub fn set_target(&self, triple: &str)
pub fn set_target(&self, triple: &str)
Set the target triple for a module.
sourcepub fn copy_module_flags_metadata(&self) -> Option<ModuleFlagEntry>
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
.
sourcepub fn get_module_flag(&self, key: &str) -> MetadataRef
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.
pub fn add_module_flag( &self, behavior: &ModuleFlagBehavior, key: &str, val: &MetadataRef, )
sourcepub fn dump_module(&self)
pub fn dump_module(&self)
Dump module to stdout
sourcepub fn print_module_to_file(&self, filename: &str) -> Result<(), String>
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
sourcepub fn print_module_to_string(&self) -> Option<String>
pub fn print_module_to_string(&self) -> Option<String>
Return a string representation of the module.
sourcepub fn get_module_inline_asm(&self) -> Option<String>
pub fn get_module_inline_asm(&self) -> Option<String>
Get inline assembly for a module.
sourcepub fn set_module_inline_asm(&self, asm: &str)
pub fn set_module_inline_asm(&self, asm: &str)
Set inline assembly for a module.
sourcepub fn append_module_inline_asm(&self, asm: &str)
pub fn append_module_inline_asm(&self, asm: &str)
Append inline assembly to a module.
sourcepub fn get_module_context(&self) -> ContextRef
pub fn get_module_context(&self) -> ContextRef
Obtain the context to which this module is associated.
sourcepub fn get_first_named_metadata(&self) -> Option<NamedMetadataNodeRef>
pub fn get_first_named_metadata(&self) -> Option<NamedMetadataNodeRef>
Obtain an iterator to the first NamedMDNode
in a Module
.
sourcepub fn get_last_named_metadata(&self) -> Option<NamedMetadataNodeRef>
pub fn get_last_named_metadata(&self) -> Option<NamedMetadataNodeRef>
Obtain an iterator to the last NamedMDNode
in a Module.
sourcepub fn get_named_metadata(&self, name: &str) -> Option<NamedMetadataNodeRef>
pub fn get_named_metadata(&self, name: &str) -> Option<NamedMetadataNodeRef>
Retrieve a NamedMetadataNode
with the given name, returning None
if no such node exists.
sourcepub fn get_or_insert_named_metadata(&self, name: &str) -> NamedMetadataNodeRef
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.
sourcepub fn get_named_metadata_num_operands(&self, name: &str) -> u32
pub fn get_named_metadata_num_operands(&self, name: &str) -> u32
Obtain the number of operands for named metadata in a module.
sourcepub fn get_named_metadata_operands(&self, name: &str) -> Vec<ValueRef>
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.
sourcepub fn add_named_metadata_operand(&self, name: &str, val: &ValueRef)
pub fn add_named_metadata_operand(&self, name: &str, val: &ValueRef)
Add an operand to named metadata.
sourcepub fn add_function(&self, fn_name: &str, fn_type: &TypeRef) -> ValueRef
pub fn add_function(&self, fn_name: &str, fn_type: &TypeRef) -> ValueRef
Set add function value based on Function type
sourcepub fn get_named_function(&self, name: &str) -> ValueRef
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.
sourcepub fn get_first_function(&self) -> ValueRef
pub fn get_first_function(&self) -> ValueRef
Obtain an iterator to the first Function in a Module.
sourcepub fn get_last_function(&self) -> ValueRef
pub fn get_last_function(&self) -> ValueRef
Obtain an iterator to the last Function in a Module.
source§impl ModuleRef
impl ModuleRef
sourcepub fn add_global(&self, ty: &TypeRef, name: &str) -> ValueRef
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 theTypeRef
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.
sourcepub fn add_global_in_address_space(
&self,
ty: &TypeRef,
name: &str,
address_space: &AddressSpace,
) -> ValueRef
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 theTypeRef
representing the type of the global variable.name
: A string slice (&str
) representing the name of the global variable.address_space
: A reference to theAddressSpace
where the global variable should be allocated.
§Returns
Returns a ValueRef
representing the newly added global variable in the specified address space.
sourcepub fn get_named_global(&self, name: &str) -> Option<ValueRef>
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.
sourcepub fn get_first_global(&self) -> Option<ValueRef>
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.
sourcepub fn get_last_global(&self) -> Option<ValueRef>
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.