Struct llvm::Module [] [src]

pub struct Module;

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.

Methods

impl Module
[src]

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::*;
let context = Context::new();
let context = context.as_semi();
let module = Module::new("name", &context);
println!("{:?}", module)

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.

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.

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.

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.

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.

fn parse_bitcode<'a>(context: &'a Context, path: &str) -> Result<CSemiBox<'a, Module>, CBox<str>>

Parse this bitcode file into a module, or return an error string.

fn write_bitcode(&self, path: &str) -> IoResult<()>

Write this module's bitcode to the path given.

fn add_function<'a>(&'a self, name: &str, sig: &'a Type) -> &'a mut Function

Add a function to the module with the name given.

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.

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.

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

Clone this module.

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.

fn get_target(&self) -> &str

Returns the target data of this module represented as a string

fn set_target(&self, target: &str)

Set the target data of this module to the target data string given.

fn verify(&self) -> Result<()CBox<str>>

Verify that the module is safe to run, returning a string detailing the error when an error occurs.

fn compile(&self, path: &Path, opt_level: usize) -> IoResult<()>

Compile the module into an object file at the given location.

Note that this uses the LLVM tool llc to do this, which may or may not be installed on the user's machine.

Link a module into this module, returning an error string if an error occurs.

This does not destroy the source module.

Link a module into this module, returning an error string if an error occurs.

This does destroy the source module.

Trait Implementations

impl Eq for Module
[src]

impl PartialEq<Module> for Module
[src]

fn eq(&self, other: &Module) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &Rhs) -> bool
1.0.0

This method tests for !=.

impl<'a> PartialEq<Module> for &'a Module
[src]

fn eq(&self, other: &Module) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &Rhs) -> bool
1.0.0

This method tests for !=.

impl<'a> From<LLVMModuleRef> for &'a Module
[src]

fn from(ty: LLVMModuleRef) -> &'a Module

Performs the conversion.

impl<'a> From<LLVMModuleRef> for &'a mut Module
[src]

fn from(ty: LLVMModuleRef) -> &'a mut Module

Performs the conversion.

impl<'a> IntoIterator for &'a Module
[src]

type Item = &'a Function

The type of the elements being iterated over.

type IntoIter = Functions<'a>

Which kind of iterator are we turning this into?

fn into_iter(self) -> Functions<'a>

Iterate through the functions in the module

impl GetContext for Module
[src]

fn get_context(&self) -> &Context

Returns a reference to the context that owns this value. Read more

impl Debug for Module
[src]

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

Formats the value using the given formatter.

impl DisposeRef for Module
[src]

type RefTo = LLVMModule

What a reference to this type represents as a C pointer.

unsafe fn dispose(ptr: *mut LLVMModule)

Destroy the contents at the pointer's location. Read more