Skip to content

Commit 81455dd

Browse files
committed
Added docs for build_return
1 parent fbc4555 commit 81455dd

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

src/builder.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,30 @@ impl Builder {
4141
Builder::new(builder)
4242
}
4343

44-
// REVIEW: Would probably make this API a bit simpler by taking Into<Option<impl BasicValue>>
45-
// So that you could just do build_return(value) or build_return(None)
46-
// Is that frowned upon?
47-
// TODO: Option<impl BasicValue>
44+
// REVIEW: Would probably make this API a bit simpler by taking Into<Option<&BasicValue>>
45+
// So that you could just do build_return(&value) or build_return(None). Is that frowned upon?
46+
/// Builds a function return instruction. It should be provided with `None` if the return type
47+
/// is void otherwise `Some(&value)` should be provided.
48+
///
49+
/// # Example
50+
///
51+
/// ```no_run
52+
/// use inkwell::context::Context;
53+
///
54+
/// // A simple function which returns its argument:
55+
/// let context = Context::create();
56+
/// let module = context.create_module("ret");
57+
/// let builder = context.create_builder();
58+
/// let i32_type = context.i32_type();
59+
/// let arg_types = [i32_type.into()];
60+
/// let fn_type = i32_type.fn_type(&arg_types, false);
61+
/// let fn_value = module.add_function("ret", fn_type, None);
62+
/// let entry = fn_value.append_basic_block("entry");
63+
/// let i32_arg = fn_value.get_first_param().unwrap();
64+
///
65+
/// builder.position_at_end(&entry);
66+
/// builder.build_return(Some(&i32_arg));
67+
/// ```
4868
pub fn build_return(&self, value: Option<&BasicValue>) -> InstructionValue {
4969
let value = unsafe {
5070
value.map_or_else(|| LLVMBuildRetVoid(self.builder), |value| LLVMBuildRet(self.builder, value.as_value_ref()))

0 commit comments

Comments
 (0)