Skip to content

Commit

Permalink
Merge pull request bytecodealliance#743 from CraneStation/expose-func…
Browse files Browse the repository at this point in the history
…tion-definitions

Expose function definitions, populate FaerieCompiledFunction
  • Loading branch information
Pat Hickey committed Apr 25, 2019
2 parents 95e6fc9 + 45013a1 commit 75ec950
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
16 changes: 14 additions & 2 deletions cranelift/faerie/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,15 @@ pub struct FaerieBackend {
libcall_names: Box<Fn(ir::LibCall) -> String>,
}

pub struct FaerieCompiledFunction {}
pub struct FaerieCompiledFunction {
code_length: u32,
}

impl FaerieCompiledFunction {
pub fn code_length(&self) -> u32 {
self.code_length
}
}

pub struct FaerieCompiledData {}

Expand Down Expand Up @@ -187,10 +195,14 @@ impl Backend for FaerieBackend {
}
}

// because `define` will take ownership of code, this is our last chance
let code_length = code.len() as u32;

self.artifact
.define(name, code)
.expect("inconsistent declaration");
Ok(FaerieCompiledFunction {})

Ok(FaerieCompiledFunction { code_length })
}

fn define_data(
Expand Down
3 changes: 2 additions & 1 deletion cranelift/module/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ mod module;
pub use crate::backend::Backend;
pub use crate::data_context::{DataContext, DataDescription, Init};
pub use crate::module::{
DataId, FuncId, FuncOrDataId, Linkage, Module, ModuleError, ModuleNamespace, ModuleResult,
DataId, FuncId, FuncOrDataId, Linkage, Module, ModuleError, ModuleFunction, ModuleNamespace,
ModuleResult,
};

/// Version number of this crate.
Expand Down
11 changes: 8 additions & 3 deletions cranelift/module/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,14 @@ pub enum ModuleError {
pub type ModuleResult<T> = Result<T, ModuleError>;

/// A function belonging to a `Module`.
struct ModuleFunction<B>
pub struct ModuleFunction<B>
where
B: Backend,
{
/// The function declaration.
decl: FunctionDeclaration,
pub decl: FunctionDeclaration,
/// The compiled artifact, once it's available.
compiled: Option<B::CompiledFunction>,
pub compiled: Option<B::CompiledFunction>,
}

impl<B> ModuleFunction<B>
Expand Down Expand Up @@ -427,6 +427,11 @@ where
}
}

/// An iterator over functions that have been declared in this module.
pub fn declared_functions(&self) -> core::slice::Iter<'_, ModuleFunction<B>> {
self.contents.functions.values()
}

/// Declare a data object in this module.
pub fn declare_data(
&mut self,
Expand Down

0 comments on commit 75ec950

Please sign in to comment.