cranelift-module: expose trap information when defining functions
The current interface of `cranelift-module` requires consumers who want
to be informed about traps to discover that information through
`Module::Product`, which is backend-specific. Since it's advantageous
to manipulate this information in a backend-agnostic way, this patch
changes `Module::define_function{,_bytes}` to return information about
the traps contained in the function being defined.
This commit is contained in:
@@ -152,10 +152,11 @@ impl Backend for FaerieBackend {
|
||||
ctx: &cranelift_codegen::Context,
|
||||
namespace: &ModuleNamespace<Self>,
|
||||
total_size: u32,
|
||||
) -> ModuleResult<FaerieCompiledFunction> {
|
||||
) -> ModuleResult<(FaerieCompiledFunction, Option<&Vec<TrapSite>>)> {
|
||||
let mut code: Vec<u8> = vec![0; total_size as usize];
|
||||
// TODO: Replace this with FaerieStackmapSink once it is implemented.
|
||||
let mut stackmap_sink = NullStackmapSink {};
|
||||
let mut traps = None;
|
||||
|
||||
// Non-lexical lifetimes would obviate the braces here.
|
||||
{
|
||||
@@ -178,7 +179,7 @@ impl Backend for FaerieBackend {
|
||||
&mut stackmap_sink,
|
||||
)
|
||||
};
|
||||
trap_manifest.add_sink(trap_sink);
|
||||
traps = Some(trap_manifest.add_sink(trap_sink));
|
||||
} else {
|
||||
let mut trap_sink = NullTrapSink {};
|
||||
unsafe {
|
||||
@@ -200,7 +201,7 @@ impl Backend for FaerieBackend {
|
||||
.define(name, code)
|
||||
.expect("inconsistent declaration");
|
||||
|
||||
Ok(FaerieCompiledFunction { code_length })
|
||||
Ok((FaerieCompiledFunction { code_length }, traps))
|
||||
}
|
||||
|
||||
fn define_function_bytes(
|
||||
@@ -210,22 +211,23 @@ impl Backend for FaerieBackend {
|
||||
bytes: &[u8],
|
||||
_namespace: &ModuleNamespace<Self>,
|
||||
traps: Vec<TrapSite>,
|
||||
) -> ModuleResult<FaerieCompiledFunction> {
|
||||
) -> ModuleResult<(FaerieCompiledFunction, Option<&Vec<TrapSite>>)> {
|
||||
let code_length: u32 = match bytes.len().try_into() {
|
||||
Ok(code_length) => code_length,
|
||||
_ => Err(ModuleError::FunctionTooLarge(name.to_string()))?,
|
||||
};
|
||||
let mut ret_traps = None;
|
||||
|
||||
if let Some(ref mut trap_manifest) = self.trap_manifest {
|
||||
let trap_sink = FaerieTrapSink::new_with_sites(name, code_length, traps);
|
||||
trap_manifest.add_sink(trap_sink);
|
||||
ret_traps = Some(trap_manifest.add_sink(trap_sink));
|
||||
}
|
||||
|
||||
self.artifact
|
||||
.define(name, bytes.to_vec())
|
||||
.expect("inconsistent declaration");
|
||||
|
||||
Ok(FaerieCompiledFunction { code_length })
|
||||
Ok((FaerieCompiledFunction { code_length }, ret_traps))
|
||||
}
|
||||
|
||||
fn define_data(
|
||||
|
||||
@@ -59,7 +59,8 @@ impl FaerieTrapManifest {
|
||||
}
|
||||
|
||||
/// Put a `FaerieTrapSink` into manifest
|
||||
pub fn add_sink(&mut self, sink: FaerieTrapSink) {
|
||||
pub fn add_sink(&mut self, sink: FaerieTrapSink) -> &Vec<TrapSite> {
|
||||
self.sinks.push(sink);
|
||||
&self.sinks.last().unwrap().sites
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user