diff --git a/lib/faerie/src/backend.rs b/lib/faerie/src/backend.rs index 890a934fd2..4c900c843a 100644 --- a/lib/faerie/src/backend.rs +++ b/lib/faerie/src/backend.rs @@ -5,7 +5,7 @@ use cretonne_codegen::binemit::{Addend, CodeOffset, NullTrapSink, Reloc, RelocSi use cretonne_codegen::isa::TargetIsa; use cretonne_codegen::{self, binemit, ir}; use cretonne_module::{Backend, DataContext, DataDescription, Init, Linkage, ModuleError, - ModuleNamespace}; + ModuleNamespace, ModuleResult}; use faerie; use failure::Error; use std::fs::File; @@ -52,7 +52,7 @@ impl FaerieBuilder { format: BinaryFormat, collect_traps: FaerieTrapCollection, libcall_names: Box String>, - ) -> Result { + ) -> ModuleResult { if !isa.flags().is_pic() { return Err(ModuleError::Backend( "faerie requires TargetIsa be PIC".to_owned(), @@ -149,7 +149,7 @@ impl Backend for FaerieBackend { ctx: &cretonne_codegen::Context, namespace: &ModuleNamespace, code_size: u32, - ) -> Result { + ) -> ModuleResult { let mut code: Vec = Vec::with_capacity(code_size as usize); code.resize(code_size as usize, 0); @@ -198,7 +198,7 @@ impl Backend for FaerieBackend { name: &str, data_ctx: &DataContext, namespace: &ModuleNamespace, - ) -> Result { + ) -> ModuleResult { let &DataDescription { writable: _writable, ref init, diff --git a/lib/module/src/backend.rs b/lib/module/src/backend.rs index 15258544d8..298e526d6c 100644 --- a/lib/module/src/backend.rs +++ b/lib/module/src/backend.rs @@ -8,6 +8,7 @@ use DataContext; use Linkage; use ModuleError; use ModuleNamespace; +use ModuleResult; /// A `Backend` implements the functionality needed to support a `Module`. pub trait Backend @@ -57,7 +58,7 @@ where ctx: &Context, namespace: &ModuleNamespace, code_size: u32, - ) -> Result; + ) -> ModuleResult; /// Define a zero-initialized data object of the given size. /// @@ -67,7 +68,7 @@ where name: &str, data_ctx: &DataContext, namespace: &ModuleNamespace, - ) -> Result; + ) -> ModuleResult; /// Write the address of `what` into the data for `data` at `offset`. `data` must refer to a /// defined data object. diff --git a/lib/module/src/lib.rs b/lib/module/src/lib.rs index 445b588c40..85e04caaff 100644 --- a/lib/module/src/lib.rs +++ b/lib/module/src/lib.rs @@ -33,7 +33,8 @@ mod module; pub use backend::Backend; pub use data_context::{DataContext, DataDescription, Init, Writability}; -pub use module::{DataId, FuncId, FuncOrDataId, Linkage, Module, ModuleError, ModuleNamespace}; +pub use module::{DataId, FuncId, FuncOrDataId, Linkage, Module, ModuleError, ModuleNamespace, + ModuleResult}; /// This replaces `std` in builds with `core`. #[cfg(not(feature = "std"))] diff --git a/lib/module/src/module.rs b/lib/module/src/module.rs index a01d58ffdf..84188ccd75 100644 --- a/lib/module/src/module.rs +++ b/lib/module/src/module.rs @@ -139,6 +139,9 @@ pub enum ModuleError { Backend(String), } +/// A convenient alias for a `Result` that uses `ModuleError` as the error type. +pub type ModuleResult = Result; + /// A function belonging to a `Module`. struct ModuleFunction where @@ -347,7 +350,7 @@ where name: &str, linkage: Linkage, signature: &ir::Signature, - ) -> Result { + ) -> ModuleResult { // TODO: Can we avoid allocating names so often? use std::collections::hash_map::Entry::*; match self.names.entry(name.to_owned()) { @@ -385,7 +388,7 @@ where name: &str, linkage: Linkage, writable: bool, - ) -> Result { + ) -> ModuleResult { // TODO: Can we avoid allocating names so often? use std::collections::hash_map::Entry::*; match self.names.entry(name.to_owned()) { @@ -457,7 +460,7 @@ where } /// Define a function, producing the function body from the given `Context`. - pub fn define_function(&mut self, func: FuncId, ctx: &mut Context) -> Result<(), ModuleError> { + pub fn define_function(&mut self, func: FuncId, ctx: &mut Context) -> ModuleResult<()> { let compiled = { let code_size = ctx.compile(self.backend.isa()).map_err(|e| { dbg!( @@ -489,7 +492,7 @@ where } /// Define a function, producing the data contents from the given `DataContext`. - pub fn define_data(&mut self, data: DataId, data_ctx: &DataContext) -> Result<(), ModuleError> { + pub fn define_data(&mut self, data: DataId, data_ctx: &DataContext) -> ModuleResult<()> { let compiled = { let info = &self.contents.data_objects[data]; if !info.compiled.is_none() { diff --git a/lib/simplejit/src/backend.rs b/lib/simplejit/src/backend.rs index 889601a819..4df071efc9 100644 --- a/lib/simplejit/src/backend.rs +++ b/lib/simplejit/src/backend.rs @@ -3,8 +3,8 @@ use cretonne_codegen::binemit::{Addend, CodeOffset, NullTrapSink, Reloc, RelocSink}; use cretonne_codegen::isa::TargetIsa; use cretonne_codegen::{self, ir, settings}; -use cretonne_module::{Backend, DataContext, DataDescription, Init, Linkage, ModuleError, - ModuleNamespace, Writability}; +use cretonne_module::{Backend, DataContext, DataDescription, Init, Linkage, ModuleNamespace, + ModuleResult, Writability}; use cretonne_native; use libc; use memory::Memory; @@ -118,7 +118,7 @@ impl<'simple_jit_backend> Backend for SimpleJITBackend { ctx: &cretonne_codegen::Context, _namespace: &ModuleNamespace, code_size: u32, - ) -> Result { + ) -> ModuleResult { let size = code_size as usize; let ptr = self.code_memory .allocate(size) @@ -141,7 +141,7 @@ impl<'simple_jit_backend> Backend for SimpleJITBackend { _name: &str, data: &DataContext, _namespace: &ModuleNamespace, - ) -> Result { + ) -> ModuleResult { let &DataDescription { writable, ref init,