Allow peeking at the compiled function

This commit is contained in:
bjorn3
2019-01-09 14:48:01 +01:00
committed by Dan Gohman
parent aeb9161e2c
commit eedc7cabf1

View File

@@ -506,7 +506,18 @@ where
/// Define a function, producing the function body from the given `Context`. /// Define a function, producing the function body from the given `Context`.
pub fn define_function(&mut self, func: FuncId, ctx: &mut Context) -> ModuleResult<()> { pub fn define_function(&mut self, func: FuncId, ctx: &mut Context) -> ModuleResult<()> {
let compiled = { self.define_function_peek_compiled(func, ctx, |_, _| ())
}
/// Define a function, allowing to peek at the compiled function and producing the
/// function body from the given `Context`.
pub fn define_function_peek_compiled<T>(
&mut self,
func: FuncId,
ctx: &mut Context,
peek_compiled: impl FnOnce(u32, &Context) -> T,
) -> ModuleResult<T> {
let (compiled, peek_res) = {
let code_size = ctx.compile(self.backend.isa()).map_err(|e| { let code_size = ctx.compile(self.backend.isa()).map_err(|e| {
info!( info!(
"defining function {}: {}", "defining function {}: {}",
@@ -523,18 +534,24 @@ where
if !info.decl.linkage.is_definable() { if !info.decl.linkage.is_definable() {
return Err(ModuleError::InvalidImportDefinition(info.decl.name.clone())); return Err(ModuleError::InvalidImportDefinition(info.decl.name.clone()));
} }
Some(self.backend.define_function(
let peek_res = peek_compiled(code_size, &ctx);
(
self.backend.define_function(
&info.decl.name, &info.decl.name,
ctx, ctx,
&ModuleNamespace::<B> { &ModuleNamespace::<B> {
contents: &self.contents, contents: &self.contents,
}, },
code_size, code_size,
)?) )?,
peek_res,
)
}; };
self.contents.functions[func].compiled = compiled; self.contents.functions[func].compiled = Some(compiled);
self.functions_to_finalize.push(func); self.functions_to_finalize.push(func);
Ok(()) Ok(peek_res)
} }
/// Define a function, producing the data contents from the given `DataContext`. /// Define a function, producing the data contents from the given `DataContext`.