Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Peekable define function #651

Merged
merged 3 commits into from
Jan 16, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions lib/module/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,20 @@ where

/// 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, |_, _, _| ())
}

/// 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, &isa::TargetIsa) -> T,
) -> ModuleResult<T> {
let code_size;
let compiled = {
let code_size = ctx.compile(self.backend.isa()).map_err(|e| {
code_size = ctx.compile(self.backend.isa()).map_err(|e| {
info!(
"defining function {}: {}",
func,
Expand All @@ -523,6 +535,7 @@ where
if !info.decl.linkage.is_definable() {
return Err(ModuleError::InvalidImportDefinition(info.decl.name.clone()));
}

Some(self.backend.define_function(
&info.decl.name,
ctx,
Expand All @@ -534,7 +547,7 @@ where
};
self.contents.functions[func].compiled = compiled;
self.functions_to_finalize.push(func);
Ok(())
Ok(peek_compiled(code_size, &ctx, self.backend.isa()))
}

/// Define a function, producing the data contents from the given `DataContext`.
Expand Down