Skip to content

Commit e120316

Browse files
committed
Added documentation for Int & Float types
1 parent 24a3a42 commit e120316

File tree

3 files changed

+219
-8
lines changed

3 files changed

+219
-8
lines changed

src/context.rs

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,18 @@ impl Context {
133133
VoidType::new(void_type)
134134
}
135135

136+
/// Gets the `IntType` representing 1 bit width. It will be assigned the current context.
137+
///
138+
/// # Example
139+
/// ```no_run
140+
/// use inkwell::context::Context;
141+
///
142+
/// let context = Context::create();
143+
/// let bool_type = context.bool_type();
144+
///
145+
/// assert_eq!(bool_type.get_bit_width(), 1);
146+
/// assert_eq!(*bool_type.get_context(), context);
147+
/// ```
136148
pub fn bool_type(&self) -> IntType {
137149
let bool_type = unsafe {
138150
LLVMInt1TypeInContext(*self.context)
@@ -141,6 +153,18 @@ impl Context {
141153
IntType::new(bool_type)
142154
}
143155

156+
/// Gets the `IntType` representing 8 bit width. It will be assigned the current context.
157+
///
158+
/// # Example
159+
/// ```no_run
160+
/// use inkwell::context::Context;
161+
///
162+
/// let context = Context::create();
163+
/// let i8_type = context.i8_type();
164+
///
165+
/// assert_eq!(i8_type.get_bit_width(), 8);
166+
/// assert_eq!(*i8_type.get_context(), context);
167+
/// ```
144168
pub fn i8_type(&self) -> IntType {
145169
let i8_type = unsafe {
146170
LLVMInt8TypeInContext(*self.context)
@@ -149,6 +173,18 @@ impl Context {
149173
IntType::new(i8_type)
150174
}
151175

176+
/// Gets the `IntType` representing 16 bit width. It will be assigned the current context.
177+
///
178+
/// # Example
179+
/// ```no_run
180+
/// use inkwell::context::Context;
181+
///
182+
/// let context = Context::create();
183+
/// let i16_type = context.i16_type();
184+
///
185+
/// assert_eq!(i16_type.get_bit_width(), 16);
186+
/// assert_eq!(*i16_type.get_context(), context);
187+
/// ```
152188
pub fn i16_type(&self) -> IntType {
153189
let i16_type = unsafe {
154190
LLVMInt16TypeInContext(*self.context)
@@ -157,6 +193,18 @@ impl Context {
157193
IntType::new(i16_type)
158194
}
159195

196+
/// Gets the `IntType` representing 32 bit width. It will be assigned the current context.
197+
///
198+
/// # Example
199+
/// ```no_run
200+
/// use inkwell::context::Context;
201+
///
202+
/// let context = Context::create();
203+
/// let i32_type = context.i32_type();
204+
///
205+
/// assert_eq!(i32_type.get_bit_width(), 32);
206+
/// assert_eq!(*i32_type.get_context(), context);
207+
/// ```
160208
pub fn i32_type(&self) -> IntType {
161209
let i32_type = unsafe {
162210
LLVMInt32TypeInContext(*self.context)
@@ -165,6 +213,18 @@ impl Context {
165213
IntType::new(i32_type)
166214
}
167215

216+
/// Gets the `IntType` representing 64 bit width. It will be assigned the current context.
217+
///
218+
/// # Example
219+
/// ```no_run
220+
/// use inkwell::context::Context;
221+
///
222+
/// let context = Context::create();
223+
/// let i64_type = context.i64_type();
224+
///
225+
/// assert_eq!(i64_type.get_bit_width(), 64);
226+
/// assert_eq!(*i64_type.get_context(), context);
227+
/// ```
168228
pub fn i64_type(&self) -> IntType {
169229
let i64_type = unsafe {
170230
LLVMInt64TypeInContext(*self.context)
@@ -173,13 +233,37 @@ impl Context {
173233
IntType::new(i64_type)
174234
}
175235

236+
/// Gets the `IntType` representing 128 bit width. It will be assigned the current context.
237+
///
238+
/// # Example
239+
/// ```no_run
240+
/// use inkwell::context::Context;
241+
///
242+
/// let context = Context::create();
243+
/// let i128_type = context.i128_type();
244+
///
245+
/// assert_eq!(i128_type.get_bit_width(), 128);
246+
/// assert_eq!(*i128_type.get_context(), context);
247+
/// ```
176248
pub fn i128_type(&self) -> IntType {
177249
// REVIEW: The docs says there's a LLVMInt128TypeInContext, but
178250
// it might only be in a newer version
179251

180252
self.custom_width_int_type(128)
181253
}
182254

255+
/// Gets the `IntType` representing a custom bit width. It will be assigned the current context.
256+
///
257+
/// # Example
258+
/// ```no_run
259+
/// use inkwell::context::Context;
260+
///
261+
/// let context = Context::create();
262+
/// let i42_type = context.custom_width_int_type(42);
263+
///
264+
/// assert_eq!(i42_type.get_bit_width(), 42);
265+
/// assert_eq!(*i42_type.get_context(), context);
266+
/// ```
183267
pub fn custom_width_int_type(&self, bits: u32) -> IntType {
184268
let int_type = unsafe {
185269
LLVMIntTypeInContext(*self.context, bits)
@@ -188,6 +272,19 @@ impl Context {
188272
IntType::new(int_type)
189273
}
190274

275+
/// Gets the `FloatType` representing a 16 bit width. It will be assigned the current context.
276+
///
277+
/// # Example
278+
///
279+
/// ```no_run
280+
/// use inkwell::context::Context;
281+
///
282+
/// let context = Context::create();
283+
///
284+
/// let f16_type = context.f16_type();
285+
///
286+
/// assert_eq!(*f16_type.get_context(), context);
287+
/// ```
191288
pub fn f16_type(&self) -> FloatType {
192289
let f16_type = unsafe {
193290
LLVMHalfTypeInContext(*self.context)
@@ -196,6 +293,19 @@ impl Context {
196293
FloatType::new(f16_type)
197294
}
198295

296+
/// Gets the `FloatType` representing a 32 bit width. It will be assigned the current context.
297+
///
298+
/// # Example
299+
///
300+
/// ```no_run
301+
/// use inkwell::context::Context;
302+
///
303+
/// let context = Context::create();
304+
///
305+
/// let f32_type = context.f32_type();
306+
///
307+
/// assert_eq!(*f32_type.get_context(), context);
308+
/// ```
199309
pub fn f32_type(&self) -> FloatType {
200310
let f32_type = unsafe {
201311
LLVMFloatTypeInContext(*self.context)
@@ -204,6 +314,19 @@ impl Context {
204314
FloatType::new(f32_type)
205315
}
206316

317+
/// Gets the `FloatType` representing a 64 bit width. It will be assigned the current context.
318+
///
319+
/// # Example
320+
///
321+
/// ```no_run
322+
/// use inkwell::context::Context;
323+
///
324+
/// let context = Context::create();
325+
///
326+
/// let f64_type = context.f64_type();
327+
///
328+
/// assert_eq!(*f64_type.get_context(), context);
329+
/// ```
207330
pub fn f64_type(&self) -> FloatType {
208331
let f64_type = unsafe {
209332
LLVMDoubleTypeInContext(*self.context)
@@ -212,6 +335,19 @@ impl Context {
212335
FloatType::new(f64_type)
213336
}
214337

338+
/// Gets the `FloatType` representing a 128 bit width. It will be assigned the current context.
339+
///
340+
/// # Example
341+
///
342+
/// ```no_run
343+
/// use inkwell::context::Context;
344+
///
345+
/// let context = Context::create();
346+
///
347+
/// let f128_type = context.f128_type();
348+
///
349+
/// assert_eq!(*f128_type.get_context(), context);
350+
/// ```
215351
pub fn f128_type(&self) -> FloatType {
216352
let f128_type = unsafe {
217353
LLVMFP128TypeInContext(*self.context)
@@ -220,6 +356,21 @@ impl Context {
220356
FloatType::new(f128_type)
221357
}
222358

359+
/// Gets the `FloatType` representing a 128 bit width. It will be assigned the current context.
360+
///
361+
/// PPC is two 64 bits side by side rather than one single 128 bit float.
362+
///
363+
/// # Example
364+
///
365+
/// ```no_run
366+
/// use inkwell::context::Context;
367+
///
368+
/// let context = Context::create();
369+
///
370+
/// let f128_type = context.ppc_f128_type();
371+
///
372+
/// assert_eq!(*f128_type.get_context(), context);
373+
/// ```
223374
pub fn ppc_f128_type(&self) -> FloatType {
224375
let f128_type = unsafe {
225376
LLVMPPCFP128TypeInContext(*self.context)

src/types/float_type.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,18 @@ impl FloatType {
8181
self.float_type.ptr_type(address_space)
8282
}
8383

84+
/// Creates a new `FloatType` which represents sixteen bits (two bytes) for the global context.
85+
///
86+
/// # Example
87+
///
88+
/// ```no_run
89+
/// use inkwell::context::Context;
90+
/// use inkwell::types::FloatType;
91+
///
92+
/// let f16_type = FloatType::f16_type();
93+
///
94+
/// assert_eq!(f16_type.get_context(), Context::get_global());
95+
/// ```
8496
pub fn f16_type() -> Self {
8597
let float_type = unsafe {
8698
LLVMHalfType()
@@ -89,6 +101,18 @@ impl FloatType {
89101
FloatType::new(float_type)
90102
}
91103

104+
/// Creates a new `FloatType` which represents thirty two bits (four bytes) for the global context.
105+
///
106+
/// # Example
107+
///
108+
/// ```no_run
109+
/// use inkwell::context::Context;
110+
/// use inkwell::types::FloatType;
111+
///
112+
/// let f32_type = FloatType::f32_type();
113+
///
114+
/// assert_eq!(f32_type.get_context(), Context::get_global());
115+
/// ```
92116
pub fn f32_type() -> Self {
93117
let float_type = unsafe {
94118
LLVMFloatType()
@@ -97,6 +121,18 @@ impl FloatType {
97121
FloatType::new(float_type)
98122
}
99123

124+
/// Creates a new `FloatType` which represents sixty four bits (eight bytes) for the global context.
125+
///
126+
/// # Example
127+
///
128+
/// ```no_run
129+
/// use inkwell::context::Context;
130+
/// use inkwell::types::FloatType;
131+
///
132+
/// let f64_type = FloatType::f64_type();
133+
///
134+
/// assert_eq!(f64_type.get_context(), Context::get_global());
135+
/// ```
100136
pub fn f64_type() -> Self {
101137
let float_type = unsafe {
102138
LLVMDoubleType()
@@ -105,6 +141,18 @@ impl FloatType {
105141
FloatType::new(float_type)
106142
}
107143

144+
/// Creates a new `FloatType` which represents one hundred and twenty eight bits (sixteen bytes) for the global context.
145+
///
146+
/// # Example
147+
///
148+
/// ```no_run
149+
/// use inkwell::context::Context;
150+
/// use inkwell::types::FloatType;
151+
///
152+
/// let f128_type = FloatType::f128_type();
153+
///
154+
/// assert_eq!(f128_type.get_context(), Context::get_global());
155+
/// ```
108156
// IEEE 754-2008’s binary128 floats according to https://internals.rust-lang.org/t/pre-rfc-introduction-of-half-and-quadruple-precision-floats-f16-and-f128/7521
109157
pub fn f128_type() -> Self {
110158
let float_type = unsafe {
@@ -114,6 +162,18 @@ impl FloatType {
114162
FloatType::new(float_type)
115163
}
116164

165+
/// Creates a new `FloatType` which represents one hundred and twenty eight bits (sixteen bytes) for the current context. PPC is two 64 bits side by side rather than one single 128 bit float.
166+
///
167+
/// # Example
168+
///
169+
/// ```no_run
170+
/// use inkwell::context::Context;
171+
/// use inkwell::types::FloatType;
172+
///
173+
/// let f128_type = FloatType::ppc_f128_type();
174+
///
175+
/// assert_eq!(f128_type.get_context(), Context::get_global());
176+
/// ```
117177
// Two 64 bits according to https://internals.rust-lang.org/t/pre-rfc-introduction-of-half-and-quadruple-precision-floats-f16-and-f128/7521
118178
pub fn ppc_f128_type() -> Self {
119179
let float_type = unsafe {

0 commit comments

Comments
 (0)