Skip to content

Commit 033571a

Browse files
committed
Adds docs for module. get_first/last/named_function
1 parent bc7be5f commit 033571a

File tree

1 file changed

+55
-1
lines changed

1 file changed

+55
-1
lines changed

src/module.rs

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,24 @@ impl Module {
207207
ContextRef::new(Context::new(context))
208208
}
209209

210+
/// Gets the first `FunctionValue` defined in this `Module`.
211+
///
212+
/// # Example
213+
/// ```rust
214+
/// use inkwell::context::Context;
215+
/// use inkwell::module::Module;
216+
///
217+
/// let context = Context::create();
218+
/// let module = context.create_module("my_mod");
219+
///
220+
/// assert!(module.get_first_function().is_none());
221+
///
222+
/// let void_type = context.void_type();
223+
/// let fn_type = void_type.fn_type(&[], false);
224+
/// let fn_value = module.add_function("my_fn", &fn_type, None);
225+
///
226+
/// assert_eq!(fn_value, module.get_first_function().unwrap());
227+
/// ```
210228
pub fn get_first_function(&self) -> Option<FunctionValue> {
211229
let function = unsafe {
212230
LLVMGetFirstFunction(self.module)
@@ -215,6 +233,24 @@ impl Module {
215233
FunctionValue::new(function)
216234
}
217235

236+
/// Gets the last `FunctionValue` defined in this `Module`.
237+
///
238+
/// # Example
239+
/// ```rust
240+
/// use inkwell::context::Context;
241+
/// use inkwell::module::Module;
242+
///
243+
/// let context = Context::create();
244+
/// let module = context.create_module("my_mod");
245+
///
246+
/// assert!(module.get_last_function().is_none());
247+
///
248+
/// let void_type = context.void_type();
249+
/// let fn_type = void_type.fn_type(&[], false);
250+
/// let fn_value = module.add_function("my_fn", &fn_type, None);
251+
///
252+
/// assert_eq!(fn_value, module.get_last_function().unwrap());
253+
/// ```
218254
pub fn get_last_function(&self) -> Option<FunctionValue> {
219255
let function = unsafe {
220256
LLVMGetLastFunction(self.module)
@@ -223,6 +259,24 @@ impl Module {
223259
FunctionValue::new(function)
224260
}
225261

262+
/// Gets a `FunctionValue` defined in this `Module` by its name.
263+
///
264+
/// # Example
265+
/// ```rust
266+
/// use inkwell::context::Context;
267+
/// use inkwell::module::Module;
268+
///
269+
/// let context = Context::create();
270+
/// let module = context.create_module("my_mod");
271+
///
272+
/// assert!(module.get_function("my_fn").is_none());
273+
///
274+
/// let void_type = context.void_type();
275+
/// let fn_type = void_type.fn_type(&[], false);
276+
/// let fn_value = module.add_function("my_fn", &fn_type, None);
277+
///
278+
/// assert_eq!(fn_value, module.get_function("my_fn").unwrap());
279+
/// ```
226280
pub fn get_function(&self, name: &str) -> Option<FunctionValue> {
227281
let c_string = CString::new(name).expect("Conversion to CString failed unexpectedly");
228282

@@ -529,7 +583,7 @@ impl Module {
529583
Some(GlobalValue::new(value))
530584
}
531585

532-
pub fn get_named_global(&self, name: &str) -> Option<GlobalValue> {
586+
pub fn get_global(&self, name: &str) -> Option<GlobalValue> {
533587
let c_string = CString::new(name).expect("Conversion to CString failed unexpectedly");
534588
let value = unsafe {
535589
LLVMGetNamedGlobal(self.module, c_string.as_ptr())

0 commit comments

Comments
 (0)