[][src]Struct inkwell::basic_block::BasicBlock

pub struct BasicBlock { /* fields omitted */ }

A BasicBlock is a container of instructions.

BasicBlocks are values because they can be referenced by instructions (ie branching and switches).

A well formed BasicBlock is a list of non terminating instructions followed by a single terminating instruction. BasicBlocks are allowed to be malformed prior to running validation because it may be useful when constructing or modifying a program.

Methods

impl BasicBlock[src]

pub fn get_parent(&self) -> Option<FunctionValue>[src]

Obtains the FunctionValue that this BasicBlock belongs to, if any.

Example

use inkwell::context::Context;
use inkwell::module::Module;
use inkwell::builder::Builder;

let context = Context::create();
let module = context.create_module("my_module");
let void_type = context.void_type();
let fn_type = void_type.fn_type(&[], false);
let function = module.add_function("do_nothing", fn_type, None);

let basic_block = context.append_basic_block(&function, "entry");

assert_eq!(basic_block.get_parent().unwrap(), function);

basic_block.remove_from_function();

assert!(basic_block.get_parent().is_none());

pub fn get_previous_basic_block(&self) -> Option<BasicBlock>[src]

Gets the BasicBlock preceeding the current one, in its own scope, if any.

Example

use inkwell::context::Context;
use inkwell::module::Module;
use inkwell::builder::Builder;

let context = Context::create();
let module = context.create_module("my_module");
let void_type = context.void_type();
let fn_type = void_type.fn_type(&[], false);
let function1 = module.add_function("do_nothing", fn_type, None);

let basic_block1 = context.append_basic_block(&function1, "entry");

assert!(basic_block1.get_previous_basic_block().is_none());

let function2 = module.add_function("do_nothing", fn_type, None);

let basic_block2 = context.append_basic_block(&function2, "entry");
let basic_block3 = context.append_basic_block(&function2, "next");

assert!(basic_block2.get_previous_basic_block().is_none());
assert_eq!(basic_block3.get_previous_basic_block().unwrap(), basic_block2);

pub fn get_next_basic_block(&self) -> Option<BasicBlock>[src]

Gets the BasicBlock succeeding the current one, in its own scope, if any.

Example

use inkwell::context::Context;
use inkwell::module::Module;
use inkwell::builder::Builder;

let context = Context::create();
let module = context.create_module("my_module");
let void_type = context.void_type();
let fn_type = void_type.fn_type(&[], false);
let function1 = module.add_function("do_nothing", fn_type, None);

let basic_block1 = context.append_basic_block(&function1, "entry");

assert!(basic_block1.get_next_basic_block().is_none());

let function2 = module.add_function("do_nothing", fn_type, None);

let basic_block2 = context.append_basic_block(&function2, "entry");
let basic_block3 = context.append_basic_block(&function2, "next");

assert!(basic_block1.get_next_basic_block().is_none());
assert_eq!(basic_block2.get_next_basic_block().unwrap(), basic_block3);
assert!(basic_block3.get_next_basic_block().is_none());

pub fn move_before(&self, basic_block: &BasicBlock)[src]

Prepends one BasicBlock before another.

Example

use inkwell::context::Context;
use inkwell::module::Module;
use inkwell::builder::Builder;

let context = Context::create();
let module = context.create_module("my_module");
let void_type = context.void_type();
let fn_type = void_type.fn_type(&[], false);
let function = module.add_function("do_nothing", fn_type, None);

let basic_block1 = context.append_basic_block(&function, "entry");
let basic_block2 = context.append_basic_block(&function, "next");

basic_block2.move_before(&basic_block1);

assert!(basic_block1.get_next_basic_block().is_none());
assert_eq!(basic_block2.get_next_basic_block().unwrap(), basic_block1);

pub fn move_after(&self, basic_block: &BasicBlock)[src]

Appends one BasicBlock after another.

Example

use inkwell::context::Context;
use inkwell::module::Module;
use inkwell::builder::Builder;

let context = Context::create();
let module = context.create_module("my_module");
let void_type = context.void_type();
let fn_type = void_type.fn_type(&[], false);
let function = module.add_function("do_nothing", fn_type, None);

let basic_block1 = context.append_basic_block(&function, "entry");
let basic_block2 = context.append_basic_block(&function, "next");

basic_block1.move_after(&basic_block2);

assert!(basic_block1.get_next_basic_block().is_none());
assert_eq!(basic_block2.get_next_basic_block().unwrap(), basic_block1);

pub fn prepend_basic_block(&self, name: &str) -> BasicBlock[src]

Prepends a new BasicBlock before this one.

Example

use inkwell::context::Context;
use inkwell::module::Module;
use inkwell::builder::Builder;

let context = Context::create();
let module = context.create_module("my_module");
let void_type = context.void_type();
let fn_type = void_type.fn_type(&[], false);
let function = module.add_function("do_nothing", fn_type, None);

let basic_block1 = context.append_basic_block(&function, "entry");
let basic_block2 = basic_block1.prepend_basic_block("previous");

assert!(basic_block1.get_next_basic_block().is_none());
assert_eq!(basic_block2.get_next_basic_block().unwrap(), basic_block1);

pub fn get_first_instruction(&self) -> Option<InstructionValue>[src]

Obtains the first InstructionValue in this BasicBlock, if any.

Example

use inkwell::context::Context;
use inkwell::module::Module;
use inkwell::builder::Builder;
use inkwell::values::InstructionOpcode;

let context = Context::create();
let builder = context.create_builder();
let module = context.create_module("my_module");
let void_type = context.void_type();
let fn_type = void_type.fn_type(&[], false);
let function = module.add_function("do_nothing", fn_type, None);
let basic_block = context.append_basic_block(&function, "entry");

builder.position_at_end(&basic_block);
builder.build_return(None);

assert_eq!(basic_block.get_first_instruction().unwrap().get_opcode(), InstructionOpcode::Return);

pub fn get_last_instruction(&self) -> Option<InstructionValue>[src]

Obtains the last InstructionValue in this BasicBlock, if any. A BasicBlock must have a last instruction to be valid.

Example

use inkwell::context::Context;
use inkwell::module::Module;
use inkwell::builder::Builder;
use inkwell::values::InstructionOpcode;

let context = Context::create();
let builder = context.create_builder();
let module = context.create_module("my_module");
let void_type = context.void_type();
let fn_type = void_type.fn_type(&[], false);
let function = module.add_function("do_nothing", fn_type, None);
let basic_block = context.append_basic_block(&function, "entry");

builder.position_at_end(&basic_block);
builder.build_return(None);

assert_eq!(basic_block.get_last_instruction().unwrap().get_opcode(), InstructionOpcode::Return);

pub fn get_terminator(&self) -> Option<InstructionValue>[src]

Obtains the terminating InstructionValue in this BasicBlock, if any. A BasicBlock must have a terminating instruction to be valid.

Example

use inkwell::context::Context;
use inkwell::module::Module;
use inkwell::builder::Builder;
use inkwell::values::InstructionOpcode;

let context = Context::create();
let builder = context.create_builder();
let module = context.create_module("my_module");
let void_type = context.void_type();
let fn_type = void_type.fn_type(&[], false);
let function = module.add_function("do_nothing", fn_type, None);
let basic_block = context.append_basic_block(&function, "entry");

builder.position_at_end(&basic_block);
builder.build_return(None);

assert_eq!(basic_block.get_terminator().unwrap().get_opcode(), InstructionOpcode::Return);

pub fn remove_from_function(&self)[src]

Removes this BasicBlock from its parent FunctionValue. Does nothing if it has no parent.

Example

use inkwell::context::Context;
use inkwell::module::Module;
use inkwell::builder::Builder;

let context = Context::create();
let module = context.create_module("my_module");
let void_type = context.void_type();
let fn_type = void_type.fn_type(&[], false);
let function = module.add_function("do_nothing", fn_type, None);
let basic_block = context.append_basic_block(&function, "entry");

assert_eq!(basic_block.get_parent().unwrap(), function);

basic_block.remove_from_function();

assert!(basic_block.get_parent().is_none());

pub unsafe fn delete(self)[src]

Removes this BasicBlock completely from memory. This is unsafe because you could easily have other references to the same BasicBlock.

Example

use inkwell::context::Context;
use inkwell::module::Module;
use inkwell::builder::Builder;

let context = Context::create();
let module = context.create_module("my_module");
let void_type = context.void_type();
let fn_type = void_type.fn_type(&[], false);
let function = module.add_function("do_nothing", fn_type, None);
let basic_block = context.append_basic_block(&function, "entry");

unsafe {
    basic_block.delete();
}
assert!(function.get_basic_blocks().is_empty());

pub fn get_context(&self) -> ContextRef[src]

Obtains the ContextRef this BasicBlock belongs to.

Example

use inkwell::context::Context;
use inkwell::module::Module;
use inkwell::builder::Builder;

let context = Context::create();
let module = context.create_module("my_module");
let void_type = context.void_type();
let fn_type = void_type.fn_type(&[], false);
let function = module.add_function("do_nothing", fn_type, None);
let basic_block = context.append_basic_block(&function, "entry");

assert_eq!(context, *basic_block.get_context());

pub fn get_name(&self) -> &CStr[src]

Gets the name of a BasicBlock.

Example

use inkwell::context::Context;
use std::ffi::CString;

let context = Context::create();
let builder = context.create_builder();
let module = context.create_module("my_mod");
let void_type = context.void_type();
let fn_type = void_type.fn_type(&[], false);
let fn_val = module.add_function("my_fn", fn_type, None);
let bb = context.append_basic_block(&fn_val, "entry");

assert_eq!(*bb.get_name(), *CString::new("entry").unwrap());

Trait Implementations

impl Eq for BasicBlock[src]

impl Clone for BasicBlock[src]

impl PartialEq<BasicBlock> for BasicBlock[src]

impl Copy for BasicBlock[src]

impl Hash for BasicBlock[src]

impl Debug for BasicBlock[src]

Auto Trait Implementations

impl !Sync for BasicBlock

impl !Send for BasicBlock

impl Unpin for BasicBlock

impl UnwindSafe for BasicBlock

impl RefUnwindSafe for BasicBlock

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]