Skip to content

Commit d909250

Browse files
committed
Doc tests for IntType.const_int, .const_all_ones, and .const_null_ptr
1 parent af51e5f commit d909250

File tree

1 file changed

+56
-7
lines changed

1 file changed

+56
-7
lines changed

src/types/int_type.rs

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl IntType {
2323
}
2424
}
2525

26-
/// Gets the `IntType` representing 1 bit width. Will be automatically assigned the global context.
26+
/// Gets the `IntType` representing 1 bit width. It will be automatically assigned the global context.
2727
///
2828
/// To use your own `Context`, see [inkwell::context::bool_type()](../context/struct.Context.html#method.bool_type)
2929
///
@@ -45,7 +45,7 @@ impl IntType {
4545
IntType::new(type_)
4646
}
4747

48-
/// Gets the `IntType` representing 8 bit width. Will be automatically assigned the global context.
48+
/// Gets the `IntType` representing 8 bit width. It will be automatically assigned the global context.
4949
///
5050
/// To use your own `Context`, see [inkwell::context::i8_type()](../context/struct.Context.html#method.i8_type)
5151
///
@@ -67,7 +67,7 @@ impl IntType {
6767
IntType::new(type_)
6868
}
6969

70-
/// Gets the `IntType` representing 16 bit width. Will be automatically assigned the global context.
70+
/// Gets the `IntType` representing 16 bit width. It will be automatically assigned the global context.
7171
///
7272
/// To use your own `Context`, see [inkwell::context::i16_type()](../context/struct.Context.html#method.i16_type)
7373
///
@@ -89,7 +89,7 @@ impl IntType {
8989
IntType::new(type_)
9090
}
9191

92-
/// Gets the `IntType` representing 32 bit width. Will be automatically assigned the global context.
92+
/// Gets the `IntType` representing 32 bit width. It will be automatically assigned the global context.
9393
///
9494
/// To use your own `Context`, see [inkwell::context::i32_type()](../context/struct.Context.html#method.i32_type)
9595
///
@@ -111,7 +111,7 @@ impl IntType {
111111
IntType::new(type_)
112112
}
113113

114-
/// Gets the `IntType` representing 64 bit width. Will be automatically assigned the global context.
114+
/// Gets the `IntType` representing 64 bit width. It will be automatically assigned the global context.
115115
///
116116
/// To use your own `Context`, see [inkwell::context::i64_type()](../context/struct.Context.html#method.i64_type)
117117
///
@@ -133,7 +133,7 @@ impl IntType {
133133
IntType::new(type_)
134134
}
135135

136-
/// Gets the `IntType` representing 128 bit width. Will be automatically assigned the global context.
136+
/// Gets the `IntType` representing 128 bit width. It will be automatically assigned the global context.
137137
///
138138
/// To use your own `Context`, see [inkwell::context::i128_type()](../context/struct.Context.html#method.i128_type)
139139
///
@@ -154,7 +154,7 @@ impl IntType {
154154
Self::custom_width_int_type(128)
155155
}
156156

157-
/// Gets the `IntType` representing a custom bit width. Will be automatically assigned the global context.
157+
/// Gets the `IntType` representing a custom bit width. It will be automatically assigned the global context.
158158
///
159159
/// To use your own `Context`, see [inkwell::context::custom_width_int_type()](../context/struct.Context.html#method.custom_width_int_type)
160160
///
@@ -176,6 +176,23 @@ impl IntType {
176176
IntType::new(type_)
177177
}
178178

179+
/// Creates an `IntValue` repesenting a constant value of this `IntType`. It will be automatically assigned this `IntType`'s `Context`.
180+
///
181+
/// # Example
182+
/// ```
183+
/// use inkwell::context::Context;
184+
/// use inkwell::types::IntType;
185+
///
186+
/// // Global Context
187+
/// let i32_type = IntType::i32_type();
188+
/// let i32_value = i32_type.const_int(42, false);
189+
///
190+
/// // Custom Context
191+
/// let context = Context::create();
192+
/// let i32_type = context.i32_type();
193+
/// let i32_value = i32_type.const_int(42, false);
194+
/// ```
195+
// TODOC: Maybe better explain sign extension
179196
pub fn const_int(&self, value: u64, sign_extend: bool) -> IntValue {
180197
let value = unsafe {
181198
LLVMConstInt(self.as_type_ref(), value, sign_extend as i32)
@@ -196,6 +213,22 @@ impl IntType {
196213
IntValue::new(value)
197214
}
198215

216+
/// Creates an `IntValue` representing a constant value of all one bits of this `IntType`. It will be automatically assigned this `IntType`'s `Context`.
217+
///
218+
/// # Example
219+
/// ```
220+
/// use inkwell::context::Context;
221+
/// use inkwell::types::IntType;
222+
///
223+
/// // Global Context
224+
/// let i32_type = IntType::i32_type();
225+
/// let i32_ptr_value = i32_type.const_all_ones();
226+
///
227+
/// // Custom Context
228+
/// let context = Context::create();
229+
/// let i32_type = context.i32_type();
230+
/// let i32_ptr_value = i32_type.const_all_ones();
231+
/// ```
199232
pub fn const_all_ones(&self) -> IntValue {
200233
let value = unsafe {
201234
LLVMConstAllOnes(self.as_type_ref())
@@ -204,6 +237,22 @@ impl IntType {
204237
IntValue::new(value)
205238
}
206239

240+
/// Creates a `PointerValue` representing a constant value of zero (null pointer) pointing to this `IntType`. It will be automatically assigned this `IntType`'s `Context`.
241+
///
242+
/// # Example
243+
/// ```
244+
/// use inkwell::context::Context;
245+
/// use inkwell::types::IntType;
246+
///
247+
/// // Global Context
248+
/// let i32_type = IntType::i32_type();
249+
/// let i32_value = i32_type.const_null_ptr();
250+
///
251+
/// // Custom Context
252+
/// let context = Context::create();
253+
/// let i32_type = context.i32_type();
254+
/// let i32_value = i32_type.const_null_ptr();
255+
/// ```
207256
pub fn const_null_ptr(&self) -> PointerValue {
208257
self.int_type.const_null_ptr()
209258
}

0 commit comments

Comments
 (0)