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
use std::fmt::{self, Display};

#[derive(PartialEq, Eq, Clone, Copy, Debug)]
pub enum IntPredicate {
    EQ,
    NE,
    UGT,
    UGE,
    ULT,
    ULE,
    SGT,
    SGE,
    SLT,
    SLE,
}

impl Display for IntPredicate {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match self {
            IntPredicate::EQ => write!(f, "eq"),
            IntPredicate::NE => write!(f, "ne"),
            IntPredicate::UGT => write!(f, "ugt"),
            IntPredicate::UGE => write!(f, "uge"),
            IntPredicate::ULT => write!(f, "ult"),
            IntPredicate::ULE => write!(f, "ule"),
            IntPredicate::SGT => write!(f, "sgt"),
            IntPredicate::SGE => write!(f, "sge"),
            IntPredicate::SLT => write!(f, "slt"),
            IntPredicate::SLE => write!(f, "sle"),
        }
    }
}

#[derive(PartialEq, Eq, Clone, Copy, Debug)]
pub enum FPPredicate {
    False,
    OEQ,
    OGT,
    OGE,
    OLT,
    OLE,
    ONE,
    ORD,
    UNO,
    UEQ,
    UGT,
    UGE,
    ULT,
    ULE,
    UNE,
    True,
}

impl Display for FPPredicate {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match self {
            FPPredicate::False => write!(f, "false"),
            FPPredicate::OEQ => write!(f, "oeq"),
            FPPredicate::OGT => write!(f, "ogt"),
            FPPredicate::OGE => write!(f, "oge"),
            FPPredicate::OLT => write!(f, "olt"),
            FPPredicate::OLE => write!(f, "ole"),
            FPPredicate::ONE => write!(f, "one"),
            FPPredicate::ORD => write!(f, "ord"),
            FPPredicate::UNO => write!(f, "uno"),
            FPPredicate::UEQ => write!(f, "ueq"),
            FPPredicate::UGT => write!(f, "ugt"),
            FPPredicate::UGE => write!(f, "uge"),
            FPPredicate::ULT => write!(f, "ult"),
            FPPredicate::ULE => write!(f, "ule"),
            FPPredicate::UNE => write!(f, "une"),
            FPPredicate::True => write!(f, "true"),
        }
    }
}

// ********* //
// from_llvm //
// ********* //

use crate::llvm_sys::*;
use llvm_sys::LLVMIntPredicate;
use llvm_sys::LLVMRealPredicate;

impl IntPredicate {
    pub(crate) fn from_llvm(pred: LLVMIntPredicate) -> Self {
        match pred {
            LLVMIntPredicate::LLVMIntEQ => IntPredicate::EQ,
            LLVMIntPredicate::LLVMIntNE => IntPredicate::NE,
            LLVMIntPredicate::LLVMIntUGT => IntPredicate::UGT,
            LLVMIntPredicate::LLVMIntUGE => IntPredicate::UGE,
            LLVMIntPredicate::LLVMIntULT => IntPredicate::ULT,
            LLVMIntPredicate::LLVMIntULE => IntPredicate::ULE,
            LLVMIntPredicate::LLVMIntSGT => IntPredicate::SGT,
            LLVMIntPredicate::LLVMIntSGE => IntPredicate::SGE,
            LLVMIntPredicate::LLVMIntSLT => IntPredicate::SLT,
            LLVMIntPredicate::LLVMIntSLE => IntPredicate::SLE,
        }
    }
}

impl FPPredicate {
    pub(crate) fn from_llvm(pred: LLVMRealPredicate) -> Self {
        match pred {
            LLVMRealPredicate::LLVMRealPredicateFalse => FPPredicate::False,
            LLVMRealPredicate::LLVMRealOEQ => FPPredicate::OEQ,
            LLVMRealPredicate::LLVMRealOGT => FPPredicate::OGT,
            LLVMRealPredicate::LLVMRealOGE => FPPredicate::OGE,
            LLVMRealPredicate::LLVMRealOLT => FPPredicate::OLT,
            LLVMRealPredicate::LLVMRealOLE => FPPredicate::OLE,
            LLVMRealPredicate::LLVMRealONE => FPPredicate::ONE,
            LLVMRealPredicate::LLVMRealORD => FPPredicate::ORD,
            LLVMRealPredicate::LLVMRealUNO => FPPredicate::UNO,
            LLVMRealPredicate::LLVMRealUEQ => FPPredicate::UEQ,
            LLVMRealPredicate::LLVMRealUGT => FPPredicate::UGT,
            LLVMRealPredicate::LLVMRealUGE => FPPredicate::UGE,
            LLVMRealPredicate::LLVMRealULT => FPPredicate::ULT,
            LLVMRealPredicate::LLVMRealULE => FPPredicate::ULE,
            LLVMRealPredicate::LLVMRealUNE => FPPredicate::UNE,
            LLVMRealPredicate::LLVMRealPredicateTrue => FPPredicate::True,
        }
    }
}