change interfaces to use slices instead of Vec
This commit is contained in:
@@ -152,11 +152,11 @@ impl Backend for FaerieBackend {
|
||||
ctx: &cranelift_codegen::Context,
|
||||
namespace: &ModuleNamespace<Self>,
|
||||
total_size: u32,
|
||||
) -> ModuleResult<(FaerieCompiledFunction, Option<&Vec<TrapSite>>)> {
|
||||
) -> ModuleResult<(FaerieCompiledFunction, &[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;
|
||||
let mut traps: &[TrapSite] = &[];
|
||||
|
||||
// Non-lexical lifetimes would obviate the braces here.
|
||||
{
|
||||
@@ -179,7 +179,7 @@ impl Backend for FaerieBackend {
|
||||
&mut stackmap_sink,
|
||||
)
|
||||
};
|
||||
traps = Some(trap_manifest.add_sink(trap_sink));
|
||||
traps = trap_manifest.add_sink(trap_sink);
|
||||
} else {
|
||||
let mut trap_sink = NullTrapSink {};
|
||||
unsafe {
|
||||
@@ -211,16 +211,16 @@ impl Backend for FaerieBackend {
|
||||
bytes: &[u8],
|
||||
_namespace: &ModuleNamespace<Self>,
|
||||
traps: Vec<TrapSite>,
|
||||
) -> ModuleResult<(FaerieCompiledFunction, Option<&Vec<TrapSite>>)> {
|
||||
) -> ModuleResult<(FaerieCompiledFunction, &[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;
|
||||
let mut ret_traps: &[TrapSite] = &[];
|
||||
|
||||
if let Some(ref mut trap_manifest) = self.trap_manifest {
|
||||
let trap_sink = FaerieTrapSink::new_with_sites(name, code_length, traps);
|
||||
ret_traps = Some(trap_manifest.add_sink(trap_sink));
|
||||
ret_traps = trap_manifest.add_sink(trap_sink);
|
||||
}
|
||||
|
||||
self.artifact
|
||||
|
||||
@@ -59,7 +59,7 @@ impl FaerieTrapManifest {
|
||||
}
|
||||
|
||||
/// Put a `FaerieTrapSink` into manifest
|
||||
pub fn add_sink(&mut self, sink: FaerieTrapSink) -> &Vec<TrapSite> {
|
||||
pub fn add_sink(&mut self, sink: FaerieTrapSink) -> &[TrapSite] {
|
||||
self.sinks.push(sink);
|
||||
&self.sinks.last().unwrap().sites
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ where
|
||||
ctx: &Context,
|
||||
namespace: &ModuleNamespace<Self>,
|
||||
code_size: u32,
|
||||
) -> ModuleResult<(Self::CompiledFunction, Option<&Vec<TrapSite>>)>;
|
||||
) -> ModuleResult<(Self::CompiledFunction, &[TrapSite])>;
|
||||
|
||||
/// Define a function, taking the function body from the given `bytes`.
|
||||
///
|
||||
@@ -98,7 +98,7 @@ where
|
||||
bytes: &[u8],
|
||||
namespace: &ModuleNamespace<Self>,
|
||||
traps: Vec<TrapSite>,
|
||||
) -> ModuleResult<(Self::CompiledFunction, Option<&Vec<TrapSite>>)>;
|
||||
) -> ModuleResult<(Self::CompiledFunction, &[TrapSite])>;
|
||||
|
||||
/// Define a zero-initialized data object of the given size.
|
||||
///
|
||||
|
||||
@@ -354,7 +354,7 @@ where
|
||||
|
||||
pub struct ModuleCompiledFunction<'a> {
|
||||
pub size: binemit::CodeOffset,
|
||||
pub traps: Option<&'a Vec<TrapSite>>,
|
||||
pub traps: &'a [TrapSite],
|
||||
}
|
||||
|
||||
impl<B> Module<B>
|
||||
|
||||
@@ -189,7 +189,7 @@ impl Backend for ObjectBackend {
|
||||
ctx: &cranelift_codegen::Context,
|
||||
_namespace: &ModuleNamespace<Self>,
|
||||
code_size: u32,
|
||||
) -> ModuleResult<(ObjectCompiledFunction, Option<&Vec<TrapSite>>)> {
|
||||
) -> ModuleResult<(ObjectCompiledFunction, &[TrapSite])> {
|
||||
let mut code: Vec<u8> = vec![0; code_size as usize];
|
||||
let mut reloc_sink = ObjectRelocSink::new(self.object.format());
|
||||
let mut trap_sink = ObjectTrapSink::default();
|
||||
@@ -232,7 +232,7 @@ impl Backend for ObjectBackend {
|
||||
}
|
||||
let trapref = self.traps.index_mut(func_id);
|
||||
*trapref = trap_sink.sites;
|
||||
Ok((ObjectCompiledFunction, Some(trapref)))
|
||||
Ok((ObjectCompiledFunction, trapref))
|
||||
}
|
||||
|
||||
fn define_function_bytes(
|
||||
@@ -242,7 +242,7 @@ impl Backend for ObjectBackend {
|
||||
bytes: &[u8],
|
||||
_namespace: &ModuleNamespace<Self>,
|
||||
traps: Vec<TrapSite>,
|
||||
) -> ModuleResult<(ObjectCompiledFunction, Option<&Vec<TrapSite>>)> {
|
||||
) -> ModuleResult<(ObjectCompiledFunction, &[TrapSite])> {
|
||||
let symbol = self.functions[func_id].unwrap();
|
||||
let section = self.object.section_id(StandardSection::Text);
|
||||
let _offset = self
|
||||
@@ -250,7 +250,7 @@ impl Backend for ObjectBackend {
|
||||
.add_symbol_data(symbol, section, bytes, self.function_alignment);
|
||||
let trapref = self.traps.index_mut(func_id);
|
||||
*trapref = traps;
|
||||
Ok((ObjectCompiledFunction, Some(trapref)))
|
||||
Ok((ObjectCompiledFunction, trapref))
|
||||
}
|
||||
|
||||
fn define_data(
|
||||
|
||||
@@ -278,7 +278,7 @@ impl<'simple_jit_backend> Backend for SimpleJITBackend {
|
||||
ctx: &cranelift_codegen::Context,
|
||||
_namespace: &ModuleNamespace<Self>,
|
||||
code_size: u32,
|
||||
) -> ModuleResult<(Self::CompiledFunction, Option<&Vec<TrapSite>>)> {
|
||||
) -> ModuleResult<(Self::CompiledFunction, &[TrapSite])> {
|
||||
let size = code_size as usize;
|
||||
let ptr = self
|
||||
.memory
|
||||
@@ -309,7 +309,7 @@ impl<'simple_jit_backend> Backend for SimpleJITBackend {
|
||||
size,
|
||||
relocs: reloc_sink.relocs,
|
||||
},
|
||||
None,
|
||||
&[],
|
||||
))
|
||||
}
|
||||
|
||||
@@ -320,7 +320,7 @@ impl<'simple_jit_backend> Backend for SimpleJITBackend {
|
||||
bytes: &[u8],
|
||||
_namespace: &ModuleNamespace<Self>,
|
||||
_traps: Vec<TrapSite>,
|
||||
) -> ModuleResult<(Self::CompiledFunction, Option<&Vec<TrapSite>>)> {
|
||||
) -> ModuleResult<(Self::CompiledFunction, &[TrapSite])> {
|
||||
let size = bytes.len();
|
||||
let ptr = self
|
||||
.memory
|
||||
@@ -340,7 +340,7 @@ impl<'simple_jit_backend> Backend for SimpleJITBackend {
|
||||
size,
|
||||
relocs: vec![],
|
||||
},
|
||||
None,
|
||||
&[],
|
||||
))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user