From 21c43e3ee182824e92e2b25f1d3c03ed47f9c02b Mon Sep 17 00:00:00 2001 From: Jakub Doka Date: Thu, 3 Oct 2024 19:08:57 +0200 Subject: [PATCH] making more intuitive api --- src/lib.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 5de19962..539466a8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1602,19 +1602,22 @@ pub fn run( } } -/// Run the allocator. -pub fn run_with_ctx( +/// Run the allocator with reusable context. +/// +/// Return value points to `ctx.output` that can be alternatively `std::mem::take`n. +pub fn run_with_ctx<'a, F: Function>( func: &F, env: &MachineEnv, options: &RegallocOptions, - ctx: &mut Ctx, -) -> Result<(), RegAllocError> { - Ok(match options.algorithm { + ctx: &'a mut Ctx, +) -> Result<&'a Output, RegAllocError> { + match options.algorithm { Algorithm::Ion => ion::run(func, env, ctx, options.verbose_log, options.validate_ssa)?, Algorithm::Fastalloc => { ctx.output = fastalloc::run(func, env, options.verbose_log, options.validate_ssa)? } - }) + } + Ok(&ctx.output) } #[derive(Clone, Copy, Debug, Default)]