Skip to content

Commit

Permalink
Remove define_function_peek_compiled
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn3 authored and bnjbvr committed Feb 15, 2019
1 parent 2145dd3 commit 50c66ae
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions cranelift-module/src/module.rs
Expand Up @@ -505,49 +505,44 @@ 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>(
///
/// Returns the size of the function's code.
///
/// Note: After calling this function the given `Context` will contain the compiled function.
pub fn define_function(
&mut self,
func: FuncId,
ctx: &mut Context,
peek_compiled: impl FnOnce(u32, &Context, &isa::TargetIsa) -> T,
) -> ModuleResult<T> {
let code_size;
let compiled = {
code_size = ctx.compile(self.backend.isa()).map_err(|e| {
info!(
"defining function {}: {}",
func,
ctx.func.display(self.backend.isa())
);
ModuleError::Compilation(e)
})?;
) -> ModuleResult<binemit::CodeOffset> {
let code_size = ctx.compile(self.backend.isa()).map_err(|e| {
info!(
"defining function {}: {}",
func,
ctx.func.display(self.backend.isa())
);
ModuleError::Compilation(e)
})?;

let info = &self.contents.functions[func];
if info.compiled.is_some() {
return Err(ModuleError::DuplicateDefinition(info.decl.name.clone()));
}
if !info.decl.linkage.is_definable() {
return Err(ModuleError::InvalidImportDefinition(info.decl.name.clone()));
}
let info = &self.contents.functions[func];
if info.compiled.is_some() {
return Err(ModuleError::DuplicateDefinition(info.decl.name.clone()));
}
if !info.decl.linkage.is_definable() {
return Err(ModuleError::InvalidImportDefinition(info.decl.name.clone()));
}

let compiled = Some(self.backend.define_function(
&info.decl.name,
ctx,
&ModuleNamespace::<B> {
contents: &self.contents,
},
code_size,
)?);

Some(self.backend.define_function(
&info.decl.name,
ctx,
&ModuleNamespace::<B> {
contents: &self.contents,
},
code_size,
)?)
};
self.contents.functions[func].compiled = compiled;
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`.
Expand Down Expand Up @@ -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`
/// implementations may provide additional functionality available after
/// a `Module` is complete.
Expand Down

0 comments on commit 50c66ae

Please sign in to comment.