pub struct Module(_);Expand description
Represents a single compilation unit of code.
This is attached to the lifetime of the context that constructs it, but is owned by the CSemiBox.
Implementations§
source§impl Module
impl Module
sourcepub fn new<'a>(name: &str, context: &'a Context) -> CSemiBox<'a, Module>
pub fn new<'a>(name: &str, context: &'a Context) -> CSemiBox<'a, Module>
Create a new module in the context given with the name given.
The lifetime of the module will match the lifetime of the context you instance it in because the context contains it.
use llvm_rs::*;
let context = Context::new();
let context = context.as_semi();
let module = Module::new("name", &context);
println!("{:?}", module)sourcepub fn add_global<'a>(&'a self, name: &str, ty: &'a Type) -> &'a GlobalVariable
pub fn add_global<'a>(&'a self, name: &str, ty: &'a Type) -> &'a GlobalVariable
Add a global to the module with the given type and name.
sourcepub fn add_global_in_address_space<'a>(
&'a self,
name: &str,
ty: &'a Type,
address: AddressSpace
) -> &'a GlobalVariable
pub fn add_global_in_address_space<'a>(
&'a self,
name: &str,
ty: &'a Type,
address: AddressSpace
) -> &'a GlobalVariable
Add a global variable to the module with the given type, name and initial value.
sourcepub fn add_global_variable<'a>(
&'a self,
name: &str,
val: &'a Value
) -> &'a GlobalVariable
pub fn add_global_variable<'a>(
&'a self,
name: &str,
val: &'a Value
) -> &'a GlobalVariable
Add a global variable to the module with the given type, name and initial value.
sourcepub fn add_global_alias<'a>(
&'a self,
name: &str,
val: &'a GlobalValue
) -> &'a Alias
pub fn add_global_alias<'a>(
&'a self,
name: &str,
val: &'a GlobalValue
) -> &'a Alias
Add a global to the module with the given type and name.
sourcepub fn get_global<'a>(&'a self, name: &str) -> Option<&'a GlobalValue>
pub fn get_global<'a>(&'a self, name: &str) -> Option<&'a GlobalValue>
Get the global with the name given, or None if no global with that name exists.
sourcepub fn parse_bitcode<'a>(
context: &'a Context,
path: &str
) -> Option<CSemiBox<'a, Module>>
pub fn parse_bitcode<'a>(
context: &'a Context,
path: &str
) -> Option<CSemiBox<'a, Module>>
Parse this bitcode file into a module, or return an error string.
sourcepub fn write_bitcode(&self, path: &str) -> IoResult<()>
pub fn write_bitcode(&self, path: &str) -> IoResult<()>
Write this module’s bitcode to the path given.
sourcepub fn parse_ir_from_str<'a>(
context: &'a Context,
s: &str
) -> Result<CSemiBox<'a, Module>, CBox<str>>
pub fn parse_ir_from_str<'a>(
context: &'a Context,
s: &str
) -> Result<CSemiBox<'a, Module>, CBox<str>>
Parse IR assembly unto a module, or return an error string.
sourcepub fn add_function<'a>(&'a self, name: &str, sig: &'a Type) -> &'a mut Function
pub fn add_function<'a>(&'a self, name: &str, sig: &'a Type) -> &'a mut Function
Add a function to the module with the name given.
sourcepub fn get_function<'a>(&'a self, name: &str) -> Option<&'a Function>
pub fn get_function<'a>(&'a self, name: &str) -> Option<&'a Function>
Returns the function with the name given, or None if no function with that name exists.
sourcepub fn get_type<'a>(&'a self, name: &str) -> Option<&'a Type>
pub fn get_type<'a>(&'a self, name: &str) -> Option<&'a Type>
Returns the type with the name given, or `None`` if no type with that name exists.
sourcepub fn optimize(&self, opt_level: usize, size_level: usize)
pub fn optimize(&self, opt_level: usize, size_level: usize)
Optimize this module with the given optimization level and size level.
This runs passes depending on the levels given.
sourcepub fn get_target(&self) -> &str
pub fn get_target(&self) -> &str
Returns the target data of this module represented as a string
sourcepub fn set_target(&self, target: &str)
pub fn set_target(&self, target: &str)
Set the target data of this module to the target data string given.
sourcepub fn verify(&self) -> Result<(), CBox<str>>
pub fn verify(&self) -> Result<(), CBox<str>>
Verify that the module is safe to run, returning a string detailing the error when an error occurs.