From 617f0d65b20b7b405b1acecea6f99ccd0a6d73f3 Mon Sep 17 00:00:00 2001 From: johannst Date: Thu, 5 Jan 2023 20:25:01 +0000 Subject: deploy: 802cca1963bc27f8ea4e4923029909e45464d3df --- src/llvm_kaleidoscope_rs/llvm/lljit.rs.html | 217 ++++++++++++++-------------- 1 file changed, 105 insertions(+), 112 deletions(-) (limited to 'src/llvm_kaleidoscope_rs/llvm/lljit.rs.html') diff --git a/src/llvm_kaleidoscope_rs/llvm/lljit.rs.html b/src/llvm_kaleidoscope_rs/llvm/lljit.rs.html index 5a5a376..80be225 100644 --- a/src/llvm_kaleidoscope_rs/llvm/lljit.rs.html +++ b/src/llvm_kaleidoscope_rs/llvm/lljit.rs.html @@ -1,10 +1,4 @@ -lljit.rs - source -
1
+lljit.rs - source
1
 2
 3
 4
@@ -158,160 +152,159 @@
 152
 153
 154
-
use llvm_sys::orc2::{
-    lljit::{
-        LLVMOrcCreateLLJIT, LLVMOrcLLJITAddLLVMIRModuleWithRT, LLVMOrcLLJITGetGlobalPrefix,
-        LLVMOrcLLJITGetMainJITDylib, LLVMOrcLLJITLookup, LLVMOrcLLJITRef,
+
use llvm_sys::orc2::{
+    lljit::{
+        LLVMOrcCreateLLJIT, LLVMOrcLLJITAddLLVMIRModuleWithRT, LLVMOrcLLJITGetGlobalPrefix,
+        LLVMOrcLLJITGetMainJITDylib, LLVMOrcLLJITLookup, LLVMOrcLLJITRef,
     },
-    LLVMOrcCreateDynamicLibrarySearchGeneratorForProcess, LLVMOrcDefinitionGeneratorRef,
-    LLVMOrcJITDylibAddGenerator, LLVMOrcJITDylibCreateResourceTracker, LLVMOrcJITDylibRef,
-    LLVMOrcReleaseResourceTracker, LLVMOrcResourceTrackerRef, LLVMOrcResourceTrackerRemove,
+    LLVMOrcCreateDynamicLibrarySearchGeneratorForProcess, LLVMOrcDefinitionGeneratorRef,
+    LLVMOrcJITDylibAddGenerator, LLVMOrcJITDylibCreateResourceTracker, LLVMOrcJITDylibRef,
+    LLVMOrcReleaseResourceTracker, LLVMOrcResourceTrackerRef, LLVMOrcResourceTrackerRemove,
 };
 
-use std::convert::TryFrom;
-use std::marker::PhantomData;
+use std::convert::TryFrom;
+use std::marker::PhantomData;
 
-use super::{Error, Module};
-use crate::SmallCStr;
+use super::{Error, Module};
+use crate::SmallCStr;
 
-/// Marker trait to constrain function signatures that can be looked up in the JIT.
-pub trait JitFn {}
+/// Marker trait to constrain function signatures that can be looked up in the JIT.
+pub trait JitFn {}
 
-impl JitFn for unsafe extern "C" fn() -> f64 {}
+impl JitFn for unsafe extern "C" fn() -> f64 {}
 
-/// Wrapper for a LLVM [LLJIT](https://www.llvm.org/docs/ORCv2.html#lljit-and-lllazyjit).
-pub struct LLJit {
-    jit: LLVMOrcLLJITRef,
-    dylib: LLVMOrcJITDylibRef,
+/// Wrapper for a LLVM [LLJIT](https://www.llvm.org/docs/ORCv2.html#lljit-and-lllazyjit).
+pub struct LLJit {
+    jit: LLVMOrcLLJITRef,
+    dylib: LLVMOrcJITDylibRef,
 }
 
-impl LLJit {
-    /// Create a new LLJit instance.
-    ///
-    /// # Panics
-    ///
-    /// Panics if LLVM API returns a `null` pointer or an error.
-    pub fn new() -> LLJit {
-        let (jit, dylib) = unsafe {
-            let mut jit = std::ptr::null_mut();
-            let err = LLVMOrcCreateLLJIT(
-                &mut jit as _,
-                std::ptr::null_mut(), /* builder: nullptr -> default */
-            );
+impl LLJit {
+    /// Create a new LLJit instance.
+    ///
+    /// # Panics
+    ///
+    /// Panics if LLVM API returns a `null` pointer or an error.
+    pub fn new() -> LLJit {
+        let (jit, dylib) = unsafe {
+            let mut jit = std::ptr::null_mut();
+            let err = LLVMOrcCreateLLJIT(
+                &mut jit as _,
+                std::ptr::null_mut(), /* builder: nullptr -> default */
+            );
 
-            if let Some(err) = Error::from(err) {
-                panic!("Error: {}", err.as_str());
+            if let Some(err) = Error::from(err) {
+                panic!("Error: {}", err.as_str());
             }
 
-            let dylib = LLVMOrcLLJITGetMainJITDylib(jit);
-            assert!(!dylib.is_null());
+            let dylib = LLVMOrcLLJITGetMainJITDylib(jit);
+            assert!(!dylib.is_null());
 
-            (jit, dylib)
+            (jit, dylib)
         };
 
-        LLJit { jit, dylib }
+        LLJit { jit, dylib }
     }
 
-    /// Add an LLVM IR module to the JIT. Return a [`ResourceTracker`], which when dropped, will
-    /// remove the code of the LLVM IR module from the JIT.
-    ///
-    /// # Panics
-    ///
-    /// Panics if LLVM API returns a `null` pointer or an error.
-    pub fn add_module(&self, module: Module) -> ResourceTracker<'_> {
-        let tsmod = module.into_raw_thread_safe_module();
+    /// Add an LLVM IR module to the JIT. Return a [`ResourceTracker`], which when dropped, will
+    /// remove the code of the LLVM IR module from the JIT.
+    ///
+    /// # Panics
+    ///
+    /// Panics if LLVM API returns a `null` pointer or an error.
+    pub fn add_module(&self, module: Module) -> ResourceTracker<'_> {
+        let tsmod = module.into_raw_thread_safe_module();
 
-        let rt = unsafe {
-            let rt = LLVMOrcJITDylibCreateResourceTracker(self.dylib);
-            let err = LLVMOrcLLJITAddLLVMIRModuleWithRT(self.jit, rt, tsmod);
+        let rt = unsafe {
+            let rt = LLVMOrcJITDylibCreateResourceTracker(self.dylib);
+            let err = LLVMOrcLLJITAddLLVMIRModuleWithRT(self.jit, rt, tsmod);
 
-            if let Some(err) = Error::from(err) {
-                panic!("Error: {}", err.as_str());
+            if let Some(err) = Error::from(err) {
+                panic!("Error: {}", err.as_str());
             }
 
-            rt
+            rt
         };
 
-        ResourceTracker::new(rt)
+        ResourceTracker::new(rt)
     }
 
-    /// Find the symbol with the name `sym` in the JIT.
-    ///
-    /// # Panics
-    ///
-    /// Panics if the symbol is not found in the JIT.
-    pub fn find_symbol<F: JitFn>(&self, sym: &str) -> F {
-        let sym =
-            SmallCStr::try_from(sym).expect("Failed to convert 'sym' argument to small C string!");
+    /// Find the symbol with the name `sym` in the JIT.
+    ///
+    /// # Panics
+    ///
+    /// Panics if the symbol is not found in the JIT.
+    pub fn find_symbol<F: JitFn>(&self, sym: &str) -> F {
+        let sym =
+            SmallCStr::try_from(sym).expect("Failed to convert 'sym' argument to small C string!");
 
-        unsafe {
-            let mut addr = 0u64;
-            let err = LLVMOrcLLJITLookup(self.jit, &mut addr as _, sym.as_ptr());
+        unsafe {
+            let mut addr = 0u64;
+            let err = LLVMOrcLLJITLookup(self.jit, &mut addr as _, sym.as_ptr());
 
-            if let Some(err) = Error::from(err) {
-                panic!("Error: {}", err.as_str());
+            if let Some(err) = Error::from(err) {
+                panic!("Error: {}", err.as_str());
             }
 
-            debug_assert_eq!(core::mem::size_of_val(&addr), core::mem::size_of::<F>());
-            std::mem::transmute_copy(&addr)
+            debug_assert_eq!(core::mem::size_of_val(&addr), core::mem::size_of::<F>());
+            std::mem::transmute_copy(&addr)
         }
     }
 
-    /// Enable lookup of dynamic symbols available in the current process from the JIT.
-    ///
-    /// # Panics
-    ///
-    /// Panics if LLVM API returns an error.
-    pub fn enable_process_symbols(&self) {
-        unsafe {
-            let mut proc_syms_gen: LLVMOrcDefinitionGeneratorRef = std::ptr::null_mut();
-            let err = LLVMOrcCreateDynamicLibrarySearchGeneratorForProcess(
-                &mut proc_syms_gen as _,
-                self.global_prefix(),
-                None,                 /* filter */
-                std::ptr::null_mut(), /* filter ctx */
-            );
+    /// Enable lookup of dynamic symbols available in the current process from the JIT.
+    ///
+    /// # Panics
+    ///
+    /// Panics if LLVM API returns an error.
+    pub fn enable_process_symbols(&self) {
+        unsafe {
+            let mut proc_syms_gen: LLVMOrcDefinitionGeneratorRef = std::ptr::null_mut();
+            let err = LLVMOrcCreateDynamicLibrarySearchGeneratorForProcess(
+                &mut proc_syms_gen as _,
+                self.global_prefix(),
+                None,                 /* filter */
+                std::ptr::null_mut(), /* filter ctx */
+            );
 
-            if let Some(err) = Error::from(err) {
-                panic!("Error: {}", err.as_str());
+            if let Some(err) = Error::from(err) {
+                panic!("Error: {}", err.as_str());
             }
 
-            LLVMOrcJITDylibAddGenerator(self.dylib, proc_syms_gen);
+            LLVMOrcJITDylibAddGenerator(self.dylib, proc_syms_gen);
         }
     }
 
-    /// Return the global prefix character according to the LLJITs data layout.
-    fn global_prefix(&self) -> libc::c_char {
-        unsafe { LLVMOrcLLJITGetGlobalPrefix(self.jit) }
+    /// Return the global prefix character according to the LLJITs data layout.
+    fn global_prefix(&self) -> libc::c_char {
+        unsafe { LLVMOrcLLJITGetGlobalPrefix(self.jit) }
     }
 }
 
-/// A resource handle for code added to an [`LLJit`] instance.
-///
-/// When a `ResourceTracker` handle is dropped, the code corresponding to the handle will be
-/// removed from the JIT.
-pub struct ResourceTracker<'jit>(LLVMOrcResourceTrackerRef, PhantomData<&'jit ()>);
+/// A resource handle for code added to an [`LLJit`] instance.
+///
+/// When a `ResourceTracker` handle is dropped, the code corresponding to the handle will be
+/// removed from the JIT.
+pub struct ResourceTracker<'jit>(LLVMOrcResourceTrackerRef, PhantomData<&'jit ()>);
 
-impl<'jit> ResourceTracker<'jit> {
-    fn new(rt: LLVMOrcResourceTrackerRef) -> ResourceTracker<'jit> {
-        assert!(!rt.is_null());
-        ResourceTracker(rt, PhantomData)
+impl<'jit> ResourceTracker<'jit> {
+    fn new(rt: LLVMOrcResourceTrackerRef) -> ResourceTracker<'jit> {
+        assert!(!rt.is_null());
+        ResourceTracker(rt, PhantomData)
     }
 }
 
-impl Drop for ResourceTracker<'_> {
-    fn drop(&mut self) {
-        unsafe {
-            let err = LLVMOrcResourceTrackerRemove(self.0);
+impl Drop for ResourceTracker<'_> {
+    fn drop(&mut self) {
+        unsafe {
+            let err = LLVMOrcResourceTrackerRemove(self.0);
 
-            if let Some(err) = Error::from(err) {
-                panic!("Error: {}", err.as_str());
+            if let Some(err) = Error::from(err) {
+                panic!("Error: {}", err.as_str());
             }
 
-            LLVMOrcReleaseResourceTracker(self.0);
+            LLVMOrcReleaseResourceTracker(self.0);
         };
     }
 }
 
-
- \ No newline at end of file +
\ No newline at end of file -- cgit v1.2.3