llvm-lib 0.8.1

LLVM library with safe and flexibility in mind, without over complexity based on LLVM-C API
Documentation
use crate::core::context::ContextRef;
use crate::core::values::ValueRef;
use crate::{CString, GetRef};
use llvm_sys::core::LLVMAppendBasicBlockInContext;
use llvm_sys::prelude::LLVMBasicBlockRef;

/// LLVM Basic block wrapper
pub struct BasicBlockRef(LLVMBasicBlockRef);

impl GetRef for BasicBlockRef {
    type RawRef = LLVMBasicBlockRef;
    fn get_ref(&self) -> Self::RawRef {
        self.0
    }
}

impl BasicBlockRef {
    // Get raw basic block reference
    #[must_use]
    pub const fn get(&self) -> LLVMBasicBlockRef {
        self.0
    }

    /// Append basic block in context
    /// TODO: return error
    #[must_use]
    pub fn append_in_context(context: &ContextRef, function: &ValueRef, name: &str) -> Self {
        unsafe {
            let c_name = CString::from(name);
            Self(LLVMAppendBasicBlockInContext(
                **context,
                **function,
                c_name.as_ptr(),
            ))
        }
    }
}