llvm_lib/
basic_block.rs

1use crate::core::context::ContextRef;
2use crate::core::values::ValueRef;
3use crate::{CString, GetRef};
4use llvm_sys::core::LLVMAppendBasicBlockInContext;
5use llvm_sys::prelude::LLVMBasicBlockRef;
6
7/// LLVM Basic block wrapper
8pub struct BasicBlockRef(LLVMBasicBlockRef);
9
10impl GetRef for BasicBlockRef {
11    type RawRef = LLVMBasicBlockRef;
12    fn get_ref(&self) -> Self::RawRef {
13        self.0
14    }
15}
16
17impl BasicBlockRef {
18    // Get raw basic block reference
19    #[must_use]
20    pub const fn get(&self) -> LLVMBasicBlockRef {
21        self.0
22    }
23
24    /// Append basic block in context
25    /// TODO: return error
26    #[must_use]
27    pub fn append_in_context(context: &ContextRef, function: &ValueRef, name: &str) -> Self {
28        unsafe {
29            let c_name = CString::from(name);
30            Self(LLVMAppendBasicBlockInContext(
31                **context,
32                **function,
33                c_name.as_ptr(),
34            ))
35        }
36    }
37}