@@ -2,6 +2,7 @@ use llvm_sys::prelude::LLVMTypeRef;
2
2
3
3
use std:: fmt:: Debug ;
4
4
5
+ use crate :: AddressSpace ;
5
6
use crate :: types:: { IntType , FunctionType , FloatType , PointerType , StructType , ArrayType , VectorType , VoidType , Type } ;
6
7
use crate :: types:: enums:: { AnyTypeEnum , BasicTypeEnum } ;
7
8
use crate :: values:: { IntMathValue , FloatMathValue , PointerMathValue , IntValue , FloatValue , PointerValue , VectorValue } ;
@@ -37,10 +38,55 @@ pub trait BasicType: AnyType {
37
38
BasicTypeEnum :: new ( self . as_type_ref ( ) )
38
39
}
39
40
40
- /// Create a function type from this `BasicType`.
41
+ /// Create a `FunctionType` with this `BasicType` as its return type.
42
+ ///
43
+ /// Example:
44
+ /// ```
45
+ /// use inkwell::context::Context;
46
+ /// use inkwell::types::BasicType;
47
+ ///
48
+ /// let context = Context::create();
49
+ /// let int = context.i32_type();
50
+ /// let int_basic_type = int.as_basic_type_enum();
51
+ /// assert_eq!(int_basic_type.fn_type(&[], false), int.fn_type(&[], false));
52
+ /// ```
41
53
fn fn_type ( & self , param_types : & [ BasicTypeEnum ] , is_var_args : bool ) -> FunctionType {
42
54
Type :: new ( self . as_type_ref ( ) ) . fn_type ( param_types, is_var_args)
43
55
}
56
+
57
+ /// Create an `ArrayType` with this `BasicType` as its elements.
58
+ ///
59
+ /// Example:
60
+ /// ```
61
+ /// use inkwell::context::Context;
62
+ /// use inkwell::types::BasicType;
63
+ ///
64
+ /// let context = Context::create();
65
+ /// let int = context.i32_type();
66
+ /// let int_basic_type = int.as_basic_type_enum();
67
+ /// assert_eq!(int_basic_type.array_type(32), int.array_type(32));
68
+ /// ```
69
+ fn array_type ( & self , size : u32 ) -> ArrayType {
70
+ Type :: new ( self . as_type_ref ( ) ) . array_type ( size)
71
+ }
72
+
73
+ /// Create a `PointerType` that points to this `BasicType`.
74
+ ///
75
+ /// Example:
76
+ /// ```
77
+ /// use inkwell::context::Context;
78
+ /// use inkwell::types::BasicType;
79
+ /// use inkwell::AddressSpace;
80
+ ///
81
+ /// let context = Context::create();
82
+ /// let int = context.i32_type();
83
+ /// let int_basic_type = int.as_basic_type_enum();
84
+ /// let addr_space = AddressSpace::Generic;
85
+ /// assert_eq!(int_basic_type.ptr_type(addr_space), int.ptr_type(addr_space));
86
+ /// ```
87
+ fn ptr_type ( & self , address_space : AddressSpace ) -> PointerType {
88
+ Type :: new ( self . as_type_ref ( ) ) . ptr_type ( address_space)
89
+ }
44
90
}
45
91
46
92
/// Represents an LLVM type that can have integer math operations applied to it.
0 commit comments