Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions hugr-llvm/src/emit/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ impl<'c, 'a, H: HugrView<Node = Node>> EmitFuncContext<'c, 'a, H> {
self.todo.insert(node.node());
}

/// Returns the current [FunctionValue] being emitted.
pub fn func(&self) -> FunctionValue<'c> {
self.func
}

/// Returns the internal [Builder]. Callers must ensure that it is
/// positioned at the end of a basic block. This invariant is not checked(it
/// doesn't seem possible to check it).
Expand Down Expand Up @@ -352,3 +357,21 @@ pub fn build_ok_or_else<'c, H: HugrView<Node = Node>>(
let either = builder.build_select(is_ok, right, left, "")?;
Ok(either)
}

#[cfg(test)]
mod tests {
#[test]
fn test_func_getter() {
// Use TestContext for consistent test setup
let test_ctx = crate::test::test_ctx(-1);
let emit_context = test_ctx.get_emit_module_context();
let func_type = emit_context.iw_context().void_type().fn_type(&[], false);
let function = emit_context
.module()
.add_function("test_func", func_type, None);
let func_context = super::EmitFuncContext::new(emit_context, function).unwrap();

// Assert the getter returns the correct function
assert_eq!(func_context.func(), function);
}
}
Loading