1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
use crate::CUint;
use llvm_sys::{
    core, LLVMDLLStorageClass, LLVMIntPredicate, LLVMLinkage, LLVMOpcode, LLVMRealPredicate,
    LLVMUnnamedAddr, LLVMVisibility,
};
use std::fmt::Display;
use std::ops::Deref;

pub mod context;
pub mod module;
pub mod types;
pub mod values;

/// Represents an LLVM address space.
///
/// The `AddressSpace` struct encapsulates a numeric value that indicates a specific address space
/// in LLVM. Address spaces are used in LLVM to distinguish between different regions of memory, such as
/// global memory, local memory, and private memory, especially in contexts like GPUs or other specialized
/// hardware where different memory regions have different characteristics.
///
/// # Attributes
///
/// - Wrapped address value - the underlying numeric value representing the address space.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AddressSpace(CUint);

impl From<u32> for AddressSpace {
    fn from(value: u32) -> Self {
        Self(CUint::from(value))
    }
}

impl Deref for AddressSpace {
    type Target = CUint;
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

impl AddressSpace {
    #[must_use]
    pub const fn new(value: CUint) -> Self {
        Self(value)
    }
}

/// Dispose LLVM message
///
/// ## Panics
/// This function is purely informative and panics with a message about the call
/// being unavailable. Since there are no cases in which it can be called in
/// safe code. For raw access, if there is such a need, must be called
/// `LLVMDisposeMessage` directly.
pub fn dispose_message(_message: libc::c_char) {
    unreachable!(
        "LLVMDisposeMessage is unsafe adn restricted to operated to operate directly for safe code"
    );
}

/// LLVM version representation
///
/// The `Version` struct encapsulates the major, minor, and patch components of the LLVM version.
/// This struct provides methods to initialize and retrieve the version information.
pub struct Version {
    major: u32,
    minor: u32,
    patch: u32,
}

impl Version {
    /// Init and return current LLVM version
    ///
    /// # Details
    ///
    /// Initializes and returns the current LLVM version.
    ///
    /// This method queries the LLVM library for its version information and returns a `Version` instance
    /// containing the major, minor, and patch components of the LLVM version.
    ///
    /// # Returns
    ///
    /// A `Version` instance with the current LLVM version.
    ///
    /// # Example
    ///
    /// ```rust
    /// let llvm_version = Version::new();
    /// ```
    #[must_use]
    pub fn new() -> Self {
        let mut major = CUint::from(0_u32);
        let mut minor = CUint::from(0_u32);
        let mut patch = CUint::from(0_u32);
        unsafe {
            core::LLVMGetVersion(&mut *major, &mut *minor, &mut *patch);
        }
        Self {
            major: major.into(),
            minor: minor.into(),
            patch: patch.into(),
        }
    }

    /// Return LLVM version data: (major, minor, patch)
    ///
    /// # Details
    ///
    ///  Returns the LLVM version as a tuple `(major, minor, patch)`.
    ///
    /// This method provides access to the individual components of the LLVM version stored in this `Version` instance.
    ///
    /// # Returns
    ///
    /// A tuple `(u32, u32, u32)` representing the major, minor, and patch components of the LLVM version.
    ///
    /// # Example
    ///
    /// ```rust
    /// let llvm_version = Version::new();
    /// let (major, minor, patch) = llvm_version.get();
    /// ```
    #[must_use]
    pub const fn get(&self) -> (u32, u32, u32) {
        (self.minor, self.minor, self.patch)
    }
}

impl Display for Version {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}.{}.{}", self.major, self.minor, self.patch)
    }
}

/// Represents the various opcodes in LLVM IR.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Opcode {
    /// Return instruction.
    Ret,
    /// Branch instruction.
    Br,
    /// Switch instruction.
    Switch,
    /// Indirect branch instruction.
    IndirectBr,
    /// Invoke instruction.
    Invoke,
    /// Unreachable instruction.
    Unreachable,
    /// `CallBr` instruction.
    CallBr,
    /// Floating-point negation instruction.
    FNeg,
    /// Integer addition instruction.
    Add,
    /// Floating-point addition instruction.
    FAdd,
    /// Integer subtraction instruction.
    Sub,
    /// Floating-point subtraction instruction.
    FSub,
    /// Integer multiplication instruction
    Mul,
    /// Floating-point multiplication instruction.
    FMul,
    /// Unsigned integer division instruction.
    UDiv,
    /// Signed integer division instruction.
    SDiv,
    /// Floating-point division instruction.
    FDiv,
    /// Unsigned integer remainder instruction.
    URem,
    /// Signed integer remainder instruction.
    SRem,
    /// Floating-point remainder instruction.
    FRem,
    /// Logical shift left instruction.
    Shl,
    /// Logical shift right instruction.
    LShr,
    /// Arithmetic shift right instruction.
    AShr,
    /// Bitwise AND instruction.
    And,
    /// Bitwise OR instruction.
    Or,
    /// Bitwise XOR instruction.
    Xor,
    /// Alloca instruction.
    Alloca,
    /// Load instruction.
    Load,
    /// Store instruction.
    Store,
    /// `GetElementPtr` instruction.
    GetElementPtr,
    /// Truncate instruction.
    Trunc,
    /// Zero extend instruction.
    ZExt,
    /// Sign extend instruction.
    SExt,
    /// Floating-point to unsigned integer instruction.
    FPToUI,
    /// Floating-point to signed integer instruction.
    FPToSI,
    /// Unsigned integer to floating-point instruction.
    UIToFP,
    /// Signed integer to floating-point instruction.
    SIToFP,
    /// Floating-point truncate instruction.
    FPTrunc,
    /// Floating-point extend instruction
    FPExt,
    /// Pointer to integer instruction
    PtrToInt,
    /// Integer to pointer instruction
    IntToPtr,
    /// Bit-cast instruction
    BitCast,
    /// Address space cast instruction
    AddrSpaceCast,
    /// Integer comparison instruction
    ICmp,
    /// Floating-point comparison instruction
    FCmp,
    /// PHI node instruction
    PHI,
    /// Call instruction
    Call,
    /// Select instruction
    Select,

    /// User-defined operation 1
    UserOp1,
    /// User-defined operation 2
    UserOp2,
    /// Variable argument instruction
    VAArg,
    /// Extract element from vector instruction
    ExtractElement,
    /// Insert element into vector instruction
    InsertElement,
    /// Shuffle vector instruction
    ShuffleVector,
    /// Extract value from aggregate instruction
    ExtractValue,
    /// Insert value into aggregate instruction
    InsertValue,
    /// Freeze instruction
    Freeze,
    /// Fence instruction
    Fence,
    /// Atomic compare and exchange instruction
    AtomicCmpXchg,
    /// Atomic read-modify-write instruction
    AtomicRMW,
    /// Resume instruction
    Resume,
    /// Landing pad instruction
    LandingPad,
    /// Cleanup return instruction.
    CleanupRet,
    /// Catch return instruction
    CatchRet,
    /// Catch pad instruction
    CatchPad,
    /// Cleanup pad instruction
    CleanupPad,
    /// Catch switch instruction
    CatchSwitch,
}

impl From<LLVMOpcode> for Opcode {
    fn from(opcode: LLVMOpcode) -> Self {
        match opcode {
            LLVMOpcode::LLVMRet => Self::Ret,
            LLVMOpcode::LLVMBr => Self::Br,
            LLVMOpcode::LLVMSwitch => Self::Switch,
            LLVMOpcode::LLVMIndirectBr => Self::IndirectBr,
            LLVMOpcode::LLVMInvoke => Self::Invoke,
            LLVMOpcode::LLVMUnreachable => Self::Unreachable,
            LLVMOpcode::LLVMCallBr => Self::CallBr,
            LLVMOpcode::LLVMFNeg => Self::FNeg,
            LLVMOpcode::LLVMAdd => Self::Add,
            LLVMOpcode::LLVMFAdd => Self::FAdd,
            LLVMOpcode::LLVMSub => Self::Sub,
            LLVMOpcode::LLVMFSub => Self::FSub,
            LLVMOpcode::LLVMMul => Self::Mul,
            LLVMOpcode::LLVMFMul => Self::FMul,
            LLVMOpcode::LLVMUDiv => Self::UDiv,
            LLVMOpcode::LLVMSDiv => Self::SDiv,
            LLVMOpcode::LLVMFDiv => Self::FDiv,
            LLVMOpcode::LLVMURem => Self::URem,
            LLVMOpcode::LLVMSRem => Self::SRem,
            LLVMOpcode::LLVMFRem => Self::FRem,
            LLVMOpcode::LLVMShl => Self::Shl,
            LLVMOpcode::LLVMLShr => Self::LShr,
            LLVMOpcode::LLVMAShr => Self::AShr,
            LLVMOpcode::LLVMAnd => Self::And,
            LLVMOpcode::LLVMOr => Self::Or,
            LLVMOpcode::LLVMXor => Self::Xor,
            LLVMOpcode::LLVMAlloca => Self::Alloca,
            LLVMOpcode::LLVMLoad => Self::Load,
            LLVMOpcode::LLVMStore => Self::Store,
            LLVMOpcode::LLVMGetElementPtr => Self::GetElementPtr,
            LLVMOpcode::LLVMTrunc => Self::Trunc,
            LLVMOpcode::LLVMZExt => Self::ZExt,
            LLVMOpcode::LLVMSExt => Self::SExt,
            LLVMOpcode::LLVMFPToUI => Self::FPToUI,
            LLVMOpcode::LLVMFPToSI => Self::FPToSI,
            LLVMOpcode::LLVMUIToFP => Self::UIToFP,
            LLVMOpcode::LLVMSIToFP => Self::SIToFP,
            LLVMOpcode::LLVMFPTrunc => Self::FPTrunc,
            LLVMOpcode::LLVMFPExt => Self::FPExt,
            LLVMOpcode::LLVMPtrToInt => Self::PtrToInt,
            LLVMOpcode::LLVMIntToPtr => Self::IntToPtr,
            LLVMOpcode::LLVMBitCast => Self::BitCast,
            LLVMOpcode::LLVMAddrSpaceCast => Self::AddrSpaceCast,
            LLVMOpcode::LLVMICmp => Self::ICmp,
            LLVMOpcode::LLVMFCmp => Self::FCmp,
            LLVMOpcode::LLVMPHI => Self::PHI,
            LLVMOpcode::LLVMCall => Self::Call,
            LLVMOpcode::LLVMSelect => Self::Select,
            LLVMOpcode::LLVMUserOp1 => Self::UserOp1,
            LLVMOpcode::LLVMUserOp2 => Self::UserOp2,
            LLVMOpcode::LLVMVAArg => Self::VAArg,
            LLVMOpcode::LLVMExtractElement => Self::ExtractElement,
            LLVMOpcode::LLVMInsertElement => Self::InsertElement,
            LLVMOpcode::LLVMShuffleVector => Self::ShuffleVector,
            LLVMOpcode::LLVMExtractValue => Self::ExtractValue,
            LLVMOpcode::LLVMInsertValue => Self::InsertValue,
            LLVMOpcode::LLVMFreeze => Self::Freeze,
            LLVMOpcode::LLVMFence => Self::Fence,
            LLVMOpcode::LLVMAtomicCmpXchg => Self::AtomicCmpXchg,
            LLVMOpcode::LLVMAtomicRMW => Self::AtomicRMW,
            LLVMOpcode::LLVMResume => Self::Resume,
            LLVMOpcode::LLVMLandingPad => Self::LandingPad,
            LLVMOpcode::LLVMCleanupRet => Self::CleanupRet,
            LLVMOpcode::LLVMCatchRet => Self::CatchRet,
            LLVMOpcode::LLVMCatchPad => Self::CatchPad,
            LLVMOpcode::LLVMCleanupPad => Self::CleanupPad,
            LLVMOpcode::LLVMCatchSwitch => Self::CatchSwitch,
        }
    }
}

impl From<Opcode> for LLVMOpcode {
    fn from(opcode: Opcode) -> Self {
        match opcode {
            Opcode::Ret => Self::LLVMRet,
            Opcode::Br => Self::LLVMBr,
            Opcode::Switch => Self::LLVMSwitch,
            Opcode::IndirectBr => Self::LLVMIndirectBr,
            Opcode::Invoke => Self::LLVMInvoke,
            Opcode::Unreachable => Self::LLVMUnreachable,
            Opcode::CallBr => Self::LLVMCallBr,
            Opcode::FNeg => Self::LLVMFNeg,
            Opcode::Add => Self::LLVMAdd,
            Opcode::FAdd => Self::LLVMFAdd,
            Opcode::Sub => Self::LLVMSub,
            Opcode::FSub => Self::LLVMFSub,
            Opcode::Mul => Self::LLVMMul,
            Opcode::FMul => Self::LLVMFMul,
            Opcode::UDiv => Self::LLVMUDiv,
            Opcode::SDiv => Self::LLVMSDiv,
            Opcode::FDiv => Self::LLVMFDiv,
            Opcode::URem => Self::LLVMURem,
            Opcode::SRem => Self::LLVMSRem,
            Opcode::FRem => Self::LLVMFRem,
            Opcode::Shl => Self::LLVMShl,
            Opcode::LShr => Self::LLVMLShr,
            Opcode::AShr => Self::LLVMAShr,
            Opcode::And => Self::LLVMAnd,
            Opcode::Or => Self::LLVMOr,
            Opcode::Xor => Self::LLVMXor,
            Opcode::Alloca => Self::LLVMAlloca,
            Opcode::Load => Self::LLVMLoad,
            Opcode::Store => Self::LLVMStore,
            Opcode::GetElementPtr => Self::LLVMGetElementPtr,
            Opcode::Trunc => Self::LLVMTrunc,
            Opcode::ZExt => Self::LLVMZExt,
            Opcode::SExt => Self::LLVMSExt,
            Opcode::FPToUI => Self::LLVMFPToUI,
            Opcode::FPToSI => Self::LLVMFPToSI,
            Opcode::UIToFP => Self::LLVMUIToFP,
            Opcode::SIToFP => Self::LLVMSIToFP,
            Opcode::FPTrunc => Self::LLVMFPTrunc,
            Opcode::FPExt => Self::LLVMFPExt,
            Opcode::PtrToInt => Self::LLVMPtrToInt,
            Opcode::IntToPtr => Self::LLVMIntToPtr,
            Opcode::BitCast => Self::LLVMBitCast,
            Opcode::AddrSpaceCast => Self::LLVMAddrSpaceCast,
            Opcode::ICmp => Self::LLVMICmp,
            Opcode::FCmp => Self::LLVMFCmp,
            Opcode::PHI => Self::LLVMPHI,
            Opcode::Call => Self::LLVMCall,
            Opcode::Select => Self::LLVMSelect,
            Opcode::UserOp1 => Self::LLVMUserOp1,
            Opcode::UserOp2 => Self::LLVMUserOp2,
            Opcode::VAArg => Self::LLVMVAArg,
            Opcode::ExtractElement => Self::LLVMExtractElement,
            Opcode::InsertElement => Self::LLVMInsertElement,
            Opcode::ShuffleVector => Self::LLVMShuffleVector,
            Opcode::ExtractValue => Self::LLVMExtractValue,
            Opcode::InsertValue => Self::LLVMInsertValue,
            Opcode::Freeze => Self::LLVMFreeze,
            Opcode::Fence => Self::LLVMFence,
            Opcode::AtomicCmpXchg => Self::LLVMAtomicCmpXchg,
            Opcode::AtomicRMW => Self::LLVMAtomicRMW,
            Opcode::Resume => Self::LLVMResume,
            Opcode::LandingPad => Self::LLVMLandingPad,
            Opcode::CleanupRet => Self::LLVMCleanupRet,
            Opcode::CatchRet => Self::LLVMCatchRet,
            Opcode::CatchPad => Self::LLVMCatchPad,
            Opcode::CleanupPad => Self::LLVMCleanupPad,
            Opcode::CatchSwitch => Self::LLVMCatchSwitch,
        }
    }
}

/// Represents the various integer comparison predicates in LLVM IR.
///
/// The `IntPredicate` enum defines the possible predicates that can be used for integer comparisons
/// in LLVM IR. These predicates specify the condition under which an integer comparison is considered true.
/// The predicates cover both signed and unsigned comparisons, as well as equality checks.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum IntPredicate {
    /// Represents an equality comparison (`==`). This predicate is true if the two integers are equal.
    IntEQ,
    /// Represents an inequality comparison (`!=`). This predicate is true if the two integers are not equal.
    IntNE,
    /// Represents an unsigned greater than comparison (`>`). This predicate is true if the first integer is greater than the second, treating both as unsigned values.
    IntUGT,
    /// Represents an unsigned greater than or equal comparison (`>=`). This predicate is true if the first integer is greater than or equal to the second, treating both as unsigned values.
    IntUGE,
    /// Represents an unsigned less than comparison (`<`). This predicate is true if the first integer is less than the second, treating both as unsigned values.
    IntULT,
    /// Represents an unsigned less than or equal comparison (`<=`). This predicate is true if the first integer is less than or equal to the second, treating both as unsigned values.
    IntULE,
    /// Represents a signed greater than comparison (`>`). This predicate is true if the first integer is greater than the second, treating both as signed values.
    IntSGT,
    /// Represents a signed greater than or equal comparison (`>=`). This predicate is true if the first integer is greater than or equal to the second, treating both as signed values.
    IntSGE,
    /// Represents a signed less than comparison (`<`). This predicate is true if the first integer is less than the second, treating both as signed values.
    IntSLT,
    /// Represents a signed less than or equal comparison (`<=`). This predicate is true if the first integer is less than or equal to the second, treating both as signed values.
    IntSLE,
}

impl From<LLVMIntPredicate> for IntPredicate {
    fn from(predicate: LLVMIntPredicate) -> Self {
        match predicate {
            LLVMIntPredicate::LLVMIntEQ => Self::IntEQ,
            LLVMIntPredicate::LLVMIntNE => Self::IntNE,
            LLVMIntPredicate::LLVMIntUGT => Self::IntUGT,
            LLVMIntPredicate::LLVMIntUGE => Self::IntUGE,
            LLVMIntPredicate::LLVMIntULT => Self::IntULT,
            LLVMIntPredicate::LLVMIntULE => Self::IntULE,
            LLVMIntPredicate::LLVMIntSGT => Self::IntSGT,
            LLVMIntPredicate::LLVMIntSGE => Self::IntSGE,
            LLVMIntPredicate::LLVMIntSLT => Self::IntSLT,
            LLVMIntPredicate::LLVMIntSLE => Self::IntSLE,
        }
    }
}

impl From<IntPredicate> for LLVMIntPredicate {
    fn from(predicate: IntPredicate) -> Self {
        match predicate {
            IntPredicate::IntEQ => Self::LLVMIntEQ,
            IntPredicate::IntNE => Self::LLVMIntNE,
            IntPredicate::IntUGT => Self::LLVMIntUGT,
            IntPredicate::IntUGE => Self::LLVMIntUGE,
            IntPredicate::IntULT => Self::LLVMIntULT,
            IntPredicate::IntULE => Self::LLVMIntULE,
            IntPredicate::IntSGT => Self::LLVMIntSGT,
            IntPredicate::IntSGE => Self::LLVMIntSGE,
            IntPredicate::IntSLT => Self::LLVMIntSLT,
            IntPredicate::IntSLE => Self::LLVMIntSLE,
        }
    }
}

/// Represents the various floating-point comparison predicates in LLVM IR.
///
/// The `RealPredicate` enum defines the possible predicates that can be used for floating-point comparisons
/// in LLVM IR. These predicates specify the conditions under which a floating-point comparison is considered true.
/// The predicates include ordered and unordered comparisons, as well as equality and inequality checks.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum RealPredicate {
    /// Represents a predicate that always returns false. No comparison is true under this predicate.
    RealPredicateFalse = 0,
    /// Represents an ordered equality comparison (`==`). This predicate is true if the two floating-point numbers are equal and neither is NaN.
    RealOEQ,
    /// Represents an ordered greater than comparison (`>`). This predicate is true if the first floating-point number is greater than the second and neither is NaN.
    RealOGT,
    /// Represents an ordered greater than or equal comparison (`>=`). This predicate is true if the first floating-point number is greater than or equal to the second and neither is NaN.
    RealOGE,
    /// Represents an ordered less than comparison (`<`). This predicate is true if the first floating-point number is less than the second and neither is NaN.
    RealOLT,
    /// Represents an ordered less than or equal comparison (`<=`). This predicate is true if the first floating-point number is less than or equal to the second and neither is NaN.
    RealOLE,
    /// Represents an ordered inequality comparison (`!=`). This predicate is true if the two floating-point numbers are not equal and neither is NaN.
    RealONE,
    /// Represents an ordered comparison. This predicate is true if neither of the floating-point numbers is NaN.
    RealORD,
    /// Represents an unordered comparison. This predicate is true if either of the floating-point numbers is NaN.
    RealUNO,
    /// Represents an unordered equality comparison. This predicate is true if the two floating-point numbers are equal or either is NaN.
    RealUEQ,
    /// Represents an unordered greater than comparison. This predicate is true if the first floating-point number is greater than the second or either is NaN.
    RealUGT,
    /// Represents an unordered greater than or equal comparison. This predicate is true if the first floating-point number is greater than or equal to the second or either is NaN.
    RealUGE,
    /// Represents an unordered less than comparison. This predicate is true if the first floating-point number is less than the second or either is NaN.
    RealULT,
    /// Represents an unordered less than or equal comparison. This predicate is true if the first floating-point number is less than or equal to the second or either is NaN.
    RealULE,
    /// Represents an unordered inequality comparison. This predicate is true if the two floating-point numbers are not equal or either is NaN.
    RealUNE,
    /// Represents a predicate that always returns true. All comparisons are true under this predicate.
    RealPredicateTrue,
}

impl From<LLVMRealPredicate> for RealPredicate {
    fn from(predicate: LLVMRealPredicate) -> Self {
        match predicate {
            LLVMRealPredicate::LLVMRealPredicateFalse => Self::RealPredicateFalse,
            LLVMRealPredicate::LLVMRealOEQ => Self::RealOEQ,
            LLVMRealPredicate::LLVMRealOGT => Self::RealOGT,
            LLVMRealPredicate::LLVMRealOGE => Self::RealOGE,
            LLVMRealPredicate::LLVMRealOLT => Self::RealOLT,
            LLVMRealPredicate::LLVMRealOLE => Self::RealOLE,
            LLVMRealPredicate::LLVMRealONE => Self::RealONE,
            LLVMRealPredicate::LLVMRealORD => Self::RealORD,
            LLVMRealPredicate::LLVMRealUNO => Self::RealUNO,
            LLVMRealPredicate::LLVMRealUEQ => Self::RealUEQ,
            LLVMRealPredicate::LLVMRealUGT => Self::RealUGT,
            LLVMRealPredicate::LLVMRealUGE => Self::RealUGE,
            LLVMRealPredicate::LLVMRealULT => Self::RealULT,
            LLVMRealPredicate::LLVMRealULE => Self::RealULE,
            LLVMRealPredicate::LLVMRealUNE => Self::RealUNE,
            LLVMRealPredicate::LLVMRealPredicateTrue => Self::RealPredicateTrue,
        }
    }
}

impl From<RealPredicate> for LLVMRealPredicate {
    fn from(predicate: RealPredicate) -> Self {
        match predicate {
            RealPredicate::RealPredicateFalse => Self::LLVMRealPredicateFalse,
            RealPredicate::RealOEQ => Self::LLVMRealOEQ,
            RealPredicate::RealOGT => Self::LLVMRealOGT,
            RealPredicate::RealOGE => Self::LLVMRealOGE,
            RealPredicate::RealOLT => Self::LLVMRealOLT,
            RealPredicate::RealOLE => Self::LLVMRealOLE,
            RealPredicate::RealONE => Self::LLVMRealONE,
            RealPredicate::RealORD => Self::LLVMRealORD,
            RealPredicate::RealUNO => Self::LLVMRealUNO,
            RealPredicate::RealUEQ => Self::LLVMRealUEQ,
            RealPredicate::RealUGT => Self::LLVMRealUGT,
            RealPredicate::RealUGE => Self::LLVMRealUGE,
            RealPredicate::RealULT => Self::LLVMRealULT,
            RealPredicate::RealULE => Self::LLVMRealULE,
            RealPredicate::RealUNE => Self::LLVMRealUNE,
            RealPredicate::RealPredicateTrue => Self::LLVMRealPredicateTrue,
        }
    }
}

/// Represents the linkage types in LLVM for global values.
/// Linkage types determine the visibility and behavior of symbols across different modules and within the same module.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Linkage {
    /// Externally visible function or variable. Can be linked from another module.
    ExternalLinkage,
    /// Similar to `ExternalLinkage`, but the symbol may be discarded if not used.
    AvailableExternallyLinkage,
    /// Keeps one copy of the function or variable when linking, discarding others.
    LinkOnceAnyLinkage,
    /// Similar to `LinkOnceAnyLinkage`, but the symbol cannot be discarded.
    LinkOnceODRLinkage,
    /// Same as `LinkOnceODRLinkage`, but with hidden visibility.
    LinkOnceODRAutoHideLinkage,
    /// Keeps one copy, discarding others, but prefer the local copy.
    WeakAnyLinkage,
    /// Similar to `WeakAnyLinkage`, but ensures that the symbol is unique and is emitted only once.
    WeakODRLinkage,
    /// Appending linkage: when linked, multiple definitions of the same variable are concatenated.
    AppendingLinkage,
    /// Local to the translation unit, not visible outside of it.
    InternalLinkage,
    /// Similar to `InternalLinkage`, but prevents inlining and other optimizations.
    PrivateLinkage,
    /// Indicates that the global value should be imported from a DLL.
    DLLImportLinkage,
    /// Indicates that the global value should be exported to a DLL.
    DLLExportLinkage,
    /// The global variable or function is merged into the program only if it is used.
    ExternalWeakLinkage,
    /// A special linkage type used internally by the linker.
    GhostLinkage,
    /// Common linkage for uninitialized global variables.
    CommonLinkage,
    /// Linker private linkage, used to indicate a symbol that is internal to the module.
    LinkerPrivateLinkage,
    /// Weak version of `LinkerPrivateLinkage`.
    LinkerPrivateWeakLinkage,
}

impl From<LLVMLinkage> for Linkage {
    fn from(linkage: LLVMLinkage) -> Self {
        match linkage {
            LLVMLinkage::LLVMExternalLinkage => Self::ExternalLinkage,
            LLVMLinkage::LLVMAvailableExternallyLinkage => Self::AvailableExternallyLinkage,
            LLVMLinkage::LLVMLinkOnceAnyLinkage => Self::LinkOnceAnyLinkage,
            LLVMLinkage::LLVMLinkOnceODRLinkage => Self::LinkOnceODRLinkage,
            LLVMLinkage::LLVMLinkOnceODRAutoHideLinkage => Self::LinkOnceODRAutoHideLinkage,
            LLVMLinkage::LLVMWeakAnyLinkage => Self::WeakAnyLinkage,
            LLVMLinkage::LLVMWeakODRLinkage => Self::WeakODRLinkage,
            LLVMLinkage::LLVMAppendingLinkage => Self::AppendingLinkage,
            LLVMLinkage::LLVMInternalLinkage => Self::InternalLinkage,
            LLVMLinkage::LLVMPrivateLinkage => Self::PrivateLinkage,
            LLVMLinkage::LLVMDLLImportLinkage => Self::DLLImportLinkage,
            LLVMLinkage::LLVMDLLExportLinkage => Self::DLLExportLinkage,
            LLVMLinkage::LLVMExternalWeakLinkage => Self::ExternalWeakLinkage,
            LLVMLinkage::LLVMGhostLinkage => Self::GhostLinkage,
            LLVMLinkage::LLVMCommonLinkage => Self::CommonLinkage,
            LLVMLinkage::LLVMLinkerPrivateLinkage => Self::LinkerPrivateLinkage,
            LLVMLinkage::LLVMLinkerPrivateWeakLinkage => Self::LinkerPrivateWeakLinkage,
        }
    }
}

impl From<Linkage> for LLVMLinkage {
    fn from(linkage: Linkage) -> Self {
        match linkage {
            Linkage::ExternalLinkage => Self::LLVMExternalLinkage,
            Linkage::AvailableExternallyLinkage => Self::LLVMAvailableExternallyLinkage,
            Linkage::LinkOnceAnyLinkage => Self::LLVMLinkOnceAnyLinkage,
            Linkage::LinkOnceODRLinkage => Self::LLVMLinkOnceODRLinkage,
            Linkage::LinkOnceODRAutoHideLinkage => Self::LLVMLinkOnceODRAutoHideLinkage,
            Linkage::WeakAnyLinkage => Self::LLVMWeakAnyLinkage,
            Linkage::WeakODRLinkage => Self::LLVMWeakODRLinkage,
            Linkage::AppendingLinkage => Self::LLVMAppendingLinkage,
            Linkage::InternalLinkage => Self::LLVMInternalLinkage,
            Linkage::PrivateLinkage => Self::LLVMPrivateLinkage,
            Linkage::DLLImportLinkage => Self::LLVMDLLImportLinkage,
            Linkage::DLLExportLinkage => Self::LLVMDLLExportLinkage,
            Linkage::ExternalWeakLinkage => Self::LLVMExternalWeakLinkage,
            Linkage::GhostLinkage => Self::LLVMGhostLinkage,
            Linkage::CommonLinkage => Self::LLVMCommonLinkage,
            Linkage::LinkerPrivateLinkage => Self::LLVMLinkerPrivateLinkage,
            Linkage::LinkerPrivateWeakLinkage => Self::LLVMLinkerPrivateWeakLinkage,
        }
    }
}

/// `Visibility` is an enumeration in LLVM that represents the
/// visibility of global values such as functions and global
/// variables. Visibility determines how symbols are treated by
/// the linker and whether they can be seen by other modules or
/// shared libraries.
/// Generally `Visibility` represent access to the symbol after `Linkage`.
/// Useful to compose `Linkage` and `Visibility` to define the symbol behavior.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Visibility {
    /// Default visibility. The symbol is visible to other modules.
    DefaultVisibility,
    /// Hidden visibility. The symbol is not visible to other modules or shared libraries.
    HiddenVisibility,
    /// Protected visibility. The symbol is visible to other modules but cannot be overridden.
    ProtectedVisibility,
}

impl From<LLVMVisibility> for Visibility {
    fn from(visibility: LLVMVisibility) -> Self {
        match visibility {
            LLVMVisibility::LLVMDefaultVisibility => Self::DefaultVisibility,
            LLVMVisibility::LLVMHiddenVisibility => Self::HiddenVisibility,
            LLVMVisibility::LLVMProtectedVisibility => Self::ProtectedVisibility,
        }
    }
}

impl From<Visibility> for LLVMVisibility {
    fn from(visibility: Visibility) -> Self {
        match visibility {
            Visibility::DefaultVisibility => Self::LLVMDefaultVisibility,
            Visibility::HiddenVisibility => Self::LLVMHiddenVisibility,
            Visibility::ProtectedVisibility => Self::LLVMProtectedVisibility,
        }
    }
}

/// Represents the DLL storage classes in LLVM, that specifies how a global value,
/// such as a function or global variable, should be treated with respect to
/// dynamic link libraries (DLLs) on platforms like Windows. The `DLLStorageClass`
/// controls whether a symbol should be imported from a DLL, exported to a DLL, or
/// treated as a normal global symbol.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum DLLStorageClass {
    /// `DefaultStorageClass`: The default storage class. The symbol is not specifically marked for import or export
    /// from a DLL. It is treated as a normal global symbol.
    DefaultStorageClass,
    /// `DLLImportStorageClass`: Specifies that the symbol should be imported from a DLL. This is used when you want
    /// to use a function or variable that is defined in another DLL. The linker will ensure that the symbol is correctly
    /// imported at runtime.
    DLLImportStorageClass,
    /// `DLLExportStorageClass`: Specifies that the symbol should be exported to a DLL. This is used when you want to make
    /// a function or variable available for use by other modules or executables. The linker will ensure that the symbol is
    /// correctly exported and accessible to other programs.
    DLLExportStorageClass,
}

impl From<DLLStorageClass> for LLVMDLLStorageClass {
    fn from(storage_class: DLLStorageClass) -> Self {
        match storage_class {
            DLLStorageClass::DefaultStorageClass => Self::LLVMDefaultStorageClass,
            DLLStorageClass::DLLImportStorageClass => Self::LLVMDLLImportStorageClass,
            DLLStorageClass::DLLExportStorageClass => Self::LLVMDLLExportStorageClass,
        }
    }
}

impl From<LLVMDLLStorageClass> for DLLStorageClass {
    fn from(storage_class: LLVMDLLStorageClass) -> Self {
        match storage_class {
            LLVMDLLStorageClass::LLVMDefaultStorageClass => Self::DefaultStorageClass,
            LLVMDLLStorageClass::LLVMDLLImportStorageClass => Self::DLLImportStorageClass,
            LLVMDLLStorageClass::LLVMDLLExportStorageClass => Self::DLLExportStorageClass,
        }
    }
}

/// Represents the unnamed address attribute for global values in LLVM.
///
/// `UnnamedAddr` is an enumeration that specifies whether a global variable or function's address is significant.
/// This can help LLVM's optimizer determine whether it can merge or duplicate global values with identical content,
/// potentially reducing code size or improving performance.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum UnnamedAddr {
    /// `NoUnnamedAddr`: The address of the global value is significant, and it must be unique.
    /// The global variable or function cannot be merged with others, even if they have the same content.
    /// This is the default behavior for most global values.
    NoUnnamedAddr,
    /// `LocalUnnamedAddr`: The address of the global value is not significant within the module, allowing the optimizer
    /// to merge or duplicate global values with the same content. However, the address is still unique within the module.
    /// This is useful for variables or functions that are only accessed within the same module and do not need a unique address.
    LocalUnnamedAddr,
    /// `GlobalUnnamedAddr`: The address of the global value is not significant across the entire program, allowing the optimizer
    /// to freely merge or duplicate global values with identical content across different modules.
    /// This can lead to more aggressive optimizations and is useful for constants or functions that do not rely on having a unique address.
    GlobalUnnamedAddr,
}

impl From<UnnamedAddr> for LLVMUnnamedAddr {
    fn from(unnamed_addr: UnnamedAddr) -> Self {
        match unnamed_addr {
            UnnamedAddr::NoUnnamedAddr => Self::LLVMNoUnnamedAddr,
            UnnamedAddr::LocalUnnamedAddr => Self::LLVMLocalUnnamedAddr,
            UnnamedAddr::GlobalUnnamedAddr => Self::LLVMGlobalUnnamedAddr,
        }
    }
}

impl From<LLVMUnnamedAddr> for UnnamedAddr {
    fn from(unnamed_addr: LLVMUnnamedAddr) -> Self {
        match unnamed_addr {
            LLVMUnnamedAddr::LLVMNoUnnamedAddr => Self::NoUnnamedAddr,
            LLVMUnnamedAddr::LLVMLocalUnnamedAddr => Self::LocalUnnamedAddr,
            LLVMUnnamedAddr::LLVMGlobalUnnamedAddr => Self::GlobalUnnamedAddr,
        }
    }
}