llvm_wrap/
builder.rs

1//! A wrapper around a `LLVMBuilderRef` for a specific context
2
3use super::*;
4use super::types::*;
5use super::c_api::*;
6
7/// A wrapper around a `LLVMBuilderRef` for a specific context
8pub struct Builder {
9    pub(crate) builder: Option<LLVMBuilderRef>,
10}
11
12impl Builder {
13    /// Build a stack allocation
14    pub fn build_alloca(&self, ty: Type) -> Value {
15        Value {
16            value: unsafe {
17                LLVMBuildAlloca(self.builder.unwrap(), ty.ty, into_c("").as_ptr())
18            }
19        }
20    }
21
22    /// Build a heap allocation
23    pub fn build_malloc(&self, ty: Type) -> Value {
24        Value {
25            value: unsafe {
26                LLVMBuildMalloc(self.builder.unwrap(), ty.ty, into_c("").as_ptr())
27            }
28        }
29    }
30
31    /// Build a stack allocation for an array
32    pub fn build_array_alloca(&self, ty: Type, count: u32) -> Value {
33        Value {
34            value: unsafe {
35                LLVMBuildArrayAlloca(self.builder.unwrap(), ty.ty, ty_i32().const_int(count as u64).value, into_c("").as_ptr())
36            }
37        }
38    }
39
40    /// Build a heap allocation for an array
41    pub fn build_array_malloc(&self, ty: Type, count: u32) -> Value {
42        Value {
43            value: unsafe {
44                LLVMBuildArrayMalloc(self.builder.unwrap(), ty.ty, ty_i32().const_int(count as u64).value, into_c("").as_ptr())
45            }
46        }
47    }
48
49    /// Build a heap free
50    pub fn build_free(&self, ptr: Value) -> Value {
51        Value {
52            value: unsafe {
53                LLVMBuildFree(self.builder.unwrap(), ptr.value)
54            }
55        }
56    }
57
58    /// Build a call to a function
59    pub fn build_call(&self, func: Value, args: Vec<Value>) -> Value {
60        Value {
61            value: unsafe {
62                LLVMBuildCall(self.builder.unwrap(), func.value, val_vec(&args).as_mut_ptr(), args.len() as u32, into_c("").as_ptr())
63            }
64        }
65    }
66
67    /// Build a struct initialization for the given type and elements
68    pub fn build_struct_init(&self, ty: Type, elements: Vec<Value>) -> Value {
69        let mut init_elems = Vec::new();
70        let mut append_elems = Vec::new();
71        for (index, element) in elements.into_iter().enumerate() {
72            if element.is_constant() {
73                init_elems.push(element);
74            } else {
75                init_elems.push(element.ty().undef());
76                append_elems.push((index, element));
77            }
78        }
79        let mut agg = ty.const_struct(init_elems);
80        for (index, element) in append_elems.into_iter() {
81            agg = self.build_insert_value(agg, element, index as u32).name(format!("insert_{}", index));
82        }
83        agg
84    }
85
86    /// Build a struct initialization that stores it into memory with `alloca`
87    pub fn build_struct_alloca_init(&self, ty: Type, elements: Vec<Value>) -> Value {
88        let ptr = self.build_alloca(ty);
89        for (index, element) in elements.into_iter().enumerate() {
90            let elem_ptr = self.build_struct_gep(ptr, index as u32).name(format!("init_{}", index));
91            self.build_store(element, elem_ptr);
92        }
93        ptr
94    }
95
96    /// Build a struct initialization that stores it into memory with `malloc`
97    pub fn build_struct_malloc_init(&self, ty: Type, elements: Vec<Value>) -> Value {
98        let ptr = self.build_malloc(ty);
99        for (index, element) in elements.into_iter().enumerate() {
100            let elem_ptr = self.build_struct_gep(ptr, index as u32).name(format!("init_{}", index));
101            self.build_store(element, elem_ptr);
102        }
103        ptr
104    }
105
106    /// Build an insert value instruction
107    pub fn build_insert_value(&self, agg: Value, elt: Value, index: u32) -> Value {
108        Value {
109            value: unsafe {
110                LLVMBuildInsertValue(self.builder.unwrap(), agg.value, elt.value, index, into_c("").as_ptr())
111            }
112        }
113    }
114
115    /// Build an extract value instruction
116    pub fn build_extract_value(&self, agg: Value, index: u32) -> Value {
117        Value {
118            value: unsafe {
119                LLVMBuildExtractValue(self.builder.unwrap(), agg.value, index, into_c("").as_ptr())
120            }
121        }
122    }
123
124    /// Build a get element pointer instruction
125    pub fn build_gep(&self, ptr: Value, indices: Vec<Value>) -> Value {
126        Value {
127            value: unsafe {
128                LLVMBuildGEP(self.builder.unwrap(), ptr.value,
129                             val_vec(&indices).as_mut_ptr(), indices.len() as u32, into_c("").as_ptr())
130            }
131        }
132    }
133
134    /// Build a struct get element pointer instruction
135    pub fn build_struct_gep(&self, ptr: Value, index: u32) -> Value {
136        Value {
137            value: unsafe {
138                LLVMBuildStructGEP(self.builder.unwrap(), ptr.value, index, into_c("").as_ptr())
139            }
140        }
141    }
142
143    /// Build an inbounds get element pointer instruction
144    pub fn build_inbounds_gep(&self, ptr: Value, indices: Vec<Value>) -> Value {
145        Value {
146            value: unsafe {
147                LLVMBuildGEP(self.builder.unwrap(), ptr.value,
148                             val_vec(&indices).as_mut_ptr(), indices.len() as u32, into_c("").as_ptr())
149            }
150        }
151    }
152
153    /// Build a global string with the given value
154    pub fn build_global_string<S>(&self, string: S) -> Value where S: AsRef<str> {
155        Value {
156            value: unsafe {
157                LLVMBuildGlobalString(self.builder.unwrap(), into_c(string).as_ptr(), into_c("").as_ptr())
158            }
159        }
160    }
161
162    /// Build a global string pointer with the given value
163    pub fn build_global_string_ptr<S>(&self, string: S) -> Value where S: AsRef<str> {
164        Value {
165            value: unsafe {
166                LLVMBuildGlobalStringPtr(self.builder.unwrap(), into_c(string).as_ptr(), into_c("").as_ptr())
167            }
168        }
169    }
170
171    /// Build a store instruction
172    pub fn build_store(&self, val: Value, ptr: Value) {
173        unsafe {
174            LLVMBuildStore(self.builder.unwrap(), val.value, ptr.value);
175        }
176    }
177
178    /// Build a load instruction
179    pub fn build_load(&self, ptr: Value) -> Value {
180        Value {
181            value: unsafe {
182                LLVMBuildLoad(self.builder.unwrap(), ptr.value, into_c("").as_ptr())
183            }
184        }
185    }
186
187    /// Alloca some memory for an array and then store values in it
188    pub fn build_array_alloca_store(&self, ty: Type, elements: Vec<Value>) -> Value {
189        let mut agg = ty_array(ty, elements.len() as u32).undef();
190        for (i, element) in elements.into_iter().enumerate() {
191            agg = self.build_insert_value(agg, element, i as u32).name(format!("insert_elem_{}", i));
192        }
193        self.build_pointer_cast(self.build_alloca_store(agg), ty.pointer())
194    }
195
196    /// Malloc some memory for an array and then store values in it
197    pub fn build_array_malloc_store(&self, ty: Type, elements: Vec<Value>) -> Value {
198        let mut agg = ty_array(ty, elements.len() as u32).undef();
199        for (i, element) in elements.into_iter().enumerate() {
200            agg = self.build_insert_value(agg, element, i as u32).name(format!("insert_elem_{}", i));
201        }
202        self.build_pointer_cast(self.build_malloc_store(agg), ty.pointer())
203    }
204
205    /// Alloca some memory and then store a value in it
206    pub fn build_alloca_store(&self, val: Value) -> Value {
207        let ptr = self.build_alloca(val.ty());
208        self.build_store(val, ptr);
209        ptr
210    }
211
212    /// Malloc some memory and then store a value in it
213    pub fn build_malloc_store(&self, val: Value) -> Value {
214        let ptr = self.build_malloc(val.ty());
215        self.build_store(val, ptr);
216        ptr
217    }
218
219    /// Load a value and then free the memory
220    pub fn build_load_free(&self, ptr: Value) -> Value {
221        let val = self.build_load(ptr);
222        self.build_free(ptr);
223        val
224    }
225
226    /// Build a cast from integer to pointer
227    pub fn build_int_to_ptr(&self, val: Value, ptr_ty: Type) -> Value {
228        Value {
229            value: unsafe {
230                LLVMBuildIntToPtr(self.builder.unwrap(), val.value, ptr_ty.ty, into_c("").as_ptr())
231            }
232        }
233    }
234
235    /// Build a cast from pointer to integer
236    pub fn build_ptr_to_int(&self, ptr: Value, val_ty: Type) -> Value {
237        Value {
238            value: unsafe {
239                LLVMBuildPtrToInt(self.builder.unwrap(), ptr.value, val_ty.ty, into_c("").as_ptr())
240            }
241        }
242    }
243
244    /// Build a pointer cast
245    pub fn build_pointer_cast(&self, ptr: Value, ty: Type) -> Value {
246        Value {
247            value: unsafe {
248                LLVMBuildPointerCast(self.builder.unwrap(), ptr.value, ty.ty, into_c("").as_ptr())
249            }
250        }
251    }
252
253    /// Build an integer cast
254    pub fn build_int_cast(&self, val: Value, ty: Type) -> Value {
255        Value {
256            value: unsafe {
257                LLVMBuildIntCast(self.builder.unwrap(), val.value, ty.ty, into_c("").as_ptr())
258            }
259        }
260    }
261
262    /// Build a bit cast
263    pub fn build_bit_cast(&self, val: Value, ty: Type) -> Value {
264        Value {
265            value: unsafe {
266                LLVMBuildBitCast(self.builder.unwrap(), val.value, ty.ty, into_c("").as_ptr())
267            }
268        }
269    }
270
271    /// Build a floating point cast
272    pub fn build_float_cast(&self, val: Value, ty: Type) -> Value {
273        Value {
274            value: unsafe {
275                LLVMBuildFPCast(self.builder.unwrap(), val.value, ty.ty, into_c("").as_ptr())
276            }
277        }
278    }
279
280    /// Build a `ret void` statement
281    pub fn build_ret_void(&self) -> Value {
282        Value {
283            value: unsafe {
284                LLVMBuildRetVoid(self.builder.unwrap())
285            }
286        }
287    }
288
289    /// Build a `ret` statement
290    pub fn build_ret(&self, val: Value) -> Value where {
291        Value {
292            value: unsafe {
293                LLVMBuildRet(self.builder.unwrap(), val.value)
294            }
295        }
296    }
297
298    /// Build an unreachable instruction
299    pub fn build_unreachable(&self) {
300        unsafe {
301            LLVMBuildUnreachable(self.builder.unwrap());
302        }
303    }
304
305    /// Build a branch instruction to the given block
306    pub fn build_br(&self, block: BasicBlock) {
307        unsafe {
308            LLVMBuildBr(self.builder.unwrap(), block.basic_block);
309        }
310    }
311
312    /// Build an if statement that branches to the given blocks
313    pub fn build_if(&self, condition: Value, then_block: BasicBlock, else_block: BasicBlock) {
314        unsafe {
315            LLVMBuildCondBr(self.builder.unwrap(), condition.value, then_block.basic_block, else_block.basic_block);
316        }
317    }
318
319    /// Build a switch statement that branches to the given blocks
320    pub fn build_switch(&self, val: Value, cases: Vec<(Value, BasicBlock)>, default: BasicBlock) {
321        unsafe {
322            let switch = LLVMBuildSwitch(self.builder.unwrap(), val.value, default.basic_block, cases.len() as u32);
323            for (val, bb) in cases {
324                LLVMAddCase(switch, val.value, bb.basic_block);
325            }
326        }
327    }
328
329    /// Build a phi instruction that takes ceratin values from certain blocks
330    pub fn build_phi(&self, incoming: Vec<(Value, BasicBlock)>) -> Value {
331        Value {
332            value: unsafe {
333                if incoming.is_empty() {
334                    panic!("phi node must have an incoming block list");
335                } else {
336                    let phi = LLVMBuildPhi(
337                        self.builder.unwrap(),
338                        incoming[0].0.ty().ty,
339                        into_c("").as_ptr()
340                    );
341                    let len = incoming.len();
342                    let mut values = Vec::new();
343                    let mut blocks = Vec::new();
344                    for (val, block) in incoming {
345                        values.push(val.value);
346                        blocks.push(block.basic_block);
347                    }
348                    LLVMAddIncoming(phi, values.as_mut_ptr(), blocks.as_mut_ptr(), len as u32);
349                    phi
350                }
351            }
352        }
353    }
354
355    /// Position the builder at a given value in a basic block
356    pub fn position_in_block(&self, bb: BasicBlock, val: Value) {
357        unsafe {
358            LLVMPositionBuilder(self.builder.unwrap(), bb.basic_block, val.value);
359        }
360    }
361
362    /// Position the builder at the end of the basic block
363    pub fn position_at_end(&self, bb: BasicBlock) {
364        unsafe {
365            LLVMPositionBuilderAtEnd(self.builder.unwrap(), bb.basic_block);
366        }
367    }
368
369    /// Position the builder before a value
370    pub fn position_before(&self, val: Value) {
371        unsafe {
372            LLVMPositionBuilderBefore(self.builder.unwrap(), val.value);
373        }
374    }
375
376    /// Returns the internal builder reference
377    pub fn inner(&self) -> LLVMBuilderRef {
378        self.builder.unwrap()
379    }
380
381    /// Destroys the wrapper, returning the internal builder reference
382    pub unsafe fn into_inner(mut self) -> LLVMBuilderRef {
383        self.builder.take().unwrap()
384    }
385
386    /// Builds a null check
387    pub fn build_is_null(&self, val: Value) -> Value {
388        Value {
389            value: unsafe {
390                LLVMBuildIsNull(self.builder.unwrap(), val.value, into_c("").as_ptr())
391            }
392        }
393    }
394
395    /// Builds a null check
396    pub fn build_is_not_null(&self, val: Value) -> Value {
397        Value {
398            value: unsafe {
399                LLVMBuildIsNotNull(self.builder.unwrap(), val.value, into_c("").as_ptr())
400            }
401        }
402    }
403
404    /// Builds an integer `add` instruction
405    pub fn build_int_add(&self, a: Value, b: Value) -> Value {
406        Value {
407            value: unsafe {
408                LLVMBuildAdd(self.builder.unwrap(), a.value, b.value, into_c("").as_ptr())
409            }
410        }
411    }
412
413    /// Builds an integer `sub` instruction
414    pub fn build_int_sub(&self, a: Value, b: Value) -> Value {
415        Value {
416            value: unsafe {
417                LLVMBuildSub(self.builder.unwrap(), a.value, b.value, into_c("").as_ptr())
418            }
419        }
420    }
421
422    /// Builds an integer `mul` instruction
423    pub fn build_int_mul(&self, a: Value, b: Value) -> Value {
424        Value {
425            value: unsafe {
426                LLVMBuildMul(self.builder.unwrap(), a.value, b.value, into_c("").as_ptr())
427            }
428        }
429    }
430
431    /// Builds an integer `udiv` instruction
432    pub fn build_int_udiv(&self, a: Value, b: Value) -> Value {
433        Value {
434            value: unsafe {
435                LLVMBuildUDiv(self.builder.unwrap(), a.value, b.value, into_c("").as_ptr())
436            }
437        }
438    }
439
440    /// Builds an integer `sdiv` instruction
441    pub fn build_int_sdiv(&self, a: Value, b: Value) -> Value {
442        Value {
443            value: unsafe {
444                LLVMBuildSDiv(self.builder.unwrap(), a.value, b.value, into_c("").as_ptr())
445            }
446        }
447    }
448
449    /// Builds an integer `urem` instruction
450    pub fn build_int_urem(&self, a: Value, b: Value) -> Value {
451        Value {
452            value: unsafe {
453                LLVMBuildSRem(self.builder.unwrap(), a.value, b.value, into_c("").as_ptr())
454            }
455        }
456    }
457
458    /// Builds an integer `srem` instruction
459    pub fn build_int_srem(&self, a: Value, b: Value) -> Value {
460        Value {
461            value: unsafe {
462                LLVMBuildSRem(self.builder.unwrap(), a.value, b.value, into_c("").as_ptr())
463            }
464        }
465    }
466
467    /// Builds a `shl` instruction
468    pub fn build_shl(&self, a: Value, b: Value) -> Value {
469        Value {
470            value: unsafe {
471                LLVMBuildShl(self.builder.unwrap(), a.value, b.value, into_c("").as_ptr())
472            }
473        }
474    }
475
476    /// Builds a `lshr` instruction
477    pub fn build_lshr(&self, a: Value, b: Value) -> Value {
478        Value {
479            value: unsafe {
480                LLVMBuildLShr(self.builder.unwrap(), a.value, b.value, into_c("").as_ptr())
481            }
482        }
483    }
484
485    /// Builds an `ashr` instruction
486    pub fn build_ashr(&self, a: Value, b: Value) -> Value {
487        Value {
488            value: unsafe {
489                LLVMBuildAShr(self.builder.unwrap(), a.value, b.value, into_c("").as_ptr())
490            }
491        }
492    }
493
494    /// Builds an `and` instruction
495    pub fn build_and(&self, a: Value, b: Value) -> Value {
496        Value {
497            value: unsafe {
498                LLVMBuildAnd(self.builder.unwrap(), a.value, b.value, into_c("").as_ptr())
499            }
500        }
501    }
502
503    /// Builds an `or` instruction
504    pub fn build_or(&self, a: Value, b: Value) -> Value {
505        Value {
506            value: unsafe {
507                LLVMBuildOr(self.builder.unwrap(), a.value, b.value, into_c("").as_ptr())
508            }
509        }
510    }
511
512    /// Builds an `xor` instruction
513    pub fn build_xor(&self, a: Value, b: Value) -> Value {
514        Value {
515            value: unsafe {
516                LLVMBuildXor(self.builder.unwrap(), a.value, b.value, into_c("").as_ptr())
517            }
518        }
519    }
520
521    /// Builds an integer `eq` check
522    pub fn build_int_eq(&self, a: Value, b: Value) -> Value {
523        Value {
524            value: unsafe {
525                LLVMBuildICmp(self.builder.unwrap(), LLVMIntPredicate::LLVMIntEQ, a.value, b.value, into_c("").as_ptr())
526            }
527        }
528    }
529
530    /// Builds an integer `ne` check
531    pub fn build_int_ne(&self, a: Value, b: Value) -> Value {
532        Value {
533            value: unsafe {
534                LLVMBuildICmp(self.builder.unwrap(), LLVMIntPredicate::LLVMIntNE, a.value, b.value, into_c("").as_ptr())
535            }
536        }
537    }
538
539    /// Builds an integer `ule` check
540    pub fn build_int_ule(&self, a: Value, b: Value) -> Value {
541        Value {
542            value: unsafe {
543                LLVMBuildICmp(self.builder.unwrap(), LLVMIntPredicate::LLVMIntULE, a.value, b.value, into_c("").as_ptr())
544            }
545        }
546    }
547
548    /// Builds an integer `ult` check
549    pub fn build_int_ult(&self, a: Value, b: Value) -> Value {
550        Value {
551            value: unsafe {
552                LLVMBuildICmp(self.builder.unwrap(), LLVMIntPredicate::LLVMIntULT, a.value, b.value, into_c("").as_ptr())
553            }
554        }
555    }
556
557    /// Builds an integer `uge` check
558    pub fn build_int_uge(&self, a: Value, b: Value) -> Value {
559        Value {
560            value: unsafe {
561                LLVMBuildICmp(self.builder.unwrap(), LLVMIntPredicate::LLVMIntUGE, a.value, b.value, into_c("").as_ptr())
562            }
563        }
564    }
565
566    /// Builds an integer `ugt` check
567    pub fn build_int_ugt(&self, a: Value, b: Value) -> Value {
568        Value {
569            value: unsafe {
570                LLVMBuildICmp(self.builder.unwrap(), LLVMIntPredicate::LLVMIntUGT, a.value, b.value, into_c("").as_ptr())
571            }
572        }
573    }
574
575    /// Builds an integer `sle` check
576    pub fn build_int_sle(&self, a: Value, b: Value) -> Value {
577        Value {
578            value: unsafe {
579                LLVMBuildICmp(self.builder.unwrap(), LLVMIntPredicate::LLVMIntSLE, a.value, b.value, into_c("").as_ptr())
580            }
581        }
582    }
583
584    /// Builds an integer `slt` check
585    pub fn build_int_slt(&self, a: Value, b: Value) -> Value {
586        Value {
587            value: unsafe {
588                LLVMBuildICmp(self.builder.unwrap(), LLVMIntPredicate::LLVMIntSLT, a.value, b.value, into_c("").as_ptr())
589            }
590        }
591    }
592
593    /// Builds an integer `sge` check
594    pub fn build_int_sge(&self, a: Value, b: Value) -> Value {
595        Value {
596            value: unsafe {
597                LLVMBuildICmp(self.builder.unwrap(), LLVMIntPredicate::LLVMIntSGE, a.value, b.value, into_c("").as_ptr())
598            }
599        }
600    }
601
602    /// Builds an integer `sgt` check
603    pub fn build_int_sgt(&self, a: Value, b: Value) -> Value {
604        Value {
605            value: unsafe {
606                LLVMBuildICmp(self.builder.unwrap(), LLVMIntPredicate::LLVMIntSGT, a.value, b.value, into_c("").as_ptr())
607            }
608        }
609    }
610
611    /// Builds a float `add` instruction
612    pub fn build_float_add(&self, a: Value, b: Value) -> Value {
613        Value {
614            value: unsafe {
615                LLVMBuildFAdd(self.builder.unwrap(), a.value, b.value, into_c("").as_ptr())
616            }
617        }
618    }
619
620    /// Builds a float `sub` instruction
621    pub fn build_float_sub(&self, a: Value, b: Value) -> Value {
622        Value {
623            value: unsafe {
624                LLVMBuildFSub(self.builder.unwrap(), a.value, b.value, into_c("").as_ptr())
625            }
626        }
627    }
628
629    /// Builds a float `mul` instruction
630    pub fn build_float_mul(&self, a: Value, b: Value) -> Value {
631        Value {
632            value: unsafe {
633                LLVMBuildFMul(self.builder.unwrap(), a.value, b.value, into_c("").as_ptr())
634            }
635        }
636    }
637
638    /// Builds a float `div` instruction
639    pub fn build_float_div(&self, a: Value, b: Value) -> Value {
640        Value {
641            value: unsafe {
642                LLVMBuildFDiv(self.builder.unwrap(), a.value, b.value, into_c("").as_ptr())
643            }
644        }
645    }
646
647    /// Builds a float `rem` instruction
648    pub fn build_float_rem(&self, a: Value, b: Value) -> Value {
649        Value {
650            value: unsafe {
651                LLVMBuildFRem(self.builder.unwrap(), a.value, b.value, into_c("").as_ptr())
652            }
653        }
654    }
655
656    /// Builds a float `eq` check
657    pub fn build_float_eq(&self, a: Value, b: Value) -> Value {
658        Value {
659            value: unsafe {
660                LLVMBuildFCmp(self.builder.unwrap(), LLVMRealPredicate::LLVMRealUEQ, a.value, b.value, into_c("").as_ptr())
661            }
662        }
663    }
664
665    /// Builds a float `ne` check
666    pub fn build_float_ne(&self, a: Value, b: Value) -> Value {
667        Value {
668            value: unsafe {
669                LLVMBuildFCmp(self.builder.unwrap(), LLVMRealPredicate::LLVMRealUNE, a.value, b.value, into_c("").as_ptr())
670            }
671        }
672    }
673
674    /// Builds a float `le` check
675    pub fn build_float_le(&self, a: Value, b: Value) -> Value {
676        Value {
677            value: unsafe {
678                LLVMBuildFCmp(self.builder.unwrap(), LLVMRealPredicate::LLVMRealULE, a.value, b.value, into_c("").as_ptr())
679            }
680        }
681    }
682
683    /// Builds a float `lt` check
684    pub fn build_float_lt(&self, a: Value, b: Value) -> Value {
685        Value {
686            value: unsafe {
687                LLVMBuildFCmp(self.builder.unwrap(), LLVMRealPredicate::LLVMRealULT, a.value, b.value, into_c("").as_ptr())
688            }
689        }
690    }
691
692    /// Builds a float `ge` check
693    pub fn build_float_ge(&self, a: Value, b: Value) -> Value {
694        Value {
695            value: unsafe {
696                LLVMBuildFCmp(self.builder.unwrap(), LLVMRealPredicate::LLVMRealUGE, a.value, b.value, into_c("").as_ptr())
697            }
698        }
699    }
700
701    /// Builds a float `gt` check
702    pub fn build_float_gt(&self, a: Value, b: Value) -> Value {
703        Value {
704            value: unsafe {
705                LLVMBuildFCmp(self.builder.unwrap(), LLVMRealPredicate::LLVMRealUGT, a.value, b.value, into_c("").as_ptr())
706            }
707        }
708    }
709
710    /// Builds an ordered float `eq` check
711    pub fn build_float_ord_eq(&self, a: Value, b: Value) -> Value {
712        Value {
713            value: unsafe {
714                LLVMBuildFCmp(self.builder.unwrap(), LLVMRealPredicate::LLVMRealOEQ, a.value, b.value, into_c("").as_ptr())
715            }
716        }
717    }
718
719    /// Builds an ordered float `ne` check
720    pub fn build_float_ord_ne(&self, a: Value, b: Value) -> Value {
721        Value {
722            value: unsafe {
723                LLVMBuildFCmp(self.builder.unwrap(), LLVMRealPredicate::LLVMRealONE, a.value, b.value, into_c("").as_ptr())
724            }
725        }
726    }
727
728    /// Builds an ordered float `le` check
729    pub fn build_float_ord_le(&self, a: Value, b: Value) -> Value {
730        Value {
731            value: unsafe {
732                LLVMBuildFCmp(self.builder.unwrap(), LLVMRealPredicate::LLVMRealOLE, a.value, b.value, into_c("").as_ptr())
733            }
734        }
735    }
736
737    /// Builds an ordered float `lt` check
738    pub fn build_float_ord_lt(&self, a: Value, b: Value) -> Value {
739        Value {
740            value: unsafe {
741                LLVMBuildFCmp(self.builder.unwrap(), LLVMRealPredicate::LLVMRealOLT, a.value, b.value, into_c("").as_ptr())
742            }
743        }
744    }
745
746    /// Builds an ordered float `ge` check
747    pub fn build_float_ord_ge(&self, a: Value, b: Value) -> Value {
748        Value {
749            value: unsafe {
750                LLVMBuildFCmp(self.builder.unwrap(), LLVMRealPredicate::LLVMRealOGE, a.value, b.value, into_c("").as_ptr())
751            }
752        }
753    }
754
755    /// Builds an ordered float `gt` check
756    pub fn build_float_ord_gt(&self, a: Value, b: Value) -> Value {
757        Value {
758            value: unsafe {
759                LLVMBuildFCmp(self.builder.unwrap(), LLVMRealPredicate::LLVMRealOGT, a.value, b.value, into_c("").as_ptr())
760            }
761        }
762    }
763
764    /// Builds a check for an ordered float
765    pub fn build_float_is_ord(&self, a: Value, b: Value) -> Value {
766        Value {
767            value: unsafe {
768                LLVMBuildFCmp(self.builder.unwrap(), LLVMRealPredicate::LLVMRealORD, a.value, b.value, into_c("").as_ptr())
769            }
770        }
771    }
772
773    /// Builds a check for an unordered float
774    pub fn build_float_non_ord(&self, a: Value, b: Value) -> Value {
775        Value {
776            value: unsafe {
777                LLVMBuildFCmp(self.builder.unwrap(), LLVMRealPredicate::LLVMRealUNO, a.value, b.value, into_c("").as_ptr())
778            }
779        }
780    }
781}
782
783impl Deref for Builder {
784    type Target = LLVMBuilderRef;
785
786    fn deref(&self) -> &LLVMBuilderRef {
787        self.builder.as_ref().unwrap()
788    }
789}
790
791impl Drop for Builder {
792    fn drop(&mut self) {
793        if let Some(builder) = self.builder {
794            unsafe {
795                LLVMDisposeBuilder(builder);
796            }
797        }
798    }
799}
800
801impl Debug for Builder {
802    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
803        write!(f, "Builder")
804    }
805}