llvm_ir/
predicates.rs

1use std::fmt::{self, Display};
2
3#[derive(PartialEq, Eq, Clone, Copy, Debug, Hash)]
4pub enum IntPredicate {
5    EQ,
6    NE,
7    UGT,
8    UGE,
9    ULT,
10    ULE,
11    SGT,
12    SGE,
13    SLT,
14    SLE,
15}
16
17impl Display for IntPredicate {
18    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
19        match self {
20            IntPredicate::EQ => write!(f, "eq"),
21            IntPredicate::NE => write!(f, "ne"),
22            IntPredicate::UGT => write!(f, "ugt"),
23            IntPredicate::UGE => write!(f, "uge"),
24            IntPredicate::ULT => write!(f, "ult"),
25            IntPredicate::ULE => write!(f, "ule"),
26            IntPredicate::SGT => write!(f, "sgt"),
27            IntPredicate::SGE => write!(f, "sge"),
28            IntPredicate::SLT => write!(f, "slt"),
29            IntPredicate::SLE => write!(f, "sle"),
30        }
31    }
32}
33
34#[derive(PartialEq, Eq, Clone, Copy, Debug, Hash)]
35pub enum FPPredicate {
36    False,
37    OEQ,
38    OGT,
39    OGE,
40    OLT,
41    OLE,
42    ONE,
43    ORD,
44    UNO,
45    UEQ,
46    UGT,
47    UGE,
48    ULT,
49    ULE,
50    UNE,
51    True,
52}
53
54impl Display for FPPredicate {
55    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
56        match self {
57            FPPredicate::False => write!(f, "false"),
58            FPPredicate::OEQ => write!(f, "oeq"),
59            FPPredicate::OGT => write!(f, "ogt"),
60            FPPredicate::OGE => write!(f, "oge"),
61            FPPredicate::OLT => write!(f, "olt"),
62            FPPredicate::OLE => write!(f, "ole"),
63            FPPredicate::ONE => write!(f, "one"),
64            FPPredicate::ORD => write!(f, "ord"),
65            FPPredicate::UNO => write!(f, "uno"),
66            FPPredicate::UEQ => write!(f, "ueq"),
67            FPPredicate::UGT => write!(f, "ugt"),
68            FPPredicate::UGE => write!(f, "uge"),
69            FPPredicate::ULT => write!(f, "ult"),
70            FPPredicate::ULE => write!(f, "ule"),
71            FPPredicate::UNE => write!(f, "une"),
72            FPPredicate::True => write!(f, "true"),
73        }
74    }
75}
76
77// ********* //
78// from_llvm //
79// ********* //
80
81use crate::llvm_sys::*;
82use llvm_sys::LLVMIntPredicate;
83use llvm_sys::LLVMRealPredicate;
84
85impl IntPredicate {
86    pub(crate) fn from_llvm(pred: LLVMIntPredicate) -> Self {
87        match pred {
88            LLVMIntPredicate::LLVMIntEQ => IntPredicate::EQ,
89            LLVMIntPredicate::LLVMIntNE => IntPredicate::NE,
90            LLVMIntPredicate::LLVMIntUGT => IntPredicate::UGT,
91            LLVMIntPredicate::LLVMIntUGE => IntPredicate::UGE,
92            LLVMIntPredicate::LLVMIntULT => IntPredicate::ULT,
93            LLVMIntPredicate::LLVMIntULE => IntPredicate::ULE,
94            LLVMIntPredicate::LLVMIntSGT => IntPredicate::SGT,
95            LLVMIntPredicate::LLVMIntSGE => IntPredicate::SGE,
96            LLVMIntPredicate::LLVMIntSLT => IntPredicate::SLT,
97            LLVMIntPredicate::LLVMIntSLE => IntPredicate::SLE,
98        }
99    }
100}
101
102impl FPPredicate {
103    pub(crate) fn from_llvm(pred: LLVMRealPredicate) -> Self {
104        match pred {
105            LLVMRealPredicate::LLVMRealPredicateFalse => FPPredicate::False,
106            LLVMRealPredicate::LLVMRealOEQ => FPPredicate::OEQ,
107            LLVMRealPredicate::LLVMRealOGT => FPPredicate::OGT,
108            LLVMRealPredicate::LLVMRealOGE => FPPredicate::OGE,
109            LLVMRealPredicate::LLVMRealOLT => FPPredicate::OLT,
110            LLVMRealPredicate::LLVMRealOLE => FPPredicate::OLE,
111            LLVMRealPredicate::LLVMRealONE => FPPredicate::ONE,
112            LLVMRealPredicate::LLVMRealORD => FPPredicate::ORD,
113            LLVMRealPredicate::LLVMRealUNO => FPPredicate::UNO,
114            LLVMRealPredicate::LLVMRealUEQ => FPPredicate::UEQ,
115            LLVMRealPredicate::LLVMRealUGT => FPPredicate::UGT,
116            LLVMRealPredicate::LLVMRealUGE => FPPredicate::UGE,
117            LLVMRealPredicate::LLVMRealULT => FPPredicate::ULT,
118            LLVMRealPredicate::LLVMRealULE => FPPredicate::ULE,
119            LLVMRealPredicate::LLVMRealUNE => FPPredicate::UNE,
120            LLVMRealPredicate::LLVMRealPredicateTrue => FPPredicate::True,
121        }
122    }
123}