@@ -207,6 +207,24 @@ impl Module {
207
207
ContextRef :: new ( Context :: new ( context) )
208
208
}
209
209
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
+ /// ```
210
228
pub fn get_first_function ( & self ) -> Option < FunctionValue > {
211
229
let function = unsafe {
212
230
LLVMGetFirstFunction ( self . module )
@@ -215,6 +233,24 @@ impl Module {
215
233
FunctionValue :: new ( function)
216
234
}
217
235
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
+ /// ```
218
254
pub fn get_last_function ( & self ) -> Option < FunctionValue > {
219
255
let function = unsafe {
220
256
LLVMGetLastFunction ( self . module )
@@ -223,6 +259,24 @@ impl Module {
223
259
FunctionValue :: new ( function)
224
260
}
225
261
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
+ /// ```
226
280
pub fn get_function ( & self , name : & str ) -> Option < FunctionValue > {
227
281
let c_string = CString :: new ( name) . expect ( "Conversion to CString failed unexpectedly" ) ;
228
282
@@ -529,7 +583,7 @@ impl Module {
529
583
Some ( GlobalValue :: new ( value) )
530
584
}
531
585
532
- pub fn get_named_global ( & self , name : & str ) -> Option < GlobalValue > {
586
+ pub fn get_global ( & self , name : & str ) -> Option < GlobalValue > {
533
587
let c_string = CString :: new ( name) . expect ( "Conversion to CString failed unexpectedly" ) ;
534
588
let value = unsafe {
535
589
LLVMGetNamedGlobal ( self . module , c_string. as_ptr ( ) )
0 commit comments