aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/llvm/module.rs
diff options
context:
space:
mode:
authorJohannes Stoelp <johannes.stoelp@gmail.com>2021-10-04 22:51:42 +0200
committerJohannes Stoelp <johannes.stoelp@gmail.com>2021-10-04 22:51:42 +0200
commit4f6dd49df3f19204694fcea55f38efd9c5118bf2 (patch)
tree119d4fa88f6f744ecdb1eb9a833c316f5932b0c1 /src/llvm/module.rs
parenta3dee93989b9fdd99b8a22a2da7f72bcd2ba50c2 (diff)
downloadllvm-kaleidoscope-rs-4f6dd49df3f19204694fcea55f38efd9c5118bf2.tar.gz
llvm-kaleidoscope-rs-4f6dd49df3f19204694fcea55f38efd9c5118bf2.zip
ch5: added if/then/else
Diffstat (limited to 'src/llvm/module.rs')
-rw-r--r--src/llvm/module.rs22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/llvm/module.rs b/src/llvm/module.rs
index d737b8e..21d85f5 100644
--- a/src/llvm/module.rs
+++ b/src/llvm/module.rs
@@ -1,7 +1,8 @@
use llvm_sys::{
core::{
- LLVMAddFunction, LLVMAppendBasicBlockInContext, LLVMDisposeModule, LLVMDoubleTypeInContext,
- LLVMDumpModule, LLVMGetNamedFunction, LLVMModuleCreateWithNameInContext,
+ LLVMAddFunction, LLVMAppendBasicBlockInContext, LLVMCreateBasicBlockInContext,
+ LLVMDisposeModule, LLVMDoubleTypeInContext, LLVMDumpModule, LLVMGetNamedFunction,
+ LLVMModuleCreateWithNameInContext,
},
orc2::{
LLVMOrcCreateNewThreadSafeContext, LLVMOrcCreateNewThreadSafeModule,
@@ -13,7 +14,6 @@ use llvm_sys::{
};
use std::convert::TryFrom;
-use std::marker::PhantomData;
use super::{BasicBlock, FnValue, Type};
use crate::SmallCStr;
@@ -176,7 +176,21 @@ impl<'llvm> Module {
};
assert!(!block.is_null());
- BasicBlock(block, PhantomData)
+ BasicBlock::new(block)
+ }
+
+ /// Create a free-standing Basic Block without adding it to a function.
+ /// This can be added to a function at a later point in time with
+ /// [`FnValue::append_basic_block`].
+ ///
+ /// # Panics
+ ///
+ /// Panics if LLVM API returns a `null` pointer.
+ pub fn create_basic_block(&self) -> BasicBlock<'llvm> {
+ let block = unsafe { LLVMCreateBasicBlockInContext(self.ctx, b"block\0".as_ptr().cast()) };
+ assert!(!block.is_null());
+
+ BasicBlock::new(block)
}
}