CodeGenLib/jit/
typed.rs

1//! <h4>Jit execution</h4>
2//! With this module you can jit execute a function
3
4// use crate::arch::AsmCall::AsmCall as asm;
5// use crate::arch::ext::AMD64::*;
6use crate::x86::function::Function;
7use crate::{Result, CodeGenLibError};
8
9pub trait JitRuntime {
10    /// Returns the function
11    unsafe fn typed<T, X>(&mut self) -> Result<extern "C" fn() -> X>;
12}
13
14impl JitRuntime for Function {
15    /// Tr
16    unsafe fn typed<Params, Ret>(&mut self) -> Result<extern "C"  fn() -> Ret> {
17        let func_ptr: extern "C" fn() -> Ret = unsafe {
18            std::mem::transmute(self.gen.as_ptr())
19        };
20
21        if self.esymbols.len() != 0 {   // ExternSymbols isn't empty
22            return Err(CodeGenLibError::JitFunctionsNoExtern)
23        }
24
25        Ok(func_ptr)
26    }
27}