From 73e25a571f12d3deaa6f4493a5b4792a9dae39eb Mon Sep 17 00:00:00 2001 From: johannst Date: Sat, 24 Sep 2022 22:38:40 +0000 Subject: deploy: 295081130ca1eed6e67dfc035e2df2c9ed49b174 --- src/llvm_kaleidoscope_rs/llvm/module.rs.html | 276 +++++++++++++++------------ 1 file changed, 154 insertions(+), 122 deletions(-) (limited to 'src/llvm_kaleidoscope_rs/llvm/module.rs.html') diff --git a/src/llvm_kaleidoscope_rs/llvm/module.rs.html b/src/llvm_kaleidoscope_rs/llvm/module.rs.html index be37a0b..99846f4 100644 --- a/src/llvm_kaleidoscope_rs/llvm/module.rs.html +++ b/src/llvm_kaleidoscope_rs/llvm/module.rs.html @@ -1,102 +1,108 @@ -module.rs - source
  1
-  2
-  3
-  4
-  5
-  6
-  7
-  8
-  9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
+module.rs - source
+    
1
+2
+3
+4
+5
+6
+7
+8
+9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+21
+22
+23
+24
+25
+26
+27
+28
+29
+30
+31
+32
+33
+34
+35
+36
+37
+38
+39
+40
+41
+42
+43
+44
+45
+46
+47
+48
+49
+50
+51
+52
+53
+54
+55
+56
+57
+58
+59
+60
+61
+62
+63
+64
+65
+66
+67
+68
+69
+70
+71
+72
+73
+74
+75
+76
+77
+78
+79
+80
+81
+82
+83
+84
+85
+86
+87
+88
+89
+90
+91
+92
+93
+94
+95
+96
+97
+98
+99
 100
 101
 102
@@ -194,11 +200,25 @@
 194
 195
 196
-
-use llvm_sys::{
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+
use llvm_sys::{
     core::{
-        LLVMAddFunction, LLVMAppendBasicBlockInContext, LLVMDisposeModule, LLVMDoubleTypeInContext,
-        LLVMDumpModule, LLVMGetNamedFunction, LLVMModuleCreateWithNameInContext,
+        LLVMAddFunction, LLVMAppendBasicBlockInContext, LLVMCreateBasicBlockInContext,
+        LLVMDisposeModule, LLVMDoubleTypeInContext, LLVMDumpModule, LLVMGetNamedFunction,
+        LLVMModuleCreateWithNameInContext,
     },
     orc2::{
         LLVMOrcCreateNewThreadSafeContext, LLVMOrcCreateNewThreadSafeModule,
@@ -210,19 +230,18 @@
 };
 
 use std::convert::TryFrom;
-use std::marker::PhantomData;
 
 use super::{BasicBlock, FnValue, Type};
-use crate::SmallCStr;
+use crate::SmallCStr;
 
 // Definition of LLVM C API functions using our `repr(transparent)` types.
 extern "C" {
     fn LLVMFunctionType(
         ReturnType: Type<'_>,
-        ParamTypes: *mut Type<'_>,
+        ParamTypes: *mut Type<'_>,
         ParamCount: ::libc::c_uint,
         IsVarArg: LLVMBool,
-    ) -> LLVMTypeRef;
+    ) -> LLVMTypeRef;
 }
 
 /// Wrapper for a LLVM Module with its own LLVM Context.
@@ -238,7 +257,7 @@
     /// # Panics
     ///
     /// Panics if creating the context or the module fails.
-    pub fn new() -> Self {
+    pub fn new() -> Self {
         let (tsctx, ctx, module) = unsafe {
             // We generate a thread safe context because we are going to jit this IR module and
             // there is no method to create a thread safe context wrapper from an existing context
@@ -260,13 +279,13 @@
 
     /// Get the raw LLVM context reference.
     #[inline]
-    pub(super) fn ctx(&self) -> LLVMContextRef {
+    pub(super) fn ctx(&self) -> LLVMContextRef {
         self.ctx
     }
 
     /// Get the raw LLVM module reference.
     #[inline]
-    pub(super) fn module(&self) -> LLVMModuleRef {
+    pub(super) fn module(&self) -> LLVMModuleRef {
         self.module
     }
 
@@ -275,8 +294,8 @@
     /// If ownership of the raw reference is not transferred (eg to the JIT), memory will be leaked
     /// in case the reference is disposed explicitly with LLVMOrcDisposeThreadSafeModule.
     #[inline]
-    pub(super) fn into_raw_thread_safe_module(mut self) -> LLVMOrcThreadSafeModuleRef {
-        let m = std::mem::replace(&mut self.module, std::ptr::null_mut());
+    pub(super) fn into_raw_thread_safe_module(mut self) -> LLVMOrcThreadSafeModuleRef {
+        let m = std::mem::replace(&mut self.module, std::ptr::null_mut());
 
         // ThreadSafeModule has unique ownership.
         // Takes ownership of module and increments ThreadSafeContext ref count.
@@ -299,7 +318,7 @@
     /// # Panics
     ///
     /// Panics if LLVM API returns a `null` pointer.
-    pub fn type_f64(&self) -> Type<'llvm> {
+    pub fn type_f64(&self) -> Type<'llvm> {
         let type_ref = unsafe { LLVMDoubleTypeInContext(self.ctx) };
         Type::new(type_ref)
     }
@@ -309,7 +328,7 @@
     /// # Panics
     ///
     /// Panics if LLVM API returns a `null` pointer.
-    pub fn type_fn(&'llvm self, args: &mut [Type<'llvm>], ret: Type<'llvm>) -> Type<'llvm> {
+    pub fn type_fn(&'llvm self, args: &mut [Type<'llvm>], ret: Type<'llvm>) -> Type<'llvm> {
         let type_ref = unsafe {
             LLVMFunctionType(
                 ret,
@@ -328,7 +347,7 @@
     ///
     /// Panics if LLVM API returns a `null` pointer or `name` could not be converted to a
     /// [`SmallCStr`].
-    pub fn add_fn(&'llvm self, name: &str, fn_type: Type<'llvm>) -> FnValue<'llvm> {
+    pub fn add_fn(&'llvm self, name: &str, fn_type: Type<'llvm>) -> FnValue<'llvm> {
         debug_assert_eq!(
             fn_type.kind(),
             LLVMTypeKind::LLVMFunctionTypeKind,
@@ -348,7 +367,7 @@
     /// # Panics
     ///
     /// Panics if `name` could not be converted to a [`SmallCStr`].
-    pub fn get_fn(&'llvm self, name: &str) -> Option<FnValue<'llvm>> {
+    pub fn get_fn(&'llvm self, name: &str) -> Option<FnValue<'llvm>> {
         let name = SmallCStr::try_from(name)
             .expect("Failed to convert 'name' argument to small C string!");
 
@@ -363,7 +382,7 @@
     /// # Panics
     ///
     /// Panics if LLVM API returns a `null` pointer.
-    pub fn append_basic_block(&'llvm self, fn_value: FnValue<'llvm>) -> BasicBlock<'llvm> {
+    pub fn append_basic_block(&'llvm self, fn_value: FnValue<'llvm>) -> BasicBlock<'llvm> {
         let block = unsafe {
             LLVMAppendBasicBlockInContext(
                 self.ctx,
@@ -373,12 +392,26 @@
         };
         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)
     }
 }
 
 impl Drop for Module {
-    fn drop(&mut self) {
+    fn drop(&mut self) {
         unsafe {
             // In case we turned the module into a ThreadSafeModule, we must not dispose the module
             // reference because ThreadSafeModule took ownership!
@@ -391,7 +424,6 @@
         }
     }
 }
-
-
- +
+
\ No newline at end of file -- cgit v1.2.3