Remove define_function_peek_compiled

This commit is contained in:
bjorn3
2019-01-18 17:26:28 +01:00
committed by Benjamin Bouvier
parent a45b814de8
commit 615499bae8

View File

@@ -505,21 +505,16 @@ 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<()> { ///
self.define_function_peek_compiled(func, ctx, |_, _, _| ()) /// Returns the size of the function's code.
} ///
/// Note: After calling this function the given `Context` will contain the compiled function.
/// Define a function, allowing to peek at the compiled function and producing the pub fn define_function(
/// function body from the given `Context`.
pub fn define_function_peek_compiled<T>(
&mut self, &mut self,
func: FuncId, func: FuncId,
ctx: &mut Context, ctx: &mut Context,
peek_compiled: impl FnOnce(u32, &Context, &isa::TargetIsa) -> T, ) -> ModuleResult<binemit::CodeOffset> {
) -> ModuleResult<T> { let code_size = ctx.compile(self.backend.isa()).map_err(|e| {
let code_size;
let compiled = {
code_size = ctx.compile(self.backend.isa()).map_err(|e| {
info!( info!(
"defining function {}: {}", "defining function {}: {}",
func, func,
@@ -536,18 +531,18 @@ where
return Err(ModuleError::InvalidImportDefinition(info.decl.name.clone())); return Err(ModuleError::InvalidImportDefinition(info.decl.name.clone()));
} }
Some(self.backend.define_function( let compiled = Some(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,
)?) )?);
};
self.contents.functions[func].compiled = compiled; self.contents.functions[func].compiled = compiled;
self.functions_to_finalize.push(func); self.functions_to_finalize.push(func);
Ok(peek_compiled(code_size, &ctx, self.backend.isa())) Ok(code_size)
} }
/// Define a function, producing the data contents from the given `DataContext`. /// Define a function, producing the data contents from the given `DataContext`.
@@ -679,6 +674,11 @@ where
) )
} }
/// Return the target isa
pub fn isa(&self) -> &isa::TargetIsa {
self.backend.isa()
}
/// Consume the module and return the resulting `Product`. Some `Backend` /// Consume the module and return the resulting `Product`. Some `Backend`
/// implementations may provide additional functionality available after /// implementations may provide additional functionality available after
/// a `Module` is complete. /// a `Module` is complete.