From 45013a1d2bd7a5c7f61683db6ef914a39ac13fa4 Mon Sep 17 00:00:00 2001 From: iximeow Date: Thu, 18 Apr 2019 16:51:26 -0700 Subject: [PATCH] Expose function definitions and populate FaerieCompiledFunction with function lengths --- cranelift/faerie/src/backend.rs | 16 ++++++++++++++-- cranelift/module/src/lib.rs | 3 ++- cranelift/module/src/module.rs | 11 ++++++++--- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/cranelift/faerie/src/backend.rs b/cranelift/faerie/src/backend.rs index f413879ac23d..1deb46e0730d 100644 --- a/cranelift/faerie/src/backend.rs +++ b/cranelift/faerie/src/backend.rs @@ -96,7 +96,15 @@ pub struct FaerieBackend { libcall_names: Box String>, } -pub struct FaerieCompiledFunction {} +pub struct FaerieCompiledFunction { + code_length: u32, +} + +impl FaerieCompiledFunction { + pub fn code_length(&self) -> u32 { + self.code_length + } +} pub struct FaerieCompiledData {} @@ -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( diff --git a/cranelift/module/src/lib.rs b/cranelift/module/src/lib.rs index ce6f00aff0a9..e30961c3bcac 100644 --- a/cranelift/module/src/lib.rs +++ b/cranelift/module/src/lib.rs @@ -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. diff --git a/cranelift/module/src/module.rs b/cranelift/module/src/module.rs index 3b0f4673e066..5b11a48e157d 100644 --- a/cranelift/module/src/module.rs +++ b/cranelift/module/src/module.rs @@ -153,14 +153,14 @@ pub enum ModuleError { pub type ModuleResult = Result; /// A function belonging to a `Module`. -struct ModuleFunction +pub struct ModuleFunction where B: Backend, { /// The function declaration. - decl: FunctionDeclaration, + pub decl: FunctionDeclaration, /// The compiled artifact, once it's available. - compiled: Option, + pub compiled: Option, } impl ModuleFunction @@ -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> { + self.contents.functions.values() + } + /// Declare a data object in this module. pub fn declare_data( &mut self,