llvm_wrap/
bb.rs

1//! A wrapper around a `LLVMBasicBlockRef`
2
3use super::*;
4use super::c_api::*;
5
6/// A wrapper around a `LLVMBasicBlockRef`
7#[derive(Copy, Clone)]
8pub struct BasicBlock {
9    pub(crate) basic_block: LLVMBasicBlockRef
10}
11
12impl BasicBlock {
13    /// Delete this basic block
14    pub fn delete(self) {
15        unsafe {
16            LLVMDeleteBasicBlock(self.basic_block)
17        }
18    }
19
20    /// Get the name of a basic block
21    pub fn get_name(&self) -> Option<String> {
22        unsafe {
23            from_c(LLVMGetBasicBlockName(self.basic_block))
24        }
25    }
26
27    /// Returns the internal basic block reference
28    pub unsafe fn inner(&self) -> LLVMBasicBlockRef {
29        self.basic_block
30    }
31}
32
33impl Deref for BasicBlock {
34    type Target = LLVMBasicBlockRef;
35
36    fn deref(&self) -> &LLVMBasicBlockRef {
37        &self.basic_block
38    }
39}
40
41impl Debug for BasicBlock {
42    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
43        if let Some(name) = self.get_name() {
44            write!(f, "BasicBlock({})", name)
45        } else {
46            write!(f, "BasicBlock")
47        }
48    }
49}