From d5d5cba8b252e26933adddb9bf6a235ec67074ad Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Mon, 9 Nov 2020 10:11:19 +0100 Subject: [PATCH] Remove SimpleJITProduct All of it's methods now have an equivalent on SimpleJitModule --- .../simplejit/examples/simplejit-minimal.rs | 4 +- cranelift/simplejit/src/backend.rs | 58 +------------------ cranelift/simplejit/src/lib.rs | 2 +- cranelift/simplejit/tests/basic.rs | 2 +- 4 files changed, 7 insertions(+), 59 deletions(-) diff --git a/cranelift/simplejit/examples/simplejit-minimal.rs b/cranelift/simplejit/examples/simplejit-minimal.rs index 7c5df36eee..ae06c07b95 100644 --- a/cranelift/simplejit/examples/simplejit-minimal.rs +++ b/cranelift/simplejit/examples/simplejit-minimal.rs @@ -70,10 +70,10 @@ fn main() { module.clear_context(&mut ctx); // Perform linking. - let product = module.finish(); + module.finalize_definitions(); // 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. let ptr_b = unsafe { mem::transmute::<_, fn() -> u32>(code_b) }; diff --git a/cranelift/simplejit/src/backend.rs b/cranelift/simplejit/src/backend.rs index eb037154dc..72e49bd02f 100644 --- a/cranelift/simplejit/src/backend.rs +++ b/cranelift/simplejit/src/backend.rs @@ -10,8 +10,8 @@ use cranelift_codegen::{ }; use cranelift_entity::SecondaryMap; use cranelift_module::{ - DataContext, DataDescription, DataId, FuncId, FuncOrDataId, Init, Linkage, Module, - ModuleCompiledFunction, ModuleDeclarations, ModuleError, ModuleResult, RelocRecord, + DataContext, DataDescription, DataId, FuncId, Init, Linkage, Module, ModuleCompiledFunction, + ModuleDeclarations, ModuleError, ModuleResult, RelocRecord, }; use cranelift_native; #[cfg(not(windows))] @@ -149,16 +149,7 @@ struct MemoryHandle { writable: Memory, } -/// A `SimpleJITProduct` allows looking up the addresses of all functions and data objects -/// defined in the original module. -pub struct SimpleJITProduct { - memory: MemoryHandle, - declarations: ModuleDeclarations, - functions: SecondaryMap>, - data_objects: SecondaryMap>, -} - -impl SimpleJITProduct { +impl SimpleJITModule { /// Free memory allocated for code and data segments of compiled functions. /// /// # Safety @@ -173,29 +164,6 @@ impl SimpleJITProduct { self.memory.writable.free_memory(); } - /// Get the `FuncOrDataId` associated with the given name. - pub fn func_or_data_for_func(&self, name: &str) -> Option { - 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> { self.symbols .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))] fn lookup_with_dlsym(name: &str) -> Option<*const u8> { let c_str = CString::new(name).unwrap(); diff --git a/cranelift/simplejit/src/lib.rs b/cranelift/simplejit/src/lib.rs index 208106b93d..de4509fca0 100644 --- a/cranelift/simplejit/src/lib.rs +++ b/cranelift/simplejit/src/lib.rs @@ -26,7 +26,7 @@ mod backend; mod compiled_blob; mod memory; -pub use crate::backend::{SimpleJITBuilder, SimpleJITModule, SimpleJITProduct}; +pub use crate::backend::{SimpleJITBuilder, SimpleJITModule}; /// Version number of this crate. pub const VERSION: &str = env!("CARGO_PKG_VERSION"); diff --git a/cranelift/simplejit/tests/basic.rs b/cranelift/simplejit/tests/basic.rs index e7b52417c1..0b91765433 100644 --- a/cranelift/simplejit/tests/basic.rs +++ b/cranelift/simplejit/tests/basic.rs @@ -186,5 +186,5 @@ fn libcall_function() { .define_function(func_id, &mut ctx, &mut trap_sink) .unwrap(); - module.finish(); + module.finalize_definitions(); }