Remove SimpleJITProduct
All of it's methods now have an equivalent on SimpleJitModule
This commit is contained in:
@@ -70,10 +70,10 @@ fn main() {
|
|||||||
module.clear_context(&mut ctx);
|
module.clear_context(&mut ctx);
|
||||||
|
|
||||||
// Perform linking.
|
// Perform linking.
|
||||||
let product = module.finish();
|
module.finalize_definitions();
|
||||||
|
|
||||||
// Get a raw pointer to the generated code.
|
// Get a raw pointer to the generated code.
|
||||||
let code_b = product.lookup_func(func_b);
|
let code_b = module.get_finalized_function(func_b);
|
||||||
|
|
||||||
// Cast it to a rust function pointer type.
|
// Cast it to a rust function pointer type.
|
||||||
let ptr_b = unsafe { mem::transmute::<_, fn() -> u32>(code_b) };
|
let ptr_b = unsafe { mem::transmute::<_, fn() -> u32>(code_b) };
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ use cranelift_codegen::{
|
|||||||
};
|
};
|
||||||
use cranelift_entity::SecondaryMap;
|
use cranelift_entity::SecondaryMap;
|
||||||
use cranelift_module::{
|
use cranelift_module::{
|
||||||
DataContext, DataDescription, DataId, FuncId, FuncOrDataId, Init, Linkage, Module,
|
DataContext, DataDescription, DataId, FuncId, Init, Linkage, Module, ModuleCompiledFunction,
|
||||||
ModuleCompiledFunction, ModuleDeclarations, ModuleError, ModuleResult, RelocRecord,
|
ModuleDeclarations, ModuleError, ModuleResult, RelocRecord,
|
||||||
};
|
};
|
||||||
use cranelift_native;
|
use cranelift_native;
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
@@ -149,16 +149,7 @@ struct MemoryHandle {
|
|||||||
writable: Memory,
|
writable: Memory,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A `SimpleJITProduct` allows looking up the addresses of all functions and data objects
|
impl SimpleJITModule {
|
||||||
/// defined in the original module.
|
|
||||||
pub struct SimpleJITProduct {
|
|
||||||
memory: MemoryHandle,
|
|
||||||
declarations: ModuleDeclarations,
|
|
||||||
functions: SecondaryMap<FuncId, Option<CompiledBlob>>,
|
|
||||||
data_objects: SecondaryMap<DataId, Option<CompiledBlob>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SimpleJITProduct {
|
|
||||||
/// Free memory allocated for code and data segments of compiled functions.
|
/// Free memory allocated for code and data segments of compiled functions.
|
||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
@@ -173,29 +164,6 @@ impl SimpleJITProduct {
|
|||||||
self.memory.writable.free_memory();
|
self.memory.writable.free_memory();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the `FuncOrDataId` associated with the given name.
|
|
||||||
pub fn func_or_data_for_func(&self, name: &str) -> Option<FuncOrDataId> {
|
|
||||||
self.declarations.get_name(name)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Return the address of a function.
|
|
||||||
pub fn lookup_func(&self, func_id: FuncId) -> *const u8 {
|
|
||||||
self.functions[func_id]
|
|
||||||
.as_ref()
|
|
||||||
.unwrap_or_else(|| panic!("{} is not defined", func_id))
|
|
||||||
.ptr
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Return the address and size of a data object.
|
|
||||||
pub fn lookup_data(&self, data_id: DataId) -> (*const u8, usize) {
|
|
||||||
let data = self.data_objects[data_id]
|
|
||||||
.as_ref()
|
|
||||||
.unwrap_or_else(|| panic!("{} is not defined", data_id));
|
|
||||||
(data.ptr, data.size)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SimpleJITModule {
|
|
||||||
fn lookup_symbol(&self, name: &str) -> Option<*const u8> {
|
fn lookup_symbol(&self, name: &str) -> Option<*const u8> {
|
||||||
self.symbols
|
self.symbols
|
||||||
.get(name)
|
.get(name)
|
||||||
@@ -547,26 +515,6 @@ impl<'simple_jit_backend> Module for SimpleJITModule {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SimpleJITModule {
|
|
||||||
/// SimpleJIT emits code and data into memory as it processes them. This
|
|
||||||
/// method performs no additional processing, but returns a handle which
|
|
||||||
/// allows freeing the allocated memory. Otherwise said memory is leaked
|
|
||||||
/// to enable safe handling of the resulting pointers.
|
|
||||||
///
|
|
||||||
/// This method does not need to be called when access to the memory
|
|
||||||
/// handle is not required.
|
|
||||||
pub fn finish(mut self) -> SimpleJITProduct {
|
|
||||||
self.finalize_definitions();
|
|
||||||
|
|
||||||
SimpleJITProduct {
|
|
||||||
memory: self.memory,
|
|
||||||
declarations: self.declarations,
|
|
||||||
functions: self.functions,
|
|
||||||
data_objects: self.data_objects,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
fn lookup_with_dlsym(name: &str) -> Option<*const u8> {
|
fn lookup_with_dlsym(name: &str) -> Option<*const u8> {
|
||||||
let c_str = CString::new(name).unwrap();
|
let c_str = CString::new(name).unwrap();
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ mod backend;
|
|||||||
mod compiled_blob;
|
mod compiled_blob;
|
||||||
mod memory;
|
mod memory;
|
||||||
|
|
||||||
pub use crate::backend::{SimpleJITBuilder, SimpleJITModule, SimpleJITProduct};
|
pub use crate::backend::{SimpleJITBuilder, SimpleJITModule};
|
||||||
|
|
||||||
/// Version number of this crate.
|
/// Version number of this crate.
|
||||||
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||||
|
|||||||
@@ -186,5 +186,5 @@ fn libcall_function() {
|
|||||||
.define_function(func_id, &mut ctx, &mut trap_sink)
|
.define_function(func_id, &mut ctx, &mut trap_sink)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
module.finish();
|
module.finalize_definitions();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user