Add prepare_for_function_redefine

This commit is contained in:
bjorn3
2020-11-12 19:29:05 +01:00
parent 03c0e7e678
commit 86d3dc9510
4 changed files with 118 additions and 0 deletions

View File

@@ -14,6 +14,7 @@ cranelift-module = { path = "../module", version = "0.68.0" }
cranelift-native = { path = "../native", version = "0.68.0" }
cranelift-codegen = { path = "../codegen", version = "0.68.0", default-features = false, features = ["std"] }
cranelift-entity = { path = "../entity", version = "0.68.0" }
anyhow = "1.0"
region = "2.2.0"
libc = { version = "0.2.42" }
errno = "0.2.4"

View File

@@ -393,6 +393,28 @@ impl SimpleJITModule {
data_objects_to_finalize: Vec::new(),
}
}
/// Allow a single future `define_function` on a previously defined function. This allows for
/// hot code swapping and lazy compilation of functions.
pub fn prepare_for_function_redefine(&mut self, func_id: FuncId) -> ModuleResult<()> {
let decl = self.declarations.get_function_decl(func_id);
if !decl.linkage.is_definable() {
return Err(ModuleError::InvalidImportDefinition(decl.name.clone()));
}
if self.compiled_functions[func_id].is_none() {
return Err(ModuleError::Backend(anyhow::anyhow!(
"Tried to redefine not yet defined function {}",
decl.name
)));
}
self.compiled_functions[func_id] = None;
// FIXME return some kind of handle that allows for deallocating the function
Ok(())
}
}
impl<'simple_jit_backend> Module for SimpleJITModule {